From patchwork Thu Jun 24 03:19:57 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ryan Harper X-Patchwork-Id: 107750 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.4/8.14.3) with ESMTP id o5O3KuCW019232 for ; Thu, 24 Jun 2010 03:20:56 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753495Ab0FXDUI (ORCPT ); Wed, 23 Jun 2010 23:20:08 -0400 Received: from e4.ny.us.ibm.com ([32.97.182.144]:36698 "EHLO e4.ny.us.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753831Ab0FXDUG (ORCPT ); Wed, 23 Jun 2010 23:20:06 -0400 Received: from d01relay06.pok.ibm.com (d01relay06.pok.ibm.com [9.56.227.116]) by e4.ny.us.ibm.com (8.14.4/8.13.1) with ESMTP id o5O36acF024054 for ; Wed, 23 Jun 2010 23:06:36 -0400 Received: from d01av02.pok.ibm.com (d01av02.pok.ibm.com [9.56.224.216]) by d01relay06.pok.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id o5O3K4Gu1658920 for ; Wed, 23 Jun 2010 23:20:04 -0400 Received: from d01av02.pok.ibm.com (loopback [127.0.0.1]) by d01av02.pok.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id o5O3K2nI002074 for ; Thu, 24 Jun 2010 00:20:04 -0300 Received: from localhost.localdomain (sig-9-65-88-241.mts.ibm.com [9.65.88.241]) by d01av02.pok.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id o5O3K0BI001875; Thu, 24 Jun 2010 00:20:02 -0300 From: Ryan Harper To: virtualization@lists.linux-foundation.org Cc: Rusty Russell , john cooper , kvm@vger.kernel.org, qemu-devel@nongnu.org, Ryan Harper Subject: [PATCH 1/2] v2 Add 'serial' attribute to virtio-blk devices Date: Wed, 23 Jun 2010 22:19:57 -0500 Message-Id: <1277349598-24559-2-git-send-email-ryanh@us.ibm.com> X-Mailer: git-send-email 1.6.3.3 In-Reply-To: <1277349598-24559-1-git-send-email-ryanh@us.ibm.com> References: <1277349598-24559-1-git-send-email-ryanh@us.ibm.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Thu, 24 Jun 2010 03:20:56 +0000 (UTC) diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c index 258bc2a..34411ff 100644 --- a/drivers/block/virtio_blk.c +++ b/drivers/block/virtio_blk.c @@ -281,6 +281,27 @@ static int index_to_minor(int index) return index << PART_BITS; } +static ssize_t virtblk_serial_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct gendisk *disk = dev_to_disk(dev); + int err; + + /* sysfs gives us a PAGE_SIZE buffer */ + BUILD_BUG_ON(PAGE_SIZE < VIRTIO_BLK_ID_BYTES); + + buf[VIRTIO_BLK_ID_BYTES] = '\0'; + err = virtblk_get_id(disk, buf); + if (!err) + return strlen(buf); + + if (err == -EIO) /* Unsupported? Make it empty. */ + return 0; + + return err; +} +DEVICE_ATTR(serial, S_IRUGO, virtblk_serial_show, NULL); + static int __devinit virtblk_probe(struct virtio_device *vdev) { struct virtio_blk *vblk; @@ -445,8 +466,15 @@ static int __devinit virtblk_probe(struct virtio_device *vdev) add_disk(vblk->disk); + err = device_create_file(disk_to_dev(vblk->disk), &dev_attr_serial); + if (err) + goto out_del_disk; + return 0; +out_del_disk: + del_gendisk(vblk->disk); + blk_cleanup_queue(vblk->disk->queue); out_put_disk: put_disk(vblk->disk); out_mempool: