From e1c51d6649f86dd0a6e4ee33f65eb9351ef126a5 Mon Sep 17 00:00:00 2001 From: Thomas Schoebel-Theuer Date: Tue, 29 Mar 2022 17:18:32 +0200 Subject: [PATCH] marsadm: prefer backup IPs for lowlevel-set-host --- userspace/marsadm | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/userspace/marsadm b/userspace/marsadm index 924b9489..538ee188 100755 --- a/userspace/marsadm +++ b/userspace/marsadm @@ -4518,6 +4518,21 @@ sub _writable { chmod($newmode, $path) == 1 or ldie "cannot chmod '$path'\n"; } +sub _get_backup_ip { + my ($peer, $ignore_missing_ip) = @_; + $peer = $host unless $peer; + my $backup_glob = "$mars/backups-*/ips-backup/ip-$peer"; + foreach my $backup (sort reverse_cmp lamport_glob($backup_glob)) { + my $check = get_link($backup, 2); + if ($check) { + lprint_stderr "Using BACKUP IP '$check' from '$backup'\n" if $verbose; + $known_ips{$peer} = $check; + return $check; + } + } + return ""; +} + sub _get_ip { my ($peer, $ignore_missing_ip) = @_; $peer = $host unless $peer; @@ -4539,15 +4554,8 @@ sub _get_ip { return $probe_link; } # Try the backups in reverse order - my $backup_glob = "$mars/backups-*/ips-backup/ip-$peer"; - foreach my $backup (sort reverse_cmp lamport_glob($backup_glob)) { - my $check = get_link($backup, 2); - if ($check) { - lprint_stderr "Using BACKUP IP '$check' from '$backup'\n" if $verbose; - $known_ips{$peer} = $check; - return $check; - } - } + my $found_backup = _get_backup_ip(@_); + return $found_backup if $found_backup; # Try /usr/bin/getent first my $answer = `/usr/bin/getent hosts '$peer'`; chomp $answer; @@ -4655,6 +4663,9 @@ sub lowlevel_ls_host_ips { sub lowlevel_set_host_ip { my ($cmd, $peer, $ip) = @_; check_id($peer, 0, 1); + if (!$ip) { + $ip = _get_backup_ip($peer); + } if (!$ip) { $ip = _get_ip($peer); }