]> sourceware.org Git - dm.git/commitdiff
Provide snapshot status as a fraction.
authorAlasdair Kergon <agk@redhat.com>
Tue, 15 Apr 2003 14:00:07 +0000 (14:00 +0000)
committerAlasdair Kergon <agk@redhat.com>
Tue, 15 Apr 2003 14:00:07 +0000 (14:00 +0000)
kernel/common/dm-exception-store.c
kernel/common/dm-snapshot.c
kernel/common/dm-snapshot.h

index f406525783e18d755708ba3b1ef38ec72cac63b4..cbb733546fc06ad680b3fa7484067364144413b4 100644 (file)
@@ -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);
index e894888c93c326e3b1c12757c727e6840027a93e..eafa15deae6e8df5340c656c6a46b6831b9388b1 100644 (file)
@@ -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;
index 26b92379f22b5d08c82e901fce6287c2c7983bcf..97a28cd8bdb17c52c808c1fee151fc156293819a 100644 (file)
@@ -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;
This page took 0.031666 seconds and 5 git commands to generate.