Received: by 10.223.176.46 with SMTP id f43csp1239529wra; Fri, 19 Jan 2018 08:44:59 -0800 (PST) X-Google-Smtp-Source: ACJfBosN8QXgh/vVx6VgVslaN4SvgzC0S2qgR4oEk3M7RA/k4yvdipN8jCOWEgR2AWIs3pgdbsN7 X-Received: by 10.98.198.139 with SMTP id x11mr7100976pfk.127.1516380299535; Fri, 19 Jan 2018 08:44:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516380299; cv=none; d=google.com; s=arc-20160816; b=UpxZhgDyazm8lAMCijhV4JFz6KQcu3e6MrJ65t6pRNqCDqk8qOYLlY7YpiNLK2f/BD GeDDMHsnNfznmoR29XLo8KMVkSb0gLKYhm7dYyonwkHc9T3msTnafR72iIMaRL5NKPgB AP7VX3OWn1GY8OC0rqFKYDLgF4mVAf/jMwZqzZu99sW7oKMxn39ExBKaObSo6ZaK1AUS smZFQkJpJCwoCcyL8zNZ4T2lYDJmANZoau4iL7q6pyVrTgL6UOVdptbXfY7IcZJDMPVa qSFmoEthjzU2R+hMrnR7jVFV2yv6fKcOTaHYhYCOvS22d8BLE2jEe0c1BBKSd5uj2PRn bOgA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=8MqZqwLV3v3cUhML3ohkwWCtiS2mJxjVgIRvoMwCuv0=; b=GVb5IJmRoKWsn/BZATeHj9x6JTeLSXxGdcsQJyVgthwDmkYvo8tnFPsNoCSh1ld640 /zPE2f01kXjF/0b3wsbT54LJL1xXDKsO+qjoofAB7tKEBUtWb6lt1+/RTN+2rTW6EOrp vY03ps2k7HlltgLDDeYEbRB63auPzdxWOCiy+F3seCTVjwFj0n6X7gdhOxDEQ3XOfUoC iTgtKsMjBqZx7g0GFWEjXJLh98VaFZYro3t/+wVQ5LVKzOjXtdzf5Js6KqWDDobm3fLY URceS3ccjTk4GORjEBIwWJ3vktgHmwZlu7+RcLfmsC8Uep/6aAD88ak06KVJoNWLf8kF YIvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ap1Mbc5J; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 33-v6si950083plu.508.2018.01.19.08.44.44; Fri, 19 Jan 2018 08:44:59 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ap1Mbc5J; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756220AbeASQoO (ORCPT + 99 others); Fri, 19 Jan 2018 11:44:14 -0500 Received: from mail-wr0-f193.google.com ([209.85.128.193]:34839 "EHLO mail-wr0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755772AbeASQoH (ORCPT ); Fri, 19 Jan 2018 11:44:07 -0500 Received: by mail-wr0-f193.google.com with SMTP id g38so2120096wrd.2 for ; Fri, 19 Jan 2018 08:44:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=8MqZqwLV3v3cUhML3ohkwWCtiS2mJxjVgIRvoMwCuv0=; b=ap1Mbc5JAo1nI3k27+0uMRs+SKrYctF5I8NKI8cpbgl3ESzEzvxXCUVCW8/CEHutep D66ZIPBZi6qZsX+q8mxQe5eqR+6qBg0iXQp1VuU4dsvGjKsfWZpVoxyAAw6C/tryN/5F XU0MUkdPaKWbWeyCf824NPMOAenXnvP4UJ+u/K4k7kjopArApqgWv4Fae12ZpJ5wfUfx AsF47HStWQBt7+ApYdoRJL2/KqXZKht1jikeV6008ecF/zwjkvOlKlwfA6CNPK75D+/e d0jGTkeS8h4OSOnKRHhhn+3ulZU/RsIIcVMNe5Yx8QJJpzNr4vkpCzZ2q6aWPOKy6zCM hvbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=8MqZqwLV3v3cUhML3ohkwWCtiS2mJxjVgIRvoMwCuv0=; b=bXNkQCkQaqQU0OE2RC7T7n/EQBeePLVm5lKb7IkzeuPNAV3olwc/7jLMDNeO17VU+C hBSFzOcqQks08EwQRvscaKntpzQUTG86NRKFeMzHg3gQyivCMdX+FvHmQ54KZBE9xM7d WJqWhb7DZkSohSU7xTYshg65p7ajStQvX5cTBIwxb45n7cgp8136L5HTFCw5GvCFLQfI bK4nNN475VsoCyji+jB+mzpdz7Z1HXhvSmqlSAmQ/6IMXwi8T7yNawehohHa2vRXPCgp ZCAA/hDOH38GU8yXSSGnFsmJLgZcHe7HHbj0KN3hq0yOY8xMIHlNmIrplYTf4DRBba1k U9rA== X-Gm-Message-State: AKwxytfDxVQ8uwsqVRfyDEf/xqg2ua2BiBiol4pkV+9mV+7MEqFN83BT YVaNCVAFYMujNzD5RCGrhhQFGnYjCbdWu+jSfwY= X-Received: by 10.223.172.14 with SMTP id v14mr10479972wrc.249.1516380246164; Fri, 19 Jan 2018 08:44:06 -0800 (PST) MIME-Version: 1.0 Received: by 10.223.183.39 with HTTP; Fri, 19 Jan 2018 08:44:05 -0800 (PST) In-Reply-To: <20180103160339.21300-1-stefanha@redhat.com> References: <20180103160339.21300-1-stefanha@redhat.com> From: Stefan Hajnoczi Date: Fri, 19 Jan 2018 16:44:05 +0000 Message-ID: Subject: Re: [PATCH] virtio_blk: print capacity at probe time To: "Michael S. Tsirkin" Cc: Linux Virtualization , Rodrigo A B Freire , linux-kernel , Stefan Hajnoczi Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jan 3, 2018 at 4:03 PM, Stefan Hajnoczi wrote: > 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 > Cc: Michael S. Tsirkin > Signed-off-by: Stefan Hajnoczi > --- > drivers/block/virtio_blk.c | 32 +++++++++++++++----------------- > 1 file changed, 15 insertions(+), 17 deletions(-) Ping? > 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, > > static DEVICE_ATTR(serial, S_IRUGO, virtblk_serial_show, NULL); > > -static void virtblk_config_changed_work(struct work_struct *work) > +/* The queue's logical block size must be set before calling this */ > +static void virtblk_update_capacity(struct virtio_blk *vblk, bool resize) > { > - struct virtio_blk *vblk = > - container_of(work, struct virtio_blk, config_work); > struct virtio_device *vdev = vblk->vdev; > struct request_queue *q = vblk->disk->queue; > char cap_str_2[10], cap_str_10[10]; > - char *envp[] = { "RESIZE=1", NULL }; > unsigned long long nblocks; > u64 capacity; > > @@ -402,13 +400,24 @@ static void virtblk_config_changed_work(struct work_struct *work) > STRING_UNITS_10, cap_str_10, sizeof(cap_str_10)); > > dev_notice(&vdev->dev, > - "new size: %llu %d-byte logical blocks (%s/%s)\n", > + "[%s] %s%llu %d-byte logical blocks (%s/%s)\n", > + vblk->disk->disk_name, > + resize ? "new size: " : "", > nblocks, > queue_logical_block_size(q), > cap_str_10, > cap_str_2); > > set_capacity(vblk->disk, capacity); > +} > + > +static void virtblk_config_changed_work(struct work_struct *work) > +{ > + struct virtio_blk *vblk = > + container_of(work, struct virtio_blk, config_work); > + char *envp[] = { "RESIZE=1", NULL }; > + > + virtblk_update_capacity(vblk, true); > revalidate_disk(vblk->disk); > kobject_uevent_env(&disk_to_dev(vblk->disk)->kobj, KOBJ_CHANGE, envp); > } > @@ -621,7 +630,6 @@ static int virtblk_probe(struct virtio_device *vdev) > struct request_queue *q; > int err, index; > > - u64 cap; > u32 v, blk_size, sg_elems, opt_io_size; > u16 min_io_size; > u8 physical_block_exp, alignment_offset; > @@ -719,17 +727,6 @@ static int virtblk_probe(struct virtio_device *vdev) > if (virtio_has_feature(vdev, VIRTIO_BLK_F_RO)) > set_disk_ro(vblk->disk, 1); > > - /* Host must always specify the capacity. */ > - virtio_cread(vdev, struct virtio_blk_config, capacity, &cap); > - > - /* If capacity is too big, truncate with warning. */ > - if ((sector_t)cap != cap) { > - dev_warn(&vdev->dev, "Capacity %llu too large: truncating\n", > - (unsigned long long)cap); > - cap = (sector_t)-1; > - } > - set_capacity(vblk->disk, cap); > - > /* We can handle whatever the host told us to handle. */ > blk_queue_max_segments(q, vblk->sg_elems-2); > > @@ -780,6 +777,7 @@ static int virtblk_probe(struct virtio_device *vdev) > if (!err && opt_io_size) > blk_queue_io_opt(q, blk_size * opt_io_size); > > + virtblk_update_capacity(vblk, false); > virtio_device_ready(vdev); > > device_add_disk(&vdev->dev, vblk->disk); > -- > 2.14.3 > > _______________________________________________ > Virtualization mailing list > Virtualization@lists.linux-foundation.org > https://lists.linuxfoundation.org/mailman/listinfo/virtualization