mgmt_dsk.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 <libgen.h>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <dirent.h>
#include "mms_mgmt.h"
#include "mmp_defs.h"
#include "mgmt_sym.h"
#include "mgmt_util.h"
#include "mms_cfg.h"
#include "dda.h"
static int
static int
#define DEF_DK_LIBNAME "MMS_Disk_Archive"
/*
* mms_mgmt_add_dklib()
*
* Single library for _all_ disk volumes. Added automatically
* the first time a disk virtual drive or disk volume is created.
*
*/
int
{
int st;
void *response;
char tid[64];
char cmd[8192];
char buf[1024];
int scf_size = MMS_CFG_MAX_VALUE;
if (!mgmt_chk_auth("solaris.mms.create")) {
return (EACCES);
}
if (!session) {
if (st != 0) {
return (st);
}
}
if (st == 0) {
}
}
if (st != 0) {
goto done;
}
if (!libname) {
}
if (st != 0) {
goto done;
}
/* already there, nothing to do */
goto done;
}
(void) mms_gen_taskid(tid);
"create task['%s'] type[LIBRARY] "
"set[LIBRARY.'LibraryName' '%s'] "
"set[LIBRARY.'LibraryType' 'DISK'];",
&response);
if (st != 0) {
goto done;
}
(void) mms_gen_taskid(tid);
"create task['%s'] type[LM] "
"set[LM.'LMName' '%s'] "
"set[LM.'LibraryName' '%s'] "
"set[LM.'LMTargetHost' '%s'];",
&response);
if (st == 0) {
/* online this library */
if (st != 0) {
goto done;
}
}
done:
if (sess) {
(void) mms_goodbye(sess, 0);
}
if (dklib) {
}
return (st);
}
static int
{
int st;
void *response;
char tid[64];
char cmd[8192];
char buf[1024];
if (!dklib) {
return (MMS_MGMT_NOARG);
}
if (!session) {
if (st != 0) {
return (st);
}
}
(void) mms_gen_taskid(tid);
"show task['%s'] report[LIBRARY.'LibraryName'] "
"reportmode[namevalue] ", tid);
if (!libname) {
"match[streq(LIBRARY.'LibraryType' 'DISK')];",
sizeof (cmd));
} else {
"match[and "
"(streq(LIBRARY.'LibraryType' 'DISK') "
"streq(LIBRARY.'LibraryName' '%s'))];",
libname);
}
&response);
if (st == 0) {
dklib);
}
if (sess) {
(void) mms_goodbye(sess, 0);
}
return (st);
}
int
{
int st;
void *response;
char tid[64];
char cmd[8192];
char thishost[1024];
if (!nvl) {
return (MMS_MGMT_NOARG);
}
if (!mgmt_chk_auth("solaris.mms.create")) {
return (EACCES);
}
if (st != 0) {
return (st);
}
if (st != 0) {
return (st);
}
if (st == 0) {
}
}
if (st != 0) {
return (st);
}
if (st != 0) {
return (st);
}
if (st != 0) {
return (st);
}
if (!session) {
if (st != 0) {
return (st);
}
}
/*
* We will always use the 'default' "DISK" library.
* If it wasn't returned in the list, create it.
*/
if (!libname) {
}
if (st != 0) {
goto done;
}
}
if (st != 0) {
goto done;
}
if (st != 0) {
goto done;
}
/* add the cartridge to MMS */
(void) mms_gen_taskid(tid);
"create task['%s'] type[CARTRIDGE] "
"set[CARTRIDGE.'CartridgePCL' '%s'] "
"set[CARTRIDGE.'CartridgeTypeName' 'DISK'] "
"set[CARTRIDGE.'CartridgeGroupName' '%s'] "
"set[CARTRIDGE.'LibraryName' '%s'] "
"set[CARTRIDGE.'CartridgeMountPoint' '%s'] "
"set[CARTRIDGE.'CartridgePath' '%s'];",
&response);
if (st == 0) {
/* create the partition */
}
done:
if (sess) {
(void) mms_goodbye(sess, 0);
}
if (dklib) {
}
(void) mms_gen_taskid(tid);
return (st);
}
static int
{
int st;
int fd = -1;
return (MMS_MGMT_NOARG);
}
if (st == 0) {
return (st);
}
if (st == 0) {
}
if (st == 0) {
/* TODO: set to root:bin for now */
} else {
}
}
}
if (st != 0) {
return (st);
}
if (st == 0) {
}
} else {
}
if (st != 0) {
return (st);
}
if (mntpt) {
if (st != 0) {
}
}
/*
* Create the data file. TODO: reserve space??
*/
if (fd == -1) {
return (st);
}
/* TODO: Fix this ownership too */
/*
* Create the metadata file
*/
if (fd == -1) {
return (st);
}
if (rlen != sizeof (dda_metadata_t)) {
return (st);
}
/* Create the index file containing one empty record */
if (fd == -1) {
return (st);
}
if (rlen != sizeof (dda_index_t)) {
return (st);
}
/* can't happen?? */
return (st);
}
if (*wpath == '/') {
/* don't include the slash, it upsets DM */
wpath++;
}
return (0);
}
int
{
int st;
void *response;
char tid[64];
char cmd[8192];
char buf[1024];
char thishost[1024];
char ddadev[1024];
int count = 0;
int i;
if (!mgmt_chk_auth("solaris.mms.create")) {
return (EACCES);
}
if (!nvl) {
return (MMS_MGMT_NOARG);
}
/*
* find an available dda number. if ! available, fail, error
* msg should tell user how to add new ones.
*/
if (st != 0) {
return (st);
}
if (!libname) {
}
return (st);
}
if (st != 0) {
return (st);
}
if (!session) {
if (st != 0) {
goto done;
}
}
/* Create the library if it doesn't already exist */
if (st != 0) {
goto done;
}
/* fetch dkdrives already configured, if any */
(void) mms_gen_taskid(tid);
"show task['%s'] reportmode[namevalue] "
"report[DM.'DMTargetPath' DM.'DMTargetHost' "
"DRIVE.'DriveName'] "
"match[streq(DM.'DMTargetHost' '%s')];",
&response);
if (st == 0) {
&drvs);
}
ddadev[0] = '\0';
continue;
}
/* already used */
ddadev[0] = '\0';
continue;
}
break;
}
if (ddadev[0] == '\0') {
goto done;
}
(void) mms_gen_taskid(tid);
"create task['%s'] type[DRIVEGROUP] "
"set[DRIVEGROUP.'DriveGroupName' 'DG_%s'];",
&response);
if (st != 0) {
goto done;
}
(void) mms_gen_taskid(tid);
"create task['%s'] type[DRIVE] "
"set[DRIVE.'DriveName' '%s'] "
"set[DRIVE.'DriveGroupName' 'DG_%s'] "
"set[DRIVE.'LibraryName' '%s'] "
"set[DRIVE.'ReserveDrive' 'no'] "
"set[DRIVE.'DriveGeometry' '%s']",
if (st == 0) {
" set[DRIVE.'MessageLevel' '%s']",
val);
}
if (st == 0) {
" set[DRIVE.'TraceLevel' '%s']",
val);
}
if (st == 0) {
if (st == 0) {
" set[DRIVE.'TraceFileSize' '%s']",
val);
} else {
}
}
if (st == 0) {
" set[DRIVE.'UnloadTime' '%s']",
val);
}
&response);
if (st != 0) {
goto done;
}
(void) mms_gen_taskid(tid);
"create task['%s'] type[DM] "
"set[DM.'DMName' 'DM_%s'] "
"set[DM.'DriveName' '%s'] "
"set[DM.'DMTargetHost' '%s'] "
"set[DM.'DMTargetPath' '%s'];",
&response);
if (st != 0) {
goto done;
}
for (i = 0; i < count; i++) {
(void) mms_gen_taskid(tid);
"create task['%s'] type[DRIVEGROUPAPPLICATION] "
"set[DRIVEGROUPAPPLICATION.'ApplicationName' '%s'] "
"set[DRIVEGROUPAPPLICATION.'DriveGroupName' 'DG_%s'];",
&response);
if (st != 0) {
goto done;
}
}
if (st == 0) {
}
}
done:
if (sess) {
(void) mms_goodbye(sess, 0);
}
if (apps) {
}
if (drvs) {
}
return (st);
}
int
{
int st;
void *response;
char tid[64];
char cmd[8192];
char buf[1024];
char thishost[1024];
int count = 0;
char *mntp;
char *rpath;
int fd = -1;
char *readonly = "false";
if (!mgmt_chk_auth("solaris.mms.media")) {
return (EACCES);
}
if (!nvl) {
return (MMS_MGMT_NOARG);
}
if (st != 0) {
return (st);
}
if (st == 0) {
}
if (st != 0) {
return (st);
}
if (st != 0) {
return (st);
}
if (!session) {
if (st != 0) {
return (st);
}
}
/* TODO: Uniquely identify the cartridge. No host name?! */
(void) mms_gen_taskid(tid);
"show task['%s'] report[CARTRIDGE] reportmode[namevalue] "
"match[streq(CARTRIDGE.'CartridgePCL' '%s')];",
&response);
if (st == 0) {
&attrs);
}
if (st != 0) {
goto done;
}
/* make sure we only got one */
count = 0;
count++;
}
if (count > 1) {
goto done;
} else if (count == 0) {
goto done;
}
if (st != 0) {
goto done;
}
if (st != 0) {
goto done;
}
if (fd == -1) {
goto done;
}
/*
* Preclude acting on an in-use cartridge. Try to
* lock it -- if it's busy, DDA will hold the lock
* so we should fail back to the user.
*/
goto done;
}
sizeof (dda_metadata_t)) {
goto done;
}
} else {
}
goto done;
}
sizeof (dda_metadata_t)) {
}
done:
if (fd > 0) {
}
if (sess) {
(void) mms_goodbye(sess, 0);
}
if (attrs) {
}
return (st);
}
int
{
int st;
char buf[1024];
if (!volpath) {
return (MMS_MGMT_NOARG);
}
if (!mgmt_chk_auth("solaris.mms.media")) {
return (EACCES);
}
if (*volpath != '/') {
return (st);
}
if (st != 0) {
/* not a failure, already removed */
return (0);
}
return (st);
}
}
}
}
if (st != 0) {
/* again, not a failure if already gone */
st = 0;
} else {
}
}
return (st);
}