From nobody Wed Feb 11 11:53:20 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.25 as permitted sender) client-ip=209.132.183.25; envelope-from=libvir-list-bounces@redhat.com; helo=mx4-phx2.redhat.com; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.25 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx4-phx2.redhat.com (mx4-phx2.redhat.com [209.132.183.25]) by mx.zohomail.com with SMTPS id 1488298564393962.6797046903893; Tue, 28 Feb 2017 08:16:04 -0800 (PST) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx4-phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v1SGCphW019148; Tue, 28 Feb 2017 11:12:51 -0500 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v1SGCm9m004437 for ; Tue, 28 Feb 2017 11:12:48 -0500 Received: from inaba.usersys.redhat.com (ovpn-204-32.brq.redhat.com [10.40.204.32]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1SGCk4o020819 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO) for ; Tue, 28 Feb 2017 11:12:48 -0500 From: Andrea Bolognani To: libvir-list@redhat.com Date: Tue, 28 Feb 2017 17:12:33 +0100 Message-Id: <1488298364-16896-2-git-send-email-abologna@redhat.com> In-Reply-To: <1488298364-16896-1-git-send-email-abologna@redhat.com> References: <1488298364-16896-1-git-send-email-abologna@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-loop: libvir-list@redhat.com Subject: [libvirt] [RFC PATCH 01/12] qemu: Allow qemuBuildControllerDevStr() to return NULL 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-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" We will soon need to be able to return a NULL pointer without the caller considering that an error: to make it possible, change the return type to int and use an out parameter for the string instead. Add some documentation for the function as well. --- src/qemu/qemu_command.c | 53 ++++++++++++++++++++++++++++++++++++---------= ---- src/qemu/qemu_command.h | 9 +++++---- src/qemu/qemu_hotplug.c | 5 ++++- 3 files changed, 48 insertions(+), 19 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 41eecfd..73767fb 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -2520,10 +2520,31 @@ qemuBuildUSBControllerDevStr(virDomainControllerDef= Ptr def, } =20 =20 -char * +/** + * qemuBuildControllerDevStr: + * @domainDef: domain definition + * @def: controller definition + * @qemuCaps: QEMU binary capabilities + * @devstr: device string + * @nusbcontroller: number of USB controllers + * + * Turn @def into a description of the controller that QEMU will understan= d, + * to be used either on the command line or through the monitor. + * + * The description will be returned in @devstr and can be NULL, eg. when + * passing in one of the built-in controllers. The returned string must be + * freed by the caller. + * + * The number pointed to by @nusbcontroller will be increased by one every + * time the description for a USB controller has been generated successful= ly. + * + * Returns: 0 on success, <0 on failure + */ +int qemuBuildControllerDevStr(const virDomainDef *domainDef, virDomainControllerDefPtr def, virQEMUCapsPtr qemuCaps, + char **devstr, int *nusbcontroller) { virBuffer buf =3D VIR_BUFFER_INITIALIZER; @@ -2532,11 +2553,11 @@ qemuBuildControllerDevStr(const virDomainDef *domai= nDef, =20 if (!qemuCheckCCWS390AddressSupport(domainDef, def->info, qemuCaps, "controller")) - return NULL; + return -1; =20 if (def->type =3D=3D VIR_DOMAIN_CONTROLLER_TYPE_SCSI) { if ((qemuDomainSetSCSIControllerModel(domainDef, qemuCaps, &model)= ) < 0) - return NULL; + return -1; } =20 if (!(def->type =3D=3D VIR_DOMAIN_CONTROLLER_TYPE_SCSI && @@ -2544,22 +2565,22 @@ qemuBuildControllerDevStr(const virDomainDef *domai= nDef, if (def->queues) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("'queues' is only supported by virtio-scsi co= ntroller")); - return NULL; + return -1; } if (def->cmd_per_lun) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("'cmd_per_lun' is only supported by virtio-sc= si controller")); - return NULL; + return -1; } if (def->max_sectors) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("'max_sectors' is only supported by virtio-sc= si controller")); - return NULL; + return -1; } if (def->ioeventfd) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("'ioeventfd' is only supported by virtio-scsi= controller")); - return NULL; + return -1; } } =20 @@ -2954,11 +2975,12 @@ qemuBuildControllerDevStr(const virDomainDef *domai= nDef, if (virBufferCheckError(&buf) < 0) goto error; =20 - return virBufferContentAndReset(&buf); + *devstr =3D virBufferContentAndReset(&buf); + return 0; =20 error: virBufferFreeAndReset(&buf); - return NULL; + return -1; } =20 =20 @@ -3053,12 +3075,15 @@ qemuBuildControllerDevCommandLine(virCommandPtr cmd, continue; } =20 - virCommandAddArg(cmd, "-device"); - if (!(devstr =3D qemuBuildControllerDevStr(def, cont, qemuCaps, - &usbcontroller))) + if (qemuBuildControllerDevStr(def, cont, qemuCaps, + &devstr, &usbcontroller) < 0) return -1; - virCommandAddArg(cmd, devstr); - VIR_FREE(devstr); + + if (devstr) { + virCommandAddArg(cmd, "-device"); + virCommandAddArg(cmd, devstr); + VIR_FREE(devstr); + } } } =20 diff --git a/src/qemu/qemu_command.h b/src/qemu/qemu_command.h index 69fe846..d8478f8 100644 --- a/src/qemu/qemu_command.h +++ b/src/qemu/qemu_command.h @@ -119,10 +119,11 @@ char *qemuBuildDriveDevStr(const virDomainDef *def, virQEMUCapsPtr qemuCaps); =20 /* Current, best practice */ -char *qemuBuildControllerDevStr(const virDomainDef *domainDef, - virDomainControllerDefPtr def, - virQEMUCapsPtr qemuCaps, - int *nusbcontroller); +int qemuBuildControllerDevStr(const virDomainDef *domainDef, + virDomainControllerDefPtr def, + virQEMUCapsPtr qemuCaps, + char **devstr, + int *nusbcontroller); =20 int qemuBuildMemoryBackendStr(unsigned long long size, unsigned long long pagesize, diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 97fb272..8a23238 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -523,7 +523,10 @@ int qemuDomainAttachControllerDevice(virQEMUDriverPtr = driver, if (qemuAssignDeviceControllerAlias(vm->def, priv->qemuCaps, controlle= r) < 0) goto cleanup; =20 - if (!(devstr =3D qemuBuildControllerDevStr(vm->def, controller, priv->= qemuCaps, NULL))) + if (qemuBuildControllerDevStr(vm->def, controller, priv->qemuCaps, &de= vstr, NULL) < 0) + goto cleanup; + + if (!devstr) goto cleanup; =20 if (VIR_REALLOC_N(vm->def->controllers, vm->def->ncontrollers+1) < 0) --=20 2.7.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list