Thomas Gleixner | b4d0d23 | 2019-05-20 19:08:01 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
David Howells | 4fbf429 | 2009-11-19 18:11:04 +0000 | [diff] [blame] | 2 | /* Global fscache object list maintainer and viewer |
| 3 | * |
| 4 | * Copyright (C) 2009 Red Hat, Inc. All Rights Reserved. |
| 5 | * Written by David Howells (dhowells@redhat.com) |
David Howells | 4fbf429 | 2009-11-19 18:11:04 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #define FSCACHE_DEBUG_LEVEL COOKIE |
| 9 | #include <linux/module.h> |
Alexey Dobriyan | 97a3253 | 2020-02-03 17:37:17 -0800 | [diff] [blame] | 10 | #include <linux/proc_fs.h> |
David Howells | 4fbf429 | 2009-11-19 18:11:04 +0000 | [diff] [blame] | 11 | #include <linux/seq_file.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 12 | #include <linux/slab.h> |
David Howells | 4fbf429 | 2009-11-19 18:11:04 +0000 | [diff] [blame] | 13 | #include <linux/key.h> |
| 14 | #include <keys/user-type.h> |
| 15 | #include "internal.h" |
| 16 | |
| 17 | static struct rb_root fscache_object_list; |
| 18 | static DEFINE_RWLOCK(fscache_object_list_lock); |
| 19 | |
| 20 | struct fscache_objlist_data { |
| 21 | unsigned long config; /* display configuration */ |
| 22 | #define FSCACHE_OBJLIST_CONFIG_KEY 0x00000001 /* show object keys */ |
| 23 | #define FSCACHE_OBJLIST_CONFIG_AUX 0x00000002 /* show object auxdata */ |
| 24 | #define FSCACHE_OBJLIST_CONFIG_COOKIE 0x00000004 /* show objects with cookies */ |
| 25 | #define FSCACHE_OBJLIST_CONFIG_NOCOOKIE 0x00000008 /* show objects without cookies */ |
| 26 | #define FSCACHE_OBJLIST_CONFIG_BUSY 0x00000010 /* show busy objects */ |
| 27 | #define FSCACHE_OBJLIST_CONFIG_IDLE 0x00000020 /* show idle objects */ |
| 28 | #define FSCACHE_OBJLIST_CONFIG_PENDWR 0x00000040 /* show objects with pending writes */ |
| 29 | #define FSCACHE_OBJLIST_CONFIG_NOPENDWR 0x00000080 /* show objects without pending writes */ |
| 30 | #define FSCACHE_OBJLIST_CONFIG_READS 0x00000100 /* show objects with active reads */ |
| 31 | #define FSCACHE_OBJLIST_CONFIG_NOREADS 0x00000200 /* show objects without active reads */ |
| 32 | #define FSCACHE_OBJLIST_CONFIG_EVENTS 0x00000400 /* show objects with events */ |
| 33 | #define FSCACHE_OBJLIST_CONFIG_NOEVENTS 0x00000800 /* show objects without no events */ |
Tejun Heo | 8b8edef | 2010-07-20 22:09:01 +0200 | [diff] [blame] | 34 | #define FSCACHE_OBJLIST_CONFIG_WORK 0x00001000 /* show objects with work */ |
| 35 | #define FSCACHE_OBJLIST_CONFIG_NOWORK 0x00002000 /* show objects without work */ |
David Howells | 4fbf429 | 2009-11-19 18:11:04 +0000 | [diff] [blame] | 36 | }; |
| 37 | |
| 38 | /* |
| 39 | * Add an object to the object list |
| 40 | * - we use the address of the fscache_object structure as the key into the |
| 41 | * tree |
| 42 | */ |
| 43 | void fscache_objlist_add(struct fscache_object *obj) |
| 44 | { |
| 45 | struct fscache_object *xobj; |
| 46 | struct rb_node **p = &fscache_object_list.rb_node, *parent = NULL; |
| 47 | |
David Howells | 7026f19 | 2014-02-17 15:01:47 +0000 | [diff] [blame] | 48 | ASSERT(RB_EMPTY_NODE(&obj->objlist_link)); |
| 49 | |
David Howells | 4fbf429 | 2009-11-19 18:11:04 +0000 | [diff] [blame] | 50 | write_lock(&fscache_object_list_lock); |
| 51 | |
| 52 | while (*p) { |
| 53 | parent = *p; |
| 54 | xobj = rb_entry(parent, struct fscache_object, objlist_link); |
| 55 | |
| 56 | if (obj < xobj) |
| 57 | p = &(*p)->rb_left; |
| 58 | else if (obj > xobj) |
| 59 | p = &(*p)->rb_right; |
| 60 | else |
| 61 | BUG(); |
| 62 | } |
| 63 | |
| 64 | rb_link_node(&obj->objlist_link, parent, p); |
| 65 | rb_insert_color(&obj->objlist_link, &fscache_object_list); |
| 66 | |
| 67 | write_unlock(&fscache_object_list_lock); |
| 68 | } |
| 69 | |
David Howells | 1362729 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 70 | /* |
| 71 | * Remove an object from the object list. |
David Howells | 4fbf429 | 2009-11-19 18:11:04 +0000 | [diff] [blame] | 72 | */ |
David Howells | 1362729 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 73 | void fscache_objlist_remove(struct fscache_object *obj) |
David Howells | 4fbf429 | 2009-11-19 18:11:04 +0000 | [diff] [blame] | 74 | { |
David Howells | 7026f19 | 2014-02-17 15:01:47 +0000 | [diff] [blame] | 75 | if (RB_EMPTY_NODE(&obj->objlist_link)) |
| 76 | return; |
| 77 | |
David Howells | 4fbf429 | 2009-11-19 18:11:04 +0000 | [diff] [blame] | 78 | write_lock(&fscache_object_list_lock); |
| 79 | |
| 80 | BUG_ON(RB_EMPTY_ROOT(&fscache_object_list)); |
| 81 | rb_erase(&obj->objlist_link, &fscache_object_list); |
| 82 | |
| 83 | write_unlock(&fscache_object_list_lock); |
| 84 | } |
David Howells | 4fbf429 | 2009-11-19 18:11:04 +0000 | [diff] [blame] | 85 | |
| 86 | /* |
| 87 | * find the object in the tree on or after the specified index |
| 88 | */ |
| 89 | static struct fscache_object *fscache_objlist_lookup(loff_t *_pos) |
| 90 | { |
David Howells | ea58ceb | 2009-12-15 16:47:46 -0800 | [diff] [blame] | 91 | struct fscache_object *pobj, *obj = NULL, *minobj = NULL; |
David Howells | 4fbf429 | 2009-11-19 18:11:04 +0000 | [diff] [blame] | 92 | struct rb_node *p; |
| 93 | unsigned long pos; |
| 94 | |
| 95 | if (*_pos >= (unsigned long) ERR_PTR(-ENOENT)) |
| 96 | return NULL; |
| 97 | pos = *_pos; |
| 98 | |
| 99 | /* banners (can't represent line 0 by pos 0 as that would involve |
| 100 | * returning a NULL pointer) */ |
| 101 | if (pos == 0) |
Andrew Morton | cc68e3b | 2010-05-25 23:43:02 -0700 | [diff] [blame] | 102 | return (struct fscache_object *)(long)++(*_pos); |
David Howells | 4fbf429 | 2009-11-19 18:11:04 +0000 | [diff] [blame] | 103 | if (pos < 3) |
| 104 | return (struct fscache_object *)pos; |
| 105 | |
| 106 | pobj = (struct fscache_object *)pos; |
| 107 | p = fscache_object_list.rb_node; |
| 108 | while (p) { |
| 109 | obj = rb_entry(p, struct fscache_object, objlist_link); |
| 110 | if (pobj < obj) { |
| 111 | if (!minobj || minobj > obj) |
| 112 | minobj = obj; |
| 113 | p = p->rb_left; |
| 114 | } else if (pobj > obj) { |
| 115 | p = p->rb_right; |
| 116 | } else { |
| 117 | minobj = obj; |
| 118 | break; |
| 119 | } |
| 120 | obj = NULL; |
| 121 | } |
| 122 | |
| 123 | if (!minobj) |
| 124 | *_pos = (unsigned long) ERR_PTR(-ENOENT); |
| 125 | else if (minobj != obj) |
| 126 | *_pos = (unsigned long) minobj; |
| 127 | return minobj; |
| 128 | } |
| 129 | |
| 130 | /* |
| 131 | * set up the iterator to start reading from the first line |
| 132 | */ |
| 133 | static void *fscache_objlist_start(struct seq_file *m, loff_t *_pos) |
| 134 | __acquires(&fscache_object_list_lock) |
| 135 | { |
| 136 | read_lock(&fscache_object_list_lock); |
| 137 | return fscache_objlist_lookup(_pos); |
| 138 | } |
| 139 | |
| 140 | /* |
| 141 | * move to the next line |
| 142 | */ |
| 143 | static void *fscache_objlist_next(struct seq_file *m, void *v, loff_t *_pos) |
| 144 | { |
| 145 | (*_pos)++; |
| 146 | return fscache_objlist_lookup(_pos); |
| 147 | } |
| 148 | |
| 149 | /* |
| 150 | * clean up after reading |
| 151 | */ |
| 152 | static void fscache_objlist_stop(struct seq_file *m, void *v) |
| 153 | __releases(&fscache_object_list_lock) |
| 154 | { |
| 155 | read_unlock(&fscache_object_list_lock); |
| 156 | } |
| 157 | |
| 158 | /* |
| 159 | * display an object |
| 160 | */ |
| 161 | static int fscache_objlist_show(struct seq_file *m, void *v) |
| 162 | { |
| 163 | struct fscache_objlist_data *data = m->private; |
| 164 | struct fscache_object *obj = v; |
David Howells | 1362729 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 165 | struct fscache_cookie *cookie; |
David Howells | 4fbf429 | 2009-11-19 18:11:04 +0000 | [diff] [blame] | 166 | unsigned long config = data->config; |
David Howells | 4fbf429 | 2009-11-19 18:11:04 +0000 | [diff] [blame] | 167 | char _type[3], *type; |
David Howells | 402cb8d | 2018-04-04 13:41:28 +0100 | [diff] [blame] | 168 | u8 *p; |
David Howells | 4fbf429 | 2009-11-19 18:11:04 +0000 | [diff] [blame] | 169 | |
| 170 | if ((unsigned long) v == 1) { |
| 171 | seq_puts(m, "OBJECT PARENT STAT CHLDN OPS OOP IPR EX READS" |
David Howells | caaef69 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 172 | " EM EV FL S" |
David Howells | 4fbf429 | 2009-11-19 18:11:04 +0000 | [diff] [blame] | 173 | " | NETFS_COOKIE_DEF TY FL NETFS_DATA"); |
| 174 | if (config & (FSCACHE_OBJLIST_CONFIG_KEY | |
| 175 | FSCACHE_OBJLIST_CONFIG_AUX)) |
| 176 | seq_puts(m, " "); |
| 177 | if (config & FSCACHE_OBJLIST_CONFIG_KEY) |
| 178 | seq_puts(m, "OBJECT_KEY"); |
| 179 | if ((config & (FSCACHE_OBJLIST_CONFIG_KEY | |
| 180 | FSCACHE_OBJLIST_CONFIG_AUX)) == |
| 181 | (FSCACHE_OBJLIST_CONFIG_KEY | FSCACHE_OBJLIST_CONFIG_AUX)) |
| 182 | seq_puts(m, ", "); |
| 183 | if (config & FSCACHE_OBJLIST_CONFIG_AUX) |
| 184 | seq_puts(m, "AUX_DATA"); |
| 185 | seq_puts(m, "\n"); |
| 186 | return 0; |
| 187 | } |
| 188 | |
| 189 | if ((unsigned long) v == 2) { |
| 190 | seq_puts(m, "======== ======== ==== ===== === === === == =====" |
David Howells | caaef69 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 191 | " == == == =" |
David Howells | 4fbf429 | 2009-11-19 18:11:04 +0000 | [diff] [blame] | 192 | " | ================ == == ================"); |
| 193 | if (config & (FSCACHE_OBJLIST_CONFIG_KEY | |
| 194 | FSCACHE_OBJLIST_CONFIG_AUX)) |
| 195 | seq_puts(m, " ================"); |
| 196 | seq_puts(m, "\n"); |
| 197 | return 0; |
| 198 | } |
| 199 | |
| 200 | /* filter out any unwanted objects */ |
| 201 | #define FILTER(criterion, _yes, _no) \ |
| 202 | do { \ |
| 203 | unsigned long yes = FSCACHE_OBJLIST_CONFIG_##_yes; \ |
| 204 | unsigned long no = FSCACHE_OBJLIST_CONFIG_##_no; \ |
| 205 | if (criterion) { \ |
| 206 | if (!(config & yes)) \ |
| 207 | return 0; \ |
| 208 | } else { \ |
| 209 | if (!(config & no)) \ |
| 210 | return 0; \ |
| 211 | } \ |
| 212 | } while(0) |
| 213 | |
David Howells | 1362729 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 214 | cookie = obj->cookie; |
David Howells | 4fbf429 | 2009-11-19 18:11:04 +0000 | [diff] [blame] | 215 | if (~config) { |
David Howells | 1362729 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 216 | FILTER(cookie->def, |
David Howells | 4fbf429 | 2009-11-19 18:11:04 +0000 | [diff] [blame] | 217 | COOKIE, NOCOOKIE); |
David Howells | caaef69 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 218 | FILTER(fscache_object_is_active(obj) || |
David Howells | 4fbf429 | 2009-11-19 18:11:04 +0000 | [diff] [blame] | 219 | obj->n_ops != 0 || |
| 220 | obj->n_obj_ops != 0 || |
| 221 | obj->flags || |
| 222 | !list_empty(&obj->dependents), |
| 223 | BUSY, IDLE); |
| 224 | FILTER(test_bit(FSCACHE_OBJECT_PENDING_WRITE, &obj->flags), |
| 225 | PENDWR, NOPENDWR); |
| 226 | FILTER(atomic_read(&obj->n_reads), |
| 227 | READS, NOREADS); |
| 228 | FILTER(obj->events & obj->event_mask, |
| 229 | EVENTS, NOEVENTS); |
Tejun Heo | 8b8edef | 2010-07-20 22:09:01 +0200 | [diff] [blame] | 230 | FILTER(work_busy(&obj->work), WORK, NOWORK); |
David Howells | 4fbf429 | 2009-11-19 18:11:04 +0000 | [diff] [blame] | 231 | } |
| 232 | |
| 233 | seq_printf(m, |
David Howells | caaef69 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 234 | "%8x %8x %s %5u %3u %3u %3u %2u %5u %2lx %2lx %2lx %1x | ", |
David Howells | 4fbf429 | 2009-11-19 18:11:04 +0000 | [diff] [blame] | 235 | obj->debug_id, |
| 236 | obj->parent ? obj->parent->debug_id : -1, |
David Howells | caaef69 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 237 | obj->state->short_name, |
David Howells | 4fbf429 | 2009-11-19 18:11:04 +0000 | [diff] [blame] | 238 | obj->n_children, |
| 239 | obj->n_ops, |
| 240 | obj->n_obj_ops, |
| 241 | obj->n_in_progress, |
| 242 | obj->n_exclusive, |
| 243 | atomic_read(&obj->n_reads), |
David Howells | c2d35bf | 2012-12-05 13:34:47 +0000 | [diff] [blame] | 244 | obj->event_mask, |
David Howells | 4fbf429 | 2009-11-19 18:11:04 +0000 | [diff] [blame] | 245 | obj->events, |
| 246 | obj->flags, |
Tejun Heo | 8b8edef | 2010-07-20 22:09:01 +0200 | [diff] [blame] | 247 | work_busy(&obj->work)); |
David Howells | 4fbf429 | 2009-11-19 18:11:04 +0000 | [diff] [blame] | 248 | |
David Howells | 1362729 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 249 | if (fscache_use_cookie(obj)) { |
| 250 | uint16_t keylen = 0, auxlen = 0; |
David Howells | 4fbf429 | 2009-11-19 18:11:04 +0000 | [diff] [blame] | 251 | |
David Howells | 402cb8d | 2018-04-04 13:41:28 +0100 | [diff] [blame] | 252 | switch (cookie->type) { |
David Howells | 1362729 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 253 | case 0: |
| 254 | type = "IX"; |
| 255 | break; |
| 256 | case 1: |
| 257 | type = "DT"; |
| 258 | break; |
| 259 | default: |
Arnd Bergmann | ebfddb3 | 2017-09-13 16:28:23 -0700 | [diff] [blame] | 260 | snprintf(_type, sizeof(_type), "%02u", |
David Howells | 402cb8d | 2018-04-04 13:41:28 +0100 | [diff] [blame] | 261 | cookie->type); |
David Howells | 1362729 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 262 | type = _type; |
| 263 | break; |
David Howells | 4fbf429 | 2009-11-19 18:11:04 +0000 | [diff] [blame] | 264 | } |
David Howells | 4fbf429 | 2009-11-19 18:11:04 +0000 | [diff] [blame] | 265 | |
David Howells | 1362729 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 266 | seq_printf(m, "%-16s %s %2lx %16p", |
| 267 | cookie->def->name, |
| 268 | type, |
| 269 | cookie->flags, |
| 270 | cookie->netfs_data); |
| 271 | |
David Howells | 402cb8d | 2018-04-04 13:41:28 +0100 | [diff] [blame] | 272 | if (config & FSCACHE_OBJLIST_CONFIG_KEY) |
| 273 | keylen = cookie->key_len; |
David Howells | 1362729 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 274 | |
David Howells | 402cb8d | 2018-04-04 13:41:28 +0100 | [diff] [blame] | 275 | if (config & FSCACHE_OBJLIST_CONFIG_AUX) |
| 276 | auxlen = cookie->aux_len; |
David Howells | 1362729 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 277 | |
| 278 | if (keylen > 0 || auxlen > 0) { |
Fabian Frederick | 3185a88 | 2014-06-04 16:05:39 -0700 | [diff] [blame] | 279 | seq_puts(m, " "); |
David Howells | 402cb8d | 2018-04-04 13:41:28 +0100 | [diff] [blame] | 280 | p = keylen <= sizeof(cookie->inline_key) ? |
| 281 | cookie->inline_key : cookie->key; |
| 282 | for (; keylen > 0; keylen--) |
David Howells | 4fbf429 | 2009-11-19 18:11:04 +0000 | [diff] [blame] | 283 | seq_printf(m, "%02x", *p++); |
| 284 | if (auxlen > 0) { |
| 285 | if (config & FSCACHE_OBJLIST_CONFIG_KEY) |
Fabian Frederick | 3185a88 | 2014-06-04 16:05:39 -0700 | [diff] [blame] | 286 | seq_puts(m, ", "); |
David Howells | 402cb8d | 2018-04-04 13:41:28 +0100 | [diff] [blame] | 287 | p = auxlen <= sizeof(cookie->inline_aux) ? |
| 288 | cookie->inline_aux : cookie->aux; |
David Howells | 4fbf429 | 2009-11-19 18:11:04 +0000 | [diff] [blame] | 289 | for (; auxlen > 0; auxlen--) |
| 290 | seq_printf(m, "%02x", *p++); |
| 291 | } |
| 292 | } |
David Howells | 4fbf429 | 2009-11-19 18:11:04 +0000 | [diff] [blame] | 293 | |
Fabian Frederick | 3185a88 | 2014-06-04 16:05:39 -0700 | [diff] [blame] | 294 | seq_puts(m, "\n"); |
David Howells | 402cb8d | 2018-04-04 13:41:28 +0100 | [diff] [blame] | 295 | fscache_unuse_cookie(obj); |
David Howells | 1362729 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 296 | } else { |
Fabian Frederick | 3185a88 | 2014-06-04 16:05:39 -0700 | [diff] [blame] | 297 | seq_puts(m, "<no_netfs>\n"); |
David Howells | 1362729 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 298 | } |
David Howells | 4fbf429 | 2009-11-19 18:11:04 +0000 | [diff] [blame] | 299 | return 0; |
| 300 | } |
| 301 | |
| 302 | static const struct seq_operations fscache_objlist_ops = { |
| 303 | .start = fscache_objlist_start, |
| 304 | .stop = fscache_objlist_stop, |
| 305 | .next = fscache_objlist_next, |
| 306 | .show = fscache_objlist_show, |
| 307 | }; |
| 308 | |
| 309 | /* |
| 310 | * get the configuration for filtering the list |
| 311 | */ |
| 312 | static void fscache_objlist_config(struct fscache_objlist_data *data) |
| 313 | { |
| 314 | #ifdef CONFIG_KEYS |
David Howells | 146aa8b | 2015-10-21 14:04:48 +0100 | [diff] [blame] | 315 | const struct user_key_payload *confkey; |
David Howells | 4fbf429 | 2009-11-19 18:11:04 +0000 | [diff] [blame] | 316 | unsigned long config; |
| 317 | struct key *key; |
| 318 | const char *buf; |
| 319 | int len; |
| 320 | |
Linus Torvalds | 028db3e | 2019-07-10 18:43:43 -0700 | [diff] [blame] | 321 | key = request_key(&key_type_user, "fscache:objlist", NULL); |
David Howells | 4fbf429 | 2009-11-19 18:11:04 +0000 | [diff] [blame] | 322 | if (IS_ERR(key)) |
| 323 | goto no_config; |
| 324 | |
| 325 | config = 0; |
| 326 | rcu_read_lock(); |
| 327 | |
David Howells | 0837e49 | 2017-03-01 15:11:23 +0000 | [diff] [blame] | 328 | confkey = user_key_payload_rcu(key); |
Eric Biggers | d124b2c | 2017-10-09 12:40:00 -0700 | [diff] [blame] | 329 | if (!confkey) { |
| 330 | /* key was revoked */ |
| 331 | rcu_read_unlock(); |
| 332 | key_put(key); |
| 333 | goto no_config; |
| 334 | } |
| 335 | |
David Howells | 4fbf429 | 2009-11-19 18:11:04 +0000 | [diff] [blame] | 336 | buf = confkey->data; |
| 337 | |
| 338 | for (len = confkey->datalen - 1; len >= 0; len--) { |
| 339 | switch (buf[len]) { |
| 340 | case 'K': config |= FSCACHE_OBJLIST_CONFIG_KEY; break; |
| 341 | case 'A': config |= FSCACHE_OBJLIST_CONFIG_AUX; break; |
| 342 | case 'C': config |= FSCACHE_OBJLIST_CONFIG_COOKIE; break; |
| 343 | case 'c': config |= FSCACHE_OBJLIST_CONFIG_NOCOOKIE; break; |
| 344 | case 'B': config |= FSCACHE_OBJLIST_CONFIG_BUSY; break; |
| 345 | case 'b': config |= FSCACHE_OBJLIST_CONFIG_IDLE; break; |
| 346 | case 'W': config |= FSCACHE_OBJLIST_CONFIG_PENDWR; break; |
| 347 | case 'w': config |= FSCACHE_OBJLIST_CONFIG_NOPENDWR; break; |
| 348 | case 'R': config |= FSCACHE_OBJLIST_CONFIG_READS; break; |
| 349 | case 'r': config |= FSCACHE_OBJLIST_CONFIG_NOREADS; break; |
| 350 | case 'S': config |= FSCACHE_OBJLIST_CONFIG_WORK; break; |
| 351 | case 's': config |= FSCACHE_OBJLIST_CONFIG_NOWORK; break; |
| 352 | } |
| 353 | } |
| 354 | |
| 355 | rcu_read_unlock(); |
| 356 | key_put(key); |
| 357 | |
| 358 | if (!(config & (FSCACHE_OBJLIST_CONFIG_COOKIE | FSCACHE_OBJLIST_CONFIG_NOCOOKIE))) |
| 359 | config |= FSCACHE_OBJLIST_CONFIG_COOKIE | FSCACHE_OBJLIST_CONFIG_NOCOOKIE; |
| 360 | if (!(config & (FSCACHE_OBJLIST_CONFIG_BUSY | FSCACHE_OBJLIST_CONFIG_IDLE))) |
| 361 | config |= FSCACHE_OBJLIST_CONFIG_BUSY | FSCACHE_OBJLIST_CONFIG_IDLE; |
| 362 | if (!(config & (FSCACHE_OBJLIST_CONFIG_PENDWR | FSCACHE_OBJLIST_CONFIG_NOPENDWR))) |
| 363 | config |= FSCACHE_OBJLIST_CONFIG_PENDWR | FSCACHE_OBJLIST_CONFIG_NOPENDWR; |
| 364 | if (!(config & (FSCACHE_OBJLIST_CONFIG_READS | FSCACHE_OBJLIST_CONFIG_NOREADS))) |
| 365 | config |= FSCACHE_OBJLIST_CONFIG_READS | FSCACHE_OBJLIST_CONFIG_NOREADS; |
| 366 | if (!(config & (FSCACHE_OBJLIST_CONFIG_EVENTS | FSCACHE_OBJLIST_CONFIG_NOEVENTS))) |
| 367 | config |= FSCACHE_OBJLIST_CONFIG_EVENTS | FSCACHE_OBJLIST_CONFIG_NOEVENTS; |
| 368 | if (!(config & (FSCACHE_OBJLIST_CONFIG_WORK | FSCACHE_OBJLIST_CONFIG_NOWORK))) |
| 369 | config |= FSCACHE_OBJLIST_CONFIG_WORK | FSCACHE_OBJLIST_CONFIG_NOWORK; |
| 370 | |
| 371 | data->config = config; |
| 372 | return; |
| 373 | |
| 374 | no_config: |
| 375 | #endif |
| 376 | data->config = ULONG_MAX; |
| 377 | } |
| 378 | |
| 379 | /* |
| 380 | * open "/proc/fs/fscache/objects" to provide a list of active objects |
| 381 | * - can be configured by a user-defined key added to the caller's keyrings |
| 382 | */ |
| 383 | static int fscache_objlist_open(struct inode *inode, struct file *file) |
| 384 | { |
| 385 | struct fscache_objlist_data *data; |
David Howells | 4fbf429 | 2009-11-19 18:11:04 +0000 | [diff] [blame] | 386 | |
Rob Jones | d5d9622 | 2014-09-17 09:56:40 +0100 | [diff] [blame] | 387 | data = __seq_open_private(file, &fscache_objlist_ops, sizeof(*data)); |
| 388 | if (!data) |
David Howells | 4fbf429 | 2009-11-19 18:11:04 +0000 | [diff] [blame] | 389 | return -ENOMEM; |
David Howells | 4fbf429 | 2009-11-19 18:11:04 +0000 | [diff] [blame] | 390 | |
| 391 | /* get the configuration key */ |
| 392 | fscache_objlist_config(data); |
| 393 | |
David Howells | 4fbf429 | 2009-11-19 18:11:04 +0000 | [diff] [blame] | 394 | return 0; |
| 395 | } |
| 396 | |
| 397 | /* |
| 398 | * clean up on close |
| 399 | */ |
| 400 | static int fscache_objlist_release(struct inode *inode, struct file *file) |
| 401 | { |
| 402 | struct seq_file *m = file->private_data; |
| 403 | |
| 404 | kfree(m->private); |
| 405 | m->private = NULL; |
| 406 | return seq_release(inode, file); |
| 407 | } |
| 408 | |
Alexey Dobriyan | 97a3253 | 2020-02-03 17:37:17 -0800 | [diff] [blame] | 409 | const struct proc_ops fscache_objlist_proc_ops = { |
| 410 | .proc_open = fscache_objlist_open, |
| 411 | .proc_read = seq_read, |
| 412 | .proc_lseek = seq_lseek, |
| 413 | .proc_release = fscache_objlist_release, |
David Howells | 4fbf429 | 2009-11-19 18:11:04 +0000 | [diff] [blame] | 414 | }; |