Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9d6a8c5c authored by Marc Eshel's avatar Marc Eshel Committed by J. Bruce Fields
Browse files

locks: give posix_test_lock same interface as ->lock



posix_test_lock() and ->lock() do the same job but have gratuitously
different interfaces.  Modify posix_test_lock() so the two agree,
simplifying some code in the process.

Signed-off-by: default avatarMarc Eshel <eshel@almaden.ibm.com>
Signed-off-by: default avatar"J. Bruce Fields" <bfields@citi.umich.edu>
parent 70cc6487
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -738,8 +738,7 @@ static int fuse_file_lock(struct file *file, int cmd, struct file_lock *fl)

	if (cmd == F_GETLK) {
		if (fc->no_lock) {
			if (!posix_test_lock(file, fl, fl))
				fl->fl_type = F_UNLCK;
			posix_test_lock(file, fl);
			err = 0;
		} else
			err = fuse_getlk(file, fl);
+1 −7
Original line number Diff line number Diff line
@@ -164,13 +164,7 @@ static void nolock_unhold_lvb(void *lock, char *lvb)
static int nolock_plock_get(void *lockspace, struct lm_lockname *name,
			    struct file *file, struct file_lock *fl)
{
	struct file_lock tmp;
	int ret;

	ret = posix_test_lock(file, fl, &tmp);
	fl->fl_type = F_UNLCK;
	if (ret)
		memcpy(fl, &tmp, sizeof(struct file_lock));
	posix_test_lock(file, fl);

	return 0;
}
+1 −6
Original line number Diff line number Diff line
@@ -513,12 +513,7 @@ static int gfs2_lock(struct file *file, int cmd, struct file_lock *fl)

	if (sdp->sd_args.ar_localflocks) {
		if (IS_GETLK(cmd)) {
			struct file_lock tmp;
			int ret;
			ret = posix_test_lock(file, fl, &tmp);
			fl->fl_type = F_UNLCK;
			if (ret)
				memcpy(fl, &tmp, sizeof(struct file_lock));
			posix_test_lock(file, fl);
			return 0;
		} else {
			return posix_lock_file_wait(file, fl);
+8 −5
Original line number Diff line number Diff line
@@ -426,15 +426,18 @@ nlmsvc_testlock(struct nlm_file *file, struct nlm_lock *lock,
				(long long)lock->fl.fl_start,
				(long long)lock->fl.fl_end);

	if (posix_test_lock(file->f_file, &lock->fl, &conflock->fl)) {
	if (posix_test_lock(file->f_file, &lock->fl)) {
		dprintk("lockd: conflicting lock(ty=%d, %Ld-%Ld)\n",
				conflock->fl.fl_type,
				(long long)conflock->fl.fl_start,
				(long long)conflock->fl.fl_end);
				lock->fl.fl_type,
				(long long)lock->fl.fl_start,
				(long long)lock->fl.fl_end);
		conflock->caller = "somehost";	/* FIXME */
		conflock->len = strlen(conflock->caller);
		conflock->oh.len = 0;		/* don't return OH info */
		conflock->svid = conflock->fl.fl_pid;
		conflock->svid = lock->fl.fl_pid;
		conflock->fl.fl_type = lock->fl.fl_type;
		conflock->fl.fl_start = lock->fl.fl_start;
		conflock->fl.fl_end = lock->fl.fl_end;
		return nlm_lck_denied;
	}

+16 −21
Original line number Diff line number Diff line
@@ -666,11 +666,11 @@ static int locks_block_on_timeout(struct file_lock *blocker, struct file_lock *w
}

int
posix_test_lock(struct file *filp, struct file_lock *fl,
		struct file_lock *conflock)
posix_test_lock(struct file *filp, struct file_lock *fl)
{
	struct file_lock *cfl;

	fl->fl_type = F_UNLCK;
	lock_kernel();
	for (cfl = filp->f_path.dentry->d_inode->i_flock; cfl; cfl = cfl->fl_next) {
		if (!IS_POSIX(cfl))
@@ -679,7 +679,7 @@ posix_test_lock(struct file *filp, struct file_lock *fl,
			break;
	}
	if (cfl) {
		__locks_copy_lock(conflock, cfl);
		__locks_copy_lock(fl, cfl);
		unlock_kernel();
		return 1;
	}
@@ -1648,7 +1648,7 @@ static void posix_lock_to_flock64(struct flock64 *flock, struct file_lock *fl)
 */
int fcntl_getlk(struct file *filp, struct flock __user *l)
{
	struct file_lock *fl, cfl, file_lock;
	struct file_lock file_lock;
	struct flock flock;
	int error;

@@ -1667,15 +1667,12 @@ int fcntl_getlk(struct file *filp, struct flock __user *l)
		error = filp->f_op->lock(filp, F_GETLK, &file_lock);
		if (error < 0)
			goto out;
		else
		  fl = (file_lock.fl_type == F_UNLCK ? NULL : &file_lock);
	} else {
		fl = (posix_test_lock(filp, &file_lock, &cfl) ? &cfl : NULL);
	}
	} else
		posix_test_lock(filp, &file_lock);
 
	flock.l_type = F_UNLCK;
	if (fl != NULL) {
		error = posix_lock_to_flock(&flock, fl);
	flock.l_type = file_lock.fl_type;
	if (file_lock.fl_type != F_UNLCK) {
		error = posix_lock_to_flock(&flock, &file_lock);
		if (error)
			goto out;
	}
@@ -1785,7 +1782,7 @@ int fcntl_setlk(unsigned int fd, struct file *filp, unsigned int cmd,
 */
int fcntl_getlk64(struct file *filp, struct flock64 __user *l)
{
	struct file_lock *fl, cfl, file_lock;
	struct file_lock file_lock;
	struct flock64 flock;
	int error;

@@ -1804,15 +1801,13 @@ int fcntl_getlk64(struct file *filp, struct flock64 __user *l)
		error = filp->f_op->lock(filp, F_GETLK, &file_lock);
		if (error < 0)
			goto out;
		else
		  fl = (file_lock.fl_type == F_UNLCK ? NULL : &file_lock);
	} else {
		fl = (posix_test_lock(filp, &file_lock, &cfl) ? &cfl : NULL);
	}
	} else
		posix_test_lock(filp, &file_lock);
 
	flock.l_type = file_lock.fl_type;
	if (file_lock.fl_type != F_UNLCK)
		posix_lock_to_flock64(&flock, &file_lock);

	flock.l_type = F_UNLCK;
	if (fl != NULL)
		posix_lock_to_flock64(&flock, fl);
	error = -EFAULT;
	if (!copy_to_user(l, &flock, sizeof(flock)))
		error = 0;
Loading