ceph: pass lock information by struct file_lock instead of as individual params.

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 637ae8d5 25933abd

+21 -37
+21 -37
fs/ceph/locks.c
··· 11 * Implement fcntl and flock locking functions. 12 */ 13 static int ceph_lock_message(u8 lock_type, u16 operation, struct file *file, 14 - u64 pid, u64 pid_ns, 15 - int cmd, u64 start, u64 length, u8 wait) 16 { 17 struct inode *inode = file->f_dentry->d_inode; 18 struct ceph_mds_client *mdsc = 19 ceph_sb_to_client(inode->i_sb)->mdsc; 20 struct ceph_mds_request *req; 21 int err; 22 23 req = ceph_mdsc_create_request(mdsc, operation, USE_AUTH_MDS); 24 if (IS_ERR(req)) 25 return PTR_ERR(req); 26 req->r_inode = igrab(inode); 27 28 dout("ceph_lock_message: rule: %d, op: %d, pid: %llu, start: %llu, " 29 "length: %llu, wait: %d, type`: %d", (int)lock_type, 30 - (int)operation, pid, start, length, wait, cmd); 31 32 req->r_args.filelock_change.rule = lock_type; 33 req->r_args.filelock_change.type = cmd; 34 - req->r_args.filelock_change.pid = cpu_to_le64(pid); 35 /* This should be adjusted, but I'm not sure if 36 namespaces actually get id numbers*/ 37 req->r_args.filelock_change.pid_namespace = 38 - cpu_to_le64((u64)pid_ns); 39 - req->r_args.filelock_change.start = cpu_to_le64(start); 40 req->r_args.filelock_change.length = cpu_to_le64(length); 41 req->r_args.filelock_change.wait = wait; 42 43 err = ceph_mdsc_do_request(mdsc, inode, req); 44 ceph_mdsc_put_request(req); 45 dout("ceph_lock_message: rule: %d, op: %d, pid: %llu, start: %llu, " 46 - "length: %llu, wait: %d, type`: %d err code %d", (int)lock_type, 47 - (int)operation, pid, start, length, wait, cmd, err); 48 return err; 49 } 50 ··· 63 */ 64 int ceph_lock(struct file *file, int cmd, struct file_lock *fl) 65 { 66 - u64 length; 67 u8 lock_cmd; 68 int err; 69 u8 wait = 0; ··· 84 else 85 lock_cmd = CEPH_LOCK_UNLOCK; 86 87 - if (LLONG_MAX == fl->fl_end) 88 - length = 0; 89 - else 90 - length = fl->fl_end - fl->fl_start + 1; 91 - 92 - err = ceph_lock_message(CEPH_LOCK_FCNTL, op, file, 93 - (u64)fl->fl_pid, 94 - (u64)(unsigned long)fl->fl_nspid, 95 - lock_cmd, fl->fl_start, 96 - length, wait); 97 if (!err) { 98 dout("mds locked, locking locally"); 99 err = posix_lock_file(file, fl, NULL); ··· 92 /* undo! This should only happen if the kernel detects 93 * local deadlock. */ 94 ceph_lock_message(CEPH_LOCK_FCNTL, op, file, 95 - (u64)fl->fl_pid, 96 - (u64)(unsigned long)fl->fl_nspid, 97 - CEPH_LOCK_UNLOCK, fl->fl_start, 98 - length, 0); 99 dout("got %d on posix_lock_file, undid lock", err); 100 } 101 } else { ··· 103 104 int ceph_flock(struct file *file, int cmd, struct file_lock *fl) 105 { 106 - u64 length; 107 u8 lock_cmd; 108 int err; 109 u8 wait = 1; ··· 122 lock_cmd = CEPH_LOCK_EXCL; 123 else 124 lock_cmd = CEPH_LOCK_UNLOCK; 125 - /* mds requires start and length rather than start and end */ 126 - if (LLONG_MAX == fl->fl_end) 127 - length = 0; 128 - else 129 - length = fl->fl_end - fl->fl_start + 1; 130 131 err = ceph_lock_message(CEPH_LOCK_FLOCK, CEPH_MDS_OP_SETFILELOCK, 132 - file, (u64)fl->fl_pid, 133 - (u64)(unsigned long)fl->fl_nspid, 134 - lock_cmd, fl->fl_start, 135 - length, wait); 136 if (!err) { 137 err = flock_lock_file_wait(file, fl); 138 if (err) { 139 ceph_lock_message(CEPH_LOCK_FLOCK, 140 CEPH_MDS_OP_SETFILELOCK, 141 - file, (u64)fl->fl_pid, 142 - (u64)(unsigned long)fl->fl_nspid, 143 - CEPH_LOCK_UNLOCK, fl->fl_start, 144 - length, 0); 145 dout("got %d on flock_lock_file_wait, undid lock", err); 146 } 147 } else {
··· 11 * Implement fcntl and flock locking functions. 12 */ 13 static int ceph_lock_message(u8 lock_type, u16 operation, struct file *file, 14 + int cmd, u8 wait, struct file_lock *fl) 15 { 16 struct inode *inode = file->f_dentry->d_inode; 17 struct ceph_mds_client *mdsc = 18 ceph_sb_to_client(inode->i_sb)->mdsc; 19 struct ceph_mds_request *req; 20 int err; 21 + u64 length = 0; 22 23 req = ceph_mdsc_create_request(mdsc, operation, USE_AUTH_MDS); 24 if (IS_ERR(req)) 25 return PTR_ERR(req); 26 req->r_inode = igrab(inode); 27 28 + /* mds requires start and length rather than start and end */ 29 + if (LLONG_MAX == fl->fl_end) 30 + length = 0; 31 + else 32 + length = fl->fl_end - fl->fl_start + 1; 33 + 34 dout("ceph_lock_message: rule: %d, op: %d, pid: %llu, start: %llu, " 35 "length: %llu, wait: %d, type`: %d", (int)lock_type, 36 + (int)operation, (u64)fl->fl_pid, fl->fl_start, 37 + length, wait, fl->fl_type); 38 + 39 40 req->r_args.filelock_change.rule = lock_type; 41 req->r_args.filelock_change.type = cmd; 42 + req->r_args.filelock_change.pid = cpu_to_le64((u64)fl->fl_pid); 43 /* This should be adjusted, but I'm not sure if 44 namespaces actually get id numbers*/ 45 req->r_args.filelock_change.pid_namespace = 46 + cpu_to_le64((u64)(unsigned long)fl->fl_nspid); 47 + req->r_args.filelock_change.start = cpu_to_le64(fl->fl_start); 48 req->r_args.filelock_change.length = cpu_to_le64(length); 49 req->r_args.filelock_change.wait = wait; 50 51 err = ceph_mdsc_do_request(mdsc, inode, req); 52 ceph_mdsc_put_request(req); 53 dout("ceph_lock_message: rule: %d, op: %d, pid: %llu, start: %llu, " 54 + "length: %llu, wait: %d, type`: %d, err code %d", (int)lock_type, 55 + (int)operation, (u64)fl->fl_pid, fl->fl_start, 56 + length, wait, fl->fl_type, err); 57 return err; 58 } 59 ··· 54 */ 55 int ceph_lock(struct file *file, int cmd, struct file_lock *fl) 56 { 57 u8 lock_cmd; 58 int err; 59 u8 wait = 0; ··· 76 else 77 lock_cmd = CEPH_LOCK_UNLOCK; 78 79 + err = ceph_lock_message(CEPH_LOCK_FCNTL, op, file, lock_cmd, wait, fl); 80 if (!err) { 81 dout("mds locked, locking locally"); 82 err = posix_lock_file(file, fl, NULL); ··· 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 } 99 } else { ··· 107 108 int ceph_flock(struct file *file, int cmd, struct file_lock *fl) 109 { 110 u8 lock_cmd; 111 int err; 112 u8 wait = 1; ··· 127 lock_cmd = CEPH_LOCK_EXCL; 128 else 129 lock_cmd = CEPH_LOCK_UNLOCK; 130 131 err = ceph_lock_message(CEPH_LOCK_FLOCK, CEPH_MDS_OP_SETFILELOCK, 132 + file, lock_cmd, wait, fl); 133 if (!err) { 134 err = flock_lock_file_wait(file, fl); 135 if (err) { 136 ceph_lock_message(CEPH_LOCK_FLOCK, 137 CEPH_MDS_OP_SETFILELOCK, 138 + file, CEPH_LOCK_UNLOCK, 0, fl); 139 dout("got %d on flock_lock_file_wait, undid lock", err); 140 } 141 } else {