From nobody Thu Nov 6 12:13:08 2025 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; dkim=fail; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1540912515429650.2575195934534; Tue, 30 Oct 2018 08:15:15 -0700 (PDT) Received: from localhost ([::1]:53815 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHVje-0004V5-6X for importer@patchew.org; Tue, 30 Oct 2018 11:15:14 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46561) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHVH4-0008Lm-BV for qemu-devel@nongnu.org; Tue, 30 Oct 2018 10:45:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gHVGw-0001KU-6l for qemu-devel@nongnu.org; Tue, 30 Oct 2018 10:45:41 -0400 Received: from mail-qt1-x831.google.com ([2607:f8b0:4864:20::831]:35642) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gHVGn-00019g-Ql for qemu-devel@nongnu.org; Tue, 30 Oct 2018 10:45:26 -0400 Received: by mail-qt1-x831.google.com with SMTP id a10-v6so13733158qtp.2 for ; Tue, 30 Oct 2018 07:45:25 -0700 (PDT) Received: from localhost (76-251-165-188.lightspeed.austtx.sbcglobal.net. [76.251.165.188]) by smtp.gmail.com with ESMTPSA id g83-v6sm3075074qkb.57.2018.10.30.07.45.22 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 30 Oct 2018 07:45:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ANbaKq6jbZhZybVA7mJIDsdQslcijwVNxDlVYklzAFc=; b=YKhgT87ke3mHFyG74ss+Xsqkuatn6H7jidZGYQT2IRJHc6ky80PUW2dCvT+f9d54tq atv/0eDX9y3moCh8kAqB/w7pRKm7OGjQ4Ta5fN+Ee5uNoP/EKknrZk+FYzW94RnGoblp EEHneF+9cRoEeCeMBmbjDH1vds9XfkZUTLHW0aGgKiCts8YHRyf539g/Xuo7fQf5JQMb V14ScQ03Xsvyk9rMlIyM9qYCP7AVqimebdtpYD3zQafCVi22mbElNycH9wQFcD+QXThK Q6sXNi8mQrQGGZdWEU4pby2otanOAamhjtXRYm8wd0wTOqOrz1ckPHa1Gp3c+shV5agd aWEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=ANbaKq6jbZhZybVA7mJIDsdQslcijwVNxDlVYklzAFc=; b=fzup7PlvuNpNhqWIuDnDUQdxlxLqW2FsEkblRWsZn/4T+5KqRKRnktilL9ujIlbvzs HFkoZAKpXthXqyqbFTtHOBD3SaHnoaGtB5TKhkLwQQU7xoa53kKMPwAWy6JNsQDhJPXC 913u7HwLgA7fQBUY7TM0yiVFWB39/7DPXhYAVpDVZNdCLbTxe01bSOYByjXgIrfHynq5 zPcVdL17f7Zn1bxti75BDjjRHjUPprBLifh+MD576LVcfeoif46mFMLtPyBLVj+iSYvq /W16/Q1Rl4pjsbv1VHfivVsRTWI/eO1LzjVT8G9Ad2xLjDmjWOPw/Gvc6Ubuc5bcm+jP DoZQ== X-Gm-Message-State: AGRZ1gKAxgBE/xZgETl8+7+PI/6p7vAMykxfaI/U428FrJcsugNRT6xL hU68+xql7WeTGgS8RqO7bgHiVSGD X-Google-Smtp-Source: AJdET5fBPh/92WaQwlxQ+L0LcV2h+Es8wtL+fPACjWJ5BqEbYjnJiC1CddC1BYBiCCyopFdZAnSqiw== X-Received: by 2002:a0c:b0c3:: with SMTP id p3mr16994882qvc.174.1540910724040; Tue, 30 Oct 2018 07:45:24 -0700 (PDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Tue, 30 Oct 2018 09:43:39 -0500 Message-Id: <20181030144358.23144-6-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181030144358.23144-1-mdroth@linux.vnet.ibm.com> References: <20181030144358.23144-1-mdroth@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::831 Subject: [Qemu-devel] [PULL 05/24] qga: linux: 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: peter.maydell@linaro.org, =?UTF-8?q?Tom=C3=A1=C5=A1=20Golembiovsk=C3=BD?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: Tom=C3=A1=C5=A1 Golembiovsk=C3=BD 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=C3=A1=C5=A1 Golembiovsk=C3=BD Signed-off-by: Michael Roth --- qga/Makefile.objs | 1 + qga/commands-posix.c | 32 ++++++++++++++++++++++++++++++-- qga/qapi-schema.json | 4 +++- 3 files changed, 34 insertions(+), 3 deletions(-) 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 42d30f078e..41bd11b2b5 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) { @@ -995,14 +1018,19 @@ static void build_guest_fsinfo_for_real_device(char = const *syspath, =20 list->next =3D fs->disk; fs->disk =3D list; - g_free(driver); - return; + goto out; =20 cleanup: if (list) { qapi_free_GuestDiskAddressList(list); } +out: g_free(driver); +#ifdef CONFIG_LIBUDEV + udev_unref(udev); + udev_device_unref(udevice); +#endif + return; } =20 static void build_guest_fsinfo_for_device(char const *devpath, 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.17.1