1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-01-03 05:18:29 +03:00

io: warn when metadata size approaches io memory size

When a single copy of metadata gets within 1MB of the
current io_memory_size value, begin printing a warning
that the io_memory_size should be increased.
This commit is contained in:
David Teigland 2019-03-04 12:13:09 -06:00
parent dd8d083795
commit 3584e0c0d5
4 changed files with 63 additions and 0 deletions

15
lib/cache/lvmcache.c vendored
View File

@ -2286,6 +2286,21 @@ int lvmcache_scan_mismatch(struct cmd_context *cmd, const char *vgname, const ch
return 1; return 1;
} }
static uint64_t _max_metadata_size;
void lvmcache_save_metadata_size(uint64_t val)
{
if (!_max_metadata_size)
_max_metadata_size = val;
else if (_max_metadata_size < val)
_max_metadata_size = val;
}
uint64_t lvmcache_max_metadata_size(void)
{
return _max_metadata_size;
}
int lvmcache_vginfo_has_pvid(struct lvmcache_vginfo *vginfo, char *pvid) int lvmcache_vginfo_has_pvid(struct lvmcache_vginfo *vginfo, char *pvid)
{ {
struct lvmcache_info *info; struct lvmcache_info *info;

View File

@ -210,6 +210,9 @@ struct volume_group *lvmcache_get_saved_vg(const char *vgid, int precommitted);
struct volume_group *lvmcache_get_saved_vg_latest(const char *vgid); struct volume_group *lvmcache_get_saved_vg_latest(const char *vgid);
void lvmcache_drop_saved_vgid(const char *vgid); void lvmcache_drop_saved_vgid(const char *vgid);
uint64_t lvmcache_max_metadata_size(void);
void lvmcache_save_metadata_size(uint64_t val);
int dev_in_device_list(struct device *dev, struct dm_list *head); int dev_in_device_list(struct device *dev, struct dm_list *head);
#endif #endif

View File

@ -1548,6 +1548,10 @@ int read_metadata_location_summary(const struct format_type *fmt,
*/ */
vgsummary->mda_checksum = rlocn->checksum; vgsummary->mda_checksum = rlocn->checksum;
vgsummary->mda_size = rlocn->size; vgsummary->mda_size = rlocn->size;
/* Keep track of largest metadata size we find. */
lvmcache_save_metadata_size(rlocn->size);
lvmcache_lookup_mda(vgsummary); lvmcache_lookup_mda(vgsummary);
if (!text_read_metadata_summary(fmt, dev_area->dev, MDA_CONTENT_REASON(primary_mda), if (!text_read_metadata_summary(fmt, dev_area->dev, MDA_CONTENT_REASON(primary_mda),

View File

@ -23,6 +23,7 @@
#include "lib/commands/toolcontext.h" #include "lib/commands/toolcontext.h"
#include "lib/activate/activate.h" #include "lib/activate/activate.h"
#include "lib/label/hints.h" #include "lib/label/hints.h"
#include "lib/metadata/metadata.h"
#include <sys/stat.h> #include <sys/stat.h>
#include <fcntl.h> #include <fcntl.h>
@ -31,6 +32,8 @@
/* FIXME Allow for larger labels? Restricted to single sector currently */ /* FIXME Allow for larger labels? Restricted to single sector currently */
static uint64_t _current_bcache_size_bytes;
/* /*
* Internal labeller struct. * Internal labeller struct.
*/ */
@ -809,6 +812,8 @@ static int _setup_bcache(int num_devs)
if (cache_blocks > MAX_BCACHE_BLOCKS) if (cache_blocks > MAX_BCACHE_BLOCKS)
cache_blocks = MAX_BCACHE_BLOCKS; cache_blocks = MAX_BCACHE_BLOCKS;
_current_bcache_size_bytes = cache_blocks * BCACHE_BLOCK_SIZE_IN_SECTORS * 512;
if (use_aio()) { if (use_aio()) {
if (!(ioe = create_async_io_engine())) { if (!(ioe = create_async_io_engine())) {
log_warn("Failed to set up async io, using sync io."); log_warn("Failed to set up async io, using sync io.");
@ -854,6 +859,7 @@ int label_scan(struct cmd_context *cmd)
struct dev_iter *iter; struct dev_iter *iter;
struct device_list *devl, *devl2; struct device_list *devl, *devl2;
struct device *dev; struct device *dev;
uint64_t max_metadata_size_bytes;
int newhints = 0; int newhints = 0;
log_debug_devs("Finding devices to scan"); log_debug_devs("Finding devices to scan");
@ -934,6 +940,41 @@ int label_scan(struct cmd_context *cmd)
*/ */
_scan_list(cmd, cmd->filter, &scan_devs, NULL); _scan_list(cmd, cmd->filter, &scan_devs, NULL);
/*
* Metadata could be larger than total size of bcache, and bcache
* cannot currently be resized during the command. If this is the
* case (or within reach), warn that io_memory_size needs to be
* set larger.
*
* Even if bcache out of space did not cause a failure during scan, it
* may cause a failure during the next vg_read phase or during vg_write.
*
* If there was an error during scan, we could recreate bcache here
* with a larger size and then restart label_scan. But, this does not
* address the problem of writing new metadata that excedes the bcache
* size and failing, which would often be hit first, i.e. we'll fail
* to write new metadata exceding the max size before we have a chance
* to read any metadata with that size, unless we find an existing vg
* that has been previously created with the larger size.
*
* If the largest metadata is within 1MB of the bcache size, then start
* warning.
*/
max_metadata_size_bytes = lvmcache_max_metadata_size();
if (max_metadata_size_bytes + (1024 * 1024) > _current_bcache_size_bytes) {
/* we want bcache to be 1MB larger than the max metadata seen */
uint64_t want_size_kb = (max_metadata_size_bytes / 1024) + 1024;
uint64_t remainder;
if ((remainder = (want_size_kb % 1024)))
want_size_kb = want_size_kb + 1024 - remainder;
log_warn("WARNING: metadata may not be usable with current io_memory_size %d KiB",
io_memory_size());
log_warn("WARNING: increase lvm.conf io_memory_size to at least %llu KiB",
(unsigned long long)want_size_kb);
}
dm_list_init(&cmd->hints); dm_list_init(&cmd->hints);
if (!dm_list_empty(&hints)) { if (!dm_list_empty(&hints)) {