From nobody Thu May 15 21:39:06 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1508873784624959.1383327865409; Tue, 24 Oct 2017 12:36:24 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 1ABB2C04AC64; Tue, 24 Oct 2017 19:36:23 +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 E7B89189E6; Tue, 24 Oct 2017 19:36:22 +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 50334180596C; Tue, 24 Oct 2017 19:36:15 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v9OJZoOk009772 for ; Tue, 24 Oct 2017 15:35:50 -0400 Received: by smtp.corp.redhat.com (Postfix) id AA5735C552; Tue, 24 Oct 2017 19:35:50 +0000 (UTC) Received: from mx1.redhat.com (ext-mx08.extmail.prod.ext.phx2.redhat.com [10.5.110.32]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A51B25C8A1 for ; Tue, 24 Oct 2017 19:35:50 +0000 (UTC) Received: from mail-qt0-f173.google.com (mail-qt0-f173.google.com [209.85.216.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5C19CC0587F6 for ; Tue, 24 Oct 2017 19:35:46 +0000 (UTC) Received: by mail-qt0-f173.google.com with SMTP id p1so31940839qtg.2 for ; Tue, 24 Oct 2017 12:35:46 -0700 (PDT) Received: from dawid-fedora.datto.lan ([47.19.105.250]) by smtp.gmail.com with ESMTPSA id f66sm683127qkc.25.2017.10.24.12.35.44 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 24 Oct 2017 12:35:44 -0700 (PDT) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 1ABB2C04AC64 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=fail (p=none dis=none) header.from=datto.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 1ABB2C04AC64 Authentication-Results: mx1.redhat.com; dkim=fail reason="signature verification failed" (2048-bit key) header.d=datto-com.20150623.gappssmtp.com header.i=@datto-com.20150623.gappssmtp.com header.b="gelbyiG1" DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 5C19CC0587F6 Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=pass (p=none dis=none) header.from=datto.com Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=dzamirski@datto.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 5C19CC0587F6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=datto-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references; bh=22c9oOYwGb0PzuLmq30ncoO6HZqm7GPeBpoL1IcY7vo=; b=gelbyiG1irSCAhdzGeb6eAfDSG3j09V52wQ6eZKXquhKveQocvtOc1SLhyM9elIpRC i0w7Oq3K3nkVmUIys3HHsIAl3b+DWIoSJBa5B06WYfg7T5LBnT4Wz0w+F07f0BnID50+ lLYbVJMvBPOSQFVr9HuhGX2+zVhnkJ0Xm8SutRvC1PdN4tQbPFkNbwp3YXk16WTfQRhz 1E6/nVmfFg0T1fAAuewpeB+2k4BUwb+erlkIEsE2cXW3dBCLF0M/DR06xPlVhkgZdnNq DC+WIM/bk3/IfhvTfw/DNzt7KHpIS2KbCPB3EWa4fure5rpR+5GevHx2pkZPGTOA0EJa A4Ug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=22c9oOYwGb0PzuLmq30ncoO6HZqm7GPeBpoL1IcY7vo=; b=ExKT3hfKXDcDzuhANuh5iI73UIstZx2fOjMFcBqYTWv9mL/1BVunzZT/7pniAetB3s HboD11dpY94Y79hIrd5oel8qzuDawNihCJKrI3pYvIpHXMmmI53n+F+H1N8AjURmBGUA /kw4b+0Cwe+dsrcbT9RpT7hKENxnj24g3RfP4rX4b5WNU8AlMkHfp2k4m1ZQHDth+Tm2 aaVs1kW9gAzGqqnWhQ6xvsfoxhEEmE6dm4nfFju0Ijgb6soKwaSPyGOG26O8sxr2V9Jx ozOB2THm6qAfjW+qgCojtj6w79I6pLDcU6mMAcRHPzZXmz5ZI2PVhz/ZDDAIHWKN0e+G 8xyg== X-Gm-Message-State: AMCzsaVfNWw53hfC+AYuavg7dDAB498Kwv++eRA5Da9Li3vyVHsy4ekX 4hVNoNTxZ8Oigufkh32a4KwgT+e/gFM= X-Google-Smtp-Source: ABhQp+SqJKJW0GTO2wFuNe6nzrcCau9qa7tPVty1JqbGT+PxK2TTL7BPaeX40nj8VZk4GI8heqF4oA== X-Received: by 10.200.8.149 with SMTP id v21mr26850696qth.123.1508873745183; Tue, 24 Oct 2017 12:35:45 -0700 (PDT) From: Dawid Zamirski To: libvir-list@redhat.com Date: Tue, 24 Oct 2017 15:35:35 -0400 Message-Id: <20171024193538.9078-13-dzamirski@datto.com> In-Reply-To: <20171024193538.9078-1-dzamirski@datto.com> References: <20171024193538.9078-1-dzamirski@datto.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Tue, 24 Oct 2017 19:35:46 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Tue, 24 Oct 2017 19:35:46 +0000 (UTC) for IP:'209.85.216.173' DOMAIN:'mail-qt0-f173.google.com' HELO:'mail-qt0-f173.google.com' FROM:'dzamirski@datto.com' RCPT:'' X-RedHat-Spam-Score: -0.031 (DKIM_SIGNED, DKIM_VALID, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_PASS) 209.85.216.173 mail-qt0-f173.google.com 209.85.216.173 mail-qt0-f173.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.32 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 12/15] vbox: Correctly generate drive name in dumpxml 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Tue, 24 Oct 2017 19:36:23 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" If a VBOX VM has e.g. a SATA and SCSI disk attached, the XML generated by dumpxml used to produce "sda" for both of those disks. This is an invalid domain XML as libvirt does not allow duplicate device names. To address this, keep the running total of disks that will use "sd" prefix for device name and pass it to the vboxGenerateMediumName which no longer tries to "compute" the value based only on current and max port and slot values. After this the vboxGetMaxPortSlotValues is not needed and was deleted. --- src/vbox/vbox_common.c | 414 +++++++++++++++++++++------------------------= ---- 1 file changed, 177 insertions(+), 237 deletions(-) diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c index 715eb670e..9dc36a1b2 100644 --- a/src/vbox/vbox_common.c +++ b/src/vbox/vbox_common.c @@ -290,61 +290,6 @@ static int openSessionForMachine(vboxDriverPtr data, c= onst unsigned char *dom_uu return 0; } =20 -/** - * function to get the values for max port per - * instance and max slots per port for the devices - * - * @returns true on Success, false on failure. - * @param vbox Input IVirtualBox pointer - * @param maxPortPerInst Output array of max port per instance - * @param maxSlotPerPort Output array of max slot per port - * - */ - -static bool vboxGetMaxPortSlotValues(IVirtualBox *vbox, - PRUint32 *maxPortPerInst, - PRUint32 *maxSlotPerPort) -{ - ISystemProperties *sysProps =3D NULL; - - if (!vbox) - return false; - - gVBoxAPI.UIVirtualBox.GetSystemProperties(vbox, &sysProps); - - if (!sysProps) - return false; - - gVBoxAPI.UISystemProperties.GetMaxPortCountForStorageBus(sysProps, - StorageBus_ID= E, - &maxPortPerIn= st[StorageBus_IDE]); - gVBoxAPI.UISystemProperties.GetMaxPortCountForStorageBus(sysProps, - StorageBus_SA= TA, - &maxPortPerIn= st[StorageBus_SATA]); - gVBoxAPI.UISystemProperties.GetMaxPortCountForStorageBus(sysProps, - StorageBus_SC= SI, - &maxPortPerIn= st[StorageBus_SCSI]); - gVBoxAPI.UISystemProperties.GetMaxPortCountForStorageBus(sysProps, - StorageBus_Fl= oppy, - &maxPortPerIn= st[StorageBus_Floppy]); - - gVBoxAPI.UISystemProperties.GetMaxDevicesPerPortForStorageBus(sysProps, - StorageB= us_IDE, - &maxSlot= PerPort[StorageBus_IDE]); - gVBoxAPI.UISystemProperties.GetMaxDevicesPerPortForStorageBus(sysProps, - StorageB= us_SATA, - &maxSlot= PerPort[StorageBus_SATA]); - gVBoxAPI.UISystemProperties.GetMaxDevicesPerPortForStorageBus(sysProps, - StorageB= us_SCSI, - &maxSlot= PerPort[StorageBus_SCSI]); - gVBoxAPI.UISystemProperties.GetMaxDevicesPerPortForStorageBus(sysProps, - StorageB= us_Floppy, - &maxSlot= PerPort[StorageBus_Floppy]); - - VBOX_RELEASE(sysProps); - - return true; -} =20 /** * function to generate the name for medium, @@ -352,57 +297,40 @@ static bool vboxGetMaxPortSlotValues(IVirtualBox *vbo= x, * * @returns null terminated string with device name or NULL * for failures - * @param conn Input Connection Pointer * @param storageBus Input storage bus type - * @param deviceInst Input device instance number * @param devicePort Input port number * @param deviceSlot Input slot number - * @param aMaxPortPerInst Input array of max port per device instance - * @param aMaxSlotPerPort Input array of max slot per device port - * + * @param sdCount Running total of disk devices with "sd" pr= efix */ -static char *vboxGenerateMediumName(PRUint32 storageBus, - PRInt32 deviceInst, - PRInt32 devicePort, - PRInt32 deviceSlot, - PRUint32 *aMaxPortPerInst, - PRUint32 *aMaxSlotPerPort) +static char * +vboxGenerateMediumName(PRUint32 storageBus, + PRInt32 devicePort, + PRInt32 deviceSlot, + size_t sdCount) { const char *prefix =3D NULL; char *name =3D NULL; int total =3D 0; - PRUint32 maxPortPerInst =3D 0; - PRUint32 maxSlotPerPort =3D 0; - - if (!aMaxPortPerInst || - !aMaxSlotPerPort) - return NULL; =20 if ((storageBus < StorageBus_IDE) || - (storageBus > StorageBus_Floppy)) + (storageBus > StorageBus_SAS)) return NULL; =20 - maxPortPerInst =3D aMaxPortPerInst[storageBus]; - maxSlotPerPort =3D aMaxSlotPerPort[storageBus]; - total =3D (deviceInst * maxPortPerInst * maxSlotPerPort) - + (devicePort * maxSlotPerPort) - + deviceSlot; - if (storageBus =3D=3D StorageBus_IDE) { prefix =3D "hd"; - } else if ((storageBus =3D=3D StorageBus_SATA) || - (storageBus =3D=3D StorageBus_SCSI)) { + total =3D devicePort * 2 + deviceSlot; + } else if (storageBus =3D=3D StorageBus_SATA || + storageBus =3D=3D StorageBus_SCSI || + storageBus =3D=3D StorageBus_SAS) { prefix =3D "sd"; + total =3D sdCount; } else if (storageBus =3D=3D StorageBus_Floppy) { + total =3D deviceSlot; prefix =3D "fd"; } =20 name =3D virIndexToDiskName(total, prefix); =20 - VIR_DEBUG("name=3D%s, total=3D%d, storageBus=3D%u, deviceInst=3D%d, " - "devicePort=3D%d deviceSlot=3D%d, maxPortPerInst=3D%u maxSlotPer= Port=3D%u", - NULLSTR(name), total, storageBus, deviceInst, devicePort, - deviceSlot, maxPortPerInst, maxSlotPerPort); return name; } =20 @@ -3270,20 +3198,17 @@ vboxDumpStorageControllers(virDomainDefPtr def, IMa= chine *machine) } =20 =20 -static void -vboxDumpIDEHDDs(virDomainDefPtr def, vboxDriverPtr data, IMachine *machine) +static int +vboxDumpDisks(virDomainDefPtr def, vboxDriverPtr data, IMachine *machine) { - /* dump IDE hdds if present */ vboxArray mediumAttachments =3D VBOX_ARRAY_INITIALIZER; - bool error =3D false; + size_t sdCount =3D 0, i; int diskCount =3D 0; - size_t i; - PRUint32 maxPortPerInst[StorageBus_Floppy + 1] =3D {}; - PRUint32 maxSlotPerPort[StorageBus_Floppy + 1] =3D {}; + int ret =3D -1; =20 def->ndisks =3D 0; gVBoxAPI.UArray.vboxArrayGet(&mediumAttachments, machine, - gVBoxAPI.UArray.handleMachineGetMediumAtt= achments(machine)); + gVBoxAPI.UArray.handleMachineGetMediumAttachments(machine= )); =20 /* get the number of attachments */ for (i =3D 0; i < mediumAttachments.count; i++) { @@ -3300,24 +3225,19 @@ vboxDumpIDEHDDs(virDomainDefPtr def, vboxDriverPtr = data, IMachine *machine) } =20 /* Allocate mem, if fails return error */ - if (VIR_ALLOC_N(def->disks, def->ndisks) >=3D 0) { - for (i =3D 0; i < def->ndisks; i++) { - virDomainDiskDefPtr disk =3D virDomainDiskDefNew(NULL); - if (!disk) { - error =3D true; - break; - } - def->disks[i] =3D disk; - } - } else { - error =3D true; - } + if (VIR_ALLOC_N(def->disks, def->ndisks) < 0) + goto cleanup; =20 - if (!error) - error =3D !vboxGetMaxPortSlotValues(data->vboxObj, maxPortPerInst,= maxSlotPerPort); + for (i =3D 0; i < def->ndisks; i++) { + virDomainDiskDefPtr disk =3D virDomainDiskDefNew(NULL); + if (!disk) + goto cleanup; + + def->disks[i] =3D disk; + } =20 /* get the attachment details here */ - for (i =3D 0; i < mediumAttachments.count && diskCount < def->ndisks &= & !error; i++) { + for (i =3D 0; i < mediumAttachments.count && diskCount < def->ndisks; = i++) { IMediumAttachment *imediumattach =3D mediumAttachments.items[i]; IStorageController *storageController =3D NULL; PRUnichar *storageControllerName =3D NULL; @@ -3327,7 +3247,6 @@ vboxDumpIDEHDDs(virDomainDefPtr def, vboxDriverPtr da= ta, IMachine *machine) IMedium *medium =3D NULL; PRUnichar *mediumLocUtf16 =3D NULL; char *mediumLocUtf8 =3D NULL; - PRUint32 deviceInst =3D 0; PRInt32 devicePort =3D 0; PRInt32 deviceSlot =3D 0; =20 @@ -3363,16 +3282,36 @@ vboxDumpIDEHDDs(virDomainDefPtr def, vboxDriverPtr = data, IMachine *machine) if (!virDomainDiskGetSource(def->disks[diskCount])) { VBOX_RELEASE(medium); VBOX_RELEASE(storageController); - error =3D true; - break; + + goto cleanup; } =20 gVBoxAPI.UIStorageController.GetBus(storageController, &storageBus= ); + gVBoxAPI.UIMediumAttachment.GetPort(imediumattach, &devicePort); + gVBoxAPI.UIMediumAttachment.GetDevice(imediumattach, &deviceSlot); + + def->disks[diskCount]->dst =3D vboxGenerateMediumName(storageBus, + devicePort, + deviceSlot, + sdCount); + if (!def->disks[diskCount]->dst) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Could not generate medium name for the disk " + "at: port:%d, slot:%d"), devicePort, deviceSl= ot); + VBOX_RELEASE(medium); + VBOX_RELEASE(storageController); + + goto cleanup; + } + if (storageBus =3D=3D StorageBus_IDE) { def->disks[diskCount]->bus =3D VIR_DOMAIN_DISK_BUS_IDE; } else if (storageBus =3D=3D StorageBus_SATA) { + sdCount++; def->disks[diskCount]->bus =3D VIR_DOMAIN_DISK_BUS_SATA; - } else if (storageBus =3D=3D StorageBus_SCSI) { + } else if (storageBus =3D=3D StorageBus_SCSI || + storageBus =3D=3D StorageBus_SAS) { + sdCount++; def->disks[diskCount]->bus =3D VIR_DOMAIN_DISK_BUS_SCSI; } else if (storageBus =3D=3D StorageBus_Floppy) { def->disks[diskCount]->bus =3D VIR_DOMAIN_DISK_BUS_FDC; @@ -3386,24 +3325,6 @@ vboxDumpIDEHDDs(virDomainDefPtr def, vboxDriverPtr d= ata, IMachine *machine) else if (deviceType =3D=3D DeviceType_DVD) def->disks[diskCount]->device =3D VIR_DOMAIN_DISK_DEVICE_CDROM; =20 - gVBoxAPI.UIMediumAttachment.GetPort(imediumattach, &devicePort); - gVBoxAPI.UIMediumAttachment.GetDevice(imediumattach, &deviceSlot); - def->disks[diskCount]->dst =3D vboxGenerateMediumName(storageBus, - deviceInst, - devicePort, - deviceSlot, - maxPortPerInst, - maxSlotPerPort= ); - if (!def->disks[diskCount]->dst) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Could not generate medium name for the disk " - "at: controller instance:%u, port:%d, slot:%d= "), - deviceInst, devicePort, deviceSlot); - VBOX_RELEASE(medium); - VBOX_RELEASE(storageController); - error =3D true; - break; - } =20 gVBoxAPI.UIMedium.GetReadOnly(medium, &readOnly); if (readOnly =3D=3D PR_TRUE) @@ -3417,15 +3338,20 @@ vboxDumpIDEHDDs(virDomainDefPtr def, vboxDriverPtr = data, IMachine *machine) diskCount++; } =20 + ret =3D 0; + + cleanup: gVBoxAPI.UArray.vboxArrayRelease(&mediumAttachments); =20 /* cleanup on error */ - if (error) { + if (ret < 0) { for (i =3D 0; i < def->ndisks; i++) VIR_FREE(def->disks[i]); VIR_FREE(def->disks); def->ndisks =3D 0; } + + return ret; } =20 static int @@ -4120,7 +4046,8 @@ static char *vboxDomainGetXMLDesc(virDomainPtr dom, u= nsigned int flags) if (vboxDumpStorageControllers(def, machine) < 0) goto cleanup; =20 - vboxDumpIDEHDDs(def, data, machine); + if (vboxDumpDisks(def, data, machine) < 0) + goto cleanup; =20 vboxDumpSharedFolders(def, data, machine); vboxDumpNetwork(def, data, machine, networkAdapterCount); @@ -5676,8 +5603,9 @@ vboxDomainSnapshotGet(vboxDriverPtr data, return snapshot; } =20 -static int vboxSnapshotGetReadWriteDisks(virDomainSnapshotDefPtr def, - virDomainSnapshotPtr snapshot) +static int +vboxSnapshotGetReadWriteDisks(virDomainSnapshotDefPtr def, + virDomainSnapshotPtr snapshot) { virDomainPtr dom =3D snapshot->domain; vboxDriverPtr data =3D dom->conn->privateData; @@ -5686,9 +5614,7 @@ static int vboxSnapshotGetReadWriteDisks(virDomainSna= pshotDefPtr def, ISnapshot *snap =3D NULL; IMachine *snapMachine =3D NULL; vboxArray mediumAttachments =3D VBOX_ARRAY_INITIALIZER; - PRUint32 maxPortPerInst[StorageBus_Floppy + 1] =3D {}; - PRUint32 maxSlotPerPort[StorageBus_Floppy + 1] =3D {}; - int diskCount =3D 0; + size_t diskCount =3D 0, sdCount =3D 0; nsresult rc; vboxIID snapIid; char *snapshotUuidStr =3D NULL; @@ -5757,9 +5683,6 @@ static int vboxSnapshotGetReadWriteDisks(virDomainSna= pshotDefPtr def, goto cleanup; } =20 - if (!vboxGetMaxPortSlotValues(data->vboxObj, maxPortPerInst, maxSlotPe= rPort)) - goto cleanup; - /* get the attachment details here */ for (i =3D 0; i < mediumAttachments.count && diskCount < def->ndisks; = i++) { IStorageController *storageController =3D NULL; @@ -5769,7 +5692,6 @@ static int vboxSnapshotGetReadWriteDisks(virDomainSna= pshotDefPtr def, IMedium *disk =3D NULL; PRUnichar *childLocUtf16 =3D NULL; char *childLocUtf8 =3D NULL; - PRUint32 deviceInst =3D 0; PRInt32 devicePort =3D 0; PRInt32 deviceSlot =3D 0; vboxArray children =3D VBOX_ARRAY_INITIALIZER; @@ -5778,26 +5700,72 @@ static int vboxSnapshotGetReadWriteDisks(virDomainS= napshotDefPtr def, void *handle; size_t j =3D 0; size_t k =3D 0; + if (!imediumattach) continue; - rc =3D gVBoxAPI.UIMediumAttachment.GetMedium(imediumattach, &disk); + + rc =3D gVBoxAPI.UIMediumAttachment.GetController(imediumattach, + &storageControllerN= ame); if (NS_FAILED(rc)) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("cannot get medium")); + _("Cannot get storage controller name")); goto cleanup; } - if (!disk) - continue; - rc =3D gVBoxAPI.UIMediumAttachment.GetController(imediumattach, &s= torageControllerName); + + rc =3D gVBoxAPI.UIMachine.GetStorageControllerByName(machine, + storageControll= erName, + &storageControl= ler); + VBOX_UTF16_FREE(storageControllerName); if (NS_FAILED(rc)) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("cannot get controller")); + _("Cannot get storage controller by name")); goto cleanup; } - if (!storageControllerName) { - VBOX_RELEASE(disk); + + rc =3D gVBoxAPI.UIStorageController.GetBus(storageController, &sto= rageBus); + if (NS_FAILED(rc)) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Cannot get storage controller bus")); + VBOX_RELEASE(storageController); + goto cleanup; + } + + rc =3D gVBoxAPI.UIMediumAttachment.GetType(imediumattach, &deviceT= ype); + if (NS_FAILED(rc)) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Cannot get medium attachment type")); + VBOX_RELEASE(storageController); + goto cleanup; + } + rc =3D gVBoxAPI.UIMediumAttachment.GetPort(imediumattach, &deviceP= ort); + if (NS_FAILED(rc)) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Cannot get medium attachment port")); + VBOX_RELEASE(storageController); + goto cleanup; + } + rc =3D gVBoxAPI.UIMediumAttachment.GetDevice(imediumattach, &devic= eSlot); + if (NS_FAILED(rc)) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Cannot get medium attachment slot")); + VBOX_RELEASE(storageController); + goto cleanup; + } + + rc =3D gVBoxAPI.UIMediumAttachment.GetMedium(imediumattach, &disk); + if (NS_FAILED(rc)) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Cannot get medium")); + VBOX_RELEASE(storageController); + goto cleanup; + } + + /* skip empty removable disk */ + if (!disk) { + VBOX_RELEASE(storageController); continue; } + handle =3D gVBoxAPI.UArray.handleMediumGetChildren(disk); rc =3D gVBoxAPI.UArray.vboxArrayGet(&children, disk, handle); if (NS_FAILED(rc)) { @@ -5820,60 +5788,30 @@ static int vboxSnapshotGetReadWriteDisks(virDomainS= napshotDefPtr def, char *diskSnapIdStr =3D NULL; VBOX_UTF16_TO_UTF8(diskSnapId, &diskSnapIdStr); if (STREQ(diskSnapIdStr, snapshotUuidStr)) { - rc =3D gVBoxAPI.UIMachine.GetStorageControllerByName(m= achine, - sto= rageControllerName, - &st= orageController); - VBOX_UTF16_FREE(storageControllerName); - if (!storageController) { - VBOX_RELEASE(child); - break; - } rc =3D gVBoxAPI.UIMedium.GetLocation(child, &childLocU= tf16); if (NS_FAILED(rc)) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("cannot get disk location")); + VBOX_RELEASE(storageController); + VBOX_RELEASE(disk); + VBOX_RELEASE(child); goto cleanup; } VBOX_UTF16_TO_UTF8(childLocUtf16, &childLocUtf8); VBOX_UTF16_FREE(childLocUtf16); if (VIR_STRDUP(def->disks[diskCount].src->path, childL= ocUtf8) < 0) { - VBOX_RELEASE(child); VBOX_RELEASE(storageController); + VBOX_RELEASE(disk); + VBOX_RELEASE(child); goto cleanup; } VBOX_UTF8_FREE(childLocUtf8); =20 - rc =3D gVBoxAPI.UIStorageController.GetBus(storageCont= roller, &storageBus); - if (NS_FAILED(rc)) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("cannot get storage controller bu= s")); - goto cleanup; - } - rc =3D gVBoxAPI.UIMediumAttachment.GetType(imediumatta= ch, &deviceType); - if (NS_FAILED(rc)) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("cannot get medium attachment typ= e")); - goto cleanup; - } - rc =3D gVBoxAPI.UIMediumAttachment.GetPort(imediumatta= ch, &devicePort); - if (NS_FAILED(rc)) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("cannot get medium attachment typ= e")); - goto cleanup; - } - rc =3D gVBoxAPI.UIMediumAttachment.GetDevice(imediumat= tach, &deviceSlot); - if (NS_FAILED(rc)) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("cannot get medium attachment dev= ice")); - goto cleanup; - } def->disks[diskCount].src->type =3D VIR_STORAGE_TYPE_F= ILE; def->disks[diskCount].name =3D vboxGenerateMediumName(= storageBus, - de= viceInst, de= vicePort, de= viceSlot, - ma= xPortPerInst, - ma= xSlotPerPort); + sd= Count); } VBOX_UTF8_FREE(diskSnapIdStr); } @@ -5881,10 +5819,16 @@ static int vboxSnapshotGetReadWriteDisks(virDomainS= napshotDefPtr def, VBOX_RELEASE(storageController); VBOX_RELEASE(disk); diskCount++; + + if (storageBus =3D=3D StorageBus_SATA || storageBus =3D=3D Storage= Bus_SCSI || + storageBus =3D=3D StorageBus_SAS) + sdCount++; + } gVBoxAPI.UArray.vboxArrayRelease(&mediumAttachments); =20 ret =3D 0; + cleanup: if (ret < 0) { for (i =3D 0; i < def->ndisks; i++) @@ -5896,9 +5840,9 @@ static int vboxSnapshotGetReadWriteDisks(virDomainSna= pshotDefPtr def, return ret; } =20 -static -int vboxSnapshotGetReadOnlyDisks(virDomainSnapshotPtr snapshot, - virDomainSnapshotDefPtr def) +static int +vboxSnapshotGetReadOnlyDisks(virDomainSnapshotPtr snapshot, + virDomainSnapshotDefPtr def) { virDomainPtr dom =3D snapshot->domain; vboxDriverPtr data =3D dom->conn->privateData; @@ -5910,10 +5854,7 @@ int vboxSnapshotGetReadOnlyDisks(virDomainSnapshotPt= r snapshot, IMedium *disk =3D NULL; nsresult rc; vboxArray mediumAttachments =3D VBOX_ARRAY_INITIALIZER; - size_t i =3D 0; - PRUint32 maxPortPerInst[StorageBus_Floppy + 1] =3D {}; - PRUint32 maxSlotPerPort[StorageBus_Floppy + 1] =3D {}; - int diskCount =3D 0; + size_t i =3D 0, diskCount =3D 0, sdCount =3D 0; int ret =3D -1; =20 if (!data->vboxObj) @@ -5976,9 +5917,6 @@ int vboxSnapshotGetReadOnlyDisks(virDomainSnapshotPtr= snapshot, goto cleanup; } =20 - if (!vboxGetMaxPortSlotValues(data->vboxObj, maxPortPerInst, maxSlotPe= rPort)) - goto cleanup; - /* get the attachment details here */ for (i =3D 0; i < mediumAttachments.count && diskCount < def->dom->ndi= sks; i++) { PRUnichar *storageControllerName =3D NULL; @@ -5987,7 +5925,6 @@ int vboxSnapshotGetReadOnlyDisks(virDomainSnapshotPtr= snapshot, PRBool readOnly =3D PR_FALSE; PRUnichar *mediumLocUtf16 =3D NULL; char *mediumLocUtf8 =3D NULL; - PRUint32 deviceInst =3D 0; PRInt32 devicePort =3D 0; PRInt32 deviceSlot =3D 0; IMediumAttachment *imediumattach =3D mediumAttachments.items[i]; @@ -5996,7 +5933,7 @@ int vboxSnapshotGetReadOnlyDisks(virDomainSnapshotPtr= snapshot, rc =3D gVBoxAPI.UIMediumAttachment.GetMedium(imediumattach, &disk); if (NS_FAILED(rc)) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("cannot get medium")); + _("Cannot get medium")); goto cleanup; } if (!disk) @@ -6004,7 +5941,7 @@ int vboxSnapshotGetReadOnlyDisks(virDomainSnapshotPtr= snapshot, rc =3D gVBoxAPI.UIMediumAttachment.GetController(imediumattach, &s= torageControllerName); if (NS_FAILED(rc)) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("cannot get storage controller name")); + _("Cannot get storage controller name")); goto cleanup; } if (!storageControllerName) @@ -6012,18 +5949,18 @@ int vboxSnapshotGetReadOnlyDisks(virDomainSnapshotP= tr snapshot, rc =3D gVBoxAPI.UIMachine.GetStorageControllerByName(machine, storageControll= erName, &storageControl= ler); + VBOX_UTF16_FREE(storageControllerName); if (NS_FAILED(rc)) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("cannot get storage controller")); + _("Cannot get storage controller")); goto cleanup; } - VBOX_UTF16_FREE(storageControllerName); if (!storageController) continue; rc =3D gVBoxAPI.UIMedium.GetLocation(disk, &mediumLocUtf16); if (NS_FAILED(rc)) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("cannot get disk location")); + _("Cannot get disk location")); goto cleanup; } VBOX_UTF16_TO_UTF8(mediumLocUtf16, &mediumLocUtf8); @@ -6036,14 +5973,48 @@ int vboxSnapshotGetReadOnlyDisks(virDomainSnapshotP= tr snapshot, rc =3D gVBoxAPI.UIStorageController.GetBus(storageController, &sto= rageBus); if (NS_FAILED(rc)) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("cannot get storage controller bus")); + _("Cannot get storage controller bus")); + goto cleanup; + } + rc =3D gVBoxAPI.UIMediumAttachment.GetPort(imediumattach, &deviceP= ort); + if (NS_FAILED(rc)) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Cannot get medium attachment port")); + goto cleanup; + } + rc =3D gVBoxAPI.UIMediumAttachment.GetDevice(imediumattach, &devic= eSlot); + if (NS_FAILED(rc)) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Cannot get device slot")); + goto cleanup; + } + rc =3D gVBoxAPI.UIMedium.GetReadOnly(disk, &readOnly); + if (NS_FAILED(rc)) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Cannot get read only attribute")); + goto cleanup; + } + + def->dom->disks[diskCount]->dst =3D vboxGenerateMediumName(storage= Bus, + devicePor= t, + deviceSlo= t, + sdCount); + if (!def->dom->disks[diskCount]->dst) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Could not generate medium name for the disk " + "at: port:%d, slot:%d"), devicePort, deviceSl= ot); + ret =3D -1; goto cleanup; } + if (storageBus =3D=3D StorageBus_IDE) { def->dom->disks[diskCount]->bus =3D VIR_DOMAIN_DISK_BUS_IDE; } else if (storageBus =3D=3D StorageBus_SATA) { + sdCount++; def->dom->disks[diskCount]->bus =3D VIR_DOMAIN_DISK_BUS_SATA; - } else if (storageBus =3D=3D StorageBus_SCSI) { + } else if (storageBus =3D=3D StorageBus_SCSI || + storageBus =3D=3D StorageBus_SAS) { + sdCount++; def->dom->disks[diskCount]->bus =3D VIR_DOMAIN_DISK_BUS_SCSI; } else if (storageBus =3D=3D StorageBus_Floppy) { def->dom->disks[diskCount]->bus =3D VIR_DOMAIN_DISK_BUS_FDC; @@ -6062,46 +6033,15 @@ int vboxSnapshotGetReadOnlyDisks(virDomainSnapshotP= tr snapshot, else if (deviceType =3D=3D DeviceType_DVD) def->dom->disks[diskCount]->device =3D VIR_DOMAIN_DISK_DEVICE_= CDROM; =20 - rc =3D gVBoxAPI.UIMediumAttachment.GetPort(imediumattach, &deviceP= ort); - if (NS_FAILED(rc)) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("cannot get medium attachment port")); - goto cleanup; - } - rc =3D gVBoxAPI.UIMediumAttachment.GetDevice(imediumattach, &devic= eSlot); - if (NS_FAILED(rc)) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("cannot get device")); - goto cleanup; - } - rc =3D gVBoxAPI.UIMedium.GetReadOnly(disk, &readOnly); - if (NS_FAILED(rc)) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("cannot get read only attribute")); - goto cleanup; - } if (readOnly =3D=3D PR_TRUE) def->dom->disks[diskCount]->src->readonly =3D true; def->dom->disks[diskCount]->src->type =3D VIR_STORAGE_TYPE_FILE; - def->dom->disks[diskCount]->dst =3D vboxGenerateMediumName(storage= Bus, - deviceIns= t, - devicePor= t, - deviceSlo= t, - maxPortPe= rInst, - maxSlotPe= rPort); - if (!def->dom->disks[diskCount]->dst) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Could not generate medium name for the disk " - "at: controller instance:%u, port:%d, slot:%d= "), - deviceInst, devicePort, deviceSlot); - ret =3D -1; - goto cleanup; - } - diskCount ++; + + diskCount++; } - /* cleanup on error */ =20 ret =3D 0; + cleanup: if (ret < 0) { for (i =3D 0; i < def->dom->ndisks; i++) --=20 2.14.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list