All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/4] Btrfs-progs 4.8, fix build on 32bit, ioctl cleanups
@ 2016-10-06 13:41 David Sterba
  2016-10-06 13:41 ` [PATCH 1/4] btrfs-progs: ioctl: pack structures David Sterba
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: David Sterba @ 2016-10-06 13:41 UTC (permalink / raw)
  To: linux-btrfs; +Cc: David Sterba

So this series should fix the 32bit build problems, tested on gcc 6.2.1. I've
added test of checking the ioctl numbers: "make test-ioctl" that will build
32bit and 64bit versions (needs compiler for both).

The ioctl compatibility reasoning is in the changelogs. The goal is to keep
everything working (send, receive), so there's no visible change, but more
testing would be welcome of course.

The patchset is now in devel, on top of 4.8.

David Sterba (4):
  btrfs-progs: ioctl: pack structures
  btrfs-progs: ioctl: add 32bit compat for SET_RECEIVED_SUBVOL
  btrfs-progs: ioctl: add 64bit compat for SEND
  btrfs-progs: tests: make the ioctl-test actually useful

 Makefile.in  |  27 +++++-
 ioctl-test.c | 266 +++++++++++++++++++++++++++++++++++++++++++++++++++++------
 ioctl.h      |  79 ++++++++++++++++--
 3 files changed, 335 insertions(+), 37 deletions(-)

-- 
2.10.0


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

* [PATCH 1/4] btrfs-progs: ioctl: pack structures
  2016-10-06 13:41 [PATCH 0/4] Btrfs-progs 4.8, fix build on 32bit, ioctl cleanups David Sterba
@ 2016-10-06 13:41 ` David Sterba
  2016-10-06 13:41 ` [PATCH 2/4] btrfs-progs: ioctl: add 32bit compat for SET_RECEIVED_SUBVOL David Sterba
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: David Sterba @ 2016-10-06 13:41 UTC (permalink / raw)
  To: linux-btrfs; +Cc: David Sterba

Add the packed attribute to several structures so we avoid any
accidental size changes due to compiler-dependent padding.

Expected alignment is 8 bytes, padded where needed.

Signed-off-by: David Sterba <dsterba@suse.com>
---
 ioctl.h | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/ioctl.h b/ioctl.h
index a7235c00c1a0..d0c06657f0c0 100644
--- a/ioctl.h
+++ b/ioctl.h
@@ -149,7 +149,7 @@ struct btrfs_ioctl_scrub_args {
 	struct btrfs_scrub_progress progress;	/* out */
 	/* pad to 1k */
 	__u64 unused[(1024-32-sizeof(struct btrfs_scrub_progress))/8];
-};
+} __attribute__((packed));
 BUILD_ASSERT(sizeof(struct btrfs_ioctl_scrub_args) == 1024);
 
 #define BTRFS_IOCTL_DEV_REPLACE_CONT_READING_FROM_SRCDEV_MODE_ALWAYS	0
@@ -160,7 +160,7 @@ struct btrfs_ioctl_dev_replace_start_params {
 						 * above */
 	__u8 srcdev_name[BTRFS_DEVICE_PATH_NAME_MAX + 1];	/* in */
 	__u8 tgtdev_name[BTRFS_DEVICE_PATH_NAME_MAX + 1];	/* in */
-};
+} __attribute__((packed, aligned (8)));
 BUILD_ASSERT(sizeof(struct btrfs_ioctl_dev_replace_start_params) == 2072);
 
 #define BTRFS_IOCTL_DEV_REPLACE_STATE_NEVER_STARTED	0
@@ -175,7 +175,7 @@ struct btrfs_ioctl_dev_replace_status_params {
 	__u64 time_stopped;	/* out, seconds since 1-Jan-1970 */
 	__u64 num_write_errors;	/* out */
 	__u64 num_uncorrectable_read_errors;	/* out */
-};
+} __attribute__((packed));
 BUILD_ASSERT(sizeof(struct btrfs_ioctl_dev_replace_status_params) == 48);
 
 #define BTRFS_IOCTL_DEV_REPLACE_CMD_START			0
@@ -556,7 +556,7 @@ BUILD_ASSERT(sizeof(struct btrfs_ioctl_qgroup_create_args) == 16);
 struct btrfs_ioctl_timespec {
 	__u64 sec;
 	__u32 nsec;
-};
+} __attribute__((packed, aligned (8)));
 
 struct btrfs_ioctl_received_subvol_args {
 	char	uuid[BTRFS_UUID_SIZE];	/* in */
@@ -601,7 +601,7 @@ struct btrfs_ioctl_send_args {
 	__u64 parent_root;		/* in */
 	__u64 flags;			/* in */
 	__u64 reserved[4];		/* in */
-};
+} __attribute__((packed));
 /*
  * Size of structure depends on pointer width, was not caught.  Kernel handles
  * pointer width differences transparently
-- 
2.10.0


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

* [PATCH 2/4] btrfs-progs: ioctl: add 32bit compat for SET_RECEIVED_SUBVOL
  2016-10-06 13:41 [PATCH 0/4] Btrfs-progs 4.8, fix build on 32bit, ioctl cleanups David Sterba
  2016-10-06 13:41 ` [PATCH 1/4] btrfs-progs: ioctl: pack structures David Sterba
@ 2016-10-06 13:41 ` David Sterba
  2016-10-06 13:41 ` [PATCH 3/4] btrfs-progs: ioctl: add 64bit compat for SEND David Sterba
  2016-10-06 13:41 ` [PATCH 4/4] btrfs-progs: tests: make the ioctl-test actually useful David Sterba
  3 siblings, 0 replies; 5+ messages in thread
From: David Sterba @ 2016-10-06 13:41 UTC (permalink / raw)
  To: linux-btrfs; +Cc: David Sterba

The ioctl value of SET_RECEIVED_SUBVOL will be different on 32bit
userspace and 64bit kernel. This is transparently handled on the kernel
side. We now define the same structure so we can verify the ioctl value.

The defined structure and ioctl should not be used. It is exists only
for testing purposes, documenting the mess and as a warning for the
future.

Signed-off-by: David Sterba <dsterba@suse.com>
---
 ioctl.h | 38 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)

diff --git a/ioctl.h b/ioctl.h
index d0c06657f0c0..6baa51ab1724 100644
--- a/ioctl.h
+++ b/ioctl.h
@@ -570,6 +570,38 @@ struct btrfs_ioctl_received_subvol_args {
 BUILD_ASSERT(sizeof(struct btrfs_ioctl_received_subvol_args) == 200);
 
 /*
+ * If we have a 32-bit userspace and 64-bit kernel, then the UAPI
+ * structures are incorrect, as the timespec structure from userspace
+ * is 4 bytes too small. We define these alternatives here for backward
+ * compatibility, the kernel understands both values.
+ */
+
+/*
+ * Structure size is different on 32bit and 64bit, has some padding if the
+ * structure is embedded. Packing makes sure the size is same on both, but will
+ * be misaligned on 64bit.
+ *
+ * NOTE: do not use in your code, this is for testing only
+ */
+struct btrfs_ioctl_timespec_32 {
+	__u64 sec;
+	__u32 nsec;
+} __attribute__ ((__packed__));
+
+struct btrfs_ioctl_received_subvol_args_32 {
+	char	uuid[BTRFS_UUID_SIZE];	/* in */
+	__u64	stransid;		/* in */
+	__u64	rtransid;		/* out */
+	struct btrfs_ioctl_timespec_32 stime; /* in */
+	struct btrfs_ioctl_timespec_32 rtime; /* out */
+	__u64	flags;			/* in */
+	__u64	reserved[16];		/* in */
+} __attribute__ ((__packed__));
+BUILD_ASSERT(sizeof(struct btrfs_ioctl_received_subvol_args_32) == 192);
+
+#define BTRFS_IOC_SET_RECEIVED_SUBVOL_32_COMPAT_DEFINED 1
+
+/*
  * Caller doesn't want file data in the send stream, even if the
  * search of clone sources doesn't find an extent. UPDATE_EXTENT
  * commands will be sent instead of WRITE commands.
@@ -723,6 +755,12 @@ static inline char *btrfs_err_str(enum btrfs_err_code err_code)
 					struct btrfs_ioctl_logical_ino_args)
 #define BTRFS_IOC_SET_RECEIVED_SUBVOL _IOWR(BTRFS_IOCTL_MAGIC, 37, \
 				struct btrfs_ioctl_received_subvol_args)
+
+#ifdef BTRFS_IOC_SET_RECEIVED_SUBVOL_32_COMPAT_DEFINED
+#define BTRFS_IOC_SET_RECEIVED_SUBVOL_32 _IOWR(BTRFS_IOCTL_MAGIC, 37, \
+				struct btrfs_ioctl_received_subvol_args_32)
+#endif
+
 #define BTRFS_IOC_SEND _IOW(BTRFS_IOCTL_MAGIC, 38, struct btrfs_ioctl_send_args)
 #define BTRFS_IOC_DEVICES_READY _IOR(BTRFS_IOCTL_MAGIC, 39, \
 				     struct btrfs_ioctl_vol_args)
-- 
2.10.0


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

* [PATCH 3/4] btrfs-progs: ioctl: add 64bit compat for SEND
  2016-10-06 13:41 [PATCH 0/4] Btrfs-progs 4.8, fix build on 32bit, ioctl cleanups David Sterba
  2016-10-06 13:41 ` [PATCH 1/4] btrfs-progs: ioctl: pack structures David Sterba
  2016-10-06 13:41 ` [PATCH 2/4] btrfs-progs: ioctl: add 32bit compat for SET_RECEIVED_SUBVOL David Sterba
@ 2016-10-06 13:41 ` David Sterba
  2016-10-06 13:41 ` [PATCH 4/4] btrfs-progs: tests: make the ioctl-test actually useful David Sterba
  3 siblings, 0 replies; 5+ messages in thread
From: David Sterba @ 2016-10-06 13:41 UTC (permalink / raw)
  To: linux-btrfs; +Cc: David Sterba

The ioctl value of SEND will be different on 32bit userspace and 64bit
kernel due to different pointer type width, that unfortunatelly made it
into the structure definition.

To maintain backward compatibility, we must do it in the 64bit->32bit
way, because we don't have the kernel side workardound like
SET_RECEIVED_SUBVOL has.  Changing value of SEND would then break
existing users of the raw ioctl.

The compatibility structure and ioctl should not be used, exists for
documentation, and testing.

Signed-off-by: David Sterba <dsterba@suse.com>
---
 ioctl.h | 31 +++++++++++++++++++++++++++++--
 1 file changed, 29 insertions(+), 2 deletions(-)

diff --git a/ioctl.h b/ioctl.h
index 6baa51ab1724..f7233da90637 100644
--- a/ioctl.h
+++ b/ioctl.h
@@ -635,8 +635,8 @@ struct btrfs_ioctl_send_args {
 	__u64 reserved[4];		/* in */
 } __attribute__((packed));
 /*
- * Size of structure depends on pointer width, was not caught.  Kernel handles
- * pointer width differences transparently
+ * Size of structure depends on pointer width, was not caught in the early
+ * days.  Kernel handles pointer width differences transparently.
  */
 BUILD_ASSERT(sizeof(__u64 *) == 8
 	     ? sizeof(struct btrfs_ioctl_send_args) == 72
@@ -644,6 +644,28 @@ BUILD_ASSERT(sizeof(__u64 *) == 8
 		? sizeof(struct btrfs_ioctl_send_args) == 68
 		: 0));
 
+/*
+ * Different pointer width leads to structure size change. Kernel should accept
+ * both ioctl values (derived from the structures) for backward compatibility.
+ * Size of this structure is same on 32bit and 64bit though.
+ *
+ * NOTE: do not use in your code, this is for testing only
+ */
+struct btrfs_ioctl_send_args_64 {
+	__s64 send_fd;			/* in */
+	__u64 clone_sources_count;	/* in */
+	union {
+		__u64 __user *clone_sources;	/* in */
+		__u64 __clone_sources_alignment;
+	};
+	__u64 parent_root;		/* in */
+	__u64 flags;			/* in */
+	__u64 reserved[4];		/* in */
+} __attribute__((packed));
+BUILD_ASSERT(sizeof(struct btrfs_ioctl_send_args_64) == 72);
+
+#define BTRFS_IOC_SEND_64_COMPAT_DEFINED 1
+
 /* Error codes as returned by the kernel */
 enum btrfs_err_code {
 	notused,
@@ -761,6 +783,11 @@ static inline char *btrfs_err_str(enum btrfs_err_code err_code)
 				struct btrfs_ioctl_received_subvol_args_32)
 #endif
 
+#ifdef BTRFS_IOC_SEND_64_COMPAT_DEFINED
+#define BTRFS_IOC_SEND_64 _IOW(BTRFS_IOCTL_MAGIC, 38, \
+		struct btrfs_ioctl_send_args_64)
+#endif
+
 #define BTRFS_IOC_SEND _IOW(BTRFS_IOCTL_MAGIC, 38, struct btrfs_ioctl_send_args)
 #define BTRFS_IOC_DEVICES_READY _IOR(BTRFS_IOCTL_MAGIC, 39, \
 				     struct btrfs_ioctl_vol_args)
-- 
2.10.0


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

* [PATCH 4/4] btrfs-progs: tests: make the ioctl-test actually useful
  2016-10-06 13:41 [PATCH 0/4] Btrfs-progs 4.8, fix build on 32bit, ioctl cleanups David Sterba
                   ` (2 preceding siblings ...)
  2016-10-06 13:41 ` [PATCH 3/4] btrfs-progs: ioctl: add 64bit compat for SEND David Sterba
@ 2016-10-06 13:41 ` David Sterba
  3 siblings, 0 replies; 5+ messages in thread
From: David Sterba @ 2016-10-06 13:41 UTC (permalink / raw)
  To: linux-btrfs; +Cc: David Sterba

Enhance the test to verify ioctl uniqueness, compare the defined values
against the hardcoded expected values, and take care of the 32bit/64bit
compatibility workarounds.

Signed-off-by: David Sterba <dsterba@suse.com>
---
 Makefile.in  |  27 +++++-
 ioctl-test.c | 266 +++++++++++++++++++++++++++++++++++++++++++++++++++++------
 2 files changed, 263 insertions(+), 30 deletions(-)

diff --git a/Makefile.in b/Makefile.in
index 983b8b9a6193..48ff54ca60f2 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -387,9 +387,30 @@ quick-test: $(objects) $(libs) quick-test.o
 	@echo "    [LD]     $@"
 	$(Q)$(CC) $(CFLAGS) -o quick-test $(objects) $(libs) quick-test.o $(LDFLAGS) $(LIBS)
 
-ioctl-test: $(objects) $(libs) ioctl-test.o
-	@echo "    [LD]     $@"
-	$(Q)$(CC) $(CFLAGS) -o ioctl-test $(objects) $(libs) ioctl-test.o $(LDFLAGS) $(LIBS)
+ioctl-test-64.o: ioctl-test.c ioctl.h kerncompat.h ctree.h
+	@echo "    [CC64]   $@"
+	$(Q)$(CC) $(CFLAGS) -m64 -c $< -o $@
+
+ioctl-test-32.o: ioctl-test.c ioctl.h kerncompat.h ctree.h
+	@echo "    [CC32]   $@"
+	$(Q)$(CC) $(CFLAGS) -m32 -c $< -o $@
+
+ioctl-test-32: ioctl-test-32.o
+	@echo "    [LD32]   $@"
+	$(Q)$(CC) $(CFLAGS) -m32 -o $@ $< $(LDFLAGS)
+	@echo "   ?[PAHOLE] $@"
+	-$(Q)pahole $@ > $@.pahole
+
+ioctl-test-64: ioctl-test-64.o
+	@echo "    [LD64]   $@"
+	$(Q)$(CC) $(CFLAGS) -m64 -o $@ $< $(LDFLAGS)
+	@echo "   ?[PAHOLE] $@"
+	-$(Q)pahole $@ > $@.pahole
+
+test-ioctl: ioctl-test-32 ioctl-test-64
+	@echo "    [TEST/ioctl]"
+	@$(Q)./ioctl-test-32 > ioctl-test-32.log
+	@$(Q)./ioctl-test-64 > ioctl-test-64.log
 
 send-test: $(objects) $(libs) send-test.o
 	@echo "    [LD]     $@"
diff --git a/ioctl-test.c b/ioctl-test.c
index 54fc013584e3..26b3c68df606 100644
--- a/ioctl-test.c
+++ b/ioctl-test.c
@@ -1,37 +1,249 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License v2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 021110-1307, USA.
+ */
+
+#include "kerncompat.h"
 #include <stdio.h>
 #include <stdlib.h>
-#include "kerncompat.h"
+
 #include "ioctl.h"
+#include "ctree.h"
+
+#define LIST_32_COMPAT				\
+	ONE(BTRFS_IOC_SET_RECEIVED_SUBVOL_32)
+
+#define LIST_64_COMPAT				\
+	ONE(BTRFS_IOC_SEND_64)
+
+#define LIST_BASE				\
+	ONE(BTRFS_IOC_SNAP_CREATE)		\
+	ONE(BTRFS_IOC_DEFRAG)			\
+	ONE(BTRFS_IOC_RESIZE)			\
+	ONE(BTRFS_IOC_SCAN_DEV)			\
+	ONE(BTRFS_IOC_TRANS_START)		\
+	ONE(BTRFS_IOC_TRANS_END)		\
+	ONE(BTRFS_IOC_SYNC)			\
+	ONE(BTRFS_IOC_CLONE)			\
+	ONE(BTRFS_IOC_ADD_DEV)			\
+	ONE(BTRFS_IOC_RM_DEV)			\
+	ONE(BTRFS_IOC_BALANCE)			\
+	ONE(BTRFS_IOC_CLONE_RANGE)		\
+	ONE(BTRFS_IOC_SUBVOL_CREATE)		\
+	ONE(BTRFS_IOC_SNAP_DESTROY)		\
+	ONE(BTRFS_IOC_DEFRAG_RANGE)		\
+	ONE(BTRFS_IOC_TREE_SEARCH)		\
+	ONE(BTRFS_IOC_TREE_SEARCH_V2)		\
+	ONE(BTRFS_IOC_INO_LOOKUP)		\
+	ONE(BTRFS_IOC_DEFAULT_SUBVOL)		\
+	ONE(BTRFS_IOC_SPACE_INFO)		\
+	ONE(BTRFS_IOC_START_SYNC)		\
+	ONE(BTRFS_IOC_WAIT_SYNC)		\
+	ONE(BTRFS_IOC_SNAP_CREATE_V2)		\
+	ONE(BTRFS_IOC_SUBVOL_CREATE_V2)		\
+	ONE(BTRFS_IOC_SUBVOL_GETFLAGS)		\
+	ONE(BTRFS_IOC_SUBVOL_SETFLAGS)		\
+	ONE(BTRFS_IOC_SCRUB)			\
+	ONE(BTRFS_IOC_SCRUB_CANCEL)		\
+	ONE(BTRFS_IOC_SCRUB_PROGRESS)		\
+	ONE(BTRFS_IOC_DEV_INFO)			\
+	ONE(BTRFS_IOC_FS_INFO)			\
+	ONE(BTRFS_IOC_BALANCE_V2)		\
+	ONE(BTRFS_IOC_BALANCE_CTL)		\
+	ONE(BTRFS_IOC_BALANCE_PROGRESS)		\
+	ONE(BTRFS_IOC_INO_PATHS)		\
+	ONE(BTRFS_IOC_LOGICAL_INO)		\
+	ONE(BTRFS_IOC_SET_RECEIVED_SUBVOL)	\
+	ONE(BTRFS_IOC_SEND)			\
+	ONE(BTRFS_IOC_DEVICES_READY)		\
+	ONE(BTRFS_IOC_QUOTA_CTL)		\
+	ONE(BTRFS_IOC_QGROUP_ASSIGN)		\
+	ONE(BTRFS_IOC_QGROUP_CREATE)		\
+	ONE(BTRFS_IOC_QGROUP_LIMIT)		\
+	ONE(BTRFS_IOC_QUOTA_RESCAN)		\
+	ONE(BTRFS_IOC_QUOTA_RESCAN_STATUS)	\
+	ONE(BTRFS_IOC_QUOTA_RESCAN_WAIT)	\
+	ONE(BTRFS_IOC_GET_FSLABEL)		\
+	ONE(BTRFS_IOC_SET_FSLABEL)		\
+	ONE(BTRFS_IOC_GET_DEV_STATS)		\
+	ONE(BTRFS_IOC_DEV_REPLACE)		\
+	ONE(BTRFS_IOC_FILE_EXTENT_SAME)		\
+	ONE(BTRFS_IOC_GET_FEATURES)		\
+	ONE(BTRFS_IOC_SET_FEATURES)		\
+	ONE(BTRFS_IOC_GET_SUPPORTED_FEATURES)	\
+	ONE(BTRFS_IOC_RM_DEV_V2)
 
-static unsigned long ioctls[] = {
-	BTRFS_IOC_SNAP_CREATE,
-	BTRFS_IOC_DEFRAG,
-	BTRFS_IOC_RESIZE,
-	BTRFS_IOC_SCAN_DEV,
-	BTRFS_IOC_TRANS_START,
-	BTRFS_IOC_TRANS_END,
-	BTRFS_IOC_SYNC,
-	BTRFS_IOC_CLONE,
-	BTRFS_IOC_ADD_DEV,
-	BTRFS_IOC_RM_DEV,
-	BTRFS_IOC_BALANCE,
-	BTRFS_IOC_SUBVOL_CREATE,
-	BTRFS_IOC_SNAP_DESTROY,
-	BTRFS_IOC_DEFRAG_RANGE,
-	BTRFS_IOC_TREE_SEARCH,
-	BTRFS_IOC_INO_LOOKUP,
-	BTRFS_IOC_DEFAULT_SUBVOL,
-	BTRFS_IOC_SPACE_INFO,
-	BTRFS_IOC_SNAP_CREATE_V2,
-	0 };
+#define LIST					\
+	LIST_BASE				\
+	LIST_32_COMPAT				\
+	LIST_64_COMPAT
+
+struct ioctl_number {
+	unsigned long defined;
+	unsigned long expected;
+};
+
+static struct ioctl_number expected_list[] = {
+	{ BTRFS_IOC_SNAP_CREATE,                    0x0050009401 },
+	{ BTRFS_IOC_DEFRAG,                         0x0050009402 },
+	{ BTRFS_IOC_RESIZE,                         0x0050009403 },
+	{ BTRFS_IOC_SCAN_DEV,                       0x0050009404 },
+	{ BTRFS_IOC_TRANS_START,                    0x0000009406 },
+	{ BTRFS_IOC_TRANS_END,                      0x0000009407 },
+	{ BTRFS_IOC_SYNC,                           0x0000009408 },
+	{ BTRFS_IOC_CLONE,                          0x0040049409 },
+	{ BTRFS_IOC_ADD_DEV,                        0x005000940a },
+	{ BTRFS_IOC_RM_DEV,                         0x005000940b },
+	{ BTRFS_IOC_BALANCE,                        0x005000940c },
+	{ BTRFS_IOC_CLONE_RANGE,                    0x004020940d },
+	{ BTRFS_IOC_SUBVOL_CREATE,                  0x005000940e },
+	{ BTRFS_IOC_SNAP_DESTROY,                   0x005000940f },
+	{ BTRFS_IOC_DEFRAG_RANGE,                   0x0040309410 },
+	{ BTRFS_IOC_TREE_SEARCH,                    0x00d0009411 },
+	{ BTRFS_IOC_TREE_SEARCH_V2,                 0x00c0709411 },
+	{ BTRFS_IOC_INO_LOOKUP,                     0x00d0009412 },
+	{ BTRFS_IOC_DEFAULT_SUBVOL,                 0x0040089413 },
+	{ BTRFS_IOC_SPACE_INFO,                     0x00c0109414 },
+	{ BTRFS_IOC_START_SYNC,                     0x0080089418 },
+	{ BTRFS_IOC_WAIT_SYNC,                      0x0040089416 },
+	{ BTRFS_IOC_SNAP_CREATE_V2,                 0x0050009417 },
+	{ BTRFS_IOC_SUBVOL_CREATE_V2,               0x0050009418 },
+	{ BTRFS_IOC_SUBVOL_GETFLAGS,                0x0080089419 },
+	{ BTRFS_IOC_SUBVOL_SETFLAGS,                0x004008941a },
+	{ BTRFS_IOC_SCRUB,                          0x00c400941b },
+	{ BTRFS_IOC_SCRUB_CANCEL,                   0x000000941c },
+	{ BTRFS_IOC_SCRUB_PROGRESS,                 0x00c400941d },
+	{ BTRFS_IOC_DEV_INFO,                       0x00d000941e },
+	{ BTRFS_IOC_FS_INFO,                        0x008400941f },
+	{ BTRFS_IOC_BALANCE_V2,                     0x00c4009420 },
+	{ BTRFS_IOC_BALANCE_CTL,                    0x0040049421 },
+	{ BTRFS_IOC_BALANCE_PROGRESS,               0x0084009422 },
+	{ BTRFS_IOC_INO_PATHS,                      0x00c0389423 },
+	{ BTRFS_IOC_LOGICAL_INO,                    0x00c0389424 },
+	{ BTRFS_IOC_SET_RECEIVED_SUBVOL,            0x00c0c89425 },
+#ifdef BTRFS_IOC_SET_RECEIVED_SUBVOL_32_COMPAT_DEFINED
+	{ BTRFS_IOC_SET_RECEIVED_SUBVOL_32,         0x00c0c09425 },
+#endif
+#if BITS_PER_LONG == 32
+	{ BTRFS_IOC_SEND,                           0x0040449426 },
+#elif BITS_PER_LONG == 64
+	{ BTRFS_IOC_SEND,                           0x0040489426 },
+#endif
+#ifdef BTRFS_IOC_SEND_64_COMPAT_DEFINED
+	{ BTRFS_IOC_SEND_64,                        0x0040489426 },
+#endif
+	{ BTRFS_IOC_DEVICES_READY,                  0x0090009427 },
+	{ BTRFS_IOC_QUOTA_CTL,                      0x00c0109428 },
+	{ BTRFS_IOC_QGROUP_ASSIGN,                  0x0040189429 },
+	{ BTRFS_IOC_QGROUP_CREATE,                  0x004010942a },
+	{ BTRFS_IOC_QGROUP_LIMIT,                   0x008030942b },
+	{ BTRFS_IOC_QUOTA_RESCAN,                   0x004040942c },
+	{ BTRFS_IOC_QUOTA_RESCAN_STATUS,            0x008040942d },
+	{ BTRFS_IOC_QUOTA_RESCAN_WAIT,              0x000000942e },
+	{ BTRFS_IOC_GET_FSLABEL,                    0x0081009431 },
+	{ BTRFS_IOC_SET_FSLABEL,                    0x0041009432 },
+	{ BTRFS_IOC_GET_DEV_STATS,                  0x00c4089434 },
+	{ BTRFS_IOC_DEV_REPLACE,                    0x00ca289435 },
+	{ BTRFS_IOC_FILE_EXTENT_SAME,               0x00c0189436 },
+	{ BTRFS_IOC_GET_FEATURES,                   0x0080189439 },
+	{ BTRFS_IOC_SET_FEATURES,                   0x0040309439 },
+	{ BTRFS_IOC_GET_SUPPORTED_FEATURES,         0x0080489439 },
+	{ BTRFS_IOC_RM_DEV_V2,                      0x005000943a },
+};
+
+static struct btrfs_ioctl_vol_args used_vol_args __attribute__((used));
+static struct btrfs_ioctl_vol_args_v2 used_vol_args2 __attribute__((used));
+static struct btrfs_ioctl_clone_range_args used_clone_args __attribute__((used));
+static struct btrfs_ioctl_defrag_range_args used_defrag_args __attribute__((used));
+static struct btrfs_ioctl_search_args used_search_args __attribute__((used));
+static struct btrfs_ioctl_search_args_v2 used_search_args2 __attribute__((used));
+static struct btrfs_ioctl_ino_lookup_args used_ino_lookup __attribute__((used));
+static struct btrfs_ioctl_space_args used_space_args __attribute__((used));
+static struct btrfs_ioctl_scrub_args used_scrub_args __attribute__((used));
+static struct btrfs_ioctl_dev_info_args used_dev_info_args __attribute__((used));
+static struct btrfs_ioctl_fs_info_args used_fs_info_args __attribute__((used));
+static struct btrfs_ioctl_balance_args used_balance_args __attribute__((used));
+static struct btrfs_ioctl_ino_path_args used_path_args __attribute__((used));
+static struct btrfs_ioctl_logical_ino_args used_logical_args __attribute__((used));
+static struct btrfs_ioctl_received_subvol_args used_received_args __attribute__((used));
+#ifdef BTRFS_IOC_SET_RECEIVED_SUBVOL_32_COMPAT_DEFINED
+static struct btrfs_ioctl_received_subvol_args_32 used_received_args32 __attribute__((used));
+#endif
+static struct btrfs_ioctl_send_args used_send_args __attribute__((used));
+#ifdef BTRFS_IOC_SEND_64_COMPAT_DEFINED
+static struct btrfs_ioctl_send_args_64 used_send_args64 __attribute__((used));
+#endif
+static struct btrfs_ioctl_quota_ctl_args used_qgctl_args __attribute__((used));
+static struct btrfs_ioctl_qgroup_assign_args used_qgassign_args __attribute__((used));
+static struct btrfs_ioctl_qgroup_create_args used_qgcreate_args __attribute__((used));
+static struct btrfs_ioctl_qgroup_limit_args used_qglimit_args __attribute__((used));
+static struct btrfs_ioctl_quota_rescan_args used_qgrescan_args __attribute__((used));
+static struct btrfs_ioctl_get_dev_stats used_dev_stats_args __attribute__((used));
+static struct btrfs_ioctl_dev_replace_args used_replace_args __attribute__((used));
+static struct btrfs_ioctl_same_args used_same_args __attribute__((used));
+static struct btrfs_ioctl_feature_flags used_feature_flags __attribute__((used));
+
+const char* value_to_string(unsigned long num)
+{
+#define ONE(x)	case x: return #x;
+	switch (num) {
+	LIST_BASE
+	}
+
+	switch (num) {
+	LIST_32_COMPAT
+	}
+
+	switch (num) {
+	LIST_64_COMPAT
+	}
+#undef ONE
+	return "UNKNOWN";
+}
 
 int main(int ac, char **av)
 {
-	int i = 0;
-	while(ioctls[i]) {
-		printf("%lu\n" ,ioctls[i]);
-		i++;
+	int i;
+	int errors = 0;
+
+	value_to_string(random());
+
+	printf("Sizeof long long:  %zu\n", sizeof(unsigned long long));
+	printf("Sizeof long:       %zu\n", sizeof(unsigned long));
+	printf("Sizeof pointer:    %zu\n", sizeof(void*));
+	printf("Raw ioctl numbers:\n");
+
+#define ONE(n)	printf("%-38s   0x%010lx\n", #n, (unsigned long)n);
+	LIST
+#undef ONE
+
+	for (i = 0; i < ARRAY_SIZE(expected_list); i++) {
+		if (expected_list[i].defined != expected_list[i].expected) {
+			printf("ERROR: wrong value for %s, defined=0x%lx expected=0x%lx\n",
+					value_to_string(expected_list[i].defined),
+					expected_list[i].defined,
+					expected_list[i].expected);
+			errors++;
+		}
 	}
-	return 0;
+
+	if (!errors) {
+		printf("All ok\n");
+	} else {
+		printf("Found %d errors in definitions\n", errors);
+	}
+
+	return !!errors;
 }
 
-- 
2.10.0


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

end of thread, other threads:[~2016-10-06 13:41 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-10-06 13:41 [PATCH 0/4] Btrfs-progs 4.8, fix build on 32bit, ioctl cleanups David Sterba
2016-10-06 13:41 ` [PATCH 1/4] btrfs-progs: ioctl: pack structures David Sterba
2016-10-06 13:41 ` [PATCH 2/4] btrfs-progs: ioctl: add 32bit compat for SET_RECEIVED_SUBVOL David Sterba
2016-10-06 13:41 ` [PATCH 3/4] btrfs-progs: ioctl: add 64bit compat for SEND David Sterba
2016-10-06 13:41 ` [PATCH 4/4] btrfs-progs: tests: make the ioctl-test actually useful David Sterba

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.