From: Ankur Arora Date: Thu, 30 Aug 2018 02:27:34 +0000 (-0700) Subject: xen-blkback: emit active physical device to xenstore X-Git-Tag: v4.1.12-124.31.3~510 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=f75e99776d19aa7e018c734555f6ea897cd5bd96;p=users%2Fjedix%2Flinux-maple.git xen-blkback: emit active physical device to xenstore The vbd physical-device is set by user-space writing to device's xenbus path: /local/domain/0/backend/vbd/1/51712/physical-device = ":" However, there is no way for the blkback driver to specify the current state of the physical-device. Accordingly we add two new backend paths: .../vbd//51712/oracle/active-physical-device = ":" .../vbd//51712/oracle/physical-device-change-status = "" which specify the active physical device and any error incurred in trying to instantiate a new physical device. Orabug: 28651655 Signed-off-by: Ankur Arora Reviewed-by: Darren Kenny Reviewed-by: Bhavesh Davda Reviewed-by: Boris Ostrovsky Signed-off-by: Brian Maly --- diff --git a/drivers/block/xen-blkback/xenbus.c b/drivers/block/xen-blkback/xenbus.c index 34f0f9f4ff5b..61de4777e272 100644 --- a/drivers/block/xen-blkback/xenbus.c +++ b/drivers/block/xen-blkback/xenbus.c @@ -591,6 +591,35 @@ int xen_blkbk_barrier(struct xenbus_transaction xbt, return err; } +static int xen_emit_oracle_phys_device(struct xenbus_device *dev, + u32 major, u32 minor, int status) +{ + struct xenbus_transaction xbt; + int err; + + err = xenbus_transaction_start(&xbt); + if (err) + return err; + + err = xenbus_printf(xbt, dev->nodename, "oracle/active-physical-device", + "%x:%x", major, minor); + if (err) + goto abort; + + err = xenbus_printf(xbt, dev->nodename, + "oracle/physical-device-change-status", + "%d", status); + if (err) + goto abort; + xenbus_transaction_end(xbt, 0); + + return 0; + +abort: + xenbus_transaction_end(xbt, 1); + return err; +} + /* * Entry point to this code when a new device is created. Allocate the basic * structures, and watch the store waiting for the hotplug scripts to tell us @@ -639,6 +668,11 @@ static int xen_blkbk_probe(struct xenbus_device *dev, /* setup back pointer */ be->blkif->be = be; + err = xen_emit_oracle_phys_device(dev, 0, 0, 0); + + if (err) + pr_warn("Failed writing oracle/active-physical-device\n"); + err = xenbus_watch_pathfmt(dev, &be->backend_watch, backend_changed, "%s/%s", dev->nodename, "physical-device"); if (err) @@ -765,7 +799,20 @@ sysfs_out: if (err) memset(&be->params, 0, sizeof(be->params)); out: - return; + /* + * err = 0: emit new vbd, err = 0 to the xenbus + * err != 0: emit unchanged vbd, err to the xenbus + */ + err = xen_emit_oracle_phys_device(dev, be->params.major, + be->params.minor, err); + if (err) { + /* + * Fatal failure because user-space might be waiting + * on this xenbus entry. + */ + xenbus_dev_fatal(dev, err, + "Failed in writing oracle/active-physical-device"); + } } /* diff --git a/include/xen/interface/io/blkif.h b/include/xen/interface/io/blkif.h index 8b8cfadf7833..c2139acb3924 100644 --- a/include/xen/interface/io/blkif.h +++ b/include/xen/interface/io/blkif.h @@ -75,6 +75,33 @@ typedef uint64_t blkif_sector_t; * */ +/* + * Vendor Extensions + * ================= + * + * Volume Swapping: + * + * blkback plugs in the backing volume based on changes to the "physical-device" + * xenstore key. + * + * Once the backing volume is plugged in, blkback writes to the + * "oracle/active-physical-device" with the now active volume, and + * "oracle/physical-device-status" with the error code. The error + * code follows backend OS convention. On Linux, defined in + * /usr/include/asm/errno*h. + * + * For instance, the toolstack plugging in a guest disk would write: + * + * /local/domain/0/backend/vbd//51712/physical-device = "1a:2" + * + * And backend would validate and plug in the new physical device and its + * status (e.g. in case of errors): + * + * /local/domain/0/backend/vbd//51712/oracle/active-physical-device = "1a:2" + * /local/domain/0/backend/vbd//51712/oracle/physical-device-status = "0" + * + */ + /* * REQUEST CODES. */