From nobody Wed May 14 15:20:28 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; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1520614240441437.40951462495275; Fri, 9 Mar 2018 08:50:40 -0800 (PST) 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 B7E8E4A71B; Fri, 9 Mar 2018 16:50:38 +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 93BA6620AE; Fri, 9 Mar 2018 16:50:38 +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 5DB3D4CA9D; Fri, 9 Mar 2018 16:50:38 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w29GmUdH000438 for ; Fri, 9 Mar 2018 11:48:30 -0500 Received: by smtp.corp.redhat.com (Postfix) id 9EF8218A75; Fri, 9 Mar 2018 16:48:30 +0000 (UTC) Received: from unknown54ee7586bd10.attlocal.net.com (ovpn-116-138.phx2.redhat.com [10.3.116.138]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5E1E518A7F for ; Fri, 9 Mar 2018 16:48:29 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Fri, 9 Mar 2018 11:48:02 -0500 Message-Id: <20180309164816.837-7-jferlan@redhat.com> In-Reply-To: <20180309164816.837-1-jferlan@redhat.com> References: <20180309164816.837-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 06/20] openvz: Create accessors to virDomainObjListFindByUUID 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.38]); Fri, 09 Mar 2018 16:50:39 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Rather than repeat code throughout, create and use a couple of accessors in order to lookup by UUID. Signed-off-by: John Ferlan Reviewed-by: Jim Fehlig --- src/openvz/openvz_driver.c | 266 +++++++++++++----------------------------= ---- 1 file changed, 76 insertions(+), 190 deletions(-) diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c index a211c370e..167ba2f7a 100644 --- a/src/openvz/openvz_driver.c +++ b/src/openvz/openvz_driver.c @@ -87,6 +87,39 @@ static void openvzDriverUnlock(struct openvz_driver *dri= ver) =20 struct openvz_driver ovz_driver; =20 + +static virDomainObjPtr +openvzDomObjFromDomainLocked(struct openvz_driver *driver, + const unsigned char *uuid) +{ + virDomainObjPtr vm; + char uuidstr[VIR_UUID_STRING_BUFLEN]; + + if (!(vm =3D virDomainObjListFindByUUID(driver->domains, uuid))) { + virUUIDFormat(uuid, uuidstr); + + virReportError(VIR_ERR_NO_DOMAIN, + _("no domain with matching uuid '%s'"), uuidstr); + return NULL; + } + + return vm; +} + + +static virDomainObjPtr +openvzDomObjFromDomain(struct openvz_driver *driver, + const unsigned char *uuid) +{ + virDomainObjPtr vm; + + openvzDriverLock(driver); + vm =3D openvzDomObjFromDomainLocked(driver, uuid); + openvzDriverUnlock(driver); + return vm; +} + + static int openvzDomainDefPostParse(virDomainDefPtr def, virCapsPtr caps ATTRIBUTE_UNUSED, @@ -281,15 +314,8 @@ openvzDomainGetHostname(virDomainPtr dom, unsigned int= flags) virDomainObjPtr vm; =20 virCheckFlags(0, NULL); - openvzDriverLock(driver); - vm =3D virDomainObjListFindByUUID(driver->domains, dom->uuid); - openvzDriverUnlock(driver); - - if (!vm) { - virReportError(VIR_ERR_NO_DOMAIN, "%s", - _("no domain with matching uuid")); - goto cleanup; - } + if (!(vm =3D openvzDomObjFromDomain(driver, dom->uuid))) + return NULL; =20 hostname =3D openvzVEGetStringParam(dom, "hostname"); if (hostname =3D=3D NULL) @@ -359,18 +385,11 @@ static char *openvzDomainGetOSType(virDomainPtr dom) virDomainObjPtr vm; char *ret =3D NULL; =20 - openvzDriverLock(driver); - vm =3D virDomainObjListFindByUUID(driver->domains, dom->uuid); - openvzDriverUnlock(driver); - - if (!vm) { - virReportError(VIR_ERR_NO_DOMAIN, NULL); - goto cleanup; - } + if (!(vm =3D openvzDomObjFromDomain(driver, dom->uuid))) + return NULL; =20 ignore_value(VIR_STRDUP(ret, virDomainOSTypeToString(vm->def->os.type)= )); =20 - cleanup: if (vm) virObjectUnlock(vm); return ret; @@ -384,18 +403,11 @@ static virDomainPtr openvzDomainLookupByUUID(virConne= ctPtr conn, virDomainObjPtr vm; virDomainPtr dom =3D NULL; =20 - openvzDriverLock(driver); - vm =3D virDomainObjListFindByUUID(driver->domains, uuid); - openvzDriverUnlock(driver); - - if (!vm) { - virReportError(VIR_ERR_NO_DOMAIN, NULL); - goto cleanup; - } + if (!(vm =3D openvzDomObjFromDomain(driver, uuid))) + return NULL; =20 dom =3D virGetDomain(conn, vm->def->name, vm->def->uuid, vm->def->id); =20 - cleanup: if (vm) virObjectUnlock(vm); return dom; @@ -432,15 +444,8 @@ static int openvzDomainGetInfo(virDomainPtr dom, int state; int ret =3D -1; =20 - openvzDriverLock(driver); - vm =3D virDomainObjListFindByUUID(driver->domains, dom->uuid); - openvzDriverUnlock(driver); - - if (!vm) { - virReportError(VIR_ERR_NO_DOMAIN, "%s", - _("no domain with matching uuid")); - goto cleanup; - } + if (!(vm =3D openvzDomObjFromDomain(driver, dom->uuid))) + return -1; =20 if (openvzGetVEStatus(vm, &state, NULL) =3D=3D -1) goto cleanup; @@ -480,19 +485,11 @@ openvzDomainGetState(virDomainPtr dom, =20 virCheckFlags(0, -1); =20 - openvzDriverLock(driver); - vm =3D virDomainObjListFindByUUID(driver->domains, dom->uuid); - openvzDriverUnlock(driver); - - if (!vm) { - virReportError(VIR_ERR_NO_DOMAIN, "%s", - _("no domain with matching uuid")); - goto cleanup; - } + if (!(vm =3D openvzDomObjFromDomain(driver, dom->uuid))) + return -1; =20 ret =3D openvzGetVEStatus(vm, state, reason); =20 - cleanup: if (vm) virObjectUnlock(vm); return ret; @@ -505,16 +502,11 @@ static int openvzDomainIsActive(virDomainPtr dom) virDomainObjPtr obj; int ret =3D -1; =20 - openvzDriverLock(driver); - obj =3D virDomainObjListFindByUUID(driver->domains, dom->uuid); - openvzDriverUnlock(driver); - if (!obj) { - virReportError(VIR_ERR_NO_DOMAIN, NULL); - goto cleanup; - } + if (!(obj =3D openvzDomObjFromDomain(driver, dom->uuid))) + return -1; + ret =3D virDomainObjIsActive(obj); =20 - cleanup: if (obj) virObjectUnlock(obj); return ret; @@ -527,16 +519,11 @@ static int openvzDomainIsPersistent(virDomainPtr dom) virDomainObjPtr obj; int ret =3D -1; =20 - openvzDriverLock(driver); - obj =3D virDomainObjListFindByUUID(driver->domains, dom->uuid); - openvzDriverUnlock(driver); - if (!obj) { - virReportError(VIR_ERR_NO_DOMAIN, NULL); - goto cleanup; - } + if (!(obj =3D openvzDomObjFromDomain(driver, dom->uuid))) + return -1; + ret =3D obj->persistent; =20 - cleanup: if (obj) virObjectUnlock(obj); return ret; @@ -554,20 +541,12 @@ static char *openvzDomainGetXMLDesc(virDomainPtr dom,= unsigned int flags) { =20 /* Flags checked by virDomainDefFormat */ =20 - openvzDriverLock(driver); - vm =3D virDomainObjListFindByUUID(driver->domains, dom->uuid); - openvzDriverUnlock(driver); - - if (!vm) { - virReportError(VIR_ERR_NO_DOMAIN, "%s", - _("no domain with matching uuid")); - goto cleanup; - } + if (!(vm =3D openvzDomObjFromDomain(driver, dom->uuid))) + return NULL; =20 ret =3D virDomainDefFormat(vm->def, driver->caps, virDomainDefFormatConvertXMLFlags(flags)); =20 - cleanup: if (vm) virObjectUnlock(vm); return ret; @@ -600,15 +579,8 @@ static int openvzDomainSuspend(virDomainPtr dom) const char *prog[] =3D {VZCTL, "--quiet", "chkpnt", PROGRAM_SENTINEL, = "--suspend", NULL}; int ret =3D -1; =20 - openvzDriverLock(driver); - vm =3D virDomainObjListFindByUUID(driver->domains, dom->uuid); - openvzDriverUnlock(driver); - - if (!vm) { - virReportError(VIR_ERR_NO_DOMAIN, "%s", - _("no domain with matching uuid")); - goto cleanup; - } + if (!(vm =3D openvzDomObjFromDomain(driver, dom->uuid))) + return -1; =20 if (!virDomainObjIsActive(vm)) { virReportError(VIR_ERR_OPERATION_INVALID, "%s", @@ -638,15 +610,8 @@ static int openvzDomainResume(virDomainPtr dom) const char *prog[] =3D {VZCTL, "--quiet", "chkpnt", PROGRAM_SENTINEL, = "--resume", NULL}; int ret =3D -1; =20 - openvzDriverLock(driver); - vm =3D virDomainObjListFindByUUID(driver->domains, dom->uuid); - openvzDriverUnlock(driver); - - if (!vm) { - virReportError(VIR_ERR_NO_DOMAIN, "%s", - _("no domain with matching uuid")); - goto cleanup; - } + if (!(vm =3D openvzDomObjFromDomain(driver, dom->uuid))) + return -1; =20 if (!virDomainObjIsActive(vm)) { virReportError(VIR_ERR_OPERATION_INVALID, "%s", @@ -681,15 +646,8 @@ openvzDomainShutdownFlags(virDomainPtr dom, =20 virCheckFlags(0, -1); =20 - openvzDriverLock(driver); - vm =3D virDomainObjListFindByUUID(driver->domains, dom->uuid); - openvzDriverUnlock(driver); - - if (!vm) { - virReportError(VIR_ERR_NO_DOMAIN, "%s", - _("no domain with matching uuid")); - goto cleanup; - } + if (!(vm =3D openvzDomObjFromDomain(driver, dom->uuid))) + return -1; =20 if (openvzGetVEStatus(vm, &status, NULL) =3D=3D -1) goto cleanup; @@ -744,15 +702,8 @@ static int openvzDomainReboot(virDomainPtr dom, =20 virCheckFlags(0, -1); =20 - openvzDriverLock(driver); - vm =3D virDomainObjListFindByUUID(driver->domains, dom->uuid); - openvzDriverUnlock(driver); - - if (!vm) { - virReportError(VIR_ERR_NO_DOMAIN, "%s", - _("no domain with matching uuid")); - goto cleanup; - } + if (!(vm =3D openvzDomObjFromDomain(driver, dom->uuid))) + return -1; =20 if (openvzGetVEStatus(vm, &status, NULL) =3D=3D -1) goto cleanup; @@ -1210,12 +1161,8 @@ openvzDomainUndefineFlags(virDomainPtr dom, virCheckFlags(0, -1); =20 openvzDriverLock(driver); - vm =3D virDomainObjListFindByUUID(driver->domains, dom->uuid); - if (!vm) { - virReportError(VIR_ERR_NO_DOMAIN, "%s", - _("no domain with matching uuid")); + if (!(vm =3D openvzDomObjFromDomainLocked(driver, dom->uuid))) goto cleanup; - } =20 if (openvzGetVEStatus(vm, &status, NULL) =3D=3D -1) goto cleanup; @@ -1255,15 +1202,8 @@ openvzDomainSetAutostart(virDomainPtr dom, int autos= tart) "--save", NULL }; int ret =3D -1; =20 - openvzDriverLock(driver); - vm =3D virDomainObjListFindByUUID(driver->domains, dom->uuid); - openvzDriverUnlock(driver); - - if (!vm) { - virReportError(VIR_ERR_NO_DOMAIN, "%s", - _("no domain with matching uuid")); - goto cleanup; - } + if (!(vm =3D openvzDomObjFromDomain(driver, dom->uuid))) + return -1; =20 openvzSetProgramSentinal(prog, vm->def->name); if (virRun(prog, NULL) < 0) @@ -1284,15 +1224,8 @@ openvzDomainGetAutostart(virDomainPtr dom, int *auto= start) char *value =3D NULL; int ret =3D -1; =20 - openvzDriverLock(driver); - vm =3D virDomainObjListFindByUUID(driver->domains, dom->uuid); - openvzDriverUnlock(driver); - - if (!vm) { - virReportError(VIR_ERR_NO_DOMAIN, "%s", - _("no domain with matching uuid")); - goto cleanup; - } + if (!(vm =3D openvzDomObjFromDomain(driver, dom->uuid))) + return -1; =20 if (openvzReadVPSConfigParam(strtoI(vm->def->name), "ONBOOT", &value) = < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", @@ -1383,15 +1316,8 @@ static int openvzDomainSetVcpusFlags(virDomainPtr do= m, unsigned int nvcpus, return -1; } =20 - openvzDriverLock(driver); - vm =3D virDomainObjListFindByUUID(driver->domains, dom->uuid); - openvzDriverUnlock(driver); - - if (!vm) { - virReportError(VIR_ERR_NO_DOMAIN, "%s", - _("no domain with matching uuid")); - goto cleanup; - } + if (!(vm =3D openvzDomObjFromDomain(driver, dom->uuid))) + return -1; =20 if (nvcpus <=3D 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", @@ -1987,17 +1913,8 @@ openvzDomainInterfaceStats(virDomainPtr dom, virDomainNetDefPtr net =3D NULL; int ret =3D -1; =20 - openvzDriverLock(driver); - vm =3D virDomainObjListFindByUUID(driver->domains, dom->uuid); - openvzDriverUnlock(driver); - - if (!vm) { - char uuidstr[VIR_UUID_STRING_BUFLEN]; - virUUIDFormat(dom->uuid, uuidstr); - virReportError(VIR_ERR_NO_DOMAIN, - _("no domain with matching uuid '%s'"), uuidstr); - goto cleanup; - } + if (!(vm =3D openvzDomObjFromDomain(driver, dom->uuid))) + return -1; =20 if (!virDomainObjIsActive(vm)) { virReportError(VIR_ERR_OPERATION_INVALID, @@ -2082,13 +1999,8 @@ openvzDomainUpdateDeviceFlags(virDomainPtr dom, cons= t char *xml, VIR_DOMAIN_DEVICE_MODIFY_CONFIG, -1); =20 openvzDriverLock(driver); - vm =3D virDomainObjListFindByUUID(driver->domains, dom->uuid); - - if (!vm) { - virReportError(VIR_ERR_NO_DOMAIN, "%s", - _("no domain with matching uuid")); + if (!(vm =3D openvzDomObjFromDomainLocked(driver, dom->uuid))) goto cleanup; - } =20 if (virStrToLong_i(vm->def->name, NULL, 10, &veid) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", @@ -2230,15 +2142,8 @@ openvzDomainMigrateBegin3Params(virDomainPtr domain, if (virTypedParamsValidate(params, nparams, OPENVZ_MIGRATION_PARAMETER= S) < 0) return NULL; =20 - openvzDriverLock(driver); - vm =3D virDomainObjListFindByUUID(driver->domains, domain->uuid); - openvzDriverUnlock(driver); - - if (!vm) { - virReportError(VIR_ERR_NO_DOMAIN, "%s", - _("no domain with matching uuid")); - goto cleanup; - } + if (!(vm =3D openvzDomObjFromDomain(driver, domain->uuid))) + return NULL; =20 if (!virDomainObjIsActive(vm)) { virReportError(VIR_ERR_OPERATION_INVALID, @@ -2394,15 +2299,8 @@ openvzDomainMigratePerform3Params(virDomainPtr domai= n, &uri_str) < 0) goto cleanup; =20 - openvzDriverLock(driver); - vm =3D virDomainObjListFindByUUID(driver->domains, domain->uuid); - openvzDriverUnlock(driver); - - if (!vm) { - virReportError(VIR_ERR_NO_DOMAIN, "%s", - _("no domain with matching uuid")); + if (!(vm =3D openvzDomObjFromDomain(driver, domain->uuid))) goto cleanup; - } =20 /* parse dst host:port from uri */ uri =3D virURIParse(uri_str); @@ -2504,15 +2402,8 @@ openvzDomainMigrateConfirm3Params(virDomainPtr domai= n, if (virTypedParamsValidate(params, nparams, OPENVZ_MIGRATION_PARAMETER= S) < 0) goto cleanup; =20 - openvzDriverLock(driver); - vm =3D virDomainObjListFindByUUID(driver->domains, domain->uuid); - openvzDriverUnlock(driver); - - if (!vm) { - virReportError(VIR_ERR_NO_DOMAIN, "%s", - _("no domain with matching uuid")); + if (!(vm =3D openvzDomObjFromDomain(driver, domain->uuid))) goto cleanup; - } =20 if (cancelled) { if (openvzGetVEStatus(vm, &status, NULL) =3D=3D -1) @@ -2552,16 +2443,11 @@ openvzDomainHasManagedSaveImage(virDomainPtr dom, u= nsigned int flags) =20 virCheckFlags(0, -1); =20 - openvzDriverLock(driver); - obj =3D virDomainObjListFindByUUID(driver->domains, dom->uuid); - openvzDriverUnlock(driver); - if (!obj) { - virReportError(VIR_ERR_NO_DOMAIN, NULL); - goto cleanup; - } + if (!(obj =3D openvzDomObjFromDomain(driver, dom->uuid))) + return -1; + ret =3D 0; =20 - cleanup: if (obj) virObjectUnlock(obj); return ret; --=20 2.13.6 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list