From: Robert Buhren <robert@robertbuhren.de>
To: Jan Schmidt <list.btrfs@jan-o-sch.net>
Cc: linux-btrfs@vger.kernel.org,
Alexander Block <ablock84@googlemail.com>,
Arne Jansen <sensille@gmx.net>
Subject: Re: [PATCH] Btrfs-progs: replace find_mount_root from send code
Date: Thu, 23 Aug 2012 10:54:54 +0200 [thread overview]
Message-ID: <5035EFDE.4090404@robertbuhren.de> (raw)
In-Reply-To: <1345463835-26636-1-git-send-email-list.btrfs@jan-o-sch.net>
Hi Jan,
thanks for the patch! Sending works. But i got some trouble on the
receiving side.
Here's my complete test-setup:
I have two btrfs partitions:
mount | grep btrfs:
/dev/loop0 on /mnt/TEST_ROOT type btrfs
(rw,relatime,compress=lzo,space_cache) # default-subvolume
/dev/loop0 on /mnt/TEST_ROOT/root_volid0 type btrfs
(rw,relatime,compress=lzo,space_cache) # subvolid= 0
/dev/loop1 on /mnt/TEST_ROOT/backup_volid0 type btrfs
(rw,relatime,compress=lzo,space_cache)
With the patch this works now:
btrfs subvolume snapshot -r /mnt/TEST_ROOT/root_volid0/root/
/mnt/TEST_ROOT/root_volid0/root_snap
btrfs send /mnt/TEST_ROOT/root_volid0/root_snap > root_snap_send
But when i try to receive it on the /mnt/TEST_ROOT/backup_volid0 btrfs
partition i get:
btrfs receive -f root_snap_send /mnt/TEST_ROOT/backup_volid0/
ERROR: utimes failed. Bad file descriptor
i also tried "cat root_snap_send | btrfs receive
/mnt/TEST_ROOT/backup_volid0". But the result is the same.
What's interesting is that there is actually a subvolume "root_snap"
created in "backup_volid0", but it's empty.
I'm on linux-3.6-rc2 and btrfs-progs from git.
If further Information is needed, just tell me.
Regards,
Robert
On 20.08.2012 13:57, Jan Schmidt wrote:
> Hi Robert,
>
> i made a quick patch, can you please give it a try? Can be applied with
> "git am --scissors".
>
> Thanks,
> -Jan
>
> -- >8 --
>
> find_mount_root had the problem that it tried to conclude from a file system
> path to a mount point, taking the fsid as an indicator. This only works if
> no two subvolumes (sharing the same btrfs fsid) are mounted in the same
> hierarchy.
>
> Now instead, we're parsing /etc/mtab and look for the longest match.
>
> Signed-off-by: Jan Schmidt <list.btrfs@jan-o-sch.net>
> ---
> cmds-send.c | 88 ++++++++++++++---------------------------------------------
> 1 files changed, 21 insertions(+), 67 deletions(-)
>
> diff --git a/cmds-send.c b/cmds-send.c
> index 8a0c110..41ea523 100644
> --- a/cmds-send.c
> +++ b/cmds-send.c
> @@ -28,6 +28,7 @@
> #include <sys/types.h>
> #include <sys/ioctl.h>
> #include <libgen.h>
> +#include <mntent.h>
>
> #include <uuid/uuid.h>
>
> @@ -55,82 +56,35 @@ struct btrfs_send {
>
> int find_mount_root(const char *path, char **mount_root)
> {
> - int ret;
> - char *cur;
> - char fsid[BTRFS_FSID_SIZE];
> + FILE *mnttab;
> int fd;
> - struct stat st;
> - char *tmp;
> - char *dup = NULL;
> -
> - struct btrfs_ioctl_fs_info_args args;
> + struct mntent *ent;
> + int len;
> + int longest_matchlen = 0;
> + char *longest_match = NULL;
>
> fd = open(path, O_RDONLY | O_NOATIME);
> - if (fd < 0) {
> - ret = -errno;
> - goto out;
> - }
> -
> - ret = fstat(fd, &st);
> - if (fd < 0) {
> - ret = -errno;
> - goto out;
> - }
> - if (!S_ISDIR(st.st_mode)) {
> - ret = -ENOTDIR;
> - goto out;
> - }
> -
> - ret = ioctl(fd, BTRFS_IOC_FS_INFO, &args);
> - if (fd < 0) {
> - ret = -errno;
> - goto out;
> - }
> - memcpy(fsid, args.fsid, BTRFS_FSID_SIZE);
> + if (fd < 0)
> + return -errno;
> close(fd);
> - fd = -1;
>
> - cur = strdup(path);
> -
> - while (1) {
> - dup = strdup(cur);
> - tmp = dirname(dup);
> -
> - if (!tmp)
> - break;
> - fd = open(tmp, O_RDONLY | O_NOATIME);
> - if (fd < 0) {
> - ret = -errno;
> - goto out;
> + mnttab = fopen("/etc/mtab", "r");
> + while ((ent = getmntent(mnttab))) {
> + len = strlen(ent->mnt_dir);
> + if (strncmp(ent->mnt_dir, path, len) == 0) {
> + /* match found */
> + if (longest_matchlen < len) {
> + free(longest_match);
> + longest_matchlen = len;
> + longest_match = strdup(ent->mnt_dir);
> + }
> }
> -
> - ret = ioctl(fd, BTRFS_IOC_FS_INFO, &args);
> - close(fd);
> - fd = -1;
> - if (ret < 0)
> - break;
> - if (memcmp(fsid, args.fsid, BTRFS_FSID_SIZE) != 0)
> - break;
> -
> - free(cur);
> - cur = strdup(tmp);
> - free(dup);
> - dup = NULL;
> - if (strcmp(cur, "/") == 0)
> - break;
> - if (strcmp(cur, ".") == 0)
> - break;
> }
>
> - ret = 0;
> - *mount_root = realpath(cur, NULL);
> + *mount_root = realpath(longest_match, NULL);
> + free(longest_match);
>
> -out:
> - if (dup)
> - free(dup);
> - if (fd != -1)
> - close(fd);
> - return ret;
> + return 0;
> }
>
> static int get_root_id(struct btrfs_send *s, const char *path, u64 *root_id)
next prev parent reply other threads:[~2012-08-23 8:55 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-08-13 10:22 Testing new send/receive: "ERROR: could not resolve root_id for" Robert Buhren
2012-08-19 14:59 ` Arne Jansen
2012-08-20 11:57 ` [PATCH] Btrfs-progs: replace find_mount_root from send code Jan Schmidt
2012-08-23 8:54 ` Robert Buhren [this message]
2012-08-24 13:33 ` David Sterba
2012-08-25 8:24 ` Robert Buhren
2012-08-27 9:16 ` Alex Lyakas
2012-08-27 18:37 ` Robert Buhren
2012-08-28 8:27 ` Alex Lyakas
2012-08-28 17:26 ` Alex Lyakas
2012-09-24 17:18 ` David Sterba
2012-10-03 13:01 ` Alex Lyakas
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=5035EFDE.4090404@robertbuhren.de \
--to=robert@robertbuhren.de \
--cc=ablock84@googlemail.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=list.btrfs@jan-o-sch.net \
--cc=sensille@gmx.net \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.