Skip to content

Commit

Permalink
migration: Send auto-num-queues capability in migratoin cookie
Browse files Browse the repository at this point in the history
auto-num-queues need to be sent to ensure the same num-queues
of virtio-blk device would be allocated on the destination.

Signed-off-by: Hyman Huang(黄勇) <yong.huang@smartx.com>
  • Loading branch information
HuangSuiXiao committed Aug 5, 2023
1 parent f546972 commit 5ee19c8
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/qemu/qemu_migration.c
Original file line number Diff line number Diff line change
Expand Up @@ -2501,6 +2501,10 @@ qemuMigrationSrcBeginXML(virDomainObj *vm,
if (!(flags & VIR_MIGRATE_OFFLINE))
cookieFlags |= QEMU_MIGRATION_COOKIE_CAPS;

if (virQEMUCapsGet(priv->qemuCaps,
QEMU_CAPS_VIRTIO_BLK_AUTO_NUM_QUEUES))
cookieFlags |= QEMU_MIGRATION_COOKIE_AUTO_NUM_QUEUES_CAP;

if (!(mig = qemuMigrationCookieNew(vm->def, priv->origname)))
return NULL;

Expand Down Expand Up @@ -3336,7 +3340,8 @@ qemuMigrationDstPrepareFresh(virQEMUDriver *driver,
QEMU_MIGRATION_COOKIE_CPU_HOTPLUG |
QEMU_MIGRATION_COOKIE_CPU |
QEMU_MIGRATION_COOKIE_CAPS |
QEMU_MIGRATION_COOKIE_BLOCK_DIRTY_BITMAPS)))
QEMU_MIGRATION_COOKIE_BLOCK_DIRTY_BITMAPS |
QEMU_MIGRATION_COOKIE_AUTO_NUM_QUEUES_CAP)))
goto cleanup;

if (!(vm = virDomainObjListAdd(driver->domains, def,
Expand Down Expand Up @@ -4784,7 +4789,8 @@ qemuMigrationSrcRun(virQEMUDriver *driver,
cookieFlags |
QEMU_MIGRATION_COOKIE_GRAPHICS |
QEMU_MIGRATION_COOKIE_CAPS |
QEMU_MIGRATION_COOKIE_BLOCK_DIRTY_BITMAPS);
QEMU_MIGRATION_COOKIE_BLOCK_DIRTY_BITMAPS |
QEMU_MIGRATION_COOKIE_AUTO_NUM_QUEUES_CAP);
if (!mig)
goto error;

Expand Down
56 changes: 56 additions & 0 deletions src/qemu/qemu_migration_cookie.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ VIR_ENUM_IMPL(qemuMigrationCookieFlag,
"allowReboot",
"capabilities",
"block-dirty-bitmaps",
"auto-num-queues-cap",
);


Expand Down Expand Up @@ -575,6 +576,21 @@ qemuMigrationCookieAddCaps(qemuMigrationCookie *mig,
return 0;
}

static void
qemuMigrationCookieAddAutoNumQueues(qemuMigrationCookie *mig,
virDomainObj *vm)
{
qemuDomainObjPrivate *priv = vm->privateData;

/* Only if auto-num-queues capability is not present on source
* side, set the disable_auto_num_queues to true; false otherwise.
* */
if (!virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_VIRTIO_BLK_AUTO_NUM_QUEUES)) {
mig->disable_auto_num_queues = true;
}

mig->flags |= QEMU_MIGRATION_COOKIE_AUTO_NUM_QUEUES_CAP;
}

static void
qemuMigrationCookieGraphicsXMLFormat(virBuffer *buf,
Expand Down Expand Up @@ -820,6 +836,15 @@ qemuMigrationCookieBlockDirtyBitmapsFormat(virBuffer *buf,
}


static void
qemuMigrationCookieAutoNumQueuesXMLFormat(virBuffer *buf,
virTristateBool disable_auto_num_queues)
{
virBufferAsprintf(buf, "<disable_auto_num_queues value='%s'/>\n",
virTristateBoolTypeToString(disable_auto_num_queues));
}


int
qemuMigrationCookieXMLFormat(virQEMUDriver *driver,
virQEMUCaps *qemuCaps,
Expand Down Expand Up @@ -891,6 +916,10 @@ qemuMigrationCookieXMLFormat(virQEMUDriver *driver,
if (mig->flags & QEMU_MIGRATION_COOKIE_BLOCK_DIRTY_BITMAPS)
qemuMigrationCookieBlockDirtyBitmapsFormat(buf, mig->blockDirtyBitmaps);

if (mig->flags & QEMU_MIGRATION_COOKIE_AUTO_NUM_QUEUES_CAP) {
qemuMigrationCookieAutoNumQueuesXMLFormat(buf, mig->disable_auto_num_queues);
}

virBufferAdjustIndent(buf, -2);
virBufferAddLit(buf, "</qemu-migration>\n");
return 0;
Expand Down Expand Up @@ -1254,6 +1283,26 @@ qemuMigrationCookieBlockDirtyBitmapsParse(xmlXPathContextPtr ctxt,
}


static int
qemuMigrationCookieAutoNumQueuesCapXMLParse(xmlXPathContextPtr ctxt,
virTristateBool *disable_auto_num_queues)
{
int val;
g_autofree char *valStr = NULL;

if ((valStr = virXPathString("string(./disable_auto_num_queues/@value)", ctxt))) {
if ((val = virTristateBoolTypeFromString(valStr)) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("invalid disable_auto_num_queues value '%1$s'"), valStr);
return -1;
}
*disable_auto_num_queues = val;
}

return 0;
}


static int
qemuMigrationCookieXMLParse(qemuMigrationCookie *mig,
virQEMUDriver *driver,
Expand Down Expand Up @@ -1400,6 +1449,10 @@ qemuMigrationCookieXMLParse(qemuMigrationCookie *mig,
qemuMigrationCookieBlockDirtyBitmapsParse(ctxt, mig) < 0)
return -1;

if (flags & QEMU_MIGRATION_COOKIE_AUTO_NUM_QUEUES_CAP &&
qemuMigrationCookieAutoNumQueuesCapXMLParse(ctxt, &mig->disable_auto_num_queues) < 0)
return -1;

return 0;
}

Expand Down Expand Up @@ -1475,6 +1528,9 @@ qemuMigrationCookieFormat(qemuMigrationCookie *mig,
qemuMigrationCookieAddCaps(mig, dom, party) < 0)
return -1;

if (flags & QEMU_MIGRATION_COOKIE_AUTO_NUM_QUEUES_CAP)
qemuMigrationCookieAddAutoNumQueues(mig, dom);

if (qemuMigrationCookieXMLFormat(driver, priv->qemuCaps, &buf, mig) < 0)
return -1;

Expand Down
5 changes: 5 additions & 0 deletions src/qemu/qemu_migration_cookie.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ typedef enum {
QEMU_MIGRATION_COOKIE_FLAG_ALLOW_REBOOT,
QEMU_MIGRATION_COOKIE_FLAG_CAPS,
QEMU_MIGRATION_COOKIE_FLAG_BLOCK_DIRTY_BITMAPS,
QEMU_MIGRATION_COOKIE_FLAG_AUTO_NUM_QUEUES_CAP,

QEMU_MIGRATION_COOKIE_FLAG_LAST
} qemuMigrationCookieFlags;
Expand All @@ -53,6 +54,7 @@ typedef enum {
QEMU_MIGRATION_COOKIE_CPU = (1 << QEMU_MIGRATION_COOKIE_FLAG_CPU),
QEMU_MIGRATION_COOKIE_CAPS = (1 << QEMU_MIGRATION_COOKIE_FLAG_CAPS),
QEMU_MIGRATION_COOKIE_BLOCK_DIRTY_BITMAPS = (1 << QEMU_MIGRATION_COOKIE_FLAG_BLOCK_DIRTY_BITMAPS),
QEMU_MIGRATION_COOKIE_AUTO_NUM_QUEUES_CAP = (1 << QEMU_MIGRATION_COOKIE_FLAG_AUTO_NUM_QUEUES_CAP),
} qemuMigrationCookieFeatures;

typedef struct _qemuMigrationCookieGraphics qemuMigrationCookieGraphics;
Expand Down Expand Up @@ -171,6 +173,9 @@ struct _qemuMigrationCookie {

/* If flags & QEMU_MIGRATION_COOKIE_BLOCK_DIRTY_BITMAPS */
GSList *blockDirtyBitmaps;

/* If flags & QEMU_MIGRATION_COOKIE_AUTO_NUM_QUEUES_CAP */
virTristateBool disable_auto_num_queues;
};


Expand Down

0 comments on commit 5ee19c8

Please sign in to comment.