diff mbox

[RFC,02/16] block: Set dirty before doing write

Message ID 1453804705-7205-3-git-send-email-famz@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Fam Zheng Jan. 26, 2016, 10:38 a.m. UTC
So that driver can write the dirty bits into persistent dirty bitmaps in
the write callback.

Signed-off-by: Fam Zheng <famz@redhat.com>
---
 block/io.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Eric Blake Jan. 26, 2016, 5:52 p.m. UTC | #1
On 01/26/2016 03:38 AM, Fam Zheng wrote:
> So that driver can write the dirty bits into persistent dirty bitmaps in
> the write callback.
> 
> Signed-off-by: Fam Zheng <famz@redhat.com>
> ---
>  block/io.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)

Reviewed-by: Eric Blake <eblake@redhat.com>

> 
> diff --git a/block/io.c b/block/io.c
> index 343ff1f..b964e7e 100644
> --- a/block/io.c
> +++ b/block/io.c
> @@ -1164,6 +1164,8 @@ static int coroutine_fn bdrv_aligned_pwritev(BlockDriverState *bs,
>          }
>      }
>  
> +    bdrv_set_dirty(bs, sector_num, nb_sectors);
> +
>      if (ret < 0) {
>          /* Do nothing, write notifier decided to fail this request */

This sets the dirty bit even on failure, but I guess that doesn't hurt
(it's better to mark too much dirty than it is to not mark enough).
John Snow Feb. 9, 2016, 12:11 a.m. UTC | #2
On 01/26/2016 05:38 AM, Fam Zheng wrote:
> So that driver can write the dirty bits into persistent dirty bitmaps in
> the write callback.
> 
> Signed-off-by: Fam Zheng <famz@redhat.com>
> ---
>  block/io.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/block/io.c b/block/io.c
> index 343ff1f..b964e7e 100644
> --- a/block/io.c
> +++ b/block/io.c
> @@ -1164,6 +1164,8 @@ static int coroutine_fn bdrv_aligned_pwritev(BlockDriverState *bs,
>          }
>      }
>  
> +    bdrv_set_dirty(bs, sector_num, nb_sectors);
> +
>      if (ret < 0) {
>          /* Do nothing, write notifier decided to fail this request */
>      } else if (flags & BDRV_REQ_ZERO_WRITE) {
> @@ -1179,8 +1181,6 @@ static int coroutine_fn bdrv_aligned_pwritev(BlockDriverState *bs,
>          ret = bdrv_co_flush(bs);
>      }
>  
> -    bdrv_set_dirty(bs, sector_num, nb_sectors);
> -
>      if (bs->wr_highest_offset < offset + bytes) {
>          bs->wr_highest_offset = offset + bytes;
>      }
> 

Might want a comment here acknowledging the write gets errantly set on
write failure, but that for $reasons it needs to be above anyway -- so
someone doesn't helpfully try to move it back below.

Reviewed-by: John Snow <jsnow@redhat.com>
diff mbox

Patch

diff --git a/block/io.c b/block/io.c
index 343ff1f..b964e7e 100644
--- a/block/io.c
+++ b/block/io.c
@@ -1164,6 +1164,8 @@  static int coroutine_fn bdrv_aligned_pwritev(BlockDriverState *bs,
         }
     }
 
+    bdrv_set_dirty(bs, sector_num, nb_sectors);
+
     if (ret < 0) {
         /* Do nothing, write notifier decided to fail this request */
     } else if (flags & BDRV_REQ_ZERO_WRITE) {
@@ -1179,8 +1181,6 @@  static int coroutine_fn bdrv_aligned_pwritev(BlockDriverState *bs,
         ret = bdrv_co_flush(bs);
     }
 
-    bdrv_set_dirty(bs, sector_num, nb_sectors);
-
     if (bs->wr_highest_offset < offset + bytes) {
         bs->wr_highest_offset = offset + bytes;
     }