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