[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v4 7/8] file-posix: account discard operations
From: |
Anton Nefedov |
Subject: |
[Qemu-devel] [PATCH v4 7/8] file-posix: account discard operations |
Date: |
Tue, 21 Aug 2018 12:46:18 +0300 |
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 | 28 +++++++++++++++++++++++++---
1 file changed, 25 insertions(+), 3 deletions(-)
diff --git a/block/file-posix.c b/block/file-posix.c
index fe83cbf..c420f76 100644
--- a/block/file-posix.c
+++ b/block/file-posix.c
@@ -163,6 +163,11 @@ typedef struct BDRVRawState {
bool has_fallocate;
bool needs_alignment;
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;
@@ -2575,12 +2580,25 @@ 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_co_pdiscard(BlockDriverState *bs, int64_t offset, int bytes)
{
BDRVRawState *s = bs->opaque;
+ int ret;
- return paio_submit_co(bs, s->fd, offset, NULL, bytes, QEMU_AIO_DISCARD);
+ ret = paio_submit_co(bs, s->fd, offset, NULL, bytes, QEMU_AIO_DISCARD);
+ raw_account_discard(s, bytes, ret);
+ return ret;
}
static int coroutine_fn raw_co_pwrite_zeroes(
@@ -3077,10 +3095,14 @@ hdev_co_pdiscard(BlockDriverState *bs, int64_t offset,
int bytes)
ret = fd_open(bs);
if (ret < 0) {
+ raw_account_discard(s, bytes, ret);
return ret;
}
- return paio_submit_co(bs, s->fd, offset, NULL, bytes,
- QEMU_AIO_DISCARD | QEMU_AIO_BLKDEV);
+
+ ret = paio_submit_co(bs, s->fd, offset, NULL, bytes,
+ QEMU_AIO_DISCARD | QEMU_AIO_BLKDEV);
+ raw_account_discard(s, bytes, ret);
+ return ret;
}
static coroutine_fn int hdev_co_pwrite_zeroes(BlockDriverState *bs,
--
2.7.4
- [Qemu-devel] [PATCH v4 0/8] discard blockstats, Anton Nefedov, 2018/08/21
- [Qemu-devel] [PATCH v4 3/8] ide: account UNMAP (TRIM) operations, Anton Nefedov, 2018/08/21
- [Qemu-devel] [PATCH v4 1/8] qapi: group BlockDeviceStats fields, Anton Nefedov, 2018/08/21
- [Qemu-devel] [PATCH v4 2/8] qapi: add unmap to BlockDeviceStats, Anton Nefedov, 2018/08/21
- [Qemu-devel] [PATCH v4 4/8] scsi: store unmap offset and nb_sectors in request struct, Anton Nefedov, 2018/08/21
- [Qemu-devel] [PATCH v4 5/8] scsi: move unmap error checking to the complete callback, Anton Nefedov, 2018/08/21
- [Qemu-devel] [PATCH v4 6/8] scsi: account unmap operations, Anton Nefedov, 2018/08/21
- [Qemu-devel] [PATCH v4 7/8] file-posix: account discard operations,
Anton Nefedov <=
- [Qemu-devel] [PATCH v4 8/8] qapi: query-blockstat: add driver specific file-posix stats, Anton Nefedov, 2018/08/21