mirror of
https://github.com/Motorhead1991/qemu.git
synced 2026-02-11 19:39:26 -07:00
migration: cpr_get_fd_param helper
Add the helper function cpr_get_fd_param, to use when preserving a file descriptor that is opened externally and passed to QEMU. cpr_get_fd_param returns a descriptor number either from a QEMU command-line parameter, from a getfd command, or from CPR state. When a descriptor is passed to new QEMU via SCM_RIGHTS, its number changes. Hence, during CPR, the command-line parameter is ignored in new QEMU, and over-ridden by the value found in CPR state. Similarly, if the descriptor was originally specified by a getfd command in old QEMU, the fd number is not known outside of QEMU, and it changes when sent to new QEMU via SCM_RIGHTS. Hence the user cannot send getfd to new QEMU, but when the user sends a hotplug command that references the fd, cpr_get_fd_param finds its value in CPR state. Signed-off-by: Steve Sistare <steven.sistare@oracle.com> Reviewed-by: Fabiano Rosas <farosas@suse.de> Link: https://lore.kernel.org/qemu-devel/1751493538-202042-5-git-send-email-steven.sistare@oracle.com Signed-off-by: Cédric Le Goater <clg@redhat.com>
This commit is contained in:
parent
7ed0919119
commit
ccfc6715cf
2 changed files with 39 additions and 0 deletions
|
|
@ -32,6 +32,8 @@ void cpr_state_close(void);
|
|||
struct QIOChannel *cpr_state_ioc(void);
|
||||
|
||||
bool cpr_incoming_needed(void *opaque);
|
||||
int cpr_get_fd_param(const char *name, const char *fdname, int index,
|
||||
Error **errp);
|
||||
|
||||
QEMUFile *cpr_transfer_output(MigrationChannel *channel, Error **errp);
|
||||
QEMUFile *cpr_transfer_input(MigrationChannel *channel, Error **errp);
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@
|
|||
#include "migration/qemu-file.h"
|
||||
#include "migration/savevm.h"
|
||||
#include "migration/vmstate.h"
|
||||
#include "monitor/monitor.h"
|
||||
#include "system/runstate.h"
|
||||
#include "trace.h"
|
||||
|
||||
|
|
@ -264,3 +265,39 @@ bool cpr_incoming_needed(void *opaque)
|
|||
MigMode mode = migrate_mode();
|
||||
return mode == MIG_MODE_CPR_TRANSFER;
|
||||
}
|
||||
|
||||
/*
|
||||
* cpr_get_fd_param: find a descriptor and return its value.
|
||||
*
|
||||
* @name: CPR name for the descriptor
|
||||
* @fdname: An integer-valued string, or a name passed to a getfd command
|
||||
* @index: CPR index of the descriptor
|
||||
* @errp: returned error message
|
||||
*
|
||||
* If CPR is not being performed, then use @fdname to find the fd.
|
||||
* If CPR is being performed, then ignore @fdname, and look for @name
|
||||
* and @index in CPR state.
|
||||
*
|
||||
* On success returns the fd value, else returns -1.
|
||||
*/
|
||||
int cpr_get_fd_param(const char *name, const char *fdname, int index,
|
||||
Error **errp)
|
||||
{
|
||||
ERRP_GUARD();
|
||||
int fd;
|
||||
|
||||
if (cpr_is_incoming()) {
|
||||
fd = cpr_find_fd(name, index);
|
||||
if (fd < 0) {
|
||||
error_setg(errp, "cannot find saved value for fd %s", fdname);
|
||||
}
|
||||
} else {
|
||||
fd = monitor_fd_param(monitor_cur(), fdname, errp);
|
||||
if (fd >= 0) {
|
||||
cpr_save_fd(name, index, fd);
|
||||
} else {
|
||||
error_prepend(errp, "Could not parse object fd %s:", fdname);
|
||||
}
|
||||
}
|
||||
return fd;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue