mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-11 07:17:44 +00:00
qemuProcessStart: Switch to flags instead of bunch booleans
Currently, we have 3 boolean arguments we have to pass to qemuProcessStart(). As libvirt grows it is harder and harder to remember them and their position. Therefore we should switch to flags instead.
This commit is contained in:
parent
794d6b1dc0
commit
63ddc65d63
@ -1351,10 +1351,16 @@ static virDomainPtr qemudDomainCreate(virConnectPtr conn, const char *xml,
|
|||||||
virDomainPtr dom = NULL;
|
virDomainPtr dom = NULL;
|
||||||
virDomainEventPtr event = NULL;
|
virDomainEventPtr event = NULL;
|
||||||
virDomainEventPtr event2 = NULL;
|
virDomainEventPtr event2 = NULL;
|
||||||
|
unsigned int start_flags = VIR_QEMU_PROCESS_START_COLD;
|
||||||
|
|
||||||
virCheckFlags(VIR_DOMAIN_START_PAUSED |
|
virCheckFlags(VIR_DOMAIN_START_PAUSED |
|
||||||
VIR_DOMAIN_START_AUTODESTROY, NULL);
|
VIR_DOMAIN_START_AUTODESTROY, NULL);
|
||||||
|
|
||||||
|
if (flags & VIR_DOMAIN_START_PAUSED)
|
||||||
|
start_flags |= VIR_QEMU_PROCESS_START_PAUSED;
|
||||||
|
if (flags & VIR_DOMAIN_START_AUTODESTROY)
|
||||||
|
start_flags |= VIR_QEMU_PROCESS_START_AUTODESROY;
|
||||||
|
|
||||||
qemuDriverLock(driver);
|
qemuDriverLock(driver);
|
||||||
if (!(def = virDomainDefParseString(driver->caps, xml,
|
if (!(def = virDomainDefParseString(driver->caps, xml,
|
||||||
QEMU_EXPECTED_VIRT_TYPES,
|
QEMU_EXPECTED_VIRT_TYPES,
|
||||||
@ -1383,10 +1389,9 @@ static virDomainPtr qemudDomainCreate(virConnectPtr conn, const char *xml,
|
|||||||
if (qemuDomainObjBeginJobWithDriver(driver, vm, QEMU_JOB_MODIFY) < 0)
|
if (qemuDomainObjBeginJobWithDriver(driver, vm, QEMU_JOB_MODIFY) < 0)
|
||||||
goto cleanup; /* XXXX free the 'vm' we created ? */
|
goto cleanup; /* XXXX free the 'vm' we created ? */
|
||||||
|
|
||||||
if (qemuProcessStart(conn, driver, vm, NULL, true,
|
if (qemuProcessStart(conn, driver, vm, NULL, -1, NULL, NULL,
|
||||||
(flags & VIR_DOMAIN_START_PAUSED) != 0,
|
VIR_NETDEV_VPORT_PROFILE_OP_CREATE,
|
||||||
(flags & VIR_DOMAIN_START_AUTODESTROY) != 0,
|
start_flags) < 0) {
|
||||||
-1, NULL, NULL, VIR_NETDEV_VPORT_PROFILE_OP_CREATE) < 0) {
|
|
||||||
virDomainAuditStart(vm, "booted", false);
|
virDomainAuditStart(vm, "booted", false);
|
||||||
if (qemuDomainObjEndJob(driver, vm) > 0)
|
if (qemuDomainObjEndJob(driver, vm) > 0)
|
||||||
qemuDomainRemoveInactive(driver, vm);
|
qemuDomainRemoveInactive(driver, vm);
|
||||||
@ -4138,9 +4143,9 @@ qemuDomainSaveImageStartVM(virConnectPtr conn,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Set the migration source and start it up. */
|
/* Set the migration source and start it up. */
|
||||||
ret = qemuProcessStart(conn, driver, vm, "stdio", false, true,
|
ret = qemuProcessStart(conn, driver, vm, "stdio", *fd, path, NULL,
|
||||||
false, *fd, path, NULL,
|
VIR_NETDEV_VPORT_PROFILE_OP_RESTORE,
|
||||||
VIR_NETDEV_VPORT_PROFILE_OP_RESTORE);
|
VIR_QEMU_PROCESS_START_PAUSED);
|
||||||
|
|
||||||
if (intermediatefd != -1) {
|
if (intermediatefd != -1) {
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
@ -4710,6 +4715,10 @@ qemuDomainObjStart(virConnectPtr conn,
|
|||||||
bool autodestroy = (flags & VIR_DOMAIN_START_AUTODESTROY) != 0;
|
bool autodestroy = (flags & VIR_DOMAIN_START_AUTODESTROY) != 0;
|
||||||
bool bypass_cache = (flags & VIR_DOMAIN_START_BYPASS_CACHE) != 0;
|
bool bypass_cache = (flags & VIR_DOMAIN_START_BYPASS_CACHE) != 0;
|
||||||
bool force_boot = (flags & VIR_DOMAIN_START_FORCE_BOOT) != 0;
|
bool force_boot = (flags & VIR_DOMAIN_START_FORCE_BOOT) != 0;
|
||||||
|
unsigned int start_flags = VIR_QEMU_PROCESS_START_COLD;
|
||||||
|
|
||||||
|
start_flags |= start_paused ? VIR_QEMU_PROCESS_START_PAUSED : 0;
|
||||||
|
start_flags |= autodestroy ? VIR_QEMU_PROCESS_START_AUTODESROY : 0;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If there is a managed saved state restore it instead of starting
|
* If there is a managed saved state restore it instead of starting
|
||||||
@ -4741,9 +4750,8 @@ qemuDomainObjStart(virConnectPtr conn,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = qemuProcessStart(conn, driver, vm, NULL, true, start_paused,
|
ret = qemuProcessStart(conn, driver, vm, NULL, -1, NULL, NULL,
|
||||||
autodestroy, -1, NULL, NULL,
|
VIR_NETDEV_VPORT_PROFILE_OP_CREATE, start_flags);
|
||||||
VIR_NETDEV_VPORT_PROFILE_OP_CREATE);
|
|
||||||
virDomainAuditStart(vm, "booted", ret >= 0);
|
virDomainAuditStart(vm, "booted", ret >= 0);
|
||||||
if (ret >= 0) {
|
if (ret >= 0) {
|
||||||
virDomainEventPtr event =
|
virDomainEventPtr event =
|
||||||
@ -11027,9 +11035,10 @@ static int qemuDomainRevertToSnapshot(virDomainSnapshotPtr snapshot,
|
|||||||
if (config)
|
if (config)
|
||||||
virDomainObjAssignDef(vm, config, false);
|
virDomainObjAssignDef(vm, config, false);
|
||||||
|
|
||||||
rc = qemuProcessStart(snapshot->domain->conn, driver, vm, NULL,
|
rc = qemuProcessStart(snapshot->domain->conn,
|
||||||
false, true, false, -1, NULL, snap,
|
driver, vm, NULL, -1, NULL, snap,
|
||||||
VIR_NETDEV_VPORT_PROFILE_OP_CREATE);
|
VIR_NETDEV_VPORT_PROFILE_OP_CREATE,
|
||||||
|
VIR_QEMU_PROCESS_START_PAUSED);
|
||||||
virDomainAuditStart(vm, "from-snapshot", rc >= 0);
|
virDomainAuditStart(vm, "from-snapshot", rc >= 0);
|
||||||
detail = VIR_DOMAIN_EVENT_STARTED_FROM_SNAPSHOT;
|
detail = VIR_DOMAIN_EVENT_STARTED_FROM_SNAPSHOT;
|
||||||
event = virDomainEventNewFromObj(vm,
|
event = virDomainEventNewFromObj(vm,
|
||||||
@ -11114,12 +11123,16 @@ static int qemuDomainRevertToSnapshot(virDomainSnapshotPtr snapshot,
|
|||||||
VIR_DOMAIN_SNAPSHOT_REVERT_PAUSED)) {
|
VIR_DOMAIN_SNAPSHOT_REVERT_PAUSED)) {
|
||||||
/* Flush first event, now do transition 2 or 3 */
|
/* Flush first event, now do transition 2 or 3 */
|
||||||
bool paused = (flags & VIR_DOMAIN_SNAPSHOT_REVERT_PAUSED) != 0;
|
bool paused = (flags & VIR_DOMAIN_SNAPSHOT_REVERT_PAUSED) != 0;
|
||||||
|
unsigned int start_flags = 0;
|
||||||
|
|
||||||
|
start_flags |= paused ? VIR_QEMU_PROCESS_START_PAUSED : 0;
|
||||||
|
|
||||||
if (event)
|
if (event)
|
||||||
qemuDomainEventQueue(driver, event);
|
qemuDomainEventQueue(driver, event);
|
||||||
rc = qemuProcessStart(snapshot->domain->conn, driver, vm, NULL,
|
rc = qemuProcessStart(snapshot->domain->conn,
|
||||||
false, paused, false, -1, NULL, NULL,
|
driver, vm, NULL, -1, NULL, NULL,
|
||||||
VIR_NETDEV_VPORT_PROFILE_OP_CREATE);
|
VIR_NETDEV_VPORT_PROFILE_OP_CREATE,
|
||||||
|
start_flags);
|
||||||
virDomainAuditStart(vm, "from-snapshot", rc >= 0);
|
virDomainAuditStart(vm, "from-snapshot", rc >= 0);
|
||||||
if (rc < 0) {
|
if (rc < 0) {
|
||||||
if (!vm->persistent) {
|
if (!vm->persistent) {
|
||||||
|
@ -1303,9 +1303,10 @@ qemuMigrationPrepareAny(struct qemud_driver *driver,
|
|||||||
/* Start the QEMU daemon, with the same command-line arguments plus
|
/* Start the QEMU daemon, with the same command-line arguments plus
|
||||||
* -incoming $migrateFrom
|
* -incoming $migrateFrom
|
||||||
*/
|
*/
|
||||||
if (qemuProcessStart(dconn, driver, vm, migrateFrom, false, true,
|
if (qemuProcessStart(dconn, driver, vm, migrateFrom, dataFD[0], NULL, NULL,
|
||||||
true, dataFD[0], NULL, NULL,
|
VIR_NETDEV_VPORT_PROFILE_OP_MIGRATE_IN_START,
|
||||||
VIR_NETDEV_VPORT_PROFILE_OP_MIGRATE_IN_START) < 0) {
|
VIR_QEMU_PROCESS_START_PAUSED |
|
||||||
|
VIR_QEMU_PROCESS_START_AUTODESROY) < 0) {
|
||||||
virDomainAuditStart(vm, "migrated", false);
|
virDomainAuditStart(vm, "migrated", false);
|
||||||
/* Note that we don't set an error here because qemuProcessStart
|
/* Note that we don't set an error here because qemuProcessStart
|
||||||
* should have already done that.
|
* should have already done that.
|
||||||
|
@ -3274,13 +3274,11 @@ int qemuProcessStart(virConnectPtr conn,
|
|||||||
struct qemud_driver *driver,
|
struct qemud_driver *driver,
|
||||||
virDomainObjPtr vm,
|
virDomainObjPtr vm,
|
||||||
const char *migrateFrom,
|
const char *migrateFrom,
|
||||||
bool cold_boot,
|
|
||||||
bool start_paused,
|
|
||||||
bool autodestroy,
|
|
||||||
int stdin_fd,
|
int stdin_fd,
|
||||||
const char *stdin_path,
|
const char *stdin_path,
|
||||||
virDomainSnapshotObjPtr snapshot,
|
virDomainSnapshotObjPtr snapshot,
|
||||||
enum virNetDevVPortProfileOp vmop)
|
enum virNetDevVPortProfileOp vmop,
|
||||||
|
unsigned int flags)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
off_t pos = -1;
|
off_t pos = -1;
|
||||||
@ -3293,6 +3291,12 @@ int qemuProcessStart(virConnectPtr conn,
|
|||||||
unsigned long cur_balloon;
|
unsigned long cur_balloon;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
/* Okay, these are just internal flags,
|
||||||
|
* but doesn't hurt to check */
|
||||||
|
virCheckFlags(VIR_QEMU_PROCESS_START_COLD |
|
||||||
|
VIR_QEMU_PROCESS_START_PAUSED |
|
||||||
|
VIR_QEMU_PROCESS_START_AUTODESROY, -1);
|
||||||
|
|
||||||
hookData.conn = conn;
|
hookData.conn = conn;
|
||||||
hookData.vm = vm;
|
hookData.vm = vm;
|
||||||
hookData.driver = driver;
|
hookData.driver = driver;
|
||||||
@ -3437,7 +3441,8 @@ int qemuProcessStart(virConnectPtr conn,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
VIR_DEBUG("Checking for CDROM and floppy presence");
|
VIR_DEBUG("Checking for CDROM and floppy presence");
|
||||||
if (qemuDomainCheckDiskPresence(driver, vm, cold_boot) < 0)
|
if (qemuDomainCheckDiskPresence(driver, vm,
|
||||||
|
flags & VIR_QEMU_PROCESS_START_COLD) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
VIR_DEBUG("Setting up domain cgroup (if required)");
|
VIR_DEBUG("Setting up domain cgroup (if required)");
|
||||||
@ -3636,7 +3641,7 @@ int qemuProcessStart(virConnectPtr conn,
|
|||||||
VIR_DEBUG("Handshake complete, child running");
|
VIR_DEBUG("Handshake complete, child running");
|
||||||
|
|
||||||
if (migrateFrom)
|
if (migrateFrom)
|
||||||
start_paused = true;
|
flags |= VIR_QEMU_PROCESS_START_PAUSED;
|
||||||
|
|
||||||
if (ret == -1) /* The VM failed to start; tear filters before taps */
|
if (ret == -1) /* The VM failed to start; tear filters before taps */
|
||||||
virDomainConfVMNWFilterTeardown(vm);
|
virDomainConfVMNWFilterTeardown(vm);
|
||||||
@ -3711,7 +3716,7 @@ int qemuProcessStart(virConnectPtr conn,
|
|||||||
}
|
}
|
||||||
qemuDomainObjExitMonitorWithDriver(driver, vm);
|
qemuDomainObjExitMonitorWithDriver(driver, vm);
|
||||||
|
|
||||||
if (!start_paused) {
|
if (!(flags & VIR_QEMU_PROCESS_START_PAUSED)) {
|
||||||
VIR_DEBUG("Starting domain CPUs");
|
VIR_DEBUG("Starting domain CPUs");
|
||||||
/* Allow the CPUS to start executing */
|
/* Allow the CPUS to start executing */
|
||||||
if (qemuProcessStartCPUs(driver, vm, conn,
|
if (qemuProcessStartCPUs(driver, vm, conn,
|
||||||
@ -3729,7 +3734,7 @@ int qemuProcessStart(virConnectPtr conn,
|
|||||||
VIR_DOMAIN_PAUSED_USER);
|
VIR_DOMAIN_PAUSED_USER);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (autodestroy &&
|
if (flags & VIR_QEMU_PROCESS_START_AUTODESROY &&
|
||||||
qemuProcessAutoDestroyAdd(driver, vm, conn) < 0)
|
qemuProcessAutoDestroyAdd(driver, vm, conn) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
|
@ -44,17 +44,21 @@ void qemuProcessReconnectAll(virConnectPtr conn, struct qemud_driver *driver);
|
|||||||
|
|
||||||
int qemuProcessAssignPCIAddresses(virDomainDefPtr def);
|
int qemuProcessAssignPCIAddresses(virDomainDefPtr def);
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
VIR_QEMU_PROCESS_START_COLD = 1 << 0,
|
||||||
|
VIR_QEMU_PROCESS_START_PAUSED = 1 << 1,
|
||||||
|
VIR_QEMU_PROCESS_START_AUTODESROY = 1 << 2,
|
||||||
|
} qemuProcessStartFlags;
|
||||||
|
|
||||||
int qemuProcessStart(virConnectPtr conn,
|
int qemuProcessStart(virConnectPtr conn,
|
||||||
struct qemud_driver *driver,
|
struct qemud_driver *driver,
|
||||||
virDomainObjPtr vm,
|
virDomainObjPtr vm,
|
||||||
const char *migrateFrom,
|
const char *migrateFrom,
|
||||||
bool cold_boot,
|
|
||||||
bool start_paused,
|
|
||||||
bool autodestroy,
|
|
||||||
int stdin_fd,
|
int stdin_fd,
|
||||||
const char *stdin_path,
|
const char *stdin_path,
|
||||||
virDomainSnapshotObjPtr snapshot,
|
virDomainSnapshotObjPtr snapshot,
|
||||||
enum virNetDevVPortProfileOp vmop);
|
enum virNetDevVPortProfileOp vmop,
|
||||||
|
unsigned int flags);
|
||||||
|
|
||||||
void qemuProcessStop(struct qemud_driver *driver,
|
void qemuProcessStop(struct qemud_driver *driver,
|
||||||
virDomainObjPtr vm,
|
virDomainObjPtr vm,
|
||||||
|
Loading…
Reference in New Issue
Block a user