blob: be2ee3bbd0a953349ccba4a30eecbd2366b840c1 [file] [log] [blame]
David Howellsec268152007-04-26 15:49:28 -07001/* /proc interface for AFS
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 *
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 Torvalds1da177e2005-04-16 15:20:36 -070012#include <linux/slab.h>
13#include <linux/module.h>
14#include <linux/proc_fs.h>
15#include <linux/seq_file.h>
Alexey Dobriyane8edc6e2007-05-21 01:22:52 +040016#include <linux/sched.h>
Linus Torvalds7c0f6ba2016-12-24 11:46:01 -080017#include <linux/uaccess.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include "internal.h"
19
David Howells0a5143f2018-10-20 00:57:57 +010020struct afs_vl_seq_net_private {
21 struct seq_net_private seq; /* Must be first */
22 struct afs_vlserver_list *vllist;
23};
24
David Howellsf044c882017-11-02 15:27:45 +000025static inline struct afs_net *afs_seq2net(struct seq_file *m)
26{
David Howells5b86d4f2018-05-18 11:46:15 +010027 return afs_net(seq_file_net(m));
28}
29
30static inline struct afs_net *afs_seq2net_single(struct seq_file *m)
31{
32 return afs_net(seq_file_single_net(m));
David Howellsf044c882017-11-02 15:27:45 +000033}
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
Linus Torvalds1da177e2005-04-16 15:20:36 -070035/*
David Howells5d9de252018-05-18 11:46:15 +010036 * Display the list of cells known to the namespace.
David Howellsf0691682018-05-18 11:46:14 +010037 */
38static int afs_proc_cells_show(struct seq_file *m, void *v)
39{
David Howellsded2f4c2018-10-20 00:57:57 +010040 struct afs_vlserver_list *vllist;
41 struct afs_cell *cell;
David Howellsf0691682018-05-18 11:46:14 +010042
David Howells6b3944e2018-10-11 22:45:49 +010043 if (v == SEQ_START_TOKEN) {
David Howellsf0691682018-05-18 11:46:14 +010044 /* display header on line 1 */
David Howellsded2f4c2018-10-20 00:57:57 +010045 seq_puts(m, "USE TTL SV NAME\n");
David Howellsf0691682018-05-18 11:46:14 +010046 return 0;
47 }
48
David Howellsded2f4c2018-10-20 00:57:57 +010049 cell = list_entry(v, struct afs_cell, proc_link);
50 vllist = rcu_dereference(cell->vl_servers);
51
David Howellsf0691682018-05-18 11:46:14 +010052 /* display one cell per line on subsequent lines */
David Howellsded2f4c2018-10-20 00:57:57 +010053 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 Howellsf0691682018-05-18 11:46:14 +010058 return 0;
59}
60
Linus Torvalds1da177e2005-04-16 15:20:36 -070061static void *afs_proc_cells_start(struct seq_file *m, loff_t *_pos)
David Howellsfe342cf2018-04-09 21:12:31 +010062 __acquires(rcu)
Linus Torvalds1da177e2005-04-16 15:20:36 -070063{
David Howells989782d2017-11-02 15:27:50 +000064 rcu_read_lock();
David Howells6b3944e2018-10-11 22:45:49 +010065 return seq_hlist_start_head_rcu(&afs_seq2net(m)->proc_cells, *_pos);
David Howellsec268152007-04-26 15:49:28 -070066}
Linus Torvalds1da177e2005-04-16 15:20:36 -070067
David Howellsf044c882017-11-02 15:27:45 +000068static void *afs_proc_cells_next(struct seq_file *m, void *v, loff_t *pos)
Linus Torvalds1da177e2005-04-16 15:20:36 -070069{
David Howells6b3944e2018-10-11 22:45:49 +010070 return seq_hlist_next_rcu(v, &afs_seq2net(m)->proc_cells, pos);
David Howellsec268152007-04-26 15:49:28 -070071}
Linus Torvalds1da177e2005-04-16 15:20:36 -070072
David Howellsf044c882017-11-02 15:27:45 +000073static void afs_proc_cells_stop(struct seq_file *m, void *v)
David Howellsfe342cf2018-04-09 21:12:31 +010074 __releases(rcu)
Linus Torvalds1da177e2005-04-16 15:20:36 -070075{
David Howells989782d2017-11-02 15:27:50 +000076 rcu_read_unlock();
David Howellsec268152007-04-26 15:49:28 -070077}
Linus Torvalds1da177e2005-04-16 15:20:36 -070078
David Howells5d9de252018-05-18 11:46:15 +010079static 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 Torvalds1da177e2005-04-16 15:20:36 -070086/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 * handle writes to /proc/fs/afs/cells
88 * - to add cells: echo "add <cellname> <IP>[:<IP>][:<IP>]"
89 */
David Howells5b86d4f2018-05-18 11:46:15 +010090static int afs_proc_cells_write(struct file *file, char *buf, size_t size)
Linus Torvalds1da177e2005-04-16 15:20:36 -070091{
David Howells5b86d4f2018-05-18 11:46:15 +010092 struct seq_file *m = file->private_data;
93 struct afs_net *net = afs_seq2net(m);
94 char *name, *args;
Linus Torvalds1da177e2005-04-16 15:20:36 -070095 int ret;
96
Linus Torvalds1da177e2005-04-16 15:20:36 -070097 /* trim to first NL */
David Howells5b86d4f2018-05-18 11:46:15 +010098 name = memchr(buf, '\n', size);
Linus Torvalds1da177e2005-04-16 15:20:36 -070099 if (name)
100 *name = 0;
101
102 /* split into command, name and argslist */
David Howells5b86d4f2018-05-18 11:46:15 +0100103 name = strchr(buf, ' ');
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 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 Howellsecfe9512018-09-07 23:55:17 +0100113 if (args) {
114 do {
115 *args++ = 0;
116 } while(*args == ' ');
117 if (!*args)
118 goto inval;
119 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120
121 /* determine command to perform */
David Howells5b86d4f2018-05-18 11:46:15 +0100122 _debug("cmd=%s name=%s args=%s", buf, name, args);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123
David Howells5b86d4f2018-05-18 11:46:15 +0100124 if (strcmp(buf, "add") == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 struct afs_cell *cell;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126
David Howells989782d2017-11-02 15:27:50 +0000127 cell = afs_lookup_cell(net, name, strlen(name), args, true);
David Howells08e0e7c2007-04-26 15:55:03 -0700128 if (IS_ERR(cell)) {
129 ret = PTR_ERR(cell);
130 goto done;
131 }
132
David Howells17814ae2018-04-09 21:12:31 +0100133 if (test_and_set_bit(AFS_CELL_FL_NO_GC, &cell->flags))
134 afs_put_cell(net, cell);
David Howellsec268152007-04-26 15:49:28 -0700135 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 goto inval;
137 }
138
David Howells5b86d4f2018-05-18 11:46:15 +0100139 ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140
David Howellsec268152007-04-26 15:49:28 -0700141done:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 _leave(" = %d", ret);
143 return ret;
144
David Howellsec268152007-04-26 15:49:28 -0700145inval:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 ret = -EINVAL;
147 printk("kAFS: Invalid Command on /proc/fs/afs/cells file\n");
148 goto done;
David Howellsec268152007-04-26 15:49:28 -0700149}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150
David Howells5d9de252018-05-18 11:46:15 +0100151/*
David Howells5b86d4f2018-05-18 11:46:15 +0100152 * Display the name of the current workstation cell.
David Howells5d9de252018-05-18 11:46:15 +0100153 */
David Howells5b86d4f2018-05-18 11:46:15 +0100154static int afs_proc_rootcell_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155{
David Howells37ab6362018-04-06 14:17:23 +0100156 struct afs_cell *cell;
David Howells5b86d4f2018-05-18 11:46:15 +0100157 struct afs_net *net;
David Howells37ab6362018-04-06 14:17:23 +0100158
David Howells5b86d4f2018-05-18 11:46:15 +0100159 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 Torvalds1da177e2005-04-16 15:20:36 -0700168}
169
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170/*
David Howells5d9de252018-05-18 11:46:15 +0100171 * 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 Torvalds1da177e2005-04-16 15:20:36 -0700175 */
David Howells5b86d4f2018-05-18 11:46:15 +0100176static int afs_proc_rootcell_write(struct file *file, char *buf, size_t size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177{
David Howells5b86d4f2018-05-18 11:46:15 +0100178 struct seq_file *m = file->private_data;
179 struct afs_net *net = afs_seq2net_single(m);
180 char *s;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 int ret;
182
David Howells6f8880d2018-04-09 21:12:31 +0100183 ret = -EINVAL;
David Howells5b86d4f2018-05-18 11:46:15 +0100184 if (buf[0] == '.')
David Howells6f8880d2018-04-09 21:12:31 +0100185 goto out;
David Howells5b86d4f2018-05-18 11:46:15 +0100186 if (memchr(buf, '/', size))
David Howells6f8880d2018-04-09 21:12:31 +0100187 goto out;
188
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 /* trim to first NL */
David Howells5b86d4f2018-05-18 11:46:15 +0100190 s = memchr(buf, '\n', size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191 if (s)
192 *s = 0;
193
194 /* determine command to perform */
David Howells5b86d4f2018-05-18 11:46:15 +0100195 _debug("rootcell=%s", buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196
David Howells5b86d4f2018-05-18 11:46:15 +0100197 ret = afs_cell_init(net, buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198
David Howells6f8880d2018-04-09 21:12:31 +0100199out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200 _leave(" = %d", ret);
201 return ret;
David Howellsec268152007-04-26 15:49:28 -0700202}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203
David Howellsf0691682018-05-18 11:46:14 +0100204static const char afs_vol_types[3][3] = {
205 [AFSVL_RWVOL] = "RW",
206 [AFSVL_ROVOL] = "RO",
207 [AFSVL_BACKVOL] = "BK",
208};
209
210/*
David Howells5d9de252018-05-18 11:46:15 +0100211 * Display the list of volumes known to a cell.
David Howellsf0691682018-05-18 11:46:14 +0100212 */
213static 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 Howells3b6492d2018-10-20 00:57:57 +0100224 seq_printf(m, "%3d %08llx %s\n",
David Howellsf0691682018-05-18 11:46:14 +0100225 atomic_read(&vol->usage), vol->vid,
226 afs_vol_types[vol->type]);
227
228 return 0;
229}
230
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231static void *afs_proc_cell_volumes_start(struct seq_file *m, loff_t *_pos)
David Howellsfe342cf2018-04-09 21:12:31 +0100232 __acquires(cell->proc_lock)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233{
Christoph Hellwig353861c2018-04-13 20:45:09 +0200234 struct afs_cell *cell = PDE_DATA(file_inode(m->file));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235
David Howellsd2ddc772017-11-02 15:27:50 +0000236 read_lock(&cell->proc_lock);
237 return seq_list_start_head(&cell->proc_volumes, *_pos);
David Howellsec268152007-04-26 15:49:28 -0700238}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239
David Howells5b86d4f2018-05-18 11:46:15 +0100240static void *afs_proc_cell_volumes_next(struct seq_file *m, void *v,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241 loff_t *_pos)
242{
David Howells5b86d4f2018-05-18 11:46:15 +0100243 struct afs_cell *cell = PDE_DATA(file_inode(m->file));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244
David Howellsd2ddc772017-11-02 15:27:50 +0000245 return seq_list_next(v, &cell->proc_volumes, _pos);
David Howellsec268152007-04-26 15:49:28 -0700246}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247
David Howells5b86d4f2018-05-18 11:46:15 +0100248static void afs_proc_cell_volumes_stop(struct seq_file *m, void *v)
David Howellsfe342cf2018-04-09 21:12:31 +0100249 __releases(cell->proc_lock)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250{
David Howells5b86d4f2018-05-18 11:46:15 +0100251 struct afs_cell *cell = PDE_DATA(file_inode(m->file));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252
David Howellsd2ddc772017-11-02 15:27:50 +0000253 read_unlock(&cell->proc_lock);
David Howellsec268152007-04-26 15:49:28 -0700254}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255
David Howells5d9de252018-05-18 11:46:15 +0100256static 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 Howells0a5143f2018-10-20 00:57:57 +0100263static 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
273static 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 Torvalds1da177e2005-04-16 15:20:36 -0700285/*
David Howells5d9de252018-05-18 11:46:15 +0100286 * Display the list of Volume Location servers we're using for a cell.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287 */
David Howellsf0691682018-05-18 11:46:14 +0100288static int afs_proc_cell_vlservers_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289{
David Howells0a5143f2018-10-20 00:57:57 +0100290 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 Torvalds1da177e2005-04-16 15:20:36 -0700296
David Howells0a5143f2018-10-20 00:57:57 +0100297 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 Torvalds1da177e2005-04-16 15:20:36 -0700301 return 0;
302 }
303
David Howells0a5143f2018-10-20 00:57:57 +0100304 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 Howells3bf0fb62018-10-20 00:57:59 +0100315 alist->preferred == i ? '>' : '-',
David Howells0a5143f2018-10-20 00:57:57 +0100316 &alist->addrs[i].transport);
317 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 return 0;
David Howellsec268152007-04-26 15:49:28 -0700319}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321static void *afs_proc_cell_vlservers_start(struct seq_file *m, loff_t *_pos)
David Howellsfe342cf2018-04-09 21:12:31 +0100322 __acquires(rcu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323{
David Howells0a5143f2018-10-20 00:57:57 +0100324 struct afs_vl_seq_net_private *priv = m->private;
325 struct afs_vlserver_list *vllist;
Christoph Hellwig353861c2018-04-13 20:45:09 +0200326 struct afs_cell *cell = PDE_DATA(file_inode(m->file));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327 loff_t pos = *_pos;
328
David Howells8b2a4642017-11-02 15:27:50 +0000329 rcu_read_lock();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330
David Howells0a5143f2018-10-20 00:57:57 +0100331 vllist = rcu_dereference(cell->vl_servers);
332 priv->vllist = vllist;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333
David Howells0a5143f2018-10-20 00:57:57 +0100334 if (pos < 0)
335 *_pos = pos = 0;
336 if (pos == 0)
337 return SEQ_START_TOKEN;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338
David Howells0a5143f2018-10-20 00:57:57 +0100339 if (!vllist || pos - 1 >= vllist->nr_servers)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 return NULL;
341
David Howells0a5143f2018-10-20 00:57:57 +0100342 return &vllist->servers[pos - 1];
David Howellsec268152007-04-26 15:49:28 -0700343}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344
David Howells5b86d4f2018-05-18 11:46:15 +0100345static void *afs_proc_cell_vlservers_next(struct seq_file *m, void *v,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 loff_t *_pos)
347{
David Howells0a5143f2018-10-20 00:57:57 +0100348 struct afs_vl_seq_net_private *priv = m->private;
349 struct afs_vlserver_list *vllist = priv->vllist;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350 loff_t pos;
351
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352 pos = *_pos;
David Howells0a5143f2018-10-20 00:57:57 +0100353 pos++;
354 *_pos = pos;
355 if (!vllist || pos - 1 >= vllist->nr_servers)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356 return NULL;
357
David Howells0a5143f2018-10-20 00:57:57 +0100358 return &vllist->servers[pos - 1];
David Howellsec268152007-04-26 15:49:28 -0700359}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360
David Howells5b86d4f2018-05-18 11:46:15 +0100361static void afs_proc_cell_vlservers_stop(struct seq_file *m, void *v)
David Howellsfe342cf2018-04-09 21:12:31 +0100362 __releases(rcu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363{
David Howells8b2a4642017-11-02 15:27:50 +0000364 rcu_read_unlock();
David Howellsec268152007-04-26 15:49:28 -0700365}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366
David Howells5d9de252018-05-18 11:46:15 +0100367static 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 Torvalds1da177e2005-04-16 15:20:36 -0700374/*
David Howells5d9de252018-05-18 11:46:15 +0100375 * Display the list of fileservers we're using within a namespace.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 */
David Howellsf0691682018-05-18 11:46:14 +0100377static int afs_proc_servers_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378{
David Howellsf0691682018-05-18 11:46:14 +0100379 struct afs_server *server;
380 struct afs_addr_list *alist;
David Howells0aac4bce2018-06-02 22:20:31 +0100381 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382
David Howellsf0691682018-05-18 11:46:14 +0100383 if (v == SEQ_START_TOKEN) {
384 seq_puts(m, "UUID USE ADDR\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385 return 0;
386 }
387
David Howellsf0691682018-05-18 11:46:14 +0100388 server = list_entry(v, struct afs_server, proc_link);
389 alist = rcu_dereference(server->addresses);
David Howells0aac4bce2018-06-02 22:20:31 +0100390 seq_printf(m, "%pU %3d %pISpc%s\n",
David Howellsf0691682018-05-18 11:46:14 +0100391 &server->uuid,
392 atomic_read(&server->usage),
David Howells0aac4bce2018-06-02 22:20:31 +0100393 &alist->addrs[0].transport,
David Howells3bf0fb62018-10-20 00:57:59 +0100394 alist->preferred == 0 ? "*" : "");
David Howells0aac4bce2018-06-02 22:20:31 +0100395 for (i = 1; i < alist->nr_addrs; i++)
396 seq_printf(m, " %pISpc%s\n",
397 &alist->addrs[i].transport,
David Howells3bf0fb62018-10-20 00:57:59 +0100398 alist->preferred == i ? "*" : "");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399 return 0;
David Howellsec268152007-04-26 15:49:28 -0700400}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401
David Howellsd2ddc772017-11-02 15:27:50 +0000402static void *afs_proc_servers_start(struct seq_file *m, loff_t *_pos)
David Howellsfe342cf2018-04-09 21:12:31 +0100403 __acquires(rcu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404{
David Howellsd2ddc772017-11-02 15:27:50 +0000405 rcu_read_lock();
David Howells5d9de252018-05-18 11:46:15 +0100406 return seq_hlist_start_head_rcu(&afs_seq2net(m)->fs_proc, *_pos);
David Howellsec268152007-04-26 15:49:28 -0700407}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408
David Howellsd2ddc772017-11-02 15:27:50 +0000409static void *afs_proc_servers_next(struct seq_file *m, void *v, loff_t *_pos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410{
David Howells5d9de252018-05-18 11:46:15 +0100411 return seq_hlist_next_rcu(v, &afs_seq2net(m)->fs_proc, _pos);
David Howellsec268152007-04-26 15:49:28 -0700412}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413
David Howells5b86d4f2018-05-18 11:46:15 +0100414static void afs_proc_servers_stop(struct seq_file *m, void *v)
David Howellsfe342cf2018-04-09 21:12:31 +0100415 __releases(rcu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416{
David Howellsd2ddc772017-11-02 15:27:50 +0000417 rcu_read_unlock();
David Howellsec268152007-04-26 15:49:28 -0700418}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419
David Howells5d9de252018-05-18 11:46:15 +0100420static 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 Howells6f8880d2018-04-09 21:12:31 +0100426
David Howells6f8880d2018-04-09 21:12:31 +0100427/*
David Howells5d9de252018-05-18 11:46:15 +0100428 * Display the list of strings that may be substituted for the @sys pathname
429 * macro.
David Howells6f8880d2018-04-09 21:12:31 +0100430 */
David Howells5d9de252018-05-18 11:46:15 +0100431static int afs_proc_sysname_show(struct seq_file *m, void *v)
David Howells6f8880d2018-04-09 21:12:31 +0100432{
David Howells5d9de252018-05-18 11:46:15 +0100433 struct afs_net *net = afs_seq2net(m);
434 struct afs_sysnames *sysnames = net->sysnames;
435 unsigned int i = (unsigned long)v - 1;
David Howells6f8880d2018-04-09 21:12:31 +0100436
David Howells5d9de252018-05-18 11:46:15 +0100437 if (i < sysnames->nr)
438 seq_printf(m, "%s\n", sysnames->subs[i]);
David Howells6f8880d2018-04-09 21:12:31 +0100439 return 0;
440}
441
David Howells5d9de252018-05-18 11:46:15 +0100442static 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 Howells5b86d4f2018-05-18 11:46:15 +0100446 struct afs_sysnames *names;
David Howells5d9de252018-05-18 11:46:15 +0100447
448 read_lock(&net->sysnames_lock);
449
David Howells5b86d4f2018-05-18 11:46:15 +0100450 names = net->sysnames;
David Howells5d9de252018-05-18 11:46:15 +0100451 if (*pos >= names->nr)
452 return NULL;
453 return (void *)(unsigned long)(*pos + 1);
454}
455
456static 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
467static 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
475static 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 Howells6f8880d2018-04-09 21:12:31 +0100482/*
David Howells5d9de252018-05-18 11:46:15 +0100483 * Allow the @sys substitution to be configured.
David Howells6f8880d2018-04-09 21:12:31 +0100484 */
David Howells5b86d4f2018-05-18 11:46:15 +0100485static int afs_proc_sysname_write(struct file *file, char *buf, size_t size)
David Howells6f8880d2018-04-09 21:12:31 +0100486{
David Howells5b86d4f2018-05-18 11:46:15 +0100487 struct afs_sysnames *sysnames, *kill;
David Howells6f8880d2018-04-09 21:12:31 +0100488 struct seq_file *m = file->private_data;
David Howells5b86d4f2018-05-18 11:46:15 +0100489 struct afs_net *net = afs_seq2net(m);
490 char *s, *p, *sub;
David Howells6f8880d2018-04-09 21:12:31 +0100491 int ret, len;
492
David Howells5b86d4f2018-05-18 11:46:15 +0100493 sysnames = kzalloc(sizeof(*sysnames), GFP_KERNEL);
David Howells6f8880d2018-04-09 21:12:31 +0100494 if (!sysnames)
David Howells5b86d4f2018-05-18 11:46:15 +0100495 return -ENOMEM;
496 refcount_set(&sysnames->usage, 1);
497 kill = sysnames;
David Howells6f8880d2018-04-09 21:12:31 +0100498
David Howells5b86d4f2018-05-18 11:46:15 +0100499 p = buf;
David Howells6f8880d2018-04-09 21:12:31 +0100500 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 Howells5b86d4f2018-05-18 11:46:15 +0100540 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 Howells6f8880d2018-04-09 21:12:31 +0100550out:
David Howells5b86d4f2018-05-18 11:46:15 +0100551 afs_put_sysnames(kill);
David Howells6f8880d2018-04-09 21:12:31 +0100552 return ret;
553
554invalid:
555 ret = -EINVAL;
556error:
David Howells6f8880d2018-04-09 21:12:31 +0100557 goto out;
558}
559
David Howells5d9de252018-05-18 11:46:15 +0100560void 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 Howellsd55b4da2018-04-06 14:17:24 +0100572/*
573 * Display general per-net namespace statistics
574 */
575static int afs_proc_stats_show(struct seq_file *m, void *v)
576{
David Howells5b86d4f2018-05-18 11:46:15 +0100577 struct afs_net *net = afs_seq2net_single(m);
David Howellsd55b4da2018-04-06 14:17:24 +0100578
579 seq_puts(m, "kAFS statistics\n");
580
David Howellsf3ddee82018-04-06 14:17:25 +0100581 seq_printf(m, "dir-mgmt: look=%u reval=%u inval=%u relpg=%u\n",
David Howellsd55b4da2018-04-06 14:17:24 +0100582 atomic_read(&net->n_lookup),
583 atomic_read(&net->n_reval),
David Howellsf3ddee82018-04-06 14:17:25 +0100584 atomic_read(&net->n_inval),
585 atomic_read(&net->n_relpg));
David Howellsd55b4da2018-04-06 14:17:24 +0100586
587 seq_printf(m, "dir-data: rdpg=%u\n",
588 atomic_read(&net->n_read_dir));
David Howells63a46812018-04-06 14:17:25 +0100589
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 Howells76a5cb62018-04-06 14:17:26 +0100593
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 Howellsd55b4da2018-04-06 14:17:24 +0100600 return 0;
601}
David Howells10495a02018-05-18 11:46:14 +0100602
603/*
604 * initialise /proc/fs/afs/<cell>/
605 */
David Howells5b86d4f2018-05-18 11:46:15 +0100606int afs_proc_cell_setup(struct afs_cell *cell)
David Howells10495a02018-05-18 11:46:14 +0100607{
608 struct proc_dir_entry *dir;
David Howells5b86d4f2018-05-18 11:46:15 +0100609 struct afs_net *net = cell->net;
David Howells10495a02018-05-18 11:46:14 +0100610
611 _enter("%p{%s},%p", cell, cell->name, net->proc_afs);
612
David Howells5b86d4f2018-05-18 11:46:15 +0100613 dir = proc_net_mkdir(net->net, cell->name, net->proc_afs);
David Howells10495a02018-05-18 11:46:14 +0100614 if (!dir)
615 goto error_dir;
616
David Howells5b86d4f2018-05-18 11:46:15 +0100617 if (!proc_create_net_data("vlservers", 0444, dir,
618 &afs_proc_cell_vlservers_ops,
David Howells0a5143f2018-10-20 00:57:57 +0100619 sizeof(struct afs_vl_seq_net_private),
David Howells5b86d4f2018-05-18 11:46:15 +0100620 cell) ||
621 !proc_create_net_data("volumes", 0444, dir,
622 &afs_proc_cell_volumes_ops,
623 sizeof(struct seq_net_private),
624 cell))
David Howells10495a02018-05-18 11:46:14 +0100625 goto error_tree;
626
627 _leave(" = 0");
628 return 0;
629
630error_tree:
631 remove_proc_subtree(cell->name, net->proc_afs);
632error_dir:
633 _leave(" = -ENOMEM");
634 return -ENOMEM;
635}
636
637/*
638 * remove /proc/fs/afs/<cell>/
639 */
David Howells5b86d4f2018-05-18 11:46:15 +0100640void afs_proc_cell_remove(struct afs_cell *cell)
David Howells10495a02018-05-18 11:46:14 +0100641{
David Howells5b86d4f2018-05-18 11:46:15 +0100642 struct afs_net *net = cell->net;
643
David Howells10495a02018-05-18 11:46:14 +0100644 _enter("");
David Howells10495a02018-05-18 11:46:14 +0100645 remove_proc_subtree(cell->name, net->proc_afs);
David Howells10495a02018-05-18 11:46:14 +0100646 _leave("");
647}
648
649/*
650 * initialise the /proc/fs/afs/ directory
651 */
652int afs_proc_init(struct afs_net *net)
653{
David Howells5b86d4f2018-05-18 11:46:15 +0100654 struct proc_dir_entry *p;
655
David Howells10495a02018-05-18 11:46:14 +0100656 _enter("");
657
David Howells5b86d4f2018-05-18 11:46:15 +0100658 p = proc_net_mkdir(net->net, "afs", net->net->proc_net);
659 if (!p)
David Howells10495a02018-05-18 11:46:14 +0100660 goto error_dir;
661
David Howells5b86d4f2018-05-18 11:46:15 +0100662 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 Howells10495a02018-05-18 11:46:14 +0100679 goto error_tree;
680
David Howells5b86d4f2018-05-18 11:46:15 +0100681 net->proc_afs = p;
David Howells10495a02018-05-18 11:46:14 +0100682 _leave(" = 0");
683 return 0;
684
685error_tree:
David Howells5b86d4f2018-05-18 11:46:15 +0100686 proc_remove(p);
David Howells10495a02018-05-18 11:46:14 +0100687error_dir:
688 _leave(" = -ENOMEM");
689 return -ENOMEM;
690}
691
692/*
693 * clean up the /proc/fs/afs/ directory
694 */
695void afs_proc_cleanup(struct afs_net *net)
696{
697 proc_remove(net->proc_afs);
698 net->proc_afs = NULL;
699}