From 69d47e8f96e5e5182333e14d38148021bfd0417b Mon Sep 17 00:00:00 2001 From: Thomas Schoebel-Theuer Date: Wed, 8 Aug 2012 17:05:16 +0200 Subject: [PATCH] marsadm: implement leave-{cluster,resource} --- userspace/marsadm | 67 +++++++++++++++++++++++++++++++++++++---------- 1 file changed, 53 insertions(+), 14 deletions(-) diff --git a/userspace/marsadm b/userspace/marsadm index b70b7ec9..98c65c77 100644 --- a/userspace/marsadm +++ b/userspace/marsadm @@ -383,6 +383,13 @@ sub join_cluster { system("rsync --recursive --links -v $mars/ips/ $peer:$mars/ips/") == 0 or die "oops\n"; } +sub leave_cluster { + my ($cmd) = @_; + my $check = "/mars/resource-*/*-$host"; + die "I am member of some resources\n" if glob($check) && !$force; + _create_delete("$mars/ips/$host"); +} + sub create_res { my ($cmd, $res, $dev, $appear) = @_; my $create = ($cmd eq "create-resource"); @@ -505,6 +512,33 @@ sub create_res { } } +sub leave_res { + my ($cmd, $res) = @_; + check_not_primary(@_); + foreach my $tmp (glob("$mars/resource-$res/todo-$host/*")) { + my $status = readlink($tmp); + die "cannot read symlink '$tmp'\n" unless defined($status); + die "switch '$tmp' is not off\n" if $status; + } + foreach my $tmp (glob("$mars/resource-$res/actual-$host/*")) { + my $status = readlink($tmp); + die "cannot read symlink '$tmp'\n" unless defined($status); + die "running status '$tmp' is not off\n" if $status; + } + my $peerlink = "$mars/resource-$res/connect-$host"; + my $peer = readlink($peerlink) or die "cannot read symlink '$peerlink'\n"; + foreach my $tmp (glob("$mars/resource-$res/connect-*")) { + next if $tmp eq $peerlink; + my $target = readlink($tmp) or die "cannot read symlink '$tmp'\n"; + next unless $target eq $host; + print "changing '$tmp' from '$host' to '$peer'\n"; + unlink("$tmp.new"); + symlink($peer, "$tmp.new") or die "cannot create symlink '$tmp.new'\n"; + rename("$tmp.new", $tmp) or die "cannot create symlink '$tmp'\n"; + } + unlink($peerlink); +} + sub logrotate_res { my ($cmd, $res) = @_; check_primary(@_); @@ -739,20 +773,23 @@ sub helplist { $temp = shift; print "ERROR: $temp" if ($temp); print " -marsadm command resource [option] +marsadm [] [