2011-01-24 12:16:30 +00:00
|
|
|
/*
|
|
|
|
* domain_lock.c: Locking for domain lifecycle operations
|
|
|
|
*
|
2014-03-17 20:23:08 +00:00
|
|
|
* Copyright (C) 2010-2014 Red Hat, Inc.
|
2011-01-24 12:16:30 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2012-09-20 22:30:55 +00:00
|
|
|
* License along with this library. If not, see
|
2012-07-21 10:06:23 +00:00
|
|
|
* <http://www.gnu.org/licenses/>.
|
2011-01-24 12:16:30 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "domain_lock.h"
|
2012-12-12 18:06:53 +00:00
|
|
|
#include "viralloc.h"
|
2012-12-13 18:01:25 +00:00
|
|
|
#include "viruuid.h"
|
2012-12-13 18:21:53 +00:00
|
|
|
#include "virerror.h"
|
2012-12-12 17:59:27 +00:00
|
|
|
#include "virlog.h"
|
2011-01-24 12:16:30 +00:00
|
|
|
|
|
|
|
#define VIR_FROM_THIS VIR_FROM_LOCKING
|
|
|
|
|
2014-02-28 12:16:17 +00:00
|
|
|
VIR_LOG_INIT("locking.domain_lock");
|
|
|
|
|
2011-01-24 12:16:30 +00:00
|
|
|
|
|
|
|
static int virDomainLockManagerAddLease(virLockManagerPtr lock,
|
|
|
|
virDomainLeaseDefPtr lease)
|
|
|
|
{
|
|
|
|
unsigned int leaseFlags = 0;
|
|
|
|
virLockManagerParam lparams[] = {
|
|
|
|
{ .type = VIR_LOCK_MANAGER_PARAM_TYPE_STRING,
|
|
|
|
.key = "path",
|
|
|
|
.value = { .str = lease->path },
|
|
|
|
},
|
|
|
|
{ .type = VIR_LOCK_MANAGER_PARAM_TYPE_ULONG,
|
|
|
|
.key = "offset",
|
|
|
|
.value = { .ul = lease->offset },
|
|
|
|
},
|
|
|
|
{ .type = VIR_LOCK_MANAGER_PARAM_TYPE_STRING,
|
|
|
|
.key = "lockspace",
|
|
|
|
.value = { .str = lease->lockspace },
|
|
|
|
},
|
|
|
|
};
|
|
|
|
size_t nparams = ARRAY_CARDINALITY(lparams);
|
|
|
|
if (!lease->lockspace)
|
|
|
|
nparams--;
|
|
|
|
|
|
|
|
VIR_DEBUG("Add lease %s", lease->path);
|
|
|
|
if (virLockManagerAddResource(lock,
|
|
|
|
VIR_LOCK_MANAGER_RESOURCE_TYPE_LEASE,
|
|
|
|
lease->key,
|
|
|
|
nparams,
|
|
|
|
lparams,
|
|
|
|
leaseFlags) < 0) {
|
|
|
|
VIR_DEBUG("Failed to add lease %s", lease->path);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-06-23 13:16:46 +00:00
|
|
|
static int virDomainLockManagerAddImage(virLockManagerPtr lock,
|
|
|
|
virStorageSourcePtr src)
|
2011-01-24 12:16:30 +00:00
|
|
|
{
|
|
|
|
unsigned int diskFlags = 0;
|
2014-06-23 13:16:46 +00:00
|
|
|
int type = virStorageSourceGetActualType(src);
|
2014-03-17 20:23:08 +00:00
|
|
|
|
2014-06-23 13:16:46 +00:00
|
|
|
if (!src->path)
|
2011-01-24 12:16:30 +00:00
|
|
|
return 0;
|
|
|
|
|
conf: move host disk type to util/
A continuation of the migration of disk details to virstoragefile.
This patch moves a single enum, but converting the name has quite
a bit of fallout.
* src/conf/domain_conf.h (virDomainDiskType): Move...
* src/util/virstoragefile.h (virStorageType): ...and rename.
* src/bhyve/bhyve_command.c (bhyveBuildDiskArgStr)
(virBhyveProcessBuildLoadCmd): Update clients.
* src/conf/domain_conf.c (virDomainDiskSourceDefParse)
(virDomainDiskDefParseXML, virDomainDiskSourceDefFormatInternal)
(virDomainDiskDefFormat, virDomainDiskGetActualType)
(virDomainDiskDefForeachPath, virDomainDiskSourceIsBlockType):
Likewise.
* src/conf/snapshot_conf.h (_virDomainSnapshotDiskDef): Likewise.
* src/conf/snapshot_conf.c (virDomainSnapshotDiskDefParseXML)
(virDomainSnapshotAlignDisks, virDomainSnapshotDiskDefFormat):
Likewise.
* src/esx/esx_driver.c (esxAutodetectSCSIControllerModel)
(esxDomainDefineXML): Likewise.
* src/locking/domain_lock.c (virDomainLockManagerAddDisk):
Likewise.
* src/lxc/lxc_controller.c
(virLXCControllerSetupLoopDeviceDisk)
(virLXCControllerSetupNBDDeviceDisk)
(virLXCControllerSetupLoopDevices, virLXCControllerSetupDisk):
Likewise.
* src/parallels/parallels_driver.c (parallelsGetHddInfo):
Likewise.
* src/phyp/phyp_driver.c (phypDiskType): Likewise.
* src/qemu/qemu_command.c (qemuGetDriveSourceString)
(qemuDomainDiskGetSourceString, qemuBuildDriveStr)
(qemuBuildCommandLine, qemuParseCommandLineDisk)
(qemuParseCommandLine): Likewise.
* src/qemu/qemu_conf.c (qemuCheckSharedDevice)
(qemuTranslateDiskSourcePool)
(qemuTranslateSnapshotDiskSourcePool): Likewise.
* src/qemu/qemu_domain.c (qemuDomainDeviceDefPostParse)
(qemuDomainDetermineDiskChain): Likewise.
* src/qemu/qemu_driver.c (qemuDomainGetBlockInfo)
(qemuDomainSnapshotPrepareDiskExternalBackingInactive)
(qemuDomainSnapshotPrepareDiskExternalBackingActive)
(qemuDomainSnapshotPrepareDiskExternalOverlayActive)
(qemuDomainSnapshotPrepareDiskExternalOverlayInactive)
(qemuDomainSnapshotPrepareDiskInternal)
(qemuDomainSnapshotPrepare)
(qemuDomainSnapshotCreateSingleDiskActive): Likewise.
* src/qemu/qemu_hotplug.c (qemuDomainChangeEjectableMedia):
Likewise.
* src/qemu/qemu_migration.c (qemuMigrationIsSafe): Likewise.
* src/security/security_apparmor.c
(AppArmorRestoreSecurityImageLabel)
(AppArmorSetSecurityImageLabel): Likewise.
* src/security/security_dac.c (virSecurityDACSetSecurityImageLabel)
(virSecurityDACRestoreSecurityImageLabelInt)
(virSecurityDACSetSecurityAllLabel): Likewise.
* src/security/security_selinux.c
(virSecuritySELinuxRestoreSecurityImageLabelInt)
(virSecuritySELinuxSetSecurityImageLabel)
(virSecuritySELinuxSetSecurityAllLabel): Likewise.
* src/storage/storage_backend.c (virStorageFileBackendForType):
Likewise.
* src/storage/storage_backend_fs.c (virStorageFileBackendFile)
(virStorageFileBackendBlock): Likewise.
* src/storage/storage_backend_gluster.c
(virStorageFileBackendGluster): Likewise.
* src/vbox/vbox_tmpl.c (vboxDomainGetXMLDesc, vboxAttachDrives)
(vboxDomainAttachDeviceImpl, vboxDomainDetachDevice): Likewise.
* src/vmware/vmware_conf.c (vmwareVmxPath): Likewise.
* src/vmx/vmx.c (virVMXParseDisk, virVMXFormatDisk)
(virVMXFormatFloppy): Likewise.
* src/xenxs/xen_sxpr.c (xenParseSxprDisks, xenParseSxpr)
(xenFormatSxprDisk): Likewise.
* src/xenxs/xen_xm.c (xenParseXM, xenFormatXMDisk): Likewise.
* tests/securityselinuxlabeltest.c (testSELinuxLoadDef):
Likewise.
* src/libvirt_private.syms (domain_conf.h): Move symbols...
(virstoragefile.h): ...as appropriate.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-03-27 21:57:49 +00:00
|
|
|
if (!(type == VIR_STORAGE_TYPE_BLOCK ||
|
|
|
|
type == VIR_STORAGE_TYPE_FILE ||
|
|
|
|
type == VIR_STORAGE_TYPE_DIR))
|
2011-01-24 12:16:30 +00:00
|
|
|
return 0;
|
|
|
|
|
2014-06-23 13:16:46 +00:00
|
|
|
if (src->readonly)
|
2011-01-24 12:16:30 +00:00
|
|
|
diskFlags |= VIR_LOCK_MANAGER_RESOURCE_READONLY;
|
2014-06-23 13:16:46 +00:00
|
|
|
if (src->shared)
|
2011-01-24 12:16:30 +00:00
|
|
|
diskFlags |= VIR_LOCK_MANAGER_RESOURCE_SHARED;
|
|
|
|
|
2014-06-23 13:16:46 +00:00
|
|
|
VIR_DEBUG("Add disk %s", src->path);
|
2011-01-24 12:16:30 +00:00
|
|
|
if (virLockManagerAddResource(lock,
|
|
|
|
VIR_LOCK_MANAGER_RESOURCE_TYPE_DISK,
|
2014-06-23 13:16:46 +00:00
|
|
|
src->path,
|
2011-01-24 12:16:30 +00:00
|
|
|
0,
|
|
|
|
NULL,
|
|
|
|
diskFlags) < 0) {
|
2014-06-23 13:16:46 +00:00
|
|
|
VIR_DEBUG("Failed add disk %s", src->path);
|
2011-01-24 12:16:30 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-06-23 13:16:46 +00:00
|
|
|
|
2011-01-24 12:16:30 +00:00
|
|
|
static virLockManagerPtr virDomainLockManagerNew(virLockManagerPluginPtr plugin,
|
2012-09-17 13:36:47 +00:00
|
|
|
const char *uri,
|
2011-01-24 12:16:30 +00:00
|
|
|
virDomainObjPtr dom,
|
2015-03-06 14:58:55 +00:00
|
|
|
bool withResources,
|
|
|
|
unsigned int flags)
|
2011-01-24 12:16:30 +00:00
|
|
|
{
|
|
|
|
virLockManagerPtr lock;
|
Convert 'int i' to 'size_t i' in src/locking/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
size_t i;
|
2011-01-24 12:16:30 +00:00
|
|
|
virLockManagerParam params[] = {
|
|
|
|
{ .type = VIR_LOCK_MANAGER_PARAM_TYPE_UUID,
|
|
|
|
.key = "uuid",
|
|
|
|
},
|
|
|
|
{ .type = VIR_LOCK_MANAGER_PARAM_TYPE_STRING,
|
|
|
|
.key = "name",
|
|
|
|
.value = { .str = dom->def->name },
|
|
|
|
},
|
|
|
|
{ .type = VIR_LOCK_MANAGER_PARAM_TYPE_UINT,
|
|
|
|
.key = "id",
|
Convert 'int i' to 'size_t i' in src/locking/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
.value = { .iv = dom->def->id },
|
2011-01-24 12:16:30 +00:00
|
|
|
},
|
|
|
|
{ .type = VIR_LOCK_MANAGER_PARAM_TYPE_UINT,
|
|
|
|
.key = "pid",
|
Convert 'int i' to 'size_t i' in src/locking/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
.value = { .iv = dom->pid },
|
2011-01-24 12:16:30 +00:00
|
|
|
},
|
2012-09-17 13:36:47 +00:00
|
|
|
{ .type = VIR_LOCK_MANAGER_PARAM_TYPE_CSTRING,
|
|
|
|
.key = "uri",
|
|
|
|
.value = { .cstr = uri },
|
|
|
|
},
|
2011-01-24 12:16:30 +00:00
|
|
|
};
|
|
|
|
VIR_DEBUG("plugin=%p dom=%p withResources=%d",
|
|
|
|
plugin, dom, withResources);
|
|
|
|
|
|
|
|
memcpy(params[0].value.uuid, dom->def->uuid, VIR_UUID_BUFLEN);
|
|
|
|
|
2011-07-06 16:15:54 +00:00
|
|
|
if (!(lock = virLockManagerNew(virLockManagerPluginGetDriver(plugin),
|
2011-01-24 12:16:30 +00:00
|
|
|
VIR_LOCK_MANAGER_OBJECT_TYPE_DOMAIN,
|
|
|
|
ARRAY_CARDINALITY(params),
|
|
|
|
params,
|
2015-03-06 14:58:55 +00:00
|
|
|
flags)))
|
2011-01-24 12:16:30 +00:00
|
|
|
goto error;
|
|
|
|
|
|
|
|
if (withResources) {
|
|
|
|
VIR_DEBUG("Adding leases");
|
2013-05-21 08:06:00 +00:00
|
|
|
for (i = 0; i < dom->def->nleases; i++)
|
2011-01-24 12:16:30 +00:00
|
|
|
if (virDomainLockManagerAddLease(lock, dom->def->leases[i]) < 0)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
VIR_DEBUG("Adding disks");
|
2014-06-23 13:16:46 +00:00
|
|
|
for (i = 0; i < dom->def->ndisks; i++) {
|
|
|
|
virDomainDiskDefPtr disk = dom->def->disks[i];
|
|
|
|
|
|
|
|
if (virDomainLockManagerAddImage(lock, disk->src) < 0)
|
2011-01-24 12:16:30 +00:00
|
|
|
goto error;
|
2014-06-23 13:16:46 +00:00
|
|
|
}
|
2011-01-24 12:16:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return lock;
|
|
|
|
|
2014-03-25 06:51:47 +00:00
|
|
|
error:
|
2011-01-24 12:16:30 +00:00
|
|
|
virLockManagerFree(lock);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int virDomainLockProcessStart(virLockManagerPluginPtr plugin,
|
2012-09-17 13:36:47 +00:00
|
|
|
const char *uri,
|
2011-01-24 12:16:30 +00:00
|
|
|
virDomainObjPtr dom,
|
2011-06-24 14:14:41 +00:00
|
|
|
bool paused,
|
|
|
|
int *fd)
|
2011-01-24 12:16:30 +00:00
|
|
|
{
|
2011-06-14 08:05:54 +00:00
|
|
|
virLockManagerPtr lock;
|
2011-01-24 12:16:30 +00:00
|
|
|
int ret;
|
2011-06-02 10:46:56 +00:00
|
|
|
int flags = VIR_LOCK_MANAGER_ACQUIRE_RESTRICT;
|
|
|
|
|
2012-08-07 11:08:28 +00:00
|
|
|
VIR_DEBUG("plugin=%p dom=%p paused=%d fd=%p",
|
|
|
|
plugin, dom, paused, fd);
|
|
|
|
|
2015-03-06 14:58:55 +00:00
|
|
|
if (!(lock = virDomainLockManagerNew(plugin, uri, dom, true,
|
|
|
|
VIR_LOCK_MANAGER_NEW_STARTED)))
|
2011-06-14 08:05:54 +00:00
|
|
|
return -1;
|
|
|
|
|
2011-01-24 12:16:30 +00:00
|
|
|
if (paused)
|
2011-06-02 10:46:56 +00:00
|
|
|
flags |= VIR_LOCK_MANAGER_ACQUIRE_REGISTER_ONLY;
|
|
|
|
|
2012-09-18 11:40:13 +00:00
|
|
|
ret = virLockManagerAcquire(lock, NULL, flags,
|
|
|
|
dom->def->onLockFailure, fd);
|
2011-01-24 12:16:30 +00:00
|
|
|
|
|
|
|
virLockManagerFree(lock);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int virDomainLockProcessPause(virLockManagerPluginPtr plugin,
|
|
|
|
virDomainObjPtr dom,
|
|
|
|
char **state)
|
|
|
|
{
|
2011-06-14 08:05:54 +00:00
|
|
|
virLockManagerPtr lock;
|
|
|
|
int ret;
|
|
|
|
|
2012-08-07 11:08:28 +00:00
|
|
|
VIR_DEBUG("plugin=%p dom=%p state=%p",
|
|
|
|
plugin, dom, state);
|
|
|
|
|
2015-03-06 14:58:55 +00:00
|
|
|
if (!(lock = virDomainLockManagerNew(plugin, NULL, dom, true, 0)))
|
2011-06-14 08:05:54 +00:00
|
|
|
return -1;
|
2011-01-24 12:16:30 +00:00
|
|
|
|
2011-06-14 08:05:54 +00:00
|
|
|
ret = virLockManagerRelease(lock, state, 0);
|
2011-01-24 12:16:30 +00:00
|
|
|
virLockManagerFree(lock);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int virDomainLockProcessResume(virLockManagerPluginPtr plugin,
|
2012-09-17 13:36:47 +00:00
|
|
|
const char *uri,
|
2011-01-24 12:16:30 +00:00
|
|
|
virDomainObjPtr dom,
|
|
|
|
const char *state)
|
|
|
|
{
|
2011-06-14 08:05:54 +00:00
|
|
|
virLockManagerPtr lock;
|
|
|
|
int ret;
|
|
|
|
|
2012-08-07 11:08:28 +00:00
|
|
|
VIR_DEBUG("plugin=%p dom=%p state=%s",
|
|
|
|
plugin, dom, NULLSTR(state));
|
|
|
|
|
2015-03-06 14:58:55 +00:00
|
|
|
if (!(lock = virDomainLockManagerNew(plugin, uri, dom, true, 0)))
|
2011-06-14 08:05:54 +00:00
|
|
|
return -1;
|
2011-01-24 12:16:30 +00:00
|
|
|
|
2012-09-18 11:40:13 +00:00
|
|
|
ret = virLockManagerAcquire(lock, state, 0, dom->def->onLockFailure, NULL);
|
2011-01-24 12:16:30 +00:00
|
|
|
virLockManagerFree(lock);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int virDomainLockProcessInquire(virLockManagerPluginPtr plugin,
|
|
|
|
virDomainObjPtr dom,
|
|
|
|
char **state)
|
|
|
|
{
|
2011-06-14 08:05:54 +00:00
|
|
|
virLockManagerPtr lock;
|
|
|
|
int ret;
|
2011-01-24 12:16:30 +00:00
|
|
|
|
2012-08-07 11:08:28 +00:00
|
|
|
VIR_DEBUG("plugin=%p dom=%p state=%p",
|
|
|
|
plugin, dom, state);
|
|
|
|
|
2015-03-06 14:58:55 +00:00
|
|
|
if (!(lock = virDomainLockManagerNew(plugin, NULL, dom, true, 0)))
|
2011-06-14 08:05:54 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
ret = virLockManagerInquire(lock, state, 0);
|
2011-01-24 12:16:30 +00:00
|
|
|
virLockManagerFree(lock);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-06-23 13:16:46 +00:00
|
|
|
int virDomainLockImageAttach(virLockManagerPluginPtr plugin,
|
|
|
|
const char *uri,
|
|
|
|
virDomainObjPtr dom,
|
|
|
|
virStorageSourcePtr src)
|
2011-01-24 12:16:30 +00:00
|
|
|
{
|
2011-06-14 08:05:54 +00:00
|
|
|
virLockManagerPtr lock;
|
2011-01-24 12:16:30 +00:00
|
|
|
int ret = -1;
|
|
|
|
|
2014-06-23 13:16:46 +00:00
|
|
|
VIR_DEBUG("plugin=%p dom=%p src=%p", plugin, dom, src);
|
2012-08-07 11:08:28 +00:00
|
|
|
|
2015-03-06 14:58:55 +00:00
|
|
|
if (!(lock = virDomainLockManagerNew(plugin, uri, dom, false, 0)))
|
2011-06-14 08:05:54 +00:00
|
|
|
return -1;
|
|
|
|
|
2014-06-23 13:16:46 +00:00
|
|
|
if (virDomainLockManagerAddImage(lock, src) < 0)
|
2011-01-24 12:16:30 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2012-09-18 11:40:13 +00:00
|
|
|
if (virLockManagerAcquire(lock, NULL, 0,
|
|
|
|
dom->def->onLockFailure, NULL) < 0)
|
2011-01-24 12:16:30 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2011-06-02 13:43:20 +00:00
|
|
|
ret = 0;
|
|
|
|
|
2014-03-25 06:51:47 +00:00
|
|
|
cleanup:
|
2011-01-24 12:16:30 +00:00
|
|
|
virLockManagerFree(lock);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-06-23 13:16:46 +00:00
|
|
|
|
|
|
|
int virDomainLockDiskAttach(virLockManagerPluginPtr plugin,
|
|
|
|
const char *uri,
|
2011-01-24 12:16:30 +00:00
|
|
|
virDomainObjPtr dom,
|
|
|
|
virDomainDiskDefPtr disk)
|
2014-06-23 13:16:46 +00:00
|
|
|
{
|
|
|
|
return virDomainLockImageAttach(plugin, uri, dom, disk->src);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int virDomainLockImageDetach(virLockManagerPluginPtr plugin,
|
|
|
|
virDomainObjPtr dom,
|
|
|
|
virStorageSourcePtr src)
|
2011-01-24 12:16:30 +00:00
|
|
|
{
|
2011-06-14 08:05:54 +00:00
|
|
|
virLockManagerPtr lock;
|
2011-01-24 12:16:30 +00:00
|
|
|
int ret = -1;
|
|
|
|
|
2014-06-23 13:16:46 +00:00
|
|
|
VIR_DEBUG("plugin=%p dom=%p src=%p", plugin, dom, src);
|
2012-08-07 11:08:28 +00:00
|
|
|
|
2015-03-06 14:58:55 +00:00
|
|
|
if (!(lock = virDomainLockManagerNew(plugin, NULL, dom, false, 0)))
|
2011-06-14 08:05:54 +00:00
|
|
|
return -1;
|
|
|
|
|
2014-06-23 13:16:46 +00:00
|
|
|
if (virDomainLockManagerAddImage(lock, src) < 0)
|
2011-01-24 12:16:30 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (virLockManagerRelease(lock, NULL, 0) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2011-06-02 13:43:20 +00:00
|
|
|
ret = 0;
|
|
|
|
|
2014-03-25 06:51:47 +00:00
|
|
|
cleanup:
|
2011-01-24 12:16:30 +00:00
|
|
|
virLockManagerFree(lock);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-06-23 13:16:46 +00:00
|
|
|
int virDomainLockDiskDetach(virLockManagerPluginPtr plugin,
|
|
|
|
virDomainObjPtr dom,
|
|
|
|
virDomainDiskDefPtr disk)
|
|
|
|
{
|
|
|
|
return virDomainLockImageDetach(plugin, dom, disk->src);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-24 12:16:30 +00:00
|
|
|
int virDomainLockLeaseAttach(virLockManagerPluginPtr plugin,
|
2012-09-17 13:36:47 +00:00
|
|
|
const char *uri,
|
2011-01-24 12:16:30 +00:00
|
|
|
virDomainObjPtr dom,
|
|
|
|
virDomainLeaseDefPtr lease)
|
|
|
|
{
|
2011-06-14 08:05:54 +00:00
|
|
|
virLockManagerPtr lock;
|
2011-01-24 12:16:30 +00:00
|
|
|
int ret = -1;
|
|
|
|
|
2012-08-07 11:08:28 +00:00
|
|
|
VIR_DEBUG("plugin=%p dom=%p lease=%p",
|
|
|
|
plugin, dom, lease);
|
|
|
|
|
2015-03-06 14:58:55 +00:00
|
|
|
if (!(lock = virDomainLockManagerNew(plugin, uri, dom, false, 0)))
|
2011-06-14 08:05:54 +00:00
|
|
|
return -1;
|
|
|
|
|
2011-01-24 12:16:30 +00:00
|
|
|
if (virDomainLockManagerAddLease(lock, lease) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2012-09-18 11:40:13 +00:00
|
|
|
if (virLockManagerAcquire(lock, NULL, 0,
|
|
|
|
dom->def->onLockFailure, NULL) < 0)
|
2011-01-24 12:16:30 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2011-06-02 13:43:20 +00:00
|
|
|
ret = 0;
|
|
|
|
|
2014-03-25 06:51:47 +00:00
|
|
|
cleanup:
|
2011-01-24 12:16:30 +00:00
|
|
|
virLockManagerFree(lock);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int virDomainLockLeaseDetach(virLockManagerPluginPtr plugin,
|
|
|
|
virDomainObjPtr dom,
|
|
|
|
virDomainLeaseDefPtr lease)
|
|
|
|
{
|
2011-06-14 08:05:54 +00:00
|
|
|
virLockManagerPtr lock;
|
2011-01-24 12:16:30 +00:00
|
|
|
int ret = -1;
|
|
|
|
|
2012-08-07 11:08:28 +00:00
|
|
|
VIR_DEBUG("plugin=%p dom=%p lease=%p",
|
|
|
|
plugin, dom, lease);
|
|
|
|
|
2015-03-06 14:58:55 +00:00
|
|
|
if (!(lock = virDomainLockManagerNew(plugin, NULL, dom, false, 0)))
|
2011-06-14 08:05:54 +00:00
|
|
|
return -1;
|
|
|
|
|
2011-01-24 12:16:30 +00:00
|
|
|
if (virDomainLockManagerAddLease(lock, lease) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (virLockManagerRelease(lock, NULL, 0) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2011-06-02 13:43:20 +00:00
|
|
|
ret = 0;
|
|
|
|
|
2014-03-25 06:51:47 +00:00
|
|
|
cleanup:
|
2011-01-24 12:16:30 +00:00
|
|
|
virLockManagerFree(lock);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|