[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v5 5/6] block/blkdebug: remove new_state field and instead use a
From: |
Emanuele Giuseppe Esposito |
Subject: |
[PATCH v5 5/6] block/blkdebug: remove new_state field and instead use a local variable |
Date: |
Mon, 14 Jun 2021 10:29:30 +0200 |
There seems to be no benefit in using a field. Replace it with a local
variable, and move the state update before the yields.
The state update has do be done before the yields because now using
a local variable does not allow the new updated state to be visible
by the other yields.
Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
---
block/blkdebug.c | 13 ++++++-------
1 file changed, 6 insertions(+), 7 deletions(-)
diff --git a/block/blkdebug.c b/block/blkdebug.c
index dd82131d1e..b47c3fd97c 100644
--- a/block/blkdebug.c
+++ b/block/blkdebug.c
@@ -40,7 +40,6 @@
typedef struct BDRVBlkdebugState {
int state;
- int new_state;
uint64_t align;
uint64_t max_transfer;
uint64_t opt_write_zero;
@@ -792,7 +791,7 @@ static void suspend_request(BlockDriverState *bs,
BlkdebugRule *rule)
}
static void process_rule(BlockDriverState *bs, struct BlkdebugRule *rule,
- int *action_count)
+ int *action_count, int *new_state)
{
BDRVBlkdebugState *s = bs->opaque;
@@ -812,7 +811,7 @@ static void process_rule(BlockDriverState *bs, struct
BlkdebugRule *rule,
break;
case ACTION_SET_STATE:
- s->new_state = rule->options.set_state.new_state;
+ *new_state = rule->options.set_state.new_state;
break;
case ACTION_SUSPEND:
@@ -825,21 +824,21 @@ static void blkdebug_debug_event(BlockDriverState *bs,
BlkdebugEvent event)
{
BDRVBlkdebugState *s = bs->opaque;
struct BlkdebugRule *rule, *next;
+ int new_state;
int actions_count[ACTION__MAX] = { 0 };
assert((int)event >= 0 && event < BLKDBG__MAX);
- s->new_state = s->state;
+ new_state = s->state;
QLIST_FOREACH_SAFE(rule, &s->rules[event], next, next) {
- process_rule(bs, rule, actions_count);
+ process_rule(bs, rule, actions_count, &new_state);
}
+ s->state = new_state;
while (actions_count[ACTION_SUSPEND] > 0) {
qemu_coroutine_yield();
actions_count[ACTION_SUSPEND]--;
}
-
- s->state = s->new_state;
}
static int blkdebug_debug_breakpoint(BlockDriverState *bs, const char *event,
--
2.31.1
- [PATCH v5 0/6] blkdebug: fix racing condition when iterating on, Emanuele Giuseppe Esposito, 2021/06/14
- [PATCH v5 1/6] blkdebug: refactor removal of a suspended request, Emanuele Giuseppe Esposito, 2021/06/14
- [PATCH v5 2/6] blkdebug: move post-resume handling to resume_req_by_tag, Emanuele Giuseppe Esposito, 2021/06/14
- [PATCH v5 3/6] blkdebug: track all actions, Emanuele Giuseppe Esposito, 2021/06/14
- [PATCH v5 4/6] blkdebug: do not suspend in the middle of QLIST_FOREACH_SAFE, Emanuele Giuseppe Esposito, 2021/06/14
- [PATCH v5 5/6] block/blkdebug: remove new_state field and instead use a local variable,
Emanuele Giuseppe Esposito <=
- [PATCH v5 6/6] blkdebug: protect rules and suspended_reqs with a lock, Emanuele Giuseppe Esposito, 2021/06/14