public inbox for linux-btrfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Qu Wenruo <quwenruo.btrfs@gmx.com>
To: Mark Harmstone <maharmstone@fb.com>, linux-btrfs@vger.kernel.org
Subject: Re: [PATCH v3] btrfs-progs: add --subvol option to mkfs.btrfs
Date: Wed, 31 Jul 2024 07:10:55 +0930	[thread overview]
Message-ID: <21c6a67f-620a-4133-a955-c5707618cff8@gmx.com> (raw)
In-Reply-To: <20240730142155.2154877-1-maharmstone@fb.com>



在 2024/7/30 23:51, Mark Harmstone 写道:
> This patch adds a --subvol option, which tells mkfs.btrfs to create the
> specified directories as subvolumes.
>
> Given a populated directory img, the command
>
> $ mkfs.btrfs --rootdir img --subvol img/usr --subvol img/home --subvol img/home/username /dev/loop0
>
> will create subvolumes usr and home within the FS root, and subvolume
> username within the home subvolume. It will fail if any of the
> directories do not yet exist.
>
> Signed-off-by: Mark Harmstone <maharmstone@fb.com>
[...]
> @@ -570,6 +626,76 @@ static int traverse_directory(struct btrfs_trans_handle *trans,
>   				pr_verbose(LOG_INFO, "ADD: %s\n", tmp);
>   			}
>
> +			if (S_ISDIR(st.st_mode)) {
> +				if (!strcmp(parent_dir_entry->dest_dir, "")) {
> +					strcpy(cur_dest, cur_file->d_name);
> +				} else {
> +					strcpy(cur_dest, parent_dir_entry->dest_dir);
> +					strcat(cur_dest, "/");
> +					strcat(cur_dest, cur_file->d_name);
> +				}
> +			}
> +
> +			if (!list_empty(subvols) && S_ISDIR(st.st_mode)) {
> +				struct rootdir_subvol *s;
> +				bool found = false;
> +
> +				list_for_each_entry(s, subvols, list) {
> +					if (!strcmp(cur_dest, s->destpath)) {
> +						found = true;
> +						break;
> +					}
> +				}
> +
> +				if (found) {

Although I'm still not a fan of merging subvolume creation now, before
we refactor the existing way of adding/linking new inodes, at least the
code style can be improved.

Under most case we prefer to reduce the indent by exiting early for
non-hit cases.

In this case, we prefer something like :

				if (!found)
					continue;
				/* do the subvolume add/link here */

Thanks,
Qu

      reply	other threads:[~2024-07-30 21:41 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-30 14:21 [PATCH v3] btrfs-progs: add --subvol option to mkfs.btrfs Mark Harmstone
2024-07-30 21:40 ` Qu Wenruo [this message]

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=21c6a67f-620a-4133-a955-c5707618cff8@gmx.com \
    --to=quwenruo.btrfs@gmx.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=maharmstone@fb.com \
    /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