From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LNYlJ-0004v3-8I for qemu-devel@nongnu.org; Thu, 15 Jan 2009 15:24:21 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LNYlH-0004sO-Hm for qemu-devel@nongnu.org; Thu, 15 Jan 2009 15:24:20 -0500 Received: from [199.232.76.173] (port=38721 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LNYlH-0004s7-DA for qemu-devel@nongnu.org; Thu, 15 Jan 2009 15:24:19 -0500 Received: from mail-qy0-f20.google.com ([209.85.221.20]:50745) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1LNYlG-00064Z-Vz for qemu-devel@nongnu.org; Thu, 15 Jan 2009 15:24:19 -0500 Received: by qyk13 with SMTP id 13so1907485qyk.10 for ; Thu, 15 Jan 2009 12:24:18 -0800 (PST) Message-ID: <496F9B65.2030102@codemonkey.ws> Date: Thu, 15 Jan 2009 14:24:05 -0600 From: Anthony Liguori MIME-Version: 1.0 Subject: Re: [Qemu-devel] [PATCH] specify vmchannel as part of "user" net option References: <20090111151008.GL3267@redhat.com> In-Reply-To: <20090111151008.GL3267@redhat.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Gleb Natapov wrote: > To configure vmchannel and something like this to -net user: > channels=;777:unix:/tmp/777,server > I'd really like to avoid using ';' as a deliminator. Is the a more clever way we can do this without it totally sucking? Regards, Anthony Liguori > The parsing is little ugly :( > > Signed-off-by: Gleb Natapov > diff --git a/net.c b/net.c > index 30ba717..47e7e40 100644 > --- a/net.c > +++ b/net.c > @@ -644,6 +644,23 @@ void do_info_slirp(void) > slirp_stats(); > } > > +struct VMChannel { > + CharDriverState *hd; > + int port; > +}; > + > +static int vmchannel_can_read(void *opaque) > +{ > + struct VMChannel *vmc = (struct VMChannel*)opaque; > + return slirp_socket_can_recv(4, vmc->port); > +} > + > +static void vmchannel_read(void *opaque, const uint8_t *buf, int size) > +{ > + struct VMChannel *vmc = (struct VMChannel*)opaque; > + slirp_socket_recv(4, vmc->port, buf, size); > +} > + > #endif /* CONFIG_SLIRP */ > > #if !defined(_WIN32) > @@ -1556,6 +1573,7 @@ int net_client_init(const char *device, const char *p) > } else > #ifdef CONFIG_SLIRP > if (!strcmp(device, "user")) { > + char *c; > if (get_param_value(buf, sizeof(buf), "hostname", p)) { > pstrcpy(slirp_hostname, sizeof(slirp_hostname), buf); > } > @@ -1565,6 +1583,53 @@ int net_client_init(const char *device, const char *p) > if (get_param_value(buf, sizeof(buf), "ip", p)) { > slirp_ip = strdup(buf); > } > + if ((c = strstr(p, "channels="))) { > + int len; > + char *e; > + c += strlen("channels="); > + e = index(c, '='); > + if (e != NULL) { > + e = rindex(c, ','); > + len = e - c; > + } else { > + len = strlen(c); > + } > + if (len >= sizeof(buf)) { > + fprintf(stderr, "vmchannel parameter is too long\n"); > + return -1; > + } > + memcpy(buf, c, len); > + buf[len + 1] = '\0'; > + c = buf; > + while (c && *c != '\0') { > + int port; > + char name[20], *devname; > + struct VMChannel *vmc; > + > + if (*c == ';') > + c++; > + > + port = strtol(c, &c, 10); > + c++; > + if (port < 1 || port > 65535) { > + fprintf(stderr, "vmchannel: wrong port number\n"); > + return -1; > + } > + snprintf(name, 20, "vmchannel%u\n", port); > + devname = strsep(&c, ";"); > + vmc = malloc(sizeof(struct VMChannel)); > + vmc->hd = qemu_chr_open(name, devname); > + if (!vmc->hd) { > + fprintf(stderr, "qemu: could not open vmchannel device" > + "'%s'\n", devname); > + return -1; > + } > + vmc->port = port; > + slirp_add_exec(3, vmc->hd, 4, port); > + qemu_chr_add_handlers(vmc->hd, vmchannel_can_read, > + vmchannel_read, NULL, vmc); > + } > + } > vlan->nb_host_devs++; > ret = net_slirp_init(vlan, device, name); > } else > -- > Gleb. > > >