/*
* 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
*/
/*
*/
#include "libzfs_jni_util.h"
#include "libzfs_jni_pool.h"
#include <strings.h>
/*
* Types
*/
typedef struct ImportablePoolBean {
typedef struct VirtualDeviceBean {
typedef struct LeafVirtualDeviceBean {
typedef struct DiskVirtualDeviceBean {
typedef struct SliceVirtualDeviceBean {
typedef struct FileVirtualDeviceBean {
typedef struct RAIDVirtualDeviceBean {
typedef struct MirrorVirtualDeviceBean {
/*
* Data
*/
/* vdev_state_t to DeviceStats$DeviceState map */
{ VDEV_STATE_CANT_OPEN, "VDEV_STATE_CANT_OPEN" },
{ VDEV_STATE_CLOSED, "VDEV_STATE_CLOSED" },
{ VDEV_STATE_DEGRADED, "VDEV_STATE_DEGRADED" },
{ VDEV_STATE_HEALTHY, "VDEV_STATE_HEALTHY" },
{ VDEV_STATE_OFFLINE, "VDEV_STATE_OFFLINE" },
{ VDEV_STATE_UNKNOWN, "VDEV_STATE_UNKNOWN" },
{ -1, NULL },
};
/* vdev_aux_t to DeviceStats$DeviceStatus map */
{ VDEV_AUX_NONE, "VDEV_AUX_NONE" },
{ VDEV_AUX_OPEN_FAILED, "VDEV_AUX_OPEN_FAILED" },
{ VDEV_AUX_CORRUPT_DATA, "VDEV_AUX_CORRUPT_DATA" },
{ VDEV_AUX_NO_REPLICAS, "VDEV_AUX_NO_REPLICAS" },
{ VDEV_AUX_BAD_GUID_SUM, "VDEV_AUX_BAD_GUID_SUM" },
{ VDEV_AUX_TOO_SMALL, "VDEV_AUX_TOO_SMALL" },
{ VDEV_AUX_BAD_LABEL, "VDEV_AUX_BAD_LABEL" },
{ -1, NULL },
};
/* zpool_state_t to PoolStats$PoolState map */
{ POOL_STATE_ACTIVE, "POOL_STATE_ACTIVE" },
{ POOL_STATE_EXPORTED, "POOL_STATE_EXPORTED" },
{ POOL_STATE_DESTROYED, "POOL_STATE_DESTROYED" },
{ POOL_STATE_SPARE, "POOL_STATE_SPARE" },
{ POOL_STATE_UNINITIALIZED, "POOL_STATE_UNINITIALIZED" },
{ POOL_STATE_UNAVAIL, "POOL_STATE_UNAVAIL" },
{ POOL_STATE_POTENTIALLY_ACTIVE, "POOL_STATE_POTENTIALLY_ACTIVE" },
{ -1, NULL },
};
/* zpool_status_t to PoolStats$PoolStatus map */
{ ZPOOL_STATUS_CORRUPT_CACHE, "ZPOOL_STATUS_CORRUPT_CACHE" },
{ ZPOOL_STATUS_MISSING_DEV_R, "ZPOOL_STATUS_MISSING_DEV_R" },
{ ZPOOL_STATUS_MISSING_DEV_NR, "ZPOOL_STATUS_MISSING_DEV_NR" },
{ ZPOOL_STATUS_CORRUPT_LABEL_R, "ZPOOL_STATUS_CORRUPT_LABEL_R" },
{ ZPOOL_STATUS_CORRUPT_LABEL_NR, "ZPOOL_STATUS_CORRUPT_LABEL_NR" },
{ ZPOOL_STATUS_BAD_GUID_SUM, "ZPOOL_STATUS_BAD_GUID_SUM" },
{ ZPOOL_STATUS_CORRUPT_POOL, "ZPOOL_STATUS_CORRUPT_POOL" },
{ ZPOOL_STATUS_CORRUPT_DATA, "ZPOOL_STATUS_CORRUPT_DATA" },
{ ZPOOL_STATUS_FAILING_DEV, "ZPOOL_STATUS_FAILING_DEV" },
{ ZPOOL_STATUS_VERSION_NEWER, "ZPOOL_STATUS_VERSION_NEWER" },
{ ZPOOL_STATUS_HOSTID_MISMATCH, "ZPOOL_STATUS_HOSTID_MISMATCH" },
{ ZPOOL_STATUS_FAULTED_DEV_R, "ZPOOL_STATUS_FAULTED_DEV_R" },
{ ZPOOL_STATUS_FAULTED_DEV_NR, "ZPOOL_STATUS_FAULTED_DEV_NR" },
{ ZPOOL_STATUS_BAD_LOG, "ZPOOL_STATUS_BAD_LOG" },
{ ZPOOL_STATUS_VERSION_OLDER, "ZPOOL_STATUS_VERSION_OLDER" },
{ ZPOOL_STATUS_RESILVERING, "ZPOOL_STATUS_RESILVERING" },
{ ZPOOL_STATUS_OFFLINE_DEV, "ZPOOL_STATUS_OFFLINE_DEV" },
{ ZPOOL_STATUS_REMOVED_DEV, "ZPOOL_STATUS_REMOVED_DEV" },
{ ZPOOL_STATUS_OK, "ZPOOL_STATUS_OK" },
{ -1, NULL }
};
/*
* Function prototypes
*/
static int populate_ImportablePoolBean(
static jobject create_DiskVirtualDeviceBean(
static jobject create_SliceVirtualDeviceBean(
static jobject create_FileVirtualDeviceBean(
static jobject create_RAIDVirtualDeviceBean(
static char *find_field(const zjni_field_mapping_t *, int);
/*
* Static functions
*/
/* Create a ImportablePoolBean */
static void
{
ZFSJNI_PACKAGE_DATA "ImportablePoolBean");
}
}
/* Create a VirtualDeviceBean */
static void
{
ZFSJNI_PACKAGE_DATA "VirtualDeviceBean");
}
}
/* Create a LeafVirtualDeviceBean */
static void
{
ZFSJNI_PACKAGE_DATA "LeafVirtualDeviceBean");
}
}
/* Create a DiskVirtualDeviceBean */
static void
{
}
}
/* Create a SliceVirtualDeviceBean */
static void
{
}
}
/* Create a FileVirtualDeviceBean */
static void
{
}
}
/* Create a RAIDVirtualDeviceBean */
static void
{
}
}
/* Create a MirrorVirtualDeviceBean */
static void
{
}
}
static int
{
char *c;
char *name;
return (-1);
}
return (0);
}
static int
{
int result;
if (result != 0) {
return (1);
}
/* Set pool name */
(*env)->CallVoidMethod(
/* Set parent vdev index */
(*env)->CallVoidMethod(
/* Get index */
if (result != 0) {
"could not retrieve virtual device ID (pool %s)",
return (1);
}
(*env)->CallVoidMethod(
return (0);
}
static int
{
return (populate_VirtualDeviceBean(
}
static int
{
char *path;
if (result) {
/* Must not call any more Java methods to preserve exception */
return (-1);
}
/* Set path */
if (result != 0) {
"could not retrieve path from disk virtual device "
} else {
/* Strip off slice portion of name, if applicable */
*end = '\0';
}
}
}
}
0) {
}
}
}
}
}
}
return (result != 0);
}
static int
{
char *path;
if (result) {
/* Must not call any more Java methods to preserve exception */
return (-1);
}
/* Set path */
if (result != 0) {
"could not retrieve path from slice virtual device (pool "
} else {
pathUTF);
}
return (result != 0);
}
static int
{
char *path;
if (result) {
/* Must not call any more Java methods to preserve exception */
return (-1);
}
/* Set path */
if (result != 0) {
"could not retrieve path from disk virtual device "
} else {
}
return (result != 0);
}
static int
{
(VirtualDeviceBean_t *)bean));
}
static int
{
(VirtualDeviceBean_t *)bean));
}
static jobject
{
int result;
/* Construct ImportablePoolBean */
if (result) {
/* Must not call any more Java methods to preserve exception */
return (NULL);
}
}
static jobject
{
int result;
/* Construct DiskVirtualDeviceBean */
if (result) {
/* Must not call any more Java methods to preserve exception */
return (NULL);
}
}
static jobject
{
int result;
/* Construct SliceVirtualDeviceBean */
if (result) {
/* Must not call any more Java methods to preserve exception */
return (NULL);
}
}
static jobject
{
int result;
/* Construct FileVirtualDeviceBean */
if (result) {
/* Must not call any more Java methods to preserve exception */
return (NULL);
}
}
static jobject
{
int result;
/* Construct RAIDVirtualDeviceBean */
/* Set parity bit */
&parity);
if (result) {
/* Default to RAID-Z1 in case of error */
parity = 1;
}
(*env)->CallVoidMethod(
if (result) {
/* Must not call any more Java methods to preserve exception */
return (NULL);
}
}
static jobject
{
int result;
/* Construct MirrorVirtualDeviceBean */
if (result) {
/* Must not call any more Java methods to preserve exception */
return (NULL);
}
}
static char *
int i;
}
}
return (NULL);
}
/*
* Converts a vdev_state_t to a Java DeviceStats$DeviceState object.
*/
static jobject
{
ZFSJNI_PACKAGE_DATA "DeviceStats$DeviceState",
"VDEV_STATE_UNKNOWN", vdev_state_map));
}
/*
* Converts a vdev_aux_t to a Java DeviceStats$DeviceStatus object.
*/
static jobject
{
ZFSJNI_PACKAGE_DATA "DeviceStats$DeviceStatus",
"VDEV_AUX_NONE", vdev_aux_map));
}
/*
* Package-private functions
*/
/* Create a DeviceStatsBean */
void
{
}
/* Create a PoolStatsBean */
void
{
}
/*
* Gets the root vdev (an nvlist_t *) for the given pool.
*/
nvlist_t *
{
if (result != 0) {
}
}
}
return (root);
}
/*
* Gets the vdev (an nvlist_t *) with the given vdev_id, below the
* given vdev. If the given vdev is NULL, all vdevs within the given
* pool are searched.
*
* If p_vdev_id is not NULL, it will be set to the ID of the parent
* vdev, if any, or to vdev_id_to_find if the searched-for vdev is a
* toplevel vdev.
*/
nvlist_t *
{
int result;
/* Was a vdev specified? */
if (vdev_parent == NULL) {
/* No -- retrieve the top-level pool vdev */
} else {
/* Get index of this vdev and compare with vdev_id_to_find */
return (vdev_parent);
}
}
if (vdev_parent != NULL) {
/* Get the vdevs under this vdev */
if (result == 0) {
int i;
/* For each vdev child... */
for (i = 0; i < nelem; i++) {
/* Save parent vdev id */
}
return (child);
}
}
}
}
return (NULL);
}
{
if (result == 0) {
} else {
}
/* Get the vdevs under this vdev */
/* Get last vdev child (replacement device) */
}
}
}
return (obj);
}
{
/* Create an array list for the vdevs */
/* Was a vdev specified? */
if (vdev_parent == NULL) {
/* No -- retrieve the top-level pool vdev */
}
if (vdev_parent != NULL) {
/* Get the vdevs under this vdev */
if (result == 0) {
/* For each vdev child... */
int i;
for (i = 0; i < nelem; i++) {
/* Create a Java object from this vdev */
/*
* Must not call any more Java methods
* to preserve exception
*/
return (NULL);
}
/* Add child to child vdev list */
((zjni_Object_t *)
((zjni_Collection_t *)
}
}
}
}
return (zjni_Collection_to_array(
ZFSJNI_PACKAGE_DATA "VirtualDevice"));
}
int
/* Construct ImportablePool object */
return (-1);
}
/* Add bean to list */
return (0);
}
int
{
uint_t c;
if (result != 0) {
"could not retrieve virtual device statistics");
return (1);
}
return (0);
}
/*
* Converts a pool_state_t to a Java PoolStats$PoolState object.
*/
{
ZFSJNI_PACKAGE_DATA "PoolStats$PoolState",
"POOL_STATE_ACTIVE", pool_state_map));
}
/*
* Converts a zpool_status_t to a Java PoolStats$PoolStatus object.
*/
{
ZFSJNI_PACKAGE_DATA "PoolStats$PoolStatus",
"ZPOOL_STATUS_OK", zpool_status_map));
}
/*
* Extern functions
*/
/*
* Iterates through each importable pool on the system. For each
* importable pool, runs the given function with the given void as the
* last arg.
*/
int
{
return (-1);
}
}
}
return (0);
}
char *
}
char *
}
char *
}
char *
}