overlay: add no wait share flock for lowers/upper/work dirs to help check mount
RFC PATCH 2/2 overlay: add no wait share flock for lowers/upper/work dirs to help check mount
In order to help check any dirs has been used in overlay, add share flock to lowerdirs/upperdir/workdir, so user space can use flock -x to help check mount.
--- fs/overlayfs/ovl_entry.h | 3 ++ fs/overlayfs/super.c | 87 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 90 insertions(+)
fs/overlayfs/ovl_entry.h +3 -0
@@ -35,10 +35,13 @@ struct ovl_path {/* private information held for overlayfs's superblock */ struct ovl_fs {struct vfsmount *upper_mnt; +struct file *upperfile;unsigned numlower;struct ovl_layer *lower_layers; +struct file **lowerfiles;/* workbasedir is the path at workdir= mount option */ struct dentry *workbasedir; +struct file *workbasefile;/* workdir is the 'work' directory under workbasedir */ struct dentry *workdir;/* index directory listing overlay inodes by origin file handle */
fs/overlayfs/super.c +87 -0
161 lines not on this page · raw message
Signature · 1 line
1.8.3.1
Amir Goldstein
maintainerQuoted 3 lines · yangerkun
In order to help check any dirs has been used in overlay, add share flock to lowerdirs/upperdir/workdir, so user space can use flock -x to help check mount.
Rephrase: so fsck.overlay can use flock -x to get an exclusive access to fix overlay layers.
Yangerkun,
Besides addressing fsck.overlay exclusive access requirement, this work should also make ovl_inuse_lock() obsolete. It should be replaced by an exclusive flock on upperdir/workdir.
Please write a new xfstest (you can clone overlay/036) that tests the interaction of overlayfs mount with flock -x and flock -s from usersapce.
Thanks for working on this.
See more comments below.
Quoted 12 lines
Signed-off-by yangerkun <[email protected]>--- fs/overlayfs/ovl_entry.h | 3 ++ fs/overlayfs/super.c | 87 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 90 insertions(+)fs/overlayfs/ovl_entry.h +0
-0
fs/overlayfs/ovl_entry.h struct ovl_path { · line 41
Quoted 7 lines
fs/overlayfs/ovl_entry.h +2
-0@@ -35,10 +35,13 @@ struct ovl_path {/* private information held for overlayfs's superblock */ struct ovl_fs {struct vfsmount *upper_mnt; +struct file *upperfile;unsigned numlower;struct ovl_layer *lower_layers; +struct file **lowerfiles;
Instead of lowerfiles array add file to struct ovl_layer.
fs/overlayfs/ovl_entry.h struct ovl_path { · line 44
Quoted 3 lines
fs/overlayfs/ovl_entry.h +1
-0/* workbasedir is the path at workdir= mount option */ struct dentry *workbasedir; +struct file *workbasefile;
workbasedir it almost only used for the old ovl_inuse_lock() and you can get it from workbasefile. No reason to keep both around.
Quoted 48 lines
fs/overlayfs/ovl_entry.h +0
-0/* workdir is the 'work' directory under workbasedir */ struct dentry *workdir;/* index directory listing overlay inodes by origin file handle */ fs/overlayfs/super.c +17
-0@@ -16,6 +16,7 @@#include <linux/module.h> #include <linux/statfs.h> #include <linux/seq_file.h> +#include <linux/file.h> #include <linux/posix_acl_xattr.h> #include "overlayfs.h" @@ -233,15 +234,31 @@ static void ovl_free_fs(struct ovl_fs *ofs)if (ofs->workdir_locked)ovl_inuse_unlock (ofs->workbasedir);dput (ofs->workbasedir); + +if (ofs->workbasefile) +fput (ofs->workbasefile); +if (ofs->upperdir_locked)ovl_inuse_unlock (ofs->upper_mnt->mnt_root);mntput (ofs->upper_mnt); + +if (ofs->upperfile) +fput (ofs->upperfile); +for (i =0 ; i < ofs->numlower; i++) {mntput (ofs->lower_layers[i].mnt);free_anon_bdev (ofs->lower_layers[i].pseudo_dev); }kfree (ofs->lower_layers); +if (ofs->lowerfiles) { +for (i =0 ; i < ofs->numlower; i++) { +if (ofs->lowerfiles[i]) +fput (ofs->lowerfiles[i]); + } +kfree (ofs->lowerfiles); + } +kfree (ofs->config.lowerdir);kfree (ofs->config.upperdir);kfree (ofs->config.workdir);
fs/overlayfs/super.c static int ovl_other_xattr_set(const struct xattr_handler *handler, · line 922
Quoted 4 lines
fs/overlayfs/super.c +1
-0@@ -902,15 +919,49 @@ static int ovl_other_xattr_set(const struct xattr_handler *handler, NULL }; +static int ovl_add_share_flock (struct file *filp)
This name is strange. ovl_flock() seems descriptive enough and it should take a 'cmd' argument, so you can use it also for exclusive flock.
fs/overlayfs/super.c static int ovl_other_xattr_set(const struct xattr_handler *handler, · line 934
Quoted 12 lines
fs/overlayfs/super.c +12
-0+{ +int err; +struct file_lock *fl =locks_alloc_lock (); + +if (!fl) +return -ENOMEM ; + fl->fl_file = filp; + fl->fl_owner = filp; + fl->fl_pid = current->tgid; + fl->fl_flags =FL_FLOCK ; + fl->fl_type =F_RDLCK ; + fl->fl_end =OFFSET_MAX ;
I would consider making non static and exporting flock_make_lock()
Quoted 15 lines
fs/overlayfs/super.c +7
-0+ + err =flock_setlk (filp, fl); +locks_free_lock (fl); +return err; +} +static int ovl_get_upper (struct ovl_fs *ofs,struct path *upperpath) {struct vfsmount *upper_mnt; +struct file *upperfile;int err; err =ovl_mount_dir (ofs->config.upperdir, upperpath);if (err) goto out;
fs/overlayfs/super.c static int ovl_other_xattr_set(const struct xattr_handler *handler, · line 959
Quoted 10 lines
fs/overlayfs/super.c +9
-0+ upperfile =ovl_path_open (upperpath,O_DIRECTORY ); +if (IS_ERR (upperfile)) { +pr_err ("overlayfs: unable to open upperdir.\n" ); + err =PTR_ERR (upperfile); + goto out; + } + + ofs->upperfile = upperfile; + err =ovl_add_share_flock (upperfile);
It should be an exclusive lock if index feature is enabled, instead of ovll_inuse_lock().
Thanks,
Amir.