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