vchan/vm: implement libvchan_cleanup to release resources used by vchan link

In most cases after vchan close program terminates (or reexec itself to wait
for next connection), so cleanup isn't needed (not sure how about evtchn and
shared pages...).
But in case of stubdom it is needed to cleanup before waiting for new
connection - we can't reexec agent there.
This commit is contained in:
Marek Marczykowski 2012-12-12 02:20:36 +01:00
parent 84be00eb14
commit efbd9466f8
2 changed files with 45 additions and 0 deletions

View File

@ -206,6 +206,49 @@ static int server_interface_init(struct libvchan *ctrl, int devno)
ctrl->wr_ring_size = sizeof(ctrl->ring->buf_##dir1); \
ctrl->rd_ring_size = sizeof(ctrl->ring->buf_##dir2)
/**
Run in AppVM (any domain).
Release resources used by vchan link. Should be used after
libvchan_close() to clean connection shutdown, but can be used alone in
recovery case.
\param ctrl connection to cleanup
\returns -1 on failure (errno for details), 0 on success
*/
int libvchan_cleanup(struct libvchan *ctrl)
{
if (!ctrl)
return 0;
if (!ctrl->is_server)
return 0;
/* do not wait flush remaining queue to allow use libvchan_cleanup for
* recovery situation. If someone want clean close, should call
* libvchan_close() first.
*/
#if 0
if (!ctrl->ring->server_closed)
libvchan_close(ctrl);
#endif
if (xc_evtchn_unbind(ctrl->evfd, ctrl->evport) < 0)
return -1;
xc_evtchn_close(ctrl->evfd);
#ifdef QREXEC_RING_V2
/* not implemented yet, need to store gntmem_handle from ring_init somewhere */
assert(0);
/* in case of disabled assertions */
errno = EINVAL;
return -1;
#else /* QREXEC_RING_V2 */
#ifdef CONFIG_STUBDOM
free(ctrl->ring);
#else /* CONFIG_STUBDOM */
munmap(ctrl->ring, 4096);
/* FIXME: leak of u2mfn_fd, check u2mfnlib.c */
#endif /* CONFIG_STUBDOM */
#endif /* QREXEC_RING_V2 */
free(ctrl);
return 0;
}
/**
Run in AppVM (any domain).
Sleeps until the connection is established. (unless in stubdom)

View File

@ -88,4 +88,6 @@ int libvchan_is_eof(struct libvchan *ctrl);
int libvchan_data_ready(struct libvchan *ctrl);
int libvchan_buffer_space(struct libvchan *ctrl);
int libvchan_cleanup(struct libvchan *ctrl);
#endif /* _LIBVCHAN_H */