sanlock: Truncate domain names longer than SANLK_NAME_LEN

Libvirt uses a domain name to fill in owner_name in sanlock_options in
virLockManagerSanlockAcquire. Unfortunately, owner_name is limited to
SANLK_NAME_LEN characters (including trailing '\0'), which means domains
with longer names fail to start when sanlock is enabled. However, we can
truncate the name when setting owner_name as explained by sanlock's
author:

Setting sanlk_options or the owner_name is unnecessary, and has very
little to no benefit.  If you do provide something in owner_name, it can
be anything, sanlock doesn't care or use it.

If you run the command "sanlock status", the output will display a list
of clients connected to the sanlock daemon.  This client list is
displayed as "pid owner_name" if the client has provided an owner_name
via sanlk_options. This debugging output is the only usage of
owner_name, so its only benefit is to potentially provide a more human
friendly output for debugging purposes.
This commit is contained in:
Jiri Denemark 2014-02-27 09:32:41 +01:00
parent b88606ec4f
commit 8f10c1e77f

View File

@ -81,7 +81,7 @@ static virLockManagerSanlockDriver *driver = NULL;
struct _virLockManagerSanlockPrivate {
const char *vm_uri;
char vm_name[SANLK_NAME_LEN];
char *vm_name;
unsigned char vm_uuid[VIR_UUID_BUFLEN];
unsigned int vm_id;
unsigned int vm_pid;
@ -474,12 +474,8 @@ static int virLockManagerSanlockNew(virLockManagerPtr lock,
if (STREQ(param->key, "uuid")) {
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)) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Domain name '%s' exceeded %d characters"),
param->value.str, SANLK_NAME_LEN);
if (VIR_STRDUP(priv->vm_name, param->value.str) < 0)
goto error;
}
} else if (STREQ(param->key, "pid")) {
priv->vm_pid = param->value.ui;
} else if (STREQ(param->key, "id")) {
@ -505,6 +501,7 @@ static void virLockManagerSanlockFree(virLockManagerPtr lock)
if (!priv)
return;
VIR_FREE(priv->vm_name);
for (i = 0; i < priv->res_count; i++)
VIR_FREE(priv->res_args[i]);
VIR_FREE(priv);
@ -909,12 +906,10 @@ static int virLockManagerSanlockAcquire(virLockManagerPtr lock,
if (VIR_ALLOC(opt) < 0)
return -1;
if (!virStrcpy(opt->owner_name, priv->vm_name, SANLK_NAME_LEN)) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Domain name '%s' exceeded %d characters"),
priv->vm_name, SANLK_NAME_LEN);
goto error;
}
/* sanlock doesn't use owner_name for anything, so it's safe to take just
* the first SANLK_NAME_LEN - 1 characters from vm_name */
ignore_value(virStrncpy(opt->owner_name, priv->vm_name,
SANLK_NAME_LEN - 1, SANLK_NAME_LEN));
if (state && STRNEQ(state, "")) {
if ((rv = sanlock_state_to_args((char *)state,