Commit a5b10629 authored by Herb Shiu's avatar Herb Shiu Committed by Sage Weil

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: default avatarHerb Shiu <herb_shiu@tcloudcomputing.com>
Acked-by: default avatarGreg Farnum <gregf@hq.newdream.net>
Signed-off-by: default avatarSage Weil <sage@newdream.net>
parent 637ae8d5
...@@ -49,6 +49,25 @@ static int ceph_lock_message(u8 lock_type, u16 operation, struct file *file, ...@@ -49,6 +49,25 @@ static int ceph_lock_message(u8 lock_type, u16 operation, struct file *file,
req->r_args.filelock_change.wait = wait; req->r_args.filelock_change.wait = wait;
err = ceph_mdsc_do_request(mdsc, inode, req); err = ceph_mdsc_do_request(mdsc, inode, req);
if ( operation == CEPH_MDS_OP_GETFILELOCK){
fl->fl_pid = le64_to_cpu(req->r_reply_info.filelock_reply->pid);
if (CEPH_LOCK_SHARED == req->r_reply_info.filelock_reply->type)
fl->fl_type = F_RDLCK;
else if (CEPH_LOCK_EXCL == req->r_reply_info.filelock_reply->type)
fl->fl_type = F_WRLCK;
else
fl->fl_type = F_UNLCK;
fl->fl_start = le64_to_cpu(req->r_reply_info.filelock_reply->start);
length = le64_to_cpu(req->r_reply_info.filelock_reply->start) +
le64_to_cpu(req->r_reply_info.filelock_reply->length);
if (length >= 1)
fl->fl_end = length -1;
else
fl->fl_end = 0;
}
ceph_mdsc_put_request(req); ceph_mdsc_put_request(req);
dout("ceph_lock_message: rule: %d, op: %d, pid: %llu, start: %llu, " dout("ceph_lock_message: rule: %d, op: %d, pid: %llu, start: %llu, "
"length: %llu, wait: %d, type`: %d, err code %d", (int)lock_type, "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) ...@@ -86,15 +105,18 @@ int ceph_lock(struct file *file, int cmd, struct file_lock *fl)
err = ceph_lock_message(CEPH_LOCK_FCNTL, op, file, lock_cmd, wait, fl); err = ceph_lock_message(CEPH_LOCK_FCNTL, op, file, lock_cmd, wait, fl);
if (!err) { if (!err) {
dout("mds locked, locking locally"); if ( op != CEPH_MDS_OP_GETFILELOCK ){
err = posix_lock_file(file, fl, NULL); dout("mds locked, locking locally");
if (err && (CEPH_MDS_OP_SETFILELOCK == op)) { err = posix_lock_file(file, fl, NULL);
/* undo! This should only happen if the kernel detects if (err && (CEPH_MDS_OP_SETFILELOCK == op)) {
* local deadlock. */ /* undo! This should only happen if the kernel detects
ceph_lock_message(CEPH_LOCK_FCNTL, op, file, * local deadlock. */
CEPH_LOCK_UNLOCK, 0, fl); ceph_lock_message(CEPH_LOCK_FCNTL, op, file,
dout("got %d on posix_lock_file, undid lock", err); CEPH_LOCK_UNLOCK, 0, fl);
dout("got %d on posix_lock_file, undid lock", err);
}
} }
} else { } else {
dout("mds returned error code %d", err); dout("mds returned error code %d", err);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment