Skip to content

Commit a30f59d

Browse files
asjkdave
authored andcommitted
btrfs-progs: merge device id comparators
There are two similar but slightly different implementations of devid comparison functions: cmp_device_id() in filesystem.c and _cmp_device_by_id() in mkfs/main.c. Merge them as cmp_device_id in common/device-utils.c. Signed-off-by: Anand Jain <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 66e3619 commit a30f59d

File tree

4 files changed

+15
-23
lines changed

4 files changed

+15
-23
lines changed

cmds/filesystem.c

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -259,21 +259,6 @@ static int uuid_search(struct btrfs_fs_devices *fs_devices, const char *search)
259259
return 0;
260260
}
261261

262-
/*
263-
* Sort devices by devid, ascending
264-
*/
265-
static int cmp_device_id(void *priv, struct list_head *a,
266-
struct list_head *b)
267-
{
268-
const struct btrfs_device *da = list_entry(a, struct btrfs_device,
269-
dev_list);
270-
const struct btrfs_device *db = list_entry(b, struct btrfs_device,
271-
dev_list);
272-
273-
return da->devid < db->devid ? -1 :
274-
da->devid > db->devid ? 1 : 0;
275-
}
276-
277262
static void splice_device_list(struct list_head *seed_devices,
278263
struct list_head *all_devices)
279264
{

common/device-utils.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -641,3 +641,15 @@ ssize_t btrfs_direct_pwrite(int fd, const void *buf, size_t count, off_t offset)
641641
free(bounce_buf);
642642
return ret;
643643
}
644+
645+
/* Sort devices by devid, ascending */
646+
int cmp_device_id(void *priv, struct list_head *a, struct list_head *b)
647+
{
648+
const struct btrfs_device *da = list_entry(a, struct btrfs_device,
649+
dev_list);
650+
const struct btrfs_device *db = list_entry(b, struct btrfs_device,
651+
dev_list);
652+
653+
return da->devid < db->devid ? -1 :
654+
da->devid > db->devid ? 1 : 0;
655+
}

common/device-utils.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ int btrfs_prepare_device(int fd, const char *file, u64 *block_count_ret,
5858
ssize_t btrfs_direct_pread(int fd, void *buf, size_t count, off_t offset);
5959
ssize_t btrfs_direct_pwrite(int fd, const void *buf, size_t count, off_t offset);
6060

61+
int cmp_device_id(void *priv, struct list_head *a, struct list_head *b);
62+
6163
#ifdef BTRFS_ZONED
6264
static inline ssize_t btrfs_pwrite(int fd, const void *buf, size_t count,
6365
off_t offset, bool direct)

mkfs/main.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -512,13 +512,6 @@ static int zero_output_file(int out_fd, u64 size)
512512
return ret;
513513
}
514514

515-
static int _cmp_device_by_id(void *priv, struct list_head *a,
516-
struct list_head *b)
517-
{
518-
return list_entry(a, struct btrfs_device, dev_list)->devid -
519-
list_entry(b, struct btrfs_device, dev_list)->devid;
520-
}
521-
522515
static void list_all_devices(struct btrfs_root *root, bool is_zoned)
523516
{
524517
struct btrfs_fs_devices *fs_devices;
@@ -532,7 +525,7 @@ static void list_all_devices(struct btrfs_root *root, bool is_zoned)
532525
list_for_each_entry(device, &fs_devices->devices, dev_list)
533526
number_of_devices++;
534527

535-
list_sort(NULL, &fs_devices->devices, _cmp_device_by_id);
528+
list_sort(NULL, &fs_devices->devices, cmp_device_id);
536529

537530
printf("Number of devices: %d\n", number_of_devices);
538531
printf("Devices:\n");

0 commit comments

Comments
 (0)