David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 1 | /* /proc interface for AFS |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * |
| 3 | * Copyright (C) 2002 Red Hat, Inc. All Rights Reserved. |
| 4 | * Written by David Howells (dhowells@redhat.com) |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License |
| 8 | * as published by the Free Software Foundation; either version |
| 9 | * 2 of the License, or (at your option) any later version. |
| 10 | */ |
| 11 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | #include <linux/slab.h> |
| 13 | #include <linux/module.h> |
| 14 | #include <linux/proc_fs.h> |
| 15 | #include <linux/seq_file.h> |
Alexey Dobriyan | e8edc6e | 2007-05-21 01:22:52 +0400 | [diff] [blame] | 16 | #include <linux/sched.h> |
Linus Torvalds | 7c0f6ba | 2016-12-24 11:46:01 -0800 | [diff] [blame] | 17 | #include <linux/uaccess.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #include "internal.h" |
| 19 | |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 20 | static inline struct afs_net *afs_seq2net(struct seq_file *m) |
| 21 | { |
David Howells | 5b86d4f | 2018-05-18 11:46:15 +0100 | [diff] [blame] | 22 | return afs_net(seq_file_net(m)); |
| 23 | } |
| 24 | |
| 25 | static inline struct afs_net *afs_seq2net_single(struct seq_file *m) |
| 26 | { |
| 27 | return afs_net(seq_file_single_net(m)); |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 28 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | /* |
David Howells | 5d9de25 | 2018-05-18 11:46:15 +0100 | [diff] [blame] | 31 | * Display the list of cells known to the namespace. |
David Howells | f069168 | 2018-05-18 11:46:14 +0100 | [diff] [blame] | 32 | */ |
| 33 | static int afs_proc_cells_show(struct seq_file *m, void *v) |
| 34 | { |
| 35 | struct afs_cell *cell = list_entry(v, struct afs_cell, proc_link); |
| 36 | struct afs_net *net = afs_seq2net(m); |
| 37 | |
| 38 | if (v == &net->proc_cells) { |
| 39 | /* display header on line 1 */ |
| 40 | seq_puts(m, "USE NAME\n"); |
| 41 | return 0; |
| 42 | } |
| 43 | |
| 44 | /* display one cell per line on subsequent lines */ |
| 45 | seq_printf(m, "%3u %s\n", atomic_read(&cell->usage), cell->name); |
| 46 | return 0; |
| 47 | } |
| 48 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | static void *afs_proc_cells_start(struct seq_file *m, loff_t *_pos) |
David Howells | fe342cf | 2018-04-09 21:12:31 +0100 | [diff] [blame] | 50 | __acquires(rcu) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | { |
David Howells | 989782d | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 52 | rcu_read_lock(); |
David Howells | 5d9de25 | 2018-05-18 11:46:15 +0100 | [diff] [blame] | 53 | return seq_list_start_head(&afs_seq2net(m)->proc_cells, *_pos); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 54 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 56 | static void *afs_proc_cells_next(struct seq_file *m, void *v, loff_t *pos) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | { |
David Howells | 5d9de25 | 2018-05-18 11:46:15 +0100 | [diff] [blame] | 58 | return seq_list_next(v, &afs_seq2net(m)->proc_cells, pos); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 59 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 61 | static void afs_proc_cells_stop(struct seq_file *m, void *v) |
David Howells | fe342cf | 2018-04-09 21:12:31 +0100 | [diff] [blame] | 62 | __releases(rcu) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | { |
David Howells | 989782d | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 64 | rcu_read_unlock(); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 65 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | |
David Howells | 5d9de25 | 2018-05-18 11:46:15 +0100 | [diff] [blame] | 67 | static const struct seq_operations afs_proc_cells_ops = { |
| 68 | .start = afs_proc_cells_start, |
| 69 | .next = afs_proc_cells_next, |
| 70 | .stop = afs_proc_cells_stop, |
| 71 | .show = afs_proc_cells_show, |
| 72 | }; |
| 73 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | * handle writes to /proc/fs/afs/cells |
| 76 | * - to add cells: echo "add <cellname> <IP>[:<IP>][:<IP>]" |
| 77 | */ |
David Howells | 5b86d4f | 2018-05-18 11:46:15 +0100 | [diff] [blame] | 78 | static int afs_proc_cells_write(struct file *file, char *buf, size_t size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | { |
David Howells | 5b86d4f | 2018-05-18 11:46:15 +0100 | [diff] [blame] | 80 | struct seq_file *m = file->private_data; |
| 81 | struct afs_net *net = afs_seq2net(m); |
| 82 | char *name, *args; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | int ret; |
| 84 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | /* trim to first NL */ |
David Howells | 5b86d4f | 2018-05-18 11:46:15 +0100 | [diff] [blame] | 86 | name = memchr(buf, '\n', size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | if (name) |
| 88 | *name = 0; |
| 89 | |
| 90 | /* split into command, name and argslist */ |
David Howells | 5b86d4f | 2018-05-18 11:46:15 +0100 | [diff] [blame] | 91 | name = strchr(buf, ' '); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | if (!name) |
| 93 | goto inval; |
| 94 | do { |
| 95 | *name++ = 0; |
| 96 | } while(*name == ' '); |
| 97 | if (!*name) |
| 98 | goto inval; |
| 99 | |
| 100 | args = strchr(name, ' '); |
| 101 | if (!args) |
| 102 | goto inval; |
| 103 | do { |
| 104 | *args++ = 0; |
| 105 | } while(*args == ' '); |
| 106 | if (!*args) |
| 107 | goto inval; |
| 108 | |
| 109 | /* determine command to perform */ |
David Howells | 5b86d4f | 2018-05-18 11:46:15 +0100 | [diff] [blame] | 110 | _debug("cmd=%s name=%s args=%s", buf, name, args); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | |
David Howells | 5b86d4f | 2018-05-18 11:46:15 +0100 | [diff] [blame] | 112 | if (strcmp(buf, "add") == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | struct afs_cell *cell; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | |
David Howells | 989782d | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 115 | cell = afs_lookup_cell(net, name, strlen(name), args, true); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 116 | if (IS_ERR(cell)) { |
| 117 | ret = PTR_ERR(cell); |
| 118 | goto done; |
| 119 | } |
| 120 | |
David Howells | 17814ae | 2018-04-09 21:12:31 +0100 | [diff] [blame] | 121 | if (test_and_set_bit(AFS_CELL_FL_NO_GC, &cell->flags)) |
| 122 | afs_put_cell(net, cell); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | printk("kAFS: Added new cell '%s'\n", name); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 124 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | goto inval; |
| 126 | } |
| 127 | |
David Howells | 5b86d4f | 2018-05-18 11:46:15 +0100 | [diff] [blame] | 128 | ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 130 | done: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | _leave(" = %d", ret); |
| 132 | return ret; |
| 133 | |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 134 | inval: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | ret = -EINVAL; |
| 136 | printk("kAFS: Invalid Command on /proc/fs/afs/cells file\n"); |
| 137 | goto done; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 138 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | |
David Howells | 5d9de25 | 2018-05-18 11:46:15 +0100 | [diff] [blame] | 140 | /* |
David Howells | 5b86d4f | 2018-05-18 11:46:15 +0100 | [diff] [blame] | 141 | * Display the name of the current workstation cell. |
David Howells | 5d9de25 | 2018-05-18 11:46:15 +0100 | [diff] [blame] | 142 | */ |
David Howells | 5b86d4f | 2018-05-18 11:46:15 +0100 | [diff] [blame] | 143 | static int afs_proc_rootcell_show(struct seq_file *m, void *v) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | { |
David Howells | 37ab636 | 2018-04-06 14:17:23 +0100 | [diff] [blame] | 145 | struct afs_cell *cell; |
David Howells | 5b86d4f | 2018-05-18 11:46:15 +0100 | [diff] [blame] | 146 | struct afs_net *net; |
David Howells | 37ab636 | 2018-04-06 14:17:23 +0100 | [diff] [blame] | 147 | |
David Howells | 5b86d4f | 2018-05-18 11:46:15 +0100 | [diff] [blame] | 148 | net = afs_seq2net_single(m); |
| 149 | if (rcu_access_pointer(net->ws_cell)) { |
| 150 | rcu_read_lock(); |
| 151 | cell = rcu_dereference(net->ws_cell); |
| 152 | if (cell) |
| 153 | seq_printf(m, "%s\n", cell->name); |
| 154 | rcu_read_unlock(); |
| 155 | } |
| 156 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | } |
| 158 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | /* |
David Howells | 5d9de25 | 2018-05-18 11:46:15 +0100 | [diff] [blame] | 160 | * Set the current workstation cell and optionally supply its list of volume |
| 161 | * location servers. |
| 162 | * |
| 163 | * echo "cell.name:192.168.231.14" >/proc/fs/afs/rootcell |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | */ |
David Howells | 5b86d4f | 2018-05-18 11:46:15 +0100 | [diff] [blame] | 165 | static int afs_proc_rootcell_write(struct file *file, char *buf, size_t size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | { |
David Howells | 5b86d4f | 2018-05-18 11:46:15 +0100 | [diff] [blame] | 167 | struct seq_file *m = file->private_data; |
| 168 | struct afs_net *net = afs_seq2net_single(m); |
| 169 | char *s; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | int ret; |
| 171 | |
David Howells | 6f8880d | 2018-04-09 21:12:31 +0100 | [diff] [blame] | 172 | ret = -EINVAL; |
David Howells | 5b86d4f | 2018-05-18 11:46:15 +0100 | [diff] [blame] | 173 | if (buf[0] == '.') |
David Howells | 6f8880d | 2018-04-09 21:12:31 +0100 | [diff] [blame] | 174 | goto out; |
David Howells | 5b86d4f | 2018-05-18 11:46:15 +0100 | [diff] [blame] | 175 | if (memchr(buf, '/', size)) |
David Howells | 6f8880d | 2018-04-09 21:12:31 +0100 | [diff] [blame] | 176 | goto out; |
| 177 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | /* trim to first NL */ |
David Howells | 5b86d4f | 2018-05-18 11:46:15 +0100 | [diff] [blame] | 179 | s = memchr(buf, '\n', size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | if (s) |
| 181 | *s = 0; |
| 182 | |
| 183 | /* determine command to perform */ |
David Howells | 5b86d4f | 2018-05-18 11:46:15 +0100 | [diff] [blame] | 184 | _debug("rootcell=%s", buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | |
David Howells | 5b86d4f | 2018-05-18 11:46:15 +0100 | [diff] [blame] | 186 | ret = afs_cell_init(net, buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | |
David Howells | 6f8880d | 2018-04-09 21:12:31 +0100 | [diff] [blame] | 188 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | _leave(" = %d", ret); |
| 190 | return ret; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 191 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | |
David Howells | f069168 | 2018-05-18 11:46:14 +0100 | [diff] [blame] | 193 | static const char afs_vol_types[3][3] = { |
| 194 | [AFSVL_RWVOL] = "RW", |
| 195 | [AFSVL_ROVOL] = "RO", |
| 196 | [AFSVL_BACKVOL] = "BK", |
| 197 | }; |
| 198 | |
| 199 | /* |
David Howells | 5d9de25 | 2018-05-18 11:46:15 +0100 | [diff] [blame] | 200 | * Display the list of volumes known to a cell. |
David Howells | f069168 | 2018-05-18 11:46:14 +0100 | [diff] [blame] | 201 | */ |
| 202 | static int afs_proc_cell_volumes_show(struct seq_file *m, void *v) |
| 203 | { |
| 204 | struct afs_cell *cell = PDE_DATA(file_inode(m->file)); |
| 205 | struct afs_volume *vol = list_entry(v, struct afs_volume, proc_link); |
| 206 | |
| 207 | /* Display header on line 1 */ |
| 208 | if (v == &cell->proc_volumes) { |
| 209 | seq_puts(m, "USE VID TY\n"); |
| 210 | return 0; |
| 211 | } |
| 212 | |
| 213 | seq_printf(m, "%3d %08x %s\n", |
| 214 | atomic_read(&vol->usage), vol->vid, |
| 215 | afs_vol_types[vol->type]); |
| 216 | |
| 217 | return 0; |
| 218 | } |
| 219 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | static void *afs_proc_cell_volumes_start(struct seq_file *m, loff_t *_pos) |
David Howells | fe342cf | 2018-04-09 21:12:31 +0100 | [diff] [blame] | 221 | __acquires(cell->proc_lock) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | { |
Christoph Hellwig | 353861c | 2018-04-13 20:45:09 +0200 | [diff] [blame] | 223 | struct afs_cell *cell = PDE_DATA(file_inode(m->file)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 225 | read_lock(&cell->proc_lock); |
| 226 | return seq_list_start_head(&cell->proc_volumes, *_pos); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 227 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | |
David Howells | 5b86d4f | 2018-05-18 11:46:15 +0100 | [diff] [blame] | 229 | static void *afs_proc_cell_volumes_next(struct seq_file *m, void *v, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | loff_t *_pos) |
| 231 | { |
David Howells | 5b86d4f | 2018-05-18 11:46:15 +0100 | [diff] [blame] | 232 | struct afs_cell *cell = PDE_DATA(file_inode(m->file)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 234 | return seq_list_next(v, &cell->proc_volumes, _pos); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 235 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | |
David Howells | 5b86d4f | 2018-05-18 11:46:15 +0100 | [diff] [blame] | 237 | static void afs_proc_cell_volumes_stop(struct seq_file *m, void *v) |
David Howells | fe342cf | 2018-04-09 21:12:31 +0100 | [diff] [blame] | 238 | __releases(cell->proc_lock) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | { |
David Howells | 5b86d4f | 2018-05-18 11:46:15 +0100 | [diff] [blame] | 240 | struct afs_cell *cell = PDE_DATA(file_inode(m->file)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 242 | read_unlock(&cell->proc_lock); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 243 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | |
David Howells | 5d9de25 | 2018-05-18 11:46:15 +0100 | [diff] [blame] | 245 | static const struct seq_operations afs_proc_cell_volumes_ops = { |
| 246 | .start = afs_proc_cell_volumes_start, |
| 247 | .next = afs_proc_cell_volumes_next, |
| 248 | .stop = afs_proc_cell_volumes_stop, |
| 249 | .show = afs_proc_cell_volumes_show, |
| 250 | }; |
| 251 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | /* |
David Howells | 5d9de25 | 2018-05-18 11:46:15 +0100 | [diff] [blame] | 253 | * Display the list of Volume Location servers we're using for a cell. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | */ |
David Howells | f069168 | 2018-05-18 11:46:14 +0100 | [diff] [blame] | 255 | static int afs_proc_cell_vlservers_show(struct seq_file *m, void *v) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | { |
David Howells | f069168 | 2018-05-18 11:46:14 +0100 | [diff] [blame] | 257 | struct sockaddr_rxrpc *addr = v; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | |
David Howells | f069168 | 2018-05-18 11:46:14 +0100 | [diff] [blame] | 259 | /* display header on line 1 */ |
| 260 | if (v == (void *)1) { |
| 261 | seq_puts(m, "ADDRESS\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | return 0; |
| 263 | } |
| 264 | |
David Howells | f069168 | 2018-05-18 11:46:14 +0100 | [diff] [blame] | 265 | /* display one cell per line on subsequent lines */ |
| 266 | seq_printf(m, "%pISp\n", &addr->transport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | return 0; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 268 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | static void *afs_proc_cell_vlservers_start(struct seq_file *m, loff_t *_pos) |
David Howells | fe342cf | 2018-04-09 21:12:31 +0100 | [diff] [blame] | 271 | __acquires(rcu) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | { |
David Howells | 8b2a464 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 273 | struct afs_addr_list *alist; |
Christoph Hellwig | 353861c | 2018-04-13 20:45:09 +0200 | [diff] [blame] | 274 | struct afs_cell *cell = PDE_DATA(file_inode(m->file)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | loff_t pos = *_pos; |
| 276 | |
David Howells | 8b2a464 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 277 | rcu_read_lock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | |
David Howells | 8b2a464 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 279 | alist = rcu_dereference(cell->vl_addrs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | |
| 281 | /* allow for the header line */ |
| 282 | if (!pos) |
| 283 | return (void *) 1; |
| 284 | pos--; |
| 285 | |
David Howells | 8b2a464 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 286 | if (!alist || pos >= alist->nr_addrs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | return NULL; |
| 288 | |
David Howells | 8b2a464 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 289 | return alist->addrs + pos; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 290 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | |
David Howells | 5b86d4f | 2018-05-18 11:46:15 +0100 | [diff] [blame] | 292 | static void *afs_proc_cell_vlservers_next(struct seq_file *m, void *v, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | loff_t *_pos) |
| 294 | { |
David Howells | 8b2a464 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 295 | struct afs_addr_list *alist; |
David Howells | 5b86d4f | 2018-05-18 11:46:15 +0100 | [diff] [blame] | 296 | struct afs_cell *cell = PDE_DATA(file_inode(m->file)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | loff_t pos; |
| 298 | |
David Howells | 8b2a464 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 299 | alist = rcu_dereference(cell->vl_addrs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | |
| 301 | pos = *_pos; |
| 302 | (*_pos)++; |
David Howells | 8b2a464 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 303 | if (!alist || pos >= alist->nr_addrs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | return NULL; |
| 305 | |
David Howells | 8b2a464 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 306 | return alist->addrs + pos; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 307 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | |
David Howells | 5b86d4f | 2018-05-18 11:46:15 +0100 | [diff] [blame] | 309 | static void afs_proc_cell_vlservers_stop(struct seq_file *m, void *v) |
David Howells | fe342cf | 2018-04-09 21:12:31 +0100 | [diff] [blame] | 310 | __releases(rcu) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | { |
David Howells | 8b2a464 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 312 | rcu_read_unlock(); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 313 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | |
David Howells | 5d9de25 | 2018-05-18 11:46:15 +0100 | [diff] [blame] | 315 | static const struct seq_operations afs_proc_cell_vlservers_ops = { |
| 316 | .start = afs_proc_cell_vlservers_start, |
| 317 | .next = afs_proc_cell_vlservers_next, |
| 318 | .stop = afs_proc_cell_vlservers_stop, |
| 319 | .show = afs_proc_cell_vlservers_show, |
| 320 | }; |
| 321 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | /* |
David Howells | 5d9de25 | 2018-05-18 11:46:15 +0100 | [diff] [blame] | 323 | * Display the list of fileservers we're using within a namespace. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | */ |
David Howells | f069168 | 2018-05-18 11:46:14 +0100 | [diff] [blame] | 325 | static int afs_proc_servers_show(struct seq_file *m, void *v) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | { |
David Howells | f069168 | 2018-05-18 11:46:14 +0100 | [diff] [blame] | 327 | struct afs_server *server; |
| 328 | struct afs_addr_list *alist; |
David Howells | 0aac4bce | 2018-06-02 22:20:31 +0100 | [diff] [blame^] | 329 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | |
David Howells | f069168 | 2018-05-18 11:46:14 +0100 | [diff] [blame] | 331 | if (v == SEQ_START_TOKEN) { |
| 332 | seq_puts(m, "UUID USE ADDR\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | return 0; |
| 334 | } |
| 335 | |
David Howells | f069168 | 2018-05-18 11:46:14 +0100 | [diff] [blame] | 336 | server = list_entry(v, struct afs_server, proc_link); |
| 337 | alist = rcu_dereference(server->addresses); |
David Howells | 0aac4bce | 2018-06-02 22:20:31 +0100 | [diff] [blame^] | 338 | seq_printf(m, "%pU %3d %pISpc%s\n", |
David Howells | f069168 | 2018-05-18 11:46:14 +0100 | [diff] [blame] | 339 | &server->uuid, |
| 340 | atomic_read(&server->usage), |
David Howells | 0aac4bce | 2018-06-02 22:20:31 +0100 | [diff] [blame^] | 341 | &alist->addrs[0].transport, |
| 342 | alist->index == 0 ? "*" : ""); |
| 343 | for (i = 1; i < alist->nr_addrs; i++) |
| 344 | seq_printf(m, " %pISpc%s\n", |
| 345 | &alist->addrs[i].transport, |
| 346 | alist->index == i ? "*" : ""); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | return 0; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 348 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 350 | static void *afs_proc_servers_start(struct seq_file *m, loff_t *_pos) |
David Howells | fe342cf | 2018-04-09 21:12:31 +0100 | [diff] [blame] | 351 | __acquires(rcu) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | { |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 353 | rcu_read_lock(); |
David Howells | 5d9de25 | 2018-05-18 11:46:15 +0100 | [diff] [blame] | 354 | return seq_hlist_start_head_rcu(&afs_seq2net(m)->fs_proc, *_pos); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 355 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 357 | static void *afs_proc_servers_next(struct seq_file *m, void *v, loff_t *_pos) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | { |
David Howells | 5d9de25 | 2018-05-18 11:46:15 +0100 | [diff] [blame] | 359 | return seq_hlist_next_rcu(v, &afs_seq2net(m)->fs_proc, _pos); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 360 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | |
David Howells | 5b86d4f | 2018-05-18 11:46:15 +0100 | [diff] [blame] | 362 | static void afs_proc_servers_stop(struct seq_file *m, void *v) |
David Howells | fe342cf | 2018-04-09 21:12:31 +0100 | [diff] [blame] | 363 | __releases(rcu) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | { |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 365 | rcu_read_unlock(); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 366 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | |
David Howells | 5d9de25 | 2018-05-18 11:46:15 +0100 | [diff] [blame] | 368 | static const struct seq_operations afs_proc_servers_ops = { |
| 369 | .start = afs_proc_servers_start, |
| 370 | .next = afs_proc_servers_next, |
| 371 | .stop = afs_proc_servers_stop, |
| 372 | .show = afs_proc_servers_show, |
| 373 | }; |
David Howells | 6f8880d | 2018-04-09 21:12:31 +0100 | [diff] [blame] | 374 | |
David Howells | 6f8880d | 2018-04-09 21:12:31 +0100 | [diff] [blame] | 375 | /* |
David Howells | 5d9de25 | 2018-05-18 11:46:15 +0100 | [diff] [blame] | 376 | * Display the list of strings that may be substituted for the @sys pathname |
| 377 | * macro. |
David Howells | 6f8880d | 2018-04-09 21:12:31 +0100 | [diff] [blame] | 378 | */ |
David Howells | 5d9de25 | 2018-05-18 11:46:15 +0100 | [diff] [blame] | 379 | static int afs_proc_sysname_show(struct seq_file *m, void *v) |
David Howells | 6f8880d | 2018-04-09 21:12:31 +0100 | [diff] [blame] | 380 | { |
David Howells | 5d9de25 | 2018-05-18 11:46:15 +0100 | [diff] [blame] | 381 | struct afs_net *net = afs_seq2net(m); |
| 382 | struct afs_sysnames *sysnames = net->sysnames; |
| 383 | unsigned int i = (unsigned long)v - 1; |
David Howells | 6f8880d | 2018-04-09 21:12:31 +0100 | [diff] [blame] | 384 | |
David Howells | 5d9de25 | 2018-05-18 11:46:15 +0100 | [diff] [blame] | 385 | if (i < sysnames->nr) |
| 386 | seq_printf(m, "%s\n", sysnames->subs[i]); |
David Howells | 6f8880d | 2018-04-09 21:12:31 +0100 | [diff] [blame] | 387 | return 0; |
| 388 | } |
| 389 | |
David Howells | 5d9de25 | 2018-05-18 11:46:15 +0100 | [diff] [blame] | 390 | static void *afs_proc_sysname_start(struct seq_file *m, loff_t *pos) |
| 391 | __acquires(&net->sysnames_lock) |
| 392 | { |
| 393 | struct afs_net *net = afs_seq2net(m); |
David Howells | 5b86d4f | 2018-05-18 11:46:15 +0100 | [diff] [blame] | 394 | struct afs_sysnames *names; |
David Howells | 5d9de25 | 2018-05-18 11:46:15 +0100 | [diff] [blame] | 395 | |
| 396 | read_lock(&net->sysnames_lock); |
| 397 | |
David Howells | 5b86d4f | 2018-05-18 11:46:15 +0100 | [diff] [blame] | 398 | names = net->sysnames; |
David Howells | 5d9de25 | 2018-05-18 11:46:15 +0100 | [diff] [blame] | 399 | if (*pos >= names->nr) |
| 400 | return NULL; |
| 401 | return (void *)(unsigned long)(*pos + 1); |
| 402 | } |
| 403 | |
| 404 | static void *afs_proc_sysname_next(struct seq_file *m, void *v, loff_t *pos) |
| 405 | { |
| 406 | struct afs_net *net = afs_seq2net(m); |
| 407 | struct afs_sysnames *names = net->sysnames; |
| 408 | |
| 409 | *pos += 1; |
| 410 | if (*pos >= names->nr) |
| 411 | return NULL; |
| 412 | return (void *)(unsigned long)(*pos + 1); |
| 413 | } |
| 414 | |
| 415 | static void afs_proc_sysname_stop(struct seq_file *m, void *v) |
| 416 | __releases(&net->sysnames_lock) |
| 417 | { |
| 418 | struct afs_net *net = afs_seq2net(m); |
| 419 | |
| 420 | read_unlock(&net->sysnames_lock); |
| 421 | } |
| 422 | |
| 423 | static const struct seq_operations afs_proc_sysname_ops = { |
| 424 | .start = afs_proc_sysname_start, |
| 425 | .next = afs_proc_sysname_next, |
| 426 | .stop = afs_proc_sysname_stop, |
| 427 | .show = afs_proc_sysname_show, |
| 428 | }; |
| 429 | |
David Howells | 6f8880d | 2018-04-09 21:12:31 +0100 | [diff] [blame] | 430 | /* |
David Howells | 5d9de25 | 2018-05-18 11:46:15 +0100 | [diff] [blame] | 431 | * Allow the @sys substitution to be configured. |
David Howells | 6f8880d | 2018-04-09 21:12:31 +0100 | [diff] [blame] | 432 | */ |
David Howells | 5b86d4f | 2018-05-18 11:46:15 +0100 | [diff] [blame] | 433 | static int afs_proc_sysname_write(struct file *file, char *buf, size_t size) |
David Howells | 6f8880d | 2018-04-09 21:12:31 +0100 | [diff] [blame] | 434 | { |
David Howells | 5b86d4f | 2018-05-18 11:46:15 +0100 | [diff] [blame] | 435 | struct afs_sysnames *sysnames, *kill; |
David Howells | 6f8880d | 2018-04-09 21:12:31 +0100 | [diff] [blame] | 436 | struct seq_file *m = file->private_data; |
David Howells | 5b86d4f | 2018-05-18 11:46:15 +0100 | [diff] [blame] | 437 | struct afs_net *net = afs_seq2net(m); |
| 438 | char *s, *p, *sub; |
David Howells | 6f8880d | 2018-04-09 21:12:31 +0100 | [diff] [blame] | 439 | int ret, len; |
| 440 | |
David Howells | 5b86d4f | 2018-05-18 11:46:15 +0100 | [diff] [blame] | 441 | sysnames = kzalloc(sizeof(*sysnames), GFP_KERNEL); |
David Howells | 6f8880d | 2018-04-09 21:12:31 +0100 | [diff] [blame] | 442 | if (!sysnames) |
David Howells | 5b86d4f | 2018-05-18 11:46:15 +0100 | [diff] [blame] | 443 | return -ENOMEM; |
| 444 | refcount_set(&sysnames->usage, 1); |
| 445 | kill = sysnames; |
David Howells | 6f8880d | 2018-04-09 21:12:31 +0100 | [diff] [blame] | 446 | |
David Howells | 5b86d4f | 2018-05-18 11:46:15 +0100 | [diff] [blame] | 447 | p = buf; |
David Howells | 6f8880d | 2018-04-09 21:12:31 +0100 | [diff] [blame] | 448 | while ((s = strsep(&p, " \t\n"))) { |
| 449 | len = strlen(s); |
| 450 | if (len == 0) |
| 451 | continue; |
| 452 | ret = -ENAMETOOLONG; |
| 453 | if (len >= AFSNAMEMAX) |
| 454 | goto error; |
| 455 | |
| 456 | if (len >= 4 && |
| 457 | s[len - 4] == '@' && |
| 458 | s[len - 3] == 's' && |
| 459 | s[len - 2] == 'y' && |
| 460 | s[len - 1] == 's') |
| 461 | /* Protect against recursion */ |
| 462 | goto invalid; |
| 463 | |
| 464 | if (s[0] == '.' && |
| 465 | (len < 2 || (len == 2 && s[1] == '.'))) |
| 466 | goto invalid; |
| 467 | |
| 468 | if (memchr(s, '/', len)) |
| 469 | goto invalid; |
| 470 | |
| 471 | ret = -EFBIG; |
| 472 | if (sysnames->nr >= AFS_NR_SYSNAME) |
| 473 | goto out; |
| 474 | |
| 475 | if (strcmp(s, afs_init_sysname) == 0) { |
| 476 | sub = (char *)afs_init_sysname; |
| 477 | } else { |
| 478 | ret = -ENOMEM; |
| 479 | sub = kmemdup(s, len + 1, GFP_KERNEL); |
| 480 | if (!sub) |
| 481 | goto out; |
| 482 | } |
| 483 | |
| 484 | sysnames->subs[sysnames->nr] = sub; |
| 485 | sysnames->nr++; |
| 486 | } |
| 487 | |
David Howells | 5b86d4f | 2018-05-18 11:46:15 +0100 | [diff] [blame] | 488 | if (sysnames->nr == 0) { |
| 489 | sysnames->subs[0] = sysnames->blank; |
| 490 | sysnames->nr++; |
| 491 | } |
| 492 | |
| 493 | write_lock(&net->sysnames_lock); |
| 494 | kill = net->sysnames; |
| 495 | net->sysnames = sysnames; |
| 496 | write_unlock(&net->sysnames_lock); |
| 497 | ret = 0; |
David Howells | 6f8880d | 2018-04-09 21:12:31 +0100 | [diff] [blame] | 498 | out: |
David Howells | 5b86d4f | 2018-05-18 11:46:15 +0100 | [diff] [blame] | 499 | afs_put_sysnames(kill); |
David Howells | 6f8880d | 2018-04-09 21:12:31 +0100 | [diff] [blame] | 500 | return ret; |
| 501 | |
| 502 | invalid: |
| 503 | ret = -EINVAL; |
| 504 | error: |
David Howells | 6f8880d | 2018-04-09 21:12:31 +0100 | [diff] [blame] | 505 | goto out; |
| 506 | } |
| 507 | |
David Howells | 5d9de25 | 2018-05-18 11:46:15 +0100 | [diff] [blame] | 508 | void afs_put_sysnames(struct afs_sysnames *sysnames) |
| 509 | { |
| 510 | int i; |
| 511 | |
| 512 | if (sysnames && refcount_dec_and_test(&sysnames->usage)) { |
| 513 | for (i = 0; i < sysnames->nr; i++) |
| 514 | if (sysnames->subs[i] != afs_init_sysname && |
| 515 | sysnames->subs[i] != sysnames->blank) |
| 516 | kfree(sysnames->subs[i]); |
| 517 | } |
| 518 | } |
| 519 | |
David Howells | d55b4da | 2018-04-06 14:17:24 +0100 | [diff] [blame] | 520 | /* |
| 521 | * Display general per-net namespace statistics |
| 522 | */ |
| 523 | static int afs_proc_stats_show(struct seq_file *m, void *v) |
| 524 | { |
David Howells | 5b86d4f | 2018-05-18 11:46:15 +0100 | [diff] [blame] | 525 | struct afs_net *net = afs_seq2net_single(m); |
David Howells | d55b4da | 2018-04-06 14:17:24 +0100 | [diff] [blame] | 526 | |
| 527 | seq_puts(m, "kAFS statistics\n"); |
| 528 | |
David Howells | f3ddee8 | 2018-04-06 14:17:25 +0100 | [diff] [blame] | 529 | seq_printf(m, "dir-mgmt: look=%u reval=%u inval=%u relpg=%u\n", |
David Howells | d55b4da | 2018-04-06 14:17:24 +0100 | [diff] [blame] | 530 | atomic_read(&net->n_lookup), |
| 531 | atomic_read(&net->n_reval), |
David Howells | f3ddee8 | 2018-04-06 14:17:25 +0100 | [diff] [blame] | 532 | atomic_read(&net->n_inval), |
| 533 | atomic_read(&net->n_relpg)); |
David Howells | d55b4da | 2018-04-06 14:17:24 +0100 | [diff] [blame] | 534 | |
| 535 | seq_printf(m, "dir-data: rdpg=%u\n", |
| 536 | atomic_read(&net->n_read_dir)); |
David Howells | 63a4681 | 2018-04-06 14:17:25 +0100 | [diff] [blame] | 537 | |
| 538 | seq_printf(m, "dir-edit: cr=%u rm=%u\n", |
| 539 | atomic_read(&net->n_dir_cr), |
| 540 | atomic_read(&net->n_dir_rm)); |
David Howells | 76a5cb6 | 2018-04-06 14:17:26 +0100 | [diff] [blame] | 541 | |
| 542 | seq_printf(m, "file-rd : n=%u nb=%lu\n", |
| 543 | atomic_read(&net->n_fetches), |
| 544 | atomic_long_read(&net->n_fetch_bytes)); |
| 545 | seq_printf(m, "file-wr : n=%u nb=%lu\n", |
| 546 | atomic_read(&net->n_stores), |
| 547 | atomic_long_read(&net->n_store_bytes)); |
David Howells | d55b4da | 2018-04-06 14:17:24 +0100 | [diff] [blame] | 548 | return 0; |
| 549 | } |
David Howells | 10495a0 | 2018-05-18 11:46:14 +0100 | [diff] [blame] | 550 | |
| 551 | /* |
| 552 | * initialise /proc/fs/afs/<cell>/ |
| 553 | */ |
David Howells | 5b86d4f | 2018-05-18 11:46:15 +0100 | [diff] [blame] | 554 | int afs_proc_cell_setup(struct afs_cell *cell) |
David Howells | 10495a0 | 2018-05-18 11:46:14 +0100 | [diff] [blame] | 555 | { |
| 556 | struct proc_dir_entry *dir; |
David Howells | 5b86d4f | 2018-05-18 11:46:15 +0100 | [diff] [blame] | 557 | struct afs_net *net = cell->net; |
David Howells | 10495a0 | 2018-05-18 11:46:14 +0100 | [diff] [blame] | 558 | |
| 559 | _enter("%p{%s},%p", cell, cell->name, net->proc_afs); |
| 560 | |
David Howells | 5b86d4f | 2018-05-18 11:46:15 +0100 | [diff] [blame] | 561 | dir = proc_net_mkdir(net->net, cell->name, net->proc_afs); |
David Howells | 10495a0 | 2018-05-18 11:46:14 +0100 | [diff] [blame] | 562 | if (!dir) |
| 563 | goto error_dir; |
| 564 | |
David Howells | 5b86d4f | 2018-05-18 11:46:15 +0100 | [diff] [blame] | 565 | if (!proc_create_net_data("vlservers", 0444, dir, |
| 566 | &afs_proc_cell_vlservers_ops, |
| 567 | sizeof(struct seq_net_private), |
| 568 | cell) || |
| 569 | !proc_create_net_data("volumes", 0444, dir, |
| 570 | &afs_proc_cell_volumes_ops, |
| 571 | sizeof(struct seq_net_private), |
| 572 | cell)) |
David Howells | 10495a0 | 2018-05-18 11:46:14 +0100 | [diff] [blame] | 573 | goto error_tree; |
| 574 | |
| 575 | _leave(" = 0"); |
| 576 | return 0; |
| 577 | |
| 578 | error_tree: |
| 579 | remove_proc_subtree(cell->name, net->proc_afs); |
| 580 | error_dir: |
| 581 | _leave(" = -ENOMEM"); |
| 582 | return -ENOMEM; |
| 583 | } |
| 584 | |
| 585 | /* |
| 586 | * remove /proc/fs/afs/<cell>/ |
| 587 | */ |
David Howells | 5b86d4f | 2018-05-18 11:46:15 +0100 | [diff] [blame] | 588 | void afs_proc_cell_remove(struct afs_cell *cell) |
David Howells | 10495a0 | 2018-05-18 11:46:14 +0100 | [diff] [blame] | 589 | { |
David Howells | 5b86d4f | 2018-05-18 11:46:15 +0100 | [diff] [blame] | 590 | struct afs_net *net = cell->net; |
| 591 | |
David Howells | 10495a0 | 2018-05-18 11:46:14 +0100 | [diff] [blame] | 592 | _enter(""); |
David Howells | 10495a0 | 2018-05-18 11:46:14 +0100 | [diff] [blame] | 593 | remove_proc_subtree(cell->name, net->proc_afs); |
David Howells | 10495a0 | 2018-05-18 11:46:14 +0100 | [diff] [blame] | 594 | _leave(""); |
| 595 | } |
| 596 | |
| 597 | /* |
| 598 | * initialise the /proc/fs/afs/ directory |
| 599 | */ |
| 600 | int afs_proc_init(struct afs_net *net) |
| 601 | { |
David Howells | 5b86d4f | 2018-05-18 11:46:15 +0100 | [diff] [blame] | 602 | struct proc_dir_entry *p; |
| 603 | |
David Howells | 10495a0 | 2018-05-18 11:46:14 +0100 | [diff] [blame] | 604 | _enter(""); |
| 605 | |
David Howells | 5b86d4f | 2018-05-18 11:46:15 +0100 | [diff] [blame] | 606 | p = proc_net_mkdir(net->net, "afs", net->net->proc_net); |
| 607 | if (!p) |
David Howells | 10495a0 | 2018-05-18 11:46:14 +0100 | [diff] [blame] | 608 | goto error_dir; |
| 609 | |
David Howells | 5b86d4f | 2018-05-18 11:46:15 +0100 | [diff] [blame] | 610 | if (!proc_create_net_data_write("cells", 0644, p, |
| 611 | &afs_proc_cells_ops, |
| 612 | afs_proc_cells_write, |
| 613 | sizeof(struct seq_net_private), |
| 614 | NULL) || |
| 615 | !proc_create_net_single_write("rootcell", 0644, p, |
| 616 | afs_proc_rootcell_show, |
| 617 | afs_proc_rootcell_write, |
| 618 | NULL) || |
| 619 | !proc_create_net("servers", 0444, p, &afs_proc_servers_ops, |
| 620 | sizeof(struct seq_net_private)) || |
| 621 | !proc_create_net_single("stats", 0444, p, afs_proc_stats_show, NULL) || |
| 622 | !proc_create_net_data_write("sysname", 0644, p, |
| 623 | &afs_proc_sysname_ops, |
| 624 | afs_proc_sysname_write, |
| 625 | sizeof(struct seq_net_private), |
| 626 | NULL)) |
David Howells | 10495a0 | 2018-05-18 11:46:14 +0100 | [diff] [blame] | 627 | goto error_tree; |
| 628 | |
David Howells | 5b86d4f | 2018-05-18 11:46:15 +0100 | [diff] [blame] | 629 | net->proc_afs = p; |
David Howells | 10495a0 | 2018-05-18 11:46:14 +0100 | [diff] [blame] | 630 | _leave(" = 0"); |
| 631 | return 0; |
| 632 | |
| 633 | error_tree: |
David Howells | 5b86d4f | 2018-05-18 11:46:15 +0100 | [diff] [blame] | 634 | proc_remove(p); |
David Howells | 10495a0 | 2018-05-18 11:46:14 +0100 | [diff] [blame] | 635 | error_dir: |
| 636 | _leave(" = -ENOMEM"); |
| 637 | return -ENOMEM; |
| 638 | } |
| 639 | |
| 640 | /* |
| 641 | * clean up the /proc/fs/afs/ directory |
| 642 | */ |
| 643 | void afs_proc_cleanup(struct afs_net *net) |
| 644 | { |
| 645 | proc_remove(net->proc_afs); |
| 646 | net->proc_afs = NULL; |
| 647 | } |