Skip to content

Commit 0c1f91f

Browse files
committed
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>
1 parent 0e98728 commit 0c1f91f

1 file changed

Lines changed: 16 additions & 10 deletions

File tree

‎fs/ceph/locks.c‎

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,10 @@ static int ceph_lock_message(u8 lock_type, u16 operation, struct file *file,
3333
length = fl->fl_end - fl->fl_start + 1;
3434

3535
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,
3737
(int)operation, (u64)fl->fl_pid, fl->fl_start,
3838
length, wait, fl->fl_type);
3939

40-
4140
req->r_args.filelock_change.rule = lock_type;
4241
req->r_args.filelock_change.type = cmd;
4342
req->r_args.filelock_change.pid = cpu_to_le64((u64)fl->fl_pid);
@@ -71,7 +70,7 @@ static int ceph_lock_message(u8 lock_type, u16 operation, struct file *file,
7170
}
7271
ceph_mdsc_put_request(req);
7372
dout("ceph_lock_message: rule: %d, op: %d, pid: %llu, start: %llu, "
74-
"length: %llu, wait: %d, type`: %d, err code %d", (int)lock_type,
73+
"length: %llu, wait: %d, type: %d, err code %d", (int)lock_type,
7574
(int)operation, (u64)fl->fl_pid, fl->fl_start,
7675
length, wait, fl->fl_type, err);
7776
return err;
@@ -110,16 +109,20 @@ int ceph_lock(struct file *file, int cmd, struct file_lock *fl)
110109
dout("mds locked, locking locally");
111110
err = posix_lock_file(file, fl, NULL);
112111
if (err && (CEPH_MDS_OP_SETFILELOCK == op)) {
113-
/* undo! This should only happen if the kernel detects
114-
* local deadlock. */
112+
/* undo! This should only happen if
113+
* the kernel detects local
114+
* deadlock. */
115115
ceph_lock_message(CEPH_LOCK_FCNTL, op, file,
116116
CEPH_LOCK_UNLOCK, 0, fl);
117-
dout("got %d on posix_lock_file, undid lock", err);
117+
dout("got %d on posix_lock_file, undid lock",
118+
err);
118119
}
119120
}
120121

121-
} else {
122-
dout("mds returned error code %d", err);
122+
} else if (err == -ERESTARTSYS) {
123+
dout("undoing lock\n");
124+
ceph_lock_message(CEPH_LOCK_FCNTL, op, file,
125+
CEPH_LOCK_UNLOCK, 0, fl);
123126
}
124127
return err;
125128
}
@@ -156,8 +159,11 @@ int ceph_flock(struct file *file, int cmd, struct file_lock *fl)
156159
file, CEPH_LOCK_UNLOCK, 0, fl);
157160
dout("got %d on flock_lock_file_wait, undid lock", err);
158161
}
159-
} else {
160-
dout("mds error code %d", err);
162+
} else if (err == -ERESTARTSYS) {
163+
dout("undoing lock\n");
164+
ceph_lock_message(CEPH_LOCK_FLOCK,
165+
CEPH_MDS_OP_SETFILELOCK,
166+
file, CEPH_LOCK_UNLOCK, 0, fl);
161167
}
162168
return err;
163169
}

0 commit comments

Comments
 (0)