From nobody Sat May 4 12:37:49 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1599470219; cv=none; d=zohomail.com; s=zohoarc; b=deB5PBp+ponviUpYzjUVwCZAuy2I8kvOFoZvYQo96CFCAJbqmfBddEsRnIQqqQpnzWQF5y32lv26G74zxDc2DanxDkD8xFfCOcV4DUt4IdwJBjfef5d6ZuYXuBYAZZhEfntmy3F7jmnfnq3aQPvYpLYf8QswKeXZPHX56JSEOHY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1599470219; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=7iaVzSDtj2xbAOGzu8HgRwFZokiSOmmlRvyGqNZEfqc=; b=BYiHoMQ9HeoACRoezlPxJtrbx/PIBPZpqPW8YC9TWq7ptzvCtl96YucD22LhU9VF/4I2Pd0q7IoKSSwddrYlOHnVhV2tnYsJ25YX38RZaeJ0X5uCEpHO4l+eobFWLG+q95raoNWNh4LgWhxruTvYr/Re2A+bQ38/dcPuW+AgpHw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1599470219280289.2644644638443; Mon, 7 Sep 2020 02:16:59 -0700 (PDT) Received: from localhost ([::1]:52620 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kFDGk-0004SQ-0s for importer@patchew.org; Mon, 07 Sep 2020 05:16:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33468) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kFDEh-00029x-8E for qemu-devel@nongnu.org; Mon, 07 Sep 2020 05:14:51 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:34645 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kFDEf-00029K-JT for qemu-devel@nongnu.org; Mon, 07 Sep 2020 05:14:50 -0400 Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com [209.85.218.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-80-KrRulgA6N_Ow0ivwQE3YwA-1; Mon, 07 Sep 2020 05:14:46 -0400 Received: by mail-ej1-f72.google.com with SMTP id qn7so5403461ejb.15 for ; Mon, 07 Sep 2020 02:14:46 -0700 (PDT) Received: from auriga.localdomain (ip-89-176-41-222.net.upcbroadband.cz. [89.176.41.222]) by smtp.gmail.com with ESMTPSA id d6sm14394910edm.31.2020.09.07.02.14.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Sep 2020 02:14:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1599470088; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7iaVzSDtj2xbAOGzu8HgRwFZokiSOmmlRvyGqNZEfqc=; b=f1AK9ailv4wdYNPNKjRzyaoMgB6+0pMHeN2IVkzXTKK9rMJzwPW3NCotLL8J60rMixRZ1c lMD9MWQEFXhPxiIwHMaSG0UkTXx3yEXCqOqDaYrhalOW7BDEa7lA3ce4DhteTrVsumE6+4 SM6qWtpCKtzksYMPyWKIR2aQWOw4QoE= X-MC-Unique: KrRulgA6N_Ow0ivwQE3YwA-1 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=7iaVzSDtj2xbAOGzu8HgRwFZokiSOmmlRvyGqNZEfqc=; b=m86q7PatDGNnZd9Lg106ARcuAcCz8eFaVKAxM/g+t08UaQl17Yixmjp8Z8mJNpvg5p MTjx9XYFUnQamX9medpJ+QIwoQTfaxZkNTgPpi/c4g4sM88bYZRo7coSWc0lwC+tsjrA JOnld/VZyMi99UexzHWsoiSfBYmIxP2okFYX/mlpOBJtfemdEbQ0NLvfgYaPmlG8MAh5 X7kcCfvpZO1Wqz44A6aDj8/uO2+RzPF1exOg2caRS6yfewqZN9FhvQe899a+zt7SPfuu 67dMB/qtDmRaQcfJTokbTtA55LaumXQGHL6BmveLlrGoMGGTDNxi5Dej/oSnMJxtJ9fD cFHg== X-Gm-Message-State: AOAM530RcG+AYo2idp1uekgrjm+y8JrnVHFXZa7yXF+aMBE3Q6d3EWap Z/SMB/ZpfTcapZ6K4kkwXFDX/3qxcdcHDSdnpCnpIFUSJPbxJksH09Wqivlo8hO29rpxr8GVhvh IwWs7Yf/bhWoIfmc= X-Received: by 2002:a17:906:fb97:: with SMTP id lr23mr6005031ejb.257.1599470085126; Mon, 07 Sep 2020 02:14:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw7Zp9W/F8N2Z7zj9RxiSnDWn1ywIjqD6re3HipxXVSvZZmt7EnfCJjvdeXOmExYKdzVJKyuA== X-Received: by 2002:a17:906:fb97:: with SMTP id lr23mr6005018ejb.257.1599470084895; Mon, 07 Sep 2020 02:14:44 -0700 (PDT) From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Golembiovsk=C3=BD?= To: Michael Roth , Thomas Huth , qemu-devel@nongnu.org Subject: [PATCH v2 1/3] qga: add command guest-get-disks Date: Mon, 7 Sep 2020 11:14:40 +0200 Message-Id: X-Mailer: git-send-email 2.25.0 In-Reply-To: References: MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=tgolembi@redhat.com X-Mimecast-Spam-Score: 0.002 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=205.139.110.120; envelope-from=tgolembi@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/07 03:19:10 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.099, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?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: pass (identity @redhat.com) Add API and stubs for new guest-get-disks command. The command guest-get-fsinfo can be used to list information about disks and partitions but it is limited only to mounted disks with filesystem. This new command should allow listing information about disks of the VM regardles whether they are mounted or not. This can be usefull for management applications for mapping virtualized devices or pass-through devices to device names in the guest OS. Signed-off-by: Tom=C3=A1=C5=A1 Golembiovsk=C3=BD Reviewed-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- qga/commands-posix.c | 6 ++++++ qga/commands-win32.c | 6 ++++++ qga/qapi-schema.json | 29 +++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+) diff --git a/qga/commands-posix.c b/qga/commands-posix.c index 744c2b5a5d..f99731af51 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -3042,3 +3042,9 @@ GuestOSInfo *qmp_guest_get_osinfo(Error **errp) =20 return info; } + +GuestDiskInfoList *qmp_guest_get_disks(Error **errp) +{ + error_setg(errp, QERR_UNSUPPORTED); + return NULL; +} diff --git a/qga/commands-win32.c b/qga/commands-win32.c index aaa71f147b..e9976a0c46 100644 --- a/qga/commands-win32.c +++ b/qga/commands-win32.c @@ -2229,3 +2229,9 @@ GuestOSInfo *qmp_guest_get_osinfo(Error **errp) =20 return info; } + +GuestDiskInfoList *qmp_guest_get_disks(Error **errp) +{ + error_setg(errp, QERR_UNSUPPORTED); + return NULL; +} diff --git a/qga/qapi-schema.json b/qga/qapi-schema.json index 408a662ea5..70b54e0d07 100644 --- a/qga/qapi-schema.json +++ b/qga/qapi-schema.json @@ -862,6 +862,35 @@ 'bus': 'int', 'target': 'int', 'unit': 'int', '*serial': 'str', '*dev': 'str'} } =20 +## +# @GuestDiskInfo: +# +# @name: device node (Linux) or device UNC (Windows) +# @partition: whether this is a partition or disk +# @slaves: list of slave devices (Linux) +# @address: disk address information (only for non-virtual devices) +# @alias: optional alias assigned to the disk, on Linux this is a name ass= igned +# by device mapper +# +# Since 5.2 +## +{ 'struct': 'GuestDiskInfo', + 'data': {'name': 'str', 'partition': 'bool', 'slaves': ['str'], + '*address': 'GuestDiskAddress', '*alias': 'str'} } + +## +# @guest-get-disks: +# +# Returns: The list of disks in the guest. For Windows these are only the +# physical disks. On Linux these are all root block devices of +# non-zero size including e.g. removable devices, loop devices, +# NBD, etc. +# +# Since: 5.2 +## +{ 'command': 'guest-get-disks', + 'returns': ['GuestDiskInfo'] } + ## # @GuestFilesystemInfo: # --=20 2.25.0 From nobody Sat May 4 12:37:49 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1599470285; cv=none; d=zohomail.com; s=zohoarc; b=KYe/0W8kvddOIJN/ETRaSGOUltH7kSr3RlNZkWEuaFEfXuh+mUbLxk7TpJ8qjJ1WLE0rpiUS7MCyBnL6EKzt6i32Knwm2dYCz99h+L1VZH82q14AjVJgv7BOgnrMHaN4j02/ndJkrfxjHiL65VMx+NRoHpk3oFfxHZ3tAmH2ApQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1599470285; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=79VWxHD2uYxnE8yhccOqd+75IUhDJGIdUzonpS82lS8=; b=NS2mZ74y1/XmWRVE2OjgeE9/nRU1IbVMDre9WCKEYe5YY58AfA1Lxjx4CU5IDuSiGC184mQGDIIJSgr1J+AziEQGD1D1VSZQJ4yEWEKm6NTlV1iUhzw9HLyNHt1sVAcBOMduxU0ZYjoy6o5JsxccqPQGjUYquwKNi6XPZg72qFA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1599470285115434.4085515188917; Mon, 7 Sep 2020 02:18:05 -0700 (PDT) Received: from localhost ([::1]:54806 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kFDHn-0005MI-CD for importer@patchew.org; Mon, 07 Sep 2020 05:18:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33488) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kFDEi-0002C0-PT for qemu-devel@nongnu.org; Mon, 07 Sep 2020 05:14:52 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:26898 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kFDEg-00029P-Jj for qemu-devel@nongnu.org; Mon, 07 Sep 2020 05:14:52 -0400 Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-73-9-lc0oOfPge1xciYH7D34w-1; Mon, 07 Sep 2020 05:14:47 -0400 Received: by mail-ed1-f70.google.com with SMTP id n4so4667765edo.20 for ; Mon, 07 Sep 2020 02:14:47 -0700 (PDT) Received: from auriga.localdomain (ip-89-176-41-222.net.upcbroadband.cz. [89.176.41.222]) by smtp.gmail.com with ESMTPSA id d6sm14394910edm.31.2020.09.07.02.14.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Sep 2020 02:14:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1599470089; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=79VWxHD2uYxnE8yhccOqd+75IUhDJGIdUzonpS82lS8=; b=hEb5YBie6VbUiwQjhMme2bxE2x+45EAVrDc8Z6rL7gmlJxStL9YzkV0eCdrV6Y/1hJPZwE kwKMxaCG++uBQmrN0nAQTPemb38c/7VpRts7b5xf1ULbAcx9+m3Rs34fslU1QVX30Qzx9S vsTmVaebNyNxRl7USC6eiD3c+R4fEFM= X-MC-Unique: 9-lc0oOfPge1xciYH7D34w-1 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=79VWxHD2uYxnE8yhccOqd+75IUhDJGIdUzonpS82lS8=; b=JPohjt+B/0y22wW+mRHCCuzPe/u0cYg60X/XSzFz2+8fGGY6b9c9HEhpTC4YIY1cxI Uu77ELsGhVVsh9Ir+fvXCK3v4mXQgF/tVMLN32cLQjugDSpH/3fUHcTTx9S36Xz/E2bl xPtK7WHKX0gk0NVcy41mtKpQwJgMrG7fxXr1Nd9Ej+w4cx+cavfKUabqpIgFNuT1i3IL Dlq4qGiYcoByMui4FzAnmkbR2fSrEmmTeen2ivTEGtfKLFdaRB9CbbyGcPPD9KOTsL33 PSWjr9iHQEd0PxlL3TJQpldahTS1uFVqkUM87HqXoYAJ5w0+RnufQDIid8oewKCiLJZF up3A== X-Gm-Message-State: AOAM530ievht7yksZJPSVshaL/jRobfVxgxsz77hPiddxAngUzcnkj9t sax5gi+AEudwOoqYc5ccKlFT85MYPm+35IlvjWM+VXeJX+wvaxMQCuQcHYc6Q3NlMQWOObhAQhk b7jOT8jvCpAlbET0= X-Received: by 2002:a17:906:5205:: with SMTP id g5mr19570267ejm.488.1599470086227; Mon, 07 Sep 2020 02:14:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw/dBszOMrEFWX44fPX4kBZNd3HoEE5LfaPNTKGBECNEWk5h+BphrAQQNsZ93XHh0FK7oC66A== X-Received: by 2002:a17:906:5205:: with SMTP id g5mr19570248ejm.488.1599470085998; Mon, 07 Sep 2020 02:14:45 -0700 (PDT) From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Golembiovsk=C3=BD?= To: Michael Roth , Thomas Huth , qemu-devel@nongnu.org Subject: [PATCH v2 2/3] qga: add implementation of guest-get-disks for Linux Date: Mon, 7 Sep 2020 11:14:41 +0200 Message-Id: <1bf9ede3b9273613319ff8ff99b40c385439cfa8.1599470071.git.tgolembi@redhat.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: References: MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=tgolembi@redhat.com X-Mimecast-Spam-Score: 0.002 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=207.211.31.81; envelope-from=tgolembi@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/06 22:29:02 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.099, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?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: pass (identity @redhat.com) The command lists all disks (real and virtual) as well as disk partitions. For each disk the list of slave disks is also listed and /dev path is used as a handle so it can be matched with "name" filed of other returned disk entries. For disk partitions the "slave" list is populated with the the parent device for easier tracking of hierarchy. Example output: { "return": [ ... { "name": "/dev/dm-0", "partition": false, "slaves": [ "/dev/sda2" ], "alias": "luks-7062202e-5b9b-433e-81e8-6628c40da9f7" }, { "name": "/dev/sda2", "partition": true, "slaves": [ "/dev/sda" ] }, { "name": "/dev/sda", "partition": false, "address": { "serial": "SAMSUNG_MZ7LN512HCHP-000L1_S1ZKNXAG822493", "bus-type": "sata", ... "dev": "/dev/sda", "target": 0 }, "slaves": [] }, ... ] } Signed-off-by: Tom=C3=A1=C5=A1 Golembiovsk=C3=BD --- qga/commands-posix.c | 247 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 240 insertions(+), 7 deletions(-) diff --git a/qga/commands-posix.c b/qga/commands-posix.c index f99731af51..3babc25c09 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -62,6 +62,9 @@ extern char **environ; #endif #endif =20 +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GuestFilesystemInfo, + qapi_free_GuestFilesystemInfo) + static void ga_wait_child(pid_t pid, int *status, Error **errp) { pid_t rpid; @@ -1150,6 +1153,21 @@ static void build_guest_fsinfo_for_virtual_device(ch= ar const *syspath, closedir(dir); } =20 +static bool is_disk_virtual(const char *devpath, Error **errp) +{ + g_autofree char *syspath =3D realpath(devpath, NULL); + + if (!syspath) { + error_setg_errno(errp, errno, "realpath(\"%s\")", devpath); + return false; + } + if (strstr(syspath, "/devices/virtual/block/")) { + return true; + } else { + return false; + } +} + /* Dispatch to functions for virtual/real device */ static void build_guest_fsinfo_for_device(char const *devpath, GuestFilesystemInfo *fs, @@ -1168,6 +1186,7 @@ static void build_guest_fsinfo_for_device(char const = *devpath, =20 g_debug(" parse sysfs path '%s'", syspath); =20 + /* TODO: use is_disk_virtual() */ if (strstr(syspath, "/devices/virtual/block/")) { build_guest_fsinfo_for_virtual_device(syspath, fs, errp); } else { @@ -1177,6 +1196,225 @@ static void build_guest_fsinfo_for_device(char cons= t *devpath, free(syspath); } =20 +#ifdef CONFIG_LIBUDEV + +/* + * Wrapper around build_guest_fsinfo_for_device() for getting just + * the disk address. + */ +static GuestDiskAddress *get_disk_address(const char *syspath, Error **err= p) +{ + g_autoptr(GuestFilesystemInfo) fs =3D NULL; + + fs =3D g_new0(GuestFilesystemInfo, 1); + build_guest_fsinfo_for_device(syspath, fs, errp); + if (fs->disk !=3D NULL) { + return g_steal_pointer(&fs->disk->value); + } + return NULL; +} + +static char *get_alias_for_syspath(const char *syspath) +{ + struct udev *udev =3D NULL; + struct udev_device *udevice =3D NULL; + char *ret =3D NULL; + + 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 *alias =3D udev_device_get_property_value( + udevice, "DM_NAME"); + if (alias !=3D NULL && *alias !=3D 0) { + ret =3D g_strdup(alias); + } + } + + udev_unref(udev); + udev_device_unref(udevice); + return ret; +} + +static char *get_device_for_syspath(const char *syspath) +{ + struct udev *udev =3D NULL; + struct udev_device *udevice =3D NULL; + char *ret =3D NULL; + + 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 { + ret =3D g_strdup(udev_device_get_devnode(udevice)); + } + udev_unref(udev); + udev_device_unref(udevice); + return ret; +} + +GuestDiskInfoList *qmp_guest_get_disks(Error **errp) +{ + GuestDiskInfoList *item, *ret =3D NULL; + GuestDiskInfo *disk, *partition; + DIR *dp =3D NULL; + struct dirent *de =3D NULL; + + g_debug("listing /sys/block directory"); + dp =3D opendir("/sys/block"); + if (dp =3D=3D NULL) { + error_setg_errno(errp, errno, "Can't open directory \"/sys/block\"= "); + return NULL; + } + while ((de =3D readdir(dp)) !=3D NULL) { + g_autofree char *disk_dir =3D NULL, *line =3D NULL, + *size_dir =3D NULL, *slaves_dir =3D NULL; + struct dirent *de_disk, *de_slaves; + DIR *dp_disk =3D NULL, *dp_slaves =3D NULL; + FILE *fp =3D NULL; + size_t n =3D 0; + Error *local_err =3D NULL; + if (de->d_type !=3D DT_LNK) { + g_debug(" skipping entry: %s", de->d_name); + continue; + } + + /* Check size and skip zero-sized disks */ + g_debug(" checking disk size"); + size_dir =3D g_strdup_printf("/sys/block/%s/size", de->d_name); + fp =3D fopen(size_dir, "r"); + if (!fp) { + g_debug(" failed to read disk size"); + continue; + } + if (getline(&line, &n, fp) =3D=3D -1) { + g_debug(" failed to read disk size"); + fclose(fp); + continue; + } + fclose(fp); + if (strcmp(line, "0\n") =3D=3D 0) { + g_debug(" skipping zero-sized disk"); + continue; + } + + g_debug(" adding %s", de->d_name); + disk_dir =3D g_strdup_printf("/sys/block/%s", de->d_name); + disk =3D g_new0(GuestDiskInfo, 1); + disk->name =3D get_device_for_syspath(disk_dir); + disk->partition =3D false; + disk->alias =3D get_alias_for_syspath(disk_dir); + if (disk->alias !=3D NULL) { + disk->has_alias =3D true; + } + item =3D g_new0(GuestDiskInfoList, 1); + item->value =3D disk; + item->next =3D ret; + ret =3D item; + + /* Get address for non-virtual devices */ + bool is_virtual =3D is_disk_virtual(disk_dir, &local_err); + if (local_err !=3D NULL) { + g_debug(" failed to check disk path, ignoring error: %s", + error_get_pretty(local_err)); + error_free(local_err); + local_err =3D NULL; + /* Don't try to get the address */ + is_virtual =3D true; + } + if (!is_virtual) { + disk->address =3D get_disk_address(disk_dir, &local_err); + if (local_err !=3D NULL) { + g_debug(" failed to get device info, ignoring error: %s", + error_get_pretty(local_err)); + error_free(local_err); + local_err =3D NULL; + } else if (disk->address !=3D NULL) { + disk->has_address =3D true; + } + } + + /* List slave disks */ + slaves_dir =3D g_strdup_printf("%s/slaves", disk_dir); + g_debug(" listing entries in: %s", slaves_dir); + dp_slaves =3D opendir(slaves_dir); + while ((de_slaves =3D readdir(dp_slaves)) !=3D NULL) { + g_autofree char *slave_dir =3D NULL; + char *slave_dev; + strList *slave_item =3D NULL; + + if ((strcmp(".", de_slaves->d_name) =3D=3D 0) || + (strcmp("..", de_slaves->d_name) =3D=3D 0)) { + continue; + } + + /* Add slave disks */ + slave_dir =3D g_strdup_printf("%s/%s", + slaves_dir, de_slaves->d_name); + slave_dev =3D get_device_for_syspath(slave_dir); + if (slave_dev !=3D NULL) { + g_debug(" adding slave device: %s", slave_dev); + slave_item =3D g_new0(strList, 1); + slave_item->value =3D slave_dev; + slave_item->next =3D disk->slaves; + disk->slaves =3D slave_item; + } + } + closedir(dp_slaves); + + /* + * Detect partitions subdirectory name is "" or + * "p" + */ + dp_disk =3D opendir(disk_dir); + while ((de_disk =3D readdir(dp_disk)) !=3D NULL) { + size_t len; + g_autofree char *partition_dir =3D NULL; + + if (!(de_disk->d_type & DT_DIR)) { + continue; + } + + len =3D strlen(de->d_name); + if (!(strncmp(de->d_name, de_disk->d_name, len) =3D=3D 0 && + ((*(de_disk->d_name + len) =3D=3D 'p' && + isdigit(*(de_disk->d_name + len + 1))) || + isdigit(*(de_disk->d_name + len))))) { + continue; + } + + partition_dir =3D g_strdup_printf("%s/%s", + disk_dir, de_disk->d_name); + partition =3D g_new0(GuestDiskInfo, 1); + partition->name =3D get_device_for_syspath(partition_dir); + partition->partition =3D true; + /* Add parent disk as slave for easier tracking of hierarchy */ + partition->slaves =3D g_new0(strList, 1); + partition->slaves->value =3D g_strdup(disk->name); + + item =3D g_new0(GuestDiskInfoList, 1); + item->value =3D partition; + item->next =3D ret; + ret =3D item; + + } + closedir(dp_disk); + } + return ret; +} + +#else + +GuestDiskInfoList *qmp_guest_get_disks(Error **errp) +{ + error_setg(errp, QERR_UNSUPPORTED); + return NULL; +} + +#endif + /* Return a list of the disk device(s)' info which @mount lies on */ static GuestFilesystemInfo *build_guest_fsinfo(struct FsMount *mount, Error **errp) @@ -2809,7 +3047,8 @@ GList *ga_command_blacklist_init(GList *blacklist) const char *list[] =3D { "guest-get-fsinfo", "guest-fsfreeze-status", "guest-fsfreeze-freeze", "guest-fsfreeze-freeze-list", - "guest-fsfreeze-thaw", "guest-get-fsinfo", NULL}; + "guest-fsfreeze-thaw", "guest-get-fsinfo", + "guest-get-disks", NULL}; char **p =3D (char **)list; =20 while (*p) { @@ -3042,9 +3281,3 @@ GuestOSInfo *qmp_guest_get_osinfo(Error **errp) =20 return info; } - -GuestDiskInfoList *qmp_guest_get_disks(Error **errp) -{ - error_setg(errp, QERR_UNSUPPORTED); - return NULL; -} --=20 2.25.0 From nobody Sat May 4 12:37:49 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1599470161; cv=none; d=zohomail.com; s=zohoarc; b=JZ2EG9VsXxuUr5JQY/FWsIsHlzbv73sDfcbj5SQ4glw4t+c+HSbc3R5MB1V1fWpAfZSZkmKPdMwO9wYy3GTWZCNRP9ZN2CdCFLnT8yDbjBim7G4L0TN5tGyu29cofWrrYAU2GGj31QGMSoB1QjLb5QN5lxpHAMwhwFSzkAQpUO0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1599470161; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=+osGm5VoqFfp8g5HnBUBNDMbAdQdsswlF1C+9TeRIP0=; b=Oze52OgY/H0u5qappWGsZc2TYynmxpEJWe8uAbX77l7tAKzPuDkaMuS7WiHmeozikqyHKN/Rc4t2pn16VIwzD8i03pyX6U982KYxR5LEWpivBzjXzaSy4sBLyA0pCA3ccLP953zcUgjVCluqyU9R8w50KU23Rh9C5C/ONbYB5XE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1599470161149794.6045897635297; Mon, 7 Sep 2020 02:16:01 -0700 (PDT) Received: from localhost ([::1]:49506 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kFDFn-00035t-Gl for importer@patchew.org; Mon, 07 Sep 2020 05:15:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33490) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kFDEj-0002CO-2g for qemu-devel@nongnu.org; Mon, 07 Sep 2020 05:14:53 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:38837) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kFDEh-00029U-5j for qemu-devel@nongnu.org; Mon, 07 Sep 2020 05:14:52 -0400 Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-36-vJ9pxOaSNdCVUhqkMVwP7w-1; Mon, 07 Sep 2020 05:14:48 -0400 Received: by mail-ej1-f71.google.com with SMTP id md9so5046252ejb.8 for ; Mon, 07 Sep 2020 02:14:47 -0700 (PDT) Received: from auriga.localdomain (ip-89-176-41-222.net.upcbroadband.cz. [89.176.41.222]) by smtp.gmail.com with ESMTPSA id d6sm14394910edm.31.2020.09.07.02.14.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Sep 2020 02:14:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1599470090; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+osGm5VoqFfp8g5HnBUBNDMbAdQdsswlF1C+9TeRIP0=; b=PQxAp6byvys4F4sOG+Gx6N7PeSg0h4hUby8aQ3bjPrFcfatl/gONngevklECLPxdtN6kk7 xCedlAUo3fya5jNWMIJLqRmGa/B4YYsbXFJll7HoCVLPHc9d9XRkg86EORQEymqRq1phTM MVxJ9EHDKvQIKt/15asS4gScPyV4gm8= X-MC-Unique: vJ9pxOaSNdCVUhqkMVwP7w-1 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=+osGm5VoqFfp8g5HnBUBNDMbAdQdsswlF1C+9TeRIP0=; b=qjOz3PlDgqebPcAdGtBdYajMw2cmvizU4hdiuYljyLzgp+tgbQVvLv8lkwkxgMpiyI ZHE0forJN9wixJpnrfEhpHp9kNdqqyJeit/gD2fTZBG1v8V7C5BPgEhvpIexG2yop8fN oCl/lmrebyncWubSbUdrAPsQvoySYn2Xex5bCYHdqXHyb39pX3XgquDDZxf9ZbCd6/St Ms5xBgEMwRqAf5DbFBXuB2/IRNpm7uJ2SKgVu4ZK0oi+XRZG8juybVOqga6L+b9h+iL8 PwAl7kw0k/JGsFpoi5RzRhNtElRlceGvfV0Tc9VXlTvar/1JF1PfEoAAnbwo1aah1irx wy+g== X-Gm-Message-State: AOAM532lIcMyZyXwmAsD727uj3QnmjxoKc4SemKJVH0pdPexPem6KKwh K32Q5rh9JaShdQDkm8Ja/Yv8uHOjG5LZPAcKLG1KzmwlxGiMwYBLSek7rCqhQB41R7rgJbcEZDn JBDk+Dj93DVG67Is= X-Received: by 2002:a17:906:4cc6:: with SMTP id q6mr12809327ejt.201.1599470086881; Mon, 07 Sep 2020 02:14:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJysKo3MUs17TWXGHG1hDfFh0K7NB9Ee4T9nbDSWlw3emoDJcn33PsOChEtn026O5kNrUw3ULw== X-Received: by 2002:a17:906:4cc6:: with SMTP id q6mr12809311ejt.201.1599470086693; Mon, 07 Sep 2020 02:14:46 -0700 (PDT) From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Golembiovsk=C3=BD?= To: Michael Roth , Thomas Huth , qemu-devel@nongnu.org Subject: [PATCH v2 3/3] qga: add implementation of guest-get-disks for Windows Date: Mon, 7 Sep 2020 11:14:42 +0200 Message-Id: <2cd59ce454e0da02eeb75ab7461ef420b30864f5.1599470071.git.tgolembi@redhat.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: References: MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=tgolembi@redhat.com X-Mimecast-Spam-Score: 0.002 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=tgolembi@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/07 03:52:11 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.099, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=-1, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?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: pass (identity @redhat.com) The command lists all the physical disk drives. Unlike for Linux partitions and virtual volumes are not listed. Example output: { "return": [ { "name": "\\\\.\\PhysicalDrive0", "partition": false, "address": { "serial": "QM00001", "bus-type": "sata", ... }, "slaves": [] } ] } Signed-off-by: Tom=C3=A1=C5=A1 Golembiovsk=C3=BD --- qga/commands-win32.c | 97 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 91 insertions(+), 6 deletions(-) diff --git a/qga/commands-win32.c b/qga/commands-win32.c index e9976a0c46..9ac847a187 100644 --- a/qga/commands-win32.c +++ b/qga/commands-win32.c @@ -945,6 +945,91 @@ out: return list; } =20 +GuestDiskInfoList *qmp_guest_get_disks(Error **errp) +{ + GuestDiskInfoList *new =3D NULL, *ret =3D NULL; + HDEVINFO dev_info; + SP_DEVICE_INTERFACE_DATA dev_iface_data; + int i; + + dev_info =3D SetupDiGetClassDevs(&GUID_DEVINTERFACE_DISK, 0, 0, + DIGCF_PRESENT | DIGCF_DEVICEINTERFACE); + if (dev_info =3D=3D INVALID_HANDLE_VALUE) { + error_setg_win32(errp, GetLastError(), "failed to get device tree"= ); + return NULL; + } + + g_debug("enumerating devices"); + dev_iface_data.cbSize =3D sizeof(SP_DEVICE_INTERFACE_DATA); + for (i =3D 0; + SetupDiEnumDeviceInterfaces(dev_info, NULL, &GUID_DEVINTERFACE_DIS= K, + i, &dev_iface_data); + i++) { + GuestDiskAddress *address =3D NULL; + GuestDiskInfo *disk =3D NULL; + Error *local_err =3D NULL; + g_autofree PSP_DEVICE_INTERFACE_DETAIL_DATA + pdev_iface_detail_data =3D NULL; + STORAGE_DEVICE_NUMBER sdn; + HANDLE dev_file; + DWORD size =3D 0; + + g_debug(" getting device path"); + while (!SetupDiGetDeviceInterfaceDetail(dev_info, &dev_iface_data, + pdev_iface_detail_data, + size, &size, + NULL)) { + if (GetLastError() =3D=3D ERROR_INSUFFICIENT_BUFFER) { + pdev_iface_detail_data =3D g_malloc(size); + pdev_iface_detail_data->cbSize =3D + sizeof(*pdev_iface_detail_data); + } else { + g_debug("failed to get device interface details"); + continue; + } + } + + g_debug(" device: %s", pdev_iface_detail_data->DevicePath); + dev_file =3D CreateFile(pdev_iface_detail_data->DevicePath, 0, + FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); + if (!DeviceIoControl(dev_file, IOCTL_STORAGE_GET_DEVICE_NUMBER, + NULL, 0, &sdn, sizeof(sdn), &size, NULL)) { + CloseHandle(dev_file); + debug_error("failed to get storage device number"); + continue; + } + CloseHandle(dev_file); + + disk =3D g_new0(GuestDiskInfo, 1); + disk->name =3D g_strdup_printf("\\\\.\\PhysicalDrive%lu", + sdn.DeviceNumber); + + g_debug(" number: %lu", sdn.DeviceNumber); + address =3D g_malloc0(sizeof(GuestDiskAddress)); + address->has_dev =3D true; + address->dev =3D g_strdup(disk->name); + get_single_disk_info(sdn.DeviceNumber, address, &local_err); + if (local_err) { + g_debug("failed to get disk info: %s", + error_get_pretty(local_err)); + error_free(local_err); + qapi_free_GuestDiskAddress(address); + address =3D NULL; + } else { + disk->address =3D address; + disk->has_address =3D true; + } + + new =3D g_malloc0(sizeof(GuestDiskInfoList)); + new->value =3D disk; + new->next =3D ret; + ret =3D new; + } + + SetupDiDestroyDeviceInfoList(dev_info); + return ret; +} + #else =20 static GuestDiskAddressList *build_guest_disk_info(char *guid, Error **err= p) @@ -952,6 +1037,12 @@ static GuestDiskAddressList *build_guest_disk_info(ch= ar *guid, Error **errp) return NULL; } =20 +GuestDiskInfoList *qmp_guest_get_disks(Error **errp) +{ + error_setg(errp, QERR_UNSUPPORTED); + return NULL; +} + #endif /* CONFIG_QGA_NTDDSCSI */ =20 static GuestFilesystemInfo *build_guest_fsinfo(char *guid, Error **errp) @@ -2229,9 +2320,3 @@ GuestOSInfo *qmp_guest_get_osinfo(Error **errp) =20 return info; } - -GuestDiskInfoList *qmp_guest_get_disks(Error **errp) -{ - error_setg(errp, QERR_UNSUPPORTED); - return NULL; -} --=20 2.25.0