locking: Pass hypervisor driver name when acquiring locks

This is required in case a lock manager needs to contact libvirtd in
case of an unexpected event.
This commit is contained in:
Jiri Denemark 2012-09-17 15:36:47 +02:00
parent e55ff49cbc
commit d236f3fc38
8 changed files with 49 additions and 18 deletions

View File

@ -183,6 +183,10 @@
.key = "pid",
.value = { .i = dom->pid },
},
{ .type = VIR_LOCK_MANAGER_PARAM_TYPE_CSTRING,
.key = "uri",
.value = { .cstr = driver->uri },
},
};
mgr = virLockManagerNew(lockPlugin,
VIR_LOCK_MANAGER_TYPE_DOMAIN,
@ -225,6 +229,10 @@
.key = "pid",
.value = { .i = dom->pid },
},
{ .type = VIR_LOCK_MANAGER_PARAM_TYPE_CSTRING,
.key = "uri",
.value = { .cstr = driver->uri },
},
};
mgr = virLockManagerNew(lockPlugin,
VIR_LOCK_MANAGER_TYPE_DOMAIN,

View File

@ -97,6 +97,7 @@ static int virDomainLockManagerAddDisk(virLockManagerPtr lock,
}
static virLockManagerPtr virDomainLockManagerNew(virLockManagerPluginPtr plugin,
const char *uri,
virDomainObjPtr dom,
bool withResources)
{
@ -118,6 +119,10 @@ static virLockManagerPtr virDomainLockManagerNew(virLockManagerPluginPtr plugin,
.key = "pid",
.value = { .i = dom->pid },
},
{ .type = VIR_LOCK_MANAGER_PARAM_TYPE_CSTRING,
.key = "uri",
.value = { .cstr = uri },
},
};
VIR_DEBUG("plugin=%p dom=%p withResources=%d",
plugin, dom, withResources);
@ -152,6 +157,7 @@ error:
int virDomainLockProcessStart(virLockManagerPluginPtr plugin,
const char *uri,
virDomainObjPtr dom,
bool paused,
int *fd)
@ -163,7 +169,7 @@ int virDomainLockProcessStart(virLockManagerPluginPtr plugin,
VIR_DEBUG("plugin=%p dom=%p paused=%d fd=%p",
plugin, dom, paused, fd);
if (!(lock = virDomainLockManagerNew(plugin, dom, true)))
if (!(lock = virDomainLockManagerNew(plugin, uri, dom, true)))
return -1;
if (paused)
@ -186,7 +192,7 @@ int virDomainLockProcessPause(virLockManagerPluginPtr plugin,
VIR_DEBUG("plugin=%p dom=%p state=%p",
plugin, dom, state);
if (!(lock = virDomainLockManagerNew(plugin, dom, true)))
if (!(lock = virDomainLockManagerNew(plugin, NULL, dom, true)))
return -1;
ret = virLockManagerRelease(lock, state, 0);
@ -196,6 +202,7 @@ int virDomainLockProcessPause(virLockManagerPluginPtr plugin,
}
int virDomainLockProcessResume(virLockManagerPluginPtr plugin,
const char *uri,
virDomainObjPtr dom,
const char *state)
{
@ -205,7 +212,7 @@ int virDomainLockProcessResume(virLockManagerPluginPtr plugin,
VIR_DEBUG("plugin=%p dom=%p state=%s",
plugin, dom, NULLSTR(state));
if (!(lock = virDomainLockManagerNew(plugin, dom, true)))
if (!(lock = virDomainLockManagerNew(plugin, uri, dom, true)))
return -1;
ret = virLockManagerAcquire(lock, state, 0, NULL);
@ -224,7 +231,7 @@ int virDomainLockProcessInquire(virLockManagerPluginPtr plugin,
VIR_DEBUG("plugin=%p dom=%p state=%p",
plugin, dom, state);
if (!(lock = virDomainLockManagerNew(plugin, dom, true)))
if (!(lock = virDomainLockManagerNew(plugin, NULL, dom, true)))
return -1;
ret = virLockManagerInquire(lock, state, 0);
@ -235,6 +242,7 @@ int virDomainLockProcessInquire(virLockManagerPluginPtr plugin,
int virDomainLockDiskAttach(virLockManagerPluginPtr plugin,
const char *uri,
virDomainObjPtr dom,
virDomainDiskDefPtr disk)
{
@ -244,7 +252,7 @@ int virDomainLockDiskAttach(virLockManagerPluginPtr plugin,
VIR_DEBUG("plugin=%p dom=%p disk=%p",
plugin, dom, disk);
if (!(lock = virDomainLockManagerNew(plugin, dom, false)))
if (!(lock = virDomainLockManagerNew(plugin, uri, dom, false)))
return -1;
if (virDomainLockManagerAddDisk(lock, disk) < 0)
@ -271,7 +279,7 @@ int virDomainLockDiskDetach(virLockManagerPluginPtr plugin,
VIR_DEBUG("plugin=%p dom=%p disk=%p",
plugin, dom, disk);
if (!(lock = virDomainLockManagerNew(plugin, dom, false)))
if (!(lock = virDomainLockManagerNew(plugin, NULL, dom, false)))
return -1;
if (virDomainLockManagerAddDisk(lock, disk) < 0)
@ -290,6 +298,7 @@ cleanup:
int virDomainLockLeaseAttach(virLockManagerPluginPtr plugin,
const char *uri,
virDomainObjPtr dom,
virDomainLeaseDefPtr lease)
{
@ -299,7 +308,7 @@ int virDomainLockLeaseAttach(virLockManagerPluginPtr plugin,
VIR_DEBUG("plugin=%p dom=%p lease=%p",
plugin, dom, lease);
if (!(lock = virDomainLockManagerNew(plugin, dom, false)))
if (!(lock = virDomainLockManagerNew(plugin, uri, dom, false)))
return -1;
if (virDomainLockManagerAddLease(lock, lease) < 0)
@ -326,7 +335,7 @@ int virDomainLockLeaseDetach(virLockManagerPluginPtr plugin,
VIR_DEBUG("plugin=%p dom=%p lease=%p",
plugin, dom, lease);
if (!(lock = virDomainLockManagerNew(plugin, dom, false)))
if (!(lock = virDomainLockManagerNew(plugin, NULL, dom, false)))
return -1;
if (virDomainLockManagerAddLease(lock, lease) < 0)

View File

@ -27,6 +27,7 @@
# include "lock_manager.h"
int virDomainLockProcessStart(virLockManagerPluginPtr plugin,
const char *uri,
virDomainObjPtr dom,
bool paused,
int *fd);
@ -34,6 +35,7 @@ int virDomainLockProcessPause(virLockManagerPluginPtr plugin,
virDomainObjPtr dom,
char **state);
int virDomainLockProcessResume(virLockManagerPluginPtr plugin,
const char *uri,
virDomainObjPtr dom,
const char *state);
int virDomainLockProcessInquire(virLockManagerPluginPtr plugin,
@ -41,6 +43,7 @@ int virDomainLockProcessInquire(virLockManagerPluginPtr plugin,
char **state);
int virDomainLockDiskAttach(virLockManagerPluginPtr plugin,
const char *uri,
virDomainObjPtr dom,
virDomainDiskDefPtr disk);
int virDomainLockDiskDetach(virLockManagerPluginPtr plugin,
@ -48,6 +51,7 @@ int virDomainLockDiskDetach(virLockManagerPluginPtr plugin,
virDomainDiskDefPtr disk);
int virDomainLockLeaseAttach(virLockManagerPluginPtr plugin,
const char *uri,
virDomainObjPtr dom,
virDomainLeaseDefPtr lease);
int virDomainLockLeaseDetach(virLockManagerPluginPtr plugin,

View File

@ -155,6 +155,7 @@ typedef int (*virLockDriverDeinit)(void);
* - uuid: the domain uuid (uuid)
* - name: the domain name (string)
* - pid: process ID to own/owning the lock (unsigned int)
* - uri: URI for connecting to the driver the domain belongs to (string)
*
* Returns 0 if successful initialized a new context, -1 on error
*/

View File

@ -57,6 +57,7 @@ struct qemud_driver {
virThreadPoolPtr workerPool;
int privileged;
const char *uri;
uid_t user;
gid_t group;

View File

@ -611,7 +611,9 @@ qemudStartup(int privileged) {
return -1;
}
qemuDriverLock(qemu_driver);
qemu_driver->privileged = privileged;
qemu_driver->uri = privileged ? "qemu:///system" : "qemu:///session";
/* Don't have a dom0 so start from 1 */
qemu_driver->nextvmid = 1;
@ -860,9 +862,7 @@ qemudStartup(int privileged) {
virHashForEach(qemu_driver->domains.objs, qemuDomainNetsRestart, NULL);
conn = virConnectOpen(qemu_driver->privileged ?
"qemu:///system" :
"qemu:///session");
conn = virConnectOpen(qemu_driver->uri);
qemuProcessReconnectAll(conn, qemu_driver);
@ -10695,7 +10695,8 @@ qemuDomainSnapshotCreateSingleDiskActive(struct qemud_driver *driver,
origdriver = disk->driverType;
disk->driverType = (char *) "raw"; /* Don't want to probe backing files */
if (virDomainLockDiskAttach(driver->lockManager, vm, disk) < 0)
if (virDomainLockDiskAttach(driver->lockManager, driver->uri,
vm, disk) < 0)
goto cleanup;
if (cgroup && qemuSetupDiskCgroup(driver, vm, cgroup, disk) < 0) {
if (virDomainLockDiskDetach(driver->lockManager, vm, disk) < 0)

View File

@ -88,7 +88,8 @@ int qemuDomainChangeEjectableMedia(struct qemud_driver *driver,
return -1;
}
if (virDomainLockDiskAttach(driver->lockManager, vm, disk) < 0)
if (virDomainLockDiskAttach(driver->lockManager, driver->uri,
vm, disk) < 0)
return -1;
if (virSecurityManagerSetImageLabel(driver->securityManager,
@ -217,7 +218,8 @@ int qemuDomainAttachPciDiskDevice(virConnectPtr conn,
}
}
if (virDomainLockDiskAttach(driver->lockManager, vm, disk) < 0)
if (virDomainLockDiskAttach(driver->lockManager, driver->uri,
vm, disk) < 0)
return -1;
if (virSecurityManagerSetImageLabel(driver->securityManager,
@ -449,7 +451,8 @@ int qemuDomainAttachSCSIDisk(virConnectPtr conn,
}
}
if (virDomainLockDiskAttach(driver->lockManager, vm, disk) < 0)
if (virDomainLockDiskAttach(driver->lockManager, driver->uri,
vm, disk) < 0)
return -1;
if (virSecurityManagerSetImageLabel(driver->securityManager,
@ -572,7 +575,8 @@ int qemuDomainAttachUsbMassstorageDevice(virConnectPtr conn,
}
}
if (virDomainLockDiskAttach(driver->lockManager, vm, disk) < 0)
if (virDomainLockDiskAttach(driver->lockManager, driver->uri,
vm, disk) < 0)
return -1;
if (virSecurityManagerSetImageLabel(driver->securityManager,
@ -2389,7 +2393,8 @@ int qemuDomainAttachLease(struct qemud_driver *driver,
if (virDomainLeaseInsertPreAlloc(vm->def) < 0)
return -1;
if (virDomainLockLeaseAttach(driver->lockManager, vm, lease) < 0) {
if (virDomainLockLeaseAttach(driver->lockManager, driver->uri,
vm, lease) < 0) {
virDomainLeaseInsertPreAlloced(vm->def, NULL);
return -1;
}

View File

@ -2597,6 +2597,7 @@ static int qemuProcessHook(void *data)
if (virSecurityManagerSetSocketLabel(h->driver->securityManager, h->vm->def) < 0)
goto cleanup;
if (virDomainLockProcessStart(h->driver->lockManager,
h->driver->uri,
h->vm,
/* QEMU is always pased initially */
true,
@ -2666,7 +2667,8 @@ qemuProcessStartCPUs(struct qemud_driver *driver, virDomainObjPtr vm,
qemuDomainObjPrivatePtr priv = vm->privateData;
VIR_DEBUG("Using lock state '%s'", NULLSTR(priv->lockState));
if (virDomainLockProcessResume(driver->lockManager, vm, priv->lockState) < 0) {
if (virDomainLockProcessResume(driver->lockManager, driver->uri,
vm, priv->lockState) < 0) {
/* Don't free priv->lockState on error, because we need
* to make sure we have state still present if the user
* tries to resume again