summaryrefslogtreecommitdiffstats
path: root/daemons/clvmd
diff options
context:
space:
mode:
authorMilan Broz <mbroz@redhat.com>2009-05-19 10:38:58 +0000
committerMilan Broz <mbroz@redhat.com>2009-05-19 10:38:58 +0000
commitfa6dca9f28c2434905687c53122361d7cecf7f63 (patch)
treeb891b2a08f352cf3d476a55e6375909013443f37 /daemons/clvmd
parent8dd0ae923b627fe04da2b431605740cff1dca8b1 (diff)
downloadlvm2-fa6dca9f28c2434905687c53122361d7cecf7f63.tar.gz
lvm2-fa6dca9f28c2434905687c53122361d7cecf7f63.tar.xz
lvm2-fa6dca9f28c2434905687c53122361d7cecf7f63.zip
Add infrastructure for queriying for remote locks.
Current code, when need to ensure that volume is not active on remote node, it need to try to exclusive activate volume. Patch adds simple clvmd command which queries all nodes for lock for given resource. The lock type is returned in reply in text. (But code currently uses CR and EX modes only.)
Diffstat (limited to 'daemons/clvmd')
-rw-r--r--daemons/clvmd/clvm.h1
-rw-r--r--daemons/clvmd/clvmd-command.c11
-rw-r--r--daemons/clvmd/clvmd.c3
-rw-r--r--daemons/clvmd/lvm-functions.c20
-rw-r--r--daemons/clvmd/lvm-functions.h1
5 files changed, 36 insertions, 0 deletions
diff --git a/daemons/clvmd/clvm.h b/daemons/clvmd/clvm.h
index 481d644a..04ab2835 100644
--- a/daemons/clvmd/clvm.h
+++ b/daemons/clvmd/clvm.h
@@ -62,6 +62,7 @@ static const char CLVMD_SOCKNAME[] = "\0clvmd";
/* Lock/Unlock commands */
#define CLVMD_CMD_LOCK_LV 50
#define CLVMD_CMD_LOCK_VG 51
+#define CLVMD_CMD_LOCK_QUERY 52
/* Misc functions */
#define CLVMD_CMD_REFRESH 40
diff --git a/daemons/clvmd/clvmd-command.c b/daemons/clvmd/clvmd-command.c
index dffff216..2266a2be 100644
--- a/daemons/clvmd/clvmd-command.c
+++ b/daemons/clvmd/clvmd-command.c
@@ -90,6 +90,7 @@ int do_command(struct local_client *client, struct clvm_header *msg, int msglen,
int arglen = msglen - sizeof(struct clvm_header) - strlen(msg->node);
int status = 0;
char *lockname;
+ const char *locktype;
struct utsname nodeinfo;
unsigned char lock_cmd;
unsigned char lock_flags;
@@ -144,6 +145,14 @@ int do_command(struct local_client *client, struct clvm_header *msg, int msglen,
}
break;
+ case CLVMD_CMD_LOCK_QUERY:
+ lockname = &args[2];
+ if (buflen < 3)
+ return EIO;
+ if ((locktype = do_lock_query(lockname)))
+ *retlen = 1 + snprintf(*buf, buflen, "%s", locktype);
+ break;
+
case CLVMD_CMD_REFRESH:
do_refresh_cache();
break;
@@ -278,6 +287,7 @@ int do_pre_command(struct local_client *client)
case CLVMD_CMD_GET_CLUSTERNAME:
case CLVMD_CMD_SET_DEBUG:
case CLVMD_CMD_VG_BACKUP:
+ case CLVMD_CMD_LOCK_QUERY:
break;
default:
@@ -308,6 +318,7 @@ int do_post_command(struct local_client *client)
case CLVMD_CMD_LOCK_VG:
case CLVMD_CMD_VG_BACKUP:
+ case CLVMD_CMD_LOCK_QUERY:
/* Nothing to do here */
break;
diff --git a/daemons/clvmd/clvmd.c b/daemons/clvmd/clvmd.c
index 1738255a..b34d26ab 100644
--- a/daemons/clvmd/clvmd.c
+++ b/daemons/clvmd/clvmd.c
@@ -257,6 +257,9 @@ static const char *decode_cmd(unsigned char cmdl)
case CLVMD_CMD_UNLOCK:
command = "UNLOCK";
break;
+ case CLVMD_CMD_LOCK_QUERY:
+ command = "LOCK_QUERY";
+ break;
default:
command = "unknown";
break;
diff --git a/daemons/clvmd/lvm-functions.c b/daemons/clvmd/lvm-functions.c
index 7e2eb2d6..29e5e6cd 100644
--- a/daemons/clvmd/lvm-functions.c
+++ b/daemons/clvmd/lvm-functions.c
@@ -434,6 +434,26 @@ static int do_deactivate_lv(char *resource, unsigned char lock_flags)
return 0;
}
+const char *do_lock_query(char *resource)
+{
+ int mode;
+ const char *type = NULL;
+
+ mode = get_current_lock(resource);
+ switch (mode) {
+ case LKM_NLMODE: type = "NL"; break;
+ case LKM_CRMODE: type = "CR"; break;
+ case LKM_CWMODE: type = "CW"; break;
+ case LKM_PRMODE: type = "PR"; break;
+ case LKM_PWMODE: type = "PW"; break;
+ case LKM_EXMODE: type = "EX"; break;
+ }
+
+ DEBUGLOG("do_lock_query: resource '%s', mode %i (%s)\n", resource, mode, type ?: "?");
+
+ return type;
+}
+
/* This is the LOCK_LV part that happens on all nodes in the cluster -
it is responsible for the interaction with device-mapper and LVM */
int do_lock_lv(unsigned char command, unsigned char lock_flags, char *resource)
diff --git a/daemons/clvmd/lvm-functions.h b/daemons/clvmd/lvm-functions.h
index 0b6866af..5da104c0 100644
--- a/daemons/clvmd/lvm-functions.h
+++ b/daemons/clvmd/lvm-functions.h
@@ -22,6 +22,7 @@ extern int pre_lock_lv(unsigned char lock_cmd, unsigned char lock_flags,
char *resource);
extern int do_lock_lv(unsigned char lock_cmd, unsigned char lock_flags,
char *resource);
+extern const char *do_lock_query(char *resource);
extern int post_lock_lv(unsigned char lock_cmd, unsigned char lock_flags,
char *resource);
extern int do_check_lvm1(const char *vgname);