From 6ca8df2d61473327b0e90b9becfe109299f47b8a Mon Sep 17 00:00:00 2001 From: Thomas Munro Date: Thu, 13 Apr 2023 13:47:39 +1200 Subject: [PATCH] Skip the 004_io_direct.pl test if a pre-flight check fails. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The test previously had a list of OSes that direct I/O was expected to work on. That worked well enough for the systems in our build farm, but didn't survive contact with the Debian build bots running on tmpfs via overlayfs. tmpfs does not support O_DIRECT, but we don't want to exclude Linux generally. The new approach is to try to create an empty file with O_DIRECT from Perl first. If that fails, we'll skip the test and report what the error was. Reported-by: Christoph Berg Reviewed-by: Dagfinn Ilmari Mannsåker Reviewed-by: Andrew Dunstan Discussion: https://postgr.es/m/ZDYd4A78cT2ULxZZ%40msg.df7cb.de --- src/test/modules/test_misc/t/004_io_direct.pl | 35 ++++++++++++++----- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/src/test/modules/test_misc/t/004_io_direct.pl b/src/test/modules/test_misc/t/004_io_direct.pl index 5a2dd0d288..b8814bb640 100644 --- a/src/test/modules/test_misc/t/004_io_direct.pl +++ b/src/test/modules/test_misc/t/004_io_direct.pl @@ -2,19 +2,38 @@ use strict; use warnings; +use Fcntl; +use IO::File; use PostgreSQL::Test::Cluster; use PostgreSQL::Test::Utils; use Test::More; -# Systems that we know to have direct I/O support, and whose typical local -# filesystems support it or at least won't fail with an error. (illumos should -# probably be in this list, but perl reports it as solaris. Solaris should not -# be in the list because we don't support its way of turning on direct I/O, and -# even if we did, its version of ZFS rejects it, and OpenBSD just doesn't have -# it.) -if (!grep { $^O eq $_ } qw(aix darwin dragonfly freebsd linux MSWin32 netbsd)) +# We know that macOS has F_NOCACHE, and we know that Windows has +# FILE_FLAG_NO_BUFFERING, and we assume that their typical file systems will +# accept those flags. For every other system, we'll probe for O_DIRECT +# support. + +if ($^O ne 'darwin' && $^O ne 'MSWin32') { - plan skip_all => "no direct I/O support"; + # Perl's Fcntl module knows if this system has O_DIRECT in . + if (defined &O_DIRECT) + { + # Can we open a file in O_DIRECT mode in the file system where + # tmp_check lives? + my $f = IO::File->new( + "${PostgreSQL::Test::Utils::tmp_check}/test_o_direct_file", + O_RDWR | O_DIRECT | O_CREAT); + if (!$f) + { + plan skip_all => + "pre-flight test if we can open a file with O_DIRECT failed: $!"; + } + $f->close; + } + else + { + plan skip_all => "no O_DIRECT"; + } } my $node = PostgreSQL::Test::Cluster->new('main');