]> sourceware.org Git - dm.git/commitdiff
Rename device node during a DM_RENAME command.
authorPatrick Caulfield <pcaulfie@redhat.com>
Thu, 11 Apr 2002 12:45:17 +0000 (12:45 +0000)
committerPatrick Caulfield <pcaulfie@redhat.com>
Thu, 11 Apr 2002 12:45:17 +0000 (12:45 +0000)
lib/ioctl/libdevmapper.c
lib/libdm-common.c
lib/libdm-common.h.in

index 20b70585a00b17d3142cc2bdefb58f0fc298c593..977d6b3a16ca5e6de2d59bd00ac561461bb7a70a 100644 (file)
@@ -338,7 +338,7 @@ int dm_task_run(struct dm_task *dmt)
                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,
@@ -354,8 +354,13 @@ int dm_task_run(struct dm_task *dmt)
        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;
index 2a43e831c20fd53d422f2d5554075c355d60578f..0ce5b151d6c1ed85da19707489223a12654347f6 100644 (file)
@@ -195,6 +195,40 @@ int add_dev_node(const char *dev_name, dev_t dev)
        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];
index d6306ac5272c733eae75ecb845008953baf686d1..f50c2d00b4c4825f70789d87539f0a103c812042 100644 (file)
@@ -25,6 +25,7 @@ extern struct target *create_target(uint64_t start,
 
 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@
 
This page took 0.032476 seconds and 5 git commands to generate.