linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] btrfs: fix wrong pad for kernelspace arg of btrfs dev stat
@ 2014-10-16  1:53 Gui Hecheng
  2014-10-16  1:53 ` [PATCH] btrfs-progs: fix wrong pad for userspace " Gui Hecheng
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Gui Hecheng @ 2014-10-16  1:53 UTC (permalink / raw)
  To: linux-btrfs; +Cc: Gui Hecheng

The @btrfs_ioctl_get_dev_stats fails to pad to 1k as descripted,
actually it valuates to 1032 bytes.
The corresponding userspace change follows this change.

Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com>
---
 include/uapi/linux/btrfs.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/uapi/linux/btrfs.h b/include/uapi/linux/btrfs.h
index 2f47824..fc4e326 100644
--- a/include/uapi/linux/btrfs.h
+++ b/include/uapi/linux/btrfs.h
@@ -416,7 +416,7 @@ struct btrfs_ioctl_get_dev_stats {
 	/* out values: */
 	__u64 values[BTRFS_DEV_STAT_VALUES_MAX];
 
-	__u64 unused[128 - 2 - BTRFS_DEV_STAT_VALUES_MAX]; /* pad to 1k */
+	__u64 unused[128 - 3 - BTRFS_DEV_STAT_VALUES_MAX]; /* pad to 1k */
 };
 
 #define BTRFS_QUOTA_CTL_ENABLE	1
-- 
1.8.1.4


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

* [PATCH] btrfs-progs: fix wrong pad for userspace arg of btrfs dev stat
  2014-10-16  1:53 [PATCH] btrfs: fix wrong pad for kernelspace arg of btrfs dev stat Gui Hecheng
@ 2014-10-16  1:53 ` Gui Hecheng
  2014-10-16  1:53 ` [PATCH] btrfs-progs: prevent silent damage when add dev to an invalid mntpnt Gui Hecheng
  2014-10-16  9:26 ` [PATCH] btrfs: fix wrong pad for kernelspace arg of btrfs dev stat Stefan Behrens
  2 siblings, 0 replies; 5+ messages in thread
From: Gui Hecheng @ 2014-10-16  1:53 UTC (permalink / raw)
  To: linux-btrfs; +Cc: Gui Hecheng

The @btrfs_ioctl_get_dev_stats fails to pad to 1k as descripted,
actually it valuates to 1032 bytes.
Correct it following the kernel patch.

Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com>
---
 ioctl.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/ioctl.h b/ioctl.h
index f0fc060..6657f8f 100644
--- a/ioctl.h
+++ b/ioctl.h
@@ -429,7 +429,7 @@ struct btrfs_ioctl_get_dev_stats {
 	/* out values: */
 	__u64 values[BTRFS_DEV_STAT_VALUES_MAX];
 
-	__u64 unused[128 - 2 - BTRFS_DEV_STAT_VALUES_MAX]; /* pad to 1k */
+	__u64 unused[128 - 3 - BTRFS_DEV_STAT_VALUES_MAX]; /* pad to 1k */
 };
 
 /* BTRFS_IOC_SNAP_CREATE is no longer used by the btrfs command */
-- 
1.8.1.4


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

* [PATCH] btrfs-progs: prevent silent damage when add dev to an invalid mntpnt
  2014-10-16  1:53 [PATCH] btrfs: fix wrong pad for kernelspace arg of btrfs dev stat Gui Hecheng
  2014-10-16  1:53 ` [PATCH] btrfs-progs: fix wrong pad for userspace " Gui Hecheng
@ 2014-10-16  1:53 ` Gui Hecheng
  2014-10-16  9:26 ` [PATCH] btrfs: fix wrong pad for kernelspace arg of btrfs dev stat Stefan Behrens
  2 siblings, 0 replies; 5+ messages in thread
From: Gui Hecheng @ 2014-10-16  1:53 UTC (permalink / raw)
  To: linux-btrfs; +Cc: Gui Hecheng

Problem:
	# mkfs.btrfs -f /dev/sda1
	# btrfs dev add /dev/sda1 /dir -f   <== dir is not a mntpnt

btrfs dev add just report invalid ioctl but it has already made
changes to /dev/sda1 with @btrfs_prepare_device(), so the fs on
/dev/sda1 is damaged.

We could check whether /dev/sda1 is a valid mntpnt by calling
@find_mount_root() to prevent this silent damage.

Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com>
---
 cmds-device.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/cmds-device.c b/cmds-device.c
index a728f21..65815c3 100644
--- a/cmds-device.c
+++ b/cmds-device.c
@@ -53,6 +53,7 @@ static int cmd_add_dev(int argc, char **argv)
 	int discard = 1;
 	int force = 0;
 	char estr[100];
+	char rmntpnt[PATH_MAX];
 
 	while (1) {
 		int long_index;
@@ -84,6 +85,22 @@ static int cmd_add_dev(int argc, char **argv)
 
 	mntpnt = argv[optind + argc - 1];
 
+	if (!realpath(mntpnt, rmntpnt)) {
+		fprintf(stderr, "ERROR: %s\n", strerror(errno));
+		return 1;
+	}
+
+	ret = find_mount_root(rmntpnt, &mntpnt);
+	if (ret < 0) {
+		fprintf(stderr, "ERROR: find_mount_root failed on '%s': %s\n",
+				rmntpnt, strerror(-ret));
+		return 1;
+	} else if (ret > 0) {
+		fprintf(stderr, "ERROR: '%s' doesn't belong to btrfs mount point\n",
+			rmntpnt);
+		return 1;
+	}
+
 	fdmnt = open_file_or_dir(mntpnt, &dirstream);
 	if (fdmnt < 0) {
 		fprintf(stderr, "ERROR: can't access '%s'\n", mntpnt);
-- 
1.8.1.4


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

* Re: [PATCH] btrfs: fix wrong pad for kernelspace arg of btrfs dev stat
  2014-10-16  1:53 [PATCH] btrfs: fix wrong pad for kernelspace arg of btrfs dev stat Gui Hecheng
  2014-10-16  1:53 ` [PATCH] btrfs-progs: fix wrong pad for userspace " Gui Hecheng
  2014-10-16  1:53 ` [PATCH] btrfs-progs: prevent silent damage when add dev to an invalid mntpnt Gui Hecheng
@ 2014-10-16  9:26 ` Stefan Behrens
  2014-10-16  9:41   ` Gui Hecheng
  2 siblings, 1 reply; 5+ messages in thread
From: Stefan Behrens @ 2014-10-16  9:26 UTC (permalink / raw)
  To: Gui Hecheng, linux-btrfs

On Thu, 16 Oct 2014 09:53:37 +0800, Gui Hecheng wrote:
> The @btrfs_ioctl_get_dev_stats fails to pad to 1k as descripted,
> actually it valuates to 1032 bytes.
> The corresponding userspace change follows this change.
> 
> Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com>
> ---
>  include/uapi/linux/btrfs.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/include/uapi/linux/btrfs.h b/include/uapi/linux/btrfs.h
> index 2f47824..fc4e326 100644
> --- a/include/uapi/linux/btrfs.h
> +++ b/include/uapi/linux/btrfs.h
> @@ -416,7 +416,7 @@ struct btrfs_ioctl_get_dev_stats {
>  	/* out values: */
>  	__u64 values[BTRFS_DEV_STAT_VALUES_MAX];
>  
> -	__u64 unused[128 - 2 - BTRFS_DEV_STAT_VALUES_MAX]; /* pad to 1k */
> +	__u64 unused[128 - 3 - BTRFS_DEV_STAT_VALUES_MAX]; /* pad to 1k */

You can't change an existing ioctl interface like this and make it
incompatible, the length of the structure is used in _IOWR(). Just
change the comment from "pad to 1k" to "pad to 1032 bytes" instead.


>  };
>  
>  #define BTRFS_QUOTA_CTL_ENABLE	1
> 



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

* Re: [PATCH] btrfs: fix wrong pad for kernelspace arg of btrfs dev stat
  2014-10-16  9:26 ` [PATCH] btrfs: fix wrong pad for kernelspace arg of btrfs dev stat Stefan Behrens
@ 2014-10-16  9:41   ` Gui Hecheng
  0 siblings, 0 replies; 5+ messages in thread
From: Gui Hecheng @ 2014-10-16  9:41 UTC (permalink / raw)
  To: Stefan Behrens; +Cc: linux-btrfs

On Thu, 2014-10-16 at 11:26 +0200, Stefan Behrens wrote:
> On Thu, 16 Oct 2014 09:53:37 +0800, Gui Hecheng wrote:
> > The @btrfs_ioctl_get_dev_stats fails to pad to 1k as descripted,
> > actually it valuates to 1032 bytes.
> > The corresponding userspace change follows this change.
> > 
> > Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com>
> > ---
> >  include/uapi/linux/btrfs.h | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/include/uapi/linux/btrfs.h b/include/uapi/linux/btrfs.h
> > index 2f47824..fc4e326 100644
> > --- a/include/uapi/linux/btrfs.h
> > +++ b/include/uapi/linux/btrfs.h
> > @@ -416,7 +416,7 @@ struct btrfs_ioctl_get_dev_stats {
> >  	/* out values: */
> >  	__u64 values[BTRFS_DEV_STAT_VALUES_MAX];
> >  
> > -	__u64 unused[128 - 2 - BTRFS_DEV_STAT_VALUES_MAX]; /* pad to 1k */
> > +	__u64 unused[128 - 3 - BTRFS_DEV_STAT_VALUES_MAX]; /* pad to 1k */
> 
> You can't change an existing ioctl interface like this and make it
> incompatible, the length of the structure is used in _IOWR(). Just
> change the comment from "pad to 1k" to "pad to 1032 bytes" instead.

Er... yeah, the problem exists, and such a fix seems cost much.
Since the related tool itself doesn't influence much, just scratch these
two may be a reasonable idea. ^_^

("pad to 1032 bytes" seems a bit...) 

> 
> >  };
> >  
> >  #define BTRFS_QUOTA_CTL_ENABLE	1
> > 
> 
> 



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

end of thread, other threads:[~2014-10-16  9:42 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-10-16  1:53 [PATCH] btrfs: fix wrong pad for kernelspace arg of btrfs dev stat Gui Hecheng
2014-10-16  1:53 ` [PATCH] btrfs-progs: fix wrong pad for userspace " Gui Hecheng
2014-10-16  1:53 ` [PATCH] btrfs-progs: prevent silent damage when add dev to an invalid mntpnt Gui Hecheng
2014-10-16  9:26 ` [PATCH] btrfs: fix wrong pad for kernelspace arg of btrfs dev stat Stefan Behrens
2014-10-16  9:41   ` Gui Hecheng

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).