qemu: domain: Store and update 'fdsetindex' across libvirtd restarts

While 'add-fd' qmp command gives the possibility to find an unused fdset
ID when hot-adding fdsets, such usage is extremely inconvenient.

This patch allows us to track the used fdset id so that we can avoid the
need to check results and thus employ simpler code flow when hot-adding
devices which use FD passing.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Peter Krempa 2022-05-05 15:45:55 +02:00
parent 76709d4f48
commit 278c630d2a
14 changed files with 49 additions and 1 deletions

View File

@ -2372,6 +2372,8 @@ qemuDomainObjPrivateXMLFormat(virBuffer *buf,
if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCKDEV))
virBufferAsprintf(buf, "<nodename index='%llu'/>\n", priv->nodenameindex);
virBufferAsprintf(buf, "<fdset index='%u'/>\n", priv->fdsetindex);
if (priv->memPrealloc)
virBufferAddLit(buf, "<memPrealloc/>\n");
@ -3106,6 +3108,9 @@ qemuDomainObjPrivateXMLParse(xmlXPathContextPtr ctxt,
return -1;
}
if (virXPathUInt("string(./fdset/@index)", ctxt, &priv->fdsetindex) == 0)
priv->fdsetindexParsed = true;
priv->memPrealloc = virXPathBoolean("boolean(./memPrealloc)", ctxt) == 1;
if (virXPathULongLong("string(./originalMemlock)",

View File

@ -204,8 +204,9 @@ struct _qemuDomainObjPrivate {
/* counter for generating node names for qemu disks */
unsigned long long nodenameindex;
/* counter for generating IDs of fdsets - only relevant during startup */
/* counter for generating IDs of fdsets */
unsigned int fdsetindex;
bool fdsetindexParsed;
/* qemuProcessStartCPUs stores the reason for starting vCPUs here for the
* RESUME event handler to use it */

View File

@ -2265,6 +2265,34 @@ qemuRefreshPRManagerState(virQEMUDriver *driver,
}
static int
qemuProcessRefreshFdsetIndex(virDomainObj *vm)
{
qemuDomainObjPrivate *priv = vm->privateData;
g_autoptr(qemuMonitorFdsets) fdsets = NULL;
size_t i;
int rc;
/* if the previous index was in the status XML we don't need to update it */
if (priv->fdsetindexParsed)
return 0;
qemuDomainObjEnterMonitor(priv->driver, vm);
rc = qemuMonitorQueryFdsets(priv->mon, &fdsets);
qemuDomainObjExitMonitor(vm);
if (rc < 0)
return -1;
for (i = 0; i < fdsets->nfdsets; i++) {
if (fdsets->fdsets[i].id >= priv->fdsetindex)
priv->fdsetindex = fdsets->fdsets[i].id + 1;
}
return 0;
}
static void
qemuRefreshRTC(virQEMUDriver *driver,
virDomainObj *vm)
@ -8928,6 +8956,9 @@ qemuProcessReconnect(void *opaque)
if (qemuRefreshPRManagerState(driver, obj) < 0)
goto error;
if (qemuProcessRefreshFdsetIndex(obj) < 0)
goto error;
qemuProcessReconnectCheckMemAliasOrderMismatch(obj);
if (qemuConnectAgent(driver, obj) < 0)

View File

@ -234,6 +234,7 @@
<chardevStdioLogd/>
<allowReboot value='yes'/>
<nodename index='0'/>
<fdset index='0'/>
<blockjobs active='yes'>
<blockjob name='backup-vda-libvirt-3-format' type='backup' state='running' jobflags='0x0'>
<disk dst='vda'/>

View File

@ -233,6 +233,7 @@
<chardevStdioLogd/>
<allowReboot value='yes'/>
<nodename index='0'/>
<fdset index='0'/>
<blockjobs active='yes'>
<blockjob name='broken-test' type='broken' state='ready' brokentype='commit'/>
<blockjob name='commit-vdc-libvirt-9-format' type='commit' state='running' jobflags='0x0'>

View File

@ -22,6 +22,7 @@
<libDir path='/tmp'/>
<channelTargetDir path='/tmp/channel'/>
<allowReboot value='yes'/>
<fdset index='0'/>
<blockjobs active='yes'/>
<agentTimeout>-2</agentTimeout>
<domain type='qemu' id='1'>

View File

@ -256,6 +256,7 @@
<channelTargetDir path='/var/lib/libvirt/qemu/channel/target/domain-1-nest'/>
<chardevStdioLogd/>
<allowReboot value='yes'/>
<fdset index='0'/>
<blockjobs active='no'/>
<agentTimeout>-2</agentTimeout>
<domain type='kvm' id='1'>

View File

@ -343,6 +343,7 @@
<rememberOwner/>
<allowReboot value='yes'/>
<nodename index='3'/>
<fdset index='0'/>
<blockjobs active='yes'>
<blockjob name='drive-virtio-disk0' type='copy' state='ready' jobflags='0x0'>
<disk dst='vda'/>

View File

@ -259,6 +259,7 @@
<channelTargetDir path='/var/lib/libvirt/qemu/channel/target/domain-4-upstream'/>
<chardevStdioLogd/>
<allowReboot value='yes'/>
<fdset index='0'/>
<blockjobs active='no'/>
<agentTimeout>-2</agentTimeout>
<domain type='kvm' id='4'>

View File

@ -288,6 +288,7 @@
<channelTargetDir path='/var/lib/libvirt/qemu/channel/target/domain-3-upstream'/>
<chardevStdioLogd/>
<allowReboot value='yes'/>
<fdset index='0'/>
<blockjobs active='no'/>
<agentTimeout>-2</agentTimeout>
<domain type='kvm' id='3'>

View File

@ -270,6 +270,7 @@
<channelTargetDir path='/var/lib/libvirt/qemu/channel/target/domain-7-nest'/>
<chardevStdioLogd/>
<allowReboot value='yes'/>
<fdset index='0'/>
<blockjobs active='no'/>
<agentTimeout>-2</agentTimeout>
<domain type='kvm' id='7'>

View File

@ -261,6 +261,7 @@
<chardevStdioLogd/>
<allowReboot value='yes'/>
<nodename index='123'/>
<fdset index='321'/>
<blockjobs active='no'/>
<agentTimeout>-2</agentTimeout>
<domain type='kvm' id='1'>

View File

@ -258,6 +258,7 @@
<channelTargetDir path='/var/lib/libvirt/qemu/channel/target/domain-1-upstream'/>
<chardevStdioLogd/>
<allowReboot value='yes'/>
<fdset index='0'/>
<blockjobs active='no'/>
<agentTimeout>-2</agentTimeout>
<domain type='kvm' id='1'>

View File

@ -308,6 +308,7 @@
<libDir path='/tmp'/>
<channelTargetDir path='/tmp/channel'/>
<allowReboot value='yes'/>
<fdset index='0'/>
<blockjobs active='no'/>
<agentTimeout>-2</agentTimeout>
<domain type='kvm' id='1729'>