Merge branch 'stable-3.2' into pandora-3.2
[pandora-kernel.git] / drivers / mtd / ubi / vmt.c
index 1bfd4b6..9df07ad 100644 (file)
@@ -223,7 +223,7 @@ int ubi_create_volume(struct ubi_device *ubi, struct ubi_mkvol_req *req)
                        }
 
                if (vol_id == UBI_VOL_NUM_AUTO) {
-                       dbg_err("out of volume IDs");
+                       ubi_err("out of volume IDs");
                        err = -ENFILE;
                        goto out_unlock;
                }
@@ -237,7 +237,7 @@ int ubi_create_volume(struct ubi_device *ubi, struct ubi_mkvol_req *req)
        /* Ensure that this volume does not exist */
        err = -EEXIST;
        if (ubi->volumes[vol_id]) {
-               dbg_err("volume %d already exists", vol_id);
+               ubi_err("volume %d already exists", vol_id);
                goto out_unlock;
        }
 
@@ -246,7 +246,7 @@ int ubi_create_volume(struct ubi_device *ubi, struct ubi_mkvol_req *req)
                if (ubi->volumes[i] &&
                    ubi->volumes[i]->name_len == req->name_len &&
                    !strcmp(ubi->volumes[i]->name, req->name)) {
-                       dbg_err("volume \"%s\" exists (ID %d)", req->name, i);
+                       ubi_err("volume \"%s\" exists (ID %d)", req->name, i);
                        goto out_unlock;
                }
 
@@ -257,9 +257,9 @@ int ubi_create_volume(struct ubi_device *ubi, struct ubi_mkvol_req *req)
 
        /* Reserve physical eraseblocks */
        if (vol->reserved_pebs > ubi->avail_pebs) {
-               dbg_err("not enough PEBs, only %d available", ubi->avail_pebs);
+               ubi_err("not enough PEBs, only %d available", ubi->avail_pebs);
                if (ubi->corr_peb_count)
-                       dbg_err("%d PEBs are corrupted and not used",
+                       ubi_err("%d PEBs are corrupted and not used",
                                ubi->corr_peb_count);
                err = -ENOSPC;
                goto out_unlock;
@@ -280,7 +280,7 @@ int ubi_create_volume(struct ubi_device *ubi, struct ubi_mkvol_req *req)
         * Finish all pending erases because there may be some LEBs belonging
         * to the same volume ID.
         */
-       err = ubi_wl_flush(ubi);
+       err = ubi_wl_flush(ubi, vol_id, UBI_ALL);
        if (err)
                goto out_acc;
 
@@ -308,6 +308,12 @@ int ubi_create_volume(struct ubi_device *ubi, struct ubi_mkvol_req *req)
                        vol->last_eb_bytes = vol->usable_leb_size;
        }
 
+       /* Make volume "available" before it becomes accessible via sysfs */
+       spin_lock(&ubi->volumes_lock);
+       ubi->volumes[vol_id] = vol;
+       ubi->vol_count += 1;
+       spin_unlock(&ubi->volumes_lock);
+
        /* Register character device for the volume */
        cdev_init(&vol->cdev, &ubi_vol_cdev_operations);
        vol->cdev.owner = THIS_MODULE;
@@ -350,11 +356,6 @@ int ubi_create_volume(struct ubi_device *ubi, struct ubi_mkvol_req *req)
        if (err)
                goto out_sysfs;
 
-       spin_lock(&ubi->volumes_lock);
-       ubi->volumes[vol_id] = vol;
-       ubi->vol_count += 1;
-       spin_unlock(&ubi->volumes_lock);
-
        ubi_volume_notify(ubi, vol, UBI_VOLUME_ADDED);
        self_check_volumes(ubi);
        return err;
@@ -374,6 +375,10 @@ out_sysfs:
 out_cdev:
        cdev_del(&vol->cdev);
 out_mapping:
+       spin_lock(&ubi->volumes_lock);
+       ubi->volumes[vol_id] = NULL;
+       ubi->vol_count -= 1;
+       spin_unlock(&ubi->volumes_lock);
        if (do_free)
                kfree(vol->eba_tbl);
 out_acc:
@@ -495,7 +500,7 @@ int ubi_resize_volume(struct ubi_volume_desc *desc, int reserved_pebs)
 
        if (vol->vol_type == UBI_STATIC_VOLUME &&
            reserved_pebs < vol->used_ebs) {
-               dbg_err("too small size %d, %d LEBs contain data",
+               ubi_err("too small size %d, %d LEBs contain data",
                        reserved_pebs, vol->used_ebs);
                return -EINVAL;
        }
@@ -524,10 +529,10 @@ int ubi_resize_volume(struct ubi_volume_desc *desc, int reserved_pebs)
        if (pebs > 0) {
                spin_lock(&ubi->volumes_lock);
                if (pebs > ubi->avail_pebs) {
-                       dbg_err("not enough PEBs: requested %d, available %d",
+                       ubi_err("not enough PEBs: requested %d, available %d",
                                pebs, ubi->avail_pebs);
                        if (ubi->corr_peb_count)
-                               dbg_err("%d PEBs are corrupted and not used",
+                               ubi_err("%d PEBs are corrupted and not used",
                                        ubi->corr_peb_count);
                        spin_unlock(&ubi->volumes_lock);
                        err = -ENOSPC;
@@ -762,7 +767,7 @@ static int self_check_volume(struct ubi_device *ubi, int vol_id)
        }
 
        if (vol->upd_marker && vol->corrupted) {
-               dbg_err("update marker and corrupted simultaneously");
+               ubi_err("update marker and corrupted simultaneously");
                goto fail;
        }