Hi all,
this patch implements a backend cleanup function in fs-backend so that
when the connection to the frontend is closed we don't leak nodes on
xenstore.
Signed-off-by: Stefano Stabellini <stefano.stabellini@xxxxxxxxxxxxx>
---
diff -r b4c47cfbb9b1 tools/fs-back/fs-backend.c
--- a/tools/fs-back/fs-backend.c Wed Dec 02 15:02:06 2009 +0000
+++ b/tools/fs-back/fs-backend.c Wed Dec 02 16:57:15 2009 +0000
@@ -179,6 +179,7 @@
static void free_mount_request(struct fs_mount *mount) {
FS_DEBUG("free_mount_request %s\n", mount->frontend);
+ xenbus_free_backend_node(mount);
free(mount->frontend);
free(mount->requests);
free(mount->freelist);
@@ -356,8 +357,19 @@
if((dom_id >= 0) && (export_id >= 0) && d == 'd') {
char *frontend = xs_read(xsh, XBT_NULL,
watch_paths[XS_WATCH_PATH], NULL);
if (frontend) {
+ char *p, *wp = strdup(watch_paths[XS_WATCH_PATH]);
handle_connection(dom_id, export_id, frontend);
- xs_rm(xsh, XBT_NULL, watch_paths[XS_WATCH_PATH]);
+ xs_rm(xsh, XBT_NULL, wp);
+ p = strrchr(wp, '/');
+ if (p) {
+ *p = '\0';
+ p = strrchr(wp, '/');
+ if (p) {
+ *p = '\0';
+ xs_rm(xsh, XBT_NULL, wp);
+ }
+ }
+ free(wp);
}
}
} else if (!strcmp(watch_paths[XS_WATCH_TOKEN], "frontend-state"))
{
diff -r b4c47cfbb9b1 tools/fs-back/fs-backend.h
--- a/tools/fs-back/fs-backend.h Wed Dec 02 15:02:06 2009 +0000
+++ b/tools/fs-back/fs-backend.h Wed Dec 02 16:57:15 2009 +0000
@@ -67,6 +67,7 @@
int xenbus_read_mount_request(struct fs_mount *mount, char *frontend);
bool xenbus_write_backend_node(struct fs_mount *mount);
bool xenbus_write_backend_state(struct fs_mount *mount, const char *state);
+void xenbus_free_backend_node(struct fs_mount *mount);
int xenbus_frontend_state_changed(struct fs_mount *mount, const char
*oldstate);
bool xenbus_watch_frontend_state(struct fs_mount *mount);
bool xenbus_unwatch_frontend_state(struct fs_mount *mount);
diff -r b4c47cfbb9b1 tools/fs-back/fs-xenbus.c
--- a/tools/fs-back/fs-xenbus.c Wed Dec 02 15:02:06 2009 +0000
+++ b/tools/fs-back/fs-xenbus.c Wed Dec 02 16:57:15 2009 +0000
@@ -204,6 +204,17 @@
return xs_write(xsh, XBT_NULL, node, state, strlen(state));
}
+void xenbus_free_backend_node(struct fs_mount *mount)
+{
+ char node[1024];
+ int self_id;
+
+ assert(xsh != NULL);
+ self_id = get_self_id();
+ snprintf(node, sizeof(node), ROOT_NODE"/%d", mount->mount_id);
+ xs_rm(xsh, XBT_NULL, node);
+}
+
bool xenbus_watch_frontend_state(struct fs_mount *mount)
{
char statepath[1024];
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel
|