From nobody Thu Nov 28 01:27:49 2024 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 1534245616651524.7984669303873; Tue, 14 Aug 2018 04:20:16 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5EA88308625E; Tue, 14 Aug 2018 11:20:14 +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 1D7FB261D4; Tue, 14 Aug 2018 11:20:14 +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 AE60318037F2; Tue, 14 Aug 2018 11:20:13 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w7EBJolJ012433 for ; Tue, 14 Aug 2018 07:19:50 -0400 Received: by smtp.corp.redhat.com (Postfix) id ED53B2027047; Tue, 14 Aug 2018 11:19:49 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6D77D2026D7E for ; Tue, 14 Aug 2018 11:19:49 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Tue, 14 Aug 2018 13:19:42 +0200 Message-Id: <1ffbcb28175f23b547a1be4c448abfce07a1f49e.1534245398.git.mprivozn@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 6/7] domain_lock: Implement metadata locking 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.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Tue, 14 Aug 2018 11:20:15 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" In order for our drivers to lock resources for metadata change we need set of new APIs. Fortunately, we don't have to care about every possible device a domain can have. We care only about those which can live on a network filesystem and hence can be accessed by multiple daemons at the same time. These devices are covered in virDomainLockMetadataLock() and only a small fraction of those can be hotplugged (covered in the rest of the introduced APIs). Signed-off-by: Michal Privoznik --- src/libvirt_private.syms | 8 ++ src/locking/domain_lock.c | 304 ++++++++++++++++++++++++++++++++++++++++++= ---- src/locking/domain_lock.h | 28 +++++ 3 files changed, 317 insertions(+), 23 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index ca4a192a4a..720ae12301 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1284,6 +1284,14 @@ virDomainLockImageAttach; virDomainLockImageDetach; virDomainLockLeaseAttach; virDomainLockLeaseDetach; +virDomainLockMetadataDiskLock; +virDomainLockMetadataDiskUnlock; +virDomainLockMetadataImageLock; +virDomainLockMetadataImageUnlock; +virDomainLockMetadataLock; +virDomainLockMetadataMemLock; +virDomainLockMetadataMemUnlock; +virDomainLockMetadataUnlock; virDomainLockProcessInquire; virDomainLockProcessPause; virDomainLockProcessResume; diff --git a/src/locking/domain_lock.c b/src/locking/domain_lock.c index 705b132457..19a097fb25 100644 --- a/src/locking/domain_lock.c +++ b/src/locking/domain_lock.c @@ -69,7 +69,8 @@ static int virDomainLockManagerAddLease(virLockManagerPtr= lock, =20 =20 static int virDomainLockManagerAddImage(virLockManagerPtr lock, - virStorageSourcePtr src) + virStorageSourcePtr src, + bool metadataOnly) { unsigned int diskFlags =3D 0; int type =3D virStorageSourceGetActualType(src); @@ -82,10 +83,14 @@ static int virDomainLockManagerAddImage(virLockManagerP= tr lock, type =3D=3D VIR_STORAGE_TYPE_DIR)) return 0; =20 - if (src->readonly) - diskFlags |=3D VIR_LOCK_MANAGER_RESOURCE_READONLY; - if (src->shared) - diskFlags |=3D VIR_LOCK_MANAGER_RESOURCE_SHARED; + if (metadataOnly) { + diskFlags =3D VIR_LOCK_MANAGER_RESOURCE_METADATA; + } else { + if (src->readonly) + diskFlags |=3D VIR_LOCK_MANAGER_RESOURCE_READONLY; + if (src->shared) + diskFlags |=3D VIR_LOCK_MANAGER_RESOURCE_SHARED; + } =20 VIR_DEBUG("Add disk %s", src->path); if (virLockManagerAddResource(lock, @@ -101,13 +106,68 @@ static int virDomainLockManagerAddImage(virLockManage= rPtr lock, } =20 =20 +static int +virDomainLockManagerAddMemory(virLockManagerPtr lock, + const virDomainMemoryDef *mem) +{ + const char *path =3D NULL; + + switch ((virDomainMemoryModel) mem->model) { + case VIR_DOMAIN_MEMORY_MODEL_NVDIMM: + path =3D mem->nvdimmPath; + break; + + case VIR_DOMAIN_MEMORY_MODEL_DIMM: + case VIR_DOMAIN_MEMORY_MODEL_LAST: + case VIR_DOMAIN_MEMORY_MODEL_NONE: + break; + } + + if (!path) + return 0; + + VIR_DEBUG("Adding memory %s", path); + if (virLockManagerAddResource(lock, + VIR_LOCK_MANAGER_RESOURCE_TYPE_DISK, + path, + 0, + NULL, + VIR_LOCK_MANAGER_RESOURCE_METADATA) < 0) + return -1; + + return 0; +} + + +static int +virDomainLockManagerAddFile(virLockManagerPtr lock, + const char *file) +{ + if (!file) + return 0; + + VIR_DEBUG("Adding file %s", file); + if (virLockManagerAddResource(lock, + VIR_LOCK_MANAGER_RESOURCE_TYPE_DISK, + file, + 0, + NULL, + VIR_LOCK_MANAGER_RESOURCE_METADATA) < 0) + return -1; + + return 0; +} + + static virLockManagerPtr virDomainLockManagerNew(virLockManagerPluginPtr p= lugin, const char *uri, virDomainObjPtr dom, bool withResources, + bool metadataOnly, unsigned int flags) { virLockManagerPtr lock; + const virDomainDef *def =3D dom->def; size_t i; virLockManagerParam params[] =3D { { .type =3D VIR_LOCK_MANAGER_PARAM_TYPE_UUID, @@ -115,11 +175,11 @@ static virLockManagerPtr virDomainLockManagerNew(virL= ockManagerPluginPtr plugin, }, { .type =3D VIR_LOCK_MANAGER_PARAM_TYPE_STRING, .key =3D "name", - .value =3D { .str =3D dom->def->name }, + .value =3D { .str =3D def->name }, }, { .type =3D VIR_LOCK_MANAGER_PARAM_TYPE_UINT, .key =3D "id", - .value =3D { .iv =3D dom->def->id }, + .value =3D { .iv =3D def->id }, }, { .type =3D VIR_LOCK_MANAGER_PARAM_TYPE_UINT, .key =3D "pid", @@ -133,7 +193,7 @@ static virLockManagerPtr virDomainLockManagerNew(virLoc= kManagerPluginPtr plugin, VIR_DEBUG("plugin=3D%p dom=3D%p withResources=3D%d", plugin, dom, withResources); =20 - memcpy(params[0].value.uuid, dom->def->uuid, VIR_UUID_BUFLEN); + memcpy(params[0].value.uuid, def->uuid, VIR_UUID_BUFLEN); =20 if (!(lock =3D virLockManagerNew(virLockManagerPluginGetDriver(plugin), VIR_LOCK_MANAGER_OBJECT_TYPE_DOMAIN, @@ -144,19 +204,46 @@ static virLockManagerPtr virDomainLockManagerNew(virL= ockManagerPluginPtr plugin, =20 if (withResources) { VIR_DEBUG("Adding leases"); - for (i =3D 0; i < dom->def->nleases; i++) - if (virDomainLockManagerAddLease(lock, dom->def->leases[i]) < = 0) + for (i =3D 0; i < def->nleases; i++) + if (virDomainLockManagerAddLease(lock, def->leases[i]) < 0) goto error; + } =20 + if (withResources || metadataOnly) { VIR_DEBUG("Adding disks"); - for (i =3D 0; i < dom->def->ndisks; i++) { - virDomainDiskDefPtr disk =3D dom->def->disks[i]; + for (i =3D 0; i < def->ndisks; i++) { + virDomainDiskDefPtr disk =3D def->disks[i]; =20 - if (virDomainLockManagerAddImage(lock, disk->src) < 0) + if (virDomainLockManagerAddImage(lock, disk->src, metadataOnly= ) < 0) goto error; } } =20 + if (metadataOnly) { + for (i =3D 0; i < def->nmems; i++) { + virDomainMemoryDefPtr mem =3D def->mems[i]; + + if (virDomainLockManagerAddMemory(lock, mem) < 0) + goto error; + } + + if (def->os.loader && + virDomainLockManagerAddFile(lock, def->os.loader->nvram) < 0) + goto error; + + if (virDomainLockManagerAddFile(lock, def->os.kernel) < 0) + goto error; + + if (virDomainLockManagerAddFile(lock, def->os.initrd) < 0) + goto error; + + if (virDomainLockManagerAddFile(lock, def->os.dtb) < 0) + goto error; + + if (virDomainLockManagerAddFile(lock, def->os.slic_table) < 0) + goto error; + } + return lock; =20 error: @@ -178,7 +265,7 @@ int virDomainLockProcessStart(virLockManagerPluginPtr p= lugin, VIR_DEBUG("plugin=3D%p dom=3D%p paused=3D%d fd=3D%p", plugin, dom, paused, fd); =20 - if (!(lock =3D virDomainLockManagerNew(plugin, uri, dom, true, + if (!(lock =3D virDomainLockManagerNew(plugin, uri, dom, true, false, VIR_LOCK_MANAGER_NEW_STARTED))) return -1; =20 @@ -203,7 +290,7 @@ int virDomainLockProcessPause(virLockManagerPluginPtr p= lugin, VIR_DEBUG("plugin=3D%p dom=3D%p state=3D%p", plugin, dom, state); =20 - if (!(lock =3D virDomainLockManagerNew(plugin, NULL, dom, true, 0))) + if (!(lock =3D virDomainLockManagerNew(plugin, NULL, dom, true, false,= 0))) return -1; =20 ret =3D virLockManagerRelease(lock, state, 0); @@ -223,7 +310,7 @@ int virDomainLockProcessResume(virLockManagerPluginPtr = plugin, VIR_DEBUG("plugin=3D%p dom=3D%p state=3D%s", plugin, dom, NULLSTR(state)); =20 - if (!(lock =3D virDomainLockManagerNew(plugin, uri, dom, true, 0))) + if (!(lock =3D virDomainLockManagerNew(plugin, uri, dom, true, false, = 0))) return -1; =20 ret =3D virLockManagerAcquire(lock, state, 0, dom->def->onLockFailure,= NULL); @@ -242,7 +329,7 @@ int virDomainLockProcessInquire(virLockManagerPluginPtr= plugin, VIR_DEBUG("plugin=3D%p dom=3D%p state=3D%p", plugin, dom, state); =20 - if (!(lock =3D virDomainLockManagerNew(plugin, NULL, dom, true, 0))) + if (!(lock =3D virDomainLockManagerNew(plugin, NULL, dom, true, false,= 0))) return -1; =20 ret =3D virLockManagerInquire(lock, state, 0); @@ -262,10 +349,10 @@ int virDomainLockImageAttach(virLockManagerPluginPtr = plugin, =20 VIR_DEBUG("plugin=3D%p dom=3D%p src=3D%p", plugin, dom, src); =20 - if (!(lock =3D virDomainLockManagerNew(plugin, uri, dom, false, 0))) + if (!(lock =3D virDomainLockManagerNew(plugin, uri, dom, false, false,= 0))) return -1; =20 - if (virDomainLockManagerAddImage(lock, src) < 0) + if (virDomainLockManagerAddImage(lock, src, false) < 0) goto cleanup; =20 if (virLockManagerAcquire(lock, NULL, 0, @@ -299,10 +386,10 @@ int virDomainLockImageDetach(virLockManagerPluginPtr = plugin, =20 VIR_DEBUG("plugin=3D%p dom=3D%p src=3D%p", plugin, dom, src); =20 - if (!(lock =3D virDomainLockManagerNew(plugin, NULL, dom, false, 0))) + if (!(lock =3D virDomainLockManagerNew(plugin, NULL, dom, false, false= , 0))) return -1; =20 - if (virDomainLockManagerAddImage(lock, src) < 0) + if (virDomainLockManagerAddImage(lock, src, false) < 0) goto cleanup; =20 if (virLockManagerRelease(lock, NULL, 0) < 0) @@ -336,7 +423,7 @@ int virDomainLockLeaseAttach(virLockManagerPluginPtr pl= ugin, VIR_DEBUG("plugin=3D%p dom=3D%p lease=3D%p", plugin, dom, lease); =20 - if (!(lock =3D virDomainLockManagerNew(plugin, uri, dom, false, 0))) + if (!(lock =3D virDomainLockManagerNew(plugin, uri, dom, false, false,= 0))) return -1; =20 if (virDomainLockManagerAddLease(lock, lease) < 0) @@ -364,7 +451,7 @@ int virDomainLockLeaseDetach(virLockManagerPluginPtr pl= ugin, VIR_DEBUG("plugin=3D%p dom=3D%p lease=3D%p", plugin, dom, lease); =20 - if (!(lock =3D virDomainLockManagerNew(plugin, NULL, dom, false, 0))) + if (!(lock =3D virDomainLockManagerNew(plugin, NULL, dom, false, false= , 0))) return -1; =20 if (virDomainLockManagerAddLease(lock, lease) < 0) @@ -380,3 +467,174 @@ int virDomainLockLeaseDetach(virLockManagerPluginPtr = plugin, =20 return ret; } + + +int +virDomainLockMetadataLock(virLockManagerPluginPtr plugin, + virDomainObjPtr dom) +{ + virLockManagerPtr lock; + const unsigned int flags =3D 0; + int ret =3D -1; + + VIR_DEBUG("plugin=3D%p dom=3D%p", plugin, dom); + + if (!(lock =3D virDomainLockManagerNew(plugin, NULL, dom, false, true,= 0))) + return -1; + + if (virLockManagerAcquire(lock, NULL, flags, + VIR_DOMAIN_LOCK_FAILURE_DEFAULT, NULL) < 0) + goto cleanup; + + ret =3D 0; + cleanup: + virLockManagerFree(lock); + return ret; +} + + +int +virDomainLockMetadataUnlock(virLockManagerPluginPtr plugin, + virDomainObjPtr dom) +{ + virLockManagerPtr lock; + const unsigned int flags =3D 0; + int ret =3D -1; + + VIR_DEBUG("plugin=3D%p dom=3D%p", plugin, dom); + + if (!(lock =3D virDomainLockManagerNew(plugin, NULL, dom, false, true,= 0))) + return -1; + + if (virLockManagerRelease(lock, NULL, flags) < 0) + goto cleanup; + + ret =3D 0; + cleanup: + virLockManagerFree(lock); + return ret; +} + + +int +virDomainLockMetadataImageLock(virLockManagerPluginPtr plugin, + virDomainObjPtr dom, + virStorageSourcePtr src) +{ + virLockManagerPtr lock; + int ret =3D -1; + + VIR_DEBUG("plugin=3D%p dom=3D%p src=3D%p", plugin, dom, src); + + if (!(lock =3D virDomainLockManagerNew(plugin, NULL, dom, false, false= , 0))) + return -1; + + if (virDomainLockManagerAddImage(lock, src, true) < 0) + goto cleanup; + + if (virLockManagerAcquire(lock, NULL, 0, + VIR_DOMAIN_LOCK_FAILURE_DEFAULT, NULL) < 0) + goto cleanup; + + ret =3D 0; + cleanup: + virLockManagerFree(lock); + return ret; +} + + +int +virDomainLockMetadataImageUnlock(virLockManagerPluginPtr plugin, + virDomainObjPtr dom, + virStorageSourcePtr src) +{ + virLockManagerPtr lock; + int ret =3D -1; + + VIR_DEBUG("plugin=3D%p dom=3D%p src=3D%p", plugin, dom, src); + + if (!(lock =3D virDomainLockManagerNew(plugin, NULL, dom, false, false= , 0))) + return -1; + + if (virDomainLockManagerAddImage(lock, src, true) < 0) + goto cleanup; + + if (virLockManagerRelease(lock, NULL, 0) < 0) + goto cleanup; + + ret =3D 0; + cleanup: + virLockManagerFree(lock); + return ret; +} + + +int +virDomainLockMetadataDiskLock(virLockManagerPluginPtr plugin, + virDomainObjPtr dom, + virDomainDiskDefPtr disk) +{ + return virDomainLockMetadataImageLock(plugin, dom, disk->src); +} + + +int +virDomainLockMetadataDiskUnlock(virLockManagerPluginPtr plugin, + virDomainObjPtr dom, + virDomainDiskDefPtr disk) +{ + return virDomainLockMetadataImageUnlock(plugin, dom, disk->src); +} + + +int +virDomainLockMetadataMemLock(virLockManagerPluginPtr plugin, + virDomainObjPtr dom, + virDomainMemoryDefPtr mem) +{ + virLockManagerPtr lock; + int ret =3D -1; + + VIR_DEBUG("plugin=3D%p dom=3D%p mem=3D%p", plugin, dom, mem); + + if (!(lock =3D virDomainLockManagerNew(plugin, NULL, dom, false, false= , 0))) + return -1; + + if (virDomainLockManagerAddMemory(lock, mem) < 0) + goto cleanup; + + if (virLockManagerAcquire(lock, NULL, 0, + VIR_DOMAIN_LOCK_FAILURE_DEFAULT, NULL) < 0) + goto cleanup; + + ret =3D 0; + cleanup: + virLockManagerFree(lock); + return ret; +} + + +int +virDomainLockMetadataMemUnlock(virLockManagerPluginPtr plugin, + virDomainObjPtr dom, + virDomainMemoryDefPtr mem) +{ + virLockManagerPtr lock; + int ret =3D -1; + + VIR_DEBUG("plugin=3D%p dom=3D%p mem=3D%p", plugin, dom, mem); + + if (!(lock =3D virDomainLockManagerNew(plugin, NULL, dom, false, false= , 0))) + return -1; + + if (virDomainLockManagerAddMemory(lock, mem) < 0) + goto cleanup; + + if (virLockManagerRelease(lock, NULL, 0) < 0) + goto cleanup; + + ret =3D 0; + cleanup: + virLockManagerFree(lock); + return ret; +} diff --git a/src/locking/domain_lock.h b/src/locking/domain_lock.h index fb4910230c..fbd3ee1d4e 100644 --- a/src/locking/domain_lock.h +++ b/src/locking/domain_lock.h @@ -66,4 +66,32 @@ int virDomainLockLeaseDetach(virLockManagerPluginPtr plu= gin, virDomainObjPtr dom, virDomainLeaseDefPtr lease); =20 +int virDomainLockMetadataLock(virLockManagerPluginPtr plugin, + virDomainObjPtr dom); + +int virDomainLockMetadataUnlock(virLockManagerPluginPtr plugin, + virDomainObjPtr dom); + +int virDomainLockMetadataDiskLock(virLockManagerPluginPtr plugin, + virDomainObjPtr dom, + virDomainDiskDefPtr disk); +int virDomainLockMetadataDiskUnlock(virLockManagerPluginPtr plugin, + virDomainObjPtr dom, + virDomainDiskDefPtr disk); + +int virDomainLockMetadataImageLock(virLockManagerPluginPtr plugin, + virDomainObjPtr dom, + virStorageSourcePtr src); + +int virDomainLockMetadataImageUnlock(virLockManagerPluginPtr plugin, + virDomainObjPtr dom, + virStorageSourcePtr src); + +int virDomainLockMetadataMemLock(virLockManagerPluginPtr plugin, + virDomainObjPtr dom, + virDomainMemoryDefPtr mem); +int virDomainLockMetadataMemUnlock(virLockManagerPluginPtr plugin, + virDomainObjPtr dom, + virDomainMemoryDefPtr mem); + #endif /* __VIR_DOMAIN_LOCK_H__ */ --=20 2.16.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list