ia64/xen-unstable

changeset 12734:0536dbde1562

[PVFB] Make sure that framebuffer backend goes away when the domain
terminates, and that it cleans up its area of xenstore.

Tidy up argument parsing a little while I'm here.

Signed-off-by: Steven Smith <sos22@cam.ac.uk>
author Steven Smith <ssmith@xensource.com>
date Fri Dec 01 12:03:15 2006 +0000 (2006-12-01)
parents d5d8aeb4fa34
children f50380324d1c
files tools/xenfb/sdlfb.c tools/xenfb/vncfb.c tools/xenfb/xenfb.c tools/xenfb/xenfb.h
line diff
     1.1 --- a/tools/xenfb/sdlfb.c	Fri Dec 01 11:52:33 2006 +0000
     1.2 +++ b/tools/xenfb/sdlfb.c	Fri Dec 01 12:03:15 2006 +0000
     1.3 @@ -204,6 +204,7 @@ static int sdl_on_event(struct xenfb *xe
     1.4  static struct option options[] = {
     1.5  	{ "domid", 1, NULL, 'd' },
     1.6  	{ "title", 1, NULL, 't' },
     1.7 +	{ NULL }
     1.8  };
     1.9  
    1.10  int main(int argc, char **argv)
    1.11 @@ -220,6 +221,7 @@ int main(int argc, char **argv)
    1.12  	int do_quit = 0;
    1.13  	int opt;
    1.14  	char *endp;
    1.15 +	int retval;
    1.16  
    1.17  	while ((opt = getopt_long(argc, argv, "d:t:", options,
    1.18  				  NULL)) != -1) {
    1.19 @@ -234,6 +236,8 @@ int main(int argc, char **argv)
    1.20                  case 't':
    1.21  			title = strdup(optarg);
    1.22  			break;
    1.23 +		case '?':
    1.24 +			exit(1);
    1.25                  }
    1.26          }
    1.27          if (optind != argc) {
    1.28 @@ -323,7 +327,11 @@ int main(int argc, char **argv)
    1.29                  if (do_quit)
    1.30  			break;
    1.31  
    1.32 -		xenfb_poll(xenfb, &readfds);
    1.33 +		retval = xenfb_poll(xenfb, &readfds);
    1.34 +		if (retval == -2)
    1.35 +		    xenfb_teardown(xenfb);
    1.36 +		if (retval < 0)
    1.37 +		    break;
    1.38  	}
    1.39  
    1.40  	xenfb_delete(xenfb);
     2.1 --- a/tools/xenfb/vncfb.c	Fri Dec 01 11:52:33 2006 +0000
     2.2 +++ b/tools/xenfb/vncfb.c	Fri Dec 01 12:03:15 2006 +0000
     2.3 @@ -253,6 +253,7 @@ static struct option options[] = {
     2.4  	{ "title", 1, NULL, 't' },
     2.5  	{ "unused", 0, NULL, 'u' },
     2.6  	{ "listen", 1, NULL, 'l' },
     2.7 +	{ NULL }
     2.8  };
     2.9  
    2.10  int main(int argc, char **argv)
    2.11 @@ -272,6 +273,7 @@ int main(int argc, char **argv)
    2.12  	int nfds;
    2.13  	char portstr[10];
    2.14  	char *endp;
    2.15 +	int r;
    2.16  
    2.17  	while ((opt = getopt_long(argc, argv, "d:p:t:u", options,
    2.18  				  NULL)) != -1) {
    2.19 @@ -301,6 +303,8 @@ int main(int argc, char **argv)
    2.20                  case 'l':
    2.21  			listen = strdup(optarg);
    2.22  			break;
    2.23 +		case '?':
    2.24 +			exit(1);
    2.25                  }
    2.26          }
    2.27          if (optind != argc) {
    2.28 @@ -383,7 +387,11 @@ int main(int argc, char **argv)
    2.29  			break;
    2.30  		}
    2.31  
    2.32 -		xenfb_poll(xenfb, &readfds);
    2.33 +		r = xenfb_poll(xenfb, &readfds);
    2.34 +		if (r == -2)
    2.35 +		    xenfb_teardown(xenfb);
    2.36 +		if (r < 0)
    2.37 +		    break;
    2.38  	}
    2.39  
    2.40  	rfbScreenCleanup(server);
     3.1 --- a/tools/xenfb/xenfb.c	Fri Dec 01 11:52:33 2006 +0000
     3.2 +++ b/tools/xenfb/xenfb.c	Fri Dec 01 12:03:15 2006 +0000
     3.3 @@ -187,6 +187,17 @@ struct xenfb *xenfb_new(void)
     3.4  	return NULL;
     3.5  }
     3.6  
     3.7 +/* Remove the backend area in xenbus since the framebuffer really is
     3.8 +   going away. */
     3.9 +void xenfb_teardown(struct xenfb *xenfb_pub)
    3.10 +{
    3.11 +       struct xenfb_private *xenfb = (struct xenfb_private *)xenfb_pub;
    3.12 +
    3.13 +       xs_rm(xenfb->xsh, XBT_NULL, xenfb->fb.nodename);
    3.14 +       xs_rm(xenfb->xsh, XBT_NULL, xenfb->kbd.nodename);
    3.15 +}
    3.16 +
    3.17 +
    3.18  void xenfb_delete(struct xenfb *xenfb_pub)
    3.19  {
    3.20  	struct xenfb_private *xenfb = (struct xenfb_private *)xenfb_pub;
    3.21 @@ -564,7 +575,7 @@ static void xenfb_on_kbd_event(struct xe
    3.22  	xc_evtchn_notify(xenfb->evt_xch, xenfb->kbd.port);
    3.23  }
    3.24  
    3.25 -static void xenfb_on_state_change(struct xenfb_device *dev)
    3.26 +static int xenfb_on_state_change(struct xenfb_device *dev)
    3.27  {
    3.28  	enum xenbus_state state;
    3.29  
    3.30 @@ -572,6 +583,10 @@ static void xenfb_on_state_change(struct
    3.31  
    3.32  	switch (state) {
    3.33  	case XenbusStateUnknown:
    3.34 +		/* There was an error reading the frontend state.  The
    3.35 +		   domain has probably gone away; in any case, there's
    3.36 +		   not much point in us continuing. */
    3.37 +		return -1;
    3.38  	case XenbusStateInitialising:
    3.39  	case XenbusStateInitWait:
    3.40  	case XenbusStateInitialised:
    3.41 @@ -585,14 +600,17 @@ static void xenfb_on_state_change(struct
    3.42  		xs_unwatch(dev->xenfb->xsh, dev->otherend, "");
    3.43  		xenfb_switch_state(dev, state);
    3.44  	}
    3.45 +	return 0;
    3.46  }
    3.47  
    3.48 +/* Returns 0 normally, -1 on error, or -2 if the domain went away. */
    3.49  int xenfb_poll(struct xenfb *xenfb_pub, fd_set *readfds)
    3.50  {
    3.51  	struct xenfb_private *xenfb = (struct xenfb_private *)xenfb_pub;
    3.52  	evtchn_port_t port;
    3.53  	unsigned dummy;
    3.54  	char **vec;
    3.55 +	int r;
    3.56  
    3.57  	if (FD_ISSET(xc_evtchn_fd(xenfb->evt_xch), readfds)) {
    3.58  		port = xc_evtchn_pending(xenfb->evt_xch);
    3.59 @@ -611,8 +629,11 @@ int xenfb_poll(struct xenfb *xenfb_pub, 
    3.60  	if (FD_ISSET(xs_fileno(xenfb->xsh), readfds)) {
    3.61  		vec = xs_read_watch(xenfb->xsh, &dummy);
    3.62  		free(vec);
    3.63 -		xenfb_on_state_change(&xenfb->fb);
    3.64 -		xenfb_on_state_change(&xenfb->kbd);
    3.65 +		r = xenfb_on_state_change(&xenfb->fb);
    3.66 +		if (r == 0)
    3.67 +			r = xenfb_on_state_change(&xenfb->kbd);
    3.68 +		if (r == -1)
    3.69 +			return -2;
    3.70  	}
    3.71  
    3.72  	return 0;
     4.1 --- a/tools/xenfb/xenfb.h	Fri Dec 01 11:52:33 2006 +0000
     4.2 +++ b/tools/xenfb/xenfb.h	Fri Dec 01 12:03:15 2006 +0000
     4.3 @@ -21,6 +21,7 @@ struct xenfb
     4.4  
     4.5  struct xenfb *xenfb_new(void);
     4.6  void xenfb_delete(struct xenfb *xenfb);
     4.7 +void xenfb_teardown(struct xenfb *xenfb);
     4.8  
     4.9  int xenfb_attach_dom(struct xenfb *xenfb, int domid);
    4.10