linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] btrfs-progs: fi: enable fi usage for filesystem top of seed device
@ 2017-10-23  4:43 Misono, Tomohiro
  2017-10-23  4:44 ` [PATCH 1/2] btrfs-progs: fi: move dev_to_fsid() to cmds-fi-usage for later use Misono, Tomohiro
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Misono, Tomohiro @ 2017-10-23  4:43 UTC (permalink / raw)
  To: linux-btrfs

Currently "fi usage" (and "dev usage") cannot run for the filesystem using
seed device.

This is because FS_INFO ioctl returns the number of devices excluding
seeds, but load_device_info() tries to access valid device from devid 0
to max_id, and results in accessing seeds too (thus causing mismatching
of number of devices).

Since only the size of non-seed devices is matter, fix this by just
skipping seed device by checking device's fsid and comparing it to the fsid
obtained by FS_INFO ioctl.

Tomohiro Misono (2):
 btrfs-progs: fi: move dev_to_fsid() to cmds-fi-usage for later use
 btrfs-progs: fi: enable fi usage for filesystem top of seed device

 cmds-fi-usage.c   | 44 ++++++++++++++++++++++++++++++++++++++++++++
 cmds-fi-usage.h   |  1 +
 cmds-filesystem.c | 27 ---------------------------
 3 files changed, 45 insertions(+), 27 deletions(-)

-- 
2.9.5


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/2] btrfs-progs: fi: move dev_to_fsid() to cmds-fi-usage for later use
  2017-10-23  4:43 [PATCH 0/2] btrfs-progs: fi: enable fi usage for filesystem top of seed device Misono, Tomohiro
@ 2017-10-23  4:44 ` Misono, Tomohiro
  2017-10-24  1:41   ` Anand Jain
  2017-10-23  4:45 ` [PATCH 2/2] btrfs-progs: fi: enable fi usage for filesystem top of seed device Misono, Tomohiro
  2017-10-26 18:36 ` [PATCH 0/2] " David Sterba
  2 siblings, 1 reply; 6+ messages in thread
From: Misono, Tomohiro @ 2017-10-23  4:44 UTC (permalink / raw)
  To: linux-btrfs

Move dev_to_fsid() from cmds-filesystem.c to cmds-fi-usage.c in order to
call it from both "fi show" and "fi usage".

Signed-off-by: Tomohiro Misono <misono.tomohiro@jp.fujitsu.com>
---
 cmds-fi-usage.c   | 29 +++++++++++++++++++++++++++++
 cmds-fi-usage.h   |  1 +
 cmds-filesystem.c | 27 ---------------------------
 3 files changed, 30 insertions(+), 27 deletions(-)

diff --git a/cmds-fi-usage.c b/cmds-fi-usage.c
index 6c846c1..a72fb4e 100644
--- a/cmds-fi-usage.c
+++ b/cmds-fi-usage.c
@@ -22,6 +22,7 @@
 #include <errno.h>
 #include <stdarg.h>
 #include <getopt.h>
+#include <fcntl.h>
 
 #include "utils.h"
 #include "kerncompat.h"
@@ -29,6 +30,7 @@
 #include "string-table.h"
 #include "cmds-fi-usage.h"
 #include "commands.h"
+#include "disk-io.h"
 
 #include "version.h"
 #include "help.h"
@@ -506,6 +508,33 @@ static int cmp_device_info(const void *a, const void *b)
 			((struct device_info *)b)->path);
 }
 
+int dev_to_fsid(const char *dev, __u8 *fsid)
+{
+	struct btrfs_super_block *disk_super;
+	char buf[BTRFS_SUPER_INFO_SIZE];
+	int ret;
+	int fd;
+
+	fd = open(dev, O_RDONLY);
+	if (fd < 0) {
+		ret = -errno;
+		return ret;
+	}
+
+	disk_super = (struct btrfs_super_block *)buf;
+	ret = btrfs_read_dev_super(fd, disk_super,
+				   BTRFS_SUPER_INFO_OFFSET, SBREAD_DEFAULT);
+	if (ret)
+		goto out;
+
+	memcpy(fsid, disk_super->fsid, BTRFS_FSID_SIZE);
+	ret = 0;
+
+out:
+	close(fd);
+	return ret;
+}
+
 /*
  *  This function loads the device_info structure and put them in an array
  */
diff --git a/cmds-fi-usage.h b/cmds-fi-usage.h
index a399517..0e82951 100644
--- a/cmds-fi-usage.h
+++ b/cmds-fi-usage.h
@@ -50,5 +50,6 @@ void print_device_chunks(struct device_info *devinfo,
 		struct chunk_info *chunks_info_ptr,
 		int chunks_info_count, unsigned unit_mode);
 void print_device_sizes(struct device_info *devinfo, unsigned unit_mode);
+int dev_to_fsid(const char *dev, __u8 *fsid);
 
 #endif
diff --git a/cmds-filesystem.c b/cmds-filesystem.c
index c39f2d1..3dc86a2 100644
--- a/cmds-filesystem.c
+++ b/cmds-filesystem.c
@@ -431,33 +431,6 @@ out:
 	return !found;
 }
 
-static int dev_to_fsid(const char *dev, __u8 *fsid)
-{
-	struct btrfs_super_block *disk_super;
-	char buf[BTRFS_SUPER_INFO_SIZE];
-	int ret;
-	int fd;
-
-	fd = open(dev, O_RDONLY);
-	if (fd < 0) {
-		ret = -errno;
-		return ret;
-	}
-
-	disk_super = (struct btrfs_super_block *)buf;
-	ret = btrfs_read_dev_super(fd, disk_super,
-				   BTRFS_SUPER_INFO_OFFSET, SBREAD_DEFAULT);
-	if (ret)
-		goto out;
-
-	memcpy(fsid, disk_super->fsid, BTRFS_FSID_SIZE);
-	ret = 0;
-
-out:
-	close(fd);
-	return ret;
-}
-
 static void free_fs_devices(struct btrfs_fs_devices *fs_devices)
 {
 	struct btrfs_fs_devices *cur_seed, *next_seed;
-- 
2.9.5


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/2] btrfs-progs: fi: enable fi usage for filesystem top of seed device
  2017-10-23  4:43 [PATCH 0/2] btrfs-progs: fi: enable fi usage for filesystem top of seed device Misono, Tomohiro
  2017-10-23  4:44 ` [PATCH 1/2] btrfs-progs: fi: move dev_to_fsid() to cmds-fi-usage for later use Misono, Tomohiro
@ 2017-10-23  4:45 ` Misono, Tomohiro
  2017-10-24  1:48   ` Anand Jain
  2017-10-26 18:36 ` [PATCH 0/2] " David Sterba
  2 siblings, 1 reply; 6+ messages in thread
From: Misono, Tomohiro @ 2017-10-23  4:45 UTC (permalink / raw)
  To: linux-btrfs

Currently "fi usage" (and "dev usage") cannot run for the filesystem using
seed device.

This is because FS_INFO ioctl returns the number of devices excluding
seeds, but load_device_info() tries to access valid device from devid 0
to max_id, and results in accessing seeds too (thus causing mismatching
of number of devices).

Since only the size of non-seed devices is matter, fix this by just
skipping seed device by checking device's fsid and comparing it to the fsid
obtained by FS_INFO ioctl.

Signed-off-by: Tomohiro Misono <misono.tomohiro@jp.fujitsu.com>
---
 cmds-fi-usage.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/cmds-fi-usage.c b/cmds-fi-usage.c
index a72fb4e..50c7e51 100644
--- a/cmds-fi-usage.c
+++ b/cmds-fi-usage.c
@@ -545,6 +545,7 @@ static int load_device_info(int fd, struct device_info **device_info_ptr,
 	struct btrfs_ioctl_fs_info_args fi_args;
 	struct btrfs_ioctl_dev_info_args dev_info;
 	struct device_info *info;
+	__u8 fsid[BTRFS_UUID_SIZE];
 
 	*device_info_count = 0;
 	*device_info_ptr = NULL;
@@ -568,6 +569,7 @@ static int load_device_info(int fd, struct device_info **device_info_ptr,
 		if (ndevs >= fi_args.num_devices) {
 			error("unexpected number of devices: %d >= %llu", ndevs,
 				(unsigned long long)fi_args.num_devices);
+			error("if seed device is used, try run as root.");
 			goto out;
 		}
 		memset(&dev_info, 0, sizeof(dev_info));
@@ -580,6 +582,19 @@ static int load_device_info(int fd, struct device_info **device_info_ptr,
 			goto out;
 		}
 
+		/*
+		 * Skip seed device by cheking device's fsid (require root).
+		 * Ignore EACCES since if seed is not used this function works
+		 * correctly without root privilege.
+		 */
+		ret = dev_to_fsid((const char *)dev_info.path, fsid);
+		if (ret != -EACCES) {
+			if (ret)
+				goto out;
+			if (memcmp(fi_args.fsid, fsid, BTRFS_FSID_SIZE) != 0)
+				continue;
+		}
+
 		info[ndevs].devid = dev_info.devid;
 		if (!dev_info.path[0]) {
 			strcpy(info[ndevs].path, "missing");
-- 
2.9.5


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/2] btrfs-progs: fi: move dev_to_fsid() to cmds-fi-usage for later use
  2017-10-23  4:44 ` [PATCH 1/2] btrfs-progs: fi: move dev_to_fsid() to cmds-fi-usage for later use Misono, Tomohiro
@ 2017-10-24  1:41   ` Anand Jain
  0 siblings, 0 replies; 6+ messages in thread
From: Anand Jain @ 2017-10-24  1:41 UTC (permalink / raw)
  To: Misono, Tomohiro, linux-btrfs



On 10/23/2017 12:44 PM, Misono, Tomohiro wrote:
> Move dev_to_fsid() from cmds-filesystem.c to cmds-fi-usage.c in order to
> call it from both "fi show" and "fi usage".
> 
> Signed-off-by: Tomohiro Misono <misono.tomohiro@jp.fujitsu.com>

Reviewed-by: Anand Jain <anand.jain@oracle.com>

Thanks, Anand

> ---
>   cmds-fi-usage.c   | 29 +++++++++++++++++++++++++++++
>   cmds-fi-usage.h   |  1 +
>   cmds-filesystem.c | 27 ---------------------------
>   3 files changed, 30 insertions(+), 27 deletions(-)
> 
> diff --git a/cmds-fi-usage.c b/cmds-fi-usage.c
> index 6c846c1..a72fb4e 100644
> --- a/cmds-fi-usage.c
> +++ b/cmds-fi-usage.c
> @@ -22,6 +22,7 @@
>   #include <errno.h>
>   #include <stdarg.h>
>   #include <getopt.h>
> +#include <fcntl.h>
>   
>   #include "utils.h"
>   #include "kerncompat.h"
> @@ -29,6 +30,7 @@
>   #include "string-table.h"
>   #include "cmds-fi-usage.h"
>   #include "commands.h"
> +#include "disk-io.h"
>   
>   #include "version.h"
>   #include "help.h"
> @@ -506,6 +508,33 @@ static int cmp_device_info(const void *a, const void *b)
>   			((struct device_info *)b)->path);
>   }
>   
> +int dev_to_fsid(const char *dev, __u8 *fsid)
> +{
> +	struct btrfs_super_block *disk_super;
> +	char buf[BTRFS_SUPER_INFO_SIZE];
> +	int ret;
> +	int fd;
> +
> +	fd = open(dev, O_RDONLY);
> +	if (fd < 0) {
> +		ret = -errno;
> +		return ret;
> +	}
> +
> +	disk_super = (struct btrfs_super_block *)buf;
> +	ret = btrfs_read_dev_super(fd, disk_super,
> +				   BTRFS_SUPER_INFO_OFFSET, SBREAD_DEFAULT);
> +	if (ret)
> +		goto out;
> +
> +	memcpy(fsid, disk_super->fsid, BTRFS_FSID_SIZE);
> +	ret = 0;
> +
> +out:
> +	close(fd);
> +	return ret;
> +}
> +
>   /*
>    *  This function loads the device_info structure and put them in an array
>    */
> diff --git a/cmds-fi-usage.h b/cmds-fi-usage.h
> index a399517..0e82951 100644
> --- a/cmds-fi-usage.h
> +++ b/cmds-fi-usage.h
> @@ -50,5 +50,6 @@ void print_device_chunks(struct device_info *devinfo,
>   		struct chunk_info *chunks_info_ptr,
>   		int chunks_info_count, unsigned unit_mode);
>   void print_device_sizes(struct device_info *devinfo, unsigned unit_mode);
> +int dev_to_fsid(const char *dev, __u8 *fsid);
>   
>   #endif
> diff --git a/cmds-filesystem.c b/cmds-filesystem.c
> index c39f2d1..3dc86a2 100644
> --- a/cmds-filesystem.c
> +++ b/cmds-filesystem.c
> @@ -431,33 +431,6 @@ out:
>   	return !found;
>   }
>   
> -static int dev_to_fsid(const char *dev, __u8 *fsid)
> -{
> -	struct btrfs_super_block *disk_super;
> -	char buf[BTRFS_SUPER_INFO_SIZE];
> -	int ret;
> -	int fd;
> -
> -	fd = open(dev, O_RDONLY);
> -	if (fd < 0) {
> -		ret = -errno;
> -		return ret;
> -	}
> -
> -	disk_super = (struct btrfs_super_block *)buf;
> -	ret = btrfs_read_dev_super(fd, disk_super,
> -				   BTRFS_SUPER_INFO_OFFSET, SBREAD_DEFAULT);
> -	if (ret)
> -		goto out;
> -
> -	memcpy(fsid, disk_super->fsid, BTRFS_FSID_SIZE);
> -	ret = 0;
> -
> -out:
> -	close(fd);
> -	return ret;
> -}
> -
>   static void free_fs_devices(struct btrfs_fs_devices *fs_devices)
>   {
>   	struct btrfs_fs_devices *cur_seed, *next_seed;
> 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/2] btrfs-progs: fi: enable fi usage for filesystem top of seed device
  2017-10-23  4:45 ` [PATCH 2/2] btrfs-progs: fi: enable fi usage for filesystem top of seed device Misono, Tomohiro
@ 2017-10-24  1:48   ` Anand Jain
  0 siblings, 0 replies; 6+ messages in thread
From: Anand Jain @ 2017-10-24  1:48 UTC (permalink / raw)
  To: Misono, Tomohiro, linux-btrfs



On 10/23/2017 12:45 PM, Misono, Tomohiro wrote:
> Currently "fi usage" (and "dev usage") cannot run for the filesystem using
> seed device.
> 
> This is because FS_INFO ioctl returns the number of devices excluding
> seeds, but load_device_info() tries to access valid device from devid 0
> to max_id, and results in accessing seeds too (thus causing mismatching
> of number of devices).

  A long time back I tried to fix this by fixing the FS_INFO num_devs
  itself, but the concern was backward compatibility of the ioctl.
  However there is no such a concern here. I am ok with this approach.

> Since only the size of non-seed devices is matter, fix this by just
> skipping seed device by checking device's fsid and comparing it to the fsid
> obtained by FS_INFO ioctl.
> 
> Signed-off-by: Tomohiro Misono <misono.tomohiro@jp.fujitsu.com>

Reviewed-by: Anand Jain <anand.jain@oracle.com>

Thanks, Anand


> ---
>   cmds-fi-usage.c | 15 +++++++++++++++
>   1 file changed, 15 insertions(+)
> 
> diff --git a/cmds-fi-usage.c b/cmds-fi-usage.c
> index a72fb4e..50c7e51 100644
> --- a/cmds-fi-usage.c
> +++ b/cmds-fi-usage.c
> @@ -545,6 +545,7 @@ static int load_device_info(int fd, struct device_info **device_info_ptr,
>   	struct btrfs_ioctl_fs_info_args fi_args;
>   	struct btrfs_ioctl_dev_info_args dev_info;
>   	struct device_info *info;
> +	__u8 fsid[BTRFS_UUID_SIZE];
>   
>   	*device_info_count = 0;
>   	*device_info_ptr = NULL;
> @@ -568,6 +569,7 @@ static int load_device_info(int fd, struct device_info **device_info_ptr,
>   		if (ndevs >= fi_args.num_devices) {
>   			error("unexpected number of devices: %d >= %llu", ndevs,
>   				(unsigned long long)fi_args.num_devices);
> +			error("if seed device is used, try run as root.");
>   			goto out;
>   		}
>   		memset(&dev_info, 0, sizeof(dev_info));
> @@ -580,6 +582,19 @@ static int load_device_info(int fd, struct device_info **device_info_ptr,
>   			goto out;
>   		}
>   
> +		/*
> +		 * Skip seed device by cheking device's fsid (require root).
> +		 * Ignore EACCES since if seed is not used this function works
> +		 * correctly without root privilege.
> +		 */
> +		ret = dev_to_fsid((const char *)dev_info.path, fsid);
> +		if (ret != -EACCES) {
> +			if (ret)
> +				goto out;
> +			if (memcmp(fi_args.fsid, fsid, BTRFS_FSID_SIZE) != 0)
> +				continue;
> +		}
> +
>   		info[ndevs].devid = dev_info.devid;
>   		if (!dev_info.path[0]) {
>   			strcpy(info[ndevs].path, "missing");
> 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 0/2] btrfs-progs: fi: enable fi usage for filesystem top of seed device
  2017-10-23  4:43 [PATCH 0/2] btrfs-progs: fi: enable fi usage for filesystem top of seed device Misono, Tomohiro
  2017-10-23  4:44 ` [PATCH 1/2] btrfs-progs: fi: move dev_to_fsid() to cmds-fi-usage for later use Misono, Tomohiro
  2017-10-23  4:45 ` [PATCH 2/2] btrfs-progs: fi: enable fi usage for filesystem top of seed device Misono, Tomohiro
@ 2017-10-26 18:36 ` David Sterba
  2 siblings, 0 replies; 6+ messages in thread
From: David Sterba @ 2017-10-26 18:36 UTC (permalink / raw)
  To: Misono, Tomohiro; +Cc: linux-btrfs

On Mon, Oct 23, 2017 at 01:43:23PM +0900, Misono, Tomohiro wrote:
> Currently "fi usage" (and "dev usage") cannot run for the filesystem using
> seed device.
> 
> This is because FS_INFO ioctl returns the number of devices excluding
> seeds, but load_device_info() tries to access valid device from devid 0
> to max_id, and results in accessing seeds too (thus causing mismatching
> of number of devices).
> 
> Since only the size of non-seed devices is matter, fix this by just
> skipping seed device by checking device's fsid and comparing it to the fsid
> obtained by FS_INFO ioctl.
> 
> Tomohiro Misono (2):
>  btrfs-progs: fi: move dev_to_fsid() to cmds-fi-usage for later use
>  btrfs-progs: fi: enable fi usage for filesystem top of seed device

Applied, thanks.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2017-10-26 18:38 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-10-23  4:43 [PATCH 0/2] btrfs-progs: fi: enable fi usage for filesystem top of seed device Misono, Tomohiro
2017-10-23  4:44 ` [PATCH 1/2] btrfs-progs: fi: move dev_to_fsid() to cmds-fi-usage for later use Misono, Tomohiro
2017-10-24  1:41   ` Anand Jain
2017-10-23  4:45 ` [PATCH 2/2] btrfs-progs: fi: enable fi usage for filesystem top of seed device Misono, Tomohiro
2017-10-24  1:48   ` Anand Jain
2017-10-26 18:36 ` [PATCH 0/2] " 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).