Jan Beulich
2012-Mar-23 15:56 UTC
[PATCH] linux-2.6.18/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@suse.com> --- a/drivers/xen/blkback/interface.c +++ b/drivers/xen/blkback/interface.c @@ -70,29 +70,22 @@ int blkif_map(blkif_t *blkif, grant_ref_ 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( --- a/drivers/xen/blkback/xenbus.c +++ b/drivers/xen/blkback/xenbus.c @@ -494,17 +494,14 @@ static int connect_ring(struct backend_i } 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; --- a/drivers/xen/blktap/interface.c +++ b/drivers/xen/blktap/interface.c @@ -71,29 +71,22 @@ int tap_blkif_map(blkif_t *blkif, struct 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( --- a/drivers/xen/blktap/xenbus.c +++ b/drivers/xen/blktap/xenbus.c @@ -447,17 +447,14 @@ static int connect_ring(struct backend_i } 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; --- a/include/xen/blkif.h +++ b/include/xen/blkif.h @@ -72,6 +72,7 @@ typedef struct blkif_x86_64_request blki 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-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel