qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/3] Add Support for GET LBA STATUS 16 command in scsi emulation
@ 2020-06-17 10:30 Lin Ma
  2020-06-17 10:30 ` [PATCH v2 1/3] block: Add bdrv_co_get_lba_status Lin Ma
                   ` (3 more replies)
  0 siblings, 4 replies; 13+ messages in thread
From: Lin Ma @ 2020-06-17 10:30 UTC (permalink / raw)
  To: qemu-devel; +Cc: fam, kwolf, mreitz, stefanha, Lin Ma, pbonzini

v2->v1:
Follow Claudio's suggestions and the docker test result, Fix the dereferencing
'void *' pointer issues and the coding style issues.


In this current design, The GET LBA STATUS parameter data only contains
an eight-byte header + one LBA status descriptor.

How to test:
host:~ # qemu-system-x86_64 \
...
-drive file=/vm0/disk0.raw,format=raw,if=none,id=drive0,discard=unmap \
-device scsi-hd,id=scsi0,drive=drive0 \
...


guest:~ # dd if=/dev/zero of=/dev/sda bs=512 seek=1024 count=256

guest:~ # sg_unmap -l 1024 -n 32 /dev/sda

guest:~ # sg_get_lba_status /dev/sda -l 1024
No indication of the completion condition
RTP=0
descriptor LBA: 0x0000000000000400  blocks: 32  deallocated

Lin Ma (3):
  block: Add bdrv_co_get_lba_status
  block: Add GET LBA STATUS support
  scsi-disk: Add support for the GET LBA STATUS 16 command

 block/block-backend.c          | 38 ++++++++++++++
 block/io.c                     | 43 ++++++++++++++++
 hw/scsi/scsi-disk.c            | 90 ++++++++++++++++++++++++++++++++++
 include/block/accounting.h     |  1 +
 include/block/block_int.h      |  5 ++
 include/scsi/constants.h       |  1 +
 include/sysemu/block-backend.h |  2 +
 7 files changed, 180 insertions(+)

-- 
2.26.0



^ permalink raw reply	[flat|nested] 13+ messages in thread
* Re: [PATCH v2 1/3] block: Add bdrv_co_get_lba_status
@ 2020-06-25 13:07 Lin Ma
  2020-06-29 10:20 ` Stefan Hajnoczi
  0 siblings, 1 reply; 13+ messages in thread
From: Lin Ma @ 2020-06-25 13:07 UTC (permalink / raw)
  To: Stefan Hajnoczi
  Cc: fam@euphon.net, kwolf@redhat.com, qemu-devel@nongnu.org,
	mreitz@redhat.com, pbonzini@redhat.com

[-- Attachment #1: Type: text/plain, Size: 4470 bytes --]

On 2020-06-25 20:59, Lin Ma wrote:
> From: Stefan Hajnoczi
> Sent: Monday, June 22, 2020 6:25 PM
> ...
>> diff --git a/block/io.c b/block/io.c
>> index df8f2a98d4..2064016b19 100644
>> --- a/block/io.c
>> +++ b/block/io.c
>> @@ -2208,6 +2208,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)
>
> Missing doc comments.

I'll add the comments.

>> +{
>> +    BlockDriverState *bs = child->bs;
>
> Why does this function take a BdrvChild argument instead of
> BlockDriverState? Most I/O functions take BlockDriverState.

OK, I'll use BlockDriverState instead.

>> +    int ret = 0;
>> +    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;
>
> This is a boolean. Please use bool instead of uint32_t.

As you mentioned in comment of patch 3/3, is_deallocated boolean is not enough
to represent 3 states. I'll keep the uint32_t *, but rename 'is_deallocated' to
'provisioning_status'

> Please initialize is_deallocated to false at the beginning of the
> function to avoid accidental uninitialized variable accesses in the
> caller.

It has already been initialized to 0 by 'data = g_new0(GetLbaStatusCBData, 1);'
in function scsi_disk_emulate_get_lba_status of patch 3/3, Do I still need to
initialize it at the beginning of this function?

>> +            } else {
>> +                wanted_bit1 = 0;
>> +            }
>> +            first = false;
>> +        }
>> +        if ((ret & BDRV_BLOCK_ZERO) >> 1 == wanted_bit1) {
>> +            (*num_blocks)++;
>
> If there is a long span of allocated/deallocated blocks then this
> function only increments num_blocks once without counting the number of
> blocks. I expected something like num_blocks += pnum / block_size.  What
> is the relationship between bytes, count, and blocks in this function?

OK, I'll change it to '*num_blocks += pnum / bytes;'
The 'bytes' is the logical block size(default value is 512).
In fact, 'count' has the same meaning as 'pnum', It is the number of bytes
(including and immediately following the specified offset) that are known to
be in the same allocated/unallocated state. I'll rename the 'count' to 'pnum'.

Once this function returns, The number of contiguous logical blocks sharing
the same provisioning status as the specified logical block will be saved into
'num_blocks'.

>> +        } else {
>> +            break;
>> +        }
>> +    }
>> +out:
>> +    return ret;
>> +}
>> +
>>  /*
>>   * Flush ALL BDSes regardless of if they are reachable via a BlkBackend or not.
>>   */
>> diff --git a/include/block/block_int.h b/include/block/block_int.h
>> index 791de6a59c..43f90591b9 100644
>> --- a/include/block/block_int.h
>> +++ b/include/block/block_int.h
>> @@ -1296,6 +1296,11 @@ int coroutine_fn bdrv_co_block_status_from_backing(BlockDriverState *bs,
>>                                                     int64_t *pnum,
>>                                                     int64_t *map,
>>                                                     BlockDriverState **file);
>> +int coroutine_fn bdrv_co_get_lba_status(BdrvChild *child,
>> +                                        int64_t offset,
>> +                                        int64_t bytes,
>> +                                        uint32_t *num_blocks,
>> +                                        uint32_t *is_deallocated);
>
> Should this function be in include/block/block.h (the public API) so
> that any part of QEMU can call it? It's not an internal API.

I'll move it to include/block/block.h.

[-- Attachment #2: Type: text/html, Size: 9059 bytes --]

^ permalink raw reply	[flat|nested] 13+ messages in thread
* [PATCH v2 0/3] Add Support for GET LBA STATUS 16 command in scsi emulation
@ 2020-06-17 10:20 Lin Ma
  2020-06-17 10:20 ` [PATCH v2 1/3] block: Add bdrv_co_get_lba_status Lin Ma
  0 siblings, 1 reply; 13+ messages in thread
From: Lin Ma @ 2020-06-17 10:20 UTC (permalink / raw)
  To: qemu-block; +Cc: fam, kwolf, qemu-devel, mreitz, stefanha, Lin Ma, pbonzini

v2->v1:
Follow Claudio's suggestions and the docker test result, Fix the dereferencing
'void *' pointer issues and the coding style issues.


In this current design, The GET LBA STATUS parameter data only contains
an eight-byte header + one LBA status descriptor.

How to test:
host:~ # qemu-system-x86_64 \
...
-drive file=/vm0/disk0.raw,format=raw,if=none,id=drive0,discard=unmap \
-device scsi-hd,id=scsi0,drive=drive0 \
...


guest:~ # dd if=/dev/zero of=/dev/sda bs=512 seek=1024 count=256

guest:~ # sg_unmap -l 1024 -n 32 /dev/sda

guest:~ # sg_get_lba_status /dev/sda -l 1024
No indication of the completion condition
RTP=0
descriptor LBA: 0x0000000000000400  blocks: 32  deallocated

Lin Ma (3):
  block: Add bdrv_co_get_lba_status
  block: Add GET LBA STATUS support
  scsi-disk: Add support for the GET LBA STATUS 16 command

 block/block-backend.c          | 38 ++++++++++++++
 block/io.c                     | 43 ++++++++++++++++
 hw/scsi/scsi-disk.c            | 90 ++++++++++++++++++++++++++++++++++
 include/block/accounting.h     |  1 +
 include/block/block_int.h      |  5 ++
 include/scsi/constants.h       |  1 +
 include/sysemu/block-backend.h |  2 +
 7 files changed, 180 insertions(+)

-- 
2.26.0



^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2020-07-08 22:18 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-06-17 10:30 [PATCH v2 0/3] Add Support for GET LBA STATUS 16 command in scsi emulation Lin Ma
2020-06-17 10:30 ` [PATCH v2 1/3] block: Add bdrv_co_get_lba_status Lin Ma
2020-06-22 10:25   ` Stefan Hajnoczi
2020-06-17 10:30 ` [PATCH v2 2/3] block: Add GET LBA STATUS support Lin Ma
2020-06-17 10:30 ` [PATCH v2 3/3] scsi-disk: Add support for the GET LBA STATUS 16 command Lin Ma
2020-06-22 12:14   ` Stefan Hajnoczi
2020-06-29  9:18     ` 回复: " Lin Ma
2020-07-08 12:29       ` Stefan Hajnoczi
2020-07-08 12:38         ` Paolo Bonzini
2020-06-17 11:14 ` [PATCH v2 0/3] Add Support for GET LBA STATUS 16 command in scsi emulation no-reply
  -- strict thread matches above, loose matches on Subject: below --
2020-06-25 13:07 [PATCH v2 1/3] block: Add bdrv_co_get_lba_status Lin Ma
2020-06-29 10:20 ` Stefan Hajnoczi
2020-06-17 10:20 [PATCH v2 0/3] Add Support for GET LBA STATUS 16 command in scsi emulation Lin Ma
2020-06-17 10:20 ` [PATCH v2 1/3] block: Add bdrv_co_get_lba_status Lin Ma

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).