dm kcopyd: accept zero size jobs
[safe/jmp/linux-2.6] / drivers / md / dm-ioctl.c
index 1128d3f..99de0e4 100644 (file)
@@ -56,6 +56,11 @@ static void dm_hash_remove_all(int keep_open_devices);
  */
 static DECLARE_RWSEM(_hash_lock);
 
+/*
+ * Protects use of mdptr to obtain hash cell name and uuid from mapped device.
+ */
+static DEFINE_MUTEX(dm_hash_cells_mutex);
+
 static void init_buckets(struct list_head *buckets)
 {
        unsigned int i;
@@ -206,7 +211,9 @@ static int dm_hash_insert(const char *name, const char *uuid, struct mapped_devi
                list_add(&cell->uuid_list, _uuid_buckets + hash_str(uuid));
        }
        dm_get(md);
+       mutex_lock(&dm_hash_cells_mutex);
        dm_set_mdptr(md, cell);
+       mutex_unlock(&dm_hash_cells_mutex);
        up_write(&_hash_lock);
 
        return 0;
@@ -224,7 +231,9 @@ static void __hash_remove(struct hash_cell *hc)
        /* remove from the dev hash */
        list_del(&hc->uuid_list);
        list_del(&hc->name_list);
+       mutex_lock(&dm_hash_cells_mutex);
        dm_set_mdptr(hc->md, NULL);
+       mutex_unlock(&dm_hash_cells_mutex);
 
        table = dm_get_table(hc->md);
        if (table) {
@@ -276,7 +285,7 @@ retry:
        up_write(&_hash_lock);
 }
 
-static int dm_hash_rename(const char *old, const char *new)
+static int dm_hash_rename(uint32_t cookie, const char *old, const char *new)
 {
        char *new_name, *old_name;
        struct hash_cell *hc;
@@ -321,7 +330,9 @@ static int dm_hash_rename(const char *old, const char *new)
         */
        list_del(&hc->name_list);
        old_name = hc->name;
+       mutex_lock(&dm_hash_cells_mutex);
        hc->name = new_name;
+       mutex_unlock(&dm_hash_cells_mutex);
        list_add(&hc->name_list, _name_buckets + hash_str(new_name));
 
        /*
@@ -333,7 +344,7 @@ static int dm_hash_rename(const char *old, const char *new)
                dm_table_put(table);
        }
 
-       dm_kobject_uevent(hc->md);
+       dm_kobject_uevent(hc->md, KOBJ_CHANGE, cookie);
 
        dm_put(hc->md);
        up_write(&_hash_lock);
@@ -634,9 +645,9 @@ static struct mapped_device *find_device(struct dm_ioctl *param)
                 * Sneakily write in both the name and the uuid
                 * while we have the cell.
                 */
-               strncpy(param->name, hc->name, sizeof(param->name));
+               strlcpy(param->name, hc->name, sizeof(param->name));
                if (hc->uuid)
-                       strncpy(param->uuid, hc->uuid, sizeof(param->uuid)-1);
+                       strlcpy(param->uuid, hc->uuid, sizeof(param->uuid));
                else
                        param->uuid[0] = '\0';
 
@@ -680,6 +691,9 @@ static int dev_remove(struct dm_ioctl *param, size_t param_size)
 
        __hash_remove(hc);
        up_write(&_hash_lock);
+
+       dm_kobject_uevent(md, KOBJ_REMOVE, param->event_nr);
+
        dm_put(md);
        param->data_size = 0;
        return 0;
@@ -715,7 +729,7 @@ static int dev_rename(struct dm_ioctl *param, size_t param_size)
                return r;
 
        param->data_size = 0;
-       return dm_hash_rename(param->name, new_name);
+       return dm_hash_rename(param->event_nr, param->name, new_name);
 }
 
 static int dev_set_geometry(struct dm_ioctl *param, size_t param_size)
@@ -842,8 +856,11 @@ static int do_resume(struct dm_ioctl *param)
        if (dm_suspended(md))
                r = dm_resume(md);
 
-       if (!r)
+
+       if (!r) {
+               dm_kobject_uevent(md, KOBJ_CHANGE, param->event_nr);
                r = __dev_status(md, param);
+       }
 
        dm_put(md);
        return r;
@@ -1044,6 +1061,12 @@ static int populate_table(struct dm_table *table,
                next = spec->next;
        }
 
+       r = dm_table_set_type(table);
+       if (r) {
+               DMWARN("unable to set table type");
+               return r;
+       }
+
        return dm_table_complete(table);
 }
 
@@ -1089,6 +1112,13 @@ static int table_load(struct dm_ioctl *param, size_t param_size)
                goto out;
        }
 
+       r = dm_table_alloc_md_mempools(t);
+       if (r) {
+               DMWARN("unable to allocate mempools for this table");
+               dm_table_destroy(t);
+               goto out;
+       }
+
        down_write(&_hash_lock);
        hc = dm_get_mdptr(md);
        if (!hc || hc->md != md) {
@@ -1513,7 +1543,7 @@ static const struct file_operations _ctl_fops = {
 static struct miscdevice _dm_misc = {
        .minor          = MISC_DYNAMIC_MINOR,
        .name           = DM_NAME,
-       .devnode        = "mapper/control",
+       .nodename       = "mapper/control",
        .fops           = &_ctl_fops
 };
 
@@ -1563,8 +1593,7 @@ int dm_copy_name_and_uuid(struct mapped_device *md, char *name, char *uuid)
        if (!md)
                return -ENXIO;
 
-       dm_get(md);
-       down_read(&_hash_lock);
+       mutex_lock(&dm_hash_cells_mutex);
        hc = dm_get_mdptr(md);
        if (!hc || hc->md != md) {
                r = -ENXIO;
@@ -1577,8 +1606,7 @@ int dm_copy_name_and_uuid(struct mapped_device *md, char *name, char *uuid)
                strcpy(uuid, hc->uuid ? : "");
 
 out:
-       up_read(&_hash_lock);
-       dm_put(md);
+       mutex_unlock(&dm_hash_cells_mutex);
 
        return r;
 }