Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1200769

[PATCH 1/3] zpool: add zpool_has_pool()

From Dan Streetman <ddstreet@ieee.org>
Newsgroups linux.kernel
Subject [PATCH 1/3] zpool: add zpool_has_pool()
Date 2015-08-05 15:50 +0200
Message-ID <pU7eY-2WR-47@gated-at.bofh.it> (permalink)
References <pU7eX-2WR-29@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


Add zpool_has_pool() function, indicating if the specified type of zpool
is available (i.e. zsmalloc or zbud).  This allows checking if a pool is
available, without actually trying to allocate it, similar to
crypto_has_alg().

This is used by a following patch to zswap that enables the dynamic
runtime creation of zswap zpools.

Signed-off-by: Dan Streetman <ddstreet@ieee.org>
---
 include/linux/zpool.h |  2 ++
 mm/zpool.c            | 25 +++++++++++++++++++++++++
 2 files changed, 27 insertions(+)

diff --git a/include/linux/zpool.h b/include/linux/zpool.h
index c924a28..42f8ec9 100644
--- a/include/linux/zpool.h
+++ b/include/linux/zpool.h
@@ -36,6 +36,8 @@ enum zpool_mapmode {
 	ZPOOL_MM_DEFAULT = ZPOOL_MM_RW
 };
 
+bool zpool_has_pool(char *type);
+
 struct zpool *zpool_create_pool(char *type, char *name,
 			gfp_t gfp, const struct zpool_ops *ops);
 
diff --git a/mm/zpool.c b/mm/zpool.c
index 951db32..aafcf8f 100644
--- a/mm/zpool.c
+++ b/mm/zpool.c
@@ -100,6 +100,31 @@ static void zpool_put_driver(struct zpool_driver *driver)
 }
 
 /**
+ * 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.
+ *
+ * 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)
  * @name	The name of the zpool (e.g. zram0, zswap)
-- 
2.1.0

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Back to linux.kernel | Previous | NextNext in thread | Find similar | Unroll thread


Thread

[PATCH 1/3] zpool: add zpool_has_pool() Dan Streetman <ddstreet@ieee.org> - 2015-08-05 15:50 +0200
  Re: [PATCH 1/3] zpool: add zpool_has_pool() Andrew Morton <akpm@linux-foundation.org> - 2015-08-05 22:10 +0200
    Re: [PATCH 1/3] zpool: add zpool_has_pool() Andrew Morton <akpm@linux-foundation.org> - 2015-08-06 00:10 +0200
      Re: [PATCH 1/3] zpool: add zpool_has_pool() Seth Jennings <sjennings@variantweb.net> - 2015-08-07 00:00 +0200
        Re: [PATCH 1/3] zpool: add zpool_has_pool() Seth Jennings <sjennings@variantweb.net> - 2015-08-07 05:40 +0200
      Re: [PATCH 1/3] zpool: add zpool_has_pool() Dan Streetman <ddstreet@ieee.org> - 2015-08-14 22:10 +0200
    Re: [PATCH 1/3] zpool: add zpool_has_pool() Dan Streetman <ddstreet@ieee.org> - 2015-08-06 00:10 +0200
      [PATCH] zpool: clarification comment for zpool_has_pool Dan Streetman <ddstreet@ieee.org> - 2015-08-06 20:00 +0200

csiph-web