When doping chunked multi-reads of a blob bigger than the max readsize,
authorRonnie Sahlberg <ronniesahlberg@gmail.com>
Mon, 20 Jun 2011 20:07:29 +0000 (06:07 +1000)
committerRonnie Sahlberg <ronniesahlberg@gmail.com>
Mon, 20 Jun 2011 20:07:29 +0000 (06:07 +1000)
a read can sometimes span beyond the end of file.

In which case individual smal read chunks beyond the end of file will return OK, 0 bytes of data and EOF==1

For this case, trap when len==0 and ignore these chunks.
Do not update the read-count if / when len is 0.

examples/nfsclient-sync.c
lib/libnfs.c

index 460af53968eb2bf7535727a5d4e6fc68044ea198..d4f6b0c0226fdc18285ce0c2fc10c67db253c71e 100644 (file)
@@ -20,7 +20,7 @@
 
 #define SERVER "10.1.1.27"
 #define EXPORT "/VIRTUAL"
-#define NFSFILE "/BOOKS/Classics/Dracula.djvu"
+#define NFSFILE "/BOOKS/Classics/Dracula.djvu.truncated"
 #define NFSFILER "/BOOKS/Classics/Dracula.djvu.renamed"
 #define NFSFILEW "/BOOKS/Classics/foo"
 #define NFSDIR "/BOOKS/Classics/"
@@ -46,7 +46,7 @@ struct client {
 };
 
 
-char buf[2*1024*1024];
+char buf[5*1024*1024];
 
 int main(int argc _U_, char *argv[] _U_)
 {
index 905e9d80656ca99e38c567d50da6211a70f7a3b7..43806538d6c3cb9871f268b7a09eb604370f78ba 100644 (file)
@@ -859,10 +859,12 @@ static void nfs_pread_mcb(struct rpc_context *rpc _U_, int status, void *command
                if (res->status != NFS3_OK) {
                        rpc_set_error(nfs->rpc, "NFS: Read failed with %s(%d)", nfsstat3_to_str(res->status), nfsstat3_to_errno(res->status));
                        data->error = 1;
-               } else {
-                       memcpy(&data->buffer[mdata->offset - data->start_offset], res->READ3res_u.resok.data.data_val, res->READ3res_u.resok.count);
-                       if ((unsigned)data->max_offset < mdata->offset + res->READ3res_u.resok.count) {
-                               data->max_offset = mdata->offset + res->READ3res_u.resok.count;
+               } else  {
+                       if (res->READ3res_u.resok.count > 0) {
+                               memcpy(&data->buffer[mdata->offset - data->start_offset], res->READ3res_u.resok.data.data_val, res->READ3res_u.resok.count);
+                               if ((unsigned)data->max_offset < mdata->offset + res->READ3res_u.resok.count) {
+                                       data->max_offset = mdata->offset + res->READ3res_u.resok.count;
+                               }
                        }
                }
        }