qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] specify vmchannel as part of "user" net option
@ 2009-01-11 15:10 Gleb Natapov
  2009-01-15 20:24 ` Anthony Liguori
  0 siblings, 1 reply; 5+ messages in thread
From: Gleb Natapov @ 2009-01-11 15:10 UTC (permalink / raw)
  To: qemu-devel

To configure vmchannel and something like this to -net user:
 channels=666:unix:/tmp/666,server,nowait;777:unix:/tmp/777,server

The parsing is little ugly :(

Signed-off-by: Gleb Natapov <gleb@redhat.com>
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.

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PATCH] specify vmchannel as part of "user" net option
  2009-01-11 15:10 [Qemu-devel] [PATCH] specify vmchannel as part of "user" net option Gleb Natapov
@ 2009-01-15 20:24 ` Anthony Liguori
  2009-01-15 20:54   ` Gleb Natapov
  0 siblings, 1 reply; 5+ messages in thread
From: Anthony Liguori @ 2009-01-15 20:24 UTC (permalink / raw)
  To: qemu-devel

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 <gleb@redhat.com>
> 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.
>
>
>   

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PATCH] specify vmchannel as part of "user" net option
  2009-01-15 20:24 ` Anthony Liguori
@ 2009-01-15 20:54   ` Gleb Natapov
  2009-01-15 21:27     ` Anthony Liguori
  2009-01-15 23:58     ` Daniel P. Berrange
  0 siblings, 2 replies; 5+ messages in thread
From: Gleb Natapov @ 2009-01-15 20:54 UTC (permalink / raw)
  To: qemu-devel

On Thu, Jan 15, 2009 at 02:24:05PM -0600, Anthony Liguori wrote:
> 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?
>
I can't say I like it, but we can't use ',' and ':' as parsing will be
ambiguous. So what's left?

--
			Gleb.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PATCH] specify vmchannel as part of "user" net option
  2009-01-15 20:54   ` Gleb Natapov
@ 2009-01-15 21:27     ` Anthony Liguori
  2009-01-15 23:58     ` Daniel P. Berrange
  1 sibling, 0 replies; 5+ messages in thread
From: Anthony Liguori @ 2009-01-15 21:27 UTC (permalink / raw)
  To: qemu-devel

Gleb Natapov wrote:
> On Thu, Jan 15, 2009 at 02:24:05PM -0600, Anthony Liguori wrote:
>   
>> 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?
>>
>>     
> I can't say I like it, but we can't use ',' and ':' as parsing will be
> ambiguous. So what's left?
>   

Brilliantly innovative alternative syntaxes?

If we can't think of anything better, I guess we're stuck with the 
semicolons, but they have to be escaped on the command line so it's 
extremely annoying.

Regards,

Anthony Liguori

> --
> 			Gleb.
>
>
>   

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PATCH] specify vmchannel as part of "user" net option
  2009-01-15 20:54   ` Gleb Natapov
  2009-01-15 21:27     ` Anthony Liguori
@ 2009-01-15 23:58     ` Daniel P. Berrange
  1 sibling, 0 replies; 5+ messages in thread
From: Daniel P. Berrange @ 2009-01-15 23:58 UTC (permalink / raw)
  To: qemu-devel

On Thu, Jan 15, 2009 at 10:54:59PM +0200, Gleb Natapov wrote:
> On Thu, Jan 15, 2009 at 02:24:05PM -0600, Anthony Liguori wrote:
> > 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?
> >
> I can't say I like it, but we can't use ',' and ':' as parsing will be
> ambiguous. So what's left?

Perhaps this is a sign that we should not try to overload it all into
one argument after all. How about just having a separate -net option
for each channel we wish to hook onto a NIC - a little cleverness
behind the scenes could make them all backed by a single Slirp device,
without forcing them to use a single ARGV for config

eg

  qemu -net nic,vlan=8 \
     -net channel=666,vlan=8,:unix:/tmp/666,server,nowait \
     -net channel=777,vlan=8,:unix:/tmp/777,server

Regards,
Daniel 
--
|: Red Hat, Engineering, London   -o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org  -o-  http://virt-manager.org  -o-  http://ovirt.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-  F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2009-01-15 23:58 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-01-11 15:10 [Qemu-devel] [PATCH] specify vmchannel as part of "user" net option Gleb Natapov
2009-01-15 20:24 ` Anthony Liguori
2009-01-15 20:54   ` Gleb Natapov
2009-01-15 21:27     ` Anthony Liguori
2009-01-15 23:58     ` Daniel P. Berrange

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).