lkml.org 
[lkml]   [2013]   [Dec]   [10]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH v3 1/6] locks: consolidate common code in the flock_to_posix_lock routines
Date
Currently, there's a lot of copy and paste between the two.  Add some
functions to do the initialization of the file_lock from values
passed in, and turn the flock/flock64 variants of those functions into
wrappers around them.

Unfortunately it's harder to consolidate the fl_start/fl_end
calculations due to the differently sized types involved so I've left
them separate for now.

Signed-off-by: Jeff Layton <jlayton@redhat.com>
---
fs/locks.c | 31 +++++++++++++++----------------
1 file changed, 15 insertions(+), 16 deletions(-)

diff --git a/fs/locks.c b/fs/locks.c
index 6084f5a..a5848ed 100644
--- a/fs/locks.c
+++ b/fs/locks.c
@@ -344,6 +344,19 @@ static int assign_type(struct file_lock *fl, long type)
return 0;
}

+static int
+flock_to_posix_lock_common(struct file_lock *fl, struct file *filp, short type)
+{
+ fl->fl_owner = current->files;
+ fl->fl_pid = current->tgid;
+ fl->fl_file = filp;
+ fl->fl_flags = FL_POSIX;
+ fl->fl_ops = NULL;
+ fl->fl_lmops = NULL;
+
+ return assign_type(fl, type);
+}
+
/* Verify a "struct flock" and copy it to a "struct file_lock" as a POSIX
* style lock.
*/
@@ -386,14 +399,7 @@ static int flock_to_posix_lock(struct file *filp, struct file_lock *fl,
if (fl->fl_end < fl->fl_start)
return -EOVERFLOW;

- fl->fl_owner = current->files;
- fl->fl_pid = current->tgid;
- fl->fl_file = filp;
- fl->fl_flags = FL_POSIX;
- fl->fl_ops = NULL;
- fl->fl_lmops = NULL;
-
- return assign_type(fl, l->l_type);
+ return flock_to_posix_lock_common(fl, filp, l->l_type);
}

#if BITS_PER_LONG == 32
@@ -431,15 +437,8 @@ static int flock64_to_posix_lock(struct file *filp, struct file_lock *fl,
fl->fl_start = start; /* we record the absolute position */
if (fl->fl_end < fl->fl_start)
return -EOVERFLOW;
-
- fl->fl_owner = current->files;
- fl->fl_pid = current->tgid;
- fl->fl_file = filp;
- fl->fl_flags = FL_POSIX;
- fl->fl_ops = NULL;
- fl->fl_lmops = NULL;

- return assign_type(fl, l->l_type);
+ return flock_to_posix_lock_common(fl, filp, l->l_type);
}
#endif

--
1.8.4.2


\
 
 \ /
  Last update: 2013-12-10 21:01    [W:0.148 / U:0.100 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site