@@ -64,6 +64,11 @@ static void ovl_entry_stack_free(struct ovl_entry *oe)
6464 dput (oe -> lowerstack [i ].dentry );
6565}
6666
67+ static bool ovl_metacopy_def = IS_ENABLED (CONFIG_OVERLAY_FS_METACOPY );
68+ module_param_named (metacopy , ovl_metacopy_def , bool , 0644 );
69+ MODULE_PARM_DESC (ovl_metacopy_def ,
70+ "Default to on or off for the metadata only copy up feature" );
71+
6772static void ovl_dentry_release (struct dentry * dentry )
6873{
6974 struct ovl_entry * oe = dentry -> d_fsdata ;
@@ -347,6 +352,9 @@ static int ovl_show_options(struct seq_file *m, struct dentry *dentry)
347352 "on" : "off" );
348353 if (ofs -> config .xino != ovl_xino_def ())
349354 seq_printf (m , ",xino=%s" , ovl_xino_str [ofs -> config .xino ]);
355+ if (ofs -> config .metacopy != ovl_metacopy_def )
356+ seq_printf (m , ",metacopy=%s" ,
357+ ofs -> config .metacopy ? "on" : "off" );
350358 return 0 ;
351359}
352360
@@ -384,6 +392,8 @@ enum {
384392 OPT_XINO_ON ,
385393 OPT_XINO_OFF ,
386394 OPT_XINO_AUTO ,
395+ OPT_METACOPY_ON ,
396+ OPT_METACOPY_OFF ,
387397 OPT_ERR ,
388398};
389399
@@ -400,6 +410,8 @@ static const match_table_t ovl_tokens = {
400410 {OPT_XINO_ON , "xino=on" },
401411 {OPT_XINO_OFF , "xino=off" },
402412 {OPT_XINO_AUTO , "xino=auto" },
413+ {OPT_METACOPY_ON , "metacopy=on" },
414+ {OPT_METACOPY_OFF , "metacopy=off" },
403415 {OPT_ERR , NULL }
404416};
405417
@@ -452,6 +464,7 @@ static int ovl_parse_redirect_mode(struct ovl_config *config, const char *mode)
452464static int ovl_parse_opt (char * opt , struct ovl_config * config )
453465{
454466 char * p ;
467+ int err ;
455468
456469 config -> redirect_mode = kstrdup (ovl_redirect_mode_def (), GFP_KERNEL );
457470 if (!config -> redirect_mode )
@@ -526,6 +539,14 @@ static int ovl_parse_opt(char *opt, struct ovl_config *config)
526539 config -> xino = OVL_XINO_AUTO ;
527540 break ;
528541
542+ case OPT_METACOPY_ON :
543+ config -> metacopy = true;
544+ break ;
545+
546+ case OPT_METACOPY_OFF :
547+ config -> metacopy = false;
548+ break ;
549+
529550 default :
530551 pr_err ("overlayfs: unrecognized mount option \"%s\" or missing value\n" , p );
531552 return - EINVAL ;
@@ -540,7 +561,20 @@ static int ovl_parse_opt(char *opt, struct ovl_config *config)
540561 config -> workdir = NULL ;
541562 }
542563
543- return ovl_parse_redirect_mode (config , config -> redirect_mode );
564+ err = ovl_parse_redirect_mode (config , config -> redirect_mode );
565+ if (err )
566+ return err ;
567+
568+ /* metacopy feature with upper requires redirect_dir=on */
569+ if (config -> upperdir && config -> metacopy && !config -> redirect_dir ) {
570+ pr_warn ("overlayfs: metadata only copy up requires \"redirect_dir=on\", falling back to metacopy=off.\n" );
571+ config -> metacopy = false;
572+ } else if (config -> metacopy && !config -> redirect_follow ) {
573+ pr_warn ("overlayfs: metadata only copy up requires \"redirect_dir=follow\" on non-upper mount, falling back to metacopy=off.\n" );
574+ config -> metacopy = false;
575+ }
576+
577+ return 0 ;
544578}
545579
546580#define OVL_WORKDIR_NAME "work"
@@ -1013,7 +1047,8 @@ static int ovl_make_workdir(struct ovl_fs *ofs, struct path *workpath)
10131047 if (err ) {
10141048 ofs -> noxattr = true;
10151049 ofs -> config .index = false;
1016- pr_warn ("overlayfs: upper fs does not support xattr, falling back to index=off.\n" );
1050+ ofs -> config .metacopy = false;
1051+ pr_warn ("overlayfs: upper fs does not support xattr, falling back to index=off and metacopy=off.\n" );
10171052 err = 0 ;
10181053 } else {
10191054 vfs_removexattr (ofs -> workdir , OVL_XATTR_OPAQUE );
@@ -1035,7 +1070,6 @@ static int ovl_make_workdir(struct ovl_fs *ofs, struct path *workpath)
10351070 pr_warn ("overlayfs: NFS export requires \"index=on\", falling back to nfs_export=off.\n" );
10361071 ofs -> config .nfs_export = false;
10371072 }
1038-
10391073out :
10401074 mnt_drop_write (mnt );
10411075 return err ;
@@ -1346,6 +1380,7 @@ static int ovl_fill_super(struct super_block *sb, void *data, int silent)
13461380 ofs -> config .index = ovl_index_def ;
13471381 ofs -> config .nfs_export = ovl_nfs_export_def ;
13481382 ofs -> config .xino = ovl_xino_def ();
1383+ ofs -> config .metacopy = ovl_metacopy_def ;
13491384 err = ovl_parse_opt ((char * ) data , & ofs -> config );
13501385 if (err )
13511386 goto out_err ;
@@ -1416,6 +1451,11 @@ static int ovl_fill_super(struct super_block *sb, void *data, int silent)
14161451 }
14171452 }
14181453
1454+ if (ofs -> config .metacopy && ofs -> config .nfs_export ) {
1455+ pr_warn ("overlayfs: NFS export is not supported with metadata only copy up, falling back to nfs_export=off.\n" );
1456+ ofs -> config .nfs_export = false;
1457+ }
1458+
14191459 if (ofs -> config .nfs_export )
14201460 sb -> s_export_op = & ovl_export_operations ;
14211461
0 commit comments