MINI MINI MANI MO

Path : /opt/oracle/product/18c/dbhomeXE/lib/
File Upload :
Current File : //opt/oracle/product/18c/dbhomeXE/lib/osds_okalib.pm

# osds_okalib.pm
# 
# Copyright (c) 2007, 2016, Oracle and/or its affiliates. All rights reserved.
#
#
#    NAME
#      osds_okalib.pm - Linux OSD library components for OKA.
#
#    DESCRIPTION
#      Purpose
#          Linux 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 acfslib;
use okalib;
use osds_unix_linux_okalib;
package osds_okalib;
require Exporter;
our @ISA = qw(Exporter);
our @EXPORT = qw(
                  lib_osds_verify_oka_devices
                  lib_osds_oka_create_udev
                  lib_osds_oka_create_node
                  lib_osds_oka_driver_inuse
                  lib_osds_get_oka_RH5_udev_rules_file 
                  @OKA_DRIVER_COMPONENTS
                  %OKA_DRIVER_INFO
                  OKA_IDX
                  OKG_IDX
                 );

# fixed constants for use
use constant USM_SUCCESS      => 0;
use constant USM_FAIL         => 1;
use constant OKA_DEV          => "/dev/oka";      # created when OKA loaded
use constant OKA_IDX => 0;                      # index into driver_components
use constant OKG_IDX => 1;                      # index into driver_components

our (@OKA_DRIVER_COMPONENTS) = (
       "oracka.ko",
       "oracka_mod_kga.ko",
       );

our %OKA_DRIVER_INFO = (
    $OKA_DRIVER_COMPONENTS[OKA_IDX] =>
                   { 'type' => "drv",
                     'perm' => ""},
    $OKA_DRIVER_COMPONENTS[OKG_IDX] =>
                   { 'type' => "drv",
                     'perm' => ""}
                   );

my ($ORACLE_HOME) = $ENV{ORACLE_HOME};

my ($CACHED_INSTALLED_DRIVERS);               # saved find /lib/modules output
my ($UNAME_R) = `uname -r`;
chomp ($UNAME_R);
my ($ARCH) = `uname -i`;
chomp ($ARCH);                                # e.g., "x86-64"

# /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";

# lib_osds_get_oka_RH5_udev_rules_file
#
# get OKA udev rules directory and file used by both install/uninstall
#
sub lib_osds_get_oka_RH5_udev_rules_file
{
  return get_oka_udev_common("/etc/udev/rules.d", "udev_rules", "55-oka.rules");
}

# lib_osds_oka_create_udev
#
# Create a OKA udev file - for now we create with open permissions but
# eventually this should just be restricted
#
sub lib_osds_oka_create_udev
{
  my ($okaadmin) = @_;
  my ($udev_perm_file);

  $udev_perm_file = lib_osds_get_oka_RH5_udev_rules_file();
  # create the permissions file - replaces existing file (if any)
  open  PERM, ">$udev_perm_file" or die "can't create file: $!";
  print PERM  "#\n";
  print PERM  "# OKA devices\n";
  print PERM  "KERNEL==\"oka\",     GROUP=\"$okaadmin\", MODE=\"0770\"\n";
  close PERM;
} # end lib_osds_oka_create_udev

# lib_osds_oka_create_node
#
# Create the /dev node and set the proper permissions
#
sub lib_osds_oka_create_node
{
  my ($okaadmin) = @_;
  my ($result) = 0;
  my ($node) = '/dev/oka';
  my ($owner) = 'root';

  if (-e $node)
  {
    # Node already exists
    print ("The node already exists.\n");
    return USM_FAIL;
  }

  # Create the node
  $result = system("mknod -m 0770 $node c 142 0");

  if ($result == 1)
  {
    print("The node could not be created.\n");
    return USM_FAIL;
  }

  $result = system("chown $owner:$okaadmin $node");
  if ($result == 1)
  {
    print("Could not change OKA node ownership.\n");
    return USM_FAIL;
  }

  return USM_SUCCESS;
} # end lib_osds_oka_create_node

# lib_osds_verify_oka_devices
#
# Verify that the OKA drivers are loaded and running by checking the
# existence of the device control files for the drivers.
#
sub lib_osds_verify_oka_devices
{
  # Make sure that the proper /dev files get created
  my ($found) = 0;
  my ($max_wait_seconds) = 60;
  my $device = OKA_DEV;

  acfslib::lib_inform_print_noalert(9156, "Detecting control device '%s'.", $device);

  while (($max_wait_seconds > 0) && (!$found))
  {
    if (! -e $device)
    {
      sleep 1;
      $max_wait_seconds -= 1;
    }
    else
    {
      $found = 1;
    }
  }

  if (!$found)
  {
     acfslib::lib_error_print_noalert(9121, "Failed to detect control device '%s'.", $device);
    return USM_FAIL;
  }

  return USM_SUCCESS;

} #end lib_osds_verify_oka_devices

# get_oka_udev_common
#
# common code for get_oka_RH5_udev_rules_file()
sub get_oka_udev_common
{
  my ($default_dir, $config_param, $file_name) = @_;
  my ($line);                              # line from the udev.conf file

  # We get the rules directory from the udev.conf file
  # and then append the file name.
  my ($udev_perm_dir) = $default_dir;       # default directory name

  # open file for read
  open (CONF, "</etc/udev/udev.conf");
  while ($line = <CONF>)
  {
    my ($line_org) = $line;
    # strip off the parameter name, if it exists, leaving only the set value
    $line =~ s/^$config_param=//;

    # did we find the right line in the file?
    # we know it's the right line if the substitution worked.
    if ($line ne $line_org)
    {
      # remove the double quotes
      $line =~ s/"//g;
      # remove the carriage return
      chomp($line);
      $udev_perm_dir = $line;
      last;
    }
  }
  close CONF;

  # avoid "//" - just to make it pretty as it works fine as is
  $udev_perm_dir =~ s/\/$//;

  return ($udev_perm_dir . "/" . $file_name);
} # end get_oka_udev_common

# lib_osds_oka_driver_inuse
#
# On linux, it allows you to unload the driver even if it is in use 
# so this function checks with the driver itself
sub lib_osds_oka_driver_inuse
{
  my $cmd  = File::Spec->catfile($ORACLE_HOME, "bin", "okacmd");
  my @cmdinuse = ($cmd, "-inuse");

  my $ret = system(@cmdinuse);

  # the okacmd -inuse would return skjretSucces (0) if not in use, 
  # skjretInUse (13) 
  return ($?);
} # end lib_osds_oka_driver_inuse

####### internal only functions #########

OHA YOOOO