/* * Format: dm-mod.create=<name>,<uuid>,<minor>,<flags>,<table>[,<table>+][;<name>,<uuid>,<minor>,<flags>,<table>[,<table>+]+] * Table format: <start_sector> <num_sectors> <target_type> <target_args> * Block devices to wait for to become available before setting up tables: * dm-mod.waitfor=<device1>[,..,<deviceN>] * * See Documentation/admin-guide/device-mapper/dm-init.rst for dm-mod.create="..." format * details.
*/
list_for_each_entry_safe(dev, tmp, devices, list) {
list_del(&dev->list); for (i = 0; i < dev->dmi.target_count; i++) {
kfree(dev->table[i]);
kfree(dev->target_args_array[i]);
}
kfree(dev);
}
}
/** * str_field_delimit - delimit a string based on a separator char. * @str: the pointer to the string to delimit. * @separator: char that delimits the field * * Find a @separator and replace it by '\0'. * Remove leading and trailing spaces. * Return the remainder string after the @separator.
*/ staticchar __init *str_field_delimit(char **str, char separator)
{ char *s;
/* TODO: add support for escaped characters */
*str = skip_spaces(*str);
s = strchr(*str, separator); /* Delimit the field and remove trailing spaces */ if (s)
*s = '\0';
*str = strim(*str); return s ? ++s : NULL;
}
/** * dm_parse_table_entry - parse a table entry * @dev: device to store the parsed information. * @str: the pointer to a string with the format: * <start_sector> <num_sectors> <target_type> <target_args>[, ...] * * Return the remainder string after the table entry, i.e, after the comma which * delimits the entry or NULL if reached the end of the string.
*/ staticchar __init *dm_parse_table_entry(struct dm_device *dev, char *str)
{ constunsignedint n = dev->dmi.target_count - 1; struct dm_target_spec *sp; unsignedint i; /* fields: */ char *field[4]; char *next;
field[0] = str; /* Delimit first 3 fields that are separated by space */ for (i = 0; i < ARRAY_SIZE(field) - 1; i++) {
field[i + 1] = str_field_delimit(&field[i], ' '); if (!field[i + 1]) return ERR_PTR(-EINVAL);
} /* Delimit last field that can be terminated by comma */
next = str_field_delimit(&field[i], ',');
/* start_sector */ if (kstrtoull(field[0], 0, &sp->sector_start)) return ERR_PTR(-EINVAL); /* num_sector */ if (kstrtoull(field[1], 0, &sp->length)) return ERR_PTR(-EINVAL); /* target_type */
strscpy(sp->target_type, field[2], sizeof(sp->target_type)); if (dm_verify_target_type(sp->target_type)) {
DMERR("invalid type \"%s\"", sp->target_type); return ERR_PTR(-EINVAL);
} /* target_args */
dev->target_args_array[n] = kstrndup(field[3], DM_MAX_STR_SIZE,
GFP_KERNEL); if (!dev->target_args_array[n]) return ERR_PTR(-ENOMEM);
return next;
}
/** * dm_parse_table - parse "dm-mod.create=" table field * @dev: device to store the parsed information. * @str: the pointer to a string with the format: * <table>[,<table>+]
*/ staticint __init dm_parse_table(struct dm_device *dev, char *str)
{ char *table_entry = str;
while (table_entry) {
DMDEBUG("parsing table \"%s\"", str); if (++dev->dmi.target_count > DM_MAX_TARGETS) {
DMERR("too many targets %u > %d",
dev->dmi.target_count, DM_MAX_TARGETS); return -EINVAL;
}
table_entry = dm_parse_table_entry(dev, table_entry); if (IS_ERR(table_entry)) {
DMERR("couldn't parse table"); return PTR_ERR(table_entry);
}
}
return 0;
}
/** * dm_parse_device_entry - parse a device entry * @dev: device to store the parsed information. * @str: the pointer to a string with the format: * name,uuid,minor,flags,table[; ...] * * Return the remainder string after the table entry, i.e, after the semi-colon * which delimits the entry or NULL if reached the end of the string.
*/ staticchar __init *dm_parse_device_entry(struct dm_device *dev, char *str)
{ /* There are 5 fields: name,uuid,minor,flags,table; */ char *field[5]; unsignedint i; char *next;
field[0] = str; /* Delimit first 4 fields that are separated by comma */ for (i = 0; i < ARRAY_SIZE(field) - 1; i++) {
field[i+1] = str_field_delimit(&field[i], ','); if (!field[i+1]) return ERR_PTR(-EINVAL);
} /* Delimit last field that can be delimited by semi-colon */
next = str_field_delimit(&field[i], ';');
/* name */
strscpy(dev->dmi.name, field[0], sizeof(dev->dmi.name)); /* uuid */
strscpy(dev->dmi.uuid, field[1], sizeof(dev->dmi.uuid)); /* minor */ if (strlen(field[2])) { if (kstrtoull(field[2], 0, &dev->dmi.dev) ||
dev->dmi.dev >= (1 << MINORBITS)) return ERR_PTR(-EINVAL);
dev->dmi.dev = huge_encode_dev((dev_t)dev->dmi.dev);
dev->dmi.flags |= DM_PERSISTENT_DEV_FLAG;
} /* flags */ if (!strcmp(field[3], "ro"))
dev->dmi.flags |= DM_READONLY_FLAG; elseif (strcmp(field[3], "rw")) return ERR_PTR(-EINVAL); /* table */ if (dm_parse_table(dev, field[4])) return ERR_PTR(-EINVAL);
return next;
}
/** * dm_parse_devices - parse "dm-mod.create=" argument * @devices: list of struct dm_device to store the parsed information. * @str: the pointer to a string with the format: * <device>[;<device>+]
*/ staticint __init dm_parse_devices(struct list_head *devices, char *str)
{ unsignedlong ndev = 0; struct dm_device *dev; char *device = str;
DMDEBUG("parsing \"%s\"", str); while (device) {
dev = kzalloc(sizeof(*dev), GFP_KERNEL); if (!dev) return -ENOMEM;
list_add_tail(&dev->list, devices);
if (++ndev > DM_MAX_DEVICES) {
DMERR("too many devices %lu > %d",
ndev, DM_MAX_DEVICES); return -EINVAL;
}
/** * dm_init_init - parse "dm-mod.create=" argument and configure drivers
*/ staticint __init dm_init_init(void)
{ struct dm_device *dev;
LIST_HEAD(devices); char *str; int i, r;
if (!create) return 0;
if (strlen(create) >= DM_MAX_STR_SIZE) {
DMERR("Argument is too big. Limit is %d", DM_MAX_STR_SIZE); return -EINVAL;
}
str = kstrndup(create, DM_MAX_STR_SIZE, GFP_KERNEL); if (!str) return -ENOMEM;
r = dm_parse_devices(&devices, str); if (r) goto out;
DMINFO("waiting for all devices to be available before creating mapped devices");
wait_for_device_probe();
for (i = 0; i < ARRAY_SIZE(waitfor); i++) { if (waitfor[i]) {
dev_t dev;
DMINFO("waiting for device %s ...", waitfor[i]); while (early_lookup_bdev(waitfor[i], &dev))
fsleep(5000);
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.