[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-changelog] [linux-2.6.18-xen] block backends: simplify protocol negotiation and initialization
# HG changeset patch # User Jan Beulich <jbeulich@xxxxxxxx> # Date 1332754718 -7200 # Node ID 8940ccd0a425346845bd102c4bc049eb58b550b6 # Parent 2748f5d7597de35e59318f4bad8ed762e8ce32aa block backends: simplify protocol negotiation and initialization In the negotiation code we can use the simpler (and type safe) xenbus_read() instead of xenbus_gather() for reading the "protocol" node. The initialization code can be considerably shrunk by using a macro to abstract out the code common for all variants. Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx> --- diff -r 2748f5d7597d -r 8940ccd0a425 drivers/xen/blkback/interface.c --- a/drivers/xen/blkback/interface.c Mon Mar 26 11:37:49 2012 +0200 +++ b/drivers/xen/blkback/interface.c Mon Mar 26 11:38:38 2012 +0200 @@ -70,29 +70,22 @@ blkif->blk_ring_area = area; switch (blkif->blk_protocol) { +#define BLKBK_RING_INIT(p) ({ \ + struct blkif_##p##_sring *sring = area->addr; \ + BACK_RING_INIT(&blkif->blk_rings.p, sring, PAGE_SIZE); \ + }) case BLKIF_PROTOCOL_NATIVE: - { - blkif_sring_t *sring; - sring = (blkif_sring_t *)area->addr; - BACK_RING_INIT(&blkif->blk_rings.native, sring, PAGE_SIZE); + BLKBK_RING_INIT(native); break; - } case BLKIF_PROTOCOL_X86_32: - { - blkif_x86_32_sring_t *sring_x86_32; - sring_x86_32 = (blkif_x86_32_sring_t *)area->addr; - BACK_RING_INIT(&blkif->blk_rings.x86_32, sring_x86_32, PAGE_SIZE); + BLKBK_RING_INIT(x86_32); break; - } case BLKIF_PROTOCOL_X86_64: - { - blkif_x86_64_sring_t *sring_x86_64; - sring_x86_64 = (blkif_x86_64_sring_t *)area->addr; - BACK_RING_INIT(&blkif->blk_rings.x86_64, sring_x86_64, PAGE_SIZE); + BLKBK_RING_INIT(x86_64); break; - } default: BUG(); +#undef BLKBK_RING_INIT } err = bind_interdomain_evtchn_to_irqhandler( diff -r 2748f5d7597d -r 8940ccd0a425 drivers/xen/blkback/xenbus.c --- a/drivers/xen/blkback/xenbus.c Mon Mar 26 11:37:49 2012 +0200 +++ b/drivers/xen/blkback/xenbus.c Mon Mar 26 11:38:38 2012 +0200 @@ -494,17 +494,14 @@ } be->blkif->blk_protocol = BLKIF_PROTOCOL_NATIVE; - err = xenbus_gather(XBT_NIL, dev->otherend, "protocol", - NULL, &protocol, NULL); - if (err) + protocol = xenbus_read(XBT_NIL, dev->otherend, "protocol", NULL); + if (IS_ERR(protocol)) protocol = NULL; - else if (0 == strcmp(protocol, XEN_IO_PROTO_ABI_NATIVE)) - be->blkif->blk_protocol = BLKIF_PROTOCOL_NATIVE; else if (0 == strcmp(protocol, XEN_IO_PROTO_ABI_X86_32)) be->blkif->blk_protocol = BLKIF_PROTOCOL_X86_32; else if (0 == strcmp(protocol, XEN_IO_PROTO_ABI_X86_64)) be->blkif->blk_protocol = BLKIF_PROTOCOL_X86_64; - else { + else if (0 != strcmp(protocol, XEN_IO_PROTO_ABI_NATIVE)) { xenbus_dev_fatal(dev, err, "unknown fe protocol %s", protocol); kfree(protocol); return -1; diff -r 2748f5d7597d -r 8940ccd0a425 drivers/xen/blktap/interface.c --- a/drivers/xen/blktap/interface.c Mon Mar 26 11:37:49 2012 +0200 +++ b/drivers/xen/blktap/interface.c Mon Mar 26 11:38:38 2012 +0200 @@ -71,29 +71,22 @@ blkif->blk_ring_area = area; switch (blkif->blk_protocol) { +#define BLKTAP_RING_INIT(p) ({ \ + struct blkif_##p##_sring *sring = area->addr; \ + BACK_RING_INIT(&blkif->blk_rings.p, sring, PAGE_SIZE); \ + }) case BLKIF_PROTOCOL_NATIVE: - { - blkif_sring_t *sring; - sring = (blkif_sring_t *)area->addr; - BACK_RING_INIT(&blkif->blk_rings.native, sring, PAGE_SIZE); + BLKTAP_RING_INIT(native); break; - } case BLKIF_PROTOCOL_X86_32: - { - blkif_x86_32_sring_t *sring_x86_32; - sring_x86_32 = (blkif_x86_32_sring_t *)area->addr; - BACK_RING_INIT(&blkif->blk_rings.x86_32, sring_x86_32, PAGE_SIZE); + BLKTAP_RING_INIT(x86_32); break; - } case BLKIF_PROTOCOL_X86_64: - { - blkif_x86_64_sring_t *sring_x86_64; - sring_x86_64 = (blkif_x86_64_sring_t *)area->addr; - BACK_RING_INIT(&blkif->blk_rings.x86_64, sring_x86_64, PAGE_SIZE); + BLKTAP_RING_INIT(x86_64); break; - } default: BUG(); +#undef BLKTAP_RING_INIT } err = bind_interdomain_evtchn_to_irqhandler( diff -r 2748f5d7597d -r 8940ccd0a425 drivers/xen/blktap/xenbus.c --- a/drivers/xen/blktap/xenbus.c Mon Mar 26 11:37:49 2012 +0200 +++ b/drivers/xen/blktap/xenbus.c Mon Mar 26 11:38:38 2012 +0200 @@ -447,17 +447,14 @@ } be->blkif->blk_protocol = BLKIF_PROTOCOL_NATIVE; - err = xenbus_gather(XBT_NIL, dev->otherend, "protocol", - NULL, &protocol, NULL); - if (err) + protocol = xenbus_read(XBT_NIL, dev->otherend, "protocol", NULL); + if (IS_ERR(protocol)) protocol = NULL; - else if (0 == strcmp(protocol, XEN_IO_PROTO_ABI_NATIVE)) - be->blkif->blk_protocol = BLKIF_PROTOCOL_NATIVE; else if (0 == strcmp(protocol, XEN_IO_PROTO_ABI_X86_32)) be->blkif->blk_protocol = BLKIF_PROTOCOL_X86_32; else if (0 == strcmp(protocol, XEN_IO_PROTO_ABI_X86_64)) be->blkif->blk_protocol = BLKIF_PROTOCOL_X86_64; - else { + else if (0 != strcmp(protocol, XEN_IO_PROTO_ABI_NATIVE)) { xenbus_dev_fatal(dev, err, "unknown fe protocol %s", protocol); kfree(protocol); return -1; diff -r 2748f5d7597d -r 8940ccd0a425 include/xen/blkif.h --- a/include/xen/blkif.h Mon Mar 26 11:37:49 2012 +0200 +++ b/include/xen/blkif.h Mon Mar 26 11:38:38 2012 +0200 @@ -72,6 +72,7 @@ typedef struct blkif_x86_64_request blkif_x86_64_request_t; typedef struct blkif_x86_64_response blkif_x86_64_response_t; +#define blkif_native_sring blkif_sring DEFINE_RING_TYPES(blkif_common, struct blkif_common_request, struct blkif_common_response); DEFINE_RING_TYPES(blkif_x86_32, struct blkif_x86_32_request, struct blkif_x86_32_response); DEFINE_RING_TYPES(blkif_x86_64, struct blkif_x86_64_request, struct blkif_x86_64_response); _______________________________________________ Xen-changelog mailing list Xen-changelog@xxxxxxxxxxxxx http://lists.xensource.com/xen-changelog
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |