]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
Fix wrong bitmap output for cluster raid
authorGuoqing Jiang <gqjiang@suse.com>
Mon, 7 Mar 2016 09:31:02 +0000 (17:31 +0800)
committerJes Sorensen <Jes.Sorensen@redhat.com>
Mon, 7 Mar 2016 20:21:02 +0000 (15:21 -0500)
For cluster raid, we need to displays bitmap related
contents from different bitmaps which are based on node
num. So bitmap_file_open and locate_bitmap are changed a
little bit for the purpose.

Reported-by: Jes Sorensen <Jes.Sorensen@redhat.com>
Fixes: b98043a2f8 ("Show all bitmaps while examining bitmap")
Signed-off-by: Guoqing Jiang <gqjiang@suse.com>
Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
bitmap.c
mdadm.h
super0.c
super1.c

index dab674b4cdd0d347bb58b6a30f175ba82d519c43..5ad7401bed0735d2763e697dc508396cba303c03 100644 (file)
--- a/bitmap.c
+++ b/bitmap.c
@@ -194,7 +194,7 @@ out:
        return info;
 }
 
-int bitmap_file_open(char *filename, struct supertype **stp)
+int bitmap_file_open(char *filename, struct supertype **stp, int node_num)
 {
        int fd;
        struct stat stb;
@@ -222,7 +222,7 @@ int bitmap_file_open(char *filename, struct supertype **stp)
                                st->ss->name);
                        return -1;
                } else {
-                       if (st->ss->locate_bitmap(st, fd)) {
+                       if (st->ss->locate_bitmap(st, fd, node_num)) {
                                pr_err("%s doesn't have bitmap\n", filename);
                                fd = -1;
                        }
@@ -267,7 +267,7 @@ int ExamineBitmap(char *filename, int brief, struct supertype *st)
        int fd, i;
        __u32 uuid32[4];
 
-       fd = bitmap_file_open(filename, &st);
+       fd = bitmap_file_open(filename, &st, 0);
        if (fd < 0)
                return rv;
 
@@ -348,11 +348,11 @@ int ExamineBitmap(char *filename, int brief, struct supertype *st)
                printf("   Cluster nodes : %d\n", sb->nodes);
                printf("    Cluster name : %-64s\n", sb->cluster_name);
                for (i = 0; i < (int)sb->nodes; i++) {
-                       if (i) {
-                               free(info);
-                               info = bitmap_fd_read(fd, brief);
-                               sb = &info->sb;
-                       }
+                       st = NULL;
+                       free(info);
+                       fd = bitmap_file_open(filename, &st, i);
+                       info = bitmap_fd_read(fd, brief);
+                       sb = &info->sb;
                        if (sb->magic != BITMAP_MAGIC)
                                pr_err("invalid bitmap magic 0x%x, the bitmap file appears to be corrupted\n", sb->magic);
 
@@ -367,7 +367,7 @@ int ExamineBitmap(char *filename, int brief, struct supertype *st)
                        printf("          Bitmap : %llu bits (chunks), %llu dirty (%2.1f%%)\n",
                               info->total_bits, info->dirty_bits,
                               100.0 * info->dirty_bits / (info->total_bits?:1));
-
+                        close(fd);
                }
        }
 
diff --git a/mdadm.h b/mdadm.h
index 72888e2dccc75248f8b7feb5e03467ca2f0c4cf8..355c455630f095e2bc902f87314758de334a8a23 100755 (executable)
--- a/mdadm.h
+++ b/mdadm.h
@@ -904,7 +904,7 @@ extern struct superswitch {
        /* Seek 'fd' to start of write-intent-bitmap.  Must be an
         * md-native format bitmap
         */
-       int (*locate_bitmap)(struct supertype *st, int fd);
+       int (*locate_bitmap)(struct supertype *st, int fd, int node_num);
        /* if add_internal_bitmap succeeded for existing array, this
         * writes it out.
         */
index 59a6a034fb6a2ba5bd442e771b357fc7ce1085f8..6fc1ac4f27c5e9cb0e4957cb38b0f6d9747a8086 100644 (file)
--- a/super0.c
+++ b/super0.c
@@ -1156,7 +1156,7 @@ static int add_internal_bitmap0(struct supertype *st, int *chunkp,
        return 1;
 }
 
-static int locate_bitmap0(struct supertype *st, int fd)
+static int locate_bitmap0(struct supertype *st, int fd, int node_num)
 {
        unsigned long long dsize;
        unsigned long long offset;
index 9b877e504c4bd05c255e5cdddf996effc84ae72b..f8a35ac1ecd4de387f7e7c22a42ebca8d3340590 100644 (file)
--- a/super1.c
+++ b/super1.c
@@ -1548,7 +1548,7 @@ static int add_to_super1(struct supertype *st, mdu_disk_info_t *dk,
 }
 #endif
 
-static int locate_bitmap1(struct supertype *st, int fd);
+static int locate_bitmap1(struct supertype *st, int fd, int node_num);
 
 static int store_super1(struct supertype *st, int fd)
 {
@@ -1622,7 +1622,7 @@ static int store_super1(struct supertype *st, int fd)
                struct bitmap_super_s *bm = (struct bitmap_super_s*)
                        (((char*)sb)+MAX_SB_SIZE);
                if (__le32_to_cpu(bm->magic) == BITMAP_MAGIC) {
-                       locate_bitmap1(st, fd);
+                       locate_bitmap1(st, fd, 0);
                        if (awrite(&afd, bm, sizeof(*bm)) != sizeof(*bm))
                                return 5;
                }
@@ -2062,7 +2062,7 @@ static int load_super1(struct supertype *st, int fd, char *devname)
         * valid.  If it doesn't clear the bit.  An --assemble --force
         * should get that written out.
         */
-       locate_bitmap1(st, fd);
+       locate_bitmap1(st, fd, 0);
        if (aread(&afd, bsb, 512) != 512)
                goto no_bitmap;
 
@@ -2334,7 +2334,7 @@ add_internal_bitmap1(struct supertype *st,
        return 1;
 }
 
-static int locate_bitmap1(struct supertype *st, int fd)
+static int locate_bitmap1(struct supertype *st, int fd, int node_num)
 {
        unsigned long long offset;
        struct mdp_superblock_1 *sb;
@@ -2353,7 +2353,7 @@ static int locate_bitmap1(struct supertype *st, int fd)
        else
                ret = -1;
        offset = __le64_to_cpu(sb->super_offset);
-       offset += (int32_t) __le32_to_cpu(sb->bitmap_offset);
+       offset += (int32_t) __le32_to_cpu(sb->bitmap_offset) * (node_num + 1);
        if (mustfree)
                free(sb);
        lseek64(fd, offset<<9, 0);
@@ -2408,7 +2408,7 @@ static int write_bitmap1(struct supertype *st, int fd, enum bitmap_update update
 
        init_afd(&afd, fd);
 
-       locate_bitmap1(st, fd);
+       locate_bitmap1(st, fd, 0);
 
        if (posix_memalign(&buf, 4096, 4096))
                return -ENOMEM;