]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
Compute backup blocks in function.
authorAdam Kwolek <adam.kwolek@intel.com>
Tue, 30 Nov 2010 02:30:22 +0000 (13:30 +1100)
committerNeilBrown <neilb@suse.de>
Tue, 30 Nov 2010 02:30:22 +0000 (13:30 +1100)
number of backup blocks evaluation is put in to function for code reuse.

Signed-off-by: Adam Kwolek <adam.kwolek@intel.com>
Signed-off-by: NeilBrown <neilb@suse.de>
Grow.c
mdadm.h

diff --git a/Grow.c b/Grow.c
index eb19c93ba618fd7704688f87463b21c56da787b1..d7c7553200dafd83383bdecfe9d8489f8bc89b45 100644 (file)
--- a/Grow.c
+++ b/Grow.c
@@ -905,6 +905,31 @@ release:
        return d;
 }
 
+unsigned long compute_backup_blocks(int nchunk, int ochunk,
+                                   unsigned int ndata, unsigned int odata)
+{
+       unsigned long a, b, blocks;
+       /* So how much do we need to backup.
+        * We need an amount of data which is both a whole number of
+        * old stripes and a whole number of new stripes.
+        * So LCM for (chunksize*datadisks).
+        */
+       a = (ochunk/512) * odata;
+       b = (nchunk/512) * ndata;
+       /* Find GCD */
+       while (a != b) {
+               if (a < b)
+                       b -= a;
+               if (b < a)
+                       a -= b;
+       }
+       /* LCM == product / GCD */
+       blocks = (ochunk/512) * (nchunk/512) * odata * ndata / a;
+
+       return blocks;
+}
+
+
 int Grow_reshape(char *devname, int fd, int quiet, char *backup_file,
                 long long size,
                 int level, char *layout_str, int chunksize, int raid_disks)
@@ -944,7 +969,7 @@ int Grow_reshape(char *devname, int fd, int quiet, char *backup_file,
        int nrdisks;
        int err;
        int frozen;
-       unsigned long a,b, blocks, stripes;
+       unsigned long blocks, stripes;
        unsigned long cache;
        unsigned long long array_size;
        int changed = 0;
@@ -1534,22 +1559,7 @@ int Grow_reshape(char *devname, int fd, int quiet, char *backup_file,
                        break;
                }
 
-               /* So how much do we need to backup.
-                * We need an amount of data which is both a whole number of
-                * old stripes and a whole number of new stripes.
-                * So LCM for (chunksize*datadisks).
-                */
-               a = (ochunk/512) * odata;
-               b = (nchunk/512) * ndata;
-               /* Find GCD */
-               while (a != b) {
-                       if (a < b)
-                               b -= a;
-                       if (b < a)
-                               a -= b;
-               }
-               /* LCM == product / GCD */
-               blocks = (ochunk/512) * (nchunk/512) * odata * ndata / a;
+               blocks = compute_backup_blocks(nchunk, ochunk, ndata, odata);
 
                sysfs_free(sra);
                sra = sysfs_read(fd, 0,
diff --git a/mdadm.h b/mdadm.h
index 3a1b66db7641ca2b877f4ca511dcc44954fff7f2..05bf0b8de92314e9ee3048b6fcba7edf1ce60a75 100644 (file)
--- a/mdadm.h
+++ b/mdadm.h
@@ -487,6 +487,8 @@ extern void reshape_free_fdlist(int *fdlist,
                                unsigned long long *offsets,
                                int size);
 
+extern unsigned long compute_backup_blocks(int nchunk, int ochunk,
+                                          unsigned int ndata, unsigned int odata);
 
 extern int save_stripes(int *source, unsigned long long *offsets,
                        int raid_disks, int chunk_size, int level, int layout,