2 * QEMU Guest Agent POSIX-specific command implementations
4 * Copyright IBM Corp. 2011
7 * Michael Roth <mdroth@linux.vnet.ibm.com>
8 * Michal Privoznik <mprivozn@redhat.com>
10 * This work is licensed under the terms of the GNU GPL, version 2 or later.
11 * See the COPYING file in the top-level directory.
15 #include <sys/types.h>
16 #include <sys/ioctl.h>
26 #include "qga/guest-agent-core.h"
27 #include "qga-qmp-commands.h"
28 #include "qapi/qmp/qerror.h"
29 #include "qemu/queue.h"
30 #include "qemu/host-utils.h"
32 #ifndef CONFIG_HAS_ENVIRON
34 #include <crt_externs.h>
35 #define environ (*_NSGetEnviron())
37 extern char **environ
;
41 #if defined(__linux__)
45 #include <arpa/inet.h>
46 #include <sys/socket.h>
50 #define CONFIG_FSFREEZE
57 static void ga_wait_child(pid_t pid
, int *status
, Error
**errp
)
64 rpid
= waitpid(pid
, status
, 0);
65 } while (rpid
== -1 && errno
== EINTR
);
68 error_setg_errno(errp
, errno
, "failed to wait for child (pid: %d)",
73 g_assert(rpid
== pid
);
76 void qmp_guest_shutdown(bool has_mode
, const char *mode
, Error
**errp
)
78 const char *shutdown_flag
;
79 Error
*local_err
= NULL
;
83 slog("guest-shutdown called, mode: %s", mode
);
84 if (!has_mode
|| strcmp(mode
, "powerdown") == 0) {
86 } else if (strcmp(mode
, "halt") == 0) {
88 } else if (strcmp(mode
, "reboot") == 0) {
92 "mode is invalid (valid values are: halt|powerdown|reboot");
98 /* child, start the shutdown */
100 reopen_fd_to_null(0);
101 reopen_fd_to_null(1);
102 reopen_fd_to_null(2);
104 execle("/sbin/shutdown", "shutdown", "-h", shutdown_flag
, "+0",
105 "hypervisor initiated shutdown", (char*)NULL
, environ
);
107 } else if (pid
< 0) {
108 error_setg_errno(errp
, errno
, "failed to create child process");
112 ga_wait_child(pid
, &status
, &local_err
);
114 error_propagate(errp
, local_err
);
118 if (!WIFEXITED(status
)) {
119 error_setg(errp
, "child process has terminated abnormally");
123 if (WEXITSTATUS(status
)) {
124 error_setg(errp
, "child process has failed to shutdown");
131 int64_t qmp_guest_get_time(Error
**errp
)
137 ret
= qemu_gettimeofday(&tq
);
139 error_setg_errno(errp
, errno
, "Failed to get time");
143 time_ns
= tq
.tv_sec
* 1000000000LL + tq
.tv_usec
* 1000;
147 void qmp_guest_set_time(bool has_time
, int64_t time_ns
, Error
**errp
)
152 Error
*local_err
= NULL
;
155 /* If user has passed a time, validate and set it. */
157 /* year-2038 will overflow in case time_t is 32bit */
158 if (time_ns
/ 1000000000 != (time_t)(time_ns
/ 1000000000)) {
159 error_setg(errp
, "Time %" PRId64
" is too large", time_ns
);
163 tv
.tv_sec
= time_ns
/ 1000000000;
164 tv
.tv_usec
= (time_ns
% 1000000000) / 1000;
166 ret
= settimeofday(&tv
, NULL
);
168 error_setg_errno(errp
, errno
, "Failed to set time to guest");
173 /* Now, if user has passed a time to set and the system time is set, we
174 * just need to synchronize the hardware clock. However, if no time was
175 * passed, user is requesting the opposite: set the system time from the
176 * hardware clock (RTC). */
180 reopen_fd_to_null(0);
181 reopen_fd_to_null(1);
182 reopen_fd_to_null(2);
184 /* Use '/sbin/hwclock -w' to set RTC from the system time,
185 * or '/sbin/hwclock -s' to set the system time from RTC. */
186 execle("/sbin/hwclock", "hwclock", has_time
? "-w" : "-s",
189 } else if (pid
< 0) {
190 error_setg_errno(errp
, errno
, "failed to create child process");
194 ga_wait_child(pid
, &status
, &local_err
);
196 error_propagate(errp
, local_err
);
200 if (!WIFEXITED(status
)) {
201 error_setg(errp
, "child process has terminated abnormally");
205 if (WEXITSTATUS(status
)) {
206 error_setg(errp
, "hwclock failed to set hardware clock to system time");
211 typedef struct GuestFileHandle
{
214 QTAILQ_ENTRY(GuestFileHandle
) next
;
218 QTAILQ_HEAD(, GuestFileHandle
) filehandles
;
221 static int64_t guest_file_handle_add(FILE *fh
, Error
**errp
)
223 GuestFileHandle
*gfh
;
226 handle
= ga_get_fd_handle(ga_state
, errp
);
231 gfh
= g_malloc0(sizeof(GuestFileHandle
));
234 QTAILQ_INSERT_TAIL(&guest_file_state
.filehandles
, gfh
, next
);
239 static GuestFileHandle
*guest_file_handle_find(int64_t id
, Error
**errp
)
241 GuestFileHandle
*gfh
;
243 QTAILQ_FOREACH(gfh
, &guest_file_state
.filehandles
, next
)
250 error_setg(errp
, "handle '%" PRId64
"' has not been found", id
);
254 typedef const char * const ccpc
;
260 /* http://pubs.opengroup.org/onlinepubs/9699919799/functions/fopen.html */
261 static const struct {
264 } guest_file_open_modes
[] = {
265 { (ccpc
[]){ "r", NULL
}, O_RDONLY
},
266 { (ccpc
[]){ "rb", NULL
}, O_RDONLY
| O_BINARY
},
267 { (ccpc
[]){ "w", NULL
}, O_WRONLY
| O_CREAT
| O_TRUNC
},
268 { (ccpc
[]){ "wb", NULL
}, O_WRONLY
| O_CREAT
| O_TRUNC
| O_BINARY
},
269 { (ccpc
[]){ "a", NULL
}, O_WRONLY
| O_CREAT
| O_APPEND
},
270 { (ccpc
[]){ "ab", NULL
}, O_WRONLY
| O_CREAT
| O_APPEND
| O_BINARY
},
271 { (ccpc
[]){ "r+", NULL
}, O_RDWR
},
272 { (ccpc
[]){ "rb+", "r+b", NULL
}, O_RDWR
| O_BINARY
},
273 { (ccpc
[]){ "w+", NULL
}, O_RDWR
| O_CREAT
| O_TRUNC
},
274 { (ccpc
[]){ "wb+", "w+b", NULL
}, O_RDWR
| O_CREAT
| O_TRUNC
| O_BINARY
},
275 { (ccpc
[]){ "a+", NULL
}, O_RDWR
| O_CREAT
| O_APPEND
},
276 { (ccpc
[]){ "ab+", "a+b", NULL
}, O_RDWR
| O_CREAT
| O_APPEND
| O_BINARY
}
280 find_open_flag(const char *mode_str
, Error
**errp
)
284 for (mode
= 0; mode
< ARRAY_SIZE(guest_file_open_modes
); ++mode
) {
287 form
= guest_file_open_modes
[mode
].forms
;
288 while (*form
!= NULL
&& strcmp(*form
, mode_str
) != 0) {
296 if (mode
== ARRAY_SIZE(guest_file_open_modes
)) {
297 error_setg(errp
, "invalid file open mode '%s'", mode_str
);
300 return guest_file_open_modes
[mode
].oflag_base
| O_NOCTTY
| O_NONBLOCK
;
303 #define DEFAULT_NEW_FILE_MODE (S_IRUSR | S_IWUSR | \
304 S_IRGRP | S_IWGRP | \
308 safe_open_or_create(const char *path
, const char *mode
, Error
**errp
)
310 Error
*local_err
= NULL
;
313 oflag
= find_open_flag(mode
, &local_err
);
314 if (local_err
== NULL
) {
317 /* If the caller wants / allows creation of a new file, we implement it
318 * with a two step process: open() + (open() / fchmod()).
320 * First we insist on creating the file exclusively as a new file. If
321 * that succeeds, we're free to set any file-mode bits on it. (The
322 * motivation is that we want to set those file-mode bits independently
323 * of the current umask.)
325 * If the exclusive creation fails because the file already exists
326 * (EEXIST is not possible for any other reason), we just attempt to
327 * open the file, but in this case we won't be allowed to change the
328 * file-mode bits on the preexistent file.
330 * The pathname should never disappear between the two open()s in
331 * practice. If it happens, then someone very likely tried to race us.
332 * In this case just go ahead and report the ENOENT from the second
333 * open() to the caller.
335 * If the caller wants to open a preexistent file, then the first
336 * open() is decisive and its third argument is ignored, and the second
337 * open() and the fchmod() are never called.
339 fd
= open(path
, oflag
| ((oflag
& O_CREAT
) ? O_EXCL
: 0), 0);
340 if (fd
== -1 && errno
== EEXIST
) {
341 oflag
&= ~(unsigned)O_CREAT
;
342 fd
= open(path
, oflag
);
346 error_setg_errno(&local_err
, errno
, "failed to open file '%s' "
347 "(mode: '%s')", path
, mode
);
349 qemu_set_cloexec(fd
);
351 if ((oflag
& O_CREAT
) && fchmod(fd
, DEFAULT_NEW_FILE_MODE
) == -1) {
352 error_setg_errno(&local_err
, errno
, "failed to set permission "
353 "0%03o on new file '%s' (mode: '%s')",
354 (unsigned)DEFAULT_NEW_FILE_MODE
, path
, mode
);
358 f
= fdopen(fd
, mode
);
360 error_setg_errno(&local_err
, errno
, "failed to associate "
361 "stdio stream with file descriptor %d, "
362 "file '%s' (mode: '%s')", fd
, path
, mode
);
369 if (oflag
& O_CREAT
) {
375 error_propagate(errp
, local_err
);
379 int64_t qmp_guest_file_open(const char *path
, bool has_mode
, const char *mode
,
383 Error
*local_err
= NULL
;
385 int64_t ret
= -1, handle
;
390 slog("guest-file-open called, filepath: %s, mode: %s", path
, mode
);
391 fh
= safe_open_or_create(path
, mode
, &local_err
);
392 if (local_err
!= NULL
) {
393 error_propagate(errp
, local_err
);
397 /* set fd non-blocking to avoid common use cases (like reading from a
398 * named pipe) from hanging the agent
401 ret
= fcntl(fd
, F_GETFL
);
402 ret
= fcntl(fd
, F_SETFL
, ret
| O_NONBLOCK
);
404 error_setg_errno(errp
, errno
, "failed to make file '%s' non-blocking",
410 handle
= guest_file_handle_add(fh
, errp
);
416 slog("guest-file-open, handle: %" PRId64
, handle
);
420 void qmp_guest_file_close(int64_t handle
, Error
**errp
)
422 GuestFileHandle
*gfh
= guest_file_handle_find(handle
, errp
);
425 slog("guest-file-close called, handle: %" PRId64
, handle
);
430 ret
= fclose(gfh
->fh
);
432 error_setg_errno(errp
, errno
, "failed to close handle");
436 QTAILQ_REMOVE(&guest_file_state
.filehandles
, gfh
, next
);
440 struct GuestFileRead
*qmp_guest_file_read(int64_t handle
, bool has_count
,
441 int64_t count
, Error
**errp
)
443 GuestFileHandle
*gfh
= guest_file_handle_find(handle
, errp
);
444 GuestFileRead
*read_data
= NULL
;
454 count
= QGA_READ_COUNT_DEFAULT
;
455 } else if (count
< 0) {
456 error_setg(errp
, "value '%" PRId64
"' is invalid for argument count",
462 buf
= g_malloc0(count
+1);
463 read_count
= fread(buf
, 1, count
, fh
);
465 error_setg_errno(errp
, errno
, "failed to read file");
466 slog("guest-file-read failed, handle: %" PRId64
, handle
);
469 read_data
= g_malloc0(sizeof(GuestFileRead
));
470 read_data
->count
= read_count
;
471 read_data
->eof
= feof(fh
);
473 read_data
->buf_b64
= g_base64_encode(buf
, read_count
);
482 GuestFileWrite
*qmp_guest_file_write(int64_t handle
, const char *buf_b64
,
483 bool has_count
, int64_t count
,
486 GuestFileWrite
*write_data
= NULL
;
490 GuestFileHandle
*gfh
= guest_file_handle_find(handle
, errp
);
498 buf
= g_base64_decode(buf_b64
, &buf_len
);
502 } else if (count
< 0 || count
> buf_len
) {
503 error_setg(errp
, "value '%" PRId64
"' is invalid for argument count",
509 write_count
= fwrite(buf
, 1, count
, fh
);
511 error_setg_errno(errp
, errno
, "failed to write to file");
512 slog("guest-file-write failed, handle: %" PRId64
, handle
);
514 write_data
= g_malloc0(sizeof(GuestFileWrite
));
515 write_data
->count
= write_count
;
516 write_data
->eof
= feof(fh
);
524 struct GuestFileSeek
*qmp_guest_file_seek(int64_t handle
, int64_t offset
,
525 int64_t whence
, Error
**errp
)
527 GuestFileHandle
*gfh
= guest_file_handle_find(handle
, errp
);
528 GuestFileSeek
*seek_data
= NULL
;
537 ret
= fseek(fh
, offset
, whence
);
539 error_setg_errno(errp
, errno
, "failed to seek file");
541 seek_data
= g_new0(GuestFileSeek
, 1);
542 seek_data
->position
= ftell(fh
);
543 seek_data
->eof
= feof(fh
);
550 void qmp_guest_file_flush(int64_t handle
, Error
**errp
)
552 GuestFileHandle
*gfh
= guest_file_handle_find(handle
, errp
);
563 error_setg_errno(errp
, errno
, "failed to flush file");
567 static void guest_file_init(void)
569 QTAILQ_INIT(&guest_file_state
.filehandles
);
572 /* linux-specific implementations. avoid this if at all possible. */
573 #if defined(__linux__)
575 #if defined(CONFIG_FSFREEZE) || defined(CONFIG_FSTRIM)
576 typedef struct FsMount
{
579 unsigned int devmajor
, devminor
;
580 QTAILQ_ENTRY(FsMount
) next
;
583 typedef QTAILQ_HEAD(FsMountList
, FsMount
) FsMountList
;
585 static void free_fs_mount_list(FsMountList
*mounts
)
587 FsMount
*mount
, *temp
;
593 QTAILQ_FOREACH_SAFE(mount
, mounts
, next
, temp
) {
594 QTAILQ_REMOVE(mounts
, mount
, next
);
595 g_free(mount
->dirname
);
596 g_free(mount
->devtype
);
601 static int dev_major_minor(const char *devpath
,
602 unsigned int *devmajor
, unsigned int *devminor
)
609 if (stat(devpath
, &st
) < 0) {
610 slog("failed to stat device file '%s': %s", devpath
, strerror(errno
));
613 if (S_ISDIR(st
.st_mode
)) {
614 /* It is bind mount */
617 if (S_ISBLK(st
.st_mode
)) {
618 *devmajor
= major(st
.st_rdev
);
619 *devminor
= minor(st
.st_rdev
);
626 * Walk the mount table and build a list of local file systems
628 static void build_fs_mount_list_from_mtab(FsMountList
*mounts
, Error
**errp
)
632 char const *mtab
= "/proc/self/mounts";
634 unsigned int devmajor
, devminor
;
636 fp
= setmntent(mtab
, "r");
638 error_setg(errp
, "failed to open mtab file: '%s'", mtab
);
642 while ((ment
= getmntent(fp
))) {
644 * An entry which device name doesn't start with a '/' is
645 * either a dummy file system or a network file system.
646 * Add special handling for smbfs and cifs as is done by
649 if ((ment
->mnt_fsname
[0] != '/') ||
650 (strcmp(ment
->mnt_type
, "smbfs") == 0) ||
651 (strcmp(ment
->mnt_type
, "cifs") == 0)) {
654 if (dev_major_minor(ment
->mnt_fsname
, &devmajor
, &devminor
) == -2) {
655 /* Skip bind mounts */
659 mount
= g_malloc0(sizeof(FsMount
));
660 mount
->dirname
= g_strdup(ment
->mnt_dir
);
661 mount
->devtype
= g_strdup(ment
->mnt_type
);
662 mount
->devmajor
= devmajor
;
663 mount
->devminor
= devminor
;
665 QTAILQ_INSERT_TAIL(mounts
, mount
, next
);
671 static void decode_mntname(char *name
, int len
)
674 for (i
= 0; i
<= len
; i
++) {
675 if (name
[i
] != '\\') {
677 } else if (name
[i
+ 1] == '\\') {
680 } else if (name
[i
+ 1] >= '0' && name
[i
+ 1] <= '3' &&
681 name
[i
+ 2] >= '0' && name
[i
+ 2] <= '7' &&
682 name
[i
+ 3] >= '0' && name
[i
+ 3] <= '7') {
683 name
[j
++] = (name
[i
+ 1] - '0') * 64 +
684 (name
[i
+ 2] - '0') * 8 +
693 static void build_fs_mount_list(FsMountList
*mounts
, Error
**errp
)
696 char const *mountinfo
= "/proc/self/mountinfo";
698 char *line
= NULL
, *dash
;
701 unsigned int devmajor
, devminor
;
702 int ret
, dir_s
, dir_e
, type_s
, type_e
, dev_s
, dev_e
;
704 fp
= fopen(mountinfo
, "r");
706 build_fs_mount_list_from_mtab(mounts
, errp
);
710 while (getline(&line
, &n
, fp
) != -1) {
711 ret
= sscanf(line
, "%*u %*u %u:%u %*s %n%*s%n%c",
712 &devmajor
, &devminor
, &dir_s
, &dir_e
, &check
);
716 dash
= strstr(line
+ dir_e
, " - ");
720 ret
= sscanf(dash
, " - %n%*s%n %n%*s%n%c",
721 &type_s
, &type_e
, &dev_s
, &dev_e
, &check
);
728 decode_mntname(line
+ dir_s
, dir_e
- dir_s
);
729 decode_mntname(dash
+ dev_s
, dev_e
- dev_s
);
731 /* btrfs reports major number = 0 */
732 if (strcmp("btrfs", dash
+ type_s
) != 0 ||
733 dev_major_minor(dash
+ dev_s
, &devmajor
, &devminor
) < 0) {
738 mount
= g_malloc0(sizeof(FsMount
));
739 mount
->dirname
= g_strdup(line
+ dir_s
);
740 mount
->devtype
= g_strdup(dash
+ type_s
);
741 mount
->devmajor
= devmajor
;
742 mount
->devminor
= devminor
;
744 QTAILQ_INSERT_TAIL(mounts
, mount
, next
);
752 #if defined(CONFIG_FSFREEZE)
754 static char *get_pci_driver(char const *syspath
, int pathlen
, Error
**errp
)
762 path
= g_strndup(syspath
, pathlen
);
763 dpath
= g_strdup_printf("%s/driver", path
);
764 len
= readlink(dpath
, buf
, sizeof(buf
) - 1);
767 driver
= g_strdup(basename(buf
));
774 static int compare_uint(const void *_a
, const void *_b
)
776 unsigned int a
= *(unsigned int *)_a
;
777 unsigned int b
= *(unsigned int *)_b
;
779 return a
< b
? -1 : a
> b
? 1 : 0;
782 /* Walk the specified sysfs and build a sorted list of host or ata numbers */
783 static int build_hosts(char const *syspath
, char const *host
, bool ata
,
784 unsigned int *hosts
, int hosts_max
, Error
**errp
)
788 struct dirent
*entry
;
791 path
= g_strndup(syspath
, host
- syspath
);
794 error_setg_errno(errp
, errno
, "opendir(\"%s\")", path
);
799 while (i
< hosts_max
) {
800 entry
= readdir(dir
);
804 if (ata
&& sscanf(entry
->d_name
, "ata%d", hosts
+ i
) == 1) {
806 } else if (!ata
&& sscanf(entry
->d_name
, "host%d", hosts
+ i
) == 1) {
811 qsort(hosts
, i
, sizeof(hosts
[0]), compare_uint
);
818 /* Store disk device info specified by @sysfs into @fs */
819 static void build_guest_fsinfo_for_real_device(char const *syspath
,
820 GuestFilesystemInfo
*fs
,
823 unsigned int pci
[4], host
, hosts
[8], tgt
[3];
824 int i
, nhosts
= 0, pcilen
;
825 GuestDiskAddress
*disk
;
826 GuestPCIAddress
*pciaddr
;
827 GuestDiskAddressList
*list
= NULL
;
828 bool has_ata
= false, has_host
= false, has_tgt
= false;
829 char *p
, *q
, *driver
= NULL
;
831 p
= strstr(syspath
, "/devices/pci");
832 if (!p
|| sscanf(p
+ 12, "%*x:%*x/%x:%x:%x.%x%n",
833 pci
, pci
+ 1, pci
+ 2, pci
+ 3, &pcilen
) < 4) {
834 g_debug("only pci device is supported: sysfs path \"%s\"", syspath
);
838 driver
= get_pci_driver(syspath
, (p
+ 12 + pcilen
) - syspath
, errp
);
843 p
= strstr(syspath
, "/target");
844 if (p
&& sscanf(p
+ 7, "%*u:%*u:%*u/%*u:%u:%u:%u",
845 tgt
, tgt
+ 1, tgt
+ 2) == 3) {
849 p
= strstr(syspath
, "/ata");
854 p
= strstr(syspath
, "/host");
857 if (p
&& sscanf(q
, "%u", &host
) == 1) {
859 nhosts
= build_hosts(syspath
, p
, has_ata
, hosts
,
860 sizeof(hosts
) / sizeof(hosts
[0]), errp
);
866 pciaddr
= g_malloc0(sizeof(*pciaddr
));
867 pciaddr
->domain
= pci
[0];
868 pciaddr
->bus
= pci
[1];
869 pciaddr
->slot
= pci
[2];
870 pciaddr
->function
= pci
[3];
872 disk
= g_malloc0(sizeof(*disk
));
873 disk
->pci_controller
= pciaddr
;
875 list
= g_malloc0(sizeof(*list
));
878 if (strcmp(driver
, "ata_piix") == 0) {
879 /* a host per ide bus, target*:0:<unit>:0 */
880 if (!has_host
|| !has_tgt
) {
881 g_debug("invalid sysfs path '%s' (driver '%s')", syspath
, driver
);
884 for (i
= 0; i
< nhosts
; i
++) {
885 if (host
== hosts
[i
]) {
886 disk
->bus_type
= GUEST_DISK_BUS_TYPE_IDE
;
893 g_debug("no host for '%s' (driver '%s')", syspath
, driver
);
896 } else if (strcmp(driver
, "sym53c8xx") == 0) {
897 /* scsi(LSI Logic): target*:0:<unit>:0 */
899 g_debug("invalid sysfs path '%s' (driver '%s')", syspath
, driver
);
902 disk
->bus_type
= GUEST_DISK_BUS_TYPE_SCSI
;
904 } else if (strcmp(driver
, "virtio-pci") == 0) {
906 /* virtio-scsi: target*:0:0:<unit> */
907 disk
->bus_type
= GUEST_DISK_BUS_TYPE_SCSI
;
910 /* virtio-blk: 1 disk per 1 device */
911 disk
->bus_type
= GUEST_DISK_BUS_TYPE_VIRTIO
;
913 } else if (strcmp(driver
, "ahci") == 0) {
914 /* ahci: 1 host per 1 unit */
915 if (!has_host
|| !has_tgt
) {
916 g_debug("invalid sysfs path '%s' (driver '%s')", syspath
, driver
);
919 for (i
= 0; i
< nhosts
; i
++) {
920 if (host
== hosts
[i
]) {
922 disk
->bus_type
= GUEST_DISK_BUS_TYPE_SATA
;
927 g_debug("no host for '%s' (driver '%s')", syspath
, driver
);
931 g_debug("unknown driver '%s' (sysfs path '%s')", driver
, syspath
);
935 list
->next
= fs
->disk
;
942 qapi_free_GuestDiskAddressList(list
);
947 static void build_guest_fsinfo_for_device(char const *devpath
,
948 GuestFilesystemInfo
*fs
,
951 /* Store a list of slave devices of virtual volume specified by @syspath into
953 static void build_guest_fsinfo_for_virtual_device(char const *syspath
,
954 GuestFilesystemInfo
*fs
,
959 struct dirent entry
, *result
;
961 dirpath
= g_strdup_printf("%s/slaves", syspath
);
962 dir
= opendir(dirpath
);
964 error_setg_errno(errp
, errno
, "opendir(\"%s\")", dirpath
);
971 if (readdir_r(dir
, &entry
, &result
) != 0) {
972 error_setg_errno(errp
, errno
, "readdir_r(\"%s\")", dirpath
);
979 if (entry
.d_type
== DT_LNK
) {
980 g_debug(" slave device '%s'", entry
.d_name
);
981 dirpath
= g_strdup_printf("%s/slaves/%s", syspath
, entry
.d_name
);
982 build_guest_fsinfo_for_device(dirpath
, fs
, errp
);
994 /* Dispatch to functions for virtual/real device */
995 static void build_guest_fsinfo_for_device(char const *devpath
,
996 GuestFilesystemInfo
*fs
,
999 char *syspath
= realpath(devpath
, NULL
);
1002 error_setg_errno(errp
, errno
, "realpath(\"%s\")", devpath
);
1007 fs
->name
= g_strdup(basename(syspath
));
1010 g_debug(" parse sysfs path '%s'", syspath
);
1012 if (strstr(syspath
, "/devices/virtual/block/")) {
1013 build_guest_fsinfo_for_virtual_device(syspath
, fs
, errp
);
1015 build_guest_fsinfo_for_real_device(syspath
, fs
, errp
);
1021 /* Return a list of the disk device(s)' info which @mount lies on */
1022 static GuestFilesystemInfo
*build_guest_fsinfo(struct FsMount
*mount
,
1025 GuestFilesystemInfo
*fs
= g_malloc0(sizeof(*fs
));
1026 char *devpath
= g_strdup_printf("/sys/dev/block/%u:%u",
1027 mount
->devmajor
, mount
->devminor
);
1029 fs
->mountpoint
= g_strdup(mount
->dirname
);
1030 fs
->type
= g_strdup(mount
->devtype
);
1031 build_guest_fsinfo_for_device(devpath
, fs
, errp
);
1037 GuestFilesystemInfoList
*qmp_guest_get_fsinfo(Error
**errp
)
1040 struct FsMount
*mount
;
1041 GuestFilesystemInfoList
*new, *ret
= NULL
;
1042 Error
*local_err
= NULL
;
1044 QTAILQ_INIT(&mounts
);
1045 build_fs_mount_list(&mounts
, &local_err
);
1047 error_propagate(errp
, local_err
);
1051 QTAILQ_FOREACH(mount
, &mounts
, next
) {
1052 g_debug("Building guest fsinfo for '%s'", mount
->dirname
);
1054 new = g_malloc0(sizeof(*ret
));
1055 new->value
= build_guest_fsinfo(mount
, &local_err
);
1059 error_propagate(errp
, local_err
);
1060 qapi_free_GuestFilesystemInfoList(ret
);
1066 free_fs_mount_list(&mounts
);
1072 FSFREEZE_HOOK_THAW
= 0,
1073 FSFREEZE_HOOK_FREEZE
,
1076 static const char *fsfreeze_hook_arg_string
[] = {
1081 static void execute_fsfreeze_hook(FsfreezeHookArg arg
, Error
**errp
)
1086 const char *arg_str
= fsfreeze_hook_arg_string
[arg
];
1087 Error
*local_err
= NULL
;
1089 hook
= ga_fsfreeze_hook(ga_state
);
1093 if (access(hook
, X_OK
) != 0) {
1094 error_setg_errno(errp
, errno
, "can't access fsfreeze hook '%s'", hook
);
1098 slog("executing fsfreeze hook with arg '%s'", arg_str
);
1102 reopen_fd_to_null(0);
1103 reopen_fd_to_null(1);
1104 reopen_fd_to_null(2);
1106 execle(hook
, hook
, arg_str
, NULL
, environ
);
1107 _exit(EXIT_FAILURE
);
1108 } else if (pid
< 0) {
1109 error_setg_errno(errp
, errno
, "failed to create child process");
1113 ga_wait_child(pid
, &status
, &local_err
);
1115 error_propagate(errp
, local_err
);
1119 if (!WIFEXITED(status
)) {
1120 error_setg(errp
, "fsfreeze hook has terminated abnormally");
1124 status
= WEXITSTATUS(status
);
1126 error_setg(errp
, "fsfreeze hook has failed with status %d", status
);
1132 * Return status of freeze/thaw
1134 GuestFsfreezeStatus
qmp_guest_fsfreeze_status(Error
**errp
)
1136 if (ga_is_frozen(ga_state
)) {
1137 return GUEST_FSFREEZE_STATUS_FROZEN
;
1140 return GUEST_FSFREEZE_STATUS_THAWED
;
1143 int64_t qmp_guest_fsfreeze_freeze(Error
**errp
)
1145 return qmp_guest_fsfreeze_freeze_list(false, NULL
, errp
);
1149 * Walk list of mounted file systems in the guest, and freeze the ones which
1150 * are real local file systems.
1152 int64_t qmp_guest_fsfreeze_freeze_list(bool has_mountpoints
,
1153 strList
*mountpoints
,
1159 struct FsMount
*mount
;
1160 Error
*local_err
= NULL
;
1163 slog("guest-fsfreeze called");
1165 execute_fsfreeze_hook(FSFREEZE_HOOK_FREEZE
, &local_err
);
1167 error_propagate(errp
, local_err
);
1171 QTAILQ_INIT(&mounts
);
1172 build_fs_mount_list(&mounts
, &local_err
);
1174 error_propagate(errp
, local_err
);
1178 /* cannot risk guest agent blocking itself on a write in this state */
1179 ga_set_frozen(ga_state
);
1181 QTAILQ_FOREACH_REVERSE(mount
, &mounts
, FsMountList
, next
) {
1182 /* To issue fsfreeze in the reverse order of mounts, check if the
1183 * mount is listed in the list here */
1184 if (has_mountpoints
) {
1185 for (list
= mountpoints
; list
; list
= list
->next
) {
1186 if (strcmp(list
->value
, mount
->dirname
) == 0) {
1195 fd
= qemu_open(mount
->dirname
, O_RDONLY
);
1197 error_setg_errno(errp
, errno
, "failed to open %s", mount
->dirname
);
1201 /* we try to cull filesytems we know won't work in advance, but other
1202 * filesytems may not implement fsfreeze for less obvious reasons.
1203 * these will report EOPNOTSUPP. we simply ignore these when tallying
1204 * the number of frozen filesystems.
1206 * any other error means a failure to freeze a filesystem we
1207 * expect to be freezable, so return an error in those cases
1208 * and return system to thawed state.
1210 ret
= ioctl(fd
, FIFREEZE
);
1212 if (errno
!= EOPNOTSUPP
) {
1213 error_setg_errno(errp
, errno
, "failed to freeze %s",
1224 free_fs_mount_list(&mounts
);
1228 free_fs_mount_list(&mounts
);
1229 qmp_guest_fsfreeze_thaw(NULL
);
1234 * Walk list of frozen file systems in the guest, and thaw them.
1236 int64_t qmp_guest_fsfreeze_thaw(Error
**errp
)
1241 int fd
, i
= 0, logged
;
1242 Error
*local_err
= NULL
;
1244 QTAILQ_INIT(&mounts
);
1245 build_fs_mount_list(&mounts
, &local_err
);
1247 error_propagate(errp
, local_err
);
1251 QTAILQ_FOREACH(mount
, &mounts
, next
) {
1253 fd
= qemu_open(mount
->dirname
, O_RDONLY
);
1257 /* we have no way of knowing whether a filesystem was actually unfrozen
1258 * as a result of a successful call to FITHAW, only that if an error
1259 * was returned the filesystem was *not* unfrozen by that particular
1262 * since multiple preceding FIFREEZEs require multiple calls to FITHAW
1263 * to unfreeze, continuing issuing FITHAW until an error is returned,
1264 * in which case either the filesystem is in an unfreezable state, or,
1265 * more likely, it was thawed previously (and remains so afterward).
1267 * also, since the most recent successful call is the one that did
1268 * the actual unfreeze, we can use this to provide an accurate count
1269 * of the number of filesystems unfrozen by guest-fsfreeze-thaw, which
1270 * may * be useful for determining whether a filesystem was unfrozen
1271 * during the freeze/thaw phase by a process other than qemu-ga.
1274 ret
= ioctl(fd
, FITHAW
);
1275 if (ret
== 0 && !logged
) {
1283 ga_unset_frozen(ga_state
);
1284 free_fs_mount_list(&mounts
);
1286 execute_fsfreeze_hook(FSFREEZE_HOOK_THAW
, errp
);
1291 static void guest_fsfreeze_cleanup(void)
1295 if (ga_is_frozen(ga_state
) == GUEST_FSFREEZE_STATUS_FROZEN
) {
1296 qmp_guest_fsfreeze_thaw(&err
);
1298 slog("failed to clean up frozen filesystems: %s",
1299 error_get_pretty(err
));
1304 #endif /* CONFIG_FSFREEZE */
1306 #if defined(CONFIG_FSTRIM)
1308 * Walk list of mounted file systems in the guest, and trim them.
1310 void qmp_guest_fstrim(bool has_minimum
, int64_t minimum
, Error
**errp
)
1314 struct FsMount
*mount
;
1316 Error
*local_err
= NULL
;
1317 struct fstrim_range r
= {
1320 .minlen
= has_minimum
? minimum
: 0,
1323 slog("guest-fstrim called");
1325 QTAILQ_INIT(&mounts
);
1326 build_fs_mount_list(&mounts
, &local_err
);
1328 error_propagate(errp
, local_err
);
1332 QTAILQ_FOREACH(mount
, &mounts
, next
) {
1333 fd
= qemu_open(mount
->dirname
, O_RDONLY
);
1335 error_setg_errno(errp
, errno
, "failed to open %s", mount
->dirname
);
1339 /* We try to cull filesytems we know won't work in advance, but other
1340 * filesytems may not implement fstrim for less obvious reasons. These
1341 * will report EOPNOTSUPP; we simply ignore these errors. Any other
1342 * error means an unexpected error, so return it in those cases. In
1343 * some other cases ENOTTY will be reported (e.g. CD-ROMs).
1345 ret
= ioctl(fd
, FITRIM
, &r
);
1347 if (errno
!= ENOTTY
&& errno
!= EOPNOTSUPP
) {
1348 error_setg_errno(errp
, errno
, "failed to trim %s",
1358 free_fs_mount_list(&mounts
);
1360 #endif /* CONFIG_FSTRIM */
1363 #define LINUX_SYS_STATE_FILE "/sys/power/state"
1364 #define SUSPEND_SUPPORTED 0
1365 #define SUSPEND_NOT_SUPPORTED 1
1367 static void bios_supports_mode(const char *pmutils_bin
, const char *pmutils_arg
,
1368 const char *sysfile_str
, Error
**errp
)
1370 Error
*local_err
= NULL
;
1375 pmutils_path
= g_find_program_in_path(pmutils_bin
);
1379 char buf
[32]; /* hopefully big enough */
1384 reopen_fd_to_null(0);
1385 reopen_fd_to_null(1);
1386 reopen_fd_to_null(2);
1389 execle(pmutils_path
, pmutils_bin
, pmutils_arg
, NULL
, environ
);
1393 * If we get here either pm-utils is not installed or execle() has
1394 * failed. Let's try the manual method if the caller wants it.
1398 _exit(SUSPEND_NOT_SUPPORTED
);
1401 fd
= open(LINUX_SYS_STATE_FILE
, O_RDONLY
);
1403 _exit(SUSPEND_NOT_SUPPORTED
);
1406 ret
= read(fd
, buf
, sizeof(buf
)-1);
1408 _exit(SUSPEND_NOT_SUPPORTED
);
1412 if (strstr(buf
, sysfile_str
)) {
1413 _exit(SUSPEND_SUPPORTED
);
1416 _exit(SUSPEND_NOT_SUPPORTED
);
1417 } else if (pid
< 0) {
1418 error_setg_errno(errp
, errno
, "failed to create child process");
1422 ga_wait_child(pid
, &status
, &local_err
);
1424 error_propagate(errp
, local_err
);
1428 if (!WIFEXITED(status
)) {
1429 error_setg(errp
, "child process has terminated abnormally");
1433 switch (WEXITSTATUS(status
)) {
1434 case SUSPEND_SUPPORTED
:
1436 case SUSPEND_NOT_SUPPORTED
:
1438 "the requested suspend mode is not supported by the guest");
1442 "the helper program '%s' returned an unexpected exit status"
1443 " code (%d)", pmutils_path
, WEXITSTATUS(status
));
1448 g_free(pmutils_path
);
1451 static void guest_suspend(const char *pmutils_bin
, const char *sysfile_str
,
1454 Error
*local_err
= NULL
;
1459 pmutils_path
= g_find_program_in_path(pmutils_bin
);
1467 reopen_fd_to_null(0);
1468 reopen_fd_to_null(1);
1469 reopen_fd_to_null(2);
1472 execle(pmutils_path
, pmutils_bin
, NULL
, environ
);
1476 * If we get here either pm-utils is not installed or execle() has
1477 * failed. Let's try the manual method if the caller wants it.
1481 _exit(EXIT_FAILURE
);
1484 fd
= open(LINUX_SYS_STATE_FILE
, O_WRONLY
);
1486 _exit(EXIT_FAILURE
);
1489 if (write(fd
, sysfile_str
, strlen(sysfile_str
)) < 0) {
1490 _exit(EXIT_FAILURE
);
1493 _exit(EXIT_SUCCESS
);
1494 } else if (pid
< 0) {
1495 error_setg_errno(errp
, errno
, "failed to create child process");
1499 ga_wait_child(pid
, &status
, &local_err
);
1501 error_propagate(errp
, local_err
);
1505 if (!WIFEXITED(status
)) {
1506 error_setg(errp
, "child process has terminated abnormally");
1510 if (WEXITSTATUS(status
)) {
1511 error_setg(errp
, "child process has failed to suspend");
1516 g_free(pmutils_path
);
1519 void qmp_guest_suspend_disk(Error
**errp
)
1521 Error
*local_err
= NULL
;
1523 bios_supports_mode("pm-is-supported", "--hibernate", "disk", &local_err
);
1525 error_propagate(errp
, local_err
);
1529 guest_suspend("pm-hibernate", "disk", errp
);
1532 void qmp_guest_suspend_ram(Error
**errp
)
1534 Error
*local_err
= NULL
;
1536 bios_supports_mode("pm-is-supported", "--suspend", "mem", &local_err
);
1538 error_propagate(errp
, local_err
);
1542 guest_suspend("pm-suspend", "mem", errp
);
1545 void qmp_guest_suspend_hybrid(Error
**errp
)
1547 Error
*local_err
= NULL
;
1549 bios_supports_mode("pm-is-supported", "--suspend-hybrid", NULL
,
1552 error_propagate(errp
, local_err
);
1556 guest_suspend("pm-suspend-hybrid", NULL
, errp
);
1559 static GuestNetworkInterfaceList
*
1560 guest_find_interface(GuestNetworkInterfaceList
*head
,
1563 for (; head
; head
= head
->next
) {
1564 if (strcmp(head
->value
->name
, name
) == 0) {
1573 * Build information about guest interfaces
1575 GuestNetworkInterfaceList
*qmp_guest_network_get_interfaces(Error
**errp
)
1577 GuestNetworkInterfaceList
*head
= NULL
, *cur_item
= NULL
;
1578 struct ifaddrs
*ifap
, *ifa
;
1580 if (getifaddrs(&ifap
) < 0) {
1581 error_setg_errno(errp
, errno
, "getifaddrs failed");
1585 for (ifa
= ifap
; ifa
; ifa
= ifa
->ifa_next
) {
1586 GuestNetworkInterfaceList
*info
;
1587 GuestIpAddressList
**address_list
= NULL
, *address_item
= NULL
;
1588 char addr4
[INET_ADDRSTRLEN
];
1589 char addr6
[INET6_ADDRSTRLEN
];
1592 unsigned char *mac_addr
;
1595 g_debug("Processing %s interface", ifa
->ifa_name
);
1597 info
= guest_find_interface(head
, ifa
->ifa_name
);
1600 info
= g_malloc0(sizeof(*info
));
1601 info
->value
= g_malloc0(sizeof(*info
->value
));
1602 info
->value
->name
= g_strdup(ifa
->ifa_name
);
1605 head
= cur_item
= info
;
1607 cur_item
->next
= info
;
1612 if (!info
->value
->has_hardware_address
&&
1613 ifa
->ifa_flags
& SIOCGIFHWADDR
) {
1614 /* we haven't obtained HW address yet */
1615 sock
= socket(PF_INET
, SOCK_STREAM
, 0);
1617 error_setg_errno(errp
, errno
, "failed to create socket");
1621 memset(&ifr
, 0, sizeof(ifr
));
1622 pstrcpy(ifr
.ifr_name
, IF_NAMESIZE
, info
->value
->name
);
1623 if (ioctl(sock
, SIOCGIFHWADDR
, &ifr
) == -1) {
1624 error_setg_errno(errp
, errno
,
1625 "failed to get MAC address of %s",
1632 mac_addr
= (unsigned char *) &ifr
.ifr_hwaddr
.sa_data
;
1634 info
->value
->hardware_address
=
1635 g_strdup_printf("%02x:%02x:%02x:%02x:%02x:%02x",
1636 (int) mac_addr
[0], (int) mac_addr
[1],
1637 (int) mac_addr
[2], (int) mac_addr
[3],
1638 (int) mac_addr
[4], (int) mac_addr
[5]);
1640 info
->value
->has_hardware_address
= true;
1643 if (ifa
->ifa_addr
&&
1644 ifa
->ifa_addr
->sa_family
== AF_INET
) {
1645 /* interface with IPv4 address */
1646 p
= &((struct sockaddr_in
*)ifa
->ifa_addr
)->sin_addr
;
1647 if (!inet_ntop(AF_INET
, p
, addr4
, sizeof(addr4
))) {
1648 error_setg_errno(errp
, errno
, "inet_ntop failed");
1652 address_item
= g_malloc0(sizeof(*address_item
));
1653 address_item
->value
= g_malloc0(sizeof(*address_item
->value
));
1654 address_item
->value
->ip_address
= g_strdup(addr4
);
1655 address_item
->value
->ip_address_type
= GUEST_IP_ADDRESS_TYPE_IPV4
;
1657 if (ifa
->ifa_netmask
) {
1658 /* Count the number of set bits in netmask.
1659 * This is safe as '1' and '0' cannot be shuffled in netmask. */
1660 p
= &((struct sockaddr_in
*)ifa
->ifa_netmask
)->sin_addr
;
1661 address_item
->value
->prefix
= ctpop32(((uint32_t *) p
)[0]);
1663 } else if (ifa
->ifa_addr
&&
1664 ifa
->ifa_addr
->sa_family
== AF_INET6
) {
1665 /* interface with IPv6 address */
1666 p
= &((struct sockaddr_in6
*)ifa
->ifa_addr
)->sin6_addr
;
1667 if (!inet_ntop(AF_INET6
, p
, addr6
, sizeof(addr6
))) {
1668 error_setg_errno(errp
, errno
, "inet_ntop failed");
1672 address_item
= g_malloc0(sizeof(*address_item
));
1673 address_item
->value
= g_malloc0(sizeof(*address_item
->value
));
1674 address_item
->value
->ip_address
= g_strdup(addr6
);
1675 address_item
->value
->ip_address_type
= GUEST_IP_ADDRESS_TYPE_IPV6
;
1677 if (ifa
->ifa_netmask
) {
1678 /* Count the number of set bits in netmask.
1679 * This is safe as '1' and '0' cannot be shuffled in netmask. */
1680 p
= &((struct sockaddr_in6
*)ifa
->ifa_netmask
)->sin6_addr
;
1681 address_item
->value
->prefix
=
1682 ctpop32(((uint32_t *) p
)[0]) +
1683 ctpop32(((uint32_t *) p
)[1]) +
1684 ctpop32(((uint32_t *) p
)[2]) +
1685 ctpop32(((uint32_t *) p
)[3]);
1689 if (!address_item
) {
1693 address_list
= &info
->value
->ip_addresses
;
1695 while (*address_list
&& (*address_list
)->next
) {
1696 address_list
= &(*address_list
)->next
;
1699 if (!*address_list
) {
1700 *address_list
= address_item
;
1702 (*address_list
)->next
= address_item
;
1705 info
->value
->has_ip_addresses
= true;
1715 qapi_free_GuestNetworkInterfaceList(head
);
1719 #define SYSCONF_EXACT(name, errp) sysconf_exact((name), #name, (errp))
1721 static long sysconf_exact(int name
, const char *name_str
, Error
**errp
)
1726 ret
= sysconf(name
);
1729 error_setg(errp
, "sysconf(%s): value indefinite", name_str
);
1731 error_setg_errno(errp
, errno
, "sysconf(%s)", name_str
);
1737 /* Transfer online/offline status between @vcpu and the guest system.
1739 * On input either @errp or *@errp must be NULL.
1741 * In system-to-@vcpu direction, the following @vcpu fields are accessed:
1742 * - R: vcpu->logical_id
1744 * - W: vcpu->can_offline
1746 * In @vcpu-to-system direction, the following @vcpu fields are accessed:
1747 * - R: vcpu->logical_id
1750 * Written members remain unmodified on error.
1752 static void transfer_vcpu(GuestLogicalProcessor
*vcpu
, bool sys2vcpu
,
1758 dirpath
= g_strdup_printf("/sys/devices/system/cpu/cpu%" PRId64
"/",
1760 dirfd
= open(dirpath
, O_RDONLY
| O_DIRECTORY
);
1762 error_setg_errno(errp
, errno
, "open(\"%s\")", dirpath
);
1764 static const char fn
[] = "online";
1768 fd
= openat(dirfd
, fn
, sys2vcpu
? O_RDONLY
: O_RDWR
);
1770 if (errno
!= ENOENT
) {
1771 error_setg_errno(errp
, errno
, "open(\"%s/%s\")", dirpath
, fn
);
1772 } else if (sys2vcpu
) {
1773 vcpu
->online
= true;
1774 vcpu
->can_offline
= false;
1775 } else if (!vcpu
->online
) {
1776 error_setg(errp
, "logical processor #%" PRId64
" can't be "
1777 "offlined", vcpu
->logical_id
);
1778 } /* otherwise pretend successful re-onlining */
1780 unsigned char status
;
1782 res
= pread(fd
, &status
, 1, 0);
1784 error_setg_errno(errp
, errno
, "pread(\"%s/%s\")", dirpath
, fn
);
1785 } else if (res
== 0) {
1786 error_setg(errp
, "pread(\"%s/%s\"): unexpected EOF", dirpath
,
1788 } else if (sys2vcpu
) {
1789 vcpu
->online
= (status
!= '0');
1790 vcpu
->can_offline
= true;
1791 } else if (vcpu
->online
!= (status
!= '0')) {
1792 status
= '0' + vcpu
->online
;
1793 if (pwrite(fd
, &status
, 1, 0) == -1) {
1794 error_setg_errno(errp
, errno
, "pwrite(\"%s/%s\")", dirpath
,
1797 } /* otherwise pretend successful re-(on|off)-lining */
1810 GuestLogicalProcessorList
*qmp_guest_get_vcpus(Error
**errp
)
1813 GuestLogicalProcessorList
*head
, **link
;
1815 Error
*local_err
= NULL
;
1820 sc_max
= SYSCONF_EXACT(_SC_NPROCESSORS_CONF
, &local_err
);
1822 while (local_err
== NULL
&& current
< sc_max
) {
1823 GuestLogicalProcessor
*vcpu
;
1824 GuestLogicalProcessorList
*entry
;
1826 vcpu
= g_malloc0(sizeof *vcpu
);
1827 vcpu
->logical_id
= current
++;
1828 vcpu
->has_can_offline
= true; /* lolspeak ftw */
1829 transfer_vcpu(vcpu
, true, &local_err
);
1831 entry
= g_malloc0(sizeof *entry
);
1832 entry
->value
= vcpu
;
1835 link
= &entry
->next
;
1838 if (local_err
== NULL
) {
1839 /* there's no guest with zero VCPUs */
1840 g_assert(head
!= NULL
);
1844 qapi_free_GuestLogicalProcessorList(head
);
1845 error_propagate(errp
, local_err
);
1849 int64_t qmp_guest_set_vcpus(GuestLogicalProcessorList
*vcpus
, Error
**errp
)
1852 Error
*local_err
= NULL
;
1855 while (vcpus
!= NULL
) {
1856 transfer_vcpu(vcpus
->value
, false, &local_err
);
1857 if (local_err
!= NULL
) {
1861 vcpus
= vcpus
->next
;
1864 if (local_err
!= NULL
) {
1865 if (processed
== 0) {
1866 error_propagate(errp
, local_err
);
1868 error_free(local_err
);
1875 #else /* defined(__linux__) */
1877 void qmp_guest_suspend_disk(Error
**errp
)
1879 error_set(errp
, QERR_UNSUPPORTED
);
1882 void qmp_guest_suspend_ram(Error
**errp
)
1884 error_set(errp
, QERR_UNSUPPORTED
);
1887 void qmp_guest_suspend_hybrid(Error
**errp
)
1889 error_set(errp
, QERR_UNSUPPORTED
);
1892 GuestNetworkInterfaceList
*qmp_guest_network_get_interfaces(Error
**errp
)
1894 error_set(errp
, QERR_UNSUPPORTED
);
1898 GuestLogicalProcessorList
*qmp_guest_get_vcpus(Error
**errp
)
1900 error_set(errp
, QERR_UNSUPPORTED
);
1904 int64_t qmp_guest_set_vcpus(GuestLogicalProcessorList
*vcpus
, Error
**errp
)
1906 error_set(errp
, QERR_UNSUPPORTED
);
1912 #if !defined(CONFIG_FSFREEZE)
1914 GuestFilesystemInfoList
*qmp_guest_get_fsinfo(Error
**errp
)
1916 error_set(errp
, QERR_UNSUPPORTED
);
1920 GuestFsfreezeStatus
qmp_guest_fsfreeze_status(Error
**errp
)
1922 error_set(errp
, QERR_UNSUPPORTED
);
1927 int64_t qmp_guest_fsfreeze_freeze(Error
**errp
)
1929 error_set(errp
, QERR_UNSUPPORTED
);
1934 int64_t qmp_guest_fsfreeze_freeze_list(bool has_mountpoints
,
1935 strList
*mountpoints
,
1938 error_set(errp
, QERR_UNSUPPORTED
);
1943 int64_t qmp_guest_fsfreeze_thaw(Error
**errp
)
1945 error_set(errp
, QERR_UNSUPPORTED
);
1949 #endif /* CONFIG_FSFREEZE */
1951 #if !defined(CONFIG_FSTRIM)
1952 void qmp_guest_fstrim(bool has_minimum
, int64_t minimum
, Error
**errp
)
1954 error_set(errp
, QERR_UNSUPPORTED
);
1958 /* add unsupported commands to the blacklist */
1959 GList
*ga_command_blacklist_init(GList
*blacklist
)
1961 #if !defined(__linux__)
1963 const char *list
[] = {
1964 "guest-suspend-disk", "guest-suspend-ram",
1965 "guest-suspend-hybrid", "guest-network-get-interfaces",
1966 "guest-get-vcpus", "guest-set-vcpus", NULL
};
1967 char **p
= (char **)list
;
1970 blacklist
= g_list_append(blacklist
, *p
++);
1975 #if !defined(CONFIG_FSFREEZE)
1977 const char *list
[] = {
1978 "guest-get-fsinfo", "guest-fsfreeze-status",
1979 "guest-fsfreeze-freeze", "guest-fsfreeze-freeze-list",
1980 "guest-fsfreeze-thaw", "guest-get-fsinfo", NULL
};
1981 char **p
= (char **)list
;
1984 blacklist
= g_list_append(blacklist
, *p
++);
1989 #if !defined(CONFIG_FSTRIM)
1990 blacklist
= g_list_append(blacklist
, (char *)"guest-fstrim");
1996 /* register init/cleanup routines for stateful command groups */
1997 void ga_command_state_init(GAState
*s
, GACommandState
*cs
)
1999 #if defined(CONFIG_FSFREEZE)
2000 ga_command_state_add(cs
, NULL
, guest_fsfreeze_cleanup
);
2002 ga_command_state_add(cs
, guest_file_init
, NULL
);