Whamcloud - gitweb
LU-17692 flock: get extra reference for lockd 22/54622/5
authorYang Sheng <ys@whamcloud.com>
Thu, 28 Mar 2024 19:54:06 +0000 (03:54 +0800)
committerOleg Drokin <green@whamcloud.com>
Tue, 23 Apr 2024 19:56:55 +0000 (19:56 +0000)
We should get local locking first for GETLK. Else
the lock_owner could be released while working with
lockd.

Signed-off-by: Yang Sheng <ys@whamcloud.com>
Change-Id: I56e4204e315c2bdbc496b7961519ae45ab1820fe
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/54622
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Lai Siyao <lai.siyao@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/llite/file.c

index bc8905b..0846564 100644 (file)
@@ -5108,6 +5108,7 @@ ll_file_flock(struct file *file, int cmd, struct file_lock *file_lock)
        struct md_op_data *op_data;
        struct lustre_handle lockh = { 0 };
        union ldlm_policy_data flock = { { 0 } };
+       struct file_lock flbuf = *file_lock;
        int fl_type = file_lock->fl_type;
        ktime_t kstart = ktime_get();
        __u64 flags = 0;
@@ -5188,6 +5189,11 @@ ll_file_flock(struct file *file, int cmd, struct file_lock *file_lock)
        case F_GETLK64:
 #endif
                flags = LDLM_FL_TEST_LOCK;
+               /*
+                * To work with lockd we should check local lock first,
+                * else lock_owner could disappear in conflict case.
+                */
+               posix_test_lock(file, &flbuf);
                break;
        default:
                rc = -EINVAL;
@@ -5240,6 +5246,19 @@ ll_file_flock(struct file *file, int cmd, struct file_lock *file_lock)
 
        ll_finish_md_op_data(op_data);
 
+       if (rc == 0 && (flags & LDLM_FL_TEST_LOCK) &&
+           flbuf.fl_type != file_lock->fl_type) { /* Verify local & remote */
+               CERROR("Flock LR mismatch! inode="DFID", flags=%#llx, mode=%u, "
+                      "pid=%u/%u, start=%llu/%llu, end=%llu/%llu,type=%u/%u\n",
+                      PFID(ll_inode2fid(inode)), flags, einfo.ei_mode,
+                      file_lock->fl_pid, flbuf.fl_pid,
+                      file_lock->fl_start, flbuf.fl_start,
+                      file_lock->fl_end, flbuf.fl_end,
+                      file_lock->fl_type, flbuf.fl_type);
+               /* return local */
+               *file_lock = flbuf;
+       }
+
        if (!rc)
                ll_stats_ops_tally(ll_i2sbi(inode), LPROC_LL_FLOCK,
                                   ktime_us_delta(ktime_get(), kstart));