|
|
c63e28 |
lib/cache/lvmcache.c | 15 +++++++++++++++
|
|
|
c63e28 |
lib/cache/lvmcache.h | 3 +++
|
|
|
c63e28 |
lib/format_text/format-text.c | 4 ++++
|
|
|
c63e28 |
lib/label/label.c | 41 +++++++++++++++++++++++++++++++++++++++++
|
|
|
c63e28 |
4 files changed, 63 insertions(+)
|
|
|
c63e28 |
|
|
|
c63e28 |
diff --git a/lib/cache/lvmcache.c b/lib/cache/lvmcache.c
|
|
|
c63e28 |
index f55a14c..62f1d3c 100644
|
|
|
c63e28 |
--- a/lib/cache/lvmcache.c
|
|
|
c63e28 |
+++ b/lib/cache/lvmcache.c
|
|
|
c63e28 |
@@ -3048,3 +3048,18 @@ int lvmcache_scan_mismatch(struct cmd_context *cmd, const char *vgname, const ch
|
|
|
c63e28 |
return 1;
|
|
|
c63e28 |
}
|
|
|
c63e28 |
|
|
|
c63e28 |
+static uint64_t _max_metadata_size;
|
|
|
c63e28 |
+
|
|
|
c63e28 |
+void lvmcache_save_metadata_size(uint64_t val)
|
|
|
c63e28 |
+{
|
|
|
c63e28 |
+ if (!_max_metadata_size)
|
|
|
c63e28 |
+ _max_metadata_size = val;
|
|
|
c63e28 |
+ else if (_max_metadata_size < val)
|
|
|
c63e28 |
+ _max_metadata_size = val;
|
|
|
c63e28 |
+}
|
|
|
c63e28 |
+
|
|
|
c63e28 |
+uint64_t lvmcache_max_metadata_size(void)
|
|
|
c63e28 |
+{
|
|
|
c63e28 |
+ return _max_metadata_size;
|
|
|
c63e28 |
+}
|
|
|
c63e28 |
+
|
|
|
c63e28 |
diff --git a/lib/cache/lvmcache.h b/lib/cache/lvmcache.h
|
|
|
c63e28 |
index bf976e9..f436785 100644
|
|
|
c63e28 |
--- a/lib/cache/lvmcache.h
|
|
|
c63e28 |
+++ b/lib/cache/lvmcache.h
|
|
|
c63e28 |
@@ -225,4 +225,7 @@ struct volume_group *lvmcache_get_saved_vg(const char *vgid, int precommitted);
|
|
|
c63e28 |
struct volume_group *lvmcache_get_saved_vg_latest(const char *vgid);
|
|
|
c63e28 |
void lvmcache_drop_saved_vgid(const char *vgid);
|
|
|
c63e28 |
|
|
|
c63e28 |
+uint64_t lvmcache_max_metadata_size(void);
|
|
|
c63e28 |
+void lvmcache_save_metadata_size(uint64_t val);
|
|
|
c63e28 |
+
|
|
|
c63e28 |
#endif
|
|
|
c63e28 |
diff --git a/lib/format_text/format-text.c b/lib/format_text/format-text.c
|
|
|
c63e28 |
index 36afba1..200b011 100644
|
|
|
c63e28 |
--- a/lib/format_text/format-text.c
|
|
|
c63e28 |
+++ b/lib/format_text/format-text.c
|
|
|
c63e28 |
@@ -1294,6 +1294,10 @@ int read_metadata_location_summary(const struct format_type *fmt,
|
|
|
c63e28 |
*/
|
|
|
c63e28 |
vgsummary->mda_checksum = rlocn->checksum;
|
|
|
c63e28 |
vgsummary->mda_size = rlocn->size;
|
|
|
c63e28 |
+
|
|
|
c63e28 |
+ /* Keep track of largest metadata size we find. */
|
|
|
c63e28 |
+ lvmcache_save_metadata_size(rlocn->size);
|
|
|
c63e28 |
+
|
|
|
c63e28 |
lvmcache_lookup_mda(vgsummary);
|
|
|
c63e28 |
|
|
|
c63e28 |
if (!text_read_metadata_summary(fmt, dev_area->dev, MDA_CONTENT_REASON(primary_mda),
|
|
|
c63e28 |
diff --git a/lib/label/label.c b/lib/label/label.c
|
|
|
c63e28 |
index 4ec7d9b..4fdbbb7 100644
|
|
|
c63e28 |
--- a/lib/label/label.c
|
|
|
c63e28 |
+++ b/lib/label/label.c
|
|
|
c63e28 |
@@ -21,6 +21,7 @@
|
|
|
c63e28 |
#include "bcache.h"
|
|
|
c63e28 |
#include "toolcontext.h"
|
|
|
c63e28 |
#include "activate.h"
|
|
|
c63e28 |
+#include "metadata.h"
|
|
|
c63e28 |
|
|
|
c63e28 |
#include <sys/stat.h>
|
|
|
c63e28 |
#include <fcntl.h>
|
|
|
c63e28 |
@@ -29,6 +30,8 @@
|
|
|
c63e28 |
|
|
|
c63e28 |
int use_full_md_check;
|
|
|
c63e28 |
|
|
|
c63e28 |
+static uint64_t _current_bcache_size_bytes;
|
|
|
c63e28 |
+
|
|
|
c63e28 |
/* FIXME Allow for larger labels? Restricted to single sector currently */
|
|
|
c63e28 |
|
|
|
c63e28 |
/*
|
|
|
c63e28 |
@@ -806,6 +809,8 @@ static int _setup_bcache(int num_devs)
|
|
|
c63e28 |
if (cache_blocks > MAX_BCACHE_BLOCKS)
|
|
|
c63e28 |
cache_blocks = MAX_BCACHE_BLOCKS;
|
|
|
c63e28 |
|
|
|
c63e28 |
+ _current_bcache_size_bytes = cache_blocks * BCACHE_BLOCK_SIZE_IN_SECTORS * 512;
|
|
|
c63e28 |
+
|
|
|
c63e28 |
if (use_aio()) {
|
|
|
c63e28 |
if (!(ioe = create_async_io_engine())) {
|
|
|
c63e28 |
log_warn("Failed to set up async io, using sync io.");
|
|
|
c63e28 |
@@ -839,6 +844,7 @@ int label_scan(struct cmd_context *cmd)
|
|
|
c63e28 |
struct dev_iter *iter;
|
|
|
c63e28 |
struct device_list *devl, *devl2;
|
|
|
c63e28 |
struct device *dev;
|
|
|
c63e28 |
+ uint64_t max_metadata_size_bytes;
|
|
|
c63e28 |
|
|
|
c63e28 |
log_debug_devs("Finding devices to scan");
|
|
|
c63e28 |
|
|
|
c63e28 |
@@ -909,6 +915,41 @@ int label_scan(struct cmd_context *cmd)
|
|
|
c63e28 |
|
|
|
c63e28 |
_scan_list(cmd, cmd->full_filter, &all_devs, NULL);
|
|
|
c63e28 |
|
|
|
c63e28 |
+ /*
|
|
|
c63e28 |
+ * Metadata could be larger than total size of bcache, and bcache
|
|
|
c63e28 |
+ * cannot currently be resized during the command. If this is the
|
|
|
c63e28 |
+ * case (or within reach), warn that io_memory_size needs to be
|
|
|
c63e28 |
+ * set larger.
|
|
|
c63e28 |
+ *
|
|
|
c63e28 |
+ * Even if bcache out of space did not cause a failure during scan, it
|
|
|
c63e28 |
+ * may cause a failure during the next vg_read phase or during vg_write.
|
|
|
c63e28 |
+ *
|
|
|
c63e28 |
+ * If there was an error during scan, we could recreate bcache here
|
|
|
c63e28 |
+ * with a larger size and then restart label_scan. But, this does not
|
|
|
c63e28 |
+ * address the problem of writing new metadata that excedes the bcache
|
|
|
c63e28 |
+ * size and failing, which would often be hit first, i.e. we'll fail
|
|
|
c63e28 |
+ * to write new metadata exceding the max size before we have a chance
|
|
|
c63e28 |
+ * to read any metadata with that size, unless we find an existing vg
|
|
|
c63e28 |
+ * that has been previously created with the larger size.
|
|
|
c63e28 |
+ *
|
|
|
c63e28 |
+ * If the largest metadata is within 1MB of the bcache size, then start
|
|
|
c63e28 |
+ * warning.
|
|
|
c63e28 |
+ */
|
|
|
c63e28 |
+ max_metadata_size_bytes = lvmcache_max_metadata_size();
|
|
|
c63e28 |
+
|
|
|
c63e28 |
+ if (max_metadata_size_bytes + (1024 * 1024) > _current_bcache_size_bytes) {
|
|
|
c63e28 |
+ /* we want bcache to be 1MB larger than the max metadata seen */
|
|
|
c63e28 |
+ uint64_t want_size_kb = (max_metadata_size_bytes / 1024) + 1024;
|
|
|
c63e28 |
+ uint64_t remainder;
|
|
|
c63e28 |
+ if ((remainder = (want_size_kb % 1024)))
|
|
|
c63e28 |
+ want_size_kb = want_size_kb + 1024 - remainder;
|
|
|
c63e28 |
+
|
|
|
c63e28 |
+ log_warn("WARNING: metadata may not be usable with current io_memory_size %d KiB",
|
|
|
c63e28 |
+ io_memory_size());
|
|
|
c63e28 |
+ log_warn("WARNING: increase lvm.conf io_memory_size to at least %llu KiB",
|
|
|
c63e28 |
+ (unsigned long long)want_size_kb);
|
|
|
c63e28 |
+ }
|
|
|
c63e28 |
+
|
|
|
c63e28 |
dm_list_iterate_items_safe(devl, devl2, &all_devs) {
|
|
|
c63e28 |
dm_list_del(&devl->list);
|
|
|
c63e28 |
dm_free(devl);
|