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

login
register
mail settings
Submitter Christoph Hellwig
Date July 8, 2012, 7:33 p.m.
Message ID <20120708193316.GA23863@lst.de>
Download mbox | patch
Permalink /patch/169667/
State New
Headers show

Comments

Christoph Hellwig - July 8, 2012, 7:33 p.m.
Only buffers that map to unallocated blocks need to be zeroed.

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

---
 block/sheepdog.c |   28 ++++++++++++++++++----------
 1 file changed, 18 insertions(+), 10 deletions(-)
MORITA Kazutaka - July 9, 2012, 8:27 a.m.
At Sun, 8 Jul 2012 21:33:16 +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 |   28 ++++++++++++++++++----------
>  1 file changed, 18 insertions(+), 10 deletions(-)
> 
> Index: qemu/block/sheepdog.c
> ===================================================================
> --- qemu.orig/block/sheepdog.c	2012-07-08 21:20:12.896597656 +0200
> +++ qemu/block/sheepdog.c	2012-07-08 21:20:56.563264061 +0200
> @@ -1556,18 +1556,26 @@ 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;
> +            }
> +            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) {
> -- 

There is no code to remove a blind memset from sd_co_readv, which
existed in the previous patch.

The others look good to me.

Thanks,

Kazutaka

Patch

Index: qemu/block/sheepdog.c
===================================================================
--- qemu.orig/block/sheepdog.c	2012-07-08 21:20:12.896597656 +0200
+++ qemu/block/sheepdog.c	2012-07-08 21:20:56.563264061 +0200
@@ -1556,18 +1556,26 @@  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;
+            }
+            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) {