Advertisement
Guest User

Untitled

a guest
Apr 18th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 6.82 KB | None | 0 0
  1. commit 8b17c5ac48677b03a2ce5706455a3d3e6f8d993d
  2. Author: Andrew Perepechko <andrew.perepechko@seagate.com>
  3. Date:   Tue May 17 16:54:36 2016 +0300
  4.  
  5.     MRP-3322 mdt: acquire an open lock for write or execute
  6.    
  7.     In mdt_object_open_lock() opens for write or execute will always
  8.     acquire an open lock of the appropriate mode so that any conflicting
  9.     cached open locks on other clients will be canceled.
  10.    
  11.     Also, do not drop LOOKUP from the original ibits mask if
  12.     the nonblocking lock request fails.
  13.    
  14.     Change-Id: I14775c5519b57d4ba8f3d74e2cc0060c503a19fe
  15.     Signed-off-by: Andrew Perepechko <andrew.perepechko@seagate.com>
  16.  
  17. diff --git a/lustre/mdt/mdt_open.c b/lustre/mdt/mdt_open.c
  18. index 1ae07248a7..d36e70c5e9 100644
  19. --- a/lustre/mdt/mdt_open.c
  20. +++ b/lustre/mdt/mdt_open.c
  21. @@ -1182,6 +1182,16 @@ static int mdt_open_by_fid(struct mdt_thread_info *info, struct ldlm_reply *rep)
  22.          RETURN(rc);
  23.  }
  24.  
  25. +static ldlm_mode_t open_flags_to_lock_mode(__u64 open_flags)
  26. +{
  27. +       if (open_flags & FMODE_WRITE)
  28. +               return LCK_CW;
  29. +       else if (open_flags & MDS_FMODE_EXEC)
  30. +               return LCK_PR;
  31. +
  32. +       return LCK_CR;
  33. +}
  34. +
  35.  /* lock object for open */
  36.  static int mdt_object_open_lock(struct mdt_thread_info *info,
  37.                                 struct mdt_object *obj,
  38. @@ -1242,26 +1252,33 @@ static int mdt_object_open_lock(struct mdt_thread_info *info,
  39.                 down_read(&obj->mot_open_sem);
  40.  
  41.                 if (open_flags & MDS_OPEN_LOCK) {
  42. -                       if (open_flags & FMODE_WRITE)
  43. -                               lm = LCK_CW;
  44. -                       else if (open_flags & MDS_FMODE_EXEC)
  45. -                               lm = LCK_PR;
  46. -                       else
  47. -                               lm = LCK_CR;
  48. -
  49. +                       lm = open_flags_to_lock_mode(open_flags);
  50.                         *ibits = MDS_INODELOCK_LOOKUP | MDS_INODELOCK_OPEN;
  51.                 } else if (atomic_read(&obj->mot_lease_count) > 0) {
  52. -                       if (open_flags & FMODE_WRITE)
  53. -                               lm = LCK_CW;
  54. -                       else
  55. -                               lm = LCK_CR;
  56. -
  57.                         /* revoke lease */
  58. +                       lm = open_flags_to_lock_mode(open_flags);
  59.                         *ibits = MDS_INODELOCK_OPEN;
  60.                         try_layout = false;
  61.  
  62.                         lhc = &info->mti_lh[MDT_LH_LOCAL];
  63. +               } else if (S_ISREG(lu_object_attr(&obj->mot_obj)) &&
  64. +                          open_flags & (FMODE_WRITE | MDS_FMODE_EXEC)) {
  65. +                       /*
  66. +                        * We need to flush open handles for proper ETXTBUSY
  67. +                        * reporting, but the client is not interested in an
  68. +                        * open lock, so lock and unlock immediately.
  69. +                        */
  70. +                       CDEBUG(D_INODE, "open lock and unlock "DFID"\n",
  71. +                              PFID(mdt_object_fid(obj)));
  72. +                       mdt_lock_reg_init(lhc,
  73. +                                         open_flags_to_lock_mode(open_flags));
  74. +                       rc = mdt_object_lock(info, obj, lhc, MDS_INODELOCK_OPEN,
  75. +                                            MDT_CROSS_LOCK);
  76. +                       if (rc < 0)
  77. +                               GOTO(out, rc);
  78. +                       mdt_object_unlock(info, obj, lhc, 1);
  79.                 }
  80. +
  81.                 CDEBUG(D_INODE, "normal open:"DFID" lease count: %d, lm: %d\n",
  82.                         PFID(mdt_object_fid(obj)),
  83.                         atomic_read(&obj->mot_open_count), lm);
  84. @@ -1277,13 +1294,15 @@ static int mdt_object_open_lock(struct mdt_thread_info *info,
  85.                  * lock for each open.
  86.                  * However this is a double-edged sword because changing
  87.                  * permission will revoke huge # of LOOKUP locks. */
  88. -               *ibits |= MDS_INODELOCK_LAYOUT | MDS_INODELOCK_LOOKUP;
  89. -               if (!mdt_object_lock_try(info, obj, lhc, *ibits,
  90. +               if (!mdt_object_lock_try(info, obj, lhc,
  91. +                                        *ibits | MDS_INODELOCK_LAYOUT |
  92. +                                                 MDS_INODELOCK_LOOKUP,
  93.                                          MDT_CROSS_LOCK)) {
  94. -                       *ibits &= ~(MDS_INODELOCK_LAYOUT|MDS_INODELOCK_LOOKUP);
  95.                         if (*ibits != 0)
  96.                                 rc = mdt_object_lock(info, obj, lhc, *ibits,
  97.                                                 MDT_CROSS_LOCK);
  98. +               } else {
  99. +                       *ibits |= MDS_INODELOCK_LAYOUT | MDS_INODELOCK_LOOKUP;
  100.                 }
  101.         } else if (*ibits != 0) {
  102.                 rc = mdt_object_lock(info, obj, lhc, *ibits, MDT_CROSS_LOCK);
  103. commit 1d02d0af9638789ff4907cb3a6c9c1f5bd295c84
  104. Author: Andrew Perepechko <andrew.perepechko@seagate.com>
  105. Date:   Fri Feb 19 19:49:26 2016 +0300
  106.  
  107.     MRP-3322 tests: conflicting locks are not flushed properly
  108.    
  109.     This patch adds a new test, sanityn.sh 14e. The test attempts
  110.     to cache an open lock (via NFS) on the client by writing to a
  111.     new file, then executes that file. If the MDS does not flush
  112.     conflicting locks, the execution will fail with -ETXTBSY.
  113.    
  114.     This tests replaces the original reproducer from LU-4398
  115.     which hasn't been working ever since LU-4367 landing.
  116.    
  117.    Change-Id: Ie1b3418fb2178d5f369a6734539cc51148200543
  118.    Signed-off-by: Andrew Perepechko <andrew.perepechko@seagate.com>
  119.  
  120. diff --git a/lustre/tests/sanityn.sh b/lustre/tests/sanityn.sh
  121. index f677f26e14..f20b20d581 100644
  122. --- a/lustre/tests/sanityn.sh
  123. +++ b/lustre/tests/sanityn.sh
  124. @@ -39,6 +39,8 @@ init_test_env $@
  125. . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
  126. init_logging
  127.  
  128. +. $LUSTRE/tests/setup-nfs.sh
  129. +
  130. if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
  131. # bug number for skipped test:        LU-2189 LU-2776
  132.        ALWAYS_EXCEPT="$ALWAYS_EXCEPT 36      51a"
  133. @@ -357,6 +359,31 @@ test_14d() { # bug 10921
  134. }
  135. run_test 14d "chmod of executing file is still possible ========"
  136.  
  137. +test_14e() { # LU-4398/MRP-3322
  138. +       local rc=0
  139. +
  140. +       test_mkdir -p $DIR1/$tdir
  141. +       rm -f $DIR1/$tdir/$tfile
  142. +
  143. +       setup_nfs 4 $DIR1 $HOSTNAME $HOSTNAME $DIR2 ||
  144. +               error "nfs setup failed!"
  145. +
  146. +       touch $DIR2/$tdir/$tfile
  147. +       chmod +x $DIR2/$tdir/$tfile
  148. +       printf '#!/bin/bash' > $DIR2/$tdir/$tfile
  149. +
  150. +       $DIR1/$tdir/$tfile || rc=1
  151. +
  152. +       # always cleanup
  153. +       cleanup_nfs $DIR2 $HOSTNAME $HOSTNAME ||
  154. +               error_noexit false "failed to cleanup nfs"
  155. +
  156. +       [ $rc -ne 0 ] && echo "failed to execute"
  157. +
  158. +       return $rc
  159. +}
  160. +run_test 14e "conflicting locks should be flushed on open ======"
  161. +
  162.  test_15() {    # bug 974 - ENOSPC
  163.         echo "PATH=$PATH"
  164.         sh oos2.sh $MOUNT1 $MOUNT2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement