]> sourceware.org Git - lvm2.git/commitdiff
Clean up cluster lock mode and flags definition.
authorMilan Broz <mbroz@redhat.com>
Thu, 17 Jun 2010 12:48:54 +0000 (12:48 +0000)
committerMilan Broz <mbroz@redhat.com>
Thu, 17 Jun 2010 12:48:54 +0000 (12:48 +0000)
Code is mixing up internal DLM and LVM definitions of lock
modes and flags.

OpenAIS and singlenode locking do not depend on DLM but
code currently cannot be compiled without libdlm.h!

LCK_* flags is LVM abstraction, used through all the code.
Only low-level backend (clvmd-cman etc) should use DLM definitions,
also this code should do all needed conversions.

Because there are two DLM flags used in generic code
(NOQUEUE, CONVERT) we define it similar way like lock modes.
(So all needed binary-compatible flags are on one place in locking.h)

(Further code cleaning still needed, though:-)

WHATS_NEW
daemons/clvmd/clvmd-command.c
daemons/clvmd/clvmd-gulm.c
daemons/clvmd/clvmd-gulm.h
daemons/clvmd/lvm-functions.c
lib/locking/locking.h

index 3c27b5857be6a8f60decafadbdd59d2777f587f7..890425970ebc94ab79c78ffec1163049532108ce 100644 (file)
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
 Version 2.02.68 -
 ===============================
+  Do not use internal DLM lock definitions in generic LVM2 clvmd code.
   Add dmeventd man page.
   Update lvresize/extend/reduce manpages with --nofsck, --resizefs options.
   Fix lvm2cmd example in documentation.
index d4024ae80149044dc481dc32e0abd2490c30814f..04b4632fe373b9063314cf21d4fd945d64307a11 100644 (file)
@@ -69,7 +69,6 @@
 #include <unistd.h>
 #include <errno.h>
 #include "libdevmapper.h"
-#include <libdlm.h>
 
 #include "locking.h"
 #include "lvm-logging.h"
@@ -239,7 +238,7 @@ static int lock_vg(struct local_client *client)
        /* Read locks need to be PR; other modes get passed through */
        if (lock_mode == LCK_READ)
            lock_mode = LCK_PREAD;
-       status = sync_lock(lockname, lock_mode, (lock_cmd & LCK_NONBLOCK) ? LKF_NOQUEUE : 0, &lkid);
+       status = sync_lock(lockname, lock_mode, (lock_cmd & LCK_NONBLOCK) ? LCKF_NOQUEUE : 0, &lkid);
        if (status)
            status = errno;
        else
@@ -266,7 +265,7 @@ int do_pre_command(struct local_client *client)
 
        switch (header->cmd) {
        case CLVMD_CMD_TEST:
-               status = sync_lock("CLVMD_TEST", LKM_EXMODE, 0, &lockid);
+               status = sync_lock("CLVMD_TEST", LCK_EXCL, 0, &lockid);
                client->bits.localsock.private = (void *)(long)lockid;
                break;
 
index b42318143d57c1dbca0854a88f5cf41b9166db07..721e7be0c6e26e4acb68f053cfc509e9a08afe42 100644 (file)
@@ -739,7 +739,7 @@ static int _lock_resource(char *resource, int mode, int flags, int *lockid)
     pthread_mutex_lock(&lwait.mutex);
 
     /* This needs to be converted from DLM/LVM2 value for GULM */
-    if (flags & LKF_NOQUEUE) flags = lg_lock_flag_Try;
+    if (flags & LCKF_NOQUEUE) flags = lg_lock_flag_Try;
 
     dm_hash_insert(lock_hash, resource, &lwait);
     DEBUGLOG("lock_resource '%s', flags=%d, mode=%d\n", resource, flags, mode);
index d4be46fac8d178a2c902a312c8f61a6b273342ad..9416f5c39c9187f1d036ea6c60641b3f59f96a44 100644 (file)
@@ -1,7 +1,3 @@
-
-/* DLM constant that clvmd uses as a generic NONBLOCK lock flag */
-#define LKF_NOQUEUE 1
-
 extern int get_next_node_csid(void **context, char *csid);
 extern void add_down_node(char *csid);
 extern int gulm_fd(void);
index 11b17b470ff7cdf9e70f28628eb243c918993801..ff44a0ff73d18c4842b3082a72d2376fc8eba953 100644 (file)
@@ -35,7 +35,6 @@
 #include <syslog.h>
 #include <assert.h>
 #include "libdevmapper.h"
-#include <libdlm.h>
 
 #include "lvm-types.h"
 #include "clvm.h"
@@ -243,7 +242,7 @@ int hold_lock(char *resource, int mode, int flags)
        struct lv_info *lvi;
 
        /* Mask off invalid options */
-       flags &= LKF_NOQUEUE | LKF_CONVERT;
+       flags &= LCKF_NOQUEUE | LCKF_CONVERT;
 
        lvi = lookup_info(resource);
 
@@ -253,7 +252,7 @@ int hold_lock(char *resource, int mode, int flags)
        }
 
        /* Only allow explicit conversions */
-       if (lvi && !(flags & LKF_CONVERT)) {
+       if (lvi && !(flags & LCKF_CONVERT)) {
                errno = EBUSY;
                return -1;
        }
@@ -276,7 +275,7 @@ int hold_lock(char *resource, int mode, int flags)
                        return -1;
 
                lvi->lock_mode = mode;
-               status = sync_lock(resource, mode, flags & ~LKF_CONVERT, &lvi->lock_id);
+               status = sync_lock(resource, mode, flags & ~LCKF_CONVERT, &lvi->lock_id);
                saved_errno = errno;
                if (status) {
                        free(lvi);
@@ -346,9 +345,9 @@ static int do_activate_lv(char *resource, unsigned char lock_flags, int mode)
                return 0;       /* Success, we did nothing! */
 
        /* Do we need to activate exclusively? */
-       if ((activate_lv == 2) || (mode == LKM_EXMODE)) {
+       if ((activate_lv == 2) || (mode == LCK_EXCL)) {
                exclusive = 1;
-               mode = LKM_EXMODE;
+               mode = LCK_EXCL;
        }
 
        /*
@@ -357,7 +356,7 @@ static int do_activate_lv(char *resource, unsigned char lock_flags, int mode)
         * of exclusive lock to shared one during activation.
         */
        if (lock_flags & LCK_CLUSTER_VG) {
-               status = hold_lock(resource, mode, LKF_NOQUEUE | (lock_flags & LCK_CONVERT?LKF_CONVERT:0));
+               status = hold_lock(resource, mode, LCKF_NOQUEUE | (lock_flags & LCK_CONVERT ? LCKF_CONVERT:0));
                if (status) {
                        /* Return an LVM-sensible error for this.
                         * Forcing EIO makes the upper level return this text
@@ -465,12 +464,11 @@ const char *do_lock_query(char *resource)
 
        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;
+               case LCK_NULL: type = "NL"; break;
+               case LCK_READ: type = "CR"; break;
+               case LCK_PREAD:type = "PR"; break;
+               case LCK_WRITE:type = "PW"; break;
+               case LCK_EXCL: type = "EX"; break;
        }
 
        DEBUGLOG("do_lock_query: resource '%s', mode %i (%s)\n", resource, mode, type ?: "?");
@@ -511,7 +509,7 @@ int do_lock_lv(unsigned char command, unsigned char lock_flags, char *resource)
 
        switch (command & LCK_MASK) {
        case LCK_LV_EXCLUSIVE:
-               status = do_activate_lv(resource, lock_flags, LKM_EXMODE);
+               status = do_activate_lv(resource, lock_flags, LCK_EXCL);
                break;
 
        case LCK_LV_SUSPEND:
@@ -528,7 +526,7 @@ int do_lock_lv(unsigned char command, unsigned char lock_flags, char *resource)
                break;
 
        case LCK_LV_ACTIVATE:
-               status = do_activate_lv(resource, lock_flags, LKM_CRMODE);
+               status = do_activate_lv(resource, lock_flags, LCK_READ);
                break;
 
        case LCK_LV_DEACTIVATE:
@@ -560,14 +558,14 @@ int pre_lock_lv(unsigned char command, unsigned char lock_flags, char *resource)
        /* Nearly all the stuff happens cluster-wide. Apart from SUSPEND. Here we get the
           lock out on this node (because we are the node modifying the metadata)
           before suspending cluster-wide.
-          LKF_CONVERT is used always, local node is going to modify metadata
+          LCKF_CONVERT is used always, local node is going to modify metadata
         */
        if ((command & (LCK_SCOPE_MASK | LCK_TYPE_MASK)) == LCK_LV_SUSPEND &&
            (lock_flags & LCK_CLUSTER_VG)) {
                DEBUGLOG("pre_lock_lv: resource '%s', cmd = %s, flags = %s\n",
                         resource, decode_locking_cmd(command), decode_flags(lock_flags));
 
-               if (hold_lock(resource, LKM_PWMODE, LKF_NOQUEUE | LKF_CONVERT))
+               if (hold_lock(resource, LCK_WRITE, LCKF_NOQUEUE | LCKF_CONVERT))
                        return errno;
        }
        return 0;
@@ -590,7 +588,7 @@ int post_lock_lv(unsigned char command, unsigned char lock_flags,
 
                /* If the lock state is PW then restore it to what it was */
                oldmode = get_current_lock(resource);
-               if (oldmode == LKM_PWMODE) {
+               if (oldmode == LCK_WRITE) {
                        struct lvinfo lvi;
 
                        pthread_mutex_lock(&lvm_lock);
@@ -600,7 +598,7 @@ int post_lock_lv(unsigned char command, unsigned char lock_flags,
                                return EIO;
 
                        if (lvi.exists) {
-                               if (hold_lock(resource, LKM_CRMODE, LKF_CONVERT))
+                               if (hold_lock(resource, LCK_READ, LCKF_CONVERT))
                                        return errno;
                        } else {
                                if (hold_unlock(resource))
@@ -792,15 +790,15 @@ static void *get_initial_state(char **argv)
                                memcpy(&uuid[58], &lv[32], 6);
                                uuid[64] = '\0';
 
-                               lock_mode = LKM_CRMODE;
+                               lock_mode = LCK_READ;
 
                                /* Look for this lock in the list of EX locks
                                   we were passed on the command-line */
                                if (was_ex_lock(uuid, argv))
-                                       lock_mode = LKM_EXMODE;
+                                       lock_mode = LCK_EXCL;
 
                                DEBUGLOG("getting initial lock for %s\n", uuid);
-                               hold_lock(uuid, lock_mode, LKF_NOQUEUE);
+                               hold_lock(uuid, lock_mode, LCKF_NOQUEUE);
                        }
                }
        }
index d904cf228c9cfb812dcf3d0c0d375c26674a3c5f..488d194da2b4621f4e3c6fcf418b0403498de4ed 100644 (file)
@@ -72,6 +72,12 @@ int check_lvm1_vg_inactive(struct cmd_context *cmd, const char *vgname);
 #define LCK_EXCL       0x00000005U     /* LCK$_EXMODE */
 #define LCK_UNLOCK      0x00000006U    /* This is ours */
 
+/*
+ * Lock flags - these numbers are the same as DLM
+ */
+#define LCKF_NOQUEUE   0x00000001U     /* LKF$_NOQUEUE */
+#define LCKF_CONVERT   0x00000004U     /* LKF$_CONVERT */
+
 /*
  * Lock scope
  */
This page took 0.05661 seconds and 5 git commands to generate.