linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jordi Pujol <jordipujolp@gmail.com>
To: linux-fsdevel@vger.kernel.org, Miklos Szeredi <miklos@szeredi.hu>
Subject: overlayfs copy_up recursive
Date: Wed, 27 Apr 2011 15:35:54 +0200	[thread overview]
Message-ID: <201104271535.54392.jordipujolp@gmail.com> (raw)

[-- Attachment #1: Type: Text/Plain, Size: 324 bytes --]

Hello,

this patch recodes ovl_copy_up and ovl_copy_up_truncate as a recursive 
routine,
there is less code and less number of instructions to execute, therefore maybe 
faster and easy to mantain,

I have tested it, that works,

Thanks,

Jordi Pujol

Live never ending Tale
GNU/Linux Live forever!
http://livenet.selfip.com

[-- Attachment #2: 08-copy-up-recursive.patch --]
[-- Type: text/x-patch, Size: 2293 bytes --]

--- a/fs/overlayfs/copy_up.c
+++ b/fs/overlayfs/copy_up.c
@@ -315,69 +315,46 @@ out_free_link:
 	return err;
 }
 
-int ovl_copy_up(struct dentry *dentry)
+/* Optimize by not copying up the file first and truncating later */
+int ovl_copy_up_truncate(struct dentry *dentry, loff_t size)
 {
 	int err;
+	struct dentry *actual;
+	struct dentry *parent;
+	struct path lowerpath;
+	struct kstat stat;
+	enum ovl_path_type type;
 
 	err = 0;
-	while (!err) {
-		struct dentry *next;
-		struct dentry *parent;
-		struct path lowerpath;
-		struct kstat stat;
-		enum ovl_path_type type = ovl_path_type(dentry);
-
-		if (type != OVL_PATH_LOWER)
-			break;
-
-		next = dget(dentry);
-		/* find the topmost dentry not yet copied up */
-		for (;;) {
-			parent = dget_parent(next);
-
-			type = ovl_path_type(parent);
-			if (type != OVL_PATH_LOWER)
-				break;
 
-			dput(next);
-			next = parent;
-		}
+	actual = dget(dentry);
+	type = ovl_path_type(actual);
+	if (type != OVL_PATH_LOWER)
+		goto out;
+
+	/* if the parent is not yet copied up, copy it now recursively */
+	err = ovl_copy_up_truncate(actual->d_parent, -1LL);
+	if (!err) {
+		parent = dget_parent(actual);
 
-		ovl_path_lower(next, &lowerpath);
+		ovl_path_lower(actual, &lowerpath);
 		err = vfs_getattr(lowerpath.mnt, lowerpath.dentry, &stat);
-		if (!err)
-			err = ovl_copy_up_one(parent, next, &lowerpath, &stat);
+		if (!err) {
+			if (size >= 0 && size < stat.size)
+				stat.size = size;
+			err = ovl_copy_up_one(parent, actual, &lowerpath, &stat);
+		}
 
 		dput(parent);
-		dput(next);
 	}
 
+out:
+	dput(actual);
+
 	return err;
 }
 
-/* Optimize by not copying up the file first and truncating later */
-int ovl_copy_up_truncate(struct dentry *dentry, loff_t size)
+int ovl_copy_up(struct dentry *dentry)
 {
-	int err;
-	struct kstat stat;
-	struct path lowerpath;
-	struct dentry *parent = dget_parent(dentry);
-
-	err = ovl_copy_up(parent);
-	if (err)
-		goto out_dput_parent;
-
-	ovl_path_lower(dentry, &lowerpath);
-	err = vfs_getattr(lowerpath.mnt, lowerpath.dentry, &stat);
-	if (err)
-		goto out_dput_parent;
-
-	if (size < stat.size)
-		stat.size = size;
-
-	err = ovl_copy_up_one(parent, dentry, &lowerpath, &stat);
-
-out_dput_parent:
-	dput(parent);
-	return err;
+	return ovl_copy_up_truncate(dentry, -1LL);
 }

             reply	other threads:[~2011-04-27 13:37 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-27 13:35 Jordi Pujol [this message]
2011-04-27 18:56 ` overlayfs copy_up recursive Miklos Szeredi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=201104271535.54392.jordipujolp@gmail.com \
    --to=jordipujolp@gmail.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=miklos@szeredi.hu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).