<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
</head>
<body>
<div style="color: rgb(33, 33, 33); background-color: rgb(255, 255, 255);" dir="auto">
I concur... Client usermode code is required to deal with ret < requested length... In this case, the requested length being the sum of the lengths of each iov segment.</div>
<div style="color: rgb(33, 33, 33); background-color: rgb(255, 255, 255);" dir="auto">
<br>
</div>
<div style="color: rgb(33, 33, 33); background-color: rgb(255, 255, 255);" dir="auto">
There are two cases where this can occure:</div>
<div style="color: rgb(33, 33, 33); background-color: rgb(255, 255, 255);" dir="auto">
1) the offset+Len > file size, and</div>
<div style="color: rgb(33, 33, 33); background-color: rgb(255, 255, 255);" dir="auto">
2) the process intercepted an EINTR before all requested data became available</div>
<div style="color: rgb(33, 33, 33); background-color: rgb(255, 255, 255);" dir="auto">
<br>
</div>
<div style="color: rgb(33, 33, 33); background-color: rgb(255, 255, 255);" dir="auto">
For file systems, we don't deal with #2...but we .just deal with #1.</div>
<div id="ms-outlook-mobile-signature">
<div><br>
</div>
Get <a href="https://aka.ms/AAb9ysg">Outlook for Android</a></div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> virtio-fs-bounces@redhat.com <virtio-fs-bounces@redhat.com> on behalf of Vivek Goyal <vgoyal@redhat.com><br>
<b>Sent:</b> Friday, May 7, 2021 1:59:09 PM<br>
<b>To:</b> Dr. David Alan Gilbert <dgilbert@redhat.com>; Stefan Hajnoczi <stefanha@redhat.com><br>
<b>Cc:</b> virtio-fs-list <virtio-fs@redhat.com><br>
<b>Subject:</b> [Virtio-fs] Few queries about virtiofsd read implementation</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt;">
<div class="PlainText">External email: Use caution opening links or attachments<br>
<br>
<br>
Hi David/Stefan,<br>
<br>
I am browsing through the code of read requests (FUSE_READ) in virtiofsd<br>
(and in virtiofs) and I have few questions. You folks probably know the<br>
answers.<br>
<br>
1. virtio_send_data_iov(), reads the data from file into the scatter list.<br>
  Some of the code looks strange.<br>
<br>
  We seem to be retrying read if we read less number of bytes than what<br>
  client asked for. I am wondering shoudl this really be our<br>
  responsibility or client should deal with it. I am assuming that client<br>
  should be ready to deal with less number of bytes read.<br>
<br>
  So what was the thought process behind retrying.<br>
<br>
          if (ret < len && ret) {<br>
            fuse_log(FUSE_LOG_DEBUG, "%s: ret < len\n", __func__);<br>
            /* Skip over this much next time around */<br>
            skip_size = ret;<br>
            buf->buf[0].pos += ret;<br>
            len -= ret;<br>
<br>
            /* Lets do another read */<br>
            continue;<br>
        }<br>
<br>
- After this we have code where if number of bytes read are not same<br>
  as we expect to, then we return EIO.<br>
<br>
          if (ret != len) {<br>
            fuse_log(FUSE_LOG_DEBUG, "%s: ret!=len\n", __func__);<br>
            ret = EIO;<br>
            free(in_sg_cpy);<br>
            goto err;<br>
        }<br>
<br>
  When do we hit this. IIUC, preadv() will return.<br>
<br>
  A. Either number of bytes we expected (no issues)<br>
  B. 0 in case of EOF (We break out of loop and just return to client with<br>
                      number of bytes we have read so far).<br>
  C. <0 (This is error case and we return error to client)<br>
  D. X bytes which is less than len.<br>
<br>
To handle D we have code to retry. So when do we hit the above if<br>
condition where "ret !=len). Is this a dead code. Or I missed something.<br>
<br>
2. When client sent FUSE_READ, we put pointer to pages into sglist. IIUC,<br>
   we put pointer to "struct page *" and not actual page. So who converts<br>
   these struct page pointer to memory belong to page.<br>
<br>
   sg_init_fuse_pages() {<br>
        sg_set_page(&sg[i], pages[i], this_len, page_descs[i].offset);<br>
   }<br>
<br>
3. Who converts guest memory address (when) into qemu process address which is<br>
   accessible by virtiofsd.<br>
<br>
Thanks<br>
Vivek<br>
<br>
_______________________________________________<br>
Virtio-fs mailing list<br>
Virtio-fs@redhat.com<br>
<a href="https://listman.redhat.com/mailman/listinfo/virtio-fs">https://listman.redhat.com/mailman/listinfo/virtio-fs</a><br>
<br>
</div>
</span></font></div>
</body>
</html>