mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 21:55:25 +00:00
lock_driver: Introduce VIR_LOCK_MANAGER_RESOURCE_TYPE_METADATA
This is a new type of object that lock drivers can handle. Currently, it is supported by lockd driver only. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: John Ferlan <jferlan@redhat.com>
This commit is contained in:
parent
aaf34cb901
commit
997283b54b
@ -51,6 +51,8 @@ typedef enum {
|
||||
VIR_LOCK_MANAGER_RESOURCE_TYPE_DISK = 0,
|
||||
/* A lease against an arbitrary resource */
|
||||
VIR_LOCK_MANAGER_RESOURCE_TYPE_LEASE = 1,
|
||||
/* The resource to be locked is a metadata */
|
||||
VIR_LOCK_MANAGER_RESOURCE_TYPE_METADATA = 2,
|
||||
} virLockManagerResourceType;
|
||||
|
||||
typedef enum {
|
||||
|
@ -563,7 +563,7 @@ static int virLockManagerLockDaemonAddResource(virLockManagerPtr lock,
|
||||
virLockManagerLockDaemonPrivatePtr priv = lock->privateData;
|
||||
char *newName = NULL;
|
||||
char *newLockspace = NULL;
|
||||
bool autoCreate = false;
|
||||
int newFlags = 0;
|
||||
int ret = -1;
|
||||
|
||||
virCheckFlags(VIR_LOCK_MANAGER_RESOURCE_READONLY |
|
||||
@ -575,7 +575,7 @@ static int virLockManagerLockDaemonAddResource(virLockManagerPtr lock,
|
||||
switch (priv->type) {
|
||||
case VIR_LOCK_MANAGER_OBJECT_TYPE_DOMAIN:
|
||||
|
||||
switch (type) {
|
||||
switch ((virLockManagerResourceType) type) {
|
||||
case VIR_LOCK_MANAGER_RESOURCE_TYPE_DISK:
|
||||
if (params || nparams) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
@ -602,7 +602,7 @@ static int virLockManagerLockDaemonAddResource(virLockManagerPtr lock,
|
||||
VIR_DEBUG("Got an LVM UUID %s for %s", newName, name);
|
||||
if (VIR_STRDUP(newLockspace, driver->lvmLockSpaceDir) < 0)
|
||||
goto cleanup;
|
||||
autoCreate = true;
|
||||
newFlags |= VIR_LOCK_SPACE_PROTOCOL_ACQUIRE_RESOURCE_AUTOCREATE;
|
||||
break;
|
||||
}
|
||||
virResetLastError();
|
||||
@ -619,7 +619,7 @@ static int virLockManagerLockDaemonAddResource(virLockManagerPtr lock,
|
||||
VIR_DEBUG("Got an SCSI ID %s for %s", newName, name);
|
||||
if (VIR_STRDUP(newLockspace, driver->scsiLockSpaceDir) < 0)
|
||||
goto cleanup;
|
||||
autoCreate = true;
|
||||
newFlags |= VIR_LOCK_SPACE_PROTOCOL_ACQUIRE_RESOURCE_AUTOCREATE;
|
||||
break;
|
||||
}
|
||||
virResetLastError();
|
||||
@ -631,7 +631,7 @@ static int virLockManagerLockDaemonAddResource(virLockManagerPtr lock,
|
||||
goto cleanup;
|
||||
if (virCryptoHashString(VIR_CRYPTO_HASH_SHA256, name, &newName) < 0)
|
||||
goto cleanup;
|
||||
autoCreate = true;
|
||||
newFlags |= VIR_LOCK_SPACE_PROTOCOL_ACQUIRE_RESOURCE_AUTOCREATE;
|
||||
VIR_DEBUG("Using indirect lease %s for %s", newName, name);
|
||||
} else {
|
||||
if (VIR_STRDUP(newLockspace, "") < 0)
|
||||
@ -676,6 +676,8 @@ static int virLockManagerLockDaemonAddResource(virLockManagerPtr lock,
|
||||
goto cleanup;
|
||||
|
||||
} break;
|
||||
|
||||
case VIR_LOCK_MANAGER_RESOURCE_TYPE_METADATA:
|
||||
default:
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("Unknown lock manager object type %d for domain lock object"),
|
||||
@ -685,6 +687,29 @@ static int virLockManagerLockDaemonAddResource(virLockManagerPtr lock,
|
||||
break;
|
||||
|
||||
case VIR_LOCK_MANAGER_OBJECT_TYPE_DAEMON:
|
||||
switch ((virLockManagerResourceType) type) {
|
||||
case VIR_LOCK_MANAGER_RESOURCE_TYPE_METADATA:
|
||||
if (params || nparams) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("Unexpected parameters for metadata resource"));
|
||||
goto cleanup;
|
||||
}
|
||||
if (VIR_STRDUP(newLockspace, "") < 0 ||
|
||||
VIR_STRDUP(newName, name) < 0)
|
||||
goto cleanup;
|
||||
newFlags |= VIR_LOCK_SPACE_PROTOCOL_ACQUIRE_RESOURCE_METADATA;
|
||||
break;
|
||||
|
||||
case VIR_LOCK_MANAGER_RESOURCE_TYPE_DISK:
|
||||
case VIR_LOCK_MANAGER_RESOURCE_TYPE_LEASE:
|
||||
default:
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("Unknown lock manager object type %d for daemon lock object"),
|
||||
type);
|
||||
goto cleanup;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("Unknown lock manager object type %d"),
|
||||
@ -692,19 +717,15 @@ static int virLockManagerLockDaemonAddResource(virLockManagerPtr lock,
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (flags & VIR_LOCK_MANAGER_RESOURCE_SHARED)
|
||||
newFlags |= VIR_LOCK_SPACE_PROTOCOL_ACQUIRE_RESOURCE_SHARED;
|
||||
|
||||
if (VIR_EXPAND_N(priv->resources, priv->nresources, 1) < 0)
|
||||
goto cleanup;
|
||||
|
||||
VIR_STEAL_PTR(priv->resources[priv->nresources-1].lockspace, newLockspace);
|
||||
VIR_STEAL_PTR(priv->resources[priv->nresources-1].name, newName);
|
||||
|
||||
if (flags & VIR_LOCK_MANAGER_RESOURCE_SHARED)
|
||||
priv->resources[priv->nresources-1].flags |=
|
||||
VIR_LOCK_SPACE_PROTOCOL_ACQUIRE_RESOURCE_SHARED;
|
||||
|
||||
if (autoCreate)
|
||||
priv->resources[priv->nresources-1].flags |=
|
||||
VIR_LOCK_SPACE_PROTOCOL_ACQUIRE_RESOURCE_AUTOCREATE;
|
||||
priv->resources[priv->nresources-1].flags = newFlags;
|
||||
|
||||
ret = 0;
|
||||
cleanup:
|
||||
|
@ -815,7 +815,7 @@ static int virLockManagerSanlockAddResource(virLockManagerPtr lock,
|
||||
if (flags & VIR_LOCK_MANAGER_RESOURCE_READONLY)
|
||||
return 0;
|
||||
|
||||
switch (type) {
|
||||
switch ((virLockManagerResourceType) type) {
|
||||
case VIR_LOCK_MANAGER_RESOURCE_TYPE_DISK:
|
||||
if (driver->autoDiskLease) {
|
||||
if (virLockManagerSanlockAddDisk(driver, lock, name, nparams, params,
|
||||
@ -839,6 +839,7 @@ static int virLockManagerSanlockAddResource(virLockManagerPtr lock,
|
||||
return -1;
|
||||
break;
|
||||
|
||||
case VIR_LOCK_MANAGER_RESOURCE_TYPE_METADATA:
|
||||
default:
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("Unknown lock manager object type %d for domain lock object"),
|
||||
|
Loading…
Reference in New Issue
Block a user