Skip to content

Commit a5b1062

Browse files
herbshiuliewegas
authored andcommitted
ceph: Behave better when handling file lock replies.
Fill in the local lock with response data if appropriate, and don't call posix_lock_file when reading locks. Signed-off-by: Herb Shiu <herb_shiu@tcloudcomputing.com> Acked-by: Greg Farnum <gregf@hq.newdream.net> Signed-off-by: Sage Weil <sage@newdream.net>
1 parent 637ae8d commit a5b1062

1 file changed

Lines changed: 30 additions & 8 deletions

File tree

‎fs/ceph/locks.c‎

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,25 @@ static int ceph_lock_message(u8 lock_type, u16 operation, struct file *file,
4949
req->r_args.filelock_change.wait = wait;
5050

5151
err = ceph_mdsc_do_request(mdsc, inode, req);
52+
53+
if ( operation == CEPH_MDS_OP_GETFILELOCK){
54+
fl->fl_pid = le64_to_cpu(req->r_reply_info.filelock_reply->pid);
55+
if (CEPH_LOCK_SHARED == req->r_reply_info.filelock_reply->type)
56+
fl->fl_type = F_RDLCK;
57+
else if (CEPH_LOCK_EXCL == req->r_reply_info.filelock_reply->type)
58+
fl->fl_type = F_WRLCK;
59+
else
60+
fl->fl_type = F_UNLCK;
61+
62+
fl->fl_start = le64_to_cpu(req->r_reply_info.filelock_reply->start);
63+
length = le64_to_cpu(req->r_reply_info.filelock_reply->start) +
64+
le64_to_cpu(req->r_reply_info.filelock_reply->length);
65+
if (length >= 1)
66+
fl->fl_end = length -1;
67+
else
68+
fl->fl_end = 0;
69+
70+
}
5271
ceph_mdsc_put_request(req);
5372
dout("ceph_lock_message: rule: %d, op: %d, pid: %llu, start: %llu, "
5473
"length: %llu, wait: %d, type`: %d, err code %d", (int)lock_type,
@@ -86,15 +105,18 @@ int ceph_lock(struct file *file, int cmd, struct file_lock *fl)
86105

87106
err = ceph_lock_message(CEPH_LOCK_FCNTL, op, file, lock_cmd, wait, fl);
88107
if (!err) {
89-
dout("mds locked, locking locally");
90-
err = posix_lock_file(file, fl, NULL);
91-
if (err && (CEPH_MDS_OP_SETFILELOCK == op)) {
92-
/* undo! This should only happen if the kernel detects
93-
* local deadlock. */
94-
ceph_lock_message(CEPH_LOCK_FCNTL, op, file,
95-
CEPH_LOCK_UNLOCK, 0, fl);
96-
dout("got %d on posix_lock_file, undid lock", err);
108+
if ( op != CEPH_MDS_OP_GETFILELOCK ){
109+
dout("mds locked, locking locally");
110+
err = posix_lock_file(file, fl, NULL);
111+
if (err && (CEPH_MDS_OP_SETFILELOCK == op)) {
112+
/* undo! This should only happen if the kernel detects
113+
* local deadlock. */
114+
ceph_lock_message(CEPH_LOCK_FCNTL, op, file,
115+
CEPH_LOCK_UNLOCK, 0, fl);
116+
dout("got %d on posix_lock_file, undid lock", err);
117+
}
97118
}
119+
98120
} else {
99121
dout("mds returned error code %d", err);
100122
}

0 commit comments

Comments
 (0)