* [PATCH 1/2] btrfs-progs: provide fail safe for BTRFS_IOC_GET_FSLABEL ioctl
@ 2015-09-15 8:46 Anand Jain
2015-09-15 8:46 ` [PATCH 2/2] btrfs-progs: optimize not to scan repeated fsid mount points Anand Jain
2015-09-25 13:55 ` [PATCH 1/2] btrfs-progs: provide fail safe for BTRFS_IOC_GET_FSLABEL ioctl David Sterba
0 siblings, 2 replies; 4+ messages in thread
From: Anand Jain @ 2015-09-15 8:46 UTC (permalink / raw)
To: linux-btrfs
Old kernel like 2.6.32 does not provide ioctl BTRFS_IOC_GET_FSLABEL.
So we need to provide a fail safe logic for btrfs-progs running
on those kernel.
In this patch when get_label_mounted() fails on the old kernel
it will fail back to the old method and uses get_label_unmounted(),
where it will read from the disk directly.
Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
cmds-filesystem.c | 7 ++++++-
utils.c | 18 +++++++++---------
utils.h | 1 +
3 files changed, 16 insertions(+), 10 deletions(-)
diff --git a/cmds-filesystem.c b/cmds-filesystem.c
index 8822695..793df0e 100644
--- a/cmds-filesystem.c
+++ b/cmds-filesystem.c
@@ -468,7 +468,12 @@ static int btrfs_scan_kernel(void *search, unsigned unit_mode)
goto out;
}
- if (get_label_mounted(mnt->mnt_dir, label)) {
+ ret = get_label_mounted(mnt->mnt_dir, label);
+ /* provide backward kernel compatibility */
+ if (ret == -ENOTTY)
+ ret = get_label_unmounted((char *) dev_info_arg->path, label);
+
+ if (ret) {
kfree(dev_info_arg);
goto out;
}
diff --git a/utils.c b/utils.c
index afc97ee..297c5a3 100644
--- a/utils.c
+++ b/utils.c
@@ -1741,7 +1741,7 @@ static int set_label_mounted(const char *mount_path, const char *label)
return 0;
}
-static int get_label_unmounted(const char *dev, char *label)
+int get_label_unmounted(const char *dev, char *label)
{
struct btrfs_root *root;
int ret;
@@ -1751,11 +1751,6 @@ static int get_label_unmounted(const char *dev, char *label)
fprintf(stderr, "FATAL: error checking %s mount status\n", dev);
return -1;
}
- if (ret > 0) {
- fprintf(stderr, "ERROR: dev %s is mounted, use mount point\n",
- dev);
- return -1;
- }
/* Open the super_block at the default location
* and as read-only.
@@ -1780,6 +1775,7 @@ int get_label_mounted(const char *mount_path, char *labelp)
{
char label[BTRFS_LABEL_SIZE];
int fd;
+ int ret;
fd = open(mount_path, O_RDONLY | O_NOATIME);
if (fd < 0) {
@@ -1788,10 +1784,14 @@ int get_label_mounted(const char *mount_path, char *labelp)
}
memset(label, '\0', sizeof(label));
- if (ioctl(fd, BTRFS_IOC_GET_FSLABEL, label) < 0) {
- fprintf(stderr, "ERROR: unable get label %s\n", strerror(errno));
+ ret = ioctl(fd, BTRFS_IOC_GET_FSLABEL, label);
+ if (ret < 0) {
+ if (errno != ENOTTY) {
+ fprintf(stderr, "ERROR: unable get label %s\n", strerror(errno));
+ }
+ ret = -errno;
close(fd);
- return -1;
+ return ret;
}
strncpy(labelp, label, sizeof(label));
diff --git a/utils.h b/utils.h
index 24d7aa5..4f7bb6f 100644
--- a/utils.h
+++ b/utils.h
@@ -164,6 +164,7 @@ u64 btrfs_device_size(int fd, struct stat *st);
#define strncpy_null(dest, src) __strncpy__null(dest, src, sizeof(dest))
int test_dev_for_mkfs(char *file, int force_overwrite);
int get_label_mounted(const char *mount_path, char *labelp);
+int get_label_unmounted(const char *dev, char *label);
int test_num_disk_vs_raid(u64 metadata_profile, u64 data_profile,
u64 dev_cnt, int mixed);
int group_profile_max_safe_loss(u64 flags);
--
2.4.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/2] btrfs-progs: optimize not to scan repeated fsid mount points
2015-09-15 8:46 [PATCH 1/2] btrfs-progs: provide fail safe for BTRFS_IOC_GET_FSLABEL ioctl Anand Jain
@ 2015-09-15 8:46 ` Anand Jain
2015-09-25 13:57 ` David Sterba
2015-09-25 13:55 ` [PATCH 1/2] btrfs-progs: provide fail safe for BTRFS_IOC_GET_FSLABEL ioctl David Sterba
1 sibling, 1 reply; 4+ messages in thread
From: Anand Jain @ 2015-09-15 8:46 UTC (permalink / raw)
To: linux-btrfs
fsid can be mounted multiple times, with different subvolid.
And we don't have to scan a mount point if we already have
that in the scanned list.
And thus nicely avoids the following warning with multiple
subvol mounts on older kernel like 2.6.32 where
BTRFS_IOC_GET_FSLABEL ioctl does not exist.
./btrfs fi show -m
Label: none uuid: 31845933-611e-422d-ae6f-386e57ad81aa
Total devices 2 FS bytes used 172.00KiB
devid 1 size 3.00GiB used 642.38MiB path /dev/sdd
devid 2 size 3.00GiB used 622.38MiB path /dev/sde
warning, device 2 is missing
warning devid 2 not found already
warning, device 2 is missing
warning devid 2 not found already
Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
cmds-filesystem.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/cmds-filesystem.c b/cmds-filesystem.c
index 793df0e..e2049cc 100644
--- a/cmds-filesystem.c
+++ b/cmds-filesystem.c
@@ -468,6 +468,10 @@ static int btrfs_scan_kernel(void *search, unsigned unit_mode)
goto out;
}
+ /* skip all fs already shown as mounted fs */
+ if (is_seen_fsid(fs_info_arg.fsid))
+ continue;
+
ret = get_label_mounted(mnt->mnt_dir, label);
/* provide backward kernel compatibility */
if (ret == -ENOTTY)
--
2.4.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 1/2] btrfs-progs: provide fail safe for BTRFS_IOC_GET_FSLABEL ioctl
2015-09-15 8:46 [PATCH 1/2] btrfs-progs: provide fail safe for BTRFS_IOC_GET_FSLABEL ioctl Anand Jain
2015-09-15 8:46 ` [PATCH 2/2] btrfs-progs: optimize not to scan repeated fsid mount points Anand Jain
@ 2015-09-25 13:55 ` David Sterba
1 sibling, 0 replies; 4+ messages in thread
From: David Sterba @ 2015-09-25 13:55 UTC (permalink / raw)
To: Anand Jain; +Cc: linux-btrfs
On Tue, Sep 15, 2015 at 04:46:22PM +0800, Anand Jain wrote:
> Old kernel like 2.6.32 does not provide ioctl BTRFS_IOC_GET_FSLABEL.
> So we need to provide a fail safe logic for btrfs-progs running
> on those kernel.
>
> In this patch when get_label_mounted() fails on the old kernel
> it will fail back to the old method and uses get_label_unmounted(),
> where it will read from the disk directly.
>
> Signed-off-by: Anand Jain <anand.jain@oracle.com>
Applied, thanks. I've changed the reference to 3.9 where the label ioctl
has been introduced.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 2/2] btrfs-progs: optimize not to scan repeated fsid mount points
2015-09-15 8:46 ` [PATCH 2/2] btrfs-progs: optimize not to scan repeated fsid mount points Anand Jain
@ 2015-09-25 13:57 ` David Sterba
0 siblings, 0 replies; 4+ messages in thread
From: David Sterba @ 2015-09-25 13:57 UTC (permalink / raw)
To: Anand Jain; +Cc: linux-btrfs
On Tue, Sep 15, 2015 at 04:46:23PM +0800, Anand Jain wrote:
> fsid can be mounted multiple times, with different subvolid.
> And we don't have to scan a mount point if we already have
> that in the scanned list.
>
> And thus nicely avoids the following warning with multiple
> subvol mounts on older kernel like 2.6.32 where
> BTRFS_IOC_GET_FSLABEL ioctl does not exist.
>
> ./btrfs fi show -m
> Label: none uuid: 31845933-611e-422d-ae6f-386e57ad81aa
> Total devices 2 FS bytes used 172.00KiB
> devid 1 size 3.00GiB used 642.38MiB path /dev/sdd
> devid 2 size 3.00GiB used 622.38MiB path /dev/sde
>
> warning, device 2 is missing
> warning devid 2 not found already
> warning, device 2 is missing
> warning devid 2 not found already
>
> Signed-off-by: Anand Jain <anand.jain@oracle.com>
Applied, thanks.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2015-09-25 13:58 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-09-15 8:46 [PATCH 1/2] btrfs-progs: provide fail safe for BTRFS_IOC_GET_FSLABEL ioctl Anand Jain
2015-09-15 8:46 ` [PATCH 2/2] btrfs-progs: optimize not to scan repeated fsid mount points Anand Jain
2015-09-25 13:57 ` David Sterba
2015-09-25 13:55 ` [PATCH 1/2] btrfs-progs: provide fail safe for BTRFS_IOC_GET_FSLABEL ioctl David Sterba
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).