1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-01-02 01:18:26 +03:00

Set PV size to current device size if it is found to be zero.

This commit is contained in:
Alasdair Kergon 2006-10-19 12:53:47 +00:00
parent 7c5ec12630
commit b16b9c2bf1
5 changed files with 49 additions and 6 deletions

View File

@ -1,5 +1,6 @@
Version 2.02.13 - Version 2.02.13 -
=================================== ===================================
Set PV size to current device size if it is found to be zero.
Add segment parameter to target_present functions. Add segment parameter to target_present functions.
Version 2.02.12 - 16th October 2006 Version 2.02.12 - 16th October 2006

View File

@ -203,8 +203,8 @@ int write_disks(const struct format_type *fmt, struct list *pvds);
* Functions to translate to between disk and in * Functions to translate to between disk and in
* core structures. * core structures.
*/ */
int import_pv(struct dm_pool *mem, struct device *dev, int import_pv(const struct format_type *fmt, struct dm_pool *mem,
struct volume_group *vg, struct device *dev, struct volume_group *vg,
struct physical_volume *pv, struct pv_disk *pvd, struct physical_volume *pv, struct pv_disk *pvd,
struct vg_disk *vgd); struct vg_disk *vgd);
int export_pv(struct cmd_context *cmd, struct dm_pool *mem, int export_pv(struct cmd_context *cmd, struct dm_pool *mem,

View File

@ -312,7 +312,7 @@ static int _format1_pv_read(const struct format_type *fmt, const char *pv_name,
goto out; goto out;
} }
if (!import_pv(fmt->cmd->mem, dl->dev, NULL, pv, &dl->pvd, &dl->vgd)) { if (!import_pv(fmt, fmt->cmd->mem, dl->dev, NULL, pv, &dl->pvd, &dl->vgd)) {
stack; stack;
goto out; goto out;
} }

View File

@ -24,6 +24,7 @@
#include "toolcontext.h" #include "toolcontext.h"
#include "segtype.h" #include "segtype.h"
#include "pv_alloc.h" #include "pv_alloc.h"
#include "display.h"
#include <time.h> #include <time.h>
@ -47,11 +48,13 @@ static char *_create_lv_name(struct dm_pool *mem, const char *full_name)
return dm_pool_strdup(mem, ptr); return dm_pool_strdup(mem, ptr);
} }
int import_pv(struct dm_pool *mem, struct device *dev, int import_pv(const struct format_type *fmt, struct dm_pool *mem,
struct volume_group *vg, struct device *dev, struct volume_group *vg,
struct physical_volume *pv, struct pv_disk *pvd, struct physical_volume *pv, struct pv_disk *pvd,
struct vg_disk *vgd) struct vg_disk *vgd)
{ {
uint64_t size;
memset(pv, 0, sizeof(*pv)); memset(pv, 0, sizeof(*pv));
memcpy(&pv->id, pvd->pv_uuid, ID_LEN); memcpy(&pv->id, pvd->pv_uuid, ID_LEN);
@ -89,6 +92,25 @@ int import_pv(struct dm_pool *mem, struct device *dev,
pv->pe_count = pvd->pe_total; pv->pe_count = pvd->pe_total;
pv->pe_alloc_count = 0; pv->pe_alloc_count = 0;
/* Fix up pv size if missing */
if (!pv->size) {
if (!dev_get_size(dev, &pv->size)) {
log_error("%s: Couldn't get size.", dev_name(pv->dev));
return 0;
}
log_verbose("Fixing up missing format1 size (%s) "
"for PV %s", display_size(fmt->cmd, pv->size),
dev_name(pv->dev));
if (vg) {
size = pv->pe_count * (uint64_t) vg->extent_size +
pv->pe_start;
if (size > pv->size)
log_error("WARNING: Physical Volume %s is too "
"large for underlying device",
dev_name(pv->dev));
}
}
list_init(&pv->tags); list_init(&pv->tags);
list_init(&pv->segments); list_init(&pv->segments);
@ -427,7 +449,7 @@ int import_pvs(const struct format_type *fmt, struct dm_pool *mem,
return 0; return 0;
} }
if (!import_pv(mem, dl->dev, vg, pvl->pv, &dl->pvd, &dl->vgd)) { if (!import_pv(fmt, mem, dl->dev, vg, pvl->pv, &dl->pvd, &dl->vgd)) {
stack; stack;
return 0; return 0;
} }

View File

@ -116,6 +116,7 @@ static int _read_pv(struct format_instance *fid, struct dm_pool *mem,
struct physical_volume *pv; struct physical_volume *pv;
struct pv_list *pvl; struct pv_list *pvl;
struct config_node *cn; struct config_node *cn;
uint64_t size;
if (!(pvl = dm_pool_zalloc(mem, sizeof(*pvl))) || if (!(pvl = dm_pool_zalloc(mem, sizeof(*pvl))) ||
!(pvl->pv = dm_pool_zalloc(mem, sizeof(*pvl->pv)))) { !(pvl->pv = dm_pool_zalloc(mem, sizeof(*pvl->pv)))) {
@ -213,6 +214,25 @@ static int _read_pv(struct format_instance *fid, struct dm_pool *mem,
pv->pe_alloc_count = 0; pv->pe_alloc_count = 0;
pv->fmt = fid->fmt; pv->fmt = fid->fmt;
/* Fix up pv size if missing */
if (!pv->size && pv->dev) {
if (!dev_get_size(pv->dev, &pv->size)) {
log_error("%s: Couldn't get size.", dev_name(pv->dev));
return 0;
}
log_verbose("Fixing up missing format1 size (%s) "
"for PV %s", display_size(fid->fmt->cmd, pv->size),
dev_name(pv->dev));
if (vg) {
size = pv->pe_count * (uint64_t) vg->extent_size +
pv->pe_start;
if (size > pv->size)
log_error("WARNING: Physical Volume %s is too "
"large for underlying device",
dev_name(pv->dev));
}
}
if (!alloc_pv_segment_whole_pv(mem, pv)) { if (!alloc_pv_segment_whole_pv(mem, pv)) {
stack; stack;
return 0; return 0;