qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Stefan Hajnoczi <stefanha@gmail.com>
To: David Marchand <david.marchand@6wind.com>
Cc: Olivier Matz <olivier.matz@6wind.com>,
	kvm@vger.kernel.org, claudio.fontana@huawei.com,
	armbru@redhat.com, qemu-devel@nongnu.org, pbonzini@redhat.com,
	jani.kokkonen@huawei.com, cam@cs.ualberta.ca
Subject: Re: [Qemu-devel] [PATCH v3 1/2] contrib: add ivshmem client and server
Date: Fri, 8 Aug 2014 15:51:32 +0100	[thread overview]
Message-ID: <20140808145132.GC13382@stefanha-thinkpad.redhat.com> (raw)
In-Reply-To: <1407488118-11245-2-git-send-email-david.marchand@6wind.com>

[-- Attachment #1: Type: text/plain, Size: 4157 bytes --]

On Fri, Aug 08, 2014 at 10:55:17AM +0200, David Marchand wrote:

Looks good, a few minor comments:

> diff --git a/contrib/ivshmem-client/Makefile b/contrib/ivshmem-client/Makefile
> new file mode 100644
> index 0000000..eee97c6
> --- /dev/null
> +++ b/contrib/ivshmem-client/Makefile
> @@ -0,0 +1,29 @@
> +# Copyright 6WIND S.A., 2014
> +#
> +# This work is licensed under the terms of the GNU GPL, version 2 or
> +# (at your option) any later version.  See the COPYING file in the
> +# top-level directory.
> +
> +S ?= $(CURDIR)
> +O ?= $(CURDIR)
> +
> +CFLAGS += -Wall -Wextra -Werror -g
> +LDFLAGS +=
> +LDLIBS += -lrt
> +
> +VPATH = $(S)
> +PROG = ivshmem-client
> +OBJS := $(O)/ivshmem-client.o
> +OBJS += $(O)/main.o
> +
> +$(O)/%.o: %.c
> +	$(CC) $(CFLAGS) -o $@ -c $<
> +
> +$(O)/$(PROG): $(OBJS)
> +	$(CC) $(LDFLAGS) -o $@ $^ $(LDLIBS)
> +
> +.PHONY: all
> +all: $(O)/$(PROG)
> +
> +clean:
> +	rm -f $(OBJS) $(O)/$(PROG)

CCed Peter Maydell for a second opinion, I'd suggest hooking up to
QEMU's top-level ./Makefile.  QEMU does not do recursive make.

The advantages of hooking up QEMU's Makefile are:

1. So that ivshmem client/server code is built by default (on supported
   host platforms) and bitrot is avoided.

2. So that you don't have to duplicate rules.mak or any other build
   infrastructure.

> +/**
> + * Structure storing a peer
> + *
> + * Each time a client connects to an ivshmem server, it is advertised to
> + * all connected clients through the unix socket. When our ivshmem
> + * client receives a notification, it creates a ivshmem_client_peer
> + * structure to store the infos of this peer.
> + *
> + * This structure is also used to store the information of our own
> + * client in (struct ivshmem_client)->local.
> + */
> +struct ivshmem_client_peer {
> +    TAILQ_ENTRY(ivshmem_client_peer) next;    /**< next in list*/
> +    long id;                                    /**< the id of the peer */
> +    int vectors[IVSHMEM_CLIENT_MAX_VECTORS];  /**< one fd per vector */
> +    unsigned vectors_count;                     /**< number of vectors */
> +};

It would be nice to follow QEMU coding style:
typedef struct IvshmemClientPeer {
    ...
} IvshmemClientPeer;

(Use scripts/checkpatch.pl to check coding style)

> +/* browse the queue, allowing to remove/free the current element */
> +#define    TAILQ_FOREACH_SAFE(var, var2, head, field)            \
> +    for ((var) = TAILQ_FIRST((head)),                            \
> +             (var2) = ((var) ? TAILQ_NEXT((var), field) : NULL); \
> +         (var);                                                  \
> +         (var) = (var2),                                         \
> +             (var2) = ((var2) ? TAILQ_NEXT((var2), field) : NULL))

Please reuse include/qemu/queue.h.  It's a copy of the BSD <sys/queue.h>
and it has QTAILQ_FOREACH_SAFE().

> +    ret = sendmsg(sock_fd, &msg, 0);
> +    if (ret <= 0) {
> +        return -1;
> +    }

This is a blocking sendmsg(2) so it could hang the server if sock_fd's
sndbuf fills up.  This shouldn't happen since the amount of data that
gets sent in the lifetime of a session is relatively small, but there is
a chance.

If hung clients should not be able to block the server then sock_fd
needs to be non-blocking.

> +struct ivshmem_server {
> +    char unix_sock_path[PATH_MAX];  /**< path to unix socket */
> +    int sock_fd;                    /**< unix sock file descriptor */
> +    char shm_path[PATH_MAX];        /**< path to shm */
> +    size_t shm_size;                /**< size of shm */
> +    int shm_fd;                     /**< shm file descriptor */
> +    unsigned n_vectors;             /**< number of vectors */
> +    long cur_id;                    /**< id to be given to next client */
> +    int verbose;                    /**< true in verbose mode */

C99 bool is fine to use in QEMU code.  It makes the code easier to read
because you can be sure something is just true/false and not a bitmap or
integer counter.

> +/* parse the size of shm */
> +static int
> +parse_size(const char *val_str, size_t *val)

Looks similar to QEMU's util/qemu-option.c:parse_option_size().

[-- Attachment #2: Type: application/pgp-signature, Size: 473 bytes --]

  reply	other threads:[~2014-08-08 14:51 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-08  8:55 [Qemu-devel] [PATCH v3 0/2] ivshmem: update documentation, add client/server tools David Marchand
2014-08-08  8:55 ` [Qemu-devel] [PATCH v3 1/2] contrib: add ivshmem client and server David Marchand
2014-08-08 14:51   ` Stefan Hajnoczi [this message]
2014-08-18 12:09     ` David Marchand
2014-08-10  3:57   ` Gonglei
2014-08-18 12:19     ` David Marchand
2014-08-08  8:55 ` [Qemu-devel] [PATCH v3 2/2] docs: update ivshmem device spec David Marchand
2014-08-08  9:04   ` Claudio Fontana
2014-08-08  9:32     ` David Marchand
2014-08-08 15:02   ` Stefan Hajnoczi
2014-08-26  6:47     ` David Marchand
2014-08-26 11:04       ` Paolo Bonzini
2014-08-28  9:49         ` Stefan Hajnoczi
2014-09-01  9:52           ` David Marchand
2014-09-09 19:04             ` Eric Blake
2014-08-08  9:30 ` [Qemu-devel] [PATCH v3 0/2] ivshmem: update documentation, add client/server tools Gonglei (Arei)
2014-08-08  9:54   ` David Marchand
2014-08-08 10:26     ` Gonglei (Arei)

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=20140808145132.GC13382@stefanha-thinkpad.redhat.com \
    --to=stefanha@gmail.com \
    --cc=armbru@redhat.com \
    --cc=cam@cs.ualberta.ca \
    --cc=claudio.fontana@huawei.com \
    --cc=david.marchand@6wind.com \
    --cc=jani.kokkonen@huawei.com \
    --cc=kvm@vger.kernel.org \
    --cc=olivier.matz@6wind.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).