#include <dlfcn.h>
#include <pthread.h>
#include <string.h>
#include <sys/sem.h>
#include "libsun_ima.h"
#include "ima.h"
#include "ima-plugin.h"
extern int number_of_plugins;
extern int libMutex;
extern IMA_PLUGIN_INFO plugintable[IMA_MAX_NUM_PLUGINS];
extern void InitLibrary();
static void os_obtainmutex(int semid);
static void os_releasemutex(int semid);
IMA_API IMA_STATUS SUN_IMA_SetTunableProperties(
IMA_OID oid,
ISCSI_TUNABLE_PARAM *param) {
SUN_IMA_SetTunablePropertiesFn PassFunc;
IMA_UINT i;
IMA_STATUS status;
if (number_of_plugins == -1) {
InitLibrary();
}
if (param == NULL) {
return (IMA_ERROR_INVALID_PARAMETER);
}
if ((oid.objectType != IMA_OBJECT_TYPE_LHBA) &&
(oid.objectType != IMA_OBJECT_TYPE_TARGET)) {
return (IMA_ERROR_INCORRECT_OBJECT_TYPE);
}
os_obtainmutex(libMutex);
status = IMA_ERROR_OBJECT_NOT_FOUND;
for (i = 0; i < number_of_plugins; i++) {
if (plugintable[i].ownerId == oid.ownerId) {
status = IMA_ERROR_UNEXPECTED_OS_ERROR;
os_obtainmutex(plugintable[i].pluginMutex);
#ifdef SOLARIS
PassFunc = (SUN_IMA_SetTunablePropertiesFn)
dlsym(plugintable[i].hPlugin,
"SUN_IMA_SetTunableProperties");
#endif
if (PassFunc != NULL) {
status = PassFunc(oid, param);
}
os_releasemutex(plugintable[i].pluginMutex);
break;
}
}
os_releasemutex(libMutex);
return (status);
}
IMA_API IMA_STATUS SUN_IMA_GetTunableProperties(
IMA_OID oid,
ISCSI_TUNABLE_PARAM *param) {
SUN_IMA_GetTunablePropertiesFn PassFunc = NULL;
int i;
IMA_STATUS status;
if (number_of_plugins == -1) {
InitLibrary();
}
if (param == NULL) {
return (IMA_ERROR_INVALID_PARAMETER);
}
if ((oid.objectType != IMA_OBJECT_TYPE_LHBA) &&
(oid.objectType != IMA_OBJECT_TYPE_TARGET)) {
return (IMA_ERROR_INCORRECT_OBJECT_TYPE);
}
os_obtainmutex(libMutex);
status = IMA_ERROR_OBJECT_NOT_FOUND;
for (i = 0; i < number_of_plugins; i++) {
status = IMA_ERROR_UNEXPECTED_OS_ERROR;
if (plugintable[i].ownerId == oid.ownerId) {
os_obtainmutex(plugintable[i].pluginMutex);
#ifdef SOLARIS
PassFunc = (SUN_IMA_GetTunablePropertiesFn)
dlsym(plugintable[i].hPlugin,
"SUN_IMA_GetTunableProperties");
#endif
if (PassFunc != NULL) {
status = PassFunc(oid, param);
}
os_releasemutex(plugintable[i].pluginMutex);
break;
}
}
os_releasemutex(libMutex);
return (status);
}
static void
os_obtainmutex(int semid)
{
struct sembuf sem_b;
sem_b.sem_num = 0;
sem_b.sem_op = -1;
sem_b.sem_flg = SEM_UNDO;
(void) semop(semid, &sem_b, 1);
}
static void
os_releasemutex(int semid)
{
struct sembuf sem_b;
sem_b.sem_num = 0;
sem_b.sem_op = 1;
sem_b.sem_flg = SEM_UNDO;
(void) semop(semid, &sem_b, 1);
}