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>

authored by Herb Shiu and committed by Sage Weil a5b10629 637ae8d5

+30 -8
+30 -8
fs/ceph/locks.c
··· 49 49 req->r_args.filelock_change.wait = wait; 50 50 51 51 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 + } 52 71 ceph_mdsc_put_request(req); 53 72 dout("ceph_lock_message: rule: %d, op: %d, pid: %llu, start: %llu, " 54 73 "length: %llu, wait: %d, type`: %d, err code %d", (int)lock_type, ··· 105 86 106 87 err = ceph_lock_message(CEPH_LOCK_FCNTL, op, file, lock_cmd, wait, fl); 107 88 if (!err) { 108 - dout("mds locked, locking locally"); 109 - err = posix_lock_file(file, fl, NULL); 110 - if (err && (CEPH_MDS_OP_SETFILELOCK == op)) { 111 - /* undo! This should only happen if the kernel detects 112 - * local deadlock. */ 113 - ceph_lock_message(CEPH_LOCK_FCNTL, op, file, 114 - CEPH_LOCK_UNLOCK, 0, fl); 115 - dout("got %d on posix_lock_file, undid lock", err); 89 + if ( op != CEPH_MDS_OP_GETFILELOCK ){ 90 + dout("mds locked, locking locally"); 91 + err = posix_lock_file(file, fl, NULL); 92 + if (err && (CEPH_MDS_OP_SETFILELOCK == op)) { 93 + /* undo! This should only happen if the kernel detects 94 + * local deadlock. */ 95 + ceph_lock_message(CEPH_LOCK_FCNTL, op, file, 96 + CEPH_LOCK_UNLOCK, 0, fl); 97 + dout("got %d on posix_lock_file, undid lock", err); 98 + } 116 99 } 100 + 117 101 } else { 118 102 dout("mds returned error code %d", err); 119 103 }