[PATCH 3/3] fscache: Print cookie debugging information

From: David Howells
Date: Mon Mar 11 2019 - 10:51:11 EST



---

fs/afs/cache.c | 11 +++++++++++
fs/fscache/cookie.c | 7 +++++--
fs/nfs/fscache-index.c | 11 +++++++++++
include/linux/fscache.h | 2 ++
4 files changed, 29 insertions(+), 2 deletions(-)

diff --git a/fs/afs/cache.c b/fs/afs/cache.c
index f6d0a21e8052..c16b10dcf895 100644
--- a/fs/afs/cache.c
+++ b/fs/afs/cache.c
@@ -32,10 +32,21 @@ struct fscache_cookie_def afs_volume_cache_index_def = {
.type = FSCACHE_COOKIE_TYPE_INDEX,
};

+static void afs_vnode_print_cookie(void *cookie_netfs_data, char prefix)
+{
+ struct afs_vnode *vnode = cookie_netfs_data;
+
+ pr_err("kAFS : %c-vnode %llx:%llx:%x\n",
+ prefix, vnode->fid.vid, vnode->fid.vnode, vnode->fid.unique);
+ pr_err("kAFS : %c-vol v=%p %llx\n",
+ prefix, vnode->volume, vnode->volume->vid);
+}
+
struct fscache_cookie_def afs_vnode_cache_index_def = {
.name = "AFS.vnode",
.type = FSCACHE_COOKIE_TYPE_DATAFILE,
.check_aux = afs_vnode_cache_check_aux,
+ .print = afs_vnode_print_cookie,
};

/*
diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
index 6931e45b7d59..50db256e6593 100644
--- a/fs/fscache/cookie.c
+++ b/fs/fscache/cookie.c
@@ -41,8 +41,9 @@ static void fscache_print_cookie(struct fscache_cookie *cookie, char prefix)
prefix, cookie, cookie->parent, cookie->flags,
atomic_read(&cookie->n_children),
atomic_read(&cookie->n_active));
- pr_err("%c-cookie d=%p n=%p\n",
- prefix, cookie->def, cookie->netfs_data);
+ pr_err("%c-cookie d=%p n=%p [%s]\n",
+ prefix, cookie->def, cookie->netfs_data,
+ cookie->def ? cookie->def->name : "");

object = READ_ONCE(cookie->backing_objects.first);
if (object)
@@ -55,6 +56,8 @@ static void fscache_print_cookie(struct fscache_cookie *cookie, char prefix)
for (loop = 0; loop < cookie->key_len; loop++)
pr_cont("%02x", k[loop]);
pr_cont("'\n");
+ if (cookie->def && cookie->def->print)
+ cookie->def->print(cookie->netfs_data, prefix);
}

void fscache_free_cookie(struct fscache_cookie *cookie)
diff --git a/fs/nfs/fscache-index.c b/fs/nfs/fscache-index.c
index 666415d13d52..bba6753cdfb7 100644
--- a/fs/nfs/fscache-index.c
+++ b/fs/nfs/fscache-index.c
@@ -124,6 +124,16 @@ static void nfs_fh_put_context(void *cookie_netfs_data, void *context)
put_nfs_open_context(context);
}

+static void nfs_inode_print_cookie(void *cookie_netfs_data, char prefix)
+{
+ struct nfs_inode *nfsi = cookie_netfs_data;
+ struct inode *i = &nfsi->vfs_inode;
+
+ pr_err("NFS : %c-nfs fl=%lx cv=%lx ii=%lx if=%x sb=%p sf=%lx\n",
+ prefix, nfsi->flags, nfsi->cache_validity,
+ i->i_ino, i->i_flags, i->i_sb, i->i_sb->s_flags);
+}
+
/*
* Define the inode object for FS-Cache. This is used to describe an inode
* object to fscache_acquire_cookie(). It is keyed by the NFS file handle for
@@ -139,4 +149,5 @@ const struct fscache_cookie_def nfs_fscache_inode_object_def = {
.check_aux = nfs_fscache_inode_check_aux,
.get_context = nfs_fh_get_context,
.put_context = nfs_fh_put_context,
+ .print = nfs_inode_print_cookie,
};
diff --git a/include/linux/fscache.h b/include/linux/fscache.h
index 84b90a79d75a..84525722522e 100644
--- a/include/linux/fscache.h
+++ b/include/linux/fscache.h
@@ -114,6 +114,8 @@ struct fscache_cookie_def {
void (*mark_page_cached)(void *cookie_netfs_data,
struct address_space *mapping,
struct page *page);
+
+ void (*print)(void *cookie_netfs_data, char prefix);
};

/*