Whamcloud - gitweb
b=2518
authorgreen <green>
Fri, 19 Mar 2004 23:25:15 +0000 (23:25 +0000)
committergreen <green>
Fri, 19 Mar 2004 23:25:15 +0000 (23:25 +0000)
LCK_GROUP lock mode implementation for group locks

lustre/include/linux/lustre_dlm.h
lustre/include/linux/lustre_idl.h
lustre/include/lustre/lustre_user.h
lustre/ldlm/ldlm_extent.c
lustre/ldlm/ldlm_lock.c
lustre/ldlm/ldlm_lockd.c
lustre/liblustre/file.c
lustre/liblustre/super.c
lustre/llite/file.c
lustre/llite/rw.c
lustre/osc/osc_request.c

index cfedfa5..e9be5f5 100644 (file)
@@ -102,6 +102,7 @@ typedef enum {
 #define LCK_COMPAT_CW  (LCK_COMPAT_PW | LCK_CW)
 #define LCK_COMPAT_CR  (LCK_COMPAT_CW | LCK_PR | LCK_PW)
 #define LCK_COMPAT_NL  (LCK_COMPAT_CR | LCK_EX)
+#define LCK_COMPAT_GROUP  (LCK_GROUP | LCK_NL)
 
 static ldlm_mode_t lck_compat_array[] = {
         [LCK_EX] LCK_COMPAT_EX,
@@ -109,12 +110,13 @@ static ldlm_mode_t lck_compat_array[] = {
         [LCK_PR] LCK_COMPAT_PR,
         [LCK_CW] LCK_COMPAT_CW,
         [LCK_CR] LCK_COMPAT_CR,
-        [LCK_NL] LCK_COMPAT_NL
+        [LCK_NL] LCK_COMPAT_NL,
+        [LCK_GROUP] LCK_COMPAT_GROUP
 };
 
 static inline void lockmode_verify(ldlm_mode_t mode)
 {
-       LASSERT(mode >= LCK_EX && mode <= LCK_NL);
+       LASSERT(mode >= LCK_EX && mode <= LCK_GROUP);
 }
 
 static inline int lockmode_compat(ldlm_mode_t exist, ldlm_mode_t new)
index 7f6813d..0d98e42 100644 (file)
@@ -724,7 +724,8 @@ typedef enum {
         LCK_PR = 4,
         LCK_CW = 8,
         LCK_CR = 16,
-        LCK_NL = 32
+        LCK_NL = 32,
+        LCK_GROUP = 64
 } ldlm_mode_t;
 
 struct ldlm_extent {
index 79aa677..ad55e05 100644 (file)
 #define LL_IOC_LOV_GETSTRIPE            _IOW ('f', 155, long)
 #define LL_IOC_LOV_SETEA                _IOW ('f', 156, long)
 #define LL_IOC_RECREATE_OBJ             _IOW ('f', 157, long)
-#define LL_IOC_CW_LOCK                  _IOW ('f', 158, long)
-#define LL_IOC_CW_UNLOCK                _IOW ('f', 159, long)
+#define LL_IOC_GROUP_LOCK               _IOW ('f', 158, long)
+#define LL_IOC_GROUP_UNLOCK             _IOW ('f', 159, long)
 
 #define O_LOV_DELAY_CREATE 0100000000  /* hopefully this does not conflict */
 
 #define LL_FILE_IGNORE_LOCK             0x00000001
-#define LL_FILE_CW_LOCKED               0x00000002
+#define LL_FILE_GROUP_LOCKED            0x00000002
 
 #define LOV_USER_MAGIC_V1 0x0BD10BD0
 #define LOV_USER_MAGIC    LOV_USER_MAGIC_V1
index dd04c1c..16a27f9 100644 (file)
@@ -159,14 +159,15 @@ ldlm_extent_compat_queue(struct list_head *queue, struct ldlm_lock *req,
 
                 /* locks are compatible, overlap doesn't matter */
                 if (lockmode_compat(lock->l_req_mode, req_mode)) {
-                        /* nonCW locks are compatible, overlap doesn't matter */
-                        if (req_mode != LCK_CW)
+                        /* non-group locks are compatible, overlap doesn't
+                           matter */
+                        if (req_mode != LCK_GROUP)
                                 continue;
                                 
-                        /* If we are trying to get a CW lock and there is
+                        /* If we are trying to get a GROUP lock and there is
                            another one of this kind, we need to compare gid */
                         if (req->l_policy_data.l_extent.gid ==
-                             lock->l_policy_data.l_extent.gid) {
+                            lock->l_policy_data.l_extent.gid) {
                                 if (lock->l_req_mode == lock->l_granted_mode)
                                         RETURN(2);
 
@@ -191,8 +192,8 @@ ldlm_extent_compat_queue(struct list_head *queue, struct ldlm_lock *req,
                         }
                 }
 
-                if (lock->l_req_mode == LCK_CW) {
-                        /* If compared lock is CW, then requested is PR/PW/ =>
+                if (lock->l_req_mode == LCK_GROUP) {
+                        /* If compared lock is GROUP, then requested is PR/PW/=>
                          * this is not compatible; extent range does not
                          * matter */
                         if (*flags & LDLM_FL_BLOCK_NOWAIT) {
@@ -203,7 +204,7 @@ ldlm_extent_compat_queue(struct list_head *queue, struct ldlm_lock *req,
                         }
                 } else if (lock->l_policy_data.l_extent.end < req_start ||
                            lock->l_policy_data.l_extent.start > req_end) {
-                        /* if a non-CW lock doesn't overlap skip it */
+                        /* if a non grouplock doesn't overlap skip it */
                         continue;
                 }
 
index 7fada77..9ffc201 100644 (file)
@@ -45,7 +45,8 @@ char *ldlm_lockname[] = {
         [LCK_PR] "PR",
         [LCK_CW] "CW",
         [LCK_CR] "CR",
-        [LCK_NL] "NL"
+        [LCK_NL] "NL",
+        [LCK_GROUP] "GROUP"
 };
 char *ldlm_typename[] = {
         [LDLM_PLAIN] "PLN",
@@ -432,7 +433,7 @@ void ldlm_lock_addref_internal(struct ldlm_lock *lock, __u32 mode)
         ldlm_lock_remove_from_lru(lock);
         if (mode & (LCK_NL | LCK_CR | LCK_PR))
                 lock->l_readers++;
-        if (mode & (LCK_EX | LCK_CW | LCK_PW))
+        if (mode & (LCK_EX | LCK_CW | LCK_PW | LCK_GROUP))
                 lock->l_writers++;
         lock->l_last_used = jiffies;
         l_unlock(&lock->l_resource->lr_namespace->ns_lock);
@@ -452,7 +453,7 @@ void ldlm_lock_decref_internal(struct ldlm_lock *lock, __u32 mode)
                 LASSERT(lock->l_readers > 0);
                 lock->l_readers--;
         }
-        if (mode & (LCK_EX | LCK_CW | LCK_PW)) {
+        if (mode & (LCK_EX | LCK_CW | LCK_PW | LCK_GROUP)) {
                 LASSERT(lock->l_writers > 0);
                 lock->l_writers--;
         }
@@ -591,7 +592,7 @@ static struct ldlm_lock *search_queue(struct list_head *queue, ldlm_mode_t mode,
                         continue;
 
                 if (lock->l_resource->lr_type == LDLM_EXTENT &&
-                    mode == LCK_CW &&
+                    mode == LCK_GROUP &&
                     lock->l_policy_data.l_extent.gid != policy->l_extent.gid)
                         continue;
 
index 9306dd8..f36661d 100644 (file)
@@ -185,7 +185,7 @@ static void waiting_locks_callback(unsigned long unused)
                                   l_pending_chain);
 
                 if ((lock->l_callback_timeout > jiffies) ||
-                    (lock->l_req_mode == LCK_CW))
+                    (lock->l_req_mode == LCK_GROUP))
                         break;
 
                 LDLM_ERROR(lock, "lock callback timer expired: evicting client "
index f666cdc..9b645d0 100644 (file)
@@ -259,10 +259,11 @@ int llu_mdc_close(struct obd_export *mdc_exp, struct inode *inode)
         ENTRY;
 
         /* clear group lock, if present */
-        if (fd->fd_flags & LL_FILE_CW_LOCKED) {
+        if (fd->fd_flags & LL_FILE_GROUP_LOCKED) {
                 struct lov_stripe_md *lsm = llu_i2info(inode)->lli_smd;
-                fd->fd_flags &= ~(LL_FILE_CW_LOCKED|LL_FILE_IGNORE_LOCK);
-                rc = llu_extent_unlock(fd, inode, lsm, LCK_CW, &fd->fd_cwlockh);
+                fd->fd_flags &= ~(LL_FILE_GROUP_LOCKED|LL_FILE_IGNORE_LOCK);
+                rc = llu_extent_unlock(fd, inode, lsm, LCK_GROUP,
+                                       &fd->fd_cwlockh);
         }
 
         valid = OBD_MD_FLID;
index 25ffc0f..6971d87 100644 (file)
@@ -1187,7 +1187,7 @@ static int llu_iop_fcntl(struct inode *ino, int cmd, va_list ap)
         return -ENOSYS;
 }
 
-static int llu_get_cwlock(struct inode *inode, unsigned long arg)
+static int llu_get_grouplock(struct inode *inode, unsigned long arg)
 {
         struct llu_inode_info *lli = llu_i2info(inode);
         struct ll_file_data *fd = lli->lli_file_data;
@@ -1199,7 +1199,7 @@ static int llu_get_cwlock(struct inode *inode, unsigned long arg)
         int flags = 0;
         ENTRY;
 
-        if (fd->fd_flags & LL_FILE_CW_LOCKED) {
+        if (fd->fd_flags & LL_FILE_GROUP_LOCKED) {
                 RETURN(-EINVAL);
         }
 
@@ -1207,18 +1207,19 @@ static int llu_get_cwlock(struct inode *inode, unsigned long arg)
         if (lli->lli_open_flags & O_NONBLOCK)
                 flags = LDLM_FL_BLOCK_NOWAIT;
 
-        err = llu_extent_lock(fd, inode, lsm, LCK_CW, &policy, &lockh, flags);
+        err = llu_extent_lock(fd, inode, lsm, LCK_GROUP, &policy, &lockh,
+                              flags);
         if (err)
                 RETURN(err);
 
-        fd->fd_flags |= LL_FILE_CW_LOCKED|LL_FILE_IGNORE_LOCK;
+        fd->fd_flags |= LL_FILE_GROUP_LOCKED|LL_FILE_IGNORE_LOCK;
         fd->fd_gid = arg;
         memcpy(&fd->fd_cwlockh, &lockh, sizeof(lockh));
 
         RETURN(0);
 }
 
-static int llu_put_cwlock(struct inode *inode, unsigned long arg)
+static int llu_put_grouplock(struct inode *inode, unsigned long arg)
 {
         struct llu_inode_info *lli = llu_i2info(inode);
         struct ll_file_data *fd = lli->lli_file_data;
@@ -1226,15 +1227,15 @@ static int llu_put_cwlock(struct inode *inode, unsigned long arg)
         ldlm_error_t err;
         ENTRY;
 
-        if (!(fd->fd_flags & LL_FILE_CW_LOCKED))
+        if (!(fd->fd_flags & LL_FILE_GROUP_LOCKED))
                 RETURN(-EINVAL);
 
         if (fd->fd_gid != arg)
                 RETURN(-EINVAL);
 
-        fd->fd_flags &= ~(LL_FILE_CW_LOCKED|LL_FILE_IGNORE_LOCK);
+        fd->fd_flags &= ~(LL_FILE_GROUP_LOCKED|LL_FILE_IGNORE_LOCK);
 
-        err = llu_extent_unlock(fd, inode, lsm, LCK_CW, &fd->fd_cwlockh);
+        err = llu_extent_unlock(fd, inode, lsm, LCK_GROUP, &fd->fd_cwlockh);
         if (err)
                 RETURN(err);
 
@@ -1250,12 +1251,12 @@ static int llu_iop_ioctl(struct inode *ino, unsigned long int request,
         unsigned long arg;
 
         switch (request) {
-        case LL_IOC_CW_LOCK:
+        case LL_IOC_GROUP_LOCK:
                 arg = va_arg(ap, unsigned long);
-                return llu_get_cwlock(ino, arg);
-        case LL_IOC_CW_UNLOCK:
+                return llu_get_grouplock(ino, arg);
+        case LL_IOC_GROUP_UNLOCK:
                 arg = va_arg(ap, unsigned long);
-                return llu_put_cwlock(ino, arg);
+                return llu_put_grouplock(ino, arg);
         }
 
         CERROR("did not support ioctl cmd %lx\n", request);
index 7fbd8a5..574f958 100644 (file)
@@ -44,10 +44,11 @@ static int ll_mdc_close(struct obd_export *mdc_exp, struct inode *inode,
         ENTRY;
 
         /* clear group lock, if present */
-        if (fd->fd_flags & LL_FILE_CW_LOCKED) {
+        if (fd->fd_flags & LL_FILE_GROUP_LOCKED) {
                 struct lov_stripe_md *lsm = ll_i2info(inode)->lli_smd;
-                fd->fd_flags &= ~(LL_FILE_CW_LOCKED|LL_FILE_IGNORE_LOCK);
-                rc = ll_extent_unlock(fd, inode, lsm, LCK_CW, &fd->fd_cwlockh);
+                fd->fd_flags &= ~(LL_FILE_GROUP_LOCKED|LL_FILE_IGNORE_LOCK);
+                rc = ll_extent_unlock(fd, inode, lsm, LCK_GROUP,
+                                      &fd->fd_cwlockh);
         }
 
         valid = OBD_MD_FLID;
@@ -1018,7 +1019,7 @@ static int ll_lov_getstripe(struct inode *inode, unsigned long arg)
                             (void *)arg);
 }
 
-static int ll_get_cwlock(struct inode *inode, struct file *file,
+static int ll_get_grouplock(struct inode *inode, struct file *file,
                          unsigned long arg)
 {
         struct ll_file_data *fd = file->private_data;
@@ -1031,7 +1032,7 @@ static int ll_get_cwlock(struct inode *inode, struct file *file,
         int flags = 0;
         ENTRY;
 
-        if (fd->fd_flags & LL_FILE_CW_LOCKED) {
+        if (fd->fd_flags & LL_FILE_GROUP_LOCKED) {
                 RETURN(-EINVAL);
         }
 
@@ -1039,18 +1040,18 @@ static int ll_get_cwlock(struct inode *inode, struct file *file,
         if (file->f_flags & O_NONBLOCK)
                 flags = LDLM_FL_BLOCK_NOWAIT;
 
-        err = ll_extent_lock(fd, inode, lsm, LCK_CW, &policy, &lockh, flags);
+        err = ll_extent_lock(fd, inode, lsm, LCK_GROUP, &policy, &lockh, flags);
         if (err)
                 RETURN(err);
 
-        fd->fd_flags |= LL_FILE_CW_LOCKED|LL_FILE_IGNORE_LOCK;
+        fd->fd_flags |= LL_FILE_GROUP_LOCKED|LL_FILE_IGNORE_LOCK;
         fd->fd_gid = arg;
         memcpy(&fd->fd_cwlockh, &lockh, sizeof(lockh));
 
         RETURN(0);
 }
 
-static int ll_put_cwlock(struct inode *inode, struct file *file,
+static int ll_put_grouplock(struct inode *inode, struct file *file,
                          unsigned long arg)
 {
         struct ll_file_data *fd = file->private_data;
@@ -1059,7 +1060,7 @@ static int ll_put_cwlock(struct inode *inode, struct file *file,
         ldlm_error_t err;
         ENTRY;
 
-        if (!(fd->fd_flags & LL_FILE_CW_LOCKED)) {
+        if (!(fd->fd_flags & LL_FILE_GROUP_LOCKED)) {
                 /* Ugh, it's already unlocked. */
                 RETURN(-EINVAL);
         }
@@ -1067,9 +1068,9 @@ static int ll_put_cwlock(struct inode *inode, struct file *file,
         if (fd->fd_gid != arg) /* Ugh? Unlocking with different gid? */
                 RETURN(-EINVAL);
         
-        fd->fd_flags &= ~(LL_FILE_CW_LOCKED|LL_FILE_IGNORE_LOCK);
+        fd->fd_flags &= ~(LL_FILE_GROUP_LOCKED|LL_FILE_IGNORE_LOCK);
 
-        err = ll_extent_unlock(fd, inode, lsm, LCK_CW, &fd->fd_cwlockh);
+        err = ll_extent_unlock(fd, inode, lsm, LCK_GROUP, &fd->fd_cwlockh);
         if (err)
                 RETURN(err);
 
@@ -1122,10 +1123,10 @@ int ll_file_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
         case EXT3_IOC_GETFLAGS:
         case EXT3_IOC_SETFLAGS:
                 RETURN( ll_iocontrol(inode, file, cmd, arg) );
-        case LL_IOC_CW_LOCK:
-                RETURN(ll_get_cwlock(inode, file, arg));
-        case LL_IOC_CW_UNLOCK:
-                RETURN(ll_put_cwlock(inode, file, arg));
+        case LL_IOC_GROUP_LOCK:
+                RETURN(ll_get_grouplock(inode, file, arg));
+        case LL_IOC_GROUP_UNLOCK:
+                RETURN(ll_put_grouplock(inode, file, arg));
         /* We need to special case any other ioctls we want to handle,
          * to send them to the MDS/OST as appropriate and to properly
          * network encode the arg field.
index a1ed4d1..11e6df8 100644 (file)
@@ -527,7 +527,7 @@ static int ll_page_matches(struct page *page, int fd_flags)
         int flags, matches;
         ENTRY;
 
-        if (fd_flags & LL_FILE_CW_LOCKED)
+        if (fd_flags & LL_FILE_GROUP_LOCKED)
                 RETURN(1);
 
         page_extent.l_extent.start = (__u64)page->index << PAGE_CACHE_SHIFT;
index db33eab..ea9836b 100644 (file)
@@ -2514,7 +2514,7 @@ static int osc_cancel(struct obd_export *exp, struct lov_stripe_md *md,
 {
         ENTRY;
 
-        if (mode == LCK_CW)
+        if (mode == LCK_GROUP)
                 ldlm_lock_decref_and_cancel(lockh, mode);
         else
                 ldlm_lock_decref(lockh, mode);