aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Hajnoczi <stefanha@redhat.com>2018-01-03 11:03:39 -0500
committerMichael S. Tsirkin <mst@redhat.com>2018-02-01 09:26:43 -0500
commitdaf2a5016983a1a533417bcdc729bd2b19af1b68 (patch)
treea20bf8cde132c8f256ad3b03b35f9d0cd8162cc6
parent7b95fec6d2ffa53f4a8d637b0f223644d458ea4e (diff)
virtio_blk: print capacity at probe time
Print the capacity of the block device when the driver is probed. Many users expect this since SCSI disks (sd) do it. Moreover, kernel dmesg output is the primary source of troubleshooting information so it's helpful to include the disk size there. The capacity is already printed by virtio_blk when a resize event occurs. Extract the code and reuse it from virtblk_probe(). This patch also adds the block device name to the message so it can be correlated with a specific device: virtio_blk virtio0: [vda] 20971520 512-byte logical blocks (10.7 GB/10.0 GiB) Cc: Rodrigo A B Freire <rfreire@redhat.com> Cc: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
-rw-r--r--drivers/block/virtio_blk.c32
1 files changed, 15 insertions, 17 deletions
diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c
index 68846897d213..787cd2a10b0b 100644
--- a/drivers/block/virtio_blk.c
+++ b/drivers/block/virtio_blk.c
@@ -373,14 +373,12 @@ static ssize_t virtblk_serial_show(struct device *dev,
373 373
374static DEVICE_ATTR(serial, S_IRUGO, virtblk_serial_show, NULL); 374static DEVICE_ATTR(serial, S_IRUGO, virtblk_serial_show, NULL);
375 375
376static void virtblk_config_changed_work(struct work_struct *work) 376/* The queue's logical block size must be set before calling this */
377static void virtblk_update_capacity(struct virtio_blk *vblk, bool resize)
377{ 378{
378 struct virtio_blk *vblk =
379 container_of(work, struct virtio_blk, config_work);
380 struct virtio_device *vdev = vblk->vdev; 379 struct virtio_device *vdev = vblk->vdev;
381 struct request_queue *q = vblk->disk->queue; 380 struct request_queue *q = vblk->disk->queue;
382 char cap_str_2[10], cap_str_10[10]; 381 char cap_str_2[10], cap_str_10[10];
383 char *envp[] = { "RESIZE=1", NULL };
384 unsigned long long nblocks; 382 unsigned long long nblocks;
385 u64 capacity; 383 u64 capacity;
386 384
@@ -402,13 +400,24 @@ static void virtblk_config_changed_work(struct work_struct *work)
402 STRING_UNITS_10, cap_str_10, sizeof(cap_str_10)); 400 STRING_UNITS_10, cap_str_10, sizeof(cap_str_10));
403 401
404 dev_notice(&vdev->dev, 402 dev_notice(&vdev->dev,
405 "new size: %llu %d-byte logical blocks (%s/%s)\n", 403 "[%s] %s%llu %d-byte logical blocks (%s/%s)\n",
404 vblk->disk->disk_name,
405 resize ? "new size: " : "",
406 nblocks, 406 nblocks,
407 queue_logical_block_size(q), 407 queue_logical_block_size(q),
408 cap_str_10, 408 cap_str_10,
409 cap_str_2); 409 cap_str_2);
410 410
411 set_capacity(vblk->disk, capacity); 411 set_capacity(vblk->disk, capacity);
412}
413
414static void virtblk_config_changed_work(struct work_struct *work)
415{
416 struct virtio_blk *vblk =
417 container_of(work, struct virtio_blk, config_work);
418 char *envp[] = { "RESIZE=1", NULL };
419
420 virtblk_update_capacity(vblk, true);
412 revalidate_disk(vblk->disk); 421 revalidate_disk(vblk->disk);
413 kobject_uevent_env(&disk_to_dev(vblk->disk)->kobj, KOBJ_CHANGE, envp); 422 kobject_uevent_env(&disk_to_dev(vblk->disk)->kobj, KOBJ_CHANGE, envp);
414} 423}
@@ -621,7 +630,6 @@ static int virtblk_probe(struct virtio_device *vdev)
621 struct request_queue *q; 630 struct request_queue *q;
622 int err, index; 631 int err, index;
623 632
624 u64 cap;
625 u32 v, blk_size, sg_elems, opt_io_size; 633 u32 v, blk_size, sg_elems, opt_io_size;
626 u16 min_io_size; 634 u16 min_io_size;
627 u8 physical_block_exp, alignment_offset; 635 u8 physical_block_exp, alignment_offset;
@@ -719,17 +727,6 @@ static int virtblk_probe(struct virtio_device *vdev)
719 if (virtio_has_feature(vdev, VIRTIO_BLK_F_RO)) 727 if (virtio_has_feature(vdev, VIRTIO_BLK_F_RO))
720 set_disk_ro(vblk->disk, 1); 728 set_disk_ro(vblk->disk, 1);
721 729
722 /* Host must always specify the capacity. */
723 virtio_cread(vdev, struct virtio_blk_config, capacity, &cap);
724
725 /* If capacity is too big, truncate with warning. */
726 if ((sector_t)cap != cap) {
727 dev_warn(&vdev->dev, "Capacity %llu too large: truncating\n",
728 (unsigned long long)cap);
729 cap = (sector_t)-1;
730 }
731 set_capacity(vblk->disk, cap);
732
733 /* We can handle whatever the host told us to handle. */ 730 /* We can handle whatever the host told us to handle. */
734 blk_queue_max_segments(q, vblk->sg_elems-2); 731 blk_queue_max_segments(q, vblk->sg_elems-2);
735 732
@@ -780,6 +777,7 @@ static int virtblk_probe(struct virtio_device *vdev)
780 if (!err && opt_io_size) 777 if (!err && opt_io_size)
781 blk_queue_io_opt(q, blk_size * opt_io_size); 778 blk_queue_io_opt(q, blk_size * opt_io_size);
782 779
780 virtblk_update_capacity(vblk, false);
783 virtio_device_ready(vdev); 781 virtio_device_ready(vdev);
784 782
785 device_add_disk(&vdev->dev, vblk->disk); 783 device_add_disk(&vdev->dev, vblk->disk);