From nobody Thu May 15 21:40:11 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 1508873766645718.4989748767977; Tue, 24 Oct 2017 12:36:06 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 06E5F5F17E; Tue, 24 Oct 2017 19:36:05 +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 D1B895D6A8; Tue, 24 Oct 2017 19:36: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 90CDF180448C; Tue, 24 Oct 2017 19:36:04 +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 v9OJZkTr009704 for ; Tue, 24 Oct 2017 15:35:46 -0400 Received: by smtp.corp.redhat.com (Postfix) id 030AC173D2; Tue, 24 Oct 2017 19:35:46 +0000 (UTC) Received: from mx1.redhat.com (ext-mx09.extmail.prod.ext.phx2.redhat.com [10.5.110.38]) by smtp.corp.redhat.com (Postfix) with ESMTPS id F191C5C8A1 for ; Tue, 24 Oct 2017 19:35:44 +0000 (UTC) Received: from mail-qt0-f177.google.com (mail-qt0-f177.google.com [209.85.216.177]) (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 ACA5AFEB1 for ; Tue, 24 Oct 2017 19:35:42 +0000 (UTC) Received: by mail-qt0-f177.google.com with SMTP id v41so31891750qtv.12 for ; Tue, 24 Oct 2017 12:35:42 -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.41 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 24 Oct 2017 12:35:41 -0700 (PDT) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 06E5F5F17E Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=fail (p=none dis=none) header.from=datto.com Authentication-Results: ext-mx01.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 06E5F5F17E 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="q3OVQdh9" DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com ACA5AFEB1 Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=pass (p=none dis=none) header.from=datto.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=dzamirski@datto.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com ACA5AFEB1 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=9DCPxvkg0HAt13TsGkHooWfRd07OLqRbZVcriUdcPkE=; b=q3OVQdh9lTwc5e7WzLbiiLKk2OA5PyQQ6Rx4qn03VXILPG2VqcmP+reEaUYImfLHmS egKiv1t4zOsf/DlOBZDCWxvyJrtmoL1CB4hIr/aE3T9mSmOlXIZ/7jRYHhdAFOj8ATyY JONtfA+y1OG3uIIhoOidwqDC1BS49jOCEEkLte2WqAUVi0/BFTJ89xt0HZUzahHMGzsq s6K9oJ+kUOOhaInD/3b00u+iPkvvhIGqxeHh6oryPmMwUbbFLUjxpynXhTw7u2CNxYuB RPfsjCRR9AMEZKIw6w8t3zd60cMcY2lWT4cKWOMbAOKeif8xzG0NZ8U49KIZ1e/8v0Vm W7jQ== 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=9DCPxvkg0HAt13TsGkHooWfRd07OLqRbZVcriUdcPkE=; b=NmBF0V4n7Eb6X93b/QfUsA7egPi5Snq1pmfHnssjW0n5LHesQmWDDrOXPAF5DFHuSs 5gfjClTveu/VRmZpd2loz/8EpfFPZXroVqmlG4fQ3dQzOTaQF7v0/Z5pBJ+TP6ZrmvQI +cnxX5cH5jewoOpXUMTxmgirIKSG0SpAlyypVVeyu8yCKNrIqmHM/7cKJGeRJqscWETb GeP+9gUU92/pdcDG4mknxqZ7DRoa8kDzAb18g8HlO4OqSoX9+9MEL3YQqRKKm1bKRA9W ZAFQzAQb4dXHwL8o53XLqNyQ/zwcHg4atCrmtr3ZC4pqC+thcK6Qw2NJ87Sbklai2vix 1Ggg== X-Gm-Message-State: AMCzsaXK9J4U53n3+VuNi/q/EcRQWuZy+sv/6uz9Ek33JLAKC2L5Pkne P7BFa/MTW36gb2bP68a4ht6Cj/5+Xsk= X-Google-Smtp-Source: ABhQp+TnmD0DVlkS1vAQapWY2Qb9fvI2mgvkx6t4AJkK23o8czhVUsTyDC6z09f+cO/eonVW+OZEcQ== X-Received: by 10.237.34.28 with SMTP id n28mr27182074qtc.30.1508873741619; Tue, 24 Oct 2017 12:35:41 -0700 (PDT) From: Dawid Zamirski To: libvir-list@redhat.com Date: Tue, 24 Oct 2017 15:35:28 -0400 Message-Id: <20171024193538.9078-6-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.38]); Tue, 24 Oct 2017 19:35:42 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Tue, 24 Oct 2017 19:35:42 +0000 (UTC) for IP:'209.85.216.177' DOMAIN:'mail-qt0-f177.google.com' HELO:'mail-qt0-f177.google.com' FROM:'dzamirski@datto.com' RCPT:'' X-RedHat-Spam-Score: 0.469 (DKIM_SIGNED, DKIM_VALID, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, RCVD_IN_SORBS_SPAM, SPF_PASS) 209.85.216.177 mail-qt0-f177.google.com 209.85.216.177 mail-qt0-f177.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.38 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 05/15] vbox: Cleanup vboxAttachDrives implementation 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Tue, 24 Oct 2017 19:36:05 +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" This commit primes vboxAttachDrives for further changes so when they are made, the diff is less noisy: * move variable declarations to the top of the function * add disk variable to replace all the def->disks[i] instances * add cleanup at the end of the loop body, so it's all in one place rather than scattered through the loop body. It's purposefully called 'cleanup' rather than 'skip' or 'continue' because future commit will treat errors as hard-failures. Reviewed-by: John Ferlan --- src/vbox/vbox_common.c | 95 ++++++++++++++++++++++++----------------------= ---- 1 file changed, 46 insertions(+), 49 deletions(-) diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c index fa8471e68..b949c4db7 100644 --- a/src/vbox/vbox_common.c +++ b/src/vbox/vbox_common.c @@ -959,8 +959,17 @@ static void vboxAttachDrives(virDomainDefPtr def, vboxDriverPtr data, IMachine *machin= e) { size_t i; + int type, format; + const char *src =3D NULL; nsresult rc =3D 0; + virDomainDiskDefPtr disk =3D NULL; PRUnichar *storageCtlName =3D NULL; + IMedium *medium =3D NULL; + PRUnichar *mediumFileUtf16 =3D NULL, *mediumEmpty =3D NULL; + PRUint32 devicePort, deviceSlot, deviceType, accessMode; + vboxIID mediumUUID; + + VBOX_IID_INITIALIZE(&mediumUUID); =20 /* add a storage controller for the mediums to be attached */ /* this needs to change when multiple controller are supported for @@ -1003,57 +1012,50 @@ vboxAttachDrives(virDomainDefPtr def, vboxDriverPtr= data, IMachine *machine) } =20 for (i =3D 0; i < def->ndisks; i++) { - const char *src =3D virDomainDiskGetSource(def->disks[i]); - int type =3D virDomainDiskGetType(def->disks[i]); - int format =3D virDomainDiskGetFormat(def->disks[i]); + disk =3D def->disks[i]; + src =3D virDomainDiskGetSource(disk); + type =3D virDomainDiskGetType(disk); + format =3D virDomainDiskGetFormat(disk); + deviceType =3D DeviceType_Null; + accessMode =3D AccessMode_ReadOnly; + devicePort =3D disk->info.addr.drive.unit; + deviceSlot =3D disk->info.addr.drive.bus; =20 VIR_DEBUG("disk(%zu) type: %d", i, type); - VIR_DEBUG("disk(%zu) device: %d", i, def->disks[i]->device); - VIR_DEBUG("disk(%zu) bus: %d", i, def->disks[i]->bus); + VIR_DEBUG("disk(%zu) device: %d", i, disk->device); + VIR_DEBUG("disk(%zu) bus: %d", i, disk->bus); VIR_DEBUG("disk(%zu) src: %s", i, src); - VIR_DEBUG("disk(%zu) dst: %s", i, def->disks[i]->dst); + VIR_DEBUG("disk(%zu) dst: %s", i, disk->dst); VIR_DEBUG("disk(%zu) driverName: %s", i, - virDomainDiskGetDriver(def->disks[i])); + virDomainDiskGetDriver(disk)); VIR_DEBUG("disk(%zu) driverType: %s", i, virStorageFileFormatTypeToString(format)); - VIR_DEBUG("disk(%zu) cachemode: %d", i, def->disks[i]->cachemode); - VIR_DEBUG("disk(%zu) readonly: %s", i, (def->disks[i]->src->read= only + VIR_DEBUG("disk(%zu) cachemode: %d", i, disk->cachemode); + VIR_DEBUG("disk(%zu) readonly: %s", i, (disk->src->readonly ? "True" : "False")); - VIR_DEBUG("disk(%zu) shared: %s", i, (def->disks[i]->src->shar= ed + VIR_DEBUG("disk(%zu) shared: %s", i, (disk->src->shared ? "True" : "False")); =20 if (type =3D=3D VIR_STORAGE_TYPE_FILE && src) { - IMedium *medium =3D NULL; - vboxIID mediumUUID; - PRUnichar *mediumFileUtf16 =3D NULL; - PRUint32 deviceType =3D DeviceType_Null; - PRUint32 accessMode =3D AccessMode_ReadOnly; - PRInt32 devicePort =3D def->disks[i]->info.addr.drive.unit; - PRInt32 deviceSlot =3D def->disks[i]->info.addr.drive.bus; - - VBOX_IID_INITIALIZE(&mediumUUID); VBOX_UTF8_TO_UTF16(src, &mediumFileUtf16); =20 - if (def->disks[i]->device =3D=3D VIR_DOMAIN_DISK_DEVICE_DISK) { + if (disk->device =3D=3D VIR_DOMAIN_DISK_DEVICE_DISK) { deviceType =3D DeviceType_HardDisk; accessMode =3D AccessMode_ReadWrite; - } else if (def->disks[i]->device =3D=3D VIR_DOMAIN_DISK_DEVICE= _CDROM) { + } else if (disk->device =3D=3D VIR_DOMAIN_DISK_DEVICE_CDROM) { deviceType =3D DeviceType_DVD; accessMode =3D AccessMode_ReadOnly; - } else if (def->disks[i]->device =3D=3D VIR_DOMAIN_DISK_DEVICE= _FLOPPY) { + } else if (disk->device =3D=3D VIR_DOMAIN_DISK_DEVICE_FLOPPY) { deviceType =3D DeviceType_Floppy; accessMode =3D AccessMode_ReadWrite; } else { - VBOX_UTF16_FREE(mediumFileUtf16); - continue; + goto cleanup; } =20 gVBoxAPI.UIVirtualBox.FindHardDisk(data->vboxObj, mediumFileUt= f16, deviceType, accessMode, &me= dium); =20 if (!medium) { - PRUnichar *mediumEmpty =3D NULL; - VBOX_UTF8_TO_UTF16("", &mediumEmpty); =20 rc =3D gVBoxAPI.UIVirtualBox.OpenMedium(data->vboxObj, @@ -1066,45 +1068,41 @@ vboxAttachDrives(virDomainDefPtr def, vboxDriverPtr= data, IMachine *machine) if (!medium) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Failed to attach the following disk/dvd/= floppy " - "to the machine: %s, rc=3D%08x"), - src, (unsigned)rc); - VBOX_UTF16_FREE(mediumFileUtf16); - continue; + "to the machine: %s, rc=3D%08x"), src, rc= ); + goto cleanup; } =20 rc =3D gVBoxAPI.UIMedium.GetId(medium, &mediumUUID); if (NS_FAILED(rc)) { virReportError(VIR_ERR_INTERNAL_ERROR, - _("can't get the uuid of the file to be att= ached " + _("Can't get the UUID of the file to be att= ached " "as harddisk/dvd/floppy: %s, rc=3D%08x"), - src, (unsigned)rc); - VBOX_MEDIUM_RELEASE(medium); - VBOX_UTF16_FREE(mediumFileUtf16); - continue; + src, rc); + goto cleanup; } =20 - if (def->disks[i]->device =3D=3D VIR_DOMAIN_DISK_DEVICE_DISK) { - if (def->disks[i]->src->readonly) { + if (disk->device =3D=3D VIR_DOMAIN_DISK_DEVICE_DISK) { + if (disk->src->readonly) { gVBoxAPI.UIMedium.SetType(medium, MediumType_Immutable= ); - VIR_DEBUG("setting harddisk to immutable"); - } else if (!def->disks[i]->src->readonly) { + VIR_DEBUG("Setting harddisk to immutable"); + } else if (!disk->src->readonly) { gVBoxAPI.UIMedium.SetType(medium, MediumType_Normal); - VIR_DEBUG("setting harddisk type to normal"); + VIR_DEBUG("Setting harddisk type to normal"); } } =20 - if (def->disks[i]->bus =3D=3D VIR_DOMAIN_DISK_BUS_IDE) { + if (disk->bus =3D=3D VIR_DOMAIN_DISK_BUS_IDE) { VBOX_UTF8_TO_UTF16("IDE Controller", &storageCtlName); devicePort =3D def->disks[i]->info.addr.drive.bus; deviceSlot =3D def->disks[i]->info.addr.drive.unit; - } else if (def->disks[i]->bus =3D=3D VIR_DOMAIN_DISK_BUS_SATA)= { + } else if (disk->bus =3D=3D VIR_DOMAIN_DISK_BUS_SATA) { VBOX_UTF8_TO_UTF16("SATA Controller", &storageCtlName); - } else if (def->disks[i]->bus =3D=3D VIR_DOMAIN_DISK_BUS_SCSI)= { + } else if (disk->bus =3D=3D VIR_DOMAIN_DISK_BUS_SCSI) { VBOX_UTF8_TO_UTF16("SCSI Controller", &storageCtlName); - } else if (def->disks[i]->bus =3D=3D VIR_DOMAIN_DISK_BUS_FDC) { + } else if (disk->bus =3D=3D VIR_DOMAIN_DISK_BUS_FDC) { VBOX_UTF8_TO_UTF16("Floppy Controller", &storageCtlName); devicePort =3D 0; - deviceSlot =3D def->disks[i]->info.addr.drive.unit; + deviceSlot =3D disk->info.addr.drive.unit; } =20 /* attach the harddisk/dvd/Floppy to the storage controller */ @@ -1117,13 +1115,12 @@ vboxAttachDrives(virDomainDefPtr def, vboxDriverPtr= data, IMachine *machine) =20 if (NS_FAILED(rc)) { virReportError(VIR_ERR_INTERNAL_ERROR, - _("could not attach the file as " - "harddisk/dvd/floppy: %s, rc=3D%08x"), - src, (unsigned)rc); + _("Could not attach the file as " + "harddisk/dvd/floppy: %s, rc=3D%08x"), sr= c, rc); } else { DEBUGIID("Attached HDD/DVD/Floppy with UUID", &mediumUUID); } - + cleanup: VBOX_MEDIUM_RELEASE(medium); vboxIIDUnalloc(&mediumUUID); VBOX_UTF16_FREE(mediumFileUtf16); --=20 2.14.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list