VFS,locks: locks: don't unnecessarily fail posix lock operations --- fs/locks.c | 27 ++++++++++++++++++++------- 1 files changed, 20 insertions(+), 7 deletions(-) diff --git a/fs/locks.c b/fs/locks.c index 6ba3756..973c1d9 100644 --- a/fs/locks.c +++ b/fs/locks.c @@ -839,10 +839,6 @@ static int __posix_lock_file_conf(struct if (request->fl_flags & FL_ACCESS) goto out; - error = -ENOLCK; /* "no luck" */ - if (!(new_fl && new_fl2)) - goto out; - /* * We've allocated the new locks in advance, so there are no * errors possible (and no blocking operations) from here on. @@ -943,9 +939,25 @@ static int __posix_lock_file_conf(struct before = &fl->fl_next; } - error = 0; - if (!added) { - if (request->fl_type == F_UNLCK) + if (request->fl_type == F_UNLCK) { + if (!added) + goto out; + if (!new_fl2 && right && left == right) { + new_fl2 = new_fl; + error = -ENOLCK; + if (!new_fl2) + goto out; + new_fl = NULL; + } + } else if (!added) { + error = -ENOLCK; + if (!new_fl) { + new_fl = new_fl2; + if (!new_fl) + goto out; + new_fl2 = NULL; + } + if (!new_fl2 && right && left == right) goto out; locks_copy_lock(new_fl, request); locks_insert_lock(before, new_fl); @@ -968,6 +980,7 @@ static int __posix_lock_file_conf(struct left->fl_end = request->fl_start - 1; locks_wake_up_blocks(left); } + error = 0; out: unlock_kernel(); /*