fs-backend: add a backend cleanup function
PATCH 1/1 fs-backend: add a backend cleanup function
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 <[email protected]>
---
tools/fs-back/fs-backend.c +13 -1
@@ -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" )) {
tools/fs-back/fs-backend.h +1 -0
@@ -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);
tools/fs-back/fs-xenbus.c +11 -0
@@ -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 ];