From b0f760c91aa9de9a853545f36dc063f6ef5e9008 Mon Sep 17 00:00:00 2001 From: Zhao Lei Date: Mon, 24 Aug 2015 16:45:02 +0800 Subject: btrfs-progs: Introduce btrfs_close_all_devices helper If there is more than one fs_devices in fs_uuids list (like mkfs.btrfs does), we need close them all before exit. Add a helper for that. Signed-off-by: Zhao Lei Signed-off-by: David Sterba --- volumes.c | 11 +++++++++++ volumes.h | 1 + 2 files changed, 12 insertions(+) diff --git a/volumes.c b/volumes.c index f7462c58..ca50f1ce 100644 --- a/volumes.c +++ b/volumes.c @@ -198,6 +198,17 @@ again: return 0; } +void btrfs_close_all_devices(void) +{ + struct btrfs_fs_devices *fs_devices; + + while (!list_empty(&fs_uuids)) { + fs_devices = list_entry(fs_uuids.next, struct btrfs_fs_devices, + list); + btrfs_close_devices(fs_devices); + } +} + int btrfs_open_devices(struct btrfs_fs_devices *fs_devices, int flags) { int fd; diff --git a/volumes.h b/volumes.h index 71d5d663..f7761311 100644 --- a/volumes.h +++ b/volumes.h @@ -187,6 +187,7 @@ int btrfs_add_device(struct btrfs_trans_handle *trans, int btrfs_open_devices(struct btrfs_fs_devices *fs_devices, int flags); int btrfs_close_devices(struct btrfs_fs_devices *fs_devices); +void btrfs_close_all_devices(void); int btrfs_add_device(struct btrfs_trans_handle *trans, struct btrfs_root *root, struct btrfs_device *device); -- cgit v1.2.3