All of lore.kernel.org
 help / color / mirror / Atom feed
From: Anthony Liguori <aliguori@us.ibm.com>
To: zwu.kernel@gmail.com
Cc: Zhi Yong Wu <wuzhy@linux.vnet.ibm.com>,
	qemu-devel@nongnu.org, stefanha@linux.vnet.ibm.com
Subject: Re: [Qemu-devel] [PATCH v2] net: add the support for -netdev socket, listen
Date: Fri, 24 Feb 2012 09:05:52 -0600	[thread overview]
Message-ID: <4F47A750.4050305@us.ibm.com> (raw)
In-Reply-To: <1329556789-24944-1-git-send-email-zwu.kernel@gmail.com>

On 02/18/2012 03:19 AM, zwu.kernel@gmail.com wrote:
> From: Zhi Yong Wu<wuzhy@linux.vnet.ibm.com>
>
> The -net socket,listen option does not work with the newer -netdev
> syntax:
> http://lists.gnu.org/archive/html/qemu-devel/2011-11/msg01508.html
>
> This patch makes it work now.
>
> Signed-off-by: Zhi Yong Wu<wuzhy@linux.vnet.ibm.com>
> ---
>   net.c        |   26 +++++++++++++++++++++
>   net.h        |    2 +
>   net/socket.c |   72 +++++++++++++++++++++++++++++++++++++++++++++-------------
>   3 files changed, 84 insertions(+), 16 deletions(-)
>
> diff --git a/net.c b/net.c
> index c34474f..60e7b35 100644
> --- a/net.c
> +++ b/net.c
> @@ -190,6 +190,32 @@ static ssize_t qemu_deliver_packet_iov(VLANClientState *sender,
>                                          int iovcnt,
>                                          void *opaque);
>
> +VLANClientState *qemu_lookup_net_client(VLANState *vlan,
> +                                        const char *name)
> +{
> +    VLANClientState *vc = NULL;
> +
> +    if (vlan) {
> +        QTAILQ_FOREACH(vc,&vlan->clients, next) {
> +            if (!strcmp(vc->name, name)) {
> +                break;
> +            }
> +        }
> +    } else {
> +        QTAILQ_FOREACH(vc,&non_vlan_clients, next) {
> +            if (!strcmp(vc->name, name)) {
> +                break;
> +            }
> +        }
> +    }
> +
> +    if (!vc) {
> +        return NULL;
> +    }
> +
> +    return vc;
> +}
> +
>   VLANClientState *qemu_new_net_client(NetClientInfo *info,
>                                        VLANState *vlan,
>                                        VLANClientState *peer,
> diff --git a/net.h b/net.h
> index 75a8c15..7f73160 100644
> --- a/net.h
> +++ b/net.h
> @@ -90,6 +90,8 @@ struct VLANState {
>
>   VLANState *qemu_find_vlan(int id, int allocate);
>   VLANClientState *qemu_find_netdev(const char *id);
> +VLANClientState *qemu_lookup_net_client(VLANState *vlan,
> +                                        const char *name);
>   VLANClientState *qemu_new_net_client(NetClientInfo *info,
>                                        VLANState *vlan,
>                                        VLANClientState *peer,
> diff --git a/net/socket.c b/net/socket.c
> index d4c2002..3ecee59 100644
> --- a/net/socket.c
> +++ b/net/socket.c
> @@ -43,6 +43,7 @@ typedef struct NetSocketState {
>   } NetSocketState;
>
>   typedef struct NetSocketListenState {
> +    VLANClientState *nc;
>       VLANState *vlan;
>       char *model;
>       char *name;
> @@ -247,7 +248,8 @@ static NetClientInfo net_dgram_socket_info = {
>   static NetSocketState *net_socket_fd_init_dgram(VLANState *vlan,
>                                                   const char *model,
>                                                   const char *name,
> -                                                int fd, int is_connected)
> +                                                int fd, int is_connected,
> +                                                int is_listen)
>   {
>       struct sockaddr_in saddr;
>       int newfd;
> @@ -286,15 +288,28 @@ static NetSocketState *net_socket_fd_init_dgram(VLANState *vlan,
>           }
>       }
>
> -    nc = qemu_new_net_client(&net_dgram_socket_info, vlan, NULL, model, name);
> +
> +    if (!is_listen || (is_listen&&  !is_connected)) {
> +        nc = qemu_new_net_client(&net_dgram_socket_info,
> +                                 vlan, NULL, model, name);
> +    } else {
> +        nc = qemu_lookup_net_client(vlan, name);
> +        if (!nc) {
> +            goto err;
> +        }
> +    }
> +
> +    s = DO_UPCAST(NetSocketState, nc, nc);
> +
> +    if (is_listen&&  !is_connected) {
> +        return s;
> +    }
>
>       snprintf(nc->info_str, sizeof(nc->info_str),
>               "socket: fd=%d (%s mcast=%s:%d)",
>               fd, is_connected ? "cloned" : "",
>               inet_ntoa(saddr.sin_addr), ntohs(saddr.sin_port));
>
> -    s = DO_UPCAST(NetSocketState, nc, nc);
> -
>       s->fd = fd;
>
>       qemu_set_fd_handler(s->fd, net_socket_send_dgram, NULL, s);
> @@ -325,16 +340,29 @@ static NetClientInfo net_socket_info = {
>   static NetSocketState *net_socket_fd_init_stream(VLANState *vlan,
>                                                    const char *model,
>                                                    const char *name,
> -                                                 int fd, int is_connected)
> +                                                 int fd, int is_connected,
> +                                                 int is_listen)
>   {
>       VLANClientState *nc;
>       NetSocketState *s;
>
> -    nc = qemu_new_net_client(&net_socket_info, vlan, NULL, model, name);
> +    if (!is_listen || (is_listen&&  !is_connected)) {
> +        nc = qemu_new_net_client(&net_socket_info, vlan, NULL, model, name);
> +    } else {
> +        nc = qemu_lookup_net_client(vlan, name);
> +        if (!nc) {
> +            return NULL;
> +        }
> +    }
> +
> +    s = DO_UPCAST(NetSocketState, nc, nc);
> +
> +    if (is_listen&&  !is_connected) {
> +        return s;
> +    }
>
>       snprintf(nc->info_str, sizeof(nc->info_str), "socket: fd=%d", fd);
>
> -    s = DO_UPCAST(NetSocketState, nc, nc);
>
>       s->fd = fd;
>
> @@ -348,7 +376,8 @@ static NetSocketState *net_socket_fd_init_stream(VLANState *vlan,
>
>   static NetSocketState *net_socket_fd_init(VLANState *vlan,
>                                             const char *model, const char *name,
> -                                          int fd, int is_connected)
> +                                          int fd, int is_connected,
> +                                          int is_listen)
>   {
>       int so_type = -1, optlen=sizeof(so_type);
>
> @@ -361,13 +390,16 @@ static NetSocketState *net_socket_fd_init(VLANState *vlan,
>       }
>       switch(so_type) {
>       case SOCK_DGRAM:
> -        return net_socket_fd_init_dgram(vlan, model, name, fd, is_connected);
> +        return net_socket_fd_init_dgram(vlan, model,
> +                                        name, fd, is_connected, is_listen);
>       case SOCK_STREAM:
> -        return net_socket_fd_init_stream(vlan, model, name, fd, is_connected);
> +        return net_socket_fd_init_stream(vlan, model,
> +                                         name, fd, is_connected, is_listen);
>       default:
>           /* who knows ... this could be a eg. a pty, do warn and continue as stream */
>           fprintf(stderr, "qemu: warning: socket type=%d for fd=%d is not SOCK_DGRAM or SOCK_STREAM\n", so_type, fd);
> -        return net_socket_fd_init_stream(vlan, model, name, fd, is_connected);
> +        return net_socket_fd_init_stream(vlan, model,
> +                                         name, fd, is_connected, is_listen);
>       }
>       return NULL;
>   }
> @@ -389,14 +421,17 @@ static void net_socket_accept(void *opaque)
>               break;
>           }
>       }
> -    s1 = net_socket_fd_init(s->vlan, s->model, s->name, fd, 1);
> +
> +    s1 = net_socket_fd_init(s->vlan, s->model, s->name, fd, 1, 1);
>       if (s1) {
>           snprintf(s1->nc.info_str, sizeof(s1->nc.info_str),
>                    "socket: connection from %s:%d",
>                    inet_ntoa(saddr.sin_addr), ntohs(saddr.sin_port));
> +        s1->nc.link_down = false;

I find this to be a little odd.  Nothing else uses link_down link this.  Why are 
you setting this flag?

Regards,

Anthony Liguori

  reply	other threads:[~2012-02-24 15:08 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-18  9:19 [Qemu-devel] [PATCH v2] net: add the support for -netdev socket, listen zwu.kernel
2012-02-24 15:05 ` Anthony Liguori [this message]
2012-02-24 16:50   ` Zhi Yong Wu
2012-02-24 17:00   ` Zhi Yong Wu
2012-02-26 14:48 ` Stefan Hajnoczi
2012-02-27  7:28   ` Zhi Yong Wu
2012-05-28  7:49   ` Zhi Yong Wu
2012-05-28 10:51     ` Stefan Hajnoczi
2012-05-28 13:13       ` Zhi Yong Wu
2012-06-03 14:35   ` Zhi Yong Wu

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=4F47A750.4050305@us.ibm.com \
    --to=aliguori@us.ibm.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@linux.vnet.ibm.com \
    --cc=wuzhy@linux.vnet.ibm.com \
    --cc=zwu.kernel@gmail.com \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.