Thomas Gleixner | 09c434b | 2019-05-19 13:08:20 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Dan Streetman | af8d417 | 2014-08-06 16:08:36 -0700 | [diff] [blame] | 2 | /* |
| 3 | * zpool memory storage api |
| 4 | * |
| 5 | * Copyright (C) 2014 Dan Streetman |
| 6 | * |
| 7 | * This is a common frontend for memory storage pool implementations. |
| 8 | * Typically, this is used to store compressed memory. |
| 9 | */ |
| 10 | |
| 11 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 12 | |
| 13 | #include <linux/list.h> |
| 14 | #include <linux/types.h> |
| 15 | #include <linux/mm.h> |
| 16 | #include <linux/slab.h> |
| 17 | #include <linux/spinlock.h> |
| 18 | #include <linux/module.h> |
| 19 | #include <linux/zpool.h> |
| 20 | |
| 21 | struct zpool { |
Dan Streetman | af8d417 | 2014-08-06 16:08:36 -0700 | [diff] [blame] | 22 | struct zpool_driver *driver; |
| 23 | void *pool; |
Dan Streetman | af8d417 | 2014-08-06 16:08:36 -0700 | [diff] [blame] | 24 | }; |
| 25 | |
| 26 | static LIST_HEAD(drivers_head); |
| 27 | static DEFINE_SPINLOCK(drivers_lock); |
| 28 | |
Dan Streetman | af8d417 | 2014-08-06 16:08:36 -0700 | [diff] [blame] | 29 | /** |
| 30 | * zpool_register_driver() - register a zpool implementation. |
| 31 | * @driver: driver to register |
| 32 | */ |
| 33 | void zpool_register_driver(struct zpool_driver *driver) |
| 34 | { |
| 35 | spin_lock(&drivers_lock); |
| 36 | atomic_set(&driver->refcount, 0); |
| 37 | list_add(&driver->list, &drivers_head); |
| 38 | spin_unlock(&drivers_lock); |
| 39 | } |
| 40 | EXPORT_SYMBOL(zpool_register_driver); |
| 41 | |
| 42 | /** |
| 43 | * zpool_unregister_driver() - unregister a zpool implementation. |
| 44 | * @driver: driver to unregister. |
| 45 | * |
| 46 | * Module usage counting is used to prevent using a driver |
| 47 | * while/after unloading, so if this is called from module |
| 48 | * exit function, this should never fail; if called from |
| 49 | * other than the module exit function, and this returns |
| 50 | * failure, the driver is in use and must remain available. |
| 51 | */ |
| 52 | int zpool_unregister_driver(struct zpool_driver *driver) |
| 53 | { |
| 54 | int ret = 0, refcount; |
| 55 | |
| 56 | spin_lock(&drivers_lock); |
| 57 | refcount = atomic_read(&driver->refcount); |
| 58 | WARN_ON(refcount < 0); |
| 59 | if (refcount > 0) |
| 60 | ret = -EBUSY; |
| 61 | else |
| 62 | list_del(&driver->list); |
| 63 | spin_unlock(&drivers_lock); |
| 64 | |
| 65 | return ret; |
| 66 | } |
| 67 | EXPORT_SYMBOL(zpool_unregister_driver); |
| 68 | |
Dan Streetman | 69e18f4 | 2015-11-06 16:29:18 -0800 | [diff] [blame] | 69 | /* this assumes @type is null-terminated. */ |
Sergey SENOZHATSKY | 6f3526d | 2015-11-06 16:29:21 -0800 | [diff] [blame] | 70 | static struct zpool_driver *zpool_get_driver(const char *type) |
Dan Streetman | af8d417 | 2014-08-06 16:08:36 -0700 | [diff] [blame] | 71 | { |
| 72 | struct zpool_driver *driver; |
| 73 | |
| 74 | spin_lock(&drivers_lock); |
| 75 | list_for_each_entry(driver, &drivers_head, list) { |
| 76 | if (!strcmp(driver->type, type)) { |
| 77 | bool got = try_module_get(driver->owner); |
| 78 | |
| 79 | if (got) |
| 80 | atomic_inc(&driver->refcount); |
| 81 | spin_unlock(&drivers_lock); |
| 82 | return got ? driver : NULL; |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | spin_unlock(&drivers_lock); |
| 87 | return NULL; |
| 88 | } |
| 89 | |
| 90 | static void zpool_put_driver(struct zpool_driver *driver) |
| 91 | { |
| 92 | atomic_dec(&driver->refcount); |
| 93 | module_put(driver->owner); |
| 94 | } |
| 95 | |
| 96 | /** |
Dan Streetman | 3f0e131 | 2015-09-09 15:35:16 -0700 | [diff] [blame] | 97 | * zpool_has_pool() - Check if the pool driver is available |
Mike Rapoport | b7701a5 | 2018-02-06 15:42:13 -0800 | [diff] [blame] | 98 | * @type: The type of the zpool to check (e.g. zbud, zsmalloc) |
Dan Streetman | 3f0e131 | 2015-09-09 15:35:16 -0700 | [diff] [blame] | 99 | * |
| 100 | * This checks if the @type pool driver is available. This will try to load |
| 101 | * the requested module, if needed, but there is no guarantee the module will |
| 102 | * still be loaded and available immediately after calling. If this returns |
| 103 | * true, the caller should assume the pool is available, but must be prepared |
| 104 | * to handle the @zpool_create_pool() returning failure. However if this |
| 105 | * returns false, the caller should assume the requested pool type is not |
| 106 | * available; either the requested pool type module does not exist, or could |
| 107 | * not be loaded, and calling @zpool_create_pool() with the pool type will |
| 108 | * fail. |
| 109 | * |
Dan Streetman | 69e18f4 | 2015-11-06 16:29:18 -0800 | [diff] [blame] | 110 | * The @type string must be null-terminated. |
| 111 | * |
Dan Streetman | 3f0e131 | 2015-09-09 15:35:16 -0700 | [diff] [blame] | 112 | * Returns: true if @type pool is available, false if not |
| 113 | */ |
| 114 | bool zpool_has_pool(char *type) |
| 115 | { |
| 116 | struct zpool_driver *driver = zpool_get_driver(type); |
| 117 | |
| 118 | if (!driver) { |
| 119 | request_module("zpool-%s", type); |
| 120 | driver = zpool_get_driver(type); |
| 121 | } |
| 122 | |
| 123 | if (!driver) |
| 124 | return false; |
| 125 | |
| 126 | zpool_put_driver(driver); |
| 127 | return true; |
| 128 | } |
| 129 | EXPORT_SYMBOL(zpool_has_pool); |
| 130 | |
| 131 | /** |
Dan Streetman | af8d417 | 2014-08-06 16:08:36 -0700 | [diff] [blame] | 132 | * zpool_create_pool() - Create a new zpool |
Mike Rapoport | b7701a5 | 2018-02-06 15:42:13 -0800 | [diff] [blame] | 133 | * @type: The type of the zpool to create (e.g. zbud, zsmalloc) |
| 134 | * @name: The name of the zpool (e.g. zram0, zswap) |
| 135 | * @gfp: The GFP flags to use when allocating the pool. |
| 136 | * @ops: The optional ops callback. |
Dan Streetman | af8d417 | 2014-08-06 16:08:36 -0700 | [diff] [blame] | 137 | * |
| 138 | * This creates a new zpool of the specified type. The gfp flags will be |
| 139 | * used when allocating memory, if the implementation supports it. If the |
Yu Zhao | 9c3760e | 2018-01-31 16:19:59 -0800 | [diff] [blame] | 140 | * ops param is NULL, then the created zpool will not be evictable. |
Dan Streetman | af8d417 | 2014-08-06 16:08:36 -0700 | [diff] [blame] | 141 | * |
| 142 | * Implementations must guarantee this to be thread-safe. |
| 143 | * |
Dan Streetman | 69e18f4 | 2015-11-06 16:29:18 -0800 | [diff] [blame] | 144 | * The @type and @name strings must be null-terminated. |
| 145 | * |
Dan Streetman | af8d417 | 2014-08-06 16:08:36 -0700 | [diff] [blame] | 146 | * Returns: New zpool on success, NULL on failure. |
| 147 | */ |
Sergey SENOZHATSKY | 6f3526d | 2015-11-06 16:29:21 -0800 | [diff] [blame] | 148 | struct zpool *zpool_create_pool(const char *type, const char *name, gfp_t gfp, |
Krzysztof Kozlowski | 7867277 | 2015-09-08 15:05:03 -0700 | [diff] [blame] | 149 | const struct zpool_ops *ops) |
Dan Streetman | af8d417 | 2014-08-06 16:08:36 -0700 | [diff] [blame] | 150 | { |
| 151 | struct zpool_driver *driver; |
| 152 | struct zpool *zpool; |
| 153 | |
Dan Streetman | cf41f5f | 2015-06-25 15:00:37 -0700 | [diff] [blame] | 154 | pr_debug("creating pool type %s\n", type); |
Dan Streetman | af8d417 | 2014-08-06 16:08:36 -0700 | [diff] [blame] | 155 | |
| 156 | driver = zpool_get_driver(type); |
| 157 | |
| 158 | if (!driver) { |
Kees Cook | 137f8cf | 2014-08-29 15:18:40 -0700 | [diff] [blame] | 159 | request_module("zpool-%s", type); |
Dan Streetman | af8d417 | 2014-08-06 16:08:36 -0700 | [diff] [blame] | 160 | driver = zpool_get_driver(type); |
| 161 | } |
| 162 | |
| 163 | if (!driver) { |
| 164 | pr_err("no driver for type %s\n", type); |
| 165 | return NULL; |
| 166 | } |
| 167 | |
| 168 | zpool = kmalloc(sizeof(*zpool), gfp); |
| 169 | if (!zpool) { |
| 170 | pr_err("couldn't create zpool - out of memory\n"); |
| 171 | zpool_put_driver(driver); |
| 172 | return NULL; |
| 173 | } |
| 174 | |
Dan Streetman | af8d417 | 2014-08-06 16:08:36 -0700 | [diff] [blame] | 175 | zpool->driver = driver; |
Dan Streetman | 479305f | 2015-06-25 15:00:40 -0700 | [diff] [blame] | 176 | zpool->pool = driver->create(name, gfp, ops, zpool); |
Dan Streetman | af8d417 | 2014-08-06 16:08:36 -0700 | [diff] [blame] | 177 | |
| 178 | if (!zpool->pool) { |
| 179 | pr_err("couldn't create %s pool\n", type); |
| 180 | zpool_put_driver(driver); |
| 181 | kfree(zpool); |
| 182 | return NULL; |
| 183 | } |
| 184 | |
Dan Streetman | cf41f5f | 2015-06-25 15:00:37 -0700 | [diff] [blame] | 185 | pr_debug("created pool type %s\n", type); |
Dan Streetman | af8d417 | 2014-08-06 16:08:36 -0700 | [diff] [blame] | 186 | |
Dan Streetman | af8d417 | 2014-08-06 16:08:36 -0700 | [diff] [blame] | 187 | return zpool; |
| 188 | } |
| 189 | |
| 190 | /** |
| 191 | * zpool_destroy_pool() - Destroy a zpool |
Mike Rapoport | f144c39 | 2018-02-06 15:42:16 -0800 | [diff] [blame] | 192 | * @zpool: The zpool to destroy. |
Dan Streetman | af8d417 | 2014-08-06 16:08:36 -0700 | [diff] [blame] | 193 | * |
| 194 | * Implementations must guarantee this to be thread-safe, |
| 195 | * however only when destroying different pools. The same |
| 196 | * pool should only be destroyed once, and should not be used |
| 197 | * after it is destroyed. |
| 198 | * |
| 199 | * This destroys an existing zpool. The zpool should not be in use. |
| 200 | */ |
| 201 | void zpool_destroy_pool(struct zpool *zpool) |
| 202 | { |
Dan Streetman | 69e18f4 | 2015-11-06 16:29:18 -0800 | [diff] [blame] | 203 | pr_debug("destroying pool type %s\n", zpool->driver->type); |
Dan Streetman | af8d417 | 2014-08-06 16:08:36 -0700 | [diff] [blame] | 204 | |
Dan Streetman | af8d417 | 2014-08-06 16:08:36 -0700 | [diff] [blame] | 205 | zpool->driver->destroy(zpool->pool); |
| 206 | zpool_put_driver(zpool->driver); |
| 207 | kfree(zpool); |
| 208 | } |
| 209 | |
| 210 | /** |
| 211 | * zpool_get_type() - Get the type of the zpool |
Mike Rapoport | f144c39 | 2018-02-06 15:42:16 -0800 | [diff] [blame] | 212 | * @zpool: The zpool to check |
Dan Streetman | af8d417 | 2014-08-06 16:08:36 -0700 | [diff] [blame] | 213 | * |
| 214 | * This returns the type of the pool. |
| 215 | * |
| 216 | * Implementations must guarantee this to be thread-safe. |
| 217 | * |
| 218 | * Returns: The type of zpool. |
| 219 | */ |
Dan Streetman | 69e18f4 | 2015-11-06 16:29:18 -0800 | [diff] [blame] | 220 | const char *zpool_get_type(struct zpool *zpool) |
Dan Streetman | af8d417 | 2014-08-06 16:08:36 -0700 | [diff] [blame] | 221 | { |
Dan Streetman | 69e18f4 | 2015-11-06 16:29:18 -0800 | [diff] [blame] | 222 | return zpool->driver->type; |
Dan Streetman | af8d417 | 2014-08-06 16:08:36 -0700 | [diff] [blame] | 223 | } |
| 224 | |
| 225 | /** |
Randy Dunlap | b6aa2c8 | 2020-08-11 18:33:28 -0700 | [diff] [blame] | 226 | * zpool_malloc_support_movable() - Check if the zpool supports |
| 227 | * allocating movable memory |
Hui Zhu | c165f25 | 2019-09-23 15:39:37 -0700 | [diff] [blame] | 228 | * @zpool: The zpool to check |
| 229 | * |
Randy Dunlap | b6aa2c8 | 2020-08-11 18:33:28 -0700 | [diff] [blame] | 230 | * This returns if the zpool supports allocating movable memory. |
Hui Zhu | c165f25 | 2019-09-23 15:39:37 -0700 | [diff] [blame] | 231 | * |
| 232 | * Implementations must guarantee this to be thread-safe. |
| 233 | * |
Randy Dunlap | b6aa2c8 | 2020-08-11 18:33:28 -0700 | [diff] [blame] | 234 | * Returns: true if the zpool supports allocating movable memory, false if not |
Hui Zhu | c165f25 | 2019-09-23 15:39:37 -0700 | [diff] [blame] | 235 | */ |
| 236 | bool zpool_malloc_support_movable(struct zpool *zpool) |
| 237 | { |
| 238 | return zpool->driver->malloc_support_movable; |
| 239 | } |
| 240 | |
| 241 | /** |
Dan Streetman | af8d417 | 2014-08-06 16:08:36 -0700 | [diff] [blame] | 242 | * zpool_malloc() - Allocate memory |
Mike Rapoport | f144c39 | 2018-02-06 15:42:16 -0800 | [diff] [blame] | 243 | * @zpool: The zpool to allocate from. |
Mike Rapoport | b7701a5 | 2018-02-06 15:42:13 -0800 | [diff] [blame] | 244 | * @size: The amount of memory to allocate. |
| 245 | * @gfp: The GFP flags to use when allocating memory. |
| 246 | * @handle: Pointer to the handle to set |
Dan Streetman | af8d417 | 2014-08-06 16:08:36 -0700 | [diff] [blame] | 247 | * |
| 248 | * This allocates the requested amount of memory from the pool. |
| 249 | * The gfp flags will be used when allocating memory, if the |
| 250 | * implementation supports it. The provided @handle will be |
| 251 | * set to the allocated object handle. |
| 252 | * |
| 253 | * Implementations must guarantee this to be thread-safe. |
| 254 | * |
| 255 | * Returns: 0 on success, negative value on error. |
| 256 | */ |
| 257 | int zpool_malloc(struct zpool *zpool, size_t size, gfp_t gfp, |
| 258 | unsigned long *handle) |
| 259 | { |
| 260 | return zpool->driver->malloc(zpool->pool, size, gfp, handle); |
| 261 | } |
| 262 | |
| 263 | /** |
| 264 | * zpool_free() - Free previously allocated memory |
Mike Rapoport | f144c39 | 2018-02-06 15:42:16 -0800 | [diff] [blame] | 265 | * @zpool: The zpool that allocated the memory. |
Mike Rapoport | b7701a5 | 2018-02-06 15:42:13 -0800 | [diff] [blame] | 266 | * @handle: The handle to the memory to free. |
Dan Streetman | af8d417 | 2014-08-06 16:08:36 -0700 | [diff] [blame] | 267 | * |
| 268 | * This frees previously allocated memory. This does not guarantee |
| 269 | * that the pool will actually free memory, only that the memory |
| 270 | * in the pool will become available for use by the pool. |
| 271 | * |
| 272 | * Implementations must guarantee this to be thread-safe, |
| 273 | * however only when freeing different handles. The same |
| 274 | * handle should only be freed once, and should not be used |
| 275 | * after freeing. |
| 276 | */ |
| 277 | void zpool_free(struct zpool *zpool, unsigned long handle) |
| 278 | { |
| 279 | zpool->driver->free(zpool->pool, handle); |
| 280 | } |
| 281 | |
| 282 | /** |
| 283 | * zpool_shrink() - Shrink the pool size |
Mike Rapoport | f144c39 | 2018-02-06 15:42:16 -0800 | [diff] [blame] | 284 | * @zpool: The zpool to shrink. |
Mike Rapoport | b7701a5 | 2018-02-06 15:42:13 -0800 | [diff] [blame] | 285 | * @pages: The number of pages to shrink the pool. |
| 286 | * @reclaimed: The number of pages successfully evicted. |
Dan Streetman | af8d417 | 2014-08-06 16:08:36 -0700 | [diff] [blame] | 287 | * |
| 288 | * This attempts to shrink the actual memory size of the pool |
| 289 | * by evicting currently used handle(s). If the pool was |
| 290 | * created with no zpool_ops, or the evict call fails for any |
| 291 | * of the handles, this will fail. If non-NULL, the @reclaimed |
| 292 | * parameter will be set to the number of pages reclaimed, |
| 293 | * which may be more than the number of pages requested. |
| 294 | * |
| 295 | * Implementations must guarantee this to be thread-safe. |
| 296 | * |
| 297 | * Returns: 0 on success, negative value on error/failure. |
| 298 | */ |
| 299 | int zpool_shrink(struct zpool *zpool, unsigned int pages, |
| 300 | unsigned int *reclaimed) |
| 301 | { |
Yu Zhao | 9c3760e | 2018-01-31 16:19:59 -0800 | [diff] [blame] | 302 | return zpool->driver->shrink ? |
| 303 | zpool->driver->shrink(zpool->pool, pages, reclaimed) : -EINVAL; |
Dan Streetman | af8d417 | 2014-08-06 16:08:36 -0700 | [diff] [blame] | 304 | } |
| 305 | |
| 306 | /** |
| 307 | * zpool_map_handle() - Map a previously allocated handle into memory |
Mike Rapoport | f144c39 | 2018-02-06 15:42:16 -0800 | [diff] [blame] | 308 | * @zpool: The zpool that the handle was allocated from |
Mike Rapoport | b7701a5 | 2018-02-06 15:42:13 -0800 | [diff] [blame] | 309 | * @handle: The handle to map |
Mike Rapoport | f144c39 | 2018-02-06 15:42:16 -0800 | [diff] [blame] | 310 | * @mapmode: How the memory should be mapped |
Dan Streetman | af8d417 | 2014-08-06 16:08:36 -0700 | [diff] [blame] | 311 | * |
Mike Rapoport | f144c39 | 2018-02-06 15:42:16 -0800 | [diff] [blame] | 312 | * This maps a previously allocated handle into memory. The @mapmode |
Dan Streetman | af8d417 | 2014-08-06 16:08:36 -0700 | [diff] [blame] | 313 | * param indicates to the implementation how the memory will be |
| 314 | * used, i.e. read-only, write-only, read-write. If the |
| 315 | * implementation does not support it, the memory will be treated |
| 316 | * as read-write. |
| 317 | * |
| 318 | * This may hold locks, disable interrupts, and/or preemption, |
| 319 | * and the zpool_unmap_handle() must be called to undo those |
| 320 | * actions. The code that uses the mapped handle should complete |
Ingo Molnar | f0953a1 | 2021-05-06 18:06:47 -0700 | [diff] [blame] | 321 | * its operations on the mapped handle memory quickly and unmap |
Dan Streetman | af8d417 | 2014-08-06 16:08:36 -0700 | [diff] [blame] | 322 | * as soon as possible. As the implementation may use per-cpu |
| 323 | * data, multiple handles should not be mapped concurrently on |
| 324 | * any cpu. |
| 325 | * |
| 326 | * Returns: A pointer to the handle's mapped memory area. |
| 327 | */ |
| 328 | void *zpool_map_handle(struct zpool *zpool, unsigned long handle, |
| 329 | enum zpool_mapmode mapmode) |
| 330 | { |
| 331 | return zpool->driver->map(zpool->pool, handle, mapmode); |
| 332 | } |
| 333 | |
| 334 | /** |
| 335 | * zpool_unmap_handle() - Unmap a previously mapped handle |
Mike Rapoport | f144c39 | 2018-02-06 15:42:16 -0800 | [diff] [blame] | 336 | * @zpool: The zpool that the handle was allocated from |
Mike Rapoport | b7701a5 | 2018-02-06 15:42:13 -0800 | [diff] [blame] | 337 | * @handle: The handle to unmap |
Dan Streetman | af8d417 | 2014-08-06 16:08:36 -0700 | [diff] [blame] | 338 | * |
| 339 | * This unmaps a previously mapped handle. Any locks or other |
| 340 | * actions that the implementation took in zpool_map_handle() |
| 341 | * will be undone here. The memory area returned from |
| 342 | * zpool_map_handle() should no longer be used after this. |
| 343 | */ |
| 344 | void zpool_unmap_handle(struct zpool *zpool, unsigned long handle) |
| 345 | { |
| 346 | zpool->driver->unmap(zpool->pool, handle); |
| 347 | } |
| 348 | |
| 349 | /** |
| 350 | * zpool_get_total_size() - The total size of the pool |
Mike Rapoport | f144c39 | 2018-02-06 15:42:16 -0800 | [diff] [blame] | 351 | * @zpool: The zpool to check |
Dan Streetman | af8d417 | 2014-08-06 16:08:36 -0700 | [diff] [blame] | 352 | * |
| 353 | * This returns the total size in bytes of the pool. |
| 354 | * |
| 355 | * Returns: Total size of the zpool in bytes. |
| 356 | */ |
| 357 | u64 zpool_get_total_size(struct zpool *zpool) |
| 358 | { |
| 359 | return zpool->driver->total_size(zpool->pool); |
| 360 | } |
| 361 | |
Yu Zhao | 9c3760e | 2018-01-31 16:19:59 -0800 | [diff] [blame] | 362 | /** |
| 363 | * zpool_evictable() - Test if zpool is potentially evictable |
Mike Rapoport | 14fec9e | 2018-02-21 14:45:46 -0800 | [diff] [blame] | 364 | * @zpool: The zpool to test |
Yu Zhao | 9c3760e | 2018-01-31 16:19:59 -0800 | [diff] [blame] | 365 | * |
| 366 | * Zpool is only potentially evictable when it's created with struct |
| 367 | * zpool_ops.evict and its driver implements struct zpool_driver.shrink. |
| 368 | * |
| 369 | * However, it doesn't necessarily mean driver will use zpool_ops.evict |
| 370 | * in its implementation of zpool_driver.shrink. It could do internal |
| 371 | * defragmentation instead. |
| 372 | * |
| 373 | * Returns: true if potentially evictable; false otherwise. |
| 374 | */ |
| 375 | bool zpool_evictable(struct zpool *zpool) |
| 376 | { |
Johannes Weiner | 6a05aa3 | 2022-11-28 11:16:11 -0800 | [diff] [blame] | 377 | return zpool->driver->shrink; |
Yu Zhao | 9c3760e | 2018-01-31 16:19:59 -0800 | [diff] [blame] | 378 | } |
| 379 | |
Tian Tao | fc6697a | 2021-02-25 17:18:17 -0800 | [diff] [blame] | 380 | /** |
| 381 | * zpool_can_sleep_mapped - Test if zpool can sleep when do mapped. |
| 382 | * @zpool: The zpool to test |
| 383 | * |
Sergey Senozhatsky | 8d9b637 | 2022-11-22 12:30:22 +0900 | [diff] [blame] | 384 | * Some allocators enter non-preemptible context in ->map() callback (e.g. |
| 385 | * disable pagefaults) and exit that context in ->unmap(), which limits what |
| 386 | * we can do with the mapped object. For instance, we cannot wait for |
| 387 | * asynchronous crypto API to decompress such an object or take mutexes |
| 388 | * since those will call into the scheduler. This function tells us whether |
| 389 | * we use such an allocator. |
| 390 | * |
Tian Tao | fc6697a | 2021-02-25 17:18:17 -0800 | [diff] [blame] | 391 | * Returns: true if zpool can sleep; false otherwise. |
| 392 | */ |
| 393 | bool zpool_can_sleep_mapped(struct zpool *zpool) |
| 394 | { |
Johannes Weiner | 6a05aa3 | 2022-11-28 11:16:11 -0800 | [diff] [blame] | 395 | return zpool->driver->sleep_mapped; |
Tian Tao | fc6697a | 2021-02-25 17:18:17 -0800 | [diff] [blame] | 396 | } |
| 397 | |
Dan Streetman | af8d417 | 2014-08-06 16:08:36 -0700 | [diff] [blame] | 398 | MODULE_AUTHOR("Dan Streetman <ddstreet@ieee.org>"); |
| 399 | MODULE_DESCRIPTION("Common API for compressed memory storage"); |