Move locks API users to locks_lock_inode_wait()

Instead of having users check for FL_POSIX or FL_FLOCK to call the correct
locks API function, use the check within locks_lock_inode_wait().  This
allows for some later cleanup.

Signed-off-by: Benjamin Coddington <bcodding@redhat.com>
Signed-off-by: Jeff Layton <jeff.layton@primarydata.com>
This commit is contained in:
Benjamin Coddington 2015-10-22 13:38:14 -04:00 committed by Jeff Layton
parent e55c34a66f
commit 4f6563677a
12 changed files with 22 additions and 59 deletions

View File

@ -2763,13 +2763,9 @@ ll_file_flock(struct file *file, int cmd, struct file_lock *file_lock)
rc = md_enqueue(sbi->ll_md_exp, &einfo, NULL, rc = md_enqueue(sbi->ll_md_exp, &einfo, NULL,
op_data, &lockh, &flock, 0, NULL /* req */, flags); op_data, &lockh, &flock, 0, NULL /* req */, flags);
if ((file_lock->fl_flags & FL_FLOCK) && if ((rc == 0 || file_lock->fl_type == F_UNLCK) &&
(rc == 0 || file_lock->fl_type == F_UNLCK))
rc2 = flock_lock_file_wait(file, file_lock);
if ((file_lock->fl_flags & FL_POSIX) &&
(rc == 0 || file_lock->fl_type == F_UNLCK) &&
!(flags & LDLM_FL_TEST_LOCK)) !(flags & LDLM_FL_TEST_LOCK))
rc2 = posix_lock_file_wait(file, file_lock); rc2 = locks_lock_file_wait(file, file_lock);
if (rc2 && file_lock->fl_type != F_UNLCK) { if (rc2 && file_lock->fl_type != F_UNLCK) {
einfo.ei_mode = LCK_NL; einfo.ei_mode = LCK_NL;

View File

@ -161,7 +161,7 @@ static int v9fs_file_do_lock(struct file *filp, int cmd, struct file_lock *fl)
if ((fl->fl_flags & FL_POSIX) != FL_POSIX) if ((fl->fl_flags & FL_POSIX) != FL_POSIX)
BUG(); BUG();
res = posix_lock_file_wait(filp, fl); res = locks_lock_file_wait(filp, fl);
if (res < 0) if (res < 0)
goto out; goto out;
@ -231,7 +231,7 @@ out_unlock:
if (res < 0 && fl->fl_type != F_UNLCK) { if (res < 0 && fl->fl_type != F_UNLCK) {
fl_type = fl->fl_type; fl_type = fl->fl_type;
fl->fl_type = F_UNLCK; fl->fl_type = F_UNLCK;
res = posix_lock_file_wait(filp, fl); res = locks_lock_file_wait(filp, fl);
fl->fl_type = fl_type; fl->fl_type = fl_type;
} }
out: out:

View File

@ -228,12 +228,12 @@ int ceph_flock(struct file *file, int cmd, struct file_lock *fl)
err = ceph_lock_message(CEPH_LOCK_FLOCK, CEPH_MDS_OP_SETFILELOCK, err = ceph_lock_message(CEPH_LOCK_FLOCK, CEPH_MDS_OP_SETFILELOCK,
file, lock_cmd, wait, fl); file, lock_cmd, wait, fl);
if (!err) { if (!err) {
err = flock_lock_file_wait(file, fl); err = locks_lock_file_wait(file, fl);
if (err) { if (err) {
ceph_lock_message(CEPH_LOCK_FLOCK, ceph_lock_message(CEPH_LOCK_FLOCK,
CEPH_MDS_OP_SETFILELOCK, CEPH_MDS_OP_SETFILELOCK,
file, CEPH_LOCK_UNLOCK, 0, fl); file, CEPH_LOCK_UNLOCK, 0, fl);
dout("got %d on flock_lock_file_wait, undid lock", err); dout("got %d on locks_lock_file_wait, undid lock", err);
} }
} }
return err; return err;

View File

@ -1553,7 +1553,7 @@ cifs_setlk(struct file *file, struct file_lock *flock, __u32 type,
out: out:
if (flock->fl_flags & FL_POSIX && !rc) if (flock->fl_flags & FL_POSIX && !rc)
rc = posix_lock_file_wait(file, flock); rc = locks_lock_file_wait(file, flock);
return rc; return rc;
} }

View File

@ -172,7 +172,7 @@ int dlm_posix_lock(dlm_lockspace_t *lockspace, u64 number, struct file *file,
rv = op->info.rv; rv = op->info.rv;
if (!rv) { if (!rv) {
if (posix_lock_file_wait(file, fl) < 0) if (locks_lock_file_wait(file, fl) < 0)
log_error(ls, "dlm_posix_lock: vfs lock error %llx", log_error(ls, "dlm_posix_lock: vfs lock error %llx",
(unsigned long long)number); (unsigned long long)number);
} }
@ -262,7 +262,7 @@ int dlm_posix_unlock(dlm_lockspace_t *lockspace, u64 number, struct file *file,
/* cause the vfs unlock to return ENOENT if lock is not found */ /* cause the vfs unlock to return ENOENT if lock is not found */
fl->fl_flags |= FL_EXISTS; fl->fl_flags |= FL_EXISTS;
rv = posix_lock_file_wait(file, fl); rv = locks_lock_file_wait(file, fl);
if (rv == -ENOENT) { if (rv == -ENOENT) {
rv = 0; rv = 0;
goto out_free; goto out_free;

View File

@ -2189,7 +2189,7 @@ static int fuse_file_flock(struct file *file, int cmd, struct file_lock *fl)
int err; int err;
if (fc->no_flock) { if (fc->no_flock) {
err = flock_lock_file_wait(file, fl); err = locks_lock_file_wait(file, fl);
} else { } else {
struct fuse_file *ff = file->private_data; struct fuse_file *ff = file->private_data;

View File

@ -1000,7 +1000,7 @@ static int gfs2_lock(struct file *file, int cmd, struct file_lock *fl)
} }
if (unlikely(test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) { if (unlikely(test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) {
if (fl->fl_type == F_UNLCK) if (fl->fl_type == F_UNLCK)
posix_lock_file_wait(file, fl); locks_lock_file_wait(file, fl);
return -EIO; return -EIO;
} }
if (IS_GETLK(cmd)) if (IS_GETLK(cmd))
@ -1031,7 +1031,7 @@ static int do_flock(struct file *file, int cmd, struct file_lock *fl)
if (gl) { if (gl) {
if (fl_gh->gh_state == state) if (fl_gh->gh_state == state)
goto out; goto out;
flock_lock_file_wait(file, locks_lock_file_wait(file,
&(struct file_lock){.fl_type = F_UNLCK}); &(struct file_lock){.fl_type = F_UNLCK});
gfs2_glock_dq(fl_gh); gfs2_glock_dq(fl_gh);
gfs2_holder_reinit(state, flags, fl_gh); gfs2_holder_reinit(state, flags, fl_gh);
@ -1056,7 +1056,7 @@ static int do_flock(struct file *file, int cmd, struct file_lock *fl)
if (error == GLR_TRYFAILED) if (error == GLR_TRYFAILED)
error = -EAGAIN; error = -EAGAIN;
} else { } else {
error = flock_lock_file_wait(file, fl); error = locks_lock_file_wait(file, fl);
gfs2_assert_warn(GFS2_SB(&ip->i_inode), !error); gfs2_assert_warn(GFS2_SB(&ip->i_inode), !error);
} }
@ -1071,7 +1071,7 @@ static void do_unflock(struct file *file, struct file_lock *fl)
struct gfs2_holder *fl_gh = &fp->f_fl_gh; struct gfs2_holder *fl_gh = &fp->f_fl_gh;
mutex_lock(&fp->f_fl_mutex); mutex_lock(&fp->f_fl_mutex);
flock_lock_file_wait(file, fl); locks_lock_file_wait(file, fl);
if (fl_gh->gh_gl) { if (fl_gh->gh_gl) {
gfs2_glock_dq(fl_gh); gfs2_glock_dq(fl_gh);
gfs2_holder_uninit(fl_gh); gfs2_holder_uninit(fl_gh);

View File

@ -474,18 +474,7 @@ static void nlmclnt_locks_init_private(struct file_lock *fl, struct nlm_host *ho
static int do_vfs_lock(struct file_lock *fl) static int do_vfs_lock(struct file_lock *fl)
{ {
int res = 0; return locks_lock_file_wait(fl->fl_file, fl);
switch (fl->fl_flags & (FL_POSIX|FL_FLOCK)) {
case FL_POSIX:
res = posix_lock_file_wait(fl->fl_file, fl);
break;
case FL_FLOCK:
res = flock_lock_file_wait(fl->fl_file, fl);
break;
default:
BUG();
}
return res;
} }
/* /*

View File

@ -1961,7 +1961,7 @@ SYSCALL_DEFINE2(flock, unsigned int, fd, unsigned int, cmd)
(can_sleep) ? F_SETLKW : F_SETLK, (can_sleep) ? F_SETLKW : F_SETLK,
lock); lock);
else else
error = flock_lock_file_wait(f.file, lock); error = locks_lock_file_wait(f.file, lock);
out_free: out_free:
locks_free_lock(lock); locks_free_lock(lock);

View File

@ -738,18 +738,7 @@ out_noconflict:
static int do_vfs_lock(struct file *file, struct file_lock *fl) static int do_vfs_lock(struct file *file, struct file_lock *fl)
{ {
int res = 0; return locks_lock_file_wait(file, fl);
switch (fl->fl_flags & (FL_POSIX|FL_FLOCK)) {
case FL_POSIX:
res = posix_lock_file_wait(file, fl);
break;
case FL_FLOCK:
res = flock_lock_file_wait(file, fl);
break;
default:
BUG();
}
return res;
} }
static int static int

View File

@ -5472,18 +5472,7 @@ static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *
static int do_vfs_lock(struct inode *inode, struct file_lock *fl) static int do_vfs_lock(struct inode *inode, struct file_lock *fl)
{ {
int res = 0; return locks_lock_inode_wait(inode, fl);
switch (fl->fl_flags & (FL_POSIX|FL_FLOCK)) {
case FL_POSIX:
res = posix_lock_inode_wait(inode, fl);
break;
case FL_FLOCK:
res = flock_lock_inode_wait(inode, fl);
break;
default:
BUG();
}
return res;
} }
struct nfs4_unlockdata { struct nfs4_unlockdata {

View File

@ -66,7 +66,7 @@ static int ocfs2_do_flock(struct file *file, struct inode *inode,
* level. * level.
*/ */
flock_lock_file_wait(file, locks_lock_file_wait(file,
&(struct file_lock){.fl_type = F_UNLCK}); &(struct file_lock){.fl_type = F_UNLCK});
ocfs2_file_unlock(file); ocfs2_file_unlock(file);
@ -81,7 +81,7 @@ static int ocfs2_do_flock(struct file *file, struct inode *inode,
goto out; goto out;
} }
ret = flock_lock_file_wait(file, fl); ret = locks_lock_file_wait(file, fl);
if (ret) if (ret)
ocfs2_file_unlock(file); ocfs2_file_unlock(file);
@ -98,7 +98,7 @@ static int ocfs2_do_funlock(struct file *file, int cmd, struct file_lock *fl)
mutex_lock(&fp->fp_mutex); mutex_lock(&fp->fp_mutex);
ocfs2_file_unlock(file); ocfs2_file_unlock(file);
ret = flock_lock_file_wait(file, fl); ret = locks_lock_file_wait(file, fl);
mutex_unlock(&fp->fp_mutex); mutex_unlock(&fp->fp_mutex);
return ret; return ret;
@ -119,7 +119,7 @@ int ocfs2_flock(struct file *file, int cmd, struct file_lock *fl)
if ((osb->s_mount_opt & OCFS2_MOUNT_LOCALFLOCKS) || if ((osb->s_mount_opt & OCFS2_MOUNT_LOCALFLOCKS) ||
ocfs2_mount_local(osb)) ocfs2_mount_local(osb))
return flock_lock_file_wait(file, fl); return locks_lock_file_wait(file, fl);
if (fl->fl_type == F_UNLCK) if (fl->fl_type == F_UNLCK)
return ocfs2_do_funlock(file, cmd, fl); return ocfs2_do_funlock(file, cmd, fl);