diff --git a/libdm/ioctl/libdevmapper.c b/libdm/ioctl/libdevmapper.c index ad005548b..0d39c93c7 100644 --- a/libdm/ioctl/libdevmapper.c +++ b/libdm/ioctl/libdevmapper.c @@ -35,6 +35,9 @@ void dm_task_destroy(struct dm_task *dmt) free(t); } + if (dmt->newname) + free(dmt->newname); + if (dmt->dmi) free(dmt->dmi); @@ -62,6 +65,16 @@ int dm_task_set_ro(struct dm_task *dmt) return 1; } +int dm_task_set_newname(struct dm_task *dmt, const char *newname) +{ + if (!(dmt->newname = strdup(newname))) { + log("dm_task_set_newname: strdup(%s) failed", newname); + return 0; + } + + return 1; +} + struct target *create_target(uint64_t start, uint64_t len, const char *type, const char *params) @@ -154,6 +167,14 @@ static struct dm_ioctl *_flatten(struct dm_task *dmt) count++; } + if (count && dmt->newname) { + log("targets and newname are incompatible"); + return NULL; + } + + if (dmt->newname) + len += strlen(dmt->newname) + 1; + if (!(dmi = malloc(len))) return NULL; @@ -176,6 +197,9 @@ static struct dm_ioctl *_flatten(struct dm_task *dmt) if (!(b = _add_target(t, b, e))) goto bad; + if (dmt->newname) + strcpy(b, dmt->newname); + return dmi; bad: @@ -227,6 +251,10 @@ int dm_task_run(struct dm_task *dmt) command = DM_INFO; break; + case DM_DEVICE_RENAME: + command = DM_RENAME; + break; + default: log("Internal error: unknown device-mapper task %d", dmt->type); diff --git a/libdm/ioctl/libdm-targets.h b/libdm/ioctl/libdm-targets.h index 72906c317..92433665d 100644 --- a/libdm/ioctl/libdm-targets.h +++ b/libdm/ioctl/libdm-targets.h @@ -21,5 +21,6 @@ struct dm_task { int read_only; struct dm_ioctl *dmi; + char *newname; }; diff --git a/libdm/libdevmapper.h b/libdm/libdevmapper.h index a8dd6c730..67ddba8b2 100644 --- a/libdm/libdevmapper.h +++ b/libdm/libdevmapper.h @@ -38,6 +38,7 @@ enum { DM_DEVICE_RESUME, DM_DEVICE_INFO, + DM_DEVICE_RENAME, }; @@ -66,6 +67,8 @@ int dm_task_get_info(struct dm_task *dmt, struct dm_info *dmi); int dm_task_set_ro(struct dm_task *dmt); +int dm_task_set_newname(struct dm_task *dmt, const char *newname); + /* * Use these to prepare for a create or reload. */