btrfs-progs: introduce btrfs-devlist
Subsystems (2)
PATCH v2 1/1 btrfs-progs: introduce btrfs-devlist
From: Anand Jain <[email protected]>
This is a small (debug) program to dump the device list in the raw format from the btrfs kernel.
here I use ioctl which was introduced in the below kernel patch
btrfs: introduce BTRFS_IOC_GET_DEVS
---
v2: add more parameter to get from the kernel
.gitignore | 1 + Makefile | 4 +- btrfs-devlist.c | 249 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ioctl.h | 49 +++++++++++ 4 files changed, 301 insertions(+), 2 deletions(-) create mode 100644 btrfs-devlist.c
.gitignore +1 -0
@@ -34,3 +34,4 @@ libbtrfs.a libbtrfs.so libbtrfs.so.0 libbtrfs.so.0.1 +btrfs-devlist
Makefile +2 -2
@@ -47,7 +47,7 @@ MAKEOPTS = --no-print-directory Q=$(Q) progs = mkfs.btrfs btrfs-debug-tree btrfsck \ btrfs btrfs-map-logical btrfs-image btrfs-zero-log btrfs-convert \ - btrfs-find-root btrfstune btrfs-show-super + btrfs-find-root btrfstune btrfs-show-super btrfs-devlist # external libs required by various binaries; for btrfs-foo, # specify btrfs_foo_libs = <list of libs>; see $($(subst...)) rules below
@@ -226,7 +226,7 @@ clean: $(CLEANDIRS) @echo "Cleaning" $(Q)rm -f $(progs) cscope.out *.o *.o.d btrfs-convert btrfs-image btrfs-select-super \ btrfs-zero-log btrfstune dir-test ioctl-test quick-test send-test btrfsck \ - btrfs.static mkfs.btrfs.static btrfs-calc-size \ + btrfs.static mkfs.btrfs.static btrfs-calc-size btrfs-devlist\ version.h $(check_defs) \ $(libs) $(lib_links)
btrfs-devlist.c new file +249 -0
249 lines not on this page · raw message
ioctl.h +49 -0
67 lines not on this page · raw message
Signature · 1 line
1.8.4.2
PATCH v2 1/1 btrfs: introduce BTRFS_IOC_GET_DEVS
From: Anand Jain <[email protected]>
The user land progs needs a simple way to see
the raw list of disks and its parameters as seen
by the btrfs kernel.
As of now btrfs-devlist uses this ioctl.
---
v2: add more parameter to get from the kernel
fs/btrfs/super.c | 56 ++++++++++++++++++ fs/btrfs/volumes.c | 140 +++++++++++++++++++++++++++++++++++++++++++++ fs/btrfs/volumes.h | 2 + include/uapi/linux/btrfs.h | 49 ++++++++++++++++ 4 files changed, 247 insertions(+)
fs/btrfs/super.c +56 -0
@@ -1717,6 +1717,59 @@ static struct file_system_type btrfs_fs_type = { };MODULE_ALIAS_FS ("btrfs" ); +static int btrfs_ioc_get_devlist (void __user *arg) +{ +int ret =0 ; +u64 sz_devlist_arg; +u64 sz_devlist; +u64 sz_out; + +struct btrfs_ioctl_devlist_args *devlist_arg; +struct btrfs_ioctl_devlist_args *tmp_devlist_arg; +struct btrfs_ioctl_devlist *devlist; + +u64 cnt =0 , ucnt; + + sz_devlist_arg =sizeof (*devlist_arg); + sz_devlist =sizeof (*devlist); + +if (copy_from_user (&ucnt, + (struct btrfs_ioctl_devlist_args __user *)(arg + + offsetof(struct btrfs_ioctl_devlist_args , count)), +sizeof (ucnt))) +return -EFAULT ; + + cnt =btrfs_get_devlist_cnt (); + +if (cnt > ucnt) { +if (copy_to_user (arg + + offsetof(struct btrfs_ioctl_devlist_args , count), + &cnt,sizeof (cnt))) +return -EFAULT ; +return 1 ; + } + + sz_out = sz_devlist_arg + sz_devlist * cnt; + + tmp_devlist_arg = devlist_arg =memdup_user (arg, sz_out); +if (IS_ERR (devlist_arg)) +return PTR_ERR (devlist_arg); + + devlist = (struct btrfs_ioctl_devlist *) (++tmp_devlist_arg); + cnt =btrfs_get_devlist (devlist, cnt); + devlist_arg->count = cnt; + +if (copy_to_user (arg, devlist_arg, sz_out)) { + ret = -EFAULT ; + goto out; + } + ret =0 ; +out: +kfree (devlist_arg); +return ret; + +} +static int btrfs_ioc_get_fslist (void __user *arg) {int ret =0 ;
@@ -1801,6 +1854,9 @@ static long btrfs_control_ioctl(struct file *file, unsigned int cmd,case BTRFS_IOC_GET_FSLIST : ret =btrfs_ioc_get_fslist (argp);break ; +case BTRFS_IOC_GET_DEVS : + ret =btrfs_ioc_get_devlist (argp); +break ; }return ret;
fs/btrfs/volumes.c +140 -0
143 lines not on this page · raw message
fs/btrfs/volumes.h +2 -0
@@ -393,4 +393,6 @@ static inline void btrfs_dev_stat_reset(struct btrfs_device *dev, }int btrfs_get_fslist_cnt (void );u64 btrfs_get_fslist (struct btrfs_ioctl_fslist *fslist,u64 ucnt); +int btrfs_get_devlist_cnt (void ); +u64 btrfs_get_devlist (struct btrfs_ioctl_devlist *devlist,u64 ucnt);#endif
include/uapi/linux/btrfs.h +49 -0
66 lines not on this page · raw message
Signature · 1 line
1.8.4.2
Re: [PATCH v2] btrfs: introduce BTRFS_IOC_GET_DEVS
Quoted 4 lines · Anand Jain
The user land progs needs a simple way to see
the raw list of disks and its parameters as seen
by the btrfs kernel.
As of now btrfs-devlist uses this ioctl.
As discussed before together with Hugo, the ioctl could exist parallel to sysfs export of the device data. From that point it's easier to maintain and update a set of sysfs files than an ioctl. The way you suggest it right now lacks future-proof extensibility and backward compatibility handling.
The userspace code is said to be a small and debug program, the sysfs would IMHO satsify it needs as well, so I suggest not to continue on the ioctl approach.
Re: [PATCH v2] btrfs: introduce BTRFS_IOC_GET_DEVS
Quoted 12 lines · David Sterba
Quoted 4 lines · Anand Jain
The user land progs needs a simple way to see
the raw list of disks and its parameters as seen
by the btrfs kernel.
As of now btrfs-devlist uses this ioctl.As discussed before together with Hugo, the ioctl could exist parallel to sysfs export of the device data. From that point it's easier to maintain and update a set of sysfs files than an ioctl. The way you suggest it right now lacks future-proof extensibility and backward compatibility handling.
Quoted 3 lines
The userspace code is said to be a small and debug program, the sysfs would IMHO satsify it needs as well, so I suggest not to continue on the ioctl approach.
sysfs interface has its advantage, but please lets not clutter it with the debug info as it just don't belong there. And one should be care full enough not to introduce regressions [1] when writing sysfs interfaces (sysfs has to be "managed" VS debug-friendly memory-dump/ioctl-dump).
Next, btrfs-kernel device management isn't just ready fully[2] so that sysfs interface can be developed as of now. It better wait.
[1]
https://www.mail-archive.com/[email protected]/msg31432.html
http://comments.gmane.org/gmane.comp.file-systems.btrfs/31915
[2] btrfs-kernel has no idea when disk disappears. To get this done we appear to need more enhancements related to the usage of kobjects with in kernel.
Thanks, Anand