Commit dd459bb1 authored by Jeff Layton's avatar Jeff Layton

locks: have locks_release_file use flock_lock_file to release generic flock locks

...instead of open-coding it and removing flock locks directly. This
helps consolidate the flock lock removal logic into a single spot.
Signed-off-by: default avatarJeff Layton <jlayton@primarydata.com>
parent 6dee60f6
...@@ -2360,22 +2360,9 @@ void locks_remove_posix(struct file *filp, fl_owner_t owner) ...@@ -2360,22 +2360,9 @@ void locks_remove_posix(struct file *filp, fl_owner_t owner)
EXPORT_SYMBOL(locks_remove_posix); EXPORT_SYMBOL(locks_remove_posix);
/* static void
* This function is called on the last close of an open file. locks_remove_flock(struct file *filp)
*/
void locks_remove_file(struct file *filp)
{ {
struct inode * inode = file_inode(filp);
struct file_lock *fl;
struct file_lock **before;
LIST_HEAD(dispose);
if (!inode->i_flock)
return;
locks_remove_posix(filp, filp);
if (filp->f_op->flock) {
struct file_lock fl = { struct file_lock fl = {
.fl_owner = filp, .fl_owner = filp,
.fl_pid = current->tgid, .fl_pid = current->tgid,
...@@ -2384,10 +2371,37 @@ void locks_remove_file(struct file *filp) ...@@ -2384,10 +2371,37 @@ void locks_remove_file(struct file *filp)
.fl_type = F_UNLCK, .fl_type = F_UNLCK,
.fl_end = OFFSET_MAX, .fl_end = OFFSET_MAX,
}; };
if (!file_inode(filp)->i_flock)
return;
if (filp->f_op->flock)
filp->f_op->flock(filp, F_SETLKW, &fl); filp->f_op->flock(filp, F_SETLKW, &fl);
else
flock_lock_file(filp, &fl);
if (fl.fl_ops && fl.fl_ops->fl_release_private) if (fl.fl_ops && fl.fl_ops->fl_release_private)
fl.fl_ops->fl_release_private(&fl); fl.fl_ops->fl_release_private(&fl);
} }
/*
* This function is called on the last close of an open file.
*/
void locks_remove_file(struct file *filp)
{
struct inode * inode = file_inode(filp);
struct file_lock *fl;
struct file_lock **before;
LIST_HEAD(dispose);
/* remove any OFD locks */
locks_remove_posix(filp, filp);
/* remove flock locks */
locks_remove_flock(filp);
if (!inode->i_flock)
return;
spin_lock(&inode->i_lock); spin_lock(&inode->i_lock);
before = &inode->i_flock; before = &inode->i_flock;
...@@ -2407,8 +2421,7 @@ void locks_remove_file(struct file *filp) ...@@ -2407,8 +2421,7 @@ void locks_remove_file(struct file *filp)
* some info about it and then just remove it from * some info about it and then just remove it from
* the list. * the list.
*/ */
WARN(!IS_FLOCK(fl), WARN(1, "leftover lock: dev=%u:%u ino=%lu type=%hhd flags=0x%x start=%lld end=%lld\n",
"leftover lock: dev=%u:%u ino=%lu type=%hhd flags=0x%x start=%lld end=%lld\n",
MAJOR(inode->i_sb->s_dev), MAJOR(inode->i_sb->s_dev),
MINOR(inode->i_sb->s_dev), inode->i_ino, MINOR(inode->i_sb->s_dev), inode->i_ino,
fl->fl_type, fl->fl_flags, fl->fl_type, fl->fl_flags,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment