/*
* 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
*/
/*
*/
/*
* This RCM module adds support to the RCM framework for IBPART links
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <synch.h>
#include <assert.h>
#include <strings.h>
#include "rcm_module.h"
#include <libintl.h>
#include <libdllink.h>
#include <libdlib.h>
#include <libdlpi.h>
/*
* Definitions
*/
#ifndef lint
#define _(x) gettext(x)
#else
#define _(x) x
#endif
/* Some generic well-knowns and defaults used in this module */
/* IBPART link flags */
typedef enum {
/* link representation */
typedef struct dl_ibpart {
} dl_ibpart_t;
/* IBPART Cache state flags */
typedef enum {
/* Network Cache lookup options */
/* Cache element */
typedef struct link_cache {
} link_cache_t;
/*
* Global cache for network IBPARTs
*/
static int events_registered = 0;
/*
* RCM module interface prototypes
*/
static int ibpart_register(rcm_handle_t *);
static int ibpart_unregister(rcm_handle_t *);
char **, char **, nvlist_t *, rcm_info_t **);
char **, rcm_info_t **);
char **, rcm_info_t **);
uint_t, char **, rcm_info_t **);
char **, rcm_info_t **);
/* Module private routines */
static void cache_free();
static int cache_update(rcm_handle_t *);
static void cache_remove(link_cache_t *);
static void node_free(link_cache_t *);
static void cache_insert(link_cache_t *);
char **, uint_t, rcm_info_t **);
char **, uint_t, rcm_info_t **);
static void ibpart_online_ibpart(link_cache_t *);
static char *ibpart_usage(link_cache_t *);
static void ibpart_log_err(datalink_id_t, char **, char *);
char **, uint_t, rcm_info_t **);
/* Module-Private data */
{
NULL,
NULL,
};
/*
* rcm_mod_init() - Update registrations, and return the ops structure.
*/
struct rcm_mod_ops *
rcm_mod_init(void)
{
"IBPART: mod_init failed: cannot open datalink "
return (NULL);
}
/* Return the ops vectors */
return (&ibpart_ops);
}
/*
* rcm_mod_info() - Return a string describing this module.
*/
const char *
rcm_mod_info(void)
{
return ("IBPART module");
}
/*
* rcm_mod_fini() - Destroy the network IBPART cache.
*/
int
rcm_mod_fini(void)
{
/*
* Note that ibpart_unregister() does not seem to be called anywhere,
* therefore we free the cache nodes here. In theory we should call
* rcm_register_interest() for each node before we free it, the
* framework does not provide the rcm_handle to allow us to do so.
*/
cache_free();
(void) mutex_destroy(&cache_lock);
return (RCM_SUCCESS);
}
/*
* ibpart_register() - Make sure the cache is properly sync'ed, and its
* registrations are in order.
*/
static int
{
if (cache_update(hd) < 0)
return (RCM_FAILURE);
/*
* Need to register interest in all new resources
* getting attached, so we get attach event notifications
*/
if (!events_registered) {
!= RCM_SUCCESS) {
_("IBPART: failed to register %s\n"),
return (RCM_FAILURE);
} else {
}
}
return (RCM_SUCCESS);
}
/*
* ibpart_unregister() - Walk the cache, unregistering all the networks.
*/
static int
{
/* Walk the cache, unregistering everything */
(void) mutex_lock(&cache_lock);
while (node != &cache_tail) {
!= RCM_SUCCESS) {
_("IBPART: failed to unregister %s\n"),
node->pc_resource);
(void) mutex_unlock(&cache_lock);
return (RCM_FAILURE);
}
}
(void) mutex_unlock(&cache_lock);
/*
* Unregister interest in all new resources
*/
if (events_registered) {
!= RCM_SUCCESS) {
_("IBPART: failed to unregister %s\n"),
return (RCM_FAILURE);
} else {
}
}
return (RCM_SUCCESS);
}
/*
* ibpart_offline() - Offline IBPARTs on a specific node.
*/
static int
{
/* Lock the cache and lookup the resource */
(void) mutex_lock(&cache_lock);
/* should not happen because the resource is registered. */
"unrecognized resource");
(void) mutex_unlock(&cache_lock);
return (RCM_SUCCESS);
}
/*
* Inform consumers (IP interfaces) of associated IBPARTs to be offlined
*/
RCM_SUCCESS) {
"IBPART: consumers agreed on offline\n");
} else {
"consumers failed to offline");
(void) mutex_unlock(&cache_lock);
return (RCM_FAILURE);
}
/* Check if it's a query */
"IBPART: offline query succeeded(%s)\n", rsrc);
(void) mutex_unlock(&cache_lock);
return (RCM_SUCCESS);
}
RCM_SUCCESS) {
(void) mutex_unlock(&cache_lock);
return (RCM_FAILURE);
}
(void) mutex_unlock(&cache_lock);
return (RCM_SUCCESS);
}
/*
* ibpart_undo_offline() - Undo offline of a previously offlined node.
*/
/*ARGSUSED*/
static int
{
(void) mutex_lock(&cache_lock);
(void) mutex_unlock(&cache_lock);
return (RCM_FAILURE);
}
/* Check if no attempt should be made to online the link here */
(void) mutex_unlock(&cache_lock);
return (RCM_SUCCESS);
}
/*
* Inform IP interfaces on associated IBPARTs to be onlined
*/
(void) mutex_unlock(&cache_lock);
return (RCM_SUCCESS);
}
static void
{
/*
* Try to bring on all offlined IBPARTs
*/
continue;
/*
* Print a warning message and continue to online
* other IBPARTs.
*/
_("IBPART: IBPART online failed (%u): %s\n"),
} else {
}
}
}
static int
{
/*
* Try to delete all explicit created IBPART
*/
_("IBPART: IBPART offline failed (%u): %s\n"),
return (RCM_FAILURE);
} else {
"IBPART: IBPART offline succeeded(%u)\n",
}
}
return (RCM_SUCCESS);
}
/*
* ibpart_get_info() - Gather usage information for this resource.
*/
/*ARGSUSED*/
int
{
(void) mutex_lock(&cache_lock);
_("IBPART: get_info(%s) unrecognized resource\n"), rsrc);
(void) mutex_unlock(&cache_lock);
return (RCM_FAILURE);
}
(void) mutex_unlock(&cache_lock);
/* most likely malloc failure */
_("IBPART: get_info(%s) malloc failure\n"), rsrc);
(void) mutex_unlock(&cache_lock);
return (RCM_FAILURE);
}
return (RCM_SUCCESS);
}
/*
* ibpart_suspend() - Nothing to do, always okay
*/
/*ARGSUSED*/
static int
{
return (RCM_SUCCESS);
}
/*
* ibpart_resume() - Nothing to do, always okay
*/
/*ARGSUSED*/
static int
{
return (RCM_SUCCESS);
}
/*
* ibpart_consumer_remove()
*
* Notify IBPART consumers to remove cache.
*/
static int
rcm_info_t **info)
{
node->pc_resource);
/*
* This will only be called when the offline operation
* succeeds, so the IBPART consumers must have been offlined
* at this point.
*/
if (ret != RCM_SUCCESS) {
_("IBPART: notify remove failed (%s)\n"), rsrc);
break;
}
}
return (ret);
}
/*
* ibpart_remove() - remove a resource from cache
*/
/*ARGSUSED*/
static int
{
int rv;
(void) mutex_lock(&cache_lock);
_("IBPART: remove(%s) unrecognized resource\n"), rsrc);
(void) mutex_unlock(&cache_lock);
return (RCM_FAILURE);
}
/* remove the cached entry for the resource */
(void) mutex_unlock(&cache_lock);
return (rv);
}
/*
* ibpart_notify_event - Project private implementation to receive new resource
* events. It intercepts all new resource events. If the
* new resource is a network resource, pass up a notify
* for it too. The new resource need not be cached, since
* it is done at register again.
*/
/*ARGSUSED*/
static int
{
"unrecognized event");
return (RCM_FAILURE);
}
/* Update cache to reflect latest IBPARTs */
if (cache_update(hd) < 0) {
"private Cache update failed");
return (RCM_FAILURE);
}
/*
* Try best to recover all configuration.
*/
continue;
"cannot get linkid");
rv = RCM_FAILURE;
continue;
}
rv = RCM_FAILURE;
continue;
}
/* Notify all IBPART consumers */
info) != 0) {
"consumer notify failed");
rv = RCM_FAILURE;
}
}
"IBPART: notify_event: link configuration complete\n");
return (rv);
}
/*
* ibpart_usage - Determine the usage of a link.
* The returned buffer is owned by caller, and the caller
* must free it up when done.
*/
static char *
{
int nibpart;
char *buf;
const char *fmt;
char *sep;
_("IBPART: usage(%s) get link name failure(%s)\n"),
return (NULL);
}
fmt = _("%1$s offlined");
else
fmt = _("%1$s IBPART: ");
/* TRANSLATION_NOTE: separator used between IBPART linkids */
sep = _(", ");
nibpart = 0;
nibpart++;
/* space for IBPARTs and separators, plus message */
_("IBPART: usage(%s) malloc failure(%s)\n"),
return (NULL);
}
/* Nothing else to do */
return (buf);
}
sizeof (name))) != DLADM_STATUS_OK) {
_("IBPART: usage(%s) get ibpart %u name "
return (NULL);
}
}
return (buf);
}
/*
* Cache management routines, all cache management functions should be
* be called with cache_lock held.
*/
/*
* cache_lookup() - Get a cache node for a resource.
* Call with cache lock held.
*
* This ensures that the cache is consistent with the system state and
* returns a pointer to the cache element corresponding to the resource.
*/
static link_cache_t *
{
if (options & CACHE_REFRESH) {
/* drop lock since update locks cache again */
(void) mutex_unlock(&cache_lock);
(void) cache_update(hd);
(void) mutex_lock(&cache_lock);
}
"IBPART: cache lookup succeeded(%s)\n", rsrc);
return (node);
}
}
return (NULL);
}
/*
* node_free - Free a node from the cache
*/
static void
{
/* free the IBPART list */
}
}
}
/*
* cache_insert - Insert a resource node in cache
*/
static void
{
/* insert at the head for best performance */
}
/*
* cache_remove() - Remove a resource node from cache.
*/
static void
{
}
typedef struct ibpart_update_arg_s {
int retval;
/*
* ibpart_update() - Update physical interface properties
*/
static int
{
char *rsrc;
if (status != DLADM_STATUS_OK) {
"IBPART: ibpart_update() cannot get ibpart information for "
return (DLADM_WALK_CONTINUE);
}
/*
* Skip the IB port nodes.
*/
"IBPART: ibpart_update(): skip the PORT nodes %u\n",
ibpartid);
return (DLADM_WALK_CONTINUE);
}
goto done;
}
"IBPART: %s already registered (ibpartid:%d)\n",
} else {
"IBPART: %s is a new resource (ibpartid:%d)\n",
goto done;
}
}
break;
}
}
if (newnode) {
}
goto done;
}
}
if (newnode)
ibpartid);
ret = 0;
done:
}
/*
* ibpart_update_all() - Determine all IBPART links in the system
*/
static int
{
}
/*
* cache_update() - Update cache with latest interface info
*/
static int
{
int rv;
(void) mutex_lock(&cache_lock);
/* first we walk the entire cache, marking each entry stale */
}
/*
* Continue to delete all stale nodes from the cache even
* ibpart_update_all() failed. Unregister link that are not offlined
* and still in cache
*/
/* clear stale IBPARTs */
else
}
}
0);
node->pc_resource);
continue;
}
continue;
RCM_SUCCESS) {
_("IBPART: failed to register %s\n"),
node->pc_resource);
rv = -1;
} else {
node->pc_resource);
}
}
(void) mutex_unlock(&cache_lock);
return (rv);
}
/*
* cache_free() - Empty the cache
*/
static void
{
(void) mutex_lock(&cache_lock);
while (node != &cache_tail) {
}
(void) mutex_unlock(&cache_lock);
}
/*
* ibpart_log_err() - RCM error log wrapper
*/
static void
{
int len;
const char *errfmt;
char *error;
link[0] = '\0';
if (linkid != DATALINK_INVALID_LINKID) {
_("IBPART: cannot get link name for (%s) %s\n"),
}
} else {
}
else
}
}
/*
* ibpart_consumer_online()
*
* Notify online to IBPART consumers.
*/
/* ARGSUSED */
static void
{
node->pc_resource);
continue;
}
}
/*
* ibpart_consumer_offline()
*
* Offline IBPART consumers.
*/
static int
{
node->pc_resource);
if (ret != RCM_SUCCESS)
break;
}
return (ret);
}
/*
* Send RCM_RESOURCE_LINK_NEW events to other modules about new IBPARTs.
* Return 0 on success, -1 on failure.
*/
static int
{
rsrc);
(void) mutex_lock(&cache_lock);
(void) mutex_unlock(&cache_lock);
return (0);
}
if (nvlist_alloc(&nvl, 0, 0) != 0) {
(void) mutex_unlock(&cache_lock);
_("IBPART: failed to allocate nvlist\n"));
goto done;
}
_("IBPART: failed to construct nvlist\n"));
(void) mutex_unlock(&cache_lock);
goto done;
}
}
(void) mutex_unlock(&cache_lock);
RCM_SUCCESS) {
_("IBPART: failed to notify %s event for %s\n"),
goto done;
}
ret = 0;
done:
return (ret);
}
/*
* ibpart_consumer_notify() - Notify consumers of IBPARTs coming back online.
*/
static int
{
/* Check for the interface in the cache */
linkid);
rsrc);
/*
* Inform IP consumers of the new link.
*/
(void) mutex_lock(&cache_lock);
}
(void) mutex_unlock(&cache_lock);
"IBPART: ibpart_notify_new_ibpart failed(%s)\n", rsrc);
return (-1);
}
"succeeded\n");
return (0);
}
typedef struct ibpart_up_arg_s {
int retval;
static int
{
if (status != DLADM_STATUS_OK) {
"IBPART: ibpart_up(): cannot get information for IBPART %u "
return (DLADM_WALK_CONTINUE);
}
return (DLADM_WALK_CONTINUE);
return (DLADM_WALK_CONTINUE);
/*
* Prompt the warning message and continue to UP other IBPARTs.
*/
_("IBPART: IBPART up failed (%u): %s\n"),
return (DLADM_WALK_CONTINUE);
}
/*
* ibpart_configure() - Configure IBPARTs over a physical link after it attaches
*/
static int
{
/* Check for the IBPARTs in the cache */
/* Check if the link is new or was previously offlined */
(void) mutex_lock(&cache_lock);
"IBPART: Skipping configured interface(%s)\n", rsrc);
(void) mutex_unlock(&cache_lock);
return (0);
}
(void) mutex_unlock(&cache_lock);
"IBPART: ibpart_configure succeeded(%s)\n", rsrc);
}
}