From: Vivek Goyal <vgoyal@redhat.com> To: qemu-devel@nongnu.org, virtio-fs@redhat.com, stefanha@redhat.com Cc: jaggel@bu.edu, iangelak@redhat.com, dgilbert@redhat.com, vgoyal@redhat.com, miklos@szeredi.hu Subject: [PATCH 04/13] virtiofsd: Add a helper to send element on virtqueue Date: Thu, 30 Sep 2021 11:30:28 -0400 [thread overview] Message-ID: <20210930153037.1194279-5-vgoyal@redhat.com> (raw) In-Reply-To: <20210930153037.1194279-1-vgoyal@redhat.com> We have open coded logic to take locks and push element on virtqueue at three places. Add a helper and use it everywhere. Code is easier to read and less number of lines of code. Signed-off-by: Vivek Goyal <vgoyal@redhat.com> --- tools/virtiofsd/fuse_virtio.c | 45 ++++++++++++++--------------------- 1 file changed, 18 insertions(+), 27 deletions(-) diff --git a/tools/virtiofsd/fuse_virtio.c b/tools/virtiofsd/fuse_virtio.c index da7b6a76bf..fcf12db9cd 100644 --- a/tools/virtiofsd/fuse_virtio.c +++ b/tools/virtiofsd/fuse_virtio.c @@ -243,6 +243,21 @@ static void vu_dispatch_unlock(struct fv_VuDev *vud) assert(ret == 0); } +static void vq_send_element(struct fv_QueueInfo *qi, VuVirtqElement *elem, + ssize_t len) +{ + struct fuse_session *se = qi->virtio_dev->se; + VuDev *dev = &se->virtio_dev->dev; + VuVirtq *q = vu_get_queue(dev, qi->qidx); + + vu_dispatch_rdlock(qi->virtio_dev); + pthread_mutex_lock(&qi->vq_lock); + vu_queue_push(dev, q, elem, len); + vu_queue_notify(dev, q); + pthread_mutex_unlock(&qi->vq_lock); + vu_dispatch_unlock(qi->virtio_dev); +} + /* * Called back by ll whenever it wants to send a reply/message back * The 1st element of the iov starts with the fuse_out_header @@ -253,8 +268,6 @@ int virtio_send_msg(struct fuse_session *se, struct fuse_chan *ch, { FVRequest *req = container_of(ch, FVRequest, ch); struct fv_QueueInfo *qi = ch->qi; - VuDev *dev = &se->virtio_dev->dev; - VuVirtq *q = vu_get_queue(dev, qi->qidx); VuVirtqElement *elem = &req->elem; int ret = 0; @@ -296,13 +309,7 @@ int virtio_send_msg(struct fuse_session *se, struct fuse_chan *ch, copy_iov(iov, count, in_sg, in_num, tosend_len); - vu_dispatch_rdlock(qi->virtio_dev); - pthread_mutex_lock(&qi->vq_lock); - vu_queue_push(dev, q, elem, tosend_len); - vu_queue_notify(dev, q); - pthread_mutex_unlock(&qi->vq_lock); - vu_dispatch_unlock(qi->virtio_dev); - + vq_send_element(qi, elem, tosend_len); req->reply_sent = true; err: @@ -321,8 +328,6 @@ int virtio_send_data_iov(struct fuse_session *se, struct fuse_chan *ch, { FVRequest *req = container_of(ch, FVRequest, ch); struct fv_QueueInfo *qi = ch->qi; - VuDev *dev = &se->virtio_dev->dev; - VuVirtq *q = vu_get_queue(dev, qi->qidx); VuVirtqElement *elem = &req->elem; int ret = 0; g_autofree struct iovec *in_sg_cpy = NULL; @@ -430,12 +435,7 @@ int virtio_send_data_iov(struct fuse_session *se, struct fuse_chan *ch, out_sg->len = tosend_len; } - vu_dispatch_rdlock(qi->virtio_dev); - pthread_mutex_lock(&qi->vq_lock); - vu_queue_push(dev, q, elem, tosend_len); - vu_queue_notify(dev, q); - pthread_mutex_unlock(&qi->vq_lock); - vu_dispatch_unlock(qi->virtio_dev); + vq_send_element(qi, elem, tosend_len); req->reply_sent = true; return 0; } @@ -447,7 +447,6 @@ static void fv_queue_worker(gpointer data, gpointer user_data) { struct fv_QueueInfo *qi = user_data; struct fuse_session *se = qi->virtio_dev->se; - struct VuDev *dev = &qi->virtio_dev->dev; FVRequest *req = data; VuVirtqElement *elem = &req->elem; struct fuse_buf fbuf = {}; @@ -589,17 +588,9 @@ out: /* If the request has no reply, still recycle the virtqueue element */ if (!req->reply_sent) { - struct VuVirtq *q = vu_get_queue(dev, qi->qidx); - fuse_log(FUSE_LOG_DEBUG, "%s: elem %d no reply sent\n", __func__, elem->index); - - vu_dispatch_rdlock(qi->virtio_dev); - pthread_mutex_lock(&qi->vq_lock); - vu_queue_push(dev, q, elem, 0); - vu_queue_notify(dev, q); - pthread_mutex_unlock(&qi->vq_lock); - vu_dispatch_unlock(qi->virtio_dev); + vq_send_element(qi, elem, 0); } pthread_mutex_destroy(&req->ch.lock); -- 2.31.1
WARNING: multiple messages have this Message-ID (diff)
From: Vivek Goyal <vgoyal@redhat.com> To: qemu-devel@nongnu.org, virtio-fs@redhat.com, stefanha@redhat.com Cc: vgoyal@redhat.com, miklos@szeredi.hu Subject: [Virtio-fs] [PATCH 04/13] virtiofsd: Add a helper to send element on virtqueue Date: Thu, 30 Sep 2021 11:30:28 -0400 [thread overview] Message-ID: <20210930153037.1194279-5-vgoyal@redhat.com> (raw) In-Reply-To: <20210930153037.1194279-1-vgoyal@redhat.com> We have open coded logic to take locks and push element on virtqueue at three places. Add a helper and use it everywhere. Code is easier to read and less number of lines of code. Signed-off-by: Vivek Goyal <vgoyal@redhat.com> --- tools/virtiofsd/fuse_virtio.c | 45 ++++++++++++++--------------------- 1 file changed, 18 insertions(+), 27 deletions(-) diff --git a/tools/virtiofsd/fuse_virtio.c b/tools/virtiofsd/fuse_virtio.c index da7b6a76bf..fcf12db9cd 100644 --- a/tools/virtiofsd/fuse_virtio.c +++ b/tools/virtiofsd/fuse_virtio.c @@ -243,6 +243,21 @@ static void vu_dispatch_unlock(struct fv_VuDev *vud) assert(ret == 0); } +static void vq_send_element(struct fv_QueueInfo *qi, VuVirtqElement *elem, + ssize_t len) +{ + struct fuse_session *se = qi->virtio_dev->se; + VuDev *dev = &se->virtio_dev->dev; + VuVirtq *q = vu_get_queue(dev, qi->qidx); + + vu_dispatch_rdlock(qi->virtio_dev); + pthread_mutex_lock(&qi->vq_lock); + vu_queue_push(dev, q, elem, len); + vu_queue_notify(dev, q); + pthread_mutex_unlock(&qi->vq_lock); + vu_dispatch_unlock(qi->virtio_dev); +} + /* * Called back by ll whenever it wants to send a reply/message back * The 1st element of the iov starts with the fuse_out_header @@ -253,8 +268,6 @@ int virtio_send_msg(struct fuse_session *se, struct fuse_chan *ch, { FVRequest *req = container_of(ch, FVRequest, ch); struct fv_QueueInfo *qi = ch->qi; - VuDev *dev = &se->virtio_dev->dev; - VuVirtq *q = vu_get_queue(dev, qi->qidx); VuVirtqElement *elem = &req->elem; int ret = 0; @@ -296,13 +309,7 @@ int virtio_send_msg(struct fuse_session *se, struct fuse_chan *ch, copy_iov(iov, count, in_sg, in_num, tosend_len); - vu_dispatch_rdlock(qi->virtio_dev); - pthread_mutex_lock(&qi->vq_lock); - vu_queue_push(dev, q, elem, tosend_len); - vu_queue_notify(dev, q); - pthread_mutex_unlock(&qi->vq_lock); - vu_dispatch_unlock(qi->virtio_dev); - + vq_send_element(qi, elem, tosend_len); req->reply_sent = true; err: @@ -321,8 +328,6 @@ int virtio_send_data_iov(struct fuse_session *se, struct fuse_chan *ch, { FVRequest *req = container_of(ch, FVRequest, ch); struct fv_QueueInfo *qi = ch->qi; - VuDev *dev = &se->virtio_dev->dev; - VuVirtq *q = vu_get_queue(dev, qi->qidx); VuVirtqElement *elem = &req->elem; int ret = 0; g_autofree struct iovec *in_sg_cpy = NULL; @@ -430,12 +435,7 @@ int virtio_send_data_iov(struct fuse_session *se, struct fuse_chan *ch, out_sg->len = tosend_len; } - vu_dispatch_rdlock(qi->virtio_dev); - pthread_mutex_lock(&qi->vq_lock); - vu_queue_push(dev, q, elem, tosend_len); - vu_queue_notify(dev, q); - pthread_mutex_unlock(&qi->vq_lock); - vu_dispatch_unlock(qi->virtio_dev); + vq_send_element(qi, elem, tosend_len); req->reply_sent = true; return 0; } @@ -447,7 +447,6 @@ static void fv_queue_worker(gpointer data, gpointer user_data) { struct fv_QueueInfo *qi = user_data; struct fuse_session *se = qi->virtio_dev->se; - struct VuDev *dev = &qi->virtio_dev->dev; FVRequest *req = data; VuVirtqElement *elem = &req->elem; struct fuse_buf fbuf = {}; @@ -589,17 +588,9 @@ out: /* If the request has no reply, still recycle the virtqueue element */ if (!req->reply_sent) { - struct VuVirtq *q = vu_get_queue(dev, qi->qidx); - fuse_log(FUSE_LOG_DEBUG, "%s: elem %d no reply sent\n", __func__, elem->index); - - vu_dispatch_rdlock(qi->virtio_dev); - pthread_mutex_lock(&qi->vq_lock); - vu_queue_push(dev, q, elem, 0); - vu_queue_notify(dev, q); - pthread_mutex_unlock(&qi->vq_lock); - vu_dispatch_unlock(qi->virtio_dev); + vq_send_element(qi, elem, 0); } pthread_mutex_destroy(&req->ch.lock); -- 2.31.1
next prev parent reply other threads:[~2021-09-30 16:08 UTC|newest] Thread overview: 106+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-09-30 15:30 [PATCH 00/13] virtiofsd: Support notification queue and Vivek Goyal 2021-09-30 15:30 ` [Virtio-fs] " Vivek Goyal 2021-09-30 15:30 ` [PATCH 01/13] virtio_fs.h: Add notification queue feature bit Vivek Goyal 2021-09-30 15:30 ` [Virtio-fs] " Vivek Goyal 2021-10-04 13:12 ` Stefan Hajnoczi 2021-10-04 13:12 ` [Virtio-fs] " Stefan Hajnoczi 2021-09-30 15:30 ` [PATCH 02/13] virtiofsd: fuse.h header file changes for lock notification Vivek Goyal 2021-09-30 15:30 ` [Virtio-fs] " Vivek Goyal 2021-10-04 13:16 ` Stefan Hajnoczi 2021-10-04 13:16 ` [Virtio-fs] " Stefan Hajnoczi 2021-10-04 14:01 ` Vivek Goyal 2021-10-04 14:01 ` [Virtio-fs] " Vivek Goyal 2021-09-30 15:30 ` [PATCH 03/13] virtiofsd: Remove unused virtio_fs_config definition Vivek Goyal 2021-09-30 15:30 ` [Virtio-fs] " Vivek Goyal 2021-10-04 13:17 ` Stefan Hajnoczi 2021-10-04 13:17 ` [Virtio-fs] " Stefan Hajnoczi 2021-09-30 15:30 ` Vivek Goyal [this message] 2021-09-30 15:30 ` [Virtio-fs] [PATCH 04/13] virtiofsd: Add a helper to send element on virtqueue Vivek Goyal 2021-10-04 13:19 ` Stefan Hajnoczi 2021-10-04 13:19 ` [Virtio-fs] " Stefan Hajnoczi 2021-09-30 15:30 ` [PATCH 05/13] virtiofsd: Add a helper to stop all queues Vivek Goyal 2021-09-30 15:30 ` [Virtio-fs] " Vivek Goyal 2021-10-04 13:22 ` Stefan Hajnoczi 2021-10-04 13:22 ` [Virtio-fs] " Stefan Hajnoczi 2021-09-30 15:30 ` [PATCH 06/13] vhost-user-fs: Use helpers to create/cleanup virtqueue Vivek Goyal 2021-09-30 15:30 ` [Virtio-fs] " Vivek Goyal 2021-10-04 13:54 ` Stefan Hajnoczi 2021-10-04 13:54 ` [Virtio-fs] " Stefan Hajnoczi 2021-10-04 19:58 ` Vivek Goyal 2021-10-04 19:58 ` [Virtio-fs] " Vivek Goyal 2021-10-05 8:09 ` Stefan Hajnoczi 2021-10-05 8:09 ` [Virtio-fs] " Stefan Hajnoczi 2021-10-06 13:35 ` Christophe de Dinechin 2021-10-06 13:35 ` Christophe de Dinechin 2021-10-06 17:40 ` Vivek Goyal 2021-10-06 17:40 ` Vivek Goyal 2021-09-30 15:30 ` [PATCH 07/13] virtiofsd: Release file locks using F_UNLCK Vivek Goyal 2021-09-30 15:30 ` [Virtio-fs] " Vivek Goyal 2021-10-05 13:37 ` Christophe de Dinechin 2021-10-05 13:37 ` Christophe de Dinechin 2021-10-05 15:38 ` Vivek Goyal 2021-10-05 15:38 ` Vivek Goyal 2021-09-30 15:30 ` [PATCH 08/13] virtiofsd: Create a notification queue Vivek Goyal 2021-09-30 15:30 ` [Virtio-fs] " Vivek Goyal 2021-10-04 14:30 ` Stefan Hajnoczi 2021-10-04 14:30 ` [Virtio-fs] " Stefan Hajnoczi 2021-10-04 21:01 ` Vivek Goyal 2021-10-04 21:01 ` [Virtio-fs] " Vivek Goyal 2021-10-05 8:14 ` Stefan Hajnoczi 2021-10-05 8:14 ` [Virtio-fs] " Stefan Hajnoczi 2021-10-05 12:31 ` Vivek Goyal 2021-10-05 12:31 ` [Virtio-fs] " Vivek Goyal 2021-09-30 15:30 ` [PATCH 09/13] virtiofsd: Specify size of notification buffer using config space Vivek Goyal 2021-09-30 15:30 ` [Virtio-fs] " Vivek Goyal 2021-10-04 14:33 ` Stefan Hajnoczi 2021-10-04 14:33 ` [Virtio-fs] " Stefan Hajnoczi 2021-10-04 21:10 ` Vivek Goyal 2021-10-04 21:10 ` [Virtio-fs] " Vivek Goyal 2021-10-06 10:05 ` Christophe de Dinechin 2021-10-06 10:05 ` Christophe de Dinechin 2021-09-30 15:30 ` [PATCH 10/13] virtiofsd: Custom threadpool for remote blocking posix locks requests Vivek Goyal 2021-09-30 15:30 ` [Virtio-fs] " Vivek Goyal 2021-10-04 14:54 ` Stefan Hajnoczi 2021-10-04 14:54 ` [Virtio-fs] " Stefan Hajnoczi 2021-10-05 13:06 ` Vivek Goyal 2021-10-05 13:06 ` [Virtio-fs] " Vivek Goyal 2021-10-05 20:09 ` Vivek Goyal 2021-10-05 20:09 ` [Virtio-fs] " Vivek Goyal 2021-10-06 10:26 ` Stefan Hajnoczi 2021-10-06 10:26 ` [Virtio-fs] " Stefan Hajnoczi 2021-09-30 15:30 ` [PATCH 11/13] virtiofsd: Shutdown notification queue in the end Vivek Goyal 2021-09-30 15:30 ` [Virtio-fs] " Vivek Goyal 2021-10-04 15:01 ` Stefan Hajnoczi 2021-10-04 15:01 ` [Virtio-fs] " Stefan Hajnoczi 2021-10-05 13:19 ` Vivek Goyal 2021-10-05 13:19 ` [Virtio-fs] " Vivek Goyal 2021-10-06 15:15 ` Christophe de Dinechin 2021-10-06 15:15 ` Christophe de Dinechin 2021-10-06 17:58 ` Vivek Goyal 2021-10-06 17:58 ` Vivek Goyal 2021-09-30 15:30 ` [PATCH 12/13] virtiofsd: Implement blocking posix locks Vivek Goyal 2021-09-30 15:30 ` [Virtio-fs] " Vivek Goyal 2021-10-04 15:07 ` Stefan Hajnoczi 2021-10-04 15:07 ` [Virtio-fs] " Stefan Hajnoczi 2021-10-05 13:26 ` Vivek Goyal 2021-10-05 13:26 ` [Virtio-fs] " Vivek Goyal 2021-10-05 12:22 ` Stefan Hajnoczi 2021-10-05 12:22 ` [Virtio-fs] " Stefan Hajnoczi 2021-10-05 15:14 ` Vivek Goyal 2021-10-05 15:14 ` [Virtio-fs] " Vivek Goyal 2021-10-05 15:49 ` Stefan Hajnoczi 2021-10-05 15:49 ` [Virtio-fs] " Stefan Hajnoczi 2021-10-06 15:34 ` Christophe de Dinechin 2021-10-06 15:34 ` Christophe de Dinechin 2021-10-06 18:17 ` Vivek Goyal 2021-10-06 18:17 ` Vivek Goyal 2021-09-30 15:30 ` [PATCH 13/13] virtiofsd, seccomp: Add clock_nanosleep() to allow list Vivek Goyal 2021-09-30 15:30 ` [Virtio-fs] " Vivek Goyal 2021-10-05 12:22 ` Stefan Hajnoczi 2021-10-05 12:22 ` [Virtio-fs] " Stefan Hajnoczi 2021-10-05 15:16 ` Vivek Goyal 2021-10-05 15:50 ` Stefan Hajnoczi 2021-10-05 17:28 ` Vivek Goyal 2021-10-06 10:27 ` Stefan Hajnoczi 2021-10-25 18:00 ` [PATCH 00/13] virtiofsd: Support notification queue and Dr. David Alan Gilbert 2021-10-25 18:00 ` [Virtio-fs] " Dr. David Alan Gilbert
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=20210930153037.1194279-5-vgoyal@redhat.com \ --to=vgoyal@redhat.com \ --cc=dgilbert@redhat.com \ --cc=iangelak@redhat.com \ --cc=jaggel@bu.edu \ --cc=miklos@szeredi.hu \ --cc=qemu-devel@nongnu.org \ --cc=stefanha@redhat.com \ --cc=virtio-fs@redhat.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: linkBe 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.