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_proc2net(struct file *f) |
| 21 | { |
| 22 | return &__afs_net; |
| 23 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 25 | static inline struct afs_net *afs_seq2net(struct seq_file *m) |
| 26 | { |
| 27 | return &__afs_net; // TODO: use seq_file_net(m) |
| 28 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | |
| 30 | static int afs_proc_cells_open(struct inode *inode, struct file *file); |
| 31 | static void *afs_proc_cells_start(struct seq_file *p, loff_t *pos); |
| 32 | static void *afs_proc_cells_next(struct seq_file *p, void *v, loff_t *pos); |
| 33 | static void afs_proc_cells_stop(struct seq_file *p, void *v); |
| 34 | static int afs_proc_cells_show(struct seq_file *m, void *v); |
| 35 | static ssize_t afs_proc_cells_write(struct file *file, const char __user *buf, |
| 36 | size_t size, loff_t *_pos); |
| 37 | |
James Morris | 88e9d34 | 2009-09-22 16:43:43 -0700 | [diff] [blame] | 38 | static const struct seq_operations afs_proc_cells_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | .start = afs_proc_cells_start, |
| 40 | .next = afs_proc_cells_next, |
| 41 | .stop = afs_proc_cells_stop, |
| 42 | .show = afs_proc_cells_show, |
| 43 | }; |
| 44 | |
Arjan van de Ven | 4b6f5d2 | 2006-03-28 01:56:42 -0800 | [diff] [blame] | 45 | static const struct file_operations afs_proc_cells_fops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | .open = afs_proc_cells_open, |
| 47 | .read = seq_read, |
| 48 | .write = afs_proc_cells_write, |
| 49 | .llseek = seq_lseek, |
| 50 | .release = seq_release, |
| 51 | }; |
| 52 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | static ssize_t afs_proc_rootcell_read(struct file *file, char __user *buf, |
| 54 | size_t size, loff_t *_pos); |
| 55 | static ssize_t afs_proc_rootcell_write(struct file *file, |
| 56 | const char __user *buf, |
| 57 | size_t size, loff_t *_pos); |
| 58 | |
Arjan van de Ven | 4b6f5d2 | 2006-03-28 01:56:42 -0800 | [diff] [blame] | 59 | static const struct file_operations afs_proc_rootcell_fops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | .read = afs_proc_rootcell_read, |
| 61 | .write = afs_proc_rootcell_write, |
| 62 | .llseek = no_llseek, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | }; |
| 64 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | static void *afs_proc_cell_volumes_start(struct seq_file *p, loff_t *pos); |
| 66 | static void *afs_proc_cell_volumes_next(struct seq_file *p, void *v, |
| 67 | loff_t *pos); |
| 68 | static void afs_proc_cell_volumes_stop(struct seq_file *p, void *v); |
| 69 | static int afs_proc_cell_volumes_show(struct seq_file *m, void *v); |
| 70 | |
James Morris | 88e9d34 | 2009-09-22 16:43:43 -0700 | [diff] [blame] | 71 | static const struct seq_operations afs_proc_cell_volumes_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | .start = afs_proc_cell_volumes_start, |
| 73 | .next = afs_proc_cell_volumes_next, |
| 74 | .stop = afs_proc_cell_volumes_stop, |
| 75 | .show = afs_proc_cell_volumes_show, |
| 76 | }; |
| 77 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | static void *afs_proc_cell_vlservers_start(struct seq_file *p, loff_t *pos); |
| 79 | static void *afs_proc_cell_vlservers_next(struct seq_file *p, void *v, |
| 80 | loff_t *pos); |
| 81 | static void afs_proc_cell_vlservers_stop(struct seq_file *p, void *v); |
| 82 | static int afs_proc_cell_vlservers_show(struct seq_file *m, void *v); |
| 83 | |
James Morris | 88e9d34 | 2009-09-22 16:43:43 -0700 | [diff] [blame] | 84 | static const struct seq_operations afs_proc_cell_vlservers_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | .start = afs_proc_cell_vlservers_start, |
| 86 | .next = afs_proc_cell_vlservers_next, |
| 87 | .stop = afs_proc_cell_vlservers_stop, |
| 88 | .show = afs_proc_cell_vlservers_show, |
| 89 | }; |
| 90 | |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 91 | static void *afs_proc_servers_start(struct seq_file *p, loff_t *pos); |
| 92 | static void *afs_proc_servers_next(struct seq_file *p, void *v, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | loff_t *pos); |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 94 | static void afs_proc_servers_stop(struct seq_file *p, void *v); |
| 95 | static int afs_proc_servers_show(struct seq_file *m, void *v); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 97 | static const struct seq_operations afs_proc_servers_ops = { |
| 98 | .start = afs_proc_servers_start, |
| 99 | .next = afs_proc_servers_next, |
| 100 | .stop = afs_proc_servers_stop, |
| 101 | .show = afs_proc_servers_show, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | }; |
| 103 | |
David Howells | 6f8880d | 2018-04-09 21:12:31 +0100 | [diff] [blame] | 104 | static int afs_proc_sysname_open(struct inode *inode, struct file *file); |
| 105 | static int afs_proc_sysname_release(struct inode *inode, struct file *file); |
| 106 | static void *afs_proc_sysname_start(struct seq_file *p, loff_t *pos); |
| 107 | static void *afs_proc_sysname_next(struct seq_file *p, void *v, |
| 108 | loff_t *pos); |
| 109 | static void afs_proc_sysname_stop(struct seq_file *p, void *v); |
| 110 | static int afs_proc_sysname_show(struct seq_file *m, void *v); |
| 111 | static ssize_t afs_proc_sysname_write(struct file *file, |
| 112 | const char __user *buf, |
| 113 | size_t size, loff_t *_pos); |
| 114 | |
| 115 | static const struct seq_operations afs_proc_sysname_ops = { |
| 116 | .start = afs_proc_sysname_start, |
| 117 | .next = afs_proc_sysname_next, |
| 118 | .stop = afs_proc_sysname_stop, |
| 119 | .show = afs_proc_sysname_show, |
| 120 | }; |
| 121 | |
| 122 | static const struct file_operations afs_proc_sysname_fops = { |
| 123 | .open = afs_proc_sysname_open, |
| 124 | .read = seq_read, |
| 125 | .llseek = seq_lseek, |
| 126 | .release = afs_proc_sysname_release, |
| 127 | .write = afs_proc_sysname_write, |
| 128 | }; |
| 129 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | /* |
| 131 | * open "/proc/fs/afs/cells" which provides a summary of extant cells |
| 132 | */ |
| 133 | static int afs_proc_cells_open(struct inode *inode, struct file *file) |
| 134 | { |
Christoph Hellwig | 353861c | 2018-04-13 20:45:09 +0200 | [diff] [blame] | 135 | return seq_open(file, &afs_proc_cells_ops); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 136 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | /* |
| 139 | * set up the iterator to start reading from the cells list and return the |
| 140 | * first item |
| 141 | */ |
| 142 | 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] | 143 | __acquires(rcu) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | { |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 145 | struct afs_net *net = afs_seq2net(m); |
| 146 | |
David Howells | 989782d | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 147 | rcu_read_lock(); |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 148 | return seq_list_start_head(&net->proc_cells, *_pos); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 149 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | /* |
| 152 | * move to next cell in cells list |
| 153 | */ |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 154 | 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] | 155 | { |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 156 | struct afs_net *net = afs_seq2net(m); |
| 157 | |
| 158 | return seq_list_next(v, &net->proc_cells, pos); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 159 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | /* |
| 162 | * clean up after reading from the cells list |
| 163 | */ |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 164 | static void afs_proc_cells_stop(struct seq_file *m, void *v) |
David Howells | fe342cf | 2018-04-09 21:12:31 +0100 | [diff] [blame] | 165 | __releases(rcu) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | { |
David Howells | 989782d | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 167 | rcu_read_unlock(); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 168 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | /* |
| 171 | * display a header line followed by a load of cell lines |
| 172 | */ |
| 173 | static int afs_proc_cells_show(struct seq_file *m, void *v) |
| 174 | { |
| 175 | struct afs_cell *cell = list_entry(v, struct afs_cell, proc_link); |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 176 | struct afs_net *net = afs_seq2net(m); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 178 | if (v == &net->proc_cells) { |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 179 | /* display header on line 1 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | seq_puts(m, "USE NAME\n"); |
| 181 | return 0; |
| 182 | } |
| 183 | |
| 184 | /* display one cell per line on subsequent lines */ |
David Howells | 989782d | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 185 | seq_printf(m, "%3u %s\n", atomic_read(&cell->usage), cell->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | return 0; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 187 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | /* |
| 190 | * handle writes to /proc/fs/afs/cells |
| 191 | * - to add cells: echo "add <cellname> <IP>[:<IP>][:<IP>]" |
| 192 | */ |
| 193 | static ssize_t afs_proc_cells_write(struct file *file, const char __user *buf, |
| 194 | size_t size, loff_t *_pos) |
| 195 | { |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 196 | struct afs_net *net = afs_proc2net(file); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | char *kbuf, *name, *args; |
| 198 | int ret; |
| 199 | |
| 200 | /* start by dragging the command into memory */ |
| 201 | if (size <= 1 || size >= PAGE_SIZE) |
| 202 | return -EINVAL; |
| 203 | |
Al Viro | 16e5c1f | 2015-12-24 00:06:05 -0500 | [diff] [blame] | 204 | kbuf = memdup_user_nul(buf, size); |
| 205 | if (IS_ERR(kbuf)) |
| 206 | return PTR_ERR(kbuf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | |
| 208 | /* trim to first NL */ |
| 209 | name = memchr(kbuf, '\n', size); |
| 210 | if (name) |
| 211 | *name = 0; |
| 212 | |
| 213 | /* split into command, name and argslist */ |
| 214 | name = strchr(kbuf, ' '); |
| 215 | if (!name) |
| 216 | goto inval; |
| 217 | do { |
| 218 | *name++ = 0; |
| 219 | } while(*name == ' '); |
| 220 | if (!*name) |
| 221 | goto inval; |
| 222 | |
| 223 | args = strchr(name, ' '); |
| 224 | if (!args) |
| 225 | goto inval; |
| 226 | do { |
| 227 | *args++ = 0; |
| 228 | } while(*args == ' '); |
| 229 | if (!*args) |
| 230 | goto inval; |
| 231 | |
| 232 | /* determine command to perform */ |
| 233 | _debug("cmd=%s name=%s args=%s", kbuf, name, args); |
| 234 | |
| 235 | if (strcmp(kbuf, "add") == 0) { |
| 236 | struct afs_cell *cell; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | |
David Howells | 989782d | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 238 | cell = afs_lookup_cell(net, name, strlen(name), args, true); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 239 | if (IS_ERR(cell)) { |
| 240 | ret = PTR_ERR(cell); |
| 241 | goto done; |
| 242 | } |
| 243 | |
David Howells | 17814ae | 2018-04-09 21:12:31 +0100 | [diff] [blame] | 244 | if (test_and_set_bit(AFS_CELL_FL_NO_GC, &cell->flags)) |
| 245 | afs_put_cell(net, cell); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | printk("kAFS: Added new cell '%s'\n", name); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 247 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | goto inval; |
| 249 | } |
| 250 | |
| 251 | ret = size; |
| 252 | |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 253 | done: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | kfree(kbuf); |
| 255 | _leave(" = %d", ret); |
| 256 | return ret; |
| 257 | |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 258 | inval: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | ret = -EINVAL; |
| 260 | printk("kAFS: Invalid Command on /proc/fs/afs/cells file\n"); |
| 261 | goto done; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 262 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | static ssize_t afs_proc_rootcell_read(struct file *file, char __user *buf, |
| 265 | size_t size, loff_t *_pos) |
| 266 | { |
David Howells | 37ab636 | 2018-04-06 14:17:23 +0100 | [diff] [blame] | 267 | struct afs_cell *cell; |
| 268 | struct afs_net *net = afs_proc2net(file); |
| 269 | unsigned int seq = 0; |
| 270 | char name[AFS_MAXCELLNAME + 1]; |
| 271 | int len; |
| 272 | |
| 273 | if (*_pos > 0) |
| 274 | return 0; |
| 275 | if (!net->ws_cell) |
| 276 | return 0; |
| 277 | |
| 278 | rcu_read_lock(); |
| 279 | do { |
| 280 | read_seqbegin_or_lock(&net->cells_lock, &seq); |
| 281 | len = 0; |
| 282 | cell = rcu_dereference_raw(net->ws_cell); |
| 283 | if (cell) { |
| 284 | len = cell->name_len; |
| 285 | memcpy(name, cell->name, len); |
| 286 | } |
| 287 | } while (need_seqretry(&net->cells_lock, seq)); |
| 288 | done_seqretry(&net->cells_lock, seq); |
| 289 | rcu_read_unlock(); |
| 290 | |
| 291 | if (!len) |
| 292 | return 0; |
| 293 | |
| 294 | name[len++] = '\n'; |
| 295 | if (len > size) |
| 296 | len = size; |
| 297 | if (copy_to_user(buf, name, len) != 0) |
| 298 | return -EFAULT; |
| 299 | *_pos = 1; |
| 300 | return len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | } |
| 302 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | /* |
| 304 | * handle writes to /proc/fs/afs/rootcell |
| 305 | * - to initialize rootcell: echo "cell.name:192.168.231.14" |
| 306 | */ |
| 307 | static ssize_t afs_proc_rootcell_write(struct file *file, |
| 308 | const char __user *buf, |
| 309 | size_t size, loff_t *_pos) |
| 310 | { |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 311 | struct afs_net *net = afs_proc2net(file); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | char *kbuf, *s; |
| 313 | int ret; |
| 314 | |
| 315 | /* start by dragging the command into memory */ |
| 316 | if (size <= 1 || size >= PAGE_SIZE) |
| 317 | return -EINVAL; |
| 318 | |
Al Viro | 16e5c1f | 2015-12-24 00:06:05 -0500 | [diff] [blame] | 319 | kbuf = memdup_user_nul(buf, size); |
| 320 | if (IS_ERR(kbuf)) |
| 321 | return PTR_ERR(kbuf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | |
David Howells | 6f8880d | 2018-04-09 21:12:31 +0100 | [diff] [blame] | 323 | ret = -EINVAL; |
| 324 | if (kbuf[0] == '.') |
| 325 | goto out; |
| 326 | if (memchr(kbuf, '/', size)) |
| 327 | goto out; |
| 328 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | /* trim to first NL */ |
| 330 | s = memchr(kbuf, '\n', size); |
| 331 | if (s) |
| 332 | *s = 0; |
| 333 | |
| 334 | /* determine command to perform */ |
| 335 | _debug("rootcell=%s", kbuf); |
| 336 | |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 337 | ret = afs_cell_init(net, kbuf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | if (ret >= 0) |
| 339 | ret = size; /* consume everything, always */ |
| 340 | |
David Howells | 6f8880d | 2018-04-09 21:12:31 +0100 | [diff] [blame] | 341 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | kfree(kbuf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | _leave(" = %d", ret); |
| 344 | return ret; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 345 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | * set up the iterator to start reading from the cells list and return the |
| 349 | * first item |
| 350 | */ |
| 351 | 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] | 352 | __acquires(cell->proc_lock) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | { |
Christoph Hellwig | 353861c | 2018-04-13 20:45:09 +0200 | [diff] [blame] | 354 | struct afs_cell *cell = PDE_DATA(file_inode(m->file)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | |
| 356 | _enter("cell=%p pos=%Ld", cell, *_pos); |
| 357 | |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 358 | read_lock(&cell->proc_lock); |
| 359 | return seq_list_start_head(&cell->proc_volumes, *_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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | /* |
| 363 | * move to next cell in cells list |
| 364 | */ |
| 365 | static void *afs_proc_cell_volumes_next(struct seq_file *p, void *v, |
| 366 | loff_t *_pos) |
| 367 | { |
Christoph Hellwig | 353861c | 2018-04-13 20:45:09 +0200 | [diff] [blame] | 368 | struct afs_cell *cell = PDE_DATA(file_inode(p->file)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | |
| 370 | _enter("cell=%p pos=%Ld", cell, *_pos); |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 371 | return seq_list_next(v, &cell->proc_volumes, _pos); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 372 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | /* |
| 375 | * clean up after reading from the cells list |
| 376 | */ |
| 377 | static void afs_proc_cell_volumes_stop(struct seq_file *p, void *v) |
David Howells | fe342cf | 2018-04-09 21:12:31 +0100 | [diff] [blame] | 378 | __releases(cell->proc_lock) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | { |
Christoph Hellwig | 353861c | 2018-04-13 20:45:09 +0200 | [diff] [blame] | 380 | struct afs_cell *cell = PDE_DATA(file_inode(p->file)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 382 | read_unlock(&cell->proc_lock); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 383 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 385 | static const char afs_vol_types[3][3] = { |
| 386 | [AFSVL_RWVOL] = "RW", |
| 387 | [AFSVL_ROVOL] = "RO", |
| 388 | [AFSVL_BACKVOL] = "BK", |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 389 | }; |
| 390 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | /* |
| 392 | * display a header line followed by a load of volume lines |
| 393 | */ |
| 394 | static int afs_proc_cell_volumes_show(struct seq_file *m, void *v) |
| 395 | { |
Christoph Hellwig | 353861c | 2018-04-13 20:45:09 +0200 | [diff] [blame] | 396 | struct afs_cell *cell = PDE_DATA(file_inode(m->file)); |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 397 | struct afs_volume *vol = list_entry(v, struct afs_volume, proc_link); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 399 | /* Display header on line 1 */ |
| 400 | if (v == &cell->proc_volumes) { |
| 401 | seq_puts(m, "USE VID TY\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | return 0; |
| 403 | } |
| 404 | |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 405 | seq_printf(m, "%3d %08x %s\n", |
| 406 | atomic_read(&vol->usage), vol->vid, |
| 407 | afs_vol_types[vol->type]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | |
| 409 | return 0; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 410 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | * set up the iterator to start reading from the cells list and return the |
| 414 | * first item |
| 415 | */ |
| 416 | 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] | 417 | __acquires(rcu) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | { |
David Howells | 8b2a464 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 419 | struct afs_addr_list *alist; |
Christoph Hellwig | 353861c | 2018-04-13 20:45:09 +0200 | [diff] [blame] | 420 | struct afs_cell *cell = PDE_DATA(file_inode(m->file)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | loff_t pos = *_pos; |
| 422 | |
David Howells | 8b2a464 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 423 | rcu_read_lock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | |
David Howells | 8b2a464 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 425 | alist = rcu_dereference(cell->vl_addrs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | |
| 427 | /* allow for the header line */ |
| 428 | if (!pos) |
| 429 | return (void *) 1; |
| 430 | pos--; |
| 431 | |
David Howells | 8b2a464 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 432 | if (!alist || pos >= alist->nr_addrs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | return NULL; |
| 434 | |
David Howells | 8b2a464 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 435 | return alist->addrs + pos; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 436 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | /* |
| 439 | * move to next cell in cells list |
| 440 | */ |
| 441 | static void *afs_proc_cell_vlservers_next(struct seq_file *p, void *v, |
| 442 | loff_t *_pos) |
| 443 | { |
David Howells | 8b2a464 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 444 | struct afs_addr_list *alist; |
Christoph Hellwig | 353861c | 2018-04-13 20:45:09 +0200 | [diff] [blame] | 445 | struct afs_cell *cell = PDE_DATA(file_inode(p->file)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | loff_t pos; |
| 447 | |
David Howells | 8b2a464 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 448 | alist = rcu_dereference(cell->vl_addrs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | |
| 450 | pos = *_pos; |
| 451 | (*_pos)++; |
David Howells | 8b2a464 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 452 | if (!alist || pos >= alist->nr_addrs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 453 | return NULL; |
| 454 | |
David Howells | 8b2a464 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 455 | return alist->addrs + pos; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 456 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 | /* |
| 459 | * clean up after reading from the cells list |
| 460 | */ |
| 461 | static void afs_proc_cell_vlservers_stop(struct seq_file *p, void *v) |
David Howells | fe342cf | 2018-04-09 21:12:31 +0100 | [diff] [blame] | 462 | __releases(rcu) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 463 | { |
David Howells | 8b2a464 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 464 | rcu_read_unlock(); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 465 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | /* |
| 468 | * display a header line followed by a load of volume lines |
| 469 | */ |
| 470 | static int afs_proc_cell_vlservers_show(struct seq_file *m, void *v) |
| 471 | { |
David Howells | 4d9df98 | 2017-11-02 15:27:47 +0000 | [diff] [blame] | 472 | struct sockaddr_rxrpc *addr = v; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 473 | |
| 474 | /* display header on line 1 */ |
David Howells | 4d9df98 | 2017-11-02 15:27:47 +0000 | [diff] [blame] | 475 | if (v == (void *)1) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 476 | seq_puts(m, "ADDRESS\n"); |
| 477 | return 0; |
| 478 | } |
| 479 | |
| 480 | /* display one cell per line on subsequent lines */ |
David Howells | 4d9df98 | 2017-11-02 15:27:47 +0000 | [diff] [blame] | 481 | seq_printf(m, "%pISp\n", &addr->transport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | return 0; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 483 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 485 | /* |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 486 | * Set up the iterator to start reading from the server list and return the |
| 487 | * first item. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 | */ |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 489 | 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] | 490 | __acquires(rcu) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 491 | { |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 492 | struct afs_net *net = afs_seq2net(m); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 493 | |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 494 | rcu_read_lock(); |
| 495 | return seq_hlist_start_head_rcu(&net->fs_proc, *_pos); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 496 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 497 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 498 | /* |
| 499 | * move to next cell in cells list |
| 500 | */ |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 501 | 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] | 502 | { |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 503 | struct afs_net *net = afs_seq2net(m); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 504 | |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 505 | return seq_hlist_next_rcu(v, &net->fs_proc, _pos); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 506 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 508 | /* |
| 509 | * clean up after reading from the cells list |
| 510 | */ |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 511 | static void afs_proc_servers_stop(struct seq_file *p, void *v) |
David Howells | fe342cf | 2018-04-09 21:12:31 +0100 | [diff] [blame] | 512 | __releases(rcu) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | { |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 514 | rcu_read_unlock(); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 515 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 | /* |
| 518 | * display a header line followed by a load of volume lines |
| 519 | */ |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 520 | static int afs_proc_servers_show(struct seq_file *m, void *v) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 | { |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 522 | struct afs_server *server; |
| 523 | struct afs_addr_list *alist; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 524 | |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 525 | if (v == SEQ_START_TOKEN) { |
| 526 | seq_puts(m, "UUID USE ADDR\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 527 | return 0; |
| 528 | } |
| 529 | |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 530 | server = list_entry(v, struct afs_server, proc_link); |
| 531 | alist = rcu_dereference(server->addresses); |
| 532 | seq_printf(m, "%pU %3d %pISp\n", |
| 533 | &server->uuid, |
| 534 | atomic_read(&server->usage), |
| 535 | &alist->addrs[alist->index].transport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 536 | return 0; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 537 | } |
David Howells | 6f8880d | 2018-04-09 21:12:31 +0100 | [diff] [blame] | 538 | |
| 539 | void afs_put_sysnames(struct afs_sysnames *sysnames) |
| 540 | { |
| 541 | int i; |
| 542 | |
| 543 | if (sysnames && refcount_dec_and_test(&sysnames->usage)) { |
| 544 | for (i = 0; i < sysnames->nr; i++) |
| 545 | if (sysnames->subs[i] != afs_init_sysname && |
| 546 | sysnames->subs[i] != sysnames->blank) |
| 547 | kfree(sysnames->subs[i]); |
| 548 | } |
| 549 | } |
| 550 | |
| 551 | /* |
| 552 | * Handle opening of /proc/fs/afs/sysname. If it is opened for writing, we |
| 553 | * assume the caller wants to change the substitution list and we allocate a |
| 554 | * buffer to hold the list. |
| 555 | */ |
| 556 | static int afs_proc_sysname_open(struct inode *inode, struct file *file) |
| 557 | { |
| 558 | struct afs_sysnames *sysnames; |
| 559 | struct seq_file *m; |
| 560 | int ret; |
| 561 | |
| 562 | ret = seq_open(file, &afs_proc_sysname_ops); |
| 563 | if (ret < 0) |
| 564 | return ret; |
| 565 | |
| 566 | if (file->f_mode & FMODE_WRITE) { |
| 567 | sysnames = kzalloc(sizeof(*sysnames), GFP_KERNEL); |
| 568 | if (!sysnames) { |
| 569 | seq_release(inode, file); |
| 570 | return -ENOMEM; |
| 571 | } |
| 572 | |
| 573 | refcount_set(&sysnames->usage, 1); |
| 574 | m = file->private_data; |
| 575 | m->private = sysnames; |
| 576 | } |
| 577 | |
| 578 | return 0; |
| 579 | } |
| 580 | |
| 581 | /* |
| 582 | * Handle writes to /proc/fs/afs/sysname to set the @sys substitution. |
| 583 | */ |
| 584 | static ssize_t afs_proc_sysname_write(struct file *file, |
| 585 | const char __user *buf, |
| 586 | size_t size, loff_t *_pos) |
| 587 | { |
| 588 | struct afs_sysnames *sysnames; |
| 589 | struct seq_file *m = file->private_data; |
| 590 | char *kbuf = NULL, *s, *p, *sub; |
| 591 | int ret, len; |
| 592 | |
| 593 | sysnames = m->private; |
| 594 | if (!sysnames) |
| 595 | return -EINVAL; |
| 596 | if (sysnames->error) |
| 597 | return sysnames->error; |
| 598 | |
| 599 | if (size >= PAGE_SIZE - 1) { |
| 600 | sysnames->error = -EINVAL; |
| 601 | return -EINVAL; |
| 602 | } |
| 603 | if (size == 0) |
| 604 | return 0; |
| 605 | |
| 606 | kbuf = memdup_user_nul(buf, size); |
| 607 | if (IS_ERR(kbuf)) |
| 608 | return PTR_ERR(kbuf); |
| 609 | |
| 610 | inode_lock(file_inode(file)); |
| 611 | |
| 612 | p = kbuf; |
| 613 | while ((s = strsep(&p, " \t\n"))) { |
| 614 | len = strlen(s); |
| 615 | if (len == 0) |
| 616 | continue; |
| 617 | ret = -ENAMETOOLONG; |
| 618 | if (len >= AFSNAMEMAX) |
| 619 | goto error; |
| 620 | |
| 621 | if (len >= 4 && |
| 622 | s[len - 4] == '@' && |
| 623 | s[len - 3] == 's' && |
| 624 | s[len - 2] == 'y' && |
| 625 | s[len - 1] == 's') |
| 626 | /* Protect against recursion */ |
| 627 | goto invalid; |
| 628 | |
| 629 | if (s[0] == '.' && |
| 630 | (len < 2 || (len == 2 && s[1] == '.'))) |
| 631 | goto invalid; |
| 632 | |
| 633 | if (memchr(s, '/', len)) |
| 634 | goto invalid; |
| 635 | |
| 636 | ret = -EFBIG; |
| 637 | if (sysnames->nr >= AFS_NR_SYSNAME) |
| 638 | goto out; |
| 639 | |
| 640 | if (strcmp(s, afs_init_sysname) == 0) { |
| 641 | sub = (char *)afs_init_sysname; |
| 642 | } else { |
| 643 | ret = -ENOMEM; |
| 644 | sub = kmemdup(s, len + 1, GFP_KERNEL); |
| 645 | if (!sub) |
| 646 | goto out; |
| 647 | } |
| 648 | |
| 649 | sysnames->subs[sysnames->nr] = sub; |
| 650 | sysnames->nr++; |
| 651 | } |
| 652 | |
| 653 | ret = size; /* consume everything, always */ |
| 654 | out: |
| 655 | inode_unlock(file_inode(file)); |
| 656 | kfree(kbuf); |
| 657 | return ret; |
| 658 | |
| 659 | invalid: |
| 660 | ret = -EINVAL; |
| 661 | error: |
| 662 | sysnames->error = ret; |
| 663 | goto out; |
| 664 | } |
| 665 | |
| 666 | static int afs_proc_sysname_release(struct inode *inode, struct file *file) |
| 667 | { |
| 668 | struct afs_sysnames *sysnames, *kill = NULL; |
| 669 | struct seq_file *m = file->private_data; |
| 670 | struct afs_net *net = afs_seq2net(m); |
| 671 | |
| 672 | sysnames = m->private; |
| 673 | if (sysnames) { |
| 674 | if (!sysnames->error) { |
| 675 | kill = sysnames; |
| 676 | if (sysnames->nr == 0) { |
| 677 | sysnames->subs[0] = sysnames->blank; |
| 678 | sysnames->nr++; |
| 679 | } |
| 680 | write_lock(&net->sysnames_lock); |
| 681 | kill = net->sysnames; |
| 682 | net->sysnames = sysnames; |
| 683 | write_unlock(&net->sysnames_lock); |
| 684 | } |
| 685 | afs_put_sysnames(kill); |
| 686 | } |
| 687 | |
| 688 | return seq_release(inode, file); |
| 689 | } |
| 690 | |
| 691 | static void *afs_proc_sysname_start(struct seq_file *m, loff_t *pos) |
| 692 | __acquires(&net->sysnames_lock) |
| 693 | { |
| 694 | struct afs_net *net = afs_seq2net(m); |
| 695 | struct afs_sysnames *names = net->sysnames; |
| 696 | |
| 697 | read_lock(&net->sysnames_lock); |
| 698 | |
| 699 | if (*pos >= names->nr) |
| 700 | return NULL; |
| 701 | return (void *)(unsigned long)(*pos + 1); |
| 702 | } |
| 703 | |
| 704 | static void *afs_proc_sysname_next(struct seq_file *m, void *v, loff_t *pos) |
| 705 | { |
| 706 | struct afs_net *net = afs_seq2net(m); |
| 707 | struct afs_sysnames *names = net->sysnames; |
| 708 | |
| 709 | *pos += 1; |
| 710 | if (*pos >= names->nr) |
| 711 | return NULL; |
| 712 | return (void *)(unsigned long)(*pos + 1); |
| 713 | } |
| 714 | |
| 715 | static void afs_proc_sysname_stop(struct seq_file *m, void *v) |
| 716 | __releases(&net->sysnames_lock) |
| 717 | { |
| 718 | struct afs_net *net = afs_seq2net(m); |
| 719 | |
| 720 | read_unlock(&net->sysnames_lock); |
| 721 | } |
| 722 | |
| 723 | static int afs_proc_sysname_show(struct seq_file *m, void *v) |
| 724 | { |
| 725 | struct afs_net *net = afs_seq2net(m); |
| 726 | struct afs_sysnames *sysnames = net->sysnames; |
| 727 | unsigned int i = (unsigned long)v - 1; |
| 728 | |
| 729 | if (i < sysnames->nr) |
| 730 | seq_printf(m, "%s\n", sysnames->subs[i]); |
| 731 | return 0; |
| 732 | } |
David Howells | d55b4da | 2018-04-06 14:17:24 +0100 | [diff] [blame] | 733 | |
| 734 | /* |
| 735 | * Display general per-net namespace statistics |
| 736 | */ |
| 737 | static int afs_proc_stats_show(struct seq_file *m, void *v) |
| 738 | { |
| 739 | struct afs_net *net = afs_seq2net(m); |
| 740 | |
| 741 | seq_puts(m, "kAFS statistics\n"); |
| 742 | |
David Howells | f3ddee8 | 2018-04-06 14:17:25 +0100 | [diff] [blame] | 743 | 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] | 744 | atomic_read(&net->n_lookup), |
| 745 | atomic_read(&net->n_reval), |
David Howells | f3ddee8 | 2018-04-06 14:17:25 +0100 | [diff] [blame] | 746 | atomic_read(&net->n_inval), |
| 747 | atomic_read(&net->n_relpg)); |
David Howells | d55b4da | 2018-04-06 14:17:24 +0100 | [diff] [blame] | 748 | |
| 749 | seq_printf(m, "dir-data: rdpg=%u\n", |
| 750 | atomic_read(&net->n_read_dir)); |
David Howells | 63a4681 | 2018-04-06 14:17:25 +0100 | [diff] [blame] | 751 | |
| 752 | seq_printf(m, "dir-edit: cr=%u rm=%u\n", |
| 753 | atomic_read(&net->n_dir_cr), |
| 754 | atomic_read(&net->n_dir_rm)); |
David Howells | 76a5cb6 | 2018-04-06 14:17:26 +0100 | [diff] [blame] | 755 | |
| 756 | seq_printf(m, "file-rd : n=%u nb=%lu\n", |
| 757 | atomic_read(&net->n_fetches), |
| 758 | atomic_long_read(&net->n_fetch_bytes)); |
| 759 | seq_printf(m, "file-wr : n=%u nb=%lu\n", |
| 760 | atomic_read(&net->n_stores), |
| 761 | atomic_long_read(&net->n_store_bytes)); |
David Howells | d55b4da | 2018-04-06 14:17:24 +0100 | [diff] [blame] | 762 | return 0; |
| 763 | } |
David Howells | 10495a0 | 2018-05-18 11:46:14 +0100 | [diff] [blame^] | 764 | |
| 765 | /* |
| 766 | * initialise /proc/fs/afs/<cell>/ |
| 767 | */ |
| 768 | int afs_proc_cell_setup(struct afs_net *net, struct afs_cell *cell) |
| 769 | { |
| 770 | struct proc_dir_entry *dir; |
| 771 | |
| 772 | _enter("%p{%s},%p", cell, cell->name, net->proc_afs); |
| 773 | |
| 774 | dir = proc_mkdir(cell->name, net->proc_afs); |
| 775 | if (!dir) |
| 776 | goto error_dir; |
| 777 | |
| 778 | if (!proc_create_seq_data("vlservers", 0, dir, |
| 779 | &afs_proc_cell_vlservers_ops, cell)) |
| 780 | goto error_tree; |
| 781 | if (!proc_create_seq_data("volumes", 0, dir, |
| 782 | &afs_proc_cell_volumes_ops, cell)) |
| 783 | goto error_tree; |
| 784 | |
| 785 | _leave(" = 0"); |
| 786 | return 0; |
| 787 | |
| 788 | error_tree: |
| 789 | remove_proc_subtree(cell->name, net->proc_afs); |
| 790 | error_dir: |
| 791 | _leave(" = -ENOMEM"); |
| 792 | return -ENOMEM; |
| 793 | } |
| 794 | |
| 795 | /* |
| 796 | * remove /proc/fs/afs/<cell>/ |
| 797 | */ |
| 798 | void afs_proc_cell_remove(struct afs_net *net, struct afs_cell *cell) |
| 799 | { |
| 800 | _enter(""); |
| 801 | |
| 802 | remove_proc_subtree(cell->name, net->proc_afs); |
| 803 | |
| 804 | _leave(""); |
| 805 | } |
| 806 | |
| 807 | /* |
| 808 | * initialise the /proc/fs/afs/ directory |
| 809 | */ |
| 810 | int afs_proc_init(struct afs_net *net) |
| 811 | { |
| 812 | _enter(""); |
| 813 | |
| 814 | net->proc_afs = proc_mkdir("fs/afs", NULL); |
| 815 | if (!net->proc_afs) |
| 816 | goto error_dir; |
| 817 | |
| 818 | if (!proc_create("cells", 0644, net->proc_afs, &afs_proc_cells_fops) || |
| 819 | !proc_create("rootcell", 0644, net->proc_afs, &afs_proc_rootcell_fops) || |
| 820 | !proc_create_seq("servers", 0644, net->proc_afs, &afs_proc_servers_ops) || |
| 821 | !proc_create_single("stats", 0644, net->proc_afs, afs_proc_stats_show) || |
| 822 | !proc_create("sysname", 0644, net->proc_afs, &afs_proc_sysname_fops)) |
| 823 | goto error_tree; |
| 824 | |
| 825 | _leave(" = 0"); |
| 826 | return 0; |
| 827 | |
| 828 | error_tree: |
| 829 | proc_remove(net->proc_afs); |
| 830 | error_dir: |
| 831 | _leave(" = -ENOMEM"); |
| 832 | return -ENOMEM; |
| 833 | } |
| 834 | |
| 835 | /* |
| 836 | * clean up the /proc/fs/afs/ directory |
| 837 | */ |
| 838 | void afs_proc_cleanup(struct afs_net *net) |
| 839 | { |
| 840 | proc_remove(net->proc_afs); |
| 841 | net->proc_afs = NULL; |
| 842 | } |