ia64/xen-unstable

changeset 5868:71271a3f41a9

Start of code to persistent store connections when xenstored restarts
Signed-off-by: Rusty Russel <rusty@rustcorp.com.au>
Signed-off-by: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
author cl349@firebug.cl.cam.ac.uk
date Tue Jul 26 14:02:33 2005 +0000 (2005-07-26)
parents 932fc8a1b38d
children f9a3f32a129b
files tools/xenstore/xenstored_core.c tools/xenstore/xenstored_domain.c tools/xenstore/xenstored_domain.h
line diff
     1.1 --- a/tools/xenstore/xenstored_core.c	Tue Jul 26 13:11:01 2005 +0000
     1.2 +++ b/tools/xenstore/xenstored_core.c	Tue Jul 26 14:02:33 2005 +0000
     1.3 @@ -1386,6 +1386,45 @@ void dump_connection(void)
     1.4  }
     1.5  #endif
     1.6  
     1.7 +static void setup_structure(void)
     1.8 +{
     1.9 +	struct xs_permissions perms = { .id = 0, .perms = XS_PERM_READ };
    1.10 +	char *root, *dir, *permfile;
    1.11 +
    1.12 +	/* Create root directory, with permissions. */
    1.13 +	if (mkdir(xs_daemon_store(), 0750) != 0) {
    1.14 +		if (errno != EEXIST)
    1.15 +			barf_perror("Could not create root %s",
    1.16 +				    xs_daemon_store());
    1.17 +		return;
    1.18 +	}
    1.19 +	root = talloc_strdup(talloc_autofree_context(), "/");
    1.20 +	if (!set_perms(NULL, root, &perms, 1))
    1.21 +		barf_perror("Could not create permissions in root");
    1.22 +
    1.23 +	/* Create tool directory, with xenstored subdir. */
    1.24 +	dir = talloc_asprintf(root, "%s/%s", xs_daemon_store(), "tool");
    1.25 +	if (mkdir(dir, 0750) != 0)
    1.26 +		barf_perror("Making dir %s", dir);
    1.27 +	
    1.28 +	permfile = talloc_strdup(root, "/tool");
    1.29 +	if (!set_perms(NULL, permfile, &perms, 1))
    1.30 +		barf_perror("Could not create permissions on %s", permfile);
    1.31 +
    1.32 +	dir = talloc_asprintf(root, "%s/%s", dir, "xenstored");
    1.33 +	if (mkdir(dir, 0750) != 0)
    1.34 +		barf_perror("Making dir %s", dir);
    1.35 +	
    1.36 +	permfile = talloc_strdup(root, "/tool/xenstored");
    1.37 +	if (!set_perms(NULL, permfile, &perms, 1))
    1.38 +		barf_perror("Could not create permissions on %s", permfile);
    1.39 +
    1.40 +	talloc_free(root);
    1.41 +	if (mkdir(xs_daemon_transactions(), 0750) != 0)
    1.42 +		barf_perror("Could not create transaction dir %s",
    1.43 +			    xs_daemon_transactions());
    1.44 +}
    1.45 +
    1.46  static struct option options[] = { { "no-fork", 0, NULL, 'N' },
    1.47  				   { "verbose", 0, NULL, 'V' },
    1.48  				   { "output-pid", 0, NULL, 'P' },
    1.49 @@ -1461,22 +1500,14 @@ int main(int argc, char *argv[])
    1.50  		barf_perror("Could not listen on sockets");
    1.51  
    1.52  	/* If we're the first, create .perms file for root. */
    1.53 -	if (mkdir(xs_daemon_store(), 0750) == 0) {
    1.54 -		struct xs_permissions perms;
    1.55 -		char *root = talloc_strdup(talloc_autofree_context(), "/");
    1.56 -
    1.57 -		perms.id = 0;
    1.58 -		perms.perms = XS_PERM_READ;
    1.59 -		if (!set_perms(NULL, root, &perms, 1))
    1.60 -			barf_perror("Could not create permissions in root");
    1.61 -		talloc_free(root);
    1.62 -		mkdir(xs_daemon_transactions(), 0750);
    1.63 -	} else if (errno != EEXIST)
    1.64 -		barf_perror("Could not create root %s", xs_daemon_store());
    1.65 +	setup_structure();
    1.66  
    1.67  	/* Listen to hypervisor. */
    1.68  	event_fd = domain_init();
    1.69  
    1.70 +	/* Restore existing connections. */
    1.71 +	restore_existing_connections();
    1.72 +
    1.73  	/* Debugging: daemonize() closes standard fds, so dup here. */
    1.74  	tmpout = dup(STDOUT_FILENO);
    1.75  	if (dofork) {
     2.1 --- a/tools/xenstore/xenstored_domain.c	Tue Jul 26 13:11:01 2005 +0000
     2.2 +++ b/tools/xenstore/xenstored_domain.c	Tue Jul 26 14:02:33 2005 +0000
     2.3 @@ -254,6 +254,38 @@ void handle_event(int event_fd)
     2.4  #endif
     2.5  }
     2.6  
     2.7 +static struct domain *new_domain(void *context, domid_t domid,
     2.8 +				 unsigned long mfn, int port,
     2.9 +				 const char *path)
    2.10 +{
    2.11 +	struct domain *domain;
    2.12 +	domain = talloc(context, struct domain);
    2.13 +	domain->domid = domid;
    2.14 +	domain->port = port;
    2.15 +	domain->path = talloc_strdup(domain, path);
    2.16 +	domain->page = xc_map_foreign_range(*xc_handle, domain->domid,
    2.17 +					    getpagesize(),
    2.18 +					    PROT_READ|PROT_WRITE,
    2.19 +					    mfn);
    2.20 +	if (!domain->page)
    2.21 +		return NULL;
    2.22 +
    2.23 +	list_add(&domain->list, &domains);
    2.24 +	talloc_set_destructor(domain, destroy_domain);
    2.25 +
    2.26 +	/* One in each half of page. */
    2.27 +	domain->input = domain->page;
    2.28 +	domain->output = domain->page + getpagesize()/2;
    2.29 +
    2.30 +	/* Tell kernel we're interested in this event. */
    2.31 +	if (ioctl(eventchn_fd, EVENTCHN_BIND, domain->port) != 0)
    2.32 +		return NULL;
    2.33 +
    2.34 +	domain->conn = new_connection(writechn, readchn);
    2.35 +	domain->conn->domain = domain;
    2.36 +	return domain;
    2.37 +}
    2.38 +
    2.39  /* domid, mfn, evtchn, path */
    2.40  bool do_introduce(struct connection *conn, struct buffered_data *in)
    2.41  {
    2.42 @@ -269,34 +301,16 @@ bool do_introduce(struct connection *con
    2.43  	if (!conn->can_write)
    2.44  		return send_error(conn, EROFS);
    2.45  
    2.46 -	/* Hang domain off "in" until we're finished. */
    2.47 -	domain = talloc(in, struct domain);
    2.48 -	domain->domid = atoi(vec[0]);
    2.49 -	domain->port = atoi(vec[2]);
    2.50 -	if ((domain->port <= 0) || !is_valid_nodename(vec[3]))
    2.51 +	/* Sanity check args. */
    2.52 +	if ((atoi(vec[2]) <= 0) || !is_valid_nodename(vec[3]))
    2.53  		return send_error(conn, EINVAL);
    2.54 -	domain->path = talloc_strdup(domain, vec[3]);
    2.55 -	domain->page = xc_map_foreign_range(*xc_handle, domain->domid,
    2.56 -					    getpagesize(),
    2.57 -					    PROT_READ|PROT_WRITE,
    2.58 -					    atol(vec[1]));
    2.59 -	if (!domain->page)
    2.60 +	/* Hang domain off "in" until we're finished. */
    2.61 +	domain = new_domain(in, atoi(vec[0]), atol(vec[1]), atol(vec[2]),
    2.62 +			    vec[3]);
    2.63 +	if (!domain)
    2.64  		return send_error(conn, errno);
    2.65  
    2.66 -	list_add(&domain->list, &domains);
    2.67 -	talloc_set_destructor(domain, destroy_domain);
    2.68 -
    2.69 -	/* One in each half of page. */
    2.70 -	domain->input = domain->page;
    2.71 -	domain->output = domain->page + getpagesize()/2;
    2.72 -
    2.73 -	/* Tell kernel we're interested in this event. */
    2.74 -	if (ioctl(eventchn_fd, EVENTCHN_BIND, domain->port) != 0)
    2.75 -		return send_error(conn, errno);
    2.76 -
    2.77 -	domain->conn = new_connection(writechn, readchn);
    2.78 -	domain->conn->domain = domain;
    2.79 -
    2.80 +	/* Now domain belongs to its connection. */
    2.81  	talloc_steal(domain->conn, domain);
    2.82  
    2.83  	return send_ack(conn, XS_INTRODUCE);
    2.84 @@ -375,6 +389,11 @@ const char *get_implicit_path(const stru
    2.85  	return conn->domain->path;
    2.86  }
    2.87  
    2.88 +/* Restore existing connections. */
    2.89 +void restore_existing_connections(void)
    2.90 +{
    2.91 +}
    2.92 +
    2.93  /* Returns the event channel handle. */
    2.94  int domain_init(void)
    2.95  {
     3.1 --- a/tools/xenstore/xenstored_domain.h	Tue Jul 26 13:11:01 2005 +0000
     3.2 +++ b/tools/xenstore/xenstored_domain.h	Tue Jul 26 14:02:33 2005 +0000
     3.3 @@ -37,4 +37,7 @@ int domain_init(void);
     3.4  /* Returns the implicit path of a connection (only domains have this) */
     3.5  const char *get_implicit_path(const struct connection *conn);
     3.6  
     3.7 +/* Read existing connection information from store. */
     3.8 +void restore_existing_connections(void);
     3.9 +
    3.10  #endif /* _XENSTORED_DOMAIN_H */