mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-22 17:35:59 +03:00
dmeventd: thin plugin update
Use dm_make_percent for percentage calculation like lvm2 command. Use a single call for resize.
This commit is contained in:
parent
6b0bc5b2d9
commit
fa9e41d2e3
@ -1,5 +1,6 @@
|
|||||||
Version 1.02.110 -
|
Version 1.02.110 -
|
||||||
======================================
|
======================================
|
||||||
|
Thin plugin for dmeventd improved percentage usage.
|
||||||
Snapshot plugin for dmeventd improved percentage usage.
|
Snapshot plugin for dmeventd improved percentage usage.
|
||||||
Add dm_hold_control_dev to allow holding of control device open.
|
Add dm_hold_control_dev to allow holding of control device open.
|
||||||
Add dm_report_compact_given_fields to remove given empty fields from report.
|
Add dm_report_compact_given_fields to remove given empty fields from report.
|
||||||
|
@ -28,11 +28,11 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* First warning when thin data or metadata is 80% full. */
|
/* First warning when thin data or metadata is 80% full. */
|
||||||
#define WARNING_THRESH 80
|
#define WARNING_THRESH (DM_PERCENT_1 * 80)
|
||||||
/* Run a check every 5%. */
|
/* Run a check every 5%. */
|
||||||
#define CHECK_STEP 5
|
#define CHECK_STEP (DM_PERCENT_1 * 5)
|
||||||
/* Do not bother checking thin data or metadata is less than 50% full. */
|
/* Do not bother checking thin data or metadata is less than 50% full. */
|
||||||
#define CHECK_MINIMUM 50
|
#define CHECK_MINIMUM (DM_PERCENT_1 * 50)
|
||||||
|
|
||||||
#define UMOUNT_COMMAND "/bin/umount"
|
#define UMOUNT_COMMAND "/bin/umount"
|
||||||
|
|
||||||
@ -138,14 +138,6 @@ out:
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int _extend(struct dso_state *state)
|
|
||||||
{
|
|
||||||
#if THIN_DEBUG
|
|
||||||
log_info("dmeventd executes: %s.", state->cmd_str);
|
|
||||||
#endif
|
|
||||||
return dmeventd_lvm2_run_with_lock(state->cmd_str);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int _run(const char *cmd, ...)
|
static int _run(const char *cmd, ...)
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
@ -188,9 +180,9 @@ static int _run(const char *cmd, ...)
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct mountinfo_s {
|
struct mountinfo_s {
|
||||||
|
const char *device;
|
||||||
struct dm_info info;
|
struct dm_info info;
|
||||||
dm_bitset_t minors; /* Bitset for active thin pool minors */
|
dm_bitset_t minors; /* Bitset for active thin pool minors */
|
||||||
const char *device;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static int _umount_device(char *buffer, unsigned major, unsigned minor,
|
static int _umount_device(char *buffer, unsigned major, unsigned minor,
|
||||||
@ -213,24 +205,24 @@ static int _umount_device(char *buffer, unsigned major, unsigned minor,
|
|||||||
* Find all thin pool users and try to umount them.
|
* Find all thin pool users and try to umount them.
|
||||||
* TODO: work with read-only thin pool support
|
* TODO: work with read-only thin pool support
|
||||||
*/
|
*/
|
||||||
static void _umount(struct dm_task *dmt, const char *device)
|
static void _umount(struct dm_task *dmt)
|
||||||
{
|
{
|
||||||
/* TODO: Convert to use hash to reduce memory usage */
|
/* TODO: Convert to use hash to reduce memory usage */
|
||||||
static const size_t MINORS = (1U << 20); /* 20 bit */
|
static const size_t MINORS = (1U << 20); /* 20 bit */
|
||||||
struct mountinfo_s data = {
|
struct mountinfo_s data = { NULL };
|
||||||
.device = device,
|
|
||||||
};
|
|
||||||
|
|
||||||
if (!dm_task_get_info(dmt, &data.info))
|
if (!dm_task_get_info(dmt, &data.info))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
data.device = dm_task_get_name(dmt);
|
||||||
|
|
||||||
if (!(data.minors = dm_bitset_create(NULL, MINORS))) {
|
if (!(data.minors = dm_bitset_create(NULL, MINORS))) {
|
||||||
log_error("Failed to allocate bitset. Not unmounting %s.", device);
|
log_error("Failed to allocate bitset. Not unmounting %s.", data.device);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!_find_all_devs(data.minors, data.info.major, data.info.minor)) {
|
if (!_find_all_devs(data.minors, data.info.major, data.info.minor)) {
|
||||||
log_error("Failed to detect mounted volumes for %s.", device);
|
log_error("Failed to detect mounted volumes for %s.", data.device);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -244,6 +236,18 @@ out:
|
|||||||
dm_bitset_destroy(data.minors);
|
dm_bitset_destroy(data.minors);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void _use_policy(struct dm_task *dmt, struct dso_state *state)
|
||||||
|
{
|
||||||
|
#if THIN_DEBUG
|
||||||
|
log_info("dmeventd executes: %s.", state->cmd_str);
|
||||||
|
#endif
|
||||||
|
if (!dmeventd_lvm2_run_with_lock(state->cmd_str)) {
|
||||||
|
log_error("Failed to extend thin pool %s.",
|
||||||
|
dm_task_get_name(dmt));
|
||||||
|
_umount(dmt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void process_event(struct dm_task *dmt,
|
void process_event(struct dm_task *dmt,
|
||||||
enum dm_event_mask event __attribute__((unused)),
|
enum dm_event_mask event __attribute__((unused)),
|
||||||
void **user)
|
void **user)
|
||||||
@ -256,12 +260,19 @@ void process_event(struct dm_task *dmt,
|
|||||||
uint64_t start, length;
|
uint64_t start, length;
|
||||||
char *target_type = NULL;
|
char *target_type = NULL;
|
||||||
char *params;
|
char *params;
|
||||||
|
int needs_policy = 0;
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
/* No longer monitoring, waiting for remove */
|
/* No longer monitoring, waiting for remove */
|
||||||
if (!state->meta_percent_check && !state->data_percent_check)
|
if (!state->meta_percent_check && !state->data_percent_check)
|
||||||
return;
|
return;
|
||||||
#endif
|
#endif
|
||||||
|
if (event & DM_EVENT_DEVICE_ERROR) {
|
||||||
|
/* Error -> no need to check and do instant resize */
|
||||||
|
_use_policy(dmt, state);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
dm_get_next_target(dmt, next, &start, &length, &target_type, ¶ms);
|
dm_get_next_target(dmt, next, &start, &length, &target_type, ¶ms);
|
||||||
|
|
||||||
if (!target_type || (strcmp(target_type, "thin-pool") != 0)) {
|
if (!target_type || (strcmp(target_type, "thin-pool") != 0)) {
|
||||||
@ -271,13 +282,13 @@ void process_event(struct dm_task *dmt,
|
|||||||
|
|
||||||
if (!dm_get_status_thin_pool(state->mem, params, &tps)) {
|
if (!dm_get_status_thin_pool(state->mem, params, &tps)) {
|
||||||
log_error("Failed to parse status.");
|
log_error("Failed to parse status.");
|
||||||
_umount(dmt, device);
|
_umount(dmt);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if THIN_DEBUG
|
#if THIN_DEBUG
|
||||||
log_debug("%p: Got status " FMTu64 " / " FMTu64 " " FMTu64
|
log_debug("Thin pool status " FMTu64 "/" FMTu64 " "
|
||||||
" / " FMTu64 ".", state,
|
FMTu64 "/" FMTu64 ".",
|
||||||
tps->used_metadata_blocks, tps->total_metadata_blocks,
|
tps->used_metadata_blocks, tps->total_metadata_blocks,
|
||||||
tps->used_data_blocks, tps->total_data_blocks);
|
tps->used_data_blocks, tps->total_data_blocks);
|
||||||
#endif
|
#endif
|
||||||
@ -293,7 +304,7 @@ void process_event(struct dm_task *dmt,
|
|||||||
state->known_data_size = tps->total_data_blocks;
|
state->known_data_size = tps->total_data_blocks;
|
||||||
}
|
}
|
||||||
|
|
||||||
percent = 100 * tps->used_metadata_blocks / tps->total_metadata_blocks;
|
percent = dm_make_percent(tps->used_metadata_blocks, tps->total_metadata_blocks);
|
||||||
if (percent >= state->metadata_percent_check) {
|
if (percent >= state->metadata_percent_check) {
|
||||||
/*
|
/*
|
||||||
* Usage has raised more than CHECK_STEP since the last
|
* Usage has raised more than CHECK_STEP since the last
|
||||||
@ -303,18 +314,12 @@ void process_event(struct dm_task *dmt,
|
|||||||
|
|
||||||
/* FIXME: extension of metadata needs to be written! */
|
/* FIXME: extension of metadata needs to be written! */
|
||||||
if (percent >= WARNING_THRESH) /* Print a warning to syslog. */
|
if (percent >= WARNING_THRESH) /* Print a warning to syslog. */
|
||||||
log_warn("WARNING: Thin metadata %s is now %i%% full.",
|
log_warn("WARNING: Thin pool %s metadata is now %.2f%% full.",
|
||||||
device, percent);
|
device, dm_percent_to_float(percent));
|
||||||
/* Try to extend the metadata, in accord with user-set policies */
|
needs_policy = 1;
|
||||||
if (!_extend(state)) {
|
|
||||||
log_error("Failed to extend thin metadata %s.",
|
|
||||||
device);
|
|
||||||
_umount(dmt, device);
|
|
||||||
}
|
|
||||||
/* FIXME: hmm READ-ONLY switch should happen in error path */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
percent = 100 * tps->used_data_blocks / tps->total_data_blocks;
|
percent = dm_make_percent(tps->used_data_blocks, tps->total_data_blocks);
|
||||||
if (percent >= state->data_percent_check) {
|
if (percent >= state->data_percent_check) {
|
||||||
/*
|
/*
|
||||||
* Usage has raised more than CHECK_STEP since
|
* Usage has raised more than CHECK_STEP since
|
||||||
@ -323,21 +328,16 @@ void process_event(struct dm_task *dmt,
|
|||||||
state->data_percent_check = (percent / CHECK_STEP) * CHECK_STEP + CHECK_STEP;
|
state->data_percent_check = (percent / CHECK_STEP) * CHECK_STEP + CHECK_STEP;
|
||||||
|
|
||||||
if (percent >= WARNING_THRESH) /* Print a warning to syslog. */
|
if (percent >= WARNING_THRESH) /* Print a warning to syslog. */
|
||||||
log_warn("WARNING: Thin %s is now %i%% full.",
|
log_warn("WARNING: Thin pool %s data is now %.2f%% full.",
|
||||||
device, percent);
|
device, dm_percent_to_float(percent));
|
||||||
/* Try to extend the thin data, in accord with user-set policies */
|
needs_policy = 1;
|
||||||
if (!_extend(state)) {
|
|
||||||
log_error("Failed to extend thin %s.", device);
|
|
||||||
state->data_percent_check = 0;
|
|
||||||
_umount(dmt, device);
|
|
||||||
}
|
|
||||||
/* FIXME: hmm READ-ONLY switch should happen in error path */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (needs_policy)
|
||||||
|
_use_policy(dmt, state);
|
||||||
out:
|
out:
|
||||||
if (tps)
|
if (tps)
|
||||||
dm_pool_free(state->mem, tps);
|
dm_pool_free(state->mem, tps);
|
||||||
|
|
||||||
dmeventd_lvm2_unlock();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int register_device(const char *device,
|
int register_device(const char *device,
|
||||||
|
Loading…
Reference in New Issue
Block a user