mirror of
git://sourceware.org/git/lvm2.git
synced 2025-02-24 17:57:48 +03:00
indent
This commit is contained in:
parent
ebae1dc0c6
commit
bb403f3361
@ -21,12 +21,11 @@
|
|||||||
#include <sys/file.h>
|
#include <sys/file.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
|
|
||||||
|
|
||||||
/* Arbitrary limits copied from format1/disk_rep.h */
|
/* Arbitrary limits copied from format1/disk_rep.h */
|
||||||
#define MAX_PV 256
|
#define MAX_PV 256
|
||||||
#define MAX_LV 256
|
#define MAX_LV 256
|
||||||
#define MAX_VG 99
|
#define MAX_VG 99
|
||||||
#define MAX_PV_SIZE ((uint32_t) -1) /* 2TB in sectors - 1 */
|
#define MAX_PV_SIZE ((uint32_t) -1) /* 2TB in sectors - 1 */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* NOTE: Currently there can be only one vg per file.
|
* NOTE: Currently there can be only one vg per file.
|
||||||
@ -59,7 +58,7 @@ static int _vg_setup(struct format_instance *fi, struct volume_group *vg)
|
|||||||
if (vg->max_lv >= MAX_LV)
|
if (vg->max_lv >= MAX_LV)
|
||||||
vg->max_lv = MAX_LV - 1;
|
vg->max_lv = MAX_LV - 1;
|
||||||
|
|
||||||
if (vg->max_pv >= MAX_PV)
|
if (vg->max_pv >= MAX_PV)
|
||||||
vg->max_pv = MAX_PV - 1;
|
vg->max_pv = MAX_PV - 1;
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
@ -70,7 +69,7 @@ static int _lv_setup(struct format_instance *fi, struct logical_volume *lv)
|
|||||||
uint64_t max_size = UINT_MAX;
|
uint64_t max_size = UINT_MAX;
|
||||||
|
|
||||||
if (lv->size > max_size) {
|
if (lv->size > max_size) {
|
||||||
char *dummy = display_size(max_size, SIZE_SHORT);
|
char *dummy = display_size(max_size, SIZE_SHORT);
|
||||||
log_error("logical volumes cannot be larger than %s", dummy);
|
log_error("logical volumes cannot be larger than %s", dummy);
|
||||||
dbg_free(dummy);
|
dbg_free(dummy);
|
||||||
return 0;
|
return 0;
|
||||||
@ -129,10 +128,10 @@ static int _vg_write(struct format_instance *fi, struct volume_group *vg)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!create_temp_name(temp_dir, temp_file, sizeof(temp_file), &fd)) {
|
if (!create_temp_name(temp_dir, temp_file, sizeof(temp_file), &fd)) {
|
||||||
log_err("Couldn't create temporary text file name.");
|
log_err("Couldn't create temporary text file name.");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(fp = fdopen(fd, "w"))) {
|
if (!(fp = fdopen(fd, "w"))) {
|
||||||
log_sys_error("fdopen", temp_file);
|
log_sys_error("fdopen", temp_file);
|
||||||
@ -162,7 +161,7 @@ static int _vg_write(struct format_instance *fi, struct volume_group *vg)
|
|||||||
|
|
||||||
static struct list *_get_vgs(struct format_instance *fi)
|
static struct list *_get_vgs(struct format_instance *fi)
|
||||||
{
|
{
|
||||||
struct text_c *tc = (struct text_c *) fi->private;
|
struct text_c *tc = (struct text_c *) fi->private;
|
||||||
struct list *names = pool_alloc(fi->cmd->mem, sizeof(*names));
|
struct list *names = pool_alloc(fi->cmd->mem, sizeof(*names));
|
||||||
struct name_list *nl;
|
struct name_list *nl;
|
||||||
struct volume_group *vg;
|
struct volume_group *vg;
|
||||||
@ -179,101 +178,101 @@ static struct list *_get_vgs(struct format_instance *fi)
|
|||||||
/* Determine the VG name from the file name */
|
/* Determine the VG name from the file name */
|
||||||
slash = rindex(tc->path, '/');
|
slash = rindex(tc->path, '/');
|
||||||
if (slash) {
|
if (slash) {
|
||||||
vgname = pool_alloc(fi->cmd->mem, strlen(slash));
|
vgname = pool_alloc(fi->cmd->mem, strlen(slash));
|
||||||
strcpy(vgname, slash+1);
|
strcpy(vgname, slash + 1);
|
||||||
}
|
} else {
|
||||||
else {
|
vgname = pool_alloc(fi->cmd->mem, strlen(tc->path) + 1);
|
||||||
vgname = pool_alloc(fi->cmd->mem, strlen(tc->path)+1);
|
strcpy(vgname, tc->path);
|
||||||
strcpy(vgname, tc->path);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
vg = _vg_read(fi, vgname);
|
vg = _vg_read(fi, vgname);
|
||||||
if (vg) {
|
if (vg) {
|
||||||
|
|
||||||
pool_free(fi->cmd->mem, vg);
|
pool_free(fi->cmd->mem, vg);
|
||||||
if (!(nl = pool_alloc(fi->cmd->mem, sizeof(*nl)))) {
|
if (!(nl = pool_alloc(fi->cmd->mem, sizeof(*nl)))) {
|
||||||
stack;
|
stack;
|
||||||
goto bad;
|
goto bad;
|
||||||
}
|
}
|
||||||
nl->name = vgname;
|
nl->name = vgname;
|
||||||
|
|
||||||
list_add(names, &nl->list);
|
list_add(names, &nl->list);
|
||||||
}
|
}
|
||||||
|
|
||||||
return names;
|
return names;
|
||||||
|
|
||||||
bad:
|
bad:
|
||||||
pool_free(fi->cmd->mem, names);
|
pool_free(fi->cmd->mem, names);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct list *_get_pvs(struct format_instance *fi)
|
static struct list *_get_pvs(struct format_instance *fi)
|
||||||
{
|
{
|
||||||
struct pv_list *pvl;
|
struct pv_list *pvl;
|
||||||
struct list *vgh;
|
struct list *vgh;
|
||||||
struct list *pvh;
|
struct list *pvh;
|
||||||
struct list *results = pool_alloc(fi->cmd->mem, sizeof(*results));
|
struct list *results = pool_alloc(fi->cmd->mem, sizeof(*results));
|
||||||
struct list *vgs = _get_vgs(fi);
|
struct list *vgs = _get_vgs(fi);
|
||||||
|
|
||||||
list_init(results);
|
list_init(results);
|
||||||
|
|
||||||
list_iterate(vgh, vgs) {
|
list_iterate(vgh, vgs) {
|
||||||
struct volume_group *vg;
|
struct volume_group *vg;
|
||||||
struct name_list *nl;
|
struct name_list *nl;
|
||||||
|
|
||||||
nl = list_item(vgh, struct name_list);
|
nl = list_item(vgh, struct name_list);
|
||||||
vg = _vg_read(fi, nl->name);
|
vg = _vg_read(fi, nl->name);
|
||||||
if (vg) {
|
if (vg) {
|
||||||
list_iterate(pvh, &vg->pvs) {
|
list_iterate(pvh, &vg->pvs) {
|
||||||
struct pv_list *vgpv = list_item(pvh, struct pv_list);
|
struct pv_list *vgpv =
|
||||||
|
list_item(pvh, struct pv_list);
|
||||||
|
|
||||||
pvl = pool_alloc(fi->cmd->mem, sizeof(*pvl));
|
pvl = pool_alloc(fi->cmd->mem, sizeof(*pvl));
|
||||||
if (!pvl) {
|
if (!pvl) {
|
||||||
stack;
|
stack;
|
||||||
goto bad;
|
goto bad;
|
||||||
}
|
}
|
||||||
/* ?? do we need to clone the pv structure...really? Nah. */
|
/* ?? do we need to clone the pv structure...really? Nah. */
|
||||||
pvl->pv = vgpv->pv;
|
pvl->pv = vgpv->pv;
|
||||||
list_add(results, &pvl->list);
|
list_add(results, &pvl->list);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return results;
|
return results;
|
||||||
|
|
||||||
bad:
|
bad:
|
||||||
pool_free(fi->cmd->mem, vgs);
|
pool_free(fi->cmd->mem, vgs);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int _pv_write(struct format_instance *fi, struct physical_volume *pv)
|
static int _pv_write(struct format_instance *fi, struct physical_volume *pv)
|
||||||
{
|
{
|
||||||
struct volume_group *vg;
|
struct volume_group *vg;
|
||||||
struct list *pvh;
|
struct list *pvh;
|
||||||
|
|
||||||
vg = _vg_read(fi, pv->vg_name);
|
vg = _vg_read(fi, pv->vg_name);
|
||||||
|
|
||||||
/* Find the PV in this VG */
|
/* Find the PV in this VG */
|
||||||
if (vg) {
|
if (vg) {
|
||||||
list_iterate(pvh, &vg->pvs) {
|
list_iterate(pvh, &vg->pvs) {
|
||||||
struct pv_list *vgpv = list_item(pvh, struct pv_list);
|
struct pv_list *vgpv = list_item(pvh, struct pv_list);
|
||||||
|
|
||||||
if (id_equal(&pv->id, &vgpv->pv->id)) {
|
if (id_equal(&pv->id, &vgpv->pv->id)) {
|
||||||
vgpv->pv->status = pv->status;
|
vgpv->pv->status = pv->status;
|
||||||
vgpv->pv->size = pv->size;
|
vgpv->pv->size = pv->size;
|
||||||
|
|
||||||
/* Not sure if it's worth doing these */
|
/* Not sure if it's worth doing these */
|
||||||
vgpv->pv->pe_size = pv->pe_size;
|
vgpv->pv->pe_size = pv->pe_size;
|
||||||
vgpv->pv->pe_count = pv->pe_count;
|
vgpv->pv->pe_count = pv->pe_count;
|
||||||
vgpv->pv->pe_start = pv->pe_start;
|
vgpv->pv->pe_start = pv->pe_start;
|
||||||
vgpv->pv->pe_allocated = pv->pe_allocated;
|
vgpv->pv->pe_allocated = pv->pe_allocated;
|
||||||
|
|
||||||
/* Write it back */
|
/* Write it back */
|
||||||
_vg_write(fi, vg);
|
_vg_write(fi, vg);
|
||||||
pool_free(fi->cmd->mem, vg);
|
pool_free(fi->cmd->mem, vg);
|
||||||
return 1;
|
return 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
pool_free(fi->cmd->mem, vg);
|
||||||
pool_free(fi->cmd->mem, vg);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Can't handle PVs not in a VG */
|
/* Can't handle PVs not in a VG */
|
||||||
@ -283,51 +282,55 @@ static int _pv_write(struct format_instance *fi, struct physical_volume *pv)
|
|||||||
static struct physical_volume *_pv_read(struct format_instance *fi,
|
static struct physical_volume *_pv_read(struct format_instance *fi,
|
||||||
const char *pv_name)
|
const char *pv_name)
|
||||||
{
|
{
|
||||||
struct list *vgs = _get_vgs(fi);
|
struct list *vgs = _get_vgs(fi);
|
||||||
struct list *vgh;
|
struct list *vgh;
|
||||||
struct list *pvh;
|
struct list *pvh;
|
||||||
struct physical_volume *pv;
|
struct physical_volume *pv;
|
||||||
|
|
||||||
/* Look for the PV */
|
/* Look for the PV */
|
||||||
list_iterate(vgh, vgs) {
|
list_iterate(vgh, vgs) {
|
||||||
struct volume_group *vg;
|
struct volume_group *vg;
|
||||||
struct name_list *nl;
|
struct name_list *nl;
|
||||||
|
|
||||||
nl = list_item(vgh, struct name_list);
|
nl = list_item(vgh, struct name_list);
|
||||||
vg = _vg_read(fi, nl->name);
|
vg = _vg_read(fi, nl->name);
|
||||||
if (vg) {
|
if (vg) {
|
||||||
list_iterate(pvh, &vg->pvs) {
|
list_iterate(pvh, &vg->pvs) {
|
||||||
struct pv_list *vgpv = list_item(pvh, struct pv_list);
|
struct pv_list *vgpv =
|
||||||
|
list_item(pvh, struct pv_list);
|
||||||
|
|
||||||
if (strcmp(dev_name(vgpv->pv->dev), pv_name) == 0) {
|
if (!strcmp(dev_name(vgpv->pv->dev), pv_name)) {
|
||||||
pv = pool_alloc(fi->cmd->mem, sizeof(*pv));
|
pv = pool_alloc(fi->cmd->mem,
|
||||||
if (!pv) {
|
sizeof(*pv));
|
||||||
stack;
|
if (!pv) {
|
||||||
pool_free(fi->cmd->mem, vg);
|
stack;
|
||||||
return NULL;
|
pool_free(fi->cmd->mem, vg);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
/* Memberwise copy */
|
||||||
|
*pv = *vgpv->pv;
|
||||||
|
|
||||||
|
pv->vg_name =
|
||||||
|
pool_alloc(fi->cmd->mem,
|
||||||
|
strlen(vgpv->pv->
|
||||||
|
vg_name) + 1);
|
||||||
|
if (!pv->vg_name) {
|
||||||
|
stack;
|
||||||
|
pool_free(fi->cmd->mem, vg);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
strcpy(pv->vg_name, vgpv->pv->vg_name);
|
||||||
|
pool_free(fi->cmd->mem, vg);
|
||||||
|
return pv;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/* Memberwise copy */
|
|
||||||
*pv = *vgpv->pv;
|
|
||||||
|
|
||||||
pv->vg_name = pool_alloc(fi->cmd->mem, strlen(vgpv->pv->vg_name)+1);
|
|
||||||
if (!pv->vg_name) {
|
|
||||||
stack;
|
|
||||||
pool_free(fi->cmd->mem, vg);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
strcpy(pv->vg_name, vgpv->pv->vg_name);
|
|
||||||
pool_free(fi->cmd->mem, vg);
|
pool_free(fi->cmd->mem, vg);
|
||||||
return pv;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
pool_free(fi->cmd->mem, vg);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void _destroy(struct format_instance *fi)
|
static void _destroy(struct format_instance *fi)
|
||||||
{
|
{
|
||||||
struct text_c *tc = (struct text_c *) fi->private;
|
struct text_c *tc = (struct text_c *) fi->private;
|
||||||
@ -339,16 +342,16 @@ static void _destroy(struct format_instance *fi)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static struct format_handler _text_handler = {
|
static struct format_handler _text_handler = {
|
||||||
get_vgs: _get_vgs,
|
get_vgs: _get_vgs,
|
||||||
get_pvs: _get_pvs,
|
get_pvs: _get_pvs,
|
||||||
pv_read: _pv_read,
|
pv_read: _pv_read,
|
||||||
pv_setup: _pv_setup,
|
pv_setup: _pv_setup,
|
||||||
pv_write: _pv_write,
|
pv_write: _pv_write,
|
||||||
vg_setup: _vg_setup,
|
vg_setup: _vg_setup,
|
||||||
lv_setup: _lv_setup,
|
lv_setup: _lv_setup,
|
||||||
vg_read: _vg_read,
|
vg_read: _vg_read,
|
||||||
vg_write: _vg_write,
|
vg_write: _vg_write,
|
||||||
destroy: _destroy
|
destroy: _destroy
|
||||||
};
|
};
|
||||||
|
|
||||||
struct format_instance *text_format_create(struct cmd_context *cmd,
|
struct format_instance *text_format_create(struct cmd_context *cmd,
|
||||||
@ -390,7 +393,7 @@ struct format_instance *text_format_create(struct cmd_context *cmd,
|
|||||||
|
|
||||||
return fi;
|
return fi;
|
||||||
|
|
||||||
no_mem:
|
no_mem:
|
||||||
if (fi)
|
if (fi)
|
||||||
dbg_free(fi);
|
dbg_free(fi);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user