[PATCH v2 2/2] Add btrfs fs_info checksum, generation and metadata

Sahil Kang sahil.kang at asilaycomputing.com
Wed Dec 29 09:48:47 UTC 2021


* src/xlat/btrfs_csum_types.in: New file.
* src/xlat/btrfs_fs_info_flags.in: Likewise.
* src/btrfs.c: Print csum_type, csum_size, flags, generation, and
metadata_uuid fields of btrfs_ioctl_fs_info_args struct.
* NEWS: Mention it.

Signed-off-by: Sahil Kang <sahil.kang at asilaycomputing.com>
---
 src/btrfs.c                     |  20 ++++++
 src/xlat/btrfs_csum_types.in    |   6 ++
 src/xlat/btrfs_fs_info_flags.in |   4 ++
 tests/btrfs.c                   | 113 ++++++++++++++++++++++++++++++++
 4 files changed, 143 insertions(+)
 create mode 100644 src/xlat/btrfs_csum_types.in
 create mode 100644 src/xlat/btrfs_fs_info_flags.in

diff --git a/src/btrfs.c b/src/btrfs.c
index ab7e0d3c4..349fee657 100644
--- a/src/btrfs.c
+++ b/src/btrfs.c
@@ -37,6 +37,7 @@ typedef struct btrfs_ioctl_vol_args_v2
 #include "xlat/btrfs_balance_state.h"
 #include "xlat/btrfs_compress_types.h"
 #include "xlat/btrfs_cont_reading_from_srcdev_mode.h"
+#include "xlat/btrfs_csum_types.h"
 #include "xlat/btrfs_defrag_flags.h"
 #include "xlat/btrfs_dev_replace_cmds.h"
 #include "xlat/btrfs_dev_replace_results.h"
@@ -46,6 +47,7 @@ typedef struct btrfs_ioctl_vol_args_v2
 #include "xlat/btrfs_features_compat.h"
 #include "xlat/btrfs_features_compat_ro.h"
 #include "xlat/btrfs_features_incompat.h"
+#include "xlat/btrfs_fs_info_flags.h"
 #include "xlat/btrfs_key_types.h"
 #include "xlat/btrfs_logical_ino_args_flags.h"
 #include "xlat/btrfs_qgroup_ctl_cmds.h"
@@ -790,6 +792,24 @@ MPERS_PRINTER_DECL(int, btrfs_ioctl,
 		PRINT_FIELD_U(args, sectorsize);
 		tprint_struct_next();
 		PRINT_FIELD_U(args, clone_alignment);
+		if (args.flags & BTRFS_FS_INFO_FLAG_CSUM_INFO) {
+			tprint_struct_next();
+			PRINT_FIELD_XVAL(args, csum_type, btrfs_csum_types,
+					 "BTRFS_CSUM_TYPE_???");
+			tprint_struct_next();
+			PRINT_FIELD_U(args, csum_size);
+		}
+		tprint_struct_next();
+		PRINT_FIELD_FLAGS(args, flags, btrfs_fs_info_flags,
+				  "BTRFS_FS_INFO_FLAG_???");
+		if (args.flags & BTRFS_FS_INFO_FLAG_GENERATION) {
+			tprint_struct_next();
+			PRINT_FIELD_U(args, generation);
+		}
+		if (args.flags & BTRFS_FS_INFO_FLAG_METADATA_UUID) {
+			tprint_struct_next();
+			PRINT_FIELD_UUID(args, metadata_uuid);
+		}
 		tprint_struct_end();
 		break;
 	}
diff --git a/src/xlat/btrfs_csum_types.in b/src/xlat/btrfs_csum_types.in
new file mode 100644
index 000000000..db94b545f
--- /dev/null
+++ b/src/xlat/btrfs_csum_types.in
@@ -0,0 +1,6 @@
+#value_indexed
+#enum
+BTRFS_CSUM_TYPE_CRC32	0
+BTRFS_CSUM_TYPE_XXHASH	1
+BTRFS_CSUM_TYPE_SHA256	2
+BTRFS_CSUM_TYPE_BLAKE2	3
diff --git a/src/xlat/btrfs_fs_info_flags.in b/src/xlat/btrfs_fs_info_flags.in
new file mode 100644
index 000000000..b1cb4eb89
--- /dev/null
+++ b/src/xlat/btrfs_fs_info_flags.in
@@ -0,0 +1,4 @@
+#unconditional
+BTRFS_FS_INFO_FLAG_CSUM_INFO
+BTRFS_FS_INFO_FLAG_GENERATION
+BTRFS_FS_INFO_FLAG_METADATA_UUID
diff --git a/tests/btrfs.c b/tests/btrfs.c
index 4686854db..a3564898f 100644
--- a/tests/btrfs.c
+++ b/tests/btrfs.c
@@ -33,6 +33,7 @@
 #include "xlat/btrfs_balance_state.h"
 #include "xlat/btrfs_compress_types.h"
 #include "xlat/btrfs_cont_reading_from_srcdev_mode.h"
+#include "xlat/btrfs_csum_types.h"
 #include "xlat/btrfs_defrag_flags.h"
 #include "xlat/btrfs_dev_stats_values.h"
 #include "xlat/btrfs_dev_stats_flags.h"
@@ -46,6 +47,7 @@
 #include "xlat/btrfs_features_compat.h"
 #include "xlat/btrfs_features_compat_ro.h"
 #include "xlat/btrfs_features_incompat.h"
+#include "xlat/btrfs_fs_info_flags.h"
 #include "xlat/btrfs_key_types.h"
 
 #include <linux/fiemap.h>
@@ -150,6 +152,41 @@ print_uint64(const char *prefix, uint64_t val)
 	}
 }
 
+static const char * const hex_chars = "0123456789abcdef";
+
+static void
+print_hex(uint8_t byte)
+{
+	printf("%c%c", hex_chars[byte >> 4], hex_chars[byte & 0xf]);
+}
+
+static void
+print_uuid(const char * const prefix, const uint8_t * const uuid)
+{
+	size_t i = 0;
+
+	printf("%s", prefix);
+
+	for (; i < 4; i++)
+		print_hex(uuid[i]);
+	printf("-");
+
+	for (; i < 6; i++)
+		print_hex(uuid[i]);
+	printf("-");
+
+	for (; i < 8; i++)
+		print_hex(uuid[i]);
+	printf("-");
+
+	for (; i < 10; i++)
+		print_hex(uuid[i]);
+	printf("-");
+
+	for (; i < 16; i++)
+		print_hex(uuid[i]);
+}
+
 /* takes highest valid flag bit */
 static uint64_t
 max_flags_plus_one(int bit)
@@ -1952,6 +1989,81 @@ btrfs_test_read_ioctls(void)
 	}
 }
 
+static void
+btrfs_print_fs_info_args(const struct btrfs_ioctl_fs_info_args * const args)
+{
+	print_uint64("{max_id=", args->max_id);
+	print_uint64(", num_devices=", args->num_devices);
+	print_uuid(", fsid=", args->fsid);
+	printf(", nodesize=%" PRIu32, args->nodesize);
+	printf(", sectorsize=%" PRIu32, args->sectorsize);
+	printf(", clone_alignment=%" PRIu32, args->clone_alignment);
+
+	if (args->flags & BTRFS_FS_INFO_FLAG_CSUM_INFO) {
+		printf(", csum_type=");
+		prxval_btrfs(btrfs_csum_types, args->csum_type,
+			     "BTRFS_CSUM_TYPE_???", true);
+		printf(", csum_size=%" PRIu16, args->csum_size);
+	}
+
+	printf(", flags=");
+	prfl_btrfs(btrfs_fs_info_flags, args->flags, "BTRFS_FS_INFO_FLAG_???");
+
+	if (args->flags & BTRFS_FS_INFO_FLAG_GENERATION)
+		print_uint64(", generation=", args->generation);
+
+	if (args->flags & BTRFS_FS_INFO_FLAG_METADATA_UUID)
+		print_uuid(", metadata_uuid=", args->metadata_uuid);
+
+	printf("}");
+}
+
+static void
+btrfs_fs_info_args_subtest(const struct btrfs_ioctl_fs_info_args * const args)
+{
+	ioctl(btrfs_test_dir_fd, BTRFS_IOC_FS_INFO, args);
+	printf("ioctl(%d, %s, ", btrfs_test_dir_fd, ioc(BTRFS_IOC_FS_INFO));
+	btrfs_print_fs_info_args(args);
+	printf(") = 0\n");
+}
+
+static void
+btrfs_test_fs_info_ioctl(void)
+{
+	struct btrfs_ioctl_fs_info_args args;
+
+	if (!write_ok)
+		return;
+
+	btrfs_fs_info_args_subtest(&args);
+
+	args.flags = BTRFS_FS_INFO_FLAG_CSUM_INFO;
+	btrfs_fs_info_args_subtest(&args);
+
+	args.flags = BTRFS_FS_INFO_FLAG_GENERATION;
+	btrfs_fs_info_args_subtest(&args);
+
+	args.flags = BTRFS_FS_INFO_FLAG_METADATA_UUID;
+	btrfs_fs_info_args_subtest(&args);
+
+	args.flags = BTRFS_FS_INFO_FLAG_CSUM_INFO
+		| BTRFS_FS_INFO_FLAG_GENERATION;
+	btrfs_fs_info_args_subtest(&args);
+
+	args.flags = BTRFS_FS_INFO_FLAG_CSUM_INFO
+		| BTRFS_FS_INFO_FLAG_METADATA_UUID;
+	btrfs_fs_info_args_subtest(&args);
+
+	args.flags = BTRFS_FS_INFO_FLAG_GENERATION
+		| BTRFS_FS_INFO_FLAG_METADATA_UUID;
+	btrfs_fs_info_args_subtest(&args);
+
+	args.flags = BTRFS_FS_INFO_FLAG_CSUM_INFO
+		| BTRFS_FS_INFO_FLAG_GENERATION
+		| BTRFS_FS_INFO_FLAG_METADATA_UUID;
+	btrfs_fs_info_args_subtest(&args);
+}
+
 static void
 rm_test_dir(void)
 {
@@ -2058,6 +2170,7 @@ main(int argc, char *argv[])
 	btrfs_test_dev_replace_ioctl();
 	btrfs_test_extent_same_ioctl();
 	btrfs_test_features_ioctls();
+	btrfs_test_fs_info_ioctl();
 
 	puts("+++ exited with 0 +++");
 
-- 
Sahil



More information about the Strace-devel mailing list