From nobody Wed Apr 24 16:56:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) client-ip=207.211.31.81; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 1580733829636542.5001151922684; Mon, 3 Feb 2020 04:43:49 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-3-s1Ui0uyDM_GCOBiLbI2fYg-1; Mon, 03 Feb 2020 07:43:45 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 626001098D17; Mon, 3 Feb 2020 12:43:40 +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 0F81A90505; Mon, 3 Feb 2020 12:43:40 +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 95CA418089CF; Mon, 3 Feb 2020 12:43:39 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 013ChcpM006050 for ; Mon, 3 Feb 2020 07:43:38 -0500 Received: by smtp.corp.redhat.com (Postfix) id 399C5610E1; Mon, 3 Feb 2020 12:43:38 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-57.ams2.redhat.com [10.36.112.57]) by smtp.corp.redhat.com (Postfix) with ESMTP id 42D0E50227; Mon, 3 Feb 2020 12:43:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1580733828; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=d4vVjg3Uo9MXjonWZu8j6XfW1Gw6y7vC5pKe8JYrc/o=; b=TZEFtF9v1U7GY59vBPA3MkCAMAaEhD6llSB59c/UmokoLz+wx+jdrGvGP+STD+YwNZjscg nY1xWdCmiqPDkhFkcEXPXw4i+r1sHYHL/mPeHndsfTpzzTQg4x/ftx0rzBPwZvj67zT0QG aX8H1OivdZedMHZEKiEUzPdb5x6YbEg= From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Subject: [libvirt PATCH 1/6] Add VIR_MIGRATE_LOCAL flag to virsh migrate command Date: Mon, 3 Feb 2020 12:43:28 +0000 Message-Id: <20200203124333.1925908-2-berrange@redhat.com> In-Reply-To: <20200203124333.1925908-1-berrange@redhat.com> References: <20200203124333.1925908-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Cc: Shaju Abraham 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-MC-Unique: s1Ui0uyDM_GCOBiLbI2fYg-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: Shaju Abraham In order to support the local migration, the migration framework should distinguish between local and non local migrations. Add a flag to the 'virsh migrate' command so that framework can easily identify a local migration attempt. Signed-off-by: Shaju Abraham --- include/libvirt/libvirt-domain.h | 6 ++++++ tools/virsh-domain.c | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-dom= ain.h index 5846e93d98..018635b4f1 100644 --- a/include/libvirt/libvirt-domain.h +++ b/include/libvirt/libvirt-domain.h @@ -849,6 +849,12 @@ typedef enum { */ VIR_MIGRATE_PARALLEL =3D (1 << 17), =20 + /* Setting the VIR_MIGRATE_LOCAL flag tells libvirt that the migration + * is within the host and bypass checks which refuses local host migra= tion.It + * indicates that the same UUID and name will be used for different do= mains. + */ + VIR_MIGRATE_LOCAL =3D (1 << 18), + } virDomainMigrateFlags; =20 =20 diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index e64e08e5da..b91117a6a2 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -10421,6 +10421,10 @@ static const vshCmdOptDef opts_migrate[] =3D { .type =3D VSH_OT_BOOL, .help =3D N_("peer-2-peer migration") }, + {.name =3D "local", + .type =3D VSH_OT_BOOL, + .help =3D N_("local migration") + }, {.name =3D "direct", .type =3D VSH_OT_BOOL, .help =3D N_("direct migration") @@ -10820,6 +10824,9 @@ doMigrate(void *opaque) flags |=3D VIR_MIGRATE_LIVE; if (vshCommandOptBool(cmd, "p2p")) flags |=3D VIR_MIGRATE_PEER2PEER; + + if (vshCommandOptBool(cmd, "local")) + flags |=3D VIR_MIGRATE_LOCAL; if (vshCommandOptBool(cmd, "tunnelled")) flags |=3D VIR_MIGRATE_TUNNELLED; =20 --=20 2.24.1 From nobody Wed Apr 24 16:56:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) client-ip=207.211.31.81; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 1580733834208465.98845305974476; Mon, 3 Feb 2020 04:43:54 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-63-0HsawvLNPHa1VN4NnXHQLw-1; Mon, 03 Feb 2020 07:43:50 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id CE0BD10B1575; Mon, 3 Feb 2020 12:43:44 +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 87FF48AC4E; Mon, 3 Feb 2020 12:43:44 +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 2CDD418089D7; Mon, 3 Feb 2020 12:43:44 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 013Chei1006067 for ; Mon, 3 Feb 2020 07:43:40 -0500 Received: by smtp.corp.redhat.com (Postfix) id 05DC7610DB; Mon, 3 Feb 2020 12:43:40 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-57.ams2.redhat.com [10.36.112.57]) by smtp.corp.redhat.com (Postfix) with ESMTP id 877C265F78; Mon, 3 Feb 2020 12:43:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1580733833; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=tbKH7zijFL5QK3tY8PnS8NDh/6+jucVR9IaHdxsu594=; b=H4zlFXP/SJMQsG3+RMWYgTg16x500gjEOBaVDz1lNwGbY1QNYfFX2sidRRR7W75oCHiw3Q ZGSj9J9g19kt2tef5aGxtdyaGs7cuWbcAFvDmr7XxRlR7/X9CH/W1QeTXv8BCHmoq0GJAl 1a1Ozun5JOk9LHCbs+XGlEt+aru5cHE= From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Subject: [libvirt PATCH 2/6] Introduce remote hash tables and helper routines Date: Mon, 3 Feb 2020 12:43:29 +0000 Message-Id: <20200203124333.1925908-3-berrange@redhat.com> In-Reply-To: <20200203124333.1925908-1-berrange@redhat.com> References: <20200203124333.1925908-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Cc: Shaju Abraham 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: , 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-MC-Unique: 0HsawvLNPHa1VN4NnXHQLw-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: Shaju Abraham Libvirt assumes that there will ever be only one VM in a host with a specific UUId and name. The VM object pointers are stored in hash tables and are indexed using the UUID or name. For local migrations both the source and destination VMs reside on the same host and share the same name and UUID. This will introduce hash collisions. Introduce two more hash tables to manage the destination VM object. The remote VM objects are always stored in the newly introduced remote hashtable. The hash table helper routines are modified to handle the newly introduced remote hash tables. The existing functions are duplicated to operate on the remote hash table. This is done intentionally so that the changes to existing migration framew= ork is minimal. Signed-off-by: Shaju Abraham --- src/conf/virdomainobjlist.c | 232 ++++++++++++++++++++++++++++++++++-- src/conf/virdomainobjlist.h | 10 ++ src/libvirt_private.syms | 4 + 3 files changed, 238 insertions(+), 8 deletions(-) diff --git a/src/conf/virdomainobjlist.c b/src/conf/virdomainobjlist.c index 417025ae9f..37fc0c4d5e 100644 --- a/src/conf/virdomainobjlist.c +++ b/src/conf/virdomainobjlist.c @@ -48,10 +48,14 @@ struct _virDomainObjList { /* uuid string -> virDomainObj mapping * for O(1), lockless lookup-by-uuid */ virHashTable *objs; + /* Hashtable to support Local Migration */ + virHashTable *remote_objs; =20 /* name -> virDomainObj mapping for O(1), * lockless lookup-by-name */ virHashTable *objsName; + /* Hashtable to support Local Migration */ + virHashTable *remote_objsName; }; =20 =20 @@ -80,6 +84,13 @@ virDomainObjListPtr virDomainObjListNew(void) virObjectUnref(doms); return NULL; } + if (!(doms->remote_objs =3D virHashCreate(50, virObjectFreeHashData)) = || + !(doms->remote_objsName =3D virHashCreate(50, virObjectFreeHashDat= a))) { + virHashFree(doms->objs); + virHashFree(doms->objsName); + virObjectUnref(doms); + return NULL; + } =20 return doms; } @@ -92,6 +103,193 @@ static void virDomainObjListDispose(void *obj) virHashFree(doms->objs); virHashFree(doms->objsName); } +/*Remote Hash table manipulation routines*/ +static virDomainObjPtr +virDomainObjListFindByUUIDRemoteLocked(virDomainObjListPtr doms, + const unsigned char *uuid) +{ + char uuidstr[VIR_UUID_STRING_BUFLEN]; + virDomainObjPtr obj; + + virUUIDFormat(uuid, uuidstr); + obj =3D virHashLookup(doms->remote_objs, uuidstr); + virObjectRef(obj); + if (obj) { + virObjectLock(obj); + if (obj->removing) { + virObjectUnlock(obj); + virObjectUnref(obj); + obj =3D NULL; + } + } + return obj; +} + +static virDomainObjPtr +virDomainObjListFindByUUIDFromHashLocked(virHashTable *table, + const unsigned char *uuid) +{ + char uuidstr[VIR_UUID_STRING_BUFLEN]; + virDomainObjPtr obj; + + virUUIDFormat(uuid, uuidstr); + obj =3D virHashLookup(table, uuidstr); + virObjectRef(obj); + if (obj) { + virObjectLock(obj); + if (obj->removing) { + virObjectUnlock(obj); + virObjectUnref(obj); + obj =3D NULL; + } + } + return obj; +} +/** + * @doms: Domain object list + * @uuid: UUID to search the doms->objs table + * + * Lookup the @uuid in the doms->objs hash table and return a + * locked and ref counted domain object if found. Caller is + * expected to use the virDomainObjEndAPI when done with the object. + */ +virDomainObjPtr +virDomainObjListFindByUUIDRemote(virDomainObjListPtr doms, + const unsigned char *uuid) +{ + virDomainObjPtr obj; + virObjectRWLockRead(doms); + obj =3D virDomainObjListFindByUUIDRemoteLocked(doms, uuid); + virObjectRWUnlock(doms); + + return obj; +} +static virDomainObjPtr +virDomainObjListFindByNameFromHashLocked(virHashTable *table, + const char *name) +{ + virDomainObjPtr obj; + + obj =3D virHashLookup(table, name); + virObjectRef(obj); + if (obj) { + virObjectLock(obj); + if (obj->removing) { + virObjectUnlock(obj); + virObjectUnref(obj); + obj =3D NULL; + } + } + return obj; +} + +/** + * @doms: Domain object list + * @name: Name to search the doms->objsName table + * + * Lookup the @name in the doms->objsName_remote hash table and return a + * locked and ref counted domain object if found. Caller is expected + * to use the virDomainObjEndAPI when done with the object. + */ +virDomainObjPtr +virDomainObjListFindByNameRemote(virDomainObjListPtr doms, + const char *name) +{ + virDomainObjPtr obj; + virObjectRWLockRead(doms); + obj =3D virDomainObjListFindByNameFromHashLocked(doms->remote_objs, na= me); + virObjectRWUnlock(doms); + + return obj; +} + +/* The caller must hold lock on 'doms' in addition to 'virDomainObjListRem= ove' + * requirements + * + * Can be used to remove current element while iterating with + * virDomainObjListForEach + */ +int +virDomainObjListRemoveRemoteLocked(virDomainObjListPtr doms, + virDomainObjPtr dom) +{ + char uuidstr[VIR_UUID_STRING_BUFLEN]; + virDomainObjPtr remoteDom; + int ret =3D -1; + + virUUIDFormat(dom->def->uuid, uuidstr); + remoteDom =3D virHashSteal(doms->remote_objs, uuidstr); + if (remoteDom !=3D dom) { + virReportError(VIR_ERR_OPERATION_INVALID, "%s", + _("Can't get matching VM from uuid")); + return ret; + } + remoteDom =3D virHashSteal(doms->remote_objsName, dom->def->name); + if (remoteDom !=3D dom) { + virReportError(VIR_ERR_OPERATION_INVALID, "%s", + _("Can't get matching VM from name")); + return ret; + } + return 0; +} + +/** + * @doms: Pointer to the domain object list + * @dom: Domain pointer from either after Add or FindBy* API where the + * @dom was successfully added to both the doms->objs and ->objsName + * hash tables that now would need to be removed. + * + * The caller must hold a lock on the driver owning 'doms', + * and must also have locked and ref counted 'dom', to ensure + * no one else is either waiting for 'dom' or still using it. + * + * When this function returns, @dom will be removed from the hash + * tables and returned with lock and refcnt that was present upon entry. + */ +int +virDomainObjListRemoveRemote(virDomainObjListPtr doms, + virDomainObjPtr dom) +{ + int ret =3D -1; + virObjectRef(dom); + virObjectUnlock(dom); + virObjectRWLockWrite(doms); + virObjectLock(dom); + ret =3D virDomainObjListRemoveRemoteLocked(doms, dom); + virObjectUnref(dom); + virObjectRWUnlock(doms); + return ret; +} +/* + * @doms: Pointer to the domain object list + * @dom: Domain pointer + * This helper routine inserts a domain object to the hash tables. + * @dom should be successfully added to both the doms->objs and ->objsName + * hashtables. Required by the local migration use case. +*/ +int virDomainObjListAddEntry(virDomainObjListPtr doms, virDomainObjPtr dom) +{ + int ret =3D -1; + char uuidstr[VIR_UUID_STRING_BUFLEN]; + virUUIDFormat(dom->def->uuid, uuidstr); + virObjectRef(dom); + virObjectUnlock(dom); + virObjectLock(doms); + virObjectLock(dom); + if (virHashAddEntry(doms->objs, uuidstr, dom) < 0) { + virObjectUnref(dom); + return ret; + } + if (virHashAddEntry(doms->objsName, dom->def->name, dom) < 0) { + virHashRemoveEntry(doms->objs, uuidstr); + goto cleanup; + } + ret =3D 0; + cleanup: + virObjectUnlock(dom); + virObjectUnlock(doms); + return ret; +} =20 =20 static int virDomainObjListSearchID(const void *payload, @@ -225,6 +423,7 @@ virDomainObjListFindByName(virDomainObjListPtr doms, /** * @doms: Domain object list pointer * @vm: Domain object to be added + * @localMigration: flag to indicate local migration * * Upon entry @vm should have at least 1 ref and be locked. * @@ -240,16 +439,22 @@ virDomainObjListFindByName(virDomainObjListPtr doms, */ static int virDomainObjListAddObjLocked(virDomainObjListPtr doms, - virDomainObjPtr vm) + virDomainObjPtr vm, bool localMigration) { char uuidstr[VIR_UUID_STRING_BUFLEN]; + virHashTable *table =3D doms->objs; + virHashTable *table_name =3D doms->objsName; + if (localMigration) { + table =3D doms->remote_objs; + table_name =3D doms->remote_objsName; + } =20 virUUIDFormat(vm->def->uuid, uuidstr); - if (virHashAddEntry(doms->objs, uuidstr, vm) < 0) + if (virHashAddEntry(table, uuidstr, vm) < 0) return -1; virObjectRef(vm); =20 - if (virHashAddEntry(doms->objsName, vm->def->name, vm) < 0) { + if (virHashAddEntry(table_name, vm->def->name, vm) < 0) { virHashRemoveEntry(doms->objs, uuidstr); return -1; } @@ -281,14 +486,25 @@ virDomainObjListAddLocked(virDomainObjListPtr doms, unsigned int flags, virDomainDefPtr *oldDef) { - virDomainObjPtr vm; + virDomainObjPtr vm =3D NULL; char uuidstr[VIR_UUID_STRING_BUFLEN]; + bool localMigration =3D 0; + virHashTable *table =3D doms->objs; + virHashTable *table_name =3D doms->objsName; =20 if (oldDef) *oldDef =3D NULL; + /* Check if it is local migration. In that case the src vm exists with + * same UUID and name.We have to create a new UUID and name for the do= main. + */ + if (flags & VIR_DOMAIN_OBJ_LIST_ADD_LIVE_LOCAL) { + table =3D doms->remote_objs; + table_name =3D doms->remote_objsName; + localMigration =3D 1; + } =20 /* See if a VM with matching UUID already exists */ - if ((vm =3D virDomainObjListFindByUUIDLocked(doms, def->uuid))) { + if ((vm =3D virDomainObjListFindByUUIDFromHashLocked(table, def->uuid)= )) { if (vm->removing) { virReportError(VIR_ERR_OPERATION_FAILED, _("domain '%s' is already being removed"), @@ -325,7 +541,7 @@ virDomainObjListAddLocked(virDomainObjListPtr doms, oldDef); } else { /* UUID does not match, but if a name matches, refuse it */ - if ((vm =3D virDomainObjListFindByNameLocked(doms, def->name))) { + if ((vm =3D virDomainObjListFindByNameFromHashLocked(table_name, d= ef->name))) { virUUIDFormat(vm->def->uuid, uuidstr); virReportError(VIR_ERR_OPERATION_FAILED, _("domain '%s' already exists with uuid %s"), @@ -337,7 +553,7 @@ virDomainObjListAddLocked(virDomainObjListPtr doms, goto error; vm->def =3D def; =20 - if (virDomainObjListAddObjLocked(doms, vm) < 0) { + if (virDomainObjListAddObjLocked(doms, vm, localMigration) < 0) { vm->def =3D NULL; goto error; } @@ -563,7 +779,7 @@ virDomainObjListLoadStatus(virDomainObjListPtr doms, goto error; } =20 - if (virDomainObjListAddObjLocked(doms, obj) < 0) + if (virDomainObjListAddObjLocked(doms, obj, 0) < 0) goto error; =20 if (notify) diff --git a/src/conf/virdomainobjlist.h b/src/conf/virdomainobjlist.h index 6150e13aa4..a3253787ff 100644 --- a/src/conf/virdomainobjlist.h +++ b/src/conf/virdomainobjlist.h @@ -33,12 +33,18 @@ virDomainObjPtr virDomainObjListFindByID(virDomainObjLi= stPtr doms, int id); virDomainObjPtr virDomainObjListFindByUUID(virDomainObjListPtr doms, const unsigned char *uuid); +virDomainObjPtr virDomainObjListFindByUUIDRemote(virDomainObjListPtr doms, + const unsigned char *uuid= ); virDomainObjPtr virDomainObjListFindByName(virDomainObjListPtr doms, const char *name); +virDomainObjPtr virDomainObjListFindByNameRemote(virDomainObjListPtr doms, + const char *name); +int virDomainObjListAddEntry(virDomainObjListPtr doms,virDomainObjPtr dom); =20 enum { VIR_DOMAIN_OBJ_LIST_ADD_LIVE =3D (1 << 0), VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE =3D (1 << 1), + VIR_DOMAIN_OBJ_LIST_ADD_LIVE_LOCAL =3D (1 << 2), }; virDomainObjPtr virDomainObjListAdd(virDomainObjListPtr doms, virDomainDefPtr def, @@ -61,6 +67,10 @@ void virDomainObjListRemove(virDomainObjListPtr doms, virDomainObjPtr dom); void virDomainObjListRemoveLocked(virDomainObjListPtr doms, virDomainObjPtr dom); +int virDomainObjListRemoveRemoteLocked(virDomainObjListPtr doms, + virDomainObjPtr dom); +int virDomainObjListRemoveRemote(virDomainObjListPtr doms, + virDomainObjPtr dom); =20 int virDomainObjListLoadAllConfigs(virDomainObjListPtr doms, const char *configDir, diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 970f412527..c104313319 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1045,7 +1045,9 @@ virDomainObjListConvert; virDomainObjListExport; virDomainObjListFindByID; virDomainObjListFindByName; +virDomainObjListFindByNameRemote; virDomainObjListFindByUUID; +virDomainObjListFindByUUIDRemote; virDomainObjListForEach; virDomainObjListGetActiveIDs; virDomainObjListGetInactiveNames; @@ -1054,7 +1056,9 @@ virDomainObjListNew; virDomainObjListNumOfDomains; virDomainObjListRemove; virDomainObjListRemoveLocked; +virDomainObjListRemoveRemote; virDomainObjListRename; +virDomainObjListAddEntry; =20 =20 # conf/virdomainsnapshotobjlist.h --=20 2.24.1 From nobody Wed Apr 24 16:56:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) client-ip=207.211.31.81; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 158073383170045.81990138185199; Mon, 3 Feb 2020 04:43:51 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-387-UF1cRtQNNEiektH4iiA5RQ-1; Mon, 03 Feb 2020 07:43:48 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 879111021868; Mon, 3 Feb 2020 12:43:42 +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 4939190770; Mon, 3 Feb 2020 12:43:42 +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 F2E9F8174A; Mon, 3 Feb 2020 12:43:41 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 013ChfUV006078 for ; Mon, 3 Feb 2020 07:43:41 -0500 Received: by smtp.corp.redhat.com (Postfix) id 2D7E765F6A; Mon, 3 Feb 2020 12:43:41 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-57.ams2.redhat.com [10.36.112.57]) by smtp.corp.redhat.com (Postfix) with ESMTP id EDAC4672C6; Mon, 3 Feb 2020 12:43:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1580733830; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=+lA6GuM+JBkk4lwTK8MRHirRZwL4ZG4ui7z8MgDJJQU=; b=Z8p3gFD5iBrzvLqI1Hs4CguSE5I+JV7Sb10FcuZmBh3UiILmqBAVNjy45gXBXpHh6WhQ0R dVtA2m0lnM0OXtUsaoZvI840ywsAJjv5cT5kJeDCnlshZihCtJAeUCJsEo7OVkj4z390zS 5xCUWRRXhLO/TAk6YuJ6vtAzIMLlFhg= From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Subject: [libvirt PATCH 3/6] Add local migration support in QEMU Migration framework Date: Mon, 3 Feb 2020 12:43:30 +0000 Message-Id: <20200203124333.1925908-4-berrange@redhat.com> In-Reply-To: <20200203124333.1925908-1-berrange@redhat.com> References: <20200203124333.1925908-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Cc: Shaju Abraham 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-MC-Unique: UF1cRtQNNEiektH4iiA5RQ-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: Shaju Abraham The local migration is selected by the option 'local' in virsh migrate command. Once 'local' is specified in the command line, the migration framework needs to follow the local migration path. Use the passed flag to selectively bypass the checks that otherwise prevents the local migration in QEMU migration framework. Signed-off-by: Shaju Abraham --- src/qemu/qemu_migration.c | 46 +++++++----- src/qemu/qemu_migration.h | 1 + src/qemu/qemu_migration_cookie.c | 121 ++++++++++++++++--------------- src/qemu/qemu_migration_cookie.h | 2 + src/qemu/qemu_process.c | 3 +- src/qemu/qemu_process.h | 2 + 6 files changed, 98 insertions(+), 77 deletions(-) diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c index d7814208a2..d22daeac9c 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -2334,15 +2334,30 @@ qemuMigrationDstPrepareAny(virQEMUDriverPtr driver, bool tunnel =3D !!st; char *xmlout =3D NULL; unsigned int cookieFlags; - unsigned int startFlags; + unsigned int startFlags =3D 0; + unsigned int eatCookieFlags; qemuProcessIncomingDefPtr incoming =3D NULL; bool taint_hook =3D false; bool stopProcess =3D false; bool relabel =3D false; int rv; char *tlsAlias =3D NULL; + unsigned long list_flags =3D VIR_DOMAIN_OBJ_LIST_ADD_LIVE | + VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE; + eatCookieFlags =3D QEMU_MIGRATION_COOKIE_LOCKSTATE | + QEMU_MIGRATION_COOKIE_NBD | + QEMU_MIGRATION_COOKIE_MEMORY_HOTPLUG | + QEMU_MIGRATION_COOKIE_CPU_HOTPLUG | + QEMU_MIGRATION_COOKIE_CPU | + QEMU_MIGRATION_COOKIE_ALLOW_REBOOT | + QEMU_MIGRATION_COOKIE_CAPS; =20 virNWFilterReadLockFilterUpdates(); + if (flags & VIR_MIGRATE_LOCAL) { + list_flags |=3D VIR_DOMAIN_OBJ_LIST_ADD_LIVE_LOCAL; + eatCookieFlags |=3D QEMU_MIGRATION_COOKIE_LOCAL_MIGRATION; + startFlags |=3D VIR_QEMU_PROCESS_START_LOCAL_MIG; + } =20 if (flags & VIR_MIGRATE_OFFLINE) { if (flags & (VIR_MIGRATE_NON_SHARED_DISK | @@ -2439,19 +2454,12 @@ qemuMigrationDstPrepareAny(virQEMUDriverPtr driver, * point in having the domain in the list at that point. */ if (!(mig =3D qemuMigrationEatCookie(driver, *def, origname, NULL, cookiein, cookieinlen, - QEMU_MIGRATION_COOKIE_LOCKSTATE | - QEMU_MIGRATION_COOKIE_NBD | - QEMU_MIGRATION_COOKIE_MEMORY_HOTPLU= G | - QEMU_MIGRATION_COOKIE_CPU_HOTPLUG | - QEMU_MIGRATION_COOKIE_CPU | - QEMU_MIGRATION_COOKIE_ALLOW_REBOOT | - QEMU_MIGRATION_COOKIE_CAPS))) + eatCookieFlags))) goto cleanup; =20 if (!(vm =3D virDomainObjListAdd(driver->domains, *def, driver->xmlopt, - VIR_DOMAIN_OBJ_LIST_ADD_LIVE | - VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE, + list_flags, NULL))) goto cleanup; *def =3D NULL; @@ -2494,9 +2502,7 @@ qemuMigrationDstPrepareAny(virQEMUDriverPtr driver, _("cannot create pipe for tunnelled migration= ")); goto stopjob; } - - startFlags =3D VIR_QEMU_PROCESS_START_AUTODESTROY; - + startFlags |=3D VIR_QEMU_PROCESS_START_AUTODESTROY; if (qemuProcessInit(driver, vm, mig->cpu, QEMU_ASYNC_JOB_MIGRATION_IN, true, startFlags) < 0) goto stopjob; @@ -2938,6 +2944,7 @@ qemuMigrationSrcConfirmPhase(virQEMUDriverPtr driver, qemuMigrationCookiePtr mig; virObjectEventPtr event; int rv =3D -1; + unsigned int cookieFlags =3D 0; virQEMUDriverConfigPtr cfg =3D virQEMUDriverGetConfig(driver); qemuDomainObjPrivatePtr priv =3D vm->privateData; qemuDomainJobInfoPtr jobInfo =3D NULL; @@ -2948,15 +2955,16 @@ qemuMigrationSrcConfirmPhase(virQEMUDriverPtr drive= r, flags, retcode); =20 virCheckFlags(QEMU_MIGRATION_FLAGS, -1); - + cookieFlags =3D QEMU_MIGRATION_COOKIE_STATS; + if (flags & VIR_MIGRATE_LOCAL) + cookieFlags |=3D QEMU_MIGRATION_COOKIE_LOCAL_MIGRATION; qemuMigrationJobSetPhase(driver, vm, retcode =3D=3D 0 ? QEMU_MIGRATION_PHASE_CONFIRM3 : QEMU_MIGRATION_PHASE_CONFIRM3_CANCELLED); =20 if (!(mig =3D qemuMigrationEatCookie(driver, vm->def, priv->origname, = priv, - cookiein, cookieinlen, - QEMU_MIGRATION_COOKIE_STATS))) + cookiein, cookieinlen, cookieFlags)= )) goto cleanup; =20 if (retcode =3D=3D 0) @@ -3420,7 +3428,8 @@ qemuMigrationSrcRun(virQEMUDriverPtr driver, cookieout, cookieoutlen, flags, resource, spec, spec->destType, spec->fwdType, dconn, NULLSTR(graphicsuri), nmigrate_disks, migrate_disks); - + if (flags & VIR_MIGRATE_LOCAL) + cookieFlags |=3D QEMU_MIGRATION_COOKIE_LOCAL_MIGRATION; if (flags & VIR_MIGRATE_NON_SHARED_DISK) { migrate_flags |=3D QEMU_MONITOR_MIGRATE_NON_SHARED_DISK; cookieFlags |=3D QEMU_MIGRATION_COOKIE_NBD; @@ -4955,6 +4964,9 @@ qemuMigrationDstFinish(virQEMUDriverPtr driver, * even though VIR_MIGRATE_PERSIST_DEST was not used. */ cookie_flags |=3D QEMU_MIGRATION_COOKIE_PERSISTENT; =20 + if (flags & VIR_MIGRATE_LOCAL) + cookie_flags |=3D QEMU_MIGRATION_COOKIE_LOCAL_MIGRATION; + if (!(mig =3D qemuMigrationEatCookie(driver, vm->def, priv->origname, = priv, cookiein, cookieinlen, cookie_flags= ))) goto endjob; diff --git a/src/qemu/qemu_migration.h b/src/qemu/qemu_migration.h index b6f88d3fd9..2cb4bb9023 100644 --- a/src/qemu/qemu_migration.h +++ b/src/qemu/qemu_migration.h @@ -59,6 +59,7 @@ VIR_MIGRATE_POSTCOPY | \ VIR_MIGRATE_TLS | \ VIR_MIGRATE_PARALLEL | \ + VIR_MIGRATE_LOCAL |\ 0) =20 /* All supported migration parameters and their types. */ diff --git a/src/qemu/qemu_migration_cookie.c b/src/qemu/qemu_migration_coo= kie.c index 299bf17c9e..18544dbaac 100644 --- a/src/qemu/qemu_migration_cookie.c +++ b/src/qemu/qemu_migration_cookie.c @@ -51,6 +51,7 @@ VIR_ENUM_IMPL(qemuMigrationCookieFlag, "cpu", "allowReboot", "capabilities", + "local-migration", ); =20 =20 @@ -1199,69 +1200,71 @@ qemuMigrationCookieXMLParse(qemuMigrationCookiePtr = mig, =20 /* We don't store the uuid, name, hostname, or hostuuid * values. We just compare them to local data to do some - * sanity checking on migration operation + * sanity checking on migration operation. In case of Local + * Migration bypass the checks. We know that we are migrating + * to the same host and the name and UUID will be existing in + * the host. */ =20 /* Extract domain name */ - if (!(tmp =3D virXPathString("string(./name[1])", ctxt))) { - virReportError(VIR_ERR_INTERNAL_ERROR, - "%s", _("missing name element in migration data")); - goto error; - } - if (STRNEQ(tmp, mig->name)) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Incoming cookie data had unexpected name %s vs %= s"), - tmp, mig->name); - goto error; - } - VIR_FREE(tmp); - - /* Extract domain uuid */ - tmp =3D virXPathString("string(./uuid[1])", ctxt); - if (!tmp) { - virReportError(VIR_ERR_INTERNAL_ERROR, - "%s", _("missing uuid element in migration data")); - goto error; - } - virUUIDFormat(mig->uuid, uuidstr); - if (STRNEQ(tmp, uuidstr)) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Incoming cookie data had unexpected UUID %s vs %= s"), - tmp, uuidstr); - goto error; - } - VIR_FREE(tmp); - - /* Check & forbid "localhost" migration */ - if (!(mig->remoteHostname =3D virXPathString("string(./hostname[1])", = ctxt))) { - virReportError(VIR_ERR_INTERNAL_ERROR, - "%s", _("missing hostname element in migration data= ")); - goto error; - } - if (STREQ(mig->remoteHostname, mig->localHostname)) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Attempt to migrate guest to the same host %s"), - mig->remoteHostname); - goto error; - } - - if (!(tmp =3D virXPathString("string(./hostuuid[1])", ctxt))) { - virReportError(VIR_ERR_INTERNAL_ERROR, - "%s", _("missing hostuuid element in migration data= ")); - goto error; - } - if (virUUIDParse(tmp, mig->remoteHostuuid) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - "%s", _("malformed hostuuid element in migration da= ta")); - goto error; - } - if (memcmp(mig->remoteHostuuid, mig->localHostuuid, VIR_UUID_BUFLEN) = =3D=3D 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Attempt to migrate guest to the same host %s"), - tmp); - goto error; + if (!(flags & QEMU_MIGRATION_COOKIE_LOCAL_MIGRATION)) { + if (!(tmp =3D virXPathString("string(./name[1])", ctxt))) { + virReportError(VIR_ERR_INTERNAL_ERROR, + "%s", _("missing name element in migration data= ")); + goto error; + } + if (STRNEQ(tmp, mig->name)) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Incoming cookie data had unexpected name %s = vs %s"), + tmp, mig->name); + goto error; + } + VIR_FREE(tmp); + /* Extract domain uuid */ + tmp =3D virXPathString("string(./uuid[1])", ctxt); + if (!tmp) { + virReportError(VIR_ERR_INTERNAL_ERROR, + "%s", _("missing uuid element in migration data= ")); + goto error; + } + virUUIDFormat(mig->uuid, uuidstr); + if (STRNEQ(tmp, uuidstr)) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Incoming cookie data had unexpected UUID %s = vs %s"), + tmp, uuidstr); + goto error; + } + VIR_FREE(tmp); + /* Check & forbid "localhost" migration */ + if (!(mig->remoteHostname =3D virXPathString("string(./hostname[1]= )", ctxt))) { + virReportError(VIR_ERR_INTERNAL_ERROR, + "%s", _("missing hostname element in migration = data")); + goto error; + } + if (STREQ(mig->remoteHostname, mig->localHostname)) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Attempt to migrate guest to the same host %s= "), + mig->remoteHostname); + goto error; + } + if (!(tmp =3D virXPathString("string(./hostuuid[1])", ctxt))) { + virReportError(VIR_ERR_INTERNAL_ERROR, + "%s", _("missing hostuuid element in migration = data")); + goto error; + } + if (virUUIDParse(tmp, mig->remoteHostuuid) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + "%s", _("malformed hostuuid element in migratio= n data")); + goto error; + } + if (memcmp(mig->remoteHostuuid, mig->localHostuuid, VIR_UUID_BUFLE= N) =3D=3D 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Attempt to migrate guest to the same host %s= "), + tmp); + goto error; + } + VIR_FREE(tmp); } - VIR_FREE(tmp); =20 /* Check to ensure all mandatory features from XML are also * present in 'flags' */ diff --git a/src/qemu/qemu_migration_cookie.h b/src/qemu/qemu_migration_coo= kie.h index 20e1ed60ca..7574672fd6 100644 --- a/src/qemu/qemu_migration_cookie.h +++ b/src/qemu/qemu_migration_cookie.h @@ -33,6 +33,7 @@ typedef enum { QEMU_MIGRATION_COOKIE_FLAG_CPU, QEMU_MIGRATION_COOKIE_FLAG_ALLOW_REBOOT, QEMU_MIGRATION_COOKIE_FLAG_CAPS, + QEMU_MIGRATION_COOKIE_FLAG_LOCAL_MIGRATION, =20 QEMU_MIGRATION_COOKIE_FLAG_LAST } qemuMigrationCookieFlags; @@ -51,6 +52,7 @@ typedef enum { QEMU_MIGRATION_COOKIE_CPU =3D (1 << QEMU_MIGRATION_COOKIE_FLAG_CPU), QEMU_MIGRATION_COOKIE_ALLOW_REBOOT =3D (1 << QEMU_MIGRATION_COOKIE_FLA= G_ALLOW_REBOOT), QEMU_MIGRATION_COOKIE_CAPS =3D (1 << QEMU_MIGRATION_COOKIE_FLAG_CAPS), + QEMU_MIGRATION_COOKIE_LOCAL_MIGRATION =3D (1 << QEMU_MIGRATION_COOKIE_= FLAG_LOCAL_MIGRATION), } qemuMigrationCookieFeatures; =20 typedef struct _qemuMigrationCookieGraphics qemuMigrationCookieGraphics; diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 57a60c568a..df0884a233 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -6679,7 +6679,8 @@ qemuProcessLaunch(virConnectPtr conn, VIR_QEMU_PROCESS_START_PAUSED | VIR_QEMU_PROCESS_START_AUTODESTROY | VIR_QEMU_PROCESS_START_NEW | - VIR_QEMU_PROCESS_START_GEN_VMID, -1); + VIR_QEMU_PROCESS_START_GEN_VMID | + VIR_QEMU_PROCESS_START_LOCAL_MIG, -1); =20 cfg =3D virQEMUDriverGetConfig(driver); =20 diff --git a/src/qemu/qemu_process.h b/src/qemu/qemu_process.h index 9af9f967fd..7aa67158b0 100644 --- a/src/qemu/qemu_process.h +++ b/src/qemu/qemu_process.h @@ -81,6 +81,8 @@ typedef enum { VIR_QEMU_PROCESS_START_GEN_VMID =3D 1 << 5, /* Generate a new VMID= */ VIR_QEMU_PROCESS_START_STANDALONE =3D 1 << 6, /* Require CLI args to= be usable standalone, ie no FD passing and = the like */ + VIR_QEMU_PROCESS_START_LOCAL_MIG =3D 1 << 7, /* internal, new VM is= starting + for Local Migration */ } qemuProcessStartFlags; =20 int qemuProcessStart(virConnectPtr conn, --=20 2.24.1 From nobody Wed Apr 24 16:56:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 15807338395421014.0899762005005; Mon, 3 Feb 2020 04:43:59 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-52-zDteTxQTObSk4BGbZFem7w-1; Mon, 03 Feb 2020 07:43:53 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C190D9EC4D1; Mon, 3 Feb 2020 12:43:47 +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 7EDE465F5D; Mon, 3 Feb 2020 12:43:47 +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 2BF8D18095FF; Mon, 3 Feb 2020 12:43:47 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 013Chglg006083 for ; Mon, 3 Feb 2020 07:43:42 -0500 Received: by smtp.corp.redhat.com (Postfix) id 74137619E2; Mon, 3 Feb 2020 12:43:42 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-57.ams2.redhat.com [10.36.112.57]) by smtp.corp.redhat.com (Postfix) with ESMTP id 86FFA6CE60; Mon, 3 Feb 2020 12:43:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1580733838; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=J1Q9zJdsgVmogfZ5s5lqAMPAt/F5q/bmjFgafsZd1dQ=; b=BunPc4nacZD30eZOdWD4xR90V0uJsI8F27AthanojXbKyfiyR2jFZ5Jv8HVE/9KiCcuak4 w8niVVpNbARBV+3eLock06UuyvI6+nsXypWhX5bbgRdX8n2Gy1+PIgDVHnyXDKwhyoHSp2 9ZTXSjTMK/xBkMXXUE0gk6ur+8XIFFk= From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Subject: [libvirt PATCH 4/6] Modify close callback routines to handle local migration Date: Mon, 3 Feb 2020 12:43:31 +0000 Message-Id: <20200203124333.1925908-5-berrange@redhat.com> In-Reply-To: <20200203124333.1925908-1-berrange@redhat.com> References: <20200203124333.1925908-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Cc: Shaju Abraham 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-MC-Unique: zDteTxQTObSk4BGbZFem7w-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: Shaju Abraham At the time of registration, the close callback routines are inserted to a hash table using the UUID as index. Since UUID is unique in a host, a single hash entry is suffice to represent a domain object. But in the case of local migration, the UUID is shared between the source and destination VMs. This creates hash collision since both source and destination VMs are on same host. Inorder to uniquely identify the source and destination VMs , the domain id is appeneded to the UUID to generate a unique hash key. The routines are modified to handle the above change. Signed-off-by: Shaju Abraham --- src/util/virclosecallbacks.c | 48 +++++++++++++++++++++++++++--------- src/util/virclosecallbacks.h | 3 +++ 2 files changed, 39 insertions(+), 12 deletions(-) diff --git a/src/util/virclosecallbacks.c b/src/util/virclosecallbacks.c index 200577e18e..a8ab46d4d7 100644 --- a/src/util/virclosecallbacks.c +++ b/src/util/virclosecallbacks.c @@ -24,6 +24,7 @@ #include "virclosecallbacks.h" #include "virlog.h" #include "virobject.h" +#include "virstring.h" =20 #define VIR_FROM_THIS VIR_FROM_NONE =20 @@ -34,6 +35,7 @@ typedef virDriverCloseDef *virDriverCloseDefPtr; struct _virDriverCloseDef { virConnectPtr conn; virCloseCallback cb; + virDomainObjPtr vm; }; =20 struct _virCloseCallbacks { @@ -85,7 +87,6 @@ virCloseCallbacksDispose(void *obj) =20 virHashFree(closeCallbacks->list); } - int virCloseCallbacksSet(virCloseCallbacksPtr closeCallbacks, virDomainObjPtr vm, @@ -93,6 +94,7 @@ virCloseCallbacksSet(virCloseCallbacksPtr closeCallbacks, virCloseCallback cb) { char uuidstr[VIR_UUID_STRING_BUFLEN]; + char *uniqstr =3D NULL; virDriverCloseDefPtr closeDef; int ret =3D -1; =20 @@ -100,9 +102,10 @@ virCloseCallbacksSet(virCloseCallbacksPtr closeCallbac= ks, VIR_DEBUG("vm=3D%s, uuid=3D%s, conn=3D%p, cb=3D%p", vm->def->name, uuidstr, conn, cb); =20 + uniqstr =3D g_strdup_printf("%s%d", uuidstr, vm->def->id); virObjectLock(closeCallbacks); =20 - closeDef =3D virHashLookup(closeCallbacks->list, uuidstr); + closeDef =3D virHashLookup(closeCallbacks->list, uniqstr); if (closeDef) { if (closeDef->conn !=3D conn) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -125,7 +128,8 @@ virCloseCallbacksSet(virCloseCallbacksPtr closeCallback= s, =20 closeDef->conn =3D conn; closeDef->cb =3D cb; - if (virHashAddEntry(closeCallbacks->list, uuidstr, closeDef) < 0) { + closeDef->vm =3D vm; + if (virHashAddEntry(closeCallbacks->list, uniqstr, closeDef) < 0) { VIR_FREE(closeDef); goto cleanup; } @@ -145,6 +149,7 @@ virCloseCallbacksUnset(virCloseCallbacksPtr closeCallba= cks, virCloseCallback cb) { char uuidstr[VIR_UUID_STRING_BUFLEN]; + char *uniqstr =3D NULL; virDriverCloseDefPtr closeDef; int ret =3D -1; =20 @@ -152,9 +157,10 @@ virCloseCallbacksUnset(virCloseCallbacksPtr closeCallb= acks, VIR_DEBUG("vm=3D%s, uuid=3D%s, cb=3D%p", vm->def->name, uuidstr, cb); =20 + uniqstr =3D g_strdup_printf("%s%d", uuidstr, vm->def->id); virObjectLock(closeCallbacks); =20 - closeDef =3D virHashLookup(closeCallbacks->list, uuidstr); + closeDef =3D virHashLookup(closeCallbacks->list, uniqstr); if (!closeDef) goto cleanup; =20 @@ -165,7 +171,7 @@ virCloseCallbacksUnset(virCloseCallbacksPtr closeCallba= cks, goto cleanup; } =20 - if (virHashRemoveEntry(closeCallbacks->list, uuidstr) < 0) + if (virHashRemoveEntry(closeCallbacks->list, uniqstr) < 0) goto cleanup; =20 virObjectUnref(vm); @@ -183,16 +189,18 @@ virCloseCallbacksGet(virCloseCallbacksPtr closeCallba= cks, virConnectPtr conn) { char uuidstr[VIR_UUID_STRING_BUFLEN]; + char *uniqstr =3D NULL; virDriverCloseDefPtr closeDef; virCloseCallback cb =3D NULL; =20 virUUIDFormat(vm->def->uuid, uuidstr); VIR_DEBUG("vm=3D%s, uuid=3D%s, conn=3D%p", vm->def->name, uuidstr, conn); + uniqstr =3D g_strdup_printf("%s%d", uuidstr, vm->def->id); =20 virObjectLock(closeCallbacks); =20 - closeDef =3D virHashLookup(closeCallbacks->list, uuidstr); + closeDef =3D virHashLookup(closeCallbacks->list, uniqstr); if (closeDef && (!conn || closeDef->conn =3D=3D conn)) cb =3D closeDef->cb; =20 @@ -207,15 +215,17 @@ virCloseCallbacksGetConn(virCloseCallbacksPtr closeCa= llbacks, virDomainObjPtr vm) { char uuidstr[VIR_UUID_STRING_BUFLEN]; + char *uniqstr =3D NULL; virDriverCloseDefPtr closeDef; virConnectPtr conn =3D NULL; =20 virUUIDFormat(vm->def->uuid, uuidstr); VIR_DEBUG("vm=3D%s, uuid=3D%s", vm->def->name, uuidstr); =20 + uniqstr =3D g_strdup_printf("%s%d", uuidstr, vm->def->id); virObjectLock(closeCallbacks); =20 - closeDef =3D virHashLookup(closeCallbacks->list, uuidstr); + closeDef =3D virHashLookup(closeCallbacks->list, uniqstr); if (closeDef) conn =3D closeDef->conn; =20 @@ -231,6 +241,7 @@ typedef virCloseCallbacksListEntry *virCloseCallbacksLi= stEntryPtr; struct _virCloseCallbacksListEntry { unsigned char uuid[VIR_UUID_BUFLEN]; virCloseCallback callback; + virDomainObjPtr vm; }; =20 typedef struct _virCloseCallbacksList virCloseCallbacksList; @@ -274,6 +285,7 @@ virCloseCallbacksGetOne(void *payload, memcpy(data->list->entries[data->list->nentries - 1].uuid, uuid, VIR_UUID_BUFLEN); data->list->entries[data->list->nentries - 1].callback =3D closeDef->c= b; + data->list->entries[data->list->nentries - 1].vm =3D closeDef->vm; return 0; } =20 @@ -302,8 +314,18 @@ virCloseCallbacksGetForConn(virCloseCallbacksPtr close= Callbacks, =20 return list; } - - +virDomainObjPtr virGetMatchingDomain(virDomainObjListPtr domains, + unsigned char *uuidstr, virDomainObjP= tr dom) +{ + virDomainObjPtr vm =3D NULL; + vm =3D virDomainObjListFindByUUID(domains, uuidstr); + if (!vm || vm !=3D dom) { + vm =3D virDomainObjListFindByUUIDRemote(domains, uuidstr); + if (!vm || vm !=3D dom) + return NULL; + } + return vm; +} void virCloseCallbacksRun(virCloseCallbacksPtr closeCallbacks, virConnectPtr conn, @@ -329,8 +351,10 @@ virCloseCallbacksRun(virCloseCallbacksPtr closeCallbac= ks, =20 for (i =3D 0; i < list->nentries; i++) { char uuidstr[VIR_UUID_STRING_BUFLEN]; + char *uniqstr =3D NULL; virUUIDFormat(list->entries[i].uuid, uuidstr); - virHashRemoveEntry(closeCallbacks->list, uuidstr); + uniqstr =3D g_strdup_printf("%s%d", uuidstr, list->entries[i].vm->= def->id); + virHashRemoveEntry(closeCallbacks->list, uniqstr); } virObjectUnlock(closeCallbacks); =20 @@ -338,8 +362,8 @@ virCloseCallbacksRun(virCloseCallbacksPtr closeCallback= s, virDomainObjPtr vm; =20 /* Grab a ref and lock to the vm */ - if (!(vm =3D virDomainObjListFindByUUID(domains, - list->entries[i].uuid))) { + if (!(vm =3D virGetMatchingDomain(domains, + list->entries[i].uuid, list->entries[i].vm))) { char uuidstr[VIR_UUID_STRING_BUFLEN]; virUUIDFormat(list->entries[i].uuid, uuidstr); VIR_DEBUG("No domain object with UUID %s", uuidstr); diff --git a/src/util/virclosecallbacks.h b/src/util/virclosecallbacks.h index 98fc2c4a94..253ecab6bc 100644 --- a/src/util/virclosecallbacks.h +++ b/src/util/virclosecallbacks.h @@ -48,3 +48,6 @@ virCloseCallbacksRun(virCloseCallbacksPtr closeCallbacks, virConnectPtr conn, virDomainObjListPtr domains, void *opaque); + +virDomainObjPtr virGetMatchingDomain(virDomainObjListPtr domains, + unsigned char *uuidstr, virDomainObjP= tr dom); --=20 2.24.1 From nobody Wed Apr 24 16:56:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 1580733840968741.706195467662; Mon, 3 Feb 2020 04:44:00 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-224-_hn_Hd1YP6us7gjlVUInJg-1; Mon, 03 Feb 2020 07:43:57 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id C6280A18D3; Mon, 3 Feb 2020 12:43:51 +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 739F78B754; Mon, 3 Feb 2020 12:43:51 +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 248E31808878; Mon, 3 Feb 2020 12:43:51 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 013ChhCI006109 for ; Mon, 3 Feb 2020 07:43:43 -0500 Received: by smtp.corp.redhat.com (Postfix) id 98A0E6CE64; Mon, 3 Feb 2020 12:43:43 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-57.ams2.redhat.com [10.36.112.57]) by smtp.corp.redhat.com (Postfix) with ESMTP id B091C6E713; Mon, 3 Feb 2020 12:43:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1580733839; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=6owWO4bB508QMEhOsnwatRJ+UtsPUPieDoJbA0H088M=; b=ZucVEyAT3T9cq62m3opEW/gmOmVH0U/jifBrv05dx7kNA9xsxm9Uunz715eo7KbcP/eWSs 6ZL3Q3gB/fiqYmpWxv4lqE+bdLh73CC7b6ZSXSFAOKF2xDhKkITYUTEwjMgp00yM2a4IbY hsEPDWzkyZ+RbfR2QxIiGYuh9A+aQR0= From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Subject: [libvirt PATCH 5/6] Make PATHs unique for a VM object instance Date: Mon, 3 Feb 2020 12:43:32 +0000 Message-Id: <20200203124333.1925908-6-berrange@redhat.com> In-Reply-To: <20200203124333.1925908-1-berrange@redhat.com> References: <20200203124333.1925908-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Cc: Shaju Abraham 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: , 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-MC-Unique: _hn_Hd1YP6us7gjlVUInJg-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: Shaju Abraham There are various config paths that a VM uses. The monitor paths and other lib paths are examples. These paths are tied to the VM name or UUID. The local migration breaks the assumption that there will be only one VM with a unique UUID and name. During local migrations there can be multiple VMs with same name and UUID in the same host. Append the domain-id field to the path so that there is no duplication of path names. Signed-off-by: Shaju Abraham --- src/qemu/qemu_conf.c | 4 ++-- src/qemu/qemu_domain.c | 16 ++++++++++------ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index 00801ef01b..6769736d58 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -1894,7 +1894,7 @@ qemuGetDomainHugepagePath(const virDomainDef *def, char *ret =3D NULL; =20 if (base && domPath) - ret =3D g_strdup_printf("%s/%s", base, domPath); + ret =3D g_strdup_printf("%s/%s-%d", base, domPath, def->id); return ret; } =20 @@ -1962,7 +1962,7 @@ qemuGetMemoryBackingDomainPath(const virDomainDef *de= f, return -1; =20 qemuGetMemoryBackingBasePath(cfg, &base); - *path =3D g_strdup_printf("%s/%s", base, shortName); + *path =3D g_strdup_printf("%s/%s-%d", base, shortName, def->id); =20 return 0; } diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index b0c0e1a19b..002c092cf8 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -2127,11 +2127,13 @@ qemuDomainSetPrivatePathsOld(virQEMUDriverPtr drive= r, virQEMUDriverConfigPtr cfg =3D virQEMUDriverGetConfig(driver); =20 if (!priv->libDir) - priv->libDir =3D g_strdup_printf("%s/domain-%s", cfg->libDir, vm->= def->name); + priv->libDir =3D g_strdup_printf("%s/domain-%s-%d", cfg->libDir, + vm->def->name, vm->def->id); =20 if (!priv->channelTargetDir) - priv->channelTargetDir =3D g_strdup_printf("%s/domain-%s", - cfg->channelTargetDir, vm= ->def->name); + priv->channelTargetDir =3D g_strdup_printf("%s/domain-%s-%d", + cfg->channelTargetDir, + vm->def->name, vm->def->i= d); =20 virObjectUnref(cfg); } @@ -2150,11 +2152,13 @@ qemuDomainSetPrivatePaths(virQEMUDriverPtr driver, goto cleanup; =20 if (!priv->libDir) - priv->libDir =3D g_strdup_printf("%s/domain-%s", cfg->libDir, domn= ame); + priv->libDir =3D g_strdup_printf("%s/domain-%s-%d", cfg->libDir, d= omname, + vm->def->id); =20 if (!priv->channelTargetDir) - priv->channelTargetDir =3D g_strdup_printf("%s/domain-%s", - cfg->channelTargetDir, do= mname); + priv->channelTargetDir =3D g_strdup_printf("%s/domain-%s-%d", + cfg->channelTargetDir, + domname, vm->def->id); =20 ret =3D 0; cleanup: --=20 2.24.1 From nobody Wed Apr 24 16:56:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 1580733838571387.339267302901; Mon, 3 Feb 2020 04:43:58 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-330-L9U1-GcNOxaCoW37WVYhzQ-1; Mon, 03 Feb 2020 07:43:54 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id E18DF1166506; Mon, 3 Feb 2020 12:43:48 +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 9416F8B744; Mon, 3 Feb 2020 12:43:48 +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 3717B8174A; Mon, 3 Feb 2020 12:43:48 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 013ChjF6006115 for ; Mon, 3 Feb 2020 07:43:45 -0500 Received: by smtp.corp.redhat.com (Postfix) id 2D432610E0; Mon, 3 Feb 2020 12:43:45 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-57.ams2.redhat.com [10.36.112.57]) by smtp.corp.redhat.com (Postfix) with ESMTP id E161E6B49E; Mon, 3 Feb 2020 12:43:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1580733837; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=epww4QlWucLpN0EZri0NudC+gPshVZ0eERZ2Ev/O1ns=; b=JEvqdpXla6gVsSw1+LEwutTtlIg+tZmiKiTTPX3FBrKpzHRnyuZCzauAPDn1EV2IdwN8QG FCZwO+c3Kb/4mblW7aFrmuiPcrChuw0hH7Hf0+6EQjvqJrZtEFAfTiMy+ASe2H7IcBhFZc 4PwOLxEMeutT20TYhec7DXxCqpfCp+0= From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Subject: [libvirt PATCH 6/6] Move the domain object from remote to source hash table Date: Mon, 3 Feb 2020 12:43:33 +0000 Message-Id: <20200203124333.1925908-7-berrange@redhat.com> In-Reply-To: <20200203124333.1925908-1-berrange@redhat.com> References: <20200203124333.1925908-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Cc: Shaju Abraham 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: , 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-MC-Unique: L9U1-GcNOxaCoW37WVYhzQ-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: Shaju Abraham After the confirm phase Libvirt domain objects should only be on the source hash table. Move the remote hash table entry corresponding to the migrated VM to the source hash table. Delete the moved entries from remote hash table. Signed-off-by: Shaju Abraham --- src/qemu/qemu_domain.c | 12 +++++++++- src/qemu/qemu_domain.h | 2 ++ src/qemu/qemu_driver.c | 46 ++++++++++++++++++++++++++++++++++----- src/qemu/qemu_migration.c | 13 +++++++++++ src/qemu/qemu_migration.h | 4 ++++ 5 files changed, 71 insertions(+), 6 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 002c092cf8..cbf779e9eb 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -16570,7 +16570,17 @@ qemuDomainRunningReasonToResumeEvent(virDomainRunn= ingReason reason) =20 return VIR_DOMAIN_EVENT_RESUMED_UNPAUSED; } - +int +qemuDomainInsertMigrateVMRef(virQEMUDriverPtr driver, + virDomainObjPtr remote_vm) +{ + if (virDomainObjListRemoveRemote(driver->domains, remote_vm) < 0) + return -1; + if (virDomainObjListAddEntry(driver->domains, remote_vm) < 0) + return -1; + else + return 0; +} =20 /* qemuDomainIsUsingNoShutdown: * @priv: Domain private data diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h index c581b3a162..caf8b2a8a5 100644 --- a/src/qemu/qemu_domain.h +++ b/src/qemu/qemu_domain.h @@ -828,6 +828,8 @@ void qemuDomainRemoveInactiveJob(virQEMUDriverPtr drive= r, =20 void qemuDomainRemoveInactiveJobLocked(virQEMUDriverPtr driver, virDomainObjPtr vm); +int qemuDomainInsertMigrateVMRef(virQEMUDriverPtr driver, + virDomainObjPtr vm); =20 void qemuDomainSetFakeReboot(virQEMUDriverPtr driver, virDomainObjPtr vm, diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 3e6d14ead8..df639b5299 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -152,6 +152,33 @@ static int qemuOpenFileAs(uid_t fallback_uid, gid_t fa= llback_gid, bool *needUnlink); =20 static virQEMUDriverPtr qemu_driver; +/** + * qemuDomObjFromDomainRemote: + * @domain: Domain pointer that has to be looked up + * + * This function looks up @domain and returns the appropriate virDomainObj= Ptr + * that has to be released by calling virDomainObjEndAPI(). + * + * Returns the domain object with incremented reference counter which is l= ocked + * on success, NULL otherwise. + */ +static virDomainObjPtr +qemuDomObjFromDomainRemote(virDomainPtr domain) +{ + virDomainObjPtr vm; + virQEMUDriverPtr driver =3D domain->conn->privateData; + char uuidstr[VIR_UUID_STRING_BUFLEN]; + + vm =3D virDomainObjListFindByUUIDRemote(driver->domains, domain->uuid); + if (!vm) { + virUUIDFormat(domain->uuid, uuidstr); + virReportError(VIR_ERR_NO_DOMAIN, + _("no domain with matching uuid '%s' (%s)"), + uuidstr, domain->name); + return NULL; + } + return vm; +} =20 /* Looks up the domain object from snapshot and unlocks the * driver. The returned domain object is locked and ref'd and the @@ -13188,8 +13215,10 @@ qemuDomainMigrateFinish3Params(virConnectPtr dconn, virReportError(VIR_ERR_NO_DOMAIN, "%s", _("missing domain name")); return NULL; } - - vm =3D virDomainObjListFindByName(driver->domains, dname); + if (flags & VIR_MIGRATE_LOCAL) + vm =3D virDomainObjListFindByNameRemote(driver->domains, dname); + else + vm =3D virDomainObjListFindByName(driver->domains, dname); if (!vm) { virReportError(VIR_ERR_NO_DOMAIN, _("no domain with matching name '%s'"), dname); @@ -13241,7 +13270,8 @@ qemuDomainMigrateConfirm3Params(virDomainPtr domain, unsigned int flags, int cancelled) { - virDomainObjPtr vm; + virDomainObjPtr vm, remote_vm; + int ret =3D 0; =20 virCheckFlags(QEMU_MIGRATION_FLAGS, -1); =20 @@ -13250,14 +13280,20 @@ qemuDomainMigrateConfirm3Params(virDomainPtr doma= in, =20 if (!(vm =3D qemuDomainObjFromDomain(domain))) return -1; + if (!(remote_vm =3D qemuDomObjFromDomainRemote(domain))) + return -1; =20 if (virDomainMigrateConfirm3ParamsEnsureACL(domain->conn, vm->def) < 0= ) { virDomainObjEndAPI(&vm); return -1; } - - return qemuMigrationSrcConfirm(domain->conn->privateData, vm, cookiein= , cookieinlen, + ret =3D qemuMigrationSrcConfirm(domain->conn->privateData, vm, cookiei= n, cookieinlen, flags, cancelled); + if (ret < 0) + return ret; + ret =3D qemuMigrationSrcMergeHashTables(domain->conn->privateData, + remote_vm, flags); + return ret; } =20 =20 diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c index d22daeac9c..45403d361e 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -3092,6 +3092,19 @@ qemuMigrationSrcConfirm(virQEMUDriverPtr driver, virObjectUnref(cfg); return ret; } +int qemuMigrationSrcMergeHashTables(virQEMUDriverPtr driver, + virDomainObjPtr vm, + unsigned int flags) +{ + int ret =3D 0; + if (!(flags & VIR_MIGRATE_LOCAL)) + return ret; + ret =3D qemuDomainInsertMigrateVMRef(driver, vm); + if (ret < 0) + return ret; + qemuDomainSaveStatus(vm); + return ret; +} =20 =20 enum qemuMigrationDestinationType { diff --git a/src/qemu/qemu_migration.h b/src/qemu/qemu_migration.h index 2cb4bb9023..f6d67e3997 100644 --- a/src/qemu/qemu_migration.h +++ b/src/qemu/qemu_migration.h @@ -256,3 +256,7 @@ qemuMigrationSrcFetchMirrorStats(virQEMUDriverPtr drive= r, virDomainObjPtr vm, qemuDomainAsyncJob asyncJob, qemuDomainJobInfoPtr jobInfo); + +int qemuMigrationSrcMergeHashTables(virQEMUDriverPtr driver, + virDomainObjPtr vm, + unsigned int flags); --=20 2.24.1