1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +03:00

labeller: Make the use of "private" as "fmt" explicit.

All labellers always use the "private" (void *) field as the fmt pointer. Making
this fact explicit in the type of the labeller simplifies the label reporting
code which needs to extract the format. Moreover, it removes a number of
error-prone casts from the code.
This commit is contained in:
Petr Rockai 2013-07-29 15:58:18 +02:00
parent bead8ef5f0
commit 9b91977f4e
9 changed files with 13 additions and 13 deletions

View File

@ -1450,7 +1450,7 @@ struct lvmcache_info *lvmcache_add(struct labeller *labeller, const char *pvid,
const char *vgname, const char *vgid,
uint32_t vgstatus)
{
const struct format_type *fmt = (const struct format_type *) labeller->private;
const struct format_type *fmt = labeller->fmt;
struct dev_types *dt = fmt->cmd->dev_types;
struct label *label;
struct lvmcache_info *existing, *info;
@ -1540,7 +1540,7 @@ struct lvmcache_info *lvmcache_add(struct labeller *labeller, const char *pvid,
label = info->label;
}
info->fmt = (const struct format_type *) labeller->private;
info->fmt = labeller->fmt;
info->status |= CACHE_INVALID;
if (!_lvmcache_update_pvid(info, pvid_s)) {

View File

@ -614,7 +614,7 @@ struct format_type *init_format(struct cmd_context *cmd)
return NULL;
}
if (!(label_register_handler(FMT_LVM1_NAME, fmt->labeller))) {
if (!(label_register_handler(fmt->labeller))) {
log_error("Couldn't register lvm1 label handler.");
fmt->labeller->ops->destroy(fmt->labeller);
dm_free(fmt);

View File

@ -122,7 +122,7 @@ struct labeller *lvm1_labeller_create(struct format_type *fmt)
}
l->ops = &_lvm1_ops;
l->private = (const void *) fmt;
l->fmt = fmt;
return l;
}

View File

@ -309,7 +309,7 @@ struct format_type *init_format(struct cmd_context *cmd)
return NULL;
}
if (!(label_register_handler(FMT_POOL_NAME, fmt->labeller))) {
if (!(label_register_handler(fmt->labeller))) {
log_error("Couldn't register pool label handler.");
fmt->labeller->ops->destroy(fmt->labeller);
dm_free(fmt);

View File

@ -99,7 +99,7 @@ struct labeller *pool_labeller_create(struct format_type *fmt)
}
l->ops = &_pool_ops;
l->private = (const void *) fmt;
l->fmt = fmt;
return l;
}

View File

@ -2433,7 +2433,7 @@ struct format_type *create_text_format(struct cmd_context *cmd)
goto bad;
}
if (!(label_register_handler(FMT_TEXT_NAME, fmt->labeller))) {
if (!(label_register_handler(fmt->labeller))) {
log_error("Couldn't register text label handler.");
fmt->labeller->ops->destroy(fmt->labeller);
goto bad;

View File

@ -316,7 +316,7 @@ struct _update_mda_baton {
static int _update_mda(struct metadata_area *mda, void *baton)
{
struct _update_mda_baton *p = baton;
const struct format_type *fmt = p->label->labeller->private; // Oh dear.
const struct format_type *fmt = p->label->labeller->fmt;
struct mda_context *mdac = (struct mda_context *) mda->metadata_locn;
struct mda_header *mdah;
const char *vgname = NULL;
@ -471,7 +471,7 @@ struct labeller *text_labeller_create(const struct format_type *fmt)
}
l->ops = &_text_ops;
l->private = (const void *) fmt;
l->fmt = fmt;
return l;
}

View File

@ -76,11 +76,11 @@ void label_exit(void)
dm_list_init(&_labellers);
}
int label_register_handler(const char *name, struct labeller *handler)
int label_register_handler(struct labeller *handler)
{
struct labeller_i *li;
if (!(li = _alloc_li(name, handler)))
if (!(li = _alloc_li(handler->fmt->name, handler)))
return_0;
dm_list_add(&_labellers, &li->list);

View File

@ -87,13 +87,13 @@ struct label_ops {
struct labeller {
struct label_ops *ops;
const void *private;
struct format_type *fmt;
};
int label_init(void);
void label_exit(void);
int label_register_handler(const char *name, struct labeller *handler);
int label_register_handler(struct labeller *handler);
struct labeller *label_get_handler(const char *name);