1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +03:00

cov: ensure settings is set

This commit is contained in:
Zdenek Kabelac 2021-03-09 16:32:36 +01:00
parent f7912635a0
commit a66380ea3e
2 changed files with 15 additions and 11 deletions

View File

@ -93,23 +93,26 @@ static uint32_t _raidmaxrecoveryrate(const struct logical_volume *lv)
static const char *_raidintegritymode(const struct logical_volume *lv) static const char *_raidintegritymode(const struct logical_volume *lv)
{ {
struct integrity_settings *settings; struct integrity_settings *settings = NULL;
if (lv_raid_has_integrity((struct logical_volume *)lv)) if (lv_raid_has_integrity((struct logical_volume *)lv))
lv_get_raid_integrity_settings((struct logical_volume *)lv, &settings); lv_get_raid_integrity_settings((struct logical_volume *)lv, &settings);
else if (lv_is_integrity(lv)) else if (lv_is_integrity(lv))
settings = &first_seg(lv)->integrity_settings; settings = &first_seg(lv)->integrity_settings;
if (settings->mode[0] == 'B') if (settings) {
return "bitmap"; switch (settings->mode[0]) {
if (settings->mode[0] == 'J') case 'B': return "bitmap";
return "journal"; case 'J': return "journal";
}
}
return "unknown"; return "unknown";
} }
static uint32_t _raidintegrityblocksize(const struct logical_volume *lv) static uint32_t _raidintegrityblocksize(const struct logical_volume *lv)
{ {
struct integrity_settings *settings; struct integrity_settings *settings = NULL;
if (lv_raid_has_integrity((struct logical_volume *)lv)) if (lv_raid_has_integrity((struct logical_volume *)lv))
lv_get_raid_integrity_settings((struct logical_volume *)lv, &settings); lv_get_raid_integrity_settings((struct logical_volume *)lv, &settings);
@ -118,7 +121,7 @@ static uint32_t _raidintegrityblocksize(const struct logical_volume *lv)
else else
return 0; return 0;
return settings->block_size; return (settings) ? settings->block_size : 0;
} }
static uint64_t _integritymismatches(const struct logical_volume *lv) static uint64_t _integritymismatches(const struct logical_volume *lv)

View File

@ -3278,7 +3278,7 @@ static int _raidintegritymode_disp(struct dm_report *rh __attribute__((unused)),
void *private __attribute__((unused))) void *private __attribute__((unused)))
{ {
struct logical_volume *lv = (struct logical_volume *) data; struct logical_volume *lv = (struct logical_volume *) data;
struct integrity_settings *settings; struct integrity_settings *settings = NULL;
const char *mode = NULL; const char *mode = NULL;
char *repstr; char *repstr;
@ -3289,7 +3289,7 @@ static int _raidintegritymode_disp(struct dm_report *rh __attribute__((unused)),
else else
goto out; goto out;
if (settings->mode[0]) { if (settings && settings->mode[0]) {
if (settings->mode[0] == 'B') if (settings->mode[0] == 'B')
mode = "bitmap"; mode = "bitmap";
else if (settings->mode[0] == 'J') else if (settings->mode[0] == 'J')
@ -3314,13 +3314,14 @@ static int _raidintegrityblocksize_disp(struct dm_report *rh __attribute__((unus
void *private __attribute__((unused))) void *private __attribute__((unused)))
{ {
struct logical_volume *lv = (struct logical_volume *) data; struct logical_volume *lv = (struct logical_volume *) data;
struct integrity_settings *settings; struct integrity_settings *settings = NULL;
if (lv_raid_has_integrity(lv)) if (lv_raid_has_integrity(lv))
lv_get_raid_integrity_settings(lv, &settings); lv_get_raid_integrity_settings(lv, &settings);
else if (lv_is_integrity(lv)) else if (lv_is_integrity(lv))
settings = &first_seg(lv)->integrity_settings; settings = &first_seg(lv)->integrity_settings;
else
if (!settings)
return dm_report_field_int32(rh, field, &GET_TYPE_RESERVED_VALUE(num_undef_32)); return dm_report_field_int32(rh, field, &GET_TYPE_RESERVED_VALUE(num_undef_32));
return dm_report_field_uint32(rh, field, &settings->block_size); return dm_report_field_uint32(rh, field, &settings->block_size);