xfs: wait for direct I/O to complete in fsync and write_inode
[safe/jmp/linux-2.6] / block / blk-integrity.c
index 61a8e2f..edce1ef 100644 (file)
@@ -24,6 +24,7 @@
 #include <linux/mempool.h>
 #include <linux/bio.h>
 #include <linux/scatterlist.h>
+#include <linux/slab.h>
 
 #include "blk.h"
 
@@ -278,7 +279,7 @@ static struct attribute *integrity_attrs[] = {
        NULL,
 };
 
-static struct sysfs_ops integrity_ops = {
+static const struct sysfs_ops integrity_ops = {
        .show   = &integrity_attr_show,
        .store  = &integrity_attr_store,
 };
@@ -309,24 +310,24 @@ static struct kobj_type integrity_ktype = {
 /**
  * blk_integrity_register - Register a gendisk as being integrity-capable
  * @disk:      struct gendisk pointer to make integrity-aware
- * @template:  integrity profile
+ * @template:  optional integrity profile to register
  *
  * Description: When a device needs to advertise itself as being able
  * to send/receive integrity metadata it must use this function to
  * register the capability with the block layer.  The template is a
  * blk_integrity struct with values appropriate for the underlying
- * hardware.  See Documentation/block/data-integrity.txt.
+ * hardware.  If template is NULL the new profile is allocated but
+ * not filled out. See Documentation/block/data-integrity.txt.
  */
 int blk_integrity_register(struct gendisk *disk, struct blk_integrity *template)
 {
        struct blk_integrity *bi;
 
        BUG_ON(disk == NULL);
-       BUG_ON(template == NULL);
 
        if (disk->integrity == NULL) {
                bi = kmem_cache_alloc(integrity_cachep,
-                                               GFP_KERNEL | __GFP_ZERO);
+                                     GFP_KERNEL | __GFP_ZERO);
                if (!bi)
                        return -1;
 
@@ -340,19 +341,22 @@ int blk_integrity_register(struct gendisk *disk, struct blk_integrity *template)
                kobject_uevent(&bi->kobj, KOBJ_ADD);
 
                bi->flags |= INTEGRITY_FLAG_READ | INTEGRITY_FLAG_WRITE;
-               bi->sector_size = disk->queue->hardsect_size;
+               bi->sector_size = queue_logical_block_size(disk->queue);
                disk->integrity = bi;
        } else
                bi = disk->integrity;
 
        /* Use the provided profile as template */
-       bi->name = template->name;
-       bi->generate_fn = template->generate_fn;
-       bi->verify_fn = template->verify_fn;
-       bi->tuple_size = template->tuple_size;
-       bi->set_tag_fn = template->set_tag_fn;
-       bi->get_tag_fn = template->get_tag_fn;
-       bi->tag_size = template->tag_size;
+       if (template != NULL) {
+               bi->name = template->name;
+               bi->generate_fn = template->generate_fn;
+               bi->verify_fn = template->verify_fn;
+               bi->tuple_size = template->tuple_size;
+               bi->set_tag_fn = template->set_tag_fn;
+               bi->get_tag_fn = template->get_tag_fn;
+               bi->tag_size = template->tag_size;
+       } else
+               bi->name = "unsupported";
 
        return 0;
 }
@@ -376,6 +380,7 @@ void blk_integrity_unregister(struct gendisk *disk)
 
        kobject_uevent(&bi->kobj, KOBJ_REMOVE);
        kobject_del(&bi->kobj);
+       kobject_put(&bi->kobj);
        kmem_cache_free(integrity_cachep, bi);
        disk->integrity = NULL;
 }