master - writecache: prevent snapshots
by David Teigland
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=ffea7daec3d09fb4315...
Commit: ffea7daec3d09fb4315104bb346cfa9d6db6f9e9
Parent: 2a6078f96168e860474b42c42b1924fc353c4558
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Thu Feb 6 11:27:33 2020 -0600
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Thu Feb 6 11:27:33 2020 -0600
writecache: prevent snapshots
there appear to be problems with taking a snapshot
of an LV with a writecache, so block it until that
is understood or fixed.
---
lib/metadata/snapshot_manip.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/lib/metadata/snapshot_manip.c b/lib/metadata/snapshot_manip.c
index e58aea4..64e27ae 100644
--- a/lib/metadata/snapshot_manip.c
+++ b/lib/metadata/snapshot_manip.c
@@ -385,8 +385,11 @@ int validate_snapshot_origin(const struct logical_volume *origin_lv)
log_warn("WARNING: Consider using the raid1 mirror type to avoid this.");
log_warn("WARNING: See global/mirror_segtype_default in lvm.conf.");
}
- } else if (lv_is_raid_type(origin_lv) && !lv_is_raid(origin_lv))
+ } else if (lv_is_raid_type(origin_lv) && !lv_is_raid(origin_lv)) {
err = "raid subvolumes";
+ } else if (lv_is_writecache(origin_lv)) {
+ err = "writecache";
+ }
if (err) {
log_error("Snapshots of %s are not supported.", err);
4 years, 2 months
stable-2.02 - lvmetad: fix heap memory leak
by David Teigland
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=bcf9556b8fcd16ad899...
Commit: bcf9556b8fcd16ad8997f80cc92785f295c66701
Parent: a1f06e2faebfbc091b4bbb900398cda05264c753
Author: wangjufeng <wangjufeng(a)huawei.com>
AuthorDate: Wed Feb 5 13:39:39 2020 +0800
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Wed Feb 5 15:30:17 2020 -0600
lvmetad: fix heap memory leak
error could be reproduced by calling pvs periodically:
#!/bin/bash
while :
do
pvs
sleep 1
done
use top command to watch RES memory of lvmetad. After a few minutes,
its RES memory will grow for a few KB. Then stop calling pvs, while
its RES will not decrease.
This is because, when lvmetad make reponse for clent request, it
will malloc new chunk for s->vgid_to_metadata, while actually the
new chunk should be added to the reponse dm_config_tree, or it will
make the chunk list of s->vgid_to_metadata keep growing.
Signed-off-by: wangjufeng <wangjufeng(a)huawei.com>
Reviewed-by: liuzhiqiang <liuzhiqiang26(a)huawei.com>
Reviewed-by: guiyao <guiyao(a)huawei.com>
---
daemons/lvmetad/lvmetad-core.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/daemons/lvmetad/lvmetad-core.c b/daemons/lvmetad/lvmetad-core.c
index 2628022..76aa62c 100644
--- a/daemons/lvmetad/lvmetad-core.c
+++ b/daemons/lvmetad/lvmetad-core.c
@@ -730,7 +730,7 @@ static response vg_lookup(lvmetad_state *s, request r)
if (!(res.cft->root = n = dm_config_create_node(res.cft, "response")))
goto nomem_un;
- if (!(n->v = dm_config_create_value(cft)))
+ if (!(n->v = dm_config_create_value(res.cft)))
goto nomem_un;
n->parent = res.cft->root;
4 years, 2 months
master - writecache: fix splitcache when origin is raid
by David Teigland
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=2a6078f96168e860474...
Commit: 2a6078f96168e860474b42c42b1924fc353c4558
Parent: 9255c7148ac3d920aafe58f78a9672dd3a0967bd
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Tue Feb 4 16:05:56 2020 -0600
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Tue Feb 4 16:12:09 2020 -0600
writecache: fix splitcache when origin is raid
---
lib/metadata/lv_manip.c | 13 +++++++++----
test/shell/writecache-split.sh | 17 +++++++++++++++++
2 files changed, 26 insertions(+), 4 deletions(-)
diff --git a/lib/metadata/lv_manip.c b/lib/metadata/lv_manip.c
index c9f7348..3604a63 100644
--- a/lib/metadata/lv_manip.c
+++ b/lib/metadata/lv_manip.c
@@ -4535,6 +4535,9 @@ static int _for_each_sub_lv(struct logical_volume *lv, int level,
if (!_for_each_sub_lv(seg->pool_lv, level, fn, data))
return_0;
+ if (!_for_each_sub_lv(seg->writecache, level, fn, data))
+ return_0;
+
for (s = 0; s < seg->area_count; s++) {
if (seg_type(seg, s) != AREA_LV)
continue;
@@ -6989,7 +6992,7 @@ int move_lv_segments(struct logical_volume *lv_to,
int remove_layer_from_lv(struct logical_volume *lv,
struct logical_volume *layer_lv)
{
- static const char _suffixes[][8] = { "_tdata", "_cdata", "_corig", "_vdata" };
+ static const char _suffixes[][8] = { "_tdata", "_cdata", "_corig", "_wcorig", "_vdata" };
struct logical_volume *parent_lv;
struct lv_segment *parent_seg;
struct segment_type *segtype;
@@ -7069,8 +7072,8 @@ int remove_layer_from_lv(struct logical_volume *lv,
* currently supported only for thin data layer
* FIXME: without strcmp it breaks mirrors....
*/
- if (!strstr(layer_lv->name, "_mimage"))
- for (r = 0; r < DM_ARRAY_SIZE(_suffixes); ++r)
+ if (!strstr(layer_lv->name, "_mimage")) {
+ for (r = 0; r < DM_ARRAY_SIZE(_suffixes); ++r) {
if (strstr(layer_lv->name, _suffixes[r]) == 0) {
lv_names.old = layer_lv->name;
lv_names.new = parent_lv->name;
@@ -7078,6 +7081,8 @@ int remove_layer_from_lv(struct logical_volume *lv,
return_0;
break;
}
+ }
+ }
return 1;
}
@@ -7093,7 +7098,7 @@ struct logical_volume *insert_layer_for_lv(struct cmd_context *cmd,
uint64_t status,
const char *layer_suffix)
{
- static const char _suffixes[][8] = { "_tdata", "_cdata", "_corig", "_vdata" };
+ static const char _suffixes[][8] = { "_tdata", "_cdata", "_corig", "_wcorig", "_vdata" };
int r;
char name[NAME_LEN];
struct dm_str_list *sl;
diff --git a/test/shell/writecache-split.sh b/test/shell/writecache-split.sh
index 7168d02..0f2dc47 100644
--- a/test/shell/writecache-split.sh
+++ b/test/shell/writecache-split.sh
@@ -128,6 +128,23 @@ vgextend --restoremissing $vg "$dev3"
vgremove -ff $vg
#
+# splitcache when origin is raid
+#
+
+vgcreate $vg "$dev1" "$dev2" "$dev3" "$dev4"
+
+lvcreate --type raid1 -m1 -L6 -n $lv1 -an $vg "$dev1" "$dev2"
+lvcreate -L6 -n $lv2 -an $vg "$dev3"
+lvconvert -y --type writecache --cachevol $lv2 $vg/$lv1
+lvchange -ay $vg/$lv1
+lvchange -an $vg/$lv1
+lvconvert --splitcache $vg/$lv1
+lvs $vg/$lv1
+lvs $vg/$lv2
+
+vgremove -ff $vg
+
+#
# vgsplit should not separate cachevol from main lv
#
4 years, 2 months
master - WHATS_NEW: update
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=9255c7148ac3d920aaf...
Commit: 9255c7148ac3d920aafe58f78a9672dd3a0967bd
Parent: aa7642a44441c63dd71184b70f5c3955696a5ad4
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Tue Feb 4 17:21:13 2020 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Tue Feb 4 17:22:06 2020 +0100
WHATS_NEW: update
---
WHATS_NEW | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/WHATS_NEW b/WHATS_NEW
index 66ea748..b03eb97 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,9 @@
Version 2.03.08 -
====================================
+ Add error handling for failing allocation in _reserve_area().
+ Fix memleak in syncing of internal cache.
+ Fix pvck dump_current_text memleak.
+ Fix lvmlockd result code on error path for _query_lock_lv().
Accept more output lines from vdo_format.
Prohibit reshaping of stacked raid LVs.
Avoid running cache input arg validation when creating vdo pool.
4 years, 2 months
master - generate: remake
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=aa7642a44441c63dd71...
Commit: aa7642a44441c63dd71184b70f5c3955696a5ad4
Parent: 336361b2f25c09c7aad4d21aca272a11c6c9352a
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Tue Feb 4 15:40:33 2020 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Tue Feb 4 17:22:06 2020 +0100
generate: remake
Regen man page.
---
man/pvck.8_pregen | 109 ++++++++++++++++++++++++++++++++++++++++--------------
1 file changed, 82 insertions(+), 27 deletions(-)
diff --git a/man/pvck.8_pregen b/man/pvck.8_pregen
index ea9d17d..1800714 100644
--- a/man/pvck.8_pregen
+++ b/man/pvck.8_pregen
@@ -25,7 +25,7 @@ pvck - Check metadata on physical volumes
.ad b
.br
.ad l
- \fB--dump\fP \fIString\fP
+ \fB--dump\fP \fBheaders\fP|\fBmetadata\fP|\fBmetadata_all\fP|\fBmetadata_search\fP
.ad b
.br
.ad l
@@ -94,44 +94,50 @@ pvck - Check metadata on physical volumes
.SH DESCRIPTION
pvck checks and repairs LVM metadata on PVs.
-.SS Dump
+.SS Dump options
.B headers
.br
-Print header values and warn if any values are incorrect. Checks the
-label_header, pv_header, mda_header(s), and metadata text.
+Print LVM on-disk headers and structures: label_header, pv_header,
+mda_header(s), and metadata text. Warnings are printed if any values are
+incorrect. The label_header and pv_header both exist in a 512 byte
+sector, usually the second sector of the device. An mda_header exists in
+a 512 byte sector at offset 4096 bytes. A second mda_header can
+optionally exist near the end of the device. The metadata text exists in
+an area (about 1MiB by default) immediately following the mda_header
+sector. The metadata text is checked but not printed (see other options).
.B metadata
.br
-Print or save the current metadata text, using headers to locate the
-metadata. If headers are damaged, the metadata may not be found. Use
---settings "mda_num=2" to look in mda2 (the second mda at the end of the
-device (if used). The metadata text is printed to stdout. With --file,
-the metadata text is saved to a file.
+Print the current LVM VG metadata text (or save to a file), using headers
+to locate the latest copy of metadata. If headers are damaged, metadata
+may not be found (see metadata_search). Use --settings "mda_num=2" to
+look in mda2 (the second mda at the end of the device, if used). The
+metadata text is printed to stdout or saved to a file with --file.
.B metadata_all
.br
-List or save all versions of metadata found in the metadata area, using
-headers to locate the metadata. If headers are damaged, the metadata may
-not be found. Use --settings "mda_num=2" as above. All metadata versions
-are listed (add -v to include descriptions and dates in the listing.)
-With -file, all versions are written to a file.
+List all versions of VG metadata found in the metadata area, using headers
+to locate metadata. Full copies of all metadata are saved to a file with
+the --file option. If headers are damaged, metadata may not be found (see
+metadata_search). Use --settings "mda_num=2" as above. Use -v to include
+descriptions and dates when listing metadata versions.
.B metadata_search
.br
-Search for all versions of metadata in the common locations. This does
-not use headers, so it can find metadata even when headers are damaged.
-Use --settings "mda_num=2" as above. All metadata versions are listed
-(add -v to include descriptions and dates in the listing.) With --file,
-all versions are written to a file. To save one copy of metadata, use
---settings "metadata_offset=<offset>", where the offset is taken from the
-dump listing.
+List all versions of VG metadata found in the metadata area, searching
+common locations so metadata can be found if headers are damaged. Full
+copies of all metadata are saved to a file with the --file option. To
+save one specific version of metadata, use --settings
+"metadata_offset=<offset>", where the offset is taken from the list of
+versions found. Use -v to include descriptions and dates when listing
+metadata versions.
.B metadata_area
.br
Save the entire text metadata area to a file without processing.
-.SS Repair
+.SS Repair options
.B --repair
.br
@@ -149,14 +155,15 @@ VG, it is important for the user to determine the correct PV UUID and
specify it in --settings. Otherwise, the wrong PV UUID could be used if
device names have been swapped since the metadata was last written.
-If a PV had no metadata areas and the pv_header is damaged, then the
+If a PV has no metadata areas and the pv_header is damaged, then the
repair will not know to create no metadata areas during repair. It will
by default repair metadata in mda1. To repair with no metadata areas, use
--settings "mda_offset=0 mda_size=0".
There are cases where repair should be run on all PVs in the VG (using the
same metadata file): if all PVs in the VG are damaged, if using an old
-metadata version, or if a backup file is used instead of raw metadata.
+metadata version, or if a backup file is used instead of raw metadata
+(taken from pvck dump.)
Using --repair is equivalent to running --repairtype pv_header followed by
--repairtype metadata.
@@ -175,6 +182,53 @@ correct (having been undamaged or already repaired).
Repairs label_header fields, leaving the pv_header (in the same sector)
unchanged. (repairtype pv_header should usually be used instead.)
+.SS Settings
+
+The --settings option controls or overrides certain dump or repair
+behaviors. All offset and size values in settings are in bytes (units are
+not recognized.) These settings are subject to change.
+
+.B mda_num=1|2
+.br
+Select which metadata area should be used. By default the first metadata
+area (1) is used. mda1 is always located at offset 4096. mda2, at the
+end of the device, often does not exist (it's not created by default.) If
+mda1 is erased, mda2, if it exists, will often still have metadata.
+
+\fBmetadata_offset=\fP\fIbytes\fP
+.br
+Select metadata text at this offset. Use with metadata_search to
+print/save one instance of metadata text.
+
+\fBmda_offset=\fP\fIbytes\fP \fBmda_size=\fP\fIbytes\fP
+.br
+Refers to a metadata area (mda) location and size. An mda includes an
+mda_header and circular metadata text buffer. Setting this forces
+metadata_search look for metadata in the given area instead of the
+standard locations. When set to zero with repair, it indicates no
+metadata areas should exist.
+
+\fBmda2_offset=\fP\fIbytes\fP \fBmda2_size=\fP\fIbytes\fP
+.br
+When repairing a pv_header, this forces a specific offset and size for
+mda2 that should be recorded in the pv_header.
+
+\fBpv_uuid=\fP\fIuuid\fP
+.br
+Specify the PV UUID of the device being repaired. When not specified,
+repair will attempt to determine the correct PV UUID by matching a device
+name in the metadata.
+
+\fBdevice_size=\fP\fIbytes\fP
+.br
+\fBdata_offset=\fP\fIbytes\fP
+.br
+When repairing a pv_header, the device_size, data_offset, and pvid can all
+be specified directly, in which case these values are not taken from a
+metadata file (where they usually come from), and the metadata file can be
+omitted. data_offset is the starting location of the first physical
+extent (data), which follows the first metadata area.
+
.SH USAGE
Check for metadata on a device
.br
@@ -190,7 +244,7 @@ Check for metadata on a device
Check and print LVM headers and metadata on a device
.br
.P
-\fBpvck\fP \fB--dump\fP \fIString\fP \fIPV\fP
+\fBpvck\fP \fB--dump\fP \fBheaders\fP|\fBmetadata\fP|\fBmetadata_all\fP|\fBmetadata_search\fP \fIPV\fP
.br
.RS 4
.ad l
@@ -344,7 +398,7 @@ For testing and debugging.
.ad b
.HP
.ad l
-\fB--dump\fP \fIString\fP
+\fB--dump\fP \fBheaders\fP|\fBmetadata\fP|\fBmetadata_all\fP|\fBmetadata_search\fP
.br
Dump headers and metadata from a PV for debugging and repair.
Option values include: \fBheaders\fP to print and check LVM headers,
@@ -437,7 +491,8 @@ Repair headers and metadata on a PV. See command description.
\fB--settings\fP \fIString\fP
.br
Specifies command specific settings in "Key = Value" form.
-Repeat this option to specify multiple values.
+Combine multiple settings in quotes, or repeat the settings
+option for each.
.ad b
.HP
.ad l
4 years, 2 months
master - lv_manip: add extra check for existin origin_lv
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=336361b2f25c09c7aad...
Commit: 336361b2f25c09c7aad4d21aca272a11c6c9352a
Parent: 67f627c8fbcd5224a1439cbef590e488f6c4823b
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Thu Jan 30 15:54:19 2020 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Tue Feb 4 17:22:06 2020 +0100
lv_manip: add extra check for existin origin_lv
clang: it's supposedly impossible path to hit, as we should always
have origin_lv defined when running this path, but adding protection
isn't a big issue to make this obvious to analyzer.
---
lib/metadata/lv_manip.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/lib/metadata/lv_manip.c b/lib/metadata/lv_manip.c
index ad9c756..c9f7348 100644
--- a/lib/metadata/lv_manip.c
+++ b/lib/metadata/lv_manip.c
@@ -8372,7 +8372,8 @@ static struct logical_volume *_lv_create_an_lv(struct volume_group *vg,
* COW LV is activated via implicit activation of origin LV
* Only the snapshot origin holds the LV lock in cluster
*/
- if (!vg_add_snapshot(origin_lv, lv, NULL,
+ if (!origin_lv ||
+ !vg_add_snapshot(origin_lv, lv, NULL,
origin_lv->le_count, lp->chunk_size)) {
log_error("Couldn't create snapshot.");
goto deactivate_and_revert_new_lv;
4 years, 2 months
master - raid: add internal error for no segment
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=67f627c8fbcd5224a14...
Commit: 67f627c8fbcd5224a1439cbef590e488f6c4823b
Parent: 409362c127222640cd2d1fe3e1b62b50867741c1
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Thu Jan 30 15:46:05 2020 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Tue Feb 4 17:22:06 2020 +0100
raid: add internal error for no segment
clang: capture internal error when data_seg would not be defined.
(invalid LV with no areas)
---
lib/metadata/raid_manip.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/lib/metadata/raid_manip.c b/lib/metadata/raid_manip.c
index 486dea1..dfc6fe5 100644
--- a/lib/metadata/raid_manip.c
+++ b/lib/metadata/raid_manip.c
@@ -4277,6 +4277,11 @@ static int _raid0_to_striped_retrieve_segments_and_lvs(struct logical_volume *lv
return_0;
}
+ if (!data_seg) {
+ log_error(INTERNAL_ERROR "No segment for %s.", display_lvname(lv));
+ return 0;
+ }
+
/* Presumes all data LVs have equal size */
area_le += data_seg->len;
}
4 years, 2 months
master - lv_manip: add error handling for _reserve_area
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=409362c127222640cd2...
Commit: 409362c127222640cd2d1fe3e1b62b50867741c1
Parent: e6a3c0901703bf98827e2da456daf0ced42dd96c
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Thu Jan 30 15:23:47 2020 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Tue Feb 4 17:22:06 2020 +0100
lv_manip: add error handling for _reserve_area
Since _reserve_area() may fail due to error allocation failure,
add support to report this already reported failure upward.
FIXME: it's log_error() without causing direct command failure.
---
lib/metadata/lv_manip.c | 29 +++++++++++++++++++----------
1 file changed, 19 insertions(+), 10 deletions(-)
diff --git a/lib/metadata/lv_manip.c b/lib/metadata/lv_manip.c
index b4daa56..ad9c756 100644
--- a/lib/metadata/lv_manip.c
+++ b/lib/metadata/lv_manip.c
@@ -2428,20 +2428,22 @@ static int _is_contiguous(struct pv_match *pvmatch __attribute((unused)), struct
return 1;
}
-static void _reserve_area(struct alloc_handle *ah, struct alloc_state *alloc_state, struct pv_area *pva,
+static int _reserve_area(struct alloc_handle *ah, struct alloc_state *alloc_state, struct pv_area *pva,
uint32_t required, uint32_t ix_pva, uint32_t unreserved)
{
struct pv_area_used *area_used = &alloc_state->areas[ix_pva];
const char *pv_tag_list = NULL;
if (ah->cling_tag_list_cn) {
- if (!dm_pool_begin_object(ah->mem, 256))
- log_error("PV tags string allocation failed");
- else if (!_tags_list_str(ah->mem, pva->map->pv, ah->cling_tag_list_cn))
+ if (!dm_pool_begin_object(ah->mem, 256)) {
+ log_error("PV tags string allocation failed.");
+ return 0;
+ } else if (!_tags_list_str(ah->mem, pva->map->pv, ah->cling_tag_list_cn))
dm_pool_abandon_object(ah->mem);
else if (!dm_pool_grow_object(ah->mem, "\0", 1)) {
dm_pool_abandon_object(ah->mem);
log_error("PV tags string extension failed.");
+ return 0;
} else
pv_tag_list = dm_pool_end_object(ah->mem);
}
@@ -2459,25 +2461,30 @@ static void _reserve_area(struct alloc_handle *ah, struct alloc_state *alloc_sta
area_used->pva = pva;
area_used->used = required;
+
+ return 1;
}
static int _reserve_required_area(struct alloc_handle *ah, struct alloc_state *alloc_state, struct pv_area *pva,
uint32_t required, uint32_t ix_pva, uint32_t unreserved)
{
uint32_t s;
+ struct pv_area_used *new_state;
/* Expand areas array if needed after an area was split. */
if (ix_pva >= alloc_state->areas_size) {
alloc_state->areas_size *= 2;
- if (!(alloc_state->areas = realloc(alloc_state->areas, sizeof(*alloc_state->areas) * (alloc_state->areas_size)))) {
+ if (!(new_state = realloc(alloc_state->areas, sizeof(*alloc_state->areas) * (alloc_state->areas_size)))) {
log_error("Memory reallocation for parallel areas failed.");
return 0;
}
+ alloc_state->areas = new_state;
for (s = alloc_state->areas_size / 2; s < alloc_state->areas_size; s++)
alloc_state->areas[s].pva = NULL;
}
- _reserve_area(ah, alloc_state, pva, required, ix_pva, unreserved);
+ if (!_reserve_area(ah, alloc_state, pva, required, ix_pva, unreserved))
+ return_0;
return 1;
}
@@ -2506,8 +2513,9 @@ static int _is_condition(struct cmd_context *cmd __attribute__((unused)),
* Only used for cling and contiguous policies (which only make one allocation per PV)
* so it's safe to say all the available space is used.
*/
- if (positional)
- _reserve_required_area(pvmatch->ah, pvmatch->alloc_state, pvmatch->pva, pvmatch->pva->count, s, 0);
+ if (positional &&
+ !_reserve_required_area(pvmatch->ah, pvmatch->alloc_state, pvmatch->pva, pvmatch->pva->count, s, 0))
+ return_0;
return 2; /* Finished */
}
@@ -2604,8 +2612,9 @@ static int _check_cling_to_alloced(struct alloc_handle *ah, const struct dm_conf
dm_list_iterate_items(aa, &ah->alloced_areas[s]) {
if ((!cling_tag_list_cn && (pva->map->pv == aa[0].pv)) ||
(cling_tag_list_cn && _pvs_have_matching_tag(cling_tag_list_cn, pva->map->pv, aa[0].pv, 0))) {
- if (positional)
- _reserve_required_area(ah, alloc_state, pva, pva->count, s, 0);
+ if (positional &&
+ !_reserve_required_area(ah, alloc_state, pva, pva->count, s, 0))
+ return_0;
return 1;
}
}
4 years, 2 months
master - command: validate reporting of previous argument
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=e6a3c0901703bf98827...
Commit: e6a3c0901703bf98827e2da456daf0ced42dd96c
Parent: 4791d0f035e006e9541d27ef2c3dcb6ea561324a
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Thu Jan 30 15:08:30 2020 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Tue Feb 4 17:22:06 2020 +0100
command: validate reporting of previous argument
When reporting parsing error, report 'previous' argument
only when there is one.
---
tools/command.c | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/tools/command.c b/tools/command.c
index 0cbd877..50791b1 100644
--- a/tools/command.c
+++ b/tools/command.c
@@ -999,8 +999,8 @@ static void __add_optional_opt_line(struct cmd_context *cmdtool, struct command
else if (takes_arg)
_update_prev_opt_arg(cmdtool, cmd, argv[i], OPTIONAL);
else {
- log_error("Parsing command defs: can't parse argc %d argv %s prev %s.",
- i, argv[i], argv[i-1]);
+ log_error("Parsing command defs: can't parse argc %d argv %s%s%s.",
+ i, argv[i], (i > 0) ? " prev " : "", (i > 0) ? argv[i - 1] : "");
cmd->cmd_flags |= CMD_FLAG_PARSE_ERROR;
return;
}
@@ -1025,8 +1025,8 @@ static void _add_ignore_opt_line(struct cmd_context *cmdtool, struct command *cm
else if (takes_arg)
_update_prev_opt_arg(cmdtool, cmd, argv[i], IGNORE);
else {
- log_error("Parsing command defs: can't parse argc %d argv %s prev %s.",
- i, argv[i], argv[i-1]);
+ log_error("Parsing command defs: can't parse argc %d argv %s%s%s.",
+ i, argv[i], (i > 0) ? " prev " : "", (i > 0) ? argv[i - 1] : "");
cmd->cmd_flags |= CMD_FLAG_PARSE_ERROR;
return;
}
@@ -1060,8 +1060,8 @@ static void _add_required_opt_line(struct cmd_context *cmdtool, struct command *
else if (takes_arg)
_update_prev_opt_arg(cmdtool, cmd, argv[i], REQUIRED);
else {
- log_error("Parsing command defs: can't parse argc %d argv %s prev %s.",
- i, argv[i], argv[i-1]);
+ log_error("Parsing command defs: can't parse argc %d argv %s%s%s.",
+ i, argv[i], (i > 0) ? " prev " : "", (i > 0) ? argv[i - 1] : "");
cmd->cmd_flags |= CMD_FLAG_PARSE_ERROR;
return;
}
@@ -1150,8 +1150,8 @@ static void _add_required_line(struct cmd_context *cmdtool, struct command *cmd,
/* set property for previous required_pos_arg */
_update_prev_pos_arg(cmd, argv[i], REQUIRED);
} else {
- log_error("Parsing command defs: can't parse argc %d argv %s prev %s.",
- i, argv[i], argv[i-1]);
+ log_error("Parsing command defs: can't parse argc %d argv %s%s%s.",
+ i, argv[i], (i > 0) ? " prev " : "", (i > 0) ? argv[i - 1] : "");
cmd->cmd_flags |= CMD_FLAG_PARSE_ERROR;
return;
}
4 years, 2 months
master - dmeventd: nicer error path for reading pipe
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=4791d0f035e006e9541...
Commit: 4791d0f035e006e9541d27ef2c3dcb6ea561324a
Parent: 91d16fc049ba2034708aa6a0bab5f548040dfd3b
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Wed Jan 29 16:41:28 2020 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Tue Feb 4 17:22:06 2020 +0100
dmeventd: nicer error path for reading pipe
When _daemon_read()/_client_read() fails during the read,
ensure memory allocated withing function is also release here
(so caller does not need to care). Also improve code readbility a bit
a for same functionality use more similar code.
---
daemons/dmeventd/dmeventd.c | 39 ++++++++++++++++-------------------
daemons/dmeventd/libdevmapper-event.c | 35 ++++++++++++++++++-------------
2 files changed, 39 insertions(+), 35 deletions(-)
diff --git a/daemons/dmeventd/dmeventd.c b/daemons/dmeventd/dmeventd.c
index 4fcb381..36a35ba 100644
--- a/daemons/dmeventd/dmeventd.c
+++ b/daemons/dmeventd/dmeventd.c
@@ -1485,37 +1485,34 @@ static int _client_read(struct dm_event_fifos *fifos,
t.tv_usec = 0;
ret = select(fifos->client + 1, &fds, NULL, NULL, &t);
- if (!ret && !bytes) /* nothing to read */
- return 0;
+ if (!ret && bytes)
+ continue; /* trying to finish read */
- if (!ret) /* trying to finish read */
- continue;
-
- if (ret < 0) /* error */
- return 0;
+ if (ret <= 0) /* nothing to read */
+ goto bad;
ret = read(fifos->client, buf + bytes, size - bytes);
bytes += ret > 0 ? ret : 0;
- if (header && (bytes == 2 * sizeof(uint32_t))) {
+ if (!msg->data && (bytes == 2 * sizeof(uint32_t))) {
msg->cmd = ntohl(header[0]);
- size = msg->size = ntohl(header[1]);
bytes = 0;
- if (!size)
- break; /* No data -> error */
- buf = msg->data = malloc(msg->size);
- if (!buf)
- break; /* No mem -> error */
- header = 0;
+
+ if (!(size = msg->size = ntohl(header[1])))
+ break;
+
+ if (!(buf = msg->data = malloc(msg->size)))
+ goto bad;
}
}
- if (bytes != size) {
- free(msg->data);
- msg->data = NULL;
- return 0;
- }
+ if (bytes == size)
+ return 1;
- return 1;
+bad:
+ free(msg->data);
+ msg->data = NULL;
+
+ return 0;
}
/*
diff --git a/daemons/dmeventd/libdevmapper-event.c b/daemons/dmeventd/libdevmapper-event.c
index 491374e..780d10d 100644
--- a/daemons/dmeventd/libdevmapper-event.c
+++ b/daemons/dmeventd/libdevmapper-event.c
@@ -237,16 +237,16 @@ static int _daemon_read(struct dm_event_fifos *fifos,
ret = select(fifos->server + 1, &fds, NULL, NULL, &tval);
if (ret < 0 && errno != EINTR) {
log_error("Unable to read from event server.");
- return 0;
+ goto bad;
}
if ((ret == 0) && (i > 4) && !bytes) {
log_error("No input from event server.");
- return 0;
+ goto bad;
}
}
if (ret < 1) {
log_error("Unable to read from event server.");
- return 0;
+ goto bad;
}
ret = read(fifos->server, buf + bytes, size);
@@ -255,25 +255,32 @@ static int _daemon_read(struct dm_event_fifos *fifos,
continue;
log_error("Unable to read from event server.");
- return 0;
+ goto bad;
}
bytes += ret;
- if (header && (bytes == 2 * sizeof(uint32_t))) {
+ if (!msg->data && (bytes == 2 * sizeof(uint32_t))) {
msg->cmd = ntohl(header[0]);
- msg->size = ntohl(header[1]);
- buf = msg->data = malloc(msg->size);
- size = msg->size;
bytes = 0;
- header = 0;
+
+ if (!(size = msg->size = ntohl(header[1])))
+ break;
+
+ if (!(buf = msg->data = malloc(msg->size))) {
+ log_error("Unable to allocate message data.");
+ return 0;
+ }
}
}
- if (bytes != size) {
- free(msg->data);
- msg->data = NULL;
- }
- return bytes == size;
+ if (bytes == size)
+ return 1;
+
+bad:
+ free(msg->data);
+ msg->data = NULL;
+
+ return 0;
}
/* Write message to daemon. */
4 years, 2 months