aboutsummaryrefslogtreecommitdiffstats
path: root/tools/blktap/lib
diff options
context:
space:
mode:
authorkfraser@localhost.localdomain <kfraser@localhost.localdomain>2006-10-06 15:04:42 +0100
committerkfraser@localhost.localdomain <kfraser@localhost.localdomain>2006-10-06 15:04:42 +0100
commitdc2917720c8693a9293efa4b1fb10fea6803d155 (patch)
treefeb30d997df7f35822f423593e4071cec9ad93bc /tools/blktap/lib
parent431414939662f36e8f09346ceeddfca7102fcc65 (diff)
downloadxen-dc2917720c8693a9293efa4b1fb10fea6803d155.tar.gz
xen-dc2917720c8693a9293efa4b1fb10fea6803d155.tar.bz2
xen-dc2917720c8693a9293efa4b1fb10fea6803d155.zip
[BLKTAP] Formatting and style cleanups to blktapctrl.
Signed-off-by: Keir Fraser <keir@xensource.com>
Diffstat (limited to 'tools/blktap/lib')
-rw-r--r--tools/blktap/lib/xenbus.c168
-rw-r--r--tools/blktap/lib/xs_api.c87
2 files changed, 117 insertions, 138 deletions
diff --git a/tools/blktap/lib/xenbus.c b/tools/blktap/lib/xenbus.c
index 95b5f602ab..ea7377d47c 100644
--- a/tools/blktap/lib/xenbus.c
+++ b/tools/blktap/lib/xenbus.c
@@ -166,60 +166,58 @@ static void ueblktap_setup(struct xs_handle *h, char *bepath)
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 (deverr) {
+ /*Dev number was not available, try to set manually*/
+ pdev = convert_dev_name_to_num(blk->params);
+ be->pdev = pdev;
+ }
- if (er != 0) {
- DPRINTF("Unable to open device %s\n",blk->params);
+ 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);
- }
+ 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_handle *h, struct xenbus_watch *w,
*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_handle *h, struct xenbus_watch *w,
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;
+ be->frontpath = frontend;
- list_add(&be->list, &belist);
+ list_add(&be->list, &belist);
- DPRINTF("[PROBE]\tADDED NEW DEVICE (%s)\n", bepath);
+ 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_handle *h, struct xenbus_watch *w,
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 xs_handle *h, const char *domid)
{
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 xs_handle *h, const char *domid)
}
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;
+ 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>
- */
+/* 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 == NULL)
+ return watch_for_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:
+ ret = add_blockdevice_probe_watch(h, domid);
+ free(domid);
return ret;
}
diff --git a/tools/blktap/lib/xs_api.c b/tools/blktap/lib/xs_api.c
index 6d6a5fdfba..4df73e1512 100644
--- a/tools/blktap/lib/xs_api.c
+++ b/tools/blktap/lib/xs_api.c
@@ -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 @@ again:
int xs_printf(struct xs_handle *h, const char *dir, const char *node,
const char *fmt, ...)
{
- char *buf, *path;
- va_list ap;
- int ret;
+ char *buf, *path;
+ va_list ap;
+ int ret;
- va_start(ap, fmt);
- ret = vasprintf(&buf, fmt, ap);
- va_end(ap);
+ va_start(ap, fmt);
+ ret = vasprintf(&buf, fmt, ap);
+ va_end(ap);
- asprintf(&path, "%s/%s", dir, node);
+ asprintf(&path, "%s/%s", dir, node);
- if ( (path == NULL) || (buf == NULL) )
+ if ((path == NULL) || (buf == NULL))
return 0;
- ret = xs_write(h, XBT_NULL, path, buf, strlen(buf)+1);
+ ret = xs_write(h, XBT_NULL, path, buf, strlen(buf)+1);
- free(buf);
- free(path);
+ free(buf);
+ free(path);
- return ret;
+ 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_handle *h, struct xenbus_watch *watch)
{
/* 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 *h)
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;
}