#! /usr/bin/perl -I /etc/ppc64-diag
#
# This script is to be registered with servicelog as a notification tool.  It
# is responsible for performing whatever actions may be necessary following
# the migration of a  partition from one system to another.
#
# It is only invoked when an event with a refcode of #MIGRATE is logged.
# The DLPAR/virtualization tools automatically log such an event just after
# a partition is migrated to a new system.
#
# Copyright (C) 2008 IBM Corporation
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

# Update the VPD database with the dynamic VPD of the new system
if (-x "/usr/sbin/vpdupdate") {
	system("/usr/sbin/vpdupdate >/dev/null 2>&1");
} else {
	print STDERR "ppc64_diag_migrate: vpdupdate not found.\n";
}

# Force RMC to detect new management servers (HMCs, etc.)
if (-x "/usr/sbin/rsct/bin/refrsrc") {
	system("/usr/sbin/rsct/bin/refrsrc IBM.ManagementServer >/dev/null 2>&1");
} else {
	print STDERR "ppc64_diag_migrate: /usr/sbin/rsct/bin/refrsrc not found.\n";
}

# We should consider having this script go through and close
# any open serviceable events that are only applicable to the
# old hardware.  That opens up a few new questions, though:
# Do we reopen those events if the partition is migrated back
# to the old system?  What if there was a repair action on
# that old system which would fix one of the serviceable events
# that we are trying to reopen?  We'll skip it for now in favor
# of manual cleanup, if necessary.

