All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH RFC 0/2] btrfs-progs: boilerplate code for printing devices.
@ 2023-07-03  7:55 Anand Jain
  2023-07-03  7:55 ` [PATCH RFC 1/2] btrfs-progs: print device list volumes-c api Anand Jain
  2023-07-03  7:55 ` [PATCH RFC 2/2] btrfs-progs: print device list Anand Jain
  0 siblings, 2 replies; 3+ messages in thread
From: Anand Jain @ 2023-07-03  7:55 UTC (permalink / raw)
  To: linux-btrfs

This is a set of boilerplate code to print the whole list of devices
wherever in the code, for example:

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

	btrfs_print_devlist(NULL);

This code has been helping me to debug and fix certain bugs for some time.

The code is a port from its kernel version and has been roughly optimized
but not cleaned. However, I am sending it out to see if it can be integrated.
Otherwise, I am fine with maintaining it externally and keeping it updated
when needed. Thx.


Anand Jain (2):
  btrfs-progs: print device list volumes-c api
  btrfs-progs: print device list

 kernel-shared/print-tree.c | 71 ++++++++++++++++++++++++++++++++++++++
 kernel-shared/print-tree.h |  1 +
 kernel-shared/volumes.c    |  5 +++
 kernel-shared/volumes.h    |  2 +-
 4 files changed, 78 insertions(+), 1 deletion(-)

-- 
2.31.1


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

* [PATCH RFC 1/2] btrfs-progs: print device list volumes-c api
  2023-07-03  7:55 [PATCH RFC 0/2] btrfs-progs: boilerplate code for printing devices Anand Jain
@ 2023-07-03  7:55 ` Anand Jain
  2023-07-03  7:55 ` [PATCH RFC 2/2] btrfs-progs: print device list Anand Jain
  1 sibling, 0 replies; 3+ messages in thread
From: Anand Jain @ 2023-07-03  7:55 UTC (permalink / raw)
  To: linux-btrfs

We need fs_uuid to print the device list. Export it.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 kernel-shared/volumes.c | 5 +++++
 kernel-shared/volumes.h | 2 +-
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/kernel-shared/volumes.c b/kernel-shared/volumes.c
index 92282524867d..c6c71fd29215 100644
--- a/kernel-shared/volumes.c
+++ b/kernel-shared/volumes.c
@@ -2939,3 +2939,8 @@ int btrfs_fix_device_and_super_size(struct btrfs_fs_info *fs_info)
 	}
 	return ret;
 }
+
+struct list_head * btrfs_get_fs_uuids(void)
+{
+	return &fs_uuids;
+}
diff --git a/kernel-shared/volumes.h b/kernel-shared/volumes.h
index ab5ac40269bb..2022ce37cf09 100644
--- a/kernel-shared/volumes.h
+++ b/kernel-shared/volumes.h
@@ -312,5 +312,5 @@ int btrfs_bg_type_to_nparity(u64 flags);
 int btrfs_bg_type_to_sub_stripes(u64 flags);
 u64 btrfs_bg_flags_for_device_num(int number);
 bool btrfs_bg_type_is_stripey(u64 flags);
-
+struct list_head * btrfs_get_fs_uuids(void);
 #endif
-- 
2.31.1


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

* [PATCH RFC 2/2] btrfs-progs: print device list
  2023-07-03  7:55 [PATCH RFC 0/2] btrfs-progs: boilerplate code for printing devices Anand Jain
  2023-07-03  7:55 ` [PATCH RFC 1/2] btrfs-progs: print device list volumes-c api Anand Jain
@ 2023-07-03  7:55 ` Anand Jain
  1 sibling, 0 replies; 3+ messages in thread
From: Anand Jain @ 2023-07-03  7:55 UTC (permalink / raw)
  To: linux-btrfs

Provides the boilerplate code to print the device list.

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

diff --git a/kernel-shared/print-tree.c b/kernel-shared/print-tree.c
index 0f7f7b72f96a..b3699e70b979 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"
@@ -2108,3 +2109,73 @@ void btrfs_print_superblock(struct btrfs_super_block *sb, int full)
 		print_backup_roots(sb);
 	}
 }
+
+#define BPSL    256
+
+#define BTRFS_SEQ_PRINT(plist, arg) \
+	do { \
+		snprintf(str, BPSL, plist, arg); \
+		printf("%s", str); \
+	} while (0)
+
+static void print_a_device(struct btrfs_device *device)
+{
+	char str[BPSL];
+	char uuidstr[BTRFS_UUID_UNPARSED_SIZE];
+
+	uuid_unparse(device->uuid, uuidstr);
+	BTRFS_SEQ_PRINT("\t[[UUID: %s]]\n", uuidstr);
+	BTRFS_SEQ_PRINT("\t\tdev_addr:\t%p\n", device);
+	BTRFS_SEQ_PRINT("\t\tdevice:\t\t%s\n", device->name);
+	BTRFS_SEQ_PRINT("\t\tdevid:\t\t%llu\n", device->devid);
+	BTRFS_SEQ_PRINT("\t\tgeneration:\t%llu\n", device->generation);
+	BTRFS_SEQ_PRINT("\t\ttotal_bytes:\t%llu\n", device->total_bytes);
+	BTRFS_SEQ_PRINT("\t\tbytes_used:\t%llu\n", device->bytes_used);
+	BTRFS_SEQ_PRINT("\t\ttype:\t\t%llu\n", device->type);
+	BTRFS_SEQ_PRINT("\t\tio_align:\t%u\n", device->io_align);
+	BTRFS_SEQ_PRINT("\t\tio_width:\t%u\n", device->io_width);
+	BTRFS_SEQ_PRINT("\t\tsector_size:\t%u\n", device->sector_size);
+}
+
+static void print_a_fs_device(struct btrfs_fs_devices *fs_devices)
+{
+	char str[BPSL];
+	char uuidstr[BTRFS_UUID_UNPARSED_SIZE];
+	struct btrfs_device *device = NULL;
+	size_t sz = sizeof(*fs_devices);
+
+	uuid_unparse(fs_devices->fsid, uuidstr);
+	BTRFS_SEQ_PRINT("[fsid: %s]\n", uuidstr);
+
+	BTRFS_SEQ_PRINT("\tsize:\t\t\t%ld\n", sz);
+
+	uuid_unparse(fs_devices->metadata_uuid, uuidstr);
+	BTRFS_SEQ_PRINT("\tmetadata_uuid:\t\t%s\n", uuidstr);
+
+	BTRFS_SEQ_PRINT("\tfs_devs_addr:\t\t%p\n", fs_devices);
+	BTRFS_SEQ_PRINT("\ttotal_rw_bytes:\t\t%llu\n", fs_devices->total_rw_bytes);
+
+	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_get_fs_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, 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 80fb6ef75ff5..826e9281ef6f 100644
--- a/kernel-shared/print-tree.h
+++ b/kernel-shared/print-tree.h
@@ -42,5 +42,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
-- 
2.31.1


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

end of thread, other threads:[~2023-07-03  7:56 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-03  7:55 [PATCH RFC 0/2] btrfs-progs: boilerplate code for printing devices Anand Jain
2023-07-03  7:55 ` [PATCH RFC 1/2] btrfs-progs: print device list volumes-c api Anand Jain
2023-07-03  7:55 ` [PATCH RFC 2/2] btrfs-progs: print device list Anand Jain

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.