summaryrefslogtreecommitdiffstats
path: root/fs/overlayfs/overlayfs.h
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2018-08-21 21:19:09 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2018-08-21 21:19:09 -0400
commitd9a185f8b49678775ef56ecbdbc7b76970302897 (patch)
tree7ace1b26133e5d796af09e5d71d6531bcb69865c /fs/overlayfs/overlayfs.h
parentc22fc16d172fba4d19ffd8f2aa8fe67edba63895 (diff)
parent989974c804574d250ac92d44e220081959ac8ac1 (diff)
Merge tag 'ovl-update-4.19' of git://git.kernel.org/pub/scm/linux/kernel/git/mszeredi/vfs
Pull overlayfs updates from Miklos Szeredi: "This contains two new features: - Stack file operations: this allows removal of several hacks from the VFS, proper interaction of read-only open files with copy-up, possibility to implement fs modifying ioctls properly, and others. - Metadata only copy-up: when file is on lower layer and only metadata is modified (except size) then only copy up the metadata and continue to use the data from the lower file" * tag 'ovl-update-4.19' of git://git.kernel.org/pub/scm/linux/kernel/git/mszeredi/vfs: (66 commits) ovl: Enable metadata only feature ovl: Do not do metacopy only for ioctl modifying file attr ovl: Do not do metadata only copy-up for truncate operation ovl: add helper to force data copy-up ovl: Check redirect on index as well ovl: Set redirect on upper inode when it is linked ovl: Set redirect on metacopy files upon rename ovl: Do not set dentry type ORIGIN for broken hardlinks ovl: Add an inode flag OVL_CONST_INO ovl: Treat metacopy dentries as type OVL_PATH_MERGE ovl: Check redirects for metacopy files ovl: Move some dir related ovl_lookup_single() code in else block ovl: Do not expose metacopy only dentry from d_real() ovl: Open file with data except for the case of fsync ovl: Add helper ovl_inode_realdata() ovl: Store lower data inode in ovl_inode ovl: Fix ovl_getattr() to get number of blocks from lower ovl: Add helper ovl_dentry_lowerdata() to get lower data dentry ovl: Copy up meta inode data from lowest data inode ovl: Modify ovl_lookup() and friends to lookup metacopy dentry ...
Diffstat (limited to 'fs/overlayfs/overlayfs.h')
-rw-r--r--fs/overlayfs/overlayfs.h47
1 files changed, 43 insertions, 4 deletions
diff --git a/fs/overlayfs/overlayfs.h b/fs/overlayfs/overlayfs.h
index 7538b9b56237..f61839e1054c 100644
--- a/fs/overlayfs/overlayfs.h
+++ b/fs/overlayfs/overlayfs.h
@@ -9,6 +9,7 @@
9 9
10#include <linux/kernel.h> 10#include <linux/kernel.h>
11#include <linux/uuid.h> 11#include <linux/uuid.h>
12#include <linux/fs.h>
12#include "ovl_entry.h" 13#include "ovl_entry.h"
13 14
14enum ovl_path_type { 15enum ovl_path_type {
@@ -28,6 +29,7 @@ enum ovl_path_type {
28#define OVL_XATTR_IMPURE OVL_XATTR_PREFIX "impure" 29#define OVL_XATTR_IMPURE OVL_XATTR_PREFIX "impure"
29#define OVL_XATTR_NLINK OVL_XATTR_PREFIX "nlink" 30#define OVL_XATTR_NLINK OVL_XATTR_PREFIX "nlink"
30#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"
31 33
32enum ovl_inode_flag { 34enum ovl_inode_flag {
33 /* Pure upper dir that may contain non pure upper entries */ 35 /* Pure upper dir that may contain non pure upper entries */
@@ -35,6 +37,9 @@ enum ovl_inode_flag {
35 /* Non-merge dir that may contain whiteout entries */ 37 /* Non-merge dir that may contain whiteout entries */
36 OVL_WHITEOUTS, 38 OVL_WHITEOUTS,
37 OVL_INDEX, 39 OVL_INDEX,
40 OVL_UPPERDATA,
41 /* Inode number will remain constant over copy up. */
42 OVL_CONST_INO,
38}; 43};
39 44
40enum ovl_entry_flag { 45enum ovl_entry_flag {
@@ -190,6 +195,14 @@ static inline struct dentry *ovl_do_tmpfile(struct dentry *dentry, umode_t mode)
190 return ret; 195 return ret;
191} 196}
192 197
198static inline bool ovl_open_flags_need_copy_up(int flags)
199{
200 if (!flags)
201 return false;
202
203 return ((OPEN_FMODE(flags) & FMODE_WRITE) || (flags & O_TRUNC));
204}
205
193/* util.c */ 206/* util.c */
194int ovl_want_write(struct dentry *dentry); 207int ovl_want_write(struct dentry *dentry);
195void ovl_drop_write(struct dentry *dentry); 208void ovl_drop_write(struct dentry *dentry);
@@ -206,15 +219,19 @@ bool ovl_dentry_weird(struct dentry *dentry);
206enum ovl_path_type ovl_path_type(struct dentry *dentry); 219enum ovl_path_type ovl_path_type(struct dentry *dentry);
207void ovl_path_upper(struct dentry *dentry, struct path *path); 220void ovl_path_upper(struct dentry *dentry, struct path *path);
208void ovl_path_lower(struct dentry *dentry, struct path *path); 221void ovl_path_lower(struct dentry *dentry, struct path *path);
222void ovl_path_lowerdata(struct dentry *dentry, struct path *path);
209enum ovl_path_type ovl_path_real(struct dentry *dentry, struct path *path); 223enum ovl_path_type ovl_path_real(struct dentry *dentry, struct path *path);
210struct dentry *ovl_dentry_upper(struct dentry *dentry); 224struct dentry *ovl_dentry_upper(struct dentry *dentry);
211struct dentry *ovl_dentry_lower(struct dentry *dentry); 225struct dentry *ovl_dentry_lower(struct dentry *dentry);
226struct dentry *ovl_dentry_lowerdata(struct dentry *dentry);
212struct ovl_layer *ovl_layer_lower(struct dentry *dentry); 227struct ovl_layer *ovl_layer_lower(struct dentry *dentry);
213struct dentry *ovl_dentry_real(struct dentry *dentry); 228struct dentry *ovl_dentry_real(struct dentry *dentry);
214struct dentry *ovl_i_dentry_upper(struct inode *inode); 229struct dentry *ovl_i_dentry_upper(struct inode *inode);
215struct inode *ovl_inode_upper(struct inode *inode); 230struct inode *ovl_inode_upper(struct inode *inode);
216struct inode *ovl_inode_lower(struct inode *inode); 231struct inode *ovl_inode_lower(struct inode *inode);
232struct inode *ovl_inode_lowerdata(struct inode *inode);
217struct inode *ovl_inode_real(struct inode *inode); 233struct inode *ovl_inode_real(struct inode *inode);
234struct inode *ovl_inode_realdata(struct inode *inode);
218struct ovl_dir_cache *ovl_dir_cache(struct inode *inode); 235struct ovl_dir_cache *ovl_dir_cache(struct inode *inode);
219void ovl_set_dir_cache(struct inode *inode, struct ovl_dir_cache *cache); 236void ovl_set_dir_cache(struct inode *inode, struct ovl_dir_cache *cache);
220void ovl_dentry_set_flag(unsigned long flag, struct dentry *dentry); 237void ovl_dentry_set_flag(unsigned long flag, struct dentry *dentry);
@@ -225,18 +242,23 @@ bool ovl_dentry_is_whiteout(struct dentry *dentry);
225void ovl_dentry_set_opaque(struct dentry *dentry); 242void ovl_dentry_set_opaque(struct dentry *dentry);
226bool ovl_dentry_has_upper_alias(struct dentry *dentry); 243bool ovl_dentry_has_upper_alias(struct dentry *dentry);
227void ovl_dentry_set_upper_alias(struct dentry *dentry); 244void ovl_dentry_set_upper_alias(struct dentry *dentry);
245bool ovl_dentry_needs_data_copy_up(struct dentry *dentry, int flags);
246bool ovl_dentry_needs_data_copy_up_locked(struct dentry *dentry, int flags);
247bool ovl_has_upperdata(struct inode *inode);
248void ovl_set_upperdata(struct inode *inode);
228bool ovl_redirect_dir(struct super_block *sb); 249bool ovl_redirect_dir(struct super_block *sb);
229const char *ovl_dentry_get_redirect(struct dentry *dentry); 250const char *ovl_dentry_get_redirect(struct dentry *dentry);
230void ovl_dentry_set_redirect(struct dentry *dentry, const char *redirect); 251void ovl_dentry_set_redirect(struct dentry *dentry, const char *redirect);
231void ovl_inode_init(struct inode *inode, struct dentry *upperdentry, 252void ovl_inode_init(struct inode *inode, struct dentry *upperdentry,
232 struct dentry *lowerdentry); 253 struct dentry *lowerdentry, struct dentry *lowerdata);
233void ovl_inode_update(struct inode *inode, struct dentry *upperdentry); 254void ovl_inode_update(struct inode *inode, struct dentry *upperdentry);
234void ovl_dentry_version_inc(struct dentry *dentry, bool impurity); 255void ovl_dir_modified(struct dentry *dentry, bool impurity);
235u64 ovl_dentry_version_get(struct dentry *dentry); 256u64 ovl_dentry_version_get(struct dentry *dentry);
236bool ovl_is_whiteout(struct dentry *dentry); 257bool ovl_is_whiteout(struct dentry *dentry);
237struct file *ovl_path_open(struct path *path, int flags); 258struct file *ovl_path_open(struct path *path, int flags);
238int ovl_copy_up_start(struct dentry *dentry); 259int ovl_copy_up_start(struct dentry *dentry, int flags);
239void ovl_copy_up_end(struct dentry *dentry); 260void ovl_copy_up_end(struct dentry *dentry);
261bool ovl_already_copied_up(struct dentry *dentry, int flags);
240bool ovl_check_origin_xattr(struct dentry *dentry); 262bool ovl_check_origin_xattr(struct dentry *dentry);
241bool ovl_check_dir_xattr(struct dentry *dentry, const char *name); 263bool ovl_check_dir_xattr(struct dentry *dentry, const char *name);
242int ovl_check_setxattr(struct dentry *dentry, struct dentry *upperdentry, 264int ovl_check_setxattr(struct dentry *dentry, struct dentry *upperdentry,
@@ -252,6 +274,9 @@ bool ovl_need_index(struct dentry *dentry);
252int ovl_nlink_start(struct dentry *dentry, bool *locked); 274int ovl_nlink_start(struct dentry *dentry, bool *locked);
253void ovl_nlink_end(struct dentry *dentry, bool locked); 275void ovl_nlink_end(struct dentry *dentry, bool locked);
254int ovl_lock_rename_workdir(struct dentry *workdir, struct dentry *upperdir); 276int ovl_lock_rename_workdir(struct dentry *workdir, struct dentry *upperdir);
277int ovl_check_metacopy_xattr(struct dentry *dentry);
278bool ovl_is_metacopy_dentry(struct dentry *dentry);
279char *ovl_get_redirect_xattr(struct dentry *dentry, int padding);
255 280
256static inline bool ovl_is_impuredir(struct dentry *dentry) 281static inline bool ovl_is_impuredir(struct dentry *dentry)
257{ 282{
@@ -324,7 +349,6 @@ int ovl_xattr_get(struct dentry *dentry, struct inode *inode, const char *name,
324 void *value, size_t size); 349 void *value, size_t size);
325ssize_t ovl_listxattr(struct dentry *dentry, char *list, size_t size); 350ssize_t ovl_listxattr(struct dentry *dentry, char *list, size_t size);
326struct posix_acl *ovl_get_acl(struct inode *inode, int type); 351struct posix_acl *ovl_get_acl(struct inode *inode, int type);
327int ovl_open_maybe_copy_up(struct dentry *dentry, unsigned int file_flags);
328int ovl_update_time(struct inode *inode, struct timespec64 *ts, int flags); 352int ovl_update_time(struct inode *inode, struct timespec64 *ts, int flags);
329bool ovl_is_private_xattr(const char *name); 353bool ovl_is_private_xattr(const char *name);
330 354
@@ -334,6 +358,8 @@ struct ovl_inode_params {
334 struct ovl_path *lowerpath; 358 struct ovl_path *lowerpath;
335 struct dentry *index; 359 struct dentry *index;
336 unsigned int numlower; 360 unsigned int numlower;
361 char *redirect;
362 struct dentry *lowerdata;
337}; 363};
338struct inode *ovl_new_inode(struct super_block *sb, umode_t mode, dev_t rdev); 364struct inode *ovl_new_inode(struct super_block *sb, umode_t mode, dev_t rdev);
339struct inode *ovl_lookup_inode(struct super_block *sb, struct dentry *real, 365struct inode *ovl_lookup_inode(struct super_block *sb, struct dentry *real,
@@ -348,6 +374,14 @@ static inline void ovl_copyattr(struct inode *from, struct inode *to)
348 to->i_atime = from->i_atime; 374 to->i_atime = from->i_atime;
349 to->i_mtime = from->i_mtime; 375 to->i_mtime = from->i_mtime;
350 to->i_ctime = from->i_ctime; 376 to->i_ctime = from->i_ctime;
377 i_size_write(to, i_size_read(from));
378}
379
380static inline void ovl_copyflags(struct inode *from, struct inode *to)
381{
382 unsigned int mask = S_SYNC | S_IMMUTABLE | S_APPEND | S_NOATIME;
383
384 inode_set_flags(to, from->i_flags & mask, mask);
351} 385}
352 386
353/* dir.c */ 387/* dir.c */
@@ -368,9 +402,14 @@ struct dentry *ovl_create_real(struct inode *dir, struct dentry *newdentry,
368int ovl_cleanup(struct inode *dir, struct dentry *dentry); 402int ovl_cleanup(struct inode *dir, struct dentry *dentry);
369struct dentry *ovl_create_temp(struct dentry *workdir, struct ovl_cattr *attr); 403struct dentry *ovl_create_temp(struct dentry *workdir, struct ovl_cattr *attr);
370 404
405/* file.c */
406extern const struct file_operations ovl_file_operations;
407
371/* copy_up.c */ 408/* copy_up.c */
372int ovl_copy_up(struct dentry *dentry); 409int ovl_copy_up(struct dentry *dentry);
410int ovl_copy_up_with_data(struct dentry *dentry);
373int ovl_copy_up_flags(struct dentry *dentry, int flags); 411int ovl_copy_up_flags(struct dentry *dentry, int flags);
412int ovl_open_maybe_copy_up(struct dentry *dentry, unsigned int file_flags);
374int ovl_copy_xattr(struct dentry *old, struct dentry *new); 413int ovl_copy_xattr(struct dentry *old, struct dentry *new);
375int ovl_set_attr(struct dentry *upper, struct kstat *stat); 414int ovl_set_attr(struct dentry *upper, struct kstat *stat);
376struct ovl_fh *ovl_encode_real_fh(struct dentry *real, bool is_upper); 415struct ovl_fh *ovl_encode_real_fh(struct dentry *real, bool is_upper);