[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PATCH v7 8/9] file-posix: account discard operations
From: |
Anton Nefedov |
Subject: |
[Qemu-block] [PATCH v7 8/9] file-posix: account discard operations |
Date: |
Tue, 14 May 2019 12:10:49 +0000 |
This will help to identify how many of the user-issued discard operations
(accounted on a device level) have actually suceeded down on the host file
(even though the numbers will not be exactly the same if non-raw format
driver is used (e.g. qcow2 sending metadata discards)).
Note that these numbers will not include discards triggered by
write-zeroes + MAY_UNMAP calls.
Signed-off-by: Anton Nefedov <address@hidden>
---
block/file-posix.c | 22 +++++++++++++++++++++-
1 file changed, 21 insertions(+), 1 deletion(-)
diff --git a/block/file-posix.c b/block/file-posix.c
index 1cf4ee49eb..76d54b3a85 100644
--- a/block/file-posix.c
+++ b/block/file-posix.c
@@ -159,6 +159,11 @@ typedef struct BDRVRawState {
bool needs_alignment;
bool drop_cache;
bool check_cache_dropped;
+ struct {
+ int64_t discard_nb_ok;
+ int64_t discard_nb_failed;
+ int64_t discard_bytes_ok;
+ } stats;
PRManager *pr_mgr;
} BDRVRawState;
@@ -2630,11 +2635,22 @@ static void coroutine_fn
raw_co_invalidate_cache(BlockDriverState *bs,
#endif /* !__linux__ */
}
+static void raw_account_discard(BDRVRawState *s, uint64_t nbytes, int ret)
+{
+ if (ret) {
+ s->stats.discard_nb_failed++;
+ } else {
+ s->stats.discard_nb_ok++;
+ s->stats.discard_bytes_ok += nbytes;
+ }
+}
+
static coroutine_fn int
raw_do_pdiscard(BlockDriverState *bs, int64_t offset, int bytes, bool blkdev)
{
BDRVRawState *s = bs->opaque;
RawPosixAIOData acb;
+ int ret;
acb = (RawPosixAIOData) {
.bs = bs,
@@ -2648,7 +2664,9 @@ raw_do_pdiscard(BlockDriverState *bs, int64_t offset, int
bytes, bool blkdev)
acb.aio_type |= QEMU_AIO_BLKDEV;
}
- return raw_thread_pool_submit(bs, handle_aiocb_discard, &acb);
+ ret = raw_thread_pool_submit(bs, handle_aiocb_discard, &acb);
+ raw_account_discard(s, bytes, ret);
+ return ret;
}
static coroutine_fn int
@@ -3263,10 +3281,12 @@ static int fd_open(BlockDriverState *bs)
static coroutine_fn int
hdev_co_pdiscard(BlockDriverState *bs, int64_t offset, int bytes)
{
+ BDRVRawState *s = bs->opaque;
int ret;
ret = fd_open(bs);
if (ret < 0) {
+ raw_account_discard(s, bytes, ret);
return ret;
}
return raw_do_pdiscard(bs, offset, bytes, true);
--
2.17.1
- [Qemu-block] [PATCH v7 0/9] discard blockstats, Anton Nefedov, 2019/05/14
- [Qemu-block] [PATCH v7 1/9] qapi: group BlockDeviceStats fields, Anton Nefedov, 2019/05/14
- [Qemu-block] [PATCH v7 5/9] scsi: store unmap offset and nb_sectors in request struct, Anton Nefedov, 2019/05/14
- [Qemu-block] [PATCH v7 2/9] qapi: add unmap to BlockDeviceStats, Anton Nefedov, 2019/05/14
- [Qemu-block] [PATCH v7 3/9] block: add empty account cookie type, Anton Nefedov, 2019/05/14
- [Qemu-block] [PATCH v7 4/9] ide: account UNMAP (TRIM) operations, Anton Nefedov, 2019/05/14
- [Qemu-block] [PATCH v7 6/9] scsi: move unmap error checking to the complete callback, Anton Nefedov, 2019/05/14
- [Qemu-block] [PATCH v7 7/9] scsi: account unmap operations, Anton Nefedov, 2019/05/14
- [Qemu-block] [PATCH v7 8/9] file-posix: account discard operations,
Anton Nefedov <=
- [Qemu-block] [PATCH v7 9/9] qapi: query-blockstat: add driver specific file-posix stats, Anton Nefedov, 2019/05/14