lilo patch for mirrored configurations
Erik Agsjö
erik.agsjo at noptec.com
Wed Oct 6 22:28:02 UTC 2004
I have added basic support for mirrored targets to Christophe Saout's lilo patch.
The patch should be applied after the "lilo-22.6-devmapper.patch" and makes it
possible to run lilo on my dmraid created mirrored configuration.
The code is by no means integrated with the MD based RAID-1 support in
lilo, which of course would be neat, but it's a start.
/Erik
-----8<------
--- lilo-22.6-devmapper_patched/geometry.c Wed Oct 6 21:34:55 2004
+++ lilo-22.6-devmapper_patched_work/geometry.c Wed Oct 6 23:34:04 2004
@@ -930,57 +930,76 @@
if (!target_type) continue;
- if (strcmp(target_type, "linear") != 0)
- die("device-mapper: only linear boot device supported");
-
target = alloc_t(DM_TARGET);
target->start = start;
target->length = length;
- if (dm_version_nr < 4 &&
- isxdigit(params[0]) &&
- isxdigit(params[1]) &&
- params[2] == ':' &&
- isxdigit(params[3]) &&
- isxdigit(params[4])) { /* old 2.4 format */
- if (sscanf(params, "%02x:%02x %"PRIu64, &major, &minor, &target->offset) != 3)
- die("device-mapper: parse error in linear params (\"%s\")", params);
- } else if (isdigit(params[0]) &&
- strchr(params, ':')) { /* dm_bdevname/format_dev_t (>= 2.6.0-test4?) format */
- if (sscanf(params, "%u:%u %"PRIu64, &major, &minor, &target->offset) != 3)
- die("device-mapper: parse error in linear params (\"%s\")", params);
- } else { /* >= 2.5.69 format, this should go away soon */
- struct stat st;
- FILE *file;
- p = strrchr(params, ' ');
- if (p == NULL)
- die("device-mapper: parse error in linear params (\"%s\")", params);
- *p = 0;
- sprintf(buf, "/dev/%s", params); /* let's hope it's there */
- if (stat(buf, &st) == 0) {
- if (!S_ISBLK(st.st_mode))
- die("device-mapper: %s is not a valid block device", buf);
- major = MAJOR(st.st_rdev);
- minor = MINOR(st.st_rdev);
- } else { /* let's try sysfs */
- int dev;
- sprintf(buf, "/sys/block/%s/dev", params);
- file = fopen(buf, "r");
- if (!file)
- die("device-mapper: \"%s\" could not be opened. /sys mounted?", buf);
- if (!fgets(buf, PATH_MAX, file))
- die("device-mapper: read error from \"/sys/block/%s/dev\"", params);
- if (sscanf(buf, "%u:%u", &major, &minor) != 2) {
- if (sscanf(buf, "%x", &dev) != 1)
- die("device-mapper: error getting device from \"%s\"", buf);
- major = MAJOR(dev);
- minor = MINOR(dev);
+ if (strcmp(target_type, "mirror") == 0){
+ int device_count = 0;
+ uint64_t secondary_offset = 0;
+ int secondary_major;
+ int secondary_minor;
+ if(sscanf(params, "%*s %*d %*d %*s %d %u:%u %"PRIu64" %u:%u %"PRIu64,
+ &device_count,
+ &major, &minor, &target->offset,
+ &secondary_major, &secondary_minor, &secondary_offset) != 7){
+ die("device-mapper: parse error in mirror params (\"%s\")", params);
+ }
+ if(device_count > 2){
+ die("device-mapper: mirrors of more than 2 devices not supported");
+ }
+ if(secondary_offset != target->offset){
+ die("device-mapper: skewed mirrors not supported");
+ }
+ } else if (strcmp(target_type, "linear") == 0) {
+ if (dm_version_nr < 4 &&
+ isxdigit(params[0]) &&
+ isxdigit(params[1]) &&
+ params[2] == ':' &&
+ isxdigit(params[3]) &&
+ isxdigit(params[4])) { /* old 2.4 format */
+ if (sscanf(params, "%02x:%02x %"PRIu64, &major, &minor, &target->offset) != 3)
+ die("device-mapper: parse error in linear params (\"%s\")", params);
+ } else if (isdigit(params[0]) &&
+ strchr(params, ':')) { /* dm_bdevname/format_dev_t (>= 2.6.0-test4?) format */
+ if (sscanf(params, "%u:%u %"PRIu64, &major, &minor, &target->offset) != 3)
+ die("device-mapper: parse error in linear params (\"%s\")", params);
+ } else { /* >= 2.5.69 format, this should go away soon */
+ struct stat st;
+ FILE *file;
+
+ p = strrchr(params, ' ');
+ if (p == NULL)
+ die("device-mapper: parse error in linear params (\"%s\")", params);
+ *p = 0;
+ sprintf(buf, "/dev/%s", params); /* let's hope it's there */
+ if (stat(buf, &st) == 0) {
+ if (!S_ISBLK(st.st_mode))
+ die("device-mapper: %s is not a valid block device", buf);
+ major = MAJOR(st.st_rdev);
+ minor = MINOR(st.st_rdev);
+ } else { /* let's try sysfs */
+ int dev;
+ sprintf(buf, "/sys/block/%s/dev", params);
+ file = fopen(buf, "r");
+ if (!file)
+ die("device-mapper: \"%s\" could not be opened. /sys mounted?", buf);
+ if (!fgets(buf, PATH_MAX, file))
+ die("device-mapper: read error from \"/sys/block/%s/dev\"", params);
+ if (sscanf(buf, "%u:%u", &major, &minor) != 2) {
+ if (sscanf(buf, "%x", &dev) != 1)
+ die("device-mapper: error getting device from \"%s\"", buf);
+ major = MAJOR(dev);
+ minor = MINOR(dev);
+ }
+ (void) fclose(file);
}
- (void) fclose(file);
+ *p = ' ';
+ if (sscanf(p+1, "%"PRIu64, &target->offset) != 1)
+ die("device-mapper: parse error in linear params (\"%s\")", params);
}
- *p = ' ';
- if (sscanf(p+1, "%"PRIu64, &target->offset) != 1)
- die("device-mapper: parse error in linear params (\"%s\")", params);
+ }else{
+ die("device-mapper: only mirror or linear boot device supported");
}
target->device = (major << 8) | minor;
if (!device)
More information about the Ataraid-list
mailing list