mm_lmp_sql.c revision d1d2228c6cf3ec632d28262810ab7902932a5d33
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <pthread.h>
#include <syslog.h>
#include <ctype.h>
#include <mms_list.h>
#include <mms_parser.h>
#include <mms_par_impl.h>
#include <libpq-fe.h>
#include <mms_trace.h>
#include <mms_strapp.h>
#include "mm_db.h"
#include "mm.h"
#include "mm_util.h"
#include "mm_commands.h"
#include "mm_sql.h"
#include "mm_sql_impl.h"
#define MM_LM_READY 0
#define MM_LM_NOT_READY 1
#define MM_LM_ABSENT 2
#define MM_LM_PRESENT 3
#define MM_LM_DISCONNECTED 4
#define MM_LM_ERROR 5
#define MM_LM_WAIT 6
#define MM_LM_SEND 7
int
"where \"LMName\" = '%s'",
lm_name) != MM_DB_DATA) {
return (MM_LM_ERROR);
}
"could not find lm in database");
return (MM_LM_ERROR);
}
"%s is %s",
return (MM_LM_READY);
}
return (MM_LM_NOT_READY);
}
return (MM_LM_PRESENT);
}
return (MM_LM_ABSENT);
}
return (MM_LM_DISCONNECTED);
}
return (MM_LM_ERROR);
}
int
int rc = 0;
/* if not, then return MM_LM_ERROR */
/* because this lmp command cannot be sent to the lm */
"select \"LibraryName\" from \"LIBRARY\""
" where \"LibraryOnline\" = 'true' and "
"\"LMName\" = '%s'; ",
lm_name) != MM_DB_DATA) {
return (MM_LM_ERROR);
}
/* this lm is not an active online lm */
"an online library");
"an online library");
return (MM_LM_ERROR);
}
/* LM is supposed to be online and active */
if (rc == MM_LM_ERROR) {
return (MM_LM_ERROR);
}
if (rc == MM_LM_NOT_READY) {
"need to wait on this cmd ");
return (MM_LM_WAIT);
} else if (rc == MM_LM_READY) {
"lm ready continue");
return (MM_LM_SEND);
} else if (rc == MM_LM_PRESENT) {
"active but not ready");
return (MM_LM_WAIT);
} else {
/* lm is present/disconnected/absent */
"this command from running");
"this command from running");
return (MM_LM_ERROR);
}
}
int
char *cartridge_pcl, char *library_name) {
/* THIS FUNCTION MAY ONLY BE CALLED BY WORKER THREAD */
/* To multi thread, must pass the db ptr */
/* check args */
return (1);
}
if (library_name == NULL) {
return (1);
}
if ((drive_name == NULL) &&
(cartridge_pcl == NULL)) {
"need a drive name or cartridge pcl");
return (1);
} else if ((drive_name) &&
(cartridge_pcl)) {
"cannot have both a drive name and a pcl");
return (1);
}
if (parent_cmd == NULL) {
"No parent command, scan will run independantly");
} else {
"Found a parent, scan will be a child command");
}
/* get the lm name */
"select \"LMName\" from "
"\"LIBRARY\" where "
"\"LibraryName\" = '%s';",
library_name) != MM_DB_DATA) {
"db error getting lm name for LMP scan");
return (1);
}
"Error getting lm name information, "
"library %s, db results != 1",
return (1);
}
/* find the lm's wka */
PQgetvalue(lm_name, 0, 0)) == 0)) {
/* Found the wka of dm */
break;
}
}
PQgetvalue(lm_name, 0, 0)) != 0)) {
/* bad wka */
"lm may not have connected yet");
return (1);
}
"Unable to malloc mm_command_t: %s",
return (1);
}
/* Create the text command */
"scan task[\"%s\"] ",
if (drive_name) {
"drive [\"%s\"]",
} else if (cartridge_pcl) {
"slot [\"%s\"]",
}
return (0);
}
/*
* mm_library_lm_clear_states(db)
*
* Clear all library and lm states at mm startup.
*/
int
{
int rc = 0;
/*
* Reset all libraries and lms states
*/
"\"LibraryBroken\" = default, "
"\"LibraryStateHard\" = default, "
"\"LibraryStateSoft\" = default;") != MM_DB_OK) {
rc = 1;
}
"\"LMStateHard\" = default, "
"\"LMStateSoft\" = default, "
"\"LMHost\" = NULL;") != MM_DB_OK) {
rc = 1;
}
return (rc);
}
/*
* mm_library_mm_wka(mm_data, library, lm)
*
* Find library in list of work areas by library, lm, or both.
*/
mm_wka_t *
{
/* pthread_mutex_lock(&mm_data->mm_wka_mutex); */
break;
break;
break;
}
}
/* pthread_mutex_unlock(&mm_data->mm_wka_mutex); */
return (mm_wka);
}
/*
* mm_library_lm_connect(mm_wka)
*
* Activate library lm at connection time if possiable.
*/
int
{
/*
* Set lm states
*/
return (1);
}
return (0);
}
/*
* mm_library_lm_activate_enable(mm_wka)
*
* Activate the library lm if possiable.
*/
int
{
int rc = 0;
int rows = 0;
/*
* Determine if activate enable can be sent
*/
"\"LIBRARY\",\"LM\" WHERE "
"\"LIBRARY\".\"LibraryDisabled\" = 'false' AND "
"\"LIBRARY\".\"LibraryStateSoft\" = 'ready' AND "
"\"LIBRARY\".\"LibraryBroken\" = 'false' AND "
"\"LIBRARY\".\"LibraryOnline\" = 'true' AND "
"\"LIBRARY\".\"LibraryName\" = '%s' AND "
"\"LIBRARY\".\"LMName\" = '%s' AND "
"\"LM\".\"LMStateHard\" = 'ready' AND "
"\"LM\".\"LMStateSoft\" = 'present' AND "
"\"LM\".\"LibraryName\" = '%s' AND "
if (rc != MM_DB_DATA) {
return (1);
} else if (rows != 1) {
return (0);
}
/*
* Build library activate enable command
*/
"Unable to malloc mm_command_t: %s",
return (1);
}
return (1);
}
/*
* Activate library is inprogress.
*/
return (0);
return (1);
}
/*
* mm_library_lm_disconnect(mm_wka)
*
* Clear library and lm connection states.
*/
int
{
/*
* Only change the library state soft and lm state soft
* preserving possiable 'broken' state.
*/
return (1);
}
return (0);
}
/*
* mm_lm_state_hard(mm_wka, state)
*
* Set lm hard state to 'ready' or 'broken'.
*/
static int
{
"\"LMStateHard\" = '%s' WHERE \"LibraryName\" = '%s' AND "
return (1);
}
return (0);
}
/*
* mm_lm_state_soft(mm_wka, state)
*
* Set lm soft state to 'absent', 'present', 'not ready',
* 'disconnected', or 'ready'.
*/
static int
{
"\"LMStateSoft\" = '%s' WHERE \"LibraryName\" = '%s' AND "
return (1);
}
return (0);
}
#ifdef MM_LIBRARY_LM_REMOVE
static int
{
/*
* Unrecoverable error, deactivate the client,
* flag the library as not in use, and
* remove the client
*/
}
#endif
/* Library and lm configured, connected, and ready. */
int
{
"\"LIBRARY\".\"LibraryStateSoft\",\"LM\".\"LMStateSoft\" "
"FROM \"LIBRARY\",\"LM\" "
"WHERE (\"LIBRARY\".\"LibraryName\" = '%s' AND "
"\"LIBRARY\".\"LMName\" = '%s') AND "
"(\"LM\".\"LibraryName\" = '%s' AND "
"\"LM\".\"LMName\" = '%s');",
return (1);
}
return (1);
}
return (1);
}
return (1);
}
return (0);
return (1);
}
/* Find a library lm cap for import export */
char *
{
"WHERE \"LibraryName\" = '%s' "
"AND \"LMName\" = '%s' "
"AND \"Type\" = 'port' "
"AND (\"Direction\" = 'both' "
"OR \"Direction\" = 'in');",
return (NULL);
}
&cmd->cmd_bufsize,
return (NULL);
}
/* default to using first cap in list */
return (slotgroup);
return (NULL);
}
/*
* mm_lmp_activate_cmd_func(mm_wka, cmd)
*
* Activate enable or disable library lm.
*/
int
{
int flag = 0;
int rc2 = 0;
int rows = 0;
int i = 0;
char *drive_name = NULL;
char *state_soft = NULL;
char *drive_online = NULL;
char *library_name = NULL;
return (MM_ACCEPT_NEEDED);
return (MM_NO_DISPATCH);
} else {
"lmp activate %d not accepted", flag);
return (MM_CMD_ERROR);
}
if (flag == 0) {
/*
* Library should not get any more
* lmp commands
*/
"set state 'present'");
"mm_lmp_activate_cmd_func: "
"LM state changed failed");
}
/* remove and return */
if (mm_has_depend(cmd)) {
return (MM_DEPEND_DONE);
}
return (MM_CMD_DONE);
} else {
/*
* Library is ready for lmp commands
*/
"mm_lmp_activate_cmd_func: "
"LM state changed failed");
}
}
/* An LMP activate enable is finishing successfully */
/* mm_lmp_add_dm_enable will: */
/* 1) Add DM enable for all ready drives */
/* 2 )Clear drives with cartridges loaded */
/* and setup DM enables dependent on the clear */
"select distinct \"DRIVE\".\"DriveName\", "
"\"DRIVE\".\"CartridgePCL\", "
"\"DRIVE\".\"DriveStateSoft\", "
"\"DRIVE\".\"DriveOnline\" "
"from \"DRIVE\""
"where (\"DRIVE\".\"LibraryName\" = '%s'); ",
if (rc2 != MM_DB_DATA) {
/* error */
"Error getting DRIVE information");
return (MM_CMD_DONE);
}
for (i = 0; i < rows; i ++) {
/* For ready and online drives */
/* add the activate enable now */
"mm_lmp_activate_cmd_func: "
"add dm enabled failed");
}
}
rows = 0;
rc2 = 0;
/* remove and return */
if (mm_has_depend(cmd)) {
return (MM_DEPEND_DONE);
}
return (MM_CMD_DONE);
}
}
return (MM_CMD_ERROR);
}
int
{
int rc = 0;
MMS_PN_KEYWORD, NULL)) {
/* Do state changes for 'not ready' */
MMS_PN_KEYWORD, NULL)) {
/* Do state changes for 'broken' */
rc = 1;
}
if (rc != 1) {
"%s set %s to broken",
lib_name);
/* Update library state */
"update \"LIBRARY\" "
"set \"LibraryBroken\" = 't' "
"where \"LibraryName\" = '%s';",
"Error setting LIBRARY.LibraryBroken");
rc = 1;
}
/* Library Down event */
"mm_lmp_ready_cmd_func: "
"error adding lm down event");
}
}
MMS_PN_KEYWORD, NULL)) {
/* Do state changes for 'disconnected' */
"%s disconnected from %s",
lib_name);
/* Library Down event */
"mm_lmp_ready_cmd_func: "
"error adding lm down event");
}
MMS_PN_KEYWORD, NULL)) {
/* Do state changes for 'present' */
"%s, %s in present state ",
lib_name);
/* Library Down event */
"mm_lmp_ready_cmd_func: "
"error adding lm down event");
}
} else {
/* Library Ready event */
"mm_lmp_ready_cmd_func: "
"error adding lm up event");
}
}
if (rc) {
return (MM_CMD_ERROR);
}
return (MM_CMD_DONE);
return (MM_CMD_ERROR);
}
int i = 0;
int num_dm = 0;
char *cur_dm_name = NULL;
char *cur_dm_state = NULL;
int request_oper = 0;
int auto_clear = 0;
if (drive_name == NULL ||
state_soft == NULL ||
drive_online == NULL ||
"mm_lmp_add_dm_enable passed a NULL arg, "
"cannot enable DM");
return (NULL);
}
cart_pcl);
/* Determine if this drive needs a clear */
/* if so set up the clear */
if (mm_system_settings(db,
&request_oper, &auto_clear)) {
"mm_lmp_add_dm_enable: "
"db error getting system settings");
request_oper = 0;
auto_clear = 1;
}
(auto_clear)) {
MM_NON_MMS_CART, 1, 0);
"mm_lmp_add_dm_enable : error "
"adding clear drive"
"for non-mms cart");
} else {
"added clear for non-mms tape, %s",
}
/* If this drive is 'in use' do not add a clear */
/* This function is only called as part on an lmp enable */
/* If state is 'in use' this MUST be an LM that has */
/* Restarted while a client has a tape mounted */
/* This cart_pcl is not empty */
/*
* Check for MOUNTPHYSICAL
* only add a clear drive func
* for drives W/O a MOUNTPHYSICAL
*/
"func for %s",
"mm_lmp_add_dm_enable : error "
"adding clear drive"
"for %s %s",
cart_pcl);
} else {
"added clear for %s %s",
}
}
/* Check the DM's */
"select distinct \"DM\".\"DMName\","
"\"DM\".\"DMStateSoft\" from \"DM\""
"cross join \"DRIVE\" where"
"((\"DM\".\"DriveName\" = \"DRIVE\".\"DriveName\")"
" and((\"DRIVE\".\"DriveName\" = '%s') AND"
"(\"DRIVE\".\"DriveOnline\" = 'true')));",
drive_name) != MM_DB_DATA) {
"error getting DM names for drive, %s",
return (NULL);
}
"trying to activate %d dm's for drive %s",
num_dm, drive_name);
/* call mm_drive_dm_activate_enable(mm_wka_t *mm_wka) */
/* on the wka of each dm whose name is in PQresults */
for (i = 0; i < num_dm; i++) {
/* check DM state soft */
/* if state soft is ready, or reserved */
/* Dont attempt to enable */
"DM, %s, StateSoft == %s, "
"skip enable",
continue;
}
cur_dm_name) == 0) {
/* to wka found */
break;
}
}
"didn't find a wka for %s",
} else {
} else {
"alloc dm enable, run enable "
"before clear drive");
/* Have the dm enable run */
/* before the clear drive */
}
}
}
}
return (dm_enable);
}
void
{
char *cur_cartid = NULL;
"mm_update_cart_loaded: ");
/* same cart */
cart->cmi_cart_loaded = 0;
cart->cmi_cart_not_ready = 0;
"mm_update_cart_loaded: "
"set cart unloaded and ready");
}
}
}
}
}
void
/* If there is a clear drive for this drive */
drive_name) == 0)) {
"set pcl, %s, in clear drive "
"for this non-mms tape",
}
}
}
/*
* mm_lmp_config_cmd_func(mm_wka, cmd)
*
* Process lmp config partial and full commands.
*/
int
{
char *slot_bay_name = NULL;
char *slotgroup_name = NULL;
char *slot_cart_id = NULL;
char *slot_cart_id_status = NULL;
char *slot_cart_pcl = NULL;
char *slot_occupied = NULL;
char *slot_accessible = NULL;
char *bay_accessible = NULL;
char *drive_name = NULL;
char *drive_bay_name = NULL;
char *drive_cart_pcl = NULL;
char *drive_occupied = NULL;
char *drive_accessible = NULL;
char *freeslots_bay_name = NULL;
char *freeslots_slot_type = NULL;
int freeslots_num_slots = NULL;
char *delslots_slot_name = NULL;
char *slotgrp_name = NULL;
char *slotgrp_bay_name = NULL;
char *slotgrp_direction = NULL;
char *slotgrp_type = NULL;
int perfno = 0;
char *drive_serial_num = NULL;
char *drive_geometry = NULL;
int rc = 0;
int row = 0;
int rows = 0;
int found = 0;
int do_update_drive = 0;
int has_serial = 1;
int has_geometry = 1;
int has_cart_pcl = 0;
int update_cart_state = 0;
/*
* Partial or full config
*/
scope = SCOPE_FULL;
}
/*
* Full config delete. The difference between full and partial
* scope is a full scope deletes the config. A full scope does
* not check for all attributes being present in the command.
*/
if (scope == SCOPE_FULL) {
"\"LibraryName\" = '%s' AND \"LMName\" = '%s';",
return (MM_CMD_ERROR);
}
"\"LibraryName\" = '%s' AND \"LMName\" = '%s';",
return (MM_CMD_ERROR);
}
"\"LibraryName\" = '%s' AND \"LMName\" = '%s';",
return (MM_CMD_ERROR);
}
"\"BayName\" = NULL, "
"\"DriveLibraryAccessible\" = 'false', "
"\"DriveLibraryOccupied\" = 'false', "
"\"CartridgePCL\" = NULL WHERE "
"\"LibraryName\" = '%s';",
return (MM_CMD_ERROR);
}
"\"LibraryName\" = '%s' AND \"LMName\" = '%s';",
return (MM_CMD_ERROR);
}
}
/*
* Library config
*/
MMS_PN_CLAUSE, &work);
MMS_PN_CLAUSE, &work)) {
/* partial config */
if (scope == SCOPE_PARTIAL &&
"\"BAY\" WHERE \"BayName\" = '%s' AND "
"\"LibraryName\" = '%s' AND \"LMName\" = '%s';",
return (MM_CMD_ERROR);
}
if (scope == SCOPE_PARTIAL) {
} else {
rows = 0;
}
/* update bay */
"(\"BayName\", \"LibraryName\", "\
"\"LMName\", "
"\"BayAccessible\") "\
"VALUES ('%s', '%s', '%s', '%s');",
bay_accessible) != MM_DB_OK) {
return (MM_CMD_ERROR);
"\"BayAccessible\" = '%s' "\
"WHERE \"BayName\" = '%s' AND "
"\"LibraryName\" = '%s' AND "\
"\"LMName\" = '%s';",
return (MM_CMD_ERROR);
}
}
MMS_PN_CLAUSE, &work);
MMS_PN_CLAUSE, &work)) {
/* partial config */
if (scope == SCOPE_PARTIAL &&
"FROM \"SLOTGROUP\" "\
"WHERE \"BayName\" = '%s' AND "
"\"LibraryName\" = '%s' AND \"LMName\" = '%s';",
return (MM_CMD_ERROR);
}
if (scope == SCOPE_PARTIAL) {
} else {
rows = 0;
}
/* full or partial config */
"INSERT INTO \"SLOTGROUP\" "
"(\"SlotGroupName\", \"BayName\", "
"\"Direction\", "
"\"Type\", \"LibraryName\", "
"\"LMName\") VALUES "
"('%s', '%s', '%s', '%s', "
"'%s', '%s');",
return (MM_CMD_ERROR);
"\"Direction\" = '%s', "\
"\"Type\" = '%s' WHERE "
"\"SlotGroupName\" = '%s' AND "\
"\"BayName\" = '%s' AND "
"\"LibraryName\" = '%s' AND "\
"\"LMName\" = '%s';",
return (MM_CMD_ERROR);
}
}
MMS_PN_CLAUSE, &work);
MMS_PN_CLAUSE, &work)) {
/* verify mms object depends on */
"\"CartridgeShapeName\" FROM "
"\"SLOTTYPE\" WHERE \"SlotTypeName\" = '%s';",
slot_type) != MM_DB_DATA) {
return (MM_CMD_ERROR);
}
found = 1;
break;
}
}
if (found == 0) {
"no slot type found");
return (MM_CMD_ERROR);
}
/* get cartridge id by cartridge pcl */
"\"CartridgeStatus\" FROM "
"\"CARTRIDGE\" WHERE "\
"\"CartridgePCL\" = '%s' AND "
"\"LibraryName\" = '%s';", slot_cart_pcl,
return (MM_CMD_ERROR);
}
slot_cart_id = NULL;
} else {
}
/* partial config find slot */
if (scope == SCOPE_PARTIAL &&
"\"SLOT\" WHERE \"SlotName\" = '%s' AND "
"\"LibraryName\" = '%s' AND "
"\"LMName\" = '%s';",
return (MM_CMD_ERROR);
}
if (scope == SCOPE_PARTIAL) {
} else {
rows = 0;
}
if (slot_cart_id) {
/* Cartridge is not in a drive */
/* This cartridge has not */
/* had a config done yet */
"update \"CARTRIDGE\" "
"set \"CartridgeStatus\" "
"= 'available' where "
"\"CartridgeID\" = '%s';",
slot_cart_id) !=
MM_DB_OK) {
return (MM_CMD_ERROR);
}
}
"update \"CARTRIDGE\" "
"set \"CartridgeDriveOccupied\" "
"= 'false' where "
"\"CartridgeID\" = '%s';",
slot_cart_id) !=
MM_DB_OK) {
return (MM_CMD_ERROR);
}
/* If this cartridge is a candidate for a mount */
/* must update cart->cmi_cart_loaded */
/* since this cart is no longer loaded */
}
if (slot_cart_id && rows == 0 &&
"(\"SlotName\", \"LibraryName\", \"LMName\", "
"\"BayName\", \"SlotGroupName\", "
"\"SlotTypeName\", "
"\"CartridgeID\", \"CartridgePCL\", "
"\"SlotAccessable\", "
"\"SlotOccupied\") VALUES "
"('%s', '%s', '%s', '%s', '%s', "
"'%s', '%s', '%s', '%s', '%s');", slot_name,
return (MM_CMD_ERROR);
} else if (slot_cart_id &&
"SET \"SlotTypeName\" = '%s', "
"\"CartridgeID\" = '%s', "
"\"CartridgePCL\" = '%s', "
"\"SlotAccessable\" = '%s', "
"\"SlotOccupied\" = '%s', "
"\"BayName\" = '%s', "
"\"SlotGroupName\" = '%s' WHERE "
"\"SlotName\" = '%s' AND "
"\"LibraryName\" = '%s' AND "
"\"LMName\" = '%s';",
conn->cci_instance) !=
MM_DB_OK) {
return (MM_CMD_ERROR);
}
if (results) {
}
}
MMS_PN_CLAUSE, &work);
MMS_PN_CLAUSE, &work)) {
has_serial = 1;
has_geometry = 1;
has_cart_pcl = 0;
update_cart_state = 0;
has_serial = 0;
}
has_geometry = 0;
}
if (!has_serial && !has_geometry) {
"drive spec missing serialnumber/geometry");
continue;
}
if (has_serial) {
if (has_geometry) {
"drive: %s, %s, %s, %s, %s, %s",
} else {
"drive: %s, %s, %s, %s, %s",
}
} else {
}
/* determine if drive is configured */
if (has_serial) {
"\"DriveStateSoft\" FROM "
"\"DRIVE\" WHERE \"DriveSerialNum\" = '%s';",
} else {
"\"DriveStateSoft\" FROM "
"\"DRIVE\" WHERE \"DriveGeometry\" = '%s';",
}
if (rc != MM_DB_DATA) {
return (MM_CMD_ERROR);
}
/* get mm drive name from db */
/* set geometry for this drive */
if (has_geometry &&
has_serial &&
"update \"DRIVE\" set \"DriveGeometry\" = '%s' "
"where \"DriveSerialNum\" = '%s';",
"error setting drive geometry");
}
} else {
/* drive not configured */
drive_name = NULL;
do_update_drive = 0;
}
has_cart_pcl = 1;
}
/* update drive states and location */
if ((do_update_drive) &&
has_cart_pcl) {
"select \"CartridgePCL\", "
"\"CartridgeStatus\" "
"from \"CARTRIDGE\" where "
"\"CartridgePCL\" = '%s' "
"and \"LibraryName\" = '%s';",
return (MM_CMD_ERROR);
} else {
/* PCL does not exists to MMS */
"Cartridge %s does not "
"belong to MMS",
do_update_drive = 0;
"UPDATE \"DRIVE\" SET "
"\"DriveLibrary"
"Accessible\" "
"= '%s', "
"\"DriveLibraryOccupied\" "
"= '%s', "
"\"BayName\" = '%s', "
"\"CartridgePCL\" "
"= '%s' "
"WHERE "
"\"DRIVE\".\"LibraryName\" "
"= '%s' AND "
"\"DRIVE\".\"DriveName\" "
"= '%s' ;",
drive_name) != MM_DB_OK) {
db);
return (MM_CMD_ERROR);
}
} else {
}
}
}
if (do_update_drive) {
/* PCL exists to MMS */
"\"DriveLibraryAccessible\" = '%s', "
"\"DriveLibraryOccupied\" = '%s', "
"\"BayName\" = '%s', "
"\"CartridgePCL\" = '%s' WHERE "
"\"DRIVE\".\"LibraryName\" = '%s' AND "
"\"DRIVE\".\"DriveName\" = '%s' ;",
drive_name) != MM_DB_OK) {
return (MM_CMD_ERROR);
}
} else {
"\"DriveLibraryAccessible\" = '%s', "
"\"DriveLibraryOccupied\" = '%s', "
"\"BayName\" = '%s', "
"\"DriveStateHard\" = 'unloaded', "
"\"CartridgePCL\" = NULL WHERE "
"\"DRIVE\".\"LibraryName\" = '%s' AND "
"\"DRIVE\".\"DriveName\" = '%s' ;",
drive_name) != MM_DB_OK) {
return (MM_CMD_ERROR);
}
}
"update \"CARTRIDGE\" set "
"\"CartridgeDriveOccupied\" = 'true' "
"where \"CartridgePCL\" = "
"'%s' and \"LibraryName\" = '%s';",
return (MM_CMD_ERROR);
}
"unavailable") == 0) {
/* this drive does not have a cart loaded */
/* if this drive state is not 'unavailable' */
/* set the state to 'ready' */
"update \"DRIVE\" set "
"\"DriveStateSoft\" = 'ready' "
"where \"DriveName\" = "
"'%s';",
drive_name) != MM_DB_OK) {
return (MM_CMD_ERROR);
}
}
if (update_cart_state) {
/* This cartridge does not have a */
/* SLOT object yet */
"update \"CARTRIDGE\" set "
"\"CartridgeStatus\" = 'available' "
"where \"CartridgePCL\" = "
"'%s' and \"LibraryName\" = '%s';",
return (MM_CMD_ERROR);
}
}
}
}
MMS_PN_CLAUSE, &work);
MMS_PN_CLAUSE, &work)) {
"freeslots: %s, %s, %d", freeslots_bay_name,
if (scope == SCOPE_PARTIAL &&
"\"SLOTCONFIG\" WHERE "\
"\"LibraryName\" = '%s' AND "
"\"LMName\" = '%s' AND \"BayName\" = '%s' AND "
"\"SlotTypeName\" = '%s';") != MM_DB_DATA) {
return (MM_CMD_ERROR);
}
if (scope == SCOPE_PARTIAL) {
} else {
rows = 0;
}
"INSERT INTO \"SLOTCONFIG\" "
"(\"LibraryName\", \"LMName\", "
"\"BayName\", "
"\"SlotTypeName\", "
"\"SlotConfigNumberFree\") VALUES "
"('%s', '%s', '%s', '%s', '%d');",
freeslots_num_slots) != MM_DB_OK) {
return (MM_CMD_ERROR);
"\"SlotConfigNumberFree\" = '%d' WHERE "
"\"LibraryName\" = '%s' AND "\
"\"LMName\" = '%s' AND "
"\"BayName\" = '%s' AND "\
"\"SlotTypeName\" = '%s';",
freeslots_slot_type) != MM_DB_OK) {
return (MM_CMD_ERROR);
}
}
MMS_PN_CLAUSE, &work);
MMS_PN_CLAUSE, &work)) {
"\"SlotName\" = '%s' AND "\
"\"LibraryName\" = '%s' AND "
"\"LMName\" = '%s';", delslots_slot_name,
return (MM_CMD_ERROR);
}
}
MMS_PN_CLAUSE, &work);
MMS_PN_CLAUSE, &work)) {
}
return (MM_CMD_DONE);
return (MM_CMD_ERROR);
NULL);
return (MM_CMD_ERROR);
}
/*
* mm_lmp_private_cmd_func(mm_wka, cmd)
*
* Send private command to set, unset, or get lm attribute values.
*/
int
{
return (MM_ACCEPT_NEEDED);
return (MM_NO_DISPATCH);
} else {
return (MM_CMD_ERROR);
}
if (mm_has_depend(cmd)) {
return (MM_DEPEND_DONE);
}
return (MM_CMD_DONE);
}
}
return (MM_CMD_ERROR);
}
/*
* mm_lmp_mount_cmd_func(mm_wka, cmd)
*
* Mount a cartridge on a drive.
*/
int
{
int rc = 0;
/* Check LM state before sending */
"check lm state before sending");
if (rc == MM_LM_ERROR) {
return (MM_CMD_ERROR);
} else if (rc == MM_LM_WAIT) {
"wait to send the lmp command ");
return (MM_NO_DISPATCH);
} else if (rc == MM_LM_SEND) {
"lm send the lmp command");
}
return (MM_ACCEPT_NEEDED);
return (MM_NO_DISPATCH);
} else {
return (MM_CMD_ERROR);
}
/* Verify the drive and cartridge */
/* states have been correctly set */
/* should be set from the lmp partial */
/* config that accompanies */
/* the mount command */
"select \"DriveLibraryOccupied\", "
"\"CartridgePCL\" from \"DRIVE\" "
"where \"DriveName\" = '%s';",
"error checking drive states after mount");
return (MM_CMD_ERROR);
}
"error checking drive state,"
"num drives returned != 1, %d returned",
"error checking drive state,"
"num drives returned != 1, %d returned",
return (MM_CMD_ERROR);
}
"t") != 0) {
"error checking drive state,"
"DriveOccupied is not true");
"error checking drive state,"
"DriveOccupied is not true");
return (MM_CMD_ERROR);
}
cart_pcl) != 0) {
"error checking drive state,"
"CartridgePCL, %s != %s",
"error checking drive state,"
"CartridgePCL, %s != %s",
return (MM_CMD_ERROR);
}
/* Update Drive and Cartridge Stats */
"update \"DRIVE\" "
"set \"DriveNumberMounts\" = "
"\"DriveNumberMounts\" + 1, "
"\"DriveTimeMountedLast\" = now(), "
"\"DriveNumberMountsSinceCleaning\" "
"= \"DriveNumberMountsSinceCleaning\" + 1 "
"where \"DriveName\" = '%s';",
"db error updating stats");
return (MM_CMD_ERROR);
}
/* Update Cartridge Table */
"update \"CARTRIDGE\" " \
"set \"CartridgeTimeMountedLast\" = now(), " \
"\"CartridgeNumberMounts\" = "\
"\"CartridgeNumberMounts\" + 1 " \
"where \"CartridgeID\" = '%s';",
"db error updating stats");
return (MM_CMD_ERROR);
}
/* Update Side Table */
"update \"SIDE\" " \
"set \"SideTimeMountedLast\" = now(), "\
"\"SideNumberMounts\" = "\
"\"SideNumberMounts\" + 1 "\
"where \"CartridgeID\" = '%s';",
"db error updating stats");
return (MM_CMD_ERROR);
}
/* Update Partition Table */
"update \"PARTITION\" "\
"set \"PartitionNumberMounts\" = "\
"\"PartitionNumberMounts\" + 1, "\
"\"PartitionTimeMountedLast\" = now() "\
"where \"CartridgeID\" = '%s';",
"db error updating stats");
return (MM_CMD_ERROR);
}
/* Update Volume Table */
"update \"VOLUME\" "\
"set \"VolumeNumberMounts\" = "\
"\"VolumeNumberMounts\" + 1, "\
"\"VolumeTimeMountedLast\" = now() "\
"where \"CartridgeID\" = '%s';",
"db error updating stats");
return (MM_CMD_ERROR);
}
if (mm_has_depend(cmd)) {
return (MM_DEPEND_DONE);
}
return (MM_CMD_DONE);
}
}
return (MM_CMD_ERROR);
}
/*
* mm_lmp_unmount_cmd_func(mm_wka, cmd)
*
* Unmount cartridge from drive.
*/
int
{
int rc = 0;
/* Check LM state before sending */
"check lm state before sending");
if (rc == MM_LM_ERROR) {
return (MM_CMD_ERROR);
} else if (rc == MM_LM_WAIT) {
"wait to send the lmp command ");
return (MM_NO_DISPATCH);
} else if (rc == MM_LM_SEND) {
"lm send the lmp command");
}
return (MM_ACCEPT_NEEDED);
return (MM_NO_DISPATCH);
} else {
return (MM_CMD_ERROR);
}
/* Verify the drive and cartridge */
/* states have been correctly set */
/* should be set from the lmp partial */
/* config that accompanies */
/* the mount command */
"select \"DriveLibraryOccupied\", "
"\"CartridgePCL\" from \"DRIVE\" "
"where \"DriveName\" = '%s';",
"error checking drive states after mount");
return (MM_CMD_ERROR);
}
"error checking drive state,"
"num drives returned != 1, %d returned",
"error checking drive state,"
"num drives returned != 1, %d returned",
return (MM_CMD_ERROR);
}
"f") != 0) {
"error checking drive state,"
"DriveOccupied is not true");
"error checking drive state,"
"DriveOccupied is not true");
return (MM_CMD_ERROR);
}
"") != 0) {
"error checking drive state,"
"CartridgePCL, %s != NULL",
"error checking drive state,"
"CartridgePCL, %s != NULL",
return (MM_CMD_ERROR);
}
if (mm_has_depend(cmd)) {
return (MM_DEPEND_DONE);
}
return (MM_CMD_DONE);
}
}
return (MM_CMD_ERROR);
}
/*
* mm_lmp_inject_cmd_func(mm_wka, cmd)
*
* Inject (import) cartridge from mailslot (cap).
*/
int
{
return (MM_ACCEPT_NEEDED);
return (MM_NO_DISPATCH);
} else {
return (MM_CMD_ERROR);
}
/* Add eject event for all injected cartridges */
MMS_PN_CLAUSE, 0);
"Injected Cartridges:");
/* Add event for this cartridge here */
" %s",
cmd,
db)) {
"mm_lmp_inject_cmd_func: "
"error adding volume "
"inject event");
}
}
}
if (mm_has_depend(cmd)) {
return (MM_DEPEND_DONE);
}
return (MM_CMD_DONE);
}
}
return (MM_CMD_ERROR);
}
/*
* mm_lmp_eject_cmd_func(mm_wka, cmd)
*
* Eject (export) cartridge from mailslot (cap).
*/
int
{
return (MM_ACCEPT_NEEDED);
return (MM_NO_DISPATCH);
} else {
return (MM_CMD_ERROR);
}
/* Add eject event for all ejected cartridges */
MMS_PN_CLAUSE, 0);
"Ejected Cartridges:");
/* Add event for this cartridge here */
" %s",
cmd,
db)) {
"mm_lmp_eject_cmd_func: "
"error adding volume "
"eject event");
}
}
}
if (mm_has_depend(cmd)) {
return (MM_DEPEND_DONE);
}
return (MM_CMD_DONE);
}
}
return (MM_CMD_ERROR);
}
/*
* mm_lmp_cpscan_cmd_func(mm_wka, cmd)
*
* Scan the robot.
*/
int
{
int rc = 0;
"lmp scan sent to non-lmp client");
return (MM_CMD_ERROR);
}
/* Check LM state before sending */
"check lm state before sending");
if (rc == MM_LM_ERROR) {
return (MM_CMD_ERROR);
} else if (rc == MM_LM_WAIT) {
"wait to send the lmp command ");
return (MM_NO_DISPATCH);
} else if (rc == MM_LM_SEND) {
"lm send the lmp command");
}
return (MM_ACCEPT_NEEDED);
return (MM_NO_DISPATCH);
} else {
return (MM_CMD_ERROR);
}
if (mm_has_depend(cmd)) {
return (MM_DEPEND_DONE);
}
return (MM_CMD_DONE);
}
}
return (MM_CMD_ERROR);
}
int
{
/* is this a command we know how to cancel */
"request") == 0) {
}
break;
}
}
/* command not found */
return (MM_CMD_ERROR);
}
/* cancel command */
"from \"REQUEST\" where \"RequestID\" = '%s';",
cmd_reqid) != MM_DB_DATA ||
return (MM_CMD_ERROR);
}
"responded") == 0) {
return (MM_CMD_ERROR);
}
/* remove the request */
return (MM_CMD_ERROR);
}
} else {
return (MM_CMD_ERROR);
}
/* send cancelled command's final-command response */
/* send cancelled command response */
&cmd_p->cmd_bufsize,
break;
}
}
/* same command not found or error sending cancelled response */
return (MM_CMD_ERROR);
}
return (MM_CMD_DONE);
NULL);
return (MM_CMD_ERROR);
return (MM_CMD_ERROR);
}
int
{
"lmp reset state %d, %s",
cmd->cmd_textcmd);
"Issuing reset for %s %s",
conn->cci_client);
return (MM_ACCEPT_NEEDED);
return (MM_NO_DISPATCH);
} else {
return (MM_CMD_ERROR);
}
return (MM_DEPEND_DONE);
}
}
return (MM_CMD_ERROR);
}
int
{
"lmp exit state %d, %s",
cmd->cmd_textcmd);
"Issuing exit for %s %s",
conn->cci_client);
return (MM_ACCEPT_NEEDED);
return (MM_NO_DISPATCH);
} else {
return (MM_CMD_ERROR);
}
return (MM_DEPEND_DONE);
}
}
return (MM_CMD_ERROR);
}