From nobody Mon Feb 9 12:11:01 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1538652948639954.8335456765992; Thu, 4 Oct 2018 04:35:48 -0700 (PDT) Received: from localhost ([::1]:55112 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g81v1-0005Cj-7j for importer@patchew.org; Thu, 04 Oct 2018 07:35:47 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34623) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g81ss-00040d-Im for qemu-devel@nongnu.org; Thu, 04 Oct 2018 07:33:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g81iU-0003Xp-Gn for qemu-devel@nongnu.org; Thu, 04 Oct 2018 07:22:54 -0400 Received: from mail-wr1-f47.google.com ([209.85.221.47]:34569) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1g81iU-0003XU-A2 for qemu-devel@nongnu.org; Thu, 04 Oct 2018 07:22:50 -0400 Received: by mail-wr1-f47.google.com with SMTP id z4-v6so9494304wrb.1 for ; Thu, 04 Oct 2018 04:22:50 -0700 (PDT) Received: from fiorina.brq.redhat.com (nat-pool-brq-t.redhat.com. [213.175.37.10]) by smtp.gmail.com with ESMTPSA id k7-v6sm5191789wmf.41.2018.10.04.04.22.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 04 Oct 2018 04:22:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=M4yuVoO3GFIGu6gJwnJT1Ygm3YJ614FqON2WvFD/AFo=; b=YRTVudr9ExU3gwnr79/ywNzS8R4KuZ/nvJ2Hp0ABIhCNchvb/NPQ1gY+Ms8LtNaRw2 DWtKZrsHfQ4tRhvLUKPnCTBsNWsZLok8bRPuL0PU9+9gCscFHdaZRvKgtlmdhRzWc6pR QFhk76zwWTiyDW+V+qLAgAQXa2qBoRbNYq/3PuvdDwv8CJfR/ofvD50LCKoAUcbONxSH 7wOxaEaM/06G2oPocG1vkqB5O73WxTLa+plWQojjTsb5Rkr9YihMDlfEJoObIKB1zfcq gnj/nRN7J/ozcEjxi/xiQdFzAOLSH6TmM4WCOb8o8ctcoEcJLw+VfxRxZO6H/eWIL9O7 Icjg== X-Gm-Message-State: ABuFfojuIS6JLOLGHxZxYZIhTeZzAyatH8N3QpZ1HyX9rS7pSHdMU/KM lMQ7im+jg7iUDwpb3XZUTCu6P9ib+iU= X-Google-Smtp-Source: ACcGV60mfZuqtF3YUMVas7VUoLEHJQnp0CTakLq+tXPecglNpKfljLD3RAxC76o7uXi9n+v2CGE8dQ== X-Received: by 2002:adf:a352:: with SMTP id d18-v6mr4428282wrb.31.1538652168917; Thu, 04 Oct 2018 04:22:48 -0700 (PDT) From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Golembiovsk=C3=BD?= To: qemu-devel@nongnu.org Date: Thu, 4 Oct 2018 13:22:34 +0200 Message-Id: <54f53859b73142e6264c948ff8a8e70616baf268.1538652143.git.tgolembi@redhat.com> X-Mailer: git-send-email 2.19.0 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.85.221.47 Subject: [Qemu-devel] [PATCH v4 07/11] qga: report disk serial number X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Roth , Olga Krishtal , =?UTF-8?q?Tom=C3=A1=C5=A1=20Golembiovsk=C3=BD?= , Sameeh Jubran , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 The feature is implemented for Windows and Linux. Reporting of serial number on Linux depends on libudev. Example from Linux: { "name": "dm-2", "mountpoint": "/", ... "disk": [ { "serial": "SAMSUNG_MZ7LN512HCHP-000L1_S1ZKNXAG822493", ... } ], } Signed-off-by: Tom=C3=A1=C5=A1 Golembiovsk=C3=BD --- qga/Makefile.objs | 1 + qga/commands-posix.c | 27 +++++++++++++++++++++++++++ qga/commands-win32.c | 24 ++++++++++++++++++++++++ qga/qapi-schema.json | 4 +++- 4 files changed, 55 insertions(+), 1 deletion(-) diff --git a/qga/Makefile.objs b/qga/Makefile.objs index ed08c5917c..80e6bb3c2e 100644 --- a/qga/Makefile.objs +++ b/qga/Makefile.objs @@ -1,3 +1,4 @@ +commands-posix.o-libs :=3D $(LIBUDEV_LIBS) qga-obj-y =3D commands.o guest-agent-command-state.o main.o qga-obj-$(CONFIG_POSIX) +=3D commands-posix.o channel-posix.o qga-obj-$(CONFIG_WIN32) +=3D commands-win32.o channel-win32.o service-win3= 2.o diff --git a/qga/commands-posix.c b/qga/commands-posix.c index 37e8a2d791..4d324178f2 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -48,6 +48,10 @@ extern char **environ; #include #include =20 +#ifdef CONFIG_LIBUDEV +#include +#endif + #ifdef FIFREEZE #define CONFIG_FSFREEZE #endif @@ -872,6 +876,10 @@ static void build_guest_fsinfo_for_real_device(char co= nst *syspath, GuestDiskAddressList *list =3D NULL; bool has_ata =3D false, has_host =3D false, has_tgt =3D false; char *p, *q, *driver =3D NULL; +#ifdef CONFIG_LIBUDEV + struct udev *udev =3D NULL; + struct udev_device *udevice =3D NULL; +#endif =20 p =3D strstr(syspath, "/devices/pci"); 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 co= nst *syspath, list =3D g_malloc0(sizeof(*list)); list->value =3D disk; =20 +#ifdef CONFIG_LIBUDEV + udev =3D udev_new(); + udevice =3D udev_device_new_from_syspath(udev, syspath); + if (udev =3D=3D NULL || udevice =3D=3D NULL) { + g_debug("failed to query udev"); + } else { + const char *serial; + serial =3D udev_device_get_property_value(udevice, "ID_SERIAL"); + if (serial !=3D NULL && *serial !=3D 0) { + disk->serial =3D g_strdup(serial); + disk->has_serial =3D true; + } + } +#endif + if (strcmp(driver, "ata_piix") =3D=3D 0) { /* a host per ide bus, target*:0::0 */ if (!has_host || !has_tgt) { @@ -1003,6 +1026,10 @@ cleanup: qapi_free_GuestDiskAddressList(list); } g_free(driver); +#ifdef CONFIG_LIBUDEV + udev_unref(udev); + udev_device_unref(udevice); +#endif } =20 static void build_guest_fsinfo_for_device(char const *devpath, diff --git a/qga/commands-win32.c b/qga/commands-win32.c index d7864fc65a..376ca1e288 100644 --- a/qga/commands-win32.c +++ b/qga/commands-win32.c @@ -603,6 +603,30 @@ static void get_disk_properties(HANDLE vol_h, GuestDis= kAddress *disk, } disk->bus_type =3D find_bus_type(dev_desc->BusType); g_debug("bus type %d", disk->bus_type); + + /* Query once more. Now with long enough buffer. */ + size =3D dev_desc->Size; + dev_desc =3D g_malloc0(size); + if (!DeviceIoControl(vol_h, IOCTL_STORAGE_QUERY_PROPERTY, &query, + sizeof(STORAGE_PROPERTY_QUERY), dev_desc, + size, &received, NULL)) { + error_setg_win32(errp, GetLastError(), "failed to get serial numbe= r"); + goto out_free; + } + if (dev_desc->SerialNumberOffset > 0) { + if (dev_desc->SerialNumberOffset >=3D received) { + error_setg(errp, "offset outside the buffer"); + goto out_free; + } + const char *serial =3D (char *)dev_desc + dev_desc->SerialNumberOf= fset; + size_t len =3D received - dev_desc->SerialNumberOffset; + if (*serial !=3D 0) { + disk->serial =3D g_strndup(serial, len); + disk->has_serial =3D true; + g_debug("serial number %s", disk->serial); + } + } +out_free: g_free(dev_desc); =20 return; diff --git a/qga/qapi-schema.json b/qga/qapi-schema.json index dfbc4a5e32..3bcda6257e 100644 --- a/qga/qapi-schema.json +++ b/qga/qapi-schema.json @@ -834,13 +834,15 @@ # @bus: bus id # @target: target id # @unit: unit id +# @serial: serial number (since: 3.1) # # Since: 2.2 ## { 'struct': 'GuestDiskAddress', 'data': {'pci-controller': 'GuestPCIAddress', 'bus-type': 'GuestDiskBusType', - 'bus': 'int', 'target': 'int', 'unit': 'int'} } + 'bus': 'int', 'target': 'int', 'unit': 'int', + '*serial': 'str'} } =20 ## # @GuestFilesystemInfo: --=20 2.19.0