debuggers.hg

changeset 20636:d988dd0f05f2

fs-backend: add a backend cleanup function

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@eu.citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Tue Dec 08 07:45:15 2009 +0000 (2009-12-08)
parents 696f94dfad26
children 91555131e235
files tools/fs-back/fs-backend.c tools/fs-back/fs-backend.h tools/fs-back/fs-xenbus.c
line diff
     1.1 --- a/tools/fs-back/fs-backend.c	Tue Dec 08 07:44:45 2009 +0000
     1.2 +++ b/tools/fs-back/fs-backend.c	Tue Dec 08 07:45:15 2009 +0000
     1.3 @@ -179,6 +179,7 @@ void terminate_mount_request(struct fs_m
     1.4  
     1.5  static void free_mount_request(struct fs_mount *mount) {
     1.6      FS_DEBUG("free_mount_request %s\n", mount->frontend);
     1.7 +    xenbus_free_backend_node(mount);
     1.8      free(mount->frontend);
     1.9      free(mount->requests);
    1.10      free(mount->freelist);
    1.11 @@ -356,8 +357,19 @@ static void await_connections(void)
    1.12                  if((dom_id >= 0) && (export_id >= 0) && d == 'd') {
    1.13                      char *frontend = xs_read(xsh, XBT_NULL, watch_paths[XS_WATCH_PATH], NULL);
    1.14                      if (frontend) {
    1.15 +                        char *p, *wp = strdup(watch_paths[XS_WATCH_PATH]);
    1.16                          handle_connection(dom_id, export_id, frontend);
    1.17 -                        xs_rm(xsh, XBT_NULL, watch_paths[XS_WATCH_PATH]);
    1.18 +                        xs_rm(xsh, XBT_NULL, wp);
    1.19 +                        p = strrchr(wp, '/');
    1.20 +                        if (p) {
    1.21 +                            *p = '\0';
    1.22 +                            p = strrchr(wp, '/');
    1.23 +                            if (p) {
    1.24 +                                *p = '\0';
    1.25 +                                xs_rm(xsh, XBT_NULL, wp);
    1.26 +                            }
    1.27 +                        }
    1.28 +                        free(wp);
    1.29                      }
    1.30                  }
    1.31              } else if (!strcmp(watch_paths[XS_WATCH_TOKEN], "frontend-state")) {
     2.1 --- a/tools/fs-back/fs-backend.h	Tue Dec 08 07:44:45 2009 +0000
     2.2 +++ b/tools/fs-back/fs-backend.h	Tue Dec 08 07:45:15 2009 +0000
     2.3 @@ -67,6 +67,7 @@ int xenbus_get_watch_fd(void);
     2.4  int xenbus_read_mount_request(struct fs_mount *mount, char *frontend);
     2.5  bool xenbus_write_backend_node(struct fs_mount *mount);
     2.6  bool xenbus_write_backend_state(struct fs_mount *mount, const char *state);
     2.7 +void xenbus_free_backend_node(struct fs_mount *mount);
     2.8  int xenbus_frontend_state_changed(struct fs_mount *mount, const char *oldstate);
     2.9  bool xenbus_watch_frontend_state(struct fs_mount *mount);
    2.10  bool xenbus_unwatch_frontend_state(struct fs_mount *mount);
     3.1 --- a/tools/fs-back/fs-xenbus.c	Tue Dec 08 07:44:45 2009 +0000
     3.2 +++ b/tools/fs-back/fs-xenbus.c	Tue Dec 08 07:45:15 2009 +0000
     3.3 @@ -204,6 +204,17 @@ bool xenbus_write_backend_state(struct f
     3.4      return xs_write(xsh, XBT_NULL, node, state, strlen(state));
     3.5  }
     3.6  
     3.7 +void xenbus_free_backend_node(struct fs_mount *mount)
     3.8 +{
     3.9 +    char node[1024];
    3.10 +    int self_id;
    3.11 +
    3.12 +    assert(xsh != NULL);
    3.13 +    self_id = get_self_id();
    3.14 +    snprintf(node, sizeof(node), ROOT_NODE"/%d", mount->mount_id);
    3.15 +    xs_rm(xsh, XBT_NULL, node);
    3.16 +}
    3.17 +
    3.18  bool xenbus_watch_frontend_state(struct fs_mount *mount)
    3.19  {
    3.20      char statepath[1024];