}
}
+# returns "0 but true" on success, undef or
sub nodatacow_fh ($) {
my ($fh) = @_;
my $buf = "\0" x 120;
warn("FS_IOC_SETFLAGS: $!\n");
}
-sub nodatacow_dir {
- if (open my $fh, '<', $_[0]) { nodatacow_fh($fh) }
+sub nodatacow_dir ($) {
+ my ($f) = @_;
+ if (open my $fh, '<', $f) {
+ my $rc = nodatacow_fh($fh); # returns "0 but true" on success
+ $rc && $rc == 0 and warn <<EOM;
+W: Disabling copy-on-write (CoW) on `$f'
+W: to avoid pathological slowdowns. Data corruption may occur on unclean
+W: shutdowns, especially if using any form of BTRFS RAID. Periodic defrag
+W: is recommended for *.sqlite3 and *.glass files to maintain performance.
+EOM
+ }
}
use constant \%CONST;
$name = "$dn/pp.d";
mkdir($name) or BAIL_OUT "mkdir($name) $!";
- PublicInbox::Syscall::nodatacow_dir($name);
+
+ {
+ my @w;
+ local $SIG{__WARN__} = sub { push @w, @_ };
+ PublicInbox::Syscall::nodatacow_dir($name);
+ like "@w", qr/^W: Disabling copy-on-write/sm,
+ 'warned about disabling CoW';
+ }
$res = xqx([$lsattr, '-d', $name]);
like($res, qr/C.*\Q$name\E/, "`C' attribute set on dir with pure Perl");
+ {
+ my @w;
+ local $SIG{__WARN__} = sub { push @w, @_ };
+ PublicInbox::Syscall::nodatacow_dir($name);
+ is_deeply \@w, [], 'no warnings if CoW already disabled';
+ }
};
done_testing;