Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1243621 > unrolled thread

[PATCH 0/2] Fix hardlinks in overlay

Started byAlexander Morozov <alexandr.morozov@docker.com>
First post2015-10-09 21:40 +0200
Last post2015-10-09 21:40 +0200
Articles 3 — 1 participant

Back to article view | Back to linux.kernel


Contents

  [PATCH 0/2] Fix hardlinks in overlay Alexander Morozov <alexandr.morozov@docker.com> - 2015-10-09 21:40 +0200
    [PATCH 2/2] fs/overlay: use same inodes for hardlinks Alexander Morozov <alexandr.morozov@docker.com> - 2015-10-09 21:40 +0200
    [PATCH 1/2] fs/overlay: move update and instantiate dentry code to function Alexander Morozov <alexandr.morozov@docker.com> - 2015-10-09 21:40 +0200

#1243621 — [PATCH 0/2] Fix hardlinks in overlay

FromAlexander Morozov <alexandr.morozov@docker.com>
Date2015-10-09 21:40 +0200
Subject[PATCH 0/2] Fix hardlinks in overlay
Message-ID<qhLGh-3cM-3@gated-at.bofh.it>
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(-)

-- 
2.6.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [next] | [standalone]


#1243623 — [PATCH 2/2] fs/overlay: use same inodes for hardlinks

FromAlexander Morozov <alexandr.morozov@docker.com>
Date2015-10-09 21:40 +0200
Subject[PATCH 2/2] fs/overlay: use same inodes for hardlinks
Message-ID<qhLGh-3cM-7@gated-at.bofh.it>
In reply to#1243621
Fix 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.

Signed-off-by: Alexander Morozov <lk4d4@docker.com>
---
 fs/overlayfs/dir.c | 25 +++++++++++++++++++------
 1 file changed, 19 insertions(+), 6 deletions(-)

diff --git a/fs/overlayfs/dir.c b/fs/overlayfs/dir.c
index 487a157..a55c89b 100644
--- a/fs/overlayfs/dir.c
+++ b/fs/overlayfs/dir.c
@@ -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);
-- 
2.6.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [next] | [standalone]


#1243624 — [PATCH 1/2] fs/overlay: move update and instantiate dentry code to function

FromAlexander Morozov <alexandr.morozov@docker.com>
Date2015-10-09 21:40 +0200
Subject[PATCH 1/2] fs/overlay: move update and instantiate dentry code to function
Message-ID<qhLGh-3cM-9@gated-at.bofh.it>
In reply to#1243621
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.

Signed-off-by: Alexander Morozov <lk4d4@docker.com>
---
 fs/overlayfs/dir.c | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/fs/overlayfs/dir.c b/fs/overlayfs/dir.c
index 692ceda..487a157 100644
--- a/fs/overlayfs/dir.c
+++ b/fs/overlayfs/dir.c
@@ -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);
-- 
2.6.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web