summaryrefslogtreecommitdiff
path: root/cmds-filesystem.c
diff options
context:
space:
mode:
authorDavid Sterba <dsterba@suse.cz>2013-09-17 17:24:53 +0200
committerChris Mason <chris.mason@fusionio.com>2013-10-16 08:22:26 -0400
commit4e466c8b440afd09a8bf600bcf18469c3e7539cd (patch)
tree9f7f063ae99962568becb47fc56f360a2226e6e8 /cmds-filesystem.c
parente9270f62090c2312bccb340e4394bc216733edac (diff)
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 <dsterba@suse.cz> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
Diffstat (limited to 'cmds-filesystem.c')
-rw-r--r--cmds-filesystem.c19
1 files changed, 17 insertions, 2 deletions
diff --git a/cmds-filesystem.c b/cmds-filesystem.c
index 815d59a5..93fd0eb5 100644
--- a/cmds-filesystem.c
+++ b/cmds-filesystem.c
@@ -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);