aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorJeff Layton <jlayton@poochiereds.net>2014-05-09 14:13:04 -0400
committerJeff Layton <jlayton@poochiereds.net>2014-06-02 08:09:29 -0400
commit130d1f956ab367bab855336279afa3b19acdc9a1 (patch)
tree8372682ec959aa89df1d280e93c3ab8119801dea /fs
parentcf01f4eef9fe367ec0d85b38dd7214e29e376cdb (diff)
locks: ensure that fl_owner is always initialized properly in flock and lease codepaths
Currently, the fl_owner isn't set for flock locks. Some filesystems use byte-range locks to simulate flock locks and there is a common idiom in those that does: fl->fl_owner = (fl_owner_t)filp; fl->fl_start = 0; fl->fl_end = OFFSET_MAX; Since flock locks are generally "owned" by the open file description, move this into the common flock lock setup code. The fl_start and fl_end fields are already set appropriately, so remove the unneeded setting of that in flock ops in those filesystems as well. Finally, the lease code also sets the fl_owner as if they were owned by the process and not the open file description. This is incorrect as leases have the same ownership semantics as flock locks. Set them the same way. The lease code doesn't actually use the fl_owner value for anything, so this is more for consistency's sake than a bugfix. Reported-by: Trond Myklebust <trond.myklebust@primarydata.com> Signed-off-by: Jeff Layton <jlayton@poochiereds.net> Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> (Staging portion) Acked-by: J. Bruce Fields <bfields@fieldses.org>
Diffstat (limited to 'fs')
-rw-r--r--fs/9p/vfs_file.c3
-rw-r--r--fs/afs/flock.c4
-rw-r--r--fs/ceph/locks.c10
-rw-r--r--fs/fuse/file.c1
-rw-r--r--fs/locks.c4
-rw-r--r--fs/nfs/file.c4
6 files changed, 5 insertions, 21 deletions
diff --git a/fs/9p/vfs_file.c b/fs/9p/vfs_file.c
index d8223209d4b1..59e3fe3d56c0 100644
--- a/fs/9p/vfs_file.c
+++ b/fs/9p/vfs_file.c
@@ -352,9 +352,6 @@ static int v9fs_file_flock_dotl(struct file *filp, int cmd,
352 invalidate_mapping_pages(&inode->i_data, 0, -1); 352 invalidate_mapping_pages(&inode->i_data, 0, -1);
353 } 353 }
354 /* Convert flock to posix lock */ 354 /* Convert flock to posix lock */
355 fl->fl_owner = (fl_owner_t)filp;
356 fl->fl_start = 0;
357 fl->fl_end = OFFSET_MAX;
358 fl->fl_flags |= FL_POSIX; 355 fl->fl_flags |= FL_POSIX;
359 fl->fl_flags ^= FL_FLOCK; 356 fl->fl_flags ^= FL_FLOCK;
360 357
diff --git a/fs/afs/flock.c b/fs/afs/flock.c
index a8cf2cff836c..4baf1d2b39e4 100644
--- a/fs/afs/flock.c
+++ b/fs/afs/flock.c
@@ -555,10 +555,6 @@ int afs_flock(struct file *file, int cmd, struct file_lock *fl)
555 return -ENOLCK; 555 return -ENOLCK;
556 556
557 /* we're simulating flock() locks using posix locks on the server */ 557 /* we're simulating flock() locks using posix locks on the server */
558 fl->fl_owner = (fl_owner_t) file;
559 fl->fl_start = 0;
560 fl->fl_end = OFFSET_MAX;
561
562 if (fl->fl_type == F_UNLCK) 558 if (fl->fl_type == F_UNLCK)
563 return afs_do_unlk(file, fl); 559 return afs_do_unlk(file, fl);
564 return afs_do_setlk(file, fl); 560 return afs_do_setlk(file, fl);
diff --git a/fs/ceph/locks.c b/fs/ceph/locks.c
index 191398852a2e..fbc39c47bacd 100644
--- a/fs/ceph/locks.c
+++ b/fs/ceph/locks.c
@@ -53,10 +53,7 @@ static int ceph_lock_message(u8 lock_type, u16 operation, struct file *file,
53 else 53 else
54 length = fl->fl_end - fl->fl_start + 1; 54 length = fl->fl_end - fl->fl_start + 1;
55 55
56 if (lock_type == CEPH_LOCK_FCNTL) 56 owner = secure_addr(fl->fl_owner);
57 owner = secure_addr(fl->fl_owner);
58 else
59 owner = secure_addr(fl->fl_file);
60 57
61 dout("ceph_lock_message: rule: %d, op: %d, owner: %llx, pid: %llu, " 58 dout("ceph_lock_message: rule: %d, op: %d, owner: %llx, pid: %llu, "
62 "start: %llu, length: %llu, wait: %d, type: %d", (int)lock_type, 59 "start: %llu, length: %llu, wait: %d, type: %d", (int)lock_type,
@@ -314,10 +311,7 @@ int lock_to_ceph_filelock(struct file_lock *lock,
314 cephlock->length = cpu_to_le64(lock->fl_end - lock->fl_start + 1); 311 cephlock->length = cpu_to_le64(lock->fl_end - lock->fl_start + 1);
315 cephlock->client = cpu_to_le64(0); 312 cephlock->client = cpu_to_le64(0);
316 cephlock->pid = cpu_to_le64((u64)lock->fl_pid); 313 cephlock->pid = cpu_to_le64((u64)lock->fl_pid);
317 if (lock->fl_flags & FL_POSIX) 314 cephlock->owner = cpu_to_le64(secure_addr(lock->fl_owner));
318 cephlock->owner = cpu_to_le64(secure_addr(lock->fl_owner));
319 else
320 cephlock->owner = cpu_to_le64(secure_addr(lock->fl_file));
321 315
322 switch (lock->fl_type) { 316 switch (lock->fl_type) {
323 case F_RDLCK: 317 case F_RDLCK:
diff --git a/fs/fuse/file.c b/fs/fuse/file.c
index 96d513e01a5d..f680d2c44e97 100644
--- a/fs/fuse/file.c
+++ b/fs/fuse/file.c
@@ -2304,7 +2304,6 @@ static int fuse_file_flock(struct file *file, int cmd, struct file_lock *fl)
2304 struct fuse_file *ff = file->private_data; 2304 struct fuse_file *ff = file->private_data;
2305 2305
2306 /* emulate flock with POSIX locks */ 2306 /* emulate flock with POSIX locks */
2307 fl->fl_owner = (fl_owner_t) file;
2308 ff->flock = true; 2307 ff->flock = true;
2309 err = fuse_setlk(file, fl, 1); 2308 err = fuse_setlk(file, fl, 1);
2310 } 2309 }
diff --git a/fs/locks.c b/fs/locks.c
index e390bd9ae068..77aff897fef3 100644
--- a/fs/locks.c
+++ b/fs/locks.c
@@ -322,6 +322,7 @@ static int flock_make_lock(struct file *filp, struct file_lock **lock,
322 return -ENOMEM; 322 return -ENOMEM;
323 323
324 fl->fl_file = filp; 324 fl->fl_file = filp;
325 fl->fl_owner = (fl_owner_t)filp;
325 fl->fl_pid = current->tgid; 326 fl->fl_pid = current->tgid;
326 fl->fl_flags = FL_FLOCK; 327 fl->fl_flags = FL_FLOCK;
327 fl->fl_type = type; 328 fl->fl_type = type;
@@ -427,7 +428,7 @@ static int lease_init(struct file *filp, long type, struct file_lock *fl)
427 if (assign_type(fl, type) != 0) 428 if (assign_type(fl, type) != 0)
428 return -EINVAL; 429 return -EINVAL;
429 430
430 fl->fl_owner = current->files; 431 fl->fl_owner = (fl_owner_t)filp;
431 fl->fl_pid = current->tgid; 432 fl->fl_pid = current->tgid;
432 433
433 fl->fl_file = filp; 434 fl->fl_file = filp;
@@ -2316,6 +2317,7 @@ void locks_remove_file(struct file *filp)
2316 2317
2317 if (filp->f_op->flock) { 2318 if (filp->f_op->flock) {
2318 struct file_lock fl = { 2319 struct file_lock fl = {
2320 .fl_owner = (fl_owner_t)filp,
2319 .fl_pid = current->tgid, 2321 .fl_pid = current->tgid,
2320 .fl_file = filp, 2322 .fl_file = filp,
2321 .fl_flags = FL_FLOCK, 2323 .fl_flags = FL_FLOCK,
diff --git a/fs/nfs/file.c b/fs/nfs/file.c
index 284ca901fe16..c1edf7336315 100644
--- a/fs/nfs/file.c
+++ b/fs/nfs/file.c
@@ -916,10 +916,6 @@ int nfs_flock(struct file *filp, int cmd, struct file_lock *fl)
916 is_local = 1; 916 is_local = 1;
917 917
918 /* We're simulating flock() locks using posix locks on the server */ 918 /* We're simulating flock() locks using posix locks on the server */
919 fl->fl_owner = (fl_owner_t)filp;
920 fl->fl_start = 0;
921 fl->fl_end = OFFSET_MAX;
922
923 if (fl->fl_type == F_UNLCK) 919 if (fl->fl_type == F_UNLCK)
924 return do_unlk(filp, cmd, fl, is_local); 920 return do_unlk(filp, cmd, fl, is_local);
925 return do_setlk(filp, cmd, fl, is_local); 921 return do_setlk(filp, cmd, fl, is_local);