Skip to contentSkip to conversation

virtiofsd: Few cleanups in virtio_send_data_iov()

PATCH Superseded Vivek Goyal 4 participants 21 messages May 11, 2021 – May 18, 2021

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover virtiofsd: Few cleanups in virtio_send_data_iov()

Hi,

Code in virtio_send_data_iov() little twisted and complicated. This patch series just tries to simplify it a bit to make it little easier to read this piece of code.

Thanks
Vivek

Vivek Goyal (7):
virtiofsd: Check for EINTR in preadv() and retry
virtiofsd: Get rid of unreachable code in read
virtiofsd: Use iov_discard_front() to skip bytes
virtiofsd: get rid of in_sg_left variable
virtiofsd: Simplify skip byte logic
virtiofsd: Check EOF before short read
virtiofsd: Set req->reply_sent right after sending reply

 tools/virtiofsd/fuse_virtio.c | 67 +++++++++++------------------------
 1 file changed, 21 insertions(+), 46 deletions(-)
Signature · 1 line
2.25.4
#1 lore raw

PATCH 1/7 virtiofsd: Check for EINTR in preadv() and retry

We don't seem to check for EINTR and retry. There are other places in code where we check for EINTR. So lets add a check.

---
 tools/virtiofsd/fuse_virtio.c | 3 +++
 1 file changed, 3 insertions(+)
tools/virtiofsd/fuse_virtio.c +3 -0
index 1170f375a5..32914f7e95 100644
@@ -421,6 +421,9 @@ int virtio_send_data_iov(struct fuse_session *se, struct fuse_chan *ch,
 
         if (ret == -1) {
             ret = errno;
+            if (ret == EINTR) {
+                continue;
+            }
             fuse_log(FUSE_LOG_DEBUG, "%s: preadv failed (%m) len=%zd\n",
                      __func__, len);
             goto err;
Signature · 1 line
2.25.4
Reviewed-by on v1 1/7
#2 lore raw

Re: [PATCH 1/7] virtiofsd: Check for EINTR in preadv() and retry

Quoted 4 lines · * Vivek Goyal ([email protected]) wrote:

We don't seem to check for EINTR and retry. There are other places in code where we check for EINTR. So lets add a check.

Quoted 21 lines
---
 tools/virtiofsd/fuse_virtio.c | 3 +++
 1 file changed, 3 insertions(+)
tools/virtiofsd/fuse_virtio.c +3 -0
index 1170f375a5..32914f7e95 100644
@@ -421,6 +421,9 @@ int virtio_send_data_iov(struct fuse_session *se, struct fuse_chan *ch,
 
         if (ret == -1) {
             ret = errno;
+            if (ret == EINTR) {
+                continue;
+            }
             fuse_log(FUSE_LOG_DEBUG, "%s: preadv failed (%m) len=%zd\n",
                      __func__, len);
             goto err;
Signature · 1 line
2.25.4
Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UK
#3 lore raw

PATCH 2/7 virtiofsd: Get rid of unreachable code in read

In reply to Vivek Goyal

pvreadv() can return following.

- error
- 0 in case of EOF
- short read

We seem to handle all the cases already. We are retrying read in case of short read. So another check for short read seems like dead code. Get rid of it.

---
 tools/virtiofsd/fuse_virtio.c | 5 -----
 1 file changed, 5 deletions(-)
tools/virtiofsd/fuse_virtio.c +0 -5
index 32914f7e95..5dcd08fccb 100644
@@ -446,11 +446,6 @@ int virtio_send_data_iov(struct fuse_session *se, struct fuse_chan *ch,
                      in_sg_left);
             break;
         }
-        if (ret != len) {
-            fuse_log(FUSE_LOG_DEBUG, "%s: ret!=len\n", __func__);
-            ret = EIO;
-            goto err;
-        }
         in_sg_left -= ret;
         len -= ret;
     } while (in_sg_left);
Signature · 1 line
2.25.4
Reviewed-by on v1 2/7
#4 lore raw

Re: [PATCH 2/7] virtiofsd: Get rid of unreachable code in read

Quoted 11 lines · * Vivek Goyal ([email protected]) wrote:

pvreadv() can return following.

- error
- 0 in case of EOF
- short read

We seem to handle all the cases already. We are retrying read in case of short read. So another check for short read seems like dead code. Get rid of it.

Quoted 23 lines
---
 tools/virtiofsd/fuse_virtio.c | 5 -----
 1 file changed, 5 deletions(-)
tools/virtiofsd/fuse_virtio.c +0 -5
index 32914f7e95..5dcd08fccb 100644
@@ -446,11 +446,6 @@ int virtio_send_data_iov(struct fuse_session *se, struct fuse_chan *ch,
                      in_sg_left);
             break;
         }
-        if (ret != len) {
-            fuse_log(FUSE_LOG_DEBUG, "%s: ret!=len\n", __func__);
-            ret = EIO;
-            goto err;
-        }
         in_sg_left -= ret;
         len -= ret;
     } while (in_sg_left);
Signature · 1 line
2.25.4
Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UK
#5 lore raw

PATCH 3/7 virtiofsd: Use iov_discard_front() to skip bytes

In reply to Vivek Goyal

There are places where we need to skip few bytes from front of the iovec array. We have our own custom code for that. Looks like iov_discard_front() can do same thing. So use that helper instead.

---
 tools/virtiofsd/fuse_virtio.c | 14 +++-----------
 1 file changed, 3 insertions(+), 11 deletions(-)
tools/virtiofsd/fuse_virtio.c +3 -11
index 5dcd08fccb..d56b225800 100644
@@ -389,23 +389,15 @@ int virtio_send_data_iov(struct fuse_session *se, struct fuse_chan *ch,
     memcpy(in_sg_cpy, in_sg, sizeof(struct iovec) * in_num);
     /* These get updated as we skip */
     struct iovec *in_sg_ptr = in_sg_cpy;
-    int in_sg_cpy_count = in_num;
+    unsigned int in_sg_cpy_count = in_num;
 
     /* skip over parts of in_sg that contained the header iov */
     size_t skip_size = iov_len;
 
     size_t in_sg_left = 0;
     do {
-        while (skip_size != 0 && in_sg_cpy_count) {
-            if (skip_size >= in_sg_ptr[0].iov_len) {
-                skip_size -= in_sg_ptr[0].iov_len;
-                in_sg_ptr++;
-                in_sg_cpy_count--;
-            } else {
-                in_sg_ptr[0].iov_len -= skip_size;
-                in_sg_ptr[0].iov_base += skip_size;
-                break;
-            }
+        if (skip_size != 0) {
+	    iov_discard_front(&in_sg_ptr, &in_sg_cpy_count, skip_size);
         }
 
         int i;
Signature · 1 line
2.25.4
Reviewed-by on v1 3/7
#6 lore raw

Re: [PATCH 3/7] virtiofsd: Use iov_discard_front() to skip bytes

Quoted 5 lines · * Vivek Goyal ([email protected]) wrote:

There are places where we need to skip few bytes from front of the iovec array. We have our own custom code for that. Looks like iov_discard_front() can do same thing. So use that helper instead.

Oh nice; I hadn't noticed that file; I bet there are loads of other places that can use it (and I still don't get why iov functions aren't part of libc)

Quoted 38 lines
---
 tools/virtiofsd/fuse_virtio.c | 14 +++-----------
 1 file changed, 3 insertions(+), 11 deletions(-)
tools/virtiofsd/fuse_virtio.c +3 -11
index 5dcd08fccb..d56b225800 100644
@@ -389,23 +389,15 @@ int virtio_send_data_iov(struct fuse_session *se, struct fuse_chan *ch,
     memcpy(in_sg_cpy, in_sg, sizeof(struct iovec) * in_num);
     /* These get updated as we skip */
     struct iovec *in_sg_ptr = in_sg_cpy;
-    int in_sg_cpy_count = in_num;
+    unsigned int in_sg_cpy_count = in_num;
 
     /* skip over parts of in_sg that contained the header iov */
     size_t skip_size = iov_len;
 
     size_t in_sg_left = 0;
     do {
-        while (skip_size != 0 && in_sg_cpy_count) {
-            if (skip_size >= in_sg_ptr[0].iov_len) {
-                skip_size -= in_sg_ptr[0].iov_len;
-                in_sg_ptr++;
-                in_sg_cpy_count--;
-            } else {
-                in_sg_ptr[0].iov_len -= skip_size;
-                in_sg_ptr[0].iov_base += skip_size;
-                break;
-            }
+        if (skip_size != 0) {
+	    iov_discard_front(&in_sg_ptr, &in_sg_cpy_count, skip_size);
         }
 
         int i;
Signature · 1 line
2.25.4
Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UK
#7 lore raw

PATCH 4/7 virtiofsd: get rid of in_sg_left variable

In reply to Vivek Goyal

in_sg_left seems to be being used primarly for debugging purpose. It is keeping track of how many bytes are left in the scatter list we are reading into.

We already have another variable "len" which keeps track how many bytes are left to be read. And in_sg_left is greater than or equal to len. We have already ensured that in the beginning of function.

    if (in_len < tosend_len) {
        fuse_log(FUSE_LOG_ERR, "%s: elem %d too small for data len %zd\n",
                 __func__, elem->index, tosend_len);
        ret = E2BIG;
        goto err;
    }

So in_sg_left seems like a redundant variable. It probably was useful for debugging when code was being developed. Get rid of it. It helps simplify this function.

---
 tools/virtiofsd/fuse_virtio.c | 17 ++++++-----------
 1 file changed, 6 insertions(+), 11 deletions(-)
tools/virtiofsd/fuse_virtio.c +6 -11
index d56b225800..ccad2b3f8a 100644
@@ -394,20 +394,16 @@ int virtio_send_data_iov(struct fuse_session *se, struct fuse_chan *ch,
     /* skip over parts of in_sg that contained the header iov */
     size_t skip_size = iov_len;
 
-    size_t in_sg_left = 0;
     do {
         if (skip_size != 0) {
 	    iov_discard_front(&in_sg_ptr, &in_sg_cpy_count, skip_size);
         }
 
-        int i;
-        for (i = 0, in_sg_left = 0; i < in_sg_cpy_count; i++) {
-            in_sg_left += in_sg_ptr[i].iov_len;
-        }
         fuse_log(FUSE_LOG_DEBUG,
                  "%s: after skip skip_size=%zd in_sg_cpy_count=%d "
-                 "in_sg_left=%zd\n",
-                 __func__, skip_size, in_sg_cpy_count, in_sg_left);
+                 "len remaining=%zd\n", __func__, skip_size, in_sg_cpy_count,
+                 len);
+
         ret = preadv(buf->buf[0].fd, in_sg_ptr, in_sg_cpy_count,
                      buf->buf[0].pos);
 
@@ -434,13 +430,12 @@ int virtio_send_data_iov(struct fuse_session *se, struct fuse_chan *ch,
         }
         if (!ret) {
             /* EOF case? */
-            fuse_log(FUSE_LOG_DEBUG, "%s: !ret in_sg_left=%zd\n", __func__,
-                     in_sg_left);
+            fuse_log(FUSE_LOG_DEBUG, "%s: !ret len remaining=%zd\n", __func__,
+                     len);
             break;
         }
-        in_sg_left -= ret;
         len -= ret;
-    } while (in_sg_left);
+    } while (len);
 
     /* Need to fix out->len on EOF */
     if (len) {
Signature · 1 line
2.25.4
Reviewed-by on v1 4/7
#8 lore raw

Re: [PATCH 4/7] virtiofsd: get rid of in_sg_left variable

Quoted 15 lines · * Vivek Goyal ([email protected]) wrote:

in_sg_left seems to be being used primarly for debugging purpose. It is keeping track of how many bytes are left in the scatter list we are reading into.

We already have another variable "len" which keeps track how many bytes are left to be read. And in_sg_left is greater than or equal to len. We have already ensured that in the beginning of function.

    if (in_len < tosend_len) {
        fuse_log(FUSE_LOG_ERR, "%s: elem %d too small for data len %zd\n",
                 __func__, elem->index, tosend_len);
        ret = E2BIG;
        goto err;
    }
Quoted 5 lines

So in_sg_left seems like a redundant variable. It probably was useful for debugging when code was being developed. Get rid of it. It helps simplify this function.

Quoted 52 lines
---
 tools/virtiofsd/fuse_virtio.c | 17 ++++++-----------
 1 file changed, 6 insertions(+), 11 deletions(-)
tools/virtiofsd/fuse_virtio.c +6 -11
index d56b225800..ccad2b3f8a 100644
@@ -394,20 +394,16 @@ int virtio_send_data_iov(struct fuse_session *se, struct fuse_chan *ch,
     /* skip over parts of in_sg that contained the header iov */
     size_t skip_size = iov_len;
 
-    size_t in_sg_left = 0;
     do {
         if (skip_size != 0) {
 	    iov_discard_front(&in_sg_ptr, &in_sg_cpy_count, skip_size);
         }
 
-        int i;
-        for (i = 0, in_sg_left = 0; i < in_sg_cpy_count; i++) {
-            in_sg_left += in_sg_ptr[i].iov_len;
-        }
         fuse_log(FUSE_LOG_DEBUG,
                  "%s: after skip skip_size=%zd in_sg_cpy_count=%d "
-                 "in_sg_left=%zd\n",
-                 __func__, skip_size, in_sg_cpy_count, in_sg_left);
+                 "len remaining=%zd\n", __func__, skip_size, in_sg_cpy_count,
+                 len);
+
         ret = preadv(buf->buf[0].fd, in_sg_ptr, in_sg_cpy_count,
                      buf->buf[0].pos);
 
@@ -434,13 +430,12 @@ int virtio_send_data_iov(struct fuse_session *se, struct fuse_chan *ch,
         }
         if (!ret) {
             /* EOF case? */
-            fuse_log(FUSE_LOG_DEBUG, "%s: !ret in_sg_left=%zd\n", __func__,
-                     in_sg_left);
+            fuse_log(FUSE_LOG_DEBUG, "%s: !ret len remaining=%zd\n", __func__,
+                     len);
             break;
         }
-        in_sg_left -= ret;
         len -= ret;
-    } while (in_sg_left);
+    } while (len);
 
     /* Need to fix out->len on EOF */
     if (len) {
Signature · 1 line
2.25.4
Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UK
#9 lore raw

PATCH 5/7 virtiofsd: Simplify skip byte logic

In reply to Vivek Goyal

We need to skip bytes in two cases.

a. Before we start reading into in_sg, we need to skip iov_len bytes
in the beginning which typically will have fuse_out_header.

b. If preadv() does a short read, then we need to retry preadv() with
remainig bytes and skip the bytes preadv() read in short read.

For case a, there is no reason that skipping logic be inside the while loop. Move it outside. And only retain logic "b" inside while loop.

Also get rid of variable "skip_size". Looks like we can do without it.

---
 tools/virtiofsd/fuse_virtio.c | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)
tools/virtiofsd/fuse_virtio.c +4 -10
index ccad2b3f8a..434fe401cf 100644
@@ -392,17 +392,11 @@ int virtio_send_data_iov(struct fuse_session *se, struct fuse_chan *ch,
     unsigned int in_sg_cpy_count = in_num;
 
     /* skip over parts of in_sg that contained the header iov */
-    size_t skip_size = iov_len;
+    iov_discard_front(&in_sg_ptr, &in_sg_cpy_count, iov_len);
 
     do {
-        if (skip_size != 0) {
-	    iov_discard_front(&in_sg_ptr, &in_sg_cpy_count, skip_size);
-        }
-
-        fuse_log(FUSE_LOG_DEBUG,
-                 "%s: after skip skip_size=%zd in_sg_cpy_count=%d "
-                 "len remaining=%zd\n", __func__, skip_size, in_sg_cpy_count,
-                 len);
+        fuse_log(FUSE_LOG_DEBUG, "%s: in_sg_cpy_count=%d len remaining=%zd\n",
+                 __func__, in_sg_cpy_count, len);
 
         ret = preadv(buf->buf[0].fd, in_sg_ptr, in_sg_cpy_count,
                      buf->buf[0].pos);
@@ -421,7 +415,7 @@ int virtio_send_data_iov(struct fuse_session *se, struct fuse_chan *ch,
         if (ret < len && ret) {
             fuse_log(FUSE_LOG_DEBUG, "%s: ret < len\n", __func__);
             /* Skip over this much next time around */
-            skip_size = ret;
+            iov_discard_front(&in_sg_ptr, &in_sg_cpy_count, ret);
             buf->buf[0].pos += ret;
             len -= ret;
 
Signature · 1 line
2.25.4
Reviewed-by on v1 5/7
#10 lore raw

Re: [PATCH 5/7] virtiofsd: Simplify skip byte logic

Quoted 8 lines · * Vivek Goyal ([email protected]) wrote:

We need to skip bytes in two cases.

a. Before we start reading into in_sg, we need to skip iov_len bytes
in the beginning which typically will have fuse_out_header.

b. If preadv() does a short read, then we need to retry preadv() with
remainig bytes and skip the bytes preadv() read in short read.

Quoted 6 lines

For case a, there is no reason that skipping logic be inside the while loop. Move it outside. And only retain logic "b" inside while loop.

Also get rid of variable "skip_size". Looks like we can do without it.

Yep, now iov_discard_front makes it easy to skip.

Quoted 41 lines
---
 tools/virtiofsd/fuse_virtio.c | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)
tools/virtiofsd/fuse_virtio.c +4 -10
index ccad2b3f8a..434fe401cf 100644
@@ -392,17 +392,11 @@ int virtio_send_data_iov(struct fuse_session *se, struct fuse_chan *ch,
     unsigned int in_sg_cpy_count = in_num;
 
     /* skip over parts of in_sg that contained the header iov */
-    size_t skip_size = iov_len;
+    iov_discard_front(&in_sg_ptr, &in_sg_cpy_count, iov_len);
 
     do {
-        if (skip_size != 0) {
-	    iov_discard_front(&in_sg_ptr, &in_sg_cpy_count, skip_size);
-        }
-
-        fuse_log(FUSE_LOG_DEBUG,
-                 "%s: after skip skip_size=%zd in_sg_cpy_count=%d "
-                 "len remaining=%zd\n", __func__, skip_size, in_sg_cpy_count,
-                 len);
+        fuse_log(FUSE_LOG_DEBUG, "%s: in_sg_cpy_count=%d len remaining=%zd\n",
+                 __func__, in_sg_cpy_count, len);
 
         ret = preadv(buf->buf[0].fd, in_sg_ptr, in_sg_cpy_count,
                      buf->buf[0].pos);
@@ -421,7 +415,7 @@ int virtio_send_data_iov(struct fuse_session *se, struct fuse_chan *ch,
         if (ret < len && ret) {
             fuse_log(FUSE_LOG_DEBUG, "%s: ret < len\n", __func__);
             /* Skip over this much next time around */
-            skip_size = ret;
+            iov_discard_front(&in_sg_ptr, &in_sg_cpy_count, ret);
             buf->buf[0].pos += ret;
             len -= ret;
 
Signature · 1 line
2.25.4
Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UK
#11 lore raw

PATCH 6/7 virtiofsd: Check EOF before short read

In reply to Vivek Goyal

In virtio_send_data_iov() we are checking first for short read and then EOF condition. Change the order. Basically check for error and EOF first and last remaining piece is short ready which will lead to retry automatically at the end of while loop.

Just that it is little simpler to read to the code. There is no need to call "continue" and also one less call of "len-=ret".

---
 tools/virtiofsd/fuse_virtio.c | 21 ++++++++++-----------
 1 file changed, 10 insertions(+), 11 deletions(-)
tools/virtiofsd/fuse_virtio.c +10 -11
index 434fe401cf..aa53808ef9 100644
@@ -410,25 +410,24 @@ int virtio_send_data_iov(struct fuse_session *se, struct fuse_chan *ch,
                      __func__, len);
             goto err;
         }
-        fuse_log(FUSE_LOG_DEBUG, "%s: preadv ret=%d len=%zd\n", __func__,
-                 ret, len);
-        if (ret < len && ret) {
-            fuse_log(FUSE_LOG_DEBUG, "%s: ret < len\n", __func__);
-            /* Skip over this much next time around */
-            iov_discard_front(&in_sg_ptr, &in_sg_cpy_count, ret);
-            buf->buf[0].pos += ret;
-            len -= ret;
 
-            /* Lets do another read */
-            continue;
-        }
         if (!ret) {
             /* EOF case? */
             fuse_log(FUSE_LOG_DEBUG, "%s: !ret len remaining=%zd\n", __func__,
                      len);
             break;
         }
+        fuse_log(FUSE_LOG_DEBUG, "%s: preadv ret=%d len=%zd\n", __func__,
+                 ret, len);
+
         len -= ret;
+        /* Short read. Retry reading remaining bytes */
+        if (len) {
+            fuse_log(FUSE_LOG_DEBUG, "%s: ret < len\n", __func__);
+            /* Skip over this much next time around */
+            iov_discard_front(&in_sg_ptr, &in_sg_cpy_count, ret);
+            buf->buf[0].pos += ret;
+        }
     } while (len);
 
     /* Need to fix out->len on EOF */
Signature · 1 line
2.25.4
Reviewed-by on v1 6/7
#12 lore raw

Re: [PATCH 6/7] virtiofsd: Check EOF before short read

Quoted 9 lines · * Vivek Goyal ([email protected]) wrote:

In virtio_send_data_iov() we are checking first for short read and then EOF condition. Change the order. Basically check for error and EOF first and last remaining piece is short ready which will lead to retry automatically at the end of while loop.

Just that it is little simpler to read to the code. There is no need to call "continue" and also one less call of "len-=ret".

Quoted 47 lines
---
 tools/virtiofsd/fuse_virtio.c | 21 ++++++++++-----------
 1 file changed, 10 insertions(+), 11 deletions(-)
tools/virtiofsd/fuse_virtio.c +10 -11
index 434fe401cf..aa53808ef9 100644
@@ -410,25 +410,24 @@ int virtio_send_data_iov(struct fuse_session *se, struct fuse_chan *ch,
                      __func__, len);
             goto err;
         }
-        fuse_log(FUSE_LOG_DEBUG, "%s: preadv ret=%d len=%zd\n", __func__,
-                 ret, len);
-        if (ret < len && ret) {
-            fuse_log(FUSE_LOG_DEBUG, "%s: ret < len\n", __func__);
-            /* Skip over this much next time around */
-            iov_discard_front(&in_sg_ptr, &in_sg_cpy_count, ret);
-            buf->buf[0].pos += ret;
-            len -= ret;
 
-            /* Lets do another read */
-            continue;
-        }
         if (!ret) {
             /* EOF case? */
             fuse_log(FUSE_LOG_DEBUG, "%s: !ret len remaining=%zd\n", __func__,
                      len);
             break;
         }
+        fuse_log(FUSE_LOG_DEBUG, "%s: preadv ret=%d len=%zd\n", __func__,
+                 ret, len);
+
         len -= ret;
+        /* Short read. Retry reading remaining bytes */
+        if (len) {
+            fuse_log(FUSE_LOG_DEBUG, "%s: ret < len\n", __func__);
+            /* Skip over this much next time around */
+            iov_discard_front(&in_sg_ptr, &in_sg_cpy_count, ret);
+            buf->buf[0].pos += ret;
+        }
     } while (len);
 
     /* Need to fix out->len on EOF */
Signature · 1 line
2.25.4
Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UK
#13 lore raw

PATCH 7/7 virtiofsd: Set req->reply_sent right after sending reply

In reply to Vivek Goyal

There is no reason to set it in label "err". We should be able to set it right after sending reply. It is easier to read.

---
 tools/virtiofsd/fuse_virtio.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
tools/virtiofsd/fuse_virtio.c +1 -4
index aa53808ef9..b1767dd5b9 100644
@@ -446,12 +446,9 @@ int virtio_send_data_iov(struct fuse_session *se, struct fuse_chan *ch,
     vu_queue_notify(dev, q);
     pthread_mutex_unlock(&qi->vq_lock);
     vu_dispatch_unlock(qi->virtio_dev);
+    req->reply_sent = true;
 
 err:
-    if (ret == 0) {
-        req->reply_sent = true;
-    }
-
     return ret;
 }
 
Signature · 1 line
2.25.4
#14 lore raw

Re: [Virtio-fs] [PATCH 7/7] virtiofsd: Set req->reply_sent right after sending reply

Quoted 13 lines · Vivek Goyal

There is no reason to set it in label "err". We should be able to set it right after sending reply. It is easier to read.

---
 tools/virtiofsd/fuse_virtio.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
tools/virtiofsd/fuse_virtio.c +0 -0
index aa53808ef9..b1767dd5b9 100644

tools/virtiofsd/fuse_virtio.c int virtio_send_data_iov(struct fuse_session *se, struct fuse_chan *ch, · line 451

Quoted 6 lines
tools/virtiofsd/fuse_virtio.c +1 -0
@@ -446,12 +446,9 @@ int virtio_send_data_iov(struct fuse_session *se, struct fuse_chan *ch,
     vu_queue_notify(dev, q);
     pthread_mutex_unlock(&qi->vq_lock);
     vu_dispatch_unlock(qi->virtio_dev);
+    req->reply_sent = true;
 
 err:

Just a really minor comment: after all these changes, I would venture that "out" is a more appropriate label name than "err" at this point.

Quoted 8 lines
tools/virtiofsd/fuse_virtio.c +0 -4
-    if (ret == 0) {
-        req->reply_sent = true;
-    }
-
     return ret;
 }
 
#15 lore raw

Re: [Virtio-fs] [PATCH 7/7] virtiofsd: Set req->reply_sent right after sending reply

Quoted 19 lines · Connor Kuehl
Quoted 18 lines · Vivek Goyal

There is no reason to set it in label "err". We should be able to set it right after sending reply. It is easier to read.

---
 tools/virtiofsd/fuse_virtio.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
tools/virtiofsd/fuse_virtio.c +1 -0
index aa53808ef9..b1767dd5b9 100644
@@ -446,12 +446,9 @@ int virtio_send_data_iov(struct fuse_session *se, struct fuse_chan *ch,
     vu_queue_notify(dev, q);
     pthread_mutex_unlock(&qi->vq_lock);
     vu_dispatch_unlock(qi->virtio_dev);
+    req->reply_sent = true;
 
Quoted 4 lines

tools/virtiofsd/fuse_virtio.c int virtio_send_data_iov(struct fuse_session *se, struct fuse_chan *ch, · line 451

Quoted 1 line
tools/virtiofsd/fuse_virtio.c +0 -0
 err:

Just a really minor comment: after all these changes, I would venture that "out" is a more appropriate label name than "err" at this point.

May be. This path is used both by error path as well as success path. Just that value of "ret" changes. I am not particular about it. So I will change this to "out".

Thanks
Vivek

Quoted 10 lines
Quoted 9 lines
tools/virtiofsd/fuse_virtio.c +0 -4
-    if (ret == 0) {
-        req->reply_sent = true;
-    }
-
     return ret;
 }
 
#16 lore raw

Re: [Virtio-fs] [PATCH 7/7] virtiofsd: Set req->reply_sent right after sending reply

Quoted 20 lines · * Vivek Goyal ([email protected]) wrote:
Quoted 19 lines · Connor Kuehl
Quoted 18 lines · Vivek Goyal

There is no reason to set it in label "err". We should be able to set it right after sending reply. It is easier to read.

---
 tools/virtiofsd/fuse_virtio.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
tools/virtiofsd/fuse_virtio.c +1 -0
index aa53808ef9..b1767dd5b9 100644
@@ -446,12 +446,9 @@ int virtio_send_data_iov(struct fuse_session *se, struct fuse_chan *ch,
     vu_queue_notify(dev, q);
     pthread_mutex_unlock(&qi->vq_lock);
     vu_dispatch_unlock(qi->virtio_dev);
+    req->reply_sent = true;
 
Quoted 8 lines
Quoted 4 lines

tools/virtiofsd/fuse_virtio.c int virtio_send_data_iov(struct fuse_session *se, struct fuse_chan *ch, · line 451

Quoted 1 line
tools/virtiofsd/fuse_virtio.c +0 -0
 err:

Just a really minor comment: after all these changes, I would venture that "out" is a more appropriate label name than "err" at this point.

May be. This path is used both by error path as well as success path. Just that value of "ret" changes. I am not particular about it. So I will change this to "out".

Well, if it only does 'return ret' we can get rid of the label and just do return's at the places that did the goto's.

Dave

Quoted 17 lines

Thanks
Vivek

Quoted 10 lines

tools/virtiofsd/fuse_virtio.c int virtio_send_data_iov(struct fuse_session *se, struct fuse_chan *ch, · line 454

Quoted 9 lines
tools/virtiofsd/fuse_virtio.c +0 -4
-    if (ret == 0) {
-        req->reply_sent = true;
-    }
-
     return ret;
 }
 

_______________________________________________
Virtio-fs mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/virtio-fs

Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Reviewed-by on v1 7/7
#17 lore raw

Re: [PATCH 7/7] virtiofsd: Set req->reply_sent right after sending reply

In reply to Vivek Goyal
Quoted 4 lines · * Vivek Goyal ([email protected]) wrote:

There is no reason to set it in label "err". We should be able to set it right after sending reply. It is easier to read.

Quoted 25 lines
---
 tools/virtiofsd/fuse_virtio.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
tools/virtiofsd/fuse_virtio.c +1 -4
index aa53808ef9..b1767dd5b9 100644
@@ -446,12 +446,9 @@ int virtio_send_data_iov(struct fuse_session *se, struct fuse_chan *ch,
     vu_queue_notify(dev, q);
     pthread_mutex_unlock(&qi->vq_lock);
     vu_dispatch_unlock(qi->virtio_dev);
+    req->reply_sent = true;
 
 err:
-    if (ret == 0) {
-        req->reply_sent = true;
-    }
-
     return ret;
 }
 
Signature · 1 line
2.25.4
Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UK
#18 lore raw
In reply to Vivek Goyal
Patchew URL: https://patchew.org/QEMU/[email protected]/

Patchew URL: https://patchew.org/QEMU/[email protected]/

Hi,

This series seems to have some coding style problems. See output below for more information:

Type: series
Message-id: [email protected]
Subject: [PATCH 0/7] virtiofsd: Few cleanups in virtio_send_data_iov()

=== TEST SCRIPT BEGIN ===
#!/bin/bash
git rev-parse base > /dev/null || exit 0
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram
./scripts/checkpatch.pl --mailback base..
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384

Quoted 1 line

From https://github.com/patchew-project/qemu

- [tag update] patchew/[email protected] -> patchew/[email protected]
* [new tag] patchew/[email protected] -> patchew/[email protected]
Switched to a new branch 'test'
b6ced9e virtiofsd: Set req->reply_sent right after sending reply c866cc2 virtiofsd: Check EOF before short read
8d45f07 virtiofsd: Simplify skip byte logic
b7afa17 virtiofsd: get rid of in_sg_left variable 37ba755 virtiofsd: Use iov_discard_front() to skip bytes f87fbd3 virtiofsd: Get rid of unreachable code in read cc6fb4a virtiofsd: Check for EINTR in preadv() and retry

=== OUTPUT BEGIN ===
1/7 Checking commit cc6fb4a9cf99 (virtiofsd: Check for EINTR in preadv() and retry) 2/7 Checking commit f87fbd364bcd (virtiofsd: Get rid of unreachable code in read) 3/7 Checking commit 37ba755df99d (virtiofsd: Use iov_discard_front() to skip bytes)
ERROR: code indent should never use tabs
#44: FILE: tools/virtiofsd/fuse_virtio.c:400:
+^I iov_discard_front(&in_sg_ptr, &in_sg_cpy_count, skip_size);$

total: 1 errors, 0 warnings, 26 lines checked

Patch 3/7 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.

4/7 Checking commit b7afa17acdc2 (virtiofsd: get rid of in_sg_left variable) 5/7 Checking commit 8d45f07e917d (virtiofsd: Simplify skip byte logic)
6/7 Checking commit c866cc21d91c (virtiofsd: Check EOF before short read) 7/7 Checking commit b6ced9e49587 (virtiofsd: Set req->reply_sent right after sending reply) === OUTPUT END ===

Test command exited with code: 1

The full log is available at
http://patchew.org/logs/[email protected]/testing.checkpatch/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to [email protected]

Reviewed-by on the v1 series
#19 lore raw
In reply to Vivek Goyal
Quoted 18 lines · Vivek Goyal

Hi,

Code in virtio_send_data_iov() little twisted and complicated. This patch series just tries to simplify it a bit to make it little easier to read this piece of code.

Thanks
Vivek

Vivek Goyal (7):
virtiofsd: Check for EINTR in preadv() and retry
virtiofsd: Get rid of unreachable code in read
virtiofsd: Use iov_discard_front() to skip bytes
virtiofsd: get rid of in_sg_left variable
virtiofsd: Simplify skip byte logic
virtiofsd: Check EOF before short read
virtiofsd: Set req->reply_sent right after sending reply

Quoted 3 lines
 tools/virtiofsd/fuse_virtio.c | 67 +++++++++++------------------------
 1 file changed, 21 insertions(+), 46 deletions(-)

With the codestyle fix to appease the bot:

(For the series)

#20 lore raw
Quoted 23 lines · Connor Kuehl
Quoted 18 lines · Vivek Goyal

Hi,

Code in virtio_send_data_iov() little twisted and complicated. This patch series just tries to simplify it a bit to make it little easier to read this piece of code.

Thanks
Vivek

Vivek Goyal (7):
virtiofsd: Check for EINTR in preadv() and retry
virtiofsd: Get rid of unreachable code in read
virtiofsd: Use iov_discard_front() to skip bytes
virtiofsd: get rid of in_sg_left variable
virtiofsd: Simplify skip byte logic
virtiofsd: Check EOF before short read
virtiofsd: Set req->reply_sent right after sending reply

Quoted 3 lines
 tools/virtiofsd/fuse_virtio.c | 67 +++++++++++------------------------
 1 file changed, 21 insertions(+), 46 deletions(-)
Quoted 5 lines

With the codestyle fix to appease the bot:

(For the series)

Thanks. I will fix the coding style issue and repost the patch series.

Vivek