aboutsummaryrefslogtreecommitdiff
path: root/qga/commands-posix.c
diff options
context:
space:
mode:
authorPeter Maydell <peter.maydell@linaro.org>2018-11-01 17:26:16 +0000
committerPeter Maydell <peter.maydell@linaro.org>2018-11-01 17:26:16 +0000
commitf96a3165ab1c36dbf4cb63e8761fa45457381aca (patch)
treea205d410506d616e109976d94675bf450df2fd90 /qga/commands-posix.c
parent00878c95165de8ffc015a43e14249d789de1b8ff (diff)
parentb70d6afe4d7f252259d3344e12daa2d6baf006e2 (diff)
Merge remote-tracking branch 'remotes/mdroth/tags/qga-pull-2018-10-30-v3-tag' into staging
qemu-ga patch queue for soft-freeze * support for --retry-path option for recovering from communication path failures * support for serial/device name in guest-get-fsinfo for linux/w32 * support for freezing individual mount points in guest-fsfreeze-* * fixes for unicode paths on w32, not-present vcpus in guest-get-vcpus, buffer overflow in guest-get-fsinfo for w32, and other minor fixes v3: * remove redundant check for --static in configure * correct authorship on "qga-win: add debugging information" v2: * set libudev=off in configure for static builds # gpg: Signature made Wed 31 Oct 2018 14:13:58 GMT # gpg: using RSA key 3353C9CEF108B584 # gpg: Good signature from "Michael Roth <flukshun@gmail.com>" # gpg: aka "Michael Roth <mdroth@utexas.edu>" # gpg: aka "Michael Roth <mdroth@linux.vnet.ibm.com>" # Primary key fingerprint: CEAC C9E1 5534 EBAB B82D 3FA0 3353 C9CE F108 B584 * remotes/mdroth/tags/qga-pull-2018-10-30-v3-tag: (24 commits) qga-win: changing --retry-path option behavior qga-win: report specific error when failing to open channel qga-win: install service with --retry-path set by default qga: add --retry-path option for re-initializing channel on failure qga: move w32 service handling out of run_agent() qga: hang GAConfig/socket_activation off of GAState global qga: group agent init/cleanup init separate routines qga: fix an off-by-one issue qga-win: demystify namespace stripping qga-win: return disk device in guest-get-fsinfo qga-win: handle multi-disk volumes qga-win: refactor disk info qga-win: report disk serial number qga-win: refactor disk properties (bus) qga-win: add debugging information build: rename CONFIG_QGA_NTDDDISK to CONFIG_QGA_NTDDSCSI qga-win: fsinfo: pci-info: allow partial info qga-win: prevent crash when executing fsinfo command qga: linux: return disk device in guest-get-fsinfo qga: linux: report disk serial number ... Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'qga/commands-posix.c')
-rw-r--r--qga/commands-posix.c152
1 files changed, 94 insertions, 58 deletions
diff --git a/qga/commands-posix.c b/qga/commands-posix.c
index 37e8a2d791..1877976522 100644
--- a/qga/commands-posix.c
+++ b/qga/commands-posix.c
@@ -48,6 +48,10 @@ extern char **environ;
#include <net/if.h>
#include <sys/statvfs.h>
+#ifdef CONFIG_LIBUDEV
+#include <libudev.h>
+#endif
+
#ifdef FIFREEZE
#define CONFIG_FSFREEZE
#endif
@@ -872,6 +876,10 @@ static void build_guest_fsinfo_for_real_device(char const *syspath,
GuestDiskAddressList *list = NULL;
bool has_ata = false, has_host = false, has_tgt = false;
char *p, *q, *driver = NULL;
+#ifdef CONFIG_LIBUDEV
+ struct udev *udev = NULL;
+ struct udev_device *udevice = NULL;
+#endif
p = strstr(syspath, "/devices/pci");
if (!p || sscanf(p + 12, "%*x:%*x/%x:%x:%x.%x%n",
@@ -936,6 +944,26 @@ static void build_guest_fsinfo_for_real_device(char const *syspath,
list = g_malloc0(sizeof(*list));
list->value = disk;
+#ifdef CONFIG_LIBUDEV
+ udev = udev_new();
+ udevice = udev_device_new_from_syspath(udev, syspath);
+ if (udev == NULL || udevice == NULL) {
+ g_debug("failed to query udev");
+ } else {
+ const char *devnode, *serial;
+ devnode = udev_device_get_devnode(udevice);
+ if (devnode != NULL) {
+ disk->dev = g_strdup(devnode);
+ disk->has_dev = true;
+ }
+ serial = udev_device_get_property_value(udevice, "ID_SERIAL");
+ if (serial != NULL && *serial != 0) {
+ disk->serial = g_strdup(serial);
+ disk->has_serial = true;
+ }
+ }
+#endif
+
if (strcmp(driver, "ata_piix") == 0) {
/* a host per ide bus, target*:0:<unit>:0 */
if (!has_host || !has_tgt) {
@@ -995,14 +1023,19 @@ static void build_guest_fsinfo_for_real_device(char const *syspath,
list->next = fs->disk;
fs->disk = list;
- g_free(driver);
- return;
+ goto out;
cleanup:
if (list) {
qapi_free_GuestDiskAddressList(list);
}
+out:
g_free(driver);
+#ifdef CONFIG_LIBUDEV
+ udev_unref(udev);
+ udev_device_unref(udevice);
+#endif
+ return;
}
static void build_guest_fsinfo_for_device(char const *devpath,
@@ -2035,61 +2068,56 @@ static long sysconf_exact(int name, const char *name_str, Error **errp)
* Written members remain unmodified on error.
*/
static void transfer_vcpu(GuestLogicalProcessor *vcpu, bool sys2vcpu,
- Error **errp)
+ char *dirpath, Error **errp)
{
- char *dirpath;
+ int fd;
+ int res;
int dirfd;
+ static const char fn[] = "online";
- dirpath = g_strdup_printf("/sys/devices/system/cpu/cpu%" PRId64 "/",
- vcpu->logical_id);
dirfd = open(dirpath, O_RDONLY | O_DIRECTORY);
if (dirfd == -1) {
error_setg_errno(errp, errno, "open(\"%s\")", dirpath);
- } else {
- static const char fn[] = "online";
- int fd;
- int res;
-
- fd = openat(dirfd, fn, sys2vcpu ? O_RDONLY : O_RDWR);
- if (fd == -1) {
- if (errno != ENOENT) {
- error_setg_errno(errp, errno, "open(\"%s/%s\")", dirpath, fn);
- } else if (sys2vcpu) {
- vcpu->online = true;
- vcpu->can_offline = false;
- } else if (!vcpu->online) {
- error_setg(errp, "logical processor #%" PRId64 " can't be "
- "offlined", vcpu->logical_id);
- } /* otherwise pretend successful re-onlining */
- } else {
- unsigned char status;
-
- res = pread(fd, &status, 1, 0);
- if (res == -1) {
- error_setg_errno(errp, errno, "pread(\"%s/%s\")", dirpath, fn);
- } else if (res == 0) {
- error_setg(errp, "pread(\"%s/%s\"): unexpected EOF", dirpath,
- fn);
- } else if (sys2vcpu) {
- vcpu->online = (status != '0');
- vcpu->can_offline = true;
- } else if (vcpu->online != (status != '0')) {
- status = '0' + vcpu->online;
- if (pwrite(fd, &status, 1, 0) == -1) {
- error_setg_errno(errp, errno, "pwrite(\"%s/%s\")", dirpath,
- fn);
- }
- } /* otherwise pretend successful re-(on|off)-lining */
+ return;
+ }
- res = close(fd);
- g_assert(res == 0);
- }
+ fd = openat(dirfd, fn, sys2vcpu ? O_RDONLY : O_RDWR);
+ if (fd == -1) {
+ if (errno != ENOENT) {
+ error_setg_errno(errp, errno, "open(\"%s/%s\")", dirpath, fn);
+ } else if (sys2vcpu) {
+ vcpu->online = true;
+ vcpu->can_offline = false;
+ } else if (!vcpu->online) {
+ error_setg(errp, "logical processor #%" PRId64 " can't be "
+ "offlined", vcpu->logical_id);
+ } /* otherwise pretend successful re-onlining */
+ } else {
+ unsigned char status;
+
+ res = pread(fd, &status, 1, 0);
+ if (res == -1) {
+ error_setg_errno(errp, errno, "pread(\"%s/%s\")", dirpath, fn);
+ } else if (res == 0) {
+ error_setg(errp, "pread(\"%s/%s\"): unexpected EOF", dirpath,
+ fn);
+ } else if (sys2vcpu) {
+ vcpu->online = (status != '0');
+ vcpu->can_offline = true;
+ } else if (vcpu->online != (status != '0')) {
+ status = '0' + vcpu->online;
+ if (pwrite(fd, &status, 1, 0) == -1) {
+ error_setg_errno(errp, errno, "pwrite(\"%s/%s\")", dirpath,
+ fn);
+ }
+ } /* otherwise pretend successful re-(on|off)-lining */
- res = close(dirfd);
+ res = close(fd);
g_assert(res == 0);
}
- g_free(dirpath);
+ res = close(dirfd);
+ g_assert(res == 0);
}
GuestLogicalProcessorList *qmp_guest_get_vcpus(Error **errp)
@@ -2107,17 +2135,21 @@ GuestLogicalProcessorList *qmp_guest_get_vcpus(Error **errp)
while (local_err == NULL && current < sc_max) {
GuestLogicalProcessor *vcpu;
GuestLogicalProcessorList *entry;
-
- vcpu = g_malloc0(sizeof *vcpu);
- vcpu->logical_id = current++;
- vcpu->has_can_offline = true; /* lolspeak ftw */
- transfer_vcpu(vcpu, true, &local_err);
-
- entry = g_malloc0(sizeof *entry);
- entry->value = vcpu;
-
- *link = entry;
- link = &entry->next;
+ int64_t id = current++;
+ char *path = g_strdup_printf("/sys/devices/system/cpu/cpu%" PRId64 "/",
+ id);
+
+ if (g_file_test(path, G_FILE_TEST_EXISTS)) {
+ vcpu = g_malloc0(sizeof *vcpu);
+ vcpu->logical_id = id;
+ vcpu->has_can_offline = true; /* lolspeak ftw */
+ transfer_vcpu(vcpu, true, path, &local_err);
+ entry = g_malloc0(sizeof *entry);
+ entry->value = vcpu;
+ *link = entry;
+ link = &entry->next;
+ }
+ g_free(path);
}
if (local_err == NULL) {
@@ -2138,7 +2170,11 @@ int64_t qmp_guest_set_vcpus(GuestLogicalProcessorList *vcpus, Error **errp)
processed = 0;
while (vcpus != NULL) {
- transfer_vcpu(vcpus->value, false, &local_err);
+ char *path = g_strdup_printf("/sys/devices/system/cpu/cpu%" PRId64 "/",
+ vcpus->value->logical_id);
+
+ transfer_vcpu(vcpus->value, false, path, &local_err);
+ g_free(path);
if (local_err != NULL) {
break;
}