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 | |
| 189 | down_read(&net->proc_cells_sem); |
| 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 | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame^] | 208 | struct afs_net *net = afs_seq2net(m); |
| 209 | |
| 210 | up_read(&net->proc_cells_sem); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 211 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | /* |
| 214 | * display a header line followed by a load of cell lines |
| 215 | */ |
| 216 | static int afs_proc_cells_show(struct seq_file *m, void *v) |
| 217 | { |
| 218 | struct afs_cell *cell = list_entry(v, struct afs_cell, proc_link); |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame^] | 219 | struct afs_net *net = afs_seq2net(m); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame^] | 221 | if (v == &net->proc_cells) { |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 222 | /* display header on line 1 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | seq_puts(m, "USE NAME\n"); |
| 224 | return 0; |
| 225 | } |
| 226 | |
| 227 | /* display one cell per line on subsequent lines */ |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 228 | seq_printf(m, "%3d %s\n", |
| 229 | atomic_read(&cell->usage), cell->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | return 0; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 231 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | /* |
| 234 | * handle writes to /proc/fs/afs/cells |
| 235 | * - to add cells: echo "add <cellname> <IP>[:<IP>][:<IP>]" |
| 236 | */ |
| 237 | static ssize_t afs_proc_cells_write(struct file *file, const char __user *buf, |
| 238 | size_t size, loff_t *_pos) |
| 239 | { |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame^] | 240 | struct afs_net *net = afs_proc2net(file); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | char *kbuf, *name, *args; |
| 242 | int ret; |
| 243 | |
| 244 | /* start by dragging the command into memory */ |
| 245 | if (size <= 1 || size >= PAGE_SIZE) |
| 246 | return -EINVAL; |
| 247 | |
Al Viro | 16e5c1f | 2015-12-24 00:06:05 -0500 | [diff] [blame] | 248 | kbuf = memdup_user_nul(buf, size); |
| 249 | if (IS_ERR(kbuf)) |
| 250 | return PTR_ERR(kbuf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | |
| 252 | /* trim to first NL */ |
| 253 | name = memchr(kbuf, '\n', size); |
| 254 | if (name) |
| 255 | *name = 0; |
| 256 | |
| 257 | /* split into command, name and argslist */ |
| 258 | name = strchr(kbuf, ' '); |
| 259 | if (!name) |
| 260 | goto inval; |
| 261 | do { |
| 262 | *name++ = 0; |
| 263 | } while(*name == ' '); |
| 264 | if (!*name) |
| 265 | goto inval; |
| 266 | |
| 267 | args = strchr(name, ' '); |
| 268 | if (!args) |
| 269 | goto inval; |
| 270 | do { |
| 271 | *args++ = 0; |
| 272 | } while(*args == ' '); |
| 273 | if (!*args) |
| 274 | goto inval; |
| 275 | |
| 276 | /* determine command to perform */ |
| 277 | _debug("cmd=%s name=%s args=%s", kbuf, name, args); |
| 278 | |
| 279 | if (strcmp(kbuf, "add") == 0) { |
| 280 | struct afs_cell *cell; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame^] | 282 | cell = afs_cell_create(net, name, strlen(name), args, false); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 283 | if (IS_ERR(cell)) { |
| 284 | ret = PTR_ERR(cell); |
| 285 | goto done; |
| 286 | } |
| 287 | |
| 288 | afs_put_cell(cell); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | printk("kAFS: Added new cell '%s'\n", name); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 290 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | goto inval; |
| 292 | } |
| 293 | |
| 294 | ret = size; |
| 295 | |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 296 | done: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | kfree(kbuf); |
| 298 | _leave(" = %d", ret); |
| 299 | return ret; |
| 300 | |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 301 | inval: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | ret = -EINVAL; |
| 303 | printk("kAFS: Invalid Command on /proc/fs/afs/cells file\n"); |
| 304 | goto done; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 305 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | static ssize_t afs_proc_rootcell_read(struct file *file, char __user *buf, |
| 308 | size_t size, loff_t *_pos) |
| 309 | { |
| 310 | return 0; |
| 311 | } |
| 312 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | /* |
| 314 | * handle writes to /proc/fs/afs/rootcell |
| 315 | * - to initialize rootcell: echo "cell.name:192.168.231.14" |
| 316 | */ |
| 317 | static ssize_t afs_proc_rootcell_write(struct file *file, |
| 318 | const char __user *buf, |
| 319 | size_t size, loff_t *_pos) |
| 320 | { |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame^] | 321 | struct afs_net *net = afs_proc2net(file); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | char *kbuf, *s; |
| 323 | int ret; |
| 324 | |
| 325 | /* start by dragging the command into memory */ |
| 326 | if (size <= 1 || size >= PAGE_SIZE) |
| 327 | return -EINVAL; |
| 328 | |
Al Viro | 16e5c1f | 2015-12-24 00:06:05 -0500 | [diff] [blame] | 329 | kbuf = memdup_user_nul(buf, size); |
| 330 | if (IS_ERR(kbuf)) |
| 331 | return PTR_ERR(kbuf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | |
| 333 | /* trim to first NL */ |
| 334 | s = memchr(kbuf, '\n', size); |
| 335 | if (s) |
| 336 | *s = 0; |
| 337 | |
| 338 | /* determine command to perform */ |
| 339 | _debug("rootcell=%s", kbuf); |
| 340 | |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame^] | 341 | ret = afs_cell_init(net, kbuf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | if (ret >= 0) |
| 343 | ret = size; /* consume everything, always */ |
| 344 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | kfree(kbuf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | _leave(" = %d", ret); |
| 347 | return ret; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 348 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | /* |
| 351 | * initialise /proc/fs/afs/<cell>/ |
| 352 | */ |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame^] | 353 | 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] | 354 | { |
Al Viro | b42d570 | 2013-11-22 01:53:47 -0500 | [diff] [blame] | 355 | struct proc_dir_entry *dir; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | |
| 357 | _enter("%p{%s}", cell, cell->name); |
| 358 | |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame^] | 359 | dir = proc_mkdir(cell->name, net->proc_afs); |
Al Viro | b42d570 | 2013-11-22 01:53:47 -0500 | [diff] [blame] | 360 | if (!dir) |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 361 | goto error_dir; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | |
Al Viro | b42d570 | 2013-11-22 01:53:47 -0500 | [diff] [blame] | 363 | if (!proc_create_data("servers", 0, dir, |
| 364 | &afs_proc_cell_servers_fops, cell) || |
| 365 | !proc_create_data("vlservers", 0, dir, |
| 366 | &afs_proc_cell_vlservers_fops, cell) || |
| 367 | !proc_create_data("volumes", 0, dir, |
| 368 | &afs_proc_cell_volumes_fops, cell)) |
| 369 | goto error_tree; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | |
| 371 | _leave(" = 0"); |
| 372 | return 0; |
| 373 | |
Al Viro | b42d570 | 2013-11-22 01:53:47 -0500 | [diff] [blame] | 374 | error_tree: |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame^] | 375 | remove_proc_subtree(cell->name, net->proc_afs); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 376 | error_dir: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | _leave(" = -ENOMEM"); |
| 378 | return -ENOMEM; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 379 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | /* |
| 382 | * remove /proc/fs/afs/<cell>/ |
| 383 | */ |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame^] | 384 | 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] | 385 | { |
| 386 | _enter(""); |
| 387 | |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame^] | 388 | remove_proc_subtree(cell->name, net->proc_afs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | |
| 390 | _leave(""); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 391 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | /* |
| 394 | * open "/proc/fs/afs/<cell>/volumes" which provides a summary of extant cells |
| 395 | */ |
| 396 | static int afs_proc_cell_volumes_open(struct inode *inode, struct file *file) |
| 397 | { |
| 398 | struct afs_cell *cell; |
| 399 | struct seq_file *m; |
| 400 | int ret; |
| 401 | |
Al Viro | d9dda78 | 2013-03-31 18:16:14 -0400 | [diff] [blame] | 402 | cell = PDE_DATA(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | if (!cell) |
| 404 | return -ENOENT; |
| 405 | |
| 406 | ret = seq_open(file, &afs_proc_cell_volumes_ops); |
| 407 | if (ret < 0) |
| 408 | return ret; |
| 409 | |
| 410 | m = file->private_data; |
| 411 | m->private = cell; |
| 412 | |
| 413 | return 0; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 414 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | * set up the iterator to start reading from the cells list and return the |
| 418 | * first item |
| 419 | */ |
| 420 | static void *afs_proc_cell_volumes_start(struct seq_file *m, loff_t *_pos) |
| 421 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | struct afs_cell *cell = m->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | |
| 424 | _enter("cell=%p pos=%Ld", cell, *_pos); |
| 425 | |
| 426 | /* lock the list against modification */ |
| 427 | down_read(&cell->vl_sem); |
Pavel Emelianov | a6a8bd6 | 2007-07-15 23:39:52 -0700 | [diff] [blame] | 428 | return seq_list_start_head(&cell->vl_list, *_pos); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 429 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | /* |
| 432 | * move to next cell in cells list |
| 433 | */ |
| 434 | static void *afs_proc_cell_volumes_next(struct seq_file *p, void *v, |
| 435 | loff_t *_pos) |
| 436 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | struct afs_cell *cell = p->private; |
| 438 | |
| 439 | _enter("cell=%p pos=%Ld", cell, *_pos); |
Pavel Emelianov | a6a8bd6 | 2007-07-15 23:39:52 -0700 | [diff] [blame] | 440 | return seq_list_next(v, &cell->vl_list, _pos); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 441 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | /* |
| 444 | * clean up after reading from the cells list |
| 445 | */ |
| 446 | static void afs_proc_cell_volumes_stop(struct seq_file *p, void *v) |
| 447 | { |
| 448 | struct afs_cell *cell = p->private; |
| 449 | |
| 450 | up_read(&cell->vl_sem); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 451 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 452 | |
Adrian Bunk | c1206a2 | 2007-10-16 23:26:41 -0700 | [diff] [blame] | 453 | static const char afs_vlocation_states[][4] = { |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 454 | [AFS_VL_NEW] = "New", |
| 455 | [AFS_VL_CREATING] = "Crt", |
| 456 | [AFS_VL_VALID] = "Val", |
| 457 | [AFS_VL_NO_VOLUME] = "NoV", |
| 458 | [AFS_VL_UPDATING] = "Upd", |
| 459 | [AFS_VL_VOLUME_DELETED] = "Del", |
| 460 | [AFS_VL_UNCERTAIN] = "Unc", |
| 461 | }; |
| 462 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 463 | /* |
| 464 | * display a header line followed by a load of volume lines |
| 465 | */ |
| 466 | static int afs_proc_cell_volumes_show(struct seq_file *m, void *v) |
| 467 | { |
Pavel Emelianov | a6a8bd6 | 2007-07-15 23:39:52 -0700 | [diff] [blame] | 468 | struct afs_cell *cell = m->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 469 | struct afs_vlocation *vlocation = |
| 470 | list_entry(v, struct afs_vlocation, link); |
| 471 | |
| 472 | /* display header on line 1 */ |
Pavel Emelianov | a6a8bd6 | 2007-07-15 23:39:52 -0700 | [diff] [blame] | 473 | if (v == &cell->vl_list) { |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 474 | 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] | 475 | return 0; |
| 476 | } |
| 477 | |
| 478 | /* display one cell per line on subsequent lines */ |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 479 | seq_printf(m, "%3d %s %08x %08x %08x %s\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | atomic_read(&vlocation->usage), |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 481 | afs_vlocation_states[vlocation->state], |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | vlocation->vldb.vid[0], |
| 483 | vlocation->vldb.vid[1], |
| 484 | vlocation->vldb.vid[2], |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 485 | vlocation->vldb.name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 486 | |
| 487 | return 0; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 488 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 | /* |
| 491 | * open "/proc/fs/afs/<cell>/vlservers" which provides a list of volume |
| 492 | * location server |
| 493 | */ |
| 494 | static int afs_proc_cell_vlservers_open(struct inode *inode, struct file *file) |
| 495 | { |
| 496 | struct afs_cell *cell; |
| 497 | struct seq_file *m; |
| 498 | int ret; |
| 499 | |
Al Viro | d9dda78 | 2013-03-31 18:16:14 -0400 | [diff] [blame] | 500 | cell = PDE_DATA(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 501 | if (!cell) |
| 502 | return -ENOENT; |
| 503 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 504 | ret = seq_open(file, &afs_proc_cell_vlservers_ops); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | if (ret<0) |
| 506 | return ret; |
| 507 | |
| 508 | m = file->private_data; |
| 509 | m->private = cell; |
| 510 | |
| 511 | return 0; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 512 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 514 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 515 | * set up the iterator to start reading from the cells list and return the |
| 516 | * first item |
| 517 | */ |
| 518 | static void *afs_proc_cell_vlservers_start(struct seq_file *m, loff_t *_pos) |
| 519 | { |
| 520 | struct afs_cell *cell = m->private; |
| 521 | loff_t pos = *_pos; |
| 522 | |
| 523 | _enter("cell=%p pos=%Ld", cell, *_pos); |
| 524 | |
| 525 | /* lock the list against modification */ |
| 526 | down_read(&cell->vl_sem); |
| 527 | |
| 528 | /* allow for the header line */ |
| 529 | if (!pos) |
| 530 | return (void *) 1; |
| 531 | pos--; |
| 532 | |
| 533 | if (pos >= cell->vl_naddrs) |
| 534 | return NULL; |
| 535 | |
| 536 | return &cell->vl_addrs[pos]; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 537 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | /* |
| 540 | * move to next cell in cells list |
| 541 | */ |
| 542 | static void *afs_proc_cell_vlservers_next(struct seq_file *p, void *v, |
| 543 | loff_t *_pos) |
| 544 | { |
| 545 | struct afs_cell *cell = p->private; |
| 546 | loff_t pos; |
| 547 | |
| 548 | _enter("cell=%p{nad=%u} pos=%Ld", cell, cell->vl_naddrs, *_pos); |
| 549 | |
| 550 | pos = *_pos; |
| 551 | (*_pos)++; |
| 552 | if (pos >= cell->vl_naddrs) |
| 553 | return NULL; |
| 554 | |
| 555 | return &cell->vl_addrs[pos]; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 556 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 558 | /* |
| 559 | * clean up after reading from the cells list |
| 560 | */ |
| 561 | static void afs_proc_cell_vlservers_stop(struct seq_file *p, void *v) |
| 562 | { |
| 563 | struct afs_cell *cell = p->private; |
| 564 | |
| 565 | up_read(&cell->vl_sem); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 566 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 | /* |
| 569 | * display a header line followed by a load of volume lines |
| 570 | */ |
| 571 | static int afs_proc_cell_vlservers_show(struct seq_file *m, void *v) |
| 572 | { |
| 573 | struct in_addr *addr = v; |
| 574 | |
| 575 | /* display header on line 1 */ |
| 576 | if (v == (struct in_addr *) 1) { |
| 577 | seq_puts(m, "ADDRESS\n"); |
| 578 | return 0; |
| 579 | } |
| 580 | |
| 581 | /* display one cell per line on subsequent lines */ |
Harvey Harrison | be85940 | 2008-10-31 00:56:28 -0700 | [diff] [blame] | 582 | seq_printf(m, "%pI4\n", &addr->s_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 583 | return 0; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 584 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 585 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 586 | /* |
| 587 | * open "/proc/fs/afs/<cell>/servers" which provides a summary of active |
| 588 | * servers |
| 589 | */ |
| 590 | static int afs_proc_cell_servers_open(struct inode *inode, struct file *file) |
| 591 | { |
| 592 | struct afs_cell *cell; |
| 593 | struct seq_file *m; |
| 594 | int ret; |
| 595 | |
Al Viro | d9dda78 | 2013-03-31 18:16:14 -0400 | [diff] [blame] | 596 | cell = PDE_DATA(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 597 | if (!cell) |
| 598 | return -ENOENT; |
| 599 | |
| 600 | ret = seq_open(file, &afs_proc_cell_servers_ops); |
| 601 | if (ret < 0) |
| 602 | return ret; |
| 603 | |
| 604 | m = file->private_data; |
| 605 | m->private = cell; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | return 0; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 607 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 608 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 609 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 610 | * set up the iterator to start reading from the cells list and return the |
| 611 | * first item |
| 612 | */ |
| 613 | 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] | 614 | __acquires(m->private->servers_lock) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 615 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 616 | struct afs_cell *cell = m->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 617 | |
| 618 | _enter("cell=%p pos=%Ld", cell, *_pos); |
| 619 | |
| 620 | /* lock the list against modification */ |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 621 | read_lock(&cell->servers_lock); |
Pavel Emelianov | a6a8bd6 | 2007-07-15 23:39:52 -0700 | [diff] [blame] | 622 | return seq_list_start_head(&cell->servers, *_pos); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 623 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 624 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 625 | /* |
| 626 | * move to next cell in cells list |
| 627 | */ |
| 628 | static void *afs_proc_cell_servers_next(struct seq_file *p, void *v, |
| 629 | loff_t *_pos) |
| 630 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 631 | struct afs_cell *cell = p->private; |
| 632 | |
| 633 | _enter("cell=%p pos=%Ld", cell, *_pos); |
Pavel Emelianov | a6a8bd6 | 2007-07-15 23:39:52 -0700 | [diff] [blame] | 634 | return seq_list_next(v, &cell->servers, _pos); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 635 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 636 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 637 | /* |
| 638 | * clean up after reading from the cells list |
| 639 | */ |
| 640 | 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] | 641 | __releases(p->private->servers_lock) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 642 | { |
| 643 | struct afs_cell *cell = p->private; |
| 644 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 645 | read_unlock(&cell->servers_lock); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 646 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 647 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 648 | /* |
| 649 | * display a header line followed by a load of volume lines |
| 650 | */ |
| 651 | static int afs_proc_cell_servers_show(struct seq_file *m, void *v) |
| 652 | { |
Pavel Emelianov | a6a8bd6 | 2007-07-15 23:39:52 -0700 | [diff] [blame] | 653 | struct afs_cell *cell = m->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 654 | struct afs_server *server = list_entry(v, struct afs_server, link); |
| 655 | char ipaddr[20]; |
| 656 | |
| 657 | /* display header on line 1 */ |
Pavel Emelianov | a6a8bd6 | 2007-07-15 23:39:52 -0700 | [diff] [blame] | 658 | if (v == &cell->servers) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 659 | seq_puts(m, "USE ADDR STATE\n"); |
| 660 | return 0; |
| 661 | } |
| 662 | |
| 663 | /* display one cell per line on subsequent lines */ |
Harvey Harrison | be85940 | 2008-10-31 00:56:28 -0700 | [diff] [blame] | 664 | sprintf(ipaddr, "%pI4", &server->addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 665 | seq_printf(m, "%3d %-15.15s %5d\n", |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 666 | atomic_read(&server->usage), ipaddr, server->fs_state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 667 | |
| 668 | return 0; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 669 | } |