[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 24/36] file-posix: account discard operations
From: |
Max Reitz |
Subject: |
[PULL 24/36] file-posix: account discard operations |
Date: |
Thu, 10 Oct 2019 13:42:48 +0200 |
From: Anton Nefedov <address@hidden>
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>
Reviewed-by: Vladimir Sementsov-Ogievskiy <address@hidden>
Message-id: address@hidden
Signed-off-by: Max Reitz <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 f12c06de2d..f3934c4e10 100644
--- a/block/file-posix.c
+++ b/block/file-posix.c
@@ -161,6 +161,11 @@ typedef struct BDRVRawState {
bool needs_alignment;
bool drop_cache;
bool check_cache_dropped;
+ struct {
+ uint64_t discard_nb_ok;
+ uint64_t discard_nb_failed;
+ uint64_t discard_bytes_ok;
+ } stats;
PRManager *pr_mgr;
} BDRVRawState;
@@ -2660,11 +2665,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,
@@ -2678,7 +2694,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
@@ -3301,10 +3319,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.21.0
- [PULL 15/36] iotests: 257: drop unused Drive.device field, (continued)
- [PULL 15/36] iotests: 257: drop unused Drive.device field, Max Reitz, 2019/10/10
- [PULL 17/36] qapi: group BlockDeviceStats fields, Max Reitz, 2019/10/10
- [PULL 14/36] iotests: prepare 124 and 257 bitmap querying for backup-top filter, Max Reitz, 2019/10/10
- [PULL 16/36] iotests: 257: drop device_add, Max Reitz, 2019/10/10
- [PULL 18/36] qapi: add unmap to BlockDeviceStats, Max Reitz, 2019/10/10
- [PULL 19/36] block: add empty account cookie type, Max Reitz, 2019/10/10
- [PULL 20/36] ide: account UNMAP (TRIM) operations, Max Reitz, 2019/10/10
- [PULL 21/36] scsi: store unmap offset and nb_sectors in request struct, Max Reitz, 2019/10/10
- [PULL 22/36] scsi: move unmap error checking to the complete callback, Max Reitz, 2019/10/10
- [PULL 23/36] scsi: account unmap operations, Max Reitz, 2019/10/10
- [PULL 24/36] file-posix: account discard operations,
Max Reitz <=
- [PULL 25/36] qapi: query-blockstat: add driver specific file-posix stats, Max Reitz, 2019/10/10
- [PULL 27/36] iotests: Disable 125 on broken XFS versions, Max Reitz, 2019/10/10
- [PULL 26/36] iotests: Fix 125 for growth_mode = metadata, Max Reitz, 2019/10/10
- [PULL 28/36] iotests: Use stat -c %b in 125, Max Reitz, 2019/10/10
- [PULL 29/36] block/backup: move in-flight requests handling from backup to block-copy, Max Reitz, 2019/10/10
- [PULL 30/36] block/backup: move write_flags calculation inside backup_job_create, Max Reitz, 2019/10/10
- [PULL 31/36] block/block-copy: split block_copy_set_callbacks function, Max Reitz, 2019/10/10
- [PULL 34/36] nbd: add empty .bdrv_reopen_prepare, Max Reitz, 2019/10/10
- [PULL 32/36] block: introduce backup-top filter driver, Max Reitz, 2019/10/10
- [PULL 36/36] iotests/162: Fix for newer Linux 5.3+, Max Reitz, 2019/10/10