sg247039

sg247039

A

Appendix A.

Dynamic logical partitioning program templates

򐂰

򐂰

򐂰

This appendix provides the following sample dynamic logical partitioning

(DLPAR) program templates:

“Perl template” on page 233

“Korn shell template” on page 245

“DLPAR-aware application using a signal handler” on page 257

These templates are provided as samples to integrate DLPAR operations into your applications.

© Copyright IBM Corp. 2003, 2004, 2005. All rights reserved.

231

General information

If you can access the source code of your application, see the last template example to make your applications DLPAR-aware.

If not, you can choose your favorite programming language from Perl, Korn shell, and the C language in order to integrate DLPAR operations into your applications. The first two templates are slightly modified from the files originally installed in the /usr/samples/dr/scripts directory on AIX 5L Version 5.2 to add a debug output facility and insert comments for readability. The original template files are included in the bos.adt.samples fileset, as shown in the following example:

# lslpp -w /usr/samples/dr/scripts/IBM_template.*

File Fileset Type

----------------------------------------------------------------------------

/usr/samples/dr/scripts/IBM_template.c bos.adt.samples File

/usr/samples/dr/scripts/IBM_template.pl bos.adt.samples File

/usr/samples/dr/scripts/IBM_template.sh bos.adt.samples File

# lslpp -L bos.adt.samples

Fileset Level State Type Description (Uninstaller)

----------------------------------------------------------------------------

bos.adt.samples 5.2.0.0 C F Base Operating System

Samples

Note: Some scripts in the /usr/samples/dr/scripts directory are provided to

demonstrate error situations. For example, IBM_XYZ_fail_dr_2.sh generates the AIX error log shown in Example A-1 in a CPU removal DLPAR event. You should carefully read the readme file in this directory before registering these scripts.

Example: A-1 DR_UNSAFE_PROCESS

LABEL: DR_UNSAFE_PROCESS

IDENTIFIER: 0E2A04B4

Date/Time: Fri Nov 15 11:04:17 CST

Sequence Number: 114

Machine Id: 0021768A4C00

Node Id: lpar01

Class: S

Type: INFO

Resource Name: SYSPROC

Description

DR Unsafe application

Detail Data

Process ID

30499421762355200

232

Partitioning Implementations for IBM

E server

p5 Servers

Perl template

Example A-2 provides the Perl version of the DLPAR script template. System

administrators can use it as a starting point when integrating DLPAR operations into your applications.

The script is added a file handle, DBG, to be used to print debug information to the debug file, /tmp/IBM_template.pl.dbg. The debug information is very helpful when you have to debug your DLPAR script, because the script should not print any undefined name-value pairs to the standard out.

To display the debug information sent to the file, enter the following command:

$ tail -f /tmp/IBM_template.pl.dbg

Example: A-2 DLPAR script template: Perl

#!/usr/bin/perl

# (C) COPYRIGHT International Business Machines Corp. 2000, 2002

# All Rights Reserved

# Licensed Materials - Property of IBM

#

# US Government Users Restricted Rights - Use, duplication or

# disclosure restricted by GSA ADP Schedule Contract with IBM Corp.

#

# FILE NAME: IBM_template.pl

#

# FILE DESCRIPTION:

# This perl script will provide a template for DLPAR script developers

# to develop their custom perl scripts.

#

# It is the basic test script. It implements all the commands of DLPAR

# script and for all them returns success. It identifies itself with

# distinct details.

#----------------------------------------------------------------------

# GLOBAL OBJECTS

#----------------------------------------------------------------------

# This hash contains the required commands specified in the DRAF.

# The values assigned to each command is irrelevant. The script

# converts the text into a number for quick accessing

%DR_script_commands = (

scriptinfo => 1,

register => 2,

usage => 3,

checkrelease => 4,

prerelease => 5,

Appendix A. Dynamic logical partitioning program templates

233

postrelease => 6,

undoprerelease => 7,

checkacquire => 8,

preacquire => 9,

postacquire => 10,

undopreacquire => 11

);

# This hash contains data used by the scriptinfo command. It lists

# required information about the script

%SCRIPT_DATA = (

SCRIPT_INFO => “AIX “,

SCRIPT_VERSION => “1”,

SCRIPT_VENDOR => “IBM Corp.”,

SCRIPT_TIMEOUT => 5

);

# This hash contains the resources for which the script will register.

# In this case, this script wants to register for DR operations that

# involve memory and cpu events.

%REGISTER_DATA = (

CPU_RESOURCE => “cpu”,

MEM_RESOURCE => “mem”

);

# This hash contains usage descriptions for each possible resource.

%USAGE_DATA = (

CPU_USAGE => “Testing DLPAR on CPU resource”,

MEM_USAGE => “Testing DLPAR on MEM resource”

);

#----------------------------------------------------------------------

# Helper Functions

#----------------------------------------------------------------------

#======================================================================

# Name: str_to_cmd

#

# Description: converts a string to a command value

#

# Input: command string

#

# Output: logically mapped command value

#

# Return Code: None

#====================================================================== sub str_to_cmd {

$s_cmd = $_[0];

$DR_script_commands{$s_cmd};

}

234

Partitioning Implementations for IBM

E server

p5 Servers

#----------------------------------------------------------------------

# Required DRAF commands

#----------------------------------------------------------------------

#======================================================================

# Name: process_scriptinfo

#

# Description: returns information about the script

#

# Input: none

#

# Output: name-value pairs

#

# Return Code: 0 = success

# 1 = failure

#====================================================================== sub process_scriptinfo {

print “DR_SCRIPTINFO=$SCRIPT_DATA{SCRIPT_INFO}\n”;

print “DR_VERSION=$SCRIPT_DATA{SCRIPT_VERSION}\n”;

print “DR_DATE=19042002\n”;

print “DR_VENDOR=$SCRIPT_DATA{SCRIPT_VENDOR}\n”;

print “DR_TIMEOUT=$SCRIPT_DATA{SCRIPT_TIMEOUT}\n”;

0;

}

#======================================================================

# Name: process_scriptinfo

#

# Description: returns information about the script

#

# Input: none

#

# Output: name-value pairs

#

# Return Code: 0 = success

# 1 = failure

#====================================================================== sub process_register {

foreach $key ( keys %REGISTER_DATA){

print “DR_RESOURCE=$REGISTER_DATA{$key}\n”;

}

0;

}

#======================================================================

Appendix A. Dynamic logical partitioning program templates

235

# Name: process_usage

#

# Description: returns usage information about the script

#

# Input: resource

#

# Output: name-value pairs

#

# Return Code: 0 = success

# 1 = failure

#====================================================================== sub process_usage {

$l_rc = 0;

$res = $_[0];

USE_SWITCH: {

if ($res eq $REGISTER_DATA{CPU_RESOURCE}) {

print “DR_USAGE=$USAGE_DATA{CPU_USAGE}\n”;

last USE_SWITCH;

}

if ($res eq $REGISTER_DATA{MEM_RESOURCE}) {

print “DR_USAGE=$USAGE_DATA{MEM_USAGE}\n”;

last USE_SWITCH;

}

print “DR_ERROR=script does not use resource $res\n”;

$l_rc = 1;

}

return $l_rc;

}

#======================================================================

# Name: process_checkrelease

#

# Description: verifies a resource can be removed without compromises

# the application.

#

# Input: resource

#

# Output: Any DR_ERROR=description or DR_LOG_DEBUG=description variables

#

# Return Code: 0 = success

# 1 = failure

#====================================================================== sub process_checkrelease {

$l_rc = 0;

$res = $_[0];

236

Partitioning Implementations for IBM

E server

p5 Servers

print DBG “-- start checkrelease phase --\n”;

foreach $key (sort keys %ENV) {

if ($key =~ /^DR_/) {

print DBG $key, ‘=’, $ENV{$key}, “\n”;

}

}

USE_SWITCH: {

if ($res eq $REGISTER_DATA{CPU_RESOURCE}) {

# perform all cpu related checks here and determine

# if resource remove can proceed.

last USE_SWITCH;

}

if ($res eq $REGISTER_DATA{MEM_RESOURCE}) {

# perform all memu related checks here and determine

# if resource remove can proceed.

last USE_SWITCH;

}

print “DR_ERROR=script does not use resource $res\n”;

$l_rc = 1;

}

print DBG “-- end checkrelease phase --\n”;

return $l_rc;

}

#======================================================================

# Name: process_prerelease

#

# Description: Prepares for the resource to be removed

#

# Input: resource

#

# Output: Any DR_ERROR=description or DR_LOG_DEBUG=description variables

#

# Return Code: 0 = success

# 1 = failure

#====================================================================== sub process_prerelease {

$l_rc = 0;

$res = $_[0];

print DBG “-- start prerelease phase --\n”;

foreach $key (sort keys %ENV) {

if ($key =~ /^DR_/) {

print DBG $key, ‘=’, $ENV{$key}, “\n”;

}

Appendix A. Dynamic logical partitioning program templates

237

}

# before we allow DR manager to proceed, we can do any prerelease

# actions here. For instance, we could send a signal from here

# and wait for the application to take some action.

# resource specific actions

USE_SWITCH: {

if ($res eq $REGISTER_DATA{CPU_RESOURCE}) {

# release any cpu bindings, etc. here if the resource

# is being used by the application.

last USE_SWITCH;

}

if ($res eq $REGISTER_DATA{MEM_RESOURCE}) {

# release any application hold over memory, etc, that

# is being removed.

last USE_SWITCH;

}

print “DR_ERROR=script does not use resource $res\n”;

$l_rc = 1;

}

print DBG “-- end prerelease phase --\n”;

return $l_rc;

}

#======================================================================

# Name: process_undoprerelease

#

# Description: Invoked to undo any changes done by the prerelease

# command.

#

# Input: resource

#

# Output: Any DR_ERROR=description or DR_LOG_DEBUG=description variables

#

# Return Code: 0 = success

# 1 = failure

#====================================================================== sub process_undoprerelease {

$l_rc = 0;

$res = $_[0];

# perform any actions here which were performed in the prerelease

# command.

print DBG “-- start undoprerelease phase --\n”;

foreach $key (sort keys %ENV) {

238

Partitioning Implementations for IBM

E server

p5 Servers

if ($key =~ /^DR_/) {

print DBG $key, ‘=’, $ENV{$key}, “\n”;

}

}

# resource specific actions

USE_SWITCH: {

if ($res eq $REGISTER_DATA{CPU_RESOURCE}) {

# undo cpu related changes done by the prerelease cmd

last USE_SWITCH;

}

if ($res eq $REGISTER_DATA{MEM_RESOURCE}) {

# undo mem related changes done by the prerelease cmd

last USE_SWITCH;

}

print “DR_ERROR=script does not use resource $res\n”;

$l_rc = 1;

}

print DBG “-- end undoprerelease phase --\n”;

return $l_rc;

}

#======================================================================

# Name: process_postrelease

#

# Description: After the resource is removed, this command makes

# necessary adjustments

#

# Input: resource

#

# Output: Any DR_ERROR=description or DR_LOG_DEBUG=description variables

#

# Return Code: 0 = success

# 1 = failure

#====================================================================== sub process_postrelease {

$l_rc = 0;

$res = $_[0];

# reacquire any resource released during prerelease

# activate any applications quieced during prerelease.

print DBG “-- start postrelease phase --\n”;

foreach $key (sort keys %ENV) {

if ($key =~ /^DR_/) {

print DBG $key, ‘=’, $ENV{$key}, “\n”;

Appendix A. Dynamic logical partitioning program templates

239

}

}

# resource specific actions

USE_SWITCH: {

if ($res eq $REGISTER_DATA{CPU_RESOURCE}) {

# perform cpu related actions.

last USE_SWITCH;

}

if ($res eq $REGISTER_DATA{MEM_RESOURCE}) {

# perform mem related actions.

last USE_SWITCH;

}

print “DR_ERROR=script does not use resource $res\n”;

$l_rc = 1;

}

print DBG “-- end postrelease phase --\n”;

return $l_rc;

}

#======================================================================

# Name: process_checkacquire

#

# Description: verifies a resource can be added withouth

# compromising the application or system.

#

# Input: resource

#

# Output: Any DR_ERROR=description or DR_LOG_DEBUG=description variables

#

# Return Code: 0 = success

# 1 = failure

#====================================================================== sub process_checkacquire {

$l_rc = 0;

$res = $_[0];

print DBG “-- start checkacquire phase --\n”;

foreach $key (sort keys %ENV) {

if ($key =~ /^DR_/) {

print DBG $key, ‘=’, $ENV{$key}, “\n”;

}

}

# resource specific actions

USE_SWITCH: {

if ($res eq $REGISTER_DATA{CPU_RESOURCE}) {

240

Partitioning Implementations for IBM

E server

p5 Servers

# perform all cpu related checks here and determine

# if resource addition can proceed.

print DBG “cpu resources: logical $ENV{DR_LCPUID}, bind $ENV{DR_BCPUID}\n”;

if ($END{DR_LCPUID} eq 2) {

$l_rc = 1;

}

last USE_SWITCH;

}

if ($res eq $REGISTER_DATA{MEM_RESOURCE}) {

# perform all mem related checks here and determine

# if resource addition can proceed.

print DBG “mem resources: $ENV{DR_MEM_SIZE_REQUEST}\n”;

last USE_SWITCH;

}

print “DR_ERROR=script does not use resource $res\n”;

$l_rc = 1;

}

print DBG “-- end checkacquire phase --\n”;

return $l_rc;

}

#======================================================================

# Name: process_preacquire

#

# Description: prepares application before the resource is added

#

# Input: resource

#

# Output: Any DR_ERROR=description or DR_LOG_DEBUG=description variables

#

# Return Code: 0 = success

# 1 = failure

#====================================================================== sub process_preacquire {

$l_rc = 0;

$res = $_[0];

print DBG “-- start preacquire phase --\n”;

foreach $key (sort keys %ENV) {

if ($key =~ /^DR_/) {

print DBG $key, ‘=’, $ENV{$key}, “\n”;

}

}

# resource specific actions

USE_SWITCH: {

if ($res eq $REGISTER_DATA{CPU_RESOURCE}) {

Appendix A. Dynamic logical partitioning program templates

241

# Prepare application for cpu additions.

last USE_SWITCH;

}

if ($res eq $REGISTER_DATA{MEM_RESOURCE}) {

# Prepare application for memory additions.

last USE_SWITCH;

}

print “DR_ERROR=script does not use resource $res\n”;

$l_rc = 1;

}

print DBG “-- end preacquire phase --\n”;

return $l_rc;

}

#======================================================================

# Name: process_undopreacquire

#

# Description: If a failure occues, this will undo any changes made by

# the preacquire command.

#

# Input: resource

#

# Output: Any DR_ERROR=description or DR_LOG_DEBUG=description variables

#

# Return Code: 0 = success

# 1 = failure

#====================================================================== sub process_undopreacquire {

$l_rc = 0;

$res = $_[0];

print DBG “-- start undopreacquire phase --\n”;

foreach $key (sort keys %ENV) {

if ($key =~ /^DR_/) {

print DBG $key, ‘=’, $ENV{$key}, “\n”;

}

}

# resource specific actions

USE_SWITCH: {

if ($res eq $REGISTER_DATA{CPU_RESOURCE}) {

# undo cpu actions taken in the preacquire command.

last USE_SWITCH;

}

if ($res eq $REGISTER_DATA{MEM_RESOURCE}) {

# undo mem actions taken in the preacquire command.

242

Partitioning Implementations for IBM

E server

p5 Servers

last USE_SWITCH;

}

print “DR_ERROR=script does not use resource $res\n”;

$l_rc = 1;

}

print DBG “-- end undopreacquire phase --\n”;

return $l_rc;

}

#======================================================================

# Name: process_postacquire

#

# Description: After a resource has been added, this will perform any

# necessary actions.

#

# Input: resource

#

# Output: Any DR_ERROR=description or DR_LOG_DEBUG=description variables

#

# Return Code: 0 = success

# 1 = failure

#====================================================================== sub process_postacquire {

$l_rc = 0;

$res = $_[0];

print DBG “-- start undopreacquire phase --\n”;

foreach $key (sort keys %ENV) {

if ($key =~ /^DR_/) {

print DBG $key, ‘=’, $ENV{$key}, “\n”;

}

}

# resource specific actions

USE_SWITCH: {

if ($res eq $REGISTER_DATA{CPU_RESOURCE}) {

# Perform actions to allow the application to adjust to a

# cpu addition such as adding more threads, etc.

last USE_SWITCH;

}

if ($res eq $REGISTER_DATA{MEM_RESOURCE}) {

# Perform actions to allow the application to adjust to a

# memory addition such as increasing memory areas reserved

# for application, etc.

last USE_SWITCH;

}

Appendix A. Dynamic logical partitioning program templates

243

print “DR_ERROR=script does not use resource $res\n”;

$l_rc = 1;

}

print DBG “-- end undopreacquire phase --\n”;

return $l_rc;

}

#----------------------------------------------------------------------

# Main Program

#----------------------------------------------------------------------

# because we should only write the specified name-value

# pairs in the DRAF, we should print debug information

# to a file. open (DBG, “>>/tmp/IBM_template.pl.dbg”);

# This block processes the command line inputs.

ARG_SWITCH: {

if ($#ARGV == -1) { $rc = -1; last ARG_SWITCH; }

if ($#ARGV == 0) { $command_str = $ARGV[0] ; last ARG_SWITCH; }

if ($#ARGV == 1) { $command_str = $ARGV[0]; $res_name = $ARGV[1]; last ARG_SWITCH; }

$rc = -2;

}

# Convert the string to a command.

$command = str_to_cmd $command_str;

#This block invokes the proper function to handle the command

CMD_SWITCH: {

if ($command == ‘’) {$rc = 10; print “DR_ERROR=command not supported\n”; last CMD_SWITCH }

if ($command == 1) {$rc = process_scriptinfo; last CMD_SWITCH }

if ($command == 2) {$rc = process_register; last CMD_SWITCH }

if ($command == 3) {$rc = process_usage $res_name; last CMD_SWITCH }

if ($command == 4) {$rc = process_checkrelease $res_name; last CMD_SWITCH }

if ($command == 5) {$rc = process_prerelease $res_name; last CMD_SWITCH }

if ($command == 6) {$rc = process_postrelease $res_name; last CMD_SWITCH }

if ($command == 7) {$rc = process_undoprerelease $res_name; last CMD_SWITCH }

if ($command == 8) {$rc = process_checkacquire $res_name; last CMD_SWITCH }

if ($command == 9) {$rc = process_preacquire $res_name; last CMD_SWITCH }

if ($command == 10) {$rc = process_postacquire $res_name; last CMD_SWITCH }

if ($command == 11) {$rc = process_undopreacquire $res_name; last CMD_SWITCH }

}

# close the debug file handle close(DBG);

# exit status generated from command processing

$rc;

244

Partitioning Implementations for IBM

E server

p5 Servers

Korn shell template

Example A-3 provides the Korn shell version of the DLPAR script template.

System administrators can use it as a starting point when integrating DLPAR operations into your applications.

The script sends debug information to the debug file,

/tmp/<script_file_name>.dbg. The debug information is very helpful when you have to debug your DLPAR script, because the script should not print any undefined name-value pairs to the standard out.

To display the debug information sent to the file, enter the following command:

$ tail -f /tmp/<script_file_name>.dbg

Example: A-3 DLPAR script template: Korn shell

#! /usr/bin/ksh

# (C) COPYRIGHT International Business Machines Corp. 2000, 2002

# All Rights Reserved

# Licensed Materials - Property of IBM

#

# US Government Users Restricted Rights - Use, duplication or

# disclosure restricted by GSA ADP Schedule Contract with IBM Corp.

#

#

# DLPAR aware Application developers will modify this script to

# develop a DLPAR script to suit their application's needs of control

# vis-a-vis Dynamic Reconfiguration(DLPAR) Operations.

#

# FILE NAME: IBM_template.sh

#

# FILE DESCRIPTION:

# This is an example template shell DLPAR script file for

# Dynamic Reconfiguration Application Framework of AIX.

# This template file just prints the various inputs

# from drmgr.

#

# Note that DLPAR script file should adher to the guildelines

# related to AIX Dynamic Reconfiguration. Some of the

# issues to be considered while chaagng this script file

# are:

# 1. Output name=value pairs only to stdout

# as per the DRAF guidelines. Refer to

# Manuals related to DLPAR for more details.

# 2. Return 0 upon success, 10 if the command

Appendix A. Dynamic logical partitioning program templates

245

# is not implemented, else return any other

# return code (1 to 9, 11 to 255)

# 3. Use DRAF defined environment variables and

# input parameters for processing the

# command.

# 4. To debug the script file, one can use

# the method shown in this template file.

#

# RETURN VALUE DESCRIPTION:

# 0 Successful

# 10 Command not implemented

# Else Error

#

################################# dbg #######################################

#

# NAME: dbg()

#

# DESCRIPTION: Write the debug message to debug file

#

# INPUT:

# Message to write to debug file

#

# OUTPUT:

# Message echoed to the debug file.

#

# RETURN VALUE DESCRIPTION:

# None

#

############################################################################## dbg()

{ echo $1 >> ${DBG_FILE_NAME}

}

############################## process_scriptinfo ############################

#

# NAME: process_scriptinfo()

#

# DESCRIPTION: Process 'scriptinfo' command from drmgr

#

# INPUT:

# The various environment variables set by drmgr

#

# OUTPUT:

# Output name=value pairs to stdout

# Various pieces of information about the DLPAR script.

#

# RETURN VALUE DESCRIPTION:

246

Partitioning Implementations for IBM

E server

p5 Servers

# 0 : success

# Else failure.

#

############################################################################## process_scriptinfo()

{ echo "DR_SCRIPTINFO=AIX DR ksh example script" echo "DR_VERSION=1" echo "DR_DATE=18102002" echo "DR_VENDOR=IBM" echo "DR_TIMEOUT=10" return 0

}

############################## process_register ############################

#

# NAME: process_register()

#

# DESCRIPTION: Process 'register' command from drmgr

#

# INPUT:

# The various environment variables set by drmgr

#

# OUTPUT:

# Output name=value pairs to stdout

# List of all the resources supported by this DLPAR script.

#

# RETURN VALUE DESCRIPTION:

# 0 : success

# Else failure.

#

############################################################################## process_register()

{ echo "DR_RESOURCE=cpu" echo "DR_RESOURCE=mem" return 0

}

############################## process_usage ############################

#

# NAME: process_usage()

#

# DESCRIPTION: Process 'usage' command from drmgr

#

# INPUT:

# The various environment variables set by drmgr

Appendix A. Dynamic logical partitioning program templates

247

# resource name input variable

#

# OUTPUT:

# Output name=value pairs to stdout

# Writes the how this resource is being used by the application

# associated with this DLPAR script.

#

# RETURN VALUE DESCRIPTION:

# 0 : success

# Else failure.

#

############################################################################## process_usage()

{ case "$1" in

"cpu") echo "DR_USAGE=cpu binding for performance"

;;

"mem") echo "DR_USAGE=Shared(Pinned) memory for app XYZ"

;;

*) echo "DR_ERROR=Script does not use Resource $1"

;; esac return 0

}

############################## process_checkrelease ##########################

#

# NAME: process_checkrelease()

#

# DESCRIPTION: Process 'checkrelease' command from drmgr

#

# INPUT:

# The various environment variables set by drmgr

# resource name input variable

#

# OUTPUT:

# Any debug information using DR debug name=value pairs

#

#

# such as DR_LOG_DEBUG="..."

# Any error message in the form of DR_ERROR name=value pair

# RETURN VALUE DESCRIPTION:

# 0 : success

# 10 : Command not implemented for this resource.

# Else DLPAR operatin is not ok with the DLPAR script/associated app.

248

Partitioning Implementations for IBM

E server

p5 Servers

#

############################################################################## process_checkrelease()

{ case "$1" in

"cpu") dbg "Resource : cpu"

# Do all the cpu related checks here and determine

# whether DLPAR remove can proceed.

;;

"mem") dbg "Resource : mem"

# Do all the memory related checks here and determine

# whether DLPAR remove can proceed. esac

;;

*) echo "DR_ERROR=Script does not support Resource $1"

;; return 0

}

############################## process_prerelease ############################

#

# NAME: process_prerelease()

#

# DESCRIPTION: Process 'prerelease' command from drmgr

#

# INPUT:

# The various environment variables set by drmgr

# resource name input variable

#

# OUTPUT:

# Any debug information using DR debug name=value pairs

# such as DR_LOG_DEBUG="..."

# Any error message in the form of DR_ERROR name=value pair

#

#

# RETURN VALUE DESCRIPTION:

# 0 : success

# 10 : Command not implemented for this resource.

# Else DLPAR script/associated application could not release the resource

# for DLPAR operation.

#

############################################################################## process_prerelease()

{

Appendix A. Dynamic logical partitioning program templates

249

# Do any pre release actions here. One could send a signal

# from here and wait for application do the necessary.

# Return from here only after the desired actions have

# taken place.

case "$1" in

"cpu") bg "Resource : cpu"

# Release any cpu bindings etc here if the

# resource being released is used by the app.

;;

"mem") dbg "Resource : mem"

# Release application hold over any memory

# that is being removed.

;;

*) echo "DR_ERROR=Script does not support Resource $1" esac

;; return 0

}

############################## process_postrelease ############################

#

# NAME: process_postrelease()

#

# DESCRIPTION: Process 'postrelease' command from drmgr

#

# INPUT:

# The various environment variables set by drmgr

# resource name input variable

#

# OUTPUT:

# Any debug information using DR debug name=value pairs

#

#

# such as DR_LOG_DEBUG="..."

# Any error message in the form of DR_ERROR name=value pair

# RETURN VALUE DESCRIPTION:

# 0 : success

# 10 : Command not implemented for this resource.

# Else DLPAR script/associated application could not post DLPAR operations.

#

############################################################################## process_postrelease()

{

# Reacquire any resource release during prerelease.

# activate any apps quieced during prerelease.

250

Partitioning Implementations for IBM

E server

p5 Servers

case "$1" in

"cpu") dbg "Resource : cpu"

;;

"mem") dbg "Resource : mem"

;;

*) esac echo "DR_ERROR=Script does not support Resource $1"

;; return 0

}

############################## process_undoprerelease #########################

#

# NAME: process_undoprerelease()

#

# DESCRIPTION: Process 'process_undoprerelease' command from drmgr

#

# INPUT:

# The various environment variables set by drmgr

# resource name input variable

#

# OUTPUT:

# Any debug information using DR debug name=value pairs

# such as DR_LOG_DEBUG="..."

# Any error message in the form of DR_ERROR name=value pair

#

#

# RETURN VALUE DESCRIPTION:

# 0 : success

# 10 : Command not implemented for this resource.

# Else DLPAR script/associated application failed undorelease

#

############################################################################## process_undoprerelease()

{

# DLPAR operation was aborted/failed. Hence undo any

# changes done during prerelease for this resource

# and the application associated with the DLPAR script.

case "$1" in

"cpu") dbg "Resource : cpu"

;;

"mem") dbg "Resource : mem"

Appendix A. Dynamic logical partitioning program templates

251

;;

*) echo "DR_ERROR=Script does not support Resource $1" esac

;; return 0

}

############################## process_checkacquire #########################

#

# NAME: process_checkacquire()

#

# DESCRIPTION: Process 'process_checkacquire' command from drmgr

#

# INPUT:

# The various environment variables set by drmgr

# resource name input variable

#

# OUTPUT:

# Any debug information using DR debug name=value pairs

# such as DR_LOG_DEBUG="..."

# Any error message in the form of DR_ERROR name=value pair

#

#

# RETURN VALUE DESCRIPTION:

# 0 : success

# 10 : Command not implemented for this resource.

# Else DLPAR script/associated application does want this resource.

#

############################################################################## process_checkacquire()

{

# Do any checks prior to resource addition.

case "$1" in

"cpu") dbg "Resource : cpu"

;;

"mem") dbg "Resource : mem"

;;

*) echo "DR_ERROR=Script does not support Resource $1"

;; esac return 0

}

############################## process_preacquire #########################

#

# NAME: process_preacquire()

252

Partitioning Implementations for IBM

E server

p5 Servers

#

# DESCRIPTION: Process 'process_preacquire' command from drmgr

#

# INPUT:

# The various environment variables set by drmgr

# resource name input variable

#

# OUTPUT:

# Any debug information using DR debug name=value pairs

# such as DR_LOG_DEBUG="..."

# Any error message in the form of DR_ERROR name=value pair

#

#

# RETURN VALUE DESCRIPTION:

# 0 : success

# 10 : Command not implemented for this resource.

# Else DLPAR script/associated application preacquire failed.

#

############################################################################## process_preacquire()

{

# Do all the necessary work prior to resource addition.

case "$1" in

"cpu")

dbg "Resource : cpu"

;;

"mem")

dbg "Resource : mem"

;;

*)

echo "DR_ERROR=Script does not support Resource $1"

;;

esac

return 0

}

############################## process_undopreacquire #########################

#

# NAME: process_undopreacquire()

#

# DESCRIPTION: Process 'process_undopreacquire' command from drmgr

#

# INPUT:

# The various environment variables set by drmgr

# resource name input variable

#

# OUTPUT:

# Any debug information using DR debug name=value pairs

# such as DR_LOG_DEBUG="..."

Appendix A. Dynamic logical partitioning program templates

253

# Any error message in the form of DR_ERROR name=value pair

#

#

# RETURN VALUE DESCRIPTION:

# 0 : success

# 10 : Command not implemented for this resource.

# Else DLPAR script/associated application undopreacquire failed.

#

############################################################################## process_undopreacquire()

{

# DLPAR operation has failed. So undo any activities done during

# preacquire case "$1" in

"cpu") dbg "Resource : cpu"

;;

"mem") dbg "Resource : mem"

;;

*) echo "DR_ERROR=Script does not support Resource $1"

;; esac return 0

}

############################## process_postacquire #########################

#

# NAME: process_postacquire()

#

# DESCRIPTION: Process 'process_postacquire' command from drmgr

#

# INPUT:

# The various environment variables set by drmgr

# resource name input variable

#

# OUTPUT:

# Any debug information using DR debug name=value pairs

# such as DR_LOG_DEBUG="..."

# Any error message in the form of DR_ERROR name=value pair

#

#

# RETURN VALUE DESCRIPTION:

# 0 : success

# 10 : Command not implemented for this resource.

# Else DLPAR script/associated application postacquire failed.

#

############################################################################## process_postacquire()

254

Partitioning Implementations for IBM

E server

p5 Servers

{

# execute any actions required after the DLPAR add operation.

# Egs: Increase the number of threads for the application

# Increase memory areas reserved for application etc.

case "$1" in

"cpu") dbg "Resource : cpu"

;;

"mem") dbg "Resource : mem"

;;

*) echo "DR_ERROR=Script does not support Resource $1" esac

;; return 0

}

###############################################

# MAIN SCRIPT STARTS HERE

############################################### script_file_name=`basename $0`

DBG_FILE_NAME=/tmp/${script_file_name}.dbg

date_and_time=`date` dbg "------ DLPAR Script start at $date_and_time -------" if [ $# -eq 0 ]; then

# Atleast the command must be part of the invocation dbg "No command passed to the DLPAR script" echo "DR_ERROR=Script Usage Error" exit 1 fi

# Note down the command command=$1 ret_code=0 dbg "command issued: $1" case "$1" in scriptinfo) process_scriptinfo ret_code=$?

;; register) process_register ret_code=$?

;;

Appendix A. Dynamic logical partitioning program templates

255

usage) process_usage $2 ret_code=$?

;; checkrelease) process_checkrelease $2 ret_code=$?

;; prerelease) process_prerelease $2 ret_code=$?

;; postrelease) process_postrelease $2 ret_code=$?

;; undoprerelease) process_undoprerelease $2 ret_code=$?

;; checkacquire) process_checkacquire $2 ret_code=$?

;; preacquire) process_preacquire $2 ret_code=$?

;; undopreacquire) process_undopreacquire $2 ret_code=$?

;; postacquire) process_postacquire $2 ret_code=$?

;;

*) dbg "unknown command: $1 issued" ret_code=10

;; esac dbg "SCRIPT exiting with return code : $ret_code" dbg "................DLPAR Script end ................" return $ret_code

256

Partitioning Implementations for IBM

E server

p5 Servers

DLPAR-aware application using a signal handler

If you can access the source code of your application, you can modify your application by adding a signal handler that reacts to the SIGRECONFIG signal so that the application is made DLPAR-aware. The SIGRECONFIG signal is delivered to the application process upon DLPAR events.

How to compile and run the application

Before running this application, you must compile the C source code by executing the following command

1

:

$ cc -o DLPAR_appl DLPAR_appl.c

In this command:

DLPAR_appl

DLPAR_appl.c

Is the application program name to be executed

Is the file name of C program source code

To run this application, enter

DLPAR_appl

at the command line prompt. To stop it, type

Control-C

at the command line prompt where you have invoked it.

The application process sends debug information to the

/tmp/dr_api_template.C.dbg file. To display the debug information sent to the file, enter the following:

$ tail -f /tmp/dr_api_template.C.dbg

Example: A-4 C language application with a signal handler

#include <stdio.h>

#include <stdlib.h>

#include <signal.h>

#include <errno.h>

#include <sys/dr.h>

/*=====================================================================*/

/* Prototypes */

/*=====================================================================*/ void perror_msg(char *func_name, int errno_old, const int line_num); void dr_func(int arg); int checkAcquire_mem(void); int checkAcquire_cpu(void); int preAcquire_mem(void); int preAcquire_cpu(void); int postAcquire_mem(void); int postAcquire_cpu(void);

1

This example requires that the C compiler is installed and available on your AIX system.

Appendix A. Dynamic logical partitioning program templates

257

int postAcquireError_mem(void); int postAcquireError_cpu(void); int checkRelease_mem(void); int checkRelease_cpu(void); int preRelease_mem(void); int preRelease_cpu(void); int postRelease_mem(void); int postRelease_cpu(void); int postReleaseError_mem(void); int postReleaseError_cpu(void);

/*=====================================================================*/

/* Globals */

/*=====================================================================*/ extern int errno; dr_info_t dr_info; char msg_buf[BUFSIZ];

FILE * l_dbgFd; typedef struct { int (*mem_ptr)(void); int (*cpu_ptr)(void);

} phases_t;

/* #J */ phases_t definedPhase[] = {

{ &checkAcquire_mem, &checkAcquire_cpu },

{ &preAcquire_mem, &preAcquire_cpu },

{ &postAcquire_mem, &postAcquire_cpu },

{ &postAcquireError_mem, &postAcquireError_cpu },

{ &checkRelease_mem, &checkRelease_cpu },

{ &preRelease_mem, &preRelease_cpu },

{ &postRelease_mem, &postRelease_cpu },

{ &postReleaseError_mem, &postReleaseError_cpu }

};

#define CHECK_ACQUIRE &definedPhase[0];

#define PRE_ACQUIRE &definedPhase[1];

#define POST_ACQUIRE &definedPhase[2];

#define POST_ACQUIRE_ERROR &definedPhase[3];

#define CHECK_RELEASE &definedPhase[4];

#define PRE_RELEASE &definedPhase[5];

#define POST_RELEASE &definedPhase[6];

#define POST_RELEASE_ERROR &definedPhase[7];

#define DR_API_SUCCESS

#define DR_API_FAIL

0

1

/*=====================================================================*/

/* Helper Functions */

258

Partitioning Implementations for IBM

E server

p5 Servers

/*=====================================================================*/

/*=====================================================================*/

/* Description: Handles any unexected errors */

/* */

/* Output: none */

/* Inputs: function name */

/* errno */

/* linenumber */

/*=====================================================================*/ void perror_msg(char *func_name, int errno_old, const int line_num)

{ sprintf(msg_buf

, “%s failed with errno = %d at line (%d).\n”

, func_name, errno_old, line_num); perror(msg_buf); return;

}

/*=====================================================================*/

/* Description: Memory Check Acquire phase */

/* */

/* This function should ensure that a memory addition will not */

/* disrupt the application, before the actual DR event occurs. */

/* */

/* Output: integer value indicating status of DR operation */

/* Values: DR_API_SUCCESS */

/* Input: None */

/*=====================================================================*/ int checkAcquire_mem(void)

{ int l_rc = DR_API_SUCCESS; fprintf(l_dbgFd, “*****Entered CheckedAcquire_mem*****\n”);

/* Check for plock’d memory */ if (dr_info.plock) { fprintf(l_dbgFd, “\t-- process has plock()’ed memory --\n”); l_rc = DR_API_FAIL;

}

/* check for pinned memory */ if (dr_info.pshm) { fprintf(l_dbgFd, “\t-- process has pinned shared memory --\n”); l_rc = DR_API_FAIL;

} return l_rc;

Appendix A. Dynamic logical partitioning program templates

259

}

/*=====================================================================*/

/* Description: CPU check acquire phase */

/* This function should ensure that a cpu addition will not */

/* disrupt the application, before the actual DR event takes place*/

/* */

/* Output: integer value indicating status of DR operation */

/* Values: DR_API_SUCCESS */

/* DR_API_FAIL */

/* Inputs: None */

/*=====================================================================*/ int checkAcquire_cpu(void)

{ int l_rc = DR_API_SUCCESS; fprintf(l_dbgFd, “*****Entered CheckedAcquire_cpu*****\n”);

/* check for processor dependencies */ if (dr_info.bindproc) { fprintf(l_dbgFd, “\t-- process has bindprocessor() dependency --\n”); l_rc = DR_API_FAIL;

} if (dr_info.softpset) { fprintf(l_dbgFd, “\t-- process has soft pset() dependency --\n”); l_rc = DR_API_FAIL;

} if (dr_info.hardpset) { fprintf(l_dbgFd, “\t-- process has hard pset() dependency --\n”); l_rc = DR_API_FAIL;

} return l_rc;

}

/*=====================================================================*/

/* Mem pre acquire phase */

/* */

/* Detailed Description: */

/* This function should ensure that the necessary steps are taken */

/* to prepare the application for a memory addition. If need be, */

/* the application should be halted. */

/* */

/* Output: integer value indicating status of DR operation */

/* Values: DR_API_SUCCESS */

/* DR_API_FAIL */

/* Inputs: None */

/*=====================================================================*/ int preAcquire_mem(void)

260

Partitioning Implementations for IBM

E server

p5 Servers

{ int l_rc = DR_API_SUCCESS; fprintf(l_dbgFd, “*****Entered PreeAcquire_mem*****\n”);

/* Perform actions here. */ return l_rc;

}

/*=====================================================================*/

/* CPU pre acquire phase */

/* */

/* Detailed Description: */

/* This function should ensure that the necessary steps are taken */

/* to prepare the application for a cpu addition. If need be, */

/* the application should be stopped. */

/* */

/* Output: integer value indicating status of DR operation */

/* Values: DR_API_SUCCESS */

/* DR_API_FAIL */

/* Inputs: None */

/*=====================================================================*/ int preAcquire_cpu(void)

{ int l_rc = DR_API_SUCCESS; fprintf(l_dbgFd, “*****Entered PreAcquire_cpu*****\n”);

/* Perform actions here */ return l_rc;

}

/*=====================================================================*/

/* Mem post acquire phase */

/* */

/* Detailed Description: */

/* After a memory addition has taken place, this function should */

/* perform any actions to clean up the DR operation and allow the */

/* application to use the new resources. If the application was */

/* stopped, it should be restarted here. */

/* */

/* Output: integer value indicating status of DR operation */

/* Values: DR_API_SUCCESS */

/* DR_API_FAIL */

/* Inputs: None */

/*=====================================================================*/ int postAcquire_mem(void)

Appendix A. Dynamic logical partitioning program templates

261

{ int l_rc = DR_API_SUCCESS; fprintf(l_dbgFd, “*****Entered PostAcquire_mem*****\n”);

/* Perform actions here */ return l_rc;

}

/*=====================================================================*/

/* CPU post acquire phase */

/* */

/* Detailed Description: */

/* After a cpu addition, this function allows the application */

/* access to the new resources. If the application was stopped, */

/* iy should be restarted here. */

/* */

/* Output: integer value indicating status of DR operation */

/* Values: DR_API_SUCCESS */

/* DR_API_FAIL */

/* Inputs: None */

/*=====================================================================*/ int postAcquire_cpu(void)

{ int l_rc = DR_API_SUCCESS; fprintf(l_dbgFd, “*****Entered PostAcquire_cpu*****\n”);

/* Perform actions here */ return l_rc;

}

/*=====================================================================*/

/* Handles post acquire Error phase for mem */

/* */

/* Detailed Description: */

/* If an error should occur, this phase should handle undoing the */

/* preacquire actions taken for mem rmovals. */

/* */

/* Output: integer value indicating status of DR operation */

/* Values: DR_API_SUCCESS */

/* DR_API_FAIL */

/* Inputs: None */

/*=====================================================================*/ int postAcquireError_mem(void)

{ int l_rc = DR_API_SUCCESS;

262

Partitioning Implementations for IBM

E server

p5 Servers

fprintf(l_dbgFd, “*****Entered PostAcquireError_mem*****\n”);

/* Perform actions here */ return l_rc;

}

/*=====================================================================*/

/* Handles post acquire Error phase for cpu */

/* */

/* Detailed Description: */

/* If an error should occur, this phase should handle undoing the */

/* preacquire actions taken for cpu rmovals. */

/* */

/* Output: integer value indicating status of DR operation */

/* Values: DR_API_SUCCESS */

/* DR_API_FAIL */

/* Inputs: None */

/*=====================================================================*/ int postAcquireError_cpu(void)

{ int l_rc = DR_API_SUCCESS; fprintf(l_dbgFd, “*****Entered PostAcquireError_cpu*****\n”);

/* Perform actions here */ return l_rc;

}

/*=====================================================================*/

/* Mem check release phase */

/* */

/* Detailed Description: */

/* This should check to make sure the application can tolerate a */

/* memory removal. If not, this should terminate the DR operation*/

/* */

/* Output: integer value indicating status of DR operation */

/* Values: DR_API_SUCCESS */

/* DR_API_FAIL */

/* Inputs: None */

/*=====================================================================*/ int checkRelease_mem(void)

{ int l_rc = DR_API_SUCCESS;

fprintf(l_dbgFd, “*****Entered CheckeRelease_mem*****\n”);

Appendix A. Dynamic logical partitioning program templates

263

/* Check for memory issues */ if (dr_info.plock) { fprintf(l_dbgFd, “\t-- process has plock()’ed memory --\n”); l_rc = DR_API_FAIL;

} if (dr_info.pshm) { fprintf(l_dbgFd, “\t-- process has pinned shared memory --\n”); l_rc = DR_API_FAIL;

} return l_rc;

}

/*=====================================================================*/

/* Handles post release Error phase for cpu */

/* */

/* Detailed Description: */

/* If an error should occur, this phase should handle undoing the */

/* prerelease actions taken for cpu rmovals. */

/* */

/* Output: integer value indicating status of DR operation */

/* Values: DR_API_SUCCESS */

/* l DR_API_FAIL */

/* Inputs: None */

/*=====================================================================*/ int checkRelease_cpu(void)

{ int l_rc = DR_API_SUCCESS; fprintf(l_dbgFd, “*****Entered CheckRelease_cpu*****\n”);

/* Check for processor dependencies */ if (dr_info.bindproc) { fprintf(l_dbgFd, “\t-- process has bindprocessor() dependency --\n”); l_rc = DR_API_FAIL;

} if (dr_info.softpset) { fprintf(l_dbgFd, “\t-- process has soft pset() dependency --\n”); l_rc = DR_API_FAIL;

} if (dr_info.hardpset) { fprintf(l_dbgFd, “\t-- process has hard pset() dependency --\n”); l_rc = DR_API_FAIL;

} return l_rc;

}

/*=====================================================================*/

/* Mem pre release phase */

264

Partitioning Implementations for IBM

E server

p5 Servers

/* */

/* Detailed Description: */

/* This function should prepare the application for memory */

/* resources being removed. */

/* */

/* Output: integer value indicating status of DR operation */

/* Values: DR_API_SUCCESS */

/* DR_API_FAIL */

/* Inputs: None */

/*=====================================================================*/ int preRelease_mem(void)

{ int l_rc = DR_API_SUCCESS; fprintf(l_dbgFd, “*****Entered PreRelease_mem*****\n”);

/* Perform actions here */ return l_rc;

}

/*=====================================================================*/

/* Cpu pre release phase */

/* */

/* Detailed Description: */

/* This should prepare the application for cpu resources being */

/* removed. */

/* */

/* Output: integer value indicating status of DR operation */

/* Values: DR_API_SUCCESS */

/* DR_API_FAIL */

/* Inputs: None */

/*=====================================================================*/ int preRelease_cpu(void)

{ int l_rc = DR_API_SUCCESS; fprintf(l_dbgFd, “*****Entered PreRelease_cpu*****\n”);

/* Perform actions here */ return l_rc;

}

/*=====================================================================*/

/* Mem post release phase */

/* */

/* Detailed Description: */

/* After the memory resources are removed, this function should */

Appendix A. Dynamic logical partitioning program templates

265

/* take care of cleaning up any DR modifications made and allow */

/* the application to continue running. */

/* */

/* Output: integer value indicating status of DR operation */

/* Values: DR_API_SUCCESS */

/* DR_API_FAIL */

/* Inputs: None */

/*=====================================================================*/ int postRelease_mem(void)

{ int l_rc = DR_API_SUCCESS; fprintf(l_dbgFd, “*****Entered PostReleasee_mem*****\n”);

/* Perform actions here */ return l_rc;

}

/*=====================================================================*/

/* Cpu post release phase */

/* */

/* Detailed Description: */

/* After cpu resources are removed, this function should handle */

/* the application so that it can continue after the DR operation.*/

/* */

/* Output: integer value indicating status of DR operation */

/* Values: DR_API_SUCCESS */

/* Values: DR_API_FAIL */

/* Inputs: None */

/*=====================================================================*/ int postRelease_cpu(void)

{ int l_rc = DR_API_SUCCESS; fprintf(l_dbgFd, “*****Entered PostRelease_cpu*****\n”);

/* Perform actions here */ return l_rc;

}

/*=====================================================================*/

/* Handles post release Error phase for mem */

/* */

/* Detailed Description: */

/* If an error should occur, this phase should handle undoing the */

/* prerelease actions taken for mem rmovals. */

/* */

266

Partitioning Implementations for IBM

E server

p5 Servers

/* Output: integer value indicating status of DR operation */

/* Values: DR_API_SUCCESS */

/* DR_API_FAIL */

/* Inputs: None */

/*=====================================================================*/ int postReleaseError_mem(void)

{ int l_rc = DR_API_SUCCESS; fprintf(l_dbgFd, “*****Entered PostReleaseError_mem*****\n”);

/* Perform actions here */ return l_rc;

}

/*=====================================================================*/

/* Handles post release Error phase for cpu */

/* */

/* Detailed Description: */

/* If an error should occur, this phase should handle undoing the */

/* prerelease actions taken for cpu rmovals. */

/* */

/* Output: integer value indicating status of DR operation */

/* Values: DR_API_SUCCESS */

/* DR_API_FAIL */

/* Inputs: None */

/*=====================================================================*/

int postReleaseError_cpu(void)

{ int l_rc = DR_API_SUCCESS; fprintf(l_dbgFd, “*****Entered PostReleaseError_cpu*****\n”);

/* Perform actions here */ return l_rc;

}

/*=====================================================================*/

/* Functions */

/*=====================================================================*/

/*=====================================================================*/

/* SIGRECONFIG signal handler */

/* */

/* Detailed Description: */

/* This will handle the signal, when a DR event occurs. The main */

/* information is communicated through a dr_info_t data structure.*/

Appendix A. Dynamic logical partitioning program templates

267

/* This will take care of parsing the data structure and taking */

/* appropriate actions. */

/* */

/* Output: None */

/* Input: argument, not used for compatability */

/*=====================================================================*/ void dr_func(int arg)

{ int l_rc= DR_API_SUCCESS; phases_t *l_currentPhase;

/* #1 create debug output file stream */ l_dbgFd = fopen(“/tmp/dr_api_template.C.dbg”, “a”); /* open for appending */ if (l_dbgFd == NULL) { perror_msg(“NULL file descriptor”, errno, __LINE__); exit(1);

} fprintf (l_dbgFd, “---Start of Signal Handler---\n”);

/* #C */ l_rc = dr_reconfig(DR_QUERY, &dr_info); if (l_rc != 0) { perror_msg(“dr_reconfig()”, errno, __LINE__); exit(1);

}

/* #2 determine type of operation and phase. */

/* addition operations */ if (dr_info.add) { fprintf(l_dbgFd, “An add request\n “);

/* #D */

/* now determine which acquire phase we are in. */ if (dr_info.check) { fprintf(l_dbgFd, “\t** check phase **\n”); l_currentPhase = CHECK_ACQUIRE;

} else if (dr_info.pre) { fprintf(l_dbgFd, “\t** pre phase **\n”); l_currentPhase = PRE_ACQUIRE;

} else if (dr_info.post) { fprintf(l_dbgFd, “\t** post phase **\n”); l_currentPhase = POST_ACQUIRE;

} else if (dr_info.posterror) { fprintf(l_dbgFd, “\t** error phase **\n”); l_currentPhase = POST_ACQUIRE_ERROR;

}

}

/* remove operations. */

268

Partitioning Implementations for IBM

E server

p5 Servers

if (dr_info.rem) { fprintf(l_dbgFd, “A remove request\n “);

/* now determine which remove phase we are in. */ if (dr_info.check) { fprintf(l_dbgFd, “\t** check phase **\n”); l_currentPhase = CHECK_RELEASE;

} else if (dr_info.pre) { fprintf(l_dbgFd, “\t** pre phase **\n”); l_currentPhase = PRE_RELEASE;

} else if (dr_info.post) { fprintf(l_dbgFd, “\t** post phase **\n”); l_currentPhase = POST_RELEASE;

} else if (dr_info.posterror) { fprintf(l_dbgFd, “\t** error phase **\n”); l_currentPhase = POST_RELEASE_ERROR;

}

}

/* #3 invoke the command associated with the resource. */

/* #E */

/* cpu resource. */ if (dr_info.cpu) { /* #F */ fprintf(l_dbgFd, “Resource is CPU .\n”); fprintf(l_dbgFd, “\tlogical CPU ID = %d\n\tBind CPU ID = %d\n”

, dr_info.lcpu, dr_info.bcpu);

/* invoke the command to process a cpu DR event */ l_rc = l_currentPhase->cpu_ptr(); /* #H */

/* memory resource. */

} else if (dr_info.mem) { fprintf(l_dbgFd, “Resource is Memory.\n”);

/* #G */ fprintf(l_dbgFd, “\trequested memory size (in bytes) = %lld\n”

, dr_info.req_memsz_change); fprintf(l_dbgFd, “\tsystem memory size = %lld\n”, dr_info.sys_memsz); fprintf(l_dbgFd, “\tnumber of free frames in system = %lld\n”

, dr_info.sys_free_frames); fprintf(l_dbgFd, “\tnumber of pinnable frams in system = %lld\n”

, dr_info.sys_pinnable_frames); fprintf(l_dbgFd, “\ttotal number of frames in system = %lld\n”

, dr_info.sys_total_frames);

/* invoke the command to process a mem DR event */ l_rc = l_currentPhase->mem_ptr(); /* #I */

/* unknown resource. */

} else { fprintf(l_dbgFd, “Unknown resource type.\n”);

Appendix A. Dynamic logical partitioning program templates

269

}

/* Check the return code of the DLPAR operation handler. */ if (l_rc == DR_API_FAIL) { fprintf(l_dbgFd, “DLPAR OPERATION failed!\n”);

/* Let the DR manager know we have to fail the DLPAR operation. */ l_rc = dr_reconfig(DR_EVENT_FAIL, &dr_info); if (l_rc != 0) { perror_msg(“dr_reconfig()”, errno, __LINE__); exit(1);

}

} fprintf(l_dbgFd, “---end of signal handler.---\n\n”); fclose(l_dbgFd);

}

/*=====================================================================*/

/* Main application */

/*=====================================================================*/

/*=====================================================================*/

/* Some Applicaiton that is registered for DR signals */

/* */

/* Detailed Description: */

/* This is a sample program that registers the signal handler */

/* function that will response to the SIGRECONFIG signal.

*/

/* */

/* Output: None */

/* Inputs: None */

/*=====================================================================*/ int main(int argc, char *argv[], char *envp[])

{ int struct sigaction rc; sigact_save, sigact;

/* Start: register this application for a DR signal. */ if ((rc = sigemptyset(&sigact.sa_mask)) != 0) { perror_msg(“sigemptyset()”, errno, __LINE__); exit(1);

} if ((rc = sigemptyset(&sigact_save.sa_mask)) != 0) { perror_msg(“sigemptyset()”, errno, __LINE__); exit(1);

}

/* register the signal handler function dr_func. */

270

Partitioning Implementations for IBM

E server

p5 Servers

sigact.sa_handler = dr_func; sigact.sa_flags |= SA_SIGINFO; if ((rc = sigaction(SIGRECONFIG, &sigact, &sigact_save)) != 0) { /* #A */ perror_msg(“sigaction()”, errno, __LINE__); exit(1);

}

/* Finish: registered the signal handler. */ while (1) { /* #B */

;

/* your applicaiton logic goes here. */

} exit(0);

}

Appendix A. Dynamic logical partitioning program templates

271

272

Partitioning Implementations for IBM

E server

p5 Servers

Was this manual useful for you? yes no
Thank you for your participation!

* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project

Download PDF

advertisement

Table of contents