From patchwork Thu Jun 9 16:43:22 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Olaf Hering X-Patchwork-Id: 9167435 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 9C44760467 for ; Thu, 9 Jun 2016 16:45:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8DEB528338 for ; Thu, 9 Jun 2016 16:45:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 82B8B28356; Thu, 9 Jun 2016 16:45:52 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 7036F28338 for ; Thu, 9 Jun 2016 16:45:51 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bB33f-0007yR-1M; Thu, 09 Jun 2016 16:43:51 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bB33e-0007yD-6R for xen-devel@lists.xenproject.org; Thu, 09 Jun 2016 16:43:50 +0000 Received: from [85.158.137.68] by server-9.bemta-3.messagelabs.com id 1F/E0-25578-5CC99575; Thu, 09 Jun 2016 16:43:49 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrKLMWRWlGSWpSXmKPExsUSuHLSHd0jcyL DDRoOa1h83zKZyYHR4/CHKywBjFGsmXlJ+RUJrBnPfx5lL9gqU3Hws2ED43aJLkYuDhaBx0wS v469ZO5i5OSQEPCUeHyoD8jmALJFJJ78TwOpERJYyyjxbut3VpAaNgElib0HjzOCJEQEXjFKN G14DpZgFkiUOPB0NhuILSzgKHF0zx52EJtFQFWi9ch2sAW8AsYSrx4cY4NYJicxefElxgmM3A sYGVYxqhenFpWlFuka6yUVZaZnlOQmZuboGhoY6+WmFhcnpqfmJCYV6yXn525iBHqXAQh2MDZ /cTrEKMnBpCTKK9gTGS7El5SfUpmRWJwRX1Sak1p8iFGGg0NJgvfAbKCcYFFqempFWmYOMMxg 0hIcPEoivBrAUBPiLS5IzC3OTIdInWJUlBLn3Q/SJwCSyCjNg2uDhfYlRlkpYV5GoEOEeApSi 3IzS1DlXzGKczAqCfN6gEzhycwrgZsODDSgm0V4lx8JB1lckoiQkmpgnCu274uH1RNdrY/dF6 o6ivc9X7Qjnyljkfzxl/uObFqlpLC0w3smY0necZMdO3UOJe3McQk5Gr1sGv8Omx+HTc6ZTp7 w080/8Mi39FeNG0wns9of9l8k4KQz/ce6MpvWK8o8zb/3PD2yNrZN3F3xwaees4w7LGo/Ve0/ ZhhjXH3IdN6LPxfjZyixFGckGmoxFxUnAgDVDnFtaAIAAA== X-Env-Sender: olaf@aepfle.de X-Msg-Ref: server-14.tower-31.messagelabs.com!1465490628!44643429!1 X-Originating-IP: [81.169.146.220] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 8.46; banners=-,-,- X-VirusChecked: Checked Received: (qmail 43773 invoked from network); 9 Jun 2016 16:43:48 -0000 Received: from mo4-p00-ob.smtp.rzone.de (HELO mo4-p00-ob.smtp.rzone.de) (81.169.146.220) by server-14.tower-31.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 9 Jun 2016 16:43:48 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1465490628; l=3694; s=domk; d=aepfle.de; h=Date:Subject:Cc:To:From; bh=mdvj5u4tMB+XjYJgfIbpy4mzjn0ia6qEg0fVYN/DviE=; b=IH0G+yhnTwJtAFeRXwRWaRCuKwIBm7r5XW65PePU/ySsriD668CXbMKXA/kfzpYJ9RU oEAVOK3PyQFWXe7Vwz8o8l89DchsCPfqf4rlTSYxuFkgEkIvS/CU7UDcC8DQA2nx4LYsM XSSSteapcNip2Xy5eGPCEwU2Ihr2/Svsllg= X-RZG-AUTH: :P2EQZWCpfu+qG7CngxMFH1J+yackYocTD1iAi8x+OWtrWFmrD4pjkQ2b4qvS X-RZG-CLASS-ID: mo00 Received: from aepfle.de (charybdis-ext.suse.de [195.135.221.2]) by post.strato.de (RZmta 38.2 AUTH) with ESMTPA id 503c85s59GhjKNa; Thu, 9 Jun 2016 18:43:45 +0200 (CEST) From: Olaf Hering To: Konrad Rzeszutek Wilk , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Boris Ostrovsky , David Vrabel , Juergen Gross Date: Thu, 9 Jun 2016 18:43:22 +0200 Message-Id: <20160609164322.11552-1-olaf@aepfle.de> X-Mailer: git-send-email 2.8.3 Cc: xen-devel@lists.xenproject.org, Olaf Hering , Jeff Mahoney Subject: [Xen-devel] [PATCH] xen-blkfront: export backend vdev name via sysfs X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Jeff Mahoney This patch creates a sysfs group to export blkfront attribute via sysfs. For now, we just export the backend device name. This helps with migrating existing domU installation from a xenlinux based kernel to a pvops based kernel. The old blkfront driver did respect the vdev=hd|sd|xvd setting in domU.cfg, while the pvops blkfront driver enforce xvd as kernel device name. If for some reason the domU uses kernel devices names in configuration files like fstab, menu.lst, grub.cfg etc. the system may not startup properly after upgrading from a dist version with xenlinux based kernel to a newer one with pvops based kernel. With the new sysfs attribute /sys/block/*/blkfront/backend_dev udev can create a symlink /dev/hda to /dev/xvda using rules as shown below. The value of "vdev" is cached to avoid the load caused by constant rereading from the sysfs file. This might be added to systemd/rules/60-persistent-storage.rules: KERNEL=="xvd*[!0-9]", ATTRS{blkfront/backend_dev}=="hd[a-d]", SYMLINK+="$attr{blkfront/backend_dev}" KERNEL=="xvd*[0-9]", ATTRS{blkfront/backend_dev}=="hd[a-d]", SYMLINK+="$attr{blkfront/backend_dev}%n" Signed-off-by: Jeff Mahoney Signed-off-by: Olaf Hering --- drivers/block/xen-blkfront.c | 61 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/drivers/block/xen-blkfront.c b/drivers/block/xen-blkfront.c index 6405b65..3c12644 100644 --- a/drivers/block/xen-blkfront.c +++ b/drivers/block/xen-blkfront.c @@ -1066,6 +1066,66 @@ static int xen_translate_vdev(int vdevice, int *minor, unsigned int *offset) return 0; } +/* xlvbd sysfs attributes */ +static ssize_t xlvbd_attr_show(struct device *dev, char *page, + ssize_t (*callback)(struct blkfront_info *, char *)) +{ + struct gendisk *disk = dev_to_disk(dev); + struct blkfront_info *lo = disk->private_data; + + return callback(lo, page); +} + +#define XLVBD_ATTR_RO(_name) \ +static ssize_t xlvbd_attr_##_name##_show(struct blkfront_info *, char *);\ +static ssize_t xlvbd_attr_do_show_##_name(struct device *d, \ + struct device_attribute *attr, char *b) \ +{ \ + return xlvbd_attr_show(d, b, xlvbd_attr_##_name##_show); \ +} \ +static struct device_attribute xlvbd_attr_##_name = \ + __ATTR(_name, S_IRUGO, xlvbd_attr_do_show_##_name, NULL); + + +static ssize_t xlvbd_attr_backend_dev_show(struct blkfront_info *info, + char *buf) +{ + const char *nodename = info->xbdev->nodename; + const char *backend; + const char *dev; + + backend = xenbus_read(XBT_NIL, nodename, "backend", NULL); + if (IS_ERR(backend)) + return PTR_ERR(backend); + + dev = xenbus_read(XBT_NIL, backend, "dev", NULL); + kfree(backend); + if (IS_ERR(dev)) + return PTR_ERR(dev); + + ret = snprintf(buf, PAGE_SIZE, "%s\n", dev); + + kfree(dev); + return ret; +} + +XLVBD_ATTR_RO(backend_dev); + +static struct attribute *xlvbd_attrs[] = { + &xlvbd_attr_backend_dev.attr, + NULL, +}; + +static const struct attribute_group xlvbd_attribute_group = { + .name = "blkfront", + .attrs = xlvbd_attrs, +}; + +static const struct attribute_group *xlvbd_attribute_groups[] = { + &xlvbd_attribute_group, + NULL, +}; + static char *encode_disk_name(char *ptr, unsigned int n) { if (n >= 26) @@ -1143,6 +1203,7 @@ static int xlvbd_alloc_gendisk(blkif_sector_t capacity, gd->private_data = info; gd->driverfs_dev = &(info->xbdev->dev); set_capacity(gd, capacity); + disk_to_dev(gd)->groups = xlvbd_attribute_groups; if (xlvbd_init_blk_queue(gd, sector_size, physical_sector_size, info->max_indirect_segments ? :