Re: [Qemu-devel] [PATCH v9 05/13] block: move block_copy from block/backup.c to separate file

2019-08-29 Thread Vladimir Sementsov-Ogievskiy
28.08.2019 19:16, Max Reitz wrote:
> On 26.08.19 18:13, Vladimir Sementsov-Ogievskiy wrote:
>> Split block_copy to separate file, to be cleanly shared with backup-top
>> filter driver in further commits.
>>
>> It's a clean movement, the only change is drop "static" from interface
>> functions.
>>
>> Signed-off-by: Vladimir Sementsov-Ogievskiy 
>> ---
>>   include/block/block-copy.h |  59 +++
>>   block/backup.c | 313 +
>>   block/block-copy.c | 307 
>>   block/Makefile.objs|   1 +
>>   block/trace-events |   2 +
>>   5 files changed, 370 insertions(+), 312 deletions(-)
>>   create mode 100644 include/block/block-copy.h
>>   create mode 100644 block/block-copy.c
> 
> May change depending on changes to the preceding patches, but FWIW
> 
> Reviewed-by: Max Reitz 
> 

If you don't mind, I'll keep it until the patch doing simple nochange movement.

-- 
Best regards,
Vladimir


Re: [Qemu-devel] [PATCH v9 05/13] block: move block_copy from block/backup.c to separate file

2019-08-28 Thread Max Reitz
On 26.08.19 18:13, Vladimir Sementsov-Ogievskiy wrote:
> Split block_copy to separate file, to be cleanly shared with backup-top
> filter driver in further commits.
> 
> It's a clean movement, the only change is drop "static" from interface
> functions.
> 
> Signed-off-by: Vladimir Sementsov-Ogievskiy 
> ---
>  include/block/block-copy.h |  59 +++
>  block/backup.c | 313 +
>  block/block-copy.c | 307 
>  block/Makefile.objs|   1 +
>  block/trace-events |   2 +
>  5 files changed, 370 insertions(+), 312 deletions(-)
>  create mode 100644 include/block/block-copy.h
>  create mode 100644 block/block-copy.c

May change depending on changes to the preceding patches, but FWIW

Reviewed-by: Max Reitz 



signature.asc
Description: OpenPGP digital signature


[Qemu-devel] [PATCH v9 05/13] block: move block_copy from block/backup.c to separate file

2019-08-26 Thread Vladimir Sementsov-Ogievskiy
Split block_copy to separate file, to be cleanly shared with backup-top
filter driver in further commits.

It's a clean movement, the only change is drop "static" from interface
functions.

Signed-off-by: Vladimir Sementsov-Ogievskiy 
---
 include/block/block-copy.h |  59 +++
 block/backup.c | 313 +
 block/block-copy.c | 307 
 block/Makefile.objs|   1 +
 block/trace-events |   2 +
 5 files changed, 370 insertions(+), 312 deletions(-)
 create mode 100644 include/block/block-copy.h
 create mode 100644 block/block-copy.c

diff --git a/include/block/block-copy.h b/include/block/block-copy.h
new file mode 100644
index 00..0dd7a3f7bf
--- /dev/null
+++ b/include/block/block-copy.h
@@ -0,0 +1,59 @@
+/*
+ * block_copy API
+ *
+ * Copyright (C) 2013 Proxmox Server Solutions
+ * Copyright (c) 2019 Virtuozzo International GmbH.
+ *
+ * Authors:
+ *  Dietmar Maurer (diet...@proxmox.com)
+ *  Vladimir Sementsov-Ogievskiy 
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
+#ifndef BLOCK_COPY_H
+#define BLOCK_COPY_H
+
+#include "block/block.h"
+
+/*
+ * ProgressCallbackFunc
+ *
+ * Called when some progress is done in context of BlockCopyState:
+ *  1. When some bytes copied, called with @bytes > 0.
+ *  2. When some bytes resetted from copy_bitmap, called with @bytes = 0 (user
+ * may recalculate remaining bytes from copy_bitmap dirty count.
+ */
+typedef void (*ProgressCallbackFunc)(int64_t bytes, void *opaque);
+typedef struct BlockCopyState {
+BlockBackend *source;
+BlockBackend *target;
+BdrvDirtyBitmap *copy_bitmap;
+int64_t cluster_size;
+bool use_copy_range;
+int64_t copy_range_size;
+uint64_t len;
+
+BdrvRequestFlags write_flags;
+bool skip_unallocated;
+
+ProgressCallbackFunc progress_callback;
+void *progress_opaque;
+} BlockCopyState;
+
+BlockCopyState *block_copy_state_new(
+BlockDriverState *source, BlockDriverState *target,
+int64_t cluster_size, BdrvRequestFlags write_flags,
+ProgressCallbackFunc progress_callback, void *progress_opaque,
+Error **errp);
+
+void block_copy_state_free(BlockCopyState *s);
+
+int64_t block_copy_reset_unallocated(BlockCopyState *s,
+ int64_t offset, int64_t *count);
+
+int coroutine_fn block_copy(BlockCopyState *s, int64_t offset, uint64_t bytes,
+bool *error_is_read, bool is_write_notifier);
+
+#endif /* BLOCK_COPY_H */
diff --git a/block/backup.c b/block/backup.c
index d9192ac778..d927c63e5a 100644
--- a/block/backup.c
+++ b/block/backup.c
@@ -18,6 +18,7 @@
 #include "block/block_int.h"
 #include "block/blockjob_int.h"
 #include "block/block_backup.h"
+#include "block/block-copy.h"
 #include "qapi/error.h"
 #include "qapi/qmp/qerror.h"
 #include "qemu/ratelimit.h"
@@ -35,31 +36,6 @@ typedef struct CowRequest {
 CoQueue wait_queue; /* coroutines blocked on this request */
 } CowRequest;
 
-/*
- * ProgressCallbackFunc
- *
- * Called when some progress is done in context of BlockCopyState:
- *  1. When some bytes copied, called with @bytes > 0.
- *  2. When some bytes resetted from copy_bitmap, called with @bytes = 0 (user
- * may recalculate remaining bytes from copy_bitmap dirty count.
- */
-typedef void (*ProgressCallbackFunc)(int64_t bytes, void *opaque);
-typedef struct BlockCopyState {
-BlockBackend *source;
-BlockBackend *target;
-BdrvDirtyBitmap *copy_bitmap;
-int64_t cluster_size;
-bool use_copy_range;
-int64_t copy_range_size;
-uint64_t len;
-
-BdrvRequestFlags write_flags;
-bool skip_unallocated;
-
-ProgressCallbackFunc progress_callback;
-void *progress_opaque;
-} BlockCopyState;
-
 typedef struct BackupBlockJob {
 BlockJob common;
 
@@ -118,293 +94,6 @@ static void cow_request_end(CowRequest *req)
 qemu_co_queue_restart_all(>wait_queue);
 }
 
-static void block_copy_state_free(BlockCopyState *s)
-{
-if (!s) {
-return;
-}
-
-bdrv_release_dirty_bitmap(blk_bs(s->source), s->copy_bitmap);
-blk_unref(s->source);
-s->source = NULL;
-blk_unref(s->target);
-s->target = NULL;
-g_free(s);
-}
-
-static BlockCopyState *block_copy_state_new(
-BlockDriverState *source, BlockDriverState *target,
-int64_t cluster_size, BdrvRequestFlags write_flags,
-ProgressCallbackFunc progress_callback, void *progress_opaque,
-Error **errp)
-{
-BlockCopyState *s;
-int ret;
-uint64_t no_resize = BLK_PERM_CONSISTENT_READ | BLK_PERM_WRITE |
- BLK_PERM_WRITE_UNCHANGED | BLK_PERM_GRAPH_MOD;
-BdrvDirtyBitmap *copy_bitmap =
-bdrv_create_dirty_bitmap(source, cluster_size, NULL, errp);
-
-if (!copy_bitmap) {
-return NULL;
-}
-