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