master - report: Make PMdaFree into a "label" field.
by Petr Rockai
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=99214c51eb8158...
Commit: 99214c51eb815806c4a4a4711fa3562546479751
Parent: b07fb3a6415215bf7e6128516a210b07376753dc
Author: Petr Rockai <prockai(a)redhat.com>
AuthorDate: Mon Jul 29 19:14:10 2013 +0200
Committer: Petr Rockai <prockai(a)redhat.com>
CommitterDate: Sun Nov 17 21:43:06 2013 +0100
report: Make PMdaFree into a "label" field.
---
lib/report/columns.h | 2 +-
lib/report/report.c | 5 ++---
2 files changed, 3 insertions(+), 4 deletions(-)
diff --git a/lib/report/columns.h b/lib/report/columns.h
index 27f4d7f..8a87d11 100644
--- a/lib/report/columns.h
+++ b/lib/report/columns.h
@@ -67,10 +67,10 @@ FIELD(LVS, lv, STR, "Host", lvid, 10, lvhost, lv_host, "Creation host of the LV,
FIELD(LVS, lv, STR, "Modules", lvid, 7, modules, lv_modules, "Kernel device-mapper modules required for this LV.", 0)
FIELD(LABEL, pv, STR, "PV UUID", id, 38, uuid, pv_uuid, "Unique identifier.", 0)
-FIELD(LABEL, pv, NUM, "PMdaFree", id, 9, pvmdafree, pv_mda_free, "Free metadata area space on this device in current units.", 0)
FIELD(LABEL, label, STR, "Fmt", type, 3, pvfmt, pv_fmt, "Type of metadata.", 0)
FIELD(LABEL, label, NUM, "DevSize", dev, 7, devsize, dev_size, "Size of underlying device in current units.", 0)
FIELD(LABEL, label, STR, "PV", dev, 10, dev_name, pv_name, "Name.", 0)
+FIELD(LABEL, label, NUM, "PMdaFree", type, 9, pvmdafree, pv_mda_free, "Free metadata area space on this device in current units.", 0)
FIELD(LABEL, pv, NUM, "PMdaSize", id, 9, pvmdasize, pv_mda_size, "Size of smallest metadata area on this device in current units.", 0)
FIELD(PVS, pv, NUM, "1st PE", pe_start, 7, size64, pe_start, "Offset to the start of data on the underlying device.", 0)
diff --git a/lib/report/report.c b/lib/report/report.c
index 94e5230..3f716b5 100644
--- a/lib/report/report.c
+++ b/lib/report/report.c
@@ -791,9 +791,8 @@ static int _pvmdafree_disp(struct dm_report *rh, struct dm_pool *mem,
struct dm_report_field *field,
const void *data, void *private)
{
- const struct physical_volume *pv =
- (const struct physical_volume *) data;
- uint64_t freespace = pv_mda_free(pv);
+ const struct label *label = (const struct label *) data;
+ uint64_t freespace = lvmcache_info_mda_free(label->info);
return _size64_disp(rh, mem, field, &freespace, private);
}
10 years, 5 months
master - report: Adapt _pvfmt_disp to label-based reporting.
by Petr Rockai
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=b07fb3a6415215...
Commit: b07fb3a6415215bf7e6128516a210b07376753dc
Parent: 7e33f50cea7a7240d81ffdec3f8b0c6a1976fce3
Author: Petr Rockai <prockai(a)redhat.com>
AuthorDate: Mon Jul 29 16:00:40 2013 +0200
Committer: Petr Rockai <prockai(a)redhat.com>
CommitterDate: Sun Nov 17 21:43:04 2013 +0100
report: Adapt _pvfmt_disp to label-based reporting.
---
lib/report/columns.h | 2 +-
lib/report/report.c | 12 +++++++-----
2 files changed, 8 insertions(+), 6 deletions(-)
diff --git a/lib/report/columns.h b/lib/report/columns.h
index 54c46e4..27f4d7f 100644
--- a/lib/report/columns.h
+++ b/lib/report/columns.h
@@ -66,9 +66,9 @@ FIELD(LVS, lv, STR, "Time", lvid, 26, lvtime, lv_time, "Creation time of the LV,
FIELD(LVS, lv, STR, "Host", lvid, 10, lvhost, lv_host, "Creation host of the LV, if known.", 0)
FIELD(LVS, lv, STR, "Modules", lvid, 7, modules, lv_modules, "Kernel device-mapper modules required for this LV.", 0)
-FIELD(LABEL, pv, STR, "Fmt", id, 3, pvfmt, pv_fmt, "Type of metadata.", 0)
FIELD(LABEL, pv, STR, "PV UUID", id, 38, uuid, pv_uuid, "Unique identifier.", 0)
FIELD(LABEL, pv, NUM, "PMdaFree", id, 9, pvmdafree, pv_mda_free, "Free metadata area space on this device in current units.", 0)
+FIELD(LABEL, label, STR, "Fmt", type, 3, pvfmt, pv_fmt, "Type of metadata.", 0)
FIELD(LABEL, label, NUM, "DevSize", dev, 7, devsize, dev_size, "Size of underlying device in current units.", 0)
FIELD(LABEL, label, STR, "PV", dev, 10, dev_name, pv_name, "Name.", 0)
FIELD(LABEL, pv, NUM, "PMdaSize", id, 9, pvmdasize, pv_mda_size, "Size of smallest metadata area on this device in current units.", 0)
diff --git a/lib/report/report.c b/lib/report/report.c
index f304157..94e5230 100644
--- a/lib/report/report.c
+++ b/lib/report/report.c
@@ -181,13 +181,15 @@ static int _pvfmt_disp(struct dm_report *rh, struct dm_pool *mem,
struct dm_report_field *field,
const void *data, void *private)
{
- const struct physical_volume *pv =
- (const struct physical_volume *) data;
+ const struct label *l =
+ (const struct label *) data;
- if (pv->fmt)
- return _string_disp(rh, mem, field, &pv->fmt->name, private);
+ if (!l->labeller->fmt) {
+ dm_report_field_set_value(field, "", NULL);
+ return 1;
+ }
- return _field_set_value(field, "", NULL);
+ return _string_disp(rh, mem, field, &l->labeller->fmt->name, private);
}
static int _lvkmaj_disp(struct dm_report *rh, struct dm_pool *mem __attribute__((unused)),
10 years, 5 months
master - report: Add a proper "label" field type.
by Petr Rockai
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=7e33f50cea7a72...
Commit: 7e33f50cea7a7240d81ffdec3f8b0c6a1976fce3
Parent: 6b41e916ff8a11e91fade523323db549417f703c
Author: Petr Rockai <prockai(a)redhat.com>
AuthorDate: Mon Jul 29 19:07:11 2013 +0200
Committer: Petr Rockai <prockai(a)redhat.com>
CommitterDate: Sun Nov 17 21:41:27 2013 +0100
report: Add a proper "label" field type.
---
lib/report/report.c | 13 +++++++++++--
lib/report/report.h | 4 +++-
tools/reporter.c | 19 +++++++++++--------
3 files changed, 25 insertions(+), 11 deletions(-)
diff --git a/lib/report/report.c b/lib/report/report.c
index 2684392..f304157 100644
--- a/lib/report/report.c
+++ b/lib/report/report.c
@@ -32,6 +32,7 @@ struct lvm_report_object {
struct physical_volume *pv;
struct lv_segment *seg;
struct pv_segment *pvseg;
+ struct label *label;
};
static const uint64_t _hundred64 = UINT64_C(100);
@@ -1138,6 +1139,11 @@ static void *_obj_get_pv(void *obj)
return ((struct lvm_report_object *)obj)->pv;
}
+static void *_obj_get_label(void *obj)
+{
+ return ((struct lvm_report_object *)obj)->label;
+}
+
static void *_obj_get_seg(void *obj)
{
return ((struct lvm_report_object *)obj)->seg;
@@ -1157,7 +1163,7 @@ static const struct dm_report_object_type _report_types[] = {
{ VGS, "Volume Group", "vg_", _obj_get_vg },
{ LVS, "Logical Volume", "lv_", _obj_get_lv },
{ PVS, "Physical Volume", "pv_", _obj_get_pv },
- { LABEL, "Physical Volume Label", "pv_", _obj_get_pv },
+ { LABEL, "Physical Volume Label", "pv_", _obj_get_label },
{ SEGS, "Logical Volume Segment", "seg_", _obj_get_seg },
{ PVSEGS, "Physical Volume Segment", "pvseg_", _obj_get_pvseg },
{ 0, "", "", NULL },
@@ -1183,6 +1189,7 @@ typedef struct logical_volume type_lv;
typedef struct volume_group type_vg;
typedef struct lv_segment type_seg;
typedef struct pv_segment type_pvseg;
+typedef struct label type_label;
typedef dev_known_type_t type_devtype;
@@ -1242,7 +1249,8 @@ void *report_init(struct cmd_context *cmd, const char *format, const char *keys,
*/
int report_object(void *handle, struct volume_group *vg,
struct logical_volume *lv, struct physical_volume *pv,
- struct lv_segment *seg, struct pv_segment *pvseg)
+ struct lv_segment *seg, struct pv_segment *pvseg,
+ struct label *label)
{
struct lvm_report_object obj;
@@ -1255,6 +1263,7 @@ int report_object(void *handle, struct volume_group *vg,
obj.pv = pv;
obj.seg = seg;
obj.pvseg = pvseg;
+ obj.label = label ? label : (pv ? pv_label(pv) : NULL);
return dm_report_object(handle, &obj);
}
diff --git a/lib/report/report.h b/lib/report/report.h
index bda8553..2c093b0 100644
--- a/lib/report/report.h
+++ b/lib/report/report.h
@@ -17,6 +17,7 @@
#define _LVM_REPORT_H
#include "metadata-exported.h"
+#include "label.h"
typedef enum {
LVS = 1,
@@ -41,7 +42,8 @@ void *report_init(struct cmd_context *cmd, const char *format, const char *keys,
void report_free(void *handle);
int report_object(void *handle, struct volume_group *vg,
struct logical_volume *lv, struct physical_volume *pv,
- struct lv_segment *seg, struct pv_segment *pvseg);
+ struct lv_segment *seg, struct pv_segment *pvseg,
+ struct label *label);
int report_devtypes(void *handle);
int report_output(void *handle);
diff --git a/tools/reporter.c b/tools/reporter.c
index a967f60..8b2a7c7 100644
--- a/tools/reporter.c
+++ b/tools/reporter.c
@@ -31,7 +31,7 @@ static int _vgs_single(struct cmd_context *cmd __attribute__((unused)),
const char *vg_name, struct volume_group *vg,
void *handle)
{
- if (!report_object(handle, vg, NULL, NULL, NULL, NULL))
+ if (!report_object(handle, vg, NULL, NULL, NULL, NULL, NULL))
return_ECMD_FAILED;
check_current_backup(vg);
@@ -42,7 +42,7 @@ static int _vgs_single(struct cmd_context *cmd __attribute__((unused)),
static int _lvs_single(struct cmd_context *cmd, struct logical_volume *lv,
void *handle)
{
- if (!report_object(handle, lv->vg, lv, NULL, NULL, NULL))
+ if (!report_object(handle, lv->vg, lv, NULL, NULL, NULL, NULL))
return_ECMD_FAILED;
return ECMD_PROCESSED;
@@ -51,7 +51,7 @@ static int _lvs_single(struct cmd_context *cmd, struct logical_volume *lv,
static int _segs_single(struct cmd_context *cmd __attribute__((unused)),
struct lv_segment *seg, void *handle)
{
- if (!report_object(handle, seg->lv->vg, seg->lv, NULL, seg, NULL))
+ if (!report_object(handle, seg->lv->vg, seg->lv, NULL, seg, NULL, NULL))
return_ECMD_FAILED;
return ECMD_PROCESSED;
@@ -107,7 +107,7 @@ static int _pvsegs_sub_single(struct cmd_context *cmd,
dm_list_init(&_free_logical_volume.snapshot_segs);
if (!report_object(handle, vg, seg ? seg->lv : &_free_logical_volume, pvseg->pv,
- seg ? : &_free_lv_segment, pvseg)) {
+ seg ? : &_free_lv_segment, pvseg, NULL)) {
ret = ECMD_FAILED;
goto_out;
}
@@ -140,6 +140,7 @@ static int _pvs_single(struct cmd_context *cmd, struct volume_group *vg,
const char *vg_name = NULL;
struct volume_group *old_vg = vg;
char uuid[64] __attribute__((aligned(8)));
+ struct label *label;
if (is_pv(pv) && !is_orphan(pv) && !vg) {
vg_name = pv_vg_name(pv);
@@ -177,7 +178,9 @@ static int _pvs_single(struct cmd_context *cmd, struct volume_group *vg,
pv = pvl->pv;
}
- if (!report_object(handle, vg, NULL, pv, NULL, NULL)) {
+ if ((!(label = pv_label(pv))) ||
+ (!report_object(handle, vg, NULL, pv, NULL, NULL, label)))
+ {
stack;
ret = ECMD_FAILED;
}
@@ -192,10 +195,10 @@ out:
return ret;
}
-static int _label_single(struct cmd_context *cmd, struct volume_group *vg,
- struct physical_volume *pv, void *handle)
+static int _label_single(struct cmd_context *cmd, struct label *label,
+ void *handle)
{
- if (!report_object(handle, vg, NULL, pv, NULL, NULL))
+ if (!report_object(handle, NULL, NULL, NULL, NULL, NULL, label))
return_ECMD_FAILED;
return ECMD_PROCESSED;
10 years, 5 months
master - report: Make dev_size and dev_name columns' type "label".
by Petr Rockai
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=6b41e916ff8a11...
Commit: 6b41e916ff8a11e91fade523323db549417f703c
Parent: cc633c84cfc82e91e83393271a068a662e7d4678
Author: Petr Rockai <prockai(a)redhat.com>
AuthorDate: Mon Jul 29 19:05:28 2013 +0200
Committer: Petr Rockai <prockai(a)redhat.com>
CommitterDate: Sun Nov 17 21:41:27 2013 +0100
report: Make dev_size and dev_name columns' type "label".
---
lib/report/columns.h | 4 ++--
lib/report/report.c | 6 ++----
2 files changed, 4 insertions(+), 6 deletions(-)
diff --git a/lib/report/columns.h b/lib/report/columns.h
index 88a0266..54c46e4 100644
--- a/lib/report/columns.h
+++ b/lib/report/columns.h
@@ -68,9 +68,9 @@ FIELD(LVS, lv, STR, "Modules", lvid, 7, modules, lv_modules, "Kernel device-mapp
FIELD(LABEL, pv, STR, "Fmt", id, 3, pvfmt, pv_fmt, "Type of metadata.", 0)
FIELD(LABEL, pv, STR, "PV UUID", id, 38, uuid, pv_uuid, "Unique identifier.", 0)
-FIELD(LABEL, pv, NUM, "DevSize", id, 7, devsize, dev_size, "Size of underlying device in current units.", 0)
-FIELD(LABEL, pv, STR, "PV", dev, 10, dev_name, pv_name, "Name.", 0)
FIELD(LABEL, pv, NUM, "PMdaFree", id, 9, pvmdafree, pv_mda_free, "Free metadata area space on this device in current units.", 0)
+FIELD(LABEL, label, NUM, "DevSize", dev, 7, devsize, dev_size, "Size of underlying device in current units.", 0)
+FIELD(LABEL, label, STR, "PV", dev, 10, dev_name, pv_name, "Name.", 0)
FIELD(LABEL, pv, NUM, "PMdaSize", id, 9, pvmdasize, pv_mda_size, "Size of smallest metadata area on this device in current units.", 0)
FIELD(PVS, pv, NUM, "1st PE", pe_start, 7, size64, pe_start, "Offset to the start of data on the underlying device.", 0)
diff --git a/lib/report/report.c b/lib/report/report.c
index c780ca4..2684392 100644
--- a/lib/report/report.c
+++ b/lib/report/report.c
@@ -690,10 +690,8 @@ static int _devsize_disp(struct dm_report *rh, struct dm_pool *mem,
struct dm_report_field *field,
const void *data, void *private)
{
- const struct physical_volume *pv =
- (const struct physical_volume *) data;
- uint64_t size = pv_dev_size(pv);
-
+ uint64_t size = 0;
+ dev_get_size(*(const struct device **) data, &size);
return _size64_disp(rh, mem, field, &size, private);
}
10 years, 5 months
master - label: Track a device pointer in struct label.
by Petr Rockai
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=cc633c84cfc82e...
Commit: cc633c84cfc82e91e83393271a068a662e7d4678
Parent: dc3a0711454938e1a6264b7e3bf24a6dd1ac7e9f
Author: Petr Rockai <prockai(a)redhat.com>
AuthorDate: Mon Jul 29 19:03:20 2013 +0200
Committer: Petr Rockai <prockai(a)redhat.com>
CommitterDate: Sun Nov 17 21:41:27 2013 +0100
label: Track a device pointer in struct label.
---
lib/label/label.c | 4 +++-
lib/label/label.h | 1 +
2 files changed, 4 insertions(+), 1 deletions(-)
diff --git a/lib/label/label.c b/lib/label/label.c
index cff6464..e083150 100644
--- a/lib/label/label.c
+++ b/lib/label/label.c
@@ -282,8 +282,10 @@ int label_read(struct device *dev, struct label **result,
if (!(l = _find_labeller(dev, buf, §or, scan_sector)))
goto out;
- if ((r = (l->ops->read)(l, dev, buf, result)) && result && *result)
+ if ((r = (l->ops->read)(l, dev, buf, result)) && result && *result) {
+ (*result)->dev = dev;
(*result)->sector = sector;
+ }
out:
if (!dev_close(dev))
diff --git a/lib/label/label.h b/lib/label/label.h
index 8dc49ff..103e799 100644
--- a/lib/label/label.h
+++ b/lib/label/label.h
@@ -42,6 +42,7 @@ struct label {
char type[8];
uint64_t sector;
struct labeller *labeller;
+ struct device *dev;
void *info;
};
10 years, 5 months
master - metadata: Add a pv_label accessor (go from a PV to its label).
by Petr Rockai
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=dc3a0711454938...
Commit: dc3a0711454938e1a6264b7e3bf24a6dd1ac7e9f
Parent: a2034e9a99337ac16ee415f7f2398e0b8e976716
Author: Petr Rockai <prockai(a)redhat.com>
AuthorDate: Mon Jul 29 18:54:59 2013 +0200
Committer: Petr Rockai <prockai(a)redhat.com>
CommitterDate: Sun Nov 17 21:41:27 2013 +0100
metadata: Add a pv_label accessor (go from a PV to its label).
---
lib/metadata/pv.c | 10 ++++++++++
lib/metadata/pv.h | 1 +
2 files changed, 11 insertions(+), 0 deletions(-)
diff --git a/lib/metadata/pv.c b/lib/metadata/pv.c
index 5b08998..0288f07 100644
--- a/lib/metadata/pv.c
+++ b/lib/metadata/pv.c
@@ -350,3 +350,13 @@ unsigned pv_mda_set_ignored(const struct physical_volume *pv, unsigned mda_ignor
return 1;
}
+struct label *pv_label(const struct physical_volume *pv)
+{
+ struct lvmcache_info *info =
+ lvmcache_info_from_pvid((const char *)&pv->id.uuid, 0);
+ if (!info) {
+ log_error(INTERNAL_ERROR "PV %s unexpectedly not in cache.", dev_name(pv->dev));
+ return NULL;
+ }
+ return lvmcache_get_label(info);
+}
diff --git a/lib/metadata/pv.h b/lib/metadata/pv.h
index ff708f8..8fd3061 100644
--- a/lib/metadata/pv.h
+++ b/lib/metadata/pv.h
@@ -95,5 +95,6 @@ unsigned pv_mda_set_ignored(const struct physical_volume *pv, unsigned ignored);
int is_orphan(const struct physical_volume *pv);
int is_missing_pv(const struct physical_volume *pv);
int is_pv(const struct physical_volume *pv);
+struct label *pv_label(const struct physical_volume *pv);
#endif /* _LVM_PV_H */
10 years, 5 months
master - metadata: Add lvmcache_info_mda_free as a companion to pv_mda_free.
by Petr Rockai
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=a2034e9a99337a...
Commit: a2034e9a99337ac16ee415f7f2398e0b8e976716
Parent: 1ef2c3c4ee325dd9ce607b62c1720d782021d399
Author: Petr Rockai <prockai(a)redhat.com>
AuthorDate: Mon Jul 29 18:52:28 2013 +0200
Committer: Petr Rockai <prockai(a)redhat.com>
CommitterDate: Sun Nov 17 21:41:27 2013 +0100
metadata: Add lvmcache_info_mda_free as a companion to pv_mda_free.
---
lib/metadata/pv.c | 16 +++++++++++-----
lib/metadata/pv.h | 2 ++
2 files changed, 13 insertions(+), 5 deletions(-)
diff --git a/lib/metadata/pv.c b/lib/metadata/pv.c
index dad747c..5b08998 100644
--- a/lib/metadata/pv.c
+++ b/lib/metadata/pv.c
@@ -241,14 +241,11 @@ static int _pv_mda_free(struct metadata_area *mda, void *baton) {
return 1;
}
-uint64_t pv_mda_free(const struct physical_volume *pv)
+uint64_t lvmcache_info_mda_free(struct lvmcache_info *info)
{
- struct lvmcache_info *info;
uint64_t freespace = UINT64_MAX;
- const char *pvid = (const char *)&pv->id.uuid;
- if ((info = lvmcache_info_from_pvid(pvid, 0)))
- lvmcache_foreach_mda(info, _pv_mda_free, &freespace);
+ lvmcache_foreach_mda(info, _pv_mda_free, &freespace);
if (freespace == UINT64_MAX)
freespace = UINT64_C(0);
@@ -256,6 +253,15 @@ uint64_t pv_mda_free(const struct physical_volume *pv)
return freespace;
}
+uint64_t pv_mda_free(const struct physical_volume *pv)
+{
+ const char *pvid = (const char *)&pv->id.uuid;
+ struct lvmcache_info *info;
+ if ((info = lvmcache_info_from_pvid(pvid, 0)))
+ return lvmcache_info_mda_free(info);
+ return 0;
+}
+
uint64_t pv_used(const struct physical_volume *pv)
{
uint64_t used;
diff --git a/lib/metadata/pv.h b/lib/metadata/pv.h
index c018f38..ff708f8 100644
--- a/lib/metadata/pv.h
+++ b/lib/metadata/pv.h
@@ -85,6 +85,8 @@ uint64_t pv_ba_size(const struct physical_volume *pv);
uint32_t pv_pe_count(const struct physical_volume *pv);
uint32_t pv_pe_alloc_count(const struct physical_volume *pv);
uint64_t pv_mda_size(const struct physical_volume *pv);
+struct lvmcache_info;
+uint64_t lvmcache_info_mda_free(struct lvmcache_info *info);
uint64_t pv_mda_free(const struct physical_volume *pv);
uint64_t pv_used(const struct physical_volume *pv);
uint32_t pv_mda_count(const struct physical_volume *pv);
10 years, 5 months
master - toollib: Implement process_each_label.
by Petr Rockai
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=1ef2c3c4ee325d...
Commit: 1ef2c3c4ee325dd9ce607b62c1720d782021d399
Parent: 9b91977f4ec21a2080daaa2e261fbdecbe8fbd2c
Author: Petr Rockai <prockai(a)redhat.com>
AuthorDate: Mon Jul 29 18:51:27 2013 +0200
Committer: Petr Rockai <prockai(a)redhat.com>
CommitterDate: Sun Nov 17 21:41:27 2013 +0100
toollib: Implement process_each_label.
---
tools/toollib.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
tools/toollib.h | 6 +++++
2 files changed, 64 insertions(+), 0 deletions(-)
diff --git a/tools/toollib.c b/tools/toollib.c
index 127dd66..529088c 100644
--- a/tools/toollib.c
+++ b/tools/toollib.c
@@ -1801,3 +1801,61 @@ int change_tag(struct cmd_context *cmd, struct volume_group *vg,
return 1;
}
+int process_each_label(struct cmd_context *cmd, int argc, char **argv, void *handle,
+ process_single_label_fn_t process_single_label)
+{
+ struct label *label;
+ struct dev_iter *iter;
+ struct device *dev;
+
+ int ret_max = ECMD_PROCESSED;
+ int ret = 0;
+ int opt = 0;
+
+ if (argc) {
+ for (; opt < argc; opt++) {
+ if (!(dev = dev_cache_get(argv[opt], cmd->filter))) {
+ log_error("Failed to find device "
+ "\"%s\"", argv[opt]);
+ ret_max = ECMD_FAILED;
+ continue;
+ }
+
+ if (!label_read(dev, &label, 0))
+ continue;
+
+ ret = process_single_label(cmd, label, handle);
+
+ if (ret > ret_max)
+ ret_max = ret;
+
+ if (sigint_caught())
+ break;
+ }
+
+ return ret_max;
+ }
+
+ if (!(iter = dev_iter_create(cmd->filter, 1))) {
+ log_error("dev_iter creation failed");
+ return ECMD_FAILED;
+ }
+
+ while ((dev = dev_iter_get(iter)))
+ {
+ if (!label_read(dev, &label, 0))
+ continue;
+
+ ret = process_single_label(cmd, label, handle);
+
+ if (ret > ret_max)
+ ret_max = ret;
+
+ if (sigint_caught())
+ break;
+ }
+
+ dev_iter_destroy(iter);
+
+ return ret_max;
+}
diff --git a/tools/toollib.h b/tools/toollib.h
index aa6f699..d809123 100644
--- a/tools/toollib.h
+++ b/tools/toollib.h
@@ -38,6 +38,9 @@ typedef int (*process_single_pv_fn_t) (struct cmd_context *cmd,
struct volume_group *vg,
struct physical_volume *pv,
void *handle);
+typedef int (*process_single_label_fn_t) (struct cmd_context *cmd,
+ struct label *label,
+ void *handle);
typedef int (*process_single_lv_fn_t) (struct cmd_context *cmd,
struct logical_volume *lv,
void *handle);
@@ -58,6 +61,9 @@ int process_each_pv(struct cmd_context *cmd, int argc, char **argv,
int scan_label_only, void *handle,
process_single_pv_fn_t process_single_pv);
+int process_each_label(struct cmd_context *cmd, int argc, char **argv,
+ void *handle, process_single_label_fn_t process_single_label);
+
int process_each_segment_in_pv(struct cmd_context *cmd,
struct volume_group *vg,
struct physical_volume *pv,
10 years, 5 months
master - labeller: Make the use of "private" as "fmt" explicit.
by Petr Rockai
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=9b91977f4ec21a...
Commit: 9b91977f4ec21a2080daaa2e261fbdecbe8fbd2c
Parent: bead8ef5f03f563064276037eed5d9ca94b67ead
Author: Petr Rockai <prockai(a)redhat.com>
AuthorDate: Mon Jul 29 15:58:18 2013 +0200
Committer: Petr Rockai <prockai(a)redhat.com>
CommitterDate: Sun Nov 17 21:41:27 2013 +0100
labeller: Make the use of "private" as "fmt" explicit.
All labellers always use the "private" (void *) field as the fmt pointer. Making
this fact explicit in the type of the labeller simplifies the label reporting
code which needs to extract the format. Moreover, it removes a number of
error-prone casts from the code.
---
lib/cache/lvmcache.c | 4 ++--
lib/format1/format1.c | 2 +-
lib/format1/lvm1-label.c | 2 +-
lib/format_pool/format_pool.c | 2 +-
lib/format_pool/pool_label.c | 2 +-
lib/format_text/format-text.c | 2 +-
lib/format_text/text_label.c | 4 ++--
lib/label/label.c | 4 ++--
lib/label/label.h | 4 ++--
9 files changed, 13 insertions(+), 13 deletions(-)
diff --git a/lib/cache/lvmcache.c b/lib/cache/lvmcache.c
index f33565c..770a1b3 100644
--- a/lib/cache/lvmcache.c
+++ b/lib/cache/lvmcache.c
@@ -1450,7 +1450,7 @@ struct lvmcache_info *lvmcache_add(struct labeller *labeller, const char *pvid,
const char *vgname, const char *vgid,
uint32_t vgstatus)
{
- const struct format_type *fmt = (const struct format_type *) labeller->private;
+ const struct format_type *fmt = labeller->fmt;
struct dev_types *dt = fmt->cmd->dev_types;
struct label *label;
struct lvmcache_info *existing, *info;
@@ -1540,7 +1540,7 @@ struct lvmcache_info *lvmcache_add(struct labeller *labeller, const char *pvid,
label = info->label;
}
- info->fmt = (const struct format_type *) labeller->private;
+ info->fmt = labeller->fmt;
info->status |= CACHE_INVALID;
if (!_lvmcache_update_pvid(info, pvid_s)) {
diff --git a/lib/format1/format1.c b/lib/format1/format1.c
index 7014a35..509167a 100644
--- a/lib/format1/format1.c
+++ b/lib/format1/format1.c
@@ -614,7 +614,7 @@ struct format_type *init_format(struct cmd_context *cmd)
return NULL;
}
- if (!(label_register_handler(FMT_LVM1_NAME, fmt->labeller))) {
+ if (!(label_register_handler(fmt->labeller))) {
log_error("Couldn't register lvm1 label handler.");
fmt->labeller->ops->destroy(fmt->labeller);
dm_free(fmt);
diff --git a/lib/format1/lvm1-label.c b/lib/format1/lvm1-label.c
index 6138a05..c5f9f35 100644
--- a/lib/format1/lvm1-label.c
+++ b/lib/format1/lvm1-label.c
@@ -122,7 +122,7 @@ struct labeller *lvm1_labeller_create(struct format_type *fmt)
}
l->ops = &_lvm1_ops;
- l->private = (const void *) fmt;
+ l->fmt = fmt;
return l;
}
diff --git a/lib/format_pool/format_pool.c b/lib/format_pool/format_pool.c
index 0891524..0f8f3a3 100644
--- a/lib/format_pool/format_pool.c
+++ b/lib/format_pool/format_pool.c
@@ -309,7 +309,7 @@ struct format_type *init_format(struct cmd_context *cmd)
return NULL;
}
- if (!(label_register_handler(FMT_POOL_NAME, fmt->labeller))) {
+ if (!(label_register_handler(fmt->labeller))) {
log_error("Couldn't register pool label handler.");
fmt->labeller->ops->destroy(fmt->labeller);
dm_free(fmt);
diff --git a/lib/format_pool/pool_label.c b/lib/format_pool/pool_label.c
index 7059b98..d453dd9 100644
--- a/lib/format_pool/pool_label.c
+++ b/lib/format_pool/pool_label.c
@@ -99,7 +99,7 @@ struct labeller *pool_labeller_create(struct format_type *fmt)
}
l->ops = &_pool_ops;
- l->private = (const void *) fmt;
+ l->fmt = fmt;
return l;
}
diff --git a/lib/format_text/format-text.c b/lib/format_text/format-text.c
index 950e0d5..e67d24d 100644
--- a/lib/format_text/format-text.c
+++ b/lib/format_text/format-text.c
@@ -2433,7 +2433,7 @@ struct format_type *create_text_format(struct cmd_context *cmd)
goto bad;
}
- if (!(label_register_handler(FMT_TEXT_NAME, fmt->labeller))) {
+ if (!(label_register_handler(fmt->labeller))) {
log_error("Couldn't register text label handler.");
fmt->labeller->ops->destroy(fmt->labeller);
goto bad;
diff --git a/lib/format_text/text_label.c b/lib/format_text/text_label.c
index 3408590..516d694 100644
--- a/lib/format_text/text_label.c
+++ b/lib/format_text/text_label.c
@@ -316,7 +316,7 @@ struct _update_mda_baton {
static int _update_mda(struct metadata_area *mda, void *baton)
{
struct _update_mda_baton *p = baton;
- const struct format_type *fmt = p->label->labeller->private; // Oh dear.
+ const struct format_type *fmt = p->label->labeller->fmt;
struct mda_context *mdac = (struct mda_context *) mda->metadata_locn;
struct mda_header *mdah;
const char *vgname = NULL;
@@ -471,7 +471,7 @@ struct labeller *text_labeller_create(const struct format_type *fmt)
}
l->ops = &_text_ops;
- l->private = (const void *) fmt;
+ l->fmt = fmt;
return l;
}
diff --git a/lib/label/label.c b/lib/label/label.c
index a38ba68..cff6464 100644
--- a/lib/label/label.c
+++ b/lib/label/label.c
@@ -76,11 +76,11 @@ void label_exit(void)
dm_list_init(&_labellers);
}
-int label_register_handler(const char *name, struct labeller *handler)
+int label_register_handler(struct labeller *handler)
{
struct labeller_i *li;
- if (!(li = _alloc_li(name, handler)))
+ if (!(li = _alloc_li(handler->fmt->name, handler)))
return_0;
dm_list_add(&_labellers, &li->list);
diff --git a/lib/label/label.h b/lib/label/label.h
index f3268bb..8dc49ff 100644
--- a/lib/label/label.h
+++ b/lib/label/label.h
@@ -87,13 +87,13 @@ struct label_ops {
struct labeller {
struct label_ops *ops;
- const void *private;
+ struct format_type *fmt;
};
int label_init(void);
void label_exit(void);
-int label_register_handler(const char *name, struct labeller *handler);
+int label_register_handler(struct labeller *handler);
struct labeller *label_get_handler(const char *name);
10 years, 5 months
master - metadata: Nuke the exported "pv_read" function.
by Petr Rockai
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=bead8ef5f03f56...
Commit: bead8ef5f03f563064276037eed5d9ca94b67ead
Parent: ba6d6f002837d0fa2f27ad3660cfde7887870401
Author: Petr Rockai <prockai(a)redhat.com>
AuthorDate: Tue Feb 19 10:57:45 2013 +0100
Committer: Petr Rockai <prockai(a)redhat.com>
CommitterDate: Sun Nov 17 21:41:27 2013 +0100
metadata: Nuke the exported "pv_read" function.
---
lib/metadata/metadata-exported.h | 3 ---
lib/metadata/metadata.c | 36 ------------------------------------
2 files changed, 0 insertions(+), 39 deletions(-)
diff --git a/lib/metadata/metadata-exported.h b/lib/metadata/metadata-exported.h
index c00e4e5..1bf5236 100644
--- a/lib/metadata/metadata-exported.h
+++ b/lib/metadata/metadata-exported.h
@@ -505,9 +505,6 @@ int vg_commit(struct volume_group *vg);
void vg_revert(struct volume_group *vg);
struct volume_group *vg_read_internal(struct cmd_context *cmd, const char *vg_name,
const char *vgid, int warnings, int *consistent);
-struct physical_volume *pv_read(struct cmd_context *cmd, const char *pv_name,
- int warnings,
- int scan_label_only);
#define get_pvs( cmd ) get_pvs_internal((cmd), NULL, NULL)
#define get_pvs_perserve_vg( cmd, pv_list, vg_list ) get_pvs_internal((cmd), (pv_list), (vg_list))
diff --git a/lib/metadata/metadata.c b/lib/metadata/metadata.c
index fa480c8..aa5f124 100644
--- a/lib/metadata/metadata.c
+++ b/lib/metadata/metadata.c
@@ -1339,20 +1339,6 @@ static int pvcreate_check(struct cmd_context *cmd, const char *name,
if (!(pv = find_pv_by_name(cmd, name, 1)))
stack;
- /*
- * If a PV has no MDAs it may appear to be an orphan until the
- * metadata is read off another PV in the same VG. Detecting
- * this means checking every VG by scanning every PV on the
- * system.
- */
- if (pv && is_orphan(pv) && dm_list_empty(&pv->fid->metadata_areas_in_use)) {
- free_pv_fid(pv);
- if (!scan_vgs_for_pvs(cmd, 0))
- return_0;
- if (!(pv = pv_read(cmd, name, 0, 0)))
- stack;
- }
-
/* Allow partial & exported VGs to be destroyed. */
/* We must have -ff to overwrite a non orphan */
if (pv && !is_orphan(pv) && pp->force != DONT_PROMPT_OVERRIDE) {
@@ -3652,28 +3638,6 @@ const char *find_vgname_from_pvname(struct cmd_context *cmd,
return find_vgname_from_pvid(cmd, pvid);
}
-/**
- * pv_read - read and return a handle to a physical volume
- * @cmd: LVM command initiating the pv_read
- * @pv_name: full device name of the PV, including the path
- * @mdas: list of metadata areas of the PV
- * @label_sector: sector number where the PV label is stored on @pv_name
- * @warnings:
- *
- * Returns:
- * PV handle - valid pv_name and successful read of the PV, or
- * NULL - invalid parameter or error in reading the PV
- *
- * Note:
- * FIXME - liblvm todo - make into function that returns handle
- */
-struct physical_volume *pv_read(struct cmd_context *cmd, const char *pv_name,
- int warnings,
- int scan_label_only)
-{
- return _pv_read(cmd, cmd->mem, pv_name, NULL, warnings, scan_label_only);
-}
-
/* FIXME Use label functions instead of PV functions */
static struct physical_volume *_pv_read(struct cmd_context *cmd,
struct dm_pool *pvmem,
10 years, 5 months