mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-08-30 05:50:08 +03:00
Replace use of virLockError with virReportError
Update the lock manager drivers to use virReportError instead of the virLockError custom macro Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
This commit is contained in:
@ -48,11 +48,6 @@
|
||||
|
||||
#define VIR_FROM_THIS VIR_FROM_LOCKING
|
||||
|
||||
#define virLockError(code, ...) \
|
||||
virReportErrorHelper(VIR_FROM_THIS, code, __FILE__, \
|
||||
__FUNCTION__, __LINE__, __VA_ARGS__)
|
||||
|
||||
|
||||
#define VIR_LOCK_MANAGER_SANLOCK_AUTO_DISK_LOCKSPACE "__LIBVIRT__DISKS__"
|
||||
|
||||
/*
|
||||
@ -111,7 +106,7 @@ static int virLockManagerSanlockLoadConfig(const char *configFile)
|
||||
return -1;
|
||||
|
||||
#define CHECK_TYPE(name,typ) if (p && p->type != (typ)) { \
|
||||
virLockError(VIR_ERR_INTERNAL_ERROR, \
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, \
|
||||
"%s: %s: expected type " #typ, \
|
||||
configFile, (name)); \
|
||||
virConfFree(conf); \
|
||||
@ -167,7 +162,7 @@ static int virLockManagerSanlockSetupLockspace(void)
|
||||
ls.host_id = 0; /* Doesn't matter for initialization */
|
||||
ls.flags = 0;
|
||||
if (!virStrcpy(ls.host_id_disk.path, path, SANLK_PATH_LEN)) {
|
||||
virLockError(VIR_ERR_INTERNAL_ERROR,
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("Lockspace path '%s' exceeded %d characters"),
|
||||
path, SANLK_PATH_LEN);
|
||||
goto error;
|
||||
@ -190,7 +185,7 @@ static int virLockManagerSanlockSetupLockspace(void)
|
||||
} else {
|
||||
if ((rv = sanlock_align(&ls.host_id_disk)) < 0) {
|
||||
if (rv <= -200)
|
||||
virLockError(VIR_ERR_INTERNAL_ERROR,
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("Unable to query sector size %s: error %d"),
|
||||
path, rv);
|
||||
else
|
||||
@ -219,7 +214,7 @@ static int virLockManagerSanlockSetupLockspace(void)
|
||||
|
||||
if ((rv = sanlock_init(&ls, NULL, 0, 0)) < 0) {
|
||||
if (rv <= -200)
|
||||
virLockError(VIR_ERR_INTERNAL_ERROR,
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("Unable to initialize lockspace %s: error %d"),
|
||||
path, rv);
|
||||
else
|
||||
@ -240,7 +235,7 @@ static int virLockManagerSanlockSetupLockspace(void)
|
||||
if ((rv = sanlock_add_lockspace(&ls, 0)) < 0) {
|
||||
if (-rv != EEXIST) {
|
||||
if (rv <= -200)
|
||||
virLockError(VIR_ERR_INTERNAL_ERROR,
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("Unable to add lockspace %s: error %d"),
|
||||
path, rv);
|
||||
else
|
||||
@ -296,7 +291,7 @@ static int virLockManagerSanlockInit(unsigned int version,
|
||||
goto error;
|
||||
|
||||
if (driver->autoDiskLease && !driver->hostID) {
|
||||
virLockError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("Automatic disk lease mode enabled, but no host ID is set"));
|
||||
goto error;
|
||||
}
|
||||
@ -338,13 +333,13 @@ static int virLockManagerSanlockNew(virLockManagerPtr lock,
|
||||
virCheckFlags(0, -1);
|
||||
|
||||
if (!driver) {
|
||||
virLockError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("Sanlock plugin is not initialized"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (type != VIR_LOCK_MANAGER_OBJECT_TYPE_DOMAIN) {
|
||||
virLockError(VIR_ERR_INTERNAL_ERROR,
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("Unsupported object type %d"), type);
|
||||
return -1;
|
||||
}
|
||||
@ -363,7 +358,7 @@ static int virLockManagerSanlockNew(virLockManagerPtr lock,
|
||||
memcpy(priv->vm_uuid, param->value.uuid, 16);
|
||||
} else if (STREQ(param->key, "name")) {
|
||||
if (!virStrcpy(priv->vm_name, param->value.str, SANLK_NAME_LEN)) {
|
||||
virLockError(VIR_ERR_INTERNAL_ERROR,
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("Domain name '%s' exceeded %d characters"),
|
||||
param->value.str, SANLK_NAME_LEN);
|
||||
goto error;
|
||||
@ -409,13 +404,13 @@ static int virLockManagerSanlockDiskLeaseName(const char *path,
|
||||
int i;
|
||||
|
||||
if (strbuflen < ((MD5_DIGEST_SIZE * 2) + 1)) {
|
||||
virLockError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("String length too small to store md5 checksum"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!(md5_buffer(path, strlen(path), buf))) {
|
||||
virLockError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("Unable to compute md5 checksum"));
|
||||
return -1;
|
||||
}
|
||||
@ -447,7 +442,7 @@ static int virLockManagerSanlockAddLease(virLockManagerPtr lock,
|
||||
res->flags = shared ? SANLK_RES_SHARED : 0;
|
||||
res->num_disks = 1;
|
||||
if (!virStrcpy(res->name, name, SANLK_NAME_LEN)) {
|
||||
virLockError(VIR_ERR_INTERNAL_ERROR,
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("Resource name '%s' exceeds %d characters"),
|
||||
name, SANLK_NAME_LEN);
|
||||
goto cleanup;
|
||||
@ -456,7 +451,7 @@ static int virLockManagerSanlockAddLease(virLockManagerPtr lock,
|
||||
for (i = 0; i < nparams; i++) {
|
||||
if (STREQ(params[i].key, "path")) {
|
||||
if (!virStrcpy(res->disks[0].path, params[i].value.str, SANLK_PATH_LEN)) {
|
||||
virLockError(VIR_ERR_INTERNAL_ERROR,
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("Lease path '%s' exceeds %d characters"),
|
||||
params[i].value.str, SANLK_PATH_LEN);
|
||||
goto cleanup;
|
||||
@ -465,7 +460,7 @@ static int virLockManagerSanlockAddLease(virLockManagerPtr lock,
|
||||
res->disks[0].offset = params[i].value.ul;
|
||||
} else if (STREQ(params[i].key, "lockspace")) {
|
||||
if (!virStrcpy(res->lockspace_name, params[i].value.str, SANLK_NAME_LEN)) {
|
||||
virLockError(VIR_ERR_INTERNAL_ERROR,
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("Resource lockspace '%s' exceeds %d characters"),
|
||||
params[i].value.str, SANLK_NAME_LEN);
|
||||
goto cleanup;
|
||||
@ -499,7 +494,7 @@ static int virLockManagerSanlockAddDisk(virLockManagerPtr lock,
|
||||
char *path = NULL;
|
||||
|
||||
if (nparams) {
|
||||
virLockError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("Unexpected lock parameters for disk resource"));
|
||||
return -1;
|
||||
}
|
||||
@ -520,7 +515,7 @@ static int virLockManagerSanlockAddDisk(virLockManagerPtr lock,
|
||||
goto cleanup;
|
||||
}
|
||||
if (!virStrcpy(res->disks[0].path, path, SANLK_PATH_LEN)) {
|
||||
virLockError(VIR_ERR_INTERNAL_ERROR,
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("Lease path '%s' exceeds %d characters"),
|
||||
path, SANLK_PATH_LEN);
|
||||
goto cleanup;
|
||||
@ -529,7 +524,7 @@ static int virLockManagerSanlockAddDisk(virLockManagerPtr lock,
|
||||
if (!virStrcpy(res->lockspace_name,
|
||||
VIR_LOCK_MANAGER_SANLOCK_AUTO_DISK_LOCKSPACE,
|
||||
SANLK_NAME_LEN)) {
|
||||
virLockError(VIR_ERR_INTERNAL_ERROR,
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("Resource lockspace '%s' exceeds %d characters"),
|
||||
VIR_LOCK_MANAGER_SANLOCK_AUTO_DISK_LOCKSPACE, SANLK_NAME_LEN);
|
||||
goto cleanup;
|
||||
@ -567,7 +562,7 @@ static int virLockManagerSanlockCreateLease(struct sanlk_resource *res)
|
||||
} else {
|
||||
if ((rv = sanlock_align(&res->disks[0])) < 0) {
|
||||
if (rv <= -200)
|
||||
virLockError(VIR_ERR_INTERNAL_ERROR,
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("Unable to query sector size %s: error %d"),
|
||||
res->disks[0].path, rv);
|
||||
else
|
||||
@ -596,7 +591,7 @@ static int virLockManagerSanlockCreateLease(struct sanlk_resource *res)
|
||||
|
||||
if ((rv = sanlock_init(NULL, res, 0, 0)) < 0) {
|
||||
if (rv <= -200)
|
||||
virLockError(VIR_ERR_INTERNAL_ERROR,
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("Unable to initialize lease %s: error %d"),
|
||||
res->disks[0].path, rv);
|
||||
else
|
||||
@ -631,7 +626,7 @@ static int virLockManagerSanlockAddResource(virLockManagerPtr lock,
|
||||
VIR_LOCK_MANAGER_RESOURCE_SHARED, -1);
|
||||
|
||||
if (priv->res_count == SANLK_MAX_RESOURCES) {
|
||||
virLockError(VIR_ERR_INTERNAL_ERROR,
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("Too many resources %d for object"),
|
||||
SANLK_MAX_RESOURCES);
|
||||
return -1;
|
||||
@ -692,7 +687,7 @@ static int virLockManagerSanlockAcquire(virLockManagerPtr lock,
|
||||
if (priv->res_count == 0 &&
|
||||
priv->hasRWDisks &&
|
||||
driver->requireLeaseForDisks) {
|
||||
virLockError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
||||
_("Read/write, exclusive access, disks were present, but no leases specified"));
|
||||
return -1;
|
||||
}
|
||||
@ -703,7 +698,7 @@ static int virLockManagerSanlockAcquire(virLockManagerPtr lock,
|
||||
}
|
||||
|
||||
if (!virStrcpy(opt->owner_name, priv->vm_name, SANLK_NAME_LEN)) {
|
||||
virLockError(VIR_ERR_INTERNAL_ERROR,
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("Domain name '%s' exceeded %d characters"),
|
||||
priv->vm_name, SANLK_NAME_LEN);
|
||||
goto error;
|
||||
@ -714,7 +709,7 @@ static int virLockManagerSanlockAcquire(virLockManagerPtr lock,
|
||||
&res_count,
|
||||
&res_args)) < 0) {
|
||||
if (rv <= -200)
|
||||
virLockError(VIR_ERR_INTERNAL_ERROR,
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("Unable to parse lock state %s: error %d"),
|
||||
state, rv);
|
||||
else
|
||||
@ -739,7 +734,7 @@ static int virLockManagerSanlockAcquire(virLockManagerPtr lock,
|
||||
if (priv->vm_pid == getpid() &&
|
||||
(sock = sanlock_register()) < 0) {
|
||||
if (sock <= -200)
|
||||
virLockError(VIR_ERR_INTERNAL_ERROR,
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("Failed to open socket to sanlock daemon: error %d"),
|
||||
sock);
|
||||
else
|
||||
@ -754,7 +749,7 @@ static int virLockManagerSanlockAcquire(virLockManagerPtr lock,
|
||||
priv->res_count, priv->res_args,
|
||||
opt)) < 0) {
|
||||
if (rv <= -200)
|
||||
virLockError(VIR_ERR_INTERNAL_ERROR,
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("Failed to acquire lock: error %d"), rv);
|
||||
else
|
||||
virReportSystemError(-rv, "%s",
|
||||
@ -778,7 +773,7 @@ static int virLockManagerSanlockAcquire(virLockManagerPtr lock,
|
||||
if (flags & VIR_LOCK_MANAGER_ACQUIRE_RESTRICT) {
|
||||
if ((rv = sanlock_restrict(sock, SANLK_RESTRICT_ALL)) < 0) {
|
||||
if (rv <= -200)
|
||||
virLockError(VIR_ERR_INTERNAL_ERROR,
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("Failed to restrict process: error %d"), rv);
|
||||
else
|
||||
virReportSystemError(-rv, "%s",
|
||||
@ -827,7 +822,7 @@ static int virLockManagerSanlockRelease(virLockManagerPtr lock,
|
||||
if (state) {
|
||||
if ((rv = sanlock_inquire(-1, priv->vm_pid, 0, &res_count, state)) < 0) {
|
||||
if (rv <= -200)
|
||||
virLockError(VIR_ERR_INTERNAL_ERROR,
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("Failed to inquire lock: error %d"), rv);
|
||||
else
|
||||
virReportSystemError(-rv, "%s",
|
||||
@ -841,7 +836,7 @@ static int virLockManagerSanlockRelease(virLockManagerPtr lock,
|
||||
|
||||
if ((rv = sanlock_release(-1, priv->vm_pid, SANLK_REL_ALL, 0, NULL)) < 0) {
|
||||
if (rv <= -200)
|
||||
virLockError(VIR_ERR_INTERNAL_ERROR,
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("Failed to release lock: error %d"), rv);
|
||||
else
|
||||
virReportSystemError(-rv, "%s",
|
||||
@ -862,7 +857,7 @@ static int virLockManagerSanlockInquire(virLockManagerPtr lock,
|
||||
virCheckFlags(0, -1);
|
||||
|
||||
if (!state) {
|
||||
virLockError(VIR_ERR_INVALID_ARG, __FUNCTION__);
|
||||
virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -870,7 +865,7 @@ static int virLockManagerSanlockInquire(virLockManagerPtr lock,
|
||||
|
||||
if ((rv = sanlock_inquire(-1, priv->vm_pid, 0, &res_count, state)) < 0) {
|
||||
if (rv <= -200)
|
||||
virLockError(VIR_ERR_INTERNAL_ERROR,
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("Failed to inquire lock: error %d"), rv);
|
||||
else
|
||||
virReportSystemError(-rv, "%s",
|
||||
|
@ -39,13 +39,9 @@
|
||||
|
||||
#define VIR_FROM_THIS VIR_FROM_LOCKING
|
||||
|
||||
#define virLockError(code, ...) \
|
||||
virReportErrorHelper(VIR_FROM_THIS, code, __FILE__, \
|
||||
__FUNCTION__, __LINE__, __VA_ARGS__)
|
||||
|
||||
#define CHECK_PLUGIN(field, errret) \
|
||||
if (!plugin->driver->field) { \
|
||||
virLockError(VIR_ERR_INTERNAL_ERROR, \
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, \
|
||||
_("Missing '%s' field in lock manager driver"), \
|
||||
#field); \
|
||||
return errret; \
|
||||
@ -53,7 +49,7 @@
|
||||
|
||||
#define CHECK_MANAGER(field, errret) \
|
||||
if (!lock->driver->field) { \
|
||||
virLockError(VIR_ERR_INTERNAL_ERROR, \
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, \
|
||||
_("Missing '%s' field in lock manager driver"), \
|
||||
#field); \
|
||||
return errret; \
|
||||
@ -150,14 +146,14 @@ virLockManagerPluginPtr virLockManagerPluginNew(const char *name,
|
||||
|
||||
handle = dlopen(modfile, RTLD_NOW | RTLD_LOCAL);
|
||||
if (!handle) {
|
||||
virLockError(VIR_ERR_SYSTEM_ERROR,
|
||||
virReportError(VIR_ERR_SYSTEM_ERROR,
|
||||
_("Failed to load plugin %s: %s"),
|
||||
modfile, dlerror());
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (!(driver = dlsym(handle, "virLockDriverImpl"))) {
|
||||
virLockError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("Missing plugin initialization symbol 'virLockDriverImpl'"));
|
||||
goto cleanup;
|
||||
}
|
||||
@ -195,7 +191,7 @@ virLockManagerPluginNew(const char *name ATTRIBUTE_UNUSED,
|
||||
const char *configFile ATTRIBUTE_UNUSED,
|
||||
unsigned int flags_unused ATTRIBUTE_UNUSED)
|
||||
{
|
||||
virLockError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("this platform is missing dlopen"));
|
||||
return NULL;
|
||||
}
|
||||
|
Reference in New Issue
Block a user