Patchwork [v3] sheepdog: do not blindly memset all read buffers

login
register
mail settings
Submitter Christoph Hellwig
Date July 9, 2012, 2:34 p.m.
Message ID <20120709143413.GA5226@lst.de>
Download mbox | patch
Permalink /patch/169862/
State New
Headers show

Comments

Christoph Hellwig - July 9, 2012, 2:34 p.m.
Only buffers that map to unallocated blocks need to be zeroed.

Signed-off-by: Christoph Hellwig <hch@lst.de>

---
 block/sheepdog.c |   37 ++++++++++++++++++-------------------
 1 file changed, 18 insertions(+), 19 deletions(-)
MORITA Kazutaka - July 9, 2012, 6:23 p.m.
At Mon, 9 Jul 2012 16:34:13 +0200,
Christoph Hellwig wrote:
> 
> Only buffers that map to unallocated blocks need to be zeroed.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> 
> ---
>  block/sheepdog.c |   37 ++++++++++++++++++-------------------
>  1 file changed, 18 insertions(+), 19 deletions(-)

Acked-by: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
Kevin Wolf - July 10, 2012, 10:53 a.m.
Am 09.07.2012 20:23, schrieb MORITA Kazutaka:
> At Mon, 9 Jul 2012 16:34:13 +0200,
> Christoph Hellwig wrote:
>>
>> Only buffers that map to unallocated blocks need to be zeroed.
>>
>> Signed-off-by: Christoph Hellwig <hch@lst.de>
>>
>> ---
>>  block/sheepdog.c |   37 ++++++++++++++++++-------------------
>>  1 file changed, 18 insertions(+), 19 deletions(-)
> 
> Acked-by: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>

Thanks, applied to the block branch.

Kevin
Kevin Wolf - July 10, 2012, 1:55 p.m.
Am 10.07.2012 12:53, schrieb Kevin Wolf:
> Am 09.07.2012 20:23, schrieb MORITA Kazutaka:
>> At Mon, 9 Jul 2012 16:34:13 +0200,
>> Christoph Hellwig wrote:
>>>
>>> Only buffers that map to unallocated blocks need to be zeroed.
>>>
>>> Signed-off-by: Christoph Hellwig <hch@lst.de>
>>>
>>> ---
>>>  block/sheepdog.c |   37 ++++++++++++++++++-------------------
>>>  1 file changed, 18 insertions(+), 19 deletions(-)
>>
>> Acked-by: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
> 
> Thanks, applied to the block branch.

And dropped again. Anthony has pulled Michael Tokarev's iovec patches
now, so qemu_iovec_memset_skip() doesn't exist any more. Please rebase.

Kevin

Patch

Index: qemu/block/sheepdog.c
===================================================================
--- qemu.orig/block/sheepdog.c	2012-07-09 16:16:01.216467182 +0200
+++ qemu/block/sheepdog.c	2012-07-09 16:22:11.039798306 +0200
@@ -1556,18 +1556,25 @@  static int coroutine_fn sd_co_rw_vector(
 
         len = MIN(total - done, SD_DATA_OBJ_SIZE - offset);
 
-        if (!inode->data_vdi_id[idx]) {
-            if (acb->aiocb_type == AIOCB_READ_UDATA) {
+        switch (acb->aiocb_type) {
+        case AIOCB_READ_UDATA:
+            if (!inode->data_vdi_id[idx]) {
+                qemu_iovec_memset_skip(acb->qiov, 0, len, done);
                 goto done;
             }
-
-            create = 1;
-        } else if (acb->aiocb_type == AIOCB_WRITE_UDATA
-                   && !is_data_obj_writable(inode, idx)) {
-            /* Copy-On-Write */
-            create = 1;
-            old_oid = oid;
-            flags = SD_FLAG_CMD_COW;
+            break;
+        case AIOCB_WRITE_UDATA:
+            if (!inode->data_vdi_id[idx]) {
+                create = 1;
+            } else if (!is_data_obj_writable(inode, idx)) {
+                /* Copy-On-Write */
+                create = 1;
+                old_oid = oid;
+                flags = SD_FLAG_CMD_COW;
+            }
+            break;
+        default:
+            break;
         }
 
         if (create) {
@@ -1655,20 +1662,12 @@  static coroutine_fn int sd_co_readv(Bloc
                        int nb_sectors, QEMUIOVector *qiov)
 {
     SheepdogAIOCB *acb;
-    int i, ret;
+    int ret;
 
     acb = sd_aio_setup(bs, qiov, sector_num, nb_sectors, NULL, NULL);
     acb->aiocb_type = AIOCB_READ_UDATA;
     acb->aio_done_func = sd_finish_aiocb;
 
-    /*
-     * TODO: we can do better; we don't need to initialize
-     * blindly.
-     */
-    for (i = 0; i < qiov->niov; i++) {
-        memset(qiov->iov[i].iov_base, 0, qiov->iov[i].iov_len);
-    }
-
     ret = sd_co_rw_vector(acb);
     if (ret <= 0) {
         qemu_aio_release(acb);