Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * drivers/s390/cio/blacklist.c |
| 3 | * S/390 common I/O routines -- blacklisting of specific devices |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * |
| 5 | * Copyright (C) 1999-2002 IBM Deutschland Entwicklung GmbH, |
| 6 | * IBM Corporation |
| 7 | * Author(s): Ingo Adlung (adlung@de.ibm.com) |
Cornelia Huck | 4ce3b30 | 2006-01-14 13:21:04 -0800 | [diff] [blame] | 8 | * Cornelia Huck (cornelia.huck@de.ibm.com) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | * Arnd Bergmann (arndb@de.ibm.com) |
| 10 | */ |
| 11 | |
| 12 | #include <linux/config.h> |
| 13 | #include <linux/init.h> |
| 14 | #include <linux/vmalloc.h> |
| 15 | #include <linux/slab.h> |
| 16 | #include <linux/proc_fs.h> |
Cornelia Huck | 678a395 | 2006-01-06 00:19:24 -0800 | [diff] [blame] | 17 | #include <linux/seq_file.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #include <linux/ctype.h> |
| 19 | #include <linux/device.h> |
| 20 | |
| 21 | #include <asm/cio.h> |
| 22 | #include <asm/uaccess.h> |
| 23 | |
| 24 | #include "blacklist.h" |
| 25 | #include "cio.h" |
| 26 | #include "cio_debug.h" |
| 27 | #include "css.h" |
| 28 | |
| 29 | /* |
| 30 | * "Blacklisting" of certain devices: |
| 31 | * Device numbers given in the commandline as cio_ignore=... won't be known |
| 32 | * to Linux. |
| 33 | * |
| 34 | * These can be single devices or ranges of devices |
| 35 | */ |
| 36 | |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 37 | /* 65536 bits for each set to indicate if a devno is blacklisted or not */ |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 38 | #define __BL_DEV_WORDS ((__MAX_SUBCHANNEL + (8*sizeof(long) - 1)) / \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | (8*sizeof(long))) |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 40 | static unsigned long bl_dev[__MAX_SSID + 1][__BL_DEV_WORDS]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | typedef enum {add, free} range_action; |
| 42 | |
| 43 | /* |
| 44 | * Function: blacklist_range |
| 45 | * (Un-)blacklist the devices from-to |
| 46 | */ |
| 47 | static inline void |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 48 | blacklist_range (range_action action, unsigned int from, unsigned int to, |
| 49 | unsigned int ssid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | { |
| 51 | if (!to) |
| 52 | to = from; |
| 53 | |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 54 | if (from > to || to > __MAX_SUBCHANNEL || ssid > __MAX_SSID) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | printk (KERN_WARNING "Invalid blacklist range " |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 56 | "0.%x.%04x to 0.%x.%04x, skipping\n", |
| 57 | ssid, from, ssid, to); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | return; |
| 59 | } |
| 60 | for (; from <= to; from++) { |
| 61 | if (action == add) |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 62 | set_bit (from, bl_dev[ssid]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | else |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 64 | clear_bit (from, bl_dev[ssid]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | } |
| 66 | } |
| 67 | |
| 68 | /* |
| 69 | * Function: blacklist_busid |
| 70 | * Get devno/busid from given string. |
| 71 | * Shamelessly grabbed from dasd_devmap.c. |
| 72 | */ |
| 73 | static inline int |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 74 | blacklist_busid(char **str, int *id0, int *ssid, int *devno) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | { |
| 76 | int val, old_style; |
| 77 | char *sav; |
| 78 | |
| 79 | sav = *str; |
| 80 | |
| 81 | /* check for leading '0x' */ |
| 82 | old_style = 0; |
| 83 | if ((*str)[0] == '0' && (*str)[1] == 'x') { |
| 84 | *str += 2; |
| 85 | old_style = 1; |
| 86 | } |
| 87 | if (!isxdigit((*str)[0])) /* We require at least one hex digit */ |
| 88 | goto confused; |
| 89 | val = simple_strtoul(*str, str, 16); |
| 90 | if (old_style || (*str)[0] != '.') { |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 91 | *id0 = *ssid = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | if (val < 0 || val > 0xffff) |
| 93 | goto confused; |
| 94 | *devno = val; |
| 95 | if ((*str)[0] != ',' && (*str)[0] != '-' && |
| 96 | (*str)[0] != '\n' && (*str)[0] != '\0') |
| 97 | goto confused; |
| 98 | return 0; |
| 99 | } |
| 100 | /* New style x.y.z busid */ |
| 101 | if (val < 0 || val > 0xff) |
| 102 | goto confused; |
| 103 | *id0 = val; |
| 104 | (*str)++; |
| 105 | if (!isxdigit((*str)[0])) /* We require at least one hex digit */ |
| 106 | goto confused; |
| 107 | val = simple_strtoul(*str, str, 16); |
| 108 | if (val < 0 || val > 0xff || (*str)++[0] != '.') |
| 109 | goto confused; |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 110 | *ssid = val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | if (!isxdigit((*str)[0])) /* We require at least one hex digit */ |
| 112 | goto confused; |
| 113 | val = simple_strtoul(*str, str, 16); |
| 114 | if (val < 0 || val > 0xffff) |
| 115 | goto confused; |
| 116 | *devno = val; |
| 117 | if ((*str)[0] != ',' && (*str)[0] != '-' && |
| 118 | (*str)[0] != '\n' && (*str)[0] != '\0') |
| 119 | goto confused; |
| 120 | return 0; |
| 121 | confused: |
| 122 | strsep(str, ",\n"); |
| 123 | printk(KERN_WARNING "Invalid cio_ignore parameter '%s'\n", sav); |
| 124 | return 1; |
| 125 | } |
| 126 | |
| 127 | static inline int |
| 128 | blacklist_parse_parameters (char *str, range_action action) |
| 129 | { |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 130 | unsigned int from, to, from_id0, to_id0, from_ssid, to_ssid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | |
| 132 | while (*str != 0 && *str != '\n') { |
| 133 | range_action ra = action; |
| 134 | while(*str == ',') |
| 135 | str++; |
| 136 | if (*str == '!') { |
| 137 | ra = !action; |
| 138 | ++str; |
| 139 | } |
| 140 | |
| 141 | /* |
| 142 | * Since we have to parse the proc commands and the |
| 143 | * kernel arguments we have to check four cases |
| 144 | */ |
| 145 | if (strncmp(str,"all,",4) == 0 || strcmp(str,"all") == 0 || |
| 146 | strncmp(str,"all\n",4) == 0 || strncmp(str,"all ",4) == 0) { |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 147 | int j; |
| 148 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | str += 3; |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 150 | for (j=0; j <= __MAX_SSID; j++) |
| 151 | blacklist_range(ra, 0, __MAX_SUBCHANNEL, j); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | } else { |
| 153 | int rc; |
| 154 | |
| 155 | rc = blacklist_busid(&str, &from_id0, |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 156 | &from_ssid, &from); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | if (rc) |
| 158 | continue; |
| 159 | to = from; |
| 160 | to_id0 = from_id0; |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 161 | to_ssid = from_ssid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | if (*str == '-') { |
| 163 | str++; |
| 164 | rc = blacklist_busid(&str, &to_id0, |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 165 | &to_ssid, &to); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | if (rc) |
| 167 | continue; |
| 168 | } |
| 169 | if (*str == '-') { |
| 170 | printk(KERN_WARNING "invalid cio_ignore " |
| 171 | "parameter '%s'\n", |
| 172 | strsep(&str, ",\n")); |
| 173 | continue; |
| 174 | } |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 175 | if ((from_id0 != to_id0) || |
| 176 | (from_ssid != to_ssid)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | printk(KERN_WARNING "invalid cio_ignore range " |
| 178 | "%x.%x.%04x-%x.%x.%04x\n", |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 179 | from_id0, from_ssid, from, |
| 180 | to_id0, to_ssid, to); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | continue; |
| 182 | } |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 183 | pr_debug("blacklist_setup: adding range " |
| 184 | "from %x.%x.%04x to %x.%x.%04x\n", |
| 185 | from_id0, from_ssid, from, to_id0, to_ssid, to); |
| 186 | blacklist_range (ra, from, to, to_ssid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | } |
| 189 | return 1; |
| 190 | } |
| 191 | |
| 192 | /* Parsing the commandline for blacklist parameters, e.g. to blacklist |
| 193 | * bus ids 0.0.1234, 0.0.1235 and 0.0.1236, you could use any of: |
| 194 | * - cio_ignore=1234-1236 |
| 195 | * - cio_ignore=0x1234-0x1235,1236 |
| 196 | * - cio_ignore=0x1234,1235-1236 |
| 197 | * - cio_ignore=1236 cio_ignore=1234-0x1236 |
| 198 | * - cio_ignore=1234 cio_ignore=1236 cio_ignore=0x1235 |
| 199 | * - cio_ignore=0.0.1234-0.0.1236 |
| 200 | * - cio_ignore=0.0.1234,0x1235,1236 |
| 201 | * - ... |
| 202 | */ |
| 203 | static int __init |
| 204 | blacklist_setup (char *str) |
| 205 | { |
| 206 | CIO_MSG_EVENT(6, "Reading blacklist parameters\n"); |
| 207 | return blacklist_parse_parameters (str, add); |
| 208 | } |
| 209 | |
| 210 | __setup ("cio_ignore=", blacklist_setup); |
| 211 | |
| 212 | /* Checking if devices are blacklisted */ |
| 213 | |
| 214 | /* |
| 215 | * Function: is_blacklisted |
| 216 | * Returns 1 if the given devicenumber can be found in the blacklist, |
| 217 | * otherwise 0. |
| 218 | * Used by validate_subchannel() |
| 219 | */ |
| 220 | int |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 221 | is_blacklisted (int ssid, int devno) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | { |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 223 | return test_bit (devno, bl_dev[ssid]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | } |
| 225 | |
| 226 | #ifdef CONFIG_PROC_FS |
Cornelia Huck | f97a56f | 2006-01-06 00:19:22 -0800 | [diff] [blame] | 227 | static int |
| 228 | __s390_redo_validation(struct subchannel_id schid, void *data) |
| 229 | { |
| 230 | int ret; |
| 231 | struct subchannel *sch; |
| 232 | |
| 233 | sch = get_subchannel_by_schid(schid); |
| 234 | if (sch) { |
| 235 | /* Already known. */ |
| 236 | put_device(&sch->dev); |
| 237 | return 0; |
| 238 | } |
| 239 | ret = css_probe_device(schid); |
| 240 | if (ret == -ENXIO) |
| 241 | return ret; /* We're through. */ |
| 242 | if (ret == -ENOMEM) |
| 243 | /* Stop validation for now. Bad, but no need for a panic. */ |
| 244 | return ret; |
| 245 | return 0; |
| 246 | } |
| 247 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | /* |
| 249 | * Function: s390_redo_validation |
| 250 | * Look for no longer blacklisted devices |
| 251 | * FIXME: there must be a better way to do this */ |
| 252 | static inline void |
| 253 | s390_redo_validation (void) |
| 254 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | CIO_TRACE_EVENT (0, "redoval"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | |
Cornelia Huck | f97a56f | 2006-01-06 00:19:22 -0800 | [diff] [blame] | 257 | for_each_subchannel(__s390_redo_validation, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | } |
| 259 | |
| 260 | /* |
| 261 | * Function: blacklist_parse_proc_parameters |
| 262 | * parse the stuff which is piped to /proc/cio_ignore |
| 263 | */ |
| 264 | static inline void |
| 265 | blacklist_parse_proc_parameters (char *buf) |
| 266 | { |
| 267 | if (strncmp (buf, "free ", 5) == 0) { |
| 268 | blacklist_parse_parameters (buf + 5, free); |
| 269 | } else if (strncmp (buf, "add ", 4) == 0) { |
| 270 | /* |
| 271 | * We don't need to check for known devices since |
| 272 | * css_probe_device will handle this correctly. |
| 273 | */ |
| 274 | blacklist_parse_parameters (buf + 4, add); |
| 275 | } else { |
| 276 | printk (KERN_WARNING "cio_ignore: Parse error; \n" |
| 277 | KERN_WARNING "try using 'free all|<devno-range>," |
| 278 | "<devno-range>,...'\n" |
| 279 | KERN_WARNING "or 'add <devno-range>," |
| 280 | "<devno-range>,...'\n"); |
| 281 | return; |
| 282 | } |
| 283 | |
| 284 | s390_redo_validation (); |
| 285 | } |
| 286 | |
Cornelia Huck | 678a395 | 2006-01-06 00:19:24 -0800 | [diff] [blame] | 287 | /* Iterator struct for all devices. */ |
| 288 | struct ccwdev_iter { |
| 289 | int devno; |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 290 | int ssid; |
Cornelia Huck | 678a395 | 2006-01-06 00:19:24 -0800 | [diff] [blame] | 291 | int in_range; |
| 292 | }; |
| 293 | |
| 294 | static void * |
| 295 | cio_ignore_proc_seq_start(struct seq_file *s, loff_t *offset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | { |
Cornelia Huck | 678a395 | 2006-01-06 00:19:24 -0800 | [diff] [blame] | 297 | struct ccwdev_iter *iter; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 299 | if (*offset >= (__MAX_SUBCHANNEL + 1) * (__MAX_SSID + 1)) |
Cornelia Huck | 678a395 | 2006-01-06 00:19:24 -0800 | [diff] [blame] | 300 | return NULL; |
Cornelia Huck | 3b79306 | 2006-01-06 00:19:26 -0800 | [diff] [blame] | 301 | iter = kzalloc(sizeof(struct ccwdev_iter), GFP_KERNEL); |
Cornelia Huck | 678a395 | 2006-01-06 00:19:24 -0800 | [diff] [blame] | 302 | if (!iter) |
| 303 | return ERR_PTR(-ENOMEM); |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 304 | iter->ssid = *offset / (__MAX_SUBCHANNEL + 1); |
| 305 | iter->devno = *offset % (__MAX_SUBCHANNEL + 1); |
Cornelia Huck | 678a395 | 2006-01-06 00:19:24 -0800 | [diff] [blame] | 306 | return iter; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | } |
| 308 | |
Cornelia Huck | 678a395 | 2006-01-06 00:19:24 -0800 | [diff] [blame] | 309 | static void |
| 310 | cio_ignore_proc_seq_stop(struct seq_file *s, void *it) |
| 311 | { |
| 312 | if (!IS_ERR(it)) |
| 313 | kfree(it); |
| 314 | } |
| 315 | |
| 316 | static void * |
| 317 | cio_ignore_proc_seq_next(struct seq_file *s, void *it, loff_t *offset) |
| 318 | { |
| 319 | struct ccwdev_iter *iter; |
| 320 | |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 321 | if (*offset >= (__MAX_SUBCHANNEL + 1) * (__MAX_SSID + 1)) |
Cornelia Huck | 678a395 | 2006-01-06 00:19:24 -0800 | [diff] [blame] | 322 | return NULL; |
Cornelia Huck | 3b79306 | 2006-01-06 00:19:26 -0800 | [diff] [blame] | 323 | iter = it; |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 324 | if (iter->devno == __MAX_SUBCHANNEL) { |
| 325 | iter->devno = 0; |
| 326 | iter->ssid++; |
| 327 | if (iter->ssid > __MAX_SSID) |
| 328 | return NULL; |
| 329 | } else |
| 330 | iter->devno++; |
Cornelia Huck | 678a395 | 2006-01-06 00:19:24 -0800 | [diff] [blame] | 331 | (*offset)++; |
| 332 | return iter; |
| 333 | } |
| 334 | |
| 335 | static int |
| 336 | cio_ignore_proc_seq_show(struct seq_file *s, void *it) |
| 337 | { |
| 338 | struct ccwdev_iter *iter; |
| 339 | |
Cornelia Huck | 3b79306 | 2006-01-06 00:19:26 -0800 | [diff] [blame] | 340 | iter = it; |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 341 | if (!is_blacklisted(iter->ssid, iter->devno)) |
Cornelia Huck | 678a395 | 2006-01-06 00:19:24 -0800 | [diff] [blame] | 342 | /* Not blacklisted, nothing to output. */ |
| 343 | return 0; |
| 344 | if (!iter->in_range) { |
| 345 | /* First device in range. */ |
| 346 | if ((iter->devno == __MAX_SUBCHANNEL) || |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 347 | !is_blacklisted(iter->ssid, iter->devno + 1)) |
Cornelia Huck | 678a395 | 2006-01-06 00:19:24 -0800 | [diff] [blame] | 348 | /* Singular device. */ |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 349 | return seq_printf(s, "0.%x.%04x\n", |
| 350 | iter->ssid, iter->devno); |
Cornelia Huck | 678a395 | 2006-01-06 00:19:24 -0800 | [diff] [blame] | 351 | iter->in_range = 1; |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 352 | return seq_printf(s, "0.%x.%04x-", iter->ssid, iter->devno); |
Cornelia Huck | 678a395 | 2006-01-06 00:19:24 -0800 | [diff] [blame] | 353 | } |
| 354 | if ((iter->devno == __MAX_SUBCHANNEL) || |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 355 | !is_blacklisted(iter->ssid, iter->devno + 1)) { |
Cornelia Huck | 678a395 | 2006-01-06 00:19:24 -0800 | [diff] [blame] | 356 | /* Last device in range. */ |
| 357 | iter->in_range = 0; |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 358 | return seq_printf(s, "0.%x.%04x\n", iter->ssid, iter->devno); |
Cornelia Huck | 678a395 | 2006-01-06 00:19:24 -0800 | [diff] [blame] | 359 | } |
| 360 | return 0; |
| 361 | } |
| 362 | |
| 363 | static ssize_t |
| 364 | cio_ignore_write(struct file *file, const char __user *user_buf, |
| 365 | size_t user_len, loff_t *offset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | { |
| 367 | char *buf; |
| 368 | |
Cornelia Huck | 678a395 | 2006-01-06 00:19:24 -0800 | [diff] [blame] | 369 | if (*offset) |
| 370 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | if (user_len > 65536) |
| 372 | user_len = 65536; |
| 373 | buf = vmalloc (user_len + 1); /* maybe better use the stack? */ |
| 374 | if (buf == NULL) |
| 375 | return -ENOMEM; |
| 376 | if (strncpy_from_user (buf, user_buf, user_len) < 0) { |
| 377 | vfree (buf); |
| 378 | return -EFAULT; |
| 379 | } |
| 380 | buf[user_len] = '\0'; |
| 381 | |
| 382 | blacklist_parse_proc_parameters (buf); |
| 383 | |
| 384 | vfree (buf); |
| 385 | return user_len; |
| 386 | } |
| 387 | |
Cornelia Huck | 678a395 | 2006-01-06 00:19:24 -0800 | [diff] [blame] | 388 | static struct seq_operations cio_ignore_proc_seq_ops = { |
| 389 | .start = cio_ignore_proc_seq_start, |
| 390 | .stop = cio_ignore_proc_seq_stop, |
| 391 | .next = cio_ignore_proc_seq_next, |
| 392 | .show = cio_ignore_proc_seq_show, |
| 393 | }; |
| 394 | |
| 395 | static int |
| 396 | cio_ignore_proc_open(struct inode *inode, struct file *file) |
| 397 | { |
| 398 | return seq_open(file, &cio_ignore_proc_seq_ops); |
| 399 | } |
| 400 | |
| 401 | static struct file_operations cio_ignore_proc_fops = { |
| 402 | .open = cio_ignore_proc_open, |
| 403 | .read = seq_read, |
| 404 | .llseek = seq_lseek, |
| 405 | .release = seq_release, |
| 406 | .write = cio_ignore_write, |
| 407 | }; |
| 408 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | static int |
| 410 | cio_ignore_proc_init (void) |
| 411 | { |
| 412 | struct proc_dir_entry *entry; |
| 413 | |
| 414 | entry = create_proc_entry ("cio_ignore", S_IFREG | S_IRUGO | S_IWUSR, |
| 415 | &proc_root); |
| 416 | if (!entry) |
Cornelia Huck | a7fbf6b | 2006-04-10 22:53:45 -0700 | [diff] [blame] | 417 | return -ENOENT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | |
Cornelia Huck | 678a395 | 2006-01-06 00:19:24 -0800 | [diff] [blame] | 419 | entry->proc_fops = &cio_ignore_proc_fops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | |
Cornelia Huck | a7fbf6b | 2006-04-10 22:53:45 -0700 | [diff] [blame] | 421 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | } |
| 423 | |
| 424 | __initcall (cio_ignore_proc_init); |
| 425 | |
| 426 | #endif /* CONFIG_PROC_FS */ |