From: Kevin Wolf <kwolf@redhat.com>
To: qemu-block@nongnu.org
Cc: kwolf@redhat.com, mreitz@redhat.com, berto@igalia.com,
qemu-devel@nongnu.org
Subject: [Qemu-devel] [RFC PATCH 7/8] quorum: Implement .bdrv_co_preadv/pwritev()
Date: Thu, 10 Nov 2016 18:19:08 +0100 [thread overview]
Message-ID: <1478798349-28983-8-git-send-email-kwolf@redhat.com> (raw)
In-Reply-To: <1478798349-28983-1-git-send-email-kwolf@redhat.com>
This enables byte granularity requests on quorum nodes.
Note that the QMP events emitted by the driver are an external API that
we were careless enough to define as sector based. The offset and length
of requests reported in events are rounded down therefore.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
block/quorum.c | 75 ++++++++++++++++++++++++++--------------------------------
1 file changed, 33 insertions(+), 42 deletions(-)
diff --git a/block/quorum.c b/block/quorum.c
index 1426115..45939c5 100644
--- a/block/quorum.c
+++ b/block/quorum.c
@@ -114,8 +114,8 @@ struct QuorumAIOCB {
Coroutine *co;
/* Request metadata */
- uint64_t sector_num;
- int nb_sectors;
+ uint64_t offset;
+ uint64_t bytes;
QEMUIOVector *qiov; /* calling IOV */
@@ -159,8 +159,8 @@ static bool quorum_64bits_compare(QuorumVoteValue *a, QuorumVoteValue *b)
static QuorumAIOCB *quorum_aio_get(BlockDriverState *bs,
QEMUIOVector *qiov,
- uint64_t sector_num,
- int nb_sectors)
+ uint64_t offset,
+ uint64_t bytes)
{
BDRVQuorumState *s = bs->opaque;
QuorumAIOCB *acb = g_new(QuorumAIOCB, 1);
@@ -168,8 +168,8 @@ static QuorumAIOCB *quorum_aio_get(BlockDriverState *bs,
acb->co = qemu_coroutine_self();
acb->bs = bs;
- acb->sector_num = sector_num;
- acb->nb_sectors = nb_sectors;
+ acb->offset = offset;
+ acb->bytes = bytes;
acb->qiov = qiov;
acb->qcrs = g_new0(QuorumChildRequest, s->num_children);
acb->count = 0;
@@ -189,8 +189,8 @@ static QuorumAIOCB *quorum_aio_get(BlockDriverState *bs,
return acb;
}
-static void quorum_report_bad(QuorumOpType type, uint64_t sector_num,
- int nb_sectors, char *node_name, int ret)
+static void quorum_report_bad(QuorumOpType type, uint64_t offset,
+ uint64_t bytes, char *node_name, int ret)
{
const char *msg = NULL;
if (ret < 0) {
@@ -198,14 +198,17 @@ static void quorum_report_bad(QuorumOpType type, uint64_t sector_num,
}
qapi_event_send_quorum_report_bad(type, !!msg, msg, node_name,
- sector_num, nb_sectors, &error_abort);
+ offset / BDRV_SECTOR_SIZE,
+ bytes / BDRV_SECTOR_SIZE, &error_abort);
}
static void quorum_report_failure(QuorumAIOCB *acb)
{
const char *reference = bdrv_get_device_or_node_name(acb->bs);
- qapi_event_send_quorum_failure(reference, acb->sector_num,
- acb->nb_sectors, &error_abort);
+ qapi_event_send_quorum_failure(reference,
+ acb->offset / BDRV_SECTOR_SIZE,
+ acb->bytes / BDRV_SECTOR_SIZE,
+ &error_abort);
}
static int quorum_vote_error(QuorumAIOCB *acb);
@@ -242,8 +245,7 @@ static void quorum_report_bad_acb(QuorumChildRequest *sacb, int ret)
{
QuorumAIOCB *acb = sacb->parent;
QuorumOpType type = acb->is_read ? QUORUM_OP_TYPE_READ : QUORUM_OP_TYPE_WRITE;
- quorum_report_bad(type, acb->sector_num, acb->nb_sectors,
- sacb->bs->node_name, ret);
+ quorum_report_bad(type, acb->offset, acb->bytes, sacb->bs->node_name, ret);
}
static int quorum_fifo_aio_cb(void *opaque, int ret)
@@ -282,8 +284,7 @@ static void quorum_report_bad_versions(BDRVQuorumState *s,
continue;
}
QLIST_FOREACH(item, &version->items, next) {
- quorum_report_bad(QUORUM_OP_TYPE_READ, acb->sector_num,
- acb->nb_sectors,
+ quorum_report_bad(QUORUM_OP_TYPE_READ, acb->offset, acb->bytes,
s->children[item->index]->bs->node_name, 0);
}
}
@@ -296,9 +297,7 @@ static void quorum_rewrite_entry(void *opaque)
BDRVQuorumState *s = acb->bs->opaque;
int ret;
- ret = bdrv_co_pwritev(s->children[co->i],
- acb->sector_num * BDRV_SECTOR_SIZE,
- acb->nb_sectors * BDRV_SECTOR_SIZE,
+ ret = bdrv_co_pwritev(s->children[co->i], acb->offset, acb->bytes,
acb->qiov, 0);
(void) ret;
@@ -462,8 +461,8 @@ static void GCC_FMT_ATTR(2, 3) quorum_err(QuorumAIOCB *acb,
va_list ap;
va_start(ap, fmt);
- fprintf(stderr, "quorum: sector_num=%" PRId64 " nb_sectors=%d ",
- acb->sector_num, acb->nb_sectors);
+ fprintf(stderr, "quorum: offset=%" PRIu64 " bytes=%" PRIu64 " ",
+ acb->offset, acb->bytes);
vfprintf(stderr, fmt, ap);
fprintf(stderr, "\n");
va_end(ap);
@@ -481,9 +480,8 @@ static bool quorum_compare(QuorumAIOCB *acb,
if (s->is_blkverify) {
offset = qemu_iovec_compare(a, b);
if (offset != -1) {
- quorum_err(acb, "contents mismatch in sector %" PRId64,
- acb->sector_num +
- (uint64_t)(offset / BDRV_SECTOR_SIZE));
+ quorum_err(acb, "contents mismatch at offset %" PRIu64,
+ acb->offset + offset);
}
return true;
}
@@ -615,9 +613,7 @@ static void read_quorum_children_entry(void *opaque)
co = NULL; /* Not valid after the first yield */
sacb->bs = s->children[i]->bs;
- sacb->ret = bdrv_co_preadv(s->children[i],
- acb->sector_num * BDRV_SECTOR_SIZE,
- acb->nb_sectors * BDRV_SECTOR_SIZE,
+ sacb->ret = bdrv_co_preadv(s->children[i], acb->offset, acb->bytes,
&acb->qcrs[i].qiov, 0);
if (sacb->ret == 0) {
@@ -685,19 +681,17 @@ static int read_fifo_child(QuorumAIOCB *acb)
int ret;
acb->qcrs[n].bs = s->children[n]->bs;
- ret = bdrv_co_preadv(s->children[n], acb->sector_num * BDRV_SECTOR_SIZE,
- acb->nb_sectors * BDRV_SECTOR_SIZE, acb->qiov, 0);
+ ret = bdrv_co_preadv(s->children[n], acb->offset, acb->bytes, acb->qiov, 0);
ret = quorum_fifo_aio_cb(&acb->qcrs[n], ret);
return ret;
}
-static int quorum_co_readv(BlockDriverState *bs,
- int64_t sector_num, int nb_sectors,
- QEMUIOVector *qiov)
+static int quorum_co_preadv(BlockDriverState *bs, uint64_t offset,
+ uint64_t bytes, QEMUIOVector *qiov, int flags)
{
BDRVQuorumState *s = bs->opaque;
- QuorumAIOCB *acb = quorum_aio_get(bs, qiov, sector_num, nb_sectors);
+ QuorumAIOCB *acb = quorum_aio_get(bs, qiov, offset, bytes);
int ret;
acb->is_read = true;
@@ -723,9 +717,7 @@ static void write_quorum_entry(void *opaque)
co = NULL; /* Not valid after the first yield */
sacb->bs = s->children[i]->bs;
- sacb->ret = bdrv_co_pwritev(s->children[i],
- acb->sector_num * BDRV_SECTOR_SIZE,
- acb->nb_sectors * BDRV_SECTOR_SIZE,
+ sacb->ret = bdrv_co_pwritev(s->children[i], acb->offset, acb->bytes,
acb->qiov, 0);
if (sacb->ret == 0) {
acb->success_count++;
@@ -739,12 +731,11 @@ static void write_quorum_entry(void *opaque)
qemu_coroutine_enter_if_inactive(acb->co);
}
-static int quorum_co_writev(BlockDriverState *bs,
- int64_t sector_num, int nb_sectors,
- QEMUIOVector *qiov)
+static int quorum_co_pwritev(BlockDriverState *bs, uint64_t offset,
+ uint64_t bytes, QEMUIOVector *qiov, int flags)
{
BDRVQuorumState *s = bs->opaque;
- QuorumAIOCB *acb = quorum_aio_get(bs, qiov, sector_num, nb_sectors);
+ QuorumAIOCB *acb = quorum_aio_get(bs, qiov, offset, bytes);
int i, ret;
for (i = 0; i < s->num_children; i++) {
@@ -811,7 +802,7 @@ static coroutine_fn int quorum_co_flush(BlockDriverState *bs)
result = bdrv_co_flush(s->children[i]->bs);
if (result) {
quorum_report_bad(QUORUM_OP_TYPE_FLUSH, 0,
- bdrv_nb_sectors(s->children[i]->bs),
+ bdrv_getlength(s->children[i]->bs),
s->children[i]->bs->node_name, result);
result_value.l = result;
quorum_count_vote(&error_votes, &result_value, i);
@@ -1144,8 +1135,8 @@ static BlockDriver bdrv_quorum = {
.bdrv_getlength = quorum_getlength,
- .bdrv_co_readv = quorum_co_readv,
- .bdrv_co_writev = quorum_co_writev,
+ .bdrv_co_preadv = quorum_co_preadv,
+ .bdrv_co_pwritev = quorum_co_pwritev,
.bdrv_add_child = quorum_add_child,
.bdrv_del_child = quorum_del_child,
--
1.8.3.1
next prev parent reply other threads:[~2016-11-10 17:19 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-11-10 17:19 [Qemu-devel] [RFC PATCH 0/8] quorum: Implement .bdrv_co_preadv/pwritev() Kevin Wolf
2016-11-10 17:19 ` [Qemu-devel] [RFC PATCH 1/8] coroutine: Introduce qemu_coroutine_enter_if_inactive() Kevin Wolf
2016-11-10 23:49 ` Eric Blake
2016-11-17 9:30 ` Alberto Garcia
2016-11-10 17:19 ` [Qemu-devel] [RFC PATCH 2/8] quorum: Remove s from quorum_aio_get() arguments Kevin Wolf
2016-11-10 23:52 ` Eric Blake
2016-11-11 9:58 ` Paolo Bonzini
2016-11-11 14:18 ` Alberto Garcia
2016-11-10 17:19 ` [Qemu-devel] [RFC PATCH 3/8] quorum: Implement .bdrv_co_readv/writev Kevin Wolf
2016-11-11 1:56 ` Eric Blake
2016-11-16 15:57 ` Alberto Garcia
2016-11-10 17:19 ` [Qemu-devel] [RFC PATCH 4/8] quorum: Do cleanup in caller coroutine Kevin Wolf
2016-11-11 2:18 ` Eric Blake
2016-11-17 10:04 ` Alberto Garcia
2016-11-10 17:19 ` [Qemu-devel] [RFC PATCH 5/8] quorum: Inline quorum_aio_cb() Kevin Wolf
2016-11-17 14:25 ` Alberto Garcia
2016-11-10 17:19 ` [Qemu-devel] [RFC PATCH 6/8] quorum: Avoid bdrv_aio_writev() for rewrites Kevin Wolf
2016-11-11 2:25 ` Eric Blake
2016-11-17 14:54 ` Alberto Garcia
2016-11-18 12:21 ` Kevin Wolf
2016-11-18 12:33 ` Alberto Garcia
2016-11-18 21:11 ` Eric Blake
2016-11-21 11:56 ` Kevin Wolf
2016-11-10 17:19 ` Kevin Wolf [this message]
2016-11-11 2:37 ` [Qemu-devel] [RFC PATCH 7/8] quorum: Implement .bdrv_co_preadv/pwritev() Eric Blake
2016-11-11 9:58 ` Kevin Wolf
2016-11-11 15:08 ` Eric Blake
2016-11-17 15:30 ` Alberto Garcia
2016-11-10 17:19 ` [Qemu-devel] [RFC PATCH 8/8] quorum: Inline quorum_fifo_aio_cb() Kevin Wolf
2016-11-18 9:47 ` Alberto Garcia
2016-11-11 9:56 ` [Qemu-devel] [RFC PATCH 0/8] quorum: Implement .bdrv_co_preadv/pwritev() Paolo Bonzini
2016-11-11 10:22 ` Kevin Wolf
2016-11-18 9:51 ` Alberto Garcia
2016-11-18 11:10 ` Paolo Bonzini
2016-11-13 3:18 ` no-reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1478798349-28983-8-git-send-email-kwolf@redhat.com \
--to=kwolf@redhat.com \
--cc=berto@igalia.com \
--cc=mreitz@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).