1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-03-20 07:59:00 +00:00

qemu: introduce qemuBuildFDSet

An alternative to qemuVirCommandGetFDSet that takes the index
into the passed FD set as an argument and does not try to look it up.

Use it as well ass virCommandPassFDIndex in qemuBuildChrChardevFileStr
and qemuBuildInterfaceCommandLine.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
This commit is contained in:
Ján Tomko 2020-11-24 14:42:58 +01:00
parent 49c66026cf
commit 9a20d8ac07

View File

@ -224,6 +224,23 @@ qemuBuildMasterKeyCommandLine(virCommandPtr cmd,
}
/**
* qemuBuildFDSet:
* @fd: fd to reassign to the child
* @idx: index in the fd set
*
* Format the parameters for the -add-fd command line option
* for the given file descriptor. The file descriptor must previously
* have been 'transferred' in a virCommandPassFDIndex() call,
* and @idx is the value returned by that call.
*/
static char *
qemuBuildFDSet(int fd, size_t idx)
{
return g_strdup_printf("set=%zu,fd=%d", idx, fd);
}
/**
* qemuVirCommandGetFDSet:
* @cmd: the command to modify
@ -4614,6 +4631,7 @@ qemuBuildChrChardevFileStr(virLogManagerPtr logManager,
g_autofree char *fdpath = NULL;
int flags = 0;
int logfd;
size_t idx;
if (appendval == VIR_TRISTATE_SWITCH_ABSENT ||
appendval == VIR_TRISTATE_SWITCH_OFF)
@ -4628,9 +4646,8 @@ qemuBuildChrChardevFileStr(virLogManagerPtr logManager,
NULL, NULL)) < 0)
return -1;
virCommandPassFD(cmd, logfd, VIR_COMMAND_PASS_FD_CLOSE_PARENT);
if (!(fdset = qemuVirCommandGetFDSet(cmd, logfd)))
return -1;
virCommandPassFDIndex(cmd, logfd, VIR_COMMAND_PASS_FD_CLOSE_PARENT, &idx);
fdset = qemuBuildFDSet(logfd, idx);
virCommandAddArg(cmd, "-add-fd");
virCommandAddArg(cmd, fdset);
@ -8183,11 +8200,10 @@ qemuBuildInterfaceCommandLine(virQEMUDriverPtr driver,
if (vdpafd > 0) {
g_autofree char *fdset = NULL;
g_autofree char *addfdarg = NULL;
size_t idx;
virCommandPassFD(cmd, vdpafd, VIR_COMMAND_PASS_FD_CLOSE_PARENT);
fdset = qemuVirCommandGetFDSet(cmd, vdpafd);
if (!fdset)
goto cleanup;
virCommandPassFDIndex(cmd, vdpafd, VIR_COMMAND_PASS_FD_CLOSE_PARENT, &idx);
fdset = qemuBuildFDSet(vdpafd, idx);
vdpafdName = qemuVirCommandGetDevSet(cmd, vdpafd);
/* set opaque to the devicepath so that we can look up the fdset later
* if necessary */