MINI MINI MANI MO
#
#
# osds_unix_linux_afdlib.pm
#
# Copyright (c) 2007, 2016, Oracle and/or its affiliates. All rights reserved.
#
#
# NAME
# osds_unix_linux_afdlib.pm - Linux Unix OSD library components.
#
# DESCRIPTION
# Purpose
# Linux Unix OSD library functions for the install/runtime scripts.
#
# NOTES
# All user visible output should be done in the common code.
# this will ensure a consistent look and feel across all platforms.
#
#
use strict;
use File::Path;
use acfslib;
use afdlib;
package osds_unix_linux_afdlib;
require Exporter;
our @ISA = qw(Exporter);
our @EXPORT = qw(
lib_osds_afd_control_devices_accessible
lib_osds_afd_supported
lib_osds_asmlib_installed
lib_osds_verify_afd_devices
lib_osds_fetch_afd_disks_dir
lib_osds_is_Exadata
AFD_IDX
AFD_DEV_DIR
AFD_CTL_DEV
AFD_CONF_PATH
);
use Config;
my ($OSNAME) = $Config{osname};
chomp($OSNAME);
use constant AFD_IDX => 0; # index into driver_components
use constant AFD_DEV_DIR=> "/dev/oracleafd"; # Created when afd is loaded
use constant AFD_CTL_DEV=> "/dev/oracleafd/admin"; # Created when afd is loaded
# Created when afd is loaded
use constant AFD_CONF_PATH=> "/etc/oracleafd.conf"; # used only for lrg testing
use constant ASMLIB_DRIVER_COMPONENT=> "oracleasm";
# On Windows, in the CRS environment, this
# redirection does not work. It fails with
# "cannot open file descriptor" or "cannot open pipe NOWAIT".
our ($REDIRECT) = "2>&1";
my ($CACHED_INSTALLED_DRIVERS); # saved find /lib/modules output
my ($CACHED_LOADED_DRIVERS); # saved find lsmod output
# /sbin/fuser ... RH Enterprise Linux
# /bin/fuser ... Suse
# /usr/sbin/fuser ... AIX, HPUX, Solaris
# /usr/sbin/lsof ... RH Enterprise Linux
# /sbin/modprobe ... RH Enterprise Linux
$ENV{PATH} = $ENV{PATH} . ":/sbin:/bin:/usr/sbin";
my $ORACLE_HOME = $ENV{ORACLE_HOME};
our ($TMPDIR) = "/tmp";
# lib_osds_control_devices_accessible
#
# We test the USM control device accessibility by opening them
# Note that this will work on all Linux/Unix - but not Windows
#
# return true (1) or false (0)
#
sub lib_osds_afd_control_devices_accessible
{
my ($ret) = 1; # assume true
open AFD, "<" . AFD_CTL_DEV or $ret = 0;
if ($ret)
{
close AFD;
}
return $ret;
} # end lib_osds_control_devices_accessible
# lib_osds_afd_supported
#
# The fact that we got here means that there is some support for
# this platform. However, perhaps not all releases are supported.
# We make that determination here.
#
# return true or false
#
sub lib_osds_afd_supported
{
my ($arch) = $Config{archname}; # Machine architecture - e.g., i386
my $afdEnv = $ENV{_AFD_ENABLE};
chomp($arch);
if (!defined $afdEnv)
{
$afdEnv = "";
}
# Other unixes AFD is not available
if (!(($OSNAME eq "linux") || ($OSNAME eq "solaris") || ($OSNAME eq "aix")))
{
acfslib::lib_error_print(618,
"AFD is not supported on this operating system: '%s'", $OSNAME);
return 0;
}
# AFD is not supported on 'Linux on Sparc (LoS)'
if (($OSNAME eq "linux") && ($arch =~ /^sparc/))
{
acfslib::lib_error_print(618,
"AFD is not supported on this operating system: '%s'",
"Linux (on Sparc)");
return 0;
}
# AFD is not supported on Exadata
if (($OSNAME eq "linux") && lib_osds_is_Exadata())
{
acfslib::lib_error_print(654,
"AFD is not supported on Exadata systems");
return 0;
}
# AFD can be disabled with '_AFD_ENABLE=FALSE'.
if ($afdEnv eq "FALSE")
{
acfslib::lib_error_print(618,
"AFD is not supported on this operating system: '%s'", $OSNAME);
return 0;
}
# On aix, AFD is not available by default. But can be enabled.
if (($OSNAME eq "aix") && (!($afdEnv eq "TRUE")))
{
acfslib::lib_error_print(618,
"AFD is not supported on this operating system: '%s'", $OSNAME);
return 0;
}
if (!(($arch =~ /^i686/) || ($arch =~ /^x86_64/)
|| ($arch =~ /^aix-thread-multi-64all/)
|| ($arch =~ /^i86pc/)
|| ($arch =~ /^sun4-solaris/)))
{
lib_error_print(619,
"The '%s' machine architecture is not supported.", $arch);
return 0;
}
# $type is "EL5", for example
my ($type) = osds_acfslib::lib_osds_get_os_type();
if ($type =~ /not supported/)
{
return 0;
}
return 1;
} # end lib_osds_afd_supported
# lib_osds_asmlib_installed
# Check if the ASMLIB library/driver is present
# If so, AFD will not co-exist with ASMLIB.
# Hence, AFD will not be supported on ASMLIB configured machine.
sub lib_osds_asmlib_installed
{
if($OSNAME eq "linux")
{
my ($whatbit) = `grep flags /proc/cpuinfo`;
my ($target);
# If configured, ASMLIB library will be under ...
# /opt/oracle/extapi/[32,64]/{API}/{VENDOR}/{VERSION}/lib<apiname>.<ext>
#
if($whatbit =~ /lm/)
{
$target = "/opt/oracle/extapi/64/asm/orcl/1/libasm.so";
}
elsif($whatbit =~ /tm/)
{
$target = "/opt/oracle/extapi/32/asm/orcl/1/libasm.so";
}
# Presence of either library or driver indicates ASMLIB configuration
if ((-e $target) ||
(acfslib::lib_osds_check_driver_loaded(ASMLIB_DRIVER_COMPONENT)))
{
acfslib::lib_error_print(9202,
"AFD can not be installed/loaded because ASMLib is installed.");
return 0;
}
}
return 1;
}
# lib_osds_is_Exadata
# Check if it's Exadata machine
# If so, AFD will not be supported
sub lib_osds_is_Exadata
{
my $status;
my $checksc = "/etc/oracle/cell/network-config/cellip.ora";
if (! (-e $checksc)) {
return 0;
}
return 1;
}
# lib_osds_verify_afd_devices
#
# Verify that the AFD drivers are loaded and running by checking the
# existence of the device control files for the drivers.
#
sub lib_osds_verify_afd_devices
{
my ($asmadmin) = acfslib::lib_get_asm_admin_name();
my ($asmuser) = acfslib::getParam("ORACLE_OWNER");
# Make sure that the proper /dev files get created
my ($found) = 0;
my ($max_wait_seconds) = 60;
my ($device) = AFD_CTL_DEV;
acfslib::lib_inform_print(9156, "Detecting control device '%s'.", $device);
while (($max_wait_seconds > 0) && (!$found))
{
if (! -e $device)
{
sleep 1;
$max_wait_seconds -= 1;
}
else
{
if($OSNAME eq "solaris")
{
if(! -c $device)
{
acfslib::lib_error_print(9122,
"Device '%s' is not a character device.",
$device);
return osds_unix_linux_acfslib::USM_FAIL;
}
}
$found = 1;
}
}
if (!$found)
{
acfslib::lib_error_print(9121, "failed to detect control device '%s'", $device);
return osds_unix_linux_acfslib::USM_FAIL;
}
else
{
if($asmuser)
{
system("chown $asmuser " . AFD_CTL_DEV);
system("chown $asmuser " . AFD_DEV_DIR);
}
system("chgrp $asmadmin " . AFD_DEV_DIR);
system("chmod 0775 " . AFD_DEV_DIR);
}
return osds_unix_linux_acfslib::USM_SUCCESS;
}
# lib_osds_fetch_afd_disks_dir
#
# Return the AFD disks directory which is created when AFD is loaded.
sub lib_osds_fetch_afd_disks_dir
{
if($OSNAME eq "solaris")
{
# Only on Solaris the AFD disks directory is not under /dev
# Bug 20073684
return "/var/opt/oracle/oracleafd/disks";
}
else
{
return "/dev/oracleafd/disks";
}
}
# vim:ts=2:expandtab
OHA YOOOO