12874c5fdSThomas Gleixner/* SPDX-License-Identifier: GPL-2.0-or-later */
22d6fff63SDavid Howells/* General filesystem caching interface
32d6fff63SDavid Howells *
41e1236b8SDavid Howells * Copyright (C) 2021 Red Hat, Inc. All Rights Reserved.
52d6fff63SDavid Howells * Written by David Howells (dhowells@redhat.com)
62d6fff63SDavid Howells *
72d6fff63SDavid Howells * NOTE!!! See:
82d6fff63SDavid Howells *
9efc930faSMauro Carvalho Chehab *	Documentation/filesystems/caching/netfs-api.rst
102d6fff63SDavid Howells *
112d6fff63SDavid Howells * for a description of the network filesystem interface declared here.
122d6fff63SDavid Howells */
132d6fff63SDavid Howells
142d6fff63SDavid Howells#ifndef _LINUX_FSCACHE_H
152d6fff63SDavid Howells#define _LINUX_FSCACHE_H
162d6fff63SDavid Howells
172d6fff63SDavid Howells#include <linux/fs.h>
18b533a83fSDavid Howells#include <linux/netfs.h>
1908276bdaSDavid Howells#include <linux/writeback.h>
202d6fff63SDavid Howells
212d6fff63SDavid Howells#if defined(CONFIG_FSCACHE) || defined(CONFIG_FSCACHE_MODULE)
221e1236b8SDavid Howells#define __fscache_available (1)
231e1236b8SDavid Howells#define fscache_available() (1)
2462ab6335SDavid Howells#define fscache_volume_valid(volume) (volume)
252d6fff63SDavid Howells#define fscache_cookie_valid(cookie) (cookie)
2612bb21a2SDavid Howells#define fscache_resources_valid(cres) ((cres)->cache_priv)
2712bb21a2SDavid Howells#define fscache_cookie_enabled(cookie) (cookie && !test_bit(FSCACHE_COOKIE_DISABLED, &cookie->flags))
282d6fff63SDavid Howells#else
291e1236b8SDavid Howells#define __fscache_available (0)
301e1236b8SDavid Howells#define fscache_available() (0)
3162ab6335SDavid Howells#define fscache_volume_valid(volume) (0)
322d6fff63SDavid Howells#define fscache_cookie_valid(cookie) (0)
3312bb21a2SDavid Howells#define fscache_resources_valid(cres) (false)
342cee6fbbSDavid Howells#define fscache_cookie_enabled(cookie) (0)
352d6fff63SDavid Howells#endif
362d6fff63SDavid Howells
377f3283abSDavid Howellsstruct fscache_cookie;
387f3283abSDavid Howells
397f3283abSDavid Howells#define FSCACHE_ADV_SINGLE_CHUNK	0x01 /* The object is a single chunk of data */
407f3283abSDavid Howells#define FSCACHE_ADV_WRITE_CACHE		0x00 /* Do cache if written to locally */
417f3283abSDavid Howells#define FSCACHE_ADV_WRITE_NOCACHE	0x02 /* Don't cache if written to locally */
427f3283abSDavid Howells
43d24af13eSDavid Howells#define FSCACHE_INVAL_DIO_WRITE		0x01 /* Invalidate due to DIO write */
44d24af13eSDavid Howells
45d64f4554SDavid Howellsenum fscache_want_state {
46d64f4554SDavid Howells	FSCACHE_WANT_PARAMS,
47d64f4554SDavid Howells	FSCACHE_WANT_WRITE,
48d64f4554SDavid Howells	FSCACHE_WANT_READ,
49d64f4554SDavid Howells};
50d64f4554SDavid Howells
517f3283abSDavid Howells/*
527f3283abSDavid Howells * Data object state.
537f3283abSDavid Howells */
547f3283abSDavid Howellsenum fscache_cookie_state {
557f3283abSDavid Howells	FSCACHE_COOKIE_STATE_QUIESCENT,		/* The cookie is uncached */
567f3283abSDavid Howells	FSCACHE_COOKIE_STATE_LOOKING_UP,	/* The cache object is being looked up */
577f3283abSDavid Howells	FSCACHE_COOKIE_STATE_CREATING,		/* The cache object is being created */
587f3283abSDavid Howells	FSCACHE_COOKIE_STATE_ACTIVE,		/* The cache is active, readable and writable */
59d24af13eSDavid Howells	FSCACHE_COOKIE_STATE_INVALIDATING,	/* The cache is being invalidated */
607f3283abSDavid Howells	FSCACHE_COOKIE_STATE_FAILED,		/* The cache failed, withdraw to clear */
6112bb21a2SDavid Howells	FSCACHE_COOKIE_STATE_LRU_DISCARDING,	/* The cookie is being discarded by the LRU */
627f3283abSDavid Howells	FSCACHE_COOKIE_STATE_WITHDRAWING,	/* The cookie is being withdrawn */
637f3283abSDavid Howells	FSCACHE_COOKIE_STATE_RELINQUISHING,	/* The cookie is being relinquished */
647f3283abSDavid Howells	FSCACHE_COOKIE_STATE_DROPPED,		/* The cookie has been dropped */
657f3283abSDavid Howells#define FSCACHE_COOKIE_STATE__NR (FSCACHE_COOKIE_STATE_DROPPED + 1)
667f3283abSDavid Howells} __attribute__((mode(byte)));
677f3283abSDavid Howells
6862ab6335SDavid Howells/*
6962ab6335SDavid Howells * Volume representation cookie.
7062ab6335SDavid Howells */
7162ab6335SDavid Howellsstruct fscache_volume {
7262ab6335SDavid Howells	refcount_t			ref;
73