goto bad;
}
- log_debug("dm %s %s %s %s", dm_cmd_list[dmt->type], dmi->name,
+ log_debug("dm %s %s %s %s", dm_cmd_list[dmt->type], dmi->name,
dmi->uuid, dmt->newname ? dmt->newname : "");
if (ioctl(fd, command, dmi) < 0) {
log_error("device-mapper ioctl cmd %d failed: %s", dmt->type,
case DM_DEVICE_REMOVE:
rm_dev_node(dmt->dev_name);
break;
+
+ case DM_DEVICE_RENAME:
+ rename_dev_node(dmt->dev_name, dmt->newname);
+ break;
}
+
dmt->dmi = dmi;
close(fd);
return 1;
return 1;
}
+int rename_dev_node(const char *old_name, const char *new_name)
+{
+ char oldpath[PATH_MAX];
+ char newpath[PATH_MAX];
+ struct stat info;
+
+ _build_dev_path(oldpath, sizeof(oldpath), old_name);
+ _build_dev_path(newpath, sizeof(newpath), new_name);
+
+ if (stat(newpath, &info) >= 0) {
+ if (!S_ISBLK(info.st_mode)) {
+ log_error("A non-block device file at '%s' "
+ "is already present", newpath);
+ return 0;
+ }
+
+ if (unlink(newpath) < 0) {
+ if (errno == EPERM) { /* devfs, entry has already been renamed */
+ return 1;
+ }
+ log_error("Unable to unlink device node for '%s'",
+ new_name);
+ return 0;
+ }
+ }
+
+ if (rename(oldpath, newpath) < 0) {
+ log_error("Unable to rename device node from '%s' to '%s'", old_name, new_name);
+ return 0;
+ }
+
+ return 1;
+}
+
int rm_dev_node(const char *dev_name)
{
char path[PATH_MAX];
int add_dev_node(const char *dev_name, dev_t dev);
int rm_dev_node(const char *dev_name);
+int rename_dev_node(const char *old_name, const char *new_name);
#define DM_LIB_VERSION @DM_LIB_VERSION@