From: Alasdair Kergon Date: Tue, 15 Apr 2003 14:00:07 +0000 (+0000) Subject: Provide snapshot status as a fraction. X-Git-Tag: beta8~26 X-Git-Url: https://sourceware.org/git/?a=commitdiff_plain;h=eec23e6195d77b46bf39159154e7fa7e132219cf;p=dm.git Provide snapshot status as a fraction. --- diff --git a/kernel/common/dm-exception-store.c b/kernel/common/dm-exception-store.c index f406525..cbb7335 100644 --- a/kernel/common/dm-exception-store.c +++ b/kernel/common/dm-exception-store.c @@ -427,11 +427,12 @@ static inline struct pstore *get_info(struct exception_store *store) return (struct pstore *) store->context; } -static int persistent_percentfull(struct exception_store *store) +static void persistent_fraction_full(struct exception_store *store, + sector_t *numerator, + sector_t *denominator) { - struct pstore *ps = get_info(store); - return (ps->next_free * store->snap->chunk_size * 100) / - get_dev_size(store->snap->cow->dev); + *numerator = get_info(store)->next_free * store->snap->chunk_size - 1; + *denominator = get_dev_size(store->snap->cow->dev); } static void persistent_destroy(struct exception_store *store) @@ -596,7 +597,7 @@ int dm_create_persistent(struct exception_store *store, uint32_t chunk_size) if (!ps->valid) { DMWARN("snapshot is marked invalid"); r = -EINVAL; - goto bad; + goto bad; } if (ps->chunk_size != chunk_size) { @@ -625,7 +626,7 @@ int dm_create_persistent(struct exception_store *store, uint32_t chunk_size) store->prepare_exception = persistent_prepare; store->commit_exception = persistent_commit; store->drop_snapshot = persistent_drop; - store->percent_full = persistent_percentfull; + store->fraction_full = persistent_fraction_full; store->context = ps; return r; @@ -678,10 +679,12 @@ void transient_commit(struct exception_store *store, callback(callback_context, 1); } -static int transient_percentfull(struct exception_store *store) +static void transient_fraction_full(struct exception_store *store, + sector_t *numerator, + sector_t *denominator) { - struct transient_c *tc = (struct transient_c *) store->context; - return (tc->next_free * 100) / get_dev_size(store->snap->cow->dev); + *numerator = ((struct transient_c *) store->context)->next_free; + *denominator = get_dev_size(store->snap->cow->dev); } int dm_create_transient(struct exception_store *store, @@ -693,7 +696,7 @@ int dm_create_transient(struct exception_store *store, store->destroy = transient_destroy; store->prepare_exception = transient_prepare; store->commit_exception = transient_commit; - store->percent_full = transient_percentfull; + store->fraction_full = transient_fraction_full; store->snap = s; tc = kmalloc(sizeof(struct transient_c), GFP_KERNEL); diff --git a/kernel/common/dm-snapshot.c b/kernel/common/dm-snapshot.c index e894888..eafa15d 100644 --- a/kernel/common/dm-snapshot.c +++ b/kernel/common/dm-snapshot.c @@ -650,8 +650,13 @@ static void pending_complete(struct pending_exception *pe, int success) DMDEBUG("Exception completed successfully."); /* Notify any interested parties */ - if (s->store.percent_full) { - int pc = s->store.percent_full(&s->store); + if (s->store.fraction_full) { + sector_t numerator, denominator; + int pc; + + s->store.fraction_full(&s->store, &numerator, + &denominator); + pc = numerator * 100 / denominator; if (pc >= s->last_percent + WAKE_UP_PERCENT) { dm_table_event(s->table); @@ -947,11 +952,15 @@ static int snapshot_status(struct dm_target *ti, status_type_t type, if (!snap->valid) snprintf(result, maxlen, "Invalid"); else { - if (snap->store.percent_full) - snprintf(result, maxlen, "%d%%", - snap->store.percent_full(&snap-> - store)); - else + if (snap->store.fraction_full) { + sector_t numerator, denominator; + snap->store.fraction_full(&snap->store, + &numerator, + &denominator); + snprintf(result, maxlen, + SECTOR_FORMAT "/" SECTOR_FORMAT, + numerator, denominator); + } else snprintf(result, maxlen, "Unknown"); } break; diff --git a/kernel/common/dm-snapshot.h b/kernel/common/dm-snapshot.h index 26b9237..97a28cd 100644 --- a/kernel/common/dm-snapshot.h +++ b/kernel/common/dm-snapshot.h @@ -68,7 +68,9 @@ struct exception_store { /* * Return the %age full of the snapshot */ - int (*percent_full) (struct exception_store *store); + void (*fraction_full) (struct exception_store *store, + sector_t *numerator, + sector_t *denominator); struct dm_snapshot *snap; void *context;