mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-21 13:34:40 +03:00
cleanup: access pool segs with check
Add some minor checks after first_seg(lv). Use direct check for thin pool segment. Drop some unneeded {}
This commit is contained in:
parent
5e19410d93
commit
5d73c0c674
@ -170,7 +170,7 @@ uint64_t lvseg_chunksize(const struct lv_segment *seg)
|
|||||||
|
|
||||||
if (lv_is_cow(seg->lv))
|
if (lv_is_cow(seg->lv))
|
||||||
size = (uint64_t) find_cow(seg->lv)->chunk_size;
|
size = (uint64_t) find_cow(seg->lv)->chunk_size;
|
||||||
else if (lv_is_thin_pool(seg->lv))
|
else if (seg_is_thin_pool(seg))
|
||||||
size = (uint64_t) seg->chunk_size;
|
size = (uint64_t) seg->chunk_size;
|
||||||
else
|
else
|
||||||
size = UINT64_C(0);
|
size = UINT64_C(0);
|
||||||
@ -254,14 +254,16 @@ char *lv_pool_lv_dup(struct dm_pool *mem, const struct logical_volume *lv)
|
|||||||
|
|
||||||
char *lv_data_lv_dup(struct dm_pool *mem, const struct logical_volume *lv)
|
char *lv_data_lv_dup(struct dm_pool *mem, const struct logical_volume *lv)
|
||||||
{
|
{
|
||||||
return lv_is_thin_pool(lv) ?
|
struct lv_segment *seg = lv_is_thin_pool(lv) ? first_seg(lv) : NULL;
|
||||||
dm_pool_strdup(mem, seg_lv(first_seg(lv), 0)->name) : NULL;
|
|
||||||
|
return seg ? dm_pool_strdup(mem, seg_lv(seg, 0)->name) : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *lv_metadata_lv_dup(struct dm_pool *mem, const struct logical_volume *lv)
|
char *lv_metadata_lv_dup(struct dm_pool *mem, const struct logical_volume *lv)
|
||||||
{
|
{
|
||||||
return lv_is_thin_pool(lv) ?
|
struct lv_segment *seg = lv_is_thin_pool(lv) ? first_seg(lv) : NULL;
|
||||||
dm_pool_strdup(mem, first_seg(lv)->metadata_lv->name) : NULL;
|
|
||||||
|
return seg ? dm_pool_strdup(mem, seg->metadata_lv->name) : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *lv_layer(const struct logical_volume *lv)
|
const char *lv_layer(const struct logical_volume *lv)
|
||||||
@ -310,27 +312,35 @@ char *lv_move_pv_dup(struct dm_pool *mem, const struct logical_volume *lv)
|
|||||||
{
|
{
|
||||||
struct lv_segment *seg;
|
struct lv_segment *seg;
|
||||||
|
|
||||||
dm_list_iterate_items(seg, &lv->segments) {
|
dm_list_iterate_items(seg, &lv->segments)
|
||||||
if (seg->status & PVMOVE)
|
if (seg->status & PVMOVE)
|
||||||
return dm_pool_strdup(mem, dev_name(seg_dev(seg, 0)));
|
return dm_pool_strdup(mem, dev_name(seg_dev(seg, 0)));
|
||||||
}
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t lv_origin_size(const struct logical_volume *lv)
|
uint64_t lv_origin_size(const struct logical_volume *lv)
|
||||||
{
|
{
|
||||||
|
struct lv_segment *seg;
|
||||||
|
|
||||||
if (lv_is_cow(lv))
|
if (lv_is_cow(lv))
|
||||||
return (uint64_t) find_cow(lv)->len * lv->vg->extent_size;
|
return (uint64_t) find_cow(lv)->len * lv->vg->extent_size;
|
||||||
if (lv_is_thin_volume(lv) && first_seg(lv)->external_lv)
|
|
||||||
return first_seg(lv)->external_lv->size;
|
if (lv_is_thin_volume(lv) && (seg = first_seg(lv)) &&
|
||||||
|
seg->external_lv)
|
||||||
|
return seg->external_lv->size;
|
||||||
|
|
||||||
if (lv_is_origin(lv))
|
if (lv_is_origin(lv))
|
||||||
return lv->size;
|
return lv->size;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t lv_metadata_size(const struct logical_volume *lv)
|
uint64_t lv_metadata_size(const struct logical_volume *lv)
|
||||||
{
|
{
|
||||||
return lv_is_thin_pool(lv) ? first_seg(lv)->metadata_lv->size : 0;
|
struct lv_segment *seg = lv_is_thin_pool(lv) ? first_seg(lv) : NULL;
|
||||||
|
|
||||||
|
return seg ? seg->metadata_lv->size : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *lv_path_dup(struct dm_pool *mem, const struct logical_volume *lv)
|
char *lv_path_dup(struct dm_pool *mem, const struct logical_volume *lv)
|
||||||
|
@ -378,7 +378,12 @@ struct logical_volume *find_pool_lv(struct logical_volume *lv)
|
|||||||
{
|
{
|
||||||
struct lv_segment *seg;
|
struct lv_segment *seg;
|
||||||
|
|
||||||
if (!(seg = find_pool_seg(first_seg(lv))))
|
if (!(seg = first_seg(lv))) {
|
||||||
|
log_error("LV %s has no segment", lv->name);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(seg = find_pool_seg(seg)))
|
||||||
return_NULL;
|
return_NULL;
|
||||||
|
|
||||||
return seg->lv;
|
return seg->lv;
|
||||||
|
@ -277,10 +277,10 @@ static int _datalv_disp(struct dm_report *rh, struct dm_pool *mem __attribute__(
|
|||||||
const void *data, void *private __attribute__((unused)))
|
const void *data, void *private __attribute__((unused)))
|
||||||
{
|
{
|
||||||
const struct logical_volume *lv = (const struct logical_volume *) data;
|
const struct logical_volume *lv = (const struct logical_volume *) data;
|
||||||
|
const struct lv_segment *seg = lv_is_thin_pool(lv) ? first_seg(lv) : NULL;
|
||||||
|
|
||||||
if (lv_is_thin_pool(lv))
|
if (seg)
|
||||||
return _lvname_disp(rh, mem, field,
|
return _lvname_disp(rh, mem, field, seg_lv(seg, 0), private);
|
||||||
seg_lv(first_seg(lv), 0), private);
|
|
||||||
|
|
||||||
dm_report_field_set_value(field, "", NULL);
|
dm_report_field_set_value(field, "", NULL);
|
||||||
return 1;
|
return 1;
|
||||||
@ -291,10 +291,10 @@ static int _metadatalv_disp(struct dm_report *rh, struct dm_pool *mem __attribut
|
|||||||
const void *data, void *private __attribute__((unused)))
|
const void *data, void *private __attribute__((unused)))
|
||||||
{
|
{
|
||||||
const struct logical_volume *lv = (const struct logical_volume *) data;
|
const struct logical_volume *lv = (const struct logical_volume *) data;
|
||||||
|
const struct lv_segment *seg = lv_is_thin_pool(lv) ? first_seg(lv) : NULL;
|
||||||
|
|
||||||
if (lv_is_thin_pool(lv))
|
if (seg)
|
||||||
return _lvname_disp(rh, mem, field,
|
return _lvname_disp(rh, mem, field, seg->metadata_lv, private);
|
||||||
first_seg(lv)->metadata_lv, private);
|
|
||||||
|
|
||||||
dm_report_field_set_value(field, "", NULL);
|
dm_report_field_set_value(field, "", NULL);
|
||||||
return 1;
|
return 1;
|
||||||
|
Loading…
Reference in New Issue
Block a user