[PATCH] get rid of blkdev_locked_ioctl()
[linux-2.6.git] / block / blk-integrity.c
index 65f23ef..61a8e2f 100644 (file)
@@ -108,51 +108,51 @@ new_segment:
 EXPORT_SYMBOL(blk_rq_map_integrity_sg);
 
 /**
- * blk_integrity_compare - Compare integrity profile of two block devices
- * @b1:                Device to compare
- * @b2:                Device to compare
+ * blk_integrity_compare - Compare integrity profile of two disks
+ * @gd1:       Disk to compare
+ * @gd2:       Disk to compare
  *
  * Description: Meta-devices like DM and MD need to verify that all
  * sub-devices use the same integrity format before advertising to
  * upper layers that they can send/receive integrity metadata.  This
- * function can be used to check whether two block devices have
+ * function can be used to check whether two gendisk devices have
  * compatible integrity formats.
  */
-int blk_integrity_compare(struct block_device *bd1, struct block_device *bd2)
+int blk_integrity_compare(struct gendisk *gd1, struct gendisk *gd2)
 {
-       struct blk_integrity *b1 = bd1->bd_disk->integrity;
-       struct blk_integrity *b2 = bd2->bd_disk->integrity;
+       struct blk_integrity *b1 = gd1->integrity;
+       struct blk_integrity *b2 = gd2->integrity;
 
-       BUG_ON(bd1->bd_disk == NULL);
-       BUG_ON(bd2->bd_disk == NULL);
+       if (!b1 && !b2)
+               return 0;
 
        if (!b1 || !b2)
-               return 0;
+               return -1;
 
        if (b1->sector_size != b2->sector_size) {
                printk(KERN_ERR "%s: %s/%s sector sz %u != %u\n", __func__,
-                      bd1->bd_disk->disk_name, bd2->bd_disk->disk_name,
+                      gd1->disk_name, gd2->disk_name,
                       b1->sector_size, b2->sector_size);
                return -1;
        }
 
        if (b1->tuple_size != b2->tuple_size) {
                printk(KERN_ERR "%s: %s/%s tuple sz %u != %u\n", __func__,
-                      bd1->bd_disk->disk_name, bd2->bd_disk->disk_name,
+                      gd1->disk_name, gd2->disk_name,
                       b1->tuple_size, b2->tuple_size);
                return -1;
        }
 
        if (b1->tag_size && b2->tag_size && (b1->tag_size != b2->tag_size)) {
                printk(KERN_ERR "%s: %s/%s tag sz %u != %u\n", __func__,
-                      bd1->bd_disk->disk_name, bd2->bd_disk->disk_name,
+                      gd1->disk_name, gd2->disk_name,
                       b1->tag_size, b2->tag_size);
                return -1;
        }
 
        if (strcmp(b1->name, b2->name)) {
                printk(KERN_ERR "%s: %s/%s type %s != %s\n", __func__,
-                      bd1->bd_disk->disk_name, bd2->bd_disk->disk_name,
+                      gd1->disk_name, gd2->disk_name,
                       b1->name, b2->name);
                return -1;
        }
@@ -178,8 +178,9 @@ static ssize_t integrity_attr_show(struct kobject *kobj, struct attribute *attr,
        return entry->show(bi, page);
 }
 
-static ssize_t integrity_attr_store(struct kobject *kobj, struct attribute *attr,
-                                   const char *page, size_t count)
+static ssize_t integrity_attr_store(struct kobject *kobj,
+                                   struct attribute *attr, const char *page,
+                                   size_t count)
 {
        struct blk_integrity *bi =
                container_of(kobj, struct blk_integrity, kobj);
@@ -216,17 +217,16 @@ static ssize_t integrity_read_store(struct blk_integrity *bi,
        unsigned long val = simple_strtoul(p, &p, 10);
 
        if (val)
-               set_bit(INTEGRITY_FLAG_READ, &bi->flags);
+               bi->flags |= INTEGRITY_FLAG_READ;
        else
-               clear_bit(INTEGRITY_FLAG_READ, &bi->flags);
+               bi->flags &= ~INTEGRITY_FLAG_READ;
 
        return count;
 }
 
 static ssize_t integrity_read_show(struct blk_integrity *bi, char *page)
 {
-       return sprintf(page, "%d\n",
-                      test_bit(INTEGRITY_FLAG_READ, &bi->flags) ? 1 : 0);
+       return sprintf(page, "%d\n", (bi->flags & INTEGRITY_FLAG_READ) != 0);
 }
 
 static ssize_t integrity_write_store(struct blk_integrity *bi,
@@ -236,17 +236,16 @@ static ssize_t integrity_write_store(struct blk_integrity *bi,
        unsigned long val = simple_strtoul(p, &p, 10);
 
        if (val)
-               set_bit(INTEGRITY_FLAG_WRITE, &bi->flags);
+               bi->flags |= INTEGRITY_FLAG_WRITE;
        else
-               clear_bit(INTEGRITY_FLAG_WRITE, &bi->flags);
+               bi->flags &= ~INTEGRITY_FLAG_WRITE;
 
        return count;
 }
 
 static ssize_t integrity_write_show(struct blk_integrity *bi, char *page)
 {
-       return sprintf(page, "%d\n",
-                      test_bit(INTEGRITY_FLAG_WRITE, &bi->flags) ? 1 : 0);
+       return sprintf(page, "%d\n", (bi->flags & INTEGRITY_FLAG_WRITE) != 0);
 }
 
 static struct integrity_sysfs_entry integrity_format_entry = {
@@ -326,20 +325,21 @@ int blk_integrity_register(struct gendisk *disk, struct blk_integrity *template)
        BUG_ON(template == NULL);
 
        if (disk->integrity == NULL) {
-               bi = kmem_cache_alloc(integrity_cachep, GFP_KERNEL | __GFP_ZERO);
+               bi = kmem_cache_alloc(integrity_cachep,
+                                               GFP_KERNEL | __GFP_ZERO);
                if (!bi)
                        return -1;
 
                if (kobject_init_and_add(&bi->kobj, &integrity_ktype,
-                                        &disk->dev.kobj, "%s", "integrity")) {
+                                        &disk_to_dev(disk)->kobj,
+                                        "%s", "integrity")) {
                        kmem_cache_free(integrity_cachep, bi);
                        return -1;
                }
 
                kobject_uevent(&bi->kobj, KOBJ_ADD);
 
-               set_bit(INTEGRITY_FLAG_READ, &bi->flags);
-               set_bit(INTEGRITY_FLAG_WRITE, &bi->flags);
+               bi->flags |= INTEGRITY_FLAG_READ | INTEGRITY_FLAG_WRITE;
                bi->sector_size = disk->queue->hardsect_size;
                disk->integrity = bi;
        } else
@@ -376,7 +376,7 @@ void blk_integrity_unregister(struct gendisk *disk)
 
        kobject_uevent(&bi->kobj, KOBJ_REMOVE);
        kobject_del(&bi->kobj);
-       kobject_put(&disk->dev.kobj);
        kmem_cache_free(integrity_cachep, bi);
+       disk->integrity = NULL;
 }
 EXPORT_SYMBOL(blk_integrity_unregister);