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

cleanup: use struct pvcreate_restorable_params throughout

This commit is contained in:
Peter Rajnoha 2013-02-18 12:47:31 +01:00
parent 6692b17777
commit 6d8de3638c
8 changed files with 51 additions and 56 deletions

View File

@ -339,11 +339,9 @@ static int _format1_pv_read(const struct format_type *fmt, const char *pv_name,
static int _format1_pv_initialise(const struct format_type * fmt,
int64_t label_sector __attribute__((unused)),
uint64_t pe_start,
uint32_t extent_count,
uint32_t extent_size,
unsigned long data_alignment __attribute__((unused)),
unsigned long data_alignment_offset __attribute__((unused)),
struct pvcreate_restorable_params *rp,
struct physical_volume * pv)
{
if (pv->size > MAX_PV_SIZE)
@ -355,18 +353,18 @@ static int _format1_pv_initialise(const struct format_type * fmt,
}
/* Nothing more to do if extent size isn't provided */
if (!extent_size)
if (!rp->extent_size)
return 1;
/*
* This works out pe_start and pe_count.
*/
if (!calculate_extent_count(pv, extent_size, extent_count, pe_start))
if (!calculate_extent_count(pv, rp->extent_size, rp->extent_count, rp->pe_start))
return_0;
/* Retain existing extent locations exactly */
if (((pe_start || extent_count) && (pe_start != pv->pe_start)) ||
(extent_count && (extent_count != pv->pe_count))) {
if (((rp->pe_start || rp->extent_count) && (rp->pe_start != pv->pe_start)) ||
(rp->extent_count && (rp->extent_count != pv->pe_count))) {
log_error("Metadata would overwrite physical extents");
return 0;
}
@ -378,7 +376,14 @@ static int _format1_pv_setup(const struct format_type *fmt,
struct physical_volume *pv,
struct volume_group *vg)
{
return _format1_pv_initialise(fmt, -1, 0, 0, vg->extent_size, 0, 0, pv);
struct pvcreate_restorable_params rp = {.restorefile = NULL,
.id = {{0}},
.idp = NULL,
.pe_start = 0,
.extent_count = 0,
.extent_size = vg->extent_size};
return _format1_pv_initialise(fmt, -1, 0, 0, &rp, pv);
}
static int _format1_lv_setup(struct format_instance *fid, struct logical_volume *lv)

View File

@ -165,11 +165,9 @@ bad:
static int _pool_pv_initialise(const struct format_type *fmt __attribute__((unused)),
int64_t label_sector __attribute__((unused)),
uint64_t pe_start __attribute__((unused)),
uint32_t extent_count __attribute__((unused)),
uint32_t extent_size __attribute__((unused)),
unsigned long data_alignment __attribute__((unused)),
unsigned long data_alignment_offset __attribute__((unused)),
struct pvcreate_restorable_params *rp __attribute__((unused)),
struct physical_volume *pv __attribute__((unused)))
{
return 1;

View File

@ -1466,19 +1466,17 @@ static int _text_pv_read(const struct format_type *fmt, const char *pv_name,
static int _text_pv_initialise(const struct format_type *fmt,
const int64_t label_sector,
uint64_t pe_start,
uint32_t extent_count,
uint32_t extent_size,
unsigned long data_alignment,
unsigned long data_alignment_offset,
struct pvcreate_restorable_params *rp,
struct physical_volume *pv)
{
/*
* Try to keep the value of PE start set to a firm value if requested.
* This is usefull when restoring existing PE start value (backups etc.).
*/
if (pe_start != PV_PE_START_CALC)
pv->pe_start = pe_start;
if (rp->pe_start != PV_PE_START_CALC)
pv->pe_start = rp->pe_start;
if (!data_alignment)
data_alignment = find_config_tree_int(pv->fmt->cmd,
@ -1514,14 +1512,14 @@ static int _text_pv_initialise(const struct format_type *fmt,
return 0;
}
if (pe_start == PV_PE_START_CALC)
if (rp->pe_start == PV_PE_START_CALC)
pv->pe_start = pv->pe_align + pv->pe_align_offset;
if (extent_size)
pv->pe_size = extent_size;
if (rp->extent_size)
pv->pe_size = rp->extent_size;
if (extent_count)
pv->pe_count = extent_count;
if (rp->extent_count)
pv->pe_count = rp->extent_count;
if ((pv->pe_start + pv->pe_count * pv->pe_size - 1) > (pv->size << SECTOR_SHIFT)) {
log_error("Physical extents end beyond end of device %s.",

View File

@ -391,6 +391,8 @@ struct lv_list {
struct logical_volume *lv;
};
#define PV_PE_START_CALC ((uint64_t) -1) /* Calculate pe_start value */
struct pvcreate_restorable_params {
const char *restorefile; /* 0 if no --restorefile option */
struct id id; /* FIXME: redundant */
@ -477,17 +479,14 @@ uint32_t vg_read_error(struct volume_group *vg_handle);
* areas can avoid overlap */
struct physical_volume *pv_create(const struct cmd_context *cmd,
struct device *dev,
struct id *id,
uint64_t size,
unsigned long data_alignment,
unsigned long data_alignment_offset,
uint64_t pe_start,
uint32_t existing_extent_count,
uint32_t existing_extent_size,
uint64_t label_sector,
unsigned pvmetadatacopies,
uint64_t pvmetadatasize,
unsigned metadataignore);
unsigned metadataignore,
struct pvcreate_restorable_params *rp);
int pv_resize(struct physical_volume *pv, struct volume_group *vg,
uint64_t size);
int pv_analyze(struct cmd_context *cmd, const char *pv_name,

View File

@ -1430,7 +1430,7 @@ void pvcreate_params_set_defaults(struct pvcreate_params *pp)
pp->metadataignore = DEFAULT_PVMETADATAIGNORE;
pp->rp.restorefile = 0;
pp->rp.idp = 0;
pp->rp.pe_start = 0;
pp->rp.pe_start = PV_PE_START_CALC;
pp->rp.extent_count = 0;
pp->rp.extent_size = 0;
}
@ -1530,12 +1530,10 @@ struct physical_volume * pvcreate_single(struct cmd_context *cmd,
dm_list_init(&mdas);
if (!(pv = pv_create(cmd, dev, pp->rp.idp, pp->size,
pp->data_alignment, pp->data_alignment_offset,
pp->rp.pe_start ? pp->rp.pe_start : PV_PE_START_CALC,
pp->rp.extent_count, pp->rp.extent_size,
pp->labelsector, pp->pvmetadatacopies,
pp->pvmetadatasize, pp->metadataignore))) {
if (!(pv = pv_create(cmd, dev, pp->size, pp->data_alignment,
pp->data_alignment_offset, pp->labelsector,
pp->pvmetadatacopies, pp->pvmetadatasize,
pp->metadataignore, &pp->rp))) {
log_error("Failed to setup physical volume \"%s\"", pv_name);
goto bad;
}
@ -1602,16 +1600,14 @@ static struct physical_volume *_alloc_pv(struct dm_pool *mem, struct device *dev
*/
struct physical_volume *pv_create(const struct cmd_context *cmd,
struct device *dev,
struct id *id, uint64_t size,
uint64_t size,
unsigned long data_alignment,
unsigned long data_alignment_offset,
uint64_t pe_start,
uint32_t existing_extent_count,
uint32_t existing_extent_size,
uint64_t label_sector,
unsigned pvmetadatacopies,
uint64_t pvmetadatasize,
unsigned metadataignore)
unsigned metadataignore,
struct pvcreate_restorable_params *rp)
{
const struct format_type *fmt = cmd->fmt;
struct dm_pool *mem = fmt->orphan_vg->vgmem;
@ -1622,8 +1618,8 @@ struct physical_volume *pv_create(const struct cmd_context *cmd,
if (!pv)
return_NULL;
if (id)
memcpy(&pv->id, id, sizeof(*id));
if (rp->idp)
memcpy(&pv->id, rp->idp, sizeof(*rp->idp));
else if (!id_create(&pv->id)) {
log_error("Failed to create random uuid for %s.",
dev_name(dev));
@ -1669,9 +1665,8 @@ struct physical_volume *pv_create(const struct cmd_context *cmd,
pv->fmt = fmt;
pv->vg_name = fmt->orphan_vg_name;
if (!fmt->ops->pv_initialise(fmt, label_sector, pe_start,
existing_extent_count, existing_extent_size,
data_alignment, data_alignment_offset, pv)) {
if (!fmt->ops->pv_initialise(fmt, label_sector, data_alignment,
data_alignment_offset, rp, pv)) {
log_error("Format-specific initialisation of physical "
"volume %s failed.", pv_dev_name(pv));
goto bad;
@ -1680,7 +1675,7 @@ struct physical_volume *pv_create(const struct cmd_context *cmd,
for (mda_index = 0; mda_index < pvmetadatacopies; mda_index++) {
if (pv->fmt->ops->pv_add_metadata_area &&
!pv->fmt->ops->pv_add_metadata_area(pv->fmt, pv,
pe_start != PV_PE_START_CALC,
rp->pe_start != PV_PE_START_CALC,
mda_index, pvmetadatasize,
metadataignore)) {
log_error("Failed to add metadata area for "

View File

@ -35,7 +35,6 @@
//#define MAX_RESTRICTED_LVS 255 /* Used by FMT_RESTRICTED_LVIDS */
#define MIRROR_LOG_OFFSET 2 /* sectors */
#define VG_MEMPOOL_CHUNK 10240 /* in bytes, hint only */
#define PV_PE_START_CALC ((uint64_t) -1) /* Calculate pe_start value */
/*
* Ceiling(n / sz)
@ -251,11 +250,9 @@ struct format_handler {
*/
int (*pv_initialise) (const struct format_type * fmt,
int64_t label_sector,
uint64_t pe_start,
uint32_t extent_count,
uint32_t extent_size,
unsigned long data_alignment,
unsigned long data_alignment_offset,
struct pvcreate_restorable_params *rp,
struct physical_volume * pv);
/*

View File

@ -1451,7 +1451,7 @@ int pvcreate_params_validate(struct cmd_context *cmd,
return 0;
}
if (pp->data_alignment && pp->rp.pe_start) {
if (pp->data_alignment && pp->rp.pe_start != PV_PE_START_CALC) {
if (pp->rp.pe_start % pp->data_alignment)
log_warn("WARNING: Ignoring data alignment %" PRIu64
" incompatible with --restorefile value (%"
@ -1470,7 +1470,7 @@ int pvcreate_params_validate(struct cmd_context *cmd,
return 0;
}
if (pp->data_alignment_offset && pp->rp.pe_start) {
if (pp->data_alignment_offset && pp->rp.pe_start != PV_PE_START_CALC) {
log_warn("WARNING: Ignoring data alignment offset %" PRIu64
" incompatible with --restorefile value (%"
PRIu64").", pp->data_alignment_offset, pp->rp.pe_start);

View File

@ -20,11 +20,11 @@ static int vgconvert_single(struct cmd_context *cmd, const char *vg_name,
void *handle __attribute__((unused)))
{
struct physical_volume *pv, *existing_pv;
struct pvcreate_restorable_params rp;
struct logical_volume *lv;
struct lv_list *lvl;
int pvmetadatacopies = 0;
uint64_t pvmetadatasize = 0;
uint64_t pe_start = 0;
struct pv_list *pvl;
int change_made = 0;
struct lvinfo info;
@ -116,16 +116,19 @@ static int vgconvert_single(struct cmd_context *cmd, const char *vg_name,
dm_list_iterate_items(pvl, &vg->pvs) {
existing_pv = pvl->pv;
pe_start = pv_pe_start(existing_pv);
rp.id = existing_pv->id;
rp.idp = &rp.id;
rp.pe_start = pv_pe_start(existing_pv);
rp.extent_count = pv_pe_count(existing_pv);
rp.extent_size = pv_pe_size(existing_pv);
/* pe_end = pv_pe_count(existing_pv) * pv_pe_size(existing_pv) + pe_start - 1; */
if (!(pv = pv_create(cmd, pv_dev(existing_pv),
&existing_pv->id, 0, 0, 0,
pe_start, pv_pe_count(existing_pv),
pv_pe_size(existing_pv),
0, 0, 0,
arg_int64_value(cmd, labelsector_ARG,
DEFAULT_LABELSECTOR),
pvmetadatacopies, pvmetadatasize, 0))) {
pvmetadatacopies, pvmetadatasize, 0, &rp))) {
log_error("Failed to setup physical volume \"%s\"",
pv_dev_name(existing_pv));
if (change_made)