Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
pmirror: Add option --noatime
Open source file with O_NOATIME if option --noatime is given.

If pmirror is used for backup purpose, we don't want to trigger metadata
writes on the source filesystem. This needs to be optional, because
O_NOATIME only works for the owner of a file or for a privileged user.

As --cksum is implemented by an external command, we can't do this with
out potentially touching the access time.
  • Loading branch information
donald committed May 6, 2020
1 parent cfb7069 commit ecb847c
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions pmirror/pmirror
Expand Up @@ -155,7 +155,7 @@ use Getopt::Long;
use Sys::Hostname;
use IO::File;
use IO::Socket::INET;
use Fcntl ':mode';
use Fcntl qw(:mode O_NOATIME);
import My::Escaper;

use Time::HiRes;
Expand All @@ -172,7 +172,8 @@ our ($debug,$quiet,$fileop_noop,$fileop_debug,$delete);
our ($slave_mode,$local_slave,$slave_unprivileged,
$lockident,$safety,$identity_file,$mkdir_slave,
$reduce,$force_status,$bandwidth,$allowremotefs,
$ssh_opt , $cksum , $nice , $unix_socket, $unix_socket_name);
$ssh_opt , $cksum , $nice , $unix_socket, $unix_socket_name,
$noatime);

# globals

Expand Down Expand Up @@ -466,7 +467,7 @@ sub send_file
my $data_buf;
my $len;

my $fh=IO::File->new($filename,O_RDONLY);
my $fh=IO::File->new($filename, O_RDONLY + ($noatime ? O_NOATIME : 0) );
unless (defined $fh) {
# one reason to get here is that the file was deleted after it has been offered to
# and requested by the client.
Expand Down Expand Up @@ -1047,6 +1048,7 @@ usage: $0 [options] path [node:]path
--nice EXPERIMENTAL nice
--unix-socket EXPERIMENTAL establish data channel over ssh via AF unix sockets
--socket-name PATH EXPERIMENTAL use PATH as name for AF unix sockets
--noatime don't touch atime on sender
__EOF__

Expand Down Expand Up @@ -1075,13 +1077,17 @@ use constant OPTIONS => (
'nice' => \$nice,
'unix-socket' => \$unix_socket,
'socket-name=s' => \$unix_socket_name,
'noatime' => \$noatime,
);

if ($ENV{SSH_ORIGINAL_COMMAND}) {
($_,@ARGV)=split ' ',$ENV{SSH_ORIGINAL_COMMAND};
}

GetOptions(OPTIONS) or die USAGE;
if ($noatime && $cksum) {
die "$0: --cksum together with --noatime not implemented\n";
}

if ($nice) {
system "ionice -c idle -p $$ 2>/dev/null"
Expand Down

0 comments on commit ecb847c

Please sign in to comment.