Skip to content

Commit

Permalink
Merge pull request #12715 from roosterfish/rsync_consistency
Browse files Browse the repository at this point in the history
Use rsync flags consistently for local and remote copy
  • Loading branch information
tomponline authored Jan 18, 2024
2 parents 4f60b9a + 58aaef4 commit 4f9b618
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lxd/rsync/rsync.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,9 @@ func LocalCopy(source string, dest string, bwlimit string, xattrs bool, rsyncArg
"--sparse",
"--devices",
"--delete",
"--checksum",
"--numeric-ids",
// Checks for file modifications on nanoseconds granularity.
"--modify-window=-1",
}

if xattrs {
Expand Down Expand Up @@ -316,6 +317,9 @@ func Recv(path string, conn io.ReadWriteCloser, tracker *ioprogress.ProgressTrac
"--devices",
"--partial",
"--sparse",
// This flag is only required on the receiving end.
// Checks for file modifications on nanoseconds granularity.
"--modify-window=-1",
}

if len(features) > 0 {
Expand Down
40 changes: 40 additions & 0 deletions test/suites/migration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -292,9 +292,49 @@ migration() {
lxc_remote copy l1:c1 l2:c2 --refresh
lxc_remote start l2:c2
lxc_remote file pull l2:c2/root/testfile1 .
[ "$(cat testfile1)" = "test" ]
rm testfile1
lxc_remote stop -f l2:c2

# Change the files modification time by adding one nanosecond.
# Perform the change on the test runner since the busybox instances `touch` doesn't support setting nanoseconds.
lxc_remote start l1:c1
c1_pid="$(lxc_remote query l1:/1.0/instances/c1?recursion=1 | jq -r .state.pid)"
mtime_old="$(stat -c %y "/proc/${c1_pid}/root/root/testfile1")"
mtime_old_ns="$(date -d "$mtime_old" +%N | sed 's/^0*//')"

# Ensure the final nanoseconds are padded with zeros to create a valid format.
mtime_new_ns="$(printf "%09d\n" "$((mtime_old_ns+1))")"
mtime_new="$(date -d "$mtime_old" "+%Y-%m-%d %H:%M:%S.${mtime_new_ns} %z")"
lxc_remote stop -f l1:c1

# Before setting the new mtime create a local copy too.
lxc_remote copy l1:c1 l1:c2

# Change the modification time.
lxc_remote start l1:c1
c1_pid="$(lxc_remote query l1:/1.0/instances/c1?recursion=1 | jq -r .state.pid)"
touch -m -d "$mtime_new" "/proc/${c1_pid}/root/root/testfile1"
lxc_remote stop -f l1:c1

# Starting from rsync 3.1.3 it should discover the change of +1 nanosecond.
# Check if the file got refreshed to a different remote.
lxc_remote copy l1:c1 l2:c2 --refresh
lxc_remote start l1:c1 l2:c2
c1_pid="$(lxc_remote query l1:/1.0/instances/c1?recursion=1 | jq -r .state.pid)"
c2_pid="$(lxc_remote query l2:/1.0/instances/c2?recursion=1 | jq -r .state.pid)"
[ "$(stat "/proc/${c1_pid}/root/root/testfile1" -c %y)" = "$(stat "/proc/${c2_pid}/root/root/testfile1" -c %y)" ]
lxc_remote stop -f l1:c1 l2:c2

# Check if the file got refreshed locally.
lxc_remote copy l1:c1 l1:c2 --refresh
lxc_remote start l1:c1 l1:c2
c1_pid="$(lxc_remote query l1:/1.0/instances/c1?recursion=1 | jq -r .state.pid)"
c2_pid="$(lxc_remote query l1:/1.0/instances/c2?recursion=1 | jq -r .state.pid)"
[ "$(stat "/proc/${c1_pid}/root/root/testfile1" -c %y)" = "$(stat "/proc/${c2_pid}/root/root/testfile1" -c %y)" ]
lxc_remote rm -f l1:c2
lxc_remote stop -f l1:c1

# This will create snapshot c1/snap0 with test device and expiry date.
lxc_remote config device add l1:c1 testsnapdev none
lxc_remote config set l1:c1 snapshots.expiry '1d'
Expand Down

0 comments on commit 4f9b618

Please sign in to comment.