~ubuntu-branches/debian/sid/lvm2/sid

« back to all changes in this revision

Viewing changes to tools/reporter.c

  • Committer: Package Import Robot
  • Author(s): Bastian Blank
  • Date: 2014-08-19 15:37:06 UTC
  • mfrom: (1.1.18)
  • Revision ID: package-import@ubuntu.com-20140819153706-i1gaio8lg534dara
Tags: 2.02.109-1
New upstream version.

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
                       const char *vg_name, struct volume_group *vg,
32
32
                       void *handle)
33
33
{
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;
36
36
 
37
37
        check_current_backup(vg);
42
42
static int _lvs_single(struct cmd_context *cmd, struct logical_volume *lv,
43
43
                       void *handle)
44
44
{
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))
 
46
                return_ECMD_FAILED;
 
47
 
 
48
        return ECMD_PROCESSED;
 
49
}
 
50
 
 
51
static void _get_lv_info_for_report(struct cmd_context *cmd,
 
52
                                   struct logical_volume *lv,
 
53
                                   struct lvinfo *lvinfo)
 
54
{
 
55
        if (!lv_info(cmd, lv, 0, lvinfo, 1, 1))
 
56
                lvinfo->exists = 0;
 
57
}
 
58
 
 
59
static int _lvs_with_info_single(struct cmd_context *cmd, struct logical_volume *lv,
 
60
                                 void *handle)
 
61
{
 
62
        struct lvinfo lvinfo;
 
63
 
 
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;
47
67
 
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)
53
73
{
54
 
        if (!report_object(handle, seg->lv->vg, seg->lv, NULL, seg, NULL, NULL))
55
 
                return_ECMD_FAILED;
56
 
 
57
 
        return ECMD_PROCESSED;
58
 
}
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))
 
75
                return_ECMD_FAILED;
 
76
 
 
77
        return ECMD_PROCESSED;
 
78
}
 
79
 
 
80
static int _segs_with_lv_info_single(struct cmd_context *cmd __attribute__((unused)),
 
81
                                     struct lv_segment *seg, void *handle)
 
82
{
 
83
        struct lvinfo lvinfo;
 
84
 
 
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))
 
87
                return_ECMD_FAILED;
 
88
 
 
89
        return ECMD_PROCESSED;
 
90
}
 
91
 
 
92
static int _do_pvsegs_sub_single(struct cmd_context *cmd,
 
93
                                 struct volume_group *vg,
 
94
                                 struct pv_segment *pvseg,
 
95
                                 int lv_info_needed,
 
96
                                 void *handle)
62
97
{
63
98
        int ret = ECMD_PROCESSED;
64
99
        struct lv_segment *seg = pvseg->lvseg;
 
100
        struct lvinfo lvinfo;
65
101
 
66
102
        struct volume_group _free_vg = {
67
103
                .cmd = cmd,
106
142
        dm_list_init(&_free_logical_volume.segs_using_this_lv);
107
143
        dm_list_init(&_free_logical_volume.snapshot_segs);
108
144
 
 
145
        lvinfo.exists = 0;
 
146
        if (seg && lv_info_needed)
 
147
            _get_lv_info_for_report(cmd, seg->lv, &lvinfo);
 
148
 
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;
112
152
                goto_out;
113
153
        }
116
156
        return ret;
117
157
}
118
158
 
 
159
static int _pvsegs_sub_single(struct cmd_context *cmd,
 
160
                              struct volume_group *vg,
 
161
                              struct pv_segment *pvseg, void *handle)
 
162
{
 
163
        return _do_pvsegs_sub_single(cmd, vg, pvseg, 0, handle);
 
164
}
 
165
 
 
166
static int _pvsegs_with_lv_info_sub_single(struct cmd_context *cmd,
 
167
                                           struct volume_group *vg,
 
168
                                           struct pv_segment *pvseg,
 
169
                                           void *handle)
 
170
{
 
171
        return _do_pvsegs_sub_single(cmd, vg, pvseg, 1, handle);
 
172
}
 
173
 
119
174
static int _lvsegs_single(struct cmd_context *cmd, struct logical_volume *lv,
120
175
                          void *handle)
121
176
{
125
180
        return process_each_segment_in_lv(cmd, lv, handle, _segs_single);
126
181
}
127
182
 
 
183
static int _lvsegs_with_lv_info_single(struct cmd_context *cmd,
 
184
                                       struct logical_volume *lv,
 
185
                                       void *handle)
 
186
{
 
187
        if (!arg_count(cmd, all_ARG) && !lv_is_visible(lv))
 
188
                return ECMD_PROCESSED;
 
189
 
 
190
        return process_each_segment_in_lv(cmd, lv, handle, _segs_with_lv_info_single);
 
191
}
 
192
 
128
193
static int _pvsegs_single(struct cmd_context *cmd, struct volume_group *vg,
129
194
                          struct physical_volume *pv, void *handle)
130
195
{
132
197
                                          _pvsegs_sub_single);
133
198
}
134
199
 
 
200
static int _pvsegs_with_lv_info_single(struct cmd_context *cmd,
 
201
                                       struct volume_group *vg,
 
202
                                       struct physical_volume *pv,
 
203
                                       void *handle)
 
204
{
 
205
        return process_each_segment_in_pv(cmd, vg, pv, handle,
 
206
                                _pvsegs_with_lv_info_sub_single);
 
207
}
 
208
 
135
209
static int _pvs_single(struct cmd_context *cmd, struct volume_group *vg,
136
210
                       struct physical_volume *pv, void *handle)
137
211
{
140
214
        const char *vg_name = NULL;
141
215
        struct volume_group *old_vg = vg;
142
216
        char uuid[64] __attribute__((aligned(8)));
143
 
        struct label *label;
144
 
        struct label dummy_label = { .dev = 0 };
145
 
        struct device dummy_device = { .dev = 0 };
146
217
 
147
218
        if (is_pv(pv) && !is_orphan(pv) && !vg) {
148
219
                vg_name = pv_vg_name(pv);
180
251
                pv = pvl->pv;
181
252
        }
182
253
 
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))) {
186
 
                if (pv->fmt)
187
 
                        dummy_label.labeller = pv->fmt->labeller;
188
 
 
189
 
                if (pv->dev)
190
 
                        dummy_label.dev = pv->dev;
191
 
                else {
192
 
                        dummy_label.dev = &dummy_device;
193
 
                        memcpy(dummy_device.pvid, &pv->id, ID_LEN);
194
 
                }
195
 
                label = &dummy_label;
196
 
        }
197
 
 
198
 
        if (!report_object(handle, vg, NULL, pv, NULL, NULL, label)) {
 
254
        if (!report_object(handle, vg, NULL, pv, NULL, NULL, NULL, NULL)) {
199
255
                stack;
200
256
                ret = ECMD_FAILED;
201
257
        }
213
269
static int _label_single(struct cmd_context *cmd, struct label *label,
214
270
                         void *handle)
215
271
{
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;
218
274
 
219
275
        return ECMD_PROCESSED;
253
309
        void *report_handle;
254
310
        const char *opts;
255
311
        char *str;
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;
261
317
 
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;
368
424
 
 
425
        if (arg_count(cmd, select_ARG))
 
426
                selection = arg_str_value(cmd, select_ARG, NULL);
 
427
 
369
428
        if (!(report_handle = report_init(cmd, options, keys, &report_type,
370
429
                                          separator, aligned, buffered,
371
430
                                          headings, field_prefixes, quoted,
372
 
                                          columns_as_rows))) {
373
 
                if (!strcasecmp(options, "help") || !strcmp(options, "?"))
374
 
                        return r;
 
431
                                          columns_as_rows, selection)))
375
432
                return_ECMD_FAILED;
376
 
        }
 
433
 
 
434
        /* Do we need lv_info to be called for LV device status? */
 
435
        lv_info_needed = (report_type & LVSINFO) ? 1 : 0;
377
436
 
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;
388
447
 
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;
396
455
                report_type = PVS;
397
456
        else if (report_type & SEGS)
398
457
                report_type = SEGS;
 
458
        else if (report_type & LVSINFO)
 
459
                report_type = LVSINFO;
399
460
        else if (report_type & LVS)
400
461
                report_type = LVS;
401
462
 
407
468
                r = process_each_lv(cmd, argc, argv, 0, report_handle,
408
469
                                    &_lvs_single);
409
470
                break;
 
471
        case LVSINFO:
 
472
                r = process_each_lv(cmd, argc, argv, 0, report_handle,
 
473
                                    &_lvs_with_info_single);
 
474
                break;
410
475
        case VGS:
411
476
                r = process_each_vg(cmd, argc, argv, 0,
412
477
                                    report_handle, &_vgs_single);
425
490
                break;
426
491
        case SEGS:
427
492
                r = process_each_lv(cmd, argc, argv, 0, report_handle,
428
 
                                    &_lvsegs_single);
 
493
                                    lv_info_needed ? &_lvsegs_with_lv_info_single
 
494
                                                   : &_lvsegs_single);
429
495
                break;
430
496
        case PVSEGS:
431
497
                if (args_are_pvs)
432
498
                        r = process_each_pv(cmd, argc, argv, NULL, 0,
433
 
                                            0, report_handle, &_pvsegs_single);
 
499
                                            0, report_handle,
 
500
                                            lv_info_needed ? &_pvsegs_with_lv_info_single
 
501
                                                           : &_pvsegs_single);
434
502
                else
435
503
                        r = process_each_vg(cmd, argc, argv, 0,
436
504
                                            report_handle, &_pvsegs_in_vg);