* [Qemu-devel] [PATCH v4 0/3] sheepdog: implement .bdrv_co_is_allocated
@ 2013-04-23 6:03 Liu Yuan
2013-04-23 6:03 ` [Qemu-devel] [PATCH v4 1/3] sheepdog: add discard/trim support for sheepdog Liu Yuan
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Liu Yuan @ 2013-04-23 6:03 UTC (permalink / raw)
To: qemu-devel; +Cc: sheepdog
From: Liu Yuan <tailai.ly@taobao.com>
v4:
- correct idx iteration range
v3:
- include discard patch for easy review and merge
- update the comment typo
- get variable 'idx' definition more clear
v2:
- correct 'end' calculation
- get the longest unallocated area
- replace SECTOR_SIZE with BDRV_SECTOR_SIZE
PATCH 1/3 is the previous distard patch which implement .bdrv_co_discard
PATCH 2/3 is ia prepare patch
PATCH 3/3 implement .bdrv_co_is_allocated
Thanks,
Yuan
--
1.7.9.5
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Qemu-devel] [PATCH v4 1/3] sheepdog: add discard/trim support for sheepdog
2013-04-23 6:03 [Qemu-devel] [PATCH v4 0/3] sheepdog: implement .bdrv_co_is_allocated Liu Yuan
@ 2013-04-23 6:03 ` Liu Yuan
2013-04-23 7:13 ` Stefan Hajnoczi
2013-04-23 6:03 ` [Qemu-devel] [PATCH v4 2/3] sheepdog: use BDRV_SECTOR_SIZE Liu Yuan
2013-04-23 6:03 ` [Qemu-devel] [PATCH v4 3/3] sheepdog: implement .bdrv_co_is_allocated() Liu Yuan
2 siblings, 1 reply; 5+ messages in thread
From: Liu Yuan @ 2013-04-23 6:03 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, Paolo Bonzini, sheepdog, Stefan Hajnoczi,
MORITA Kazutaka
From: Liu Yuan <tailai.ly@taobao.com>
The 'TRIM' command from VM that is to release underlying data storage for
better thin-provision is already supported by the Sheepdog.
This patch adds the TRIM support at QEMU part.
For older Sheepdog that doesn't support it, we return 0(success) to upper layer.
Cc: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
Cc: Kevin Wolf <kwolf@redhat.com>
Cc: Stefan Hajnoczi <stefanha@redhat.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Liu Yuan <tailai.ly@taobao.com>
---
block/sheepdog.c | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 63 insertions(+), 1 deletion(-)
diff --git a/block/sheepdog.c b/block/sheepdog.c
index 1c5b532..c3b7770 100644
--- a/block/sheepdog.c
+++ b/block/sheepdog.c
@@ -27,6 +27,8 @@
#define SD_OP_CREATE_AND_WRITE_OBJ 0x01
#define SD_OP_READ_OBJ 0x02
#define SD_OP_WRITE_OBJ 0x03
+/* 0x04 is used internally by Sheepdog */
+#define SD_OP_DISCARD_OBJ 0x05
#define SD_OP_NEW_VDI 0x11
#define SD_OP_LOCK_VDI 0x12
@@ -269,6 +271,7 @@ enum AIOCBState {
AIOCB_WRITE_UDATA,
AIOCB_READ_UDATA,
AIOCB_FLUSH_CACHE,
+ AIOCB_DISCARD_OBJ,
};
struct SheepdogAIOCB {
@@ -298,6 +301,7 @@ typedef struct BDRVSheepdogState {
char name[SD_MAX_VDI_LEN];
bool is_snapshot;
uint32_t cache_flags;
+ bool discard_supported;
char *host_spec;
bool is_unix;
@@ -656,7 +660,7 @@ static void coroutine_fn aio_read_response(void *opaque)
int ret;
AIOReq *aio_req = NULL;
SheepdogAIOCB *acb;
- unsigned long idx;
+ uint64_t idx;
if (QLIST_EMPTY(&s->inflight_aio_head)) {
goto out;
@@ -727,6 +731,21 @@ static void coroutine_fn aio_read_response(void *opaque)
rsp.result = SD_RES_SUCCESS;
}
break;
+ case AIOCB_DISCARD_OBJ:
+ switch (rsp.result) {
+ case SD_RES_INVALID_PARMS:
+ error_report("sheep(%s) doesn't support discard command",
+ s->host_spec);
+ rsp.result = SD_RES_SUCCESS;
+ s->discard_supported = false;
+ break;
+ case SD_RES_SUCCESS:
+ idx = data_oid_to_idx(aio_req->oid);
+ s->inode.data_vdi_id[idx] = 0;
+ break;
+ default:
+ break;
+ }
}
if (rsp.result != SD_RES_SUCCESS) {
@@ -1016,6 +1035,9 @@ static int coroutine_fn add_aio_request(BDRVSheepdogState *s, AIOReq *aio_req,
wlen = datalen;
hdr.flags = SD_FLAG_CMD_WRITE | flags;
break;
+ case AIOCB_DISCARD_OBJ:
+ hdr.opcode = SD_OP_DISCARD_OBJ;
+ break;
}
if (s->cache_flags) {
@@ -1170,6 +1192,7 @@ static int sd_open(BlockDriverState *bs, const char *filename,
if (flags & BDRV_O_NOCACHE) {
s->cache_flags = SD_FLAG_CMD_DIRECT;
}
+ s->discard_supported = true;
if (snapid || tag[0] != '\0') {
dprintf("%" PRIx32 " snapshot inode was open.\n", vid);
@@ -1633,6 +1656,15 @@ static int coroutine_fn sd_co_rw_vector(void *p)
flags = SD_FLAG_CMD_COW;
}
break;
+ case AIOCB_DISCARD_OBJ:
+ /*
+ * We discard the object only when the whole object is
+ * 1) allocated 2) trimmed. Otherwise, simply skip it.
+ */
+ if (len != SD_DATA_OBJ_SIZE || inode->data_vdi_id[idx] == 0) {
+ goto done;
+ }
+ break;
default:
break;
}
@@ -2078,6 +2110,33 @@ static int sd_load_vmstate(BlockDriverState *bs, uint8_t *data,
}
+static coroutine_fn int sd_co_discard(BlockDriverState *bs, int64_t sector_num,
+ int nb_sectors)
+{
+ SheepdogAIOCB *acb;
+ QEMUIOVector dummy;
+ BDRVSheepdogState *s = bs->opaque;
+ int ret;
+
+ if (!s->discard_supported) {
+ return 0;
+ }
+
+ acb = sd_aio_setup(bs, &dummy, sector_num, nb_sectors);
+ acb->aiocb_type = AIOCB_DISCARD_OBJ;
+ acb->aio_done_func = sd_finish_aiocb;
+
+ ret = sd_co_rw_vector(acb);
+ if (ret <= 0) {
+ qemu_aio_release(acb);
+ return ret;
+ }
+
+ qemu_coroutine_yield();
+
+ return acb->ret;
+}
+
static QEMUOptionParameter sd_create_options[] = {
{
.name = BLOCK_OPT_SIZE,
@@ -2110,6 +2169,7 @@ static BlockDriver bdrv_sheepdog = {
.bdrv_co_readv = sd_co_readv,
.bdrv_co_writev = sd_co_writev,
.bdrv_co_flush_to_disk = sd_co_flush_to_disk,
+ .bdrv_co_discard = sd_co_discard,
.bdrv_snapshot_create = sd_snapshot_create,
.bdrv_snapshot_goto = sd_snapshot_goto,
@@ -2135,6 +2195,7 @@ static BlockDriver bdrv_sheepdog_tcp = {
.bdrv_co_readv = sd_co_readv,
.bdrv_co_writev = sd_co_writev,
.bdrv_co_flush_to_disk = sd_co_flush_to_disk,
+ .bdrv_co_discard = sd_co_discard,
.bdrv_snapshot_create = sd_snapshot_create,
.bdrv_snapshot_goto = sd_snapshot_goto,
@@ -2160,6 +2221,7 @@ static BlockDriver bdrv_sheepdog_unix = {
.bdrv_co_readv = sd_co_readv,
.bdrv_co_writev = sd_co_writev,
.bdrv_co_flush_to_disk = sd_co_flush_to_disk,
+ .bdrv_co_discard = sd_co_discard,
.bdrv_snapshot_create = sd_snapshot_create,
.bdrv_snapshot_goto = sd_snapshot_goto,
--
1.7.9.5
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [Qemu-devel] [PATCH v4 2/3] sheepdog: use BDRV_SECTOR_SIZE
2013-04-23 6:03 [Qemu-devel] [PATCH v4 0/3] sheepdog: implement .bdrv_co_is_allocated Liu Yuan
2013-04-23 6:03 ` [Qemu-devel] [PATCH v4 1/3] sheepdog: add discard/trim support for sheepdog Liu Yuan
@ 2013-04-23 6:03 ` Liu Yuan
2013-04-23 6:03 ` [Qemu-devel] [PATCH v4 3/3] sheepdog: implement .bdrv_co_is_allocated() Liu Yuan
2 siblings, 0 replies; 5+ messages in thread
From: Liu Yuan @ 2013-04-23 6:03 UTC (permalink / raw)
To: qemu-devel; +Cc: Kevin Wolf, sheepdog, Stefan Hajnoczi, MORITA Kazutaka
From: Liu Yuan <tailai.ly@taobao.com>
Cc: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
Cc: Kevin Wolf <kwolf@redhat.com>
Cc: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Liu Yuan <tailai.ly@taobao.com>
---
block/sheepdog.c | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)
diff --git a/block/sheepdog.c b/block/sheepdog.c
index c3b7770..916f360 100644
--- a/block/sheepdog.c
+++ b/block/sheepdog.c
@@ -89,7 +89,6 @@
#define SD_NR_VDIS (1U << 24)
#define SD_DATA_OBJ_SIZE (UINT64_C(1) << 22)
#define SD_MAX_VDI_SIZE (SD_DATA_OBJ_SIZE * MAX_DATA_OBJS)
-#define SECTOR_SIZE 512
#define SD_INODE_SIZE (sizeof(SheepdogInode))
#define CURRENT_VDI_ID 0
@@ -1219,7 +1218,7 @@ static int sd_open(BlockDriverState *bs, const char *filename,
s->min_dirty_data_idx = UINT32_MAX;
s->max_dirty_data_idx = 0;
- bs->total_sectors = s->inode.vdi_size / SECTOR_SIZE;
+ bs->total_sectors = s->inode.vdi_size / BDRV_SECTOR_SIZE;
pstrcpy(s->name, sizeof(s->name), vdi);
qemu_co_mutex_init(&s->lock);
g_free(buf);
@@ -1604,10 +1603,10 @@ static int coroutine_fn sd_co_rw_vector(void *p)
{
SheepdogAIOCB *acb = p;
int ret = 0;
- unsigned long len, done = 0, total = acb->nb_sectors * SECTOR_SIZE;
- unsigned long idx = acb->sector_num * SECTOR_SIZE / SD_DATA_OBJ_SIZE;
+ unsigned long len, done = 0, total = acb->nb_sectors * BDRV_SECTOR_SIZE;
+ unsigned long idx = acb->sector_num * BDRV_SECTOR_SIZE / SD_DATA_OBJ_SIZE;
uint64_t oid;
- uint64_t offset = (acb->sector_num * SECTOR_SIZE) % SD_DATA_OBJ_SIZE;
+ uint64_t offset = (acb->sector_num * BDRV_SECTOR_SIZE) % SD_DATA_OBJ_SIZE;
BDRVSheepdogState *s = acb->common.bs->opaque;
SheepdogInode *inode = &s->inode;
AIOReq *aio_req;
@@ -1726,7 +1725,7 @@ static coroutine_fn int sd_co_writev(BlockDriverState *bs, int64_t sector_num,
int ret;
if (bs->growable && sector_num + nb_sectors > bs->total_sectors) {
- ret = sd_truncate(bs, (sector_num + nb_sectors) * SECTOR_SIZE);
+ ret = sd_truncate(bs, (sector_num + nb_sectors) * BDRV_SECTOR_SIZE);
if (ret < 0) {
return ret;
}
--
1.7.9.5
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [Qemu-devel] [PATCH v4 3/3] sheepdog: implement .bdrv_co_is_allocated()
2013-04-23 6:03 [Qemu-devel] [PATCH v4 0/3] sheepdog: implement .bdrv_co_is_allocated Liu Yuan
2013-04-23 6:03 ` [Qemu-devel] [PATCH v4 1/3] sheepdog: add discard/trim support for sheepdog Liu Yuan
2013-04-23 6:03 ` [Qemu-devel] [PATCH v4 2/3] sheepdog: use BDRV_SECTOR_SIZE Liu Yuan
@ 2013-04-23 6:03 ` Liu Yuan
2 siblings, 0 replies; 5+ messages in thread
From: Liu Yuan @ 2013-04-23 6:03 UTC (permalink / raw)
To: qemu-devel; +Cc: Kevin Wolf, sheepdog, Stefan Hajnoczi, MORITA Kazutaka
From: Liu Yuan <tailai.ly@taobao.com>
Cc: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
Cc: Kevin Wolf <kwolf@redhat.com>
Cc: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Liu Yuan <tailai.ly@taobao.com>
---
block/sheepdog.c | 37 +++++++++++++++++++++++++++++++++++++
1 file changed, 37 insertions(+)
diff --git a/block/sheepdog.c b/block/sheepdog.c
index 916f360..2fe0783 100644
--- a/block/sheepdog.c
+++ b/block/sheepdog.c
@@ -2136,6 +2136,40 @@ static coroutine_fn int sd_co_discard(BlockDriverState *bs, int64_t sector_num,
return acb->ret;
}
+static coroutine_fn int
+sd_co_is_allocated(BlockDriverState *bs, int64_t sector_num, int nb_sectors,
+ int *pnum)
+{
+ BDRVSheepdogState *s = bs->opaque;
+ SheepdogInode *inode = &s->inode;
+ unsigned long start = sector_num * BDRV_SECTOR_SIZE / SD_DATA_OBJ_SIZE,
+ end = DIV_ROUND_UP((sector_num + nb_sectors) *
+ BDRV_SECTOR_SIZE, SD_DATA_OBJ_SIZE);
+ unsigned long idx;
+ int ret = 1;
+
+ for (idx = start; idx < end; idx++) {
+ if (inode->data_vdi_id[idx] == 0) {
+ break;
+ }
+ }
+ if (idx == start) {
+ /* Get the longest length of unallocated sectors */
+ ret = 0;
+ for (idx = start + 1; idx < end; idx++) {
+ if (inode->data_vdi_id[idx] != 0) {
+ break;
+ }
+ }
+ }
+
+ *pnum = (idx - start) * SD_DATA_OBJ_SIZE / BDRV_SECTOR_SIZE;
+ if (*pnum > nb_sectors) {
+ *pnum = nb_sectors;
+ }
+ return ret;
+}
+
static QEMUOptionParameter sd_create_options[] = {
{
.name = BLOCK_OPT_SIZE,
@@ -2169,6 +2203,7 @@ static BlockDriver bdrv_sheepdog = {
.bdrv_co_writev = sd_co_writev,
.bdrv_co_flush_to_disk = sd_co_flush_to_disk,
.bdrv_co_discard = sd_co_discard,
+ .bdrv_co_is_allocated = sd_co_is_allocated,
.bdrv_snapshot_create = sd_snapshot_create,
.bdrv_snapshot_goto = sd_snapshot_goto,
@@ -2195,6 +2230,7 @@ static BlockDriver bdrv_sheepdog_tcp = {
.bdrv_co_writev = sd_co_writev,
.bdrv_co_flush_to_disk = sd_co_flush_to_disk,
.bdrv_co_discard = sd_co_discard,
+ .bdrv_co_is_allocated = sd_co_is_allocated,
.bdrv_snapshot_create = sd_snapshot_create,
.bdrv_snapshot_goto = sd_snapshot_goto,
@@ -2221,6 +2257,7 @@ static BlockDriver bdrv_sheepdog_unix = {
.bdrv_co_writev = sd_co_writev,
.bdrv_co_flush_to_disk = sd_co_flush_to_disk,
.bdrv_co_discard = sd_co_discard,
+ .bdrv_co_is_allocated = sd_co_is_allocated,
.bdrv_snapshot_create = sd_snapshot_create,
.bdrv_snapshot_goto = sd_snapshot_goto,
--
1.7.9.5
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH v4 1/3] sheepdog: add discard/trim support for sheepdog
2013-04-23 6:03 ` [Qemu-devel] [PATCH v4 1/3] sheepdog: add discard/trim support for sheepdog Liu Yuan
@ 2013-04-23 7:13 ` Stefan Hajnoczi
0 siblings, 0 replies; 5+ messages in thread
From: Stefan Hajnoczi @ 2013-04-23 7:13 UTC (permalink / raw)
To: Liu Yuan; +Cc: Kevin Wolf, Paolo Bonzini, sheepdog, qemu-devel, MORITA Kazutaka
On Tue, Apr 23, 2013 at 02:03:33PM +0800, Liu Yuan wrote:
> From: Liu Yuan <tailai.ly@taobao.com>
>
> The 'TRIM' command from VM that is to release underlying data storage for
> better thin-provision is already supported by the Sheepdog.
>
> This patch adds the TRIM support at QEMU part.
>
> For older Sheepdog that doesn't support it, we return 0(success) to upper layer.
>
> Cc: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
> Cc: Kevin Wolf <kwolf@redhat.com>
> Cc: Stefan Hajnoczi <stefanha@redhat.com>
> Cc: Paolo Bonzini <pbonzini@redhat.com>
> Signed-off-by: Liu Yuan <tailai.ly@taobao.com>
> ---
> block/sheepdog.c | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
> 1 file changed, 63 insertions(+), 1 deletion(-)
Thanks, applied to my block tree:
https://github.com/stefanha/qemu/commits/block
Stefan
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2013-04-23 7:14 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-04-23 6:03 [Qemu-devel] [PATCH v4 0/3] sheepdog: implement .bdrv_co_is_allocated Liu Yuan
2013-04-23 6:03 ` [Qemu-devel] [PATCH v4 1/3] sheepdog: add discard/trim support for sheepdog Liu Yuan
2013-04-23 7:13 ` Stefan Hajnoczi
2013-04-23 6:03 ` [Qemu-devel] [PATCH v4 2/3] sheepdog: use BDRV_SECTOR_SIZE Liu Yuan
2013-04-23 6:03 ` [Qemu-devel] [PATCH v4 3/3] sheepdog: implement .bdrv_co_is_allocated() Liu Yuan
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).