libzfs_jni_pool.c revision a1a659ae4f0ae792e70c00834f74ae0d472c2b05
fa9e4066f08beec538e775443c5be79dd423fcabahrens * CDDL HEADER START
fa9e4066f08beec538e775443c5be79dd423fcabahrens * The contents of this file are subject to the terms of the
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Common Development and Distribution License, Version 1.0 only
fa9e4066f08beec538e775443c5be79dd423fcabahrens * (the "License"). You may not use this file except in compliance
fa9e4066f08beec538e775443c5be79dd423fcabahrens * with the License.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
fa9e4066f08beec538e775443c5be79dd423fcabahrens * See the License for the specific language governing permissions
fa9e4066f08beec538e775443c5be79dd423fcabahrens * and limitations under the License.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * When distributing Covered Code, include this CDDL HEADER in each
fa9e4066f08beec538e775443c5be79dd423fcabahrens * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * If applicable, add the following below this CDDL HEADER, with the
fa9e4066f08beec538e775443c5be79dd423fcabahrens * fields enclosed by brackets "[]" replaced with your own identifying
fa9e4066f08beec538e775443c5be79dd423fcabahrens * information: Portions Copyright [yyyy] [name of copyright owner]
fa9e4066f08beec538e775443c5be79dd423fcabahrens * CDDL HEADER END
fbfd10ff571cfd0139aa5127460f1b8a53dac971talley * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Use is subject to license terms.
fa9e4066f08beec538e775443c5be79dd423fcabahrens#pragma ident "%Z%%M% %I% %E% SMI"
c8e9ed14d97e244b9753db14caf8481f181f5750talleytypedef struct ImportablePoolBean {
fa9e4066f08beec538e775443c5be79dd423fcabahrenstypedef struct VirtualDeviceBean {
a1a659ae4f0ae792e70c00834f74ae0d472c2b05talleytypedef struct LeafVirtualDeviceBean {
a1a659ae4f0ae792e70c00834f74ae0d472c2b05talleytypedef struct DiskVirtualDeviceBean {
a1a659ae4f0ae792e70c00834f74ae0d472c2b05talleytypedef struct SliceVirtualDeviceBean {
a1a659ae4f0ae792e70c00834f74ae0d472c2b05talleytypedef struct FileVirtualDeviceBean {
fa9e4066f08beec538e775443c5be79dd423fcabahrenstypedef struct RAIDVirtualDeviceBean {
fbfd10ff571cfd0139aa5127460f1b8a53dac971talley/* vdev_state_t to DeviceStats$DeviceState map */
fbfd10ff571cfd0139aa5127460f1b8a53dac971talley/* vdev_aux_t to DeviceStats$DeviceStatus map */
fbfd10ff571cfd0139aa5127460f1b8a53dac971talley/* zpool_state_t to PoolStats$PoolState map */
fbfd10ff571cfd0139aa5127460f1b8a53dac971talley { POOL_STATE_UNINITIALIZED, "POOL_STATE_UNINITIALIZED" },
fbfd10ff571cfd0139aa5127460f1b8a53dac971talley/* zpool_status_t to PoolStats$PoolStatus map */
fbfd10ff571cfd0139aa5127460f1b8a53dac971talley "ZPOOL_STATUS_CORRUPT_CACHE" },
fbfd10ff571cfd0139aa5127460f1b8a53dac971talley "ZPOOL_STATUS_MISSING_DEV_R" },
fbfd10ff571cfd0139aa5127460f1b8a53dac971talley "ZPOOL_STATUS_MISSING_DEV_NR" },
fbfd10ff571cfd0139aa5127460f1b8a53dac971talley "ZPOOL_STATUS_CORRUPT_LABEL_R" },
fbfd10ff571cfd0139aa5127460f1b8a53dac971talley "ZPOOL_STATUS_CORRUPT_LABEL_NR" },
fbfd10ff571cfd0139aa5127460f1b8a53dac971talley { ZPOOL_STATUS_BAD_GUID_SUM, "ZPOOL_STATUS_BAD_GUID_SUM" },
fbfd10ff571cfd0139aa5127460f1b8a53dac971talley { ZPOOL_STATUS_CORRUPT_POOL, "ZPOOL_STATUS_CORRUPT_POOL" },
fbfd10ff571cfd0139aa5127460f1b8a53dac971talley { ZPOOL_STATUS_CORRUPT_DATA, "ZPOOL_STATUS_CORRUPT_DATA" },
fbfd10ff571cfd0139aa5127460f1b8a53dac971talley { ZPOOL_STATUS_FAILING_DEV, "ZPOOL_STATUS_FAILING_DEV" },
fbfd10ff571cfd0139aa5127460f1b8a53dac971talley "ZPOOL_STATUS_VERSION_MISMATCH" },
fbfd10ff571cfd0139aa5127460f1b8a53dac971talley { ZPOOL_STATUS_RESILVERING, "ZPOOL_STATUS_RESILVERING" },
fbfd10ff571cfd0139aa5127460f1b8a53dac971talley { ZPOOL_STATUS_OFFLINE_DEV, "ZPOOL_STATUS_OFFLINE_DEV" },
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Function prototypes
c8e9ed14d97e244b9753db14caf8481f181f5750talleystatic void new_ImportablePoolBean(JNIEnv *, ImportablePoolBean_t *);
fa9e4066f08beec538e775443c5be79dd423fcabahrensstatic void new_VirtualDevice(JNIEnv *, VirtualDeviceBean_t *);
a1a659ae4f0ae792e70c00834f74ae0d472c2b05talleystatic void new_LeafVirtualDevice(JNIEnv *, LeafVirtualDeviceBean_t *);
fa9e4066f08beec538e775443c5be79dd423fcabahrensstatic void new_DiskVirtualDeviceBean(JNIEnv *, DiskVirtualDeviceBean_t *);
a1a659ae4f0ae792e70c00834f74ae0d472c2b05talleystatic void new_SliceVirtualDeviceBean(JNIEnv *, SliceVirtualDeviceBean_t *);
fa9e4066f08beec538e775443c5be79dd423fcabahrensstatic void new_FileVirtualDeviceBean(JNIEnv *, FileVirtualDeviceBean_t *);
fa9e4066f08beec538e775443c5be79dd423fcabahrensstatic void new_RAIDVirtualDeviceBean(JNIEnv *, RAIDVirtualDeviceBean_t *);
fa9e4066f08beec538e775443c5be79dd423fcabahrensstatic void new_MirrorVirtualDeviceBean(JNIEnv *, MirrorVirtualDeviceBean_t *);
fa9e4066f08beec538e775443c5be79dd423fcabahrens JNIEnv *, zpool_handle_t *, nvlist_t *, VirtualDeviceBean_t *);
a1a659ae4f0ae792e70c00834f74ae0d472c2b05talley JNIEnv *, zpool_handle_t *, nvlist_t *, LeafVirtualDeviceBean_t *);
fa9e4066f08beec538e775443c5be79dd423fcabahrens JNIEnv *, zpool_handle_t *, nvlist_t *, DiskVirtualDeviceBean_t *);
a1a659ae4f0ae792e70c00834f74ae0d472c2b05talley JNIEnv *, zpool_handle_t *, nvlist_t *, SliceVirtualDeviceBean_t *);
fa9e4066f08beec538e775443c5be79dd423fcabahrens JNIEnv *, zpool_handle_t *, nvlist_t *, FileVirtualDeviceBean_t *);
fa9e4066f08beec538e775443c5be79dd423fcabahrens JNIEnv *, zpool_handle_t *, nvlist_t *, RAIDVirtualDeviceBean_t *);
fa9e4066f08beec538e775443c5be79dd423fcabahrens JNIEnv *, zpool_handle_t *, nvlist_t *, MirrorVirtualDeviceBean_t *);
fbfd10ff571cfd0139aa5127460f1b8a53dac971talleystatic jobject create_ImportablePoolBean(JNIEnv *, nvlist_t *);
fbfd10ff571cfd0139aa5127460f1b8a53dac971talleystatic char *find_field(const zjni_field_mapping_t *, int);
fbfd10ff571cfd0139aa5127460f1b8a53dac971talleystatic jobject zjni_vdev_state_to_obj(JNIEnv *, vdev_state_t);
fbfd10ff571cfd0139aa5127460f1b8a53dac971talleystatic jobject zjni_vdev_aux_to_obj(JNIEnv *, vdev_aux_t);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Static functions
c8e9ed14d97e244b9753db14caf8481f181f5750talley/* Create a ImportablePoolBean */
c8e9ed14d97e244b9753db14caf8481f181f5750talleynew_ImportablePoolBean(JNIEnv *env, ImportablePoolBean_t *bean)
c8e9ed14d97e244b9753db14caf8481f181f5750talley (*env)->GetMethodID(env, object->class, "<init>", "()V");
c8e9ed14d97e244b9753db14caf8481f181f5750talley (*env)->NewObject(env, object->class, object->constructor);
fbfd10ff571cfd0139aa5127460f1b8a53dac971talley new_PoolStats(env, &(bean->interface_PoolStats), object);
c8e9ed14d97e244b9753db14caf8481f181f5750talley env, object->class, "setName", "(Ljava/lang/String;)V");
fa9e4066f08beec538e775443c5be79dd423fcabahrens/* Create a VirtualDeviceBean */
fa9e4066f08beec538e775443c5be79dd423fcabahrensnew_VirtualDevice(JNIEnv *env, VirtualDeviceBean_t *bean)
fa9e4066f08beec538e775443c5be79dd423fcabahrens (*env)->GetMethodID(env, object->class, "<init>", "()V");
fa9e4066f08beec538e775443c5be79dd423fcabahrens (*env)->NewObject(env, object->class, object->constructor);
fbfd10ff571cfd0139aa5127460f1b8a53dac971talley new_DeviceStats(env, &(bean->interface_DeviceStats), object);
fa9e4066f08beec538e775443c5be79dd423fcabahrens env, object->class, "setPoolName", "(Ljava/lang/String;)V");
a1a659ae4f0ae792e70c00834f74ae0d472c2b05talley/* Create a LeafVirtualDeviceBean */
a1a659ae4f0ae792e70c00834f74ae0d472c2b05talleynew_LeafVirtualDevice(JNIEnv *env, LeafVirtualDeviceBean_t *bean)
a1a659ae4f0ae792e70c00834f74ae0d472c2b05talley (*env)->GetMethodID(env, object->class, "<init>", "()V");
a1a659ae4f0ae792e70c00834f74ae0d472c2b05talley (*env)->NewObject(env, object->class, object->constructor);
a1a659ae4f0ae792e70c00834f74ae0d472c2b05talley env, object->class, "setName", "(Ljava/lang/String;)V");
fa9e4066f08beec538e775443c5be79dd423fcabahrens/* Create a DiskVirtualDeviceBean */
fa9e4066f08beec538e775443c5be79dd423fcabahrensnew_DiskVirtualDeviceBean(JNIEnv *env, DiskVirtualDeviceBean_t *bean)
fa9e4066f08beec538e775443c5be79dd423fcabahrens (*env)->GetMethodID(env, object->class, "<init>", "()V");
fa9e4066f08beec538e775443c5be79dd423fcabahrens (*env)->NewObject(env, object->class, object->constructor);
a1a659ae4f0ae792e70c00834f74ae0d472c2b05talley new_LeafVirtualDevice(env, (LeafVirtualDeviceBean_t *)bean);
a1a659ae4f0ae792e70c00834f74ae0d472c2b05talley/* Create a SliceVirtualDeviceBean */
a1a659ae4f0ae792e70c00834f74ae0d472c2b05talleynew_SliceVirtualDeviceBean(JNIEnv *env, SliceVirtualDeviceBean_t *bean)
a1a659ae4f0ae792e70c00834f74ae0d472c2b05talley (*env)->GetMethodID(env, object->class, "<init>", "()V");
a1a659ae4f0ae792e70c00834f74ae0d472c2b05talley (*env)->NewObject(env, object->class, object->constructor);
a1a659ae4f0ae792e70c00834f74ae0d472c2b05talley new_LeafVirtualDevice(env, (LeafVirtualDeviceBean_t *)bean);
fa9e4066f08beec538e775443c5be79dd423fcabahrens/* Create a FileVirtualDeviceBean */
fa9e4066f08beec538e775443c5be79dd423fcabahrensnew_FileVirtualDeviceBean(JNIEnv *env, FileVirtualDeviceBean_t *bean)
fa9e4066f08beec538e775443c5be79dd423fcabahrens (*env)->GetMethodID(env, object->class, "<init>", "()V");
fa9e4066f08beec538e775443c5be79dd423fcabahrens (*env)->NewObject(env, object->class, object->constructor);
a1a659ae4f0ae792e70c00834f74ae0d472c2b05talley new_LeafVirtualDevice(env, (LeafVirtualDeviceBean_t *)bean);
fa9e4066f08beec538e775443c5be79dd423fcabahrens/* Create a RAIDVirtualDeviceBean */
fa9e4066f08beec538e775443c5be79dd423fcabahrensnew_RAIDVirtualDeviceBean(JNIEnv *env, RAIDVirtualDeviceBean_t *bean)
fa9e4066f08beec538e775443c5be79dd423fcabahrens (*env)->GetMethodID(env, object->class, "<init>", "()V");
fa9e4066f08beec538e775443c5be79dd423fcabahrens (*env)->NewObject(env, object->class, object->constructor);
fa9e4066f08beec538e775443c5be79dd423fcabahrens/* Create a MirrorVirtualDeviceBean */
fa9e4066f08beec538e775443c5be79dd423fcabahrensnew_MirrorVirtualDeviceBean(JNIEnv *env, MirrorVirtualDeviceBean_t *bean)
fa9e4066f08beec538e775443c5be79dd423fcabahrens (*env)->GetMethodID(env, object->class, "<init>", "()V");
fa9e4066f08beec538e775443c5be79dd423fcabahrens (*env)->NewObject(env, object->class, object->constructor);
c8e9ed14d97e244b9753db14caf8481f181f5750talleypopulate_ImportablePoolBean(JNIEnv *env, ImportablePoolBean_t *bean,
fbfd10ff571cfd0139aa5127460f1b8a53dac971talley PoolStatsBean_t *pool_stats = &(bean->interface_PoolStats);
fbfd10ff571cfd0139aa5127460f1b8a53dac971talley DeviceStatsBean_t *dev_stats = (DeviceStatsBean_t *)pool_stats;
fbfd10ff571cfd0139aa5127460f1b8a53dac971talley if (nvlist_lookup_string(config, ZPOOL_CONFIG_POOL_NAME, &name) ||
fbfd10ff571cfd0139aa5127460f1b8a53dac971talley nvlist_lookup_uint64(config, ZPOOL_CONFIG_POOL_GUID, &guid) ||
fbfd10ff571cfd0139aa5127460f1b8a53dac971talley nvlist_lookup_uint64(config, ZPOOL_CONFIG_POOL_STATE, &state) ||
fbfd10ff571cfd0139aa5127460f1b8a53dac971talley nvlist_lookup_nvlist(config, ZPOOL_CONFIG_VDEV_TREE, &devices) ||
fbfd10ff571cfd0139aa5127460f1b8a53dac971talley populate_DeviceStatsBean(env, devices, dev_stats, object)) {
fbfd10ff571cfd0139aa5127460f1b8a53dac971talley return (-1);
fbfd10ff571cfd0139aa5127460f1b8a53dac971talley bean->method_setName, (*env)->NewStringUTF(env, name));
fbfd10ff571cfd0139aa5127460f1b8a53dac971talley zjni_pool_status_to_obj(env, zpool_import_status(config, &c)));
c8e9ed14d97e244b9753db14caf8481f181f5750talley return (0);
fa9e4066f08beec538e775443c5be79dd423fcabahrenspopulate_VirtualDeviceBean(JNIEnv *env, zpool_handle_t *zhp,
fbfd10ff571cfd0139aa5127460f1b8a53dac971talley DeviceStatsBean_t *stats = &(bean->interface_DeviceStats);
fbfd10ff571cfd0139aa5127460f1b8a53dac971talley result = populate_DeviceStatsBean(env, vdev, stats, object);
fbfd10ff571cfd0139aa5127460f1b8a53dac971talley if (result != 0) {
fbfd10ff571cfd0139aa5127460f1b8a53dac971talley return (1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* Set pool name */
fbfd10ff571cfd0139aa5127460f1b8a53dac971talley poolUTF = (*env)->NewStringUTF(env, zpool_get_name(zhp));
fa9e4066f08beec538e775443c5be79dd423fcabahrens env, object->object, bean->method_setPoolName, poolUTF);
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* Get index */
fa9e4066f08beec538e775443c5be79dd423fcabahrens result = nvlist_lookup_uint64(vdev, ZPOOL_CONFIG_GUID, &vdev_id);
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (result != 0) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens "could not retrieve virtual device ID (pool %s)",
fbfd10ff571cfd0139aa5127460f1b8a53dac971talley return (1);
fbfd10ff571cfd0139aa5127460f1b8a53dac971talley env, object->object, bean->method_setIndex, (jlong)vdev_id);
fbfd10ff571cfd0139aa5127460f1b8a53dac971talley return (0);
a1a659ae4f0ae792e70c00834f74ae0d472c2b05talleypopulate_LeafVirtualDeviceBean(JNIEnv *env, zpool_handle_t *zhp,
fa9e4066f08beec538e775443c5be79dd423fcabahrenspopulate_DiskVirtualDeviceBean(JNIEnv *env, zpool_handle_t *zhp,
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* Must not call any more Java methods to preserve exception */
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (-1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* Set path */
fa9e4066f08beec538e775443c5be79dd423fcabahrens result = nvlist_lookup_string(vdev, ZPOOL_CONFIG_PATH, &path);
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (result != 0) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens "could not retrive path from disk virtual device (pool %s)",
a1a659ae4f0ae792e70c00834f74ae0d472c2b05talley /* Strip off slice portion of name, if applicable */
a1a659ae4f0ae792e70c00834f74ae0d472c2b05talley if (regcomp(&re, "^(/dev/dsk/.*)s[0-9]+$", REG_EXTENDED) == 0) {
a1a659ae4f0ae792e70c00834f74ae0d472c2b05talley (*env)->CallVoidMethod(env, ((zjni_Object_t *)bean)->object,
a1a659ae4f0ae792e70c00834f74ae0d472c2b05talley ((LeafVirtualDeviceBean_t *)bean)->method_setName, pathUTF);
a1a659ae4f0ae792e70c00834f74ae0d472c2b05talley return (result != 0);
a1a659ae4f0ae792e70c00834f74ae0d472c2b05talleypopulate_SliceVirtualDeviceBean(JNIEnv *env, zpool_handle_t *zhp,
a1a659ae4f0ae792e70c00834f74ae0d472c2b05talley /* Must not call any more Java methods to preserve exception */
a1a659ae4f0ae792e70c00834f74ae0d472c2b05talley return (-1);
a1a659ae4f0ae792e70c00834f74ae0d472c2b05talley /* Set path */
a1a659ae4f0ae792e70c00834f74ae0d472c2b05talley result = nvlist_lookup_string(vdev, ZPOOL_CONFIG_PATH, &path);
a1a659ae4f0ae792e70c00834f74ae0d472c2b05talley if (result != 0) {
a1a659ae4f0ae792e70c00834f74ae0d472c2b05talley "could not retrive path from slice virtual device (pool "
fa9e4066f08beec538e775443c5be79dd423fcabahrens (*env)->CallVoidMethod(env, ((zjni_Object_t *)bean)->object,
a1a659ae4f0ae792e70c00834f74ae0d472c2b05talley ((LeafVirtualDeviceBean_t *)bean)->method_setName, pathUTF);
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (result != 0);
fa9e4066f08beec538e775443c5be79dd423fcabahrenspopulate_FileVirtualDeviceBean(JNIEnv *env, zpool_handle_t *zhp,
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* Must not call any more Java methods to preserve exception */
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (-1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* Set path */
fa9e4066f08beec538e775443c5be79dd423fcabahrens result = nvlist_lookup_string(vdev, ZPOOL_CONFIG_PATH, &path);
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (result != 0) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens "could not retrive path from disk virtual device (pool %s)",
fa9e4066f08beec538e775443c5be79dd423fcabahrens (*env)->CallVoidMethod(env, ((zjni_Object_t *)bean)->object,
a1a659ae4f0ae792e70c00834f74ae0d472c2b05talley ((LeafVirtualDeviceBean_t *)bean)->method_setName, pathUTF);
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (result != 0);
fa9e4066f08beec538e775443c5be79dd423fcabahrenspopulate_RAIDVirtualDeviceBean(JNIEnv *env, zpool_handle_t *zhp,
fa9e4066f08beec538e775443c5be79dd423fcabahrenspopulate_MirrorVirtualDeviceBean(JNIEnv *env, zpool_handle_t *zhp,
fbfd10ff571cfd0139aa5127460f1b8a53dac971talleycreate_ImportablePoolBean(JNIEnv *env, nvlist_t *config)
c8e9ed14d97e244b9753db14caf8481f181f5750talley /* Construct ImportablePoolBean */
fbfd10ff571cfd0139aa5127460f1b8a53dac971talley result = populate_ImportablePoolBean(env, bean, config);
c8e9ed14d97e244b9753db14caf8481f181f5750talley /* Must not call any more Java methods to preserve exception */
fa9e4066f08beec538e775443c5be79dd423fcabahrenscreate_DiskVirtualDeviceBean(JNIEnv *env, zpool_handle_t *zhp, nvlist_t *vdev)
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* Construct DiskVirtualDeviceBean */
fa9e4066f08beec538e775443c5be79dd423fcabahrens result = populate_DiskVirtualDeviceBean(env, zhp, vdev, bean);
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* Must not call any more Java methods to preserve exception */
a1a659ae4f0ae792e70c00834f74ae0d472c2b05talleycreate_SliceVirtualDeviceBean(JNIEnv *env, zpool_handle_t *zhp, nvlist_t *vdev)
a1a659ae4f0ae792e70c00834f74ae0d472c2b05talley /* Construct SliceVirtualDeviceBean */
a1a659ae4f0ae792e70c00834f74ae0d472c2b05talley result = populate_SliceVirtualDeviceBean(env, zhp, vdev, bean);
a1a659ae4f0ae792e70c00834f74ae0d472c2b05talley /* Must not call any more Java methods to preserve exception */
fa9e4066f08beec538e775443c5be79dd423fcabahrenscreate_FileVirtualDeviceBean(JNIEnv *env, zpool_handle_t *zhp, nvlist_t *vdev)
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* Construct FileVirtualDeviceBean */
fa9e4066f08beec538e775443c5be79dd423fcabahrens result = populate_FileVirtualDeviceBean(env, zhp, vdev, bean);
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* Must not call any more Java methods to preserve exception */
fa9e4066f08beec538e775443c5be79dd423fcabahrenscreate_RAIDVirtualDeviceBean(JNIEnv *env, zpool_handle_t *zhp, nvlist_t *vdev)
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* Construct RAIDVirtualDeviceBean */
fa9e4066f08beec538e775443c5be79dd423fcabahrens result = populate_RAIDVirtualDeviceBean(env, zhp, vdev, bean);
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* Must not call any more Java methods to preserve exception */
fa9e4066f08beec538e775443c5be79dd423fcabahrenscreate_MirrorVirtualDeviceBean(JNIEnv *env, zpool_handle_t *zhp, nvlist_t *vdev)
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* Construct MirrorVirtualDeviceBean */
fa9e4066f08beec538e775443c5be79dd423fcabahrens result = populate_MirrorVirtualDeviceBean(env, zhp, vdev, bean);
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* Must not call any more Java methods to preserve exception */
fbfd10ff571cfd0139aa5127460f1b8a53dac971talleystatic char *
fbfd10ff571cfd0139aa5127460f1b8a53dac971talleyfind_field(const zjni_field_mapping_t *mapping, int value) {
fbfd10ff571cfd0139aa5127460f1b8a53dac971talley * Converts a vdev_state_t to a Java DeviceStats$DeviceState object.
fbfd10ff571cfd0139aa5127460f1b8a53dac971talleyzjni_vdev_state_to_obj(JNIEnv *env, vdev_state_t state)
fbfd10ff571cfd0139aa5127460f1b8a53dac971talley * Converts a vdev_aux_t to a Java DeviceStats$DeviceStatus object.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Package-private functions
fbfd10ff571cfd0139aa5127460f1b8a53dac971talley/* Create a DeviceStatsBean */
fbfd10ff571cfd0139aa5127460f1b8a53dac971talleynew_DeviceStats(JNIEnv *env, DeviceStatsBean_t *bean, zjni_Object_t *object)
a1a659ae4f0ae792e70c00834f74ae0d472c2b05talley bean->method_setReplacementSize = (*env)->GetMethodID(
fbfd10ff571cfd0139aa5127460f1b8a53dac971talley bean->method_setReadOperations = (*env)->GetMethodID(
fbfd10ff571cfd0139aa5127460f1b8a53dac971talley bean->method_setWriteOperations = (*env)->GetMethodID(
fbfd10ff571cfd0139aa5127460f1b8a53dac971talley bean->method_setChecksumErrors = (*env)->GetMethodID(
fbfd10ff571cfd0139aa5127460f1b8a53dac971talley "(L" ZFSJNI_PACKAGE_DATA "DeviceStats$DeviceState;)V");
fbfd10ff571cfd0139aa5127460f1b8a53dac971talley "(L" ZFSJNI_PACKAGE_DATA "DeviceStats$DeviceStatus;)V");
fbfd10ff571cfd0139aa5127460f1b8a53dac971talley/* Create a PoolStatsBean */
fbfd10ff571cfd0139aa5127460f1b8a53dac971talleynew_PoolStats(JNIEnv *env, PoolStatsBean_t *bean, zjni_Object_t *object)
fbfd10ff571cfd0139aa5127460f1b8a53dac971talley new_DeviceStats(env, (DeviceStatsBean_t *)bean, object);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Gets the root vdev (an nvlist_t *) for the given pool.
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (result != 0) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Gets the vdev (an nvlist_t *) with the given vdev_id, below the
fa9e4066f08beec538e775443c5be79dd423fcabahrens * given vdev. If the given vdev is NULL, all vdevs within the given
fa9e4066f08beec538e775443c5be79dd423fcabahrens * pool are searched.
fa9e4066f08beec538e775443c5be79dd423fcabahrenszjni_get_vdev(zpool_handle_t *zhp, nvlist_t *vdev_parent,
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* Was a vdev specified? */
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* No -- retrieve the top-level pool vdev */
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* Get index of this vdev and compare with vdev_id_to_find */
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* Get the vdevs under this vdev */
fa9e4066f08beec538e775443c5be79dd423fcabahrens vdev_parent, ZPOOL_CONFIG_CHILDREN, &children, &nelem);
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (result == 0) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* For each vdev child... */
fa9e4066f08beec538e775443c5be79dd423fcabahrens for (i = 0; i < nelem; i++) {
fa9e4066f08beec538e775443c5be79dd423fcabahrenszjni_get_VirtualDevice_from_vdev(JNIEnv *env, zpool_handle_t *zhp,
fa9e4066f08beec538e775443c5be79dd423fcabahrens int result = nvlist_lookup_string(vdev, ZPOOL_CONFIG_TYPE, &type);
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (result == 0) {
a1a659ae4f0ae792e70c00834f74ae0d472c2b05talley if (nvlist_lookup_uint64(vdev, ZPOOL_CONFIG_WHOLE_DISK,
fa9e4066f08beec538e775443c5be79dd423fcabahrens obj = create_MirrorVirtualDeviceBean(env, zhp, vdev);
c8e9ed14d97e244b9753db14caf8481f181f5750talley /* Get the vdevs under this vdev */
c8e9ed14d97e244b9753db14caf8481f181f5750talley /* Get last vdev child (replacement device) */
fa9e4066f08beec538e775443c5be79dd423fcabahrenszjni_get_VirtualDevices_from_vdev(JNIEnv *env, zpool_handle_t *zhp,
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* Create an array list for the vdevs */
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* Was a vdev specified? */
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* No -- retrieve the top-level pool vdev */
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* Get the vdevs under this vdev */
fa9e4066f08beec538e775443c5be79dd423fcabahrens vdev_parent, ZPOOL_CONFIG_CHILDREN, &children, &nelem);
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (result == 0) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* For each vdev child... */
fa9e4066f08beec538e775443c5be79dd423fcabahrens for (i = 0; i < nelem; i++) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* Create a Java object from this vdev */
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Must not call any more Java methods
fa9e4066f08beec538e775443c5be79dd423fcabahrens * to preserve exception
c8e9ed14d97e244b9753db14caf8481f181f5750talley /* Add child to child vdev list */
fbfd10ff571cfd0139aa5127460f1b8a53dac971talleyzjni_create_add_ImportablePool(nvlist_t *config, void *data) {
c8e9ed14d97e244b9753db14caf8481f181f5750talley JNIEnv *env = ((zjni_ArrayCallbackData_t *)data)->env;
c8e9ed14d97e244b9753db14caf8481f181f5750talley zjni_Collection_t *list = ((zjni_ArrayCallbackData_t *)data)->list;
c8e9ed14d97e244b9753db14caf8481f181f5750talley /* Construct ImportablePool object */
fbfd10ff571cfd0139aa5127460f1b8a53dac971talley jobject bean = create_ImportablePoolBean(env, config);
c8e9ed14d97e244b9753db14caf8481f181f5750talley return (-1);
c8e9ed14d97e244b9753db14caf8481f181f5750talley /* Add bean to list */
c8e9ed14d97e244b9753db14caf8481f181f5750talley (*env)->CallBooleanMethod(env, ((zjni_Object_t *)list)->object,
c8e9ed14d97e244b9753db14caf8481f181f5750talley return (0);
fbfd10ff571cfd0139aa5127460f1b8a53dac971talley if (result != 0) {
fbfd10ff571cfd0139aa5127460f1b8a53dac971talley "could not retrieve virtual device statistics");
fbfd10ff571cfd0139aa5127460f1b8a53dac971talley return (1);
a1a659ae4f0ae792e70c00834f74ae0d472c2b05talley bean->method_setReplacementSize, (jlong)vs->vs_rsize);
fbfd10ff571cfd0139aa5127460f1b8a53dac971talley bean->method_setReadBytes, (jlong)vs->vs_bytes[ZIO_TYPE_READ]);
fbfd10ff571cfd0139aa5127460f1b8a53dac971talley bean->method_setWriteBytes, (jlong)vs->vs_bytes[ZIO_TYPE_WRITE]);
fbfd10ff571cfd0139aa5127460f1b8a53dac971talley bean->method_setReadOperations, (jlong)vs->vs_ops[ZIO_TYPE_READ]);
fbfd10ff571cfd0139aa5127460f1b8a53dac971talley bean->method_setWriteOperations, (jlong)vs->vs_ops[ZIO_TYPE_WRITE]);
fbfd10ff571cfd0139aa5127460f1b8a53dac971talley bean->method_setReadErrors, (jlong)vs->vs_read_errors);
fbfd10ff571cfd0139aa5127460f1b8a53dac971talley bean->method_setWriteErrors, (jlong)vs->vs_write_errors);
fbfd10ff571cfd0139aa5127460f1b8a53dac971talley bean->method_setChecksumErrors, (jlong)vs->vs_checksum_errors);
fbfd10ff571cfd0139aa5127460f1b8a53dac971talley return (0);
fbfd10ff571cfd0139aa5127460f1b8a53dac971talley * Converts a pool_state_t to a Java PoolStats$PoolState object.
fbfd10ff571cfd0139aa5127460f1b8a53dac971talleyzjni_pool_state_to_obj(JNIEnv *env, pool_state_t state)
fbfd10ff571cfd0139aa5127460f1b8a53dac971talley * Converts a zpool_status_t to a Java PoolStats$PoolStatus object.
fbfd10ff571cfd0139aa5127460f1b8a53dac971talleyzjni_pool_status_to_obj(JNIEnv *env, zpool_status_t status)
c8e9ed14d97e244b9753db14caf8481f181f5750talley * Extern functions
c8e9ed14d97e244b9753db14caf8481f181f5750talley * Iterates through each importable pool on the system. For each
c8e9ed14d97e244b9753db14caf8481f181f5750talley * importable pool, runs the given function with the given void as the
c8e9ed14d97e244b9753db14caf8481f181f5750talley * last arg.
c8e9ed14d97e244b9753db14caf8481f181f5750talleyzjni_ipool_iter(int argc, char **argv, zjni_ipool_iter_f func, void *data)
c8e9ed14d97e244b9753db14caf8481f181f5750talley while ((elem = nvlist_next_nvpair(pools, elem)) != NULL) {
c8e9ed14d97e244b9753db14caf8481f181f5750talley return (-1);
c8e9ed14d97e244b9753db14caf8481f181f5750talley return (0);