From: Qu Wenruo <quwenruo.btrfs@gmx.com>
To: Marcos Paulo de Souza <marcos@mpdesouza.com>,
linux-btrfs@vger.kernel.org
Cc: Marcos Paulo de Souza <mpdesouza@suse.com>,
wqu@suse.com, dsterba@suse.com
Subject: Re: [PATCH v2 1/3] btrfs-progs: Adapt find_mount_root to verify other fields of mntent struct
Date: Fri, 20 Nov 2020 16:22:44 +0800 [thread overview]
Message-ID: <9335c923-d83b-d1e2-4fc1-86c3d8de9e9f@gmx.com> (raw)
In-Reply-To: <20201116173249.11847-2-marcos@mpdesouza.com>
[-- Attachment #1.1: Type: text/plain, Size: 5227 bytes --]
On 2020/11/17 上午1:32, Marcos Paulo de Souza wrote:
> From: Marcos Paulo de Souza <mpdesouza@suse.com>
>
> Currently find_mount_root searches for all btrfs filesystems
> mounted and comparing <path> with mnt_dir of each mountpoint.
>
> But there are cases when we need to find the mountpoint for a determined
> subvolid or subvol path, and these informations are present in mnt_opts
> of mntent struct.
Mind to share why we want that?
The main concern here is, I didn't see the point that how the mount
point of a subvolume would affect anything.
Thanks,
Qu
>
> This patch adds two arguments to find_mount_root (data and flag). The
> data argument hold the information that we want to compare, and the flag
> argument specifies which field of mntent struct that we want to compare.
> Currently there is only one flag, BTRFS_FIND_ROOT_PATH, implementing the
> current behavior. The next patch will add a new flag to expand the functionality.
>
> Users of find_mount_root were changed, having the data argument the same
> as path, since they are only trying to find the mountpoint based on path alone.
>
> Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
> ---
> cmds/receive.c | 3 ++-
> cmds/send.c | 6 ++++--
> common/utils.c | 15 ++++++++++++---
> common/utils.h | 8 +++++++-
> 4 files changed, 25 insertions(+), 7 deletions(-)
>
> diff --git a/cmds/receive.c b/cmds/receive.c
> index 2aaba3ff..dc64480e 100644
> --- a/cmds/receive.c
> +++ b/cmds/receive.c
> @@ -1079,7 +1079,8 @@ static int do_receive(struct btrfs_receive *rctx, const char *tomnt,
> if (realmnt[0]) {
> rctx->root_path = realmnt;
> } else {
> - ret = find_mount_root(dest_dir_full_path, &rctx->root_path);
> + ret = find_mount_root(dest_dir_full_path, dest_dir_full_path,
> + BTRFS_FIND_ROOT_PATH, &rctx->root_path);
> if (ret < 0) {
> errno = -ret;
> error("failed to determine mount point for %s: %m",
> diff --git a/cmds/send.c b/cmds/send.c
> index b8e3ba12..7757f0da 100644
> --- a/cmds/send.c
> +++ b/cmds/send.c
> @@ -329,7 +329,8 @@ static int init_root_path(struct btrfs_send *sctx, const char *subvol)
> if (sctx->root_path)
> goto out;
>
> - ret = find_mount_root(subvol, &sctx->root_path);
> + ret = find_mount_root(subvol, subvol, BTRFS_FIND_ROOT_PATH,
> + &sctx->root_path);
> if (ret < 0) {
> errno = -ret;
> error("failed to determine mount point for %s: %m", subvol);
> @@ -659,7 +660,8 @@ static int cmd_send(const struct cmd_struct *cmd, int argc, char **argv)
> goto out;
> }
>
> - ret = find_mount_root(subvol, &mount_root);
> + ret = find_mount_root(subvol, subvol, BTRFS_FIND_ROOT_PATH,
> + &mount_root);
> if (ret < 0) {
> errno = -ret;
> error("find_mount_root failed on %s: %m", subvol);
> diff --git a/common/utils.c b/common/utils.c
> index 1253e87d..1c264455 100644
> --- a/common/utils.c
> +++ b/common/utils.c
> @@ -1248,7 +1248,7 @@ int ask_user(const char *question)
> * return 1 if a mount point is found but not btrfs
> * return <0 if something goes wrong
> */
> -int find_mount_root(const char *path, char **mount_root)
> +int find_mount_root(const char *path, const char *data, u8 flag, char **mount_root)
> {
> FILE *mnttab;
> int fd;
> @@ -1258,6 +1258,10 @@ int find_mount_root(const char *path, char **mount_root)
> int not_btrfs = 1;
> int longest_matchlen = 0;
> char *longest_match = NULL;
> + char *cmp_field = NULL;
> + bool found;
> +
> + BUG_ON(flag != BTRFS_FIND_ROOT_PATH);
>
> fd = open(path, O_RDONLY | O_NOATIME);
> if (fd < 0)
> @@ -1269,8 +1273,13 @@ int find_mount_root(const char *path, char **mount_root)
> return -errno;
>
> while ((ent = getmntent(mnttab))) {
> - len = strlen(ent->mnt_dir);
> - if (strncmp(ent->mnt_dir, path, len) == 0) {
> + cmp_field = ent->mnt_dir;
> +
> + len = strlen(cmp_field);
> +
> + found = strncmp(cmp_field, data, len) == 0;
> +
> + if (found) {
> /* match found and use the latest match */
> if (longest_matchlen <= len) {
> free(longest_match);
> diff --git a/common/utils.h b/common/utils.h
> index 119c3881..449e1d3e 100644
> --- a/common/utils.h
> +++ b/common/utils.h
> @@ -52,6 +52,11 @@
> #define UNITS_HUMAN (UNITS_HUMAN_BINARY)
> #define UNITS_DEFAULT (UNITS_HUMAN)
>
> +enum btrfs_find_root_flags {
> + /* check mnt_dir of mntent */
> + BTRFS_FIND_ROOT_PATH = 0
> +};
> +
> void units_set_mode(unsigned *units, unsigned mode);
> void units_set_base(unsigned *units, unsigned base);
>
> @@ -93,7 +98,8 @@ int csum_tree_block(struct btrfs_fs_info *root, struct extent_buffer *buf,
> int ask_user(const char *question);
> int lookup_path_rootid(int fd, u64 *rootid);
> int get_btrfs_mount(const char *dev, char *mp, size_t mp_size);
> -int find_mount_root(const char *path, char **mount_root);
> +int find_mount_root(const char *path, const char *data, u8 flag,
> + char **mount_root);
> int get_device_info(int fd, u64 devid,
> struct btrfs_ioctl_dev_info_args *di_args);
> int get_df(int fd, struct btrfs_ioctl_space_args **sargs_ret);
>
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
next prev parent reply other threads:[~2020-11-20 8:23 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-16 17:32 [PATCH v2 0/3] btrfs-progs: Fix logical-resolve Marcos Paulo de Souza
2020-11-16 17:32 ` [PATCH v2 1/3] btrfs-progs: Adapt find_mount_root to verify other fields of mntent struct Marcos Paulo de Souza
2020-11-20 8:22 ` Qu Wenruo [this message]
2020-11-16 17:32 ` [PATCH v2 2/3] btrfs-progs: inspect: Fix logical-resolve file path lookup Marcos Paulo de Souza
2020-11-20 8:32 ` Qu Wenruo
2020-11-20 8:43 ` Qu Wenruo
2020-11-21 12:38 ` Marcos Paulo de Souza
2020-11-21 12:35 ` Marcos Paulo de Souza
2020-11-21 12:48 ` Qu Wenruo
2020-11-16 17:32 ` [PATCH v2 3/3] btrfs-progs: tests: Add new logical-resolve test Marcos Paulo de Souza
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=9335c923-d83b-d1e2-4fc1-86c3d8de9e9f@gmx.com \
--to=quwenruo.btrfs@gmx.com \
--cc=dsterba@suse.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=marcos@mpdesouza.com \
--cc=mpdesouza@suse.com \
--cc=wqu@suse.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