mirror of
git://sourceware.org/git/lvm2.git
synced 2025-03-01 08:58:47 +03:00
Add mda location specific mda_copy constructor.
Because of the way mdas are handled internally, where a PV in a VG has mdas on both info->mdas and vg->fid->metadata_areas list, we need a location independent copy constructor for struct metadata_area. Break up the existing format-text specific copy constructor into a format independent piece and a format dependent piece. This function is necessary to properly implement pv_set_mda_ignored(). Signed-off-by: Dave Wysochanski <dwysocha@redhat.com> Reviewed-by: Alasdair G Kergon <agk@redhat.com>
This commit is contained in:
parent
e56f421490
commit
d4f0f090c0
@ -1622,32 +1622,20 @@ static int _populate_pv_fields(struct lvmcache_info *info,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copy constructor for a metadata_area.
|
* Copy constructor for a metadata_locn.
|
||||||
*/
|
*/
|
||||||
static struct metadata_area *_mda_copy(struct dm_pool *mem,
|
static void *_metadata_locn_copy_raw(struct dm_pool *mem, void *metadata_locn)
|
||||||
struct metadata_area *mda)
|
|
||||||
{
|
{
|
||||||
struct metadata_area *mda_new;
|
|
||||||
struct mda_context *mdac, *mdac_new;
|
struct mda_context *mdac, *mdac_new;
|
||||||
|
|
||||||
if (!(mda_new = dm_pool_alloc(mem, sizeof(*mda_new)))) {
|
mdac = (struct mda_context *) metadata_locn;
|
||||||
log_error("metadata_area allocation failed");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
/* FIXME: Should have a per-format constructor here */
|
|
||||||
mdac = (struct mda_context *) mda->metadata_locn;
|
|
||||||
if (!(mdac_new = dm_pool_alloc(mem, sizeof(*mdac_new)))) {
|
if (!(mdac_new = dm_pool_alloc(mem, sizeof(*mdac_new)))) {
|
||||||
log_error("mda_context allocation failed");
|
log_error("mda_context allocation failed");
|
||||||
dm_pool_free(mem, mda_new);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
memcpy(mda_new, mda, sizeof(*mda));
|
|
||||||
memcpy(mdac_new, mdac, sizeof(*mdac));
|
memcpy(mdac_new, mdac, sizeof(*mdac));
|
||||||
mda_new->metadata_locn = mdac_new;
|
|
||||||
|
|
||||||
/* FIXME mda 'list' left invalid here */
|
return mdac_new;
|
||||||
|
|
||||||
return mda_new;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1675,7 +1663,7 @@ static int _text_pv_read(const struct format_type *fmt, const char *pv_name,
|
|||||||
|
|
||||||
/* Add copy of mdas to supplied list */
|
/* Add copy of mdas to supplied list */
|
||||||
dm_list_iterate_items(mda, &info->mdas) {
|
dm_list_iterate_items(mda, &info->mdas) {
|
||||||
mda_new = _mda_copy(fmt->cmd->mem, mda);
|
mda_new = mda_copy(fmt->cmd->mem, mda);
|
||||||
if (!mda_new)
|
if (!mda_new)
|
||||||
return 0;
|
return 0;
|
||||||
dm_list_add(mdas, &mda_new->list);
|
dm_list_add(mdas, &mda_new->list);
|
||||||
@ -1742,6 +1730,7 @@ static struct metadata_area_ops _metadata_text_raw_ops = {
|
|||||||
.vg_precommit = _vg_precommit_raw,
|
.vg_precommit = _vg_precommit_raw,
|
||||||
.vg_commit = _vg_commit_raw,
|
.vg_commit = _vg_commit_raw,
|
||||||
.vg_revert = _vg_revert_raw,
|
.vg_revert = _vg_revert_raw,
|
||||||
|
.mda_metadata_locn_copy = _metadata_locn_copy_raw,
|
||||||
.mda_free_sectors = _mda_free_sectors_raw,
|
.mda_free_sectors = _mda_free_sectors_raw,
|
||||||
.mda_total_sectors = _mda_total_sectors_raw,
|
.mda_total_sectors = _mda_total_sectors_raw,
|
||||||
.mda_in_vg = _mda_in_vg_raw,
|
.mda_in_vg = _mda_in_vg_raw,
|
||||||
@ -1812,7 +1801,7 @@ static int _text_pv_setup(const struct format_type *fmt,
|
|||||||
if (found)
|
if (found)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
mda_new = _mda_copy(fmt->cmd->mem, mda);
|
mda_new = mda_copy(fmt->cmd->mem, mda);
|
||||||
if (!mda_new)
|
if (!mda_new)
|
||||||
return_0;
|
return_0;
|
||||||
dm_list_add(mdas, &mda_new->list);
|
dm_list_add(mdas, &mda_new->list);
|
||||||
@ -1980,7 +1969,7 @@ static struct format_instance *_text_create_text_instance(const struct format_ty
|
|||||||
mdas = &info->mdas;
|
mdas = &info->mdas;
|
||||||
dm_list_iterate_items(mda, mdas) {
|
dm_list_iterate_items(mda, mdas) {
|
||||||
/* FIXME Check it holds this VG */
|
/* FIXME Check it holds this VG */
|
||||||
mda_new = _mda_copy(fmt->cmd->mem, mda);
|
mda_new = mda_copy(fmt->cmd->mem, mda);
|
||||||
if (!mda_new)
|
if (!mda_new)
|
||||||
return_NULL;
|
return_NULL;
|
||||||
dm_list_add(&fid->metadata_areas, &mda_new->list);
|
dm_list_add(&fid->metadata_areas, &mda_new->list);
|
||||||
|
@ -3855,6 +3855,32 @@ uint32_t pv_pe_alloc_count(const struct physical_volume *pv)
|
|||||||
return pv_field(pv, pe_alloc_count);
|
return pv_field(pv, pe_alloc_count);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copy constructor for a metadata_area.
|
||||||
|
*/
|
||||||
|
struct metadata_area *mda_copy(struct dm_pool *mem,
|
||||||
|
struct metadata_area *mda)
|
||||||
|
{
|
||||||
|
struct metadata_area *mda_new;
|
||||||
|
|
||||||
|
if (!(mda_new = dm_pool_alloc(mem, sizeof(*mda_new)))) {
|
||||||
|
log_error("metadata_area allocation failed");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
memcpy(mda_new, mda, sizeof(*mda));
|
||||||
|
if (mda->ops->mda_metadata_locn_copy && mda->metadata_locn) {
|
||||||
|
mda_new->metadata_locn =
|
||||||
|
mda->ops->mda_metadata_locn_copy(mem, mda->metadata_locn);
|
||||||
|
if (!mda_new->metadata_locn) {
|
||||||
|
dm_pool_free(mem, mda_new);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* FIXME mda 'list' left invalid here */
|
||||||
|
|
||||||
|
return mda_new;
|
||||||
|
}
|
||||||
/*
|
/*
|
||||||
* This function provides a way to answer the question on a format specific
|
* This function provides a way to answer the question on a format specific
|
||||||
* basis - does the format specfic context of these two metadata areas
|
* basis - does the format specfic context of these two metadata areas
|
||||||
|
@ -135,6 +135,11 @@ struct metadata_area_ops {
|
|||||||
int (*vg_remove) (struct format_instance * fi, struct volume_group * vg,
|
int (*vg_remove) (struct format_instance * fi, struct volume_group * vg,
|
||||||
struct metadata_area * mda);
|
struct metadata_area * mda);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Per location copy constructor.
|
||||||
|
*/
|
||||||
|
void *(*mda_metadata_locn_copy) (struct dm_pool *mem, void *metadata_locn);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Returns number of free sectors in given metadata area.
|
* Returns number of free sectors in given metadata area.
|
||||||
*/
|
*/
|
||||||
@ -172,6 +177,8 @@ struct metadata_area {
|
|||||||
void *metadata_locn;
|
void *metadata_locn;
|
||||||
uint32_t flags;
|
uint32_t flags;
|
||||||
};
|
};
|
||||||
|
struct metadata_area *mda_copy(struct dm_pool *mem,
|
||||||
|
struct metadata_area *mda);
|
||||||
|
|
||||||
unsigned mda_is_ignored(struct metadata_area *mda);
|
unsigned mda_is_ignored(struct metadata_area *mda);
|
||||||
void mda_set_ignored(struct metadata_area *mda, int value);
|
void mda_set_ignored(struct metadata_area *mda, int value);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user