Skip to content

Commit

Permalink
qmp event: Refactor QUORUM_REPORT_BAD
Browse files Browse the repository at this point in the history
Introduce QuorumOpType, and make QUORUM_REPORT_BAD compatible
with it.

Cc: Dr. David Alan Gilbert <[email protected]>
Cc: Wen Congyang <[email protected]>
Signed-off-by: Wen Congyang <[email protected]>
Signed-off-by: Changlong Xie <[email protected]>
Reviewed-by: Alberto Garcia <[email protected]>
Signed-off-by: Kevin Wolf <[email protected]>
  • Loading branch information
Changlong Xie authored and kevmw committed Mar 14, 2016
1 parent 58346b8 commit 0ae053b
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 7 deletions.
17 changes: 12 additions & 5 deletions block/quorum.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,14 +215,16 @@ static QuorumAIOCB *quorum_aio_get(BDRVQuorumState *s,
return acb;
}

static void quorum_report_bad(QuorumAIOCB *acb, char *node_name, int ret)
static void quorum_report_bad(QuorumOpType type, uint64_t sector_num,
int nb_sectors, char *node_name, int ret)
{
const char *msg = NULL;
if (ret < 0) {
msg = strerror(-ret);
}
qapi_event_send_quorum_report_bad(!!msg, msg, node_name,
acb->sector_num, acb->nb_sectors, &error_abort);

qapi_event_send_quorum_report_bad(type, !!msg, msg, node_name,
sector_num, nb_sectors, &error_abort);
}

static void quorum_report_failure(QuorumAIOCB *acb)
Expand Down Expand Up @@ -282,6 +284,7 @@ static void quorum_aio_cb(void *opaque, int ret)
QuorumChildRequest *sacb = opaque;
QuorumAIOCB *acb = sacb->parent;
BDRVQuorumState *s = acb->common.bs->opaque;
QuorumOpType type;
bool rewrite = false;

if (acb->is_read && s->read_pattern == QUORUM_READ_PATTERN_FIFO) {
Expand All @@ -300,12 +303,14 @@ static void quorum_aio_cb(void *opaque, int ret)
return;
}

type = acb->is_read ? QUORUM_OP_TYPE_READ : QUORUM_OP_TYPE_WRITE;
sacb->ret = ret;
acb->count++;
if (ret == 0) {
acb->success_count++;
} else {
quorum_report_bad(acb, sacb->aiocb->bs->node_name, ret);
quorum_report_bad(type, acb->sector_num, acb->nb_sectors,
sacb->aiocb->bs->node_name, ret);
}
assert(acb->count <= s->num_children);
assert(acb->success_count <= s->num_children);
Expand Down Expand Up @@ -338,7 +343,9 @@ static void quorum_report_bad_versions(BDRVQuorumState *s,
continue;
}
QLIST_FOREACH(item, &version->items, next) {
quorum_report_bad(acb, s->children[item->index]->bs->node_name, 0);
quorum_report_bad(QUORUM_OP_TYPE_READ, acb->sector_num,
acb->nb_sectors,
s->children[item->index]->bs->node_name, 0);
}
}
}
Expand Down
11 changes: 10 additions & 1 deletion docs/qmp-events.txt
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ Emitted to report a corruption of a Quorum file.

Data:

- "type": Quorum operation type
- "error": Error message (json-string, optional)
Only present on failure. This field contains a human-readable
error message. There are no semantics other than that the
Expand All @@ -336,10 +337,18 @@ Data:

Example:

Read operation:
{ "event": "QUORUM_REPORT_BAD",
"data": { "node-name": "node0", "sector-num": 345435, "sectors-count": 5 },
"data": { "node-name": "node0", "sector-num": 345435, "sectors-count": 5,
"type": "read" },
"timestamp": { "seconds": 1344522075, "microseconds": 745528 } }

Flush operation:
{ "event": "QUORUM_REPORT_BAD",
"data": { "node-name": "node0", "sector-num": 0, "sectors-count": 2097120,
"type": "flush", "error": "Broken pipe" },
"timestamp": { "seconds": 1456406829, "microseconds": 291763 } }

Note: this event is rate-limited.

RESET
Expand Down
16 changes: 16 additions & 0 deletions qapi/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -196,3 +196,19 @@
##
{ 'event': 'DEVICE_TRAY_MOVED',
'data': { 'device': 'str', 'tray-open': 'bool' } }

##
# @QuorumOpType
#
# An enumeration of the quorum operation types
#
# @read: read operation
#
# @write: write operation
#
# @flush: flush operation
#
# Since: 2.6
##
{ 'enum': 'QuorumOpType',
'data': [ 'read', 'write', 'flush' ] }
4 changes: 3 additions & 1 deletion qapi/event.json
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,8 @@
#
# Emitted to report a corruption of a Quorum file
#
# @type: quorum operation type (Since 2.6)
#
# @error: #optional, error message. Only present on failure. This field
# contains a human-readable error message. There are no semantics other
# than that the block layer reported an error and clients should not
Expand All @@ -339,7 +341,7 @@
# Since: 2.0
##
{ 'event': 'QUORUM_REPORT_BAD',
'data': { '*error': 'str', 'node-name': 'str',
'data': { 'type': 'QuorumOpType', '*error': 'str', 'node-name': 'str',
'sector-num': 'int', 'sectors-count': 'int' } }

##
Expand Down

0 comments on commit 0ae053b

Please sign in to comment.