}
/*
- * Copy constructor for a metadata_area.
+ * Copy constructor for a metadata_locn.
*/
-static struct metadata_area *_mda_copy(struct dm_pool *mem,
- struct metadata_area *mda)
+static void *_metadata_locn_copy_raw(struct dm_pool *mem, void *metadata_locn)
{
- struct metadata_area *mda_new;
struct mda_context *mdac, *mdac_new;
- if (!(mda_new = dm_pool_alloc(mem, sizeof(*mda_new)))) {
- log_error("metadata_area allocation failed");
- return NULL;
- }
- /* FIXME: Should have a per-format constructor here */
- mdac = (struct mda_context *) mda->metadata_locn;
+ mdac = (struct mda_context *) metadata_locn;
if (!(mdac_new = dm_pool_alloc(mem, sizeof(*mdac_new)))) {
log_error("mda_context allocation failed");
- dm_pool_free(mem, mda_new);
return NULL;
}
- memcpy(mda_new, mda, sizeof(*mda));
memcpy(mdac_new, mdac, sizeof(*mdac));
- mda_new->metadata_locn = mdac_new;
-
- /* FIXME mda 'list' left invalid here */
- return mda_new;
+ return mdac_new;
}
/* Add copy of mdas to supplied list */
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)
return 0;
dm_list_add(mdas, &mda_new->list);
.vg_precommit = _vg_precommit_raw,
.vg_commit = _vg_commit_raw,
.vg_revert = _vg_revert_raw,
+ .mda_metadata_locn_copy = _metadata_locn_copy_raw,
.mda_free_sectors = _mda_free_sectors_raw,
.mda_total_sectors = _mda_total_sectors_raw,
.mda_in_vg = _mda_in_vg_raw,
if (found)
continue;
- mda_new = _mda_copy(fmt->cmd->mem, mda);
+ mda_new = mda_copy(fmt->cmd->mem, mda);
if (!mda_new)
return_0;
dm_list_add(mdas, &mda_new->list);
mdas = &info->mdas;
dm_list_iterate_items(mda, mdas) {
/* 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)
return_NULL;
dm_list_add(&fid->metadata_areas, &mda_new->list);
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
* basis - does the format specfic context of these two metadata areas
int (*vg_remove) (struct format_instance * fi, struct volume_group * vg,
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.
*/
void *metadata_locn;
uint32_t flags;
};
+struct metadata_area *mda_copy(struct dm_pool *mem,
+ struct metadata_area *mda);
unsigned mda_is_ignored(struct metadata_area *mda);
void mda_set_ignored(struct metadata_area *mda, int value);