qga: linux: report disk serial number
Add reporting of disk serial number on Linux guests. The feature depends on libudev. Example: { "name": "dm-2", "mountpoint": "/", ... "disk": [ { "serial": "SAMSUNG_MZ7LN512HCHP-000L1_S1ZKNXAG822493", ... } ], } Signed-off-by: Tomáš Golembiovský <tgolembi@redhat.com> Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
This commit is contained in:
parent
3efac6ebb8
commit
b616105a90
|
@ -1,3 +1,4 @@
|
||||||
|
commands-posix.o-libs := $(LIBUDEV_LIBS)
|
||||||
qga-obj-y = commands.o guest-agent-command-state.o main.o
|
qga-obj-y = commands.o guest-agent-command-state.o main.o
|
||||||
qga-obj-$(CONFIG_POSIX) += commands-posix.o channel-posix.o
|
qga-obj-$(CONFIG_POSIX) += commands-posix.o channel-posix.o
|
||||||
qga-obj-$(CONFIG_WIN32) += commands-win32.o channel-win32.o service-win32.o
|
qga-obj-$(CONFIG_WIN32) += commands-win32.o channel-win32.o service-win32.o
|
||||||
|
|
|
@ -48,6 +48,10 @@ extern char **environ;
|
||||||
#include <net/if.h>
|
#include <net/if.h>
|
||||||
#include <sys/statvfs.h>
|
#include <sys/statvfs.h>
|
||||||
|
|
||||||
|
#ifdef CONFIG_LIBUDEV
|
||||||
|
#include <libudev.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef FIFREEZE
|
#ifdef FIFREEZE
|
||||||
#define CONFIG_FSFREEZE
|
#define CONFIG_FSFREEZE
|
||||||
#endif
|
#endif
|
||||||
|
@ -872,6 +876,10 @@ static void build_guest_fsinfo_for_real_device(char const *syspath,
|
||||||
GuestDiskAddressList *list = NULL;
|
GuestDiskAddressList *list = NULL;
|
||||||
bool has_ata = false, has_host = false, has_tgt = false;
|
bool has_ata = false, has_host = false, has_tgt = false;
|
||||||
char *p, *q, *driver = NULL;
|
char *p, *q, *driver = NULL;
|
||||||
|
#ifdef CONFIG_LIBUDEV
|
||||||
|
struct udev *udev = NULL;
|
||||||
|
struct udev_device *udevice = NULL;
|
||||||
|
#endif
|
||||||
|
|
||||||
p = strstr(syspath, "/devices/pci");
|
p = strstr(syspath, "/devices/pci");
|
||||||
if (!p || sscanf(p + 12, "%*x:%*x/%x:%x:%x.%x%n",
|
if (!p || sscanf(p + 12, "%*x:%*x/%x:%x:%x.%x%n",
|
||||||
|
@ -936,6 +944,21 @@ static void build_guest_fsinfo_for_real_device(char const *syspath,
|
||||||
list = g_malloc0(sizeof(*list));
|
list = g_malloc0(sizeof(*list));
|
||||||
list->value = disk;
|
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 *serial;
|
||||||
|
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) {
|
if (strcmp(driver, "ata_piix") == 0) {
|
||||||
/* a host per ide bus, target*:0:<unit>:0 */
|
/* a host per ide bus, target*:0:<unit>:0 */
|
||||||
if (!has_host || !has_tgt) {
|
if (!has_host || !has_tgt) {
|
||||||
|
@ -995,14 +1018,19 @@ static void build_guest_fsinfo_for_real_device(char const *syspath,
|
||||||
|
|
||||||
list->next = fs->disk;
|
list->next = fs->disk;
|
||||||
fs->disk = list;
|
fs->disk = list;
|
||||||
g_free(driver);
|
goto out;
|
||||||
return;
|
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
if (list) {
|
if (list) {
|
||||||
qapi_free_GuestDiskAddressList(list);
|
qapi_free_GuestDiskAddressList(list);
|
||||||
}
|
}
|
||||||
|
out:
|
||||||
g_free(driver);
|
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,
|
static void build_guest_fsinfo_for_device(char const *devpath,
|
||||||
|
|
|
@ -834,13 +834,15 @@
|
||||||
# @bus: bus id
|
# @bus: bus id
|
||||||
# @target: target id
|
# @target: target id
|
||||||
# @unit: unit id
|
# @unit: unit id
|
||||||
|
# @serial: serial number (since: 3.1)
|
||||||
#
|
#
|
||||||
# Since: 2.2
|
# Since: 2.2
|
||||||
##
|
##
|
||||||
{ 'struct': 'GuestDiskAddress',
|
{ 'struct': 'GuestDiskAddress',
|
||||||
'data': {'pci-controller': 'GuestPCIAddress',
|
'data': {'pci-controller': 'GuestPCIAddress',
|
||||||
'bus-type': 'GuestDiskBusType',
|
'bus-type': 'GuestDiskBusType',
|
||||||
'bus': 'int', 'target': 'int', 'unit': 'int'} }
|
'bus': 'int', 'target': 'int', 'unit': 'int',
|
||||||
|
'*serial': 'str'} }
|
||||||
|
|
||||||
##
|
##
|
||||||
# @GuestFilesystemInfo:
|
# @GuestFilesystemInfo:
|
||||||
|
|
Loading…
Reference in New Issue