]> asedeno.scripts.mit.edu Git - linux.git/blobdiff - block/blk-zoned.c
Merge tag 'tty-5.5-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty
[linux.git] / block / blk-zoned.c
index 65a9bdc9fe2772b22cbbef583b09f43e18f2c62f..d00fcfd71dfeae047fab62b37ab117c4fc467e6b 100644 (file)
@@ -332,16 +332,18 @@ static inline unsigned long *blk_alloc_zone_bitmap(int node,
 
 void blk_queue_free_zone_bitmaps(struct request_queue *q)
 {
-       kfree(q->seq_zones_bitmap);
-       q->seq_zones_bitmap = NULL;
+       kfree(q->conv_zones_bitmap);
+       q->conv_zones_bitmap = NULL;
        kfree(q->seq_zones_wlock);
        q->seq_zones_wlock = NULL;
 }
 
 struct blk_revalidate_zone_args {
        struct gendisk  *disk;
-       unsigned long   *seq_zones_bitmap;
+       unsigned long   *conv_zones_bitmap;
        unsigned long   *seq_zones_wlock;
+       unsigned int    nr_zones;
+       sector_t        zone_sectors;
        sector_t        sector;
 };
 
@@ -354,25 +356,33 @@ static int blk_revalidate_zone_cb(struct blk_zone *zone, unsigned int idx,
        struct blk_revalidate_zone_args *args = data;
        struct gendisk *disk = args->disk;
        struct request_queue *q = disk->queue;
-       sector_t zone_sectors = blk_queue_zone_sectors(q);
        sector_t capacity = get_capacity(disk);
 
        /*
         * All zones must have the same size, with the exception on an eventual
         * smaller last zone.
         */
-       if (zone->start + zone_sectors < capacity &&
-           zone->len != zone_sectors) {
-               pr_warn("%s: Invalid zoned device with non constant zone size\n",
-                       disk->disk_name);
-               return false;
-       }
+       if (zone->start == 0) {
+               if (zone->len == 0 || !is_power_of_2(zone->len)) {
+                       pr_warn("%s: Invalid zoned device with non power of two zone size (%llu)\n",
+                               disk->disk_name, zone->len);
+                       return -ENODEV;
+               }
 
-       if (zone->start + zone->len >= capacity &&
-           zone->len > zone_sectors) {
-               pr_warn("%s: Invalid zoned device with larger last zone size\n",
-                       disk->disk_name);
-               return -ENODEV;
+               args->zone_sectors = zone->len;
+               args->nr_zones = (capacity + zone->len - 1) >> ilog2(zone->len);
+       } else if (zone->start + args->zone_sectors < capacity) {
+               if (zone->len != args->zone_sectors) {
+                       pr_warn("%s: Invalid zoned device with non constant zone size\n",
+                               disk->disk_name);
+                       return -ENODEV;
+               }
+       } else {
+               if (zone->len > args->zone_sectors) {
+                       pr_warn("%s: Invalid zoned device with larger last zone size\n",
+                               disk->disk_name);
+                       return -ENODEV;
+               }
        }
 
        /* Check for holes in the zone report */
@@ -385,8 +395,22 @@ static int blk_revalidate_zone_cb(struct blk_zone *zone, unsigned int idx,
        /* Check zone type */
        switch (zone->type) {
        case BLK_ZONE_TYPE_CONVENTIONAL:
+               if (!args->conv_zones_bitmap) {
+                       args->conv_zones_bitmap =
+                               blk_alloc_zone_bitmap(q->node, args->nr_zones);
+                       if (!args->conv_zones_bitmap)
+                               return -ENOMEM;
+               }
+               set_bit(idx, args->conv_zones_bitmap);
+               break;
        case BLK_ZONE_TYPE_SEQWRITE_REQ:
        case BLK_ZONE_TYPE_SEQWRITE_PREF:
+               if (!args->seq_zones_wlock) {
+                       args->seq_zones_wlock =
+                               blk_alloc_zone_bitmap(q->node, args->nr_zones);
+                       if (!args->seq_zones_wlock)
+                               return -ENOMEM;
+               }
                break;
        default:
                pr_warn("%s: Invalid zone type 0x%x at sectors %llu\n",
@@ -394,78 +418,54 @@ static int blk_revalidate_zone_cb(struct blk_zone *zone, unsigned int idx,
                return -ENODEV;
        }
 
-       if (zone->type != BLK_ZONE_TYPE_CONVENTIONAL)
-               set_bit(idx, args->seq_zones_bitmap);
-
        args->sector += zone->len;
        return 0;
 }
 
-static int blk_update_zone_info(struct gendisk *disk, unsigned int nr_zones,
-                               struct blk_revalidate_zone_args *args)
-{
-       /*
-        * Ensure that all memory allocations in this context are done as
-        * if GFP_NOIO was specified.
-        */
-       unsigned int noio_flag = memalloc_noio_save();
-       struct request_queue *q = disk->queue;
-       int ret;
-
-       args->seq_zones_wlock = blk_alloc_zone_bitmap(q->node, nr_zones);
-       if (!args->seq_zones_wlock)
-               return -ENOMEM;
-       args->seq_zones_bitmap = blk_alloc_zone_bitmap(q->node, nr_zones);
-       if (!args->seq_zones_bitmap)
-               return -ENOMEM;
-
-       ret = disk->fops->report_zones(disk, 0, nr_zones,
-                                      blk_revalidate_zone_cb, args);
-       memalloc_noio_restore(noio_flag);
-       return ret;
-}
-
 /**
  * blk_revalidate_disk_zones - (re)allocate and initialize zone bitmaps
  * @disk:      Target disk
  *
  * Helper function for low-level device drivers to (re) allocate and initialize
  * a disk request queue zone bitmaps. This functions should normally be called
- * within the disk ->revalidate method. For BIO based queues, no zone bitmap
- * is allocated.
+ * within the disk ->revalidate method for blk-mq based drivers.  For BIO based
+ * drivers only q->nr_zones needs to be updated so that the sysfs exposed value
+ * is correct.
  */
 int blk_revalidate_disk_zones(struct gendisk *disk)
 {
        struct request_queue *q = disk->queue;
-       unsigned int nr_zones = blkdev_nr_zones(disk);
-       struct blk_revalidate_zone_args args = { .disk = disk };
-       int ret = 0;
+       struct blk_revalidate_zone_args args = {
+               .disk           = disk,
+       };
+       unsigned int noio_flag;
+       int ret;
 
        if (WARN_ON_ONCE(!blk_queue_is_zoned(q)))
                return -EIO;
+       if (WARN_ON_ONCE(!queue_is_mq(q)))
+               return -EIO;
 
        /*
-        * BIO based queues do not use a scheduler so only q->nr_zones
-        * needs to be updated so that the sysfs exposed value is correct.
+        * Ensure that all memory allocations in this context are done as if
+        * GFP_NOIO was specified.
         */
-       if (!queue_is_mq(q)) {
-               q->nr_zones = nr_zones;
-               return 0;
-       }
-
-       if (nr_zones)
-               ret = blk_update_zone_info(disk, nr_zones, &args);
+       noio_flag = memalloc_noio_save();
+       ret = disk->fops->report_zones(disk, 0, UINT_MAX,
+                                      blk_revalidate_zone_cb, &args);
+       memalloc_noio_restore(noio_flag);
 
        /*
-        * Install the new bitmaps, making sure the queue is stopped and
-        * all I/Os are completed (i.e. a scheduler is not referencing the
-        * bitmaps).
+        * Install the new bitmaps and update nr_zones only once the queue is
+        * stopped and all I/Os are completed (i.e. a scheduler is not
+        * referencing the bitmaps).
         */
        blk_mq_freeze_queue(q);
        if (ret >= 0) {
-               q->nr_zones = nr_zones;
+               blk_queue_chunk_sectors(q, args.zone_sectors);
+               q->nr_zones = args.nr_zones;
                swap(q->seq_zones_wlock, args.seq_zones_wlock);
-               swap(q->seq_zones_bitmap, args.seq_zones_bitmap);
+               swap(q->conv_zones_bitmap, args.conv_zones_bitmap);
                ret = 0;
        } else {
                pr_warn("%s: failed to revalidate zones\n", disk->disk_name);
@@ -474,7 +474,7 @@ int blk_revalidate_disk_zones(struct gendisk *disk)
        blk_mq_unfreeze_queue(q);
 
        kfree(args.seq_zones_wlock);
-       kfree(args.seq_zones_bitmap);
+       kfree(args.conv_zones_bitmap);
        return ret;
 }
 EXPORT_SYMBOL_GPL(blk_revalidate_disk_zones);