[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-changelog] [xen-unstable] [BLKTAP] Formatting and style cleanups to blktapctrl.
# HG changeset patch # User kfraser@xxxxxxxxxxxxxxxxxxxxx # Node ID ff9746d600e9041810a089bc085be3fbc022ad31 # Parent 7efaaae374155b93bceb9a2918fb6c5023978ae7 [BLKTAP] Formatting and style cleanups to blktapctrl. Signed-off-by: Keir Fraser <keir@xxxxxxxxxxxxx> --- tools/blktap/drivers/blktapctrl.c | 5 - tools/blktap/lib/xenbus.c | 186 +++++++++++++++++--------------------- tools/blktap/lib/xs_api.c | 97 +++++++++---------- 3 files changed, 132 insertions(+), 156 deletions(-) diff -r 7efaaae37415 -r ff9746d600e9 tools/blktap/drivers/blktapctrl.c --- a/tools/blktap/drivers/blktapctrl.c Fri Oct 06 11:52:41 2006 +0100 +++ b/tools/blktap/drivers/blktapctrl.c Fri Oct 06 15:04:42 2006 +0100 @@ -684,13 +684,10 @@ int main(int argc, char *argv[]) } ret = setup_probe_watch(h); - if (ret < 0) { + if (ret != 0) { DPRINTF("Failed adding device probewatch\n"); xs_daemon_close(h); goto open_failed; - } else { - DPRINTF("Added probe %s\n", - (ret ? "ASYNCHRONOUSLY":"SYNCHRONOUSLY")); } ioctl(ctlfd, BLKTAP_IOCTL_SETMODE, BLKTAP_MODE_INTERPOSE ); diff -r 7efaaae37415 -r ff9746d600e9 tools/blktap/lib/xenbus.c --- a/tools/blktap/lib/xenbus.c Fri Oct 06 11:52:41 2006 +0100 +++ b/tools/blktap/lib/xenbus.c Fri Oct 06 15:04:42 2006 +0100 @@ -166,60 +166,58 @@ static void ueblktap_setup(struct xs_han goto fail; } - deverr = xs_gather(h, bepath, "physical-device", "%li", &pdev, NULL); - if (!deverr) { - DPRINTF("pdev set to %ld\n",pdev); - if (be->pdev && be->pdev != pdev) { - DPRINTF("changing physical-device not supported"); - goto fail; - } - be->pdev = pdev; - } - - /*Check to see if device is to be opened read-only*/ - asprintf(&path, "%s/%s", bepath, "read-only"); - if (xs_exists(h, path)) - be->readonly = 1; - - if (be->blkif == NULL) { - - /* Front end dir is a number, which is used as the handle. */ - p = strrchr(be->frontpath, '/') + 1; - handle = strtoul(p, NULL, 0); - - be->blkif = alloc_blkif(be->frontend_id); - - if (be->blkif == NULL) - goto fail; + deverr = xs_gather(h, bepath, "physical-device", "%li", &pdev, NULL); + if (!deverr) { + DPRINTF("pdev set to %ld\n",pdev); + if (be->pdev && be->pdev != pdev) { + DPRINTF("changing physical-device not supported"); + goto fail; + } + be->pdev = pdev; + } + + /* Check to see if device is to be opened read-only. */ + asprintf(&path, "%s/%s", bepath, "read-only"); + if (xs_exists(h, path)) + be->readonly = 1; + + if (be->blkif == NULL) { + /* Front end dir is a number, which is used as the handle. */ + p = strrchr(be->frontpath, '/') + 1; + handle = strtoul(p, NULL, 0); + + be->blkif = alloc_blkif(be->frontend_id); + if (be->blkif == NULL) + goto fail; be->blkif->be_id = get_be_id(bepath); - /*Insert device specific info*/ - blk = malloc(sizeof(blkif_info_t)); + /* Insert device specific info, */ + blk = malloc(sizeof(blkif_info_t)); if (!blk) { DPRINTF("Out of memory - blkif_info_t\n"); goto fail; } - er = xs_gather(h, bepath, "params", NULL, &blk->params, NULL); - if (er) - goto fail; - be->blkif->info = blk; + er = xs_gather(h, bepath, "params", NULL, &blk->params, NULL); + if (er) + goto fail; + be->blkif->info = blk; - if (deverr) { - /*Dev number was not available, try to set manually*/ - pdev = convert_dev_name_to_num(blk->params); - be->pdev = pdev; - } - - er = blkif_init(be->blkif, handle, be->pdev, be->readonly); - - if (er != 0) { - DPRINTF("Unable to open device %s\n",blk->params); - goto fail; - } - - DPRINTF("[BECHG]: ADDED A NEW BLKIF (%s)\n", bepath); - } + if (deverr) { + /*Dev number was not available, try to set manually*/ + pdev = convert_dev_name_to_num(blk->params); + be->pdev = pdev; + } + + er = blkif_init(be->blkif, handle, be->pdev, be->readonly); + if (er != 0) { + DPRINTF("Unable to open device %s\n",blk->params); + goto fail; + } + + DPRINTF("[BECHG]: ADDED A NEW BLKIF (%s)\n", bepath); + } + /* Supply the information about the device to xenstore */ er = xs_printf(h, be->backpath, "sectors", "%lu", be->blkif->ops->get_size(be->blkif)); @@ -283,10 +281,10 @@ static void ueblktap_probe(struct xs_han *asserts that xenstore structure is always 7 levels deep *e.g. /local/domain/0/backend/vbd/1/2049 */ - len = strsep_len(bepath, '/', 7); - if (len < 0) - goto free_be; - bepath[len] = '\0'; + len = strsep_len(bepath, '/', 7); + if (len < 0) + goto free_be; + bepath[len] = '\0'; be = malloc(sizeof(*be)); if (!be) { @@ -318,22 +316,21 @@ static void ueblktap_probe(struct xs_han if ( (be != NULL) && (be->blkif != NULL) ) backend_remove(h, be); else goto free_be; - if (bepath) + if (bepath) free(bepath); return; } - /* Are we already tracking this device? */ - if (be_exists_be(bepath)) { + /* Are we already tracking this device? */ + if (be_exists_be(bepath)) goto free_be; - } be->backpath = bepath; - be->frontpath = frontend; - - list_add(&be->list, &belist); - - DPRINTF("[PROBE]\tADDED NEW DEVICE (%s)\n", bepath); + be->frontpath = frontend; + + list_add(&be->list, &belist); + + DPRINTF("[PROBE]\tADDED NEW DEVICE (%s)\n", bepath); DPRINTF("\tFRONTEND (%s),(%ld)\n", frontend,be->frontend_id); ueblktap_setup(h, bepath); @@ -342,11 +339,10 @@ static void ueblktap_probe(struct xs_han free_be: if (frontend) free(frontend); - if (bepath) + if (bepath) free(bepath); if (be) free(be); - return; } /** @@ -360,7 +356,6 @@ int add_blockdevice_probe_watch(struct x { char *path; struct xenbus_watch *vbd_watch; - int er; asprintf(&path, "/local/domain/%s/backend/tap", domid); if (path == NULL) @@ -373,76 +368,67 @@ int add_blockdevice_probe_watch(struct x } vbd_watch->node = path; vbd_watch->callback = ueblktap_probe; - er = register_xenbus_watch(h, vbd_watch); - if (er == 0) { + if (register_xenbus_watch(h, vbd_watch) != 0) { DPRINTF("ERROR: adding vbd probe watch %s\n", path); return -EINVAL; } return 0; } -/* - *Asynch callback to check for /local/domain/<DOMID>/name - */ +/* Asynch callback to check for /local/domain/<DOMID>/name */ void check_dom(struct xs_handle *h, struct xenbus_watch *w, - const char *bepath_im) { - char *domid = NULL; + const char *bepath_im) +{ + char *domid; domid = get_dom_domid(h); - if (domid) { - add_blockdevice_probe_watch(h, domid); - free(domid); - unregister_xenbus_watch(h, w); - } - return; -} - -/* - *We must wait for xend to register /local/domain/<DOMID> - */ + if (domid == NULL) + return; + + add_blockdevice_probe_watch(h, domid); + free(domid); + unregister_xenbus_watch(h, w); +} + +/* We must wait for xend to register /local/domain/<DOMID> */ int watch_for_domid(struct xs_handle *h) { struct xenbus_watch *domid_watch; char *path = NULL; - int er; asprintf(&path, "/local/domain"); if (path == NULL) return -ENOMEM; - domid_watch = (struct xenbus_watch *)malloc(sizeof(struct xenbus_watch)); - if (!domid_watch) { + domid_watch = malloc(sizeof(struct xenbus_watch)); + if (domid_watch == NULL) { DPRINTF("ERROR: unable to malloc domid_watch [%s]\n", path); return -EINVAL; } + domid_watch->node = path; domid_watch->callback = check_dom; - er = register_xenbus_watch(h, domid_watch); - if (er == 0) { + + if (register_xenbus_watch(h, domid_watch) != 0) { DPRINTF("ERROR: adding vbd probe watch %s\n", path); return -EINVAL; } - if (path == NULL) - return -ENOMEM; - return 1; + + DPRINTF("Set async watch for /local/domain\n"); + + return 0; } int setup_probe_watch(struct xs_handle *h) { - char *domid = NULL, *path; + char *domid; int ret; domid = get_dom_domid(h); - - if (!domid) { - /*Asynchronous path*/ - ret = watch_for_domid(h); - goto finish; - } else { - /*Synchronous path*/ - ret = add_blockdevice_probe_watch(h, domid); - free(domid); - } - finish: + if (domid == NULL) + return watch_for_domid(h); + + ret = add_blockdevice_probe_watch(h, domid); + free(domid); return ret; } diff -r 7efaaae37415 -r ff9746d600e9 tools/blktap/lib/xs_api.c --- a/tools/blktap/lib/xs_api.c Fri Oct 06 11:52:41 2006 +0100 +++ b/tools/blktap/lib/xs_api.c Fri Oct 06 15:04:42 2006 +0100 @@ -106,7 +106,7 @@ again: if (!xs_transaction_end(xs, xth, ret)) { if (ret == 0 && errno == EAGAIN) goto again; - else + else ret = errno; } @@ -118,25 +118,25 @@ int xs_printf(struct xs_handle *h, const int xs_printf(struct xs_handle *h, const char *dir, const char *node, const char *fmt, ...) { - char *buf, *path; - va_list ap; - int ret; - - va_start(ap, fmt); - ret = vasprintf(&buf, fmt, ap); - va_end(ap); - - asprintf(&path, "%s/%s", dir, node); - - if ( (path == NULL) || (buf == NULL) ) + char *buf, *path; + va_list ap; + int ret; + + va_start(ap, fmt); + ret = vasprintf(&buf, fmt, ap); + va_end(ap); + + asprintf(&path, "%s/%s", dir, node); + + if ((path == NULL) || (buf == NULL)) return 0; - ret = xs_write(h, XBT_NULL, path, buf, strlen(buf)+1); - - free(buf); - free(path); - - return ret; + ret = xs_write(h, XBT_NULL, path, buf, strlen(buf)+1); + + free(buf); + free(path); + + return ret; } @@ -179,7 +179,7 @@ char *get_dom_domid(struct xs_handle *h) } e = xs_directory(h, xth, "/local/domain", &num); - + for (i = 0; (i < num) && (domid == NULL); i++) { asprintf(&path, "/local/domain/%s/name", e[i]); val = xs_read(h, xth, path, &len); @@ -249,12 +249,12 @@ int convert_dev_name_to_num(char *name) ret = BASE_DEV_VAL; } - free(p_sd); - free(p_hd); - free(p_xvd); - free(p_plx); - free(alpha); - + free(p_sd); + free(p_hd); + free(p_xvd); + free(p_plx); + free(alpha); + return ret; } @@ -281,42 +281,39 @@ int register_xenbus_watch(struct xs_hand { /* Pointer in ascii is the token. */ char token[sizeof(watch) * 2 + 1]; - int er; - + sprintf(token, "%lX", (long)watch); - if (find_watch(token)) - { + if (find_watch(token)) { DPRINTF("watch collision!\n"); return -EINVAL; } - er = xs_watch(h, watch->node, token); - if (er != 0) { - list_add(&watch->list, &watches); - } - - return er; + if (!xs_watch(h, watch->node, token)) { + DPRINTF("unable to set watch!\n"); + return -EINVAL; + } + + list_add(&watch->list, &watches); + + return 0; } int unregister_xenbus_watch(struct xs_handle *h, struct xenbus_watch *watch) { char token[sizeof(watch) * 2 + 1]; - int er; sprintf(token, "%lX", (long)watch); - if (!find_watch(token)) - { + if (!find_watch(token)) { DPRINTF("no such watch!\n"); return -EINVAL; } - - - er = xs_unwatch(h, watch->node, token); + + if (!xs_unwatch(h, watch->node, token)) + DPRINTF("XENBUS Failed to release watch %s: %i\n", + watch->node, er); + list_del(&watch->list); - if (er == 0) - DPRINTF("XENBUS Failed to release watch %s: %i\n", - watch->node, er); return 0; } @@ -354,14 +351,10 @@ int xs_fire_next_watch(struct xs_handle token = res[XS_WATCH_TOKEN]; w = find_watch(token); - if (!w) - { - DPRINTF("unregistered watch fired\n"); - goto done; - } - w->callback(h, w, node); - - done: + if (w) + w->callback(h, w, node); + free(res); + return 1; } _______________________________________________ Xen-changelog mailing list Xen-changelog@xxxxxxxxxxxxxxxxxxx http://lists.xensource.com/xen-changelog
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |