ceph: unwind canceled flock state

If we request a lock and then abort (e.g., ^C), we need to send a matching
unlock request to the MDS to unwind our lock attempt to avoid indefinitely
blocking other clients.

Reported-by: Brian Chrisman <brchrisman@gmail.com>
Signed-off-by: Sage Weil <sage@newdream.net>

Sage Weil 0c1f91f2 0e98728f

Changed files
+16 -10
fs
ceph
+16 -10
fs/ceph/locks.c
··· 33 33 length = fl->fl_end - fl->fl_start + 1; 34 34 35 35 dout("ceph_lock_message: rule: %d, op: %d, pid: %llu, start: %llu, " 36 - "length: %llu, wait: %d, type`: %d", (int)lock_type, 36 + "length: %llu, wait: %d, type: %d", (int)lock_type, 37 37 (int)operation, (u64)fl->fl_pid, fl->fl_start, 38 38 length, wait, fl->fl_type); 39 - 40 39 41 40 req->r_args.filelock_change.rule = lock_type; 42 41 req->r_args.filelock_change.type = cmd; ··· 70 71 } 71 72 ceph_mdsc_put_request(req); 72 73 dout("ceph_lock_message: rule: %d, op: %d, pid: %llu, start: %llu, " 73 - "length: %llu, wait: %d, type`: %d, err code %d", (int)lock_type, 74 + "length: %llu, wait: %d, type: %d, err code %d", (int)lock_type, 74 75 (int)operation, (u64)fl->fl_pid, fl->fl_start, 75 76 length, wait, fl->fl_type, err); 76 77 return err; ··· 109 110 dout("mds locked, locking locally"); 110 111 err = posix_lock_file(file, fl, NULL); 111 112 if (err && (CEPH_MDS_OP_SETFILELOCK == op)) { 112 - /* undo! This should only happen if the kernel detects 113 - * local deadlock. */ 113 + /* undo! This should only happen if 114 + * the kernel detects local 115 + * deadlock. */ 114 116 ceph_lock_message(CEPH_LOCK_FCNTL, op, file, 115 117 CEPH_LOCK_UNLOCK, 0, fl); 116 - dout("got %d on posix_lock_file, undid lock", err); 118 + dout("got %d on posix_lock_file, undid lock", 119 + err); 117 120 } 118 121 } 119 122 120 - } else { 121 - dout("mds returned error code %d", err); 123 + } else if (err == -ERESTARTSYS) { 124 + dout("undoing lock\n"); 125 + ceph_lock_message(CEPH_LOCK_FCNTL, op, file, 126 + CEPH_LOCK_UNLOCK, 0, fl); 122 127 } 123 128 return err; 124 129 } ··· 159 156 file, CEPH_LOCK_UNLOCK, 0, fl); 160 157 dout("got %d on flock_lock_file_wait, undid lock", err); 161 158 } 162 - } else { 163 - dout("mds error code %d", err); 159 + } else if (err == -ERESTARTSYS) { 160 + dout("undoing lock\n"); 161 + ceph_lock_message(CEPH_LOCK_FLOCK, 162 + CEPH_MDS_OP_SETFILELOCK, 163 + file, CEPH_LOCK_UNLOCK, 0, fl); 164 164 } 165 165 return err; 166 166 }