]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - restripe.c
Consistently print program Name and __func__ in debug messages.
[thirdparty/mdadm.git] / restripe.c
index 9aaf707a7246c70d1c44c5f9b537379843e1ced8..93ef056e12ceaf3ac13746d34829a8219db0862d 100644 (file)
@@ -83,7 +83,6 @@ int geo_map(int block, unsigned long long stripe, int raid_disks,
        case 500 + ALGORITHM_PARITY_0:
                return block + 1;
 
-
        case 600 + ALGORITHM_PARITY_N_6:
                if (block == -2)
                        return raid_disks - 1;
@@ -131,7 +130,6 @@ int geo_map(int block, unsigned long long stripe, int raid_disks,
                        return raid_disks - 1;
                return block + 1;
 
-
        case 600 + ALGORITHM_PARITY_0:
                if (block == -1)
                        return 0;
@@ -173,7 +171,6 @@ int geo_map(int block, unsigned long long stripe, int raid_disks,
                if (block == -2) return (pd+1) % raid_disks;
                return (pd + 2 + block) % raid_disks;
 
-
        case 600 + ALGORITHM_ROTATING_N_RESTART:
                /* Same a left_asymmetric, by first stripe is
                 * D D D P Q  rather than
@@ -210,8 +207,7 @@ static int is_ddf(int layout)
        }
 }
 
-
-static void xor_blocks(char *target, char **sources, int disks, int size)
+void xor_blocks(char *target, char **sources, int disks, int size)
 {
        int i, j;
        /* Amazingly inefficient... */
@@ -243,7 +239,6 @@ void qsyndrome(uint8_t *p, uint8_t *q, uint8_t **sources, int disks, int size)
        }
 }
 
-
 /*
  * The following was taken from linux/drivers/md/mktables.c, and modified
  * to create in-memory tables rather than C code
@@ -335,6 +330,17 @@ void make_tables(void)
 
 uint8_t *zero;
 int zero_size;
+
+void ensure_zero_has_size(int chunk_size)
+{
+       if (zero == NULL || chunk_size > zero_size) {
+               if (zero)
+                       free(zero);
+               zero = xcalloc(1, chunk_size);
+               zero_size = chunk_size;
+       }
+}
+
 /* Following was taken from linux/drivers/md/raid6recov.c */
 
 /* Recover two failed data blocks. */
@@ -425,11 +431,9 @@ int raid6_check_disks(int data_disks, int start, int chunk_size,
                if((Px != 0) && (Qx == 0))
                        curr_broken_disk = diskP;
 
-
                if((Px == 0) && (Qx != 0))
                        curr_broken_disk = diskQ;
 
-
                if((Px != 0) && (Qx != 0)) {
                        data_id = (raid6_gflog[Qx] - raid6_gflog[Px]);
                        if(data_id < 0) data_id += 255;
@@ -510,13 +514,7 @@ int save_stripes(int *source, unsigned long long *offsets,
 
        if (!tables_ready)
                make_tables();
-
-       if (zero == NULL || chunk_size > zero_size) {
-               if (zero)
-                       free(zero);
-               zero = xcalloc(1, chunk_size);
-               zero_size = chunk_size;
-       }
+       ensure_zero_has_size(chunk_size);
 
        len = data_disks * chunk_size;
        length_test = length / len;
@@ -775,7 +773,7 @@ int restore_stripes(int *dest, unsigned long long *offsets,
                                syndrome_disks = data_disks;
                        }
                        qsyndrome((uint8_t*)stripes[disk],
-                                 (uint8_t*)stripes[qdisk], 
+                                 (uint8_t*)stripes[qdisk],
                                  (uint8_t**)blocks,
                                  syndrome_disks, chunk_size);
                        break;
@@ -948,7 +946,7 @@ main(int argc, char *argv[])
                        *p++ = '\0';
                        offsets[i] = atoll(p) * 512;
                }
-                       
+
                fds[i] = open(argv[9+i], O_RDWR);
                if (fds[i] < 0) {
                        perror(argv[9+i]);
@@ -993,26 +991,4 @@ main(int argc, char *argv[])
        exit(0);
 }
 
-
-void *xmalloc(size_t len)
-{
-       void *rv = malloc(len);
-       char *msg;
-       if (rv)
-               return rv;
-       msg = Name ": memory allocation failure - aborting\n";
-       write(2, msg, strlen(msg));
-       exit(4);
-}
-
-void *xcalloc(size_t num, size_t size)
-{
-       void *rv = calloc(num, size);
-       char *msg;
-       if (rv)
-               return rv;
-       msg = Name ": memory allocation failure - aborting\n";
-       write(2, msg, strlen(msg));
-       exit(4);
-}
 #endif /* MAIN */