mirror of
git://sourceware.org/git/lvm2.git
synced 2025-01-04 09:18:36 +03:00
o Added lvs_in_vgs_opened
This commit is contained in:
parent
801495c0f7
commit
2ba80b436f
@ -15,7 +15,7 @@ static void _build_lv_name(char *buffer, size_t s, struct logical_volume *lv)
|
|||||||
snprintf(buffer, s, "%s_%s", lv->vg->name, lv->name);
|
snprintf(buffer, s, "%s_%s", lv->vg->name, lv->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct dm_task *_setup_task(struct logical_volume *lv, int task)
|
static struct dm_task *_setup_task(struct logical_volume *lv, int task)
|
||||||
{
|
{
|
||||||
char name[128];
|
char name[128];
|
||||||
struct dm_task *dmt;
|
struct dm_task *dmt;
|
||||||
@ -31,9 +31,8 @@ struct dm_task *_setup_task(struct logical_volume *lv, int task)
|
|||||||
return dmt;
|
return dmt;
|
||||||
}
|
}
|
||||||
|
|
||||||
int lv_active(struct logical_volume *lv, int *result)
|
static struct dm_task *_info(struct logical_volume *lv)
|
||||||
{
|
{
|
||||||
int r = 0;
|
|
||||||
struct dm_task *dmt;
|
struct dm_task *dmt;
|
||||||
|
|
||||||
if (!(dmt = _setup_task(lv, DM_DEVICE_INFO))) {
|
if (!(dmt = _setup_task(lv, DM_DEVICE_INFO))) {
|
||||||
@ -42,6 +41,23 @@ int lv_active(struct logical_volume *lv, int *result)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!dm_task_run(dmt)) {
|
if (!dm_task_run(dmt)) {
|
||||||
|
stack;
|
||||||
|
goto bad;
|
||||||
|
}
|
||||||
|
|
||||||
|
return dmt;
|
||||||
|
|
||||||
|
bad:
|
||||||
|
dm_task_destroy(dmt);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
int lv_active(struct logical_volume *lv, int *result)
|
||||||
|
{
|
||||||
|
int r = 0;
|
||||||
|
struct dm_task *dmt;
|
||||||
|
|
||||||
|
if (!(dmt = _info(lv))) {
|
||||||
stack;
|
stack;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
@ -58,6 +74,28 @@ int lv_active(struct logical_volume *lv, int *result)
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int lv_open_count(struct logical_volume *lv, int *result)
|
||||||
|
{
|
||||||
|
int r = 0;
|
||||||
|
struct dm_task *dmt;
|
||||||
|
|
||||||
|
if (!(dmt = _info(lv))) {
|
||||||
|
stack;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!dm_task_open_count(dmt, result)) {
|
||||||
|
stack;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
r = 1;
|
||||||
|
|
||||||
|
out:
|
||||||
|
dm_task_destroy(dmt);
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Creates a target for the next contiguous run of
|
* Creates a target for the next contiguous run of
|
||||||
* extents.
|
* extents.
|
||||||
@ -220,7 +258,7 @@ int deactivate_lvs_in_vg(struct volume_group *vg)
|
|||||||
list_iterate(lvh, &vg->lvs) {
|
list_iterate(lvh, &vg->lvs) {
|
||||||
lv = &(list_item(lvh, struct lv_list)->lv);
|
lv = &(list_item(lvh, struct lv_list)->lv);
|
||||||
|
|
||||||
if (!lv_active(lv, &exists) || exists)
|
if (!lv_active(lv, &exists) || !exists)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
count += lv_activate(lv);
|
count += lv_activate(lv);
|
||||||
@ -248,3 +286,24 @@ int lvs_in_vg_activated(struct volume_group *vg)
|
|||||||
|
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int lvs_in_vg_opened(struct volume_group *vg)
|
||||||
|
{
|
||||||
|
struct list *lvh;
|
||||||
|
struct logical_volume *lv;
|
||||||
|
int open, count = 0;
|
||||||
|
|
||||||
|
list_iterate(lvh, &vg->lvs) {
|
||||||
|
lv = &(list_item(lvh, struct lv_list)->lv);
|
||||||
|
|
||||||
|
if (!lv_open_count(lv, &open)) {
|
||||||
|
stack;
|
||||||
|
continue; /* FIXME: what is the right thing here ? */
|
||||||
|
}
|
||||||
|
|
||||||
|
count += open ? 1 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -10,15 +10,18 @@
|
|||||||
/* FIXME Snapshot handling? */
|
/* FIXME Snapshot handling? */
|
||||||
|
|
||||||
int lv_active(struct logical_volume *lv, int *result);
|
int lv_active(struct logical_volume *lv, int *result);
|
||||||
|
int lv_open_count(struct logical_volume *lv, int *result);
|
||||||
|
|
||||||
int lv_activate(struct logical_volume *lv);
|
int lv_activate(struct logical_volume *lv);
|
||||||
int lv_reactivate(struct logical_volume *lv);
|
int lv_reactivate(struct logical_volume *lv);
|
||||||
int lv_deactivate(struct logical_volume *lv);
|
int lv_deactivate(struct logical_volume *lv);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Return number of LVs in the VG that are
|
* Return number of LVs in the VG that are
|
||||||
* active
|
* active.
|
||||||
*/
|
*/
|
||||||
int lvs_in_vg_activated(struct volume_group *vg);
|
int lvs_in_vg_activated(struct volume_group *vg);
|
||||||
|
int lvs_in_vg_opened(struct volume_group *vg);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Test for (lv->status & LVM_WRITE)
|
* Test for (lv->status & LVM_WRITE)
|
||||||
|
@ -355,6 +355,12 @@ int import_extents(struct pool *mem, struct volume_group *vg, struct list *pvs)
|
|||||||
lv = lvs[lv_num];
|
lv = lvs[lv_num];
|
||||||
le = e[i].le_num;
|
le = e[i].le_num;
|
||||||
|
|
||||||
|
if (le >= lv->le_count) {
|
||||||
|
log_err("logical extent number "
|
||||||
|
"out of bounds");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
lv->map[le].pv = pv;
|
lv->map[le].pv = pv;
|
||||||
lv->map[le].pe = i;
|
lv->map[le].pe = i;
|
||||||
}
|
}
|
||||||
|
@ -65,7 +65,7 @@ void print_log(int level, const char *file, int line, const char *format, ...)
|
|||||||
#define log_err(x...) plog(_LOG_ERR, x)
|
#define log_err(x...) plog(_LOG_ERR, x)
|
||||||
#define log_fatal(x...) plog(_LOG_FATAL, x)
|
#define log_fatal(x...) plog(_LOG_FATAL, x)
|
||||||
|
|
||||||
#define stack log_debug( "s" )
|
#define stack log_debug("stack")
|
||||||
|
|
||||||
#define log_error(fmt, args...) log_err(fmt , ## args)
|
#define log_error(fmt, args...) log_err(fmt , ## args)
|
||||||
#define log_print(fmt, args...) log_warn(fmt , ## args)
|
#define log_print(fmt, args...) log_warn(fmt , ## args)
|
||||||
|
@ -289,7 +289,7 @@ int lv_extend(struct io_space *ios,
|
|||||||
new_lv->map = new_map;
|
new_lv->map = new_map;
|
||||||
new_lv->le_count += extents;
|
new_lv->le_count += extents;
|
||||||
|
|
||||||
if (!_allocate(lv->vg, lv, acceptable_pvs, lv->le_count)) {
|
if (!_allocate(new_lv->vg, new_lv, acceptable_pvs, new_lv->le_count)) {
|
||||||
stack;
|
stack;
|
||||||
goto bad;
|
goto bad;
|
||||||
}
|
}
|
||||||
|
@ -133,7 +133,8 @@ struct volume_group *vg_create(struct io_space *ios, const char *vg_name,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!id_create(&vg->id)) {
|
if (!id_create(&vg->id)) {
|
||||||
log_err("Couldn't create uuid for volume group '%s'.", vg_name);
|
log_err("Couldn't create uuid for volume group '%s'.",
|
||||||
|
vg_name);
|
||||||
goto bad;
|
goto bad;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,7 +23,6 @@
|
|||||||
int lvcreate(int argc, char **argv)
|
int lvcreate(int argc, char **argv)
|
||||||
{
|
{
|
||||||
int zero;
|
int zero;
|
||||||
int size_rest = 0;
|
|
||||||
uint32_t read_ahead = 0;
|
uint32_t read_ahead = 0;
|
||||||
int stripes = 1;
|
int stripes = 1;
|
||||||
int stripesize = 0;
|
int stripesize = 0;
|
||||||
|
@ -94,8 +94,8 @@ void vgchange_available(struct volume_group *vg)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* FIXME: Force argument to deactivate them? */
|
/* FIXME: Force argument to deactivate them? */
|
||||||
if (!available && (lv_open = lvs_in_vg_activated(vg))) {
|
if (!available && (lv_open = lvs_in_vg_opened(vg))) {
|
||||||
log_error("Can't deactivate volume group '%s' with %d active "
|
log_error("Can't deactivate volume group '%s' with %d open "
|
||||||
"logical volume(s)", vg->name, lv_open);
|
"logical volume(s)", vg->name, lv_open);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user