fa9e4066f08beec538e775443c5be79dd423fcabahrens * CDDL HEADER START
fa9e4066f08beec538e775443c5be79dd423fcabahrens * The contents of this file are subject to the terms of the
bfe5f5a4bed2da6ba708c3b046a37de8b4568d4ftalley * Common Development and Distribution License (the "License").
bfe5f5a4bed2da6ba708c3b046a37de8b4568d4ftalley * You may not use this file except in compliance 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
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
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" },
a55b6846f87afedf14b3f9b64fbb8c0d0a3f2fe2cristian { POOL_STATE_POTENTIALLY_ACTIVE, "POOL_STATE_POTENTIALLY_ACTIVE" },
fbfd10ff571cfd0139aa5127460f1b8a53dac971talley/* zpool_status_t to PoolStats$PoolStatus map */
a55b6846f87afedf14b3f9b64fbb8c0d0a3f2fe2cristian { ZPOOL_STATUS_CORRUPT_CACHE, "ZPOOL_STATUS_CORRUPT_CACHE" },
a55b6846f87afedf14b3f9b64fbb8c0d0a3f2fe2cristian { ZPOOL_STATUS_MISSING_DEV_R, "ZPOOL_STATUS_MISSING_DEV_R" },
a55b6846f87afedf14b3f9b64fbb8c0d0a3f2fe2cristian { ZPOOL_STATUS_MISSING_DEV_NR, "ZPOOL_STATUS_MISSING_DEV_NR" },
a55b6846f87afedf14b3f9b64fbb8c0d0a3f2fe2cristian { ZPOOL_STATUS_CORRUPT_LABEL_R, "ZPOOL_STATUS_CORRUPT_LABEL_R" },
a55b6846f87afedf14b3f9b64fbb8c0d0a3f2fe2cristian { ZPOOL_STATUS_CORRUPT_LABEL_NR, "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" },
a55b6846f87afedf14b3f9b64fbb8c0d0a3f2fe2cristian { ZPOOL_STATUS_VERSION_NEWER, "ZPOOL_STATUS_VERSION_NEWER" },
a55b6846f87afedf14b3f9b64fbb8c0d0a3f2fe2cristian { ZPOOL_STATUS_HOSTID_MISMATCH, "ZPOOL_STATUS_HOSTID_MISMATCH" },
a55b6846f87afedf14b3f9b64fbb8c0d0a3f2fe2cristian { ZPOOL_STATUS_FAULTED_DEV_R, "ZPOOL_STATUS_FAULTED_DEV_R" },
a55b6846f87afedf14b3f9b64fbb8c0d0a3f2fe2cristian { ZPOOL_STATUS_FAULTED_DEV_NR, "ZPOOL_STATUS_FAULTED_DEV_NR" },
a55b6846f87afedf14b3f9b64fbb8c0d0a3f2fe2cristian { ZPOOL_STATUS_VERSION_OLDER, "ZPOOL_STATUS_VERSION_OLDER" },
fbfd10ff571cfd0139aa5127460f1b8a53dac971talley { ZPOOL_STATUS_RESILVERING, "ZPOOL_STATUS_RESILVERING" },
fbfd10ff571cfd0139aa5127460f1b8a53dac971talley { ZPOOL_STATUS_OFFLINE_DEV, "ZPOOL_STATUS_OFFLINE_DEV" },
c25309d42d46e04be84e0dbadaf3c9ab3369ad05George Wilson { ZPOOL_STATUS_REMOVED_DEV, "ZPOOL_STATUS_REMOVED_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 *);
bfe5f5a4bed2da6ba708c3b046a37de8b4568d4ftalleystatic int populate_VirtualDeviceBean(JNIEnv *, zpool_handle_t *,
bfe5f5a4bed2da6ba708c3b046a37de8b4568d4ftalley nvlist_t *, uint64_t *p_vdev_id, VirtualDeviceBean_t *);
bfe5f5a4bed2da6ba708c3b046a37de8b4568d4ftalleystatic int populate_LeafVirtualDeviceBean(JNIEnv *, zpool_handle_t *,
bfe5f5a4bed2da6ba708c3b046a37de8b4568d4ftalley nvlist_t *, uint64_t *p_vdev_id, LeafVirtualDeviceBean_t *);
bfe5f5a4bed2da6ba708c3b046a37de8b4568d4ftalleystatic int populate_DiskVirtualDeviceBean(JNIEnv *, zpool_handle_t *,
bfe5f5a4bed2da6ba708c3b046a37de8b4568d4ftalley nvlist_t *, uint64_t *p_vdev_id, DiskVirtualDeviceBean_t *);
bfe5f5a4bed2da6ba708c3b046a37de8b4568d4ftalleystatic int populate_SliceVirtualDeviceBean(JNIEnv *, zpool_handle_t *,
bfe5f5a4bed2da6ba708c3b046a37de8b4568d4ftalley nvlist_t *, uint64_t *p_vdev_id, SliceVirtualDeviceBean_t *);
bfe5f5a4bed2da6ba708c3b046a37de8b4568d4ftalleystatic int populate_FileVirtualDeviceBean(JNIEnv *, zpool_handle_t *,
bfe5f5a4bed2da6ba708c3b046a37de8b4568d4ftalley nvlist_t *, uint64_t *p_vdev_id, FileVirtualDeviceBean_t *);
bfe5f5a4bed2da6ba708c3b046a37de8b4568d4ftalleystatic int populate_RAIDVirtualDeviceBean(JNIEnv *, zpool_handle_t *,
bfe5f5a4bed2da6ba708c3b046a37de8b4568d4ftalley nvlist_t *, uint64_t *p_vdev_id, RAIDVirtualDeviceBean_t *);
bfe5f5a4bed2da6ba708c3b046a37de8b4568d4ftalleystatic int populate_MirrorVirtualDeviceBean(JNIEnv *, zpool_handle_t *,
bfe5f5a4bed2da6ba708c3b046a37de8b4568d4ftalley nvlist_t *, uint64_t *p_vdev_id, MirrorVirtualDeviceBean_t *);
fbfd10ff571cfd0139aa5127460f1b8a53dac971talleystatic jobject create_ImportablePoolBean(JNIEnv *, nvlist_t *);
bfe5f5a4bed2da6ba708c3b046a37de8b4568d4ftalley JNIEnv *, zpool_handle_t *, nvlist_t *, uint64_t *p_vdev_id);
bfe5f5a4bed2da6ba708c3b046a37de8b4568d4ftalley JNIEnv *, zpool_handle_t *, nvlist_t *, uint64_t *p_vdev_id);
bfe5f5a4bed2da6ba708c3b046a37de8b4568d4ftalley JNIEnv *, zpool_handle_t *, nvlist_t *, uint64_t *p_vdev_id);
bfe5f5a4bed2da6ba708c3b046a37de8b4568d4ftalley JNIEnv *, zpool_handle_t *, nvlist_t *, uint64_t *p_vdev_id);
bfe5f5a4bed2da6ba708c3b046a37de8b4568d4ftalley JNIEnv *, zpool_handle_t *, nvlist_t *, uint64_t *p_vdev_id);
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");
bfe5f5a4bed2da6ba708c3b046a37de8b4568d4ftalley env, object->class, "setParentIndex", "(Ljava/lang/Long;)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) ||
a55b6846f87afedf14b3f9b64fbb8c0d0a3f2fe2cristian nvlist_lookup_uint64(config, ZPOOL_CONFIG_VERSION, &version) ||
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)));
a55b6846f87afedf14b3f9b64fbb8c0d0a3f2fe2cristian pool_stats->method_setPoolVersion, (jlong)version);
c8e9ed14d97e244b9753db14caf8481f181f5750talley return (0);
fa9e4066f08beec538e775443c5be79dd423fcabahrenspopulate_VirtualDeviceBean(JNIEnv *env, zpool_handle_t *zhp,
bfe5f5a4bed2da6ba708c3b046a37de8b4568d4ftalley nvlist_t *vdev, uint64_t *p_vdev_id, VirtualDeviceBean_t *bean)
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);
bfe5f5a4bed2da6ba708c3b046a37de8b4568d4ftalley /* Set parent vdev index */
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,
bfe5f5a4bed2da6ba708c3b046a37de8b4568d4ftalley nvlist_t *vdev, uint64_t *p_vdev_id, LeafVirtualDeviceBean_t *bean)
bfe5f5a4bed2da6ba708c3b046a37de8b4568d4ftalley env, zhp, vdev, p_vdev_id, (VirtualDeviceBean_t *)bean));
fa9e4066f08beec538e775443c5be79dd423fcabahrenspopulate_DiskVirtualDeviceBean(JNIEnv *env, zpool_handle_t *zhp,
bfe5f5a4bed2da6ba708c3b046a37de8b4568d4ftalley nvlist_t *vdev, uint64_t *p_vdev_id, DiskVirtualDeviceBean_t *bean)
bfe5f5a4bed2da6ba708c3b046a37de8b4568d4ftalley env, zhp, vdev, p_vdev_id, (LeafVirtualDeviceBean_t *)bean);
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) {
d7d4af51b4d115490d97f0b89993fdbaaf441c94mmusante "could not retrieve path from disk virtual device "
a1a659ae4f0ae792e70c00834f74ae0d472c2b05talley /* Strip off slice portion of name, if applicable */
a1a659ae4f0ae792e70c00834f74ae0d472c2b05talley if (regcomp(&re, "^(/dev/dsk/.*)s[0-9]+$", REG_EXTENDED) == 0) {
3fdda4994a108ded4ec1a2b544804f191a4ec83aJohn Harres if (regcomp(&re, "^(/dev/dsk/.*)s[0-9]+/old$", REG_EXTENDED) ==
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,
bfe5f5a4bed2da6ba708c3b046a37de8b4568d4ftalley nvlist_t *vdev, uint64_t *p_vdev_id, SliceVirtualDeviceBean_t *bean)
bfe5f5a4bed2da6ba708c3b046a37de8b4568d4ftalley env, zhp, vdev, p_vdev_id, (LeafVirtualDeviceBean_t *)bean);
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) {
d7d4af51b4d115490d97f0b89993fdbaaf441c94mmusante "could not retrieve path from slice virtual device (pool "
fa9e4066f08beec538e775443c5be79dd423fcabahrens (*env)->CallVoidMethod(env, ((zjni_Object_t *)bean)->object,
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (result != 0);
fa9e4066f08beec538e775443c5be79dd423fcabahrenspopulate_FileVirtualDeviceBean(JNIEnv *env, zpool_handle_t *zhp,
bfe5f5a4bed2da6ba708c3b046a37de8b4568d4ftalley nvlist_t *vdev, uint64_t *p_vdev_id, FileVirtualDeviceBean_t *bean)
bfe5f5a4bed2da6ba708c3b046a37de8b4568d4ftalley env, zhp, vdev, p_vdev_id, (LeafVirtualDeviceBean_t *)bean);
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) {
d7d4af51b4d115490d97f0b89993fdbaaf441c94mmusante "could not retrieve path from disk virtual device "
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,
bfe5f5a4bed2da6ba708c3b046a37de8b4568d4ftalley nvlist_t *vdev, uint64_t *p_vdev_id, RAIDVirtualDeviceBean_t *bean)
bfe5f5a4bed2da6ba708c3b046a37de8b4568d4ftalley return (populate_VirtualDeviceBean(env, zhp, vdev, p_vdev_id,
fa9e4066f08beec538e775443c5be79dd423fcabahrenspopulate_MirrorVirtualDeviceBean(JNIEnv *env, zpool_handle_t *zhp,
bfe5f5a4bed2da6ba708c3b046a37de8b4568d4ftalley nvlist_t *vdev, uint64_t *p_vdev_id, MirrorVirtualDeviceBean_t *bean)
bfe5f5a4bed2da6ba708c3b046a37de8b4568d4ftalley return (populate_VirtualDeviceBean(env, zhp, vdev, p_vdev_id,
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 */
bfe5f5a4bed2da6ba708c3b046a37de8b4568d4ftalleycreate_DiskVirtualDeviceBean(JNIEnv *env, zpool_handle_t *zhp,
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* Construct DiskVirtualDeviceBean */
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* Must not call any more Java methods to preserve exception */
bfe5f5a4bed2da6ba708c3b046a37de8b4568d4ftalleycreate_SliceVirtualDeviceBean(JNIEnv *env, zpool_handle_t *zhp,
a1a659ae4f0ae792e70c00834f74ae0d472c2b05talley /* Construct SliceVirtualDeviceBean */
a1a659ae4f0ae792e70c00834f74ae0d472c2b05talley /* Must not call any more Java methods to preserve exception */
bfe5f5a4bed2da6ba708c3b046a37de8b4568d4ftalleycreate_FileVirtualDeviceBean(JNIEnv *env, zpool_handle_t *zhp,
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* Construct FileVirtualDeviceBean */
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* Must not call any more Java methods to preserve exception */
bfe5f5a4bed2da6ba708c3b046a37de8b4568d4ftalleycreate_RAIDVirtualDeviceBean(JNIEnv *env, zpool_handle_t *zhp,
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* Construct RAIDVirtualDeviceBean */
1e995cfce563729fbd612e2ee27dbbab4f50dbaarl /* Set parity bit */
1e995cfce563729fbd612e2ee27dbbab4f50dbaarl result = nvlist_lookup_uint64(vdev, ZPOOL_CONFIG_NPARITY,
1e995cfce563729fbd612e2ee27dbbab4f50dbaarl /* Default to RAID-Z1 in case of error */
1e995cfce563729fbd612e2ee27dbbab4f50dbaarl env, ((zjni_Object_t *)bean)->object, bean->method_setParity,
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* Must not call any more Java methods to preserve exception */
bfe5f5a4bed2da6ba708c3b046a37de8b4568d4ftalleycreate_MirrorVirtualDeviceBean(JNIEnv *env, zpool_handle_t *zhp,
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* Construct MirrorVirtualDeviceBean */
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.
bfe5f5a4bed2da6ba708c3b046a37de8b4568d4ftalley * If p_vdev_id is not NULL, it will be set to the ID of the parent
bfe5f5a4bed2da6ba708c3b046a37de8b4568d4ftalley * vdev, if any, or to vdev_id_to_find if the searched-for vdev is a
bfe5f5a4bed2da6ba708c3b046a37de8b4568d4ftalley * toplevel vdev.
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++) {
bfe5f5a4bed2da6ba708c3b046a37de8b4568d4ftalley /* Save parent vdev id */
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,
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);
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling vdev, ZPOOL_CONFIG_VDEV_STATS, (uint64_t **)&vs, &c);
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);