diff mbox series

btrfs-progs: print-tree add device list

Message ID 1c088db3e322e8f8d5b332b9f3ab582e06f66387.1693226314.git.anand.jain@oracle.com (mailing list archive)
State New, archived
Headers show
Series btrfs-progs: print-tree add device list | expand

Commit Message

Anand Jain Aug. 28, 2023, 12:41 p.m. UTC
A ready code for printing the device list for debugging purposes. This
helps investigating issues related to the in-memory scanned device list.

Example usecase:

	include "kernel-shared/print-tree.h"

	btrfs_print_devlist(NULL);

[fsid: ef1fdb64-9cf8-48e0-8657-e06ee2b3ac80]
	size:			144
	metadata_uuid:		ef1fdb64-9cf8-48e0-8657-e06ee2b3ac80
	fs_devs_addr:		0x152f2a0
	latest_devid:		1
	latest_generation:	8
	lowest_devid:		1
	num_devices:		2
	missing_devices:	0
	total_rw_bytes:		1048576000
	total_devices:		2
	changing_fsid:		0
	active_metadata_uuid:	0
	[[UUID: ac7dd718-fedd-4640-8b99-12a8cf45ae87]]
		dev_addr:	0x1542470
		device:		/dev/loop1
		devid:		2
		generation:	8
		total_bytes:	524288000
		bytes_used:	60817408
		type:		0
		io_align:	4096
		io_width:	4096
		sector_size:	4096
	[[UUID: 0e4fb27e-3855-48cf-820a-684a37762549]]
		dev_addr:	0x152f340
		device:		/dev/loop0
		devid:		1
		generation:	8
		total_bytes:	524288000
		bytes_used:	69206016
		type:		0
		io_align:	4096
		io_width:	4096
		sector_size:	4096

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 kernel-shared/print-tree.c | 76 ++++++++++++++++++++++++++++++++++++++
 kernel-shared/print-tree.h |  1 +
 2 files changed, 77 insertions(+)
diff mbox series

Patch

diff --git a/kernel-shared/print-tree.c b/kernel-shared/print-tree.c
index b7ca8b7e218d..cf0cd2508d76 100644
--- a/kernel-shared/print-tree.c
+++ b/kernel-shared/print-tree.c
@@ -18,6 +18,7 @@ 
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <sys/types.h>
 #include <uuid/uuid.h>
 #include <ctype.h>
 #include "kerncompat.h"
@@ -2104,3 +2105,78 @@  void btrfs_print_superblock(struct btrfs_super_block *sb, int full)
 		print_backup_roots(sb);
 	}
 }
+
+static void print_a_device(struct btrfs_device *device)
+{
+	char uuidstr[BTRFS_UUID_UNPARSED_SIZE];
+
+	uuid_unparse(device->uuid, uuidstr);
+	printf("\t[[UUID: %s]]\n", uuidstr);
+	printf("\t\tdev_addr:\t%p\n", device);
+	printf("\t\tdevice:\t\t%s\n", device->name);
+	printf("\t\tdevid:\t\t%llu\n", device->devid);
+	printf("\t\tgeneration:\t%llu\n", device->generation);
+	printf("\t\ttotal_bytes:\t%llu\n", device->total_bytes);
+	printf("\t\tbytes_used:\t%llu\n", device->bytes_used);
+	printf("\t\ttype:\t\t%llu\n", device->type);
+	printf("\t\tio_align:\t%u\n", device->io_align);
+	printf("\t\tio_width:\t%u\n", device->io_width);
+	printf("\t\tsector_size:\t%u\n", device->sector_size);
+}
+
+static void print_a_fs_device(struct btrfs_fs_devices *fs_devices)
+{
+	char uuidstr[BTRFS_UUID_UNPARSED_SIZE];
+	struct btrfs_device *device = NULL;
+	size_t sz = sizeof(*fs_devices);
+
+	uuid_unparse(fs_devices->fsid, uuidstr);
+	printf("[fsid: %s]\n", uuidstr);
+
+	printf("\tsize:\t\t\t%ld\n", sz);
+
+	uuid_unparse(fs_devices->metadata_uuid, uuidstr);
+	printf("\tmetadata_uuid:\t\t%s\n", uuidstr);
+
+	printf("\tfs_devs_addr:\t\t%p\n", fs_devices);
+
+	printf("\tlatest_devid:\t\t%llu\n", fs_devices->latest_devid);
+	printf("\tlatest_generation:\t%llu\n", fs_devices->latest_generation);
+	printf("\tlowest_devid:\t\t%llu\n", fs_devices->lowest_devid);
+
+
+	printf("\tnum_devices:\t\t%llu\n", fs_devices->num_devices);
+	printf("\tmissing_devices:\t%llu\n", fs_devices->missing_devices);
+	printf("\ttotal_rw_bytes:\t\t%llu\n", fs_devices->total_rw_bytes);
+
+	printf("\ttotal_devices:\t\t%llu\n", fs_devices->total_devices);
+
+	printf("\tchanging_fsid:\t\t%d\n", fs_devices->changing_fsid);
+	printf("\tactive_metadata_uuid:\t%d\n",
+			fs_devices->active_metadata_uuid);
+
+	list_for_each_entry(device, &fs_devices->devices, dev_list) {
+		print_a_device(device);
+	}
+}
+
+
+void btrfs_print_devlist(struct btrfs_fs_devices *the_fs_devices)
+{
+	struct list_head *fs_uuids = btrfs_scanned_uuids();
+	struct list_head *cur_uuid;
+
+	list_for_each(cur_uuid, fs_uuids) {
+		struct btrfs_fs_devices *fs_devices;
+
+		fs_devices  = list_entry(cur_uuid, struct btrfs_fs_devices,
+					 fs_list);
+		if (the_fs_devices) {
+			if (the_fs_devices == fs_devices)
+				print_a_fs_device(fs_devices);
+		} else {
+			print_a_fs_device(fs_devices);
+		}
+		printf("\n");
+	}
+}
diff --git a/kernel-shared/print-tree.h b/kernel-shared/print-tree.h
index c1e75d1e117f..da17c96426e3 100644
--- a/kernel-shared/print-tree.h
+++ b/kernel-shared/print-tree.h
@@ -47,5 +47,6 @@  void print_extent_item(struct extent_buffer *eb, int slot, int metadata);
 void print_objectid(FILE *stream, u64 objectid, u8 type);
 void print_key_type(FILE *stream, u64 objectid, u8 type);
 void btrfs_print_superblock(struct btrfs_super_block *sb, int full);
+void btrfs_print_devlist(struct btrfs_fs_devices *the_fs_devices);
 
 #endif