mirror of
git://sourceware.org/git/lvm2.git
synced 2025-01-11 09:18:25 +03:00
Miscellaneous tidying
This commit is contained in:
parent
7c233c6c0c
commit
0b6d132759
@ -44,13 +44,14 @@ int dev_open(struct device *dev, int flags)
|
||||
{
|
||||
const char *name = dev_name(dev);
|
||||
|
||||
/* FIXME Check flags (eg is write now reqd?) */
|
||||
if (dev->fd >= 0) {
|
||||
log_err("Device '%s' has already been opened", name);
|
||||
log_error("Device '%s' has already been opened", name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ((dev->fd = open(name, flags)) < 0) {
|
||||
log_sys_error("open", "opening device");
|
||||
log_sys_error("open", name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -60,12 +61,14 @@ int dev_open(struct device *dev, int flags)
|
||||
int dev_close(struct device *dev)
|
||||
{
|
||||
if (dev->fd < 0) {
|
||||
log_err("Request to close device '%s', "
|
||||
"which has not been opened.", dev_name(dev));
|
||||
log_error("Attempt to close device '%s' "
|
||||
"which is not open.", dev_name(dev));
|
||||
return 0;
|
||||
}
|
||||
|
||||
close(dev->fd);
|
||||
if (close(dev->fd))
|
||||
log_sys_error("close", dev_name(dev));
|
||||
|
||||
dev->fd = -1;
|
||||
|
||||
return 1;
|
||||
@ -140,7 +143,7 @@ int64_t dev_write(struct device *dev, uint64_t offset,
|
||||
int fd = dev->fd;
|
||||
|
||||
if (fd < 0) {
|
||||
log_err("Attempt to write to an unopened device (%s).", name);
|
||||
log_error("Attempt to write to unopened device %s", name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -160,7 +163,8 @@ int dev_zero(struct device *dev, uint64_t offset, int64_t len)
|
||||
int fd = dev->fd;
|
||||
|
||||
if (fd < 0) {
|
||||
log_err("Attempt to zero an unopened device (%s).", name);
|
||||
log_error("Attempt to zero part of an unopened device %s",
|
||||
name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -411,7 +411,7 @@ static int _write_lvs(struct disk_list *data)
|
||||
pos = data->pvd.lv_on_disk.base;
|
||||
|
||||
if (!dev_zero(data->dev, pos, data->pvd.lv_on_disk.size)) {
|
||||
log_err("couldn't zero lv area on device '%s'",
|
||||
log_error("Couldn't zero lv area on device '%s'",
|
||||
dev_name(data->dev));
|
||||
return 0;
|
||||
}
|
||||
|
@ -184,7 +184,7 @@ struct disk_list *read_disk(struct device *dev, struct pool *mem,
|
||||
int read_pvs_in_vg(const char *vg_name, struct dev_filter *filter,
|
||||
struct pool *mem, struct list *results);
|
||||
|
||||
int write_disks(struct list *pvs);
|
||||
int write_disks(struct list *pvds);
|
||||
|
||||
|
||||
/*
|
||||
@ -202,31 +202,32 @@ int export_vg(struct vg_disk *vgd, struct volume_group *vg);
|
||||
int import_lv(struct pool *mem, struct logical_volume *lv,
|
||||
struct lv_disk *lvd);
|
||||
void export_lv(struct lv_disk *lvd, struct volume_group *vg,
|
||||
struct logical_volume *lv, const char *prefix);
|
||||
struct logical_volume *lv, const char *dev_dir);
|
||||
|
||||
int import_extents(struct pool *mem, struct volume_group *vg, struct list *pvs);
|
||||
int import_extents(struct pool *mem, struct volume_group *vg,
|
||||
struct list *pvds);
|
||||
int export_extents(struct disk_list *dl, int lv_num,
|
||||
struct logical_volume *lv,
|
||||
struct physical_volume *pv);
|
||||
|
||||
int import_pvs(struct pool *mem, struct list *pvs,
|
||||
int import_pvs(struct pool *mem, struct list *pvds,
|
||||
struct list *results, int *count);
|
||||
|
||||
int import_lvs(struct pool *mem, struct volume_group *vg,
|
||||
struct list *pvs);
|
||||
struct list *pvds);
|
||||
int export_lvs(struct disk_list *dl, struct volume_group *vg,
|
||||
struct physical_volume *pv, const char *prefix);
|
||||
struct physical_volume *pv, const char *dev_dir);
|
||||
|
||||
int export_uuids(struct disk_list *dl, struct volume_group *vg);
|
||||
|
||||
void export_numbers(struct list *pvs, struct volume_group *vg);
|
||||
void export_numbers(struct list *pvds, struct volume_group *vg);
|
||||
|
||||
void export_pv_act(struct list *pvs);
|
||||
void export_pv_act(struct list *pvds);
|
||||
|
||||
/* blech */
|
||||
int get_free_vg_number(struct dev_filter *filter, const char *candidate_vg,
|
||||
int *result);
|
||||
int export_vg_number(struct list *pvs, const char *vg_name,
|
||||
int export_vg_number(struct list *pvds, const char *vg_name,
|
||||
struct dev_filter *filter);
|
||||
|
||||
|
||||
|
@ -100,7 +100,7 @@ static struct volume_group *_vg_read(struct format_instance *fi,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Strip prefix if present */
|
||||
/* Strip dev_dir if present */
|
||||
vg_name = strip_dir(vg_name, fi->cmd->dev_dir);
|
||||
|
||||
if (!read_pvs_in_vg(vg_name, fi->cmd->filter, mem, &pvs)) {
|
||||
@ -122,7 +122,7 @@ static struct volume_group *_vg_read(struct format_instance *fi,
|
||||
|
||||
static struct disk_list *_flatten_pv(struct pool *mem, struct volume_group *vg,
|
||||
struct physical_volume *pv,
|
||||
const char *prefix)
|
||||
const char *dev_dir)
|
||||
{
|
||||
struct disk_list *dl = pool_alloc(mem, sizeof(*dl));
|
||||
|
||||
@ -140,7 +140,7 @@ static struct disk_list *_flatten_pv(struct pool *mem, struct volume_group *vg,
|
||||
if (!export_pv(&dl->pvd, pv) ||
|
||||
!export_vg(&dl->vgd, vg) ||
|
||||
!export_uuids(dl, vg) ||
|
||||
!export_lvs(dl, vg, pv, prefix) ||
|
||||
!export_lvs(dl, vg, pv, dev_dir) ||
|
||||
!calculate_layout(dl)) {
|
||||
stack;
|
||||
pool_free(mem, dl);
|
||||
@ -151,7 +151,7 @@ static struct disk_list *_flatten_pv(struct pool *mem, struct volume_group *vg,
|
||||
}
|
||||
|
||||
static int _flatten_vg(struct pool *mem, struct volume_group *vg,
|
||||
struct list *pvs, const char *prefix,
|
||||
struct list *pvds, const char *dev_dir,
|
||||
struct dev_filter *filter)
|
||||
{
|
||||
struct list *pvh;
|
||||
@ -161,18 +161,18 @@ static int _flatten_vg(struct pool *mem, struct volume_group *vg,
|
||||
list_iterate(pvh, &vg->pvs) {
|
||||
pvl = list_item(pvh, struct pv_list);
|
||||
|
||||
if (!(data = _flatten_pv(mem, vg, &pvl->pv, prefix))) {
|
||||
if (!(data = _flatten_pv(mem, vg, &pvl->pv, dev_dir))) {
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
|
||||
list_add(pvs, &data->list);
|
||||
list_add(pvds, &data->list);
|
||||
}
|
||||
|
||||
export_numbers(pvs, vg);
|
||||
export_pv_act(pvs);
|
||||
export_numbers(pvds, vg);
|
||||
export_pv_act(pvds);
|
||||
|
||||
if (!export_vg_number(pvs, vg->name, filter)) {
|
||||
if (!export_vg_number(pvds, vg->name, filter)) {
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
@ -183,7 +183,7 @@ static int _flatten_vg(struct pool *mem, struct volume_group *vg,
|
||||
static int _vg_write(struct format_instance *fi, struct volume_group *vg)
|
||||
{
|
||||
struct pool *mem = pool_create(1024 * 10);
|
||||
struct list pvs;
|
||||
struct list pvds;
|
||||
int r = 0;
|
||||
|
||||
if (!mem) {
|
||||
@ -191,10 +191,10 @@ static int _vg_write(struct format_instance *fi, struct volume_group *vg)
|
||||
return 0;
|
||||
}
|
||||
|
||||
list_init(&pvs);
|
||||
list_init(&pvds);
|
||||
|
||||
r = (_flatten_vg(mem, vg, &pvs, fi->cmd->dev_dir, fi->cmd->filter) &&
|
||||
write_disks(&pvs));
|
||||
r = (_flatten_vg(mem, vg, &pvds, fi->cmd->dev_dir, fi->cmd->filter) &&
|
||||
write_disks(&pvds));
|
||||
pool_destroy(mem);
|
||||
return r;
|
||||
}
|
||||
|
@ -279,11 +279,11 @@ int import_lv(struct pool *mem, struct logical_volume *lv, struct lv_disk *lvd)
|
||||
}
|
||||
|
||||
void export_lv(struct lv_disk *lvd, struct volume_group *vg,
|
||||
struct logical_volume *lv, const char *prefix)
|
||||
struct logical_volume *lv, const char *dev_dir)
|
||||
{
|
||||
memset(lvd, 0, sizeof(*lvd));
|
||||
snprintf(lvd->lv_name, sizeof(lvd->lv_name), "%s%s/%s",
|
||||
prefix, vg->name, lv->name);
|
||||
dev_dir, vg->name, lv->name);
|
||||
|
||||
/* FIXME: Add 'if' test */
|
||||
_check_vg_name(vg->name);
|
||||
@ -323,7 +323,7 @@ void export_lv(struct lv_disk *lvd, struct volume_group *vg,
|
||||
lvd->lv_allocation |= LV_CONTIGUOUS;
|
||||
}
|
||||
|
||||
int import_extents(struct pool *mem, struct volume_group *vg, struct list *pvs)
|
||||
int import_extents(struct pool *mem, struct volume_group *vg, struct list *pvds)
|
||||
{
|
||||
struct disk_list *dl;
|
||||
struct logical_volume *lv, *lvs[MAX_LV];
|
||||
@ -331,10 +331,10 @@ int import_extents(struct pool *mem, struct volume_group *vg, struct list *pvs)
|
||||
struct pe_disk *e;
|
||||
int i;
|
||||
uint32_t lv_num, le;
|
||||
struct list *pvh;
|
||||
struct list *pvdh;
|
||||
|
||||
list_iterate(pvh, pvs) {
|
||||
dl = list_item(pvh, struct disk_list);
|
||||
list_iterate(pvdh, pvds) {
|
||||
dl = list_item(pvdh, struct disk_list);
|
||||
pv = _find_pv(vg, dl->dev);
|
||||
e = dl->extents;
|
||||
|
||||
@ -391,16 +391,16 @@ int export_extents(struct disk_list *dl, int lv_num,
|
||||
return 1;
|
||||
}
|
||||
|
||||
int import_pvs(struct pool *mem, struct list *pvs,
|
||||
int import_pvs(struct pool *mem, struct list *pvds,
|
||||
struct list *results, int *count)
|
||||
{
|
||||
struct list *pvh;
|
||||
struct list *pvdh;
|
||||
struct disk_list *dl;
|
||||
struct pv_list *pvl;
|
||||
|
||||
*count = 0;
|
||||
list_iterate(pvh, pvs) {
|
||||
dl = list_item(pvh, struct disk_list);
|
||||
list_iterate(pvdh, pvds) {
|
||||
dl = list_item(pvdh, struct disk_list);
|
||||
pvl = pool_alloc(mem, sizeof(*pvl));
|
||||
|
||||
if (!pvl) {
|
||||
@ -446,17 +446,17 @@ static struct logical_volume *_add_lv(struct pool *mem,
|
||||
}
|
||||
|
||||
int import_lvs(struct pool *mem, struct volume_group *vg,
|
||||
struct list *pvs)
|
||||
struct list *pvds)
|
||||
{
|
||||
struct disk_list *dl;
|
||||
struct lvd_list *ll;
|
||||
struct lv_disk *lvd;
|
||||
struct list *pvh, *lvh;
|
||||
struct list *pvdh, *lvdh;
|
||||
|
||||
list_iterate(pvh, pvs) {
|
||||
dl = list_item(pvh, struct disk_list);
|
||||
list_iterate(lvh, &dl->lvds) {
|
||||
ll = list_item(lvh, struct lvd_list);
|
||||
list_iterate(pvdh, pvds) {
|
||||
dl = list_item(pvdh, struct disk_list);
|
||||
list_iterate(lvdh, &dl->lvds) {
|
||||
ll = list_item(lvdh, struct lvd_list);
|
||||
lvd = &ll->lvd;
|
||||
|
||||
if (!find_lv(vg, lvd->lv_name) &&
|
||||
@ -471,7 +471,7 @@ int import_lvs(struct pool *mem, struct volume_group *vg,
|
||||
}
|
||||
|
||||
int export_lvs(struct disk_list *dl, struct volume_group *vg,
|
||||
struct physical_volume *pv, const char *prefix)
|
||||
struct physical_volume *pv, const char *dev_dir)
|
||||
{
|
||||
struct list *lvh;
|
||||
struct lv_list *ll;
|
||||
@ -496,7 +496,7 @@ int export_lvs(struct disk_list *dl, struct volume_group *vg,
|
||||
return 0;
|
||||
}
|
||||
|
||||
export_lv(&lvdl->lvd, vg, &ll->lv, prefix);
|
||||
export_lv(&lvdl->lvd, vg, &ll->lv, dev_dir);
|
||||
lvdl->lvd.lv_number = lv_num;
|
||||
if (!export_extents(dl, lv_num + 1, &ll->lv, pv)) {
|
||||
stack;
|
||||
@ -536,14 +536,14 @@ int export_uuids(struct disk_list *dl, struct volume_group *vg)
|
||||
* lv_number fields used by LVM1. Very
|
||||
* inefficient code.
|
||||
*/
|
||||
void export_numbers(struct list *pvs, struct volume_group *vg)
|
||||
void export_numbers(struct list *pvds, struct volume_group *vg)
|
||||
{
|
||||
struct list *pvh;
|
||||
struct list *pvdh;
|
||||
struct disk_list *dl;
|
||||
int pv_num = 1;
|
||||
|
||||
list_iterate(pvh, pvs) {
|
||||
dl = list_item(pvh, struct disk_list);
|
||||
list_iterate(pvdh, pvds) {
|
||||
dl = list_item(pvdh, struct disk_list);
|
||||
dl->pvd.pv_number = pv_num++;
|
||||
}
|
||||
}
|
||||
@ -551,28 +551,28 @@ void export_numbers(struct list *pvs, struct volume_group *vg)
|
||||
/*
|
||||
* Calculate vg_disk->pv_act.
|
||||
*/
|
||||
void export_pv_act(struct list *pvs)
|
||||
void export_pv_act(struct list *pvds)
|
||||
{
|
||||
struct list *pvh;
|
||||
struct list *pvdh;
|
||||
struct disk_list *dl;
|
||||
int act = 0;
|
||||
|
||||
list_iterate(pvh, pvs) {
|
||||
dl = list_item(pvh, struct disk_list);
|
||||
list_iterate(pvdh, pvds) {
|
||||
dl = list_item(pvdh, struct disk_list);
|
||||
if (dl->pvd.pv_status & PV_ACTIVE)
|
||||
act++;
|
||||
}
|
||||
|
||||
list_iterate(pvh, pvs) {
|
||||
dl = list_item(pvh, struct disk_list);
|
||||
list_iterate(pvdh, pvds) {
|
||||
dl = list_item(pvdh, struct disk_list);
|
||||
dl->vgd.pv_act = act;
|
||||
}
|
||||
}
|
||||
|
||||
int export_vg_number(struct list *pvs, const char *vg_name,
|
||||
int export_vg_number(struct list *pvds, const char *vg_name,
|
||||
struct dev_filter *filter)
|
||||
{
|
||||
struct list *pvh;
|
||||
struct list *pvdh;
|
||||
struct disk_list *dl;
|
||||
int vg_num;
|
||||
|
||||
@ -581,8 +581,8 @@ int export_vg_number(struct list *pvs, const char *vg_name,
|
||||
return 0;
|
||||
}
|
||||
|
||||
list_iterate(pvh, pvs) {
|
||||
dl = list_item(pvh, struct disk_list);
|
||||
list_iterate(pvdh, pvds) {
|
||||
dl = list_item(pvdh, struct disk_list);
|
||||
dl->vgd.vg_number = vg_num;
|
||||
}
|
||||
|
||||
|
@ -160,8 +160,8 @@ static int _allocate(struct volume_group *vg, struct logical_volume *lv,
|
||||
r = _alloc_simple(lv, pvms, allocated);
|
||||
|
||||
else {
|
||||
log_err("Unknown allocation policy, "
|
||||
"unable to setup logical volume.");
|
||||
log_error("Unknown allocation policy: "
|
||||
"unable to setup logical volume.");
|
||||
goto out;
|
||||
}
|
||||
|
||||
@ -179,7 +179,7 @@ static char *_make_up_lv_name(struct volume_group *vg,
|
||||
{
|
||||
struct list *lvh;
|
||||
struct logical_volume *lv;
|
||||
int high = 1, i;
|
||||
int high = 1, i, s;
|
||||
|
||||
list_iterate(lvh, &vg->lvs) {
|
||||
lv = &(list_item(lvh, struct lv_list)->lv);
|
||||
@ -191,7 +191,7 @@ static char *_make_up_lv_name(struct volume_group *vg,
|
||||
high = i + 1;
|
||||
}
|
||||
|
||||
if (snprintf(buffer, len, "lvol%d", high) < 0)
|
||||
if ((s = snprintf(buffer, len, "lvol%d", high)) < 0 || s >= len)
|
||||
return NULL;
|
||||
|
||||
return buffer;
|
||||
@ -212,14 +212,14 @@ struct logical_volume *lv_create(const char *name,
|
||||
int i;
|
||||
|
||||
if (!extents) {
|
||||
log_err("Unable to create logical volume %s with no extents",
|
||||
name);
|
||||
log_error("Unable to create logical volume %s with no extents",
|
||||
name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (vg->free_count < extents) {
|
||||
log_err("Insufficient free extents (%u) in volume group %s: "
|
||||
"%u required", vg->free_count, vg->name, extents);
|
||||
log_error("Insufficient free extents (%u) in volume group %s: "
|
||||
"%u required", vg->free_count, vg->name, extents);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -231,7 +231,8 @@ struct logical_volume *lv_create(const char *name,
|
||||
|
||||
if (!name &&
|
||||
!(name = _make_up_lv_name(vg, dname, sizeof(dname)))) {
|
||||
log_err("Unable to think of a name for logical volume.");
|
||||
log_error("Failed to generate unique name for the new "
|
||||
"logical volume");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -149,7 +149,7 @@ struct volume_group *vg_create(struct format_instance *fi, const char *vg_name,
|
||||
goto bad;
|
||||
}
|
||||
|
||||
/* Strip prefix if present */
|
||||
/* Strip dev_dir if present */
|
||||
vg_name = strip_dir(vg_name, fi->cmd->dev_dir);
|
||||
|
||||
if (!(vg->name = pool_strdup(mem, vg_name))) {
|
||||
|
@ -277,7 +277,7 @@ struct physical_volume *_find_pv(struct volume_group *vg, struct device *dev);
|
||||
struct logical_volume *find_lv(struct volume_group *vg, const char *lv_name);
|
||||
|
||||
/*
|
||||
* Remove a prefix directory if present.
|
||||
* Remove a dev_dir if present.
|
||||
*/
|
||||
const char *strip_dir(const char *vg_name, const char *dir);
|
||||
|
||||
|
@ -84,7 +84,7 @@ int lvcreate(int argc, char **argv)
|
||||
|
||||
/* If VG not on command line, try -n arg and then environment */
|
||||
if (!argc) {
|
||||
if (!lv_name || !(vg_name = extract_vgname(fid, lv_name))) {
|
||||
if (!(vg_name = extract_vgname(fid, lv_name))) {
|
||||
log_error("Please provide a volume group name");
|
||||
return EINVALID_CMD_LINE;
|
||||
}
|
||||
@ -236,7 +236,7 @@ int lvcreate(int argc, char **argv)
|
||||
if (!lv_activate(lv))
|
||||
return ECMD_FAILED;
|
||||
|
||||
if (0) {
|
||||
if (zero) {
|
||||
struct device *dev;
|
||||
/* FIXME 2 blocks */
|
||||
char buf[4096];
|
||||
@ -245,13 +245,16 @@ int lvcreate(int argc, char **argv)
|
||||
|
||||
log_verbose("Zeroing start of logical volume %s", lv->name);
|
||||
|
||||
/* FIXME get dev = dev_cache_get(lv_name, fid->cmd->filter); */
|
||||
log_print("WARNING: %s not zeroed", lv->name);
|
||||
/* FIXME get dev = dev_cache_get(lv->name, fid->cmd->filter); */
|
||||
/* FIXME Add fsync! */
|
||||
/******** FIXME Really zero it
|
||||
if (!(dev_write(dev, 0, sizeof(buf), &buf) == sizeof(buf))) {
|
||||
log_error("Initialisation of %s failed",
|
||||
dev_name(dev));
|
||||
return ECMD_FAILED;
|
||||
}
|
||||
**************/
|
||||
} else
|
||||
log_print("WARNING: %s not zeroed", lv->name);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user