[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v6 07/12] block/qcow2: qcow2_co_pwrite_zeroes: use QEMU_LOCK_GUAR
From: |
Vladimir Sementsov-Ogievskiy |
Subject: |
[PATCH v6 07/12] block/qcow2: qcow2_co_pwrite_zeroes: use QEMU_LOCK_GUARD |
Date: |
Thu, 22 Apr 2021 19:30:41 +0300 |
We'll need to handle qcow2_get_host_offset() success and failure in
separate in future patch. Still, let's go a bit further and refactor
the function to use QEMU_LOCK_GUARD.
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
---
block/qcow2.c | 37 +++++++++++++++++++------------------
1 file changed, 19 insertions(+), 18 deletions(-)
diff --git a/block/qcow2.c b/block/qcow2.c
index 066d44e2be..be62585e03 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -3931,10 +3931,6 @@ static coroutine_fn int
qcow2_co_pwrite_zeroes(BlockDriverState *bs,
}
if (head || tail) {
- uint64_t off;
- unsigned int nr;
- QCow2SubclusterType type;
-
assert(head + bytes + tail <= s->subcluster_size);
/* check whether remainder of cluster already reads as zero */
@@ -3942,32 +3938,37 @@ static coroutine_fn int
qcow2_co_pwrite_zeroes(BlockDriverState *bs,
is_zero(bs, offset + bytes, tail))) {
return -ENOTSUP;
}
+ }
+
+ QEMU_LOCK_GUARD(&s->lock);
+
+ if (head || tail) {
+ uint64_t off;
+ unsigned int nr;
+ QCow2SubclusterType type;
- qemu_co_mutex_lock(&s->lock);
/* We can have new write after previous check */
offset -= head;
bytes = s->subcluster_size;
nr = s->subcluster_size;
ret = qcow2_get_host_offset(bs, offset, &nr, &off, &type);
- if (ret < 0 ||
- (type != QCOW2_SUBCLUSTER_UNALLOCATED_PLAIN &&
- type != QCOW2_SUBCLUSTER_UNALLOCATED_ALLOC &&
- type != QCOW2_SUBCLUSTER_ZERO_PLAIN &&
- type != QCOW2_SUBCLUSTER_ZERO_ALLOC)) {
- qemu_co_mutex_unlock(&s->lock);
- return ret < 0 ? ret : -ENOTSUP;
+ if (ret < 0) {
+ return ret;
+ }
+
+ if (type != QCOW2_SUBCLUSTER_UNALLOCATED_PLAIN &&
+ type != QCOW2_SUBCLUSTER_UNALLOCATED_ALLOC &&
+ type != QCOW2_SUBCLUSTER_ZERO_PLAIN &&
+ type != QCOW2_SUBCLUSTER_ZERO_ALLOC)
+ {
+ return -ENOTSUP;
}
- } else {
- qemu_co_mutex_lock(&s->lock);
}
trace_qcow2_pwrite_zeroes(qemu_coroutine_self(), offset, bytes);
/* Whatever is left can use real zero subclusters */
- ret = qcow2_subcluster_zeroize(bs, offset, bytes, flags);
- qemu_co_mutex_unlock(&s->lock);
-
- return ret;
+ return qcow2_subcluster_zeroize(bs, offset, bytes, flags);
}
static coroutine_fn int qcow2_co_pdiscard(BlockDriverState *bs,
--
2.29.2
- [PATCH v6 00/12] qcow2: fix parallel rewrite and discard (lockless), Vladimir Sementsov-Ogievskiy, 2021/04/22
- [PATCH v6 01/12] iotests: add qcow2-discard-during-rewrite, Vladimir Sementsov-Ogievskiy, 2021/04/22
- [PATCH v6 02/12] qcow2: fix cache discarding in update_refcount(), Vladimir Sementsov-Ogievskiy, 2021/04/22
- [PATCH v6 03/12] block/qcow2-cluster: assert no data_file on compressed write path, Vladimir Sementsov-Ogievskiy, 2021/04/22
- [PATCH v6 04/12] block/qcow2-refcount: rename and publish update_refcount_discard(), Vladimir Sementsov-Ogievskiy, 2021/04/22
- [PATCH v6 05/12] block/qcow2: introduce qcow2_parse_compressed_cluster_descriptor(), Vladimir Sementsov-Ogievskiy, 2021/04/22
- [PATCH v6 06/12] block/qcow2: refactor qcow2_co_preadv_task() to have one return, Vladimir Sementsov-Ogievskiy, 2021/04/22
- [PATCH v6 08/12] qcow2: introduce is_cluster_free() helper, Vladimir Sementsov-Ogievskiy, 2021/04/22
- [PATCH v6 07/12] block/qcow2: qcow2_co_pwrite_zeroes: use QEMU_LOCK_GUARD,
Vladimir Sementsov-Ogievskiy <=
- [PATCH v6 10/12] qcow2: introduce qcow2_host_cluster_postponed_discard(), Vladimir Sementsov-Ogievskiy, 2021/04/22
- [PATCH v6 11/12] qcow2: protect data writing by host range reference, Vladimir Sementsov-Ogievskiy, 2021/04/22
- [PATCH v6 09/12] qcow2: introduce host-range-refs, Vladimir Sementsov-Ogievskiy, 2021/04/22
- [PATCH v6 12/12] qcow2: protect data reading by host range reference, Vladimir Sementsov-Ogievskiy, 2021/04/22
- Re: [PATCH v6 00/12] qcow2: fix parallel rewrite and discard (lockless), Vladimir Sementsov-Ogievskiy, 2021/04/26