/*
* 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 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include <dlfcn.h>
#include <errno.h>
#include <libintl.h>
#include <link.h>
#include <pthread.h>
#include <strings.h>
#include <unistd.h>
#include <libzfs.h>
#include <sys/systeminfo.h>
#include "libzfs_impl.h"
/*
* This file is responsible for determining the relationship between I/O
* devices paths and physical locations. In the world of MPxIO and external
* enclosures, the device path is not synonymous with the physical location.
* If you remove a drive and insert it into a different slot, it will end up
* with the same path under MPxIO. If you recable storage enclosures, the
* device paths may change. All of this makes it difficult to implement the
* 'autoreplace' property, which is supposed to automatically manage disk
* replacement based on physical slot.
*
* In order to work around these limitations, we have a per-vdev FRU property
* that is the libtopo path (minus disk-specific authority information) to the
* physical location of the device on the system. This is an optional
* property, and is only needed when using the 'autoreplace' property or when
* generating FMA faults against vdevs.
*/
/*
* Because the FMA packages depend on ZFS, we have to dlopen() libtopo in case
* it is not present. We only need this once per library instance, so it is
* not part of the libzfs handle.
*/
static void *_topo_dlhandle;
topo_walk_cb_t, void *, int *);
char **, int *);
const char *);
static size_t
{
ulong_t g, h = 0;
const char *p;
for (p = key; *p != '\0'; p++) {
h = (h << 4) + *p;
if ((g = (h & 0xf0000000)) != 0) {
h ^= (g >> 24);
h ^= g;
}
}
return (h % ZFS_FRU_HASH_SIZE);
}
static int
{
int err;
/*
* If this is the chassis node, and we don't yet have the system
* chassis ID, then fill in this value now.
*/
sizeof (hdl->libzfs_chassis_id));
}
/*
* Skip non-disk nodes.
*/
return (TOPO_WALK_NEXT);
/*
* Get the devfs path and FRU.
*/
return (TOPO_WALK_NEXT);
return (TOPO_WALK_NEXT);
}
return (TOPO_WALK_NEXT);
}
/*
* Convert the FRU into a string.
*/
return (TOPO_WALK_NEXT);
}
/*
* Finally, we have a FRU string and device path. Add it to the hash.
*/
return (TOPO_WALK_NEXT);
}
return (TOPO_WALK_NEXT);
}
return (TOPO_WALK_NEXT);
}
/*
* Called during initialization to setup the dynamic libtopo connection.
*/
#pragma init(libzfs_init_fru)
static void
libzfs_init_fru(void)
{
#if defined(_LP64)
isa[0] = '\0';
#else
isa[0] = '\0';
#endif
return;
_topo_open = (topo_hdl_t *(*)())
_topo_close = (void (*)())
_topo_snap_hold = (char *(*)())
_topo_snap_release = (void (*)())
_topo_walk_init = (topo_walk_t *(*)())
_topo_walk_step = (int (*)())
_topo_walk_fini = (void (*)())
_topo_hdl_strfree = (void (*)())
_topo_node_name = (char *(*)())
_topo_prop_get_string = (int (*)())
_topo_node_fru = (int (*)())
_topo_fmri_nvl2str = (int (*)())
_topo_fmri_strcmp_noauth = (int (*)())
_topo_fmri_strcmp_noauth == NULL) {
(void) dlclose(_topo_dlhandle);
}
}
/*
* Refresh the mappings from device path -> FMRI. We do this by walking the
* hc topology looking for disk nodes, and recording the io/devfs-path and FRU.
* Note that we strip out the disk-specific authority information (serial,
* part, revision, etc) so that we are left with only the identifying
* characteristics of the slot (hc path and chassis-id).
*/
void
{
int err;
char *uuid;
if (_topo_dlhandle == NULL)
return;
/*
* Clear the FRU hash and initialize our basic structures.
*/
return;
return;
(hdl->libzfs_fru_hash =
return;
/*
* We now have a topo snapshot, so iterate over the hc topology looking
* for disks to add to the hash.
*/
}
}
/*
* Given a devfs path, return the FRU for the device, if known. This will
* automatically call libzfs_fru_refresh() if it hasn't already been called by
* the consumer. The string returned is valid until the next call to
* libzfs_fru_refresh().
*/
const char *
{
return (NULL);
}
return (NULL);
}
/*
* Given a fru path, return the device path. This will automatically call
* libzfs_fru_refresh() if it hasn't already been called by the consumer. The
* string returned is valid until the next call to libzfs_fru_refresh().
*/
const char *
{
return (NULL);
}
}
return (NULL);
}
/*
* Change the stored FRU for the given vdev.
*/
int
{
return (0);
}
/*
* Compare to two FRUs, ignoring any authority information.
*/
{
return (strcmp(a, b) == 0);
}
/*
* This special function checks to see whether the FRU indicates it's supposed
* to be in the system chassis, but the chassis-id doesn't match. This can
* happen in a clustered case, where both head nodes have the same logical
* disk, but opening the device on the other head node is meaningless.
*/
{
const char *chassisid;
return (B_FALSE);
return (B_FALSE);
return (B_FALSE);
chassisid += 12;
return (B_FALSE);
return (B_TRUE);
}
/*
* Clear memory associated with the FRU hash.
*/
void
{
}
}
if (final) {
ZFS_FRU_HASH_SIZE * sizeof (void *));
}
}