Skip to content

Commit bbb480a

Browse files
ukernelidryomov
authored andcommitted
ceph: check if file lock exists before sending unlock request
When a process exits, kernel closes its files. locks_remove_file() is called to remove file locks on these files. locks_remove_file() tries unlocking files even there is no file lock. Signed-off-by: "Yan, Zheng" <zyan@redhat.com> Reviewed-by: Jeff Layton <jlayton@kernel.org> Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
1 parent cb63483 commit bbb480a

1 file changed

Lines changed: 29 additions & 2 deletions

File tree

‎fs/ceph/locks.c‎

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,21 @@ static int ceph_lock_wait_for_completion(struct ceph_mds_client *mdsc,
210210
return 0;
211211
}
212212

213+
static int try_unlock_file(struct file *file, struct file_lock *fl)
214+
{
215+
int err;
216+
unsigned int orig_flags = fl->fl_flags;
217+
fl->fl_flags |= FL_EXISTS;
218+
err = locks_lock_file_wait(file, fl);
219+
fl->fl_flags = orig_flags;
220+
if (err == -ENOENT) {
221+
if (!(orig_flags & FL_EXISTS))
222+
err = 0;
223+
return err;
224+
}
225+
return 1;
226+
}
227+
213228
/**
214229
* Attempt to set an fcntl lock.
215230
* For now, this just goes away to the server. Later it may be more awesome.
@@ -255,9 +270,15 @@ int ceph_lock(struct file *file, int cmd, struct file_lock *fl)
255270
else
256271
lock_cmd = CEPH_LOCK_UNLOCK;
257272

273+
if (op == CEPH_MDS_OP_SETFILELOCK && F_UNLCK == fl->fl_type) {
274+
err = try_unlock_file(file, fl);
275+
if (err <= 0)
276+
return err;
277+
}
278+
258279
err = ceph_lock_message(CEPH_LOCK_FCNTL, op, inode, lock_cmd, wait, fl);
259280
if (!err) {
260-
if (op == CEPH_MDS_OP_SETFILELOCK) {
281+
if (op == CEPH_MDS_OP_SETFILELOCK && F_UNLCK != fl->fl_type) {
261282
dout("mds locked, locking locally\n");
262283
err = posix_lock_file(file, fl, NULL);
263284
if (err) {
@@ -311,9 +332,15 @@ int ceph_flock(struct file *file, int cmd, struct file_lock *fl)
311332
else
312333
lock_cmd = CEPH_LOCK_UNLOCK;
313334

335+
if (F_UNLCK == fl->fl_type) {
336+
err = try_unlock_file(file, fl);
337+
if (err <= 0)
338+
return err;
339+
}
340+
314341
err = ceph_lock_message(CEPH_LOCK_FLOCK, CEPH_MDS_OP_SETFILELOCK,
315342
inode, lock_cmd, wait, fl);
316-
if (!err) {
343+
if (!err && F_UNLCK != fl->fl_type) {
317344
err = locks_lock_file_wait(file, fl);
318345
if (err) {
319346
ceph_lock_message(CEPH_LOCK_FLOCK,

0 commit comments

Comments
 (0)