summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Teigland <teigland@redhat.com>2019-03-04 12:13:09 -0600
committerDavid Teigland <teigland@redhat.com>2019-03-04 12:13:09 -0600
commit3584e0c0d5e5992a3c93e03de8b6042de0853ef2 (patch)
tree5a6c288da41fedd03fbf740719fd1095e8b3004d
parentdd8d0837950ae72939b13c3a1eb4cff902bbccdd (diff)
downloadlvm2-3584e0c0d5e5992a3c93e03de8b6042de0853ef2.tar.gz
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.
-rw-r--r--lib/cache/lvmcache.c15
-rw-r--r--lib/cache/lvmcache.h3
-rw-r--r--lib/format_text/format-text.c4
-rw-r--r--lib/label/label.c41
4 files changed, 63 insertions, 0 deletions
diff --git a/lib/cache/lvmcache.c b/lib/cache/lvmcache.c
index 0ffa604df..8aed59ba9 100644
--- a/lib/cache/lvmcache.c
+++ b/lib/cache/lvmcache.c
@@ -2286,6 +2286,21 @@ int lvmcache_scan_mismatch(struct cmd_context *cmd, const char *vgname, const ch
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)
{
struct lvmcache_info *info;
diff --git a/lib/cache/lvmcache.h b/lib/cache/lvmcache.h
index 12f17dfa6..26e09535e 100644
--- a/lib/cache/lvmcache.h
+++ b/lib/cache/lvmcache.h
@@ -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);
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);
#endif
diff --git a/lib/format_text/format-text.c b/lib/format_text/format-text.c
index 414941f22..d97617753 100644
--- a/lib/format_text/format-text.c
+++ b/lib/format_text/format-text.c
@@ -1548,6 +1548,10 @@ int read_metadata_location_summary(const struct format_type *fmt,
*/
vgsummary->mda_checksum = rlocn->checksum;
vgsummary->mda_size = rlocn->size;
+
+ /* Keep track of largest metadata size we find. */
+ lvmcache_save_metadata_size(rlocn->size);
+
lvmcache_lookup_mda(vgsummary);
if (!text_read_metadata_summary(fmt, dev_area->dev, MDA_CONTENT_REASON(primary_mda),
diff --git a/lib/label/label.c b/lib/label/label.c
index a877b388d..174139e55 100644
--- a/lib/label/label.c
+++ b/lib/label/label.c
@@ -23,6 +23,7 @@
#include "lib/commands/toolcontext.h"
#include "lib/activate/activate.h"
#include "lib/label/hints.h"
+#include "lib/metadata/metadata.h"
#include <sys/stat.h>
#include <fcntl.h>
@@ -31,6 +32,8 @@
/* FIXME Allow for larger labels? Restricted to single sector currently */
+static uint64_t _current_bcache_size_bytes;
+
/*
* Internal labeller struct.
*/
@@ -809,6 +812,8 @@ static int _setup_bcache(int num_devs)
if (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 (!(ioe = create_async_io_engine())) {
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 device_list *devl, *devl2;
struct device *dev;
+ uint64_t max_metadata_size_bytes;
int newhints = 0;
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);
+ /*
+ * 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);
if (!dm_list_empty(&hints)) {