* [Qemu-devel] [RESEND][PATCH] specify vmchannel as a net option
@ 2009-01-22 14:22 Gleb Natapov
2009-01-22 16:12 ` Anthony Liguori
0 siblings, 1 reply; 2+ messages in thread
From: Gleb Natapov @ 2009-01-22 14:22 UTC (permalink / raw)
To: qemu-devel
Another version. Try to maintain balance between command
line ugliness and parsing ugliness.
To configure vmchannel use:
-net channel,666:unix:/tmp/666,server,nowait
Signed-off-by: Gleb Natapov <gleb@redhat.com>
diff --git a/net.c b/net.c
index 86ee7d5..35728dd 100644
--- a/net.c
+++ b/net.c
@@ -644,6 +644,23 @@ void do_info_slirp(void)
slirp_stats();
}
+struct VMChannel {
+ CharDriverState *hd;
+ int port;
+} *vmchannels;
+
+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)
@@ -1604,6 +1621,30 @@ int net_client_init(const char *device, const char *p)
}
vlan->nb_host_devs++;
ret = net_slirp_init(vlan, device, name);
+ } else if (!strcmp(device, "channel")) {
+ long port;
+ char name[20], *devname;
+ struct VMChannel *vmc;
+
+ port = strtol(p, &devname, 10);
+ devname++;
+ if (port < 1 || port > 65535) {
+ fprintf(stderr, "vmchannel wrong port number\n");
+ return -1;
+ }
+ vmc = malloc(sizeof(struct VMChannel));
+ snprintf(name, 20, "vmchannel%ld", port);
+ 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);
+ ret = 0;
} else
#endif
#ifdef _WIN32
--
Gleb.
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [Qemu-devel] [RESEND][PATCH] specify vmchannel as a net option
2009-01-22 14:22 [Qemu-devel] [RESEND][PATCH] specify vmchannel as a net option Gleb Natapov
@ 2009-01-22 16:12 ` Anthony Liguori
0 siblings, 0 replies; 2+ messages in thread
From: Anthony Liguori @ 2009-01-22 16:12 UTC (permalink / raw)
To: qemu-devel
Gleb Natapov wrote:
> Another version. Try to maintain balance between command
> line ugliness and parsing ugliness.
>
> To configure vmchannel use:
> -net channel,666:unix:/tmp/666,server,nowait
>
> Signed-off-by: Gleb Natapov <gleb@redhat.com>
>
Can you add some docs to qemu-doc.texi?
Regards,
Anthony Liguori
> diff --git a/net.c b/net.c
> index 86ee7d5..35728dd 100644
> --- a/net.c
> +++ b/net.c
> @@ -644,6 +644,23 @@ void do_info_slirp(void)
> slirp_stats();
> }
>
> +struct VMChannel {
> + CharDriverState *hd;
> + int port;
> +} *vmchannels;
> +
> +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)
> @@ -1604,6 +1621,30 @@ int net_client_init(const char *device, const char *p)
> }
> vlan->nb_host_devs++;
> ret = net_slirp_init(vlan, device, name);
> + } else if (!strcmp(device, "channel")) {
> + long port;
> + char name[20], *devname;
> + struct VMChannel *vmc;
> +
> + port = strtol(p, &devname, 10);
> + devname++;
> + if (port < 1 || port > 65535) {
> + fprintf(stderr, "vmchannel wrong port number\n");
> + return -1;
> + }
> + vmc = malloc(sizeof(struct VMChannel));
> + snprintf(name, 20, "vmchannel%ld", port);
> + 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);
> + ret = 0;
> } else
> #endif
> #ifdef _WIN32
> --
> Gleb.
>
>
>
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2009-01-22 16:12 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-01-22 14:22 [Qemu-devel] [RESEND][PATCH] specify vmchannel as a net option Gleb Natapov
2009-01-22 16:12 ` Anthony Liguori
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).