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

readahead activation code (but no dm support yet)

This commit is contained in:
Alasdair Kergon 2007-11-12 20:51:54 +00:00
parent 6dd60469ba
commit a6b22cf317
16 changed files with 93 additions and 51 deletions

View File

@ -1,9 +1,10 @@
Version 2.02.29 -
==================================
Attempt to remove incomplete LVs with lvcreate zeroing/activation problems.
Add read_ahead activation code.
Add activation/readahead configuration option and FMT_RESTRICTED_READAHEAD.
Extend readahead arg to accept "auto" and "none".
Add lv_read_ahead and lv_kernel_read_ahead fields to reports.
Add lv_read_ahead and lv_kernel_read_ahead fields to reports and lvdisplay.
Prevent lvconvert -s from using same LV as origin and snapshot.
Fix human-readable output of odd numbers of sectors.
Add pv_mda_free and vg_mda_free fields to reports for raw text format.

View File

@ -146,12 +146,12 @@ int target_present(const char *target_name, int use_modprobe)
return 0;
}
int lv_info(struct cmd_context *cmd, const struct logical_volume *lv, struct lvinfo *info,
int with_open_count)
int with_open_count, int with_read_ahead)
{
return 0;
}
int lv_info_by_lvid(struct cmd_context *cmd, const char *lvid_s,
struct lvinfo *info, int with_open_count)
struct lvinfo *info, int with_open_count, int with_read_ahead)
{
return 0;
}
@ -425,7 +425,7 @@ int target_present(const char *target_name, int use_modprobe)
* Returns 1 if info structure populated, else 0 on failure.
*/
static int _lv_info(struct cmd_context *cmd, const struct logical_volume *lv, int with_mknodes,
struct lvinfo *info, int with_open_count, unsigned by_uuid_only)
struct lvinfo *info, int with_open_count, int with_read_ahead, unsigned by_uuid_only)
{
struct dm_info dminfo;
char *name = NULL;
@ -439,7 +439,8 @@ static int _lv_info(struct cmd_context *cmd, const struct logical_volume *lv, in
log_debug("Getting device info for %s", name);
if (!dev_manager_info(lv->vg->cmd->mem, name, lv, with_mknodes,
with_open_count, &dminfo)) {
with_open_count, with_read_ahead, &dminfo,
&info->read_ahead)) {
if (name)
dm_pool_free(cmd->mem, name);
return_0;
@ -461,20 +462,20 @@ static int _lv_info(struct cmd_context *cmd, const struct logical_volume *lv, in
}
int lv_info(struct cmd_context *cmd, const struct logical_volume *lv, struct lvinfo *info,
int with_open_count)
int with_open_count, int with_read_ahead)
{
return _lv_info(cmd, lv, 0, info, with_open_count, 0);
return _lv_info(cmd, lv, 0, info, with_open_count, with_read_ahead, 0);
}
int lv_info_by_lvid(struct cmd_context *cmd, const char *lvid_s,
struct lvinfo *info, int with_open_count)
struct lvinfo *info, int with_open_count, int with_read_ahead)
{
struct logical_volume *lv;
if (!(lv = lv_from_lvid(cmd, lvid_s, 0)))
return 0;
return _lv_info(cmd, lv, 0, info, with_open_count, 0);
return _lv_info(cmd, lv, 0, info, with_open_count, with_read_ahead, 0);
}
/*
@ -510,7 +511,7 @@ int lv_mirror_percent(struct cmd_context *cmd, struct logical_volume *lv,
if (!activation())
return 0;
if (!lv_info(cmd, lv, &info, 0))
if (!lv_info(cmd, lv, &info, 0, 0))
return_0;
if (!info.exists)
@ -532,7 +533,7 @@ static int _lv_active(struct cmd_context *cmd, struct logical_volume *lv,
{
struct lvinfo info;
if (!_lv_info(cmd, lv, 0, &info, 0, by_uuid_only)) {
if (!_lv_info(cmd, lv, 0, &info, 0, 0, by_uuid_only)) {
stack;
return -1;
}
@ -544,7 +545,7 @@ static int _lv_open_count(struct cmd_context *cmd, struct logical_volume *lv)
{
struct lvinfo info;
if (!lv_info(cmd, lv, &info, 1)) {
if (!lv_info(cmd, lv, &info, 1, 0)) {
stack;
return -1;
}
@ -772,7 +773,7 @@ static int _lv_suspend(struct cmd_context *cmd, const char *lvid_s,
return 1;
}
if (!lv_info(cmd, lv, &info, 0))
if (!lv_info(cmd, lv, &info, 0, 0))
return_0;
if (!info.exists || info.suspended)
@ -832,7 +833,7 @@ static int _lv_resume(struct cmd_context *cmd, const char *lvid_s,
return 1;
}
if (!lv_info(cmd, lv, &info, 0))
if (!lv_info(cmd, lv, &info, 0, 0))
return_0;
if (!info.exists || !info.suspended)
@ -878,7 +879,7 @@ int lv_deactivate(struct cmd_context *cmd, const char *lvid_s)
return 1;
}
if (!lv_info(cmd, lv, &info, 1))
if (!lv_info(cmd, lv, &info, 1, 0))
return_0;
if (!info.exists)
@ -949,7 +950,7 @@ static int _lv_activate(struct cmd_context *cmd, const char *lvid_s,
return 1;
}
if (!lv_info(cmd, lv, &info, 0))
if (!lv_info(cmd, lv, &info, 0, 0))
return_0;
if (info.exists && !info.suspended && info.live_table)
@ -992,7 +993,7 @@ int lv_mknodes(struct cmd_context *cmd, const struct logical_volume *lv)
return r;
}
if (!_lv_info(cmd, lv, 1, &info, 0, 0))
if (!_lv_info(cmd, lv, 1, &info, 0, 0, 0))
return_0;
if (info.exists)

View File

@ -27,6 +27,7 @@ struct lvinfo {
int read_only;
int live_table;
int inactive_table;
uint32_t read_ahead;
};
void set_activation(int activation);
@ -62,9 +63,9 @@ int lv_mknodes(struct cmd_context *cmd, const struct logical_volume *lv);
* Returns 1 if info structure has been populated, else 0.
*/
int lv_info(struct cmd_context *cmd, const struct logical_volume *lv, struct lvinfo *info,
int with_open_count);
int with_open_count, int with_read_ahead);
int lv_info_by_lvid(struct cmd_context *cmd, const char *lvid_s,
struct lvinfo *info, int with_open_count);
struct lvinfo *info, int with_open_count, int with_read_ahead);
/*
* Returns 1 if activate_lv has been set: 1 = activate; 0 = don't.

View File

@ -118,7 +118,8 @@ static struct dm_task *_setup_task(const char *name, const char *uuid,
}
static int _info_run(const char *name, const char *dlid, struct dm_info *info,
int mknodes, int with_open_count)
uint32_t *read_ahead, int mknodes, int with_open_count,
int with_read_ahead)
{
int r = 0;
struct dm_task *dmt;
@ -141,6 +142,12 @@ static int _info_run(const char *name, const char *dlid, struct dm_info *info,
if (!dm_task_get_info(dmt, info))
goto_out;
if (!with_read_ahead) {
if (read_ahead)
*read_ahead = DM_READ_AHEAD_NONE;
} else
; // FIXME *read_ahead = dm_task_get_read_ahead(dmt);
r = 1;
out:
@ -201,27 +208,32 @@ int device_is_usable(dev_t dev)
}
static int _info(const char *name, const char *dlid, int mknodes,
int with_open_count, struct dm_info *info)
int with_open_count, int with_read_ahead,
struct dm_info *info, uint32_t *read_ahead)
{
if (!mknodes && dlid && *dlid) {
if (_info_run(NULL, dlid, info, 0, with_open_count) &&
if (_info_run(NULL, dlid, info, read_ahead, 0, with_open_count,
with_read_ahead) &&
info->exists)
return 1;
else if (_info_run(NULL, dlid + sizeof(UUID_PREFIX) - 1, info,
0, with_open_count) &&
read_ahead, 0, with_open_count,
with_read_ahead) &&
info->exists)
return 1;
}
if (name)
return _info_run(name, NULL, info, mknodes, with_open_count);
return _info_run(name, NULL, info, read_ahead, mknodes,
with_open_count, with_read_ahead);
return 0;
}
int dev_manager_info(struct dm_pool *mem, const char *name,
const struct logical_volume *lv, int with_mknodes,
int with_open_count, struct dm_info *info)
int with_open_count, int with_read_ahead,
struct dm_info *info, uint32_t *read_ahead)
{
const char *dlid;
@ -230,7 +242,8 @@ int dev_manager_info(struct dm_pool *mem, const char *name,
return 0;
}
return _info(name, dlid, with_mknodes, with_open_count, info);
return _info(name, dlid, with_mknodes, with_open_count, with_read_ahead,
info, read_ahead);
}
/* FIXME Interface must cope with multiple targets */
@ -631,7 +644,7 @@ static int _add_dev_to_dtree(struct dev_manager *dm, struct dm_tree *dtree,
return_0;
log_debug("Getting device info for %s [%s]", name, dlid);
if (!_info(name, dlid, 0, 1, &info)) {
if (!_info(name, dlid, 0, 1, 0, &info, NULL)) {
log_error("Failed to get info for %s [%s].", name, dlid);
return 0;
}
@ -886,6 +899,9 @@ static int _add_new_lv_to_dtree(struct dev_manager *dm, struct dm_tree *dtree,
struct lv_layer *lvlayer;
struct dm_tree_node *dnode;
char *name, *dlid;
uint32_t max_stripe_size = UINT32_C(0);
uint32_t read_ahead = lv->read_ahead;
uint32_t flags = UINT32_C(0);
if (!(name = build_dm_name(dm->mem, lv->vg->name, lv->name, layer)))
return_0;
@ -932,8 +948,17 @@ static int _add_new_lv_to_dtree(struct dev_manager *dm, struct dm_tree *dtree,
break;
if (lv_is_cow(lv) && !layer)
break;
if (max_stripe_size < seg->stripe_size)
max_stripe_size = seg->stripe_size;
}
if (read_ahead == DM_READ_AHEAD_AUTO)
read_ahead = max_stripe_size;
else
flags = DM_READ_AHEAD_MINIMUM_FLAG;
// FIXME dm_tree_node_set_read_ahead(dnode, read_ahead, flags);
return 1;
}

View File

@ -40,7 +40,8 @@ void dev_manager_exit(void);
*/
int dev_manager_info(struct dm_pool *mem, const char *name,
const struct logical_volume *lv,
int mknodes, int with_open_count, struct dm_info *info);
int mknodes, int with_open_count, int with_read_ahead,
struct dm_info *info, uint32_t *read_ahead);
int dev_manager_snapshot_percent(struct dev_manager *dm,
const struct logical_volume *lv,
float *percent);

View File

@ -381,7 +381,7 @@ void lvdisplay_colons(const struct logical_volume *lv)
{
int inkernel;
struct lvinfo info;
inkernel = lv_info(lv->vg->cmd, lv, &info, 1) && info.exists;
inkernel = lv_info(lv->vg->cmd, lv, &info, 1, 0) && info.exists;
log_print("%s%s/%s:%s:%d:%d:-1:%d:%" PRIu64 ":%d:-1:%d:%d:%d:%d",
lv->vg->cmd->dev_dir,
@ -412,7 +412,7 @@ int lvdisplay_full(struct cmd_context *cmd,
return 0;
}
inkernel = lv_info(cmd, lv, &info, 1) && info.exists;
inkernel = lv_info(cmd, lv, &info, 1, 1) && info.exists;
log_print("--- Logical volume ---");
@ -493,7 +493,15 @@ int lvdisplay_full(struct cmd_context *cmd,
***********/
log_print("Allocation %s", get_alloc_string(lv->alloc));
log_print("Read ahead sectors %u", lv->read_ahead);
if (lv->read_ahead == DM_READ_AHEAD_AUTO)
log_print("Read ahead sectors auto");
else if (lv->read_ahead == DM_READ_AHEAD_NONE)
log_print("Read ahead sectors 0");
else
log_print("Read ahead sectors %u", lv->read_ahead);
if (inkernel && lv->read_ahead != info.read_ahead)
log_print("- currently set to %u", info.read_ahead);
if (lv->status & FIXED_MINOR) {
if (lv->major >= 0)

View File

@ -1839,7 +1839,7 @@ int lv_remove_single(struct cmd_context *cmd, struct logical_volume *lv,
/* FIXME Ensure not referred to by another existing LVs */
if (lv_info(cmd, lv, &info, 1)) {
if (lv_info(cmd, lv, &info, 1, 0)) {
if (info.open_count) {
log_error("Can't remove open logical volume \"%s\"",
lv->name);

View File

@ -227,7 +227,7 @@ static int _lvkmaj_disp(struct dm_report *rh, struct dm_pool *mem __attribute((u
const struct logical_volume *lv = (const struct logical_volume *) data;
struct lvinfo info;
if (lv_info(lv->vg->cmd, lv, &info, 0) && info.exists)
if (lv_info(lv->vg->cmd, lv, &info, 0, 0) && info.exists)
return dm_report_field_int(rh, field, &info.major);
return dm_report_field_uint64(rh, field, &_minusone);
@ -240,7 +240,7 @@ static int _lvkmin_disp(struct dm_report *rh, struct dm_pool *mem __attribute((u
const struct logical_volume *lv = (const struct logical_volume *) data;
struct lvinfo info;
if (lv_info(lv->vg->cmd, lv, &info, 0) && info.exists)
if (lv_info(lv->vg->cmd, lv, &info, 0, 0) && info.exists)
return dm_report_field_int(rh, field, &info.minor);
return dm_report_field_uint64(rh, field, &_minusone);
@ -297,7 +297,7 @@ static int _lvstatus_disp(struct dm_report *rh __attribute((unused)), struct dm_
else
repstr[3] = '-';
if (lv_info(lv->vg->cmd, lv, &info, 1) && info.exists) {
if (lv_info(lv->vg->cmd, lv, &info, 1, 0) && info.exists) {
if (info.suspended)
repstr[4] = 's'; /* Suspended */
else if (info.live_table)
@ -583,7 +583,12 @@ static int _lvkreadahead_disp(struct dm_report *rh, struct dm_pool *mem,
const void *data,
void *private __attribute((unused)))
{
// FIXME after dm support is added
const struct logical_volume *lv = (const struct logical_volume *) data;
struct lvinfo info;
if (lv_info(lv->vg->cmd, lv, &info, 0, 1) && info.exists)
return dm_report_field_int(rh, field, &info.read_ahead);
return dm_report_field_uint64(rh, field, &_minusone);
}
@ -852,7 +857,7 @@ static int _snpercent_disp(struct dm_report *rh __attribute((unused)), struct dm
}
if (!lv_is_cow(lv) ||
(lv_info(lv->vg->cmd, lv, &info, 0) && !info.exists)) {
(lv_info(lv->vg->cmd, lv, &info, 0, 0) && !info.exists)) {
*sortval = UINT64_C(0);
dm_report_field_set_value(field, "", sortval);
return 1;

View File

@ -36,7 +36,7 @@ static int lvchange_permission(struct cmd_context *cmd,
}
if ((lv->status & MIRRORED) && (lv->vg->status & CLUSTERED) &&
lv_info(cmd, lv, &info, 0) && info.exists) {
lv_info(cmd, lv, &info, 0, 0) && info.exists) {
log_error("Cannot change permissions of mirror \"%s\" "
"while active.", lv->name);
return 0;
@ -85,7 +85,7 @@ static int lvchange_monitoring(struct cmd_context *cmd,
{
struct lvinfo info;
if (!lv_info(cmd, lv, &info, 0) || !info.exists) {
if (!lv_info(cmd, lv, &info, 0, 0) || !info.exists) {
log_error("Logical volume, %s, is not active", lv->name);
return 0;
}
@ -195,7 +195,7 @@ static int lvchange_resync(struct cmd_context *cmd,
return 0;
}
if (lv_info(cmd, lv, &info, 1)) {
if (lv_info(cmd, lv, &info, 1, 0)) {
if (info.open_count) {
log_error("Can't resync open logical volume \"%s\"",
lv->name);
@ -447,7 +447,7 @@ static int lvchange_persistent(struct cmd_context *cmd,
log_error("Major number must be specified with -My");
return 0;
}
if (lv_info(cmd, lv, &info, 0) && info.exists)
if (lv_info(cmd, lv, &info, 0, 0) && info.exists)
active = 1;
if (active && !arg_count(cmd, force_ARG) &&
yes_no_prompt("Logical volume %s will be "

View File

@ -680,7 +680,7 @@ static int _lvcreate(struct cmd_context *cmd, struct lvcreate_params *lp)
/* Must zero cow */
status |= LVM_WRITE;
if (!lv_info(cmd, org, &info, 0)) {
if (!lv_info(cmd, org, &info, 0, 0)) {
log_error("Check for existence of snapshot origin "
"'%s' failed.", org->name);
return 0;
@ -918,7 +918,7 @@ deactivate_and_revert_new_lv:
revert_new_lv:
/* FIXME Better to revert to backup of metadata? */
if (!lv_remove(lv) || !vg_write(vg) || backup(vg) || !vg_commit(vg))
if (!lv_remove(lv) || !vg_write(vg) || backup(vg), !vg_commit(vg))
log_error("Manual intervention may be required to remove "
"abandoned LV(s) before retrying.");
return 0;

View File

@ -95,7 +95,7 @@ static int confirm_resizefs_reduce(struct cmd_context *cmd,
memset(&info, 0, sizeof(info));
if (!lv_info(cmd, lv, &info, 1) && driver_version(NULL, 0)) {
if (!lv_info(cmd, lv, &info, 1, 0) && driver_version(NULL, 0)) {
log_error("lv_info failed: aborting");
return 0;
}
@ -545,7 +545,7 @@ static int _lvresize(struct cmd_context *cmd, struct lvresize_params *lp)
}
if (lp->mirrors && activation() &&
lv_info(cmd, lv, &info, 0) && info.exists) {
lv_info(cmd, lv, &info, 0, 0) && info.exists) {
log_error("Mirrors cannot be resized while active yet.");
return ECMD_FAILED;
}
@ -559,7 +559,7 @@ static int _lvresize(struct cmd_context *cmd, struct lvresize_params *lp)
memset(&info, 0, sizeof(info));
if (lv_info(cmd, lv, &info, 0) && info.exists) {
if (lv_info(cmd, lv, &info, 0, 0) && info.exists) {
log_error("Snapshot origin volumes can be resized "
"only while inactive: try lvchange -an");
return ECMD_FAILED;

View File

@ -30,7 +30,7 @@ static int lvscan_single(struct cmd_context *cmd, struct logical_volume *lv,
if (!arg_count(cmd, all_ARG) && !lv_is_visible(lv))
return ECMD_PROCESSED;
inkernel = lv_info(cmd, lv, &info, 1) && info.exists;
inkernel = lv_info(cmd, lv, &info, 1, 0) && info.exists;
if (lv_is_origin(lv)) {
list_iterate_items_gen(snap_seg, &lv->snapshot_segs,
origin_list) {

View File

@ -1415,7 +1415,7 @@ deactivate_and_revert_new_lv:
}
revert_new_lv:
if (!lv_remove(log_lv) || !vg_write(vg) || backup(vg) || !vg_commit(vg))
if (!lv_remove(log_lv) || !vg_write(vg) || backup(vg), !vg_commit(vg))
log_error("Manual intervention may be required to remove "
"abandoned log LV before retrying.");
return NULL;

View File

@ -27,7 +27,7 @@ static int _monitor_lvs_in_vg(struct cmd_context *cmd,
list_iterate_items(lvl, &vg->lvs) {
lv = lvl->lv;
if (!lv_info(cmd, lv, &info, 0))
if (!lv_info(cmd, lv, &info, 0, 0))
lv_active = 0;
else
lv_active = info.exists;

View File

@ -89,7 +89,7 @@ static int vgconvert_single(struct cmd_context *cmd, const char *vg_name,
continue;
if (lvnum_from_lvid(&lv->lvid) < MAX_RESTRICTED_LVS)
continue;
if (lv_info(cmd, lv, &info, 0) && info.exists) {
if (lv_info(cmd, lv, &info, 0, 0) && info.exists) {
log_error("Logical volume %s must be "
"deactivated before conversion.",
lv->name);

View File

@ -116,7 +116,7 @@ static int _remove_lv(struct cmd_context *cmd, struct logical_volume *lv,
* the mirrored LV also should be cleaned up.
* Clean-up is currently done by caller (_make_vg_consistent()).
*/
if ((lv_info(cmd, lv, &info, 0) && info.exists)
if ((lv_info(cmd, lv, &info, 0, 0) && info.exists)
|| first_seg(lv)->mirror_seg) {
extents = lv->le_count;
mirror_seg = first_seg(lv)->mirror_seg;