This patch fixes to set local processes and their pid value represented
inside the struct flock when using F_GETLK if there is a conflict with
another process.

Currently every pid in struct flock l_pid is set as negative pid number.
This was changed by commit 9d5b86ac13c5 ("fs/locks: Remove fl_nspid and use
fs-specific l_pid for remote locks"). There is still the question how to
represent remote pid lock holders, which is possible for DLM posix
handling, in the flock structure. This patch however will only change
local process holders to be represented as positive pids.

Further patches may change the behaviour for remote pid lock holders,
for now this patch will leave the behaviour of remote lock holders
unchanged which will be represented as negative pid.

There exists a simple ltp testcase [0] as reproducer.

[0] 
https://gitlab.com/netcoder/ltp/-/blob/dlm_fcntl_owner_testcase/testcases/kernel/syscalls/fcntl/fcntl05.c

Cc: sta...@vger.kernel.org
Fixes: 9d5b86ac13c5 ("fs/locks: Remove fl_nspid and use fs-specific l_pid for 
remote locks")
Signed-off-by: Alexander Aring <aahri...@redhat.com>
---
 fs/dlm/plock.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/fs/dlm/plock.c b/fs/dlm/plock.c
index ed4357e62f35..ff364901f22b 100644
--- a/fs/dlm/plock.c
+++ b/fs/dlm/plock.c
@@ -360,7 +360,9 @@ int dlm_posix_get(dlm_lockspace_t *lockspace, u64 number, 
struct file *file,
                locks_init_lock(fl);
                fl->fl_type = (op->info.ex) ? F_WRLCK : F_RDLCK;
                fl->fl_flags = FL_POSIX;
-               fl->fl_pid = -op->info.pid;
+               fl->fl_pid = op->info.pid;
+               if (op->info.nodeid != dlm_our_nodeid())
+                       fl->fl_pid = -fl->fl_pid;
                fl->fl_start = op->info.start;
                fl->fl_end = op->info.end;
                rv = 0;
-- 
2.31.1

Reply via email to