summaryrefslogtreecommitdiffstats
path: root/fs/overlayfs/overlayfs.h
diff options
context:
space:
mode:
authorVivek Goyal <vgoyal@redhat.com>2018-05-11 11:49:28 -0400
committerMiklos Szeredi <mszeredi@redhat.com>2018-07-20 03:56:08 -0400
commit0c2888749363645d62cc48852d0af98d5ceef332 (patch)
treed2e8932551adc3a41cb164223a0e9db6c8d2a1c0 /fs/overlayfs/overlayfs.h
parent2002df85367ca69961d39020f56d3d727897be01 (diff)
ovl: A new xattr OVL_XATTR_METACOPY for file on upper
Now we will have the capability to have upper inodes which might be only metadata copy up and data is still on lower inode. So add a new xattr OVL_XATTR_METACOPY to distinguish between two cases. Presence of OVL_XATTR_METACOPY reflects that file has been copied up metadata only and and data will be copied up later from lower origin. So this xattr is set when a metadata copy takes place and cleared when data copy takes place. We also use a bit in ovl_inode->flags to cache OVL_UPPERDATA which reflects whether ovl inode has data or not (as opposed to metadata only copy up). If a file is copied up metadata only and later when same file is opened for WRITE, then data copy up takes place. We copy up data, remove METACOPY xattr and then set the UPPERDATA flag in ovl_inode->flags. While all these operations happen with oi->lock held, read side of oi->flags can be lockless. That is another thread on another cpu can check if UPPERDATA flag is set or not. So this gives us an ordering requirement w.r.t UPPERDATA flag. That is, if another cpu sees UPPERDATA flag set, then it should be guaranteed that effects of data copy up and remove xattr operations are also visible. For example. CPU1 CPU2 ovl_open() acquire(oi->lock) ovl_open_maybe_copy_up() ovl_copy_up_data() open_open_need_copy_up() vfs_removexattr() ovl_already_copied_up() ovl_dentry_needs_data_copy_up() ovl_set_flag(OVL_UPPERDATA) ovl_test_flag(OVL_UPPERDATA) release(oi->lock) Say CPU2 is copying up data and in the end sets UPPERDATA flag. But if CPU1 perceives the effects of setting UPPERDATA flag but not the effects of preceding operations (ex. upper that is not fully copied up), it will be a problem. Hence this patch introduces smp_wmb() on setting UPPERDATA flag operation and smp_rmb() on UPPERDATA flag test operation. May be some other lock or barrier is already covering it. But I am not sure what that is and is it obvious enough that we will not break it in future. So hence trying to be safe here and introducing barriers explicitly for UPPERDATA flag/bit. Signed-off-by: Vivek Goyal <vgoyal@redhat.com> Reviewed-by: Amir Goldstein <amir73il@gmail.com> Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
Diffstat (limited to 'fs/overlayfs/overlayfs.h')
-rw-r--r--fs/overlayfs/overlayfs.h18
1 files changed, 16 insertions, 2 deletions
diff --git a/fs/overlayfs/overlayfs.h b/fs/overlayfs/overlayfs.h
index 206e588df095..16a000694c4e 100644
--- a/fs/overlayfs/overlayfs.h
+++ b/fs/overlayfs/overlayfs.h
@@ -29,6 +29,7 @@ enum ovl_path_type {
29#define OVL_XATTR_IMPURE OVL_XATTR_PREFIX "impure" 29#define OVL_XATTR_IMPURE OVL_XATTR_PREFIX "impure"
30#define OVL_XATTR_NLINK OVL_XATTR_PREFIX "nlink" 30#define OVL_XATTR_NLINK OVL_XATTR_PREFIX "nlink"
31#define OVL_XATTR_UPPER OVL_XATTR_PREFIX "upper" 31#define OVL_XATTR_UPPER OVL_XATTR_PREFIX "upper"
32#define OVL_XATTR_METACOPY OVL_XATTR_PREFIX "metacopy"
32 33
33enum ovl_inode_flag { 34enum ovl_inode_flag {
34 /* Pure upper dir that may contain non pure upper entries */ 35 /* Pure upper dir that may contain non pure upper entries */
@@ -36,6 +37,7 @@ enum ovl_inode_flag {
36 /* Non-merge dir that may contain whiteout entries */ 37 /* Non-merge dir that may contain whiteout entries */
37 OVL_WHITEOUTS, 38 OVL_WHITEOUTS,
38 OVL_INDEX, 39 OVL_INDEX,
40 OVL_UPPERDATA,
39}; 41};
40 42
41enum ovl_entry_flag { 43enum ovl_entry_flag {
@@ -191,6 +193,14 @@ static inline struct dentry *ovl_do_tmpfile(struct dentry *dentry, umode_t mode)
191 return ret; 193 return ret;
192} 194}
193 195
196static inline bool ovl_open_flags_need_copy_up(int flags)
197{
198 if (!flags)
199 return false;
200
201 return ((OPEN_FMODE(flags) & FMODE_WRITE) || (flags & O_TRUNC));
202}
203
194/* util.c */ 204/* util.c */
195int ovl_want_write(struct dentry *dentry); 205int ovl_want_write(struct dentry *dentry);
196void ovl_drop_write(struct dentry *dentry); 206void ovl_drop_write(struct dentry *dentry);
@@ -226,6 +236,10 @@ bool ovl_dentry_is_whiteout(struct dentry *dentry);
226void ovl_dentry_set_opaque(struct dentry *dentry); 236void ovl_dentry_set_opaque(struct dentry *dentry);
227bool ovl_dentry_has_upper_alias(struct dentry *dentry); 237bool ovl_dentry_has_upper_alias(struct dentry *dentry);
228void ovl_dentry_set_upper_alias(struct dentry *dentry); 238void ovl_dentry_set_upper_alias(struct dentry *dentry);
239bool ovl_dentry_needs_data_copy_up(struct dentry *dentry, int flags);
240bool ovl_dentry_needs_data_copy_up_locked(struct dentry *dentry, int flags);
241bool ovl_has_upperdata(struct inode *inode);
242void ovl_set_upperdata(struct inode *inode);
229bool ovl_redirect_dir(struct super_block *sb); 243bool ovl_redirect_dir(struct super_block *sb);
230const char *ovl_dentry_get_redirect(struct dentry *dentry); 244const char *ovl_dentry_get_redirect(struct dentry *dentry);
231void ovl_dentry_set_redirect(struct dentry *dentry, const char *redirect); 245void ovl_dentry_set_redirect(struct dentry *dentry, const char *redirect);
@@ -236,9 +250,9 @@ void ovl_dir_modified(struct dentry *dentry, bool impurity);
236u64 ovl_dentry_version_get(struct dentry *dentry); 250u64 ovl_dentry_version_get(struct dentry *dentry);
237bool ovl_is_whiteout(struct dentry *dentry); 251bool ovl_is_whiteout(struct dentry *dentry);
238struct file *ovl_path_open(struct path *path, int flags); 252struct file *ovl_path_open(struct path *path, int flags);
239int ovl_copy_up_start(struct dentry *dentry); 253int ovl_copy_up_start(struct dentry *dentry, int flags);
240void ovl_copy_up_end(struct dentry *dentry); 254void ovl_copy_up_end(struct dentry *dentry);
241bool ovl_already_copied_up(struct dentry *dentry); 255bool ovl_already_copied_up(struct dentry *dentry, int flags);
242bool ovl_check_origin_xattr(struct dentry *dentry); 256bool ovl_check_origin_xattr(struct dentry *dentry);
243bool ovl_check_dir_xattr(struct dentry *dentry, const char *name); 257bool ovl_check_dir_xattr(struct dentry *dentry, const char *name);
244int ovl_check_setxattr(struct dentry *dentry, struct dentry *upperdentry, 258int ovl_check_setxattr(struct dentry *dentry, struct dentry *upperdentry,