mirror of
git://sourceware.org/git/lvm2.git
synced 2025-12-08 08:23:50 +03:00
The new label_scan() function reads a large buffer of data from the start of the disk, and saves it so that multiple structs can be read from it. Previously, only the label_header was read from this buffer, and the code which needed data structures that immediately followed the label_header would read those from disk separately. This created a large number of small, unnecessary disk reads. In each place that the two read paths (label_scan and vg_read) need to read data from disk, first check if that data is already available from the label_read_data buffer, and if so just copy it from the buffer instead of reading from disk. Code changes ------------ - passing the label_read_data struct down through both read paths to make it available. - before every disk read, first check if the location and size of the desired piece of data exists fully in the label_read_data buffer, and if so copy it from there. Otherwise, use the existing code to read the data from disk. - adding some log_error messages on existing error paths that were already being updated for the reasons above. - using similar naming for parallel functions on the two parallel read paths that are being updated above. label_scan path calls: read_metadata_location_summary, text_read_metadata_summary vg_read path calls: read_metadata_location_vg, text_read_metadata_file Previously, those functions were named: label_scan path calls: vgname_from_mda, text_vgsummary_import vg_read path calls: _find_vg_rlocn, text_vg_import_fd I/O changes ----------- In the label_scan path, the following data is either copied from label_read_data or read from disk for each PV: - label_header and pv_header - mda_header (in _raw_read_mda_header) - vg metadata name (in read_metadata_location_summary) - vg metadata (in config_file_read_fd) Total of 4 reads per PV in the label_scan path. In the vg_read path, the following data is either copied from label_read_data or read from disk for each PV: - mda_header (in _raw_read_mda_header) - vg metadata name (in read_metadata_location_vg) - vg metadata (in config_file_read_fd) Total of 3 reads per PV in the vg_read path. For a common read/reporting command, each PV will be: - read by the command's initial lvmcache_label_scan() - read by lvmcache_label_rescan_vg() at the start of vg_read() - read by vg_read() Previously, this would cause 11 synchronous disk reads per PV: 4 from lvmcache_label_scan(), 4 from lvmcache_label_rescan_vg() and 3 from vg_read(). With this commit's optimization, there are now 2 async disk reads per PV: 1 from lvmcache_label_scan() and 1 from lvmcache_label_rescan_vg(). When a second mda is used on a PV, it is located at the end of the PV. This second mda and copy of metadata will not be found in the label_read_data buffer, and will always require separate disk reads.
299 lines
7.8 KiB
C
299 lines
7.8 KiB
C
/*
|
|
* Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.
|
|
* Copyright (C) 2004-2008 Red Hat, Inc. All rights reserved.
|
|
*
|
|
* This file is part of LVM2.
|
|
*
|
|
* 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 Lesser General Public License v.2.1.
|
|
*
|
|
* You should have received a copy of the GNU Lesser 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
|
|
*/
|
|
|
|
#include "lib.h"
|
|
#include "metadata.h"
|
|
#include "import-export.h"
|
|
|
|
/* FIXME Use tidier inclusion method */
|
|
static struct text_vg_version_ops *(_text_vsn_list[2]);
|
|
|
|
static int _text_import_initialised = 0;
|
|
|
|
static void _init_text_import(void)
|
|
{
|
|
if (_text_import_initialised)
|
|
return;
|
|
|
|
_text_vsn_list[0] = text_vg_vsn1_init();
|
|
_text_vsn_list[1] = NULL;
|
|
_text_import_initialised = 1;
|
|
}
|
|
|
|
/*
|
|
* Find out vgname on a given device.
|
|
*/
|
|
int text_read_metadata_summary(const struct format_type *fmt,
|
|
struct device *dev,
|
|
struct label_read_data *ld,
|
|
off_t offset, uint32_t size,
|
|
off_t offset2, uint32_t size2,
|
|
checksum_fn_t checksum_fn,
|
|
int checksum_only,
|
|
struct lvmcache_vgsummary *vgsummary)
|
|
{
|
|
struct dm_config_tree *cft;
|
|
struct text_vg_version_ops **vsn;
|
|
char *buf = NULL;
|
|
int r = 0;
|
|
|
|
if (ld) {
|
|
if (ld->buf_len >= (offset + size))
|
|
buf = ld->buf;
|
|
else {
|
|
/*
|
|
* Needs data beyond the end of the ld buffer.
|
|
* Will do a new synchronous read to get the data.
|
|
* (scan_size could also be made larger.)
|
|
*/
|
|
log_debug_metadata("label scan buffer for %s len %u does not include metadata at %llu size %u",
|
|
dev_name(dev), ld->buf_len, (unsigned long long)offset, size);
|
|
buf = NULL;
|
|
}
|
|
}
|
|
|
|
_init_text_import();
|
|
|
|
if (!(cft = config_open(CONFIG_FILE_SPECIAL, NULL, 0)))
|
|
return_0;
|
|
|
|
if (dev) {
|
|
if (buf)
|
|
log_debug_metadata("Copying metadata summary for %s at %llu size %d (+%d)",
|
|
dev_name(dev), (unsigned long long)offset,
|
|
size, size2);
|
|
else
|
|
log_debug_metadata("Reading metadata summary from %s at %llu size %d (+%d)",
|
|
dev_name(dev), (unsigned long long)offset,
|
|
size, size2);
|
|
|
|
if (!config_file_read_fd(cft, dev, buf, offset, size,
|
|
offset2, size2, checksum_fn,
|
|
vgsummary->mda_checksum,
|
|
checksum_only, 1)) {
|
|
/* FIXME: handle errors */
|
|
log_error("Couldn't read volume group metadata from %s.", dev_name(dev));
|
|
goto out;
|
|
}
|
|
} else {
|
|
if (!config_file_read(cft)) {
|
|
log_error("Couldn't read volume group metadata from file.");
|
|
goto out;
|
|
}
|
|
}
|
|
|
|
if (checksum_only) {
|
|
/* Checksum matches already-cached content - no need to reparse. */
|
|
r = 1;
|
|
goto out;
|
|
}
|
|
|
|
/*
|
|
* Find a set of version functions that can read this file
|
|
*/
|
|
for (vsn = &_text_vsn_list[0]; *vsn; vsn++) {
|
|
if (!(*vsn)->check_version(cft))
|
|
continue;
|
|
|
|
if (!(*vsn)->read_vgsummary(fmt, cft, vgsummary))
|
|
goto_out;
|
|
|
|
r = 1;
|
|
break;
|
|
}
|
|
|
|
out:
|
|
config_destroy(cft);
|
|
return r;
|
|
}
|
|
|
|
struct cached_vg_fmtdata {
|
|
uint32_t cached_mda_checksum;
|
|
size_t cached_mda_size;
|
|
};
|
|
|
|
struct volume_group *text_read_metadata(struct format_instance *fid,
|
|
struct device *dev,
|
|
const char *file,
|
|
struct label_read_data *ld,
|
|
struct cached_vg_fmtdata **vg_fmtdata,
|
|
unsigned *use_previous_vg,
|
|
off_t offset, uint32_t size,
|
|
off_t offset2, uint32_t size2,
|
|
checksum_fn_t checksum_fn,
|
|
uint32_t checksum,
|
|
time_t *when, char **desc)
|
|
{
|
|
struct volume_group *vg = NULL;
|
|
struct dm_config_tree *cft;
|
|
struct text_vg_version_ops **vsn;
|
|
char *buf = NULL;
|
|
int skip_parse;
|
|
|
|
/*
|
|
* This struct holds the checksum and size of the VG metadata
|
|
* that was read from a previous device. When we read the VG
|
|
* metadata from this device, we can skip parsing it into a
|
|
* cft (saving time) if the checksum of the metadata buffer
|
|
* we read from this device matches the size/checksum saved in
|
|
* the mda_header/rlocn struct on this device, and matches the
|
|
* size/checksum from the previous device.
|
|
*/
|
|
if (vg_fmtdata && !*vg_fmtdata &&
|
|
!(*vg_fmtdata = dm_pool_zalloc(fid->mem, sizeof(**vg_fmtdata)))) {
|
|
log_error("Failed to allocate VG fmtdata for text format.");
|
|
return NULL;
|
|
}
|
|
|
|
_init_text_import();
|
|
|
|
*desc = NULL;
|
|
*when = 0;
|
|
|
|
if (!(cft = config_open(CONFIG_FILE_SPECIAL, file, 0)))
|
|
return_NULL;
|
|
|
|
/* Does the metadata match the already-cached VG? */
|
|
skip_parse = vg_fmtdata &&
|
|
((*vg_fmtdata)->cached_mda_checksum == checksum) &&
|
|
((*vg_fmtdata)->cached_mda_size == (size + size2));
|
|
|
|
if (ld) {
|
|
if (ld->buf_len >= (offset + size))
|
|
buf = ld->buf;
|
|
else {
|
|
/*
|
|
* Needs data beyond the end of the ld buffer.
|
|
* Will do a new synchronous read to get the data.
|
|
* (scan_size could also be made larger.)
|
|
*/
|
|
log_debug_metadata("label scan buffer for %s len %u does not include metadata at %llu size %u",
|
|
dev_name(dev), ld->buf_len, (unsigned long long)offset, size);
|
|
buf = NULL;
|
|
}
|
|
}
|
|
|
|
if (dev) {
|
|
if (buf)
|
|
log_debug_metadata("Copying metadata for %s at %llu size %d (+%d)",
|
|
dev_name(dev), (unsigned long long)offset,
|
|
size, size2);
|
|
else
|
|
log_debug_metadata("Reading metadata from %s at %llu size %d (+%d)",
|
|
dev_name(dev), (unsigned long long)offset,
|
|
size, size2);
|
|
|
|
if (!config_file_read_fd(cft, dev, buf, offset, size,
|
|
offset2, size2, checksum_fn, checksum,
|
|
skip_parse, 1)) {
|
|
/* FIXME: handle errors */
|
|
log_error("Couldn't read volume group metadata from %s.", dev_name(dev));
|
|
goto out;
|
|
}
|
|
} else {
|
|
if (!config_file_read(cft)) {
|
|
log_error("Couldn't read volume group metadata from file.");
|
|
goto out;
|
|
}
|
|
}
|
|
|
|
if (skip_parse) {
|
|
if (use_previous_vg)
|
|
*use_previous_vg = 1;
|
|
log_debug_metadata("Skipped parsing metadata on %s", dev_name(dev));
|
|
goto out;
|
|
}
|
|
|
|
/*
|
|
* Find a set of version functions that can read this file
|
|
*/
|
|
for (vsn = &_text_vsn_list[0]; *vsn; vsn++) {
|
|
if (!(*vsn)->check_version(cft))
|
|
continue;
|
|
|
|
if (!(vg = (*vsn)->read_vg(fid, cft, 0)))
|
|
goto_out;
|
|
|
|
(*vsn)->read_desc(vg->vgmem, cft, when, desc);
|
|
break;
|
|
}
|
|
|
|
if (vg && vg_fmtdata && *vg_fmtdata) {
|
|
(*vg_fmtdata)->cached_mda_size = (size + size2);
|
|
(*vg_fmtdata)->cached_mda_checksum = checksum;
|
|
}
|
|
|
|
if (use_previous_vg)
|
|
*use_previous_vg = 0;
|
|
|
|
out:
|
|
config_destroy(cft);
|
|
return vg;
|
|
}
|
|
|
|
struct volume_group *text_read_metadata_file(struct format_instance *fid,
|
|
const char *file,
|
|
time_t *when, char **desc)
|
|
{
|
|
return text_read_metadata(fid, NULL, file, NULL, NULL, NULL,
|
|
(off_t)0, 0, (off_t)0, 0,
|
|
NULL,
|
|
0,
|
|
when, desc);
|
|
}
|
|
|
|
static struct volume_group *_import_vg_from_config_tree(const struct dm_config_tree *cft,
|
|
struct format_instance *fid,
|
|
unsigned for_lvmetad)
|
|
{
|
|
struct volume_group *vg = NULL;
|
|
struct text_vg_version_ops **vsn;
|
|
int vg_missing;
|
|
|
|
_init_text_import();
|
|
|
|
for (vsn = &_text_vsn_list[0]; *vsn; vsn++) {
|
|
if (!(*vsn)->check_version(cft))
|
|
continue;
|
|
/*
|
|
* The only path to this point uses cached vgmetadata,
|
|
* so it can use cached PV state too.
|
|
*/
|
|
if (!(vg = (*vsn)->read_vg(fid, cft, for_lvmetad)))
|
|
stack;
|
|
else if ((vg_missing = vg_missing_pv_count(vg))) {
|
|
log_verbose("There are %d physical volumes missing.",
|
|
vg_missing);
|
|
vg_mark_partial_lvs(vg, 1);
|
|
/* FIXME: move this code inside read_vg() */
|
|
}
|
|
break;
|
|
}
|
|
|
|
return vg;
|
|
}
|
|
|
|
struct volume_group *import_vg_from_config_tree(const struct dm_config_tree *cft,
|
|
struct format_instance *fid)
|
|
{
|
|
return _import_vg_from_config_tree(cft, fid, 0);
|
|
}
|
|
|
|
struct volume_group *import_vg_from_lvmetad_config_tree(const struct dm_config_tree *cft,
|
|
struct format_instance *fid)
|
|
{
|
|
return _import_vg_from_config_tree(cft, fid, 1);
|
|
}
|