1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* 3 * zpool memory storage api 4 * 5 * Copyright (C) 2014 Dan Streetman 6 * 7 * This is a common frontend for the zswap compressed memory storage 8 * implementations. 9 */ 10 11 #ifndef _ZPOOL_H_ 12 #define _ZPOOL_H_ 13 14 struct zpool; 15 16 bool zpool_has_pool(char *type); 17 18 struct zpool *zpool_create_pool(const char *type, const char *name, gfp_t gfp); 19 20 const char *zpool_get_type(struct zpool *pool); 21 22 void zpool_destroy_pool(struct zpool *pool); 23 24 bool zpool_malloc_support_movable(struct zpool *pool); 25 26 int zpool_malloc(struct zpool *pool, size_t size, gfp_t gfp, 27 unsigned long *handle); 28 29 void zpool_free(struct zpool *pool, unsigned long handle); 30 31 void *zpool_obj_read_begin(struct zpool *zpool, unsigned long handle, 32 void *local_copy); 33 34 void zpool_obj_read_end(struct zpool *zpool, unsigned long handle, 35 void *handle_mem); 36 37 void zpool_obj_write(struct zpool *zpool, unsigned long handle, 38 void *handle_mem, size_t mem_len); 39 40 u64 zpool_get_total_pages(struct zpool *pool); 41 42 43 /** 44 * struct zpool_driver - driver implementation for zpool 45 * @type: name of the driver. 46 * @list: entry in the list of zpool drivers. 47 * @create: create a new pool. 48 * @destroy: destroy a pool. 49 * @malloc: allocate mem from a pool. 50 * @free: free mem from a pool. 51 * @sleep_mapped: whether zpool driver can sleep during map. 52 * @map: map a handle. 53 * @unmap: unmap a handle. 54 * @total_size: get total size of a pool. 55 * 56 * This is created by a zpool implementation and registered 57 * with zpool. 58 */ 59 struct zpool_driver { 60 char *type; 61 struct module *owner; 62 atomic_t refcount; 63 struct list_head list; 64 65 void *(*create)(const char *name, gfp_t gfp); 66 void (*destroy)(void *pool); 67 68 bool malloc_support_movable; 69 int (*malloc)(void *pool, size_t size, gfp_t gfp, 70 unsigned long *handle); 71 void (*free)(void *pool, unsigned long handle); 72 73 void *(*obj_read_begin)(void *pool, unsigned long handle, 74 void *local_copy); 75 void (*obj_read_end)(void *pool, unsigned long handle, 76 void *handle_mem); 77 void (*obj_write)(void *pool, unsigned long handle, 78 void *handle_mem, size_t mem_len); 79 80 u64 (*total_pages)(void *pool); 81 }; 82 83 void zpool_register_driver(struct zpool_driver *driver); 84 85 int zpool_unregister_driver(struct zpool_driver *driver); 86 87 bool zpool_can_sleep_mapped(struct zpool *pool); 88 89 #endif 90