mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-22 17:35:59 +03:00
dmeventd: snapshot plugin updates
Improve test for invalid snapshot. Use dm_make_percent() to manipulate with exactly same percentage as lvm2 command is using.
This commit is contained in:
parent
91350f5c6a
commit
7ff5b03e5e
@ -1,5 +1,6 @@
|
|||||||
Version 1.02.110 -
|
Version 1.02.110 -
|
||||||
======================================
|
======================================
|
||||||
|
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.
|
||||||
Use libdm status parsing and local mem raid dmeventd plugin.
|
Use libdm status parsing and local mem raid dmeventd plugin.
|
||||||
|
@ -20,17 +20,17 @@
|
|||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
|
||||||
/* First warning when snapshot is 80% full. */
|
/* First warning when snapshot 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 snapshots less than 50% full. */
|
/* Do not bother checking snapshots 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"
|
||||||
|
|
||||||
struct dso_state {
|
struct dso_state {
|
||||||
struct dm_pool *mem;
|
struct dm_pool *mem;
|
||||||
int percent_check;
|
dm_percent_t percent_check;
|
||||||
uint64_t known_size;
|
uint64_t known_size;
|
||||||
char cmd_lvextend[512];
|
char cmd_lvextend[512];
|
||||||
};
|
};
|
||||||
@ -137,6 +137,7 @@ void process_event(struct dm_task *dmt,
|
|||||||
struct dm_status_snapshot *status = NULL;
|
struct dm_status_snapshot *status = NULL;
|
||||||
const char *device = dm_task_get_name(dmt);
|
const char *device = dm_task_get_name(dmt);
|
||||||
int percent;
|
int percent;
|
||||||
|
struct dm_info info;
|
||||||
|
|
||||||
/* No longer monitoring, waiting for remove */
|
/* No longer monitoring, waiting for remove */
|
||||||
if (!state->percent_check)
|
if (!state->percent_check)
|
||||||
@ -148,16 +149,22 @@ void process_event(struct dm_task *dmt,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!dm_get_status_snapshot(state->mem, params, &status))
|
if (!dm_get_status_snapshot(state->mem, params, &status)) {
|
||||||
|
log_error("Cannot parse snapshot %s state: %s.", device, params);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (status->invalid || status->overflow) {
|
/*
|
||||||
struct dm_info info;
|
* If the snapshot has been invalidated or we failed to parse
|
||||||
log_error("Snapshot %s is lost.", device);
|
* the status string. Report the full status string to syslog.
|
||||||
if (dm_task_get_info(dmt, &info)) {
|
*/
|
||||||
|
if (status->invalid || status->overflow || !status->total_sectors) {
|
||||||
|
log_warn("WARNING: Snapshot %s changed state to: %s and should be removed.",
|
||||||
|
device, params);
|
||||||
|
state->percent_check = 0;
|
||||||
|
if (dm_task_get_info(dmt, &info))
|
||||||
_umount(device, info.major, info.minor);
|
_umount(device, info.major, info.minor);
|
||||||
goto_out;
|
goto out;
|
||||||
} /* else; too bad, but this is best-effort thing... */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Snapshot size had changed. Clear the threshold. */
|
/* Snapshot size had changed. Clear the threshold. */
|
||||||
@ -166,24 +173,15 @@ void process_event(struct dm_task *dmt,
|
|||||||
state->known_size = status->total_sectors;
|
state->known_size = status->total_sectors;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
percent = dm_make_percent(status->used_sectors, status->total_sectors);
|
||||||
* If the snapshot has been invalidated or we failed to parse
|
|
||||||
* the status string. Report the full status string to syslog.
|
|
||||||
*/
|
|
||||||
if (status->invalid || status->overflow || !status->total_sectors) {
|
|
||||||
log_error("Snapshot %s changed state to: %s.", device, params);
|
|
||||||
state->percent_check = 0;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
percent = (int) (100 * status->used_sectors / status->total_sectors);
|
|
||||||
if (percent >= state->percent_check) {
|
if (percent >= state->percent_check) {
|
||||||
/* Usage has raised more than CHECK_STEP since the last
|
/* Usage has raised more than CHECK_STEP since the last
|
||||||
time. Run actions. */
|
time. Run actions. */
|
||||||
state->percent_check = (percent / CHECK_STEP) * CHECK_STEP + CHECK_STEP;
|
state->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: Snapshot %s is now %i%% full.", device, percent);
|
log_warn("WARNING: Snapshot %s is now %.2f%% full.",
|
||||||
|
device, dm_percent_to_float(percent));
|
||||||
|
|
||||||
/* Try to extend the snapshot, in accord with user-set policies */
|
/* Try to extend the snapshot, in accord with user-set policies */
|
||||||
if (!_extend(state->cmd_lvextend))
|
if (!_extend(state->cmd_lvextend))
|
||||||
|
Loading…
Reference in New Issue
Block a user