Skip to content

Commit f328296

Browse files
kinglongmeeJeff Layton
authored andcommitted
locks: Copy fl_lmops information for conflock in locks_copy_conflock()
Commit d5b9026 ([PATCH] knfsd: locks: flag NFSv4-owned locks) using fl_lmops field in file_lock for checking nfsd4 lockowner. But, commit 1a747ee (locks: don't call ->copy_lock methods on return of conflicting locks) causes the fl_lmops of conflock always be NULL. Also, commit 0996905 (lockd: posix_test_lock() should not call locks_copy_lock()) caused the fl_lmops of conflock always be NULL too. Make sure copy the private information by fl_copy_lock() in struct file_lock_operations, merge __locks_copy_lock() to fl_copy_lock(). Jeff advice, "Set fl_lmops on conflocks, but don't set fl_ops. fl_ops are superfluous, since they are callbacks into the filesystem. There should be no need to bother the filesystem at all with info in a conflock. But, lock _ownership_ matters for conflocks and that's indicated by the fl_lmops. So you really do want to copy the fl_lmops for conflocks I think." v5: add missing calling of locks_release_private() in nlmsvc_testlock() v4: only copy fl_lmops for conflock, don't copy fl_ops Signed-off-by: Kinglong Mee <kinglongmee@gmail.com> Signed-off-by: Jeff Layton <jlayton@primarydata.com>
1 parent 5c97d7b commit f328296

2 files changed

Lines changed: 17 additions & 20 deletions

File tree

‎fs/lockd/svclock.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,7 @@ nlmsvc_testlock(struct svc_rqst *rqstp, struct nlm_file *file,
586586
conflock->fl.fl_type = lock->fl.fl_type;
587587
conflock->fl.fl_start = lock->fl.fl_start;
588588
conflock->fl.fl_end = lock->fl.fl_end;
589+
locks_release_private(&lock->fl);
589590
ret = nlm_lck_denied;
590591
out:
591592
if (block)

‎fs/locks.c‎

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -271,21 +271,6 @@ void locks_init_lock(struct file_lock *fl)
271271

272272
EXPORT_SYMBOL(locks_init_lock);
273273

274-
static void locks_copy_private(struct file_lock *new, struct file_lock *fl)
275-
{
276-
if (fl->fl_ops) {
277-
if (fl->fl_ops->fl_copy_lock)
278-
fl->fl_ops->fl_copy_lock(new, fl);
279-
new->fl_ops = fl->fl_ops;
280-
}
281-
282-
if (fl->fl_lmops) {
283-
if (fl->fl_lmops->lm_get_owner)
284-
fl->fl_lmops->lm_get_owner(new, fl);
285-
new->fl_lmops = fl->fl_lmops;
286-
}
287-
}
288-
289274
/*
290275
* Initialize a new lock from an existing file_lock structure.
291276
*/
@@ -298,8 +283,13 @@ void locks_copy_conflock(struct file_lock *new, struct file_lock *fl)
298283
new->fl_type = fl->fl_type;
299284
new->fl_start = fl->fl_start;
300285
new->fl_end = fl->fl_end;
286+
new->fl_lmops = fl->fl_lmops;
301287
new->fl_ops = NULL;
302-
new->fl_lmops = NULL;
288+
289+
if (fl->fl_lmops) {
290+
if (fl->fl_lmops->lm_get_owner)
291+
fl->fl_lmops->lm_get_owner(new, fl);
292+
}
303293
}
304294
EXPORT_SYMBOL(locks_copy_conflock);
305295

@@ -309,11 +299,14 @@ void locks_copy_lock(struct file_lock *new, struct file_lock *fl)
309299
WARN_ON_ONCE(new->fl_ops);
310300

311301
locks_copy_conflock(new, fl);
302+
312303
new->fl_file = fl->fl_file;
313304
new->fl_ops = fl->fl_ops;
314-
new->fl_lmops = fl->fl_lmops;
315305

316-
locks_copy_private(new, fl);
306+
if (fl->fl_ops) {
307+
if (fl->fl_ops->fl_copy_lock)
308+
fl->fl_ops->fl_copy_lock(new, fl);
309+
}
317310
}
318311

319312
EXPORT_SYMBOL(locks_copy_lock);
@@ -1989,11 +1982,13 @@ int fcntl_getlk(struct file *filp, unsigned int cmd, struct flock __user *l)
19891982
if (file_lock.fl_type != F_UNLCK) {
19901983
error = posix_lock_to_flock(&flock, &file_lock);
19911984
if (error)
1992-
goto out;
1985+
goto rel_priv;
19931986
}
19941987
error = -EFAULT;
19951988
if (!copy_to_user(l, &flock, sizeof(flock)))
19961989
error = 0;
1990+
rel_priv:
1991+
locks_release_private(&file_lock);
19971992
out:
19981993
return error;
19991994
}
@@ -2214,7 +2209,8 @@ int fcntl_getlk64(struct file *filp, unsigned int cmd, struct flock64 __user *l)
22142209
error = -EFAULT;
22152210
if (!copy_to_user(l, &flock, sizeof(flock)))
22162211
error = 0;
2217-
2212+
2213+
locks_release_private(&file_lock);
22182214
out:
22192215
return error;
22202216
}

0 commit comments

Comments
 (0)