]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - bitmap.c
{platform,super}-intel: Fix two resource leaks
[thirdparty/mdadm.git] / bitmap.c
index 920033ad38893e56e18933967871e255cf485c43..5ad7401bed0735d2763e697dc508396cba303c03 100644 (file)
--- a/bitmap.c
+++ b/bitmap.c
@@ -20,7 +20,7 @@
 
 #include "mdadm.h"
 
-inline void sb_le_to_cpu(bitmap_super_t *sb)
+static inline void sb_le_to_cpu(bitmap_super_t *sb)
 {
        sb->magic = __le32_to_cpu(sb->magic);
        sb->version = __le32_to_cpu(sb->version);
@@ -36,7 +36,7 @@ inline void sb_le_to_cpu(bitmap_super_t *sb)
        sb->sectors_reserved = __le32_to_cpu(sb->sectors_reserved);
 }
 
-inline void sb_cpu_to_le(bitmap_super_t *sb)
+static inline void sb_cpu_to_le(bitmap_super_t *sb)
 {
        sb_le_to_cpu(sb); /* these are really the same thing */
 }
@@ -76,7 +76,7 @@ typedef struct bitmap_info_s {
 } bitmap_info_t;
 
 /* count the dirty bits in the first num_bits of byte */
-inline int count_dirty_bits_byte(char byte, int num_bits)
+static inline int count_dirty_bits_byte(char byte, int num_bits)
 {
        int num = 0;
 
@@ -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;
@@ -221,8 +221,12 @@ int bitmap_file_open(char *filename, struct supertype **stp)
                        pr_err("No bitmap possible with %s metadata\n",
                                st->ss->name);
                        return -1;
-               } else
-                       st->ss->locate_bitmap(st, fd);
+               } else {
+                       if (st->ss->locate_bitmap(st, fd, node_num)) {
+                               pr_err("%s doesn't have bitmap\n", filename);
+                               fd = -1;
+                       }
+               }
 
                *stp = st;
        } else {
@@ -260,10 +264,10 @@ int ExamineBitmap(char *filename, int brief, struct supertype *st)
        int rv = 1;
        char buf[64];
        int swap;
-       int fd;
+       int fd, i;
        __u32 uuid32[4];
 
-       fd = bitmap_file_open(filename, &st);
+       fd = bitmap_file_open(filename, &st, 0);
        if (fd < 0)
                return rv;
 
@@ -287,7 +291,7 @@ int ExamineBitmap(char *filename, int brief, struct supertype *st)
        }
        printf("         Version : %d\n", sb->version);
        if (sb->version < BITMAP_MAJOR_LO ||
-           sb->version > BITMAP_MAJOR_HI) {
+           sb->version > BITMAP_MAJOR_CLUSTERED) {
                pr_err("unknown bitmap version %d, either the bitmap file\n",
                       sb->version);
                pr_err("is corrupted or you need to upgrade your tools\n");
@@ -317,9 +321,13 @@ int ExamineBitmap(char *filename, int brief, struct supertype *st)
                       uuid32[2],
                       uuid32[3]);
 
-       printf("          Events : %llu\n", (unsigned long long)sb->events);
-       printf("  Events Cleared : %llu\n", (unsigned long long)sb->events_cleared);
-       printf("           State : %s\n", bitmap_state(sb->state));
+       if (sb->nodes == 0) {
+               printf("          Events : %llu\n", (unsigned long long)sb->events);
+               printf("  Events Cleared : %llu\n", (unsigned long long)sb->events_cleared);
+               printf("           State : %s\n", bitmap_state(sb->state));
+
+       }
+
        printf("       Chunksize : %s\n", human_chunksize(sb->chunksize));
        printf("          Daemon : %ds flush period\n", sb->daemon_sleep);
        if (sb->write_behind)
@@ -329,11 +337,40 @@ int ExamineBitmap(char *filename, int brief, struct supertype *st)
        printf("      Write Mode : %s\n", buf);
        printf("       Sync Size : %llu%s\n", (unsigned long long)sb->sync_size/2,
                                        human_size(sb->sync_size * 512));
-       if (brief)
-               goto free_info;
-       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));
+
+       if (sb->nodes == 0) {
+               if (brief)
+                       goto free_info;
+               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));
+       } else {
+               printf("   Cluster nodes : %d\n", sb->nodes);
+               printf("    Cluster name : %-64s\n", sb->cluster_name);
+               for (i = 0; i < (int)sb->nodes; i++) {
+                       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);
+
+                       printf("       Node Slot : %d\n", i);
+                       printf("          Events : %llu\n",
+                              (unsigned long long)sb->events);
+                       printf("  Events Cleared : %llu\n",
+                              (unsigned long long)sb->events_cleared);
+                       printf("           State : %s\n", bitmap_state(sb->state));
+                       if (brief)
+                               continue;
+                       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);
+               }
+       }
+
 free_info:
        free(info);
        return rv;