Fix hardlinks in overlay
cover Fix hardlinks in overlay
There were reports that overlay doesn't work very well with unix-sockets. In particular you can't access unix-socket through hardlink on overlay fs. Problem is that overlay creates different inodes for hardlinks and code in net/unix/af_unix.c relies on inodes for unix-socket lookup. I think this affects any code which relies on inodes from kern_path. There is helper d_backing_inode, which I think supposed to get inodes from underlying fs (for example ext4), but in current implementation it does nothing. These patches made on top of v4.3-rc4 of main linux tree (master is broken for my ubuntu VM), but I tested that they applying on master and there was no changes to overlay since v4.3-rc4.
Alexander Morozov (2):
fs/overlay: move update and instantiate dentry code to function fs/overlay: use same inodes for hardlinks
fs/overlayfs/dir.c | 41 +++++++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 12 deletions(-)
Signature · 1 line
2.6.1
PATCH 1/2 fs/overlay: move update and instantiate dentry code to function
ovl_create_upper and ovl_create_over_whiteout shared same code about updating and instantiating dentry. Move that code to ovl_dentry_update_instantiate function, so it'll be easier to bring new changes there.
--- fs/overlayfs/dir.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-)
fs/overlayfs/dir.c +12 -8
@@ -158,6 +158,16 @@ static int ovl_dir_getattr(struct vfsmount *mnt, struct dentry *dentry,return 0 ; } +static void ovl_dentry_update_instantiate (struct dentry *dentry, +struct dentry *newdentry, +struct inode *inode) +{ +ovl_dentry_version_inc (dentry->d_parent); +ovl_dentry_update (dentry, newdentry); +ovl_copyattr (newdentry->d_inode, inode); +d_instantiate (dentry, inode); +} +static int ovl_create_upper (struct dentry *dentry,struct inode *inode,struct kstat *stat,const char *link,struct dentry *hardlink)
@@ -177,10 +187,7 @@ static int ovl_create_upper(struct dentry *dentry, struct inode *inode,if (err) goto out_dput; -ovl_dentry_version_inc (dentry->d_parent); -ovl_dentry_update (dentry, newdentry); -ovl_copyattr (newdentry->d_inode, inode); -d_instantiate (dentry, inode); +ovl_dentry_update_instantiate (dentry, newdentry, inode); newdentry =NULL ; out_dput:dput (newdentry);
@@ -363,10 +370,7 @@ static int ovl_create_over_whiteout(struct dentry *dentry, struct inode *inode,if (err) goto out_cleanup; } -ovl_dentry_version_inc (dentry->d_parent); -ovl_dentry_update (dentry, newdentry); -ovl_copyattr (newdentry->d_inode, inode); -d_instantiate (dentry, inode); +ovl_dentry_update_instantiate (dentry, newdentry, inode); newdentry =NULL ; out_dput2:dput (upper);
Signature · 1 line
2.6.1
PATCH 2/2 fs/overlay: use same inodes for hardlinks
In reply to Alexander MorozovFix problem with accessing hardlink to unix-socket. unix_find_other function from net/unix/af_unix.c uses d_backing_inode helper which in current implementation doesn't return any "backing" inode, but just dentry->d_inode, so, there from kern_path we have path with dentry from overlayfs and not underlying file system. Further in code in unix_find_socket_byinode we looking for unix-socket by inode, but due overlayfs implementation that inode for hardlink will be different from original inode of unix-socket.
Now ovl_link doesn't create new inode, but uses old->d_inode for instantiating new dentry. Not use inc_nlink, because nlink seems to be correctly propagated from underlying fs where it need.
--- fs/overlayfs/dir.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-)
fs/overlayfs/dir.c +19 -6
@@ -164,8 +164,14 @@ static void ovl_dentry_update_instantiate(struct dentry *dentry, {ovl_dentry_version_inc (dentry->d_parent);ovl_dentry_update (dentry, newdentry); -ovl_copyattr (newdentry->d_inode, inode); -d_instantiate (dentry, inode); +/* +* inode == NULL only in case of hardlink +* for hardlink dentry will be instantiated in ovl_link +*/ +if (inode) { +ovl_copyattr (newdentry->d_inode, inode); +d_instantiate (dentry, inode); + } } static int ovl_create_upper(struct dentry *dentry, struct inode *inode,
@@ -390,16 +396,19 @@ static int ovl_create_or_link(struct dentry *dentry, int mode, dev_t rdev, const char *link, struct dentry *hardlink) { int err; -struct inode *inode; +struct inode *inode =NULL ;struct kstat stat = { .mode = mode, .rdev = rdev, }; err = -ENOMEM ; - inode =ovl_new_inode (dentry->d_sb, mode, dentry->d_fsdata); -if (!inode) - goto out; +/* We don't need inode for hardlink */ +if (!hardlink) { + inode =ovl_new_inode (dentry->d_sb, mode, dentry->d_fsdata); +if (!inode) + goto out; + } err =ovl_copy_up (dentry->d_parent);if (err)
@@ -498,6 +507,10 @@ static int ovl_link(struct dentry *old, struct inode *newdir, upper =ovl_dentry_upper (old); err =ovl_create_or_link (new, upper->d_inode->i_mode,0 ,NULL , upper); +if (!err) { +ihold (old->d_inode); +d_instantiate (new, old->d_inode); + } out_drop_write:ovl_drop_write (old);
Signature · 1 line
2.6.1
Re: [PATCH 2/2] fs/overlay: use same inodes for hardlinks
ping
it's still fixes issue for me
and still can be applied to master of main linux tree
Miklos Szeredi
maintainerQuoted 11 lines · Alexander Morozov
There were reports that overlay doesn't work very well with unix-sockets. In particular you can't access unix-socket through hardlink on overlay fs. Problem is that overlay creates different inodes for hardlinks and code in
net/unix/af_unix.crelies on inodes for unix-socket lookup. I think this affects any code which relies on inodes fromkern_path. There is helperd_backing_inode, which I think supposed to get inodes from underlying fs (for example ext4), but in current implementation it does nothing. These patches made on top of v4.3-rc4 of main linux tree (master is broken for my ubuntu VM), but I tested that they applying on master and there was no changes to overlay since v4.3-rc4.
Quoted 3 lines
Alexander Morozov (2):
fs/overlay: move update and instantiate dentry code to function fs/overlay: use same inodes for hardlinks
Problem is with lookup: how do we go from backing dentry to overlayfs dentry so the inode can be shared?
Thanks,
Miklos
Sequence of calls is kern_path(filename, LOOKUP_FOLLOW, &path) -> filename_lookup(AT_FDCWD, getname_kernel(name), flags, path, NULL) -> path_lookup(nameidata *nd, flags | LOOKUP_RCU, path) -> path_init(nd, flags). In that function if I understand correctly nd->path is set to current_thread_info()->task->fs->pwd and I don't see any further tricks with dentry, so I suppose that current_thread_info()->task->fs->pwd->dentry already points to overlayfs dentry.
Let me know what we can do with it.
Thanks!
- Alex
Quoted 22 lines · Miklos Szeredi
Quoted 11 lines · Alexander Morozov
There were reports that overlay doesn't work very well with unix-sockets. In particular you can't access unix-socket through hardlink on overlay fs. Problem is that overlay creates different inodes for hardlinks and code in
net/unix/af_unix.crelies on inodes for unix-socket lookup. I think this affects any code which relies on inodes fromkern_path. There is helperd_backing_inode, which I think supposed to get inodes from underlying fs (for example ext4), but in current implementation it does nothing. These patches made on top of v4.3-rc4 of main linux tree (master is broken for my ubuntu VM), but I tested that they applying on master and there was no changes to overlay since v4.3-rc4.Quoted 3 lines
Alexander Morozov (2):
fs/overlay: move update and instantiate dentry code to function fs/overlay: use same inodes for hardlinksProblem is with lookup: how do we go from backing dentry to overlayfs dentry so the inode can be shared?
Thanks,
Miklos