From nobody Thu Apr 18 23:57:22 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1578699176; cv=none; d=zohomail.com; s=zohoarc; b=iXXKAnJ09NVPS2U/ssOFNX0d6Lfe+e2wQjVUY6vXdQwCXvQAlmonG4jbxe8sQ2GBFuUoKbYvcOp4SLNev0uFD6+24+JA6f2M0Pc2oml1L42f1ULWSMCSVZ4BCwgDqnCH6eo/tSRPcx/7gBQ1GWJf37jVK5QgEpkg+c+T/YZRjh8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1578699176; 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=/1qQIiQJ/PNR40yaspX7GYFPnQQf0m9WIDSrPRsyB5Y=; b=GEz16nPUigflp6GJqt+Pk9uKktEQUstsc83sBidkHWaHYEFSXqqWaP7QhvWuKJwuzA4XqTzte5Y8VdmeoO1+dCGqFK5NnezRP54kRkXdj/7mKA0T2WRapnturRXSJof2FyvsxOjNsa5BO8nu+/bMA8tf9aS2KYErkga/Rna4U8Y= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 1578699176806659.7682306428308; Fri, 10 Jan 2020 15:32:56 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-266-10VJfMT5Oser7W-fdOqm1w-1; Fri, 10 Jan 2020 18:32:53 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 80C75800A02; Fri, 10 Jan 2020 23:32:48 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 39EDF5C1D4; Fri, 10 Jan 2020 23:32:48 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id A24E7503CC; Fri, 10 Jan 2020 23:32:47 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 00ANWMKe018722 for ; Fri, 10 Jan 2020 18:32:22 -0500 Received: by smtp.corp.redhat.com (Postfix) id F31805D72B; Fri, 10 Jan 2020 23:32:21 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-117-214.phx2.redhat.com [10.3.117.214]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AD8147C408; Fri, 10 Jan 2020 23:32:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1578699175; h=from:from:sender:sender: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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=/1qQIiQJ/PNR40yaspX7GYFPnQQf0m9WIDSrPRsyB5Y=; b=XW20kK4Q9RCw602jILUaX43sWSLO2u2GPpPhLZ+Ez0kc8IRaqKs9sE6YR036lywg84Ji10 pl5YHzp4DHffP9F5/hbmTp3J0cDV66pt0MKw2Sos8KL7mf9Sq3dWv+NcTtgxU92TUqGt5l 1kE7oSMoehDQvlQOk8Entdou5++W3yo= From: Jonathon Jongsma To: libvir-list@redhat.com Date: Fri, 10 Jan 2020 17:32:10 -0600 Message-Id: <20200110233217.18770-2-jjongsma@redhat.com> In-Reply-To: <20200110233217.18770-1-jjongsma@redhat.com> References: <20200110233217.18770-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: mprivozn@redhat.com Subject: [libvirt] [PATCH v2 1/8] qemu: rename qemuAgentGetFSInfoInternalDisk() X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-MC-Unique: 10VJfMT5Oser7W-fdOqm1w-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" The function name doesn't give a good idea of what the function does. Rename to qemuAgentGetFSInfoFillDisks() to make it more obvious than it is filling in the disk information in the fsinfo struct. Signed-off-by: Jonathon Jongsma Reviewed-by: Michal Privoznik --- src/qemu/qemu_agent.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c index 5fa8d24a91..8b54786ed8 100644 --- a/src/qemu/qemu_agent.c +++ b/src/qemu/qemu_agent.c @@ -1929,9 +1929,9 @@ qemuAgentFSInfoToPublic(qemuAgentFSInfoPtr agent) } =20 static int -qemuAgentGetFSInfoInternalDisk(virJSONValuePtr jsondisks, - qemuAgentFSInfoPtr fsinfo, - virDomainDefPtr vmdef) +qemuAgentGetFSInfoFillDisks(virJSONValuePtr jsondisks, + qemuAgentFSInfoPtr fsinfo, + virDomainDefPtr vmdef) { size_t ndisks; size_t i; @@ -2143,7 +2143,7 @@ qemuAgentGetFSInfoInternal(qemuAgentPtr mon, goto cleanup; } =20 - if (qemuAgentGetFSInfoInternalDisk(disk, info_ret[i], vmdef) < 0) + if (qemuAgentGetFSInfoFillDisks(disk, info_ret[i], vmdef) < 0) goto cleanup; } =20 --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Apr 18 23:57:22 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1578699191; cv=none; d=zohomail.com; s=zohoarc; b=IE7S6XM19sJgsJdCNgvwUDmFghwir13vvESZdnQQP8BS9e9DgXLnfotx5/HuBby84lChcqBcbFaY1nuBIixWcBzC5pf700lQWTRoNupdy+Ku4Xr3MifkfNJ/Lpym80KDjjpDQz+QpfB/S0l3ELgBVdfbn/5mVq4IZKNwAoSmLSc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1578699191; 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=ZuKgJv9aL+oAMkrl89y+0mCsEZ4vNtjqSyvjh7uVGdE=; b=BFwi+mQVjsE4DGKWroyYdg7pVrwESqe4jjrFhxWHdd3FQ/c4AMkJ02xonpPyw1pfDhU2m1thlY197B0GWkpXpmfpt/XgqfNr7ZKGERexg8x21Ak/bA1BWZDN/XZNyuw1LFQgjSVJbHgQ0iAQx80cELpsfPZmoiv/OBotGMhs3HI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 1578699191907781.2361097812063; Fri, 10 Jan 2020 15:33:11 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-356-JRO2vey3Pt6Oke6wlTaGOw-1; Fri, 10 Jan 2020 18:32:58 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 157CB800D53; Fri, 10 Jan 2020 23:32:53 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E5CB87FB76; Fri, 10 Jan 2020 23:32:52 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 9AA3D81C7C; Fri, 10 Jan 2020 23:32:52 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 00ANWM8q018727 for ; Fri, 10 Jan 2020 18:32:22 -0500 Received: by smtp.corp.redhat.com (Postfix) id 6450B7C409; Fri, 10 Jan 2020 23:32:22 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-117-214.phx2.redhat.com [10.3.117.214]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1EF3D5D72B; Fri, 10 Jan 2020 23:32:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1578699190; h=from:from:sender:sender: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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=ZuKgJv9aL+oAMkrl89y+0mCsEZ4vNtjqSyvjh7uVGdE=; b=Dh6DGjg4efXF6DH1qkRwX78SWy6fmuFU1R8w8Lg0I6kU9yu2RBtJvnlcvd0jXCIbasDHNk VqSGwmuKd2j2PD0y2/gHCdCFNuvK2ECQYtbsTGwlC1gpxerl82RU1mk+Rot6FYkeiSwTR1 ny3YhtzvP9RWtthBEJGh5XKH5/rTDTc= From: Jonathon Jongsma To: libvir-list@redhat.com Date: Fri, 10 Jan 2020 17:32:11 -0600 Message-Id: <20200110233217.18770-3-jjongsma@redhat.com> In-Reply-To: <20200110233217.18770-1-jjongsma@redhat.com> References: <20200110233217.18770-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: mprivozn@redhat.com Subject: [libvirt] [PATCH v2 2/8] qemu: store complete agent filesystem information X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-MC-Unique: JRO2vey3Pt6Oke6wlTaGOw-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" In an effort to avoid holding both an agent and normal job at the same time, we shouldn't access the vm definition from within qemu_agent.c (i.e. while the agent job is being held). In preparation, we need to store the full filesystem disk information in qemuAgentDiskInfo. In a following commit, we can pass this information back to the caller and the caller can search the vm definition to match the filsystem disk to an alias. Signed-off-by: Jonathon Jongsma Reviewed-by: Michal Privoznik --- src/qemu/qemu_agent.c | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c index 8b54786ed8..fa55ff0a57 100644 --- a/src/qemu/qemu_agent.c +++ b/src/qemu/qemu_agent.c @@ -1853,6 +1853,11 @@ typedef qemuAgentDiskInfo *qemuAgentDiskInfoPtr; struct _qemuAgentDiskInfo { char *alias; char *serial; + virPCIDeviceAddress pci_controller; + char *bus_type; + unsigned int bus; + unsigned int target; + unsigned int unit; char *devnode; }; =20 @@ -1876,6 +1881,7 @@ qemuAgentDiskInfoFree(qemuAgentDiskInfoPtr info) =20 VIR_FREE(info->serial); VIR_FREE(info->alias); + VIR_FREE(info->bus_type); VIR_FREE(info->devnode); VIR_FREE(info); } @@ -1956,10 +1962,6 @@ qemuAgentGetFSInfoFillDisks(virJSONValuePtr jsondisk= s, qemuAgentDiskInfoPtr disk; virDomainDiskDefPtr diskDef; const char *val; - unsigned int bus; - unsigned int target; - unsigned int unit; - virPCIDeviceAddress pci_address; =20 if (!jsondisk) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -1973,6 +1975,9 @@ qemuAgentGetFSInfoFillDisks(virJSONValuePtr jsondisks, return -1; disk =3D fsinfo->disks[i]; =20 + if ((val =3D virJSONValueObjectGetString(jsondisk, "bus-type"))) + disk->bus_type =3D g_strdup(val); + if ((val =3D virJSONValueObjectGetString(jsondisk, "serial"))) disk->serial =3D g_strdup(val); =20 @@ -1989,9 +1994,9 @@ qemuAgentGetFSInfoFillDisks(virJSONValuePtr jsondisks, } \ } while (0) =20 - GET_DISK_ADDR(jsondisk, &bus, "bus"); - GET_DISK_ADDR(jsondisk, &target, "target"); - GET_DISK_ADDR(jsondisk, &unit, "unit"); + GET_DISK_ADDR(jsondisk, &disk->bus, "bus"); + GET_DISK_ADDR(jsondisk, &disk->target, "target"); + GET_DISK_ADDR(jsondisk, &disk->unit, "unit"); =20 if (!(pci =3D virJSONValueObjectGet(jsondisk, "pci-controller"))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", @@ -2000,18 +2005,17 @@ qemuAgentGetFSInfoFillDisks(virJSONValuePtr jsondis= ks, return -1; } =20 - GET_DISK_ADDR(pci, &pci_address.domain, "domain"); - GET_DISK_ADDR(pci, &pci_address.bus, "bus"); - GET_DISK_ADDR(pci, &pci_address.slot, "slot"); - GET_DISK_ADDR(pci, &pci_address.function, "function"); + GET_DISK_ADDR(pci, &disk->pci_controller.domain, "domain"); + GET_DISK_ADDR(pci, &disk->pci_controller.bus, "bus"); + GET_DISK_ADDR(pci, &disk->pci_controller.slot, "slot"); + GET_DISK_ADDR(pci, &disk->pci_controller.function, "function"); =20 #undef GET_DISK_ADDR - if (!(diskDef =3D virDomainDiskByAddress(vmdef, - &pci_address, - bus, - target, - unit))) + &disk->pci_controller, + disk->bus, + disk->target, + disk->unit))) continue; =20 disk->alias =3D g_strdup(diskDef->dst); --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Apr 18 23:57:22 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1578699217; cv=none; d=zohomail.com; s=zohoarc; b=C75WByHvU1zvkdLMpgjkNWyyv0tw2PHu7hmXl+Dx3wWQomwz6qPmrRC4CPTSBPQX7gfE3HO1OlVIQXO9TRNbcP2ivj05EUUSd+1yN4Z+Z0R3OciJ8BaEIe2dgwQWQAYccGTss5cefuzzuCjThwX18rlrHai1mFgVHSAHnyIe/AI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1578699217; 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=8Tjx5kG+pqAhATmaOtPOD379wPogvbpYlg/HrmSnDC4=; b=VSOnsv/SAIafJWZgnlezK+VEVwbdPva3NDqfpUWRmYKGJyon+k6ePh8FCpe8oQXWVLBAwGPcq55XgptyNdSQet8/9sd9ihGogMmpvOf7FCBa7acFZaAiEATewDg2fGhEbFMRv/OrUMfqHGhxKkKsnfVyLKRfrGiL3V3/HGUCXVM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 1578699217408846.4076480860894; Fri, 10 Jan 2020 15:33:37 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-162-kmc30sRGO-ifrg8UqyDrPQ-1; Fri, 10 Jan 2020 18:33:34 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 649508024D5; Fri, 10 Jan 2020 23:33:29 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 33D631001B00; Fri, 10 Jan 2020 23:33:29 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 819D518089CD; Fri, 10 Jan 2020 23:33:28 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 00ANWM6e018732 for ; Fri, 10 Jan 2020 18:32:22 -0500 Received: by smtp.corp.redhat.com (Postfix) id C98787C409; Fri, 10 Jan 2020 23:32:22 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-117-214.phx2.redhat.com [10.3.117.214]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 84B695D72B; Fri, 10 Jan 2020 23:32:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1578699216; h=from:from:sender:sender: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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=8Tjx5kG+pqAhATmaOtPOD379wPogvbpYlg/HrmSnDC4=; b=eDXAg5fhk1gNh5m1eLjTTQRfg2KtMADGaEqPBqtoqlIb5EFefk26dc7er+qeoRE2f3xu8K 6+Gcjv4M0zbin/W1/ivD3oPe9YUemGmqonKGFueQ3WVGmKrFi+rrUB9hzknBP9IzvHao5P ew/KK7Bjlkoi93vIXLah9UWjMPpvoDo= From: Jonathon Jongsma To: libvir-list@redhat.com Date: Fri, 10 Jan 2020 17:32:12 -0600 Message-Id: <20200110233217.18770-4-jjongsma@redhat.com> In-Reply-To: <20200110233217.18770-1-jjongsma@redhat.com> References: <20200110233217.18770-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: mprivozn@redhat.com Subject: [libvirt] [PATCH v2 3/8] qemu: Don't store disk alias in qemuAgentDiskInfo X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-MC-Unique: kmc30sRGO-ifrg8UqyDrPQ-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" The qemuAgentDiskInfo structure is filled with information received from the agent command response, except for the 'alias' field, which is retrieved from the vm definition. Limit this structure only to data that was received from the agent message. This is another intermediate step in moving the responsibility for searching the vmdef from qemu_agent.c to qemu_driver.c so that we can avoid holding an agent job and a normal job at the same time. Signed-off-by: Jonathon Jongsma Reviewed-by: Michal Privoznik --- src/qemu/qemu_agent.c | 63 ++++++++++++++++++++++++------------------- 1 file changed, 35 insertions(+), 28 deletions(-) diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c index fa55ff0a57..b250077f0a 100644 --- a/src/qemu/qemu_agent.c +++ b/src/qemu/qemu_agent.c @@ -1851,7 +1851,6 @@ qemuAgentSetTime(qemuAgentPtr mon, typedef struct _qemuAgentDiskInfo qemuAgentDiskInfo; typedef qemuAgentDiskInfo *qemuAgentDiskInfoPtr; struct _qemuAgentDiskInfo { - char *alias; char *serial; virPCIDeviceAddress pci_controller; char *bus_type; @@ -1880,7 +1879,6 @@ qemuAgentDiskInfoFree(qemuAgentDiskInfoPtr info) return; =20 VIR_FREE(info->serial); - VIR_FREE(info->alias); VIR_FREE(info->bus_type); VIR_FREE(info->devnode); VIR_FREE(info); @@ -1906,10 +1904,12 @@ qemuAgentFSInfoFree(qemuAgentFSInfoPtr info) } =20 static virDomainFSInfoPtr -qemuAgentFSInfoToPublic(qemuAgentFSInfoPtr agent) +qemuAgentFSInfoToPublic(qemuAgentFSInfoPtr agent, + virDomainDefPtr vmdef) { virDomainFSInfoPtr ret =3D NULL; size_t i; + virDomainDiskDefPtr diskDef; =20 if (VIR_ALLOC(ret) < 0) goto error; @@ -1924,8 +1924,17 @@ qemuAgentFSInfoToPublic(qemuAgentFSInfoPtr agent) =20 ret->ndevAlias =3D agent->ndisks; =20 - for (i =3D 0; i < ret->ndevAlias; i++) - ret->devAlias[i] =3D g_strdup(agent->disks[i]->alias); + for (i =3D 0; i < ret->ndevAlias; i++) { + qemuAgentDiskInfoPtr agentdisk =3D agent->disks[i]; + if (!(diskDef =3D virDomainDiskByAddress(vmdef, + &agentdisk->pci_controller, + agentdisk->bus, + agentdisk->target, + agentdisk->unit))) + continue; + + ret->devAlias[i] =3D g_strdup(diskDef->dst); + } =20 return ret; =20 @@ -1936,8 +1945,7 @@ qemuAgentFSInfoToPublic(qemuAgentFSInfoPtr agent) =20 static int qemuAgentGetFSInfoFillDisks(virJSONValuePtr jsondisks, - qemuAgentFSInfoPtr fsinfo, - virDomainDefPtr vmdef) + qemuAgentFSInfoPtr fsinfo) { size_t ndisks; size_t i; @@ -1960,7 +1968,6 @@ qemuAgentGetFSInfoFillDisks(virJSONValuePtr jsondisks, virJSONValuePtr jsondisk =3D virJSONValueArrayGet(jsondisks, i); virJSONValuePtr pci; qemuAgentDiskInfoPtr disk; - virDomainDiskDefPtr diskDef; const char *val; =20 if (!jsondisk) { @@ -2011,14 +2018,6 @@ qemuAgentGetFSInfoFillDisks(virJSONValuePtr jsondisk= s, GET_DISK_ADDR(pci, &disk->pci_controller.function, "function"); =20 #undef GET_DISK_ADDR - if (!(diskDef =3D virDomainDiskByAddress(vmdef, - &disk->pci_controller, - disk->bus, - disk->target, - disk->unit))) - continue; - - disk->alias =3D g_strdup(diskDef->dst); } =20 return 0; @@ -2030,8 +2029,7 @@ qemuAgentGetFSInfoFillDisks(virJSONValuePtr jsondisks, */ static int qemuAgentGetFSInfoInternal(qemuAgentPtr mon, - qemuAgentFSInfoPtr **info, - virDomainDefPtr vmdef) + qemuAgentFSInfoPtr **info) { size_t i; int ret =3D -1; @@ -2147,7 +2145,7 @@ qemuAgentGetFSInfoInternal(qemuAgentPtr mon, goto cleanup; } =20 - if (qemuAgentGetFSInfoFillDisks(disk, info_ret[i], vmdef) < 0) + if (qemuAgentGetFSInfoFillDisks(disk, info_ret[i]) < 0) goto cleanup; } =20 @@ -2177,14 +2175,14 @@ qemuAgentGetFSInfo(qemuAgentPtr mon, size_t i; int nfs; =20 - nfs =3D qemuAgentGetFSInfoInternal(mon, &agentinfo, vmdef); + nfs =3D qemuAgentGetFSInfoInternal(mon, &agentinfo); if (nfs < 0) return ret; if (VIR_ALLOC_N(info_ret, nfs) < 0) goto cleanup; =20 for (i =3D 0; i < nfs; i++) { - if (!(info_ret[i] =3D qemuAgentFSInfoToPublic(agentinfo[i]))) + if (!(info_ret[i] =3D qemuAgentFSInfoToPublic(agentinfo[i], vmdef)= )) goto cleanup; } =20 @@ -2219,7 +2217,7 @@ qemuAgentGetFSInfoParams(qemuAgentPtr mon, size_t i, j; int nfs; =20 - if ((nfs =3D qemuAgentGetFSInfoInternal(mon, &fsinfo, vmdef)) < 0) + if ((nfs =3D qemuAgentGetFSInfoInternal(mon, &fsinfo)) < 0) return nfs; =20 if (virTypedParamsAddUInt(params, nparams, maxparams, @@ -2266,13 +2264,22 @@ qemuAgentGetFSInfoParams(qemuAgentPtr mon, param_name, fsinfo[i]->ndisks) < 0) goto cleanup; for (j =3D 0; j < fsinfo[i]->ndisks; j++) { + virDomainDiskDefPtr diskdef =3D NULL; qemuAgentDiskInfoPtr d =3D fsinfo[i]->disks[j]; - g_snprintf(param_name, VIR_TYPED_PARAM_FIELD_LENGTH, - "fs.%zu.disk.%zu.alias", i, j); - if (d->alias && - virTypedParamsAddString(params, nparams, maxparams, - param_name, d->alias) < 0) - goto cleanup; + /* match the disk to the target in the vm definition */ + diskdef =3D virDomainDiskByAddress(vmdef, + &d->pci_controller, + d->bus, + d->target, + d->unit); + if (diskdef) { + g_snprintf(param_name, VIR_TYPED_PARAM_FIELD_LENGTH, + "fs.%zu.disk.%zu.alias", i, j); + if (diskdef->dst && + virTypedParamsAddString(params, nparams, maxparams, + param_name, diskdef->dst) < 0) + goto cleanup; + } =20 g_snprintf(param_name, VIR_TYPED_PARAM_FIELD_LENGTH, "fs.%zu.disk.%zu.serial", i, j); --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Apr 18 23:57:22 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1578699186; cv=none; d=zohomail.com; s=zohoarc; b=TqOpGcFkjR4y58fhtz57BOgHK/5fZEj8ixZ9yEDQG8ClwADfARu03HcikRO535NCJxwFmSrU+hJMLInBYCLFLcfZPobmrsPpTFuG5z/e5ZkzfJhg46CA7DcYDKO4cww/RNGFR4WMA0zjOBKTAdT/bKKCDmRuPmv/M08RFfdWtf0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1578699186; 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=DwqJuuO22oIQ3x36ZjdYW8Mb/GRmI63HXphjX7DSoXs=; b=luYUw2FK8J4mT/sjYklA4cmfCh9vvYQUkZMGen/zKGVj6TUfE6XjrtDUUvzwSdAYnT9vdkC5S5TnVn7sKIA9dAZsDq+uUTASWama3MxHnc/Iu94aH4o3oE2fN3W0Dm4N7UBhg5C8KQTb6oZKn0pai+7AqBr99fH+28IMEZ1peqA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 1578699186043364.47588495708817; Fri, 10 Jan 2020 15:33:06 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-278-E2XS4ZVMNbKOYRfWjyFq0w-1; Fri, 10 Jan 2020 18:33:02 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0AAB6184B1F7; Fri, 10 Jan 2020 23:32:57 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D6C0C5DA60; Fri, 10 Jan 2020 23:32:56 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 9696781C8B; Fri, 10 Jan 2020 23:32:56 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 00ANWNH8018740 for ; Fri, 10 Jan 2020 18:32:23 -0500 Received: by smtp.corp.redhat.com (Postfix) id 5D04A7C409; Fri, 10 Jan 2020 23:32:23 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-117-214.phx2.redhat.com [10.3.117.214]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EA3165D72B; Fri, 10 Jan 2020 23:32:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1578699184; h=from:from:sender:sender: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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=DwqJuuO22oIQ3x36ZjdYW8Mb/GRmI63HXphjX7DSoXs=; b=EBtHzGp+3SncLqK8hsh/ipWzv9gbAgJqbOTqkb4q8RnTXrDslaKfzLk7Z9ikscQHb0XXrB RXpIS4PeBF4/PMZ/nSjnXCTLQ49yQgDyD+PBhdibY+zFS4L2CrfA1GSacKmZPUJMtN5UL/ IMK/TiyGWZdo1KlAAhurHIQTUU9rkFo= From: Jonathon Jongsma To: libvir-list@redhat.com Date: Fri, 10 Jan 2020 17:32:13 -0600 Message-Id: <20200110233217.18770-5-jjongsma@redhat.com> In-Reply-To: <20200110233217.18770-1-jjongsma@redhat.com> References: <20200110233217.18770-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: mprivozn@redhat.com Subject: [libvirt] [PATCH v2 4/8] qemu: don't access vmdef within qemu_agent.c X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-MC-Unique: E2XS4ZVMNbKOYRfWjyFq0w-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" In order to avoid holding an agent job and a normal job at the same time, we want to avoid accessing the domain's definition while holding the agent job. To achieve this, qemuAgentGetFSInfo() only returns the raw information from the agent query to the caller. The caller can then release the agent job and then proceed to look up the disk alias from the vm definition. This necessitates moving a few helper functions to qemu_driver.c and exposing the agent data structure (qemuAgentFSInfo) in the header. In addition, because the agent function no longer returns the looked-up disk alias, we can't test the alias within qemuagenttest. Instead we simply test that we parse and return the raw agent data correctly. Signed-off-by: Jonathon Jongsma Reviewed-by: Michal Privoznik --- src/qemu/qemu_agent.c | 218 +---------------------------------- src/qemu/qemu_agent.h | 33 ++++-- src/qemu/qemu_driver.c | 254 ++++++++++++++++++++++++++++++++++++++--- tests/qemuagenttest.c | 196 +++++-------------------------- 4 files changed, 298 insertions(+), 403 deletions(-) diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c index b250077f0a..47bfef7141 100644 --- a/src/qemu/qemu_agent.c +++ b/src/qemu/qemu_agent.c @@ -1848,30 +1848,6 @@ qemuAgentSetTime(qemuAgentPtr mon, return ret; } =20 -typedef struct _qemuAgentDiskInfo qemuAgentDiskInfo; -typedef qemuAgentDiskInfo *qemuAgentDiskInfoPtr; -struct _qemuAgentDiskInfo { - char *serial; - virPCIDeviceAddress pci_controller; - char *bus_type; - unsigned int bus; - unsigned int target; - unsigned int unit; - char *devnode; -}; - -typedef struct _qemuAgentFSInfo qemuAgentFSInfo; -typedef qemuAgentFSInfo *qemuAgentFSInfoPtr; -struct _qemuAgentFSInfo { - char *mountpoint; /* path to mount point */ - char *name; /* device name in the guest (e.g. "sda1") */ - char *fstype; /* filesystem type */ - long long total_bytes; - long long used_bytes; - size_t ndisks; - qemuAgentDiskInfoPtr *disks; -}; - static void qemuAgentDiskInfoFree(qemuAgentDiskInfoPtr info) { @@ -1884,7 +1860,7 @@ qemuAgentDiskInfoFree(qemuAgentDiskInfoPtr info) VIR_FREE(info); } =20 -static void +void qemuAgentFSInfoFree(qemuAgentFSInfoPtr info) { size_t i; @@ -1903,46 +1879,6 @@ qemuAgentFSInfoFree(qemuAgentFSInfoPtr info) VIR_FREE(info); } =20 -static virDomainFSInfoPtr -qemuAgentFSInfoToPublic(qemuAgentFSInfoPtr agent, - virDomainDefPtr vmdef) -{ - virDomainFSInfoPtr ret =3D NULL; - size_t i; - virDomainDiskDefPtr diskDef; - - if (VIR_ALLOC(ret) < 0) - goto error; - - ret->mountpoint =3D g_strdup(agent->mountpoint); - ret->name =3D g_strdup(agent->name); - ret->fstype =3D g_strdup(agent->fstype); - - if (agent->disks && - VIR_ALLOC_N(ret->devAlias, agent->ndisks) < 0) - goto error; - - ret->ndevAlias =3D agent->ndisks; - - for (i =3D 0; i < ret->ndevAlias; i++) { - qemuAgentDiskInfoPtr agentdisk =3D agent->disks[i]; - if (!(diskDef =3D virDomainDiskByAddress(vmdef, - &agentdisk->pci_controller, - agentdisk->bus, - agentdisk->target, - agentdisk->unit))) - continue; - - ret->devAlias[i] =3D g_strdup(diskDef->dst); - } - - return ret; - - error: - virDomainFSInfoFree(ret); - return NULL; -} - static int qemuAgentGetFSInfoFillDisks(virJSONValuePtr jsondisks, qemuAgentFSInfoPtr fsinfo) @@ -2016,7 +1952,6 @@ qemuAgentGetFSInfoFillDisks(virJSONValuePtr jsondisks, GET_DISK_ADDR(pci, &disk->pci_controller.bus, "bus"); GET_DISK_ADDR(pci, &disk->pci_controller.slot, "slot"); GET_DISK_ADDR(pci, &disk->pci_controller.function, "function"); - #undef GET_DISK_ADDR } =20 @@ -2027,9 +1962,9 @@ qemuAgentGetFSInfoFillDisks(virJSONValuePtr jsondisks, * -2 when agent command is not supported by the agent * -1 otherwise */ -static int -qemuAgentGetFSInfoInternal(qemuAgentPtr mon, - qemuAgentFSInfoPtr **info) +int +qemuAgentGetFSInfo(qemuAgentPtr mon, + qemuAgentFSInfoPtr **info) { size_t i; int ret =3D -1; @@ -2161,151 +2096,6 @@ qemuAgentGetFSInfoInternal(qemuAgentPtr mon, return ret; } =20 -/* Returns: 0 on success - * -1 otherwise - */ -int -qemuAgentGetFSInfo(qemuAgentPtr mon, - virDomainFSInfoPtr **info, - virDomainDefPtr vmdef) -{ - int ret =3D -1; - qemuAgentFSInfoPtr *agentinfo =3D NULL; - virDomainFSInfoPtr *info_ret =3D NULL; - size_t i; - int nfs; - - nfs =3D qemuAgentGetFSInfoInternal(mon, &agentinfo); - if (nfs < 0) - return ret; - if (VIR_ALLOC_N(info_ret, nfs) < 0) - goto cleanup; - - for (i =3D 0; i < nfs; i++) { - if (!(info_ret[i] =3D qemuAgentFSInfoToPublic(agentinfo[i], vmdef)= )) - goto cleanup; - } - - *info =3D g_steal_pointer(&info_ret); - ret =3D nfs; - - cleanup: - for (i =3D 0; i < nfs; i++) { - qemuAgentFSInfoFree(agentinfo[i]); - /* if there was an error, free any memory we've allocated for the - * return value */ - if (info_ret) - virDomainFSInfoFree(info_ret[i]); - } - VIR_FREE(agentinfo); - VIR_FREE(info_ret); - return ret; -} - -/* Returns: 0 on success - * -2 when agent command is not supported by the agent - * -1 otherwise - */ -int -qemuAgentGetFSInfoParams(qemuAgentPtr mon, - virTypedParameterPtr *params, - int *nparams, int *maxparams, - virDomainDefPtr vmdef) -{ - int ret =3D -1; - qemuAgentFSInfoPtr *fsinfo =3D NULL; - size_t i, j; - int nfs; - - if ((nfs =3D qemuAgentGetFSInfoInternal(mon, &fsinfo)) < 0) - return nfs; - - if (virTypedParamsAddUInt(params, nparams, maxparams, - "fs.count", nfs) < 0) - goto cleanup; - - for (i =3D 0; i < nfs; i++) { - char param_name[VIR_TYPED_PARAM_FIELD_LENGTH]; - g_snprintf(param_name, VIR_TYPED_PARAM_FIELD_LENGTH, - "fs.%zu.name", i); - if (virTypedParamsAddString(params, nparams, maxparams, - param_name, fsinfo[i]->name) < 0) - goto cleanup; - g_snprintf(param_name, VIR_TYPED_PARAM_FIELD_LENGTH, - "fs.%zu.mountpoint", i); - if (virTypedParamsAddString(params, nparams, maxparams, - param_name, fsinfo[i]->mountpoint) < 0) - goto cleanup; - g_snprintf(param_name, VIR_TYPED_PARAM_FIELD_LENGTH, - "fs.%zu.fstype", i); - if (virTypedParamsAddString(params, nparams, maxparams, - param_name, fsinfo[i]->fstype) < 0) - goto cleanup; - - /* disk usage values are not returned by older guest agents, so - * only add the params if the value is set */ - g_snprintf(param_name, VIR_TYPED_PARAM_FIELD_LENGTH, - "fs.%zu.total-bytes", i); - if (fsinfo[i]->total_bytes !=3D -1 && - virTypedParamsAddULLong(params, nparams, maxparams, - param_name, fsinfo[i]->total_bytes) < = 0) - goto cleanup; - - g_snprintf(param_name, VIR_TYPED_PARAM_FIELD_LENGTH, - "fs.%zu.used-bytes", i); - if (fsinfo[i]->used_bytes !=3D -1 && - virTypedParamsAddULLong(params, nparams, maxparams, - param_name, fsinfo[i]->used_bytes) < 0) - goto cleanup; - - g_snprintf(param_name, VIR_TYPED_PARAM_FIELD_LENGTH, - "fs.%zu.disk.count", i); - if (virTypedParamsAddUInt(params, nparams, maxparams, - param_name, fsinfo[i]->ndisks) < 0) - goto cleanup; - for (j =3D 0; j < fsinfo[i]->ndisks; j++) { - virDomainDiskDefPtr diskdef =3D NULL; - qemuAgentDiskInfoPtr d =3D fsinfo[i]->disks[j]; - /* match the disk to the target in the vm definition */ - diskdef =3D virDomainDiskByAddress(vmdef, - &d->pci_controller, - d->bus, - d->target, - d->unit); - if (diskdef) { - g_snprintf(param_name, VIR_TYPED_PARAM_FIELD_LENGTH, - "fs.%zu.disk.%zu.alias", i, j); - if (diskdef->dst && - virTypedParamsAddString(params, nparams, maxparams, - param_name, diskdef->dst) < 0) - goto cleanup; - } - - g_snprintf(param_name, VIR_TYPED_PARAM_FIELD_LENGTH, - "fs.%zu.disk.%zu.serial", i, j); - if (d->serial && - virTypedParamsAddString(params, nparams, maxparams, - param_name, d->serial) < 0) - goto cleanup; - - g_snprintf(param_name, VIR_TYPED_PARAM_FIELD_LENGTH, - "fs.%zu.disk.%zu.device", i, j); - if (d->devnode && - virTypedParamsAddString(params, nparams, maxparams, - param_name, d->devnode) < 0) - goto cleanup; - } - } - ret =3D nfs; - - cleanup: - for (i =3D 0; i < nfs; i++) - qemuAgentFSInfoFree(fsinfo[i]); - VIR_FREE(fsinfo); - - return ret; -} - /* * qemuAgentGetInterfaces: * @mon: Agent monitor diff --git a/src/qemu/qemu_agent.h b/src/qemu/qemu_agent.h index 85e436cf68..5656fe60ff 100644 --- a/src/qemu/qemu_agent.h +++ b/src/qemu/qemu_agent.h @@ -65,19 +65,38 @@ typedef enum { QEMU_AGENT_SHUTDOWN_LAST, } qemuAgentShutdownMode; =20 +typedef struct _qemuAgentDiskInfo qemuAgentDiskInfo; +typedef qemuAgentDiskInfo *qemuAgentDiskInfoPtr; +struct _qemuAgentDiskInfo { + char *serial; + virPCIDeviceAddress pci_controller; + char *bus_type; + unsigned int bus; + unsigned int target; + unsigned int unit; + char *devnode; +}; + +typedef struct _qemuAgentFSInfo qemuAgentFSInfo; +typedef qemuAgentFSInfo *qemuAgentFSInfoPtr; +struct _qemuAgentFSInfo { + char *mountpoint; /* path to mount point */ + char *name; /* device name in the guest (e.g. "sda1") */ + char *fstype; /* filesystem type */ + long long total_bytes; + long long used_bytes; + size_t ndisks; + qemuAgentDiskInfoPtr *disks; +}; +void qemuAgentFSInfoFree(qemuAgentFSInfoPtr info); + int qemuAgentShutdown(qemuAgentPtr mon, qemuAgentShutdownMode mode); =20 int qemuAgentFSFreeze(qemuAgentPtr mon, const char **mountpoints, unsigned int nmountpoints); int qemuAgentFSThaw(qemuAgentPtr mon); -int qemuAgentGetFSInfo(qemuAgentPtr mon, virDomainFSInfoPtr **info, - virDomainDefPtr vmdef); - -int qemuAgentGetFSInfoParams(qemuAgentPtr mon, - virTypedParameterPtr *params, - int *nparams, int *maxparams, - virDomainDefPtr vmdef); +int qemuAgentGetFSInfo(qemuAgentPtr mon, qemuAgentFSInfoPtr **info); =20 int qemuAgentSuspend(qemuAgentPtr mon, unsigned int target); diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index d6b1e9f00c..50e6178dbb 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -21814,6 +21814,110 @@ qemuNodeAllocPages(virConnectPtr conn, startCell, cellCount, add); } =20 +static int +qemuDomainGetFSInfoAgent(virQEMUDriverPtr driver, + virDomainObjPtr vm, + qemuAgentFSInfoPtr **info) +{ + int ret =3D -1; + qemuAgentPtr agent; + + if (qemuDomainObjBeginAgentJob(driver, vm, + QEMU_AGENT_JOB_QUERY) < 0) + return ret; + + if (virDomainObjCheckActive(vm) < 0) + goto endjob; + + if (!qemuDomainAgentAvailable(vm, true)) + goto endjob; + + agent =3D qemuDomainObjEnterAgent(vm); + ret =3D qemuAgentGetFSInfo(agent, info); + qemuDomainObjExitAgent(vm, agent); + + endjob: + qemuDomainObjEndAgentJob(vm); + return ret; +} + +static virDomainFSInfoPtr +qemuAgentFSInfoToPublic(qemuAgentFSInfoPtr agent, + virDomainDefPtr vmdef) +{ + virDomainFSInfoPtr ret =3D NULL; + size_t i; + virDomainDiskDefPtr diskDef; + + if (VIR_ALLOC(ret) < 0) + goto error; + + ret->mountpoint =3D g_strdup(agent->mountpoint); + ret->name =3D g_strdup(agent->name); + ret->fstype =3D g_strdup(agent->fstype); + + if (agent->disks && + VIR_ALLOC_N(ret->devAlias, agent->ndisks) < 0) + goto error; + + ret->ndevAlias =3D agent->ndisks; + + for (i =3D 0; i < ret->ndevAlias; i++) { + qemuAgentDiskInfoPtr agentdisk =3D agent->disks[i]; + if (!(diskDef =3D virDomainDiskByAddress(vmdef, + &agentdisk->pci_controller, + agentdisk->bus, + agentdisk->target, + agentdisk->unit))) + continue; + + ret->devAlias[i] =3D g_strdup(diskDef->dst); + } + + return ret; + + error: + virDomainFSInfoFree(ret); + return NULL; +} + +/* Returns: 0 on success + * -1 otherwise + */ +static int +virDomainFSInfoFormat(qemuAgentFSInfoPtr *agentinfo, + int nagentinfo, + virDomainDefPtr vmdef, + virDomainFSInfoPtr **info) +{ + int ret =3D -1; + virDomainFSInfoPtr *info_ret =3D NULL; + size_t i; + + if (nagentinfo < 0) + return ret; + if (VIR_ALLOC_N(info_ret, nagentinfo) < 0) + goto cleanup; + + for (i =3D 0; i < nagentinfo; i++) { + if (!(info_ret[i] =3D qemuAgentFSInfoToPublic(agentinfo[i], vmdef)= )) + goto cleanup; + } + + *info =3D g_steal_pointer(&info_ret); + ret =3D nagentinfo; + + cleanup: + for (i =3D 0; i < nagentinfo; i++) { + qemuAgentFSInfoFree(agentinfo[i]); + /* if there was an error, free any memory we've allocated for the + * return value */ + if (info_ret) + virDomainFSInfoFree(info_ret[i]); + } + VIR_FREE(info_ret); + return ret; +} =20 static int qemuDomainGetFSInfo(virDomainPtr dom, @@ -21822,8 +21926,9 @@ qemuDomainGetFSInfo(virDomainPtr dom, { virQEMUDriverPtr driver =3D dom->conn->privateData; virDomainObjPtr vm; - qemuAgentPtr agent; + qemuAgentFSInfoPtr *agentinfo =3D NULL; int ret =3D -1; + int nfs; =20 virCheckFlags(0, ret); =20 @@ -21833,25 +21938,22 @@ qemuDomainGetFSInfo(virDomainPtr dom, if (virDomainGetFSInfoEnsureACL(dom->conn, vm->def) < 0) goto cleanup; =20 - if (qemuDomainObjBeginJobWithAgent(driver, vm, - QEMU_JOB_QUERY, - QEMU_AGENT_JOB_QUERY) < 0) + if ((nfs =3D qemuDomainGetFSInfoAgent(driver, vm, &agentinfo)) < 0) + goto cleanup; + + if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_QUERY) < 0) goto cleanup; =20 if (virDomainObjCheckActive(vm) < 0) goto endjob; =20 - if (!qemuDomainAgentAvailable(vm, true)) - goto endjob; - - agent =3D qemuDomainObjEnterAgent(vm); - ret =3D qemuAgentGetFSInfo(agent, info, vm->def); - qemuDomainObjExitAgent(vm, agent); + ret =3D virDomainFSInfoFormat(agentinfo, nfs, vm->def, info); =20 endjob: - qemuDomainObjEndJobWithAgent(driver, vm); + qemuDomainObjEndJob(driver, vm); =20 cleanup: + g_free(agentinfo); virDomainObjEndAPI(&vm); return ret; } @@ -22857,6 +22959,103 @@ qemuDomainGetGuestInfoCheckSupport(unsigned int *= types) *types =3D *types & supportedGuestInfoTypes; } =20 +/* Returns: 0 on success + * -1 otherwise + */ +static int +qemuAgentFSInfoFormatParams(qemuAgentFSInfoPtr *fsinfo, + int nfs, + virDomainDefPtr vmdef, + virTypedParameterPtr *params, + int *nparams, int *maxparams) +{ + int ret =3D -1; + size_t i, j; + + /* FIXME: get disk target */ + + if (virTypedParamsAddUInt(params, nparams, maxparams, + "fs.count", nfs) < 0) + goto cleanup; + + for (i =3D 0; i < nfs; i++) { + char param_name[VIR_TYPED_PARAM_FIELD_LENGTH]; + g_snprintf(param_name, VIR_TYPED_PARAM_FIELD_LENGTH, + "fs.%zu.name", i); + if (virTypedParamsAddString(params, nparams, maxparams, + param_name, fsinfo[i]->name) < 0) + goto cleanup; + g_snprintf(param_name, VIR_TYPED_PARAM_FIELD_LENGTH, + "fs.%zu.mountpoint", i); + if (virTypedParamsAddString(params, nparams, maxparams, + param_name, fsinfo[i]->mountpoint) < 0) + goto cleanup; + g_snprintf(param_name, VIR_TYPED_PARAM_FIELD_LENGTH, + "fs.%zu.fstype", i); + if (virTypedParamsAddString(params, nparams, maxparams, + param_name, fsinfo[i]->fstype) < 0) + goto cleanup; + + /* disk usage values are not returned by older guest agents, so + * only add the params if the value is set */ + g_snprintf(param_name, VIR_TYPED_PARAM_FIELD_LENGTH, + "fs.%zu.total-bytes", i); + if (fsinfo[i]->total_bytes !=3D -1 && + virTypedParamsAddULLong(params, nparams, maxparams, + param_name, fsinfo[i]->total_bytes) < = 0) + goto cleanup; + + g_snprintf(param_name, VIR_TYPED_PARAM_FIELD_LENGTH, + "fs.%zu.used-bytes", i); + if (fsinfo[i]->used_bytes !=3D -1 && + virTypedParamsAddULLong(params, nparams, maxparams, + param_name, fsinfo[i]->used_bytes) < 0) + goto cleanup; + + g_snprintf(param_name, VIR_TYPED_PARAM_FIELD_LENGTH, + "fs.%zu.disk.count", i); + if (virTypedParamsAddUInt(params, nparams, maxparams, + param_name, fsinfo[i]->ndisks) < 0) + goto cleanup; + for (j =3D 0; j < fsinfo[i]->ndisks; j++) { + virDomainDiskDefPtr diskdef =3D NULL; + qemuAgentDiskInfoPtr d =3D fsinfo[i]->disks[j]; + /* match the disk to the target in the vm definition */ + diskdef =3D virDomainDiskByAddress(vmdef, + &d->pci_controller, + d->bus, + d->target, + d->unit); + if (diskdef) { + g_snprintf(param_name, VIR_TYPED_PARAM_FIELD_LENGTH, + "fs.%zu.disk.%zu.alias", i, j); + if (diskdef->dst && + virTypedParamsAddString(params, nparams, maxparams, + param_name, diskdef->dst) < 0) + goto cleanup; + } + + g_snprintf(param_name, VIR_TYPED_PARAM_FIELD_LENGTH, + "fs.%zu.disk.%zu.serial", i, j); + if (d->serial && + virTypedParamsAddString(params, nparams, maxparams, + param_name, d->serial) < 0) + goto cleanup; + + g_snprintf(param_name, VIR_TYPED_PARAM_FIELD_LENGTH, + "fs.%zu.disk.%zu.device", i, j); + if (d->devnode && + virTypedParamsAddString(params, nparams, maxparams, + param_name, d->devnode) < 0) + goto cleanup; + } + } + ret =3D nfs; + + cleanup: + return ret; +} + static int qemuDomainGetGuestInfo(virDomainPtr dom, unsigned int types, @@ -22872,6 +23071,9 @@ qemuDomainGetGuestInfo(virDomainPtr dom, g_autofree char *hostname =3D NULL; unsigned int supportedTypes =3D types; int rc; + int nfs =3D 0; + qemuAgentFSInfoPtr *agentfsinfo =3D NULL; + size_t i; =20 virCheckFlags(0, -1); qemuDomainGetGuestInfoCheckSupport(&supportedTypes); @@ -22882,13 +23084,12 @@ qemuDomainGetGuestInfo(virDomainPtr dom, if (virDomainGetGuestInfoEnsureACL(dom->conn, vm->def) < 0) goto cleanup; =20 - if (qemuDomainObjBeginJobWithAgent(driver, vm, - QEMU_JOB_QUERY, - QEMU_AGENT_JOB_QUERY) < 0) + if (qemuDomainObjBeginAgentJob(driver, vm, + QEMU_AGENT_JOB_QUERY) < 0) goto cleanup; =20 if (!qemuDomainAgentAvailable(vm, true)) - goto endjob; + goto endagentjob; =20 agent =3D qemuDomainObjEnterAgent(vm); =20 @@ -22923,7 +23124,7 @@ qemuDomainGetGuestInfo(virDomainPtr dom, } } if (supportedTypes & VIR_DOMAIN_GUEST_INFO_FILESYSTEM) { - rc =3D qemuAgentGetFSInfoParams(agent, params, nparams, &maxparams= , vm->def); + rc =3D nfs =3D qemuAgentGetFSInfo(agent, &agentfsinfo); if (rc < 0 && !(rc =3D=3D -2 && types =3D=3D 0)) goto exitagent; } @@ -22933,10 +23134,29 @@ qemuDomainGetGuestInfo(virDomainPtr dom, exitagent: qemuDomainObjExitAgent(vm, agent); =20 + endagentjob: + qemuDomainObjEndAgentJob(vm); + + if (nfs > 0) { + if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_QUERY) < 0) + goto cleanup; + + if (virDomainObjCheckActive(vm) < 0) + goto endjob; + + /* we need to convert the agent fsinfo struct to parameters and ma= tch + * it to the vm disk target */ + qemuAgentFSInfoFormatParams(agentfsinfo, nfs, vm->def, params, npa= rams, &maxparams); + endjob: - qemuDomainObjEndJobWithAgent(driver, vm); + qemuDomainObjEndJob(driver, vm); + } =20 cleanup: + for (i =3D 0; i < nfs; i++) + qemuAgentFSInfoFree(agentfsinfo[i]); + VIR_FREE(agentfsinfo); + virDomainObjEndAPI(&vm); return ret; } diff --git a/tests/qemuagenttest.c b/tests/qemuagenttest.c index 644dc9d08b..a45ce4f44a 100644 --- a/tests/qemuagenttest.c +++ b/tests/qemuagenttest.c @@ -247,14 +247,14 @@ testQemuAgentGetFSInfo(const void *data) virDomainXMLOptionPtr xmlopt =3D (virDomainXMLOptionPtr)data; qemuMonitorTestPtr test =3D NULL; virDomainDefPtr def =3D NULL; - virDomainFSInfoPtr *info =3D NULL; + qemuAgentFSInfoPtr *info =3D NULL; int ret =3D -1, ninfo =3D 0, i; =20 if (testQemuAgentGetFSInfoCommon(xmlopt, &test, &def) < 0) goto cleanup; =20 if ((ninfo =3D qemuAgentGetFSInfo(qemuMonitorTestGetAgent(test), - &info, def)) < 0) + &info)) < 0) goto cleanup; =20 if (ninfo !=3D 3) { @@ -266,35 +266,48 @@ testQemuAgentGetFSInfo(const void *data) if (STRNEQ(info[2]->name, "sda1") || STRNEQ(info[2]->mountpoint, "/") || STRNEQ(info[2]->fstype, "ext4") || - info[2]->ndevAlias !=3D 1 || - !info[2]->devAlias || !info[2]->devAlias[0] || - STRNEQ(info[2]->devAlias[0], "hdc")) { + info[2]->ndisks !=3D 1 || + !info[2]->disks || !info[2]->disks[0]) { virReportError(VIR_ERR_INTERNAL_ERROR, - "unexpected filesystems information returned for sda1 (%s,%s)", - info[2]->name, info[2]->devAlias ? info[2]->devAlias[0] : "nul= l"); + "unexpected filesystems information returned for sda1 (%s)", + info[2]->name); ret =3D -1; goto cleanup; } if (STRNEQ(info[1]->name, "dm-1") || STRNEQ(info[1]->mountpoint, "/opt") || STRNEQ(info[1]->fstype, "vfat") || - info[1]->ndevAlias !=3D 2 || - !info[1]->devAlias || !info[1]->devAlias[0] || !info[1]->devAlias[= 1] || - STRNEQ(info[1]->devAlias[0], "vda") || - STRNEQ(info[1]->devAlias[1], "vdb")) { + info[1]->ndisks !=3D 2 || + !info[1]->disks || !info[1]->disks[0] || !info[1]->disks[1] || + STRNEQ(info[1]->disks[0]->bus_type, "virtio") || + info[1]->disks[0]->bus !=3D 0 || + info[1]->disks[0]->target !=3D 0 || + info[1]->disks[0]->unit !=3D 0 || + info[1]->disks[0]->pci_controller.domain !=3D 0 || + info[1]->disks[0]->pci_controller.bus !=3D 0 || + info[1]->disks[0]->pci_controller.slot !=3D 6 || + info[1]->disks[0]->pci_controller.function !=3D 0 || + STRNEQ(info[1]->disks[1]->bus_type, "virtio") || + info[1]->disks[1]->bus !=3D 0 || + info[1]->disks[1]->target !=3D 0 || + info[1]->disks[1]->unit !=3D 0 || + info[1]->disks[1]->pci_controller.domain !=3D 0 || + info[1]->disks[1]->pci_controller.bus !=3D 0 || + info[1]->disks[1]->pci_controller.slot !=3D 7 || + info[1]->disks[1]->pci_controller.function !=3D 0) { virReportError(VIR_ERR_INTERNAL_ERROR, - "unexpected filesystems information returned for dm-1 (%s,%s)", - info[0]->name, info[0]->devAlias ? info[0]->devAlias[0] : "nul= l"); + "unexpected filesystems information returned for dm-1 (%s)", + info[0]->name); ret =3D -1; goto cleanup; } if (STRNEQ(info[0]->name, "sdb1") || STRNEQ(info[0]->mountpoint, "/mnt/disk") || STRNEQ(info[0]->fstype, "xfs") || - info[0]->ndevAlias !=3D 0 || info[0]->devAlias) { + info[0]->ndisks !=3D 0 || info[0]->disks) { virReportError(VIR_ERR_INTERNAL_ERROR, - "unexpected filesystems information returned for sdb1 (%s,%s)", - info[0]->name, info[0]->devAlias ? info[0]->devAlias[0] : "nul= l"); + "unexpected filesystems information returned for sdb1 (%s)", + info[0]->name); ret =3D -1; goto cleanup; } @@ -313,7 +326,7 @@ testQemuAgentGetFSInfo(const void *data) "}") < 0) goto cleanup; =20 - if (qemuAgentGetFSInfo(qemuMonitorTestGetAgent(test), &info, def) !=3D= -1) { + if (qemuAgentGetFSInfo(qemuMonitorTestGetAgent(test), &info) >=3D 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", "agent get-fsinfo command should have failed"); goto cleanup; @@ -323,159 +336,13 @@ testQemuAgentGetFSInfo(const void *data) =20 cleanup: for (i =3D 0; i < ninfo; i++) - virDomainFSInfoFree(info[i]); + qemuAgentFSInfoFree(info[i]); VIR_FREE(info); virDomainDefFree(def); qemuMonitorTestFree(test); return ret; } =20 -static int -testQemuAgentGetFSInfoParams(const void *data) -{ - virDomainXMLOptionPtr xmlopt =3D (virDomainXMLOptionPtr)data; - qemuMonitorTestPtr test =3D NULL; - virDomainDefPtr def =3D NULL; - virTypedParameterPtr params =3D NULL; - int nparams =3D 0, maxparams =3D 0; - int ret =3D -1; - unsigned int count; - const char *name, *mountpoint, *fstype, *alias, *serial; - unsigned int diskcount; - unsigned long long bytesused, bytestotal; - const char *alias2; - - if (testQemuAgentGetFSInfoCommon(xmlopt, &test, &def) < 0) - goto cleanup; - - if (qemuAgentGetFSInfoParams(qemuMonitorTestGetAgent(test), - ¶ms, &nparams, &maxparams, def) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - "Failed to execute qemuAgentGetFSInfoParams()"); - goto cleanup; - } - - if (virTypedParamsGetUInt(params, nparams, "fs.count", &count) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - "expected filesystem count"); - goto cleanup; - } - - if (count !=3D 3) { - virReportError(VIR_ERR_INTERNAL_ERROR, - "expected 3 filesystems information, got %d", count= ); - goto cleanup; - } - - if (virTypedParamsGetString(params, nparams, "fs.2.name", &name) < 0 || - virTypedParamsGetString(params, nparams, "fs.2.mountpoint", &mount= point) < 0 || - virTypedParamsGetString(params, nparams, "fs.2.fstype", &fstype) <= 0 || - virTypedParamsGetULLong(params, nparams, "fs.2.used-bytes", &bytes= used) <=3D 0 || - virTypedParamsGetULLong(params, nparams, "fs.2.total-bytes", &byte= stotal) <=3D 0 || - virTypedParamsGetUInt(params, nparams, "fs.2.disk.count", &diskcou= nt) < 0 || - virTypedParamsGetString(params, nparams, "fs.2.disk.0.alias", &ali= as) < 0 || - virTypedParamsGetString(params, nparams, "fs.2.disk.0.serial", &se= rial) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - "Missing an expected parameter for sda1 (%s,%s)", - name, alias); - goto cleanup; - } - - if (STRNEQ(name, "sda1") || - STRNEQ(mountpoint, "/") || - STRNEQ(fstype, "ext4") || - bytesused !=3D 229019648 || - bytestotal !=3D 952840192 || - diskcount !=3D 1 || - STRNEQ(alias, "hdc") || - STRNEQ(serial, "ARBITRARYSTRING")) { - virReportError(VIR_ERR_INTERNAL_ERROR, - "unexpected filesystems information returned for sda1 (%s,%s)", - name, alias); - goto cleanup; - } - - if (virTypedParamsGetString(params, nparams, "fs.1.name", &name) < 0 || - virTypedParamsGetString(params, nparams, "fs.1.mountpoint", &mount= point) < 0 || - virTypedParamsGetString(params, nparams, "fs.1.fstype", &fstype) <= 0 || - virTypedParamsGetULLong(params, nparams, "fs.1.used-bytes", &bytes= used) =3D=3D 1 || - virTypedParamsGetULLong(params, nparams, "fs.1.total-bytes", &byte= stotal) =3D=3D 1 || - virTypedParamsGetUInt(params, nparams, "fs.1.disk.count", &diskcou= nt) < 0 || - virTypedParamsGetString(params, nparams, "fs.1.disk.0.alias", &ali= as) < 0 || - virTypedParamsGetString(params, nparams, "fs.1.disk.1.alias", &ali= as2) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - "Incorrect parameters for dm-1 (%s,%s)", - name, alias); - goto cleanup; - } - if (STRNEQ(name, "dm-1") || - STRNEQ(mountpoint, "/opt") || - STRNEQ(fstype, "vfat") || - diskcount !=3D 2 || - STRNEQ(alias, "vda") || - STRNEQ(alias2, "vdb")) { - virReportError(VIR_ERR_INTERNAL_ERROR, - "unexpected filesystems information returned for dm-1 (%s,%s)", - name, alias); - goto cleanup; - } - - alias =3D NULL; - if (virTypedParamsGetString(params, nparams, "fs.0.name", &name) < 0 || - virTypedParamsGetString(params, nparams, "fs.0.mountpoint", &mount= point) < 0 || - virTypedParamsGetString(params, nparams, "fs.0.fstype", &fstype) <= 0 || - virTypedParamsGetULLong(params, nparams, "fs.0.used-bytes", &bytes= used) =3D=3D 1 || - virTypedParamsGetULLong(params, nparams, "fs.0.total-bytes", &byte= stotal) =3D=3D 1 || - virTypedParamsGetUInt(params, nparams, "fs.0.disk.count", &diskcou= nt) < 0 || - virTypedParamsGetString(params, nparams, "fs.0.disk.0.alias", &ali= as) =3D=3D 1) { - virReportError(VIR_ERR_INTERNAL_ERROR, - "Incorrect parameters for sdb1 (%s,%s)", - name, alias); - goto cleanup; - } - - if (STRNEQ(name, "sdb1") || - STRNEQ(mountpoint, "/mnt/disk") || - STRNEQ(fstype, "xfs") || - diskcount !=3D 0 || - alias !=3D NULL) { - virReportError(VIR_ERR_INTERNAL_ERROR, - "unexpected filesystems information returned for sdb1 (%s,%s)", - name, alias); - goto cleanup; - } - - if (qemuMonitorTestAddAgentSyncResponse(test) < 0) - goto cleanup; - - if (qemuMonitorTestAddItem(test, "guest-get-fsinfo", - "{\"error\":" - " {\"class\":\"CommandDisabled\"," - " \"desc\":\"The command guest-get-fsin= fo " - "has been disabled for " - "this instance\"," - " \"data\":{\"name\":\"guest-get-fsinfo= \"}" - " }" - "}") < 0) - goto cleanup; - - if (qemuAgentGetFSInfoParams(qemuMonitorTestGetAgent(test), ¶ms, - &nparams, &maxparams, def) !=3D -2) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - "agent get-fsinfo command should have failed"); - goto cleanup; - } - - ret =3D 0; - - cleanup: - virTypedParamsFree(params, nparams); - virDomainDefFree(def); - qemuMonitorTestFree(test); - return ret; -} - - static int testQemuAgentSuspend(const void *data) { @@ -1438,7 +1305,6 @@ mymain(void) DO_TEST(FSFreeze); DO_TEST(FSThaw); DO_TEST(FSTrim); - DO_TEST(GetFSInfoParams); DO_TEST(GetFSInfo); DO_TEST(Suspend); DO_TEST(Shutdown); --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Apr 18 23:57:22 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) client-ip=207.211.31.81; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1578699221; cv=none; d=zohomail.com; s=zohoarc; b=ZWJvzgzRSp7asZolbpx1LK9QAlW4l/wvlON3D61lu0yqkBXO32SFZX9Rq5jLC3Chgfd6pDpJ47L+m9PPSDAcKgHy/+X4WonqZ0+GQ8rZMXYvn6IZ/IkTCP74Q+dXQaK774OAfHZtPNilHAqRiZCwZqhZ198ZHss2gX6STtMHnCs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1578699221; 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=XbqJy3wRUDqXz1iEGAwm3zS+W21+P9aYZLjkdM2/gGY=; b=Ye9qtKX0f+UWaVW5e5enE8dqUpg4f9MdulRcQe1+I217aL3kQczWG1SvMUArFl6c6kXzL9v/TUT5ugezQdGLlrSGnkt8Leqt9xPYF7MrtzxhBBvQDbnYQDHEv8hrzDqTlQeA409gH0Ak0tbrbX6VKK2KZ+wliO0W2ejIYMzvZew= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 1578699221101705.6847570252069; Fri, 10 Jan 2020 15:33:41 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-25-X5iTc5dhOQuUOIzegjvwEw-1; Fri, 10 Jan 2020 18:33:38 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id ECBBA8024D7; Fri, 10 Jan 2020 23:33:32 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C8DA260BE1; Fri, 10 Jan 2020 23:33:32 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 858DF820F9; Fri, 10 Jan 2020 23:33:32 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 00ANWNuL018748 for ; Fri, 10 Jan 2020 18:32:23 -0500 Received: by smtp.corp.redhat.com (Postfix) id C01DF5D72B; Fri, 10 Jan 2020 23:32:23 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-117-214.phx2.redhat.com [10.3.117.214]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7AA6A7C409; Fri, 10 Jan 2020 23:32:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1578699220; h=from:from:sender:sender: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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=XbqJy3wRUDqXz1iEGAwm3zS+W21+P9aYZLjkdM2/gGY=; b=a2MSfDoO5+w5pItHW25ucORNAskgBCUUVdahJUbABe3sPGNzSQNwqj2GEZd74rOuXqBqWL nGTM9GMQoOdUMb7wlJLi1qrrl309vv48FoeJSQC1z1SfwS+yc9c95c9ypWYfxKn9gvmUi8 mP/eLj59HZD8CcjzpVMQwYE07vI/ZQw= From: Jonathon Jongsma To: libvir-list@redhat.com Date: Fri, 10 Jan 2020 17:32:14 -0600 Message-Id: <20200110233217.18770-6-jjongsma@redhat.com> In-Reply-To: <20200110233217.18770-1-jjongsma@redhat.com> References: <20200110233217.18770-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: mprivozn@redhat.com Subject: [libvirt] [PATCH v2 5/8] qemu: remove qemuDomainObjBegin/EndJobWithAgent() X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-MC-Unique: X5iTc5dhOQuUOIzegjvwEw-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" This function potentially grabs both a monitor job and an agent job at the same time. This is problematic because it means that a malicious (or just buggy) guest agent can cause a denial of service on the host. The presence of this function makes it easy to do the wrong thing and hold both jobs at the same time. All existing uses have already been removed by previous commits. Signed-off-by: Jonathon Jongsma Reviewed-by: Michal Privoznik --- src/qemu/THREADS.txt | 58 +++++------------------------------------- src/qemu/qemu_domain.c | 56 ++++------------------------------------ src/qemu/qemu_domain.h | 7 ----- 3 files changed, 11 insertions(+), 110 deletions(-) diff --git a/src/qemu/THREADS.txt b/src/qemu/THREADS.txt index aa428fda6a..a7d8709a43 100644 --- a/src/qemu/THREADS.txt +++ b/src/qemu/THREADS.txt @@ -61,11 +61,12 @@ There are a number of locks on various objects =20 Agent job condition is then used when thread wishes to talk to qemu agent monitor. It is possible to acquire just agent job - (qemuDomainObjBeginAgentJob), or only normal job - (qemuDomainObjBeginJob) or both at the same time - (qemuDomainObjBeginJobWithAgent). Which type of job to grab depends - whether caller wishes to communicate only with agent socket, or only - with qemu monitor socket or both, respectively. + (qemuDomainObjBeginAgentJob), or only normal job (qemuDomainObjBeginJo= b) + but not both at the same time. Holding an agent job and a normal job w= ould + allow an unresponsive or malicious agent to block normal libvirt API a= nd + potentially result in a denial of service. Which type of job to grab + depends whether caller wishes to communicate only with agent socket, or + only with qemu monitor socket. =20 Immediately after acquiring the virDomainObjPtr lock, any method which intends to update state must acquire asynchronous, normal or @@ -141,18 +142,6 @@ To acquire the agent job condition =20 =20 =20 -To acquire both normal and agent job condition - - qemuDomainObjBeginJobWithAgent() - - Waits until there is no normal and no agent job set - - Sets both job.active and job.agentActive with required job types - - qemuDomainObjEndJobWithAgent() - - Sets both job.active and job.agentActive to 0 - - Signals on job.cond condition - - - To acquire the asynchronous job condition =20 qemuDomainObjBeginAsyncJob() @@ -292,41 +281,6 @@ Design patterns virDomainObjEndAPI(&obj); =20 =20 - * Invoking both monitor and agent commands on a virDomainObjPtr - - virDomainObjPtr obj; - qemuAgentPtr agent; - - obj =3D qemuDomObjFromDomain(dom); - - qemuDomainObjBeginJobWithAgent(obj, QEMU_JOB_TYPE, QEMU_AGENT_JOB_TYP= E); - - if (!virDomainObjIsActive(dom)) - goto cleanup; - - ...do prep work... - - if (!qemuDomainAgentAvailable(obj, true)) - goto cleanup; - - agent =3D qemuDomainObjEnterAgent(obj); - qemuAgentXXXX(agent, ..); - qemuDomainObjExitAgent(obj, agent); - - ... - - qemuDomainObjEnterMonitor(obj); - qemuMonitorXXXX(priv->mon); - qemuDomainObjExitMonitor(obj); - - /* Alternatively, talk to the monitor first and then talk to the agen= t. */ - - ...do final work... - - qemuDomainObjEndJobWithAgent(obj); - virDomainObjEndAPI(&obj); - - * Running asynchronous job =20 virDomainObjPtr obj; diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 1f358544ab..ce141c5256 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -9640,26 +9640,6 @@ qemuDomainObjBeginAgentJob(virQEMUDriverPtr driver, QEMU_ASYNC_JOB_NONE, false); } =20 -/** - * qemuDomainObjBeginJobWithAgent: - * - * Grabs both monitor and agent types of job. Use if caller talks to - * both monitor and guest agent. However, if @job (or @agentJob) is - * QEMU_JOB_NONE (or QEMU_AGENT_JOB_NONE) only agent job is acquired (or - * monitor job). - * - * To end job call qemuDomainObjEndJobWithAgent. - */ -int -qemuDomainObjBeginJobWithAgent(virQEMUDriverPtr driver, - virDomainObjPtr obj, - qemuDomainJob job, - qemuDomainAgentJob agentJob) -{ - return qemuDomainObjBeginJobInternal(driver, obj, job, agentJob, - QEMU_ASYNC_JOB_NONE, false); -} - int qemuDomainObjBeginAsyncJob(virQEMUDriverPtr driver, virDomainObjPtr obj, qemuDomainAsyncJob asyncJob, @@ -9774,31 +9754,6 @@ qemuDomainObjEndAgentJob(virDomainObjPtr obj) virCondBroadcast(&priv->job.cond); } =20 -void -qemuDomainObjEndJobWithAgent(virQEMUDriverPtr driver, - virDomainObjPtr obj) -{ - qemuDomainObjPrivatePtr priv =3D obj->privateData; - qemuDomainJob job =3D priv->job.active; - qemuDomainAgentJob agentJob =3D priv->job.agentActive; - - priv->jobs_queued--; - - VIR_DEBUG("Stopping both jobs: %s %s (async=3D%s vm=3D%p name=3D%s)", - qemuDomainJobTypeToString(job), - qemuDomainAgentJobTypeToString(agentJob), - qemuDomainAsyncJobTypeToString(priv->job.asyncJob), - obj, obj->def->name); - - qemuDomainObjResetJob(priv); - qemuDomainObjResetAgentJob(priv); - if (qemuDomainTrackJob(job)) - qemuDomainObjSaveStatus(driver, obj); - /* We indeed need to wake up ALL threads waiting because - * grabbing a job requires checking more variables. */ - virCondBroadcast(&priv->job.cond); -} - void qemuDomainObjEndAsyncJob(virQEMUDriverPtr driver, virDomainObjPtr obj) { @@ -9832,9 +9787,9 @@ qemuDomainObjAbortAsyncJob(virDomainObjPtr obj) * obj must be locked before calling * * To be called immediately before any QEMU monitor API call - * Must have already either called qemuDomainObjBeginJob() or - * qemuDomainObjBeginJobWithAgent() and checked that the VM is - * still active; may not be used for nested async jobs. + * Must have already called qemuDomainObjBeginJob() and checked + * that the VM is still active; may not be used for nested async + * jobs. * * To be followed with qemuDomainObjExitMonitor() once complete */ @@ -9956,9 +9911,8 @@ qemuDomainObjEnterMonitorAsync(virQEMUDriverPtr drive= r, * obj must be locked before calling * * To be called immediately before any QEMU agent API call. - * Must have already called qemuDomainObjBeginAgentJob() or - * qemuDomainObjBeginJobWithAgent() and checked that the VM is - * still active. + * Must have already called qemuDomainObjBeginAgentJob() and + * checked that the VM is still active. * * To be followed with qemuDomainObjExitAgent() once complete */ diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h index c6afc484f6..eb34f17921 100644 --- a/src/qemu/qemu_domain.h +++ b/src/qemu/qemu_domain.h @@ -650,11 +650,6 @@ int qemuDomainObjBeginAgentJob(virQEMUDriverPtr driver, virDomainObjPtr obj, qemuDomainAgentJob agentJob) G_GNUC_WARN_UNUSED_RESULT; -int qemuDomainObjBeginJobWithAgent(virQEMUDriverPtr driver, - virDomainObjPtr obj, - qemuDomainJob job, - qemuDomainAgentJob agentJob) - G_GNUC_WARN_UNUSED_RESULT; int qemuDomainObjBeginAsyncJob(virQEMUDriverPtr driver, virDomainObjPtr obj, qemuDomainAsyncJob asyncJob, @@ -673,8 +668,6 @@ int qemuDomainObjBeginJobNowait(virQEMUDriverPtr driver, void qemuDomainObjEndJob(virQEMUDriverPtr driver, virDomainObjPtr obj); void qemuDomainObjEndAgentJob(virDomainObjPtr obj); -void qemuDomainObjEndJobWithAgent(virQEMUDriverPtr driver, - virDomainObjPtr obj); void qemuDomainObjEndAsyncJob(virQEMUDriverPtr driver, virDomainObjPtr obj); void qemuDomainObjAbortAsyncJob(virDomainObjPtr obj); --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Apr 18 23:57:22 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1578699225; cv=none; d=zohomail.com; s=zohoarc; b=L3HQrGKLova7OYL3ujsAkf7MDpIhvlJ92NbQl2nYKDrRdW5kx9CIG5WaP/C6Ui7xh4Y3wprDR41wTYlLbrN7K6ZQSCA0L8xWhw5xHpz3BTDSmyg6Hbfki8J136VHNfDfs9BJ2HkoLUQDoM9kBV4yRUjhov5xcKAcmvFZLEdFQ0I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1578699225; 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=Duna7ITNrTFXa317rbsd9xG13hMhtEgNkmAKHjPj3+w=; b=kMnvXdWN6Q5C97l617G8uYNFj8CJdFG8rFGZKYQoGyQADVSPiQ2UySp8wrBv3j1miEWItkSrjogY1hHj1fNC12NpO5bBCCk4kdQ4h679AnZdpKrRHW+rB1gS1hMQysTRwMU87tAqNsnC6c7W9P2vVigp9XKFbCPRc6E5zmYU2Us= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 1578699225395772.1591588253798; Fri, 10 Jan 2020 15:33:45 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-2-pkuyKeaMMAi_joln0-RviQ-1; Fri, 10 Jan 2020 18:33:42 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7DE1EDB22; Fri, 10 Jan 2020 23:33:36 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 59A2687EC2; Fri, 10 Jan 2020 23:33:36 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 1C91018089CF; Fri, 10 Jan 2020 23:33:36 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 00ANWO4e018756 for ; Fri, 10 Jan 2020 18:32:24 -0500 Received: by smtp.corp.redhat.com (Postfix) id 3122B7C409; Fri, 10 Jan 2020 23:32:24 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-117-214.phx2.redhat.com [10.3.117.214]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E00FF5D72B; Fri, 10 Jan 2020 23:32:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1578699224; h=from:from:sender:sender: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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=Duna7ITNrTFXa317rbsd9xG13hMhtEgNkmAKHjPj3+w=; b=NxZNa8sVKgwiZ9vZLdjhd6I/4X/ikdkkzlMkGfQcElyIEkZXcGeDSqyGGkoef9H2os8KvL Y2JerUNYM2sJZTy+yuD3HDR2MO1xViVWas6rWWDl18Ch1io/PGWxh6+Vko2JLnFV5s1oVD 2itOo435fUYXloCY3AZyIYjctVtob80= From: Jonathon Jongsma To: libvir-list@redhat.com Date: Fri, 10 Jan 2020 17:32:15 -0600 Message-Id: <20200110233217.18770-7-jjongsma@redhat.com> In-Reply-To: <20200110233217.18770-1-jjongsma@redhat.com> References: <20200110233217.18770-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: mprivozn@redhat.com Subject: [libvirt] [PATCH v2 6/8] qemu: use glib alloc in qemuAgentGetFSInfoFillDisks() X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-MC-Unique: pkuyKeaMMAi_joln0-RviQ-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Signed-off-by: Jonathon Jongsma Reviewed-by: Michal Privoznik --- src/qemu/qemu_agent.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c index 47bfef7141..7186b1da64 100644 --- a/src/qemu/qemu_agent.c +++ b/src/qemu/qemu_agent.c @@ -1894,10 +1894,8 @@ qemuAgentGetFSInfoFillDisks(virJSONValuePtr jsondisk= s, =20 ndisks =3D virJSONValueArraySize(jsondisks); =20 - if (ndisks && - VIR_ALLOC_N(fsinfo->disks, ndisks) < 0) - return -1; - + if (ndisks) + fsinfo->disks =3D g_new0(qemuAgentDiskInfoPtr, ndisks); fsinfo->ndisks =3D ndisks; =20 for (i =3D 0; i < fsinfo->ndisks; i++) { @@ -1914,8 +1912,7 @@ qemuAgentGetFSInfoFillDisks(virJSONValuePtr jsondisks, return -1; } =20 - if (VIR_ALLOC(fsinfo->disks[i]) < 0) - return -1; + fsinfo->disks[i] =3D g_new0(qemuAgentDiskInfo, 1); disk =3D fsinfo->disks[i]; =20 if ((val =3D virJSONValueObjectGetString(jsondisk, "bus-type"))) --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Apr 18 23:57:22 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1578699190; cv=none; d=zohomail.com; s=zohoarc; b=kKHug9QvbkFY8qFi3Yx5So5bMtnAioieJ23lzcjfv1hsL9dJsa/3CO6t6IpPhXZXWI36fP8WvogzJty3QR8lEzTm4k+lXDR2LOflcVPkFBDRJooK0R4DuJi7ROVd4js4QCAuDaJQagpH3YSnda6Z82WnEa6owih+lYfewAQM5tA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1578699190; 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=S2VSzTJ2tooA5JDUtLB6+ByRb8l6iPkfCmV/Kxnms9M=; b=lXu65TvTf3xtRV7SAM8vFkwDYzNZR23yDMlSWySf9hh2M2lSafCYWRiP3kfhZP3nZZz57/Ss9pjFlznBzqP0WUnA6SK+tto3COGiWeb0X0WZLterYEN6qtIhAlfk/3pWPQENMGMBsV9DIvZrSAkC1VBC1rZMhJ0zxp7UpqMdKtk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 157869919096763.56679425059258; Fri, 10 Jan 2020 15:33:10 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-78-I_sHSPnkOPemAsgXR0zK6g-1; Fri, 10 Jan 2020 18:33:07 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id DBF79800D41; Fri, 10 Jan 2020 23:33:00 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B38A91001B00; Fri, 10 Jan 2020 23:33:00 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 6DBB381C7C; Fri, 10 Jan 2020 23:33:00 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 00ANWOCI018763 for ; Fri, 10 Jan 2020 18:32:24 -0500 Received: by smtp.corp.redhat.com (Postfix) id 95F497C408; Fri, 10 Jan 2020 23:32:24 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-117-214.phx2.redhat.com [10.3.117.214]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 50A095D72B; Fri, 10 Jan 2020 23:32:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1578699189; h=from:from:sender:sender: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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=S2VSzTJ2tooA5JDUtLB6+ByRb8l6iPkfCmV/Kxnms9M=; b=FBaXLlbXFRuVvVeWAtvoifTYPvvHafkOvjrOGDBxg7uJ5awTJaT/kkGH+tM3zr0b5WCIO4 8ebFUJW5GjjR3IQtdDB8DrV6+sZVzE8s3/pID6eukFmbVq/Zt4Noe6uaFRM2bLziU/qCg2 U/TePjtHuRL+52xmb7PwHG7BzagEYnM= From: Jonathon Jongsma To: libvir-list@redhat.com Date: Fri, 10 Jan 2020 17:32:16 -0600 Message-Id: <20200110233217.18770-8-jjongsma@redhat.com> In-Reply-To: <20200110233217.18770-1-jjongsma@redhat.com> References: <20200110233217.18770-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: mprivozn@redhat.com Subject: [libvirt] [PATCH v2 7/8] qemu: use glib allocation apis for qemuAgentFSInfo X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-MC-Unique: I_sHSPnkOPemAsgXR0zK6g-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Switch from old VIR_ allocation APIs to glib equivalents. Signed-off-by: Jonathon Jongsma Reviewed-by: Michal Privoznik --- src/qemu/qemu_agent.c | 26 ++++++++++++-------------- src/qemu/qemu_driver.c | 2 +- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c index 7186b1da64..b6556ffbaf 100644 --- a/src/qemu/qemu_agent.c +++ b/src/qemu/qemu_agent.c @@ -1854,10 +1854,10 @@ qemuAgentDiskInfoFree(qemuAgentDiskInfoPtr info) if (!info) return; =20 - VIR_FREE(info->serial); - VIR_FREE(info->bus_type); - VIR_FREE(info->devnode); - VIR_FREE(info); + g_free(info->serial); + g_free(info->bus_type); + g_free(info->devnode); + g_free(info); } =20 void @@ -1868,15 +1868,15 @@ qemuAgentFSInfoFree(qemuAgentFSInfoPtr info) if (!info) return; =20 - VIR_FREE(info->mountpoint); - VIR_FREE(info->name); - VIR_FREE(info->fstype); + g_free(info->mountpoint); + g_free(info->name); + g_free(info->fstype); =20 for (i =3D 0; i < info->ndisks; i++) qemuAgentDiskInfoFree(info->disks[i]); - VIR_FREE(info->disks); + g_free(info->disks); =20 - VIR_FREE(info); + g_free(info); } =20 static int @@ -1999,8 +1999,7 @@ qemuAgentGetFSInfo(qemuAgentPtr mon, *info =3D NULL; goto cleanup; } - if (VIR_ALLOC_N(info_ret, ndata) < 0) - goto cleanup; + info_ret =3D g_new0(qemuAgentFSInfoPtr, ndata); =20 for (i =3D 0; i < ndata; i++) { /* Reverse the order to arrange in mount order */ @@ -2017,8 +2016,7 @@ qemuAgentGetFSInfo(qemuAgentPtr mon, goto cleanup; } =20 - if (VIR_ALLOC(info_ret[i]) < 0) - goto cleanup; + info_ret[i] =3D g_new0(qemuAgentFSInfo, 1); =20 if (!(result =3D virJSONValueObjectGetString(entry, "mountpoint"))= ) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", @@ -2088,7 +2086,7 @@ qemuAgentGetFSInfo(qemuAgentPtr mon, if (info_ret) { for (i =3D 0; i < ndata; i++) qemuAgentFSInfoFree(info_ret[i]); - VIR_FREE(info_ret); + g_free(info_ret); } return ret; } diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 50e6178dbb..812ff45707 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -23155,7 +23155,7 @@ qemuDomainGetGuestInfo(virDomainPtr dom, cleanup: for (i =3D 0; i < nfs; i++) qemuAgentFSInfoFree(agentfsinfo[i]); - VIR_FREE(agentfsinfo); + g_free(agentfsinfo); =20 virDomainObjEndAPI(&vm); return ret; --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Apr 18 23:57:22 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1578699197; cv=none; d=zohomail.com; s=zohoarc; b=cvS0hhTRrv62I904uudCiRX5h7RVl15cO/RTOkPcT1GUlUinrkIB01s8V/AQw6rqxfIbc9yryO6HZMmbxdLvsDeE20TW5taQozcHxSwCm6sEZ5XqEqaAeXpC01zp0WNqmJA2uIu22nRjC3Ka5WBCc3QmBd19AoKmyJ09G+T/c0g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1578699197; 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=GcZ6ZuyeHLUYgwcN3btOie2HDVdfT+3FSD4D2VzFKPk=; b=RA2izxOa+/HNb7xAOjCrBdG57S6jU3PLzXrhtg5GVcQ+k8RjK6dnJSsEW7X96HdSFp/Rq7kmH9feOyRAbxV67r69naHd6OID/Qh5ry8tMIZ9wNHr4Tw/whTp/mgAwsux15JsZZjkOtfOzw4xn2BVob47Z2YERzYkQi6C3Shv9Jo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 1578699197411891.0978403477558; Fri, 10 Jan 2020 15:33:17 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-4-8rlPKpU0NAeS_9lW7dw_4A-1; Fri, 10 Jan 2020 18:33:12 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id DA08F800D4C; Fri, 10 Jan 2020 23:33:04 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B28A087EC1; Fri, 10 Jan 2020 23:33:04 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 6BC93820EE; Fri, 10 Jan 2020 23:33:04 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 00ANWPe9018768 for ; Fri, 10 Jan 2020 18:32:25 -0500 Received: by smtp.corp.redhat.com (Postfix) id 058017C408; Fri, 10 Jan 2020 23:32:25 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-117-214.phx2.redhat.com [10.3.117.214]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B5CEE5D72B; Fri, 10 Jan 2020 23:32:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1578699196; h=from:from:sender:sender: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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=GcZ6ZuyeHLUYgwcN3btOie2HDVdfT+3FSD4D2VzFKPk=; b=PP65HBsJ4sbJt8bBtYcJcHAvGcnWRlSu+2naXLUfWoWETwVnhvMJL2aeAEAEWshNTPjNMe 3KSx2f8KgQzjQ/i6IK+pyjygRYICGoCLdWB+i6sUNxR9IdwvZfMFVdQZt4yUtWFv3JCWuU gqW5nZ/R23gbZRs9H3M/orinpv7YwX0= From: Jonathon Jongsma To: libvir-list@redhat.com Date: Fri, 10 Jan 2020 17:32:17 -0600 Message-Id: <20200110233217.18770-9-jjongsma@redhat.com> In-Reply-To: <20200110233217.18770-1-jjongsma@redhat.com> References: <20200110233217.18770-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: mprivozn@redhat.com Subject: [libvirt] [PATCH v2 8/8] Use glib alloc API for virDomainFSInfo X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-MC-Unique: 8rlPKpU0NAeS_9lW7dw_4A-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Signed-off-by: Jonathon Jongsma Reviewed-by: Michal Privoznik --- src/libvirt-domain.c | 12 ++++++------ src/qemu/qemu_driver.c | 18 +++++------------- src/remote/remote_daemon_dispatch.c | 2 +- 3 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c index eb66999f07..33c0e1949d 100644 --- a/src/libvirt-domain.c +++ b/src/libvirt-domain.c @@ -11924,15 +11924,15 @@ virDomainFSInfoFree(virDomainFSInfoPtr info) if (!info) return; =20 - VIR_FREE(info->mountpoint); - VIR_FREE(info->name); - VIR_FREE(info->fstype); + g_free(info->mountpoint); + g_free(info->name); + g_free(info->fstype); =20 for (i =3D 0; i < info->ndevAlias; i++) - VIR_FREE(info->devAlias[i]); - VIR_FREE(info->devAlias); + g_free(info->devAlias[i]); + g_free(info->devAlias); =20 - VIR_FREE(info); + g_free(info); } =20 /** diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 812ff45707..f905ef4675 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -21849,17 +21849,14 @@ qemuAgentFSInfoToPublic(qemuAgentFSInfoPtr agent, size_t i; virDomainDiskDefPtr diskDef; =20 - if (VIR_ALLOC(ret) < 0) - goto error; + ret =3D g_new0(virDomainFSInfo, 1); =20 ret->mountpoint =3D g_strdup(agent->mountpoint); ret->name =3D g_strdup(agent->name); ret->fstype =3D g_strdup(agent->fstype); =20 - if (agent->disks && - VIR_ALLOC_N(ret->devAlias, agent->ndisks) < 0) - goto error; - + if (agent->disks) + ret->devAlias =3D g_new0(char *, agent->ndisks); ret->ndevAlias =3D agent->ndisks; =20 for (i =3D 0; i < ret->ndevAlias; i++) { @@ -21875,10 +21872,6 @@ qemuAgentFSInfoToPublic(qemuAgentFSInfoPtr agent, } =20 return ret; - - error: - virDomainFSInfoFree(ret); - return NULL; } =20 /* Returns: 0 on success @@ -21896,8 +21889,7 @@ virDomainFSInfoFormat(qemuAgentFSInfoPtr *agentinfo, =20 if (nagentinfo < 0) return ret; - if (VIR_ALLOC_N(info_ret, nagentinfo) < 0) - goto cleanup; + info_ret =3D g_new0(virDomainFSInfoPtr, nagentinfo); =20 for (i =3D 0; i < nagentinfo; i++) { if (!(info_ret[i] =3D qemuAgentFSInfoToPublic(agentinfo[i], vmdef)= )) @@ -21915,7 +21907,7 @@ virDomainFSInfoFormat(qemuAgentFSInfoPtr *agentinfo, if (info_ret) virDomainFSInfoFree(info_ret[i]); } - VIR_FREE(info_ret); + g_free(info_ret); return ret; } =20 diff --git a/src/remote/remote_daemon_dispatch.c b/src/remote/remote_daemon= _dispatch.c index 9c294ddc39..70fdb7f36b 100644 --- a/src/remote/remote_daemon_dispatch.c +++ b/src/remote/remote_daemon_dispatch.c @@ -7032,7 +7032,7 @@ remoteDispatchDomainGetFSInfo(virNetServerPtr server = G_GNUC_UNUSED, if (ninfo >=3D 0) for (i =3D 0; i < ninfo; i++) virDomainFSInfoFree(info[i]); - VIR_FREE(info); + g_free(info); =20 return rv; } --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list