From: Jason Andryuk <jandryuk@gmail.com> To: "Marek Marczykowski-Górecki" <marmarek@invisiblethingslab.com> Cc: Stefano Stabellini <sstabellini@kernel.org>, Julien Grall <julien@xen.org>, Wei Liu <wl@xen.org>, Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>, George Dunlap <George.Dunlap@eu.citrix.com>, Andrew Cooper <andrew.cooper3@citrix.com>, Ian Jackson <ian.jackson@eu.citrix.com>, xen-devel <xen-devel@lists.xenproject.org> Subject: Re: [Xen-devel] [PATCH v4 11/16] tools: add simple vchan-socket-proxy Date: Tue, 21 Jan 2020 14:43:03 -0500 Message-ID: <CAKf6xpuQ1iggu6Lz8bcAWpGL732bXf3qwO9HYSd+8ScsNN2wnA@mail.gmail.com> (raw) In-Reply-To: <ce51dd78fd7aa0856d160b2d94c82f68dd4e7056.1579055705.git-series.marmarek@invisiblethingslab.com> On Tue, Jan 14, 2020 at 9:42 PM Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com> wrote: > > Add a simple proxy for tunneling socket connection over vchan. This is > based on existing vchan-node* applications, but extended with socket > support. vchan-socket-proxy serves both as a client and as a server, > depending on parameters. It can be used to transparently communicate > with an application in another domian that normally expose UNIX socket > interface. Specifically, it's written to communicate with qemu running > within stubdom. > > Server mode listens for vchan connections and when one is opened, > connects to a pointed UNIX socket. Client mode listens on UNIX > socket and when someone connects, opens a vchan connection. Only > a single connection at a time is supported. > > Additionally, socket can be provided as a number - in which case it's > interpreted as already open FD (in case of UNIX listening socket - > listen() needs to be already called). Or "-" meaning stdin/stdout - in > which case it is reduced to vchan-node2 functionality. > > Example usage: > > 1. (in dom0) vchan-socket-proxy --mode=client <DOMID> > /local/domain/<DOMID>/data/vchan/1234 /run/qemu.(DOMID) > > 2. (in DOMID) vchan-socket-proxy --mode=server 0 > /local/domain/<DOMID>/data/vchan/1234 /run/qemu.(DOMID) > > This will listen on /run/qemu.(DOMID) in dom0 and whenever connection is > made, it will connect to DOMID, where server process will connect to > /run/qemu.(DOMID) there. When client disconnects, vchan connection is > terminated and server vchan-socket-proxy process also disconnects from > qemu. > > Signed-off-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com> > --- Looks good. A few typos and string updates below. Reviewed-by: Jason Andryuk <jandryuk@gmail.com> <snip> > diff --git a/tools/libvchan/vchan-socket-proxy.c b/tools/libvchan/vchan-socket-proxy.c > new file mode 100644 > index 0000000..6b4ae09 > --- /dev/null > +++ b/tools/libvchan/vchan-socket-proxy.c <snip> > +static void usage(char** argv) > +{ > + fprintf(stderr, "usage:\n" > + "\t%s [options] domainid nodepath [socket-path|file-no|-]\n" > + "\n" > + "options:\n" > + "\t-m, --mode=client|server - vchan connection mode\n" Add "(client by default)"? > + "\t-m, --state-path=path - xenstore path where write \"running\" to at startup\n" -s is the short option here. > + "\t-v, --verbose - verbose logging\n" > + "\n" > + "client: client of a vchan connection, fourth parameter can be:\n" > + "\tsocket-path: listen on a UNIX socket at this path and connect to vchan\n" > + "\t whenever new connection is accepted;\n" > + "\t handle multiple _subsequent_ connections, until terminated\n" > + "\tfile-no: except open FD of a socket in listen mode; otherwise similar to socket-path\n" Many of these lines are long and hard to read on 80 column terminals. > + "\t-: open vchan connection immediately and pass the data from stdin/stdout;\n" > + "\t terminate when vchan connection is closed\n" > + "server: server of a vchan connection, fourth parameter can be:\n" > + "\tsocket-path: connect to this UNIX socket when new vchan connection is accepted\n" > + "\t handle multiple _subsequent_ connections, until terminated\n" > + "\tfile-no: pass data to/from this FD; terminate when vchan connection is closed\n" > + "\t-: pass data to/from stdin/stdout; terminatate when vchan connection is closed\n", s/terminatate/terminate/ > + argv[0]); > + exit(1); > +} > + > +#define BUFSIZE 8192 > +char inbuf[BUFSIZE]; > +char outbuf[BUFSIZE]; > +int insiz = 0; > +int outsiz = 0; > +int verbose = 0; > + > +static void vchan_wr(struct libxenvchan *ctrl) { > + int ret; > + > + if (!insiz) > + return; > + ret = libxenvchan_write(ctrl, inbuf, insiz); > + if (ret < 0) { > + fprintf(stderr, "vchan write failed\n"); > + exit(1); > + } > + if (verbose) > + fprintf(stderr, "written %d bytes to vchan\n", ret); s/written/wrote/ > + if (ret > 0) { > + insiz -= ret; > + memmove(inbuf, inbuf + ret, insiz); > + } > +} > + <snip> > + > +int data_loop(struct libxenvchan *ctrl, int input_fd, int output_fd) > +{ > + int ret; > + int libxenvchan_fd; > + int max_fd; > + > + libxenvchan_fd = libxenvchan_fd_for_select(ctrl); > + for (;;) { > + fd_set rfds; > + fd_set wfds; > + FD_ZERO(&rfds); > + FD_ZERO(&wfds); > + > + max_fd = -1; > + if (input_fd != -1 && insiz != BUFSIZE) { > + FD_SET(input_fd, &rfds); > + if (input_fd > max_fd) > + max_fd = input_fd; > + } > + if (output_fd != -1 && outsiz) { > + FD_SET(output_fd, &wfds); > + if (output_fd > max_fd) > + max_fd = output_fd; > + } > + FD_SET(libxenvchan_fd, &rfds); > + if (libxenvchan_fd > max_fd) > + max_fd = libxenvchan_fd; > + ret = select(max_fd + 1, &rfds, &wfds, NULL, NULL); > + if (ret < 0) { > + perror("select"); > + exit(1); > + } > + if (FD_ISSET(libxenvchan_fd, &rfds)) { > + libxenvchan_wait(ctrl); > + if (!libxenvchan_is_open(ctrl)) { > + if (verbose) > + fprintf(stderr, "vchan client disconnected\n"); > + while (outsiz) > + socket_wr(output_fd); > + close(output_fd); > + close(input_fd); > + discard_buffers(ctrl); > + break; > + } > + vchan_wr(ctrl); > + } > + > + /* socket_fd guaranteed to be != -1 */ Old comment? > + if (FD_ISSET(input_fd, &rfds)) { > + ret = read(input_fd, inbuf + insiz, BUFSIZE - insiz); > + if (ret < 0 && errno != EAGAIN) > + exit(1); > + if (verbose) > + fprintf(stderr, "from-unix: %.*s\n", ret, inbuf + insiz); > + if (ret == 0) { > + /* EOF on socket, write everything in the buffer and close the > + * socket */ Change to socket to input_fd? > + while (insiz) { > + vchan_wr(ctrl); > + libxenvchan_wait(ctrl); > + } > + close(input_fd); > + input_fd = -1; > + /* TODO: maybe signal the vchan client somehow? */ > + break; > + } > + if (ret) > + insiz += ret; > + vchan_wr(ctrl); > + } > + if (FD_ISSET(output_fd, &wfds)) > + socket_wr(output_fd); > + while (libxenvchan_data_ready(ctrl) && outsiz < BUFSIZE) { > + ret = libxenvchan_read(ctrl, outbuf + outsiz, BUFSIZE - outsiz); > + if (ret < 0) > + exit(1); > + if (verbose) > + fprintf(stderr, "from-vchan: %.*s\n", ret, outbuf + outsiz); > + outsiz += ret; > + socket_wr(output_fd); > + } > + } > + return 0; > +} > + <snip> _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel
next prev parent reply index Thread overview: 53+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-01-15 2:39 [Xen-devel] [PATCH v4 00/16] Add support for qemu-xen runnning in a Linux-based stubdomain Marek Marczykowski-Górecki 2020-01-15 2:39 ` [Xen-devel] [PATCH v4 01/16] Document ioemu MiniOS stubdomain protocol Marek Marczykowski-Górecki 2020-01-20 18:30 ` Jason Andryuk 2020-01-15 2:39 ` [Xen-devel] [PATCH v4 02/16] Document ioemu Linux " Marek Marczykowski-Górecki 2020-01-20 18:54 ` Jason Andryuk 2020-01-21 21:08 ` Marek Marczykowski-Górecki 2020-01-22 14:04 ` Jason Andryuk 2020-01-15 2:39 ` [Xen-devel] [PATCH v4 03/16] libxl: fix qemu-trad cmdline for no sdl/vnc case Marek Marczykowski-Górecki 2020-01-15 2:39 ` [Xen-devel] [PATCH v4 04/16] libxl: Allow running qemu-xen in stubdomain Marek Marczykowski-Górecki 2020-01-20 18:56 ` Jason Andryuk 2020-01-21 21:12 ` Marek Marczykowski-Górecki 2020-01-15 2:39 ` [Xen-devel] [PATCH v4 05/16] libxl: Handle Linux stubdomain specific QEMU options Marek Marczykowski-Górecki 2020-01-20 19:24 ` Jason Andryuk 2020-01-21 21:18 ` Marek Marczykowski-Górecki 2020-01-22 14:25 ` Jason Andryuk 2020-01-15 2:39 ` [Xen-devel] [PATCH v4 06/16] libxl: write qemu arguments into separate xenstore keys Marek Marczykowski-Górecki 2020-01-20 19:36 ` Jason Andryuk 2020-01-21 21:19 ` Marek Marczykowski-Górecki 2020-01-22 14:39 ` Jason Andryuk 2020-01-15 2:39 ` [Xen-devel] [PATCH v4 07/16] xl: add stubdomain related options to xl config parser Marek Marczykowski-Górecki 2020-01-20 19:41 ` Jason Andryuk 2020-01-21 21:22 ` Marek Marczykowski-Górecki 2020-01-22 14:39 ` Jason Andryuk 2020-01-15 2:39 ` [Xen-devel] [PATCH v4 08/16] tools/libvchan: notify server when client is connected Marek Marczykowski-Górecki 2020-01-20 19:44 ` Jason Andryuk 2020-01-21 21:28 ` Marek Marczykowski-Górecki 2020-01-22 14:43 ` Jason Andryuk 2020-01-15 2:39 ` [Xen-devel] [PATCH v4 09/16] libxl: add save/restore support for qemu-xen in stubdomain Marek Marczykowski-Górecki 2020-01-15 2:39 ` [Xen-devel] [PATCH v4 10/16] tools: add missing libxenvchan cflags Marek Marczykowski-Górecki 2020-01-20 19:58 ` Jason Andryuk 2020-01-15 2:39 ` [Xen-devel] [PATCH v4 11/16] tools: add simple vchan-socket-proxy Marek Marczykowski-Górecki 2020-01-15 11:02 ` Jan Beulich 2020-01-16 17:11 ` Marek Marczykowski-Górecki 2020-01-17 8:13 ` Jan Beulich 2020-01-17 18:44 ` Rich Persaud 2020-01-17 18:56 ` Marek Marczykowski-Górecki 2020-01-21 19:43 ` Jason Andryuk [this message] 2020-01-21 23:09 ` Marek Marczykowski-Górecki 2020-01-15 2:39 ` [Xen-devel] [PATCH v4 12/16] libxl: use vchan for QMP access with Linux stubdomain Marek Marczykowski-Górecki 2020-01-21 20:17 ` Jason Andryuk 2020-01-21 23:46 ` Marek Marczykowski-Górecki 2020-01-24 14:05 ` Jason Andryuk 2020-01-15 2:39 ` [Xen-devel] [PATCH v4 13/16] Regenerate autotools files Marek Marczykowski-Górecki 2020-01-15 21:57 ` Rich Persaud 2020-01-21 20:56 ` Marek Marczykowski-Górecki 2020-01-21 21:28 ` Rich Persaud 2020-01-22 8:57 ` Lars Kurth 2020-01-15 2:39 ` [Xen-devel] [PATCH v4 14/16] libxl: require qemu in dom0 even if stubdomain is in use Marek Marczykowski-Górecki 2020-01-15 2:39 ` [Xen-devel] [PATCH v4 15/16] libxl: ignore emulated IDE disks beyond the first 4 Marek Marczykowski-Górecki 2020-01-21 20:24 ` Jason Andryuk 2020-01-15 2:39 ` [Xen-devel] [PATCH v4 16/16] libxl: consider also qemu in stubdomain in libxl__dm_active check Marek Marczykowski-Górecki 2020-01-21 20:25 ` Jason Andryuk 2020-01-22 16:50 ` [Xen-devel] [PATCH v4 00/16] Add support for qemu-xen runnning in a Linux-based stubdomain Jason Andryuk
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=CAKf6xpuQ1iggu6Lz8bcAWpGL732bXf3qwO9HYSd+8ScsNN2wnA@mail.gmail.com \ --to=jandryuk@gmail.com \ --cc=George.Dunlap@eu.citrix.com \ --cc=andrew.cooper3@citrix.com \ --cc=ian.jackson@eu.citrix.com \ --cc=julien@xen.org \ --cc=konrad.wilk@oracle.com \ --cc=marmarek@invisiblethingslab.com \ --cc=sstabellini@kernel.org \ --cc=wl@xen.org \ --cc=xen-devel@lists.xenproject.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Xen-Devel Archive on lore.kernel.org Archives are clonable: git clone --mirror https://lore.kernel.org/xen-devel/0 xen-devel/git/0.git git clone --mirror https://lore.kernel.org/xen-devel/1 xen-devel/git/1.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 xen-devel xen-devel/ https://lore.kernel.org/xen-devel \ xen-devel@lists.xenproject.org xen-devel@lists.xen.org public-inbox-index xen-devel Example config snippet for mirrors Newsgroup available over NNTP: nntp://nntp.lore.kernel.org/org.xenproject.lists.xen-devel AGPL code for this site: git clone https://public-inbox.org/public-inbox.git