volmgt_fsi.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (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 (c) 1996 by Sun Microsystems, Inc.
* All rights reserved.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <volmgt.h>
#include <errno.h>
#include "volmgt.h"
#include "volmgt_private.h"
#include "volmgt_fsi_private.h"
/* just utnil volmgt.h is up to date */
#ifndef VOL_RSV_MAXIDLEN
#define VOL_RSV_MAXIDLEN 256
#endif
/* this routine used by both acquire and release */
static char *fsi_xlate_name(char *);
/*
* arc approved interface
* - can not be modified without approval from an arc
*
* committment level:
* uncommitted
*
* description:
* volmgt_acquire: try to acquire the volmgt advisory device reservation
* for a specific device.
*
* arguments:
* dev - a device name to attempt reserving. This string can be:
* - a full path name to a device
* - a symbolic device name (e.g. floppy0)
*
* id - a reservation string that hopefully describes the application
* making this reservation.
*
* pid - a pointer to a pid_t type. If this argument is not NULL
* and the requested device is already reserved, the process
* id of the reservation owner will be returned in this
* location.
*
* ovr - an override indicator. If set to non-zero, the caller requests
* that this reservation be made unconditionally.
*
* err - the address of a pointer to a string which is to receive the
* id argument used when the current device was reserved. This
* is only used when the current reservation attempt fails due
* to an already existing reservation for this device.
*
* return value(s):
* A non-zero indicator if successful.
*
* A zero indicator if unsuccessful. If errno is EBUSY, then the err
* argument will be set to point to the string that the process currently
* holding the reservation supplied when reserving the device. It is up
* to the caller to release the storage occupied by the string via
* free(3C) when no longer needed.
*
* preconditions:
* none
*/
int
{
int retval = 0; /* default return => ERROR */
int reterr = 0;
#ifdef DEBUG
denter("volmgt_acquire(\"%s\", \"%s\", %s, %#p, %#p): entering\n",
#endif
/*
* the supplied arguments must not be NULL
*/
goto dun;
}
/*
* the id string must not be longer than the maximum allowable
* number of characters
*/
goto dun;
}
goto dun;
}
/*
*/
goto dun;
}
/*
* open the database file
*/
if ((dbid = vol_db_open()) < 0) {
goto dun;
}
/*
* the entry wasn't found, so reserve it
*/
}
} else {
/*
* the entry exists but either override was specified
* or the process holding the reservation is no longer
* active
*
* in either case we'll usurp the reservation
*/
/* reserve the device */
retval = 1;
}
}
} else {
/*
* the entry exists and override was NOT specified
*/
/*
* optionally return the pid of the reservation
* owner
*/
}
}
}
/*
* if an error was encountered (currently only EBUSY supported)
* set errno to reflect it
*/
if (reterr != 0) {
}
dun:
if ((int)dbid >= 0) {
(void) vol_db_close(dbid);
}
}
#ifdef DEBUG
#endif
return (retval);
}
/*
* arc approved interface
* - can not be modified without approval from an arc
*
* committment level:
* uncommitted
*
* description:
* volmgt_release: try to release the volmgt advisory device reservation
* for a specific device.
*
* arguments:
* dev - a device name to attempt reserving. This string can be:
* - a full path name to a device
* - a symbolic device name (e.g. floppy0)
*
* return value(s):
* A non-zero indicator if successful
* A zero indicator if unsuccessful
*
* preconditions:
* none
*/
int
volmgt_release(char *dev)
{
long idev;
int retval = 0; /* default return => FAILURE */
int reterr = 0;
#ifdef DEBUG
#endif
/*
* first let's do some minimal validation of the supplied arguments
*/
/*
* the supplied argument must not be NULL
*/
goto dun;
}
goto dun;
}
/*
*/
goto dun;
}
/*
* open the database file
*/
if ((dbid = vol_db_open()) < 0) {
goto dun;
}
/* the entry wasn't found so I can't clear reservation */
goto dun;
}
/* the entry was found so make sure I can clear it */
/*
* the reservation was made by me, clear it
*/
retval = 1;
}
} else {
/*
* the entry wasn't made by me
*/
}
/*
* if an error was encountered (currently only EBUSY supported)
* set errno to reflect it
*/
if (reterr != 0) {
}
dun:
if ((int)dbid >= 0) {
(void) vol_db_close(dbid);
}
}
#ifdef DEBUG
#endif
return (retval);
}
/*
* translate suplied vol name into a pathname
*
* if volmgt is running, this pathname will be in /vol (or its equiv)
*
* if volmgt is not running then this path may be anywhere
*
*
* if the return value is non-null then it's been alloced
*
* NOTE: assume "vol" is not a NULL ptr
*/
static char *
fsi_xlate_name(char *vol)
{
char *vr; /* volmgt root dir */
#ifdef DEBUG
#endif
/* is it an absolute pathname ?? */
if (*vol == '/') {
if (vm_running) {
/* pathname must be in the /vol namespace */
vr = (char *)volmgt_root();
/* not a cool pathname */
goto dun;
}
}
} else {
/*
* if volmgt is running we can try to dereference it
* if volmgt isn't running then just give up
*/
if (!vm_running) {
/* some unknown "name" */
goto dun;
}
}
dun:
#ifdef DEBUG
#endif
return (res);
}