/*
* 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.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <pri.h>
#include "priplugin.h"
static void priplugin_init(void);
static void priplugin_fini(void);
static void
static void *pri_worker_thread(void *arg);
static void *pri_reader_thread(void *arg);
"pri_plugin",
};
static void
{
}
{
int status;
if (status == PICL_SUCCESS)
return (B_TRUE);
else
return (B_FALSE);
}
void
{
}
}
/*ARGSUSED*/
static int
{
int status;
else
return (PICL_WALK_CONTINUE);
}
static void
priplugin_init(void)
{
int status;
"being created; callbacks being registered\n");
&pri_worker_thread_id)) < 0) {
"%d\n", status);
(void) mutex_destroy(&rebuild_lock);
(void) cond_destroy(&rebuild_cv);
THR_BOUND, &pri_reader_thread_id)) < 0) {
"%d\n", status);
(void) mutex_lock(&rebuild_lock);
(void) cond_signal(&rebuild_cv);
(void) mutex_unlock(&rebuild_lock);
(void) mutex_destroy(&rebuild_lock);
(void) cond_destroy(&rebuild_cv);
} else {
"threads created - registering event handlers\n");
/*
* register event_handler for both "sysevent-device-added",
* "sysevent_device_removed", and for
* "sysevent-dr-app-state-change" PICL events
*/
}
}
/*
* This thread handles the main processing of PRI data. It is woken
* up by either the event handler, to process a PICL event, or it is
* woken up by the PRI reader thread which has just fetched a new
* copy of the PRI.
*/
/*ARGSUSED*/
static void *
{
int status;
(void) mutex_lock(&rebuild_lock);
/*LINTED E_FUNC_RET_MAYBE_IGNORED2*/
while (1) {
if (all_thr_exit == B_TRUE) {
(void) mutex_unlock(&rebuild_lock);
"exit\n");
break;
}
/*
* We don't get events for changes to system memory,
* and we do not want to interfere with other plug-ins
* by making changes to the picl tree. So if we were
* woken up by a thread then do not destroy and rebuild
* the memory info. Just go fix the labels.
*/
if (event_caught == B_FALSE) {
if (status != PICL_SUCCESS) {
"can't get picl tree root node: %s\n",
continue;
}
"picl and PRI nodes\n");
if (status != PICL_SUCCESS) {
"can't remove old memory segments: \n",
} else
"old memory segments removed\n");
if (status != PICL_SUCCESS) {
"memory segments walk failed: \n",
} else
"success walking memory node\n");
} else
}
return (NULL);
}
/*
* This thread camps out in the PRI driver, waiting for it to return
* the contents of a new PRI. When the PRI is changed this thread
* reads that data and prepares it for processing by the worker thread.
* It then signals the worker thread to process the new PRI data.
*/
/*ARGSUSED*/
static void *
{
if (pri_init() != 0) {
return (NULL);
}
/*
* It's entirely possible that a new PRI may get pushed while
* the worker thread is processing the previous PRI. We will
* wait until the worker is finished, then flush the old contents
* and wake up the worker again to process the new data.
*/
tok = 0;
count = 0;
/*LINTED E_FUNC_RET_MAYBE_IGNORED2*/
while (1) {
/*
* The _fini() function will close the PRI's fd, which will
* cause this function to break out of waiting in the PRI
* driver and return an error.
*/
(void) mutex_lock(&rebuild_lock);
if (all_thr_exit == B_TRUE) {
(void) mutex_unlock(&rebuild_lock);
"exit\n");
break;
}
/*
* Wait until the worker is idle before swapping in the
* new PRI contents, then signal the worker to process
* that new data.
*/
if (status == 0) {
/* old buffer will be freed by pri_bufinit() */
(void) cond_signal(&rebuild_cv);
count = 0;
} else {
"NULL mdp!\n");
status = -1;
}
}
/*
* Try to handle SP resets or other unexplained errors
* from ds by closing down and re-opening the PRI driver.
*/
if (status == -1) {
if (errno != 0) {
"can't get PRI contents: %s\n",
}
if (++count > 6) {
"can't process PRI data\n");
(void) mutex_unlock(&rebuild_lock);
break;
}
/* old buffer will be freed by pri_fini() */
pri_fini();
tok = 0;
sleep(10);
if (pri_init() != 0) {
"can't reinitialize PRI driver\n");
(void) mutex_unlock(&rebuild_lock);
break;
}
}
(void) mutex_unlock(&rebuild_lock);
}
return (NULL);
}
static void
priplugin_fini(void)
{
if (all_thr_exit == B_TRUE)
return;
/* unregister the event handlers */
/*
* Set the exit flag to tell the worker thread to quit and wake
* up that thread. Once that thread is reaped then pull the rug
* out from the PRI reader thread by calling pri_fini(), which
* closes the PRI fd. That wakes the PRI reader thread and it
* will then exit as well.
*/
(void) mutex_lock(&rebuild_lock);
(void) cond_signal(&rebuild_cv);
(void) mutex_unlock(&rebuild_lock);
pri_fini();
(void) mutex_destroy(&rebuild_lock);
(void) cond_destroy(&rebuild_cv);
}
void
priplugin_register(void)
{
}
/*
* Discovery event handler
* respond to the picl events:
* PICLEVENT_SYSEVENT_DEVICE_ADDED
* PICLEVENT_SYSEVENT_DEVICE_REMOVED
* PICLEVENT_DR_AP_STATE_CHANGE
*
* We can't do much of anything fancy since the event data doesn't contain
* a nac for the device. Nothing to do for remove - the devtree plug-in
* will have removed the node for us. For add we have to go back and
* add labels again.
*/
static void
{
"%s\n", ename);
"%s; waking worker thread\n", ename);
(void) mutex_lock(&rebuild_lock);
if (all_thr_exit == B_FALSE) {
/*
* Tell the worker thread to only re-examine the
* IO device labels.
*/
(void) cond_signal(&rebuild_cv);
}
(void) mutex_unlock(&rebuild_lock);
}
}
/*VARARGS2*/
void
{
#if (PRI_DEBUG != 0)
#endif
}