From: Michael Paquier <michael@paquier.xyz>
To: Andres Freund <andres@anarazel.de>
Cc: Postgres hackers <pgsql-hackers@postgresql.org>
Cc: Daniel Gustafsson <daniel@yesql.se>
Cc: Magnus Hagander <magnus@hagander.net>
Subject: Re: pgsql: Add TAP tests for pg_verify_checksums
Date: Fri, 12 Oct 2018 15:05:43 +0900
Message-ID: <20181012060543.GE30064@paquier.xyz> (raw)
In-Reply-To: <20181012031158.GD30064@paquier.xyz>
References: <E1gAl9R-00015q-Nl@gemulon.postgresql.org>
<20181012005614.GC26424@paquier.xyz>
<20181012010411.re53cwcistcpip5j@alap3.anarazel.de>
<20181012013918.GA30064@paquier.xyz>
<20181012015319.ezsb2cxb52ulbqgx@alap3.anarazel.de>
<20181012020758.GB30064@paquier.xyz>
<20181012024118.q3jwio7gf52nsrmm@alap3.anarazel.de>
<20181012031158.GD30064@paquier.xyz>
On Fri, Oct 12, 2018 at 12:11:58PM +0900, Michael Paquier wrote:
> Agreed. I am just working on a patch for v11- which uses a
> whitelist-based method instead of what is present now. Reverting the
> tests to put the buildfarm to green could be done, but that's not the
> root of the problem.
So, I have coded this thing, and finish with the attached. The
following file patterns are accepted for the checksums:
<digits>.<segment>
<digits>_<forkname>
<digits>_<forkname>.<segment>
I have added some tests on the way to make sure that all the patterns
get covered. Please note that this skips the temporary files.
Thoughts?
--
Michael
Attachments:checksum-whitelist.patch (text/x-diff, 3.3K) downloaddiff --git a/src/bin/pg_verify_checksums/pg_verify_checksums.c b/src/bin/pg_verify_checksums/pg_verify_checksums.cindex 1bc020ab6c..81abb021d9 100644--- a/src/bin/pg_verify_checksums/pg_verify_checksums.c+++ b/src/bin/pg_verify_checksums/pg_verify_checksums.c@@ -49,26 +49,64 @@ usage(void)
printf(_("Report bugs to <pgsql-bugs@postgresql.org>.\n"));
}
-static const char *const skip[] = {- "pg_control",- "pg_filenode.map",- "pg_internal.init",- "PG_VERSION",- NULL,-};-
static bool
skipfile(const char *fn)
{
- const char *const *f;+ int pos;+ int savepos;
if (strcmp(fn, ".") == 0 ||
strcmp(fn, "..") == 0)
return true;
- for (f = skip; *f; f++)- if (strcmp(*f, fn) == 0)+ /*----------+ * Only files including data checksums are authorized for scanning. This+ * is guessed based on the file name, by reverse-engineering+ * GetRelationPath so make sure to update both code paths if any updates+ * are done. The following file names are allowed: <digits>+ * <digits>.<segment>+ * <digits>_<forkname>+ * <digits>_<forkname>.<segment>+ *+ * Note that temporary files, beginning with 't', are also skipped.+ *+ *----------+ */++ /* A non-empty string of digits should follow */+ for (pos = 0; isdigit((unsigned char) fn[pos]); ++pos)+ ;+ /* good to go if only digits */+ if (fn[pos] == '\0')+ return false;+ /* leave if no digits */+ if (pos == 0)+ return true;++ /* VM and FSM files can be scanned */+ if (fn[pos] == '_')+ {+ if (strncmp(fn + pos + 1, "vm", 2) == 0)+ pos += 3;+ else if (strncmp(fn + pos + 1, "fsm", 3) == 0)+ pos += 4;+ else
return true;
+ }++ /* Check for an optional segment number */+ if (fn[pos] == '.')+ {+ savepos = pos + 1; /* count the dot */+ /* This should use only digits */+ for (pos = savepos; isdigit((unsigned char) fn[pos]); ++pos)+ ;+ if (fn[pos] != '\0')+ return true;+ }++ if (fn[pos] != '\0')+ return true;
return false;
}
diff --git a/src/bin/pg_verify_checksums/t/002_actions.pl b/src/bin/pg_verify_checksums/t/002_actions.plindex dc29da09af..6ad1d019f1 100644--- a/src/bin/pg_verify_checksums/t/002_actions.pl+++ b/src/bin/pg_verify_checksums/t/002_actions.pl@@ -17,6 +17,25 @@ command_like(['pg_controldata', $pgdata],
qr/Data page checksum version:.*1/,
'checksums enabled in control file');
+# Add set of dummy files with some contents. These should not be scanned+# by the tool.+append_to_file "$pgdata/global/123.12t", "foo";+append_to_file "$pgdata/global/foo", "foo2";+append_to_file "$pgdata/global/t123", "bar";+append_to_file "$pgdata/global/123a", "bar2";+append_to_file "$pgdata/global/.123", "foobar";+append_to_file "$pgdata/global/_fsm", "foobar2";+append_to_file "$pgdata/global/_vm.123", "foohoge";+append_to_file "$pgdata/global/123_vm.123t", "foohoge2";++# Those are correct but empty files, so they should pass through.+append_to_file "$pgdata/global/99999", "";+append_to_file "$pgdata/global/99999.123", "";+append_to_file "$pgdata/global/99999_vm", "";+append_to_file "$pgdata/global/99999_fsm", "";+append_to_file "$pgdata/global/99999_vm.123", "";+append_to_file "$pgdata/global/99999_fsm.123", "";+
# Checksums pass on a newly-created cluster
command_ok(['pg_verify_checksums', '-D', $pgdata],
"succeeds with offline cluster");
signature.asc (application/pgp-signature, 832B) download
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-committers@postgresql.org
Cc: michael@paquier.xyz, andres@anarazel.de, pgsql-hackers@postgresql.org, daniel@yesql.se, magnus@hagander.net
Subject: Re: pgsql: Add TAP tests for pg_verify_checksums
In-Reply-To: <20181012060543.GE30064@paquier.xyz>
References: <E1gAl9R-00015q-Nl@gemulon.postgresql.org> <20181012005614.GC26424@paquier.xyz> <20181012010411.re53cwcistcpip5j@alap3.anarazel.de> <20181012013918.GA30064@paquier.xyz> <20181012015319.ezsb2cxb52ulbqgx@alap3.anarazel.de> <20181012020758.GB30064@paquier.xyz> <20181012024118.q3jwio7gf52nsrmm@alap3.anarazel.de> <20181012031158.GD30064@paquier.xyz> <20181012060543.GE30064@paquier.xyz>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox