mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-28 11:31:16 +00:00
locking: Add APIs to lock individual image files
Add helper APIs to manage individual image files rather than disks. To simplify the addition some parts of the code were refactored in this patch.
This commit is contained in:
parent
1ba14d6df2
commit
68f0deb0dc
@ -862,6 +862,8 @@ virRegisterStorageDriver;
|
|||||||
# locking/domain_lock.h
|
# locking/domain_lock.h
|
||||||
virDomainLockDiskAttach;
|
virDomainLockDiskAttach;
|
||||||
virDomainLockDiskDetach;
|
virDomainLockDiskDetach;
|
||||||
|
virDomainLockImageAttach;
|
||||||
|
virDomainLockImageDetach;
|
||||||
virDomainLockLeaseAttach;
|
virDomainLockLeaseAttach;
|
||||||
virDomainLockLeaseDetach;
|
virDomainLockLeaseDetach;
|
||||||
virDomainLockProcessInquire;
|
virDomainLockProcessInquire;
|
||||||
|
@ -68,14 +68,13 @@ static int virDomainLockManagerAddLease(virLockManagerPtr lock,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int virDomainLockManagerAddDisk(virLockManagerPtr lock,
|
static int virDomainLockManagerAddImage(virLockManagerPtr lock,
|
||||||
virDomainDiskDefPtr disk)
|
virStorageSourcePtr src)
|
||||||
{
|
{
|
||||||
unsigned int diskFlags = 0;
|
unsigned int diskFlags = 0;
|
||||||
const char *src = virDomainDiskGetSource(disk);
|
int type = virStorageSourceGetActualType(src);
|
||||||
int type = virDomainDiskGetType(disk);
|
|
||||||
|
|
||||||
if (!src)
|
if (!src->path)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (!(type == VIR_STORAGE_TYPE_BLOCK ||
|
if (!(type == VIR_STORAGE_TYPE_BLOCK ||
|
||||||
@ -83,24 +82,25 @@ static int virDomainLockManagerAddDisk(virLockManagerPtr lock,
|
|||||||
type == VIR_STORAGE_TYPE_DIR))
|
type == VIR_STORAGE_TYPE_DIR))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (disk->src->readonly)
|
if (src->readonly)
|
||||||
diskFlags |= VIR_LOCK_MANAGER_RESOURCE_READONLY;
|
diskFlags |= VIR_LOCK_MANAGER_RESOURCE_READONLY;
|
||||||
if (disk->src->shared)
|
if (src->shared)
|
||||||
diskFlags |= VIR_LOCK_MANAGER_RESOURCE_SHARED;
|
diskFlags |= VIR_LOCK_MANAGER_RESOURCE_SHARED;
|
||||||
|
|
||||||
VIR_DEBUG("Add disk %s", src);
|
VIR_DEBUG("Add disk %s", src->path);
|
||||||
if (virLockManagerAddResource(lock,
|
if (virLockManagerAddResource(lock,
|
||||||
VIR_LOCK_MANAGER_RESOURCE_TYPE_DISK,
|
VIR_LOCK_MANAGER_RESOURCE_TYPE_DISK,
|
||||||
src,
|
src->path,
|
||||||
0,
|
0,
|
||||||
NULL,
|
NULL,
|
||||||
diskFlags) < 0) {
|
diskFlags) < 0) {
|
||||||
VIR_DEBUG("Failed add disk %s", src);
|
VIR_DEBUG("Failed add disk %s", src->path);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static virLockManagerPtr virDomainLockManagerNew(virLockManagerPluginPtr plugin,
|
static virLockManagerPtr virDomainLockManagerNew(virLockManagerPluginPtr plugin,
|
||||||
const char *uri,
|
const char *uri,
|
||||||
virDomainObjPtr dom,
|
virDomainObjPtr dom,
|
||||||
@ -148,9 +148,12 @@ static virLockManagerPtr virDomainLockManagerNew(virLockManagerPluginPtr plugin,
|
|||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
VIR_DEBUG("Adding disks");
|
VIR_DEBUG("Adding disks");
|
||||||
for (i = 0; i < dom->def->ndisks; i++)
|
for (i = 0; i < dom->def->ndisks; i++) {
|
||||||
if (virDomainLockManagerAddDisk(lock, dom->def->disks[i]) < 0)
|
virDomainDiskDefPtr disk = dom->def->disks[i];
|
||||||
|
|
||||||
|
if (virDomainLockManagerAddImage(lock, disk->src) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return lock;
|
return lock;
|
||||||
@ -247,21 +250,20 @@ int virDomainLockProcessInquire(virLockManagerPluginPtr plugin,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int virDomainLockDiskAttach(virLockManagerPluginPtr plugin,
|
int virDomainLockImageAttach(virLockManagerPluginPtr plugin,
|
||||||
const char *uri,
|
const char *uri,
|
||||||
virDomainObjPtr dom,
|
virDomainObjPtr dom,
|
||||||
virDomainDiskDefPtr disk)
|
virStorageSourcePtr src)
|
||||||
{
|
{
|
||||||
virLockManagerPtr lock;
|
virLockManagerPtr lock;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
VIR_DEBUG("plugin=%p dom=%p disk=%p",
|
VIR_DEBUG("plugin=%p dom=%p src=%p", plugin, dom, src);
|
||||||
plugin, dom, disk);
|
|
||||||
|
|
||||||
if (!(lock = virDomainLockManagerNew(plugin, uri, dom, false)))
|
if (!(lock = virDomainLockManagerNew(plugin, uri, dom, false)))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (virDomainLockManagerAddDisk(lock, disk) < 0)
|
if (virDomainLockManagerAddImage(lock, src) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (virLockManagerAcquire(lock, NULL, 0,
|
if (virLockManagerAcquire(lock, NULL, 0,
|
||||||
@ -276,20 +278,29 @@ int virDomainLockDiskAttach(virLockManagerPluginPtr plugin,
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int virDomainLockDiskDetach(virLockManagerPluginPtr plugin,
|
|
||||||
|
int virDomainLockDiskAttach(virLockManagerPluginPtr plugin,
|
||||||
|
const char *uri,
|
||||||
virDomainObjPtr dom,
|
virDomainObjPtr dom,
|
||||||
virDomainDiskDefPtr disk)
|
virDomainDiskDefPtr disk)
|
||||||
|
{
|
||||||
|
return virDomainLockImageAttach(plugin, uri, dom, disk->src);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int virDomainLockImageDetach(virLockManagerPluginPtr plugin,
|
||||||
|
virDomainObjPtr dom,
|
||||||
|
virStorageSourcePtr src)
|
||||||
{
|
{
|
||||||
virLockManagerPtr lock;
|
virLockManagerPtr lock;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
VIR_DEBUG("plugin=%p dom=%p disk=%p",
|
VIR_DEBUG("plugin=%p dom=%p src=%p", plugin, dom, src);
|
||||||
plugin, dom, disk);
|
|
||||||
|
|
||||||
if (!(lock = virDomainLockManagerNew(plugin, NULL, dom, false)))
|
if (!(lock = virDomainLockManagerNew(plugin, NULL, dom, false)))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (virDomainLockManagerAddDisk(lock, disk) < 0)
|
if (virDomainLockManagerAddImage(lock, src) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (virLockManagerRelease(lock, NULL, 0) < 0)
|
if (virLockManagerRelease(lock, NULL, 0) < 0)
|
||||||
@ -304,6 +315,14 @@ int virDomainLockDiskDetach(virLockManagerPluginPtr plugin,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int virDomainLockDiskDetach(virLockManagerPluginPtr plugin,
|
||||||
|
virDomainObjPtr dom,
|
||||||
|
virDomainDiskDefPtr disk)
|
||||||
|
{
|
||||||
|
return virDomainLockImageDetach(plugin, dom, disk->src);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int virDomainLockLeaseAttach(virLockManagerPluginPtr plugin,
|
int virDomainLockLeaseAttach(virLockManagerPluginPtr plugin,
|
||||||
const char *uri,
|
const char *uri,
|
||||||
virDomainObjPtr dom,
|
virDomainObjPtr dom,
|
||||||
|
@ -50,6 +50,14 @@ int virDomainLockDiskDetach(virLockManagerPluginPtr plugin,
|
|||||||
virDomainObjPtr dom,
|
virDomainObjPtr dom,
|
||||||
virDomainDiskDefPtr disk);
|
virDomainDiskDefPtr disk);
|
||||||
|
|
||||||
|
int virDomainLockImageAttach(virLockManagerPluginPtr plugin,
|
||||||
|
const char *uri,
|
||||||
|
virDomainObjPtr dom,
|
||||||
|
virStorageSourcePtr src);
|
||||||
|
int virDomainLockImageDetach(virLockManagerPluginPtr plugin,
|
||||||
|
virDomainObjPtr dom,
|
||||||
|
virStorageSourcePtr src);
|
||||||
|
|
||||||
int virDomainLockLeaseAttach(virLockManagerPluginPtr plugin,
|
int virDomainLockLeaseAttach(virLockManagerPluginPtr plugin,
|
||||||
const char *uri,
|
const char *uri,
|
||||||
virDomainObjPtr dom,
|
virDomainObjPtr dom,
|
||||||
|
Loading…
Reference in New Issue
Block a user