mirror of
git://sourceware.org/git/lvm2.git
synced 2025-01-03 05:18:29 +03:00
lvmlockd: reconnect to lvmetad if it's restarted
If lvmetad is restarted after lvmlockd has connected to it, then lvmlockd should reconnect.
This commit is contained in:
parent
bdba4e7a93
commit
dcb26b5f13
@ -1020,6 +1020,43 @@ static void add_work_action(struct action *act)
|
||||
pthread_mutex_unlock(&worker_mutex);
|
||||
}
|
||||
|
||||
static daemon_reply send_lvmetad(const char *id, ...)
|
||||
{
|
||||
daemon_reply reply;
|
||||
va_list ap;
|
||||
int retries = 0;
|
||||
|
||||
va_start(ap, id);
|
||||
|
||||
/*
|
||||
* mutex is used because all threads share a single
|
||||
* lvmetad connection/handle.
|
||||
*/
|
||||
pthread_mutex_lock(&lvmetad_mutex);
|
||||
retry:
|
||||
reply = daemon_send_simple_v(lvmetad_handle, id, ap);
|
||||
|
||||
/* lvmetad may have been restarted */
|
||||
if ((reply.error == ECONNRESET) && (retries < 2)) {
|
||||
daemon_close(lvmetad_handle);
|
||||
lvmetad_connected = 0;
|
||||
|
||||
lvmetad_handle = lvmetad_open(NULL);
|
||||
if (lvmetad_handle.error || lvmetad_handle.socket_fd < 0) {
|
||||
log_error("lvmetad_open reconnect error %d", lvmetad_handle.error);
|
||||
} else {
|
||||
log_debug("lvmetad reconnected");
|
||||
lvmetad_connected = 1;
|
||||
}
|
||||
retries++;
|
||||
goto retry;
|
||||
}
|
||||
pthread_mutex_unlock(&lvmetad_mutex);
|
||||
|
||||
va_end(ap);
|
||||
return reply;
|
||||
}
|
||||
|
||||
static int res_lock(struct lockspace *ls, struct resource *r, struct action *act, int *retry)
|
||||
{
|
||||
struct lock *lk;
|
||||
@ -1246,14 +1283,12 @@ static int res_lock(struct lockspace *ls, struct resource *r, struct action *act
|
||||
else
|
||||
uuid = ls->vg_uuid;
|
||||
|
||||
pthread_mutex_lock(&lvmetad_mutex);
|
||||
reply = daemon_send_simple(lvmetad_handle, "set_vg_info",
|
||||
reply = send_lvmetad("set_vg_info",
|
||||
"token = %s", "skip",
|
||||
"uuid = %s", uuid,
|
||||
"name = %s", ls->vg_name,
|
||||
"version = " FMTd64, (int64_t)new_version,
|
||||
NULL);
|
||||
pthread_mutex_unlock(&lvmetad_mutex);
|
||||
|
||||
if (reply.error || strcmp(daemon_reply_str(reply, "response", ""), "OK"))
|
||||
log_error("set_vg_info in lvmetad failed %d", reply.error);
|
||||
@ -1266,12 +1301,10 @@ static int res_lock(struct lockspace *ls, struct resource *r, struct action *act
|
||||
log_debug("S %s R %s res_lock set lvmetad global invalid",
|
||||
ls->name, r->name);
|
||||
|
||||
pthread_mutex_lock(&lvmetad_mutex);
|
||||
reply = daemon_send_simple(lvmetad_handle, "set_global_info",
|
||||
reply = send_lvmetad("set_global_info",
|
||||
"token = %s", "skip",
|
||||
"global_invalid = " FMTd64, INT64_C(1),
|
||||
NULL);
|
||||
pthread_mutex_unlock(&lvmetad_mutex);
|
||||
|
||||
if (reply.error || strcmp(daemon_reply_str(reply, "response", ""), "OK"))
|
||||
log_error("set_global_info in lvmetad failed %d", reply.error);
|
||||
@ -4747,15 +4780,11 @@ static int get_lockd_vgs(struct list_head *vg_lockd)
|
||||
const char *lock_type;
|
||||
const char *lock_args;
|
||||
char find_str_path[PATH_MAX];
|
||||
int mutex_unlocked = 0;
|
||||
int rv = 0;
|
||||
|
||||
INIT_LIST_HEAD(&update_vgs);
|
||||
|
||||
pthread_mutex_lock(&lvmetad_mutex);
|
||||
reply = daemon_send_simple(lvmetad_handle, "vg_list",
|
||||
"token = %s", "skip",
|
||||
NULL);
|
||||
reply = send_lvmetad("vg_list", "token = %s", "skip", NULL);
|
||||
|
||||
if (reply.error || strcmp(daemon_reply_str(reply, "response", ""), "OK")) {
|
||||
log_error("vg_list from lvmetad failed %d", reply.error);
|
||||
@ -4792,7 +4821,7 @@ static int get_lockd_vgs(struct list_head *vg_lockd)
|
||||
/* get vg_name and lock_type for each vg uuid entry in update_vgs */
|
||||
|
||||
list_for_each_entry(ls, &update_vgs, list) {
|
||||
reply = daemon_send_simple(lvmetad_handle, "vg_lookup",
|
||||
reply = send_lvmetad("vg_lookup",
|
||||
"token = %s", "skip",
|
||||
"uuid = %s", ls->vg_uuid,
|
||||
NULL);
|
||||
@ -4884,8 +4913,6 @@ static int get_lockd_vgs(struct list_head *vg_lockd)
|
||||
if (rv < 0)
|
||||
break;
|
||||
}
|
||||
pthread_mutex_unlock(&lvmetad_mutex);
|
||||
mutex_unlocked = 1;
|
||||
out:
|
||||
/* Return lockd VG's on the vg_lockd list. */
|
||||
|
||||
@ -4898,9 +4925,6 @@ out:
|
||||
free(ls);
|
||||
}
|
||||
|
||||
if (!mutex_unlocked)
|
||||
pthread_mutex_unlock(&lvmetad_mutex);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user