]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
Split 'GCD' out into a separate function.
authorNeilBrown <neilb@suse.de>
Thu, 4 Oct 2012 06:34:21 +0000 (16:34 +1000)
committerNeilBrown <neilb@suse.de>
Thu, 4 Oct 2012 06:34:21 +0000 (16:34 +1000)
It is neater that way.

Signed-off-by: NeilBrown <neilb@suse.de>
Grow.c

diff --git a/Grow.c b/Grow.c
index f6fe1683234f2393f23dabf4e74dd1dc31e0b9e9..ba00f2757e853aee3eb94fb6911c5ba7157ef53c 100644 (file)
--- a/Grow.c
+++ b/Grow.c
@@ -938,6 +938,17 @@ int reshape_open_backup_file(char *backup_file,
        return 1;
 }
 
+unsigned long GCD(unsigned long a, unsigned long b)
+{
+       while (a != b) {
+               if (a < b)
+                       b -= a;
+               if (b < a)
+                       a -= b;
+       }
+       return a;
+}
+
 unsigned long compute_backup_blocks(int nchunk, int ochunk,
                                    unsigned int ndata, unsigned int odata)
 {
@@ -950,12 +961,7 @@ unsigned long compute_backup_blocks(int nchunk, int ochunk,
        a = (ochunk/512) * odata;
        b = (nchunk/512) * ndata;
        /* Find GCD */
-       while (a != b) {
-               if (a < b)
-                       b -= a;
-               if (b < a)
-                       a -= b;
-       }
+       a = GCD(a, b);
        /* LCM == product / GCD */
        blocks = (ochunk/512) * (nchunk/512) * odata * ndata / a;