?? NEWTITLE := '  NOS/VE Set Management ' ??
MODULE stm$pf_interfaces;
?? RIGHT := 110 ??

{  PURPOSE:
{    This module manages the interface from permanent files into sets.
{    Interfaces are provided to store and retrieve information.
{    -interfaces dealing with the pf root
{       stp$get_pf_root_size
{       stp$get_pf_root
{       stp$store_pf_root
{       stp$purge_pf_root
{    -stp$get_set_owner
{    -interfaces dealing with the pf lock
{       stp$set_pf_lock
{       stp$clear_pf_lock

?? NEWTITLE := 'Global Declarations Referenced by This Module', EJECT ??
?? PUSH (LISTEXT := ON) ??
*copyc pft$root
*copyc ste$error_condition_codes
*copyc ost$signature_lock
*copyc ost$status
*copyc ost$wait
?? POP ??
*copyc osp$append_status_parameter
*copyc osp$set_status_abnormal
*copyc pmp$cycle
*copyc stp$clear_ast_pf_lock
*copyc stp$clear_exclusive_access
*copyc stp$create_jast_entry
*copyc stp$dm_mount_volume
*copyc stp$get_unused_entry_in_jast
*copyc stp$increment_job_count_in_ast
*copyc stp$obtain_ast_entry
*copyc stp$obtain_ast_pf_root
*copyc stp$purge_ast_pf_root
*copyc stp$purge_vst_pf_root
*copyc stp$search_ast_by_set
*copyc stp$search_jast_for_set
*copyc stp$set_ast_pf_lock
*copyc stp$set_exclusive_access
*copyc stp$store_ast_pf_root
*copyc stp$store_vst_pf_root
*copyc stv$p_jast
?? OLDTITLE ??
?? NEWTITLE := '  [XDCL] stp$clear_pf_lock', EJECT ??
*copyc sth$clear_pf_lock

  PROCEDURE [XDCL] stp$clear_pf_lock
    (    set_name: stt$set_name;
     VAR status: ost$status);

    VAR
      ast_entry: stt$active_set_entry,
      ast_index: stt$ast_index;

    stp$set_exclusive_access;
    stp$get_pf_active_set_entry (set_name, ast_index, ast_entry, status);
    IF status.normal THEN
      IF (NOT ast_entry.master_ever_up) OR (ast_entry.master_volume_activity.volume_activity_status =
            stc$inactive) THEN
        stp$clear_exclusive_access;
        stp$dm_mount_volume (ast_entry.master_vsn, status);
        IF NOT status.normal THEN
          osp$set_status_abnormal (stc$set_management_id, ste$master_not_active, ast_entry.master_vsn,
                status);
          osp$append_status_parameter (osc$status_parameter_delimiter, set_name, status);
        IFEND;
        stp$set_exclusive_access;
      ELSE
        stp$clear_ast_pf_lock (ast_index, status);
      IFEND;
    IFEND;
    stp$clear_exclusive_access;

  PROCEND stp$clear_pf_lock;
?? OLDTITLE ??
?? NEWTITLE := '  [XDCL] stp$get_pf_active_set_entry', EJECT ??
*copyc sth$get_pf_active_set_entry

  PROCEDURE [XDCL] stp$get_pf_active_set_entry
    (    set_name: stt$set_name;
     VAR ast_index: stt$ast_index;
     VAR ast_entry: stt$active_set_entry;
     VAR status: ost$status);

    VAR
      job_active_set_entry: stt$job_active_set_entry,
      job_using_set: boolean,
      set_active: boolean;

    stp$search_jast_for_set (set_name, job_active_set_entry, job_using_set);
    IF job_using_set THEN
      ast_index := job_active_set_entry.ast_index;
      stp$obtain_ast_entry (ast_index, ast_entry, status);
    ELSE
      stp$search_ast_by_set (set_name, ast_entry, ast_index, set_active);
      IF set_active THEN
        IF ast_entry.access_status = stc$allow_access THEN
          stp$create_jast_entry (set_name, ast_entry.unique_set_name, ast_index, status);
          IF status.normal THEN
            stp$increment_job_count_in_ast (ast_index, status);
          IFEND;
        ELSE
          osp$set_status_abnormal (stc$set_management_id, ste$not_allowing_access, set_name, status);
        IFEND;
      ELSE
        osp$set_status_abnormal (stc$set_management_id, ste$set_not_active, set_name, status);
      IFEND;
    IFEND;

  PROCEND stp$get_pf_active_set_entry;
?? OLDTITLE ??
?? NEWTITLE := '  [XDCL] stp$get_pf_root', EJECT ??
*copyc sth$get_pf_root

  PROCEDURE [XDCL] stp$get_pf_root
    (    set_name: stt$set_name;
     VAR pf_root_size: pft$root_size;
     VAR pf_root_container: pft$root;
     VAR status: ost$status);

    VAR
      ast_entry: stt$active_set_entry,
      ast_index: stt$ast_index;

    {
    { Make sure that the job set table exists, prior to locking the mainframe
    { set table, so that if the job pageable heap is damaged, the failure
    { will not leave the mainframe set table locked.
    {

    stp$reserve_jast_space;

    stp$set_exclusive_access;
    stp$get_pf_active_set_entry (set_name, ast_index, ast_entry, status);
    IF status.normal THEN
      IF (NOT ast_entry.master_ever_up) OR (ast_entry.master_volume_activity.volume_activity_status =
            stc$inactive) THEN
        stp$clear_exclusive_access;
        stp$dm_mount_volume (ast_entry.master_vsn, status);
        IF status.normal THEN
          stp$get_pf_root (set_name, pf_root_size, pf_root_container, status);
        ELSE
          osp$set_status_abnormal (stc$set_management_id, ste$master_not_active, ast_entry.master_vsn,
                status);
          osp$append_status_parameter (osc$status_parameter_delimiter, set_name, status);
        IFEND;
        stp$set_exclusive_access;
      ELSEIF ast_entry.pf_root_ever_stored THEN
        pf_root_size := ast_entry.pf_root_size;
        stp$obtain_ast_pf_root (ast_index, pf_root_container, status);
      ELSE
        osp$set_status_abnormal (stc$set_management_id, ste$pf_root_not_stored, set_name, status);
      IFEND;
    IFEND;
    stp$clear_exclusive_access;

  PROCEND stp$get_pf_root;
?? OLDTITLE ??
?? NEWTITLE := '  [XDCL] stp$get_pf_root_size', EJECT ??
*copyc sth$get_pf_root_size

  PROCEDURE [XDCL] stp$get_pf_root_size
    (    set_name: stt$set_name;
     VAR pf_root_size: pft$root_size;
     VAR status: ost$status);

    VAR
      ast_entry: stt$active_set_entry,
      ast_index: stt$ast_index;

    stp$set_exclusive_access;
    stp$get_pf_active_set_entry (set_name, ast_index, ast_entry, status);
    IF status.normal THEN
      IF (NOT ast_entry.master_ever_up) OR (ast_entry.master_volume_activity.volume_activity_status =
            stc$inactive) THEN
        stp$clear_exclusive_access;
        stp$dm_mount_volume (ast_entry.master_vsn, status);
        IF status.normal THEN
          stp$get_pf_root_size (set_name, pf_root_size, status);
        ELSE
          osp$set_status_abnormal (stc$set_management_id, ste$master_not_active, ast_entry.master_vsn,
                status);
          osp$append_status_parameter (osc$status_parameter_delimiter, set_name, status);
        IFEND;
        stp$set_exclusive_access;
      ELSEIF ast_entry.pf_root_ever_stored THEN
        pf_root_size := ast_entry.pf_root_size;
      ELSE
        osp$set_status_abnormal (stc$set_management_id, ste$pf_root_not_stored, set_name, status);
      IFEND;
    IFEND;
    stp$clear_exclusive_access;

  PROCEND stp$get_pf_root_size;
?? OLDTITLE ??
?? NEWTITLE := '  [XDCL, #GATE] stp$get_set_owner', EJECT ??
*copyc sth$get_set_owner

  PROCEDURE [XDCL, #GATE] stp$get_set_owner
    (    set_name: stt$set_name;
     VAR set_owner: ost$user_identification;
     VAR status: ost$status);

    VAR
      ast_entry: stt$active_set_entry,
      ast_index: stt$ast_index;

    stp$set_exclusive_access;
    stp$get_pf_active_set_entry (set_name, ast_index, ast_entry, status);
    IF status.normal THEN
      IF (NOT ast_entry.master_ever_up) OR (ast_entry.master_volume_activity.volume_activity_status =
            stc$inactive) THEN
        stp$clear_exclusive_access;
        stp$dm_mount_volume (ast_entry.master_vsn, status);
        IF status.normal THEN
          stp$get_set_owner (set_name, set_owner, status);
        ELSE
          osp$set_status_abnormal (stc$set_management_id, ste$master_not_active, ast_entry.master_vsn,
                status);
          osp$append_status_parameter (osc$status_parameter_delimiter, set_name, status);
        IFEND;
        stp$set_exclusive_access;
      ELSE
        set_owner := ast_entry.set_owner;
      IFEND;
    IFEND;
    stp$clear_exclusive_access;

  PROCEND stp$get_set_owner;
?? OLDTITLE ??
?? NEWTITLE := '  [XDCL] stp$purge_pf_root', EJECT ??
*copyc sth$purge_pf_root

  PROCEDURE [XDCL] stp$purge_pf_root
    (    set_name: stt$set_name;
     VAR status: ost$status);

    VAR
      ast_entry: stt$active_set_entry,
      ast_index: stt$ast_index;

    stp$set_exclusive_access;
    stp$get_pf_active_set_entry (set_name, ast_index, ast_entry, status);
    IF status.normal THEN
      IF (NOT ast_entry.master_ever_up) OR (ast_entry.master_volume_activity.volume_activity_status =
            stc$inactive) THEN
        stp$clear_exclusive_access;
        stp$dm_mount_volume (ast_entry.master_vsn, status);
        IF status.normal THEN
          stp$purge_pf_root (set_name, status);
        ELSE
          osp$set_status_abnormal (stc$set_management_id, ste$master_not_active, ast_entry.master_vsn,
                status);
          osp$append_status_parameter (osc$status_parameter_delimiter, set_name, status);
        IFEND;
        stp$set_exclusive_access;
      ELSE
        stp$purge_vst_pf_root (ast_entry.master_vsn, status);
        IF status.normal THEN
          stp$purge_ast_pf_root (ast_index);
        IFEND;
      IFEND;
    IFEND;
    stp$clear_exclusive_access;

  PROCEND stp$purge_pf_root;
?? OLDTITLE ??
?? NEWTITLE := '   [INLINE] stp$reserve_jast_space ', EJECT ??

  PROCEDURE [INLINE] stp$reserve_jast_space;

    VAR
      jast_index: integer,
      status: ost$status;

    IF stv$p_jast = NIL THEN
      stp$get_unused_entry_in_jast (jast_index, status);
    IFEND;

  PROCEND stp$reserve_jast_space;
?? OLDTITLE ??
?? NEWTITLE := '  [XDCL] stp$set_pf_lock', EJECT ??
*copyc sth$set_pf_lock

  PROCEDURE [XDCL] stp$set_pf_lock
    (    set_name: stt$set_name;
         wait: ost$wait;
     VAR status: ost$status);

    VAR
      ast_entry: stt$active_set_entry,
      ast_index: stt$ast_index,
      need_to_try_again: boolean;

    stp$set_exclusive_access;
    REPEAT
      need_to_try_again := FALSE;
      stp$get_pf_active_set_entry (set_name, ast_index, ast_entry, status);
      IF status.normal THEN
        IF (NOT ast_entry.master_ever_up) OR (ast_entry.master_volume_activity.volume_activity_status =
              stc$inactive) THEN
          stp$clear_exclusive_access;
          stp$dm_mount_volume (ast_entry.master_vsn, status);
          IF status.normal THEN
            need_to_try_again := TRUE;
          ELSE
            osp$set_status_abnormal (stc$set_management_id, ste$master_not_active, ast_entry.master_vsn,
                  status);
            osp$append_status_parameter (osc$status_parameter_delimiter, set_name, status);
          IFEND;
          stp$set_exclusive_access;
        ELSE
          stp$set_ast_pf_lock (ast_index, status);
          IF ((NOT status.normal) AND (status.condition = ste$lock_set_in_another_task)) AND
                (wait = osc$wait) THEN
            stp$clear_exclusive_access;
            pmp$cycle (status);
            need_to_try_again := TRUE;
            stp$set_exclusive_access;
          IFEND;
        IFEND;
      IFEND;
    UNTIL NOT need_to_try_again;
    stp$clear_exclusive_access;

  PROCEND stp$set_pf_lock;
?? OLDTITLE ??
?? NEWTITLE := '  [XDCL] stp$store_pf_root', EJECT ??
*copyc sth$store_pf_root

  PROCEDURE [XDCL] stp$store_pf_root
    (    set_name: stt$set_name;
         pf_root: pft$root;
     VAR status: ost$status);

    VAR
      ast_entry: stt$active_set_entry,
      ast_index: stt$ast_index;

    stp$set_exclusive_access;
    stp$get_pf_active_set_entry (set_name, ast_index, ast_entry, status);
    IF status.normal THEN
      IF (NOT ast_entry.master_ever_up) OR (ast_entry.master_volume_activity.volume_activity_status =
            stc$inactive) THEN
        stp$clear_exclusive_access;
        stp$dm_mount_volume (ast_entry.master_vsn, status);
        IF status.normal THEN
          stp$store_pf_root (set_name, pf_root, status);
        ELSE
          osp$set_status_abnormal (stc$set_management_id, ste$master_not_active, ast_entry.master_vsn,
                status);
          osp$append_status_parameter (osc$status_parameter_delimiter, set_name, status);
        IFEND;
        stp$set_exclusive_access;
      ELSE
        stp$store_vst_pf_root (ast_entry.master_vsn, pf_root, status);
        IF status.normal THEN
          stp$store_ast_pf_root (ast_index, pf_root, status);
        IFEND;
      IFEND;
    IFEND;
    stp$clear_exclusive_access;

  PROCEND stp$store_pf_root;
?? OLDTITLE ??
MODEND stm$pf_interfaces;
