Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1gAqaE-00066y-99 for pgsql-hackers@arkaria.postgresql.org; Fri, 12 Oct 2018 06:05:59 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gAqaC-00006U-8a for pgsql-hackers@arkaria.postgresql.org; Fri, 12 Oct 2018 06:05:56 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1gAqaA-00006I-9V for pgsql-hackers@lists.postgresql.org; Fri, 12 Oct 2018 06:05:56 +0000 Received: from out3-smtp.messagingengine.com ([66.111.4.27]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1gAqa5-0001GG-Dw for pgsql-hackers@postgresql.org; Fri, 12 Oct 2018 06:05:52 +0000 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 5128921F4C; Fri, 12 Oct 2018 02:05:48 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Fri, 12 Oct 2018 02:05:48 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paquier.xyz; h= date:from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=fm2; bh=FQIn/wDqeCykdZUaLNaS1D58n/w 6wQjTEXC+eD7Zc+o=; b=eroDnCexxN9AU7SvwHSwH67bH0ZXbbi1u9MpKvFUC/d Sjsfq4F152HVx+vYHG7ebSmlCTX3eRqO8atMQwzLQLnK0KvfKz6OEFhFT7gHWY5Q fxY/AsNjqG2uijlT9elXU8kjzad3ENgyowYNBHg3sBtzIgqOAAOq43OWVjXcT+aR /yCiOazT/eNVJ2KHDtuajIDFPLcmZLD1CYQmvoDTfkoyM2DOdNPBLYAsnd56n1CO gB81qWpvyU9jU5SGaxkgEW0IHDZVOHiu60BdCV97cWJa1PGw4G54zbR71gETsoI1 giSCtPGu53f8/Y0p4S5NFqOG39HMU/4m+2WTZklesyg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=FQIn/w DqeCykdZUaLNaS1D58n/w6wQjTEXC+eD7Zc+o=; b=kCyKd/Y/oZZ2jSdEF8fPgS h+5SoiOQcb2pw5r6JCHG9QCI3RV5RZEfU05e1I6QPRrilHNmfuzhlCHjZyQrqFL9 O2E6rVvVIWKgQ0E23/X/WLzl3gLQrH00W10At8oyscXn/wNPdd6WNGK8TPeAd/9s VpzgQ03F9ILdiKbrV3LZnr0XW2ebrVeo0TNb+UhHwgNjDRrWp4/79BdKmzj1TCPT bVJyNn1MTIiyezKV+eWRl62KxuNHOSSJhjgmnENDx3oG47UG3xv/HkpFDbtTn5Td STDKlqpXtbDEkf7x/+26zxAjalLE1o69VCrfDbwuk2ZYBhNE1k+/HVy7Yf/hjaOw == X-ME-Sender: X-ME-Proxy: Received: from paquier.xyz (mp76f1fb18.ap.nuro.jp [118.241.251.24]) by mail.messagingengine.com (Postfix) with ESMTPA id CF8E0102D5; Fri, 12 Oct 2018 02:05:45 -0400 (EDT) Date: Fri, 12 Oct 2018 15:05:43 +0900 From: Michael Paquier To: Andres Freund Cc: Postgres hackers , Daniel Gustafsson , Magnus Hagander Subject: Re: pgsql: Add TAP tests for pg_verify_checksums Message-ID: <20181012060543.GE30064@paquier.xyz> References: <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> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="CNfT9TXqV7nd4cfk" Content-Disposition: inline In-Reply-To: <20181012031158.GD30064@paquier.xyz> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --CNfT9TXqV7nd4cfk Content-Type: multipart/mixed; boundary="gvF4niNJ+uBMJnEh" Content-Disposition: inline --gvF4niNJ+uBMJnEh Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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: . _ _. 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 --gvF4niNJ+uBMJnEh Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="checksum-whitelist.patch" Content-Transfer-Encoding: quoted-printable diff --git a/src/bin/pg_verify_checksums/pg_verify_checksums.c b/src/bin/pg= _verify_checksums/pg_verify_checksums.c index 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 .\n")); } =20 -static const char *const skip[] =3D { - "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; =20 if (strcmp(fn, ".") =3D=3D 0 || strcmp(fn, "..") =3D=3D 0) return true; =20 - for (f =3D skip; *f; f++) - if (strcmp(*f, fn) =3D=3D 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: + * . + * _ + * _. + * + * Note that temporary files, beginning with 't', are also skipped. + * + *---------- + */ + + /* A non-empty string of digits should follow */ + for (pos =3D 0; isdigit((unsigned char) fn[pos]); ++pos) + ; + /* good to go if only digits */ + if (fn[pos] =3D=3D '\0') + return false; + /* leave if no digits */ + if (pos =3D=3D 0) + return true; + + /* VM and FSM files can be scanned */ + if (fn[pos] =3D=3D '_') + { + if (strncmp(fn + pos + 1, "vm", 2) =3D=3D 0) + pos +=3D 3; + else if (strncmp(fn + pos + 1, "fsm", 3) =3D=3D 0) + pos +=3D 4; + else return true; + } + + /* Check for an optional segment number */ + if (fn[pos] =3D=3D '.') + { + savepos =3D pos + 1; /* count the dot */ + /* This should use only digits */ + for (pos =3D savepos; isdigit((unsigned char) fn[pos]); ++pos) + ; + if (fn[pos] !=3D '\0') + return true; + } + + if (fn[pos] !=3D '\0') + return true; return false; } =20 diff --git a/src/bin/pg_verify_checksums/t/002_actions.pl b/src/bin/pg_veri= fy_checksums/t/002_actions.pl index 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'); =20 +# 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"); --gvF4niNJ+uBMJnEh-- --CNfT9TXqV7nd4cfk Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAlvAObcACgkQnvQgOdby QH2DGg/7B98UGfCimVgoI+vEk8DzyyuMakhD4oaf8Q4IwSWn61nK+L85v+ulv5Xb X+0H+wr1DfSzTxP+r1bScrpp9wEgqOwc6mlZgaWrQAExe9GDduW1jQueiOwyNmp9 GeWlotqIKMMFl7i70hYb3mxclxgnGE/GyBwQkhyKQWauhdFNfOi6xbEidK36KCi9 PjouEEBmst20f8bjmud7m5mwWK61OB38LmAf4NpXZl+x3Wu+4r3sgdEFbJv/S8Dl +fmMZdNB9RobhG7SJO6HpyHY+itqhM20VuL5IANQs4gmNEUJhjJNpYcdrFrF5cNb y79FpFUrZuvRaI5/kSZ0Oq7bmsrl3azUNA7VypODqs6sXxCeupF3Bq9ay2Nfters BEUanX+17fhi2G0O7I0a9lDe03Xjg6rnDc2Fj+sD+tfMmANV6MXbkuIPkEod7S7b 6zX6L/RplRRq70aZA9o/lsBkXqmD/S/Hoo5NuYN5JySBzGRZjK/TKLJ6sd9UNeGi oIH7rOR98CQ8VSqjSNe74p2dKu6TcuLknAKlI0M6ZwoYbk/0DM5me2k8VjEba/Xz KXQ25gOri7kgBhpvTYJv0gazRzoJ0V2nUBWDHRJOpctHzheLnGDkobTKVq85ijWE a3qfT+/h5ft80tz8BpdzQu6ZUx/snA+VJ8pG6pZMTJBTxRNkQ2U= =N2Kz -----END PGP SIGNATURE----- --CNfT9TXqV7nd4cfk--