From ad273af9c74403e2fa83426b573ed2f7e89d72db Mon Sep 17 00:00:00 2001 From: Mike Snitzer Date: Thu, 30 Jul 2009 17:19:31 +0000 Subject: [PATCH] Fix _mda_setup() to not check first mda's size before pe_align rounding. Without this fix rounding the end of the first mda to a pe_align boundary could silently exceed the disk_size. Final 'if (start1 + mda_size1 > disk_size)' block serves as a safety net. Signed-off-by: Mike Snitzer --- WHATS_NEW | 1 + lib/format_text/format-text.c | 23 ++++++++++++++++++----- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/WHATS_NEW b/WHATS_NEW index 27568728c..c35932eaa 100644 --- a/WHATS_NEW +++ b/WHATS_NEW @@ -1,5 +1,6 @@ Version 2.02.51 - ================================ + Fix _mda_setup() to not check first mda's size before pe_align rounding. Formalize pe_start policy as split between .pv_setup and .pv_write. Document -I option of clvmd in the man page. Fix configure script to handle multiple clvmd selections. diff --git a/lib/format_text/format-text.c b/lib/format_text/format-text.c index a5e6664c6..25839558c 100644 --- a/lib/format_text/format-text.c +++ b/lib/format_text/format-text.c @@ -1214,6 +1214,15 @@ static int _mda_setup(const struct format_type *fmt, start1 += (pagesize - mda_adjustment); } + /* Round up to pe_align boundary */ + mda_adjustment = (mda_size1 + start1) % alignment; + if (mda_adjustment) { + mda_size1 += (alignment - mda_adjustment); + /* Revert if it's now too large */ + if (start1 + mda_size1 > disk_size) + mda_size1 -= (alignment - mda_adjustment); + } + /* Ensure it's not going to be bigger than the disk! */ if (start1 + mda_size1 > disk_size) { log_warn("WARNING: metadata area fills disk leaving no " @@ -1221,15 +1230,19 @@ static int _mda_setup(const struct format_type *fmt, /* Leave some free space for rounding */ /* Avoid empty data area as could cause tools problems */ mda_size1 = disk_size - start1 - alignment * 2; + if (start1 + mda_size1 > disk_size) { + log_error("Insufficient space for first mda on %s", + pv_dev_name(pv)); + return 0; + } + /* Round up to pe_align boundary */ + mda_adjustment = (mda_size1 + start1) % alignment; + if (mda_adjustment) + mda_size1 += (alignment - mda_adjustment); /* Only have 1 mda in this case */ pvmetadatacopies = 1; } - /* Round up to pe_align() boundary */ - mda_adjustment = (mda_size1 + start1) % alignment; - if (mda_adjustment) - mda_size1 += (alignment - mda_adjustment); - /* If we already have PEs, avoid overlap */ if (pe_start || pe_end) { if (pe_start <= start1)