summaryrefslogtreecommitdiffstats
path: root/include/linux/fs.h
diff options
context:
space:
mode:
authorMiklos Szeredi <mszeredi@redhat.com>2016-09-16 06:44:20 -0400
committerMiklos Szeredi <mszeredi@redhat.com>2016-09-16 06:44:20 -0400
commitc568d68341be7030f5647def68851e469b21ca11 (patch)
treefe205e47e6d6d292557580c16ea0186a05752634 /include/linux/fs.h
parentf3fbbb079263bd29ae592478de6808db7e708267 (diff)
locks: fix file locking on overlayfs
This patch allows flock, posix locks, ofd locks and leases to work correctly on overlayfs. Instead of using the underlying inode for storing lock context use the overlay inode. This allows locks to be persistent across copy-up. This is done by introducing locks_inode() helper and using it instead of file_inode() to get the inode in locking code. For non-overlayfs the two are equivalent, except for an extra pointer dereference in locks_inode(). Since lock operations are in "struct file_operations" we must also make sure not to call underlying filesystem's lock operations. Introcude a super block flag MS_NOREMOTELOCK to this effect. Signed-off-by: Miklos Szeredi <mszeredi@redhat.com> Acked-by: Jeff Layton <jlayton@poochiereds.net> Cc: "J. Bruce Fields" <bfields@fieldses.org>
Diffstat (limited to 'include/linux/fs.h')
-rw-r--r--include/linux/fs.h16
1 files changed, 14 insertions, 2 deletions
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 7db097d673a8..8ee0f011547f 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -1065,6 +1065,18 @@ struct file_lock_context {
1065 1065
1066extern void send_sigio(struct fown_struct *fown, int fd, int band); 1066extern void send_sigio(struct fown_struct *fown, int fd, int band);
1067 1067
1068/*
1069 * Return the inode to use for locking
1070 *
1071 * For overlayfs this should be the overlay inode, not the real inode returned
1072 * by file_inode(). For any other fs file_inode(filp) and locks_inode(filp) are
1073 * equal.
1074 */
1075static inline struct inode *locks_inode(const struct file *f)
1076{
1077 return f->f_path.dentry->d_inode;
1078}
1079
1068#ifdef CONFIG_FILE_LOCKING 1080#ifdef CONFIG_FILE_LOCKING
1069extern int fcntl_getlk(struct file *, unsigned int, struct flock __user *); 1081extern int fcntl_getlk(struct file *, unsigned int, struct flock __user *);
1070extern int fcntl_setlk(unsigned int, struct file *, unsigned int, 1082extern int fcntl_setlk(unsigned int, struct file *, unsigned int,
@@ -1252,7 +1264,7 @@ static inline struct dentry *file_dentry(const struct file *file)
1252 1264
1253static inline int locks_lock_file_wait(struct file *filp, struct file_lock *fl) 1265static inline int locks_lock_file_wait(struct file *filp, struct file_lock *fl)
1254{ 1266{
1255 return locks_lock_inode_wait(file_inode(filp), fl); 1267 return locks_lock_inode_wait(locks_inode(filp), fl);
1256} 1268}
1257 1269
1258struct fasync_struct { 1270struct fasync_struct {
@@ -2155,7 +2167,7 @@ static inline int mandatory_lock(struct inode *ino)
2155 2167
2156static inline int locks_verify_locked(struct file *file) 2168static inline int locks_verify_locked(struct file *file)
2157{ 2169{
2158 if (mandatory_lock(file_inode(file))) 2170 if (mandatory_lock(locks_inode(file)))
2159 return locks_mandatory_locked(file); 2171 return locks_mandatory_locked(file);
2160 return 0; 2172 return 0;
2161} 2173}