Skip to content

Commit 4fbf429

Browse files
committed
FS-Cache: Allow the current state of all objects to be dumped
Allow the current state of all fscache objects to be dumped by doing: cat /proc/fs/fscache/objects By default, all objects and all fields will be shown. This can be restricted by adding a suitable key to one of the caller's keyrings (such as the session keyring): keyctl add user fscache:objlist "<restrictions>" @s The <restrictions> are: K Show hexdump of object key (don't show if not given) A Show hexdump of object aux data (don't show if not given) And paired restrictions: C Show objects that have a cookie c Show objects that don't have a cookie B Show objects that are busy b Show objects that aren't busy W Show objects that have pending writes w Show objects that don't have pending writes R Show objects that have outstanding reads r Show objects that don't have outstanding reads S Show objects that have slow work queued s Show objects that don't have slow work queued If neither side of a restriction pair is given, then both are implied. For example: keyctl add user fscache:objlist KB @s shows objects that are busy, and lists their object keys, but does not dump their auxiliary data. It also implies "CcWwRrSs", but as 'B' is given, 'b' is not implied. Signed-off-by: David Howells <dhowells@redhat.com>
1 parent 440f0af commit 4fbf429

14 files changed

Lines changed: 578 additions & 3 deletions

File tree

‎Documentation/filesystems/caching/fscache.txt‎

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,87 @@ proc files.
299299
jiffy range covered, and the SECS field the equivalent number of seconds.
300300

301301

302+
===========
303+
OBJECT LIST
304+
===========
305+
306+
If CONFIG_FSCACHE_OBJECT_LIST is enabled, the FS-Cache facility will maintain a
307+
list of all the objects currently allocated and allow them to be viewed
308+
through:
309+
310+
/proc/fs/fscache/objects
311+
312+
This will look something like:
313+
314+
[root@andromeda ~]# head /proc/fs/fscache/objects
315+
OBJECT PARENT STAT CHLDN OPS OOP IPR EX READS EM EV F S | NETFS_COOKIE_DEF TY FL NETFS_DATA OBJECT_KEY, AUX_DATA
316+
======== ======== ==== ===== === === === == ===== == == = = | ================ == == ================ ================
317+
17e4b 2 ACTV 0 0 0 0 0 0 7b 4 0 8 | NFS.fh DT 0 ffff88001dd82820 010006017edcf8bbc93b43298fdfbe71e50b57b13a172c0117f38472, e567634700000000000000000000000063f2404a000000000000000000000000c9030000000000000000000063f2404a
318+
1693a 2 ACTV 0 0 0 0 0 0 7b 4 0 8 | NFS.fh DT 0 ffff88002db23380 010006017edcf8bbc93b43298fdfbe71e50b57b1e0162c01a2df0ea6, 420ebc4a000000000000000000000000420ebc4a0000000000000000000000000e1801000000000000000000420ebc4a
319+
320+
where the first set of columns before the '|' describe the object:
321+
322+
COLUMN DESCRIPTION
323+
======= ===============================================================
324+
OBJECT Object debugging ID (appears as OBJ%x in some debug messages)
325+
PARENT Debugging ID of parent object
326+
STAT Object state
327+
CHLDN Number of child objects of this object
328+
OPS Number of outstanding operations on this object
329+
OOP Number of outstanding child object management operations
330+
IPR
331+
EX Number of outstanding exclusive operations
332+
READS Number of outstanding read operations
333+
EM Object's event mask
334+
EV Events raised on this object
335+
F Object flags
336+
S Object slow-work work item flags
337+
338+
and the second set of columns describe the object's cookie, if present:
339+
340+
COLUMN DESCRIPTION
341+
=============== =======================================================
342+
NETFS_COOKIE_DEF Name of netfs cookie definition
343+
TY Cookie type (IX - index, DT - data, hex - special)
344+
FL Cookie flags
345+
NETFS_DATA Netfs private data stored in the cookie
346+
OBJECT_KEY Object key } 1 column, with separating comma
347+
AUX_DATA Object aux data } presence may be configured
348+
349+
The data shown may be filtered by attaching the a key to an appropriate keyring
350+
before viewing the file. Something like:
351+
352+
keyctl add user fscache:objlist <restrictions> @s
353+
354+
where <restrictions> are a selection of the following letters:
355+
356+
K Show hexdump of object key (don't show if not given)
357+
A Show hexdump of object aux data (don't show if not given)
358+
359+
and the following paired letters:
360+
361+
C Show objects that have a cookie
362+
c Show objects that don't have a cookie
363+
B Show objects that are busy
364+
b Show objects that aren't busy
365+
W Show objects that have pending writes
366+
w Show objects that don't have pending writes
367+
R Show objects that have outstanding reads
368+
r Show objects that don't have outstanding reads
369+
S Show objects that have slow work queued
370+
s Show objects that don't have slow work queued
371+
372+
If neither side of a letter pair is given, then both are implied. For example:
373+
374+
keyctl add user fscache:objlist KB @s
375+
376+
shows objects that are busy, and lists their object keys, but does not dump
377+
their auxiliary data. It also implies "CcWwRrSs", but as 'B' is given, 'b' is
378+
not implied.
379+
380+
By default all objects and all fields will be shown.
381+
382+
302383
=========
303384
DEBUGGING
304385
=========

‎fs/cachefiles/interface.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,7 @@ static void cachefiles_put_object(struct fscache_object *_object)
331331
}
332332

333333
cache = object->fscache.cache;
334+
fscache_object_destroy(&object->fscache);
334335
kmem_cache_free(cachefiles_object_jar, object);
335336
fscache_object_destroyed(cache);
336337
}

‎fs/cachefiles/rdwr.c‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,8 @@ int cachefiles_read_or_alloc_page(struct fscache_retrieval *op,
333333

334334
shift = PAGE_SHIFT - inode->i_sb->s_blocksize_bits;
335335

336-
op->op.flags = FSCACHE_OP_FAST;
336+
op->op.flags &= FSCACHE_OP_KEEP_FLAGS;
337+
op->op.flags |= FSCACHE_OP_FAST;
337338
op->op.processor = cachefiles_read_copier;
338339

339340
pagevec_init(&pagevec, 0);
@@ -639,7 +640,8 @@ int cachefiles_read_or_alloc_pages(struct fscache_retrieval *op,
639640

640641
pagevec_init(&pagevec, 0);
641642

642-
op->op.flags = FSCACHE_OP_FAST;
643+
op->op.flags &= FSCACHE_OP_KEEP_FLAGS;
644+
op->op.flags |= FSCACHE_OP_FAST;
643645
op->op.processor = cachefiles_read_copier;
644646

645647
INIT_LIST_HEAD(&backpages);

‎fs/fscache/Kconfig‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,10 @@ config FSCACHE_DEBUG
5454
enabled by setting bits in /sys/modules/fscache/parameter/debug.
5555

5656
See Documentation/filesystems/caching/fscache.txt for more information.
57+
58+
config FSCACHE_OBJECT_LIST
59+
bool "Maintain global object list for debugging purposes"
60+
depends on FSCACHE && PROC_FS
61+
help
62+
Maintain a global list of active fscache objects that can be
63+
retrieved through /proc/fs/fscache/objects for debugging purposes

‎fs/fscache/Makefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@ fscache-y := \
1515
fscache-$(CONFIG_PROC_FS) += proc.o
1616
fscache-$(CONFIG_FSCACHE_STATS) += stats.o
1717
fscache-$(CONFIG_FSCACHE_HISTOGRAM) += histogram.o
18+
fscache-$(CONFIG_FSCACHE_OBJECT_LIST) += object-list.o
1819

1920
obj-$(CONFIG_FSCACHE) := fscache.o

‎fs/fscache/cache.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ int fscache_add_cache(struct fscache_cache *cache,
263263
spin_lock(&cache->object_list_lock);
264264
list_add_tail(&ifsdef->cache_link, &cache->object_list);
265265
spin_unlock(&cache->object_list_lock);
266+
fscache_objlist_add(ifsdef);
266267

267268
/* add the cache's netfs definition index object to the top level index
268269
* cookie as a known backing object */

‎fs/fscache/cookie.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,8 @@ static int fscache_attach_object(struct fscache_cookie *cookie,
349349
object->cookie = cookie;
350350
atomic_inc(&cookie->usage);
351351
hlist_add_head(&object->cookie_link, &cookie->backing_objects);
352+
353+
fscache_objlist_add(object);
352354
ret = 0;
353355

354356
cant_attach_object:

‎fs/fscache/internal.h‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,23 @@ extern int fscache_wait_bit_interruptible(void *);
8888
/*
8989
* object.c
9090
*/
91+
extern const char fscache_object_states_short[FSCACHE_OBJECT__NSTATES][5];
92+
9193
extern void fscache_withdrawing_object(struct fscache_cache *,
9294
struct fscache_object *);
9395
extern void fscache_enqueue_object(struct fscache_object *);
9496

97+
/*
98+
* object-list.c
99+
*/
100+
#ifdef CONFIG_FSCACHE_OBJECT_LIST
101+
extern const struct file_operations fscache_objlist_fops;
102+
103+
extern void fscache_objlist_add(struct fscache_object *);
104+
#else
105+
#define fscache_objlist_add(object) do {} while(0)
106+
#endif
107+
95108
/*
96109
* operation.c
97110
*/

0 commit comments

Comments
 (0)