Introduce /proc/fs/btrfs/devlist
cover Introduce /proc/fs/btrfs/devlist
An example is easy to understand so is below. Output is in Python config reader module format, just import of this output within a python script is enough.
Useful for
troubleshoot/debug,
storage based on btrfs to render info on their bui/gui and further btrfs-progs could be very sleek if uses this.
[fsid: 763c600a-7af6-4b8a-a421-6611de307dbf]
seed_fsid: e962e198-ef98-4782-ae99-d0128c9f5c37 fs_devs_addr: ffff880046fb4400 num_devices: 1 open_devices: 1 rw_devices: 1 missing_devices: 0 total_rw_devices: 1633799168 total_devices: 3 opened: 1 seeding: 0 rotating: 1 super_kobj_state: 1 super_kobj_insysfs: 1 device_kobj_state: 1 device_kobj_insysfs: 1 [[uuid: 762f7b41-419e-438a-8a58-8a90f6642c18]] dev_addr: ffff880046990000 device: /dev/sdg devid: 3 dev_root_fsid: 763c600a-7af6-4b8a-a421-6611de307dbf generation: 37 total_bytes: 1633799168 dev_totalbytes: 1633799168 bytes_used: 234881024 type: 0 io_align: 4096 io_width: 4096 sector_size: 4096 mode: 0x83 writeable: 1 in_fs_metadata: 1 missing: 0 can_discard: 0 replace_tgtdev: 0 active_pending: 0 nobarriers: 0 devstats_valid: 1 bdev: not_null [[seed_fsid: e962e198-ef98-4782-ae99-d0128c9f5c37]] sprout_fsid: 763c600a-7af6-4b8a-a421-6611de307dbf seed_fsid: 1c52f894-0ead-43d6-847a-d42359f78370 fs_devs_addr: ffff88004586a400 num_devices: 1 open_devices: 1 rw_devices: 0 missing_devices: 0 total_rw_devices: 0 total_devices: 2 opened: 1 seeding: 1 rotating: 1 super_kobj_state: 1 super_kobj_insysfs: 1 device_kobj_state: 1 device_kobj_insysfs: 1 [[uuid: d064a43c-e9ce-42fb-9c01-140d2bdcd528]] dev_addr: ffff880046991400 device: /dev/sdf devid: 2 dev_root_fsid: 763c600a-7af6-4b8a-a421-6611de307dbf generation: 27 total_bytes: 1633799168 dev_totalbytes: 1633799168 bytes_used: 167772160 type: 0 io_align: 4096 io_width: 4096 sector_size: 4096 mode: 0x81 writeable: 0 in_fs_metadata: 1 missing: 0 can_discard: 0 replace_tgtdev: 0 active_pending: 0 nobarriers: 0 devstats_valid: 0 bdev: not_null [[seed_fsid: 1c52f894-0ead-43d6-847a-d42359f78370]] sprout_fsid: e962e198-ef98-4782-ae99-d0128c9f5c37 fs_devs_addr: ffff88004586a000 num_devices: 1 open_devices: 1 rw_devices: 0 missing_devices: 0 total_rw_devices: 0 total_devices: 1 opened: 1 seeding: 1 rotating: 1 super_kobj_state: 1 super_kobj_insysfs: 1 device_kobj_state: 1 device_kobj_insysfs: 1 [[uuid: 4c9b2e81-e4b9-474c-9462-cc2dcd6117d5]] dev_addr: ffff880046990800 device: /dev/sde devid: 1 dev_root_fsid: 763c600a-7af6-4b8a-a421-6611de307dbf generation: 5 total_bytes: 1633796096 dev_totalbytes: 1633796096 bytes_used: 180092928 type: 0 io_align: 4096 io_width: 4096 sector_size: 4096 mode: 0x81 writeable: 0 in_fs_metadata: 1 missing: 0 can_discard: 0 replace_tgtdev: 0 active_pending: 0 nobarriers: 0 devstats_valid: 0 bdev: not_null
V2: Added 3/3 to support for sysfs kobjects that was moved to fs_devices
Anand Jain (3):
Btrfs: procfs-devlist: introduce procfs interface for the device list
Btrfs: procfs-devlist: backport global rcu-string non support
Btsfs: procfs-devlist: update the sysfs contents
fs/btrfs/Makefile | 2 +- fs/btrfs/ctree.h | 4 ++ fs/btrfs/procfs.c | 153 +++++++++++++++++++++++++++++++++++++++++++++++++++++ fs/btrfs/super.c | 4 ++ fs/btrfs/volumes.h | 1 + 5 files changed, 163 insertions(+), 1 deletion(-) create mode 100644 fs/btrfs/procfs.c
Signature · 1 line
2.0.0.153.g79dcccc
PATCH 1/3 Btrfs: procfs-devlist: introduce procfs interface for the device list
From: Anand Jain <[email protected]>
(added RFC prefix to the patch header)
(as of now just an experimental interface)
This patch introduces profs interface /proc/fs/btrfs/devlist, which as of now exports all the members of kernel fs_devices.
The current /sys/fs/btrfs interface works when the fs is mounted, and is on the file directory hierarchy and also has the sysfs limitation max output of U64 per file.
Here btrfs procfs uses seq_file to export all the members of fs_devices. Also shows the contents when device is not mounted, but have registered with btrfs kernel (useful as an alternative to buggy ready ioctl)
An attempt is made to follow the some standard file format output such as ini. So that a simple warper python script will provide end user useful interfaces.
Further planning to add few more members to the interface such as group profile info. The long term idea is to make procfs interface a onestop btrfs application interface for the device and fs info from the kernel, where a simple python script can make use of it.
--- fs/btrfs/Makefile | 2 +- fs/btrfs/ctree.h | 4 ++ fs/btrfs/procfs.c | 142 +++++++++++++++++++++++++++++++++++++++++++++++++++++ fs/btrfs/super.c | 4 ++ fs/btrfs/volumes.h | 1 + 5 files changed, 152 insertions(+), 1 deletion(-) create mode 100644 fs/btrfs/procfs.c
fs/btrfs/Makefile +1 -1
@@ -4,7 +4,7 @@ obj-$(CONFIG_BTRFS_FS) := btrfs.o btrfs-y += super.o ctree.o extent-tree.o print-tree.o root-tree.o dir-item.o \ file-item.o inode-item.o inode-map.o disk-io.o \ transaction.o inode.o file.o tree-defrag.o \ - extent_map.o sysfs.o struct-funcs.o xattr.o ordered-data.o \ + extent_map.o sysfs.o procfs.o struct-funcs.o xattr.o ordered-data.o \ extent_io.o volumes.o async-thread.o ioctl.o locking.o orphan.o \ export.o tree-log.o free-space-cache.o zlib.o lzo.o \ compression.o delayed-ref.o relocation.o delayed-inode.o scrub.o \
fs/btrfs/ctree.h +4 -0
@@ -3986,6 +3986,10 @@ ssize_t btrfs_listxattr(struct dentry *dentry, char *buffer, size_t size);int btrfs_parse_options (struct btrfs_root *root,char *options);int btrfs_sync_fs (struct super_block *sb,int wait); +/* procfs.c */ +void btrfs_exit_procfs (void ); +void btrfs_init_procfs (void ); +#ifdef CONFIG_PRINTK __printf(2, 3)void btrfs_printk (const struct btrfs_fs_info *fs_info,const char *fmt, ...);
fs/btrfs/procfs.c new file +142 -0
142 lines not on this page · raw message
fs/btrfs/super.c +4 -0
@@ -2086,6 +2086,8 @@ static int __init init_btrfs_fs(void)if (err) goto free_hash; +btrfs_init_procfs (); +btrfs_init_compress (); err =btrfs_init_cachep ();
@@ -2164,6 +2166,7 @@ free_cachep:btrfs_destroy_cachep (); free_compress:btrfs_exit_compress (); +btrfs_exit_procfs ();btrfs_exit_sysfs (); free_hash:btrfs_hash_exit ();
@@ -2183,6 +2186,7 @@ static void __exit exit_btrfs_fs(void)btrfs_interface_exit ();btrfs_end_io_wq_exit ();unregister_filesystem (&btrfs_fs_type); +btrfs_exit_procfs ();btrfs_exit_sysfs ();btrfs_cleanup_fs_uuids ();btrfs_exit_compress ();
fs/btrfs/volumes.h +1 -0
@@ -392,6 +392,7 @@ struct btrfs_balance_control {struct btrfs_balance_progress stat; }; +struct list_head *btrfs_get_fs_uuids (void );int btrfs_account_dev_extents_size (struct btrfs_device *device,u64 start,u64 end,u64 *length);
Signature · 1 line
2.0.0.153.g79dcccc
PATCH 2/3 Btrfs: procfs-devlist: backport global rcu-string non support
In reply to Anand Jain--- fs/btrfs/procfs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
fs/btrfs/procfs.c +2 -2
@@ -1,9 +1,9 @@#include <linux/seq_file.h> #include <linux/vmalloc.h> #include <linux/proc_fs.h> -#include <linux/rcustring.h> #include "ctree.h" #include "volumes.h" +#include "rcu-string.h" #define BTRFS_PROC_PATH "fs/btrfs"#define BTRFS_PROC_DEVLIST "devlist"
@@ -67,7 +67,7 @@ again_fs_devs:BTRFS_SEQ_PRINT ("\t\tdev_addr:\t%p\n" , device);rcu_read_lock ();BTRFS_SEQ_PRINT ("\t\tdevice:\t\t%s\n" , - device->name ?rcu_string_dereference (device->name):"(null)" ); + device->name ?rcu_str_deref (device->name):"(null)" );rcu_read_unlock ();BTRFS_SEQ_PRINT ("\t\tdevid:\t\t%llu\n" , device->devid);if (device->dev_root) {
Signature · 1 line
2.0.0.153.g79dcccc
PATCH 3/3 Btsfs: procfs-devlist: update the sysfs contents
In reply to Anand Jain--- fs/btrfs/procfs.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
fs/btrfs/procfs.c +11 -0
@@ -62,6 +62,17 @@ again_fs_devs:BTRFS_SEQ_PRINT ("\tseeding:\t\t%d\n" , fs_devices->seeding);BTRFS_SEQ_PRINT ("\trotating:\t\t%d\n" , fs_devices->rotating); +BTRFS_SEQ_PRINT ("\tsuper_kobj_state:\t%d\n" , fs_devices->super_kobj.state_initialized); +BTRFS_SEQ_PRINT ("\tsuper_kobj_insysfs:\t%d\n" , fs_devices->super_kobj.state_in_sysfs); + +if (fs_devices->device_dir_kobj) { +BTRFS_SEQ_PRINT ("\tdevice_kobj_state:\t%d\n" , fs_devices->device_dir_kobj->state_initialized); +BTRFS_SEQ_PRINT ("\tdevice_kobj_insysfs:\t%d\n" , fs_devices->device_dir_kobj->state_in_sysfs); + }else { +BTRFS_SEQ_PRINT ("\tdevice_kobj_state:\t%s\n" ,"null" ); +BTRFS_SEQ_PRINT ("\tdevice_kobj_insysfs:\t%s\n" ,"null" ); + } +list_for_each_entry (device, &fs_devices->devices, dev_list) {BTRFS_SEQ_PRINT ("\t[[uuid: %pU]]\n" , device->uuid);BTRFS_SEQ_PRINT ("\t\tdev_addr:\t%p\n" , device);
Signature · 1 line
2.0.0.153.g79dcccc