dasd_devmap.c
来自「Linux Kernel 2.6.9 for OMAP1710」· C语言 代码 · 共 713 行 · 第 1/2 页
C
713 行
/* * File...........: linux/drivers/s390/block/dasd_devmap.c * Author(s)......: Holger Smolinski <Holger.Smolinski@de.ibm.com> * Horst Hummel <Horst.Hummel@de.ibm.com> * Carsten Otte <Cotte@de.ibm.com> * Martin Schwidefsky <schwidefsky@de.ibm.com> * Bugreports.to..: <Linux390@de.ibm.com> * (C) IBM Corporation, IBM Deutschland Entwicklung GmbH, 1999-2001 * * Device mapping and dasd= parameter parsing functions. All devmap * functions may not be called from interrupt context. In particular * dasd_get_device is a no-no from interrupt context. * * $Revision: 1.30 $ */#include <linux/config.h>#include <linux/ctype.h>#include <linux/init.h>#include <asm/debug.h>#include <asm/uaccess.h>/* This is ugly... */#define PRINTK_HEADER "dasd_devmap:"#include "dasd_int.h"/* * dasd_devmap_t is used to store the features and the relation * between device number and device index. To find a dasd_devmap_t * that corresponds to a device number of a device index each * dasd_devmap_t is added to two linked lists, one to search by * the device number and one to search by the device index. As * soon as big minor numbers are available the device index list * can be removed since the device number will then be identical * to the device index. */struct dasd_devmap { struct list_head list; char bus_id[BUS_ID_SIZE]; unsigned int devindex; unsigned short features; struct dasd_device *device;};/* * Parameter parsing functions for dasd= parameter. The syntax is: * <devno> : (0x)?[0-9a-fA-F]+ * <busid> : [0-0a-f]\.[0-9a-f]\.(0x)?[0-9a-fA-F]+ * <feature> : ro * <feature_list> : \(<feature>(:<feature>)*\) * <devno-range> : <devno>(-<devno>)?<feature_list>? * <busid-range> : <busid>(-<busid>)?<feature_list>? * <devices> : <devno-range>|<busid-range> * <dasd_module> : dasd_diag_mod|dasd_eckd_mod|dasd_fba_mod * * <dasd> : autodetect|probeonly|<devices>(,<devices>)* */int dasd_probeonly = 0; /* is true, when probeonly mode is active */int dasd_autodetect = 0; /* is true, when autodetection is active *//* * char *dasd[] is intended to hold the ranges supplied by the dasd= statement * it is named 'dasd' to directly be filled by insmod with the comma separated * strings when running as a module. */static char *dasd[256];/* * Single spinlock to protect devmap structures and lists. */static spinlock_t dasd_devmap_lock = SPIN_LOCK_UNLOCKED;/* * Hash lists for devmap structures. */static struct list_head dasd_hashlists[256];int dasd_max_devindex;static struct dasd_devmap *dasd_add_busid(char *, int);static inline intdasd_hash_busid(char *bus_id){ int hash, i; hash = 0; for (i = 0; (i < BUS_ID_SIZE) && *bus_id; i++, bus_id++) hash += *bus_id; return hash & 0xff;}#ifndef MODULE/* * The parameter parsing functions for builtin-drivers are called * before kmalloc works. Store the pointers to the parameters strings * into dasd[] for later processing. */static int __initdasd_call_setup(char *str){ static int count = 0; if (count < 256) dasd[count++] = str; return 1;}__setup ("dasd=", dasd_call_setup);#endif /* #ifndef MODULE *//* * Read a device busid/devno from a string. */static inline intdasd_busid(char **str, int *id0, int *id1, int *devno){ int val, old_style; /* check for leading '0x' */ old_style = 0; if ((*str)[0] == '0' && (*str)[1] == 'x') { *str += 2; old_style = 1; } if (!isxdigit((*str)[0])) /* We require at least one hex digit */ return -EINVAL; val = simple_strtoul(*str, str, 16); if (old_style || (*str)[0] != '.') { *id0 = *id1 = 0; if (val < 0 || val > 0xffff) return -EINVAL; *devno = val; return 0; } /* New style x.y.z busid */ if (val < 0 || val > 0xff) return -EINVAL; *id0 = val; (*str)++; if (!isxdigit((*str)[0])) /* We require at least one hex digit */ return -EINVAL; val = simple_strtoul(*str, str, 16); if (val < 0 || val > 0xff || (*str)++[0] != '.') return -EINVAL; *id1 = val; if (!isxdigit((*str)[0])) /* We require at least one hex digit */ return -EINVAL; val = simple_strtoul(*str, str, 16); if (val < 0 || val > 0xffff) return -EINVAL; *devno = val; return 0;}/* * Read colon separated list of dasd features. Currently there is * only one: "ro" for read-only devices. The default feature set * is empty (value 0). */static inline intdasd_feature_list(char *str, char **endp){ int features, len, rc; rc = 0; if (*str != '(') { *endp = str; return DASD_FEATURE_DEFAULT; } str++; features = 0; while (1) { for (len = 0; str[len] && str[len] != ':' && str[len] != ')'; len++); if (len == 2 && !strncmp(str, "ro", 2)) features |= DASD_FEATURE_READONLY; else if (len == 4 && !strncmp(str, "diag", 4)) features |= DASD_FEATURE_USEDIAG; else { MESSAGE(KERN_WARNING, "unsupported feature: %*s, " "ignoring setting", len, str); rc = -EINVAL; } str += len; if (*str != ':') break; str++; } if (*str != ')') { MESSAGE(KERN_WARNING, "%s", "missing ')' in dasd parameter string\n"); rc = -EINVAL; } else str++; *endp = str; if (rc != 0) return rc; return features;}/* * Read comma separated list of dasd ranges. */static inline intdasd_ranges_list(char *str){ struct dasd_devmap *devmap; int from, from_id0, from_id1; int to, to_id0, to_id1; int features, rc; char bus_id[BUS_ID_SIZE+1], *orig_str; orig_str = str; while (1) { rc = dasd_busid(&str, &from_id0, &from_id1, &from); if (rc == 0) { to = from; to_id0 = from_id0; to_id1 = from_id1; if (*str == '-') { str++; rc = dasd_busid(&str, &to_id0, &to_id1, &to); } } if (rc == 0 && (from_id0 != to_id0 || from_id1 != to_id1 || from > to)) rc = -EINVAL; if (rc) { MESSAGE(KERN_ERR, "Invalid device range %s", orig_str); return rc; } features = dasd_feature_list(str, &str); if (features < 0) return -EINVAL; while (from <= to) { sprintf(bus_id, "%01x.%01x.%04x", from_id0, from_id1, from++); devmap = dasd_add_busid(bus_id, features); if (IS_ERR(devmap)) return PTR_ERR(devmap); } if (*str != ',') break; str++; } if (*str != '\0') { MESSAGE(KERN_WARNING, "junk at end of dasd parameter string: %s\n", str); return -EINVAL; } return 0;}/* * Parse a single dasd= parameter. */static intdasd_parameter(char *str){ if (strcmp ("autodetect", str) == 0) { dasd_autodetect = 1; MESSAGE (KERN_INFO, "%s", "turning to autodetection mode"); return 0; } if (strcmp ("probeonly", str) == 0) { dasd_probeonly = 1; MESSAGE(KERN_INFO, "%s", "turning to probeonly mode"); return 0; } /* turn off autodetect mode and scan for dasd ranges */ dasd_autodetect = 0; return dasd_ranges_list(str);}/* * Parse parameters stored in dasd[] and dasd_disciplines[]. */intdasd_parse(void){ int rc, i; rc = 0; for (i = 0; i < 256; i++) { if (dasd[i] == NULL) break; rc = dasd_parameter(dasd[i]); if (rc) { DBF_EVENT(DBF_ALERT, "%s", "invalid range found"); break; } } return rc;}/* * Add a devmap for the device specified by busid. It is possible that * the devmap already exists (dasd= parameter). The order of the devices * added through this function will define the kdevs for the individual * devices. */static struct dasd_devmap *dasd_add_busid(char *bus_id, int features){ struct dasd_devmap *devmap, *new, *tmp; int hash; new = (struct dasd_devmap *) kmalloc(sizeof(struct dasd_devmap), GFP_KERNEL); if (!new) return ERR_PTR(-ENOMEM); spin_lock(&dasd_devmap_lock); devmap = 0; hash = dasd_hash_busid(bus_id); list_for_each_entry(tmp, &dasd_hashlists[hash], list) if (strncmp(tmp->bus_id, bus_id, BUS_ID_SIZE) == 0) { devmap = tmp; break; } if (!devmap) { /* This bus_id is new. */ new->devindex = dasd_max_devindex++; strncpy(new->bus_id, bus_id, BUS_ID_SIZE); new->features = features; new->device = 0; list_add(&new->list, &dasd_hashlists[hash]); devmap = new; new = 0; } spin_unlock(&dasd_devmap_lock); if (new) kfree(new); return devmap;}/* * Find devmap for device with given bus_id. */static struct dasd_devmap *dasd_find_busid(char *bus_id){ struct dasd_devmap *devmap, *tmp; int hash; spin_lock(&dasd_devmap_lock); devmap = ERR_PTR(-ENODEV); hash = dasd_hash_busid(bus_id); list_for_each_entry(tmp, &dasd_hashlists[hash], list) { if (strncmp(tmp->bus_id, bus_id, BUS_ID_SIZE) == 0) { devmap = tmp;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?