From: Wang Shilong <wangshilong1991@gmail.com>
To: linux-btrfs@vger.kernel.org
Subject: [PATCH] Btrfs: deal with all 'subvol=xxx' options once
Date: Tue, 25 Nov 2014 15:23:14 +0800 [thread overview]
Message-ID: <1416900194-17495-1-git-send-email-wangshilong1991@gmail.com> (raw)
Steps to reproduce:
# mkfs.btrfs -f /dev/sdb
# mount -t btrfs /dev/sdb /mnt
# btrfs sub create /mnt/dir
# mount -t btrfs /dev/sdb /mnt -o subvol=dir,subvol=dir
It fails with:
mount: mount(2) failed: No such file or directory
Btrfs deal with subvolume mounting in a recursive way,
to avoid looping, it will stripe out 'subvol=xxxx' string,
then next loop will stop.Problem here is it only deal one
string once, if users specify mount option multiple times.
It will loop several times which is not good, and above
reproducing steps will also return confusing results.
Fix this problem by striping out all 'subvol=xxx' options,
only last is valid.
Signed-off-by: Wang Shilong <wangshilong1991@gmail.com>
---
fs/btrfs/super.c | 20 +++++++++++++++++++-
1 file changed, 19 insertions(+), 1 deletion(-)
diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
index 54bd91e..2b2fa4b 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
@@ -1115,7 +1115,7 @@ static inline int is_subvolume_inode(struct inode *inode)
* subvolid=0 to make sure we get the actual tree root for path walking to the
* subvol we want.
*/
-static char *setup_root_args(char *args)
+static char *__setup_root_args(char *args)
{
unsigned len = strlen(args) + 2 + 1;
char *src, *dst, *buf;
@@ -1161,6 +1161,24 @@ static char *setup_root_args(char *args)
return buf;
}
+static char *setup_root_args(char *args)
+{
+ char *p, *new_args;
+
+ p = new_args = __setup_root_args(args);
+ /* in case users specify subvol=xxx option multiple times */
+ while (p) {
+ p = __setup_root_args(new_args);
+ if (p) {
+ kfree(new_args);
+ new_args = p;
+ } else {
+ break;
+ }
+ }
+ return new_args;
+}
+
static struct dentry *mount_subvol(const char *subvol_name, int flags,
const char *device_name, char *data)
{
--
1.7.12.4
next reply other threads:[~2014-11-25 7:24 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-11-25 7:23 Wang Shilong [this message]
2014-11-25 7:42 ` [PATCH] Btrfs: deal with all 'subvol=xxx' options once Wang Shilong
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=1416900194-17495-1-git-send-email-wangshilong1991@gmail.com \
--to=wangshilong1991@gmail.com \
--cc=linux-btrfs@vger.kernel.org \
/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).