master - WHATS_NEW: commit 76467bdcfd297ffbe2c088b6340ecc7d17d56742
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=ca1abe70ff6f6e...
Commit: ca1abe70ff6f6efc6bd49c648aa3e6b8fab184fd
Parent: 63f5be01702f3344fe2e95eea74c5149bab2d78d
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Wed Jun 18 12:30:34 2014 +0200
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Wed Jun 18 12:30:34 2014 +0200
WHATS_NEW: commit 76467bdcfd297ffbe2c088b6340ecc7d17d56742
Ordering string list items on reports is also new compared to
previous state where items were not ordered at all and they
got reported simply as they appeared/were processed.
---
WHATS_NEW_DM | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/WHATS_NEW_DM b/WHATS_NEW_DM
index d1b05cb..9e6f92e 100644
--- a/WHATS_NEW_DM
+++ b/WHATS_NEW_DM
@@ -7,6 +7,7 @@ Version 1.02.88 -
Add dm_report_reserved_value to libdevmapper for reserved value definition.
Also display field types when listing all fields in selection help.
Recognize "help" keyword in selection string to show brief help for selection.
+ Always order items reported as string list field lexicographically.
Add dm_report_field_string_list to libdevmapper for direct string list report.
Add DM_REPORT_FIELD_TYPE_STRING_LIST: separate string and string list fields.
Add dm_str_list to libdevmapper for string list type definition and its reuse.
8 years, 9 months
master - WHATS_NEW: commits 7dbbc05a69c4cb9756464720cad29e3c1ed971c3..b16f5633ab199dedfd25f08562f686a6fb4aba9d
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=63f5be01702f33...
Commit: 63f5be01702f3344fe2e95eea74c5149bab2d78d
Parent: 5ebff6cc9f631b7409d99b72fa0b39ccec30bf1f
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Wed Jun 18 10:48:53 2014 +0200
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Wed Jun 18 10:48:53 2014 +0200
WHATS_NEW: commits 7dbbc05a69c4cb9756464720cad29e3c1ed971c3..b16f5633ab199dedfd25f08562f686a6fb4aba9d
Report selection support...
---
WHATS_NEW | 5 +++++
WHATS_NEW_DM | 13 +++++++++++++
2 files changed, 18 insertions(+), 0 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index 5a9a498..5d59845 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,10 @@
Version 2.02.107 -
==================================
+ Update pvs,vgs,lvs and lvm man page for selection support.
+ Add -S/--select to lvm devtypes for report selection.
+ Add -S/--select to pvs,vgs,lvs and {pv,vg,lv}display -C for report selection.
+ Use dm_report_init_with_selection now, implicit "selected" field appears.
+ Make use of libdm's DM_REPORT_FIELD_TYPE{SIZE,PERCENT,STRING_LIST} for fields.
Add support for all-or-nothing (atomic) pvmove.
Automatically add snapshot metadata size for -l %ORIGIN calculation.
When converting RAID origin to cache LV, properly rename sub-LVs.
diff --git a/WHATS_NEW_DM b/WHATS_NEW_DM
index 90dd5f5..d1b05cb 100644
--- a/WHATS_NEW_DM
+++ b/WHATS_NEW_DM
@@ -1,5 +1,18 @@
Version 1.02.88 -
=================================
+ Recognize implicit "selected" field if using dm_report_init_with_selection.
+ Add support for implicit reporting fields which are predefined in libdm.
+ Add DM_REPORT_FIELD_TYPE_PERCENT: separate number and percent fields.
+ Add dm_percent_range_t,dm_percent_to_float,dm_make_percent to libdm for reuse.
+ Add dm_report_reserved_value to libdevmapper for reserved value definition.
+ Also display field types when listing all fields in selection help.
+ Recognize "help" keyword in selection string to show brief help for selection.
+ Add dm_report_field_string_list to libdevmapper for direct string list report.
+ Add DM_REPORT_FIELD_TYPE_STRING_LIST: separate string and string list fields.
+ Add dm_str_list to libdevmapper for string list type definition and its reuse.
+ Add dmsetup -S/--select to define selection criteria for dmsetup reports.
+ Add dm_report_init_with_selection to intialize report with selection criteria.
+ Add DM_REPORT_FIELD_TYPE_SIZE: separate number and size reporting fields.
Use RemoveOnStop for dm-event.socket systemd unit.
Document env var 'DM_DEFAULT_NAME_MANGLING_MODE' in dmsetup man page.
Warn user about incorrect use of cookie with 'dmsetup remove --force'.
8 years, 9 months
master - pvmove: Enable all-or-nothing (atomic) pvmoves
by Jonathan Brassow
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=5ebff6cc9f631b...
Commit: 5ebff6cc9f631b7409d99b72fa0b39ccec30bf1f
Parent: b16f5633ab199dedfd25f08562f686a6fb4aba9d
Author: Jonathan Brassow <jbrassow(a)redhat.com>
AuthorDate: Tue Jun 17 22:59:36 2014 -0500
Committer: Jonathan Brassow <jbrassow(a)redhat.com>
CommitterDate: Tue Jun 17 22:59:36 2014 -0500
pvmove: Enable all-or-nothing (atomic) pvmoves
pvmove can be used to move single LVs by name or multiple LVs that
lie within the specified PV range (e.g. /dev/sdb1:0-1000). When
moving more than one LV, the portions of those LVs that are in the
range to be moved are added to a new temporary pvmove LV. The LVs
then point to the range in the pvmove LV, rather than the PV
range.
Example 1:
We have two LVs in this example. After they were
created, the first LV was grown, yeilding two segments
in LV1. So, there are two LVs with a total of three
segments.
Before pvmove:
--------- --------- ---------
| LV1s0 | | LV2s0 | | LV1s1 |
--------- --------- ---------
| | |
-------------------------------------
PV | 000 - 255 | 256 - 511 | 512 - 767 |
-------------------------------------
After pvmove inserts the temporary pvmove LV:
--------- --------- ---------
| LV1s0 | | LV2s0 | | LV1s1 |
--------- --------- ---------
| | |
-------------------------------------
pvmove0 | seg 0 | seg 1 | seg 2 |
-------------------------------------
| | |
-------------------------------------
PV | 000 - 255 | 256 - 511 | 512 - 767 |
-------------------------------------
Each of the affected LV segments now point to a
range of blocks in the pvmove LV, which purposefully
corresponds to the segments moved from the original
LVs into the temporary pvmove LV.
The current implementation goes on from here to mirror the temporary
pvmove LV by segment. Further, as the pvmove LV is activated, only
one of its segments is actually mirrored (i.e. "moving") at a time.
The rest are either complete or not addressed yet. If the pvmove
is aborted, those segments that are completed will remain on the
destination and those that are not yet addressed or in the process
of moving will stay on the source PV. Thus, it is possible to have
a partially completed move - some LVs (or certain segments of LVs)
on the source PV and some on the destination.
Example 2:
What 'example 1' might look if it was half-way
through the move.
--------- --------- ---------
| LV1s0 | | LV2s0 | | LV1s1 |
--------- --------- ---------
| | |
-------------------------------------
pvmove0 | seg 0 | seg 1 | seg 2 |
-------------------------------------
| | |
| -------------------------
source PV | | 256 - 511 | 512 - 767 |
| -------------------------
| ||
-------------------------
dest PV | 000 - 255 | 256 - 511 |
-------------------------
This update allows the user to specify that they would like the
pvmove mirror created "by LV" rather than "by segment". That is,
the pvmove LV becomes an image in an encapsulating mirror along
with the allocated copy image.
Example 3:
A pvmove that is performed "by LV" rather than "by segment".
--------- ---------
| LV1s0 | | LV2s0 |
--------- ---------
| |
-------------------------
pvmove0 | * LV-level mirror * |
-------------------------
/ \
pvmove_mimage0 / pvmove_mimage1
------------------------- -------------------------
| seg 0 | seg 1 | | seg 0 | seg 1 |
------------------------- -------------------------
| | | |
------------------------- -------------------------
| 000 - 255 | 256 - 511 | | 000 - 255 | 256 - 511 |
------------------------- -------------------------
source PV dest PV
The thing that differentiates a pvmove done in this way and a simple
"up-convert" from linear to mirror is the preservation of the
distinct segments. A normal up-convert would simply allocate the
necessary space with no regard for segment boundaries. The pvmove
operation must preserve the segments because they are the critical
boundary between the segments of the LVs being moved. So, when the
pvmove copy image is allocated, all corresponding segments must be
allocated. The code that merges ajoining segments that are part of
the same LV when the metadata is written must also be avoided in
this case. This method of mirroring is unique enough to warrant its
own definitional macro, MIRROR_BY_SEGMENTED_LV. This joins the two
existing macros: MIRROR_BY_SEG (for original pvmove) and MIRROR_BY_LV
(for user created mirrors).
The advantages of performing pvmove in this way is that all of the
LVs affected can be moved together. It is an all-or-nothing approach
that leaves all LV segments on the source PV if the move is aborted.
Additionally, a mirror log can be used (in the future) to provide tracking
of progress; allowing the copy to continue where it left off in the event
there is a deactivation.
---
WHATS_NEW | 1 +
lib/metadata/lv_alloc.h | 3 +
lib/metadata/lv_manip.c | 108 ++++++++++++++++++++++++++++++++++-
lib/metadata/merge.c | 7 ++-
lib/metadata/metadata-exported.h | 4 +
lib/metadata/mirror.c | 66 +++++++++++++++++----
man/pvmove.8.in | 34 ++++++++++-
test/shell/pvmove-background.sh | 7 ++-
test/shell/pvmove-basic.sh | 78 +++++++++++++++----------
test/shell/pvmove-cache-segtypes.sh | 24 +++++---
test/shell/pvmove-raid-segtypes.sh | 17 ++++--
test/shell/pvmove-restart.sh | 8 ++-
test/shell/pvmove-thin-segtypes.sh | 13 +++-
tools/args.h | 1 +
tools/commands.h | 3 +-
tools/pvmove.c | 45 ++++++++++++++-
16 files changed, 344 insertions(+), 75 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index 77dfdcf..5a9a498 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
Version 2.02.107 -
==================================
+ Add support for all-or-nothing (atomic) pvmove.
Automatically add snapshot metadata size for -l %ORIGIN calculation.
When converting RAID origin to cache LV, properly rename sub-LVs.
Use RemoveOnStop for lvm2-lvmetad.socket systemd unit.
diff --git a/lib/metadata/lv_alloc.h b/lib/metadata/lv_alloc.h
index 395420d..f99e1a1 100644
--- a/lib/metadata/lv_alloc.h
+++ b/lib/metadata/lv_alloc.h
@@ -68,6 +68,9 @@ int lv_add_segment(struct alloc_handle *ah,
int lv_add_mirror_areas(struct alloc_handle *ah,
struct logical_volume *lv, uint32_t le,
uint32_t region_size);
+int lv_add_segmented_mirror_image(struct alloc_handle *ah,
+ struct logical_volume *lv, uint32_t le,
+ uint32_t region_size);
int lv_add_mirror_lvs(struct logical_volume *lv,
struct logical_volume **sub_lvs,
uint32_t num_extra_areas,
diff --git a/lib/metadata/lv_manip.c b/lib/metadata/lv_manip.c
index 0aac385..b05f6cc 100644
--- a/lib/metadata/lv_manip.c
+++ b/lib/metadata/lv_manip.c
@@ -2712,6 +2712,112 @@ static struct lv_segment *_convert_seg_to_mirror(struct lv_segment *seg,
/*
* Add new areas to mirrored segments
*/
+int lv_add_segmented_mirror_image(struct alloc_handle *ah,
+ struct logical_volume *lv, uint32_t le,
+ uint32_t region_size)
+{
+ char *image_name;
+ struct alloced_area *aa;
+ struct lv_segment *seg, *new_seg;
+ uint32_t current_le = le;
+ uint32_t s;
+ struct segment_type *segtype;
+ struct logical_volume *orig_lv, *copy_lv;
+
+ if (!(lv->status & PVMOVE)) {
+ log_error(INTERNAL_ERROR
+ "Non-pvmove LV, %s, passed as argument", lv->name);
+ return 0;
+ }
+
+ if (seg_type(first_seg(lv), 0) != AREA_PV) {
+ log_error(INTERNAL_ERROR
+ "Bad segment type for first segment area");
+ return 0;
+ }
+
+ /*
+ * Perform any necessary segment splitting before creating
+ * the mirror layer.
+ */
+ dm_list_iterate_items(aa, &ah->alloced_areas[0]) {
+ if (!(seg = find_seg_by_le(lv, current_le))) {
+ log_error("Failed to find segment for %s extent %"
+ PRIu32, lv->name, current_le);
+ return 0;
+ }
+
+ /* Allocator assures aa[0].len <= seg->area_len */
+ if (aa[0].len < seg->area_len) {
+ if (!lv_split_segment(lv, seg->le + aa[0].len)) {
+ log_error("Failed to split segment at %s "
+ "extent %" PRIu32, lv->name, le);
+ return 0;
+ }
+ }
+ current_le += seg->area_len;
+ }
+ current_le = le;
+
+ if (!insert_layer_for_lv(lv->vg->cmd, lv, PVMOVE, "_mimage_0")) {
+ log_error("Failed to build pvmove LV-type mirror, %s",
+ lv->name);
+ return 0;
+ }
+ orig_lv = seg_lv(first_seg(lv), 0);
+ if (!(image_name = dm_pool_strdup(lv->vg->vgmem, orig_lv->name)))
+ return_0;
+ image_name[strlen(image_name) - 1] = '1';
+
+ if (!(copy_lv = lv_create_empty(image_name, NULL,
+ orig_lv->status,
+ ALLOC_INHERIT, lv->vg)))
+ return_0;
+
+ if (!lv_add_mirror_lvs(lv, ©_lv, 1, MIRROR_IMAGE, region_size))
+ return_0;
+
+ if (!(segtype = get_segtype_from_string(lv->vg->cmd, "striped")))
+ return_0;
+
+ dm_list_iterate_items(aa, &ah->alloced_areas[0]) {
+ if (!(seg = find_seg_by_le(orig_lv, current_le))) {
+ log_error("Failed to find segment for %s extent %"
+ PRIu32, lv->name, current_le);
+ return 0;
+ }
+
+ if (!(new_seg = alloc_lv_segment(segtype, copy_lv,
+ seg->le, seg->len, PVMOVE, 0,
+ NULL, NULL, 1, seg->len,
+ 0, 0, 0, NULL)))
+ return_0;
+
+ for (s = 0; s < ah->area_count; s++) {
+ if (!set_lv_segment_area_pv(new_seg, s,
+ aa[s].pv, aa[s].pe))
+ return_0;
+ }
+
+ dm_list_add(©_lv->segments, &new_seg->list);
+
+ current_le += seg->area_len;
+ copy_lv->le_count += seg->area_len;
+ }
+ lv->status |= MIRRORED;
+
+ /* FIXME: add log */
+
+ if (lv->vg->fid->fmt->ops->lv_setup &&
+ !lv->vg->fid->fmt->ops->lv_setup(lv->vg->fid, lv))
+ return_0;
+
+ return 1;
+}
+
+/*
+ * Add new areas to mirrored segments
+ */
int lv_add_mirror_areas(struct alloc_handle *ah,
struct logical_volume *lv, uint32_t le,
uint32_t region_size)
@@ -5116,7 +5222,7 @@ int remove_layers_for_segments(struct cmd_context *cmd,
layer_lv->name, lseg->le);
return 0;
}
- if ((lseg->status & status_mask) != status_mask) {
+ if (((lseg->status & status_mask) != status_mask)) {
log_error("Layer status does not match: "
"%s:%" PRIu32 " status: 0x%" PRIx64 "/0x%" PRIx64,
layer_lv->name, lseg->le,
diff --git a/lib/metadata/merge.c b/lib/metadata/merge.c
index 9d6df34..142d4d8 100644
--- a/lib/metadata/merge.c
+++ b/lib/metadata/merge.c
@@ -38,11 +38,16 @@ static int _merge(struct lv_segment *first, struct lv_segment *second)
int lv_merge_segments(struct logical_volume *lv)
{
struct dm_list *segh, *t;
- struct lv_segment *current, *prev = NULL;
+ struct lv_segment *seg, *current, *prev = NULL;
if (lv->status & LOCKED || lv->status & PVMOVE)
return 1;
+ if ((lv->status & MIRROR_IMAGE) &&
+ (seg = get_only_segment_using_this_lv(lv)) &&
+ (seg->lv->status & LOCKED || seg->lv->status & PVMOVE))
+ return 1;
+
dm_list_iterate_safe(segh, t, &lv->segments) {
current = dm_list_item(segh, struct lv_segment);
diff --git a/lib/metadata/metadata-exported.h b/lib/metadata/metadata-exported.h
index 237ed18..90fd6d8 100644
--- a/lib/metadata/metadata-exported.h
+++ b/lib/metadata/metadata-exported.h
@@ -133,6 +133,10 @@
/* Mirror conversion type flags */
#define MIRROR_BY_SEG 0x00000001U /* segment-by-segment mirror */
#define MIRROR_BY_LV 0x00000002U /* mirror using whole mimage LVs */
+#define MIRROR_BY_SEGMENTED_LV 0x00000004U /* mirror using whole mimage
+ * LVs, but preserve the
+ * segment layout templated by
+ * the primary mimage */
#define MIRROR_SKIP_INIT_SYNC 0x00000010U /* skip initial sync */
/* vg_read and vg_read_for_update flags */
diff --git a/lib/metadata/mirror.c b/lib/metadata/mirror.c
index 81a5f19..ca0c2a1 100644
--- a/lib/metadata/mirror.c
+++ b/lib/metadata/mirror.c
@@ -842,7 +842,7 @@ static int _remove_mirror_images(struct logical_volume *lv,
struct logical_volume *sub_lv;
struct logical_volume *detached_log_lv = NULL;
struct logical_volume *temp_layer_lv = NULL;
- struct lv_segment *mirrored_seg = first_seg(lv);
+ struct lv_segment *pvmove_seg, *mirrored_seg = first_seg(lv);
uint32_t old_area_count = mirrored_seg->area_count;
uint32_t new_area_count = mirrored_seg->area_count;
struct lv_list *lvl;
@@ -949,6 +949,10 @@ static int _remove_mirror_images(struct logical_volume *lv,
mirrored_seg = first_seg(lv);
if (remove_log && !detached_log_lv)
detached_log_lv = detach_mirror_log(mirrored_seg);
+
+ if (lv->status & PVMOVE)
+ dm_list_iterate_items(pvmove_seg, &lv->segments)
+ pvmove_seg->status |= PVMOVE;
} else if (new_area_count == 0) {
log_very_verbose("All mimages of %s are gone", lv->name);
@@ -1557,7 +1561,9 @@ struct logical_volume *find_pvmove_lv(struct volume_group *vg,
/* Check segment origins point to pvname */
dm_list_iterate_items(seg, &lv->segments) {
- if (seg_type(seg, 0) != AREA_PV)
+ if (seg_type(seg, 0) == AREA_LV) /* Atomic pvmove */
+ seg = first_seg(seg_lv(seg, 0));
+ if (seg_type(seg, 0) != AREA_PV) /* Segment pvmove */
continue;
if (seg_dev(seg, 0) != dev)
continue;
@@ -1652,13 +1658,14 @@ int fixup_imported_mirrors(struct volume_group *vg)
return 1;
}
-/*
- * Add mirrors to "linear" or "mirror" segments
- */
-int add_mirrors_to_segments(struct cmd_context *cmd, struct logical_volume *lv,
- uint32_t mirrors, uint32_t region_size,
- struct dm_list *allocatable_pvs, alloc_policy_t alloc)
+static int _add_mirrors_that_preserve_segments(struct logical_volume *lv,
+ uint32_t flags,
+ uint32_t mirrors,
+ uint32_t region_size,
+ struct dm_list *allocatable_pvs,
+ alloc_policy_t alloc)
{
+ struct cmd_context *cmd = lv->vg->cmd;
struct alloc_handle *ah;
const struct segment_type *segtype;
struct dm_list *parallel_areas;
@@ -1682,16 +1689,38 @@ int add_mirrors_to_segments(struct cmd_context *cmd, struct logical_volume *lv,
return 0;
}
- if (!lv_add_mirror_areas(ah, lv, 0, adjusted_region_size)) {
- log_error("Failed to add mirror areas to %s", lv->name);
+ if (flags & MIRROR_BY_SEG) {
+ if (!lv_add_mirror_areas(ah, lv, 0, adjusted_region_size)) {
+ log_error("Failed to add mirror areas to %s", lv->name);
+ r = 0;
+ }
+ } else if (flags & MIRROR_BY_SEGMENTED_LV) {
+ if (!lv_add_segmented_mirror_image(ah, lv, 0,
+ adjusted_region_size)) {
+ log_error("Failed to add mirror areas to %s", lv->name);
+ r = 0;
+ }
+ } else {
+ log_error(INTERNAL_ERROR "Unknown mirror flag");
r = 0;
}
-
alloc_destroy(ah);
return r;
}
/*
+ * Add mirrors to "linear" or "mirror" segments
+ */
+int add_mirrors_to_segments(struct cmd_context *cmd, struct logical_volume *lv,
+ uint32_t mirrors, uint32_t region_size,
+ struct dm_list *allocatable_pvs, alloc_policy_t alloc)
+{
+ return _add_mirrors_that_preserve_segments(lv, MIRROR_BY_SEG,
+ mirrors, region_size,
+ allocatable_pvs, alloc);
+}
+
+/*
* Convert mirror log
*
* FIXME: Can't handle segment-by-segment mirror (like pvmove)
@@ -2112,8 +2141,19 @@ int lv_add_mirrors(struct cmd_context *cmd, struct logical_volume *lv,
return 0;
}
- return add_mirrors_to_segments(cmd, lv, mirrors,
- region_size, pvs, alloc);
+ return _add_mirrors_that_preserve_segments(lv, MIRROR_BY_SEG,
+ mirrors, region_size,
+ pvs, alloc);
+ } else if (flags & MIRROR_BY_SEGMENTED_LV) {
+ if (stripes > 1) {
+ log_error("Striped-mirroring is not supported on "
+ "segment-by-segment mirroring");
+ return 0;
+ }
+
+ return _add_mirrors_that_preserve_segments(lv, MIRROR_BY_SEGMENTED_LV,
+ mirrors, region_size,
+ pvs, alloc);
} else if (flags & MIRROR_BY_LV) {
if (!mirrors)
return add_mirror_log(cmd, lv, log_count,
diff --git a/man/pvmove.8.in b/man/pvmove.8.in
index 0f58b05..43a4e00 100644
--- a/man/pvmove.8.in
+++ b/man/pvmove.8.in
@@ -6,6 +6,7 @@ pvmove \(em move physical extents
.RB [ \-\-abort ]
.RB [ \-\-alloc
.IR AllocationPolicy ]
+.RB [ \-\-atomic ]
.RB [ \-b | \-\-background ]
.RB [ \-\-commandprofile
.IR ProfileName ]
@@ -35,8 +36,11 @@ is specified, the normal allocation rules for the Volume Group are used.
If pvmove gets interrupted for any reason (e.g. the machine crashes)
then run pvmove again without any PhysicalVolume arguments to
restart any moves that were in progress from the last checkpoint.
-Alternatively use \fBpvmove \-\-abort\fP at any time to abort them
-at the last checkpoint.
+Alternatively use \fBpvmove \-\-abort\fP at any time to abort. The
+resulting location of logical volumes after an abort is issued depends
+on whether the
+.B \-\-atomic
+option was used when starting the pvmove process.
You can run more than one pvmove at once provided they are moving data
off different SourcePhysicalVolumes, but additional pvmoves will ignore
@@ -77,11 +81,35 @@ is updated so that the Logical Volumes reflect the new data locations.
Note that this new process cannot support the original LVM1
type of on-disk metadata. Metadata can be converted using \fBvgconvert\fP(8).
+If the
+.B \-\-atomic
+option is used, a slightly different approach is used for the move. Again,
+a temporary 'pvmove' logical volume is created to store the details of all
+the data movements required. This temporary LV contains all the segments of
+the various LVs that need to be moved. However this time, an identical
+logical volume is allocated that contains the same number of segments and
+a mirror is created to copy the contents from the first temporary LV to the
+second. When a complete copy is accomplished, the temporary logical volumes
+are removed, leaving behind the segments on the destination physical volume.
+If an abort is issued during the move, all logical volumes being moved will
+remain on the source physical volume.
+
.SH OPTIONS
See \fBlvm\fP(8) for common options.
.TP
.B \-\-abort
-Abort any moves in progress.
+Abort any moves in progress. If the
+.B \-\-atomic
+option was used to start the pvmove, all logical volumes will remain on
+the source physical volume. Otherwise, those segments that have completed
+the move will stay on the destination physical volume, while those that
+have not will remain on the source physical volume.
+.TP
+.B \-\-atomic
+Make the entire operation atomic. That is, ensure that all affected logical
+volumes are moved to the destination physical volume together; unless the move
+has been aborted. If the move has been aborted, all logical volumes will
+remain on the source physical volume.
.TP
.B \-\-noudevsync
Disable udev synchronisation. The
diff --git a/test/shell/pvmove-background.sh b/test/shell/pvmove-background.sh
index 0cd5dd3..8f59301 100644
--- a/test/shell/pvmove-background.sh
+++ b/test/shell/pvmove-background.sh
@@ -15,10 +15,15 @@
aux prepare_vg 3
+for mode in "--atomic" ""
+do
lvcreate -aey -l1 -n $lv1 $vg "$dev1"
lvs -o +devices | grep $dev1
-pvmove -i 1 -b "$dev1" "$dev2"
+pvmove $mode -i 1 -b "$dev1" "$dev2"
sleep 5 # arbitrary...
lvs -o +devices | not grep "pvmove"
lvs -o +devices | grep "$dev2"
+
+lvremove -ff $vg
+done
\ No newline at end of file
diff --git a/test/shell/pvmove-basic.sh b/test/shell/pvmove-basic.sh
index e58f5bf..bdfb79a 100644
--- a/test/shell/pvmove-basic.sh
+++ b/test/shell/pvmove-basic.sh
@@ -80,6 +80,9 @@ check_and_cleanup_lvs_() {
aux prepare_pvs 5 5
create_vg_
+for mode in "--atomic" ""
+do
+
#COMM "check environment setup/cleanup"
prepare_lvs_
check_and_cleanup_lvs_
@@ -92,7 +95,7 @@ check_and_cleanup_lvs_
#COMM "only specified LV is moved: from pv2 to pv5 only for lv1"
restore_lvs_
-pvmove -i1 -n $vg/$lv1 "$dev2" "$dev5"
+pvmove $mode -i1 -n $vg/$lv1 "$dev2" "$dev5"
check lv_on $vg $lv1 "$dev1" "$dev5" "$dev3"
lvs_not_changed_ $lv2 $lv3
check_and_cleanup_lvs_
@@ -102,21 +105,21 @@ check_and_cleanup_lvs_
#COMM "the 1st seg of 3-segs LV is moved: from pv1 of lv1 to pv4"
restore_lvs_
-pvmove -i0 -n $vg/$lv1 "$dev1" "$dev4"
+pvmove $mode -i0 -n $vg/$lv1 "$dev1" "$dev4"
check lv_on $vg $lv1 "$dev4" "$dev2" "$dev3"
lvs_not_changed_ $lv2 $lv3
check_and_cleanup_lvs_
#COMM "the 2nd seg of 3-segs LV is moved: from pv2 of lv1 to pv4"
restore_lvs_
-pvmove -i0 -n $vg/$lv1 "$dev2" "$dev4"
+pvmove $mode -i0 -n $vg/$lv1 "$dev2" "$dev4"
check lv_on $vg $lv1 "$dev1" "$dev4" "$dev3"
lvs_not_changed_ $lv2 $lv3
check_and_cleanup_lvs_
#COMM "the 3rd seg of 3-segs LV is moved: from pv3 of lv1 to pv4"
restore_lvs_
-pvmove -i0 -n $vg/$lv1 "$dev3" "$dev4"
+pvmove $mode -i0 -n $vg/$lv1 "$dev3" "$dev4"
check lv_on $vg $lv1 "$dev1" "$dev2" "$dev4"
lvs_not_changed_ $lv2 $lv3
check_and_cleanup_lvs_
@@ -126,14 +129,14 @@ check_and_cleanup_lvs_
#COMM "1 out of 3 LVs is moved: from pv4 to pv5"
restore_lvs_
-pvmove -i0 "$dev4" "$dev5"
+pvmove $mode -i0 "$dev4" "$dev5"
check lv_on $vg $lv2 "$dev2" "$dev3" "$dev5"
lvs_not_changed_ $lv1 $lv3
check_and_cleanup_lvs_
#COMM "2 out of 3 LVs are moved: from pv3 to pv5"
restore_lvs_
-pvmove -i0 "$dev3" "$dev5"
+pvmove $mode -i0 "$dev3" "$dev5"
check lv_on $vg $lv1 "$dev1" "$dev2" "$dev5"
check lv_on $vg $lv2 "$dev2" "$dev5" "$dev4"
lvs_not_changed_ $lv3
@@ -141,7 +144,7 @@ check_and_cleanup_lvs_
#COMM "3 out of 3 LVs are moved: from pv2 to pv5"
restore_lvs_
-pvmove -i0 "$dev2" "$dev5"
+pvmove $mode -i0 "$dev2" "$dev5"
check lv_on $vg $lv1 "$dev1" "$dev5" "$dev3"
check lv_on $vg $lv2 "$dev5" "$dev3" "$dev4"
check lv_on $vg $lv3 "$dev5"
@@ -152,21 +155,21 @@ check_and_cleanup_lvs_
#COMM "move the 1st stripe: from pv2 of lv2 to pv1"
restore_lvs_
-pvmove -i0 -n $vg/$lv2 "$dev2" "$dev1"
+pvmove $mode -i0 -n $vg/$lv2 "$dev2" "$dev1"
check lv_on $vg $lv2 "$dev1" "$dev3" "$dev4"
lvs_not_changed_ $lv1 $lv3
check_and_cleanup_lvs_
#COMM "move the 2nd stripe: from pv3 of lv2 to pv1"
restore_lvs_
-pvmove -i0 -n $vg/$lv2 "$dev3" "$dev1"
+pvmove $mode -i0 -n $vg/$lv2 "$dev3" "$dev1"
check lv_on $vg $lv2 "$dev2" "$dev1" "$dev4"
lvs_not_changed_ $lv1 $lv3
check_and_cleanup_lvs_
#COMM "move the 3rd stripe: from pv4 of lv2 to pv1"
restore_lvs_
-pvmove -i0 -n $vg/$lv2 "$dev4" "$dev1"
+pvmove $mode -i0 -n $vg/$lv2 "$dev4" "$dev1"
check lv_on $vg $lv2 "$dev2" "$dev3" "$dev1"
lvs_not_changed_ $lv1 $lv3
check_and_cleanup_lvs_
@@ -176,21 +179,21 @@ check_and_cleanup_lvs_
#COMM "match to the start of segment:from pv2:0-0 to pv5"
restore_lvs_
-pvmove -i0 "$dev2":0-0 "$dev5"
+pvmove $mode -i0 "$dev2":0-0 "$dev5"
check lv_on $vg $lv2 "$dev5" "$dev2" "$dev3" "$dev4"
lvs_not_changed_ $lv1 $lv3
check_and_cleanup_lvs_
#exit 0
#COMM "match to the middle of segment: from pv2:1-1 to pv5"
restore_lvs_
-pvmove -i0 "$dev2":1-1 "$dev5"
+pvmove $mode -i0 "$dev2":1-1 "$dev5"
check lv_on $vg $lv2 "$dev2" "$dev3" "$dev4" "$dev5"
lvs_not_changed_ $lv1 $lv3
check_and_cleanup_lvs_
#COMM "match to the end of segment: from pv2:2-2 to pv5"
restore_lvs_
-pvmove -i0 "$dev2":2-2 "$dev5"
+pvmove $mode -i0 "$dev2":2-2 "$dev5"
check lv_on $vg $lv2 "$dev2" "$dev5" "$dev3" "$dev4"
lvs_not_changed_ $lv1 $lv3
check_and_cleanup_lvs_
@@ -200,21 +203,21 @@ check_and_cleanup_lvs_
#COMM "no destination split: from pv2:0-2 to pv5"
restore_lvs_
-pvmove -i0 "$dev2":0-2 "$dev5"
+pvmove $mode -i0 "$dev2":0-2 "$dev5"
check lv_on $vg $lv2 "$dev5" "$dev3" "$dev4"
lvs_not_changed_ $lv1 $lv3
check_and_cleanup_lvs_
#COMM "destination split into 2: from pv2:0-2 to pv5:5-5 and pv4:5-6"
restore_lvs_
-pvmove -i0 --alloc anywhere "$dev2":0-2 "$dev5":5-5 "$dev4":5-6
+pvmove $mode -i0 --alloc anywhere "$dev2":0-2 "$dev5":5-5 "$dev4":5-6
check lv_on $vg $lv2 "$dev5" "$dev4" "$dev3"
lvs_not_changed_ $lv1 $lv3
check_and_cleanup_lvs_
#COMM "destination split into 3: from pv2:0-2 to {pv3,4,5}:5-5"
restore_lvs_
-pvmove -i0 --alloc anywhere "$dev2":0-2 "$dev3":5-5 "$dev4":5-5 "$dev5":5-5
+pvmove $mode -i0 --alloc anywhere "$dev2":0-2 "$dev3":5-5 "$dev4":5-5 "$dev5":5-5
check lv_on $vg $lv2 "$dev3" "$dev4" "$dev5"
lvs_not_changed_ $lv1 $lv3
check_and_cleanup_lvs_
@@ -224,14 +227,14 @@ check_and_cleanup_lvs_
#COMM "alloc normal on same PV for source and destination: from pv3:0-2 to pv3:5-7"
restore_lvs_
-not pvmove -i0 "$dev3":0-2 "$dev3":5-7
+not pvmove $mode -i0 "$dev3":0-2 "$dev3":5-7
# "(cleanup previous test)"
lvs_not_changed_ $lv1 $lv2 $lv3
check_and_cleanup_lvs_
#COMM "alloc anywhere on same PV for source and destination: from pv3:0-2 to pv3:5-7"
restore_lvs_
-pvmove -i0 --alloc anywhere "$dev3":0-2 "$dev3":5-7
+pvmove $mode -i0 --alloc anywhere "$dev3":0-2 "$dev3":5-7
check lv_on $vg $lv2 "$dev2" "$dev3" "$dev4"
lvs_not_changed_ $lv1 $lv3
check_and_cleanup_lvs_
@@ -241,7 +244,7 @@ restore_lvs_
#lvs -a -o name,size,seg_pe_ranges $vg
#LV2 1.12m @TESTDIR@/dev/mapper/@PREFIX@pv2:0-2 @TESTDIR@/dev/mapper/@PREFIX@pv3:0-2 @TESTDIR@/dev/mapper/@PREFIX@pv4:0-2
-pvmove -i0 --alloc anywhere "$dev3":0-2 "$dev3":5-7 "$dev5":5-6 "$dev4":5-5
+pvmove $mode -i0 --alloc anywhere "$dev3":0-2 "$dev3":5-7 "$dev5":5-6 "$dev4":5-5
#lvs -a -o name,size,seg_pe_ranges $vg
# Hmm is this correct ? - why pv2 is split
@@ -253,14 +256,14 @@ check_and_cleanup_lvs_
#COMM "alloc contiguous but area not available: from pv2:0-2 to pv5:5-5 and pv4:5-6"
restore_lvs_
-not pvmove -i0 --alloc contiguous "$dev2":0-2 "$dev5":5-5 "$dev4":5-6
+not pvmove $mode -i0 --alloc contiguous "$dev2":0-2 "$dev5":5-5 "$dev4":5-6
# "(cleanup previous test)"
lvs_not_changed_ $lv1 $lv2 $lv3
check_and_cleanup_lvs_
#COMM "alloc contiguous and contiguous area available: from pv2:0-2 to pv5:0-0,pv5:3-5 and pv4:5-6"
restore_lvs_
-pvmove -i0 --alloc contiguous "$dev2":0-2 "$dev5":0-0 "$dev5":3-5 "$dev4":5-6
+pvmove $mode -i0 --alloc contiguous "$dev2":0-2 "$dev5":0-0 "$dev5":3-5 "$dev4":5-6
check lv_on $vg $lv2 "$dev5" "$dev3" "$dev4"
lvs_not_changed_ $lv1 $lv3
check_and_cleanup_lvs_
@@ -270,7 +273,7 @@ check_and_cleanup_lvs_
#COMM "multiple source LVs: from pv3 to pv5"
restore_lvs_
-pvmove -i0 "$dev3" "$dev5"
+pvmove $mode -i0 "$dev3" "$dev5"
check lv_on $vg $lv1 "$dev1" "$dev2" "$dev5"
check lv_on $vg $lv2 "$dev2" "$dev5" "$dev4"
lvs_not_changed_ $lv3
@@ -283,7 +286,7 @@ check_and_cleanup_lvs_
restore_lvs_
lvchange -an $vg/$lv1
lvchange -an $vg/$lv3
-pvmove -i0 "$dev2" "$dev5"
+pvmove $mode -i0 "$dev2" "$dev5"
check lv_on $vg $lv1 "$dev1" "$dev5" "$dev3"
check lv_on $vg $lv2 "$dev5" "$dev3" "$dev4"
check lv_on $vg $lv3 "$dev5"
@@ -294,8 +297,8 @@ check_and_cleanup_lvs_
#COMM "no PEs to move: from pv3 to pv1"
restore_lvs_
-pvmove -i0 "$dev3" "$dev1"
-not pvmove -i0 "$dev3" "$dev1"
+pvmove $mode -i0 "$dev3" "$dev1"
+not pvmove $mode -i0 "$dev3" "$dev1"
# "(cleanup previous test)"
check lv_on $vg $lv1 "$dev1" "$dev2" "$dev1"
check lv_on $vg $lv2 "$dev2" "$dev1" "$dev4"
@@ -304,21 +307,21 @@ check_and_cleanup_lvs_
#COMM "no space available: from pv2:0-0 to pv1:0-0"
restore_lvs_
-not pvmove -i0 "$dev2":0-0 "$dev1":0-0
+not pvmove $mode -i0 "$dev2":0-0 "$dev1":0-0
# "(cleanup previous test)"
lvs_not_changed_ $lv1 $lv2 $lv3
check_and_cleanup_lvs_
#COMM 'same source and destination: from pv1 to pv1'
restore_lvs_
-not pvmove -i0 "$dev1" "$dev1"
+not pvmove $mode -i0 "$dev1" "$dev1"
#"(cleanup previous test)"
lvs_not_changed_ $lv1 $lv2 $lv3
check_and_cleanup_lvs_
#COMM "sum of specified destination PEs is large enough, but it includes source PEs and the free PEs are not enough"
restore_lvs_
-not pvmove --alloc anywhere "$dev1":0-2 "$dev1":0-2 "$dev5":0-0 2> err
+not pvmove $mode --alloc anywhere "$dev1":0-2 "$dev1":0-2 "$dev5":0-0 2> err
#"(cleanup previous test)"
grep "Insufficient free space" err
lvs_not_changed_ $lv1 $lv2 $lv3
@@ -328,7 +331,7 @@ check_and_cleanup_lvs_
#COMM "pvmove abort"
restore_lvs_
-pvmove -i100 -b "$dev1" "$dev3"
+pvmove $mode -i100 -b "$dev1" "$dev3"
pvmove --abort
check_and_cleanup_lvs_
@@ -338,10 +341,21 @@ pvcreate $(cat DEVICES)
pvcreate --metadatacopies 0 "$dev1" "$dev2"
create_vg_
lvcreate -l4 -n $lv1 $vg "$dev1"
-pvmove "$dev1"
+pvmove $mode "$dev1"
#COMM "pvmove fails activating mirror, properly restores state before pvmove"
dmsetup create $vg-pvmove0 --notable
-not pvmove -i 1 "$dev2"
+not pvmove $mode -i 1 "$dev2"
+echo BARF
+dmsetup ls
+dmsetup info --noheadings -c -o suspended $vg-$lv1
test $(dmsetup info --noheadings -c -o suspended $vg-$lv1) = "Active"
-dmsetup remove $vg-pvmove0
+if [ -e /dev/mapper/$vg-pvmove0_mimage_0 ]; then
+ dmsetup remove $vg-pvmove0 /dev/mapper/$vg-pvmove0_mimage*
+else
+ dmsetup remove $vg-pvmove0
+fi
+dmsetup ls
+
+lvremove -ff $vg
+done
\ No newline at end of file
diff --git a/test/shell/pvmove-cache-segtypes.sh b/test/shell/pvmove-cache-segtypes.sh
index 0c1020e..94a3848 100644
--- a/test/shell/pvmove-cache-segtypes.sh
+++ b/test/shell/pvmove-cache-segtypes.sh
@@ -29,6 +29,8 @@ aux have_raid 1 4 2 || skip
aux prepare_vg 5 80
+for mode in "--atomic" ""
+do
# Each of the following tests does:
# 1) Create two LVs - one linear and one other segment type
# The two LVs will share a PV.
@@ -42,14 +44,14 @@ lvcreate --type cache-pool -n ${lv1}_pool -l 4 $vg "$dev1"
check lv_tree_on $vg ${lv1}_foo "$dev1"
check lv_tree_on $vg ${lv1}_pool "$dev1"
-pvmove "$dev1" "$dev5" 2>&1 | tee out
+pvmove $mode "$dev1" "$dev5" 2>&1 | tee out
grep "Skipping cache-pool LV, ${lv1}_pool" out
grep "Skipping cache-related LV, ${lv1}_pool_cmeta" out
grep "Skipping cache-related LV, ${lv1}_pool_cdata" out
check lv_tree_on $vg ${lv1}_foo "$dev5"
not check lv_tree_on $vg ${lv1}_pool "$dev5"
-#pvmove -n ${lv1}_pool "$dev5" "$dev4"
+#pvmove $mode -n ${lv1}_pool "$dev5" "$dev4"
#check lv_tree_on $vg ${lv1}_pool "$dev4"
#check lv_tree_on $vg ${lv1}_foo "$dev5"
@@ -66,7 +68,7 @@ check lv_tree_on $vg ${lv1}_pool "$dev5"
check lv_tree_on $vg ${lv1} "$dev1"
aux mkdev_md5sum $vg $lv1
-pvmove "$dev1" "$dev3" 2>&1 | tee out
+pvmove $mode "$dev1" "$dev3" 2>&1 | tee out
grep "Skipping cache LV, ${lv1}" out
check lv_tree_on $vg ${lv1}_foo "$dev3"
#check lv_tree_on $vg ${lv1}_pool "$dev5"
@@ -74,7 +76,7 @@ lvs -a -o name,attr,devices $vg
not check lv_tree_on $vg ${lv1} "$dev3"
#check dev_md5sum $vg $lv1
-#pvmove -n $lv1 "$dev3" "$dev1"
+#pvmove $mode -n $lv1 "$dev3" "$dev1"
#check lv_tree_on $vg ${lv1}_foo "$dev3"
#check lv_tree_on $vg ${lv1}_pool "$dev5"
#check lv_tree_on $vg ${lv1} "$dev1"
@@ -91,14 +93,14 @@ check lv_tree_on $vg ${lv1} "$dev1" "$dev2"
check lv_tree_on $vg ${lv1}_pool "$dev5"
aux mkdev_md5sum $vg $lv1
-pvmove "$dev1" "$dev3" 2>&1 | tee out
+pvmove $mode "$dev1" "$dev3" 2>&1 | tee out
grep "Skipping cache LV, ${lv1}" out
check lv_tree_on $vg ${lv1}_foo "$dev3"
not check lv_tree_on $vg ${lv1} "$dev2" "$dev3"
#check lv_tree_on $vg ${lv1}_pool "$dev5"
#check dev_md5sum $vg $lv1 -- THIS IS WHERE THINGS FAIL IF PVMOVE NOT DISALLOWED
-#pvmove -n $lv1 "$dev3" "$dev1"
+#pvmove $mode -n $lv1 "$dev3" "$dev1"
#check lv_tree_on $vg ${lv1}_foo "$dev3"
#check lv_tree_on $vg ${lv1} "$dev1" "$dev2"
#check lv_tree_on $vg ${lv1}_pool "$dev5"
@@ -120,7 +122,7 @@ check lv_tree_on $vg ${lv1} "$dev5"
aux mkdev_md5sum $vg $lv1
# This will move ${lv1}_foo and the cache-pool data & meta
# LVs, both of which contain a RAID1 _rimage & _rmeta LV - 5 total LVs
-pvmove "$dev1" "$dev3" 2>&1 | tee out
+pvmove $mode "$dev1" "$dev3" 2>&1 | tee out
grep "Skipping cache-pool LV, ${lv1}_pool" out
grep "Skipping cache-related LV, ${lv1}_pool_cmeta" out
grep "Skipping cache-related LV, ${lv1}_pool_cdata" out
@@ -129,7 +131,7 @@ not check lv_tree_on $vg ${lv1}_pool "$dev2" "$dev3"
#check lv_tree_on $vg ${lv1} "$dev5"
#check dev_md5sum $vg $lv1
-#pvmove -n ${lv1}_pool "$dev3" "$dev1"
+#pvmove $mode -n ${lv1}_pool "$dev3" "$dev1"
#check lv_tree_on $vg ${lv1}_foo "$dev3"
#check lv_tree_on $vg ${lv1}_pool "$dev1" "$dev2"
#check lv_tree_on $vg ${lv1} "$dev5"
@@ -161,17 +163,19 @@ check lv_tree_on $vg thinpool "$dev1" "$dev3" "$dev4"
aux mkdev_md5sum $vg thin_lv
lvs -a -o name,attr,devices $vg
# Should move ${lv1}_foo and thinpool_tmeta from dev1 to dev5
-pvmove "$dev1" "$dev5" 2>&1 | tee out
+pvmove $mode "$dev1" "$dev5" 2>&1 | tee out
lvs -a -o name,attr,devices $vg
check lv_tree_on $vg ${lv1}_foo "$dev5"
not check lv_tree_on $vg cachepool "$dev5" "$dev2"
check lv_tree_on $vg thinpool "$dev3" "$dev4" "$dev5" # Move non-cache tmeta
#check dev_md5sum $vg/thin_lv
-#pvmove -n $vg/cachepool "$dev5" "$dev1"
+#pvmove $mode -n $vg/cachepool "$dev5" "$dev1"
#check lv_tree_on $vg ${lv1}_foo "$dev5"
#check lv_tree_on $vg $vg/cachepool "$dev1" "$dev2"
#check lv_tree_on $vg $vg/thinpool "$dev3" "$dev4"
#check dev_md5sum $vg/thin_lv
lvremove -ff $vg
+
+done
diff --git a/test/shell/pvmove-raid-segtypes.sh b/test/shell/pvmove-raid-segtypes.sh
index dd12c1b..0accf4a 100644
--- a/test/shell/pvmove-raid-segtypes.sh
+++ b/test/shell/pvmove-raid-segtypes.sh
@@ -21,6 +21,8 @@ aux have_raid 1 3 5 || skip
aux prepare_pvs 5 20
vgcreate -c n -s 128k $vg $(cat DEVICES)
+for mode in "--atomic" ""
+do
# Each of the following tests does:
# 1) Create two LVs - one linear and one other segment type
# The two LVs will share a PV.
@@ -33,11 +35,11 @@ lvcreate -l 2 --type raid1 -m 1 -n $lv1 $vg "$dev1" "$dev2"
check lv_tree_on $vg ${lv1}_foo "$dev1"
check lv_tree_on $vg $lv1 "$dev1" "$dev2"
aux mkdev_md5sum $vg $lv1
-pvmove "$dev1" "$dev5"
+pvmove $mode "$dev1" "$dev5"
check lv_tree_on $vg ${lv1}_foo "$dev5"
check lv_tree_on $vg $lv1 "$dev2" "$dev5"
check dev_md5sum $vg $lv1
-pvmove -n $lv1 "$dev5" "$dev4"
+pvmove $mode -n $lv1 "$dev5" "$dev4"
check lv_tree_on $vg $lv1 "$dev2" "$dev4"
check lv_tree_on $vg ${lv1}_foo "$dev5"
check dev_md5sum $vg $lv1
@@ -50,11 +52,11 @@ lvcreate -l 4 --type raid10 -i 2 -m 1 -n $lv1 $vg \
check lv_tree_on $vg ${lv1}_foo "$dev1"
check lv_tree_on $vg $lv1 "$dev1" "$dev2" "$dev3" "$dev4"
aux mkdev_md5sum $vg $lv1
-pvmove "$dev1" "$dev5"
+pvmove $mode "$dev1" "$dev5"
check lv_tree_on $vg ${lv1}_foo "$dev5"
check lv_tree_on $vg $lv1 "$dev2" "$dev3" "$dev4" "$dev5"
check dev_md5sum $vg $lv1
-pvmove -n $lv1 "$dev5" "$dev1"
+pvmove $mode -n $lv1 "$dev5" "$dev1"
check lv_tree_on $vg $lv1 "$dev1" "$dev2" "$dev3" "$dev4"
check lv_tree_on $vg ${lv1}_foo "$dev5"
check dev_md5sum $vg $lv1
@@ -67,13 +69,16 @@ lvcreate -l 4 --type raid5 -i 2 -n $lv1 $vg \
check lv_tree_on $vg ${lv1}_foo "$dev1"
check lv_tree_on $vg $lv1 "$dev1" "$dev2" "$dev3"
aux mkdev_md5sum $vg $lv1
-pvmove "$dev1" "$dev5"
+pvmove $mode "$dev1" "$dev5"
check lv_tree_on $vg ${lv1}_foo "$dev5"
check lv_tree_on $vg $lv1 "$dev2" "$dev3" "$dev5"
check dev_md5sum $vg $lv1
-pvmove -n $lv1 "$dev5" "$dev4"
+pvmove $mode -n $lv1 "$dev5" "$dev4"
check lv_tree_on $vg $lv1 "$dev2" "$dev3" "$dev4"
check lv_tree_on $vg ${lv1}_foo "$dev5"
check dev_md5sum $vg $lv1
+lvremove -ff $vg
+done
+
vgremove -ff $vg
diff --git a/test/shell/pvmove-restart.sh b/test/shell/pvmove-restart.sh
index 9f30cf7..af079ea 100644
--- a/test/shell/pvmove-restart.sh
+++ b/test/shell/pvmove-restart.sh
@@ -17,6 +17,9 @@ aux prepare_pvs 3 60
vgcreate -s 128k $vg "$dev1" "$dev2" "$dev3"
+for mode in "--atomic" ""
+do
+
# Create multisegment LV
lvcreate -an -Zn -l5 -n $lv1 $vg "$dev1"
lvextend -l+10 $vg/$lv1 "$dev2"
@@ -37,7 +40,7 @@ wait
# Simulate reboot - forcibly remove related devices
dmsetup remove $vg-$lv1
-dmsetup remove $vg-pvmove0
+dmsetup remove /dev/mapper/$vg-pvmove0*
# Check we really have pvmove volume
check lv_attr_bit type $vg/pvmove0 "p"
@@ -81,4 +84,7 @@ aux delay_dev "$dev3"
lvs -a -o+devices $vg
+lvremove -ff $vg
+done
+
vgremove -ff $vg
diff --git a/test/shell/pvmove-thin-segtypes.sh b/test/shell/pvmove-thin-segtypes.sh
index 7819e6c..33128d5 100644
--- a/test/shell/pvmove-thin-segtypes.sh
+++ b/test/shell/pvmove-thin-segtypes.sh
@@ -22,6 +22,9 @@ aux have_raid 1 3 5 || skip
aux prepare_pvs 5 20
vgcreate -c n -s 128k $vg $(cat DEVICES)
+for mode in "--atomic" ""
+do
+
# Each of the following tests does:
# 1) Create two LVs - one linear and one other segment type
# The two LVs will share a PV.
@@ -35,11 +38,11 @@ lvcreate -T $vg/${lv1}_pool -l 4 -V 8 -n $lv1 "$dev1"
check lv_tree_on $vg ${lv1}_foo "$dev1"
check lv_tree_on $vg $lv1 "$dev1"
aux mkdev_md5sum $vg $lv1
-pvmove "$dev1" "$dev5"
+pvmove "$dev1" "$dev5" $mode
check lv_tree_on $vg ${lv1}_foo "$dev5"
check lv_tree_on $vg $lv1 "$dev5"
check dev_md5sum $vg $lv1
-pvmove -n $lv1 "$dev5" "$dev4"
+pvmove -n $lv1 "$dev5" "$dev4" $mode
check lv_tree_on $vg $lv1 "$dev4"
check lv_tree_on $vg ${lv1}_foo "$dev5"
check dev_md5sum $vg $lv1
@@ -55,14 +58,16 @@ lvcreate -T $vg/${lv1}_raid1_pool -V 8 -n $lv1
check lv_tree_on $vg ${lv1}_foo "$dev1"
check lv_tree_on $vg $lv1 "$dev1" "$dev2"
aux mkdev_md5sum $vg $lv1
-pvmove "$dev1" "$dev5"
+pvmove "$dev1" "$dev5" $mode
check lv_tree_on $vg ${lv1}_foo "$dev5"
check lv_tree_on $vg $lv1 "$dev2" "$dev5"
check dev_md5sum $vg $lv1
-pvmove -n $lv1 "$dev5" "$dev4"
+pvmove -n $lv1 "$dev5" "$dev4" $mode
check lv_tree_on $vg $lv1 "$dev2" "$dev4"
check lv_tree_on $vg ${lv1}_foo "$dev5"
check dev_md5sum $vg $lv1
lvremove -ff $vg
+done
+
vgremove -ff $vg
diff --git a/tools/args.h b/tools/args.h
index 0ee380a..8dc8b5f 100644
--- a/tools/args.h
+++ b/tools/args.h
@@ -17,6 +17,7 @@
* Put all long args that don't have a corresponding short option first.
*/
/* *INDENT-OFF* */
+arg(atomic_ARG, '\0', "atomic", NULL, 0)
arg(version_ARG, '\0', "version", NULL, 0)
arg(physicalvolumesize_ARG, '\0', "setphysicalvolumesize", size_mb_arg, 0)
arg(ignorelockingfailure_ARG, '\0', "ignorelockingfailure", NULL, 0)
diff --git a/tools/commands.h b/tools/commands.h
index 019d4ef..0644c54 100644
--- a/tools/commands.h
+++ b/tools/commands.h
@@ -764,6 +764,7 @@ xx(pvmove,
0,
"pvmove " "\n"
"\t[--abort]\n"
+ "\t[--atomic]\n"
"\t[-A|--autobackup {y|n}]\n"
"\t[--alloc AllocationPolicy]\n"
"\t[-b|--background]\n"
@@ -780,7 +781,7 @@ xx(pvmove,
"\tSourcePhysicalVolume[:PhysicalExtent[-PhysicalExtent]...]}\n"
"\t[DestinationPhysicalVolume[:PhysicalExtent[-PhysicalExtent]...]...]\n",
- abort_ARG, alloc_ARG, autobackup_ARG, background_ARG,
+ abort_ARG, atomic_ARG, alloc_ARG, autobackup_ARG, background_ARG,
interval_ARG, name_ARG, noudevsync_ARG, test_ARG)
xx(pvremove,
diff --git a/tools/pvmove.c b/tools/pvmove.c
index a7788ba..24410d1 100644
--- a/tools/pvmove.c
+++ b/tools/pvmove.c
@@ -486,7 +486,9 @@ static struct logical_volume *_set_up_pvmove_lv(struct cmd_context *cmd,
}
if (!lv_add_mirrors(cmd, lv_mirr, 1, 1, 0, 0, log_count,
- allocatable_pvs, alloc, MIRROR_BY_SEG)) {
+ allocatable_pvs, alloc,
+ (arg_count(cmd, atomic_ARG)) ?
+ MIRROR_BY_SEGMENTED_LV : MIRROR_BY_SEG)) {
log_error("Failed to convert pvmove LV to mirrored");
return_NULL;
}
@@ -515,15 +517,54 @@ static int _activate_lv(struct cmd_context *cmd, struct logical_volume *lv_mirr,
return r;
}
+static int _is_pvmove_image_removable(struct logical_volume *mimage_lv,
+ void *baton)
+{
+ uint32_t s = *((uint32_t *)baton);
+ struct lv_segment *mirror_seg;
+
+ if (!(mirror_seg = get_only_segment_using_this_lv(mimage_lv))) {
+ log_error(INTERNAL_ERROR
+ "%s is not a proper mirror image",
+ mimage_lv->name);
+ return 0;
+ }
+
+ if (seg_type(mirror_seg, 0) != AREA_LV) {
+ log_error(INTERNAL_ERROR
+ "%s is not a pvmove mirror of LV-type",
+ mirror_seg->lv->name);
+ return 0;
+ }
+
+ if (s > mirror_seg->area_count) {
+ log_error(INTERNAL_ERROR
+ "Invalid segment number");
+ return 0;
+ }
+
+ if (seg_lv(mirror_seg, s) == mimage_lv)
+ return 1;
+
+ return 0;
+}
+
static int _detach_pvmove_mirror(struct cmd_context *cmd,
struct logical_volume *lv_mirr)
{
+ uint32_t s = 0;
struct dm_list lvs_completed;
struct lv_list *lvl;
/* Update metadata to remove mirror segments and break dependencies */
dm_list_init(&lvs_completed);
- if (!lv_remove_mirrors(cmd, lv_mirr, 1, 0, NULL, NULL, PVMOVE) ||
+
+ if (arg_is_set(cmd, abort_ARG) &&
+ (seg_type(first_seg(lv_mirr), 0) == AREA_LV))
+ s = 1; /* remove the second mirror leg */
+
+ if (!lv_remove_mirrors(cmd, lv_mirr, 1, 0,
+ _is_pvmove_image_removable, &s, PVMOVE) ||
!remove_layers_for_segments_all(cmd, lv_mirr, PVMOVE,
&lvs_completed)) {
return 0;
8 years, 9 months
master - test: fix report_select test to work in cluster
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=b16f5633ab199d...
Commit: b16f5633ab199dedfd25f08562f686a6fb4aba9d
Parent: ef43a50926d0590910798dd366f6b8da548b05a3
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Tue Jun 17 18:28:27 2014 +0200
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Tue Jun 17 18:34:46 2014 +0200
test: fix report_select test to work in cluster
The snapshot LV is used to check selection of percent values.
The orig volume must be activated exclusively in cluster.
---
test/shell/report-select.sh | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/test/shell/report-select.sh b/test/shell/report-select.sh
index 13d18fc..8df1d27 100644
--- a/test/shell/report-select.sh
+++ b/test/shell/report-select.sh
@@ -32,7 +32,7 @@ lvcreate --addtag 'lv_tag2.-+/=!:&#' --addtag "lv_tag1" -L8m -n "vol1" $vg1
lvcreate --addtag "lv_tag1" -L4m -n "vol2" $vg1
lvcreate --readahead 512 --addtag "lv_tag1" -L16m -n "abc" $vg2
lvcreate --readahead 512 -My --minor 254 -L4m -n "xyz" $vg3
-lvcreate -L4m -n "orig" $vg3
+lvcreate -L4m -aey -n "orig" $vg3
lvcreate -L4m -s "$vg3/orig" -n "snap"
OUT_LOG_FILE="out"
8 years, 9 months
master - tests: update lvcreate-thin for latest changes
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=ef43a50926d059...
Commit: ef43a50926d0590910798dd366f6b8da548b05a3
Parent: d09590c4b601f261d164fd253c7f2b9864cbf7ab
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Tue Jun 17 18:19:59 2014 +0200
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Tue Jun 17 18:20:08 2014 +0200
tests: update lvcreate-thin for latest changes
With recent changes introduced with the report selection support,
the content of lv_modules field is of string list type (before
it was just string type).
String list elements are always ordered now so update lvcreate-thin
test to expect the elements to be ordered.
---
test/shell/lvcreate-thin.sh | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/test/shell/lvcreate-thin.sh b/test/shell/lvcreate-thin.sh
index 9712652..215bfac 100644
--- a/test/shell/lvcreate-thin.sh
+++ b/test/shell/lvcreate-thin.sh
@@ -146,7 +146,7 @@ lvcreate --type snapshot $vg/lv1 --name lv4
lvcreate --type snapshot $vg/lv1 --name $vg/lv5
lvdisplay --maps $vg
-check_lv_field_modules_ thin-pool,thin lv1 snap_lv1 lv2 lv3 lv4 lv5 lv6
+check_lv_field_modules_ thin,thin-pool lv1 snap_lv1 lv2 lv3 lv4 lv5 lv6
check vg_field $vg lv_count 8
lvremove -ff $vg
8 years, 9 months
master - prop: update FIELD macro to accomodate the differentiation of number, size and percent field values
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=d09590c4b601f2...
Commit: d09590c4b601f261d164fd253c7f2b9864cbf7ab
Parent: 94316dfe9d61a7b46c88458e4a8232667fde192a
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Tue Jun 17 18:14:38 2014 +0200
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Tue Jun 17 18:14:57 2014 +0200
prop: update FIELD macro to accomodate the differentiation of number, size and percent field values
The differentiation of the original number field into number, size and
percent field types has been introduced with recent changes for report
selection support.
---
lib/properties/prop_common.h | 2 +-
lib/report/properties.c | 1 +
2 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/lib/properties/prop_common.h b/lib/properties/prop_common.h
index 6972f9f..6d4c2e4 100644
--- a/lib/properties/prop_common.h
+++ b/lib/properties/prop_common.h
@@ -128,6 +128,6 @@ static int _ ## NAME ## _get (const void *obj, struct lvm_property_type *prop) \
#define FIELD_MODIFIABLE 0x00000001
#define FIELD(type, strct, field_type, head, field, width, fn, id, desc, settable) \
- { type, #id, settable, field_type == STR, field_type == NUM, { .integer = 0 }, _ ## id ## _get, _ ## id ## _set },
+ { type, #id, settable, field_type == STR, ((field_type == NUM) || (field_type == SIZ) || (field_type == PCT)), { .integer = 0 }, _ ## id ## _get, _ ## id ## _set },
#endif
diff --git a/lib/report/properties.c b/lib/report/properties.c
index 0c49b0f..ce3ed53 100644
--- a/lib/report/properties.c
+++ b/lib/report/properties.c
@@ -343,6 +343,7 @@ struct lvm_property_type _properties[] = {
#undef STR
#undef NUM
#undef SIZ
+#undef PCT
#undef STR_LIST
#undef FIELD
8 years, 9 months
master - report: select: add man pages for report selection feature
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=94316dfe9d61a7...
Commit: 94316dfe9d61a7b46c88458e4a8232667fde192a
Parent: 40e0f444955690d4c5a5c5da8320a65e23a50553
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Mon Jun 16 16:23:55 2014 +0200
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Tue Jun 17 16:27:21 2014 +0200
report: select: add man pages for report selection feature
---
man/lvdisplay.8.in | 2 +
man/lvm.8.in | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++
man/lvs.8.in | 14 ++++++++++
man/pvdisplay.8.in | 2 +
man/pvs.8.in | 14 ++++++++++
man/vgdisplay.8.in | 2 +
man/vgs.8.in | 14 ++++++++++
7 files changed, 117 insertions(+), 0 deletions(-)
diff --git a/man/lvdisplay.8.in b/man/lvdisplay.8.in
index 5593752..1283d58 100644
--- a/man/lvdisplay.8.in
+++ b/man/lvdisplay.8.in
@@ -40,6 +40,8 @@ lvdisplay \(em display attributes of a logical volume
.RI [ + | \- ] Key1 [ , [ + | \- ] Key2 ...]]
.RB [ \-P | \-\-partial ]
.RB [ \-\-segments ]
+.RB [ \-S | \-\-select
+.IR Selection ]
.RB [ \-\-separator
.IR Separator ]
.RB [ \-\-unbuffered ]
diff --git a/man/lvm.8.in b/man/lvm.8.in
index 5449e20..0a5c69c 100644
--- a/man/lvm.8.in
+++ b/man/lvm.8.in
@@ -207,6 +207,13 @@ changed with this option. To insert a replacement Physical Volume
of the same or large size use \fBpvcreate \-u\fP to set the uuid to
match the original followed by \fBvgcfgrestore\fP(8).
.TP
+.BR \-S ", " \-\-select " " \fISelection
+For reporting commands, display only rows that match selection criteria.
+All rows are displayed with the additional "selected" column (\fB-o selected\fP)
+showing 1 if the row matches the Selection and 0 otherwise.
+See \fBSELECTION CRITERIA\fP section of this man page for more
+information about the way the selection criteria are constructed.
+.TP
.BR \-M ", " \-\-metadatatype " " \fIType
Specifies which type of on-disk metadata to use, such as \fIlvm1\fP
or \fIlvm2\fP, which can be abbreviated to \fI1\fP or \fI2\fP respectively.
@@ -419,6 +426,68 @@ volume types are an example of this. Other logical volume types may
require more than one command to create. The cache (\fBlvmcache\fP(7))
and thin provisioning (\fBlvmthin\fP(7)) types are examples of this.
+.SH SELECTION CRITERIA
+.LP
+The selection criteria are a set of \fBstatements\fP combined by \fBlogical
+and grouping operators\fP. The \fBstatement\fP consists of \fBcolumn\fP
+name for which a set of valid \fBvalues\fP is defined using
+\fBcomparison operators\fP. For complete list of column names (fields)
+that can be used in selection, see the output of \fB<lvm reporting command> -S help\fP.
+.LP
+\fBComparison operators\fP (cmp_op):
+.IP
+\fB=~\fP \(em Matching regular expression.
+.IP
+\fB!~\fP \(em Not matching regular expression.
+.IP
+\fB=\fP \(em Equal to.
+.IP
+\fB!=\fP \(em Not equal to.
+.IP
+\fB>=\fP \(em Greater than or equal to.
+.IP
+\fB>\fP \(em Greater than
+.IP
+\fB<=\fP \(em Less than or equal to.
+.IP
+\fB<\fP \(em Less than.
+.LP
+\fBBinary logical operators\fP (cmp_log):
+.IP
+\fB&&\fP \(em All fields must match
+.IP
+\fB,\fP \(em All fields must match
+.IP
+\fB||\fP \(em At least one field must match
+.IP
+\fB#\fP \(em At least one field must match
+.LP
+\fBUnary logical operators\fP:
+.IP
+\fB!\fP \(em Logical negation
+.LP
+\fBGrouping operators\fP:
+.IP
+\fB(\fP \(em Left parenthesis
+.IP
+\fB)\fP \(em Right parenthesis
+.IP
+\fB[\fP \(em List start
+.IP
+\fB]\fP \(em List end
+.LP
+\fBInformal grammar specification\fP:
+.IP
+.BR STATEMENT " = " column " cmp_op " VALUE " | " STATEMENT " log_op " STATEMENT " | " (STATEMENT) " | " !(STATEMENT)
+.IP
+.BR VALUE " = " [VALUE " log_op " VALUE]
+.br
+For list-based types: string list. The log_op must always be of one type within the whole list value.
+.IP
+.BR VALUE " = " value
+.br
+For scalar types: number (integer), size (floating point number with size unit suffix), percent (floating point number with or without % suffix), string.
+
.SH DIAGNOSTICS
All tools return a status code of zero on success or non-zero on failure.
.SH FILES
diff --git a/man/lvs.8.in b/man/lvs.8.in
index 2467306..371aaf6 100644
--- a/man/lvs.8.in
+++ b/man/lvs.8.in
@@ -20,6 +20,8 @@ lvs \(em report information about logical volumes
.RI [ + | \- ] Key1 [,[ + | \- ] Key2 [,...]]]
.RB [ \-P | \-\-partial ]
.RB [ \-\-rows ]
+.RB [ \-S | \-\-select
+.IR Selection ]
.RB [ \-\-separator
.IR Separator ]
.RB [ \-\-segments ]
@@ -195,6 +197,18 @@ selection. Precede any column with '\fI\-\fP' for a reverse sort on that column.
.B \-\-rows
Output columns as rows.
.TP
+.BR \-S ", " \-\-select " " \fISelection
+Display only rows that match selection criteria. All rows are displayed with
+the additional "selected" column (\fB-o selected\fP) showing 1 if the row
+matches the Selection and 0 otherwise. The selection criteria are defined
+by specifying column names and their valid values (that can include reserved
+values) while making use of supported comparison operators. See \fBlvm\fP(8)
+and \fB\-S\fP, \fB\-\-select\fP description for more detailed information
+about constructing the selection criteria. As a quick help and to see full
+list of columns names that can be used in selection including the list of
+reserved values and the set of supported selection operators, check the
+output of \fBlvs -S help\fP command.
+.TP
.B \-\-segments
Use default columns that emphasize segment information.
.TP
diff --git a/man/pvdisplay.8.in b/man/pvdisplay.8.in
index aab65ca..0399c1e 100644
--- a/man/pvdisplay.8.in
+++ b/man/pvdisplay.8.in
@@ -39,6 +39,8 @@ pvdisplay \- display attributes of a physical volume
.RB [ \-O | \-\-sort
.RI [ + | \- ] Key1 [ , [ + | \- ] Key2 ...
.RI ]]
+.RB [ \-S | \-\-select
+.IR Selection ]
.RB [ \-\-separator
.IR Separator ]
.RB [ \-\-unbuffered ]
diff --git a/man/pvs.8.in b/man/pvs.8.in
index ed57980..ea32d78 100644
--- a/man/pvs.8.in
+++ b/man/pvs.8.in
@@ -21,6 +21,8 @@ pvs \(em report information about physical volumes
.RB [ \-P | \-\-partial ]
.RB [ \-\-rows ]
.RB [ \-\-segments ]
+.RB [ \-S | \-\-select
+.IR Selection ]
.RB [ \-\-separator
.IR Separator ]
.RB [ \-\-unbuffered ]
@@ -79,6 +81,18 @@ Produces one line of output for each contiguous allocation of space on each
Physical Volume, showing the start (pvseg_start) and length (pvseg_size) in
units of physical extents.
.TP
+.BR \-S ", " \-\-select " " \fISelection
+Display only rows that match selection criteria. All rows are displayed with
+the additional "selected" column (\fB-o selected\fP) showing 1 if the row
+matches the Selection and 0 otherwise. The selection criteria are defined
+by specifying column names and their valid values (that can include reserved
+values) while making use of supported comparison operators. See \fBlvm\fP(8)
+and \fB\-S\fP, \fB\-\-select\fP description for more detailed information
+about constructing the selection criteria. As a quick help and to see full
+list of columns names that can be used in selection including the list of
+reserved values and the set of supported selection operators, check the
+output of \fBpvs -S help\fP command.
+.TP
.BR \-O ", " \-\-sort
Comma-separated ordered list of columns to sort by. Replaces the default
selection. Precede any column with '\fI\-\fP' for a reverse sort on that
diff --git a/man/vgdisplay.8.in b/man/vgdisplay.8.in
index d1ea89a..97cb314 100644
--- a/man/vgdisplay.8.in
+++ b/man/vgdisplay.8.in
@@ -39,6 +39,8 @@ vgdisplay \(em display attributes of volume groups
.RB [ \-O | \-\-sort
.RI [ + | \- ] Key1 [ , [ + | \- ] Key2 ...]]
.RB [ \-P | \-\-partial ]
+.RB [ \-S | \-\-select
+.IR Selection ]
.RB [ \-\-separator
.IR Separator ]
.RB [ \-\-unbuffered ]
diff --git a/man/vgs.8.in b/man/vgs.8.in
index b389ea2..2f71d26 100644
--- a/man/vgs.8.in
+++ b/man/vgs.8.in
@@ -20,6 +20,8 @@ vgs \(em report information about volume groups
.RI [ + | \- ] Key1 [ , [ + | \- ] Key2 ...]]
.RB [ \-P | \-\-partial ]
.RB [ \-\-rows ]
+.RB [ \-S | \-\-select
+.IR Selection ]
.RB [ \-\-separator
.IR Separator ]
.RB [ \-\-unbuffered ]
@@ -96,6 +98,18 @@ column.
.B \-\-rows
Output columns as rows.
.TP
+.BR \-S ", " \-\-select " " \fISelection
+Display only rows that match selection criteria. All rows are displayed with
+the additional "selected" column (\fB-o selected\fP) showing 1 if the row
+matches the Selection and 0 otherwise. The selection criteria are defined
+by specifying column names and their valid values (that can include reserved
+values) while making use of supported comparison operators. See \fBlvm\fP(8)
+and \fB\-S\fP, \fB\-\-select\fP description for more detailed information
+about constructing the selection criteria. As a quick help and to see full
+list of columns names that can be used in selection including the list of
+reserved values and the set of supported selection operators, check the
+output of \fBvgs -S help\fP command.
+.TP
.B \-\-separator \fISeparator
String to use to separate each column. Useful if grepping the output.
.TP
8 years, 9 months
master - report: select: add --select arg to lvm devtypes
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=40e0f444955690...
Commit: 40e0f444955690d4c5a5c5da8320a65e23a50553
Parent: f88130fd8543c3fd5829afb1bc4e4bd30a255d0c
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Fri Jun 13 12:57:22 2014 +0200
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Tue Jun 17 16:27:21 2014 +0200
report: select: add --select arg to lvm devtypes
---
tools/commands.h | 3 ++-
1 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/tools/commands.h b/tools/commands.h
index 4504126..019d4ef 100644
--- a/tools/commands.h
+++ b/tools/commands.h
@@ -42,6 +42,7 @@ xx(devtypes,
"\t[-o|--options [+]Field[,Field]]\n"
"\t[-O|--sort [+|-]key1[,[+|-]key2[,...]]]\n"
"\t[--rows]\n"
+ "\t[-S|--select Selection]\n"
"\t[--separator Separator]\n"
"\t[--unbuffered]\n"
"\t[--unquoted]\n"
@@ -50,7 +51,7 @@ xx(devtypes,
aligned_ARG, nameprefixes_ARG,
noheadings_ARG, nosuffix_ARG, options_ARG,
- rows_ARG, separator_ARG, sort_ARG,
+ rows_ARG, select_ARG, separator_ARG, sort_ARG,
unbuffered_ARG, unquoted_ARG)
xx(dumpconfig,
8 years, 9 months
master - report: add support for implicit fields, add implicit "selected" field
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=f88130fd8543c3...
Commit: f88130fd8543c3fd5829afb1bc4e4bd30a255d0c
Parent: 0d8e94ce2e6f48c47194c4844d4f59ccd7806959
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Thu Jun 12 13:57:22 2014 +0200
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Tue Jun 17 16:27:21 2014 +0200
report: add support for implicit fields, add implicit "selected" field
Implicit fields are fields that are registered with the report
and reported internally by libdevmapper itself (compared to explicit
fields that are registered by the layer above libdevmapper - e.g. LVM,
dmsetup...).
The "selected" field is the implicit field (for now the only one)
that reports the result of the selection. Since the selection itself
is the property of the libdevmapper, the upper layer using dm_report_init
can't register this field itself and it must be done directly at
libdevmapper layer.
The "selected" field is internally registered as part of the "common"
report type with id 0x80000000 (the last bit in uin32_t) which is then
reserved (the explicit report types are then checked if they do not
contain this id and if yes, we error out).
This way, the "selected" field is recognized by all libdevmapper users
that initialize the reporting with "dm_report_init_with_selection".
If reporting is initialized with the classical "dm_report_init",
there's no functional change (so the "selected" field is not defined
and it's not recognized).
---
libdm/libdm-report.c | 349 ++++++++++++++++++++++++++++++++++++++++----------
1 files changed, 282 insertions(+), 67 deletions(-)
diff --git a/libdm/libdm-report.c b/libdm/libdm-report.c
index 0461bdf..79b3687 100644
--- a/libdm/libdm-report.c
+++ b/libdm/libdm-report.c
@@ -71,6 +71,7 @@ struct field_properties {
int32_t width;
const struct dm_report_object_type *type;
uint32_t flags;
+ int implicit;
};
/*
@@ -184,6 +185,49 @@ struct row {
struct dm_report *rh;
struct dm_list fields; /* Fields in display order */
struct dm_report_field *(*sort_fields)[]; /* Fields in sort order */
+ int selected;
+};
+
+/*
+ * Implicit report types and fields.
+ */
+static const struct dm_report_object_type _implicit_void_report_types[] = {
+ { 0, "", "", NULL }
+};
+
+static const struct dm_report_field_type _implicit_void_report_fields[] = {
+ { 0, 0, 0, 0, "", "", 0, 0}
+};
+
+static const struct dm_report_object_type *_implicit_report_types = _implicit_void_report_types;
+static const struct dm_report_field_type *_implicit_report_fields = _implicit_void_report_fields;
+
+#define COMMON_REPORT_TYPE 0x80000000
+#define COMMON_FIELD_SELECTED_ID "selected"
+
+static void *_null_returning_fn(void *obj)
+{
+ return NULL;
+}
+
+static const struct dm_report_object_type _implicit_common_report_types[] = {
+ { COMMON_REPORT_TYPE, "Common", "common_", _null_returning_fn },
+ { 0, "", "", NULL }
+};
+
+static int _selected_disp(struct dm_report *rh,
+ struct dm_pool *mem __attribute__((unused)),
+ struct dm_report_field *field,
+ const void *data,
+ void *private __attribute__((unused)))
+{
+ struct row *row = (struct row *)data;
+ return dm_report_field_int(rh, field, &row->selected);
+}
+
+static const struct dm_report_field_type _implicit_common_report_fields[] = {
+ { COMMON_REPORT_TYPE, DM_REPORT_FIELD_TYPE_NUMBER, 0, 8, COMMON_FIELD_SELECTED_ID, "Selected", _selected_disp, "Item passes selection criteria." },
+ { 0, 0, 0, 0, "", "", 0, 0}
};
static const struct dm_report_object_type *_find_type(struct dm_report *rh,
@@ -191,6 +235,10 @@ static const struct dm_report_object_type *_find_type(struct dm_report *rh,
{
const struct dm_report_object_type *t;
+ for (t = _implicit_report_types; t->data_fn; t++)
+ if (t->id == report_type)
+ return t;
+
for (t = rh->types; t->data_fn; t++)
if (t->id == report_type)
return t;
@@ -524,25 +572,37 @@ static const char *_get_field_type_name(unsigned field_type)
/*
* show help message
*/
-static void _display_fields(struct dm_report *rh, int display_all_fields_item
- int display_field_types)
+static size_t _get_longest_field_id_len(const struct dm_report_field_type *fields)
{
uint32_t f;
- const struct dm_report_object_type *type;
- const char *desc, *last_desc = "";
size_t id_len = 0;
- for (f = 0; rh->fields[f].report_fn; f++)
- if (strlen(rh->fields[f].id) > id_len)
- id_len = strlen(rh->fields[f].id);
+ for (f = 0; fields[f].report_fn; f++)
+ if (strlen(fields[f].id) > id_len)
+ id_len = strlen(fields[f].id);
+
+ return id_len;
+}
+
+static void _display_fields_more(struct dm_report *rh,
+ const struct dm_report_field_type *fields,
+ size_t id_len, int display_all_fields_item,
+ int display_field_types)
+{
+ uint32_t f;
+ const struct dm_report_object_type *type;
+ const char *desc, *last_desc = "";
+ for (f = 0; fields[f].report_fn; f++)
+ if (strlen(fields[f].id) > id_len)
+ id_len = strlen(fields[f].id);
for (type = rh->types; type->data_fn; type++)
if (strlen(type->prefix) + 3 > id_len)
id_len = strlen(type->prefix) + 3;
- for (f = 0; rh->fields[f].report_fn; f++) {
- if ((type = _find_type(rh, rh->fields[f].type)) && type->desc)
+ for (f = 0; fields[f].report_fn; f++) {
+ if ((type = _find_type(rh, fields[f].type)) && type->desc)
desc = type->desc;
else
desc = " ";
@@ -559,31 +619,54 @@ static void _display_fields(struct dm_report *rh, int display_all_fields_item
"All fields in this section.");
}
}
-
/* FIXME Add line-wrapping at terminal width (or 80 cols) */
- log_warn(" %-*s - %s%s%s%s", (int) id_len, rh->fields[f].id, rh->fields[f].desc,
+ log_warn(" %-*s - %s%s%s%s", (int) id_len, fields[f].id, fields[f].desc,
display_field_types ? " [" : "",
- display_field_types ? _get_field_type_name(rh->fields[f].flags & DM_REPORT_FIELD_TYPE_MASK) : "",
+ display_field_types ? _get_field_type_name(fields[f].flags & DM_REPORT_FIELD_TYPE_MASK) : "",
display_field_types ? "]" : "");
last_desc = desc;
}
}
/*
+ * show help message
+ */
+static void _display_fields(struct dm_report *rh, int display_all_fields_item,
+ int display_field_types)
+{
+ size_t tmp, id_len = 0;
+
+ if ((tmp = _get_longest_field_id_len(_implicit_report_fields)) > id_len)
+ id_len = tmp;
+ if ((tmp = _get_longest_field_id_len(rh->fields)) > id_len)
+ id_len = tmp;
+
+ _display_fields_more(rh, _implicit_report_fields, id_len,
+ display_all_fields_item, display_field_types);
+ log_warn(" ");
+ _display_fields_more(rh, rh->fields, id_len, display_all_fields_item,
+ display_field_types);
+}
+
+/*
* Initialise report handle
*/
static int _copy_field(struct dm_report *rh, struct field_properties *dest,
- uint32_t field_num)
+ uint32_t field_num, int implicit)
{
+ const struct dm_report_field_type *fields = implicit ? _implicit_report_fields
+ : rh->fields;
+
dest->field_num = field_num;
- dest->width = rh->fields[field_num].width;
- dest->flags = rh->fields[field_num].flags & DM_REPORT_FIELD_MASK;
+ dest->width = fields[field_num].width;
+ dest->flags = fields[field_num].flags & DM_REPORT_FIELD_MASK;
+ dest->implicit = implicit;
/* set object type method */
- dest->type = _find_type(rh, rh->fields[field_num].type);
+ dest->type = _find_type(rh, fields[field_num].type);
if (!dest->type) {
log_error("dm_report: field not match: %s",
- rh->fields[field_num].id);
+ fields[field_num].id);
return 0;
}
@@ -591,7 +674,8 @@ static int _copy_field(struct dm_report *rh, struct field_properties *dest,
}
static struct field_properties * _add_field(struct dm_report *rh,
- uint32_t field_num, uint32_t flags)
+ uint32_t field_num, int implicit,
+ uint32_t flags)
{
struct field_properties *fp;
@@ -601,7 +685,7 @@ static struct field_properties * _add_field(struct dm_report *rh,
return NULL;
}
- if (!_copy_field(rh, fp, field_num)) {
+ if (!_copy_field(rh, fp, field_num, implicit)) {
stack;
dm_pool_free(rh->mem, fp);
return NULL;
@@ -648,10 +732,27 @@ static int _is_same_field(const char *name1, const char *name2,
/*
* Check for a report type prefix + "all" match.
*/
-static uint32_t _all_match(struct dm_report *rh, const char *field, size_t flen)
+static void _all_match_combine(const struct dm_report_object_type *types,
+ unsigned unprefixed_all_matched,
+ const char *field, size_t flen,
+ uint32_t *report_types)
{
- size_t prefix_len;
const struct dm_report_object_type *t;
+ size_t prefix_len;
+
+ for (t = types; t->data_fn; t++) {
+ prefix_len = strlen(t->prefix);
+
+ if (!strncasecmp(t->prefix, field, prefix_len) &&
+ ((unprefixed_all_matched && (flen == prefix_len)) ||
+ (!strncasecmp(field + prefix_len, "all", 3) &&
+ (flen == prefix_len + 3))))
+ *report_types |= t->id;
+ }
+}
+
+static uint32_t _all_match(struct dm_report *rh, const char *field, size_t flen)
+{
uint32_t report_types = 0;
unsigned unprefixed_all_matched = 0;
@@ -667,15 +768,8 @@ static uint32_t _all_match(struct dm_report *rh, const char *field, size_t flen)
}
/* Combine all report types that have a matching prefix. */
- for (t = rh->types; t->data_fn; t++) {
- prefix_len = strlen(t->prefix);
-
- if (!strncasecmp(t->prefix, field, prefix_len) &&
- ((unprefixed_all_matched && (flen == prefix_len)) ||
- (!strncasecmp(field + prefix_len, "all", 3) &&
- (flen == prefix_len + 3))))
- report_types |= t->id;
- }
+ _all_match_combine(_implicit_report_types, unprefixed_all_matched, field, flen, &report_types);
+ _all_match_combine(rh->types, unprefixed_all_matched, field, flen, &report_types);
return report_types;
}
@@ -687,23 +781,37 @@ static int _add_all_fields(struct dm_report *rh, uint32_t type)
{
uint32_t f;
+ for (f = 0; _implicit_report_fields[f].report_fn; f++)
+ if ((_implicit_report_fields[f].type & type) && !_add_field(rh, f, 1, 0))
+ return 0;
+
for (f = 0; rh->fields[f].report_fn; f++)
- if ((rh->fields[f].type & type) && !_add_field(rh, f, 0))
+ if ((rh->fields[f].type & type) && !_add_field(rh, f, 0, 0))
return 0;
return 1;
}
-static int _get_field(struct dm_report *rh, const char *field, size_t flen, uint32_t *f_ret)
+static int _get_field(struct dm_report *rh, const char *field, size_t flen,
+ uint32_t *f_ret, int *implicit)
{
uint32_t f;
if (!flen)
return 0;
+ for (f = 0; _implicit_report_fields[f].report_fn; f++) {
+ if (_is_same_field(_implicit_report_fields[f].id, field, flen, rh->field_prefix)) {
+ *f_ret = f;
+ *implicit = 1;
+ return 1;
+ }
+ }
+
for (f = 0; rh->fields[f].report_fn; f++) {
if (_is_same_field(rh->fields[f].id, field, flen, rh->field_prefix)) {
*f_ret = f;
+ *implicit = 0;
return 1;
}
}
@@ -715,16 +823,18 @@ static int _field_match(struct dm_report *rh, const char *field, size_t flen,
unsigned report_type_only)
{
uint32_t f, type;
+ int implicit;
if (!flen)
return 0;
- if ((_get_field(rh, field, flen, &f))) {
+ if ((_get_field(rh, field, flen, &f, &implicit))) {
if (report_type_only) {
- rh->report_types |= rh->fields[f].type;
+ rh->report_types |= implicit ? _implicit_report_fields[f].type
+ : rh->fields[f].type;
return 1;
} else
- return _add_field(rh, f, 0) ? 1 : 0;
+ return _add_field(rh, f, implicit, 0) ? 1 : 0;
}
if ((type = _all_match(rh, field, flen))) {
@@ -738,13 +848,15 @@ static int _field_match(struct dm_report *rh, const char *field, size_t flen,
return 0;
}
-static int _add_sort_key(struct dm_report *rh, uint32_t field_num,
+static int _add_sort_key(struct dm_report *rh, uint32_t field_num, int implicit,
uint32_t flags, unsigned report_type_only)
{
struct field_properties *fp, *found = NULL;
+ const struct dm_report_field_type *fields = implicit ? _implicit_report_fields
+ : rh->fields;
dm_list_iterate_items(fp, &rh->field_props) {
- if (fp->field_num == field_num) {
+ if ((fp->implicit == implicit) && (fp->field_num == field_num)) {
found = fp;
break;
}
@@ -752,8 +864,8 @@ static int _add_sort_key(struct dm_report *rh, uint32_t field_num,
if (!found) {
if (report_type_only)
- rh->report_types |= rh->fields[field_num].type;
- else if (!(found = _add_field(rh, field_num, FLD_HIDDEN)))
+ rh->report_types |= fields[field_num].type;
+ else if (!(found = _add_field(rh, field_num, implicit, FLD_HIDDEN)))
return_0;
}
@@ -762,7 +874,7 @@ static int _add_sort_key(struct dm_report *rh, uint32_t field_num,
if (found->flags & FLD_SORT_KEY) {
log_warn("dm_report: Ignoring duplicate sort field: %s.",
- rh->fields[field_num].id);
+ fields[field_num].id);
return 1;
}
@@ -798,10 +910,13 @@ static int _key_match(struct dm_report *rh, const char *key, size_t len,
return 0;
}
+ for (f = 0; _implicit_report_fields[f].report_fn; f++)
+ if (_is_same_field(_implicit_report_fields[f].id, key, len, rh->field_prefix))
+ return _add_sort_key(rh, f, 1, flags, report_type_only);
+
for (f = 0; rh->fields[f].report_fn; f++)
- if (_is_same_field(rh->fields[f].id, key, len,
- rh->field_prefix))
- return _add_sort_key(rh, f, flags, report_type_only);
+ if (_is_same_field(rh->fields[f].id, key, len, rh->field_prefix))
+ return _add_sort_key(rh, f, 0, flags, report_type_only);
return 0;
}
@@ -866,6 +981,40 @@ static int _parse_keys(struct dm_report *rh, const char *keys,
return 1;
}
+static int _contains_reserved_report_type(const struct dm_report_object_type *types)
+{
+ const struct dm_report_object_type *type, *implicit_type;
+
+ for (implicit_type = _implicit_report_types; implicit_type->data_fn; implicit_type++) {
+ for (type = types; type->data_fn; type++) {
+ if (implicit_type->id & type->id) {
+ log_error(INTERNAL_ERROR "dm_report_init: definition of report "
+ "types given contains reserved identifier");
+ return 1;
+ }
+ }
+ }
+
+ return 0;
+}
+
+static void _dm_report_init_update_types(struct dm_report *rh, uint32_t *report_types)
+{
+ const struct dm_report_object_type *type;
+
+ if (!report_types)
+ return;
+
+ *report_types = rh->report_types;
+ /*
+ * Do not include implicit types as these are not understood by
+ * dm_report_init caller - the caller doesn't know how to check
+ * these types anyway.
+ */
+ for (type = _implicit_report_types; type->data_fn; type++)
+ *report_types &= ~type->id;
+}
+
struct dm_report *dm_report_init(uint32_t *report_types,
const struct dm_report_object_type *types,
const struct dm_report_field_type *fields,
@@ -883,6 +1032,9 @@ struct dm_report *dm_report_init(uint32_t *report_types,
return 0;
}
+ if (_contains_reserved_report_type(types))
+ return_0;
+
/*
* rh->report_types is updated in _parse_fields() and _parse_keys()
* to contain all types corresponding to the fields specified by
@@ -941,9 +1093,10 @@ struct dm_report *dm_report_init(uint32_t *report_types,
return NULL;
}
- /* Return updated types value for further compatility check by caller */
- if (report_types)
- *report_types = rh->report_types;
+ /*
+ * Return updated types value for further compatility check by caller.
+ */
+ _dm_report_init_update_types(rh, report_types);
return rh;
}
@@ -985,12 +1138,24 @@ int dm_report_set_output_field_name_prefix(struct dm_report *rh, const char *out
static void *_report_get_field_data(struct dm_report *rh,
struct field_properties *fp, void *object)
{
+ const struct dm_report_field_type *fields = fp->implicit ? _implicit_report_fields
+ : rh->fields;
+
char *ret = fp->type->data_fn(object);
if (!ret)
return NULL;
- return (void *)(ret + rh->fields[fp->field_num].offset);
+ return (void *)(ret + fields[fp->field_num].offset);
+}
+
+static void *_report_get_implicit_field_data(struct dm_report *rh __attribute__((unused)),
+ struct field_properties *fp, struct row *row)
+{
+ if (!strcmp(_implicit_report_fields[fp->field_num].id, COMMON_FIELD_SELECTED_ID))
+ return row;
+
+ return NULL;
}
static int _cmp_field_int(const char *field_id, uint64_t a, uint64_t b, uint32_t flags)
@@ -1138,7 +1303,9 @@ static int _compare_selection_field(struct dm_report *rh,
struct dm_report_field *f,
struct field_selection *fs)
{
- const char *field_id = rh->fields[f->props->field_num].id;
+ const struct dm_report_field_type *fields = f->props->implicit ? _implicit_report_fields
+ : rh->fields;
+ const char *field_id = fields[f->props->field_num].id;
int r = 0;
if (!f->sort_value) {
@@ -1226,9 +1393,10 @@ static int _check_report_selection(struct dm_report *rh, struct dm_list *fields)
int dm_report_object(struct dm_report *rh, void *object)
{
+ const struct dm_report_field_type *fields;
struct field_properties *fp;
struct row *row = NULL;
- struct dm_report_field *field;
+ struct dm_report_field *field, *field_sel_status = NULL;
void *data = NULL;
int len;
int r = 0;
@@ -1255,6 +1423,7 @@ int dm_report_object(struct dm_report *rh, void *object)
}
dm_list_init(&row->fields);
+ row->selected = 1;
/* For each field to be displayed, call its report_fn */
dm_list_iterate_items(fp, &rh->field_props) {
@@ -1263,21 +1432,31 @@ int dm_report_object(struct dm_report *rh, void *object)
"struct dm_report_field allocation failed");
goto out;
}
+
+ if (fp->implicit) {
+ fields = _implicit_report_fields;
+ if (!strcmp(fields[fp->field_num].id, COMMON_FIELD_SELECTED_ID))
+ field_sel_status = field;
+ } else
+ fields = rh->fields;
+
field->props = fp;
- if (!(data = _report_get_field_data(rh, fp, object))) {
+ data = fp->implicit ? _report_get_implicit_field_data(rh, fp, row)
+ : _report_get_field_data(rh, fp, object);
+ if (!data) {
log_error("dm_report_object: "
"no data assigned to field %s",
- rh->fields[fp->field_num].id);
+ fields[fp->field_num].id);
goto out;
}
- if (!rh->fields[fp->field_num].report_fn(rh, rh->mem,
+ if (!fields[fp->field_num].report_fn(rh, rh->mem,
field, data,
rh->private)) {
log_error("dm_report_object: "
"report function failed for field %s",
- rh->fields[fp->field_num].id);
+ fields[fp->field_num].id);
goto out;
}
@@ -1285,8 +1464,29 @@ int dm_report_object(struct dm_report *rh, void *object)
}
if (!_check_report_selection(rh, &row->fields)) {
- r = 1;
- goto out;
+ if (!field_sel_status) {
+ r = 1;
+ goto out;
+ }
+ /*
+ * If field with id "selected" is reported,
+ * report the row although it does not pass
+ * the selection criteria.
+ * The "selected" field reports the result
+ * of the selection.
+ */
+ row->selected = 0;
+ _implicit_report_fields[field_sel_status->props->field_num].report_fn(rh,
+ rh->mem, field_sel_status, row, rh->private);
+ /*
+ * If the "selected" field is not displayed, e.g.
+ * because it is part of the sort field list,
+ * skip the display of the row as usual.
+ */
+ if (field_sel_status->props->flags & FLD_HIDDEN) {
+ r = 1;
+ goto out;
+ }
}
dm_list_add(&rh->rows, &row->list);
@@ -1916,6 +2116,7 @@ static const char *_tok_field_name(const char *s,
static struct field_selection *_create_field_selection(struct dm_report *rh,
uint32_t field_num,
+ int implicit,
const char *v,
size_t len,
uint32_t flags,
@@ -1923,6 +2124,8 @@ static struct field_selection *_create_field_selection(struct dm_report *rh,
void *custom)
{
static const char *_out_of_range_msg = "Field selection value %s out of supported range for field %s.";
+ const struct dm_report_field_type *fields = implicit ? _implicit_report_fields
+ : rh->fields;
struct field_properties *fp, *found = NULL;
struct field_selection *fs;
const char *field_id;
@@ -1930,7 +2133,7 @@ static struct field_selection *_create_field_selection(struct dm_report *rh,
char *s;
dm_list_iterate_items(fp, &rh->field_props) {
- if (fp->field_num == field_num) {
+ if ((fp->implicit == implicit) && (fp->field_num == field_num)) {
found = fp;
break;
}
@@ -1938,12 +2141,12 @@ static struct field_selection *_create_field_selection(struct dm_report *rh,
/* The field is neither used in display options nor sort keys. */
if (!found) {
- if (!(found = _add_field(rh, field_num, FLD_HIDDEN)))
+ if (!(found = _add_field(rh, field_num, implicit, FLD_HIDDEN)))
return NULL;
- rh->report_types |= rh->fields[field_num].type;
+ rh->report_types |= fields[field_num].type;
}
- field_id = rh->fields[found->field_num].id;
+ field_id = fields[found->field_num].id;
if (!(found->flags & flags & DM_REPORT_FIELD_TYPE_MASK)) {
log_error("dm_report: incompatible comparison "
@@ -2192,6 +2395,7 @@ static struct selection_node *_parse_selection(struct dm_report *rh,
const char *vs, *ve; /* value */
const char *last;
uint32_t flags, field_num;
+ int implicit;
const struct dm_report_field_type *ft;
struct selection_str_list *str_list;
const struct dm_report_reserved_value *reserved;
@@ -2207,7 +2411,7 @@ static struct selection_node *_parse_selection(struct dm_report *rh,
}
/* check if the field with given name exists */
- if (!_get_field(rh, ws, (size_t) (we - ws), &field_num)) {
+ if (!_get_field(rh, ws, (size_t) (we - ws), &field_num, &implicit)) {
c = we[0];
tmp = (char *) we;
tmp[0] = '\0';
@@ -2218,7 +2422,8 @@ static struct selection_node *_parse_selection(struct dm_report *rh,
goto bad;
}
- ft = &rh->fields[field_num];
+ ft = implicit ? &_implicit_report_fields[field_num]
+ : &rh->fields[field_num];
/* comparison operator */
if (!(flags = _tok_op_cmp(we, &last))) {
@@ -2262,7 +2467,7 @@ static struct selection_node *_parse_selection(struct dm_report *rh,
*next = _skip_space(last);
/* create selection */
- if (!(fs = _create_field_selection(rh, field_num, vs, (size_t) (ve - vs), flags, reserved, custom)))
+ if (!(fs = _create_field_selection(rh, field_num, implicit, vs, (size_t) (ve - vs), flags, reserved, custom)))
return_NULL;
/* create selection node */
@@ -2410,6 +2615,9 @@ struct dm_report *dm_report_init_with_selection(uint32_t *report_types,
struct selection_node *root = NULL;
const char *fin, *next;
+ _implicit_report_types = _implicit_common_report_types;
+ _implicit_report_fields = _implicit_common_report_fields;
+
if (!(rh = dm_report_init(report_types, types, fields, output_fields,
output_separator, output_flags, sort_keys, private_data)))
return NULL;
@@ -2449,8 +2657,7 @@ struct dm_report *dm_report_init_with_selection(uint32_t *report_types,
goto error;
}
- if (report_types)
- *report_types = rh->report_types;
+ _dm_report_init_update_types(rh, report_types);
rh->selection_root = root;
return rh;
@@ -2464,6 +2671,7 @@ error:
*/
static int _report_headings(struct dm_report *rh)
{
+ const struct dm_report_field_type *fields;
struct field_properties *fp;
const char *heading;
char *buf = NULL;
@@ -2500,7 +2708,9 @@ static int _report_headings(struct dm_report *rh)
if (fp->flags & FLD_HIDDEN)
continue;
- heading = rh->fields[fp->field_num].heading;
+ fields = fp->implicit ? _implicit_report_fields : rh->fields;
+
+ heading = fields[fp->field_num].heading;
if (rh->flags & DM_REPORT_OUTPUT_ALIGNED) {
if (dm_snprintf(buf, buf_size, "%-*.*s",
fp->width, fp->width, heading) < 0) {
@@ -2616,6 +2826,8 @@ static int _sort_rows(struct dm_report *rh)
*/
static int _output_field(struct dm_report *rh, struct dm_report_field *field)
{
+ const struct dm_report_field_type *fields = field->props->implicit ? _implicit_report_fields
+ : rh->fields;
char *field_id;
int32_t width;
uint32_t align;
@@ -2624,7 +2836,7 @@ static int _output_field(struct dm_report *rh, struct dm_report_field *field)
size_t buf_size = 0;
if (rh->flags & DM_REPORT_OUTPUT_FIELD_NAME_PREFIX) {
- if (!(field_id = dm_strdup(rh->fields[field->props->field_num].id))) {
+ if (!(field_id = dm_strdup(fields[field->props->field_num].id))) {
log_error("dm_report: Failed to copy field name");
return 0;
}
@@ -2715,6 +2927,7 @@ bad:
static int _output_as_rows(struct dm_report *rh)
{
+ const struct dm_report_field_type *fields;
struct field_properties *fp;
struct dm_report_field *field;
struct row *row;
@@ -2728,13 +2941,15 @@ static int _output_as_rows(struct dm_report *rh)
continue;
}
+ fields = fp->implicit ? _implicit_report_fields : rh->fields;
+
if (!dm_pool_begin_object(rh->mem, 512)) {
log_error("dm_report: Unable to allocate output line");
return 0;
}
if ((rh->flags & DM_REPORT_OUTPUT_HEADINGS)) {
- if (!dm_pool_grow_object(rh->mem, rh->fields[fp->field_num].heading, 0)) {
+ if (!dm_pool_grow_object(rh->mem, fields[fp->field_num].heading, 0)) {
log_error("dm_report: Failed to extend row for field name");
goto bad;
}
8 years, 9 months
master - tests: select: add test for report selection feature
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=0d8e94ce2e6f48...
Commit: 0d8e94ce2e6f48c47194c4844d4f59ccd7806959
Parent: 51a86dc2f8cdfe3de9f0876548731ede1f6a4f24
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Tue Jun 10 09:20:58 2014 +0200
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Tue Jun 17 16:27:21 2014 +0200
tests: select: add test for report selection feature
---
test/shell/report-select.sh | 212 +++++++++++++++++++++++++++++++++++++++++++
1 files changed, 212 insertions(+), 0 deletions(-)
diff --git a/test/shell/report-select.sh b/test/shell/report-select.sh
new file mode 100644
index 0000000..13d18fc
--- /dev/null
+++ b/test/shell/report-select.sh
@@ -0,0 +1,212 @@
+#!/bin/sh
+# Copyright (C) 2014 Red Hat, Inc. All rights reserved.
+#
+# This copyrighted material is made available to anyone wishing to use,
+# modify, copy, or redistribute it subject to the terms and conditions
+# of the GNU General Public License v.2.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software Foundation,
+# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+. lib/inittest
+
+aux prepare_pvs 6 16
+
+# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+# MAKE SURE ALL PV, VG AND LV NAMES CREATED IN
+# THIS TEST ARE UNIQUE - THIS SIMPLIFIES TESTING
+# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
+# create $VGS with assorted tags
+vgcreate $vg1 --vgmetadatacopies 2 --addtag "vg_tag3" --addtag "vg_tag2" -s 4m $dev1 $dev2 $dev3
+vgcreate $vg2 --addtag "vg_tag2" -s 4m $dev4 $dev5
+vgcreate $vg3 --addtag "vg_tag1" -s 4m $dev6
+
+# add PV assorted tags
+pvchange --addtag "pv_tag3" --addtag "pv_tag1" --addtag "pv_tag2" $dev1
+pvchange --addtag "pv_tag1" --addtag "pv_tag4" $dev6
+
+# create $LVS with assorted tags and various sizes
+lvcreate --addtag 'lv_tag2.-+/=!:&#' --addtag "lv_tag1" -L8m -n "vol1" $vg1
+lvcreate --addtag "lv_tag1" -L4m -n "vol2" $vg1
+lvcreate --readahead 512 --addtag "lv_tag1" -L16m -n "abc" $vg2
+lvcreate --readahead 512 -My --minor 254 -L4m -n "xyz" $vg3
+lvcreate -L4m -n "orig" $vg3
+lvcreate -L4m -s "$vg3/orig" -n "snap"
+
+OUT_LOG_FILE="out"
+ERR_LOG_FILE="err"
+
+function result()
+{
+ local items_found
+
+ test -f $OUT_LOG_FILE || {
+ echo " >>> Missing log file to check!"
+ return 1
+ }
+
+ # there shouldn't be any selection syntax error
+ grep "Selection syntax error at" $ERR_LOG_FILE > /dev/null && {
+ echo " >>> Selection syntax error hit!"
+ return 1
+ }
+
+ items_found=$(wc -l $OUT_LOG_FILE | cut -f 1 -d " ")
+
+ # the number of lines on output must match
+ test $items_found -eq $# || {
+ echo " >>> NUMBER OF ITEMS EXPECTED: $# ($@)"
+ echo " >>> NUMBER OF ITEMS FOUND: $items_found ($(cat $OUT_LOG_FILE))"
+ return 1
+ }
+
+ # the names selected must be correct
+ # each pv, vg and lv name is unique so just check
+ # the presence of the names given as arg
+ for name in $1; do
+ grep $name $OUT_LOG_FILE > /dev/null || {
+ echo " >>> $name not found in the output log"
+ return 1
+ }
+ done
+
+ rm -f $OUT_LOG_FILE
+ rm -f $ERR_LOG_FILE
+}
+
+function pvs_sel()
+{
+ pvs 1>$OUT_LOG_FILE 2>$ERR_LOG_FILE --noheadings -o pv_name --select "$1" && result $2
+}
+
+function vgs_sel()
+{
+ vgs &>$OUT_LOG_FILE 2>$ERR_LOG_FILE --noheadings -o vg_name --select "$1" && result $2
+}
+
+function lvs_sel()
+{
+ lvs &>$OUT_LOG_FILE 2>$ERR_LOG_FILE --noheadings -o lv_name --select "$1" && result $2
+}
+
+##########################
+# STRING FIELD SELECTION #
+##########################
+#$LVS 'lv_name="vol1"' && result vol1
+lvs_sel 'lv_name="vol1"' "vol1"
+#$LVS 'lv_name!="vol1"' && result vol2 abc xyz
+lvs_sel 'lv_name!="vol1"' "vol2 abc xyz orig snap"
+# check string values are accepted without quotes too
+lvs_sel 'lv_name=vol1' "vol1"
+# check single quotes are also accepted instead of double quotes
+lvs_sel "lv_name='vol1'" "vol1"
+
+###############################
+# STRING LIST FIELD SELECTION #
+###############################
+pvs_sel 'tags=["pv_tag1"]' "$dev1 $dev2"
+# for one item, no need to use []
+pvs_sel 'tags="pv_tag1"' "$dev1 $dev2"
+# no match
+pvs_sel 'tags=["pv_tag1" && "pv_tag2"]'
+pvs_sel 'tags=["pv_tag1" && "pv_tag2" && "pv_tag3"]' "$dev1"
+# check the order has no effect on selection result
+pvs_sel 'tags=["pv_tag3" && "pv_tag2" && "pv_tag1"]' "$dev1"
+pvs_sel 'tags=["pv_tag4" || "pv_tag3"]' "$dev1 $dev6"
+pvs_sel 'tags!=["pv_tag1"]' "$dev2 $dev3 $dev4 $dev5"
+# check mixture of && and || - this is not allowed
+not pvs_sel 'tags=["pv_tag1" && "pv_tag2" || "pv_tag3"]'
+
+##########################
+# NUMBER FIELD SELECTION #
+##########################
+vgs_sel 'pv_count=3' "$vg1"
+vgs_sel 'pv_count!=3' "$vg3 $vg2"
+vgs_sel 'pv_count<2' "$vg3"
+vgs_sel 'pv_count<=2' "$vg3 $vg2"
+vgs_sel 'pv_count>2' "$vg1"
+vgs_sel 'pv_count>=2' "$vg1 $vg2"
+
+########################
+# SIZE FIELD SELECTION #
+########################
+# check size units are accepted as well as floating point numbers for sizes
+lvs_sel 'size=8388608b' "vol1"
+lvs_sel 'size=8192k' "vol1"
+lvs_sel 'size=8m' "vol1"
+lvs_sel 'size=8.00m' "vol1"
+lvs_sel 'size=0.0078125g' "vol1"
+lvs_sel 'size=0.00000762939453125t' "vol1"
+lvs_sel 'size=0.000000007450580596923828125p' "vol1"
+lvs_sel 'size=0.0000000000072759576141834259033203125e' "vol1"
+
+lvs_sel 'size>8m' "abc"
+lvs_sel 'size>=8m' "abc vol1"
+lvs_sel 'size<8m' "vol2 xyz orig snap"
+lvs_sel 'size<=8m' "vol2 xyz vol1 orig snap"
+
+###########################
+# PERCENT FIELD SELECTION #
+###########################
+lvs_sel 'snap_percent=0' "snap"
+dd if=/dev/zero of=$DM_DEV_DIR/$vg3/snap bs=1M count=1
+lvs_sel 'snap_percent<50' "snap"
+lvs_sel 'snap_percent>50'
+dd if=/dev/zero of=$DM_DEV_DIR/$vg3/snap bs=1M count=4
+lvs_sel 'snap_percent=100' "snap"
+# % char is accepted as suffix for percent values
+lvs_sel 'snap_percent=100%' "snap"
+# percent values over 100% are not accepted
+not lvs_sel 'snap_percent=101%'
+
+#########################
+# REGEX FIELD SELECTION #
+#########################
+lvs_sel 'lv_name=~"^vol[12]"' "vol1 vol2"
+lvs_sel 'lv_name!~"^vol[12]"' "abc xyz orig snap"
+# check regex is accepted without quotes too
+lvs_sel 'lv_name=~^vol[12]' "vol1 vol2"
+
+###########
+# GENERIC #
+###########
+# check prefix works for selection too
+lvs_sel 'lv_name="vol1"' "vol1"
+lvs_sel 'name="vol1"' "vol1"
+
+# check reserved values are accepted for certain fields as well as usual values
+vgs_sel 'vg_mda_copies=unmanaged' "$vg2 $vg3"
+vgs_sel 'vg_mda_copies=2' "$vg1"
+
+lvs_sel 'lv_read_ahead=auto' "vol1 vol2 orig snap"
+lvs_sel 'lv_read_ahead=256k' "abc xyz"
+
+lvs_sel 'lv_minor=-1' "vol1 vol2 abc orig snap"
+lvs_sel 'lv_minor=undefined' "vol1 vol2 abc orig snap"
+lvs_sel 'lv_minor=undef' "vol1 vol2 abc orig snap"
+lvs_sel 'lv_minor=unknown' "vol1 vol2 abc orig snap"
+lvs_sel 'lv_minor=254' "xyz"
+
+# if size unit not spefied, the 'm' (MiB) unit is used by default
+lvs_sel 'lv_size=8' "vol1"
+
+# no need to use quotes for the whole selection string if it does not clash with shell
+lvs_sel name=vol1 vol1
+
+##########################################
+# FORMING MORE COMPLEX SELECTION CLAUSES #
+##########################################
+# AND clause
+lvs_sel 'lv_tags=lv_tag1 && lv_size=4m' "vol2"
+# OR clause
+lvs_sel 'lv_name=vol1 || lv_name=vol2' "vol1 vol2"
+# grouping by using ( )
+lvs_sel '(lv_name=vol1 || lv_name=vol2) || vg_tags=vg_tag1' "vol1 vol2 abc orig snap"
+lvs_sel '(lv_name=vol1 && lv_size=100m) || vg_tags=vg_tag1' "xyz orig snap"
+lvs_sel '(lv_name=vol1 || lv_name=vol2) && vg_tags=vg_tag1'
+lvs_sel '(lv_name=vol1 || lv_name=vol2) && lv_size < 8m' "vol2"
+lvs_sel '(lv_name=vol1 && lv_size=8m) && vg_tags=vg_tag2' "vol1"
+# negation of clause grouped by ( )
+lvs_sel '!(lv_name=vol1 || lv_name=vol2)' "abc xyz orig snap"
8 years, 9 months