at v6.15 2.2 kB view raw
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 14struct zpool; 15 16bool zpool_has_pool(char *type); 17 18struct zpool *zpool_create_pool(const char *type, const char *name, gfp_t gfp); 19 20const char *zpool_get_type(struct zpool *pool); 21 22void zpool_destroy_pool(struct zpool *pool); 23 24int zpool_malloc(struct zpool *pool, size_t size, gfp_t gfp, 25 unsigned long *handle); 26 27void zpool_free(struct zpool *pool, unsigned long handle); 28 29void *zpool_obj_read_begin(struct zpool *zpool, unsigned long handle, 30 void *local_copy); 31 32void zpool_obj_read_end(struct zpool *zpool, unsigned long handle, 33 void *handle_mem); 34 35void zpool_obj_write(struct zpool *zpool, unsigned long handle, 36 void *handle_mem, size_t mem_len); 37 38u64 zpool_get_total_pages(struct zpool *pool); 39 40 41/** 42 * struct zpool_driver - driver implementation for zpool 43 * @type: name of the driver. 44 * @list: entry in the list of zpool drivers. 45 * @create: create a new pool. 46 * @destroy: destroy a pool. 47 * @malloc: allocate mem from a pool. 48 * @free: free mem from a pool. 49 * @sleep_mapped: whether zpool driver can sleep during map. 50 * @map: map a handle. 51 * @unmap: unmap a handle. 52 * @total_size: get total size of a pool. 53 * 54 * This is created by a zpool implementation and registered 55 * with zpool. 56 */ 57struct zpool_driver { 58 char *type; 59 struct module *owner; 60 atomic_t refcount; 61 struct list_head list; 62 63 void *(*create)(const char *name, gfp_t gfp); 64 void (*destroy)(void *pool); 65 66 int (*malloc)(void *pool, size_t size, gfp_t gfp, 67 unsigned long *handle); 68 void (*free)(void *pool, unsigned long handle); 69 70 void *(*obj_read_begin)(void *pool, unsigned long handle, 71 void *local_copy); 72 void (*obj_read_end)(void *pool, unsigned long handle, 73 void *handle_mem); 74 void (*obj_write)(void *pool, unsigned long handle, 75 void *handle_mem, size_t mem_len); 76 77 u64 (*total_pages)(void *pool); 78}; 79 80void zpool_register_driver(struct zpool_driver *driver); 81 82int zpool_unregister_driver(struct zpool_driver *driver); 83 84bool zpool_can_sleep_mapped(struct zpool *pool); 85 86#endif