btrfs: add helper function to check if btrfs is module
authorAnand Jain <Anand.Jain@oracle.com>
Wed, 15 Jun 2016 08:47:54 +0000 (16:47 +0800)
committerEryu Guan <eguan@redhat.com>
Fri, 1 Jul 2016 15:12:50 +0000 (23:12 +0800)
We need btrfs to be a module so that it can unloaded and reloaded,
so that we can clean up the btrfs internal in memory device list.

This patch adds _require_btrfs_unloadable() and _reload_btrfs_ko()
to help with the same.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Reviewed-by: Eryu Guan <eguan@redhat.com>
Signed-off-by: Eryu Guan <eguan@redhat.com>
common/rc

index 0b1f24cb87da281c9f5f88fda420cbaf49278493..6b3e87050b6a235fa00c8978d454fd1a548fe5e3 100644 (file)
--- a/common/rc
+++ b/common/rc
@@ -1441,6 +1441,18 @@ _supported_os()
     _notrun "not suitable for this OS: $HOSTOS"
 }
 
+_require_btrfs_loadable()
+{
+       modprobe -r btrfs || _notrun "btrfs unloadable"
+       modprobe btrfs || _notrun "Can't load btrfs"
+}
+
+_reload_btrfs_ko()
+{
+       modprobe -r btrfs || _fail "btrfs unload failed"
+       modprobe btrfs || _fail "btrfs load failed"
+}
+
 # this test needs a scratch partition - check we're ok & unmount it
 # No post-test check of the device is required. e.g. the test intentionally
 # finishes the test with the filesystem in a corrupt state