ceph: use fl->fl_type to decide flock operation

VFS does not directly pass flock's operation code to filesystem's
flock callback. It translates the operation code to the form how
posix lock's parameters are presented.

Signed-off-by: Yan, Zheng <zheng.z.yan@intel.com>
This commit is contained in:
Yan, Zheng 2014-03-04 15:42:24 +08:00 committed by Sage Weil
parent 8c93cd610c
commit 0e8e95d6d7
1 changed files with 9 additions and 12 deletions

View File

@ -91,10 +91,10 @@ int ceph_lock(struct file *file, int cmd, struct file_lock *fl)
dout("ceph_lock, fl_pid:%d", fl->fl_pid); dout("ceph_lock, fl_pid:%d", fl->fl_pid);
/* set wait bit as appropriate, then make command as Ceph expects it*/ /* set wait bit as appropriate, then make command as Ceph expects it*/
if (F_SETLKW == cmd) if (IS_GETLK(cmd))
wait = 1;
if (F_GETLK == cmd)
op = CEPH_MDS_OP_GETFILELOCK; op = CEPH_MDS_OP_GETFILELOCK;
else if (IS_SETLKW(cmd))
wait = 1;
if (F_RDLCK == fl->fl_type) if (F_RDLCK == fl->fl_type)
lock_cmd = CEPH_LOCK_SHARED; lock_cmd = CEPH_LOCK_SHARED;
@ -131,20 +131,17 @@ int ceph_flock(struct file *file, int cmd, struct file_lock *fl)
{ {
u8 lock_cmd; u8 lock_cmd;
int err; int err;
u8 wait = 1; u8 wait = 0;
fl->fl_nspid = get_pid(task_tgid(current)); fl->fl_nspid = get_pid(task_tgid(current));
dout("ceph_flock, fl_pid:%d", fl->fl_pid); dout("ceph_flock, fl_pid:%d", fl->fl_pid);
/* set wait bit, then clear it out of cmd*/ if (IS_SETLKW(cmd))
if (cmd & LOCK_NB) wait = 1;
wait = 0;
cmd = cmd & (LOCK_SH | LOCK_EX | LOCK_UN); if (F_RDLCK == fl->fl_type)
/* set command sequence that Ceph wants to see:
shared lock, exclusive lock, or unlock */
if (LOCK_SH == cmd)
lock_cmd = CEPH_LOCK_SHARED; lock_cmd = CEPH_LOCK_SHARED;
else if (LOCK_EX == cmd) else if (F_WRLCK == fl->fl_type)
lock_cmd = CEPH_LOCK_EXCL; lock_cmd = CEPH_LOCK_EXCL;
else else
lock_cmd = CEPH_LOCK_UNLOCK; lock_cmd = CEPH_LOCK_UNLOCK;