1 /* SPDX-License-Identifier: GPL-2.0-or-later */ 2 /* General filesystem caching backing cache interface 3 * 4 * Copyright (C) 2021 Red Hat, Inc. All Rights Reserved. 5 * Written by David Howells ([email protected]) 6 * 7 * NOTE!!! See: 8 * 9 * Documentation/filesystems/caching/backend-api.rst 10 * 11 * for a description of the cache backend interface declared here. 12 */ 13 14 #ifndef _LINUX_FSCACHE_CACHE_H 15 #define _LINUX_FSCACHE_CACHE_H 16 17 #include <linux/fscache.h> 18 19 enum fscache_cache_trace; 20 enum fscache_cookie_trace; 21 enum fscache_access_trace; 22 23 enum fscache_cache_state { 24 FSCACHE_CACHE_IS_NOT_PRESENT, /* No cache is present for this name */ 25 FSCACHE_CACHE_IS_PREPARING, /* A cache is preparing to come live */ 26 FSCACHE_CACHE_IS_ACTIVE, /* Attached cache is active and can be used */ 27 FSCACHE_CACHE_GOT_IOERROR, /* Attached cache stopped on I/O error */ 28 FSCACHE_CACHE_IS_WITHDRAWN, /* Attached cache is being withdrawn */ 29 #define NR__FSCACHE_CACHE_STATE (FSCACHE_CACHE_IS_WITHDRAWN + 1) 30 }; 31 32 /* 33 * Cache cookie. 34 */ 35 struct fscache_cache { 36 struct list_head cache_link; /* Link in cache list */ 37 void *cache_priv; /* Private cache data (or NULL) */ 38 refcount_t ref; 39 atomic_t n_volumes; /* Number of active volumes; */ 40 atomic_t n_accesses; /* Number of in-progress accesses on the cache */ 41 atomic_t object_count; /* no. of live objects in this cache */ 42 unsigned int debug_id; 43 enum fscache_cache_state state; 44 char *name; 45 }; 46 47 extern struct workqueue_struct *fscache_wq; 48 49 /* 50 * out-of-line cache backend functions 51 */ 52 extern struct rw_semaphore fscache_addremove_sem; 53 extern struct fscache_cache *fscache_acquire_cache(const char *name); 54 extern void fscache_relinquish_cache(struct fscache_cache *cache); 55 56 extern void fscache_end_volume_access(struct fscache_volume *volume, 57 struct fscache_cookie *cookie, 58 enum fscache_access_trace why); 59 60 extern struct fscache_cookie *fscache_get_cookie(struct fscache_cookie *cookie, 61 enum fscache_cookie_trace where); 62 extern void fscache_put_cookie(struct fscache_cookie *cookie, 63 enum fscache_cookie_trace where); 64 extern void fscache_end_cookie_access(struct fscache_cookie *cookie, 65 enum fscache_access_trace why); 66 extern void fscache_set_cookie_state(struct fscache_cookie *cookie, 67 enum fscache_cookie_state state); 68 69 /** 70 * fscache_get_key - Get a pointer to the cookie key 71 * @cookie: The cookie to query 72 * 73 * Return a pointer to the where a cookie's key is stored. 74 */ 75 static inline void *fscache_get_key(struct fscache_cookie *cookie) 76 { 77 if (cookie->key_len <= sizeof(cookie->inline_key)) 78 return cookie->inline_key; 79 else 80 return cookie->key; 81 } 82 83 #endif /* _LINUX_FSCACHE_CACHE_H */ 84