lkml.org 
[lkml]   [2014]   [Sep]   [10]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Subject[RFC PATCH 03/12] locks: have locks_release_file use flock_lock_file to release generic flock locks
    Date
    Signed-off-by: Jeff Layton <jlayton@primarydata.com>
    ---
    fs/locks.c | 49 +++++++++++++++++++++++++++++++------------------
    1 file changed, 31 insertions(+), 18 deletions(-)

    diff --git a/fs/locks.c b/fs/locks.c
    index af55bd35be5f..5e8b865814a2 100644
    --- a/fs/locks.c
    +++ b/fs/locks.c
    @@ -2393,6 +2393,30 @@ void locks_remove_posix(struct file *filp, fl_owner_t owner)

    EXPORT_SYMBOL(locks_remove_posix);

    +static void
    +locks_remove_flock(struct file *filp)
    +{
    + struct file_lock fl = {
    + .fl_owner = filp,
    + .fl_pid = current->tgid,
    + .fl_file = filp,
    + .fl_flags = FL_FLOCK,
    + .fl_type = F_UNLCK,
    + .fl_end = OFFSET_MAX,
    + };
    +
    + if (!file_inode(filp)->i_flock)
    + return;
    +
    + if (filp->f_op->flock)
    + filp->f_op->flock(filp, F_SETLKW, &fl);
    + else
    + flock_lock_file(filp, &fl);
    +
    + if (fl.fl_ops && fl.fl_ops->fl_release_private)
    + fl.fl_ops->fl_release_private(&fl);
    +}
    +
    /*
    * This function is called on the last close of an open file.
    */
    @@ -2403,24 +2427,14 @@ void locks_remove_file(struct file *filp)
    struct file_lock **before;
    LIST_HEAD(dispose);

    - if (!inode->i_flock)
    - return;
    -
    + /* remove any OFD locks */
    locks_remove_posix(filp, filp);

    - if (filp->f_op->flock) {
    - struct file_lock fl = {
    - .fl_owner = filp,
    - .fl_pid = current->tgid,
    - .fl_file = filp,
    - .fl_flags = FL_FLOCK,
    - .fl_type = F_UNLCK,
    - .fl_end = OFFSET_MAX,
    - };
    - filp->f_op->flock(filp, F_SETLKW, &fl);
    - if (fl.fl_ops && fl.fl_ops->fl_release_private)
    - fl.fl_ops->fl_release_private(&fl);
    - }
    + /* remove flock locks */
    + locks_remove_flock(filp);
    +
    + if (!inode->i_flock)
    + return;

    spin_lock(&inode->i_lock);
    before = &inode->i_flock;
    @@ -2440,8 +2454,7 @@ void locks_remove_file(struct file *filp)
    * some info about it and then just remove it from
    * the list.
    */
    - WARN(!IS_FLOCK(fl),
    - "leftover lock: dev=%u:%u ino=%lu type=%hhd flags=0x%x start=%lld end=%lld\n",
    + WARN(1, "leftover lock: dev=%u:%u ino=%lu type=%hhd flags=0x%x start=%lld end=%lld\n",
    MAJOR(inode->i_sb->s_dev),
    MINOR(inode->i_sb->s_dev), inode->i_ino,
    fl->fl_type, fl->fl_flags,
    --
    1.9.3


    \
     
     \ /
      Last update: 2014-09-10 17:01    [W:2.944 / U:0.124 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site