/*
* 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"
/*
* RCM module supporting multiplexed I/O controllers (MPxIO).
*/
#include <stdlib.h>
#include <stdarg.h>
#include <unistd.h>
#include <assert.h>
#include <syslog.h>
#include <string.h>
#include <synch.h>
#include <libintl.h>
#include <locale.h>
#include <ctype.h>
#include <errno.h>
#include <libdevinfo.h>
#include "rcm_module.h"
#define CMD_GETINFO 0
#define CACHE_NEW 0
typedef struct {
char *path;
} phci_t;
typedef struct phci_list {
int referenced;
} phci_list_t;
typedef struct group {
int offline;
int nphcis;
int nclients;
char **clients;
} group_t;
static int mpxio_register(rcm_handle_t *);
static int mpxio_unregister(rcm_handle_t *);
nvlist_t *, rcm_info_t **);
char **, rcm_info_t **);
rcm_info_t **);
rcm_info_t **);
rcm_info_t **);
rcm_info_t **);
static int get_nclients(di_node_t, void *);
static int build_groups(di_node_t, void *);
static void refresh_regs(rcm_handle_t *);
static int get_affected_clients(rcm_handle_t *, char *, int, int, char ***);
static int merge_clients(int *, char ***, group_t *);
static phci_list_t *lookup_phci(char *);
static char *get_rsrcname(di_node_t);
static char *s_state(di_path_state_t);
static int compare_phci(const void *, const void *);
static void free_grouplist();
static void free_group(group_t *);
static void free_clients(int, char **);
static void free_phcis(int, phci_t *);
{
NULL,
NULL,
};
extern int errno;
/*
* Return the mod-ops vector for initialization.
*/
struct rcm_mod_ops *
{
return (&mpxio_ops);
}
/*
* Return name and version number for mod_info.
*/
const char *
{
return (gettext("RCM MPxIO module 1.6"));
}
/*
* Destroy the cache and mutex lock when being unloaded.
*/
int
{
/* Free the cache of MPxIO group information */
/* Free the cache of registrants */
while (reg) {
}
/* Destroy the mutex for locking the caches */
(void) mutex_destroy(&mpxio_lock);
return (RCM_SUCCESS);
}
/*
* During each register callback: totally rebuild the group list from a new
* libdevinfo snapshot, and then update the registrants.
*/
static int
{
int nclients = 0;
(void) mutex_lock(&mpxio_lock);
/* Destroy the previous group list */
/* Get a current libdevinfo snapshot */
"MPXIO: libdevinfo initialization failed (%s).\n",
(void) mutex_unlock(&mpxio_lock);
return (RCM_FAILURE);
}
/*
* First count the total number of clients. This'll be a useful
* upper bound when allocating client arrays within each group.
*/
nclients);
/*
* Then walk the libdevinfo snapshot, building up the new group list
* along the way. Pass in the total number of clients (from above) to
* assist in group construction.
*/
/* Now with a new group list constructed, refresh the registrants */
/* Free the libdevinfo snapshot */
(void) mutex_unlock(&mpxio_lock);
return (0);
}
/*
* Unregister all PHCIs and mark the whole registrants list as stale.
*/
static int
{
(void) mutex_lock(&mpxio_lock);
}
(void) mutex_unlock(&mpxio_lock);
return (RCM_SUCCESS);
}
/*
* To return usage information, just lookup the PHCI in the cache and return
* a string identifying that it's a PHCI and describing its cached MPxIO state.
* Recurse with the cached list of disks if dependents are to be included.
*/
static int
{
char c;
(void) mutex_lock(&mpxio_lock);
(void) mutex_unlock(&mpxio_lock);
return (RCM_FAILURE);
}
(void) mutex_unlock(&mpxio_lock);
if (buf)
return (RCM_FAILURE);
}
if (flags & RCM_INCLUDE_DEPENDENT) {
&clients) < 0) {
(void) mutex_unlock(&mpxio_lock);
return (RCM_FAILURE);
}
if (clients) {
} else {
}
}
(void) mutex_unlock(&mpxio_lock);
return (rv);
}
/*
* Nothing is implemented for suspend operations.
*/
static int
{
return (RCM_SUCCESS);
}
/*
* Nothing is implemented for resume operations.
*/
static int
{
return (RCM_SUCCESS);
}
/*
* MPxIO has no policy against offlining. If disks will be affected, then
* base the return value for this request on the results of offlining the
* list of disks. Otherwise succeed.
*/
static int
{
(void) mutex_lock(&mpxio_lock);
(void) mutex_unlock(&mpxio_lock);
return (RCM_FAILURE);
}
if (clients) {
if (rv != RCM_SUCCESS)
}
(void) mutex_unlock(&mpxio_lock);
return (rv);
}
/*
* If disks are affected, then they are probably offline and we need to
* propagate this online notification to them.
*/
static int
{
char **clients;
(void) mutex_lock(&mpxio_lock);
(void) mutex_unlock(&mpxio_lock);
return (RCM_FAILURE);
}
if (clients) {
}
(void) mutex_unlock(&mpxio_lock);
return (rv);
}
/*
* If clients are affected, then they are probably offline and we need to
* propagate this removal notification to them. We can also remove the
* cache entry for this PHCI. If that leaves its group empty, then the
* group will be removed during the next register callback.
*/
static int
{
char **clients;
(void) mutex_lock(&mpxio_lock);
(void) mutex_unlock(&mpxio_lock);
return (RCM_FAILURE);
}
if (clients) {
}
(void) mutex_unlock(&mpxio_lock);
return (rv);
}
/*
* Returns a string representation of a given libdevinfo path state.
*/
static char *
{
switch (state) {
case DI_PATH_STATE_ONLINE:
return ("online");
case DI_PATH_STATE_OFFLINE:
return ("offline");
case DI_PATH_STATE_STANDBY:
return ("standby");
case DI_PATH_STATE_FAULT:
return ("faulted");
default:
return ("<unknown>");
}
}
static int
char ***clientsp)
{
int nclients = 0;
/* Build a dummy phci_t for use with bsearch(). */
/* Analyze the effects upon each group. */
/* If the PHCI isn't in the group, then no effects. Skip. */
compare_phci) == NULL)
continue;
/*
* Merge in the clients. All clients are merged in for getinfo
* operations. Otherwise it's contingent upon a state change
* being transferred to the clients as a result of changing
* the PHCI's state.
*/
if ((cmd == CMD_GETINFO) ||
return (-1);
}
}
}
/* Return the array of affected disks */
return (0);
}
/*
* Iterates through the members of a PHCI list, returning the entry
* corresponding to the named PHCI resource. Returns NULL when the lookup
* fails.
*/
static phci_list_t *
{
return (reg);
}
return (NULL);
}
/*
* Tests whether or not an operation on a specific PHCI resource would affect
* the array of client devices attached to the PHCI's MPxIO group.
*
* Returns: 1 if clients would be affected, 0 if not.
*/
static int
char *rsrc)
{
int i;
int state;
/*
* Perform a full set analysis on the set of redundant PHCIs. When
* there are no unaffected and online PHCIs, then changing the state
* of the named PHCI results in a client state change.
*/
/* Filter the named resource out of the analysis */
continue;
/*
* If we find a path that's in the ONLINE or STANDBY state
* that would be left over in the system after completing
* whatever DR or hotplugging operation is in progress, then
* return a 0.
*/
!= RCM_SUCCESS) {
"MPXIO: Failed to query resource state\n");
continue;
}
if (state == RCM_STATE_ONLINE) {
return (0);
}
}
}
/*
* The analysis above didn't find a redundant path to take over. So
* report that the state of the client resources will change.
*/
return (1);
}
/*
* Merges the client disks connected to a particular MPxIO group in with a
* previous array of disk clients. The result is to adjust the 'nclients'
* value with the new count of disks in the array, and to adjust the 'disks'
* value to be a larger array of disks including its original contents along
* with the current group's contents merged in.
*/
static int
{
int i;
int old_nclients;
char **clients_new;
old_nclients = *nclients;
((*nclients) + 1) * sizeof (char *));
if (clients_new == NULL) {
"MPXIO: cannot reallocate client array (%s).\n",
return (-1);
}
for (i = old_nclients; i < (*nclients); i++) {
/*
* Don't allocate space for individual disks in the
* merged list. Just make references to the previously
* allocated strings in the group_t structs themselves.
*/
}
*clientsp = clients_new;
}
return (0);
}
/*
* A libdevinfo di_walk_node() callback. It's passed an integer pointer as an
* argument, and it increments the integer each time it encounters an MPxIO
* client. By initializing the integer to zero and doing a libdevinfo walk with
* this function, the total count of MPxIO clients in the system can be found.
*/
static int
{
(*nclients)++;
return (DI_WALK_CONTINUE);
}
/*
* Tests a libdevinfo node to determine if it's an MPxIO client.
*
* Returns: non-zero for true, 0 for false.
*/
static int
{
}
/*
* After a new group_list has been constructed, this refreshes the RCM
* registrations and the reg_list contents. It uses a clock like algorithm
* with reference bits in the reg_list to know which registrants are new or
* old.
*/
static void
{
int i;
/*
* First part of the clock-like algorithm: clear reference bits.
*/
/*
* Second part of the clock-like algorithm: set the reference bits
* on every registrant that's still active. (Also add new list nodes
* for new registrants.)
*/
/*
* If already stale in the registrants list, just set
* its reference bit to REFERENCED and update its state.
*/
continue;
}
/*
* Otherwise, build a new list node and mark it NEW.
*/
"MPXIO: cannot allocate phci_list (%s).\n",
continue;
}
"MPXIO: cannot allocate phci path (%s).\n",
continue;
}
/* Link it at the head of reg_list */
}
}
/*
* Final part of the clock algorithm: unregister stale entries, and
* register new entries. Stale entries get removed from the list.
*/
while (reg) {
/* Unregister and remove stale entries. */
} else {
}
continue;
}
/* Register new entries. */
!= RCM_SUCCESS) {
"MPXIO: failed to register %s (%s).\n",
}
}
}
}
/*
* A libdevinfo di_walk_node() callback that builds up the MPxIO group list.
*
* Every node encountered that's a client node is added into a group's client
* list. Whenever a group doesn't already exist with a matching set of
* related PHCIs, then a new group is constructed and put at the head of the
* group list.
*/
static int
{
int i = 0;
int nphcis = 0;
/* Safety check */
return (DI_WALK_TERMINATE);
/*
* Build a sorted array of PHCIs pertaining to the client.
*/
while ((dipath =
nphcis++;
/* Skip non-clients. */
if (nphcis == 0)
return (DI_WALK_CONTINUE);
"MPXIO: failed to allocate client's PHCIs (%s).\n",
return (DI_WALK_TERMINATE);
}
while ((dipath =
if (phcinode == DI_NODE_NIL) {
"MPXIO: client appears to have no PHCIs.\n");
return (DI_WALK_TERMINATE);
}
free_phcis(i, phcis);
return (DI_WALK_TERMINATE);
}
i++;
}
/*
* Compare that PHCI set to each existing group's set. We just add
* the client to the group and exit successfully once a match is made.
* Falling out of this loop means no match was found.
*/
/* There is no match if the number of PHCIs is inequal */
continue;
/* Compare the PHCIs linearly (which is okay; they're sorted) */
for (i = 0; i < nphcis; i++)
break;
/*
* If the loop above completed, we have a match. Add the client
* to the group's disk array in that case, and return
* successfully.
*/
if (i == nphcis) {
return (DI_WALK_TERMINATE);
return (DI_WALK_CONTINUE);
}
}
/* The loop above didn't find a match. So build a new group. */
"MPXIO: failed to allocate PHCI group (%s).\n",
return (DI_WALK_TERMINATE);
}
NULL) {
return (DI_WALK_TERMINATE);
}
return (DI_WALK_TERMINATE);
}
/* Link the group into the group list and return successfully. */
group_list = group;
return (DI_WALK_CONTINUE);
}
/*
* For bsearch() and qsort(). Returns the results of a strcmp() on the names
* of two phci_t's.
*/
static int
{
return (-1);
return (1);
return (0);
}
}
/*
* Free the whole list of group's in the global group_list.
*/
static void
{
while (group) {
}
group_list = NULL;
}
/*
* Free the contents of a single group_t.
*/
static void
{
if (group) {
}
}
/*
* Free an array of clients.
*/
static void
{
int i;
if (nclients > 0) {
for (i = 0; i < nclients; i++)
if (clients[i])
}
}
}
/*
* Free an array of phci_t's.
*/
static void
{
int i;
for (i = 0; i < nphcis; i++)
}
}
/*
* Converts a libdevinfo node into a /devices path. Caller must free results.
*/
static char *
{
int len;
char *rsrcname;
char *devfspath;
return (NULL);
}
return (NULL);
}
"MPXIO: failed to allocate resource name (%s).\n",
return (rsrcname);
}