From: David Howells <dhowells@redhat.com>
To: linux-afs@lists.infradead.org
Cc: dhowells@redhat.com, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH 02/11] rxrpc: Do procfs lists through objcache
Date: Mon, 07 Mar 2016 14:38:13 +0000 [thread overview]
Message-ID: <20160307143813.18567.5819.stgit@warthog.procyon.org.uk> (raw)
In-Reply-To: <20160307143759.18567.8234.stgit@warthog.procyon.org.uk>
Use the object cache primary hash to provide lists of RxRPC objects through
/proc/net/ for all caches where desired. Each user of the cache just needs
to provide a show function in its objcache struct and register the proc
file with objcache_seq_fops as its file operations.
Signed-off-by: David Howells <dhowells@redhat.com>
---
net/rxrpc/objcache.c | 104 ++++++++++++++++++++++++++++++++++++++++++++++++++
net/rxrpc/objcache.h | 8 ++++
2 files changed, 112 insertions(+)
diff --git a/net/rxrpc/objcache.c b/net/rxrpc/objcache.c
index 74eed8ce5894..e74f8c3c4119 100644
--- a/net/rxrpc/objcache.c
+++ b/net/rxrpc/objcache.c
@@ -11,6 +11,8 @@
#include <linux/sched.h>
#include <linux/hash.h>
+#include <linux/proc_fs.h>
+#include <linux/seq_file.h>
#include "ar-internal.h"
#include "objcache.h"
@@ -475,3 +477,105 @@ void objcache_clear(struct objcache *cache)
_leave("");
}
+
+/*
+ * Generate a list of cached objects in /proc/net/x
+ */
+static void *objcache_seq_start(struct seq_file *seq, loff_t *_pos)
+ __acquires(rcu)
+{
+ struct objcache *cache = seq->private;
+ struct hlist_head *hash;
+ loff_t pos_l = *_pos;
+ unsigned pos = pos_l, bucket;
+ void *ret;
+
+ if (*_pos > UINT_MAX)
+ return NULL;
+ bucket = pos >> 16;
+ pos &= 0xffff;
+
+ rcu_read_lock();
+
+ do {
+ hash = &cache->hash_table[bucket];
+ if (bucket == 0)
+ ret = seq_hlist_start_head(hash, pos);
+ else
+ ret = seq_hlist_start(hash, pos);
+ } while (!ret && (bucket++,
+ *_pos = bucket << 16,
+ bucket < cache->nr_buckets));
+
+ return ret;
+}
+
+static void *objcache_seq_next(struct seq_file *seq, void *v, loff_t *_pos)
+{
+ struct objcache *cache = seq->private;
+ struct hlist_head *hash;
+ unsigned bucket;
+ void *ret;
+
+ if (*_pos > UINT_MAX)
+ return NULL;
+ bucket = *_pos >> 16;
+ hash = &cache->hash_table[bucket];
+ ret = seq_hlist_next(v, hash, _pos);
+ if (ret)
+ return ret;
+
+ while (bucket++,
+ *_pos = bucket << 16,
+ bucket < cache->nr_buckets
+ ) {
+ hash = &cache->hash_table[bucket];
+ ret = seq_hlist_start(hash, 0);
+ if (ret)
+ break;
+ }
+ return ret;
+}
+
+static void objcache_seq_stop(struct seq_file *seq, void *v)
+ __releases(rcu)
+{
+ rcu_read_unlock();
+}
+
+static int objcache_seq_show(struct seq_file *seq, void *v)
+{
+ struct objcache *cache = seq->private;
+ struct obj_node *obj = v;
+
+ return cache->seq_show(seq, obj);
+}
+
+static const struct seq_operations objcache_seq_ops = {
+ .start = objcache_seq_start,
+ .next = objcache_seq_next,
+ .stop = objcache_seq_stop,
+ .show = objcache_seq_show,
+};
+
+static int objcache_seq_open(struct inode *inode, struct file *file)
+{
+ struct objcache *cache = PDE_DATA(inode);
+ struct seq_file *seq;
+ int ret;
+
+ ret = seq_open(file, &objcache_seq_ops);
+ if (ret == 0) {
+ seq = file->private_data;
+ seq->private = cache;
+ }
+ return ret;
+}
+
+const struct file_operations objcache_seq_fops = {
+ .owner = THIS_MODULE,
+ .open = objcache_seq_open,
+ .read = seq_read,
+ .llseek = seq_lseek,
+ .release = seq_release,
+};
diff --git a/net/rxrpc/objcache.h b/net/rxrpc/objcache.h
index 770ec924a6d2..a3799eb4c857 100644
--- a/net/rxrpc/objcache.h
+++ b/net/rxrpc/objcache.h
@@ -52,6 +52,11 @@ struct objcache {
unsigned long (*hash_key_2)(const void *);
int (*cmp_key_2)(const struct obj_node *, const void *);
+ /* If the cache should be visible through /proc, the following
+ * should be implemented.
+ */
+ int (*seq_show)(struct seq_file *, void *);
+
/* Internal data */
spinlock_t lock;
atomic_t count;
@@ -64,6 +69,7 @@ struct objcache {
time64_t gc_next_run;
unsigned gc_bucket;
unsigned gc_last_bucket;
+ struct seq_operations seq_ops;
};
static inline bool objcache_get_maybe(struct obj_node *obj)
@@ -86,4 +92,6 @@ extern void objcache_put(struct objcache *, struct obj_node *);
extern void objcache_obj_rcu_done(struct objcache *);
extern void objcache_clear(struct objcache *);
+extern const struct file_operations objcache_seq_fops;
+
#endif /* _OBJCACHE_H */
next prev parent reply other threads:[~2016-03-07 14:42 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-07 14:37 [PATCH 00/11] RxRPC: Rewrite part 2 David Howells
2016-03-07 14:38 ` [PATCH 01/11] rxrpc: Add a common object cache David Howells
2016-03-07 18:42 ` David Miller
2016-03-07 22:45 ` David Howells
2016-03-08 4:07 ` David Miller
2016-03-08 11:39 ` David Howells
2016-03-08 20:13 ` David Miller
2016-03-08 21:11 ` David Howells
2016-03-09 3:00 ` David Miller
2016-03-08 13:02 ` David Howells
2016-03-08 20:15 ` David Miller
2016-03-07 14:38 ` David Howells [this message]
2016-03-07 14:38 ` [PATCH 03/11] rxrpc: Separate local endpoint object handling out into its own file David Howells
2016-03-07 14:38 ` [PATCH 04/11] rxrpc: Implement local endpoint cache David Howells
2016-03-07 14:38 ` [PATCH 05/11] rxrpc: procfs file to list local endpoints David Howells
2016-03-07 14:38 ` [PATCH 06/11] rxrpc: Rename ar-local.c to local-event.c David Howells
2016-03-07 14:38 ` [PATCH 07/11] rxrpc: Rename ar-peer.c to peer-object.c David Howells
2016-03-07 14:38 ` [PATCH 08/11] rxrpc: Implement peer endpoint cache David Howells
2016-03-07 14:39 ` [PATCH 09/11] rxrpc: Add /proc/net/rxrpc_peers to display the known remote endpoints David Howells
2016-03-07 14:39 ` [PATCH 10/11] rxrpc: Rename ar-error.c to peer-event.c David Howells
2016-03-07 14:39 ` [PATCH 11/11] rxrpc: Rename rxrpc_UDP_error_report() to rxrpc_error_report() David Howells
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160307143813.18567.5819.stgit@warthog.procyon.org.uk \
--to=dhowells@redhat.com \
--cc=linux-afs@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®