Skip to content

Commit

Permalink
block: Rename BdrvChildRole to BdrvChildClass
Browse files Browse the repository at this point in the history
This structure nearly only contains parent callbacks for child state
changes.  It cannot really reflect a child's role, because different
roles may overlap (as we will see when real roles are introduced), and
because parents can have custom callbacks even when the child fulfills a
standard role.

Signed-off-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Alberto Garcia <berto@igalia.com>
Message-Id: <20200513110544.176672-4-mreitz@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
  • Loading branch information
XanClic authored and kevmw committed May 18, 2020
1 parent d67066d commit bd86fb9
Show file tree
Hide file tree
Showing 17 changed files with 141 additions and 133 deletions.
142 changes: 73 additions & 69 deletions block.c

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions block/backup-top.c
Expand Up @@ -122,7 +122,7 @@ static void backup_top_refresh_filename(BlockDriverState *bs)
}

static void backup_top_child_perm(BlockDriverState *bs, BdrvChild *c,
const BdrvChildRole *role,
const BdrvChildClass *child_class,
BlockReopenQueue *reopen_queue,
uint64_t perm, uint64_t shared,
uint64_t *nperm, uint64_t *nshared)
Expand All @@ -142,7 +142,7 @@ static void backup_top_child_perm(BlockDriverState *bs, BdrvChild *c,
return;
}

if (role == &child_file) {
if (child_class == &child_file) {
/*
* Target child
*
Expand All @@ -155,8 +155,8 @@ static void backup_top_child_perm(BlockDriverState *bs, BdrvChild *c,
*nperm = BLK_PERM_WRITE;
} else {
/* Source child */
bdrv_filter_default_perms(bs, c, role, reopen_queue, perm, shared,
nperm, nshared);
bdrv_filter_default_perms(bs, c, child_class, reopen_queue,
perm, shared, nperm, nshared);

if (perm & BLK_PERM_WRITE) {
*nperm = *nperm | BLK_PERM_CONSISTENT_READ;
Expand Down
4 changes: 2 additions & 2 deletions block/blkdebug.c
Expand Up @@ -993,14 +993,14 @@ static int blkdebug_reopen_prepare(BDRVReopenState *reopen_state,
}

static void blkdebug_child_perm(BlockDriverState *bs, BdrvChild *c,
const BdrvChildRole *role,
const BdrvChildClass *child_class,
BlockReopenQueue *reopen_queue,
uint64_t perm, uint64_t shared,
uint64_t *nperm, uint64_t *nshared)
{
BDRVBlkdebugState *s = bs->opaque;

bdrv_filter_default_perms(bs, c, role, reopen_queue, perm, shared,
bdrv_filter_default_perms(bs, c, child_class, reopen_queue, perm, shared,
nperm, nshared);

*nperm |= s->take_child_perms;
Expand Down
8 changes: 5 additions & 3 deletions block/blklogwrites.c
Expand Up @@ -282,7 +282,7 @@ static int64_t blk_log_writes_getlength(BlockDriverState *bs)
}

static void blk_log_writes_child_perm(BlockDriverState *bs, BdrvChild *c,
const BdrvChildRole *role,
const BdrvChildClass *child_class,
BlockReopenQueue *ro_q,
uint64_t perm, uint64_t shrd,
uint64_t *nperm, uint64_t *nshrd)
Expand All @@ -294,9 +294,11 @@ static void blk_log_writes_child_perm(BlockDriverState *bs, BdrvChild *c,
}

if (!strcmp(c->name, "log")) {
bdrv_format_default_perms(bs, c, role, ro_q, perm, shrd, nperm, nshrd);
bdrv_format_default_perms(bs, c, child_class, ro_q, perm, shrd, nperm,
nshrd);
} else {
bdrv_filter_default_perms(bs, c, role, ro_q, perm, shrd, nperm, nshrd);
bdrv_filter_default_perms(bs, c, child_class, ro_q, perm, shrd, nperm,
nshrd);
}
}

Expand Down
6 changes: 3 additions & 3 deletions block/block-backend.c
Expand Up @@ -297,7 +297,7 @@ static void blk_root_detach(BdrvChild *child)
}
}

static const BdrvChildRole child_root = {
static const BdrvChildClass child_root = {
.inherit_options = blk_root_inherit_options,

.change_media = blk_root_change_media,
Expand Down Expand Up @@ -716,7 +716,7 @@ static BlockBackend *bdrv_first_blk(BlockDriverState *bs)
{
BdrvChild *child;
QLIST_FOREACH(child, &bs->parents, next_parent) {
if (child->role == &child_root) {
if (child->klass == &child_root) {
return child->opaque;
}
}
Expand All @@ -740,7 +740,7 @@ bool bdrv_is_root_node(BlockDriverState *bs)
BdrvChild *c;

QLIST_FOREACH(c, &bs->parents, next_parent) {
if (c->role != &child_root) {
if (c->klass != &child_root) {
return false;
}
}
Expand Down
2 changes: 1 addition & 1 deletion block/commit.c
Expand Up @@ -223,7 +223,7 @@ static void bdrv_commit_top_refresh_filename(BlockDriverState *bs)
}

static void bdrv_commit_top_child_perm(BlockDriverState *bs, BdrvChild *c,
const BdrvChildRole *role,
const BdrvChildClass *child_class,
BlockReopenQueue *reopen_queue,
uint64_t perm, uint64_t shared,
uint64_t *nperm, uint64_t *nshared)
Expand Down
2 changes: 1 addition & 1 deletion block/copy-on-read.c
Expand Up @@ -51,7 +51,7 @@ static int cor_open(BlockDriverState *bs, QDict *options, int flags,
#define PERM_UNCHANGED (BLK_PERM_ALL & ~PERM_PASSTHROUGH)

static void cor_child_perm(BlockDriverState *bs, BdrvChild *c,
const BdrvChildRole *role,
const BdrvChildClass *child_class,
BlockReopenQueue *reopen_queue,
uint64_t perm, uint64_t shared,
uint64_t *nperm, uint64_t *nshared)
Expand Down
22 changes: 11 additions & 11 deletions block/io.c
Expand Up @@ -50,7 +50,7 @@ static void bdrv_parent_drained_begin(BlockDriverState *bs, BdrvChild *ignore,
BdrvChild *c, *next;

QLIST_FOREACH_SAFE(c, &bs->parents, next_parent, next) {
if (c == ignore || (ignore_bds_parents && c->role->parent_is_bds)) {
if (c == ignore || (ignore_bds_parents && c->klass->parent_is_bds)) {
continue;
}
bdrv_parent_drained_begin_single(c, false);
Expand All @@ -62,8 +62,8 @@ static void bdrv_parent_drained_end_single_no_poll(BdrvChild *c,
{
assert(c->parent_quiesce_counter > 0);
c->parent_quiesce_counter--;
if (c->role->drained_end) {
c->role->drained_end(c, drained_end_counter);
if (c->klass->drained_end) {
c->klass->drained_end(c, drained_end_counter);
}
}

Expand All @@ -81,7 +81,7 @@ static void bdrv_parent_drained_end(BlockDriverState *bs, BdrvChild *ignore,
BdrvChild *c;

QLIST_FOREACH(c, &bs->parents, next_parent) {
if (c == ignore || (ignore_bds_parents && c->role->parent_is_bds)) {
if (c == ignore || (ignore_bds_parents && c->klass->parent_is_bds)) {
continue;
}
bdrv_parent_drained_end_single_no_poll(c, drained_end_counter);
Expand All @@ -90,8 +90,8 @@ static void bdrv_parent_drained_end(BlockDriverState *bs, BdrvChild *ignore,

static bool bdrv_parent_drained_poll_single(BdrvChild *c)
{
if (c->role->drained_poll) {
return c->role->drained_poll(c);
if (c->klass->drained_poll) {
return c->klass->drained_poll(c);
}
return false;
}
Expand All @@ -103,7 +103,7 @@ static bool bdrv_parent_drained_poll(BlockDriverState *bs, BdrvChild *ignore,
bool busy = false;

QLIST_FOREACH_SAFE(c, &bs->parents, next_parent, next) {
if (c == ignore || (ignore_bds_parents && c->role->parent_is_bds)) {
if (c == ignore || (ignore_bds_parents && c->klass->parent_is_bds)) {
continue;
}
busy |= bdrv_parent_drained_poll_single(c);
Expand All @@ -115,8 +115,8 @@ static bool bdrv_parent_drained_poll(BlockDriverState *bs, BdrvChild *ignore,
void bdrv_parent_drained_begin_single(BdrvChild *c, bool poll)
{
c->parent_quiesce_counter++;
if (c->role->drained_begin) {
c->role->drained_begin(c);
if (c->klass->drained_begin) {
c->klass->drained_begin(c);
}
if (poll) {
BDRV_POLL_WHILE(c->bs, bdrv_parent_drained_poll_single(c));
Expand Down Expand Up @@ -3326,8 +3326,8 @@ static void bdrv_parent_cb_resize(BlockDriverState *bs)
{
BdrvChild *c;
QLIST_FOREACH(c, &bs->parents, next_parent) {
if (c->role->resize) {
c->role->resize(c);
if (c->klass->resize) {
c->klass->resize(c);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion block/mirror.c
Expand Up @@ -1492,7 +1492,7 @@ static void bdrv_mirror_top_refresh_filename(BlockDriverState *bs)
}

static void bdrv_mirror_top_child_perm(BlockDriverState *bs, BdrvChild *c,
const BdrvChildRole *role,
const BdrvChildClass *child_class,
BlockReopenQueue *reopen_queue,
uint64_t perm, uint64_t shared,
uint64_t *nperm, uint64_t *nshared)
Expand Down
2 changes: 1 addition & 1 deletion block/quorum.c
Expand Up @@ -1151,7 +1151,7 @@ static char *quorum_dirname(BlockDriverState *bs, Error **errp)
}

static void quorum_child_perm(BlockDriverState *bs, BdrvChild *c,
const BdrvChildRole *role,
const BdrvChildClass *child_class,
BlockReopenQueue *reopen_queue,
uint64_t perm, uint64_t shared,
uint64_t *nperm, uint64_t *nshared)
Expand Down
2 changes: 1 addition & 1 deletion block/replication.c
Expand Up @@ -163,7 +163,7 @@ static void replication_close(BlockDriverState *bs)
}

static void replication_child_perm(BlockDriverState *bs, BdrvChild *c,
const BdrvChildRole *role,
const BdrvChildClass *child_class,
BlockReopenQueue *reopen_queue,
uint64_t perm, uint64_t shared,
uint64_t *nperm, uint64_t *nshared)
Expand Down
6 changes: 3 additions & 3 deletions block/vvfat.c
Expand Up @@ -3136,7 +3136,7 @@ static void vvfat_qcow_options(int *child_flags, QDict *child_options,
qdict_set_default_str(child_options, BDRV_OPT_CACHE_NO_FLUSH, "on");
}

static const BdrvChildRole child_vvfat_qcow = {
static const BdrvChildClass child_vvfat_qcow = {
.parent_is_bds = true,
.inherit_options = vvfat_qcow_options,
};
Expand Down Expand Up @@ -3210,14 +3210,14 @@ static int enable_write_target(BlockDriverState *bs, Error **errp)
}

static void vvfat_child_perm(BlockDriverState *bs, BdrvChild *c,
const BdrvChildRole *role,
const BdrvChildClass *child_class,
BlockReopenQueue *reopen_queue,
uint64_t perm, uint64_t shared,
uint64_t *nperm, uint64_t *nshared)
{
BDRVVVFATState *s = bs->opaque;

assert(c == s->qcow || role == &child_backing);
assert(c == s->qcow || child_class == &child_backing);

if (c == s->qcow) {
/* This is a private node, nobody should try to attach to it */
Expand Down
2 changes: 1 addition & 1 deletion blockjob.c
Expand Up @@ -163,7 +163,7 @@ static void child_job_set_aio_ctx(BdrvChild *c, AioContext *ctx,
job->job.aio_context = ctx;
}

static const BdrvChildRole child_job = {
static const BdrvChildClass child_job = {
.get_parent_desc = child_job_get_parent_desc,
.drained_begin = child_job_drained_begin,
.drained_poll = child_job_drained_poll,
Expand Down
6 changes: 3 additions & 3 deletions include/block/block.h
Expand Up @@ -13,7 +13,7 @@
/* block.c */
typedef struct BlockDriver BlockDriver;
typedef struct BdrvChild BdrvChild;
typedef struct BdrvChildRole BdrvChildRole;
typedef struct BdrvChildClass BdrvChildClass;

typedef struct BlockDriverInfo {
/* in bytes, 0 if irrelevant */
Expand Down Expand Up @@ -296,7 +296,7 @@ int bdrv_parse_discard_flags(const char *mode, int *flags);
BdrvChild *bdrv_open_child(const char *filename,
QDict *options, const char *bdref_key,
BlockDriverState* parent,
const BdrvChildRole *child_role,
const BdrvChildClass *child_class,
bool allow_none, Error **errp);
BlockDriverState *bdrv_open_blockdev_ref(BlockdevRef *ref, Error **errp);
void bdrv_set_backing_hd(BlockDriverState *bs, BlockDriverState *backing_hd,
Expand Down Expand Up @@ -541,7 +541,7 @@ void bdrv_unref_child(BlockDriverState *parent, BdrvChild *child);
BdrvChild *bdrv_attach_child(BlockDriverState *parent_bs,
BlockDriverState *child_bs,
const char *child_name,
const BdrvChildRole *child_role,
const BdrvChildClass *child_class,
Error **errp);

bool bdrv_op_is_blocked(BlockDriverState *bs, BlockOpType op, Error **errp);
Expand Down
22 changes: 11 additions & 11 deletions include/block/block_int.h
Expand Up @@ -556,14 +556,14 @@ struct BlockDriver {
* the parents in @parent_perm and @parent_shared.
*
* If @c is NULL, return the permissions for attaching a new child for the
* given @role.
* given @child_class.
*
* If @reopen_queue is non-NULL, don't return the currently needed
* permissions, but those that will be needed after applying the
* @reopen_queue.
*/
void (*bdrv_child_perm)(BlockDriverState *bs, BdrvChild *c,
const BdrvChildRole *role,
const BdrvChildClass *child_class,
BlockReopenQueue *reopen_queue,
uint64_t parent_perm, uint64_t parent_shared,
uint64_t *nperm, uint64_t *nshared);
Expand Down Expand Up @@ -665,7 +665,7 @@ typedef struct BdrvAioNotifier {
QLIST_ENTRY(BdrvAioNotifier) list;
} BdrvAioNotifier;

struct BdrvChildRole {
struct BdrvChildClass {
/* If true, bdrv_replace_node() doesn't change the node this BdrvChild
* points to. */
bool stay_at_node;
Expand Down Expand Up @@ -738,14 +738,14 @@ struct BdrvChildRole {
void (*set_aio_ctx)(BdrvChild *child, AioContext *ctx, GSList **ignore);
};

extern const BdrvChildRole child_file;
extern const BdrvChildRole child_format;
extern const BdrvChildRole child_backing;
extern const BdrvChildClass child_file;
extern const BdrvChildClass child_format;
extern const BdrvChildClass child_backing;

struct BdrvChild {
BlockDriverState *bs;
char *name;
const BdrvChildRole *role;
const BdrvChildClass *klass;
void *opaque;

/**
Expand All @@ -772,7 +772,7 @@ struct BdrvChild {

/*
* How many times the parent of this child has been drained
* (through role->drained_*).
* (through klass->drained_*).
* Usually, this is equal to bs->quiesce_counter (potentially
* reduced by bdrv_drain_all_count). It may differ while the
* child is entering or leaving a drained section.
Expand Down Expand Up @@ -1232,7 +1232,7 @@ BlockJob *backup_job_create(const char *job_id, BlockDriverState *bs,

BdrvChild *bdrv_root_attach_child(BlockDriverState *child_bs,
const char *child_name,
const BdrvChildRole *child_role,
const BdrvChildClass *child_class,
AioContext *ctx,
uint64_t perm, uint64_t shared_perm,
void *opaque, Error **errp);
Expand Down Expand Up @@ -1263,7 +1263,7 @@ int bdrv_child_refresh_perms(BlockDriverState *bs, BdrvChild *c, Error **errp);
* block filters: Forward CONSISTENT_READ, WRITE, WRITE_UNCHANGED and RESIZE to
* all children */
void bdrv_filter_default_perms(BlockDriverState *bs, BdrvChild *c,
const BdrvChildRole *role,
const BdrvChildClass *child_class,
BlockReopenQueue *reopen_queue,
uint64_t perm, uint64_t shared,
uint64_t *nperm, uint64_t *nshared);
Expand All @@ -1273,7 +1273,7 @@ void bdrv_filter_default_perms(BlockDriverState *bs, BdrvChild *c,
* requires WRITE | RESIZE for read-write images, always requires
* CONSISTENT_READ and doesn't share WRITE. */
void bdrv_format_default_perms(BlockDriverState *bs, BdrvChild *c,
const BdrvChildRole *role,
const BdrvChildClass *child_class,
BlockReopenQueue *reopen_queue,
uint64_t perm, uint64_t shared,
uint64_t *nperm, uint64_t *nshared);
Expand Down

0 comments on commit bd86fb9

Please sign in to comment.