David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 1 | /* /proc interface for AFS |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * |
| 3 | * Copyright (C) 2002 Red Hat, Inc. All Rights Reserved. |
| 4 | * Written by David Howells (dhowells@redhat.com) |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License |
| 8 | * as published by the Free Software Foundation; either version |
| 9 | * 2 of the License, or (at your option) any later version. |
| 10 | */ |
| 11 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | #include <linux/slab.h> |
| 13 | #include <linux/module.h> |
| 14 | #include <linux/proc_fs.h> |
| 15 | #include <linux/seq_file.h> |
Alexey Dobriyan | e8edc6e | 2007-05-21 01:22:52 +0400 | [diff] [blame] | 16 | #include <linux/sched.h> |
Linus Torvalds | 7c0f6ba | 2016-12-24 11:46:01 -0800 | [diff] [blame] | 17 | #include <linux/uaccess.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #include "internal.h" |
| 19 | |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 20 | static inline struct afs_net *afs_proc2net(struct file *f) |
| 21 | { |
| 22 | return &__afs_net; |
| 23 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 25 | static inline struct afs_net *afs_seq2net(struct seq_file *m) |
| 26 | { |
| 27 | return &__afs_net; // TODO: use seq_file_net(m) |
| 28 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | |
| 30 | static int afs_proc_cells_open(struct inode *inode, struct file *file); |
| 31 | static void *afs_proc_cells_start(struct seq_file *p, loff_t *pos); |
| 32 | static void *afs_proc_cells_next(struct seq_file *p, void *v, loff_t *pos); |
| 33 | static void afs_proc_cells_stop(struct seq_file *p, void *v); |
| 34 | static int afs_proc_cells_show(struct seq_file *m, void *v); |
| 35 | static ssize_t afs_proc_cells_write(struct file *file, const char __user *buf, |
| 36 | size_t size, loff_t *_pos); |
| 37 | |
James Morris | 88e9d34 | 2009-09-22 16:43:43 -0700 | [diff] [blame] | 38 | static const struct seq_operations afs_proc_cells_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | .start = afs_proc_cells_start, |
| 40 | .next = afs_proc_cells_next, |
| 41 | .stop = afs_proc_cells_stop, |
| 42 | .show = afs_proc_cells_show, |
| 43 | }; |
| 44 | |
Arjan van de Ven | 4b6f5d2 | 2006-03-28 01:56:42 -0800 | [diff] [blame] | 45 | static const struct file_operations afs_proc_cells_fops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | .open = afs_proc_cells_open, |
| 47 | .read = seq_read, |
| 48 | .write = afs_proc_cells_write, |
| 49 | .llseek = seq_lseek, |
| 50 | .release = seq_release, |
| 51 | }; |
| 52 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | static ssize_t afs_proc_rootcell_read(struct file *file, char __user *buf, |
| 54 | size_t size, loff_t *_pos); |
| 55 | static ssize_t afs_proc_rootcell_write(struct file *file, |
| 56 | const char __user *buf, |
| 57 | size_t size, loff_t *_pos); |
| 58 | |
Arjan van de Ven | 4b6f5d2 | 2006-03-28 01:56:42 -0800 | [diff] [blame] | 59 | static const struct file_operations afs_proc_rootcell_fops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | .read = afs_proc_rootcell_read, |
| 61 | .write = afs_proc_rootcell_write, |
| 62 | .llseek = no_llseek, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | }; |
| 64 | |
| 65 | static int afs_proc_cell_volumes_open(struct inode *inode, struct file *file); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | static void *afs_proc_cell_volumes_start(struct seq_file *p, loff_t *pos); |
| 67 | static void *afs_proc_cell_volumes_next(struct seq_file *p, void *v, |
| 68 | loff_t *pos); |
| 69 | static void afs_proc_cell_volumes_stop(struct seq_file *p, void *v); |
| 70 | static int afs_proc_cell_volumes_show(struct seq_file *m, void *v); |
| 71 | |
James Morris | 88e9d34 | 2009-09-22 16:43:43 -0700 | [diff] [blame] | 72 | static const struct seq_operations afs_proc_cell_volumes_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | .start = afs_proc_cell_volumes_start, |
| 74 | .next = afs_proc_cell_volumes_next, |
| 75 | .stop = afs_proc_cell_volumes_stop, |
| 76 | .show = afs_proc_cell_volumes_show, |
| 77 | }; |
| 78 | |
Arjan van de Ven | 4b6f5d2 | 2006-03-28 01:56:42 -0800 | [diff] [blame] | 79 | static const struct file_operations afs_proc_cell_volumes_fops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | .open = afs_proc_cell_volumes_open, |
| 81 | .read = seq_read, |
| 82 | .llseek = seq_lseek, |
Al Viro | b42d570 | 2013-11-22 01:53:47 -0500 | [diff] [blame] | 83 | .release = seq_release, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | }; |
| 85 | |
| 86 | static int afs_proc_cell_vlservers_open(struct inode *inode, |
| 87 | struct file *file); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | static void *afs_proc_cell_vlservers_start(struct seq_file *p, loff_t *pos); |
| 89 | static void *afs_proc_cell_vlservers_next(struct seq_file *p, void *v, |
| 90 | loff_t *pos); |
| 91 | static void afs_proc_cell_vlservers_stop(struct seq_file *p, void *v); |
| 92 | static int afs_proc_cell_vlservers_show(struct seq_file *m, void *v); |
| 93 | |
James Morris | 88e9d34 | 2009-09-22 16:43:43 -0700 | [diff] [blame] | 94 | static const struct seq_operations afs_proc_cell_vlservers_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | .start = afs_proc_cell_vlservers_start, |
| 96 | .next = afs_proc_cell_vlservers_next, |
| 97 | .stop = afs_proc_cell_vlservers_stop, |
| 98 | .show = afs_proc_cell_vlservers_show, |
| 99 | }; |
| 100 | |
Arjan van de Ven | 4b6f5d2 | 2006-03-28 01:56:42 -0800 | [diff] [blame] | 101 | static const struct file_operations afs_proc_cell_vlservers_fops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | .open = afs_proc_cell_vlservers_open, |
| 103 | .read = seq_read, |
| 104 | .llseek = seq_lseek, |
Al Viro | b42d570 | 2013-11-22 01:53:47 -0500 | [diff] [blame] | 105 | .release = seq_release, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | }; |
| 107 | |
| 108 | static int afs_proc_cell_servers_open(struct inode *inode, struct file *file); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | static void *afs_proc_cell_servers_start(struct seq_file *p, loff_t *pos); |
| 110 | static void *afs_proc_cell_servers_next(struct seq_file *p, void *v, |
| 111 | loff_t *pos); |
| 112 | static void afs_proc_cell_servers_stop(struct seq_file *p, void *v); |
| 113 | static int afs_proc_cell_servers_show(struct seq_file *m, void *v); |
| 114 | |
James Morris | 88e9d34 | 2009-09-22 16:43:43 -0700 | [diff] [blame] | 115 | static const struct seq_operations afs_proc_cell_servers_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | .start = afs_proc_cell_servers_start, |
| 117 | .next = afs_proc_cell_servers_next, |
| 118 | .stop = afs_proc_cell_servers_stop, |
| 119 | .show = afs_proc_cell_servers_show, |
| 120 | }; |
| 121 | |
Arjan van de Ven | 4b6f5d2 | 2006-03-28 01:56:42 -0800 | [diff] [blame] | 122 | static const struct file_operations afs_proc_cell_servers_fops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | .open = afs_proc_cell_servers_open, |
| 124 | .read = seq_read, |
| 125 | .llseek = seq_lseek, |
Al Viro | b42d570 | 2013-11-22 01:53:47 -0500 | [diff] [blame] | 126 | .release = seq_release, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | }; |
| 128 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | /* |
| 130 | * initialise the /proc/fs/afs/ directory |
| 131 | */ |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 132 | int afs_proc_init(struct afs_net *net) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | _enter(""); |
| 135 | |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 136 | net->proc_afs = proc_mkdir("fs/afs", NULL); |
| 137 | if (!net->proc_afs) |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 138 | goto error_dir; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 140 | if (!proc_create("cells", 0644, net->proc_afs, &afs_proc_cells_fops) || |
| 141 | !proc_create("rootcell", 0644, net->proc_afs, &afs_proc_rootcell_fops)) |
Al Viro | b42d570 | 2013-11-22 01:53:47 -0500 | [diff] [blame] | 142 | goto error_tree; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | |
| 144 | _leave(" = 0"); |
| 145 | return 0; |
| 146 | |
Al Viro | b42d570 | 2013-11-22 01:53:47 -0500 | [diff] [blame] | 147 | error_tree: |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 148 | proc_remove(net->proc_afs); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 149 | error_dir: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | _leave(" = -ENOMEM"); |
| 151 | return -ENOMEM; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 152 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | /* |
| 155 | * clean up the /proc/fs/afs/ directory |
| 156 | */ |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 157 | void afs_proc_cleanup(struct afs_net *net) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | { |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 159 | proc_remove(net->proc_afs); |
| 160 | net->proc_afs = NULL; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 161 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | /* |
| 164 | * open "/proc/fs/afs/cells" which provides a summary of extant cells |
| 165 | */ |
| 166 | static int afs_proc_cells_open(struct inode *inode, struct file *file) |
| 167 | { |
| 168 | struct seq_file *m; |
| 169 | int ret; |
| 170 | |
| 171 | ret = seq_open(file, &afs_proc_cells_ops); |
| 172 | if (ret < 0) |
| 173 | return ret; |
| 174 | |
| 175 | m = file->private_data; |
Al Viro | d9dda78 | 2013-03-31 18:16:14 -0400 | [diff] [blame] | 176 | m->private = PDE_DATA(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | |
| 178 | return 0; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 179 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | /* |
| 182 | * set up the iterator to start reading from the cells list and return the |
| 183 | * first item |
| 184 | */ |
| 185 | static void *afs_proc_cells_start(struct seq_file *m, loff_t *_pos) |
| 186 | { |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 187 | struct afs_net *net = afs_seq2net(m); |
| 188 | |
David Howells | 989782d | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 189 | rcu_read_lock(); |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 190 | return seq_list_start_head(&net->proc_cells, *_pos); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 191 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | /* |
| 194 | * move to next cell in cells list |
| 195 | */ |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 196 | 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] | 197 | { |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 198 | struct afs_net *net = afs_seq2net(m); |
| 199 | |
| 200 | return seq_list_next(v, &net->proc_cells, pos); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 201 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | /* |
| 204 | * clean up after reading from the cells list |
| 205 | */ |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 206 | static void afs_proc_cells_stop(struct seq_file *m, void *v) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | { |
David Howells | 989782d | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 208 | rcu_read_unlock(); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 209 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | /* |
| 212 | * display a header line followed by a load of cell lines |
| 213 | */ |
| 214 | static int afs_proc_cells_show(struct seq_file *m, void *v) |
| 215 | { |
| 216 | struct afs_cell *cell = list_entry(v, struct afs_cell, proc_link); |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 217 | struct afs_net *net = afs_seq2net(m); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 219 | if (v == &net->proc_cells) { |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 220 | /* display header on line 1 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | seq_puts(m, "USE NAME\n"); |
| 222 | return 0; |
| 223 | } |
| 224 | |
| 225 | /* display one cell per line on subsequent lines */ |
David Howells | 989782d | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 226 | seq_printf(m, "%3u %s\n", atomic_read(&cell->usage), cell->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | return 0; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 228 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | /* |
| 231 | * handle writes to /proc/fs/afs/cells |
| 232 | * - to add cells: echo "add <cellname> <IP>[:<IP>][:<IP>]" |
| 233 | */ |
| 234 | static ssize_t afs_proc_cells_write(struct file *file, const char __user *buf, |
| 235 | size_t size, loff_t *_pos) |
| 236 | { |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 237 | struct afs_net *net = afs_proc2net(file); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | char *kbuf, *name, *args; |
| 239 | int ret; |
| 240 | |
| 241 | /* start by dragging the command into memory */ |
| 242 | if (size <= 1 || size >= PAGE_SIZE) |
| 243 | return -EINVAL; |
| 244 | |
Al Viro | 16e5c1f | 2015-12-24 00:06:05 -0500 | [diff] [blame] | 245 | kbuf = memdup_user_nul(buf, size); |
| 246 | if (IS_ERR(kbuf)) |
| 247 | return PTR_ERR(kbuf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | |
| 249 | /* trim to first NL */ |
| 250 | name = memchr(kbuf, '\n', size); |
| 251 | if (name) |
| 252 | *name = 0; |
| 253 | |
| 254 | /* split into command, name and argslist */ |
| 255 | name = strchr(kbuf, ' '); |
| 256 | if (!name) |
| 257 | goto inval; |
| 258 | do { |
| 259 | *name++ = 0; |
| 260 | } while(*name == ' '); |
| 261 | if (!*name) |
| 262 | goto inval; |
| 263 | |
| 264 | args = strchr(name, ' '); |
| 265 | if (!args) |
| 266 | goto inval; |
| 267 | do { |
| 268 | *args++ = 0; |
| 269 | } while(*args == ' '); |
| 270 | if (!*args) |
| 271 | goto inval; |
| 272 | |
| 273 | /* determine command to perform */ |
| 274 | _debug("cmd=%s name=%s args=%s", kbuf, name, args); |
| 275 | |
| 276 | if (strcmp(kbuf, "add") == 0) { |
| 277 | struct afs_cell *cell; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | |
David Howells | 989782d | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 279 | cell = afs_lookup_cell(net, name, strlen(name), args, true); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 280 | if (IS_ERR(cell)) { |
| 281 | ret = PTR_ERR(cell); |
| 282 | goto done; |
| 283 | } |
| 284 | |
David Howells | 989782d | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 285 | set_bit(AFS_CELL_FL_NO_GC, &cell->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | printk("kAFS: Added new cell '%s'\n", name); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 287 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | goto inval; |
| 289 | } |
| 290 | |
| 291 | ret = size; |
| 292 | |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 293 | done: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | kfree(kbuf); |
| 295 | _leave(" = %d", ret); |
| 296 | return ret; |
| 297 | |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 298 | inval: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | ret = -EINVAL; |
| 300 | printk("kAFS: Invalid Command on /proc/fs/afs/cells file\n"); |
| 301 | goto done; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 302 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | static ssize_t afs_proc_rootcell_read(struct file *file, char __user *buf, |
| 305 | size_t size, loff_t *_pos) |
| 306 | { |
| 307 | return 0; |
| 308 | } |
| 309 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | /* |
| 311 | * handle writes to /proc/fs/afs/rootcell |
| 312 | * - to initialize rootcell: echo "cell.name:192.168.231.14" |
| 313 | */ |
| 314 | static ssize_t afs_proc_rootcell_write(struct file *file, |
| 315 | const char __user *buf, |
| 316 | size_t size, loff_t *_pos) |
| 317 | { |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 318 | struct afs_net *net = afs_proc2net(file); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | char *kbuf, *s; |
| 320 | int ret; |
| 321 | |
| 322 | /* start by dragging the command into memory */ |
| 323 | if (size <= 1 || size >= PAGE_SIZE) |
| 324 | return -EINVAL; |
| 325 | |
Al Viro | 16e5c1f | 2015-12-24 00:06:05 -0500 | [diff] [blame] | 326 | kbuf = memdup_user_nul(buf, size); |
| 327 | if (IS_ERR(kbuf)) |
| 328 | return PTR_ERR(kbuf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | |
| 330 | /* trim to first NL */ |
| 331 | s = memchr(kbuf, '\n', size); |
| 332 | if (s) |
| 333 | *s = 0; |
| 334 | |
| 335 | /* determine command to perform */ |
| 336 | _debug("rootcell=%s", kbuf); |
| 337 | |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 338 | ret = afs_cell_init(net, kbuf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | if (ret >= 0) |
| 340 | ret = size; /* consume everything, always */ |
| 341 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | kfree(kbuf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | _leave(" = %d", ret); |
| 344 | return ret; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 345 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | /* |
| 348 | * initialise /proc/fs/afs/<cell>/ |
| 349 | */ |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 350 | int afs_proc_cell_setup(struct afs_net *net, struct afs_cell *cell) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | { |
Al Viro | b42d570 | 2013-11-22 01:53:47 -0500 | [diff] [blame] | 352 | struct proc_dir_entry *dir; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | |
David Howells | 989782d | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 354 | _enter("%p{%s},%p", cell, cell->name, net->proc_afs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 356 | dir = proc_mkdir(cell->name, net->proc_afs); |
Al Viro | b42d570 | 2013-11-22 01:53:47 -0500 | [diff] [blame] | 357 | if (!dir) |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 358 | goto error_dir; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | |
Al Viro | b42d570 | 2013-11-22 01:53:47 -0500 | [diff] [blame] | 360 | if (!proc_create_data("servers", 0, dir, |
| 361 | &afs_proc_cell_servers_fops, cell) || |
| 362 | !proc_create_data("vlservers", 0, dir, |
| 363 | &afs_proc_cell_vlservers_fops, cell) || |
| 364 | !proc_create_data("volumes", 0, dir, |
| 365 | &afs_proc_cell_volumes_fops, cell)) |
| 366 | goto error_tree; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | |
| 368 | _leave(" = 0"); |
| 369 | return 0; |
| 370 | |
Al Viro | b42d570 | 2013-11-22 01:53:47 -0500 | [diff] [blame] | 371 | error_tree: |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 372 | remove_proc_subtree(cell->name, net->proc_afs); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 373 | error_dir: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | _leave(" = -ENOMEM"); |
| 375 | return -ENOMEM; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 376 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | /* |
| 379 | * remove /proc/fs/afs/<cell>/ |
| 380 | */ |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 381 | void afs_proc_cell_remove(struct afs_net *net, struct afs_cell *cell) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | { |
| 383 | _enter(""); |
| 384 | |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 385 | remove_proc_subtree(cell->name, net->proc_afs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | |
| 387 | _leave(""); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 388 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | /* |
| 391 | * open "/proc/fs/afs/<cell>/volumes" which provides a summary of extant cells |
| 392 | */ |
| 393 | static int afs_proc_cell_volumes_open(struct inode *inode, struct file *file) |
| 394 | { |
| 395 | struct afs_cell *cell; |
| 396 | struct seq_file *m; |
| 397 | int ret; |
| 398 | |
Al Viro | d9dda78 | 2013-03-31 18:16:14 -0400 | [diff] [blame] | 399 | cell = PDE_DATA(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | if (!cell) |
| 401 | return -ENOENT; |
| 402 | |
| 403 | ret = seq_open(file, &afs_proc_cell_volumes_ops); |
| 404 | if (ret < 0) |
| 405 | return ret; |
| 406 | |
| 407 | m = file->private_data; |
| 408 | m->private = cell; |
| 409 | |
| 410 | return 0; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 411 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | * set up the iterator to start reading from the cells list and return the |
| 415 | * first item |
| 416 | */ |
| 417 | static void *afs_proc_cell_volumes_start(struct seq_file *m, loff_t *_pos) |
| 418 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | struct afs_cell *cell = m->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | |
| 421 | _enter("cell=%p pos=%Ld", cell, *_pos); |
| 422 | |
| 423 | /* lock the list against modification */ |
| 424 | down_read(&cell->vl_sem); |
Pavel Emelianov | a6a8bd6 | 2007-07-15 23:39:52 -0700 | [diff] [blame] | 425 | return seq_list_start_head(&cell->vl_list, *_pos); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 426 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | /* |
| 429 | * move to next cell in cells list |
| 430 | */ |
| 431 | static void *afs_proc_cell_volumes_next(struct seq_file *p, void *v, |
| 432 | loff_t *_pos) |
| 433 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | struct afs_cell *cell = p->private; |
| 435 | |
| 436 | _enter("cell=%p pos=%Ld", cell, *_pos); |
Pavel Emelianov | a6a8bd6 | 2007-07-15 23:39:52 -0700 | [diff] [blame] | 437 | return seq_list_next(v, &cell->vl_list, _pos); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 438 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | /* |
| 441 | * clean up after reading from the cells list |
| 442 | */ |
| 443 | static void afs_proc_cell_volumes_stop(struct seq_file *p, void *v) |
| 444 | { |
| 445 | struct afs_cell *cell = p->private; |
| 446 | |
| 447 | up_read(&cell->vl_sem); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 448 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | |
Adrian Bunk | c1206a2 | 2007-10-16 23:26:41 -0700 | [diff] [blame] | 450 | static const char afs_vlocation_states[][4] = { |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 451 | [AFS_VL_NEW] = "New", |
| 452 | [AFS_VL_CREATING] = "Crt", |
| 453 | [AFS_VL_VALID] = "Val", |
| 454 | [AFS_VL_NO_VOLUME] = "NoV", |
| 455 | [AFS_VL_UPDATING] = "Upd", |
| 456 | [AFS_VL_VOLUME_DELETED] = "Del", |
| 457 | [AFS_VL_UNCERTAIN] = "Unc", |
| 458 | }; |
| 459 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | /* |
| 461 | * display a header line followed by a load of volume lines |
| 462 | */ |
| 463 | static int afs_proc_cell_volumes_show(struct seq_file *m, void *v) |
| 464 | { |
Pavel Emelianov | a6a8bd6 | 2007-07-15 23:39:52 -0700 | [diff] [blame] | 465 | struct afs_cell *cell = m->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | struct afs_vlocation *vlocation = |
| 467 | list_entry(v, struct afs_vlocation, link); |
| 468 | |
| 469 | /* display header on line 1 */ |
Pavel Emelianov | a6a8bd6 | 2007-07-15 23:39:52 -0700 | [diff] [blame] | 470 | if (v == &cell->vl_list) { |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 471 | seq_puts(m, "USE STT VLID[0] VLID[1] VLID[2] NAME\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 472 | return 0; |
| 473 | } |
| 474 | |
| 475 | /* display one cell per line on subsequent lines */ |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 476 | seq_printf(m, "%3d %s %08x %08x %08x %s\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 477 | atomic_read(&vlocation->usage), |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 478 | afs_vlocation_states[vlocation->state], |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 479 | vlocation->vldb.vid[0], |
| 480 | vlocation->vldb.vid[1], |
| 481 | vlocation->vldb.vid[2], |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 482 | vlocation->vldb.name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | |
| 484 | return 0; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 485 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 486 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | /* |
| 488 | * open "/proc/fs/afs/<cell>/vlservers" which provides a list of volume |
| 489 | * location server |
| 490 | */ |
| 491 | static int afs_proc_cell_vlservers_open(struct inode *inode, struct file *file) |
| 492 | { |
| 493 | struct afs_cell *cell; |
| 494 | struct seq_file *m; |
| 495 | int ret; |
| 496 | |
Al Viro | d9dda78 | 2013-03-31 18:16:14 -0400 | [diff] [blame] | 497 | cell = PDE_DATA(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 498 | if (!cell) |
| 499 | return -ENOENT; |
| 500 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 501 | ret = seq_open(file, &afs_proc_cell_vlservers_ops); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 502 | if (ret<0) |
| 503 | return ret; |
| 504 | |
| 505 | m = file->private_data; |
| 506 | m->private = cell; |
| 507 | |
| 508 | return 0; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 509 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 510 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 512 | * set up the iterator to start reading from the cells list and return the |
| 513 | * first item |
| 514 | */ |
| 515 | static void *afs_proc_cell_vlservers_start(struct seq_file *m, loff_t *_pos) |
| 516 | { |
David Howells | 8b2a464 | 2017-11-02 15:27:50 +0000 | [diff] [blame^] | 517 | struct afs_addr_list *alist; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 518 | struct afs_cell *cell = m->private; |
| 519 | loff_t pos = *_pos; |
| 520 | |
David Howells | 8b2a464 | 2017-11-02 15:27:50 +0000 | [diff] [blame^] | 521 | rcu_read_lock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | |
David Howells | 8b2a464 | 2017-11-02 15:27:50 +0000 | [diff] [blame^] | 523 | alist = rcu_dereference(cell->vl_addrs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 524 | |
| 525 | /* allow for the header line */ |
| 526 | if (!pos) |
| 527 | return (void *) 1; |
| 528 | pos--; |
| 529 | |
David Howells | 8b2a464 | 2017-11-02 15:27:50 +0000 | [diff] [blame^] | 530 | if (!alist || pos >= alist->nr_addrs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | return NULL; |
| 532 | |
David Howells | 8b2a464 | 2017-11-02 15:27:50 +0000 | [diff] [blame^] | 533 | return alist->addrs + pos; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 534 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 535 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 536 | /* |
| 537 | * move to next cell in cells list |
| 538 | */ |
| 539 | static void *afs_proc_cell_vlservers_next(struct seq_file *p, void *v, |
| 540 | loff_t *_pos) |
| 541 | { |
David Howells | 8b2a464 | 2017-11-02 15:27:50 +0000 | [diff] [blame^] | 542 | struct afs_addr_list *alist; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | struct afs_cell *cell = p->private; |
| 544 | loff_t pos; |
| 545 | |
David Howells | 8b2a464 | 2017-11-02 15:27:50 +0000 | [diff] [blame^] | 546 | alist = rcu_dereference(cell->vl_addrs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 547 | |
| 548 | pos = *_pos; |
| 549 | (*_pos)++; |
David Howells | 8b2a464 | 2017-11-02 15:27:50 +0000 | [diff] [blame^] | 550 | if (!alist || pos >= alist->nr_addrs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | return NULL; |
| 552 | |
David Howells | 8b2a464 | 2017-11-02 15:27:50 +0000 | [diff] [blame^] | 553 | return alist->addrs + pos; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 554 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 556 | /* |
| 557 | * clean up after reading from the cells list |
| 558 | */ |
| 559 | static void afs_proc_cell_vlservers_stop(struct seq_file *p, void *v) |
| 560 | { |
David Howells | 8b2a464 | 2017-11-02 15:27:50 +0000 | [diff] [blame^] | 561 | rcu_read_unlock(); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 562 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 563 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | /* |
| 565 | * display a header line followed by a load of volume lines |
| 566 | */ |
| 567 | static int afs_proc_cell_vlservers_show(struct seq_file *m, void *v) |
| 568 | { |
David Howells | 4d9df98 | 2017-11-02 15:27:47 +0000 | [diff] [blame] | 569 | struct sockaddr_rxrpc *addr = v; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 570 | |
| 571 | /* display header on line 1 */ |
David Howells | 4d9df98 | 2017-11-02 15:27:47 +0000 | [diff] [blame] | 572 | if (v == (void *)1) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 573 | seq_puts(m, "ADDRESS\n"); |
| 574 | return 0; |
| 575 | } |
| 576 | |
| 577 | /* display one cell per line on subsequent lines */ |
David Howells | 4d9df98 | 2017-11-02 15:27:47 +0000 | [diff] [blame] | 578 | seq_printf(m, "%pISp\n", &addr->transport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 579 | return 0; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 580 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 581 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 582 | /* |
| 583 | * open "/proc/fs/afs/<cell>/servers" which provides a summary of active |
| 584 | * servers |
| 585 | */ |
| 586 | static int afs_proc_cell_servers_open(struct inode *inode, struct file *file) |
| 587 | { |
| 588 | struct afs_cell *cell; |
| 589 | struct seq_file *m; |
| 590 | int ret; |
| 591 | |
Al Viro | d9dda78 | 2013-03-31 18:16:14 -0400 | [diff] [blame] | 592 | cell = PDE_DATA(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 593 | if (!cell) |
| 594 | return -ENOENT; |
| 595 | |
| 596 | ret = seq_open(file, &afs_proc_cell_servers_ops); |
| 597 | if (ret < 0) |
| 598 | return ret; |
| 599 | |
| 600 | m = file->private_data; |
| 601 | m->private = cell; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 602 | return 0; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 603 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 604 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 605 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | * set up the iterator to start reading from the cells list and return the |
| 607 | * first item |
| 608 | */ |
| 609 | static void *afs_proc_cell_servers_start(struct seq_file *m, loff_t *_pos) |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 610 | __acquires(m->private->servers_lock) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 611 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 | struct afs_cell *cell = m->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 613 | |
| 614 | _enter("cell=%p pos=%Ld", cell, *_pos); |
| 615 | |
| 616 | /* lock the list against modification */ |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 617 | read_lock(&cell->servers_lock); |
Pavel Emelianov | a6a8bd6 | 2007-07-15 23:39:52 -0700 | [diff] [blame] | 618 | return seq_list_start_head(&cell->servers, *_pos); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 619 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 620 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 621 | /* |
| 622 | * move to next cell in cells list |
| 623 | */ |
| 624 | static void *afs_proc_cell_servers_next(struct seq_file *p, void *v, |
| 625 | loff_t *_pos) |
| 626 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 627 | struct afs_cell *cell = p->private; |
| 628 | |
| 629 | _enter("cell=%p pos=%Ld", cell, *_pos); |
Pavel Emelianov | a6a8bd6 | 2007-07-15 23:39:52 -0700 | [diff] [blame] | 630 | return seq_list_next(v, &cell->servers, _pos); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 631 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 632 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 633 | /* |
| 634 | * clean up after reading from the cells list |
| 635 | */ |
| 636 | static void afs_proc_cell_servers_stop(struct seq_file *p, void *v) |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 637 | __releases(p->private->servers_lock) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 638 | { |
| 639 | struct afs_cell *cell = p->private; |
| 640 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 641 | read_unlock(&cell->servers_lock); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 642 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 643 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 644 | /* |
| 645 | * display a header line followed by a load of volume lines |
| 646 | */ |
| 647 | static int afs_proc_cell_servers_show(struct seq_file *m, void *v) |
| 648 | { |
Pavel Emelianov | a6a8bd6 | 2007-07-15 23:39:52 -0700 | [diff] [blame] | 649 | struct afs_cell *cell = m->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 650 | struct afs_server *server = list_entry(v, struct afs_server, link); |
David Howells | 4d9df98 | 2017-11-02 15:27:47 +0000 | [diff] [blame] | 651 | char ipaddr[64]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 652 | |
| 653 | /* display header on line 1 */ |
Pavel Emelianov | a6a8bd6 | 2007-07-15 23:39:52 -0700 | [diff] [blame] | 654 | if (v == &cell->servers) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 655 | seq_puts(m, "USE ADDR STATE\n"); |
| 656 | return 0; |
| 657 | } |
| 658 | |
| 659 | /* display one cell per line on subsequent lines */ |
David Howells | 8b2a464 | 2017-11-02 15:27:50 +0000 | [diff] [blame^] | 660 | sprintf(ipaddr, "%pISp", &server->addrs->addrs[0].transport); |
David Howells | 3838d3e | 2017-11-02 15:27:47 +0000 | [diff] [blame] | 661 | seq_printf(m, "%3d %-15s %5d\n", |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 662 | atomic_read(&server->usage), ipaddr, server->fs_state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 663 | |
| 664 | return 0; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 665 | } |