Skip to content

Commit 62ab633

Browse files
committed
fscache: Implement volume registration
Add functions to the fscache API to allow volumes to be acquired and relinquished by the network filesystem. A volume is an index of data storage cache objects. A volume is represented by a volume cookie in the API. A filesystem would typically create a volume for a superblock and then create per-inode cookies within it. To request a volume, the filesystem calls: struct fscache_volume * fscache_acquire_volume(const char *volume_key, const char *cache_name, const void *coherency_data, size_t coherency_len) The volume_key is a printable string used to match the volume in the cache. It should not contain any '/' characters. For AFS, for example, this would be "afs,<cellname>,<volume_id>", e.g. "afs,example.com,523001". The cache_name can be NULL, but if not it should be a string indicating the name of the cache to use if there's more than one available. The coherency data, if given, is an arbitrarily-sized blob that's attached to the volume and is compared when the volume is looked up. If it doesn't match, the old volume is judged to be out of date and it and everything within it is discarded. Acquiring a volume twice concurrently is disallowed, though the function will wait if an old volume cookie is being relinquishing. When a network filesystem has finished with a volume, it should return the volume cookie by calling: void fscache_relinquish_volume(struct fscache_volume *volume, const void *coherency_data, bool invalidate) If invalidate is true, the entire volume will be discarded; if false, the volume will be synced and the coherency data will be updated. Changes ======= ver #4: - Removed an extraneous param from kdoc on fscache_relinquish_volume()[3]. ver #3: - fscache_hash()'s size parameter is now in bytes. Use __le32 as the unit to round up to. - When comparing cookies, simply see if the attributes are the same rather than subtracting them to produce a strcmp-style return[2]. - Make the coherency data an arbitrary blob rather than a u64, but don't store it for the moment. ver #2: - Fix error check[1]. - Make a fscache_acquire_volume() return errors, including EBUSY if a conflicting volume cookie already exists. No error is printed now - that's left to the netfs. Signed-off-by: David Howells <dhowells@redhat.com> Reviewed-by: Jeff Layton <jlayton@kernel.org> cc: linux-cachefs@redhat.com Link: https://lore.kernel.org/r/20211203095608.GC2480@kili/ [1] Link: https://lore.kernel.org/r/CAHk-=whtkzB446+hX0zdLsdcUJsJ=8_-0S1mE_R+YurThfUbLA@mail.gmail.com/ [2] Link: https://lore.kernel.org/r/20211220224646.30e8205c@canb.auug.org.au/ [3] Link: https://lore.kernel.org/r/163819588944.215744.1629085755564865996.stgit@warthog.procyon.org.uk/ # v1 Link: https://lore.kernel.org/r/163906890630.143852.13972180614535611154.stgit@warthog.procyon.org.uk/ # v2 Link: https://lore.kernel.org/r/163967086836.1823006.8191672796841981763.stgit@warthog.procyon.org.uk/ # v3 Link: https://lore.kernel.org/r/164021495816.640689.4403156093668590217.stgit@warthog.procyon.org.uk/ # v4
1 parent 9549332 commit 62ab633

File tree

7 files changed

+516
-2
lines changed

7 files changed

+516
-2
lines changed

fs/fscache/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55

66
fscache-y := \
77
cache.o \
8-
main.o
8+
main.o \
9+
volume.o
910

1011
fscache-$(CONFIG_PROC_FS) += proc.o
1112
fscache-$(CONFIG_FSCACHE_STATS) += stats.o

fs/fscache/internal.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ extern void fscache_proc_cleanup(void);
7272
* stats.c
7373
*/
7474
#ifdef CONFIG_FSCACHE_STATS
75+
extern atomic_t fscache_n_volumes;
76+
extern atomic_t fscache_n_volumes_collision;
77+
extern atomic_t fscache_n_volumes_nomem;
7578

7679
static inline void fscache_stat(atomic_t *stat)
7780
{
@@ -93,6 +96,17 @@ int fscache_stats_show(struct seq_file *m, void *v);
9396
#define fscache_stat_d(stat) do {} while (0)
9497
#endif
9598

99+
/*
100+
* volume.c
101+
*/
102+
extern const struct seq_operations fscache_volumes_seq_ops;
103+
104+
struct fscache_volume *fscache_get_volume(struct fscache_volume *volume,
105+
enum fscache_volume_trace where);
106+
void fscache_put_volume(struct fscache_volume *volume,
107+
enum fscache_volume_trace where);
108+
void fscache_create_volume(struct fscache_volume *volume, bool wait);
109+
96110

97111
/*****************************************************************************/
98112
/*

fs/fscache/proc.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ int __init fscache_proc_init(void)
2323
&fscache_caches_seq_ops))
2424
goto error;
2525

26+
if (!proc_create_seq("fs/fscache/volumes", S_IFREG | 0444, NULL,
27+
&fscache_volumes_seq_ops))
28+
goto error;
29+
2630
#ifdef CONFIG_FSCACHE_STATS
2731
if (!proc_create_single("fs/fscache/stats", S_IFREG | 0444, NULL,
2832
fscache_stats_show))

fs/fscache/stats.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,24 @@
1010
#include <linux/seq_file.h>
1111
#include "internal.h"
1212

13+
/*
14+
* operation counters
15+
*/
16+
atomic_t fscache_n_volumes;
17+
atomic_t fscache_n_volumes_collision;
18+
atomic_t fscache_n_volumes_nomem;
19+
1320
/*
1421
* display the general statistics
1522
*/
1623
int fscache_stats_show(struct seq_file *m, void *v)
1724
{
1825
seq_puts(m, "FS-Cache statistics\n");
26+
seq_printf(m, "Cookies: v=%d vcol=%u voom=%u\n",
27+
atomic_read(&fscache_n_volumes),
28+
atomic_read(&fscache_n_volumes_collision),
29+
atomic_read(&fscache_n_volumes_nomem)
30+
);
1931

2032
netfs_stats_show(m);
2133
return 0;

0 commit comments

Comments
 (0)