[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 1/4] block: Add bdrv_co_get_lba_status
From: |
Lin Ma |
Subject: |
[PATCH 1/4] block: Add bdrv_co_get_lba_status |
Date: |
Tue, 2 Jun 2020 15:41:58 +0800 |
The get lba status wrapper based on the bdrv_block_status. The following
patches will add GET LBA STATUS 16 support for scsi emulation layer.
Signed-off-by: Lin Ma <lma@suse.com>
---
block/io.c | 43 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 43 insertions(+)
diff --git a/block/io.c b/block/io.c
index 121ce17a49..dacc3c2471 100644
--- a/block/io.c
+++ b/block/io.c
@@ -2186,6 +2186,49 @@ int coroutine_fn bdrv_co_pwrite_zeroes(BdrvChild *child,
int64_t offset,
BDRV_REQ_ZERO_WRITE | flags);
}
+int coroutine_fn
+bdrv_co_get_lba_status(BdrvChild *child, int64_t offset, int64_t bytes,
+ uint32_t *num_blocks, uint32_t *is_deallocated)
+{
+ BlockDriverState *bs = child->bs;
+ int ret;
+ int64_t target_size, count = 0;
+ bool first = true;
+ uint8_t wanted_bit1 = 0;
+
+ target_size = bdrv_getlength(bs);
+ if (target_size < 0) {
+ return -EIO;
+ }
+
+ if (offset < 0 || bytes < 0) {
+ return -EIO;
+ }
+
+ for ( ; offset <= target_size - bytes; offset += count) {
+ ret = bdrv_block_status(bs, offset, bytes, &count, NULL, NULL);
+ if (ret < 0) {
+ goto out;
+ }
+ if (first) {
+ if (ret & BDRV_BLOCK_ZERO) {
+ wanted_bit1 = BDRV_BLOCK_ZERO >> 1;;
+ *is_deallocated = 1;
+ } else {
+ wanted_bit1 = 0;
+ }
+ first = false;
+ }
+ if ((ret & BDRV_BLOCK_ZERO) >> 1 == wanted_bit1) {
+ (*num_blocks)++;
+ } else {
+ break;
+ }
+ }
+out:
+ return ret;
+}
+
/*
* Flush ALL BDSes regardless of if they are reachable via a BlkBackend or not.
*/
--
2.24.0
- [PATCH 0/4] Add Support for GET LBA STATUS 16 command in scsi emulation, Lin Ma, 2020/06/02
- [PATCH 1/4] block: Add bdrv_co_get_lba_status,
Lin Ma <=
- [PATCH 2/4] block: Add GET LBA STATUS support, Lin Ma, 2020/06/02
- [PATCH 3/4] block: Add block accounting code for GET LBA STATUS, Lin Ma, 2020/06/02
- [PATCH 4/4] scsi-disk: Add support for the GET LBA STATUS 16 command, Lin Ma, 2020/06/02
- Re: [PATCH 0/4] Add Support for GET LBA STATUS 16 command in scsi emulation, no-reply, 2020/06/02
- Re: [PATCH 0/4] Add Support for GET LBA STATUS 16 command in scsi emulation, no-reply, 2020/06/02
- Re: [PATCH 0/4] Add Support for GET LBA STATUS 16 command in scsi emulation, no-reply, 2020/06/02
- Re: [PATCH 0/4] Add Support for GET LBA STATUS 16 command in scsi emulation, no-reply, 2020/06/02