]> sourceware.org Git - dm.git/commitdiff
Support the renaming of active mapped devices (ioctl interface only).
authorAlasdair Kergon <agk@redhat.com>
Thu, 10 Jan 2002 23:29:14 +0000 (23:29 +0000)
committerAlasdair Kergon <agk@redhat.com>
Thu, 10 Jan 2002 23:29:14 +0000 (23:29 +0000)
VERSION
kernel/common/dm.c.in
kernel/common/dm.h
kernel/ioctl/dm-ioctl.c
kernel/ioctl/dm-ioctl.h.in
lib/ioctl/libdevmapper.c
lib/ioctl/libdm-targets.h
lib/libdevmapper.h

diff --git a/VERSION b/VERSION
index c3d0f828839a01550fdb78ac599342e80b530673..6f835a073e34f2fe2b1bb7d57f38e2a229c878f3 100644 (file)
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-0.91.02-cvs (2002-01-04)
+0.92.00-cvs (2002-01-10)
index 4cc4ece92bee3c746d1b151f2bbb10354c68692e..59541aaef368bb3632a0966f47be4a9a8257b517 100644 (file)
@@ -731,7 +731,7 @@ static struct mapped_device *__get_by_name(const char *name)
 
 static int __check_name(const char *name)
 {
-       if (strchr(name, '/')) {
+       if (strchr(name, '/') || strlen(name) > DM_NAME_LEN) {
                DMWARN("invalid device name");
                return -1;
        }
@@ -845,6 +845,36 @@ void dm_set_ro(struct mapped_device *md, int ro)
        dm_unlock_w();
 }
 
+/*
+ * Renames the device
+ */
+int dm_set_name(struct mapped_device *md, const char *newname)
+{
+       int r;
+
+       dm_lock_w();
+
+       if (__check_name(newname) < 0) {
+               r = -EINVAL;
+               goto err;
+       }
+
+       r = unregister_device(md);
+       if (r)
+               goto err;
+
+       strcpy(md->name, newname);
+
+       r = register_device(md);
+       if (r)
+               goto err;
+
+      err:
+       dm_unlock_w();
+       return r;
+}
+
+
 /*
  * Requeue the deferred buffer_heads by calling generic_make_request.
  */
index 190ecd37bf659a4eb9616f542b0c5d0e5c5bb20e..9882269ecada4b7314bfc81f1d0f25e7593c969f 100644 (file)
@@ -9,6 +9,7 @@
 #ifndef DM_INTERNAL_H
 #define DM_INTERNAL_H
 
+
 #include <linux/config.h>
 #include <linux/version.h>
 #include <linux/major.h>
@@ -122,6 +123,7 @@ int dm_create(const char *name, int minor, struct dm_table *table,
              struct mapped_device **result);
 int dm_destroy(struct mapped_device *md);
 void dm_set_ro(struct mapped_device *md, int ro);
+int dm_set_name(struct mapped_device *md, const char *newname);
 
 /*
  * The device must be suspended before calling this method.
@@ -173,10 +175,11 @@ void dm_interface_exit(void);
 /* 
  * Targets for linear and striped mappings
  */
+
 int dm_linear_init(void);
 void dm_linear_exit(void);
+
 int dm_stripe_init(void);
 void dm_stripe_exit(void);
 
-
 #endif
index 7b2cd67f21b097bfc6f7b76c37a3e6bdae113531..7fe167cb22c3e1b071a1899df790db9e6d548bca 100644 (file)
@@ -33,8 +33,9 @@ static int copy_params(struct dm_ioctl *user, struct dm_ioctl **result)
 }
 
 /*
- * check a string doesn't overrun the chunk of
+ * Check a string doesn't overrun the chunk of
  * memory we copied from userland.
+ * Returns 1 if OK.
  */
 static int valid_str(char *str, void *begin, void *end)
 {
@@ -50,7 +51,7 @@ static int first_target(struct dm_ioctl *a, void *begin, void *end,
        *spec = (struct dm_target_spec *) (a + 1);
        *params = (char *) (*spec + 1);
 
-       return valid_str(*params, begin, end);
+       return !valid_str(*params, begin, end);
 }
 
 static int next_target(struct dm_target_spec *last, void *begin, void *end,
@@ -60,7 +61,7 @@ static int next_target(struct dm_target_spec *last, void *begin, void *end,
            (((unsigned char *) last) + last->next);
        *params = (char *) (*spec + 1);
 
-       return valid_str(*params, begin, end);
+       return !valid_str(*params, begin, end);
 }
 
 void dm_error(const char *message)
@@ -107,7 +108,7 @@ static int populate_table(struct dm_table *table, struct dm_ioctl *args)
                r = first ? first_target(args, begin, end, &spec, &params) :
                    next_target(spec, begin, end, &spec, &params);
 
-               if (!r)
+               if (r)
                        PARSE_ERROR("unable to find target");
 
                /* Look up the target type */
@@ -259,6 +260,25 @@ static int reload(struct dm_ioctl *param)
        return r;
 }
 
+static int rename(struct dm_ioctl *param)
+{
+       char *newname = (char *) (param + 1);
+       struct mapped_device *md = dm_get(param->name);
+
+       if (!md)
+               return -ENXIO;
+
+       if (!valid_str(newname, (void *)param, 
+                      (void *)param + param->data_size) ||
+           dm_set_name(md, newname)) {
+               dm_error("Invalid new logical volume name supplied.");
+               return -EINVAL;
+       }
+
+       dm_put(md);
+       return 0;
+}
+
 static int ctl_open(struct inode *inode, struct file *file)
 {
        /* only root can open this */
@@ -312,6 +332,10 @@ static int ctl_ioctl(struct inode *inode, struct file *file,
                r = info(p->name, (struct dm_ioctl *) a);
                break;
 
+       case DM_RENAME:
+               r = rename(p);
+               break;
+
        default:
                DMWARN("dm_ctl_ioctl: unknown command 0x%x", command);
                r = -EINVAL;
index b3b4c87fc5f8d17c643a796ba5744d20f5f99a15..20ebcae1e27e5652f9b32717b445bf55591957b9 100644 (file)
@@ -52,6 +52,7 @@ struct dm_ioctl {
 #define        DM_SUSPEND _IOW(DM_IOCTL, 0x02, struct dm_ioctl)
 #define        DM_RELOAD _IOWR(DM_IOCTL, 0x03, struct dm_ioctl)
 #define DM_INFO _IOWR(DM_IOCTL, 0x04, struct dm_ioctl)
+#define DM_RENAME _IOWR(DM_IOCTL, 0x05, struct dm_ioctl)
 
 #define DM_IOCTL_VERSION @DM_IOCTL_VERSION@
 
index ad005548b9cf35046c249b3c171b67c43c4887ce..0d39c93c7320a1509d162984c3a5631c160cab2f 100644 (file)
@@ -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);
index 72906c317c5b561aeee40b1ed6111ba5e80648a5..92433665d303b8193047390157bb439db350c937 100644 (file)
@@ -21,5 +21,6 @@ struct dm_task {
 
        int read_only;
        struct dm_ioctl *dmi;
+       char *newname;
 };
 
index a8dd6c730c52d6b1ce458481a19f790827dd389a..67ddba8b2ef4937003c1b6f61803da83ec685e7f 100644 (file)
@@ -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.
  */
This page took 0.032361 seconds and 5 git commands to generate.