]> git.kernelconcepts.de Git - karo-tx-linux.git/blobdiff - mm/zpool.c
Merge branch 'linus' of git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6
[karo-tx-linux.git] / mm / zpool.c
index 722a4f60e90b29cd3626cdc4acddc1594ab7a0a5..8f670d3e87060f6277f5651a79cfaa8d27a30713 100644 (file)
@@ -22,7 +22,7 @@ struct zpool {
 
        struct zpool_driver *driver;
        void *pool;
-       struct zpool_ops *ops;
+       const struct zpool_ops *ops;
 
        struct list_head list;
 };
@@ -99,6 +99,39 @@ static void zpool_put_driver(struct zpool_driver *driver)
        module_put(driver->owner);
 }
 
+/**
+ * zpool_has_pool() - Check if the pool driver is available
+ * @type       The type of the zpool to check (e.g. zbud, zsmalloc)
+ *
+ * This checks if the @type pool driver is available.  This will try to load
+ * the requested module, if needed, but there is no guarantee the module will
+ * still be loaded and available immediately after calling.  If this returns
+ * true, the caller should assume the pool is available, but must be prepared
+ * to handle the @zpool_create_pool() returning failure.  However if this
+ * returns false, the caller should assume the requested pool type is not
+ * available; either the requested pool type module does not exist, or could
+ * not be loaded, and calling @zpool_create_pool() with the pool type will
+ * fail.
+ *
+ * Returns: true if @type pool is available, false if not
+ */
+bool zpool_has_pool(char *type)
+{
+       struct zpool_driver *driver = zpool_get_driver(type);
+
+       if (!driver) {
+               request_module("zpool-%s", type);
+               driver = zpool_get_driver(type);
+       }
+
+       if (!driver)
+               return false;
+
+       zpool_put_driver(driver);
+       return true;
+}
+EXPORT_SYMBOL(zpool_has_pool);
+
 /**
  * zpool_create_pool() - Create a new zpool
  * @type       The type of the zpool to create (e.g. zbud, zsmalloc)
@@ -115,7 +148,7 @@ static void zpool_put_driver(struct zpool_driver *driver)
  * Returns: New zpool on success, NULL on failure.
  */
 struct zpool *zpool_create_pool(char *type, char *name, gfp_t gfp,
-               struct zpool_ops *ops)
+               const struct zpool_ops *ops)
 {
        struct zpool_driver *driver;
        struct zpool *zpool;
@@ -320,20 +353,6 @@ u64 zpool_get_total_size(struct zpool *zpool)
        return zpool->driver->total_size(zpool->pool);
 }
 
-static int __init init_zpool(void)
-{
-       pr_info("loaded\n");
-       return 0;
-}
-
-static void __exit exit_zpool(void)
-{
-       pr_info("unloaded\n");
-}
-
-module_init(init_zpool);
-module_exit(exit_zpool);
-
 MODULE_LICENSE("GPL");
 MODULE_AUTHOR("Dan Streetman <ddstreet@ieee.org>");
 MODULE_DESCRIPTION("Common API for compressed memory storage");