master - config: Split config buffer processing into new fn.
by Alasdair Kergon
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=22b6c482ecb4673c30a...
Commit: 22b6c482ecb4673c30aa1e9ae1946f9fc5497510
Parent: 96801ac0859798c4e478d05e91aaa68b4ce10c91
Author: Alasdair G Kergon <agk(a)redhat.com>
AuthorDate: Tue Jan 2 20:40:18 2018 +0000
Committer: Alasdair G Kergon <agk(a)redhat.com>
CommitterDate: Tue Jan 2 21:10:46 2018 +0000
config: Split config buffer processing into new fn.
Wrap its parameters into struct process_config_file_params allocated
from a mempool now passed into the config_file_read* fns.
---
lib/cache/lvmcache.c | 2 +-
lib/commands/toolcontext.c | 4 +-
lib/config/config.c | 90 ++++++++++++++++++++++++++++----------
lib/config/config.h | 4 +-
lib/device/dev-cache.h | 8 ++--
lib/filters/filter-composite.c | 4 +-
lib/filters/filter-persistent.c | 8 ++--
lib/filters/filter.h | 2 +-
lib/format_text/import.c | 9 ++--
9 files changed, 87 insertions(+), 44 deletions(-)
diff --git a/lib/cache/lvmcache.c b/lib/cache/lvmcache.c
index 5d4732c..25bf7ee 100644
--- a/lib/cache/lvmcache.c
+++ b/lib/cache/lvmcache.c
@@ -1204,7 +1204,7 @@ int lvmcache_label_scan(struct cmd_context *cmd)
*/
if (_force_label_scan && cmd->is_long_lived &&
cmd->dump_filter && cmd->full_filter && cmd->full_filter->dump &&
- !cmd->full_filter->dump(cmd->full_filter, 0))
+ !cmd->full_filter->dump(cmd->full_filter, cmd->mem, 0))
stack;
r = 1;
diff --git a/lib/commands/toolcontext.c b/lib/commands/toolcontext.c
index 1d21443..eda412e 100644
--- a/lib/commands/toolcontext.c
+++ b/lib/commands/toolcontext.c
@@ -1287,7 +1287,7 @@ int init_filters(struct cmd_context *cmd, unsigned load_persistent_cache)
lvm_stat_ctim(&ts, &st);
cts = config_file_timestamp(cmd->cft);
if (timespeccmp(&ts, &cts, >) &&
- !persistent_filter_load(cmd->filter, NULL))
+ !persistent_filter_load(cmd->mem, cmd->filter, NULL))
log_verbose("Failed to load existing device cache from %s",
dev_cache);
}
@@ -2225,7 +2225,7 @@ void destroy_toolcontext(struct cmd_context *cmd)
int flags;
if (cmd->dump_filter && cmd->filter && cmd->filter->dump &&
- !cmd->filter->dump(cmd->filter, 1))
+ !cmd->filter->dump(cmd->filter, cmd->mem, 1))
stack;
archive_exit(cmd);
diff --git a/lib/config/config.c b/lib/config/config.c
index bbbcc3d..bb1d80e 100644
--- a/lib/config/config.c
+++ b/lib/config/config.c
@@ -279,7 +279,7 @@ struct dm_config_tree *config_file_open_and_read(const char *config_file,
}
log_very_verbose("Loading config file: %s", config_file);
- if (!config_file_read(cft)) {
+ if (!config_file_read(cmd->mem, cft)) {
log_error("Failed to load config file %s", config_file);
goto bad;
}
@@ -489,23 +489,67 @@ int override_config_tree_from_profile(struct cmd_context *cmd,
return 0;
}
+struct process_config_file_params {
+ struct dm_config_tree *cft;
+ struct device *dev;
+ off_t offset;
+ size_t size;
+ off_t offset2;
+ size_t size2;
+ checksum_fn_t checksum_fn;
+ uint32_t checksum;
+ int checksum_only;
+ int no_dup_node_check;
+};
+
+static int _process_config_file_buffer(struct process_config_file_params *pcfp, char *buffer)
+{
+ char *fb, *fe;
+ int r = 0;
+
+ fb = buffer;
+
+ if (pcfp->checksum_fn && pcfp->checksum !=
+ (pcfp->checksum_fn(pcfp->checksum_fn(INITIAL_CRC, (const uint8_t *)fb, pcfp->size),
+ (const uint8_t *)(fb + pcfp->size), pcfp->size2))) {
+ log_error("%s: Checksum error at offset %" PRIu64, dev_name(pcfp->dev), (uint64_t) pcfp->offset);
+ goto out;
+ }
+
+ if (!pcfp->checksum_only) {
+ fe = fb + pcfp->size + pcfp->size2;
+ if (pcfp->no_dup_node_check) {
+ if (!dm_config_parse_without_dup_node_check(pcfp->cft, fb, fe))
+ goto_out;
+ } else {
+ if (!dm_config_parse(pcfp->cft, fb, fe))
+ goto_out;
+ }
+ }
+
+ r = 1;
+out:
+ return r;
+}
+
/*
* When checksum_only is set, the checksum of buffer is only matched
* and function avoids parsing of mda into config tree which
* remains unmodified and should not be used.
*/
-int config_file_read_fd(struct dm_config_tree *cft, struct device *dev, dev_io_reason_t reason,
+int config_file_read_fd(struct dm_pool *mem, struct dm_config_tree *cft, struct device *dev, dev_io_reason_t reason,
off_t offset, size_t size, off_t offset2, size_t size2,
checksum_fn_t checksum_fn, uint32_t checksum,
int checksum_only, int no_dup_node_check)
{
- char *fb, *fe;
+ char *fb;
int r = 0;
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);
+ struct process_config_file_params *pcfp;
if (!_is_file_based_config_source(cs->type)) {
log_error(INTERNAL_ERROR "config_file_read_fd: expected file, special file "
@@ -514,6 +558,22 @@ int config_file_read_fd(struct dm_config_tree *cft, struct device *dev, dev_io_r
return 0;
}
+ if (!(pcfp = dm_pool_zalloc(mem, sizeof(*pcfp)))) {
+ log_debug("config_file_read_fd: process_config_file_params struct allocation failed");
+ return 0;
+ }
+
+ pcfp->cft = cft;
+ pcfp->dev = dev;
+ pcfp->offset = offset;
+ pcfp->size = size;
+ pcfp->offset2 = offset2;
+ pcfp->size2 = size2;
+ pcfp->checksum_fn = checksum_fn;
+ pcfp->checksum = checksum;
+ pcfp->checksum_only = checksum_only;
+ pcfp->no_dup_node_check = no_dup_node_check;
+
/* Only use mmap with regular files */
if (!(dev->flags & DEV_REGULAR) || circular)
use_mmap = 0;
@@ -539,25 +599,7 @@ int config_file_read_fd(struct dm_config_tree *cft, struct device *dev, dev_io_r
fb = buf;
}
- if (checksum_fn && checksum !=
- (checksum_fn(checksum_fn(INITIAL_CRC, (const uint8_t *)fb, size),
- (const uint8_t *)(fb + size), size2))) {
- log_error("%s: Checksum error at offset %" PRIu64, dev_name(dev), (uint64_t) offset);
- goto out;
- }
-
- if (!checksum_only) {
- fe = fb + size + size2;
- if (no_dup_node_check) {
- if (!dm_config_parse_without_dup_node_check(cft, fb, fe))
- goto_out;
- } else {
- if (!dm_config_parse(cft, fb, fe))
- goto_out;
- }
- }
-
- r = 1;
+ r = _process_config_file_buffer(pcfp, fb);
out:
if (!use_mmap)
@@ -573,7 +615,7 @@ int config_file_read_fd(struct dm_config_tree *cft, struct device *dev, dev_io_r
return r;
}
-int config_file_read(struct dm_config_tree *cft)
+int config_file_read(struct dm_pool *mem, struct dm_config_tree *cft)
{
const char *filename = NULL;
struct config_source *cs = dm_config_get_custom(cft);
@@ -601,7 +643,7 @@ int config_file_read(struct dm_config_tree *cft)
}
}
- r = config_file_read_fd(cft, cf->dev, DEV_IO_MDA_CONTENT, 0, (size_t) info.st_size, 0, 0,
+ r = config_file_read_fd(mem, cft, cf->dev, DEV_IO_MDA_CONTENT, 0, (size_t) info.st_size, 0, 0,
(checksum_fn_t) NULL, 0, 0, 0);
if (!cf->keep_open) {
diff --git a/lib/config/config.h b/lib/config/config.h
index d01306b..5c8844a 100644
--- a/lib/config/config.h
+++ b/lib/config/config.h
@@ -239,11 +239,11 @@ config_source_t config_get_source_type(struct dm_config_tree *cft);
typedef uint32_t (*checksum_fn_t) (uint32_t initial, const uint8_t *buf, uint32_t size);
struct dm_config_tree *config_open(config_source_t source, const char *filename, int keep_open);
-int config_file_read_fd(struct dm_config_tree *cft, struct device *dev, dev_io_reason_t reason,
+int config_file_read_fd(struct dm_pool *mem, struct dm_config_tree *cft, struct device *dev, dev_io_reason_t reason,
off_t offset, size_t size, off_t offset2, size_t size2,
checksum_fn_t checksum_fn, uint32_t checksum,
int skip_parse, int no_dup_node_check);
-int config_file_read(struct dm_config_tree *cft);
+int config_file_read(struct dm_pool *mem, struct dm_config_tree *cft);
struct dm_config_tree *config_file_open_and_read(const char *config_file, config_source_t source,
struct cmd_context *cmd);
int config_write(struct dm_config_tree *cft, struct config_def_tree_spec *tree_spec,
diff --git a/lib/device/dev-cache.h b/lib/device/dev-cache.h
index 546b1fe..0143dfa 100644
--- a/lib/device/dev-cache.h
+++ b/lib/device/dev-cache.h
@@ -23,10 +23,10 @@
* predicate for devices.
*/
struct dev_filter {
- int (*passes_filter) (struct dev_filter * f, struct device * dev);
- void (*destroy) (struct dev_filter * f);
- void (*wipe) (struct dev_filter * f);
- int (*dump) (struct dev_filter * f, int merge_existing);
+ int (*passes_filter) (struct dev_filter *f, struct device * dev);
+ void (*destroy) (struct dev_filter *f);
+ void (*wipe) (struct dev_filter *f);
+ int (*dump) (struct dev_filter *f, struct dm_pool *mem, int merge_existing);
void *private;
unsigned use_count;
};
diff --git a/lib/filters/filter-composite.c b/lib/filters/filter-composite.c
index c635896..83a0f02 100644
--- a/lib/filters/filter-composite.c
+++ b/lib/filters/filter-composite.c
@@ -52,13 +52,13 @@ static void _composite_destroy(struct dev_filter *f)
dm_free(f);
}
-static int _dump(struct dev_filter *f, int merge_existing)
+static int _dump(struct dev_filter *f, struct dm_pool *mem, int merge_existing)
{
struct dev_filter **filters;
for (filters = (struct dev_filter **) f->private; *filters; ++filters)
if ((*filters)->dump &&
- !(*filters)->dump(*filters, merge_existing))
+ !(*filters)->dump(*filters, mem, merge_existing))
return_0;
return 1;
diff --git a/lib/filters/filter-persistent.c b/lib/filters/filter-persistent.c
index 5bc0861..7542e02 100644
--- a/lib/filters/filter-persistent.c
+++ b/lib/filters/filter-persistent.c
@@ -87,7 +87,7 @@ static int _read_array(struct pfilter *pf, struct dm_config_tree *cft,
return 1;
}
-int persistent_filter_load(struct dev_filter *f, struct dm_config_tree **cft_out)
+int persistent_filter_load(struct dm_pool *mem, struct dev_filter *f, struct dm_config_tree **cft_out)
{
struct pfilter *pf = (struct pfilter *) f->private;
struct dm_config_tree *cft;
@@ -116,7 +116,7 @@ int persistent_filter_load(struct dev_filter *f, struct dm_config_tree **cft_out
if (!(cft = config_open(CONFIG_FILE_SPECIAL, pf->file, 1)))
return_0;
- if (!config_file_read(cft))
+ if (!config_file_read(mem, cft))
goto_out;
log_debug_devs("Loading persistent filter cache from %s", pf->file);
@@ -175,7 +175,7 @@ static void _write_array(struct pfilter *pf, FILE *fp, const char *path,
fprintf(fp, "\n\t]\n");
}
-static int _persistent_filter_dump(struct dev_filter *f, int merge_existing)
+static int _persistent_filter_dump(struct dev_filter *f, struct dm_pool *mem, int merge_existing)
{
struct pfilter *pf;
char *tmp_file;
@@ -234,7 +234,7 @@ static int _persistent_filter_dump(struct dev_filter *f, int merge_existing)
lvm_stat_ctim(&ts, &info);
if (merge_existing && timespeccmp(&ts, &pf->ctime, !=))
/* Keep cft open to avoid losing lock */
- persistent_filter_load(f, &cft);
+ persistent_filter_load(mem, f, &cft);
tmp_file = alloca(strlen(pf->file) + 5);
sprintf(tmp_file, "%s.tmp", pf->file);
diff --git a/lib/filters/filter.h b/lib/filters/filter.h
index d75f6e1..5dbf0b4 100644
--- a/lib/filters/filter.h
+++ b/lib/filters/filter.h
@@ -53,6 +53,6 @@ typedef enum {
} filter_mode_t;
struct dev_filter *usable_filter_create(struct dev_types *dt, filter_mode_t mode);
-int persistent_filter_load(struct dev_filter *f, struct dm_config_tree **cft_out);
+int persistent_filter_load(struct dm_pool *mem, struct dev_filter *f, struct dm_config_tree **cft_out);
#endif /* _LVM_FILTER_H */
diff --git a/lib/format_text/import.c b/lib/format_text/import.c
index da4cefd..039722a 100644
--- a/lib/format_text/import.c
+++ b/lib/format_text/import.c
@@ -16,6 +16,7 @@
#include "lib.h"
#include "metadata.h"
#include "import-export.h"
+#include "toolcontext.h"
/* FIXME Use tidier inclusion method */
static struct text_vg_version_ops *(_text_vsn_list[2]);
@@ -52,8 +53,8 @@ int text_vgsummary_import(const struct format_type *fmt,
if (!(cft = config_open(CONFIG_FILE_SPECIAL, NULL, 0)))
return_0;
- if ((!dev && !config_file_read(cft)) ||
- (dev && !config_file_read_fd(cft, dev, reason, offset, size,
+ if ((!dev && !config_file_read(fmt->cmd->mem, cft)) ||
+ (dev && !config_file_read_fd(fmt->cmd->mem, cft, dev, reason, offset, size,
offset2, size2, checksum_fn,
vgsummary->mda_checksum,
checksum_only, 1))) {
@@ -127,8 +128,8 @@ struct volume_group *text_vg_import_fd(struct format_instance *fid,
((*vg_fmtdata)->cached_mda_checksum == checksum) &&
((*vg_fmtdata)->cached_mda_size == (size + size2));
- if ((!dev && !config_file_read(cft)) ||
- (dev && !config_file_read_fd(cft, dev, MDA_CONTENT_REASON(primary_mda), offset, size,
+ if ((!dev && !config_file_read(fid->mem, cft)) ||
+ (dev && !config_file_read_fd(fid->mem, cft, dev, MDA_CONTENT_REASON(primary_mda), offset, size,
offset2, size2, checksum_fn, checksum,
skip_parse, 1)))
goto_out;
6 years, 3 months
master - man lvmlockd: update wording
by David Teigland
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=96801ac0859798c4e47...
Commit: 96801ac0859798c4e478d05e91aaa68b4ce10c91
Parent: 3db51e3f0e90e45e6c3734000fa5a5246a1e6c96
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Tue Jan 2 13:10:34 2018 -0600
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Tue Jan 2 13:35:58 2018 -0600
man lvmlockd: update wording
---
man/lvmlockd.8_main | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/man/lvmlockd.8_main b/man/lvmlockd.8_main
index fbcdc87..bb45871 100644
--- a/man/lvmlockd.8_main
+++ b/man/lvmlockd.8_main
@@ -15,7 +15,7 @@ coordinate reading and writing of LVM metadata
validate caching of LVM metadata
.br
\[bu]
-prevent concurrent activation of logical volumes
+prevent conflicting activation of logical volumes
.br
lvmlockd uses an external lock manager to perform basic locking.
6 years, 3 months
master - label: Wrap _find_labeller params into a struct.
by Alasdair Kergon
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=3db51e3f0e90e45e6c3...
Commit: 3db51e3f0e90e45e6c3734000fa5a5246a1e6c96
Parent: 9b830791eabe24b69e82ab480498c617c4d8fc71
Author: Alasdair G Kergon <agk(a)redhat.com>
AuthorDate: Tue Jan 2 16:01:10 2018 +0000
Committer: Alasdair G Kergon <agk(a)redhat.com>
CommitterDate: Tue Jan 2 17:15:32 2018 +0000
label: Wrap _find_labeller params into a struct.
Move the actual buffer reading up to _label_read() so _find_labeller()
just examines the buffer supplied.
---
lib/label/label.c | 62 +++++++++++++++++++++++++++++++++++++---------------
1 files changed, 44 insertions(+), 18 deletions(-)
diff --git a/lib/label/label.c b/lib/label/label.c
index 4defc1d..26d94cf 100644
--- a/lib/label/label.c
+++ b/lib/label/label.c
@@ -119,42 +119,48 @@ static void _update_lvmcache_orphan(struct lvmcache_info *info)
stack;
}
-static void _set_label_read_result(int failed, struct device *dev, uint64_t sector, struct label **result)
+struct find_labeller_params {
+ struct device *dev;
+ uint64_t scan_sector; /* Sector to be scanned */
+
+ uint64_t label_sector; /* Sector where label found */
+ struct label **result;
+};
+
+static void _set_label_read_result(int failed, struct find_labeller_params *flp)
{
+ struct label **result = flp->result;
+
if (failed)
goto_out;
if (result && *result) {
- (*result)->dev = dev;
- (*result)->sector = sector;
+ (*result)->dev = flp->dev;
+ (*result)->sector = flp->label_sector;
}
out:
- if (!dev_close(dev))
+ if (!dev_close(flp->dev))
stack;
}
-static int _find_labeller(struct device *dev, uint64_t scan_sector, struct label **result)
+static int _find_labeller(struct find_labeller_params *flp, char *readbuf)
{
+ struct device *dev = flp->dev;
+ uint64_t scan_sector = flp->scan_sector;
+ struct label **result = flp->result;
char labelbuf[LABEL_SIZE] __attribute__((aligned(8)));
- uint64_t label_sector;
struct labeller_i *li;
struct labeller *l = NULL; /* Set when a labeller claims the label */
struct label_header *lh;
struct lvmcache_info *info;
uint64_t sector;
- char *buf = NULL;
int r = 0;
- 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;
- }
-
/* Scan a few sectors for a valid label */
for (sector = 0; sector < LABEL_SCAN_SECTORS;
sector += LABEL_SIZE >> SECTOR_SHIFT) {
- lh = (struct label_header *) (buf + (sector << SECTOR_SHIFT));
+ lh = (struct label_header *) (readbuf + (sector << SECTOR_SHIFT));
if (!strncmp((char *)lh->id, LABEL_ID, sizeof(lh->id))) {
if (l) {
@@ -196,15 +202,14 @@ static int _find_labeller(struct device *dev, uint64_t scan_sector, struct label
continue;
}
memcpy(labelbuf, lh, LABEL_SIZE);
- label_sector = sector + scan_sector;
+ flp->label_sector = sector + scan_sector;
l = li->l;
break;
}
}
}
- out:
- dm_free(buf);
+ dm_free(readbuf);
if (!l) {
if ((info = lvmcache_info_from_pvid(dev->pvid, dev, 0)))
@@ -213,7 +218,7 @@ static int _find_labeller(struct device *dev, uint64_t scan_sector, struct label
} else
r = (l->ops->read)(l, dev, labelbuf, result);
- _set_label_read_result(!r, dev, label_sector, result);
+ _set_label_read_result(!r, flp);
return r;
}
@@ -296,6 +301,8 @@ int label_remove(struct device *dev)
static int _label_read(struct device *dev, uint64_t scan_sector, struct label **result)
{
struct lvmcache_info *info;
+ struct find_labeller_params *flp;
+ char *readbuf = NULL;
if ((info = lvmcache_info_from_pvid(dev->pvid, dev, 1))) {
log_debug_devs("Reading label from lvmcache for %s", dev_name(dev));
@@ -303,6 +310,19 @@ static int _label_read(struct device *dev, uint64_t scan_sector, struct label **
return 1;
}
+ if (!(flp = dm_pool_zalloc(_labeller_mem, sizeof *flp))) {
+ log_error("find_labeller_params allocation failed.");
+ return 0;
+ }
+
+ flp->dev = dev;
+ flp->scan_sector = scan_sector;
+ flp->result = result;
+
+ /* Ensure result is always wiped as a precaution */
+ if (result)
+ *result = NULL;
+
log_debug_devs("Reading label from device %s", dev_name(dev));
if (!dev_open_readonly(dev)) {
@@ -314,7 +334,13 @@ static int _label_read(struct device *dev, uint64_t scan_sector, struct label **
return 0;
}
- return _find_labeller(dev, scan_sector, result);
+ if (!(readbuf = 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));
+ _set_label_read_result(1, flp);
+ return 0;
+ }
+
+ return _find_labeller(flp, readbuf);
}
int label_read(struct device *dev, struct label **result, uint64_t scan_sector)
6 years, 3 months
master - label: Move _set_label_read_result call into _find_labeller.
by Alasdair Kergon
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=9b830791eabe24b69e8...
Commit: 9b830791eabe24b69e82ab480498c617c4d8fc71
Parent: 4f4ddb806d9e27f141d76b4b80113948da012426
Author: Alasdair G Kergon <agk(a)redhat.com>
AuthorDate: Tue Jan 2 14:58:21 2018 +0000
Committer: Alasdair G Kergon <agk(a)redhat.com>
CommitterDate: Tue Jan 2 15:30:58 2018 +0000
label: Move _set_label_read_result call into _find_labeller.
Move responsibility for setting the label_read() result parameter down
into _find_labeller().
---
lib/label/label.c | 57 +++++++++++++++++++++++++---------------------------
1 files changed, 27 insertions(+), 30 deletions(-)
diff --git a/lib/label/label.c b/lib/label/label.c
index 04db752..4defc1d 100644
--- a/lib/label/label.c
+++ b/lib/label/label.c
@@ -119,25 +119,32 @@ static void _update_lvmcache_orphan(struct lvmcache_info *info)
stack;
}
-static void _set_label_read_result(struct device *dev, uint64_t sector, struct label **result)
+static void _set_label_read_result(int failed, struct device *dev, uint64_t sector, struct label **result)
{
+ if (failed)
+ goto_out;
+
if (result && *result) {
(*result)->dev = dev;
(*result)->sector = sector;
}
+
+out:
+ if (!dev_close(dev))
+ stack;
}
-static struct labeller *_find_labeller(struct device *dev, char *labelbuf,
- uint64_t *label_sector,
- uint64_t scan_sector)
+static int _find_labeller(struct device *dev, uint64_t scan_sector, struct label **result)
{
+ char labelbuf[LABEL_SIZE] __attribute__((aligned(8)));
+ uint64_t label_sector;
struct labeller_i *li;
- struct labeller *r = NULL;
+ struct labeller *l = NULL; /* Set when a labeller claims the label */
struct label_header *lh;
struct lvmcache_info *info;
uint64_t sector;
- int found = 0;
char *buf = NULL;
+ int r = 0;
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));
@@ -150,7 +157,7 @@ static struct labeller *_find_labeller(struct device *dev, char *labelbuf,
lh = (struct label_header *) (buf + (sector << SECTOR_SHIFT));
if (!strncmp((char *)lh->id, LABEL_ID, sizeof(lh->id))) {
- if (found) {
+ if (l) {
log_error("Ignoring additional label on %s at "
"sector %" PRIu64, dev_name(dev),
sector + scan_sector);
@@ -170,7 +177,7 @@ static struct labeller *_find_labeller(struct device *dev, char *labelbuf,
"ignoring", dev_name(dev));
continue;
}
- if (found)
+ if (l)
continue;
}
@@ -181,18 +188,16 @@ static struct labeller *_find_labeller(struct device *dev, char *labelbuf,
"sector %" PRIu64,
dev_name(dev), li->name,
sector + scan_sector);
- if (found) {
+ if (l) {
log_error("Ignoring additional label "
"on %s at sector %" PRIu64,
dev_name(dev),
sector + scan_sector);
continue;
}
- r = li->l;
memcpy(labelbuf, lh, LABEL_SIZE);
- if (label_sector)
- *label_sector = sector + scan_sector;
- found = 1;
+ label_sector = sector + scan_sector;
+ l = li->l;
break;
}
}
@@ -201,11 +206,14 @@ static struct labeller *_find_labeller(struct device *dev, char *labelbuf,
out:
dm_free(buf);
- if (!found) {
+ if (!l) {
if ((info = lvmcache_info_from_pvid(dev->pvid, dev, 0)))
_update_lvmcache_orphan(info);
log_very_verbose("%s: No label detected", dev_name(dev));
- }
+ } else
+ r = (l->ops->read)(l, dev, labelbuf, result);
+
+ _set_label_read_result(!r, dev, label_sector, result);
return r;
}
@@ -285,13 +293,9 @@ int label_remove(struct device *dev)
return r;
}
-static int _label_read(struct device *dev, struct label **result, uint64_t scan_sector)
+static int _label_read(struct device *dev, uint64_t scan_sector, struct label **result)
{
- char buf[LABEL_SIZE] __attribute__((aligned(8)));
- struct labeller *l;
- uint64_t sector;
struct lvmcache_info *info;
- int r = 0;
if ((info = lvmcache_info_from_pvid(dev->pvid, dev, 1))) {
log_debug_devs("Reading label from lvmcache for %s", dev_name(dev));
@@ -307,22 +311,15 @@ static int _label_read(struct device *dev, struct label **result, uint64_t scan_
if ((info = lvmcache_info_from_pvid(dev->pvid, dev, 0)))
_update_lvmcache_orphan(info);
- return r;
+ return 0;
}
- if ((l = _find_labeller(dev, buf, §or, scan_sector)))
- if ((r = (l->ops->read)(l, dev, buf, result)))
- _set_label_read_result(dev, sector, result);
-
- if (!dev_close(dev))
- stack;
-
- return r;
+ return _find_labeller(dev, scan_sector, result);
}
int label_read(struct device *dev, struct label **result, uint64_t scan_sector)
{
- return _label_read(dev, result, scan_sector);
+ return _label_read(dev, scan_sector, result);
}
/* Caller may need to use label_get_handler to create label struct! */
6 years, 3 months
master - label: Move setting result of label_read into separate fn.
by Alasdair Kergon
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=4f4ddb806d9e27f141d...
Commit: 4f4ddb806d9e27f141d76b4b80113948da012426
Parent: e6b4b41881b6070b24353496dd32cccc270fe9ce
Author: Alasdair G Kergon <agk(a)redhat.com>
AuthorDate: Tue Jan 2 14:19:20 2018 +0000
Committer: Alasdair G Kergon <agk(a)redhat.com>
CommitterDate: Tue Jan 2 14:19:20 2018 +0000
label: Move setting result of label_read into separate fn.
---
lib/label/label.c | 22 ++++++++++++++++------
1 files changed, 16 insertions(+), 6 deletions(-)
diff --git a/lib/label/label.c b/lib/label/label.c
index fa44f2c..04db752 100644
--- a/lib/label/label.c
+++ b/lib/label/label.c
@@ -119,6 +119,14 @@ static void _update_lvmcache_orphan(struct lvmcache_info *info)
stack;
}
+static void _set_label_read_result(struct device *dev, uint64_t sector, struct label **result)
+{
+ if (result && *result) {
+ (*result)->dev = dev;
+ (*result)->sector = sector;
+ }
+}
+
static struct labeller *_find_labeller(struct device *dev, char *labelbuf,
uint64_t *label_sector,
uint64_t scan_sector)
@@ -277,8 +285,7 @@ int label_remove(struct device *dev)
return r;
}
-int label_read(struct device *dev, struct label **result,
- uint64_t scan_sector)
+static int _label_read(struct device *dev, struct label **result, uint64_t scan_sector)
{
char buf[LABEL_SIZE] __attribute__((aligned(8)));
struct labeller *l;
@@ -304,10 +311,8 @@ int label_read(struct device *dev, struct label **result,
}
if ((l = _find_labeller(dev, buf, §or, scan_sector)))
- if ((r = (l->ops->read)(l, dev, buf, result)) && result && *result) {
- (*result)->dev = dev;
- (*result)->sector = sector;
- }
+ if ((r = (l->ops->read)(l, dev, buf, result)))
+ _set_label_read_result(dev, sector, result);
if (!dev_close(dev))
stack;
@@ -315,6 +320,11 @@ int label_read(struct device *dev, struct label **result,
return r;
}
+int label_read(struct device *dev, struct label **result, uint64_t scan_sector)
+{
+ return _label_read(dev, result, scan_sector);
+}
+
/* Caller may need to use label_get_handler to create label struct! */
int label_write(struct device *dev, struct label *label)
{
6 years, 3 months
master - label: Add mempool.
by Alasdair Kergon
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=e6b4b41881b6070b243...
Commit: e6b4b41881b6070b24353496dd32cccc270fe9ce
Parent: 0bf1cc2320cb96cde9be742bed2aa391c998588a
Author: Alasdair G Kergon <agk(a)redhat.com>
AuthorDate: Tue Jan 2 13:37:12 2018 +0000
Committer: Alasdair G Kergon <agk(a)redhat.com>
CommitterDate: Tue Jan 2 13:37:12 2018 +0000
label: Add mempool.
---
lib/label/label.c | 10 ++++++++++
1 files changed, 10 insertions(+), 0 deletions(-)
diff --git a/lib/label/label.c b/lib/label/label.c
index b90fff3..fa44f2c 100644
--- a/lib/label/label.c
+++ b/lib/label/label.c
@@ -26,6 +26,8 @@
/* FIXME Allow for larger labels? Restricted to single sector currently */
+static struct dm_pool *_labeller_mem;
+
/*
* Internal labeller struct.
*/
@@ -58,7 +60,13 @@ static struct labeller_i *_alloc_li(const char *name, struct labeller *l)
int label_init(void)
{
+ if (!(_labeller_mem = dm_pool_create("label scan", 128))) {
+ log_error("Labeller pool creation failed.");
+ return 0;
+ }
+
dm_list_init(&_labellers);
+
return 1;
}
@@ -73,6 +81,8 @@ void label_exit(void)
}
dm_list_init(&_labellers);
+
+ dm_pool_destroy(_labeller_mem);
}
int label_register_handler(struct labeller *handler)
6 years, 3 months