btrfs-progs: add list_sort and use it to sort devices by id
Subsystems (2)
PATCH 1/1 btrfs-progs: add list_sort and use it to sort devices by id
The devices in 'btrfs filesystem show' are now sorted by the device id, currently the order was undefined.
Signed-off-by David Sterba <[email protected]>
--- Makefile | 2 +- cmds-filesystem.c | 19 ++++++- list_sort.c | 144 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ list_sort.h | 14 ++++++ 4 files changed, 176 insertions(+), 3 deletions(-) create mode 100644 list_sort.c create mode 100644 list_sort.h
Makefile +1 -1
@@ -9,7 +9,7 @@ CFLAGS = -g -O1 objects = ctree.o disk-io.o radix-tree.o extent-tree.o print-tree.o \ root-tree.o dir-item.o file-item.o inode-item.o inode-map.o \ extent-cache.o extent_io.o volumes.o utils.o repair.o \ - qgroup.o raid6.o free-space-cache.o uuid-tree.o + qgroup.o raid6.o free-space-cache.o uuid-tree.o list_sort.o cmds_objects = cmds-subvolume.o cmds-filesystem.o cmds-device.o cmds-scrub.o \ cmds-inspect.o cmds-balance.o cmds-send.o cmds-receive.o \ cmds-quota.o cmds-qgroup.o cmds-replace.o cmds-check.o \
cmds-filesystem.c +17 -2
@@ -28,10 +28,9 @@#include "ioctl.h" #include "utils.h" #include "volumes.h" -#include "version.h" -#include "commands.h" +#include "list_sort.h" static const char *const filesystem_cmd_group_usage[] = {"btrfs filesystem [<group>] <command> [<args>]" ,
@@ -183,6 +182,21 @@ static int uuid_search(struct btrfs_fs_devices *fs_devices, char *search)return 0 ; } +/* +* Sort devices by devid, ascending +*/ +static int cmp_device_id (void *priv,struct list_head *a, +struct list_head *b) +{ + const struct btrfs_device *da = list_entry(a, struct btrfs_device, + dev_list); + const struct btrfs_device *db = list_entry(b, struct btrfs_device, + dev_list); + +return da->devid < db->devid ?-1 : + da->devid > db->devid ?1 :0 ; +} +static void print_one_uuid (struct btrfs_fs_devices *fs_devices) {char uuidbuf[37 ];
@@ -205,6 +219,7 @@ static void print_one_uuid(struct btrfs_fs_devices *fs_devices) (unsigned long long )total, pretty_size(device->super_bytes_used)); +list_sort (NULL , &fs_devices->devices, cmp_device_id);list_for_each (cur, &fs_devices->devices) { device = list_entry(cur, struct btrfs_device, dev_list);
list_sort.c new file +144 -0
144 lines not on this page · raw message
list_sort.h new file +14 -0
@@ -0,0 +1,14 @@ +/* +* taken from linux kernel include/list_sort.h +*/ +#ifndef _LINUX_LIST_SORT_H +#define _LINUX_LIST_SORT_H + +#include "kerncompat.h" + +struct list_head ; + +void list_sort (void *priv,struct list_head *head, +int (*cmp)(void *priv,struct list_head *a, +struct list_head *b)); +#endif
Signature · 1 line
1.8.3.1