bitmap.c (mdadm-4.1) | : | bitmap.c (mdadm-4.2) | ||
---|---|---|---|---|
skipping to change at line 183 | skipping to change at line 183 | |||
total_bits = read_bits; | total_bits = read_bits; | |||
} | } | |||
out: | out: | |||
free(buf); | free(buf); | |||
info->total_bits = total_bits; | info->total_bits = total_bits; | |||
info->dirty_bits = dirty_bits; | info->dirty_bits = dirty_bits; | |||
return info; | return info; | |||
} | } | |||
static int | static int | |||
bitmap_file_open(char *filename, struct supertype **stp, int node_num) | bitmap_file_open(char *filename, struct supertype **stp, int node_num, int fd) | |||
{ | { | |||
int fd; | ||||
struct stat stb; | struct stat stb; | |||
struct supertype *st = *stp; | struct supertype *st = *stp; | |||
fd = open(filename, O_RDONLY|O_DIRECT); | /* won't re-open filename when (fd >= 0) */ | |||
if (fd < 0) | ||||
fd = open(filename, O_RDONLY|O_DIRECT); | ||||
if (fd < 0) { | if (fd < 0) { | |||
pr_err("failed to open bitmap file %s: %s\n", | pr_err("failed to open bitmap file %s: %s\n", | |||
filename, strerror(errno)); | filename, strerror(errno)); | |||
return -1; | return -1; | |||
} | } | |||
if (fstat(fd, &stb) < 0) { | if (fstat(fd, &stb) < 0) { | |||
pr_err("fstat failed for %s: %s\n", filename, strerror(errno)); | pr_err("fstat failed for %s: %s\n", filename, strerror(errno)); | |||
close(fd); | close(fd); | |||
return -1; | return -1; | |||
skipping to change at line 252 | skipping to change at line 253 | |||
*/ | */ | |||
bitmap_super_t *sb; | bitmap_super_t *sb; | |||
bitmap_info_t *info; | bitmap_info_t *info; | |||
int rv = 1; | int rv = 1; | |||
char buf[64]; | char buf[64]; | |||
int swap; | int swap; | |||
int fd, i; | int fd, i; | |||
__u32 uuid32[4]; | __u32 uuid32[4]; | |||
fd = bitmap_file_open(filename, &st, 0); | fd = bitmap_file_open(filename, &st, 0, -1); | |||
if (fd < 0) | if (fd < 0) | |||
return rv; | return rv; | |||
info = bitmap_fd_read(fd, brief); | info = bitmap_fd_read(fd, brief); | |||
if (!info) | if (!info) | |||
return rv; | return rv; | |||
sb = &info->sb; | sb = &info->sb; | |||
if (sb->magic != BITMAP_MAGIC) { | if (sb->magic != BITMAP_MAGIC) { | |||
pr_err("This is an md array. To view a bitmap you need to examin e\n"); | pr_err("This is an md array. To view a bitmap you need to examin e\n"); | |||
pr_err("a member device, not the array.\n"); | pr_err("a member device, not the array.\n"); | |||
pr_err("Reporting bitmap that would be used if this array were us ed\n"); | pr_err("Reporting bitmap that would be used if this array were us ed\n"); | |||
pr_err("as a member of some other array\n"); | pr_err("as a member of some other array\n"); | |||
} | } | |||
close(fd); | ||||
printf(" Filename : %s\n", filename); | printf(" Filename : %s\n", filename); | |||
printf(" Magic : %08x\n", sb->magic); | printf(" Magic : %08x\n", sb->magic); | |||
if (sb->magic != BITMAP_MAGIC) { | if (sb->magic != BITMAP_MAGIC) { | |||
pr_err("invalid bitmap magic 0x%x, the bitmap file appears\n", | pr_err("invalid bitmap magic 0x%x, the bitmap file appears\n", | |||
sb->magic); | sb->magic); | |||
pr_err("to be corrupted or missing.\n"); | pr_err("to be corrupted or missing.\n"); | |||
} | } | |||
printf(" Version : %d\n", sb->version); | printf(" Version : %d\n", sb->version); | |||
if (sb->version < BITMAP_MAJOR_LO || | if (sb->version < BITMAP_MAJOR_LO || | |||
sb->version > BITMAP_MAJOR_CLUSTERED) { | sb->version > BITMAP_MAJOR_CLUSTERED) { | |||
skipping to change at line 335 | skipping to change at line 335 | |||
goto free_info; | goto free_info; | |||
printf(" Bitmap : %llu bits (chunks), %llu dirty (%2.1f% %)\n", | printf(" Bitmap : %llu bits (chunks), %llu dirty (%2.1f% %)\n", | |||
info->total_bits, info->dirty_bits, | info->total_bits, info->dirty_bits, | |||
100.0 * info->dirty_bits / (info->total_bits?:1)); | 100.0 * info->dirty_bits / (info->total_bits?:1)); | |||
} else { | } else { | |||
printf(" Cluster nodes : %d\n", sb->nodes); | printf(" Cluster nodes : %d\n", sb->nodes); | |||
printf(" Cluster name : %-64s\n", sb->cluster_name); | printf(" Cluster name : %-64s\n", sb->cluster_name); | |||
for (i = 0; i < (int)sb->nodes; i++) { | for (i = 0; i < (int)sb->nodes; i++) { | |||
st = NULL; | st = NULL; | |||
free(info); | free(info); | |||
fd = bitmap_file_open(filename, &st, i); | fd = bitmap_file_open(filename, &st, i, fd); | |||
if (fd < 0) { | if (fd < 0) { | |||
printf(" Unable to open bitmap file on node: %i \n", i); | printf(" Unable to open bitmap file on node: %i \n", i); | |||
continue; | continue; | |||
} | } | |||
info = bitmap_fd_read(fd, brief); | info = bitmap_fd_read(fd, brief); | |||
if (!info) { | if (!info) { | |||
close(fd); | ||||
printf(" Unable to read bitmap on node: %i\n", i); | printf(" Unable to read bitmap on node: %i\n", i); | |||
continue; | continue; | |||
} | } | |||
sb = &info->sb; | sb = &info->sb; | |||
if (sb->magic != BITMAP_MAGIC) | if (sb->magic != BITMAP_MAGIC) | |||
pr_err("invalid bitmap magic 0x%x, the bitmap fil e appears to be corrupted\n", sb->magic); | pr_err("invalid bitmap magic 0x%x, the bitmap fil e appears to be corrupted\n", sb->magic); | |||
printf(" Node Slot : %d\n", i); | printf(" Node Slot : %d\n", i); | |||
printf(" Events : %llu\n", | printf(" Events : %llu\n", | |||
(unsigned long long)sb->events); | (unsigned long long)sb->events); | |||
printf(" Events Cleared : %llu\n", | printf(" Events Cleared : %llu\n", | |||
(unsigned long long)sb->events_cleared); | (unsigned long long)sb->events_cleared); | |||
printf(" State : %s\n", bitmap_state(sb->state) ); | printf(" State : %s\n", bitmap_state(sb->state) ); | |||
if (brief) | if (brief) | |||
continue; | continue; | |||
printf(" Bitmap : %llu bits (chunks), %llu dirty (%2.1f%%)\n", | printf(" Bitmap : %llu bits (chunks), %llu dirty (%2.1f%%)\n", | |||
info->total_bits, info->dirty_bits, | info->total_bits, info->dirty_bits, | |||
100.0 * info->dirty_bits / (info->total_bits?:1)); | 100.0 * info->dirty_bits / (info->total_bits?:1)); | |||
close(fd); | ||||
} | } | |||
} | } | |||
free_info: | free_info: | |||
close(fd); | ||||
free(info); | free(info); | |||
return rv; | return rv; | |||
} | } | |||
int IsBitmapDirty(char *filename) | ||||
{ | ||||
/* | ||||
* Read the bitmap file | ||||
* It will break reading bitmap action immediately when meeting any error | ||||
. | ||||
* | ||||
* Return: 1(dirty), 0 (clean), -1(error) | ||||
*/ | ||||
int fd = -1, rv = 0, i; | ||||
struct supertype *st = NULL; | ||||
bitmap_info_t *info = NULL; | ||||
bitmap_super_t *sb = NULL; | ||||
fd = bitmap_file_open(filename, &st, 0, fd); | ||||
free(st); | ||||
if (fd < 0) | ||||
goto out; | ||||
info = bitmap_fd_read(fd, 0); | ||||
if (!info) { | ||||
close(fd); | ||||
goto out; | ||||
} | ||||
sb = &info->sb; | ||||
for (i = 0; i < (int)sb->nodes; i++) { | ||||
st = NULL; | ||||
free(info); | ||||
info = NULL; | ||||
fd = bitmap_file_open(filename, &st, i, fd); | ||||
free(st); | ||||
if (fd < 0) | ||||
goto out; | ||||
info = bitmap_fd_read(fd, 0); | ||||
if (!info) { | ||||
close(fd); | ||||
goto out; | ||||
} | ||||
sb = &info->sb; | ||||
if (sb->magic != BITMAP_MAGIC) { /* invalid bitmap magic */ | ||||
free(info); | ||||
close(fd); | ||||
goto out; | ||||
} | ||||
if (info->dirty_bits) | ||||
rv = 1; | ||||
} | ||||
close(fd); | ||||
free(info); | ||||
return rv; | ||||
out: | ||||
return -1; | ||||
} | ||||
int CreateBitmap(char *filename, int force, char uuid[16], | int CreateBitmap(char *filename, int force, char uuid[16], | |||
unsigned long chunksize, unsigned long daemon_sleep, | unsigned long chunksize, unsigned long daemon_sleep, | |||
unsigned long write_behind, | unsigned long write_behind, | |||
unsigned long long array_size /* sectors */, | unsigned long long array_size /* sectors */, | |||
int major) | int major) | |||
{ | { | |||
/* | /* | |||
* Create a bitmap file with a superblock and (optionally) a full bitmap | * Create a bitmap file with a superblock and (optionally) a full bitmap | |||
*/ | */ | |||
End of changes. 11 change blocks. | ||||
9 lines changed or deleted | 67 lines changed or added |