master - tests: sleep first
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=0bf1cc2320cb96cde9b...
Commit: 0bf1cc2320cb96cde9be742bed2aa391c998588a
Parent: 3a841515af623b86be0628ef6568ff74009ea643
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Wed Dec 13 16:17:56 2017 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Tue Dec 19 15:28:07 2017 +0100
tests: sleep first
Sleep a bit before checking /sys/block dir so the kernel has a moment to
actually put scsi debug device in it...
Some quite old kernels are in troubles with this plain searching grep
without sleep (namely 2.6.32)
modprobe scsi_debug
<sleep .1>
grep -H scsi_debug /sys/block/*/device/model
modprobe -r scsi_debug
---
test/lib/aux.sh | 6 +++---
1 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/test/lib/aux.sh b/test/lib/aux.sh
index 6bc7bd4..fa9a1a2 100644
--- a/test/lib/aux.sh
+++ b/test/lib/aux.sh
@@ -703,10 +703,10 @@ prepare_scsi_debug_dev() {
modprobe scsi_debug dev_size_mb="$DEV_SIZE" "$@" num_tgts=1 || skip
for i in {1..20} ; do
- DEBUG_DEV="/dev/$(grep -H scsi_debug /sys/block/*/device/model | cut -f4 -d /)"
- test -b "$DEBUG_DEV" && break
sleep .1 # allow for async Linux SCSI device registration
- done
+ DEBUG_DEV="/dev/$(grep -H scsi_debug /sys/block/sd*/device/model | cut -f4 -d /)"
+ test -b "$DEBUG_DEV" && break
+ done
test -b "$DEBUG_DEV" || return 1 # should not happen
# Create symlink to scsi_debug device in $DM_DEV_DIR
5 years, 9 months
master - lvm-string: add function to detect component LV suffix
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=3a841515af623b86be0...
Commit: 3a841515af623b86be0628ef6568ff74009ea643
Parent: 17649d4ac8d4c7d10bf58feefa5f1faae89713ca
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Mon Dec 11 18:12:47 2017 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Tue Dec 19 15:28:07 2017 +0100
lvm-string: add function to detect component LV suffix
Add is_component_lvname() function to recognize component LV name.
---
lib/misc/lvm-string.c | 30 +++++++++++++++++++++++++++---
lib/misc/lvm-string.h | 1 +
2 files changed, 28 insertions(+), 3 deletions(-)
diff --git a/lib/misc/lvm-string.c b/lib/misc/lvm-string.c
index cdcc993..a2098fd 100644
--- a/lib/misc/lvm-string.c
+++ b/lib/misc/lvm-string.c
@@ -150,22 +150,41 @@ static const char *_lvname_has_reserved_prefix(const char *lvname)
return NULL;
}
-static const char *_lvname_has_reserved_string(const char *lvname)
+static const char *_lvname_has_reserved_component_string(const char *lvname)
{
static const char _strings[][12] = {
+ /* Suffixes for compoment LVs */
"_cdata",
"_cmeta",
"_corig",
"_mimage",
"_mlog",
- "_pmspare",
"_rimage",
"_rmeta",
"_tdata",
- "_tmeta",
+ "_tmeta"
+ };
+ unsigned i;
+
+ for (i = 0; i < DM_ARRAY_SIZE(_strings); ++i)
+ if (strstr(lvname, _strings[i]))
+ return _strings[i];
+
+ return NULL;
+}
+
+static const char *_lvname_has_reserved_string(const char *lvname)
+{
+ static const char _strings[][12] = {
+ /* Additional suffixes for non-compoment LVs */
+ "_pmspare",
"_vorigin"
};
unsigned i;
+ const char *cs;
+
+ if ((cs = _lvname_has_reserved_component_string(lvname)))
+ return cs;
for (i = 0; i < DM_ARRAY_SIZE(_strings); ++i)
if (strstr(lvname, _strings[i]))
@@ -208,6 +227,11 @@ int is_reserved_lvname(const char *name)
_lvname_has_reserved_string(name)) ? 1 : 0;
}
+int is_component_lvname(const char *name)
+{
+ return (_lvname_has_reserved_component_string(name)) ? 1 : 0;
+}
+
char *build_dm_uuid(struct dm_pool *mem, const struct logical_volume *lv,
const char *layer)
{
diff --git a/lib/misc/lvm-string.h b/lib/misc/lvm-string.h
index ebdf956..4e7404a 100644
--- a/lib/misc/lvm-string.h
+++ b/lib/misc/lvm-string.h
@@ -47,6 +47,7 @@ int validate_tag(const char *n);
void copy_systemid_chars(const char *src, char *dst);
int apply_lvname_restrictions(const char *name);
+int is_component_lvname(const char *name);
int is_reserved_lvname(const char *name);
/*
5 years, 9 months
master - device: Move dev_read memory allocation into device layer.
by Alasdair Kergon
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=17649d4ac8d4c7d10bf...
Commit: 17649d4ac8d4c7d10bf58feefa5f1faae89713ca
Parent: 3f9ae846b89a2963a4ca72cfa0281aab0bedcc02
Author: Alasdair G Kergon <agk(a)redhat.com>
AuthorDate: Tue Dec 19 01:12:18 2017 +0000
Committer: Alasdair G Kergon <agk(a)redhat.com>
CommitterDate: Tue Dec 19 01:31:50 2017 +0000
device: Move dev_read memory allocation into device layer.
Rename dev_read() to dev_read_buf() - the function that reads data
into a supplied buffer.
Introduce a new dev_read() that allocates the buffer it returns and
switch the important users over to this. No caller may change the
returned data. (For now, callers are responsible for freeing it after
use, but later the device layer will take full ownership.)
dev_read_buf() should only be used for tiny buffers or unimportant code
(such as the old disk formats).
---
WHATS_NEW | 1 +
lib/config/config.c | 6 +----
lib/device/dev-io.c | 42 +++++++++++++++++++++++++++++++++++++---
lib/device/dev-luks.c | 2 +-
lib/device/dev-md.c | 2 +-
lib/device/dev-swap.c | 3 +-
lib/device/dev-type.c | 2 +-
lib/device/device.h | 8 ++++++-
lib/format1/disk-rep.c | 10 ++++----
lib/format_pool/disk_rep.c | 2 +-
lib/format_text/format-text.c | 28 +++++++++++++-------------
lib/label/label.c | 29 +++++++++++++--------------
12 files changed, 85 insertions(+), 50 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index e4b04b0..fa79068 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
Version 2.02.178 -
=====================================
+ Move memory allocation for the key dev_reads into the device layer.
Version 2.02.177 - 18th December 2017
=====================================
diff --git a/lib/config/config.c b/lib/config/config.c
index fac7e4c..bbbcc3d 100644
--- a/lib/config/config.c
+++ b/lib/config/config.c
@@ -533,11 +533,7 @@ int config_file_read_fd(struct dm_config_tree *cft, struct device *dev, dev_io_r
if (!(buf = dev_read_circular(dev, (uint64_t) offset, size, (uint64_t) offset2, size2, reason)))
goto_out;
} else {
- if (!(buf = dm_malloc(size))) {
- log_error("Failed to allocate buffer for metadata read.");
- return 0;
- }
- if (!dev_read(dev, (uint64_t) offset, size, reason, buf))
+ if (!(buf = dev_read(dev, (uint64_t) offset, size, reason)))
goto_out;
}
fb = buf;
diff --git a/lib/device/dev-io.c b/lib/device/dev-io.c
index 0545d8c..72d6768 100644
--- a/lib/device/dev-io.c
+++ b/lib/device/dev-io.c
@@ -722,7 +722,7 @@ static void _dev_inc_error_count(struct device *dev)
dev->max_error_count, dev_name(dev));
}
-int dev_read(struct device *dev, uint64_t offset, size_t len, dev_io_reason_t reason, void *buffer)
+static int _dev_read(struct device *dev, uint64_t offset, size_t len, dev_io_reason_t reason, char *buf)
{
struct device_area where;
int ret;
@@ -737,13 +737,47 @@ int dev_read(struct device *dev, uint64_t offset, size_t len, dev_io_reason_t re
where.start = offset;
where.size = len;
- ret = _aligned_io(&where, buffer, 0, reason);
+ ret = _aligned_io(&where, buf, 0, reason);
if (!ret)
_dev_inc_error_count(dev);
return ret;
}
+/* Caller is responsible for dm_free */
+char *dev_read(struct device *dev, uint64_t offset, size_t len, dev_io_reason_t reason)
+{
+ char *buf;
+
+ if (!(buf = dm_malloc(len))) {
+ log_error("Buffer allocation failed for device read.");
+ return NULL;
+ }
+
+ if (!_dev_read(dev, offset, len, reason, buf)) {
+ log_error("Read from %s failed", dev_name(dev));
+ dm_free(buf);
+ return NULL;
+ }
+
+ return buf;
+}
+
+/* Read into supplied retbuf */
+int dev_read_buf(struct device *dev, uint64_t offset, size_t len, dev_io_reason_t reason, void *retbuf)
+{
+ char *buf = NULL;
+
+ if (!(buf = dev_read(dev, offset, len, reason)))
+ return_0;
+
+ memcpy(retbuf, buf, len);
+
+ dm_free(buf);
+
+ return 1;
+}
+
/*
* Read from 'dev' in 2 distinct regions, denoted by (offset,len) and (offset2,len2).
* Caller is responsible for dm_free().
@@ -758,13 +792,13 @@ char *dev_read_circular(struct device *dev, uint64_t offset, size_t len,
return NULL;
}
- if (!dev_read(dev, offset, len, reason, buf)) {
+ if (!_dev_read(dev, offset, len, reason, buf)) {
log_error("Read from %s failed", dev_name(dev));
dm_free(buf);
return NULL;
}
- if (!dev_read(dev, offset2, len2, reason, buf + len)) {
+ if (!_dev_read(dev, offset2, len2, reason, buf + len)) {
log_error("Circular read from %s failed", dev_name(dev));
dm_free(buf);
return NULL;
diff --git a/lib/device/dev-luks.c b/lib/device/dev-luks.c
index 8513e14..f291615 100644
--- a/lib/device/dev-luks.c
+++ b/lib/device/dev-luks.c
@@ -31,7 +31,7 @@ int dev_is_luks(struct device *dev, uint64_t *offset_found)
if (offset_found)
*offset_found = 0;
- if (!dev_read(dev, 0, LUKS_SIGNATURE_SIZE, DEV_IO_SIGNATURES, buf))
+ if (!dev_read_buf(dev, 0, LUKS_SIGNATURE_SIZE, DEV_IO_SIGNATURES, buf))
goto_out;
ret = memcmp(buf, LUKS_SIGNATURE, LUKS_SIGNATURE_SIZE) ? 0 : 1;
diff --git a/lib/device/dev-md.c b/lib/device/dev-md.c
index 92ee214..1a5d470 100644
--- a/lib/device/dev-md.c
+++ b/lib/device/dev-md.c
@@ -37,7 +37,7 @@ static int _dev_has_md_magic(struct device *dev, uint64_t sb_offset)
uint32_t md_magic;
/* Version 1 is little endian; version 0.90.0 is machine endian */
- if (dev_read(dev, sb_offset, sizeof(uint32_t), DEV_IO_SIGNATURES, &md_magic) &&
+ if (dev_read_buf(dev, sb_offset, sizeof(uint32_t), DEV_IO_SIGNATURES, &md_magic) &&
((md_magic == MD_SB_MAGIC) ||
((MD_SB_MAGIC != xlate32(MD_SB_MAGIC)) && (md_magic == xlate32(MD_SB_MAGIC)))))
return 1;
diff --git a/lib/device/dev-swap.c b/lib/device/dev-swap.c
index a7ff10b..094eb05 100644
--- a/lib/device/dev-swap.c
+++ b/lib/device/dev-swap.c
@@ -60,8 +60,7 @@ int dev_is_swap(struct device *dev, uint64_t *offset_found)
continue;
if (size < (page >> SECTOR_SHIFT))
break;
- if (!dev_read(dev, page - SIGNATURE_SIZE,
- SIGNATURE_SIZE, DEV_IO_SIGNATURES, buf)) {
+ if (!dev_read_buf(dev, page - SIGNATURE_SIZE, SIGNATURE_SIZE, DEV_IO_SIGNATURES, buf)) {
ret = -1;
break;
}
diff --git a/lib/device/dev-type.c b/lib/device/dev-type.c
index 9608146..b9e77f8 100644
--- a/lib/device/dev-type.c
+++ b/lib/device/dev-type.c
@@ -363,7 +363,7 @@ static int _has_partition_table(struct device *dev)
uint16_t magic;
} __attribute__((packed)) buf; /* sizeof() == SECTOR_SIZE */
- if (!dev_read(dev, UINT64_C(0), sizeof(buf), DEV_IO_SIGNATURES, &buf))
+ if (!dev_read_buf(dev, UINT64_C(0), sizeof(buf), DEV_IO_SIGNATURES, &buf))
return_0;
/* FIXME Check for other types of partition table too */
diff --git a/lib/device/device.h b/lib/device/device.h
index a369195..dac638c 100644
--- a/lib/device/device.h
+++ b/lib/device/device.h
@@ -145,9 +145,15 @@ int dev_test_excl(struct device *dev);
int dev_fd(struct device *dev);
const char *dev_name(const struct device *dev);
-int dev_read(struct device *dev, uint64_t offset, size_t len, dev_io_reason_t reason, void *buffer);
+/* Returns a read-only buffer */
+char *dev_read(struct device *dev, uint64_t offset, size_t len, dev_io_reason_t reason);
char *dev_read_circular(struct device *dev, uint64_t offset, size_t len,
uint64_t offset2, size_t len2, dev_io_reason_t reason);
+
+/* Read data and copy it into a supplied private buffer. */
+/* Only use for tiny reads or on unimportant code paths. */
+int dev_read_buf(struct device *dev, uint64_t offset, size_t len, dev_io_reason_t reason, void *retbuf);
+
int dev_write(struct device *dev, uint64_t offset, size_t len, dev_io_reason_t reason, void *buffer);
int dev_append(struct device *dev, size_t len, dev_io_reason_t reason, char *buffer);
int dev_set(struct device *dev, uint64_t offset, size_t len, dev_io_reason_t reason, int value);
diff --git a/lib/format1/disk-rep.c b/lib/format1/disk-rep.c
index 41955af..cf34e91 100644
--- a/lib/format1/disk-rep.c
+++ b/lib/format1/disk-rep.c
@@ -205,7 +205,7 @@ int munge_pvd(struct device *dev, struct pv_disk *pvd)
static int _read_pvd(struct device *dev, struct pv_disk *pvd)
{
- if (!dev_read(dev, UINT64_C(0), sizeof(*pvd), DEV_IO_FMT1, pvd)) {
+ if (!dev_read_buf(dev, UINT64_C(0), sizeof(*pvd), DEV_IO_FMT1, pvd)) {
log_very_verbose("Failed to read PV data from %s",
dev_name(dev));
return 0;
@@ -216,7 +216,7 @@ static int _read_pvd(struct device *dev, struct pv_disk *pvd)
static int _read_lvd(struct device *dev, uint64_t pos, struct lv_disk *disk)
{
- if (!dev_read(dev, pos, sizeof(*disk), DEV_IO_FMT1, disk))
+ if (!dev_read_buf(dev, pos, sizeof(*disk), DEV_IO_FMT1, disk))
return_0;
_xlate_lvd(disk);
@@ -228,7 +228,7 @@ int read_vgd(struct device *dev, struct vg_disk *vgd, struct pv_disk *pvd)
{
uint64_t pos = pvd->vg_on_disk.base;
- if (!dev_read(dev, pos, sizeof(*vgd), DEV_IO_FMT1, vgd))
+ if (!dev_read_buf(dev, pos, sizeof(*vgd), DEV_IO_FMT1, vgd))
return_0;
_xlate_vgd(vgd);
@@ -252,7 +252,7 @@ static int _read_uuids(struct disk_list *data)
uint64_t end = pos + data->pvd.pv_uuidlist_on_disk.size;
while (pos < end && num_read < data->vgd.pv_cur) {
- if (!dev_read(data->dev, pos, sizeof(buffer), DEV_IO_FMT1, buffer))
+ if (!dev_read_buf(data->dev, pos, sizeof(buffer), DEV_IO_FMT1, buffer))
return_0;
if (!(ul = dm_pool_alloc(data->mem, sizeof(*ul))))
@@ -311,7 +311,7 @@ static int _read_extents(struct disk_list *data)
if (!extents)
return_0;
- if (!dev_read(data->dev, pos, len, DEV_IO_FMT1, extents))
+ if (!dev_read_buf(data->dev, pos, len, DEV_IO_FMT1, extents))
return_0;
_xlate_extents(extents, data->pvd.pe_total);
diff --git a/lib/format_pool/disk_rep.c b/lib/format_pool/disk_rep.c
index 374ff44..4b2e7fb 100644
--- a/lib/format_pool/disk_rep.c
+++ b/lib/format_pool/disk_rep.c
@@ -40,7 +40,7 @@ static int __read_pool_disk(const struct format_type *fmt, struct device *dev,
char buf[512] __attribute__((aligned(8)));
/* FIXME: Need to check the cache here first */
- if (!dev_read(dev, UINT64_C(0), 512, DEV_IO_POOL, buf)) {
+ if (!dev_read_buf(dev, UINT64_C(0), 512, DEV_IO_POOL, buf)) {
log_very_verbose("Failed to read PV data from %s",
dev_name(dev));
return 0;
diff --git a/lib/format_text/format-text.c b/lib/format_text/format-text.c
index 79bb9fa..c57ffd2 100644
--- a/lib/format_text/format-text.c
+++ b/lib/format_text/format-text.c
@@ -182,7 +182,7 @@ static int _pv_analyze_mda_raw (const struct format_type * fmt,
uint64_t offset2;
size_t size;
size_t size2;
- char *buf=NULL;
+ char *buf = NULL;
struct device_area *area;
struct mda_context *mdac;
unsigned circular = 0;
@@ -240,12 +240,8 @@ static int _pv_analyze_mda_raw (const struct format_type * fmt,
if (circular) {
if (!(buf = dev_read_circular(area->dev, offset, size, offset2, size2, MDA_CONTENT_REASON(mda_is_primary(mda)))))
goto_out;
- } else {
- if (!(buf = dm_malloc(size)))
- goto_out;
- if (!dev_read(area->dev, offset, size, MDA_CONTENT_REASON(mda_is_primary(mda)), buf))
+ } else if (!(buf = dev_read(area->dev, offset, size, MDA_CONTENT_REASON(mda_is_primary(mda)))))
goto_out;
- }
/*
* FIXME: We could add more sophisticated metadata detection
@@ -334,7 +330,7 @@ static int _raw_read_mda_header(struct mda_header *mdah, struct device_area *dev
if (!dev_open_readonly(dev_area->dev))
return_0;
- if (!dev_read(dev_area->dev, dev_area->start, MDA_HEADER_SIZE, MDA_HEADER_REASON(primary_mda), mdah)) {
+ if (!dev_read_buf(dev_area->dev, dev_area->start, MDA_HEADER_SIZE, MDA_HEADER_REASON(primary_mda), mdah)) {
if (!dev_close(dev_area->dev))
stack;
return_0;
@@ -420,13 +416,13 @@ static struct raw_locn *_find_vg_rlocn(struct device_area *dev_area,
int *precommitted)
{
size_t len;
- char vgnamebuf[NAME_LEN + 2] __attribute__((aligned(8)));
struct raw_locn *rlocn, *rlocn_precommitted;
struct lvmcache_info *info;
struct lvmcache_vgsummary vgsummary_orphan = {
.vgname = FMT_TEXT_ORPHAN_VG_NAME,
};
int rlocn_was_ignored;
+ char *buf;
memcpy(&vgsummary_orphan.vgid, FMT_TEXT_ORPHAN_VG_NAME, sizeof(FMT_TEXT_ORPHAN_VG_NAME));
@@ -461,13 +457,17 @@ static struct raw_locn *_find_vg_rlocn(struct device_area *dev_area,
/* FIXME Loop through rlocns two-at-a-time. List null-terminated. */
/* FIXME Ignore if checksum incorrect!!! */
- if (!dev_read(dev_area->dev, dev_area->start + rlocn->offset,
- sizeof(vgnamebuf), MDA_CONTENT_REASON(primary_mda), vgnamebuf))
+ if (!(buf = dev_read(dev_area->dev, dev_area->start + rlocn->offset,
+ NAME_LEN + 2, MDA_CONTENT_REASON(primary_mda))))
goto_bad;
- if (!strncmp(vgnamebuf, vgname, len = strlen(vgname)) &&
- (isspace(vgnamebuf[len]) || vgnamebuf[len] == '{'))
+ if (!strncmp(buf, vgname, len = strlen(vgname)) &&
+ (isspace(*(buf + len)) || *(buf + len) == '{')) {
+ dm_free(buf);
return rlocn;
+ }
+
+ dm_free(buf);
log_debug_metadata("Volume group name found in %smetadata on %s at " FMTu64 " does "
"not match expected name %s.",
@@ -1332,8 +1332,8 @@ int vgname_from_mda(const struct format_type *fmt,
}
/* Do quick check for a vgname */
- if (!dev_read(dev_area->dev, dev_area->start + rlocn->offset,
- NAME_LEN, MDA_CONTENT_REASON(primary_mda), buf))
+ if (!dev_read_buf(dev_area->dev, dev_area->start + rlocn->offset,
+ NAME_LEN, MDA_CONTENT_REASON(primary_mda), buf))
return_0;
while (buf[len] && !isspace(buf[len]) && buf[len] != '{' &&
diff --git a/lib/label/label.c b/lib/label/label.c
index 249927b..b90fff3 100644
--- a/lib/label/label.c
+++ b/lib/label/label.c
@@ -109,7 +109,7 @@ static void _update_lvmcache_orphan(struct lvmcache_info *info)
stack;
}
-static struct labeller *_find_labeller(struct device *dev, char *buf,
+static struct labeller *_find_labeller(struct device *dev, char *labelbuf,
uint64_t *label_sector,
uint64_t scan_sector)
{
@@ -119,10 +119,9 @@ static struct labeller *_find_labeller(struct device *dev, char *buf,
struct lvmcache_info *info;
uint64_t sector;
int found = 0;
- char readbuf[LABEL_SCAN_SIZE] __attribute__((aligned(8)));
+ char *buf = NULL;
- if (!dev_read(dev, scan_sector << SECTOR_SHIFT,
- LABEL_SCAN_SIZE, DEV_IO_LABEL, readbuf)) {
+ if (!(buf = dev_read(dev, scan_sector << SECTOR_SHIFT, LABEL_SCAN_SIZE, DEV_IO_LABEL))) {
log_debug_devs("%s: Failed to read label area", dev_name(dev));
goto out;
}
@@ -130,8 +129,7 @@ static struct labeller *_find_labeller(struct device *dev, char *buf,
/* Scan a few sectors for a valid label */
for (sector = 0; sector < LABEL_SCAN_SECTORS;
sector += LABEL_SIZE >> SECTOR_SHIFT) {
- lh = (struct label_header *) (readbuf +
- (sector << SECTOR_SHIFT));
+ lh = (struct label_header *) (buf + (sector << SECTOR_SHIFT));
if (!strncmp((char *)lh->id, LABEL_ID, sizeof(lh->id))) {
if (found) {
@@ -173,7 +171,7 @@ static struct labeller *_find_labeller(struct device *dev, char *buf,
continue;
}
r = li->l;
- memcpy(buf, lh, LABEL_SIZE);
+ memcpy(labelbuf, lh, LABEL_SIZE);
if (label_sector)
*label_sector = sector + scan_sector;
found = 1;
@@ -183,6 +181,8 @@ static struct labeller *_find_labeller(struct device *dev, char *buf,
}
out:
+ dm_free(buf);
+
if (!found) {
if ((info = lvmcache_info_from_pvid(dev->pvid, dev, 0)))
_update_lvmcache_orphan(info);
@@ -195,16 +195,16 @@ static struct labeller *_find_labeller(struct device *dev, char *buf,
/* FIXME Also wipe associated metadata area headers? */
int label_remove(struct device *dev)
{
- char buf[LABEL_SIZE] __attribute__((aligned(8)));
- char readbuf[LABEL_SCAN_SIZE] __attribute__((aligned(8)));
+ char labelbuf[LABEL_SIZE] __attribute__((aligned(8)));
int r = 1;
uint64_t sector;
int wipe;
struct labeller_i *li;
struct label_header *lh;
struct lvmcache_info *info;
+ char *buf = NULL;
- memset(buf, 0, LABEL_SIZE);
+ memset(labelbuf, 0, LABEL_SIZE);
log_very_verbose("Scanning for labels to wipe from %s", dev_name(dev));
@@ -217,7 +217,7 @@ int label_remove(struct device *dev)
*/
dev_flush(dev);
- if (!dev_read(dev, UINT64_C(0), LABEL_SCAN_SIZE, DEV_IO_LABEL, readbuf)) {
+ if (!(buf = dev_read(dev, UINT64_C(0), LABEL_SCAN_SIZE, DEV_IO_LABEL))) {
log_debug_devs("%s: Failed to read label area", dev_name(dev));
goto out;
}
@@ -225,8 +225,7 @@ int label_remove(struct device *dev)
/* Scan first few sectors for anything looking like a label */
for (sector = 0; sector < LABEL_SCAN_SECTORS;
sector += LABEL_SIZE >> SECTOR_SHIFT) {
- lh = (struct label_header *) (readbuf +
- (sector << SECTOR_SHIFT));
+ lh = (struct label_header *) (buf + (sector << SECTOR_SHIFT));
wipe = 0;
@@ -246,8 +245,7 @@ int label_remove(struct device *dev)
if (wipe) {
log_very_verbose("%s: Wiping label at sector %" PRIu64,
dev_name(dev), sector);
- if (dev_write(dev, sector << SECTOR_SHIFT, LABEL_SIZE, DEV_IO_LABEL,
- buf)) {
+ if (dev_write(dev, sector << SECTOR_SHIFT, LABEL_SIZE, DEV_IO_LABEL, labelbuf)) {
/* Also remove the PV record from cache. */
info = lvmcache_info_from_pvid(dev->pvid, dev, 0);
if (info)
@@ -265,6 +263,7 @@ int label_remove(struct device *dev)
if (!dev_close(dev))
stack;
+ dm_free(buf);
return r;
}
5 years, 9 months
master - lvmlockd: clear coverity complaint
by David Teigland
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=3f9ae846b89a2963a4c...
Commit: 3f9ae846b89a2963a4ca72cfa0281aab0bedcc02
Parent: 81be333e9fcf1f73b23318a9b3e9c366bf1a6cd2
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Mon Dec 18 15:19:17 2017 -0600
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Mon Dec 18 15:19:17 2017 -0600
lvmlockd: clear coverity complaint
from previous coverity fix, it's never happy.
---
lib/locking/lvmlockd.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/lib/locking/lvmlockd.c b/lib/locking/lvmlockd.c
index 0365797..a4684b4 100644
--- a/lib/locking/lvmlockd.c
+++ b/lib/locking/lvmlockd.c
@@ -2148,7 +2148,7 @@ int lockd_lv_name(struct cmd_context *cmd, struct volume_group *vg,
static int _lockd_lv_thin(struct cmd_context *cmd, struct logical_volume *lv,
const char *def_mode, uint32_t flags)
{
- struct logical_volume *pool_lv;
+ struct logical_volume *pool_lv = NULL;
if (lv_is_thin_volume(lv)) {
struct lv_segment *pool_seg = first_seg(lv);
5 years, 9 months
v2_02_177 annotated tag has been created
by Alasdair Kergon
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=6c8c8b1b244fc6a6a27...
Commit: 6c8c8b1b244fc6a6a27c4b3888844ad8a4750394
Parent: 0000000000000000000000000000000000000000
Author: Alasdair G Kergon <agk(a)redhat.com>
AuthorDate: 2017-12-18 20:36 +0000
Committer: Alasdair G Kergon <agk(a)redhat.com>
CommitterDate: 2017-12-18 20:36 +0000
annotated tag: v2_02_177 has been created
at 6c8c8b1b244fc6a6a27c4b3888844ad8a4750394 (tag)
tagging a1f7a483253b11e52ad5460b28cf0c75dba26659 (commit)
replaces v2_02_176
Release 2.02.177.
A wide-ranging bug fix and tidy-up release, covering in particular raid,
pvmove, activation and also switching to aligned 4k blocks when writing
out on-disk volume group metadata.
124 files changed, 3119 insertions(+), 2485 deletions(-)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.14 (GNU/Linux)
iEYEABECAAYFAlo4KDgACgkQIoGRwVZ+LBfTKwCgsJYQcXtiuHP5MWpJcCiZSDvZ
rVkAnRcOvGOnfkpwX7aFrKecuoxjqTyv
=KKDA
-----END PGP SIGNATURE-----
Alasdair G Kergon (31):
post-release
persistent filter: Skip import before rescan
log: Improve various device-related messages
metadata: Remove unused vg.cft_precommitted
metadata: Eliminate redundant nested VG metadata
log: Add io debug class
regenerate man and conf
lvmdiskscan: Remove unnecessary read.
device: log debug when I/O bounce buffer used
label: Remove unused verify functions.
device: categorise block i/o
device: Skip read-modify-write if replacing whole block.
device: Tag I/O for each mda on a device separately in log messages.
lvmetad: drop stray underscore
format_text: Use explicit alignment in wrapping calc.
format_text: Replace PRI with FMT.
format_text: Log additional circular buffer information.
format_text: Move metadata size checking into separate fn.
format_text: Use absolute alignment to calculate metadata usage
format_text: Adjust metadata alignment calculation.
device: Internal error if writing 0 bytes to dev.
metadata: Consistently skip metadata areas that failed.
device: Fix an unpaired device close.
format_text: Refactor and document metadata offset calculation.
format_text: More refactoring of metadata offset calcs
format_text: Change metadata alignment from 512 to 4096.
format_text: Round size written up to multiple of 4096.
format_text: Supply mempool directly to raw_read_mda_header.
format_text: Separate out code paths for buffer wraparound
format_text: Transfer circular buf alloc to device layer.
pre-release
David Teigland (11):
lvmlockd: retry on other sanlock errors
lvmlockd: override unknown lock manager error numbers
man: lvmlockd steps for changing lock type
lvconvert: prevent combining split snapshots in shared vg
lvmlockd: avoid blocking in sanlock_convert
lvmlockd: recognize normal errors from sanlock_convert
lvmlockd: improve error message for VG lock conflict
lvmlockd: fix log print
lvmlockd: use pool lock for tmeta access
lvmlock: return an error if lvb cannot be written
lvmlockd: clear coverity complaint
Eric Ren (1):
clvmd: supress ENOENT error on testing connection
Heinz Mauelshagen (17):
raid: reject conversion request to striped/raid0 on 2-legged raid4/5
raid: reject message for 2-legged raid4/5 -> striped
raid: correct raid6_n_6 -> raid5 convenience type
test: avoid have_raid overhead
test: additional avoid have_raid overhead
raid: add validation checks for reshape flags
raid: ignore --stripesize on raid4/5 conversion to 1 stripe
test: new reshape test under io load
test: disable new reshape test until target version 1.13.1
lv_manip: allow extension on --nosync raid lv
test: cleanup command
test: reduce pv sizes, fix comment and stripe size
test: add large tests skip option
test: allow to succeed in the cluster
deactivate_lvs: deactivate any missing RaidLV legs
test: new raid tests
test: fix trap adding proper teardown to previous, new raid tests
Marian Csontos (15):
test: Rename test nothing methods
test: D-Bus test_nesting requires filter
Update WHATS_NEW
tests: Fix common_dev_ argument handling
Update WHATS_NEW
Update WHATS_NEW
configure: applib is not required by dbusd
lvmdbusd: Fix path to python3
configure: Fix deprecation warning for lvmapp
test: lvmdbusd is used for process name
lvmdbusd: All tools use detected python3
test: Fix condition when detecting lvmdbusd
docs: Add TESTING file
lvmdbusd: Make lvmdbusd executable
lvm2app: Suppress deprecation warnings for our builds
Ondrej Kozina (2):
dmsetup: hide integrity encryption keys on table output
test: check dmsetup hides integrity encryption keys
Zdenek Kabelac (91):
snapshot: prevent repeated merging
coverity: avoid memleak
coverity: avoid overflow_before_widen
blkdeactive: use /sbin for mdamd
shellcheck: fsadm cleanup
cleanup: gcc const warning
cleanup: update messages in lvconvert
cleanup: drop unneeded headerfiles
coverity: add some initilizers
tests: snasphot merging
lvconvert: update delaying message
tests: have some space for 2nd mda
tests: detect racy systemd version
tests: allow to proceed futher with test
raid: protect raid4 activation
cleanup: constify lv parameter
cleanup: remove stack tracing for ok path
reload: do not take backup with suspended devices
lvremove: for unused cache deactive sublv
lv_lock_holder: unused cache-pool is not lock holder
tests: use nonflusing status
pvmove: snapshots need to go with origin device
pvmove: return pvmove itself
layers: collect only lock holding LVs
activate_lvs: deactivate on uniterate
activation: check subLV before skipping resume
activation: suspend pvmove using lv.
pvmove: always flush when working with pvmove tree
activate_lvs: use exclusive activation
cleanup: update log messages
pvmove: change locking on finish
pvmove: activation changes
pvmove: remove unusued code
tests: pvmove supports more cases
suspend: handle start of pvmove
resume: secure critical section
locking: pvmove is locking holding LV
libdm: preload propagates delayed resume
mirror: use lv_update_and_reload_origin
activation: automaticaly discover pvmove holders
pvmove: finish no longer needs explicit resumed
toollib: avoid printing default stripe size
cache: use conditional in warning message
cleanup: reduce couple debug lines
cleanup: using max args consistently
cleanup: update error messages
tests: typo
tests: more places where missing should not appear
activation: enhance holders detection
pvmove: enhance delayed_resume logic
toollib: improve stripes args reading
cmdline: avoid overrun on very large numbers.
cleanup: reuse existing macro
pvmove: move code from tools to lib
pvmove: add missing segment merging
activation: split priority from memory locking
activation: extend resume validation
activation: avoid rechecking pvmove node
suspend: optimize generated list
cleanup: simplify _deps code
cleanup: remove debug code
libdm: watch for failing _info_by_dev
libdm: support for replicator target is dropped
cleanup: drop unused header
cleanup: futher code reduction
cleanup: simplier error message
cleanup: drop impossible test case
cleanup: mark success at the end
cleanup: stack tracing
cleanup: use _node_name
clenaup: use log_warn
cleanup: use log_warn
cleanup: use existing define with prefix
cleanup: drop unused define
cleanup: messsage cleanup
cleanup: drop unneeded check
activation: also lock memory for clustered locking
thin: always clear memory before parsing status
thin: missing type is error
libdm: add help func _get_last_load_segment
libdm: avoid checking status on activation
libdm: use delay_resume_if_extended
libdm: drop extra structure copy
cleanup: reorder calling of pool checking tools
cleanup: use log_warn
debug: update debug msg
vgchange: drop extra counting
activation: keep priority till memlock_unlock
thin: regression fix for metadata checking
cleanup: switch to standard query
cleanup: debug message
5 years, 9 months
v2.02.174 annotated tag has been created
by Alasdair Kergon
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=761691e233fabddfbf6...
Commit: 761691e233fabddfbf678b3a988fce99d39591f4
Parent: 0000000000000000000000000000000000000000
Author: Alasdair G Kergon <agk(a)redhat.com>
AuthorDate: 2017-09-13 19:38 +0000
Committer: Alasdair G Kergon <agk(a)redhat.com>
CommitterDate: 2017-09-13 19:38 +0000
annotated tag: v2.02.174 has been created
at 761691e233fabddfbf678b3a988fce99d39591f4 (tag)
tagging 918f0a92daef84867e0df4b422c3de2a36997f17 (commit)
replaces v2_02_173
Release 2.02.174
Assorted fixes and small improvements, including an extension to
dmsetup for activating more than one device with a single command.
As of this release, we're also pushing the code to github:
https://github.com/lvmteam/lvm2
and will handle any issues reported at
https://github.com/lvmteam/lvm2/issues
81 files changed, 1782 insertions(+), 857 deletions(-)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.14 (GNU/Linux)
iEYEABECAAYFAlm5iu8ACgkQIoGRwVZ+LBdCwgCfWI67MvWO3jaZ0/xvgwl5qjU1
KBwAoM8aCqMfl6N6X8jDEhR8FGDoKJ62
=oAdS
-----END PGP SIGNATURE-----
Alasdair G Kergon (14):
post-release
dmsetup: Add concise table output format.
make generate
dmsetup: Add minor number to concise table output format.
tools: Introduce exit code EINIT_FAILED.
toolcontext: Improve invalid units error message.
ioctl: Allow minor without major.
dmsetup: Add --concise to dmsetup create.
lvmconfig: Add options to produce file preamble
pvcreate: Disallow --bootloaderareasize with --restorefile.
pvcreate: Wipe cached bootloaderarea when wiping label.
pvcreate: Use maximum metadata area size with --restorefile
README: Include new github links
pre-release
David Teigland (16):
vgchange: separate change locktype and allow recovery
vgchange: split out code for lockstart and lockstop
vgchange: split out code for systemid
man: remove hyphen escapes from source
commands: expand comment on configuring option vals
lvmlockd: fix lm running check during adoption
lvmlockd: global name doesn't apply to sanlock
commands: recognize -? for help
commands: recognize lvm command -?
lvmlockd: zero extended lvmlock LV
lvmlockd: add comment about temp ls name
lvmlockd: fix mutex unlock
man lvmthin: change fsck references
lvmlockd: print error about starting lock manager
lvmlockd: fix check for no running lock manager
lvmlockd: always disallow mirror splitting
Heinz Mauelshagen (1):
raid: more validation checks for segment data_offset member
Peter Rajnoha (2):
pvcreate: fix check for 2nd mda at end of disk fits if using pvcreate --restorefile
test: pvcreate-bootloaderarea: pvcreate --restorefile --bootloaderarea not supported anymore
Zdenek Kabelac (31):
raid: reshape synchronization point
tidy: declaration names match implementation
thin: warn about too big chunks size
man: fix generated paths
libdm: log_warn
makefiles: RT_LIB
makefiles: use gcc warns with gcc only
makefiles: fixing linking
makefiles: cleanups
tests: update makefile
configure: improve test for realtime clock
configure: tune BUILD_DMEVENTD
makefiles: fix tested vars
makefiles: script executable missed dynamic
makefiles: add DEFS_$@ for cxx
tests: update makefiles
tests: update checked message
libdm: fix errpath for control node creation
lvmlockd: shorter code
lvmcache: check for lvmcache_foreach_mda return code
debug: add stack trace point
locking: avoid descriptor leak for nonblocking mode
daemonize: more unified code
lvmlockd: avoid double unlock of client_mutex
lvmlockctl: fix check for failing close
lvmlockd: log pthread_join errno code
reporting: validate time parsing with strtol
dmsetup: add missing -- for option
dmsetup: validate strtol reading
cleanup: easier to read code
deamonize: restore detection of errors
Zhang Huan (1):
lvmlockd: reduce io impact for finding sanlock lv free lock offset
5 years, 9 months
master - post-release
by Alasdair Kergon
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=81be333e9fcf1f73b23...
Commit: 81be333e9fcf1f73b23318a9b3e9c366bf1a6cd2
Parent: a1f7a483253b11e52ad5460b28cf0c75dba26659
Author: Alasdair G Kergon <agk(a)redhat.com>
AuthorDate: Mon Dec 18 20:43:09 2017 +0000
Committer: Alasdair G Kergon <agk(a)redhat.com>
CommitterDate: Mon Dec 18 20:43:09 2017 +0000
post-release
---
VERSION | 2 +-
VERSION_DM | 2 +-
WHATS_NEW | 3 +++
WHATS_NEW_DM | 3 +++
4 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/VERSION b/VERSION
index 414b4df..586bf0f 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-2.02.177(2)-git (2017-12-18)
+2.02.178(2)-git (2017-12-18)
diff --git a/VERSION_DM b/VERSION_DM
index 4c2ffa3..d55b61b 100644
--- a/VERSION_DM
+++ b/VERSION_DM
@@ -1 +1 @@
-1.02.146-git (2017-12-18)
+1.02.147-git (2017-12-18)
diff --git a/WHATS_NEW b/WHATS_NEW
index 2163a5e..e4b04b0 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,3 +1,6 @@
+Version 2.02.178 -
+=====================================
+
Version 2.02.177 - 18th December 2017
=====================================
When writing text metadata content, use complete 4096 byte blocks.
diff --git a/WHATS_NEW_DM b/WHATS_NEW_DM
index 8b304e6..bcd6deb 100644
--- a/WHATS_NEW_DM
+++ b/WHATS_NEW_DM
@@ -1,3 +1,6 @@
+Version 1.02.147 -
+=====================================
+
Version 1.02.146 - 18th December 2017
=====================================
Activation tree of thin pool skips duplicated check of pool status.
5 years, 9 months
master - pre-release
by Alasdair Kergon
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=a1f7a483253b11e52ad...
Commit: a1f7a483253b11e52ad5460b28cf0c75dba26659
Parent: 5f45cb90a7d6ca8ea3d0456c42d2fc4721cf5d79
Author: Alasdair G Kergon <agk(a)redhat.com>
AuthorDate: Mon Dec 18 20:36:10 2017 +0000
Committer: Alasdair G Kergon <agk(a)redhat.com>
CommitterDate: Mon Dec 18 20:36:10 2017 +0000
pre-release
---
VERSION | 2 +-
VERSION_DM | 2 +-
WHATS_NEW | 4 ++--
WHATS_NEW_DM | 4 ++--
4 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/VERSION b/VERSION
index 282f6f9..414b4df 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-2.02.177(2)-git (2017-11-03)
+2.02.177(2)-git (2017-12-18)
diff --git a/VERSION_DM b/VERSION_DM
index 7aab7d6..4c2ffa3 100644
--- a/VERSION_DM
+++ b/VERSION_DM
@@ -1 +1 @@
-1.02.146-git (2017-11-03)
+1.02.146-git (2017-12-18)
diff --git a/WHATS_NEW b/WHATS_NEW
index 5fc4cd3..2163a5e 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,5 @@
-Version 2.02.177 -
-====================================
+Version 2.02.177 - 18th December 2017
+=====================================
When writing text metadata content, use complete 4096 byte blocks.
Change text format metadata alignment from 512 to 4096 bytes.
When writing metadata, consistently skip mdas marked as failed.
diff --git a/WHATS_NEW_DM b/WHATS_NEW_DM
index d9503c2..8b304e6 100644
--- a/WHATS_NEW_DM
+++ b/WHATS_NEW_DM
@@ -1,5 +1,5 @@
-Version 1.02.146 -
-====================================
+Version 1.02.146 - 18th December 2017
+=====================================
Activation tree of thin pool skips duplicated check of pool status.
Remove code supporting replicator target.
Do not ignore failure of _info_by_dev().
5 years, 9 months
master - format_text: Transfer circular buf alloc to device layer.
by Alasdair Kergon
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=5f45cb90a7d6ca8ea3d...
Commit: 5f45cb90a7d6ca8ea3d0456c42d2fc4721cf5d79
Parent: beee9940a503dd6165afd73835d3a6935afcce60
Author: Alasdair G Kergon <agk(a)redhat.com>
AuthorDate: Fri Dec 15 22:34:26 2017 +0000
Committer: Alasdair G Kergon <agk(a)redhat.com>
CommitterDate: Fri Dec 15 22:34:26 2017 +0000
format_text: Transfer circular buf alloc to device layer.
Instead of the caller passing dev_read_circular() a buffer to fill with
data, the device layer itself now allocates it.
---
lib/config/config.c | 15 ++++-----------
lib/device/dev-io.c | 27 +++++++++++++++++----------
lib/device/device.h | 4 ++--
lib/format_text/format-text.c | 12 +++++++-----
4 files changed, 30 insertions(+), 28 deletions(-)
diff --git a/lib/config/config.c b/lib/config/config.c
index f634e5b..fac7e4c 100644
--- a/lib/config/config.c
+++ b/lib/config/config.c
@@ -530,22 +530,15 @@ int config_file_read_fd(struct dm_config_tree *cft, struct device *dev, dev_io_r
fb = fb + mmap_offset;
} else {
if (circular) {
- if (!(buf = dm_malloc(size + size2))) {
- log_error("Failed to allocate circular buffer.");
- return 0;
- }
- if (!dev_read_circular(dev, (uint64_t) offset, size,
- (uint64_t) offset2, size2, reason, buf)) {
- goto out;
- }
+ if (!(buf = dev_read_circular(dev, (uint64_t) offset, size, (uint64_t) offset2, size2, reason)))
+ goto_out;
} else {
if (!(buf = dm_malloc(size))) {
log_error("Failed to allocate buffer for metadata read.");
return 0;
}
- if (!dev_read(dev, (uint64_t) offset, size, reason, buf)) {
- goto out;
- }
+ if (!dev_read(dev, (uint64_t) offset, size, reason, buf))
+ goto_out;
}
fb = buf;
}
diff --git a/lib/device/dev-io.c b/lib/device/dev-io.c
index 1adf2ad..0545d8c 100644
--- a/lib/device/dev-io.c
+++ b/lib/device/dev-io.c
@@ -745,25 +745,32 @@ int dev_read(struct device *dev, uint64_t offset, size_t len, dev_io_reason_t re
}
/*
- * Read from 'dev' into 'buf' in 2 distinct regions, denoted
- * by (offset,len) and (offset2,len2). Thus, the total size of
- * 'buf' should be len+len2.
+ * Read from 'dev' in 2 distinct regions, denoted by (offset,len) and (offset2,len2).
+ * Caller is responsible for dm_free().
*/
-int dev_read_circular(struct device *dev, uint64_t offset, size_t len,
- uint64_t offset2, size_t len2, dev_io_reason_t reason, char *buf)
+char *dev_read_circular(struct device *dev, uint64_t offset, size_t len,
+ uint64_t offset2, size_t len2, dev_io_reason_t reason)
{
+ char *buf = NULL;
+
+ if (!(buf = dm_malloc(len + len2))) {
+ log_error("Buffer allocation failed for split metadata.");
+ return NULL;
+ }
+
if (!dev_read(dev, offset, len, reason, buf)) {
log_error("Read from %s failed", dev_name(dev));
- return 0;
+ dm_free(buf);
+ return NULL;
}
if (!dev_read(dev, offset2, len2, reason, buf + len)) {
- log_error("Circular read from %s failed",
- dev_name(dev));
- return 0;
+ log_error("Circular read from %s failed", dev_name(dev));
+ dm_free(buf);
+ return NULL;
}
- return 1;
+ return buf;
}
/* FIXME If O_DIRECT can't extend file, dev_extend first; dev_truncate after.
diff --git a/lib/device/device.h b/lib/device/device.h
index 503373f..a369195 100644
--- a/lib/device/device.h
+++ b/lib/device/device.h
@@ -146,8 +146,8 @@ int dev_fd(struct device *dev);
const char *dev_name(const struct device *dev);
int dev_read(struct device *dev, uint64_t offset, size_t len, dev_io_reason_t reason, void *buffer);
-int dev_read_circular(struct device *dev, uint64_t offset, size_t len,
- uint64_t offset2, size_t len2, dev_io_reason_t reason, char *buf);
+char *dev_read_circular(struct device *dev, uint64_t offset, size_t len,
+ uint64_t offset2, size_t len2, dev_io_reason_t reason);
int dev_write(struct device *dev, uint64_t offset, size_t len, dev_io_reason_t reason, void *buffer);
int dev_append(struct device *dev, size_t len, dev_io_reason_t reason, char *buffer);
int dev_set(struct device *dev, uint64_t offset, size_t len, dev_io_reason_t reason, int value);
diff --git a/lib/format_text/format-text.c b/lib/format_text/format-text.c
index ebc2dbb..79bb9fa 100644
--- a/lib/format_text/format-text.c
+++ b/lib/format_text/format-text.c
@@ -234,16 +234,18 @@ static int _pv_analyze_mda_raw (const struct format_type * fmt,
* "dm_config_maybe_section" returning true when there's no valid
* metadata in a sector (sectors with all nulls).
*/
- if (!(buf = dm_malloc(size + size2)))
- goto_out;
circular = size2 ? 1 : 0;
if (circular) {
- if (!dev_read_circular(area->dev, offset, size, offset2, size2, MDA_CONTENT_REASON(mda_is_primary(mda)), buf))
+ if (!(buf = dev_read_circular(area->dev, offset, size, offset2, size2, MDA_CONTENT_REASON(mda_is_primary(mda)))))
goto_out;
- } else if (!dev_read(area->dev, offset, size, MDA_CONTENT_REASON(mda_is_primary(mda)), buf))
- goto_out;
+ } else {
+ if (!(buf = dm_malloc(size)))
+ goto_out;
+ if (!dev_read(area->dev, offset, size, MDA_CONTENT_REASON(mda_is_primary(mda)), buf))
+ goto_out;
+ }
/*
* FIXME: We could add more sophisticated metadata detection
5 years, 9 months
master - format_text: Separate out code paths for buffer wraparound
by Alasdair Kergon
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=beee9940a503dd6165a...
Commit: beee9940a503dd6165afd73835d3a6935afcce60
Parent: 145ded10c29a2e76ea12aab98a797e79135d6d44
Author: Alasdair G Kergon <agk(a)redhat.com>
AuthorDate: Fri Dec 15 21:12:19 2017 +0000
Committer: Alasdair G Kergon <agk(a)redhat.com>
CommitterDate: Fri Dec 15 21:12:19 2017 +0000
format_text: Separate out code paths for buffer wraparound
The creation of wrapped around metadata - where the start of metadata is
written up to the end of the buffer and the remainder follows back at
the start of the buffer - is now restricted to cases where writing the
metadata in one piece wouldn't fit. This shouldn't happen in 'normal'
usage so let's begin treating the code for this as a special case that
can be ignored when optimising 'normal' cases.
---
lib/config/config.c | 27 +++++++++++++++++++--------
lib/device/dev-io.c | 9 +--------
lib/format_text/format-text.c | 10 ++++++++--
3 files changed, 28 insertions(+), 18 deletions(-)
diff --git a/lib/config/config.c b/lib/config/config.c
index 8fca372..f634e5b 100644
--- a/lib/config/config.c
+++ b/lib/config/config.c
@@ -504,6 +504,7 @@ int config_file_read_fd(struct dm_config_tree *cft, struct device *dev, dev_io_r
int use_mmap = 1;
off_t mmap_offset = 0;
char *buf = NULL;
+ unsigned circular = size2 ? 1 : 0; /* Wrapped around end of disk metadata buffer? */
struct config_source *cs = dm_config_get_custom(cft);
if (!_is_file_based_config_source(cs->type)) {
@@ -514,7 +515,7 @@ int config_file_read_fd(struct dm_config_tree *cft, struct device *dev, dev_io_r
}
/* Only use mmap with regular files */
- if (!(dev->flags & DEV_REGULAR) || size2)
+ if (!(dev->flags & DEV_REGULAR) || circular)
use_mmap = 0;
if (use_mmap) {
@@ -528,13 +529,23 @@ int config_file_read_fd(struct dm_config_tree *cft, struct device *dev, dev_io_r
}
fb = fb + mmap_offset;
} else {
- if (!(buf = dm_malloc(size + size2))) {
- log_error("Failed to allocate circular buffer.");
- return 0;
- }
- if (!dev_read_circular(dev, (uint64_t) offset, size,
- (uint64_t) offset2, size2, reason, buf)) {
- goto out;
+ if (circular) {
+ if (!(buf = dm_malloc(size + size2))) {
+ log_error("Failed to allocate circular buffer.");
+ return 0;
+ }
+ if (!dev_read_circular(dev, (uint64_t) offset, size,
+ (uint64_t) offset2, size2, reason, buf)) {
+ goto out;
+ }
+ } else {
+ if (!(buf = dm_malloc(size))) {
+ log_error("Failed to allocate buffer for metadata read.");
+ return 0;
+ }
+ if (!dev_read(dev, (uint64_t) offset, size, reason, buf)) {
+ goto out;
+ }
}
fb = buf;
}
diff --git a/lib/device/dev-io.c b/lib/device/dev-io.c
index c321e61..1adf2ad 100644
--- a/lib/device/dev-io.c
+++ b/lib/device/dev-io.c
@@ -745,7 +745,7 @@ int dev_read(struct device *dev, uint64_t offset, size_t len, dev_io_reason_t re
}
/*
- * Read from 'dev' into 'buf', possibly in 2 distinct regions, denoted
+ * Read from 'dev' into 'buf' in 2 distinct regions, denoted
* by (offset,len) and (offset2,len2). Thus, the total size of
* 'buf' should be len+len2.
*/
@@ -757,13 +757,6 @@ int dev_read_circular(struct device *dev, uint64_t offset, size_t len,
return 0;
}
- /*
- * The second region is optional, and allows for
- * a circular buffer on the device.
- */
- if (!len2)
- return 1;
-
if (!dev_read(dev, offset2, len2, reason, buf + len)) {
log_error("Circular read from %s failed",
dev_name(dev));
diff --git a/lib/format_text/format-text.c b/lib/format_text/format-text.c
index ab610ad..ebc2dbb 100644
--- a/lib/format_text/format-text.c
+++ b/lib/format_text/format-text.c
@@ -185,6 +185,7 @@ static int _pv_analyze_mda_raw (const struct format_type * fmt,
char *buf=NULL;
struct device_area *area;
struct mda_context *mdac;
+ unsigned circular = 0;
int r=0;
mdac = (struct mda_context *) mda->metadata_locn;
@@ -236,7 +237,12 @@ static int _pv_analyze_mda_raw (const struct format_type * fmt,
if (!(buf = dm_malloc(size + size2)))
goto_out;
- if (!dev_read_circular(area->dev, offset, size, offset2, size2, MDA_CONTENT_REASON(mda_is_primary(mda)), buf))
+ circular = size2 ? 1 : 0;
+
+ if (circular) {
+ if (!dev_read_circular(area->dev, offset, size, offset2, size2, MDA_CONTENT_REASON(mda_is_primary(mda)), buf))
+ goto_out;
+ } else if (!dev_read(area->dev, offset, size, MDA_CONTENT_REASON(mda_is_primary(mda)), buf))
goto_out;
/*
@@ -708,7 +714,7 @@ static int _vg_write_raw(struct format_instance *fid, struct volume_group *vg,
int found = 0;
int noprecommit = 0;
const char *old_vg_name = NULL;
- uint64_t new_size_rounded;
+ uint64_t new_size_rounded = 0;
/* Ignore any mda on a PV outside the VG. vgsplit relies on this */
dm_list_iterate_items(pvl, &vg->pvs) {
5 years, 9 months