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 | |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 108 | static int afs_proc_servers_open(struct inode *inode, struct file *file); |
| 109 | static void *afs_proc_servers_start(struct seq_file *p, loff_t *pos); |
| 110 | static void *afs_proc_servers_next(struct seq_file *p, void *v, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | loff_t *pos); |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 112 | static void afs_proc_servers_stop(struct seq_file *p, void *v); |
| 113 | static int afs_proc_servers_show(struct seq_file *m, void *v); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 115 | static const struct seq_operations afs_proc_servers_ops = { |
| 116 | .start = afs_proc_servers_start, |
| 117 | .next = afs_proc_servers_next, |
| 118 | .stop = afs_proc_servers_stop, |
| 119 | .show = afs_proc_servers_show, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | }; |
| 121 | |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 122 | static const struct file_operations afs_proc_servers_fops = { |
| 123 | .open = afs_proc_servers_open, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
David Howells | 6f8880d | 2018-04-09 21:12:31 +0100 | [diff] [blame^] | 129 | static int afs_proc_sysname_open(struct inode *inode, struct file *file); |
| 130 | static int afs_proc_sysname_release(struct inode *inode, struct file *file); |
| 131 | static void *afs_proc_sysname_start(struct seq_file *p, loff_t *pos); |
| 132 | static void *afs_proc_sysname_next(struct seq_file *p, void *v, |
| 133 | loff_t *pos); |
| 134 | static void afs_proc_sysname_stop(struct seq_file *p, void *v); |
| 135 | static int afs_proc_sysname_show(struct seq_file *m, void *v); |
| 136 | static ssize_t afs_proc_sysname_write(struct file *file, |
| 137 | const char __user *buf, |
| 138 | size_t size, loff_t *_pos); |
| 139 | |
| 140 | static const struct seq_operations afs_proc_sysname_ops = { |
| 141 | .start = afs_proc_sysname_start, |
| 142 | .next = afs_proc_sysname_next, |
| 143 | .stop = afs_proc_sysname_stop, |
| 144 | .show = afs_proc_sysname_show, |
| 145 | }; |
| 146 | |
| 147 | static const struct file_operations afs_proc_sysname_fops = { |
| 148 | .open = afs_proc_sysname_open, |
| 149 | .read = seq_read, |
| 150 | .llseek = seq_lseek, |
| 151 | .release = afs_proc_sysname_release, |
| 152 | .write = afs_proc_sysname_write, |
| 153 | }; |
| 154 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | /* |
| 156 | * initialise the /proc/fs/afs/ directory |
| 157 | */ |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 158 | int afs_proc_init(struct afs_net *net) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | _enter(""); |
| 161 | |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 162 | net->proc_afs = proc_mkdir("fs/afs", NULL); |
| 163 | if (!net->proc_afs) |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 164 | goto error_dir; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 166 | if (!proc_create("cells", 0644, net->proc_afs, &afs_proc_cells_fops) || |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 167 | !proc_create("rootcell", 0644, net->proc_afs, &afs_proc_rootcell_fops) || |
David Howells | 6f8880d | 2018-04-09 21:12:31 +0100 | [diff] [blame^] | 168 | !proc_create("servers", 0644, net->proc_afs, &afs_proc_servers_fops) || |
| 169 | !proc_create("sysname", 0644, net->proc_afs, &afs_proc_sysname_fops)) |
Al Viro | b42d570 | 2013-11-22 01:53:47 -0500 | [diff] [blame] | 170 | goto error_tree; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | |
| 172 | _leave(" = 0"); |
| 173 | return 0; |
| 174 | |
Al Viro | b42d570 | 2013-11-22 01:53:47 -0500 | [diff] [blame] | 175 | error_tree: |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 176 | proc_remove(net->proc_afs); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 177 | error_dir: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | _leave(" = -ENOMEM"); |
| 179 | return -ENOMEM; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 180 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | /* |
| 183 | * clean up the /proc/fs/afs/ directory |
| 184 | */ |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 185 | void afs_proc_cleanup(struct afs_net *net) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | { |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 187 | proc_remove(net->proc_afs); |
| 188 | net->proc_afs = NULL; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 189 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | /* |
| 192 | * open "/proc/fs/afs/cells" which provides a summary of extant cells |
| 193 | */ |
| 194 | static int afs_proc_cells_open(struct inode *inode, struct file *file) |
| 195 | { |
| 196 | struct seq_file *m; |
| 197 | int ret; |
| 198 | |
| 199 | ret = seq_open(file, &afs_proc_cells_ops); |
| 200 | if (ret < 0) |
| 201 | return ret; |
| 202 | |
| 203 | m = file->private_data; |
Al Viro | d9dda78 | 2013-03-31 18:16:14 -0400 | [diff] [blame] | 204 | m->private = PDE_DATA(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | return 0; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 206 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | /* |
| 209 | * set up the iterator to start reading from the cells list and return the |
| 210 | * first item |
| 211 | */ |
| 212 | static void *afs_proc_cells_start(struct seq_file *m, loff_t *_pos) |
David Howells | fe342cf | 2018-04-09 21:12:31 +0100 | [diff] [blame] | 213 | __acquires(rcu) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | { |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 215 | struct afs_net *net = afs_seq2net(m); |
| 216 | |
David Howells | 989782d | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 217 | rcu_read_lock(); |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 218 | return seq_list_start_head(&net->proc_cells, *_pos); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 219 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | /* |
| 222 | * move to next cell in cells list |
| 223 | */ |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 224 | 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] | 225 | { |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 226 | struct afs_net *net = afs_seq2net(m); |
| 227 | |
| 228 | return seq_list_next(v, &net->proc_cells, pos); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 229 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | /* |
| 232 | * clean up after reading from the cells list |
| 233 | */ |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 234 | static void afs_proc_cells_stop(struct seq_file *m, void *v) |
David Howells | fe342cf | 2018-04-09 21:12:31 +0100 | [diff] [blame] | 235 | __releases(rcu) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | { |
David Howells | 989782d | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 237 | rcu_read_unlock(); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 238 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | /* |
| 241 | * display a header line followed by a load of cell lines |
| 242 | */ |
| 243 | static int afs_proc_cells_show(struct seq_file *m, void *v) |
| 244 | { |
| 245 | struct afs_cell *cell = list_entry(v, struct afs_cell, proc_link); |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 246 | struct afs_net *net = afs_seq2net(m); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 248 | if (v == &net->proc_cells) { |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 249 | /* display header on line 1 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | seq_puts(m, "USE NAME\n"); |
| 251 | return 0; |
| 252 | } |
| 253 | |
| 254 | /* display one cell per line on subsequent lines */ |
David Howells | 989782d | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 255 | seq_printf(m, "%3u %s\n", atomic_read(&cell->usage), cell->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | return 0; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 257 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | /* |
| 260 | * handle writes to /proc/fs/afs/cells |
| 261 | * - to add cells: echo "add <cellname> <IP>[:<IP>][:<IP>]" |
| 262 | */ |
| 263 | static ssize_t afs_proc_cells_write(struct file *file, const char __user *buf, |
| 264 | size_t size, loff_t *_pos) |
| 265 | { |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 266 | struct afs_net *net = afs_proc2net(file); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | char *kbuf, *name, *args; |
| 268 | int ret; |
| 269 | |
| 270 | /* start by dragging the command into memory */ |
| 271 | if (size <= 1 || size >= PAGE_SIZE) |
| 272 | return -EINVAL; |
| 273 | |
Al Viro | 16e5c1f | 2015-12-24 00:06:05 -0500 | [diff] [blame] | 274 | kbuf = memdup_user_nul(buf, size); |
| 275 | if (IS_ERR(kbuf)) |
| 276 | return PTR_ERR(kbuf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | |
| 278 | /* trim to first NL */ |
| 279 | name = memchr(kbuf, '\n', size); |
| 280 | if (name) |
| 281 | *name = 0; |
| 282 | |
| 283 | /* split into command, name and argslist */ |
| 284 | name = strchr(kbuf, ' '); |
| 285 | if (!name) |
| 286 | goto inval; |
| 287 | do { |
| 288 | *name++ = 0; |
| 289 | } while(*name == ' '); |
| 290 | if (!*name) |
| 291 | goto inval; |
| 292 | |
| 293 | args = strchr(name, ' '); |
| 294 | if (!args) |
| 295 | goto inval; |
| 296 | do { |
| 297 | *args++ = 0; |
| 298 | } while(*args == ' '); |
| 299 | if (!*args) |
| 300 | goto inval; |
| 301 | |
| 302 | /* determine command to perform */ |
| 303 | _debug("cmd=%s name=%s args=%s", kbuf, name, args); |
| 304 | |
| 305 | if (strcmp(kbuf, "add") == 0) { |
| 306 | struct afs_cell *cell; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | |
David Howells | 989782d | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 308 | cell = afs_lookup_cell(net, name, strlen(name), args, true); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 309 | if (IS_ERR(cell)) { |
| 310 | ret = PTR_ERR(cell); |
| 311 | goto done; |
| 312 | } |
| 313 | |
David Howells | 17814ae | 2018-04-09 21:12:31 +0100 | [diff] [blame] | 314 | if (test_and_set_bit(AFS_CELL_FL_NO_GC, &cell->flags)) |
| 315 | afs_put_cell(net, cell); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | printk("kAFS: Added new cell '%s'\n", name); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 317 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | goto inval; |
| 319 | } |
| 320 | |
| 321 | ret = size; |
| 322 | |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 323 | done: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | kfree(kbuf); |
| 325 | _leave(" = %d", ret); |
| 326 | return ret; |
| 327 | |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 328 | inval: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | ret = -EINVAL; |
| 330 | printk("kAFS: Invalid Command on /proc/fs/afs/cells file\n"); |
| 331 | goto done; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 332 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | static ssize_t afs_proc_rootcell_read(struct file *file, char __user *buf, |
| 335 | size_t size, loff_t *_pos) |
| 336 | { |
| 337 | return 0; |
| 338 | } |
| 339 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | /* |
| 341 | * handle writes to /proc/fs/afs/rootcell |
| 342 | * - to initialize rootcell: echo "cell.name:192.168.231.14" |
| 343 | */ |
| 344 | static ssize_t afs_proc_rootcell_write(struct file *file, |
| 345 | const char __user *buf, |
| 346 | size_t size, loff_t *_pos) |
| 347 | { |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 348 | struct afs_net *net = afs_proc2net(file); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | char *kbuf, *s; |
| 350 | int ret; |
| 351 | |
| 352 | /* start by dragging the command into memory */ |
| 353 | if (size <= 1 || size >= PAGE_SIZE) |
| 354 | return -EINVAL; |
| 355 | |
Al Viro | 16e5c1f | 2015-12-24 00:06:05 -0500 | [diff] [blame] | 356 | kbuf = memdup_user_nul(buf, size); |
| 357 | if (IS_ERR(kbuf)) |
| 358 | return PTR_ERR(kbuf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | |
David Howells | 6f8880d | 2018-04-09 21:12:31 +0100 | [diff] [blame^] | 360 | ret = -EINVAL; |
| 361 | if (kbuf[0] == '.') |
| 362 | goto out; |
| 363 | if (memchr(kbuf, '/', size)) |
| 364 | goto out; |
| 365 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | /* trim to first NL */ |
| 367 | s = memchr(kbuf, '\n', size); |
| 368 | if (s) |
| 369 | *s = 0; |
| 370 | |
| 371 | /* determine command to perform */ |
| 372 | _debug("rootcell=%s", kbuf); |
| 373 | |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 374 | ret = afs_cell_init(net, kbuf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | if (ret >= 0) |
| 376 | ret = size; /* consume everything, always */ |
| 377 | |
David Howells | 6f8880d | 2018-04-09 21:12:31 +0100 | [diff] [blame^] | 378 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | kfree(kbuf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | _leave(" = %d", ret); |
| 381 | return ret; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 382 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | /* |
| 385 | * initialise /proc/fs/afs/<cell>/ |
| 386 | */ |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 387 | 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] | 388 | { |
Al Viro | b42d570 | 2013-11-22 01:53:47 -0500 | [diff] [blame] | 389 | struct proc_dir_entry *dir; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | |
David Howells | 989782d | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 391 | _enter("%p{%s},%p", cell, cell->name, net->proc_afs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 393 | dir = proc_mkdir(cell->name, net->proc_afs); |
Al Viro | b42d570 | 2013-11-22 01:53:47 -0500 | [diff] [blame] | 394 | if (!dir) |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 395 | goto error_dir; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 397 | if (!proc_create_data("vlservers", 0, dir, |
| 398 | &afs_proc_cell_vlservers_fops, cell) || |
Al Viro | b42d570 | 2013-11-22 01:53:47 -0500 | [diff] [blame] | 399 | !proc_create_data("volumes", 0, dir, |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 400 | &afs_proc_cell_volumes_fops, cell)) |
Al Viro | b42d570 | 2013-11-22 01:53:47 -0500 | [diff] [blame] | 401 | goto error_tree; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | |
| 403 | _leave(" = 0"); |
| 404 | return 0; |
| 405 | |
Al Viro | b42d570 | 2013-11-22 01:53:47 -0500 | [diff] [blame] | 406 | error_tree: |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 407 | remove_proc_subtree(cell->name, net->proc_afs); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 408 | error_dir: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | _leave(" = -ENOMEM"); |
| 410 | return -ENOMEM; |
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 | /* |
| 414 | * remove /proc/fs/afs/<cell>/ |
| 415 | */ |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 416 | 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] | 417 | { |
| 418 | _enter(""); |
| 419 | |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 420 | remove_proc_subtree(cell->name, net->proc_afs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | |
| 422 | _leave(""); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 423 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | /* |
| 426 | * open "/proc/fs/afs/<cell>/volumes" which provides a summary of extant cells |
| 427 | */ |
| 428 | static int afs_proc_cell_volumes_open(struct inode *inode, struct file *file) |
| 429 | { |
| 430 | struct afs_cell *cell; |
| 431 | struct seq_file *m; |
| 432 | int ret; |
| 433 | |
Al Viro | d9dda78 | 2013-03-31 18:16:14 -0400 | [diff] [blame] | 434 | cell = PDE_DATA(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | if (!cell) |
| 436 | return -ENOENT; |
| 437 | |
| 438 | ret = seq_open(file, &afs_proc_cell_volumes_ops); |
| 439 | if (ret < 0) |
| 440 | return ret; |
| 441 | |
| 442 | m = file->private_data; |
| 443 | m->private = cell; |
| 444 | |
| 445 | return 0; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 446 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | * set up the iterator to start reading from the cells list and return the |
| 450 | * first item |
| 451 | */ |
| 452 | static void *afs_proc_cell_volumes_start(struct seq_file *m, loff_t *_pos) |
David Howells | fe342cf | 2018-04-09 21:12:31 +0100 | [diff] [blame] | 453 | __acquires(cell->proc_lock) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | struct afs_cell *cell = m->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 456 | |
| 457 | _enter("cell=%p pos=%Ld", cell, *_pos); |
| 458 | |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 459 | read_lock(&cell->proc_lock); |
| 460 | return seq_list_start_head(&cell->proc_volumes, *_pos); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 461 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 463 | /* |
| 464 | * move to next cell in cells list |
| 465 | */ |
| 466 | static void *afs_proc_cell_volumes_next(struct seq_file *p, void *v, |
| 467 | loff_t *_pos) |
| 468 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 469 | struct afs_cell *cell = p->private; |
| 470 | |
| 471 | _enter("cell=%p pos=%Ld", cell, *_pos); |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 472 | return seq_list_next(v, &cell->proc_volumes, _pos); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 473 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 475 | /* |
| 476 | * clean up after reading from the cells list |
| 477 | */ |
| 478 | static void afs_proc_cell_volumes_stop(struct seq_file *p, void *v) |
David Howells | fe342cf | 2018-04-09 21:12:31 +0100 | [diff] [blame] | 479 | __releases(cell->proc_lock) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | { |
| 481 | struct afs_cell *cell = p->private; |
| 482 | |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 483 | read_unlock(&cell->proc_lock); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 484 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 485 | |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 486 | static const char afs_vol_types[3][3] = { |
| 487 | [AFSVL_RWVOL] = "RW", |
| 488 | [AFSVL_ROVOL] = "RO", |
| 489 | [AFSVL_BACKVOL] = "BK", |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 490 | }; |
| 491 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 492 | /* |
| 493 | * display a header line followed by a load of volume lines |
| 494 | */ |
| 495 | static int afs_proc_cell_volumes_show(struct seq_file *m, void *v) |
| 496 | { |
Pavel Emelianov | a6a8bd6 | 2007-07-15 23:39:52 -0700 | [diff] [blame] | 497 | struct afs_cell *cell = m->private; |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 498 | struct afs_volume *vol = list_entry(v, struct afs_volume, proc_link); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 499 | |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 500 | /* Display header on line 1 */ |
| 501 | if (v == &cell->proc_volumes) { |
| 502 | seq_puts(m, "USE VID TY\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | return 0; |
| 504 | } |
| 505 | |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 506 | seq_printf(m, "%3d %08x %s\n", |
| 507 | atomic_read(&vol->usage), vol->vid, |
| 508 | afs_vol_types[vol->type]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 509 | |
| 510 | return 0; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 511 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 512 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | /* |
| 514 | * open "/proc/fs/afs/<cell>/vlservers" which provides a list of volume |
| 515 | * location server |
| 516 | */ |
| 517 | static int afs_proc_cell_vlservers_open(struct inode *inode, struct file *file) |
| 518 | { |
| 519 | struct afs_cell *cell; |
| 520 | struct seq_file *m; |
| 521 | int ret; |
| 522 | |
Al Viro | d9dda78 | 2013-03-31 18:16:14 -0400 | [diff] [blame] | 523 | cell = PDE_DATA(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 524 | if (!cell) |
| 525 | return -ENOENT; |
| 526 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 527 | ret = seq_open(file, &afs_proc_cell_vlservers_ops); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | if (ret<0) |
| 529 | return ret; |
| 530 | |
| 531 | m = file->private_data; |
| 532 | m->private = cell; |
| 533 | |
| 534 | return 0; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 535 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 536 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 537 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | * set up the iterator to start reading from the cells list and return the |
| 539 | * first item |
| 540 | */ |
| 541 | static void *afs_proc_cell_vlservers_start(struct seq_file *m, loff_t *_pos) |
David Howells | fe342cf | 2018-04-09 21:12:31 +0100 | [diff] [blame] | 542 | __acquires(rcu) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | { |
David Howells | 8b2a464 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 544 | struct afs_addr_list *alist; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 545 | struct afs_cell *cell = m->private; |
| 546 | loff_t pos = *_pos; |
| 547 | |
David Howells | 8b2a464 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 548 | rcu_read_lock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 549 | |
David Howells | 8b2a464 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 550 | alist = rcu_dereference(cell->vl_addrs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | |
| 552 | /* allow for the header line */ |
| 553 | if (!pos) |
| 554 | return (void *) 1; |
| 555 | pos--; |
| 556 | |
David Howells | 8b2a464 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 557 | if (!alist || pos >= alist->nr_addrs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 558 | return NULL; |
| 559 | |
David Howells | 8b2a464 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 560 | return alist->addrs + pos; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 561 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 562 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 563 | /* |
| 564 | * move to next cell in cells list |
| 565 | */ |
| 566 | static void *afs_proc_cell_vlservers_next(struct seq_file *p, void *v, |
| 567 | loff_t *_pos) |
| 568 | { |
David Howells | 8b2a464 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 569 | struct afs_addr_list *alist; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 570 | struct afs_cell *cell = p->private; |
| 571 | loff_t pos; |
| 572 | |
David Howells | 8b2a464 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 573 | alist = rcu_dereference(cell->vl_addrs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 | |
| 575 | pos = *_pos; |
| 576 | (*_pos)++; |
David Howells | 8b2a464 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 577 | if (!alist || pos >= alist->nr_addrs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 578 | return NULL; |
| 579 | |
David Howells | 8b2a464 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 580 | return alist->addrs + pos; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 581 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 582 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 583 | /* |
| 584 | * clean up after reading from the cells list |
| 585 | */ |
| 586 | static void afs_proc_cell_vlservers_stop(struct seq_file *p, void *v) |
David Howells | fe342cf | 2018-04-09 21:12:31 +0100 | [diff] [blame] | 587 | __releases(rcu) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 588 | { |
David Howells | 8b2a464 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 589 | rcu_read_unlock(); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 590 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 591 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 592 | /* |
| 593 | * display a header line followed by a load of volume lines |
| 594 | */ |
| 595 | static int afs_proc_cell_vlservers_show(struct seq_file *m, void *v) |
| 596 | { |
David Howells | 4d9df98 | 2017-11-02 15:27:47 +0000 | [diff] [blame] | 597 | struct sockaddr_rxrpc *addr = v; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 598 | |
| 599 | /* display header on line 1 */ |
David Howells | 4d9df98 | 2017-11-02 15:27:47 +0000 | [diff] [blame] | 600 | if (v == (void *)1) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 601 | seq_puts(m, "ADDRESS\n"); |
| 602 | return 0; |
| 603 | } |
| 604 | |
| 605 | /* display one cell per line on subsequent lines */ |
David Howells | 4d9df98 | 2017-11-02 15:27:47 +0000 | [diff] [blame] | 606 | seq_printf(m, "%pISp\n", &addr->transport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 607 | return 0; |
David Howells | ec26815 | 2007-04-26 15:49:28 -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 | /* |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 611 | * open "/proc/fs/afs/servers" which provides a summary of active |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 | * servers |
| 613 | */ |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 614 | static int afs_proc_servers_open(struct inode *inode, struct file *file) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 615 | { |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 616 | return seq_open(file, &afs_proc_servers_ops); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 617 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 618 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 619 | /* |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 620 | * Set up the iterator to start reading from the server list and return the |
| 621 | * first item. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 622 | */ |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 623 | static void *afs_proc_servers_start(struct seq_file *m, loff_t *_pos) |
David Howells | fe342cf | 2018-04-09 21:12:31 +0100 | [diff] [blame] | 624 | __acquires(rcu) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 625 | { |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 626 | struct afs_net *net = afs_seq2net(m); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 627 | |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 628 | rcu_read_lock(); |
| 629 | return seq_hlist_start_head_rcu(&net->fs_proc, *_pos); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 630 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 631 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 632 | /* |
| 633 | * move to next cell in cells list |
| 634 | */ |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 635 | static void *afs_proc_servers_next(struct seq_file *m, void *v, loff_t *_pos) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 636 | { |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 637 | struct afs_net *net = afs_seq2net(m); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 638 | |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 639 | return seq_hlist_next_rcu(v, &net->fs_proc, _pos); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 640 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 641 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 642 | /* |
| 643 | * clean up after reading from the cells list |
| 644 | */ |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 645 | static void afs_proc_servers_stop(struct seq_file *p, void *v) |
David Howells | fe342cf | 2018-04-09 21:12:31 +0100 | [diff] [blame] | 646 | __releases(rcu) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 647 | { |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 648 | rcu_read_unlock(); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 649 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 650 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 651 | /* |
| 652 | * display a header line followed by a load of volume lines |
| 653 | */ |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 654 | static int afs_proc_servers_show(struct seq_file *m, void *v) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 655 | { |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 656 | struct afs_server *server; |
| 657 | struct afs_addr_list *alist; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 658 | |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 659 | if (v == SEQ_START_TOKEN) { |
| 660 | seq_puts(m, "UUID USE ADDR\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 661 | return 0; |
| 662 | } |
| 663 | |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 664 | server = list_entry(v, struct afs_server, proc_link); |
| 665 | alist = rcu_dereference(server->addresses); |
| 666 | seq_printf(m, "%pU %3d %pISp\n", |
| 667 | &server->uuid, |
| 668 | atomic_read(&server->usage), |
| 669 | &alist->addrs[alist->index].transport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 670 | return 0; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 671 | } |
David Howells | 6f8880d | 2018-04-09 21:12:31 +0100 | [diff] [blame^] | 672 | |
| 673 | void afs_put_sysnames(struct afs_sysnames *sysnames) |
| 674 | { |
| 675 | int i; |
| 676 | |
| 677 | if (sysnames && refcount_dec_and_test(&sysnames->usage)) { |
| 678 | for (i = 0; i < sysnames->nr; i++) |
| 679 | if (sysnames->subs[i] != afs_init_sysname && |
| 680 | sysnames->subs[i] != sysnames->blank) |
| 681 | kfree(sysnames->subs[i]); |
| 682 | } |
| 683 | } |
| 684 | |
| 685 | /* |
| 686 | * Handle opening of /proc/fs/afs/sysname. If it is opened for writing, we |
| 687 | * assume the caller wants to change the substitution list and we allocate a |
| 688 | * buffer to hold the list. |
| 689 | */ |
| 690 | static int afs_proc_sysname_open(struct inode *inode, struct file *file) |
| 691 | { |
| 692 | struct afs_sysnames *sysnames; |
| 693 | struct seq_file *m; |
| 694 | int ret; |
| 695 | |
| 696 | ret = seq_open(file, &afs_proc_sysname_ops); |
| 697 | if (ret < 0) |
| 698 | return ret; |
| 699 | |
| 700 | if (file->f_mode & FMODE_WRITE) { |
| 701 | sysnames = kzalloc(sizeof(*sysnames), GFP_KERNEL); |
| 702 | if (!sysnames) { |
| 703 | seq_release(inode, file); |
| 704 | return -ENOMEM; |
| 705 | } |
| 706 | |
| 707 | refcount_set(&sysnames->usage, 1); |
| 708 | m = file->private_data; |
| 709 | m->private = sysnames; |
| 710 | } |
| 711 | |
| 712 | return 0; |
| 713 | } |
| 714 | |
| 715 | /* |
| 716 | * Handle writes to /proc/fs/afs/sysname to set the @sys substitution. |
| 717 | */ |
| 718 | static ssize_t afs_proc_sysname_write(struct file *file, |
| 719 | const char __user *buf, |
| 720 | size_t size, loff_t *_pos) |
| 721 | { |
| 722 | struct afs_sysnames *sysnames; |
| 723 | struct seq_file *m = file->private_data; |
| 724 | char *kbuf = NULL, *s, *p, *sub; |
| 725 | int ret, len; |
| 726 | |
| 727 | sysnames = m->private; |
| 728 | if (!sysnames) |
| 729 | return -EINVAL; |
| 730 | if (sysnames->error) |
| 731 | return sysnames->error; |
| 732 | |
| 733 | if (size >= PAGE_SIZE - 1) { |
| 734 | sysnames->error = -EINVAL; |
| 735 | return -EINVAL; |
| 736 | } |
| 737 | if (size == 0) |
| 738 | return 0; |
| 739 | |
| 740 | kbuf = memdup_user_nul(buf, size); |
| 741 | if (IS_ERR(kbuf)) |
| 742 | return PTR_ERR(kbuf); |
| 743 | |
| 744 | inode_lock(file_inode(file)); |
| 745 | |
| 746 | p = kbuf; |
| 747 | while ((s = strsep(&p, " \t\n"))) { |
| 748 | len = strlen(s); |
| 749 | if (len == 0) |
| 750 | continue; |
| 751 | ret = -ENAMETOOLONG; |
| 752 | if (len >= AFSNAMEMAX) |
| 753 | goto error; |
| 754 | |
| 755 | if (len >= 4 && |
| 756 | s[len - 4] == '@' && |
| 757 | s[len - 3] == 's' && |
| 758 | s[len - 2] == 'y' && |
| 759 | s[len - 1] == 's') |
| 760 | /* Protect against recursion */ |
| 761 | goto invalid; |
| 762 | |
| 763 | if (s[0] == '.' && |
| 764 | (len < 2 || (len == 2 && s[1] == '.'))) |
| 765 | goto invalid; |
| 766 | |
| 767 | if (memchr(s, '/', len)) |
| 768 | goto invalid; |
| 769 | |
| 770 | ret = -EFBIG; |
| 771 | if (sysnames->nr >= AFS_NR_SYSNAME) |
| 772 | goto out; |
| 773 | |
| 774 | if (strcmp(s, afs_init_sysname) == 0) { |
| 775 | sub = (char *)afs_init_sysname; |
| 776 | } else { |
| 777 | ret = -ENOMEM; |
| 778 | sub = kmemdup(s, len + 1, GFP_KERNEL); |
| 779 | if (!sub) |
| 780 | goto out; |
| 781 | } |
| 782 | |
| 783 | sysnames->subs[sysnames->nr] = sub; |
| 784 | sysnames->nr++; |
| 785 | } |
| 786 | |
| 787 | ret = size; /* consume everything, always */ |
| 788 | out: |
| 789 | inode_unlock(file_inode(file)); |
| 790 | kfree(kbuf); |
| 791 | return ret; |
| 792 | |
| 793 | invalid: |
| 794 | ret = -EINVAL; |
| 795 | error: |
| 796 | sysnames->error = ret; |
| 797 | goto out; |
| 798 | } |
| 799 | |
| 800 | static int afs_proc_sysname_release(struct inode *inode, struct file *file) |
| 801 | { |
| 802 | struct afs_sysnames *sysnames, *kill = NULL; |
| 803 | struct seq_file *m = file->private_data; |
| 804 | struct afs_net *net = afs_seq2net(m); |
| 805 | |
| 806 | sysnames = m->private; |
| 807 | if (sysnames) { |
| 808 | if (!sysnames->error) { |
| 809 | kill = sysnames; |
| 810 | if (sysnames->nr == 0) { |
| 811 | sysnames->subs[0] = sysnames->blank; |
| 812 | sysnames->nr++; |
| 813 | } |
| 814 | write_lock(&net->sysnames_lock); |
| 815 | kill = net->sysnames; |
| 816 | net->sysnames = sysnames; |
| 817 | write_unlock(&net->sysnames_lock); |
| 818 | } |
| 819 | afs_put_sysnames(kill); |
| 820 | } |
| 821 | |
| 822 | return seq_release(inode, file); |
| 823 | } |
| 824 | |
| 825 | static void *afs_proc_sysname_start(struct seq_file *m, loff_t *pos) |
| 826 | __acquires(&net->sysnames_lock) |
| 827 | { |
| 828 | struct afs_net *net = afs_seq2net(m); |
| 829 | struct afs_sysnames *names = net->sysnames; |
| 830 | |
| 831 | read_lock(&net->sysnames_lock); |
| 832 | |
| 833 | if (*pos >= names->nr) |
| 834 | return NULL; |
| 835 | return (void *)(unsigned long)(*pos + 1); |
| 836 | } |
| 837 | |
| 838 | static void *afs_proc_sysname_next(struct seq_file *m, void *v, loff_t *pos) |
| 839 | { |
| 840 | struct afs_net *net = afs_seq2net(m); |
| 841 | struct afs_sysnames *names = net->sysnames; |
| 842 | |
| 843 | *pos += 1; |
| 844 | if (*pos >= names->nr) |
| 845 | return NULL; |
| 846 | return (void *)(unsigned long)(*pos + 1); |
| 847 | } |
| 848 | |
| 849 | static void afs_proc_sysname_stop(struct seq_file *m, void *v) |
| 850 | __releases(&net->sysnames_lock) |
| 851 | { |
| 852 | struct afs_net *net = afs_seq2net(m); |
| 853 | |
| 854 | read_unlock(&net->sysnames_lock); |
| 855 | } |
| 856 | |
| 857 | static int afs_proc_sysname_show(struct seq_file *m, void *v) |
| 858 | { |
| 859 | struct afs_net *net = afs_seq2net(m); |
| 860 | struct afs_sysnames *sysnames = net->sysnames; |
| 861 | unsigned int i = (unsigned long)v - 1; |
| 862 | |
| 863 | if (i < sysnames->nr) |
| 864 | seq_printf(m, "%s\n", sysnames->subs[i]); |
| 865 | return 0; |
| 866 | } |