mm_mmp_cp.c revision cee0fb94c0d4227de0a00efc162fb2739844b641
/*
* 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 <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"
#include "mm_task.h"
#include "mm_path.h"
int
{
char *type;
int rows;
int rc;
char *dev_name;
char *mgr_name;
char *query;
char *host;
char *disabled;
char *response_message = NULL;
5055,
"msg_rsp", response_message,
MESS_END);
return (MM_CMD_ERROR);
}
return (MM_CMD_DONE);
}
return (MM_CMD_ERROR);
}
/* device type */
/* find device manager */
"mm_cpexit_cmd_func: "
"out of mem creating source list");
"out of mem creating source list");
return (MM_CMD_ERROR);
}
query = "select distinct "
"\"DM\".\"DriveName\",\"DM\".\"DMName\","
"\"DM\".\"DMTargetHost\",\"DM\".\"DMDisabled\" from ";
} else {
"mm_cpexit_cmd_func: "
"out of mem creating source list");
"out of mem creating source list");
return (MM_CMD_ERROR);
}
query = "select distinct "
"\"LM\".\"LibraryName\",\"LM\".\"LMName\","
"\"LM\".\"LMTargetHost\",\"LM\".\"LMDisabled\" from ";
}
"mm_cpexit_cmd_func: "
"db error creating helper functions");
return (MM_CMD_ERROR);
}
goto db_error;
}
if (rows == 0) {
5079,
MESS_END);
return (MM_CMD_ERROR);
} else if (rows > 1) {
/* Can only have 1 dev manager */
5076,
MESS_END);
return (MM_CMD_ERROR);
}
/*
* Disable device manager
*/
"set \"DMDisabled\" = 'true' "
"where \"DriveName\" = '%s' and "
"\"DMName\" = '%s';",
} else {
"set \"LMDisabled\" = 'true' "
"where \"LibraryName\" = '%s' and "
"\"LMName\" = '%s';",
}
goto db_error;
}
}
/*
* Check for connection
*/
mgr_name) == 0) &&
dev_name) == 0)) {
/* Found the wka of dev manager */
break;
}
}
return (MM_CMD_DONE);
}
/* Allocate command and add to the queue */
/*
* exit command
*/
"Unable to malloc mm_command_t: %s",
return (1);
}
} else {
}
} else {
}
task);
/*
* Notify watcher
*/
"failed to add config "
"event for watcher");
return (MM_CMD_ERROR);
}
"added exit command for %s %s",
return (MM_DISPATCH_DEPEND);
return (MM_CMD_ERROR);
5062,
MESS_END);
return (MM_CMD_ERROR);
rc = MM_CMD_ERROR;
return (rc);
}
int
{
char *type;
int rows;
int rc;
char *dev_name;
char *mgr_name;
char *query;
char *host;
char *disabled;
char *state_soft;
char *state_hard;
return (MM_CMD_ERROR);
}
/* device type */
/* find device manager */
"mm_cpstart_cmd_func: "
"out of mem creating source list");
"out of mem creating source list");
return (MM_CMD_ERROR);
}
query = "select distinct "
"\"DM\".\"DriveName\",\"DM\".\"DMName\","
"\"DM\".\"DMTargetHost\",\"DM\".\"DMDisabled\", "
"\"DM\".\"DMStateSoft\",\"DM\".\"DMStateHard\" from ";
} else {
"mm_cpstart_cmd_func: "
"out of mem creating source list");
"out of mem creating source list");
return (MM_CMD_ERROR);
}
query = "select distinct "
"\"LM\".\"LibraryName\",\"LM\".\"LMName\","
"\"LM\".\"LMTargetHost\",\"LM\".\"LMDisabled\", "
"\"LM\".\"LMStateSoft\",\"LM\".\"LMStateHard\" from ";
}
"mm_cpstart_cmd_func: "
"db error creating helper functions");
return (MM_CMD_ERROR);
}
goto db_error;
}
if (rows == 0) {
5079,
MESS_END);
return (MM_CMD_ERROR);
} else if (rows > 1) {
/* Can only have 1 dev manager */
5076,
MESS_END);
return (MM_CMD_ERROR);
}
/* manager is already enabled + connected */
"enabled and connected");
"%s is already enabled and connected",
mgr_name);
return (MM_CMD_DONE);
}
/*
* Clear broken state
*/
"set \"DMStateHard\" = 'ready' "
"where \"DriveName\" = '%s' and "
"\"DMName\" = '%s';",
} else {
"set \"LMStateHard\" = 'ready' "
"where \"LibraryName\" = '%s' and "
"\"LMName\" = '%s';",
}
goto db_error;
}
}
/*
* Enable device manager
*/
"set \"DMDisabled\" = 'false' "
"where \"DriveName\" = '%s' and "
"\"DMName\" = '%s';",
} else {
"set \"LMDisabled\" = 'false' "
"where \"LibraryName\" = '%s' and "
"\"LMName\" = '%s';",
}
goto db_error;
}
"is already connected, %s",
mgr_name);
"disabled device manager "
"is already connected, %s",
mgr_name);
return (MM_CMD_DONE);
}
/*
* Notify watcher
*/
"enable",
"failed to add config "
"enable event");
return (MM_CMD_ERROR);
}
"device manager should be started, %s",
mgr_name);
return (MM_CMD_DONE);
}
"manager is enabled but not connecetd,"
" notify watcher to restart, %s",
mgr_name);
/*
* Notify watcher
*/
"enable",
"failed to add config "
"enable event");
return (MM_CMD_ERROR);
}
"device manager should be started, %s",
mgr_name);
"%s is already enabled but not connected, "
"attempting to restart",
mgr_name);
return (MM_CMD_DONE);
}
return (MM_CMD_DONE);
return (MM_CMD_ERROR);
5062,
MESS_END);
return (MM_CMD_ERROR);
rc = MM_CMD_ERROR;
return (rc);
}
int
{
char *fromslot;
char *toslot;
char *drive_name;
char *slot_name;
int slot = 0;
int drive = 0;
int range = 0; /* all slots */
int rows;
char *lib_name;
char *lm_name;
const char *query;
int rc;
return (MM_CMD_ERROR);
}
/* slot range */
MMS_PN_CLAUSE, NULL)) {
range = 1;
}
/* single slot */
MMS_PN_CLAUSE, NULL)) {
slot = 1;
}
/* single drive */
MMS_PN_CLAUSE, NULL)) {
drive = 1;
}
/* find lm */
"mm_cpscan_cmd_func: "
"out of mem creating source list");
"out of mem creating source list");
return (MM_CMD_ERROR);
}
query = "select \"LM\".\"LibraryName\","
"\"LM\".\"LMName\" from ";
"mm_cpscan_cmd_func: "
"db error creating helper functions");
return (MM_CMD_ERROR);
}
return (MM_CMD_ERROR);
}
5080,
MESS_END);
return (MM_CMD_ERROR);
} else if (rows > 1) {
5076,
MESS_END);
return (MM_CMD_ERROR);
}
/* check for library ready and online */
"\"LIBRARY\".\"LibraryStateSoft\","
"\"LM\".\"LMStateSoft\","
"\"LIBRARY\".\"LibraryOnline\" "
"FROM \"LIBRARY\",\"LM\" "
"WHERE (\"LIBRARY\".\"LibraryName\" = '%s' AND "
"\"LIBRARY\".\"LMName\" = '%s') AND "
"(\"LM\".\"LibraryName\" = '%s' AND "
"\"LM\".\"LMName\" = '%s')",
return (MM_CMD_ERROR);
}
5021,
"lm",
MESS_END);
return (MM_CMD_ERROR);
}
"ready") != 0 ||
"ready") != 0 ||
"true") != 0) {
5021,
"lm",
MESS_END);
return (MM_CMD_ERROR);
}
/* begin lm scan command */
if (range) { /* build lm scan cmd */
/* scan part of slots */
query = "scan task[\"%s\"] fromslot[\"%s\"] "
"toslot[\"%s\"];";
} else if (slot) {
/* single slot */
query = "scan task[\"%s\"] slot[\"%s\"];";
} else if (drive) {
/* single drive */
query = "scan task[\"%s\"] drive[\"%s\"];";
} else {
/* scan all slots */
query = "scan task[\"%s\"] all;";
}
/*
* LMP scan command
*/
return (MM_DISPATCH_DEPEND);
cmd->cmd_bufsize = 0;
/* Send Failure */
char *response_message = NULL;
5055,
"msg_rsp", response_message,
MESS_END);
rc = MM_CMD_ERROR;
} else {
/* Send Success */
rc = MM_CMD_DONE;
}
return (rc);
}
return (MM_CMD_ERROR);
5062,
MESS_END);
return (MM_CMD_ERROR);
}
int
{
char *type;
int scope = 0; /* full reset */
int rows;
int rc;
char *dev_name;
char *mgr_name;
char *query;
char *response_message = NULL;
5055,
"msg_rsp", response_message,
MESS_END);
return (MM_CMD_ERROR);
}
return (MM_CMD_DONE);
}
return (MM_CMD_ERROR);
}
/* device type */
/* reset scope */
MMS_PN_KEYWORD, NULL)) {
scope = 1;
}
/* find device manager */
"mm_cpreset_cmd_func: "
"out of mem creating source list");
"out of mem creating source list");
return (MM_CMD_ERROR);
}
query = "select distinct "
"\"DM\".\"DriveName\",\"DM\".\"DMName\" from ";
} else {
"mm_cpreset_cmd_func: "
"out of mem creating source list");
"out of mem creating source list");
return (MM_CMD_ERROR);
}
query = "select distinct "
"\"LM\".\"LibraryName\",\"LM\".\"LMName\" from ";
}
"mm_cpreset_cmd_func: "
"db error creating helper functions");
return (MM_CMD_ERROR);
}
"cmd buf is %s",
goto db_error;
}
if (rows == 0) {
5074,
MESS_END);
} else {
5075,
MESS_END);
}
return (MM_CMD_ERROR);
} else if (rows > 1) {
/* Can only have 1 dev manager */
5076,
MESS_END);
return (MM_CMD_ERROR);
}
/* check device connections */
/* check for connected device */
"\"DM\".\"DMStateSoft\" FROM \"DM\" "
"WHERE \"DM\".\"DriveName\" = '%s' AND "
"\"DM\".\"DMName\" ='%s';",
goto db_error;
}
"\"LM\".\"LMStateSoft\" FROM \"LM\" "
"WHERE \"LM\".\"LibraryName\" = '%s' AND "
"\"LM\".\"LMName\" = '%s';",
goto db_error;
}
"Error getting device manager state");
"Error getting device manager state");
return (MM_CMD_ERROR);
}
"Device and Manager State:");
" Device = %s",
5077,
"dm",
MESS_END);
} else {
5078,
"lm",
MESS_END);
}
return (MM_CMD_ERROR);
}
mgr_name) == 0) &&
dev_name) == 0)) {
/* Found the wka of dev manager */
break;
}
}
5077,
"dm",
MESS_END);
} else {
5078,
"lm",
MESS_END);
}
return (MM_CMD_ERROR);
}
/* Allocate command and add to the queue */
/*
* reset command
*/
"Unable to malloc mm_command_t: %s",
return (1);
}
} else {
}
if (scope) { /* build device reset cmd */
"partial;", task);
} else {
task);
}
} else {
}
"added reset command for %s %s",
return (MM_DISPATCH_DEPEND);
return (MM_CMD_ERROR);
5062,
MESS_END);
return (MM_CMD_ERROR);
rc = MM_CMD_ERROR;
return (rc);
}