From: Greg Kurz <groug@kaod.org>
To: Stefano Stabellini <sstabellini@kernel.org>
Cc: aneesh.kumar@linux.vnet.ibm.com, qemu-devel@nongnu.org,
xen-devel@lists.xensource.com, anthony.perard@citrix.com
Subject: Re: [Qemu-devel] [PATCH v2 2/4] 9pfs: introduce transport specific callbacks
Date: Fri, 2 Dec 2016 12:03:30 +0100 [thread overview]
Message-ID: <20161202120330.733c02d5@bahia> (raw)
In-Reply-To: <1480368444-4310-2-git-send-email-sstabellini@kernel.org>
On Mon, 28 Nov 2016 13:27:22 -0800
Stefano Stabellini <sstabellini@kernel.org> wrote:
> Don't call virtio functions from 9pfs generic code, use generic function
> callbacks instead.
>
> Signed-off-by: Stefano Stabellini <sstabellini@kernel.org>
>
> ---
Reviewed-by: Greg Kurz <groug@kaod.org>
> Changes in v2:
> - constify virtio_9p_transport and V9fsTransport
> - assert !s->transport.
> - code style
> ---
> hw/9pfs/9p.c | 8 ++++----
> hw/9pfs/9p.h | 19 +++++++++++++++++++
> hw/9pfs/virtio-9p-device.c | 24 +++++++++++++++++-------
> hw/9pfs/virtio-9p.h | 9 ---------
> 4 files changed, 40 insertions(+), 20 deletions(-)
>
> diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c
> index 05e950f..5a20a13 100644
> --- a/hw/9pfs/9p.c
> +++ b/hw/9pfs/9p.c
> @@ -47,7 +47,7 @@ ssize_t pdu_marshal(V9fsPDU *pdu, size_t offset, const char *fmt, ...)
> va_list ap;
>
> va_start(ap, fmt);
> - ret = virtio_pdu_vmarshal(pdu, offset, fmt, ap);
> + ret = pdu->s->transport->pdu_vmarshal(pdu, offset, fmt, ap);
> va_end(ap);
>
> return ret;
> @@ -59,7 +59,7 @@ ssize_t pdu_unmarshal(V9fsPDU *pdu, size_t offset, const char *fmt, ...)
> va_list ap;
>
> va_start(ap, fmt);
> - ret = virtio_pdu_vunmarshal(pdu, offset, fmt, ap);
> + ret = pdu->s->transport->pdu_vunmarshal(pdu, offset, fmt, ap);
> va_end(ap);
>
> return ret;
> @@ -67,7 +67,7 @@ ssize_t pdu_unmarshal(V9fsPDU *pdu, size_t offset, const char *fmt, ...)
>
> static void pdu_push_and_notify(V9fsPDU *pdu)
> {
> - virtio_9p_push_and_notify(pdu);
> + pdu->s->transport->push_and_notify(pdu);
> }
>
> static int omode_to_uflags(int8_t mode)
> @@ -1751,7 +1751,7 @@ static void v9fs_init_qiov_from_pdu(QEMUIOVector *qiov, V9fsPDU *pdu,
> struct iovec *iov;
> unsigned int niov;
>
> - virtio_init_iov_from_pdu(pdu, &iov, &niov, is_write);
> + pdu->s->transport->init_iov_from_pdu(pdu, &iov, &niov, is_write);
>
> qemu_iovec_init_external(&elem, iov, niov);
> qemu_iovec_init(qiov, niov);
> diff --git a/hw/9pfs/9p.h b/hw/9pfs/9p.h
> index 07cee01..c8c9aa8 100644
> --- a/hw/9pfs/9p.h
> +++ b/hw/9pfs/9p.h
> @@ -230,6 +230,7 @@ typedef struct V9fsState
> enum p9_proto_version proto_version;
> int32_t msize;
> V9fsPDU pdus[MAX_REQ];
> + const struct V9fsTransport *transport;
> /*
> * lock ensuring atomic path update
> * on rename.
> @@ -343,4 +344,22 @@ void pdu_free(V9fsPDU *pdu);
> void pdu_submit(V9fsPDU *pdu);
> void v9fs_reset(V9fsState *s);
>
> +struct V9fsTransport {
> + ssize_t (*pdu_vmarshal)(V9fsPDU *pdu, size_t offset, const char *fmt,
> + va_list ap);
> + ssize_t (*pdu_vunmarshal)(V9fsPDU *pdu, size_t offset, const char *fmt,
> + va_list ap);
> + void (*init_iov_from_pdu)(V9fsPDU *pdu, struct iovec **piov,
> + unsigned int *pniov, bool is_write);
> + void (*push_and_notify)(V9fsPDU *pdu);
> +};
> +
> +static inline int v9fs_register_transport(V9fsState *s,
> + const struct V9fsTransport *t)
> +{
> + assert(!s->transport);
> + s->transport = t;
> + return 0;
> +}
> +
> #endif
> diff --git a/hw/9pfs/virtio-9p-device.c b/hw/9pfs/virtio-9p-device.c
> index 1782e4a..273425b 100644
> --- a/hw/9pfs/virtio-9p-device.c
> +++ b/hw/9pfs/virtio-9p-device.c
> @@ -20,7 +20,9 @@
> #include "hw/virtio/virtio-access.h"
> #include "qemu/iov.h"
>
> -void virtio_9p_push_and_notify(V9fsPDU *pdu)
> +static const struct V9fsTransport virtio_9p_transport;
> +
> +static void virtio_9p_push_and_notify(V9fsPDU *pdu)
> {
> V9fsState *s = pdu->s;
> V9fsVirtioState *v = container_of(s, V9fsVirtioState, state);
> @@ -126,6 +128,7 @@ static void virtio_9p_device_realize(DeviceState *dev, Error **errp)
> v->config_size = sizeof(struct virtio_9p_config) + strlen(s->fsconf.tag);
> virtio_init(vdev, "virtio-9p", VIRTIO_ID_9P, v->config_size);
> v->vq = virtio_add_queue(vdev, MAX_REQ, handle_9p_output);
> + v9fs_register_transport(s, &virtio_9p_transport);
>
> out:
> return;
> @@ -148,8 +151,8 @@ static void virtio_9p_reset(VirtIODevice *vdev)
> v9fs_reset(&v->state);
> }
>
> -ssize_t virtio_pdu_vmarshal(V9fsPDU *pdu, size_t offset,
> - const char *fmt, va_list ap)
> +static ssize_t virtio_pdu_vmarshal(V9fsPDU *pdu, size_t offset,
> + const char *fmt, va_list ap)
> {
> V9fsState *s = pdu->s;
> V9fsVirtioState *v = container_of(s, V9fsVirtioState, state);
> @@ -158,8 +161,8 @@ ssize_t virtio_pdu_vmarshal(V9fsPDU *pdu, size_t offset,
> return v9fs_iov_vmarshal(elem->in_sg, elem->in_num, offset, 1, fmt, ap);
> }
>
> -ssize_t virtio_pdu_vunmarshal(V9fsPDU *pdu, size_t offset,
> - const char *fmt, va_list ap)
> +static ssize_t virtio_pdu_vunmarshal(V9fsPDU *pdu, size_t offset,
> + const char *fmt, va_list ap)
> {
> V9fsState *s = pdu->s;
> V9fsVirtioState *v = container_of(s, V9fsVirtioState, state);
> @@ -168,8 +171,8 @@ ssize_t virtio_pdu_vunmarshal(V9fsPDU *pdu, size_t offset,
> return v9fs_iov_vunmarshal(elem->out_sg, elem->out_num, offset, 1, fmt, ap);
> }
>
> -void virtio_init_iov_from_pdu(V9fsPDU *pdu, struct iovec **piov,
> - unsigned int *pniov, bool is_write)
> +static void virtio_init_iov_from_pdu(V9fsPDU *pdu, struct iovec **piov,
> + unsigned int *pniov, bool is_write)
> {
> V9fsState *s = pdu->s;
> V9fsVirtioState *v = container_of(s, V9fsVirtioState, state);
> @@ -184,6 +187,13 @@ void virtio_init_iov_from_pdu(V9fsPDU *pdu, struct iovec **piov,
> }
> }
>
> +static const struct V9fsTransport virtio_9p_transport = {
> + .pdu_vmarshal = virtio_pdu_vmarshal,
> + .pdu_vunmarshal = virtio_pdu_vunmarshal,
> + .init_iov_from_pdu = virtio_init_iov_from_pdu,
> + .push_and_notify = virtio_9p_push_and_notify,
> +};
> +
> /* virtio-9p device */
>
> static const VMStateDescription vmstate_virtio_9p = {
> diff --git a/hw/9pfs/virtio-9p.h b/hw/9pfs/virtio-9p.h
> index 52c4b9d..e763da2c 100644
> --- a/hw/9pfs/virtio-9p.h
> +++ b/hw/9pfs/virtio-9p.h
> @@ -14,15 +14,6 @@ typedef struct V9fsVirtioState
> V9fsState state;
> } V9fsVirtioState;
>
> -void virtio_9p_push_and_notify(V9fsPDU *pdu);
> -
> -ssize_t virtio_pdu_vmarshal(V9fsPDU *pdu, size_t offset,
> - const char *fmt, va_list ap);
> -ssize_t virtio_pdu_vunmarshal(V9fsPDU *pdu, size_t offset,
> - const char *fmt, va_list ap);
> -void virtio_init_iov_from_pdu(V9fsPDU *pdu, struct iovec **piov,
> - unsigned int *pniov, bool is_write);
> -
> #define TYPE_VIRTIO_9P "virtio-9p-device"
> #define VIRTIO_9P(obj) \
> OBJECT_CHECK(V9fsVirtioState, (obj), TYPE_VIRTIO_9P)
WARNING: multiple messages have this Message-ID (diff)
From: Greg Kurz <groug@kaod.org>
To: Stefano Stabellini <sstabellini@kernel.org>
Cc: anthony.perard@citrix.com, xen-devel@lists.xensource.com,
aneesh.kumar@linux.vnet.ibm.com, qemu-devel@nongnu.org
Subject: Re: [PATCH v2 2/4] 9pfs: introduce transport specific callbacks
Date: Fri, 2 Dec 2016 12:03:30 +0100 [thread overview]
Message-ID: <20161202120330.733c02d5@bahia> (raw)
In-Reply-To: <1480368444-4310-2-git-send-email-sstabellini@kernel.org>
On Mon, 28 Nov 2016 13:27:22 -0800
Stefano Stabellini <sstabellini@kernel.org> wrote:
> Don't call virtio functions from 9pfs generic code, use generic function
> callbacks instead.
>
> Signed-off-by: Stefano Stabellini <sstabellini@kernel.org>
>
> ---
Reviewed-by: Greg Kurz <groug@kaod.org>
> Changes in v2:
> - constify virtio_9p_transport and V9fsTransport
> - assert !s->transport.
> - code style
> ---
> hw/9pfs/9p.c | 8 ++++----
> hw/9pfs/9p.h | 19 +++++++++++++++++++
> hw/9pfs/virtio-9p-device.c | 24 +++++++++++++++++-------
> hw/9pfs/virtio-9p.h | 9 ---------
> 4 files changed, 40 insertions(+), 20 deletions(-)
>
> diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c
> index 05e950f..5a20a13 100644
> --- a/hw/9pfs/9p.c
> +++ b/hw/9pfs/9p.c
> @@ -47,7 +47,7 @@ ssize_t pdu_marshal(V9fsPDU *pdu, size_t offset, const char *fmt, ...)
> va_list ap;
>
> va_start(ap, fmt);
> - ret = virtio_pdu_vmarshal(pdu, offset, fmt, ap);
> + ret = pdu->s->transport->pdu_vmarshal(pdu, offset, fmt, ap);
> va_end(ap);
>
> return ret;
> @@ -59,7 +59,7 @@ ssize_t pdu_unmarshal(V9fsPDU *pdu, size_t offset, const char *fmt, ...)
> va_list ap;
>
> va_start(ap, fmt);
> - ret = virtio_pdu_vunmarshal(pdu, offset, fmt, ap);
> + ret = pdu->s->transport->pdu_vunmarshal(pdu, offset, fmt, ap);
> va_end(ap);
>
> return ret;
> @@ -67,7 +67,7 @@ ssize_t pdu_unmarshal(V9fsPDU *pdu, size_t offset, const char *fmt, ...)
>
> static void pdu_push_and_notify(V9fsPDU *pdu)
> {
> - virtio_9p_push_and_notify(pdu);
> + pdu->s->transport->push_and_notify(pdu);
> }
>
> static int omode_to_uflags(int8_t mode)
> @@ -1751,7 +1751,7 @@ static void v9fs_init_qiov_from_pdu(QEMUIOVector *qiov, V9fsPDU *pdu,
> struct iovec *iov;
> unsigned int niov;
>
> - virtio_init_iov_from_pdu(pdu, &iov, &niov, is_write);
> + pdu->s->transport->init_iov_from_pdu(pdu, &iov, &niov, is_write);
>
> qemu_iovec_init_external(&elem, iov, niov);
> qemu_iovec_init(qiov, niov);
> diff --git a/hw/9pfs/9p.h b/hw/9pfs/9p.h
> index 07cee01..c8c9aa8 100644
> --- a/hw/9pfs/9p.h
> +++ b/hw/9pfs/9p.h
> @@ -230,6 +230,7 @@ typedef struct V9fsState
> enum p9_proto_version proto_version;
> int32_t msize;
> V9fsPDU pdus[MAX_REQ];
> + const struct V9fsTransport *transport;
> /*
> * lock ensuring atomic path update
> * on rename.
> @@ -343,4 +344,22 @@ void pdu_free(V9fsPDU *pdu);
> void pdu_submit(V9fsPDU *pdu);
> void v9fs_reset(V9fsState *s);
>
> +struct V9fsTransport {
> + ssize_t (*pdu_vmarshal)(V9fsPDU *pdu, size_t offset, const char *fmt,
> + va_list ap);
> + ssize_t (*pdu_vunmarshal)(V9fsPDU *pdu, size_t offset, const char *fmt,
> + va_list ap);
> + void (*init_iov_from_pdu)(V9fsPDU *pdu, struct iovec **piov,
> + unsigned int *pniov, bool is_write);
> + void (*push_and_notify)(V9fsPDU *pdu);
> +};
> +
> +static inline int v9fs_register_transport(V9fsState *s,
> + const struct V9fsTransport *t)
> +{
> + assert(!s->transport);
> + s->transport = t;
> + return 0;
> +}
> +
> #endif
> diff --git a/hw/9pfs/virtio-9p-device.c b/hw/9pfs/virtio-9p-device.c
> index 1782e4a..273425b 100644
> --- a/hw/9pfs/virtio-9p-device.c
> +++ b/hw/9pfs/virtio-9p-device.c
> @@ -20,7 +20,9 @@
> #include "hw/virtio/virtio-access.h"
> #include "qemu/iov.h"
>
> -void virtio_9p_push_and_notify(V9fsPDU *pdu)
> +static const struct V9fsTransport virtio_9p_transport;
> +
> +static void virtio_9p_push_and_notify(V9fsPDU *pdu)
> {
> V9fsState *s = pdu->s;
> V9fsVirtioState *v = container_of(s, V9fsVirtioState, state);
> @@ -126,6 +128,7 @@ static void virtio_9p_device_realize(DeviceState *dev, Error **errp)
> v->config_size = sizeof(struct virtio_9p_config) + strlen(s->fsconf.tag);
> virtio_init(vdev, "virtio-9p", VIRTIO_ID_9P, v->config_size);
> v->vq = virtio_add_queue(vdev, MAX_REQ, handle_9p_output);
> + v9fs_register_transport(s, &virtio_9p_transport);
>
> out:
> return;
> @@ -148,8 +151,8 @@ static void virtio_9p_reset(VirtIODevice *vdev)
> v9fs_reset(&v->state);
> }
>
> -ssize_t virtio_pdu_vmarshal(V9fsPDU *pdu, size_t offset,
> - const char *fmt, va_list ap)
> +static ssize_t virtio_pdu_vmarshal(V9fsPDU *pdu, size_t offset,
> + const char *fmt, va_list ap)
> {
> V9fsState *s = pdu->s;
> V9fsVirtioState *v = container_of(s, V9fsVirtioState, state);
> @@ -158,8 +161,8 @@ ssize_t virtio_pdu_vmarshal(V9fsPDU *pdu, size_t offset,
> return v9fs_iov_vmarshal(elem->in_sg, elem->in_num, offset, 1, fmt, ap);
> }
>
> -ssize_t virtio_pdu_vunmarshal(V9fsPDU *pdu, size_t offset,
> - const char *fmt, va_list ap)
> +static ssize_t virtio_pdu_vunmarshal(V9fsPDU *pdu, size_t offset,
> + const char *fmt, va_list ap)
> {
> V9fsState *s = pdu->s;
> V9fsVirtioState *v = container_of(s, V9fsVirtioState, state);
> @@ -168,8 +171,8 @@ ssize_t virtio_pdu_vunmarshal(V9fsPDU *pdu, size_t offset,
> return v9fs_iov_vunmarshal(elem->out_sg, elem->out_num, offset, 1, fmt, ap);
> }
>
> -void virtio_init_iov_from_pdu(V9fsPDU *pdu, struct iovec **piov,
> - unsigned int *pniov, bool is_write)
> +static void virtio_init_iov_from_pdu(V9fsPDU *pdu, struct iovec **piov,
> + unsigned int *pniov, bool is_write)
> {
> V9fsState *s = pdu->s;
> V9fsVirtioState *v = container_of(s, V9fsVirtioState, state);
> @@ -184,6 +187,13 @@ void virtio_init_iov_from_pdu(V9fsPDU *pdu, struct iovec **piov,
> }
> }
>
> +static const struct V9fsTransport virtio_9p_transport = {
> + .pdu_vmarshal = virtio_pdu_vmarshal,
> + .pdu_vunmarshal = virtio_pdu_vunmarshal,
> + .init_iov_from_pdu = virtio_init_iov_from_pdu,
> + .push_and_notify = virtio_9p_push_and_notify,
> +};
> +
> /* virtio-9p device */
>
> static const VMStateDescription vmstate_virtio_9p = {
> diff --git a/hw/9pfs/virtio-9p.h b/hw/9pfs/virtio-9p.h
> index 52c4b9d..e763da2c 100644
> --- a/hw/9pfs/virtio-9p.h
> +++ b/hw/9pfs/virtio-9p.h
> @@ -14,15 +14,6 @@ typedef struct V9fsVirtioState
> V9fsState state;
> } V9fsVirtioState;
>
> -void virtio_9p_push_and_notify(V9fsPDU *pdu);
> -
> -ssize_t virtio_pdu_vmarshal(V9fsPDU *pdu, size_t offset,
> - const char *fmt, va_list ap);
> -ssize_t virtio_pdu_vunmarshal(V9fsPDU *pdu, size_t offset,
> - const char *fmt, va_list ap);
> -void virtio_init_iov_from_pdu(V9fsPDU *pdu, struct iovec **piov,
> - unsigned int *pniov, bool is_write);
> -
> #define TYPE_VIRTIO_9P "virtio-9p-device"
> #define VIRTIO_9P(obj) \
> OBJECT_CHECK(V9fsVirtioState, (obj), TYPE_VIRTIO_9P)
next prev parent reply other threads:[~2016-12-02 11:03 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-11-28 21:24 [Qemu-devel] [PATCH v2 0/4] 9pfs: clean-up for multiple transports Stefano Stabellini
2016-11-28 21:24 ` Stefano Stabellini
2016-11-28 21:27 ` [Qemu-devel] [PATCH v2 1/4] 9pfs: move pdus to V9fsState Stefano Stabellini
2016-11-28 21:27 ` Stefano Stabellini
2016-11-28 21:27 ` [Qemu-devel] [PATCH v2 2/4] 9pfs: introduce transport specific callbacks Stefano Stabellini
2016-11-28 21:27 ` Stefano Stabellini
2016-12-02 11:03 ` Greg Kurz [this message]
2016-12-02 11:03 ` Greg Kurz
2016-11-28 21:27 ` [Qemu-devel] [PATCH v2 3/4] 9pfs: call v9fs_init_qiov_from_pdu before v9fs_pack Stefano Stabellini
2016-11-28 21:27 ` Stefano Stabellini
2016-12-02 11:04 ` [Qemu-devel] " Greg Kurz
2016-12-02 11:04 ` Greg Kurz
2016-11-28 21:27 ` [Qemu-devel] [PATCH v2 4/4] 9pfs: introduce init_out/in_iov_from_pdu Stefano Stabellini
2016-11-28 21:27 ` Stefano Stabellini
2016-12-02 11:05 ` [Qemu-devel] " Greg Kurz
2016-12-02 11:05 ` Greg Kurz
2016-12-02 19:02 ` [Qemu-devel] [Xen-devel] " Stefano Stabellini
2016-12-02 19:02 ` Stefano Stabellini
2016-12-03 8:57 ` [Qemu-devel] " Greg Kurz
2016-12-03 8:57 ` Greg Kurz
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=20161202120330.733c02d5@bahia \
--to=groug@kaod.org \
--cc=aneesh.kumar@linux.vnet.ibm.com \
--cc=anthony.perard@citrix.com \
--cc=qemu-devel@nongnu.org \
--cc=sstabellini@kernel.org \
--cc=xen-devel@lists.xensource.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.