1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +03:00

dmstats: only generate aux data separator if group tag is defined

Fix a bug in _stats_set_aux() that causes bogus data to appear
in the 'userdata' field of stats reports when previously grouped
regions are ungrouped:

/var/tmp/File With Spaces: Created new group with 1 region(s) as group ID 0.

Removed group ID 0 on fedora-root

Name             GrpID RgID ObjType RgStart RgSize  #Areas ArSize  ProgID  UserData
fedora-root          -    0 region    6.39g 100.00m      1 100.00m dmstats #-
                                                                           ^^
This is the aux_data separator character followed by empty user data.
The _stats_set_aux() function should only emit the separator if
there is a valid group descriptor for the region.
This commit is contained in:
Bryn M. Reeves 2023-09-28 15:06:24 +01:00 committed by Zdeněk Kabeláč
parent 995c7b503b
commit 0ff027ae2c
3 changed files with 87 additions and 5 deletions

View File

@ -1954,10 +1954,9 @@ bad:
static int _stats_set_aux(struct dm_stats *dms,
uint64_t region_id, const char *user_data)
{
const char *group_tag = NULL;
char *group_tag = NULL, *group_tag_escaped = NULL;
struct dm_task *dmt = NULL;
char msg[STATS_MSG_BUF_LEN];
char *group_tag_escaped = NULL;
/* group data required? */
if (_stats_group_id_present(dms, region_id)) {
@ -1970,8 +1969,7 @@ static int _stats_set_aux(struct dm_stats *dms,
group_tag_escaped = _stats_escape_aux_data(group_tag);
if (!group_tag_escaped)
goto bad;
} else
group_tag_escaped = dm_strdup("");
}
if (dm_snprintf(msg, sizeof(msg), "@stats_set_aux " FMTu64 " %s%s%s ",
region_id, (group_tag_escaped) ? group_tag_escaped : "",
@ -1984,7 +1982,7 @@ static int _stats_set_aux(struct dm_stats *dms,
if (!(dmt = _stats_send_message(dms, msg)))
goto_bad;
dm_free((char *) group_tag);
dm_free(group_tag);
dm_free(group_tag_escaped);
/* no response to a @stats_set_aux message */

View File

@ -0,0 +1,41 @@
#!/usr/bin/env bash
# Copyright (C) 2023 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
SKIP_WITH_LVMPOLLD=1
SKIP_WITH_LVMLOCKD=1
. lib/inittest
# Don't attempt to test stats with driver < 4.33.00
aux driver_at_least 4 33 || skip
# ensure we can create devices (uses dmsetup, etc)
aux prepare_devs 1
GROUP_NAME="group0"
BAD_USERDATA="#-"
# Create a region and make it part of a group with an alias
dmstats create "$dev1"
dmstats group --alias "$GROUP_NAME" --regions 0 "$dev1"
dmstats list -ostats_name |& tee out
grep "$GROUP_NAME" out
# Ungroup the regions then remove them
dmstats ungroup --groupid 0 "$dev1"
# Verify userdata does not contain '#-'
dmstats list -ouserdata |& tee out
not grep "$BAD_USERDATA" out
# Clean up
dmstats delete --allregions "$dev1"

View File

@ -0,0 +1,43 @@
#!/usr/bin/env bash
# Copyright (C) 2023 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
SKIP_WITH_LVMPOLLD=1
SKIP_WITH_LVMLOCKD=1
. lib/inittest
# Don't attempt to test stats with driver < 4.33.00
aux driver_at_least 4 33 || skip
# ensure we can create devices (uses dmsetup, etc)
aux prepare_devs 1
GROUP_NAME="group0"
USERDATA="foo"
# Create a region and make it part of a group with an alias
dmstats create "$dev1" --userdata "$USERDATA"
dmstats group --alias "$GROUP_NAME" --regions 0 "$dev1"
dmstats list -ostats_name |& tee out
grep "$GROUP_NAME" out
dmstats list -ouserdata |& tee out
grep "$USERDATA" out
# Ungroup the regions then remove them
dmstats ungroup --groupid 0 "$dev1"
# Verify userdata is still valid
dmstats list -ouserdata |& tee out
grep "$USERDATA" out
# Clean up
dmstats delete --allregions "$dev1"