fixed-point values instead of a combination of a float value and an enum.
@top_srcdir@/lib/misc/lvm-string.h
@top_builddir@/lib/misc/lvm-version.h
@top_srcdir@/lib/misc/lvm-wrappers.h
+@top_srcdir@/lib/misc/lvm-percent.h
@top_srcdir@/lib/misc/sharedlib.h
@top_srcdir@/lib/report/properties.h
@top_srcdir@/lib/report/report.h
misc/lvm-globals.c \
misc/lvm-string.c \
misc/lvm-wrappers.c \
+ misc/lvm-percent.c \
misc/util.c \
mm/memlock.c \
report/properties.c \
{
return 0;
}
-int lv_snapshot_percent(const struct logical_volume *lv, float *percent,
- percent_range_t *percent_range)
+int lv_snapshot_percent(const struct logical_volume *lv, percent_t *percent)
{
return 0;
}
int lv_mirror_percent(struct cmd_context *cmd, struct logical_volume *lv,
- int wait, float *percent, percent_range_t *percent_range,
- uint32_t *event_nr)
+ int wait, percent_t *percent, uint32_t *event_nr)
{
return 0;
}
/*
* Returns 1 if percent set, else 0 on failure.
*/
-int lv_snapshot_percent(const struct logical_volume *lv, float *percent,
- percent_range_t *percent_range)
+int lv_snapshot_percent(const struct logical_volume *lv, percent_t *percent)
{
int r;
struct dev_manager *dm;
if (!(dm = dev_manager_create(lv->vg->cmd, lv->vg->name)))
return_0;
- if (!(r = dev_manager_snapshot_percent(dm, lv, percent, percent_range)))
+ if (!(r = dev_manager_snapshot_percent(dm, lv, percent)))
stack;
dev_manager_destroy(dm);
/* FIXME Merge with snapshot_percent */
int lv_mirror_percent(struct cmd_context *cmd, struct logical_volume *lv,
- int wait, float *percent, percent_range_t *percent_range,
- uint32_t *event_nr)
+ int wait, percent_t *percent, uint32_t *event_nr)
{
int r;
struct dev_manager *dm;
/* If mirrored LV is temporarily shrinked to 1 area (= linear),
* it should be considered in-sync. */
if (dm_list_size(&lv->segments) == 1 && first_seg(lv)->area_count == 1) {
- *percent = 100.0;
+ *percent = PERCENT_100;
return 1;
}
if (!(dm = dev_manager_create(lv->vg->cmd, lv->vg->name)))
return_0;
- if (!(r = dev_manager_mirror_percent(dm, lv, wait, percent,
- percent_range, event_nr)))
+ if (!(r = dev_manager_mirror_percent(dm, lv, wait, percent, event_nr)))
stack;
dev_manager_destroy(dm);
/*
* Returns 1 if percent has been set, else 0.
*/
-int lv_snapshot_percent(const struct logical_volume *lv, float *percent,
- percent_range_t *percent_range);
+int lv_snapshot_percent(const struct logical_volume *lv, percent_t *percent);
int lv_mirror_percent(struct cmd_context *cmd, struct logical_volume *lv,
- int wait, float *percent, percent_range_t *percent_range,
- uint32_t *event_nr);
+ int wait, percent_t *percent, uint32_t *event_nr);
/*
* Return number of LVs in the VG that are active.
return r;
}
-static percent_range_t _combine_percent_ranges(percent_range_t a,
- percent_range_t b)
+static percent_range_t _combine_percent(percent_t a, percent_t b,
+ uint32_t numerator, uint32_t denominator)
{
if (a == PERCENT_INVALID || b == PERCENT_INVALID)
return PERCENT_INVALID;
if (a == PERCENT_0 && b == PERCENT_0)
return PERCENT_0;
- return PERCENT_0_TO_100;
+ return make_percent(numerator, denominator);
}
static int _percent_run(struct dev_manager *dm, const char *name,
const char *dlid,
const char *target_type, int wait,
- const struct logical_volume *lv, float *percent,
- percent_range_t *overall_percent_range,
+ const struct logical_volume *lv, percent_t *overall_percent,
uint32_t *event_nr, int fail_if_percent_unsupported)
{
int r = 0;
const struct dm_list *segh = &lv->segments;
struct lv_segment *seg = NULL;
struct segment_type *segtype;
- percent_range_t percent_range = 0, combined_percent_range = 0;
int first_time = 1;
+ percent_t percent;
uint64_t total_numerator = 0, total_denominator = 0;
- *percent = -1;
- *overall_percent_range = PERCENT_INVALID;
+ *overall_percent = PERCENT_INVALID;
if (!(dmt = _setup_task(name, dlid, event_nr,
wait ? DM_DEVICE_WAITEVENT : DM_DEVICE_STATUS, 0, 0)))
if (segtype->ops->target_percent &&
!segtype->ops->target_percent(&dm->target_state,
- &percent_range, dm->mem,
+ &percent, dm->mem,
dm->cmd, seg, params,
&total_numerator,
&total_denominator))
goto_out;
if (first_time) {
- combined_percent_range = percent_range;
+ *overall_percent = percent;
first_time = 0;
} else
- combined_percent_range =
- _combine_percent_ranges(combined_percent_range,
- percent_range);
+ *overall_percent =
+ _combine_percent(*overall_percent, percent,
+ total_numerator, total_denominator);
} while (next);
if (lv && (segh = dm_list_next(&lv->segments, segh))) {
goto out;
}
- if (total_denominator) {
- *percent = (float) total_numerator *100 / total_denominator;
- *overall_percent_range = combined_percent_range;
- } else {
- *percent = 100;
- if (first_time) {
- /* above ->target_percent() was not executed! */
- /* FIXME why return PERCENT_100 et. al. in this case? */
- *overall_percent_range = PERCENT_100;
- if (fail_if_percent_unsupported)
- goto_out;
- } else
- *overall_percent_range = combined_percent_range;
+ if (first_time) {
+ /* above ->target_percent() was not executed! */
+ /* FIXME why return PERCENT_100 et. al. in this case? */
+ *overall_percent = PERCENT_100;
+ if (fail_if_percent_unsupported)
+ goto_out;
}
- log_debug("LV percent: %f", *percent);
+ log_debug("LV percent: %f", percent_to_float(*overall_percent));
r = 1;
out:
static int _percent(struct dev_manager *dm, const char *name, const char *dlid,
const char *target_type, int wait,
- const struct logical_volume *lv, float *percent,
- percent_range_t *overall_percent_range, uint32_t *event_nr,
- int fail_if_percent_unsupported)
+ const struct logical_volume *lv, percent_t *percent,
+ uint32_t *event_nr, int fail_if_percent_unsupported)
{
if (dlid && *dlid) {
if (_percent_run(dm, NULL, dlid, target_type, wait, lv, percent,
- overall_percent_range, event_nr,
- fail_if_percent_unsupported))
+ event_nr, fail_if_percent_unsupported))
return 1;
else if (_percent_run(dm, NULL, dlid + sizeof(UUID_PREFIX) - 1,
target_type, wait, lv, percent,
- overall_percent_range, event_nr,
- fail_if_percent_unsupported))
+ event_nr, fail_if_percent_unsupported))
return 1;
}
if (name && _percent_run(dm, name, NULL, target_type, wait, lv, percent,
- overall_percent_range, event_nr,
- fail_if_percent_unsupported))
+ event_nr, fail_if_percent_unsupported))
return 1;
return 0;
int dev_manager_snapshot_percent(struct dev_manager *dm,
const struct logical_volume *lv,
- float *percent, percent_range_t *percent_range)
+ percent_t *percent)
{
char *name;
const char *dlid;
*/
log_debug("Getting device status percentage for %s", name);
if (!(_percent(dm, name, dlid, "snapshot", 0, NULL, percent,
- percent_range, NULL, fail_if_percent_unsupported)))
+ NULL, fail_if_percent_unsupported)))
return_0;
/* FIXME dm_pool_free ? */
/* FIXME Cope with more than one target */
int dev_manager_mirror_percent(struct dev_manager *dm,
const struct logical_volume *lv, int wait,
- float *percent, percent_range_t *percent_range,
- uint32_t *event_nr)
+ percent_t *percent, uint32_t *event_nr)
{
char *name;
const char *dlid;
log_debug("Getting device mirror status percentage for %s", name);
if (!(_percent(dm, name, dlid, "mirror", wait, lv, percent,
- percent_range, event_nr, 0)))
+ event_nr, 0)))
return_0;
return 1;
struct dm_info *info, uint32_t *read_ahead);
int dev_manager_snapshot_percent(struct dev_manager *dm,
const struct logical_volume *lv,
- float *percent,
- percent_range_t *percent_range);
+ percent_t *percent);
int dev_manager_mirror_percent(struct dev_manager *dm,
const struct logical_volume *lv, int wait,
- float *percent, percent_range_t *percent_range,
- uint32_t *event_nr);
+ percent_t *percent, uint32_t *event_nr);
int dev_manager_suspend(struct dev_manager *dm, struct logical_volume *lv,
unsigned origin_only, int lockfs, int flush_required);
int dev_manager_activate(struct dev_manager *dm, struct logical_volume *lv, unsigned origin_only);
int inkernel, snap_active = 0;
char uuid[64] __attribute__((aligned(8)));
struct lv_segment *snap_seg = NULL, *mirror_seg = NULL;
- float snap_percent; /* fused, fsize; */
- percent_range_t percent_range;
+ percent_t snap_percent;
if (!id_write_format(&lv->lvid.id[1], uuid, sizeof(uuid)))
return_0;
origin_list) {
if (inkernel &&
(snap_active = lv_snapshot_percent(snap_seg->cow,
- &snap_percent,
- &percent_range)))
- if (percent_range == PERCENT_INVALID)
+ &snap_percent)))
+ if (snap_percent == PERCENT_INVALID)
snap_active = 0;
log_print(" %s%s/%s [%s]",
lv->vg->cmd->dev_dir, lv->vg->name,
} else if ((snap_seg = find_cow(lv))) {
if (inkernel &&
(snap_active = lv_snapshot_percent(snap_seg->cow,
- &snap_percent,
- &percent_range)))
- if (percent_range == PERCENT_INVALID)
+ &snap_percent)))
+ if (snap_percent == PERCENT_INVALID)
snap_active = 0;
log_print("LV snapshot status %s destination for %s%s/%s",
log_print("COW-table LE %u", lv->le_count);
if (snap_active)
- log_print("Allocated to snapshot %.2f%% ", snap_percent);
+ log_print("Allocated to snapshot %.2f%% ",
+ percent_to_float(snap_percent));
log_print("Snapshot chunk size %s",
display_size(cmd, (uint64_t) snap_seg->chunk_size));
static int _lv_mimage_in_sync(const struct logical_volume *lv)
{
- float percent;
- percent_range_t percent_range;
+ percent_t percent;
struct lv_segment *mirror_seg = find_mirror_seg(first_seg(lv));
if (!(lv->status & MIRROR_IMAGE) || !mirror_seg)
return_0;
if (!lv_mirror_percent(lv->vg->cmd, mirror_seg->lv, 0, &percent,
- &percent_range, NULL))
+ NULL))
return_0;
- return (percent_range == PERCENT_100) ? 1 : 0;
+ return (percent == PERCENT_100) ? 1 : 0;
}
char *lv_attr_dup(struct dm_pool *mem, const struct logical_volume *lv)
{
- float snap_percent;
- percent_range_t percent_range;
+ percent_t snap_percent;
struct lvinfo info;
char *repstr;
/* Snapshot dropped? */
if (info.live_table && lv_is_cow(lv) &&
- (!lv_snapshot_percent(lv, &snap_percent, &percent_range) ||
- percent_range == PERCENT_INVALID)) {
+ (!lv_snapshot_percent(lv, &snap_percent) ||
+ snap_percent == PERCENT_INVALID)) {
repstr[0] = toupper(repstr[0]);
if (info.suspended)
repstr[4] = 'S'; /* Susp Inv snapshot */
#include "pv.h"
#include "vg.h"
#include "lv.h"
+#include "lvm-percent.h"
#define MAX_STRIPES 128U
#define SECTOR_SHIFT 9L
DONT_PROMPT_OVERRIDE = 2 /* Skip prompt + override a second condition */
} force_t;
-typedef enum {
- PERCENT_0 = 0,
- PERCENT_0_TO_100 = 1,
- PERCENT_100 = 2,
- PERCENT_INVALID = 3
-} percent_range_t;
-
struct cmd_context;
struct format_handler;
struct labeller;
uint32_t lv_type);
const char *get_pvmove_pvname_from_lv(struct logical_volume *lv);
const char *get_pvmove_pvname_from_lv_mirr(struct logical_volume *lv_mirr);
-float copy_percent(struct logical_volume *lv_mirr,
- percent_range_t *percent_range);
+percent_t copy_percent(struct logical_volume *lv_mirr);
struct dm_list *lvs_using_lv(struct cmd_context *cmd, struct volume_group *vg,
struct logical_volume *lv);
static int _mirrored_lv_in_sync(struct logical_volume *lv)
{
- float sync_percent;
- percent_range_t percent_range;
+ percent_t sync_percent;
if (!lv_mirror_percent(lv->vg->cmd, lv, 0, &sync_percent,
- &percent_range, NULL)) {
+ NULL)) {
log_error("Unable to determine mirror sync status of %s/%s.",
lv->vg->name, lv->name);
return 0;
}
- return (percent_range == PERCENT_100) ? 1 : 0;
+ return (sync_percent == PERCENT_100) ? 1 : 0;
}
/*
return lvs;
}
-float copy_percent(struct logical_volume *lv_mirr,
- percent_range_t *percent_range)
+percent_t copy_percent(struct logical_volume *lv_mirr)
{
uint32_t numerator = 0u, denominator = 0u;
struct lv_segment *seg;
numerator += seg->area_len;
}
- if (!denominator || (numerator == denominator))
- *percent_range = PERCENT_100;
- else if (numerator == 0)
- *percent_range = PERCENT_0;
- else
- *percent_range = PERCENT_0_TO_100;
-
- return denominator ? (float) numerator *100 / denominator : 100.0;
+ return denominator ? make_percent( numerator, denominator ) : 100.0;
}
/*
struct dm_list *removable_pvs,
int force)
{
- float sync_percent;
- percent_range_t percent_range = PERCENT_0;
+ percent_t sync_percent;
struct lvinfo info;
struct volume_group *vg = lv->vg;
/* Had disk log, switch to core. */
if (lv_info(cmd, lv, 0, &info, 0, 0) && info.exists) {
if (!lv_mirror_percent(cmd, lv, 0, &sync_percent,
- &percent_range, NULL)) {
+ NULL)) {
log_error("Unable to determine mirror sync status.");
return 0;
}
else
return 0;
- if (percent_range == PERCENT_100)
+ if (sync_percent == PERCENT_100)
init_mirror_in_sync(1);
else {
/* A full resync will take place */
struct alloc_handle *ah;
const struct segment_type *segtype;
struct dm_list *parallel_areas;
- float sync_percent;
- percent_range_t percent_range;
+ percent_t sync_percent;
int in_sync;
struct logical_volume *log_lv;
struct lvinfo info;
}
/* check sync status */
- if (lv_mirror_percent(cmd, lv, 0, &sync_percent, &percent_range,
- NULL) &&
- (percent_range == PERCENT_100))
+ if (lv_mirror_percent(cmd, lv, 0, &sync_percent, NULL) &&
+ (sync_percent == PERCENT_100))
in_sync = 1;
else
in_sync = 0;
int (*target_status_compatible) (const char *type);
int (*check_transient_status) (struct lv_segment *seg, char *params);
int (*target_percent) (void **target_state,
- percent_range_t *percent_range,
+ percent_t *percent,
struct dm_pool * mem,
struct cmd_context *cmd,
struct lv_segment *seg, char *params,
}
static int _mirrored_target_percent(void **target_state,
- percent_range_t *percent_range,
+ percent_t *percent,
struct dm_pool *mem,
struct cmd_context *cmd,
struct lv_segment *seg, char *params,
if (seg)
seg->extents_copied = seg->area_len * numerator / denominator;
- if (numerator == denominator)
- *percent_range = PERCENT_100;
- else if (numerator == 0)
- *percent_range = PERCENT_0;
- else
- *percent_range = PERCENT_0_TO_100;
+ *percent = make_percent(numerator, denominator);
return 1;
}
--- /dev/null
+/*
+ * Copyright (C) 2010 Red Hat, Inc. All rights reserved.
+ *
+ * This file is part of LVM2.
+ *
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License v.2.1.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include "lvm-percent.h"
+
+float percent_to_float(percent_t v)
+{
+ return (float)v / PERCENT_1;
+}
+
+percent_t make_percent(uint64_t numerator, uint64_t denominator)
+{
+ percent_t percent;
+ if (!denominator)
+ return PERCENT_100; /* FIXME? */
+ if (!numerator)
+ return PERCENT_0;
+ if (numerator == denominator)
+ return PERCENT_100;
+ switch (percent = PERCENT_100 * ((double) numerator / (double) denominator)) {
+ case PERCENT_100:
+ return PERCENT_100 - 1;
+ case PERCENT_0:
+ return PERCENT_0 + 1;
+ default:
+ return percent;
+ }
+}
+
--- /dev/null
+/*
+ * Copyright (C) 2010 Red Hat, Inc. All rights reserved.
+ *
+ * This file is part of LVM2.
+ *
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License v.2.1.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef _LVM_PERCENT_H
+#define _LVM_PERCENT_H
+#include <stdint.h>
+
+/*
+ * A fixed-point representation of percent values. One percent equals to
+ * PERCENT_1 as defined below. Values that are not multiples of PERCENT_1
+ * represent fractions, with precision of 1/1000000 of a percent. See
+ * percent_to_float for a conversion to a floating-point representation.
+ *
+ * You should always use make_percent when building percent_t values. The
+ * implementation of make_percent is biased towards the middle: it ensures that
+ * the result is PERCENT_0 or PERCENT_100 if and only if this is the actual
+ * value -- it never rounds any intermediate value (> 0 or < 100) to either 0
+ * or 100.
+ */
+typedef int32_t percent_t;
+
+typedef enum {
+ PERCENT_0 = 0,
+ PERCENT_1 = 1000000,
+ PERCENT_100 = 100 * PERCENT_1,
+ PERCENT_INVALID = -1
+} percent_range_t;
+
+float percent_to_float(percent_t v);
+percent_t make_percent(uint64_t numerator, uint64_t denominator);
+
+#endif
/* FIXME: write something useful for replicator here */
static int _replicator_target_percent(void **target_state,
- percent_range_t *percent_range,
+ percent_t *percent,
struct dm_pool *mem,
struct cmd_context *cmd,
struct lv_segment *seg,
/* FIXME: write something useful for replicator-dev here */
static int _replicator_dev_target_percent(void **target_state,
- percent_range_t *percent_range,
+ percent_t *percent,
struct dm_pool *mem,
struct cmd_context *cmd,
struct lv_segment *seg,
{
const struct logical_volume *lv = (const struct logical_volume *) data;
struct lvinfo info;
- float snap_percent;
- percent_range_t percent_range;
+ percent_t snap_percent;
uint64_t *sortval;
char *repstr;
return 1;
}
- if (!lv_snapshot_percent(lv, &snap_percent, &percent_range) ||
- (percent_range == PERCENT_INVALID)) {
+ if (!lv_snapshot_percent(lv, &snap_percent) ||
+ (snap_percent == PERCENT_INVALID)) {
if (!lv_is_merging_origin(lv)) {
*sortval = UINT64_C(100);
dm_report_field_set_value(field, "100.00", sortval);
return 0;
}
- if (dm_snprintf(repstr, 7, "%.2f", snap_percent) < 0) {
+ if (dm_snprintf(repstr, 7, "%.2f", percent_to_float(snap_percent)) < 0) {
log_error("snapshot percentage too large");
return 0;
}
const void *data, void *private __attribute__((unused)))
{
struct logical_volume *lv = (struct logical_volume *) data;
- float percent;
- percent_range_t percent_range;
+ percent_t percent;
uint64_t *sortval;
char *repstr;
}
if ((!(lv->status & PVMOVE) && !(lv->status & MIRRORED)) ||
- !lv_mirror_percent(lv->vg->cmd, lv, 0, &percent, &percent_range,
- NULL) || (percent_range == PERCENT_INVALID)) {
+ !lv_mirror_percent(lv->vg->cmd, lv, 0, &percent,
+ NULL) || (percent == PERCENT_INVALID)) {
*sortval = UINT64_C(0);
dm_report_field_set_value(field, "", sortval);
return 1;
}
- percent = copy_percent(lv, &percent_range);
+ percent = copy_percent(lv);
if (!(repstr = dm_pool_zalloc(mem, 8))) {
log_error("dm_pool_alloc failed");
return 0;
}
- if (dm_snprintf(repstr, 7, "%.2f", percent) < 0) {
+ if (dm_snprintf(repstr, 7, "%.2f", percent_to_float(percent)) < 0) {
log_error("copy percentage too large");
return 0;
}
#ifdef DEVMAPPER_SUPPORT
static int _snap_target_percent(void **target_state __attribute__((unused)),
- percent_range_t *percent_range,
+ percent_t *percent,
struct dm_pool *mem __attribute__((unused)),
struct cmd_context *cmd __attribute__((unused)),
struct lv_segment *seg __attribute__((unused)),
*total_numerator += sectors_allocated;
*total_denominator += total_sectors;
if (r == 3 && sectors_allocated == metadata_sectors)
- *percent_range = PERCENT_0;
+ *percent = PERCENT_0;
else if (sectors_allocated == total_sectors)
- *percent_range = PERCENT_100;
+ *percent = PERCENT_100;
else
- *percent_range = PERCENT_0_TO_100;
+ *percent = make_percent(*total_numerator, *total_denominator);
} else if (!strcmp(params, "Invalid") ||
!strcmp(params, "Merge failed"))
- *percent_range = PERCENT_INVALID;
+ *percent = PERCENT_INVALID;
else
return 0;
const char *name __attribute__((unused)),
struct daemon_parms *parms)
{
- float percent = 0.0;
- percent_range_t percent_range;
+ percent_t percent = PERCENT_0;
- if (!lv_snapshot_percent(lv, &percent, &percent_range)) {
+ if (!lv_snapshot_percent(lv, &percent)) {
log_error("%s: Failed query for merging percentage. Aborting merge.", lv->name);
return PROGRESS_CHECK_FAILED;
- } else if (percent_range == PERCENT_INVALID) {
+ } else if (percent == PERCENT_INVALID) {
log_error("%s: Merging snapshot invalidated. Aborting merge.", lv->name);
return PROGRESS_CHECK_FAILED;
}
if (parms->progress_display)
- log_print("%s: %s: %.1f%%", lv->name, parms->progress_title, percent);
+ log_print("%s: %s: %.1f%%", lv->name, parms->progress_title,
+ percent_to_float(percent));
else
- log_verbose("%s: %s: %.1f%%", lv->name, parms->progress_title, percent);
+ log_verbose("%s: %s: %.1f%%", lv->name, parms->progress_title,
+ percent_to_float(percent));
- if (percent_range == PERCENT_0)
+ if (percent == PERCENT_0)
return PROGRESS_FINISHED_ALL;
return PROGRESS_UNFINISHED;
#include <fcntl.h>
struct lvcreate_cmdline_params {
- percent_t percent;
+ percent_type_t percent;
uint64_t size;
char **pvs;
int pv_count;
return arg_count(cmd, a) ? cmd->arg_values[a].sign : def;
}
-percent_t arg_percent_value(struct cmd_context *cmd, int a, const percent_t def)
+percent_type_t arg_percent_value(struct cmd_context *cmd, int a, const percent_type_t def)
{
return arg_count(cmd, a) ? cmd->arg_values[a].percent : def;
}
uint32_t extents;
uint64_t size;
sign_t sign;
- percent_t percent;
+ percent_type_t percent;
enum {
LV_ANY = 0,
static int _adjust_policy_params(struct cmd_context *cmd,
struct logical_volume *lv, struct lvresize_params *lp)
{
- float percent;
- percent_range_t range;
+ percent_t percent;
int policy_threshold, policy_amount;
policy_threshold =
find_config_tree_int(cmd, "activation/snapshot_autoextend_threshold",
- DEFAULT_SNAPSHOT_AUTOEXTEND_THRESHOLD);
+ DEFAULT_SNAPSHOT_AUTOEXTEND_THRESHOLD) * PERCENT_1;
policy_amount =
find_config_tree_int(cmd, "activation/snapshot_autoextend_percent",
DEFAULT_SNAPSHOT_AUTOEXTEND_PERCENT);
- if (policy_threshold >= 100)
+ if (policy_threshold >= PERCENT_100)
return 1; /* nothing to do */
- if (!lv_snapshot_percent(lv, &percent, &range))
+ if (!lv_snapshot_percent(lv, &percent))
return_0;
- if (range != PERCENT_0_TO_100 || percent <= policy_threshold)
+ if (!(PERCENT_0 < percent && percent < PERCENT_100) || percent <= policy_threshold)
return 1; /* nothing to do */
lp->extents = policy_amount;
uint64_t lv_capacity_total = 0;
int inkernel, snap_active = 1;
struct lv_segment *snap_seg = NULL;
- float snap_percent; /* fused, fsize; */
- percent_range_t percent_range;
+ percent_t snap_percent; /* fused, fsize; */
const char *active_str, *snapshot_str;
origin_list) {
if (inkernel &&
(snap_active = lv_snapshot_percent(snap_seg->cow,
- &snap_percent,
- &percent_range)))
- if (percent_range == PERCENT_INVALID)
+ &snap_percent)))
+ if (snap_percent == PERCENT_INVALID)
snap_active = 0;
}
snap_seg = NULL;
} else if (lv_is_cow(lv)) {
if (inkernel &&
- (snap_active = lv_snapshot_percent(lv, &snap_percent,
- &percent_range)))
- if (percent_range == PERCENT_INVALID)
+ (snap_active = lv_snapshot_percent(lv, &snap_percent)))
+ if (snap_percent == PERCENT_INVALID)
snap_active = 0;
}
struct logical_volume *lv, const char *name,
struct daemon_parms *parms)
{
- float segment_percent = 0.0, overall_percent = 0.0;
- percent_range_t percent_range, overall_percent_range;
+ percent_t segment_percent = PERCENT_0, overall_percent = PERCENT_0;
uint32_t event_nr = 0;
if (!lv_is_mirrored(lv) ||
!lv_mirror_percent(cmd, lv, !parms->interval, &segment_percent,
- &percent_range, &event_nr) ||
- (percent_range == PERCENT_INVALID)) {
+ &event_nr) ||
+ (segment_percent == PERCENT_INVALID)) {
log_error("ABORTING: Mirror percentage check failed.");
return PROGRESS_CHECK_FAILED;
}
- overall_percent = copy_percent(lv, &overall_percent_range);
+ overall_percent = copy_percent(lv);
if (parms->progress_display)
log_print("%s: %s: %.1f%%", name, parms->progress_title,
- overall_percent);
+ percent_to_float(overall_percent));
else
log_verbose("%s: %s: %.1f%%", name, parms->progress_title,
- overall_percent);
+ percent_to_float(overall_percent));
- if (percent_range != PERCENT_100)
+ if (segment_percent != PERCENT_100)
return PROGRESS_UNFINISHED;
- if (overall_percent_range == PERCENT_100)
+ if (overall_percent == PERCENT_100)
return PROGRESS_FINISHED_ALL;
return PROGRESS_FINISHED_SEGMENT;
PERCENT_LV,
PERCENT_PVS,
PERCENT_ORIGIN
-} percent_t;
+} percent_type_t;
enum {
CHANGE_AY = 0,
int64_t i64_value;
uint64_t ui64_value;
sign_t sign;
- percent_t percent;
+ percent_type_t percent;
/* void *ptr; // Currently not used. */
};
uint64_t arg_uint64_value(struct cmd_context *cmd, int a, const uint64_t def);
const void *arg_ptr_value(struct cmd_context *cmd, int a, const void *def);
sign_t arg_sign_value(struct cmd_context *cmd, int a, const sign_t def);
-percent_t arg_percent_value(struct cmd_context *cmd, int a, const percent_t def);
+percent_type_t arg_percent_value(struct cmd_context *cmd, int a, const percent_type_t def);
int arg_count_increment(struct cmd_context *cmd, int a);
unsigned grouped_arg_count(const struct arg_values *av, int a);