31
31
const char *vg_name, struct volume_group *vg,
34
if (!report_object(handle, vg, NULL, NULL, NULL, NULL, NULL))
34
if (!report_object(handle, vg, NULL, NULL, NULL, NULL, NULL, NULL))
35
35
return_ECMD_FAILED;
37
37
check_current_backup(vg);
42
42
static int _lvs_single(struct cmd_context *cmd, struct logical_volume *lv,
45
if (!report_object(handle, lv->vg, lv, NULL, NULL, NULL, NULL))
45
if (!report_object(handle, lv->vg, lv, NULL, NULL, NULL, NULL, NULL))
48
return ECMD_PROCESSED;
51
static void _get_lv_info_for_report(struct cmd_context *cmd,
52
struct logical_volume *lv,
53
struct lvinfo *lvinfo)
55
if (!lv_info(cmd, lv, 0, lvinfo, 1, 1))
59
static int _lvs_with_info_single(struct cmd_context *cmd, struct logical_volume *lv,
64
_get_lv_info_for_report(cmd, lv, &lvinfo);
65
if (!report_object(handle, lv->vg, lv, NULL, NULL, NULL, &lvinfo, NULL))
46
66
return_ECMD_FAILED;
48
68
return ECMD_PROCESSED;
51
71
static int _segs_single(struct cmd_context *cmd __attribute__((unused)),
52
72
struct lv_segment *seg, void *handle)
54
if (!report_object(handle, seg->lv->vg, seg->lv, NULL, seg, NULL, NULL))
57
return ECMD_PROCESSED;
59
static int _pvsegs_sub_single(struct cmd_context *cmd,
60
struct volume_group *vg,
61
struct pv_segment *pvseg, void *handle)
74
if (!report_object(handle, seg->lv->vg, seg->lv, NULL, seg, NULL, NULL, NULL))
77
return ECMD_PROCESSED;
80
static int _segs_with_lv_info_single(struct cmd_context *cmd __attribute__((unused)),
81
struct lv_segment *seg, void *handle)
85
_get_lv_info_for_report(cmd, seg->lv, &lvinfo);
86
if (!report_object(handle, seg->lv->vg, seg->lv, NULL, seg, NULL, &lvinfo, NULL))
89
return ECMD_PROCESSED;
92
static int _do_pvsegs_sub_single(struct cmd_context *cmd,
93
struct volume_group *vg,
94
struct pv_segment *pvseg,
63
98
int ret = ECMD_PROCESSED;
64
99
struct lv_segment *seg = pvseg->lvseg;
100
struct lvinfo lvinfo;
66
102
struct volume_group _free_vg = {
106
142
dm_list_init(&_free_logical_volume.segs_using_this_lv);
107
143
dm_list_init(&_free_logical_volume.snapshot_segs);
146
if (seg && lv_info_needed)
147
_get_lv_info_for_report(cmd, seg->lv, &lvinfo);
109
149
if (!report_object(handle, vg, seg ? seg->lv : &_free_logical_volume, pvseg->pv,
110
seg ? : &_free_lv_segment, pvseg, pv_label(pvseg->pv))) {
150
seg ? : &_free_lv_segment, pvseg, &lvinfo, pv_label(pvseg->pv))) {
111
151
ret = ECMD_FAILED;
159
static int _pvsegs_sub_single(struct cmd_context *cmd,
160
struct volume_group *vg,
161
struct pv_segment *pvseg, void *handle)
163
return _do_pvsegs_sub_single(cmd, vg, pvseg, 0, handle);
166
static int _pvsegs_with_lv_info_sub_single(struct cmd_context *cmd,
167
struct volume_group *vg,
168
struct pv_segment *pvseg,
171
return _do_pvsegs_sub_single(cmd, vg, pvseg, 1, handle);
119
174
static int _lvsegs_single(struct cmd_context *cmd, struct logical_volume *lv,
125
180
return process_each_segment_in_lv(cmd, lv, handle, _segs_single);
183
static int _lvsegs_with_lv_info_single(struct cmd_context *cmd,
184
struct logical_volume *lv,
187
if (!arg_count(cmd, all_ARG) && !lv_is_visible(lv))
188
return ECMD_PROCESSED;
190
return process_each_segment_in_lv(cmd, lv, handle, _segs_with_lv_info_single);
128
193
static int _pvsegs_single(struct cmd_context *cmd, struct volume_group *vg,
129
194
struct physical_volume *pv, void *handle)
132
197
_pvsegs_sub_single);
200
static int _pvsegs_with_lv_info_single(struct cmd_context *cmd,
201
struct volume_group *vg,
202
struct physical_volume *pv,
205
return process_each_segment_in_pv(cmd, vg, pv, handle,
206
_pvsegs_with_lv_info_sub_single);
135
209
static int _pvs_single(struct cmd_context *cmd, struct volume_group *vg,
136
210
struct physical_volume *pv, void *handle)
140
214
const char *vg_name = NULL;
141
215
struct volume_group *old_vg = vg;
142
216
char uuid[64] __attribute__((aligned(8)));
144
struct label dummy_label = { .dev = 0 };
145
struct device dummy_device = { .dev = 0 };
147
218
if (is_pv(pv) && !is_orphan(pv) && !vg) {
148
219
vg_name = pv_vg_name(pv);
183
/* FIXME workaround for pv_label going through cache; remove once struct
184
* physical_volume gains a proper "label" pointer */
185
if (!(label = pv_label(pv))) {
187
dummy_label.labeller = pv->fmt->labeller;
190
dummy_label.dev = pv->dev;
192
dummy_label.dev = &dummy_device;
193
memcpy(dummy_device.pvid, &pv->id, ID_LEN);
195
label = &dummy_label;
198
if (!report_object(handle, vg, NULL, pv, NULL, NULL, label)) {
254
if (!report_object(handle, vg, NULL, pv, NULL, NULL, NULL, NULL)) {
200
256
ret = ECMD_FAILED;
213
269
static int _label_single(struct cmd_context *cmd, struct label *label,
216
if (!report_object(handle, NULL, NULL, NULL, NULL, NULL, label))
272
if (!report_object(handle, NULL, NULL, NULL, NULL, NULL, NULL, label))
217
273
return_ECMD_FAILED;
219
275
return ECMD_PROCESSED;
253
309
void *report_handle;
254
310
const char *opts;
256
const char *keys = NULL, *options = NULL, *separator;
312
const char *keys = NULL, *options = NULL, *selection = NULL, *separator;
257
313
int r = ECMD_PROCESSED;
258
314
int aligned, buffered, headings, field_prefixes, quoted;
259
315
int columns_as_rows;
260
unsigned args_are_pvs;
316
unsigned args_are_pvs, lv_info_needed;
262
318
aligned = find_config_tree_bool(cmd, report_aligned_CFG, NULL);
263
319
buffered = find_config_tree_bool(cmd, report_buffered_CFG, NULL);
366
422
if (arg_count(cmd, rows_ARG))
367
423
columns_as_rows = 1;
425
if (arg_count(cmd, select_ARG))
426
selection = arg_str_value(cmd, select_ARG, NULL);
369
428
if (!(report_handle = report_init(cmd, options, keys, &report_type,
370
429
separator, aligned, buffered,
371
430
headings, field_prefixes, quoted,
373
if (!strcasecmp(options, "help") || !strcmp(options, "?"))
431
columns_as_rows, selection)))
375
432
return_ECMD_FAILED;
434
/* Do we need lv_info to be called for LV device status? */
435
lv_info_needed = (report_type & LVSINFO) ? 1 : 0;
378
437
/* Ensure options selected are compatible */
379
438
if (report_type & SEGS)
380
439
report_type |= LVS;
381
440
if (report_type & PVSEGS)
382
441
report_type |= PVS;
383
if ((report_type & LVS) && (report_type & (PVS | LABEL)) && !args_are_pvs) {
442
if ((report_type & (LVS | LVSINFO)) && (report_type & (PVS | LABEL)) && !args_are_pvs) {
384
443
log_error("Can't report LV and PV fields at the same time");
385
444
dm_report_free(report_handle);
386
445
return ECMD_FAILED;
389
448
/* Change report type if fields specified makes this necessary */
390
449
if ((report_type & PVSEGS) ||
391
((report_type & (PVS | LABEL)) && (report_type & LVS)))
450
((report_type & (PVS | LABEL)) && (report_type & (LVS | LVSINFO))))
392
451
report_type = PVSEGS;
393
452
else if ((report_type & LABEL) && (report_type & VGS))
394
453
report_type = PVS;
407
468
r = process_each_lv(cmd, argc, argv, 0, report_handle,
472
r = process_each_lv(cmd, argc, argv, 0, report_handle,
473
&_lvs_with_info_single);
411
476
r = process_each_vg(cmd, argc, argv, 0,
412
477
report_handle, &_vgs_single);
427
492
r = process_each_lv(cmd, argc, argv, 0, report_handle,
493
lv_info_needed ? &_lvsegs_with_lv_info_single
431
497
if (args_are_pvs)
432
498
r = process_each_pv(cmd, argc, argv, NULL, 0,
433
0, report_handle, &_pvsegs_single);
500
lv_info_needed ? &_pvsegs_with_lv_info_single
435
503
r = process_each_vg(cmd, argc, argv, 0,
436
504
report_handle, &_pvsegs_in_vg);