fa9e4066f08beec538e775443c5be79dd423fcabahrens/*
fa9e4066f08beec538e775443c5be79dd423fcabahrens * CDDL HEADER START
fa9e4066f08beec538e775443c5be79dd423fcabahrens *
fa9e4066f08beec538e775443c5be79dd423fcabahrens * The contents of this file are subject to the terms of the
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley * Common Development and Distribution License (the "License").
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley * You may not use this file except in compliance with the License.
fa9e4066f08beec538e775443c5be79dd423fcabahrens *
fa9e4066f08beec538e775443c5be79dd423fcabahrens * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
fa9e4066f08beec538e775443c5be79dd423fcabahrens * or http://www.opensolaris.org/os/licensing.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * See the License for the specific language governing permissions
fa9e4066f08beec538e775443c5be79dd423fcabahrens * and limitations under the License.
fa9e4066f08beec538e775443c5be79dd423fcabahrens *
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 *
fa9e4066f08beec538e775443c5be79dd423fcabahrens * CDDL HEADER END
fa9e4066f08beec538e775443c5be79dd423fcabahrens */
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley
fa9e4066f08beec538e775443c5be79dd423fcabahrens/*
990b4856d0eaada6f8140335733a1b1771ed2746lling * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Use is subject to license terms.
fa9e4066f08beec538e775443c5be79dd423fcabahrens */
fa9e4066f08beec538e775443c5be79dd423fcabahrens
9adfa60d484ce2435f5af77cc99dcd4e692b6660Matthew Ahrens/*
9adfa60d484ce2435f5af77cc99dcd4e692b6660Matthew Ahrens * Copyright (c) 2015 by Delphix. All rights reserved.
9adfa60d484ce2435f5af77cc99dcd4e692b6660Matthew Ahrens */
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fbfd10ff571cfd0139aa5127460f1b8a53dac971talley#include "libzfs_jni_util.h"
fa9e4066f08beec538e775443c5be79dd423fcabahrens#include "libzfs_jni_dataset.h"
fa9e4066f08beec538e775443c5be79dd423fcabahrens#include "libzfs_jni_property.h"
fbfd10ff571cfd0139aa5127460f1b8a53dac971talley#include "libzfs_jni_pool.h"
fa9e4066f08beec538e775443c5be79dd423fcabahrens#include <strings.h>
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens#define REGEX_ZFS_NAME "^((([^/]*)(/.+)?)[/@])?([^/]+)/*"
fa9e4066f08beec538e775443c5be79dd423fcabahrens#define REGEX_ZFS_NAME_NGROUPS 6
fa9e4066f08beec538e775443c5be79dd423fcabahrens#define REGEX_ZFS_NAME_POOL_GROUP 3
fa9e4066f08beec538e775443c5be79dd423fcabahrens#define REGEX_ZFS_NAME_PARENT_GROUP 2
fa9e4066f08beec538e775443c5be79dd423fcabahrens#define REGEX_ZFS_NAME_BASE_GROUP 5
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens/*
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Types
fa9e4066f08beec538e775443c5be79dd423fcabahrens */
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrenstypedef struct DatasetBean {
fa9e4066f08beec538e775443c5be79dd423fcabahrens zjni_Object_t super;
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens jmethodID method_setPoolName;
fa9e4066f08beec538e775443c5be79dd423fcabahrens jmethodID method_setParentName;
fa9e4066f08beec538e775443c5be79dd423fcabahrens jmethodID method_setBaseName;
fa9e4066f08beec538e775443c5be79dd423fcabahrens jmethodID method_setProperties;
fa9e4066f08beec538e775443c5be79dd423fcabahrens jmethodID method_addProperty;
fa9e4066f08beec538e775443c5be79dd423fcabahrens} DatasetBean_t;
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrenstypedef struct FileSystemBean {
fa9e4066f08beec538e775443c5be79dd423fcabahrens DatasetBean_t super;
fa9e4066f08beec538e775443c5be79dd423fcabahrens} FileSystemBean_t;
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrenstypedef struct PoolBean {
fa9e4066f08beec538e775443c5be79dd423fcabahrens FileSystemBean_t super;
fbfd10ff571cfd0139aa5127460f1b8a53dac971talley PoolStatsBean_t interface_PoolStats;
fa9e4066f08beec538e775443c5be79dd423fcabahrens} PoolBean_t;
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrenstypedef struct VolumeBean {
fa9e4066f08beec538e775443c5be79dd423fcabahrens DatasetBean_t super;
fa9e4066f08beec538e775443c5be79dd423fcabahrens} VolumeBean_t;
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrenstypedef struct SnapshotBean {
fa9e4066f08beec538e775443c5be79dd423fcabahrens DatasetBean_t super;
fa9e4066f08beec538e775443c5be79dd423fcabahrens} SnapshotBean_t;
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrenstypedef struct FileSystemSnapshotBean {
fa9e4066f08beec538e775443c5be79dd423fcabahrens DatasetBean_t super;
fa9e4066f08beec538e775443c5be79dd423fcabahrens} FileSystemSnapshotBean_t;
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrenstypedef struct VolumeSnapshotBean {
fa9e4066f08beec538e775443c5be79dd423fcabahrens DatasetBean_t super;
fa9e4066f08beec538e775443c5be79dd423fcabahrens} VolumeSnapshotBean_t;
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens/*
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Function prototypes
fa9e4066f08beec538e775443c5be79dd423fcabahrens */
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrensstatic void new_DatasetBean(JNIEnv *, DatasetBean_t *);
fa9e4066f08beec538e775443c5be79dd423fcabahrensstatic void new_PoolBean(JNIEnv *, PoolBean_t *);
fa9e4066f08beec538e775443c5be79dd423fcabahrensstatic void new_FileSystemBean(JNIEnv *, FileSystemBean_t *);
fa9e4066f08beec538e775443c5be79dd423fcabahrensstatic void new_VolumeBean(JNIEnv *, VolumeBean_t *);
fa9e4066f08beec538e775443c5be79dd423fcabahrensstatic void new_SnapshotBean(JNIEnv *, SnapshotBean_t *);
fa9e4066f08beec538e775443c5be79dd423fcabahrensstatic void new_FileSystemSnapshotBean(JNIEnv *, FileSystemSnapshotBean_t *);
fa9e4066f08beec538e775443c5be79dd423fcabahrensstatic void new_VolumeSnapshotBean(JNIEnv *, VolumeSnapshotBean_t *);
32f884e0ef76c8ab2a6e26895696620c8d49ad05talleystatic int set_name_in_DatasetBean(JNIEnv *, char *, DatasetBean_t *);
fa9e4066f08beec538e775443c5be79dd423fcabahrensstatic int populate_DatasetBean(JNIEnv *, zfs_handle_t *, DatasetBean_t *);
32f884e0ef76c8ab2a6e26895696620c8d49ad05talleystatic int populate_PoolBean(
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley JNIEnv *, zpool_handle_t *, zfs_handle_t *, PoolBean_t *);
fa9e4066f08beec538e775443c5be79dd423fcabahrensstatic int populate_FileSystemBean(
fa9e4066f08beec538e775443c5be79dd423fcabahrens JNIEnv *, zfs_handle_t *, FileSystemBean_t *);
fa9e4066f08beec538e775443c5be79dd423fcabahrensstatic int populate_VolumeBean(
fa9e4066f08beec538e775443c5be79dd423fcabahrens JNIEnv *, zfs_handle_t *, VolumeBean_t *);
fa9e4066f08beec538e775443c5be79dd423fcabahrensstatic int populate_SnapshotBean(JNIEnv *, zfs_handle_t *, SnapshotBean_t *);
fa9e4066f08beec538e775443c5be79dd423fcabahrensstatic int populate_FileSystemSnapshotBean(
fa9e4066f08beec538e775443c5be79dd423fcabahrens JNIEnv *, zfs_handle_t *, FileSystemSnapshotBean_t *);
fa9e4066f08beec538e775443c5be79dd423fcabahrensstatic int populate_VolumeSnapshotBean(
fa9e4066f08beec538e775443c5be79dd423fcabahrens JNIEnv *, zfs_handle_t *, VolumeSnapshotBean_t *);
32f884e0ef76c8ab2a6e26895696620c8d49ad05talleystatic jobject create_PoolBean(JNIEnv *, zpool_handle_t *, zfs_handle_t *);
fa9e4066f08beec538e775443c5be79dd423fcabahrensstatic jobject create_FileSystemBean(JNIEnv *, zfs_handle_t *);
fa9e4066f08beec538e775443c5be79dd423fcabahrensstatic jobject create_VolumeBean(JNIEnv *, zfs_handle_t *);
fa9e4066f08beec538e775443c5be79dd423fcabahrensstatic jobject create_FileSystemSnapshotBean(JNIEnv *, zfs_handle_t *);
fa9e4066f08beec538e775443c5be79dd423fcabahrensstatic jobject create_VolumeSnapshotBean(JNIEnv *, zfs_handle_t *);
fa9e4066f08beec538e775443c5be79dd423fcabahrensstatic jobject create_DatasetBean(JNIEnv *, zfs_handle_t *);
fa9e4066f08beec538e775443c5be79dd423fcabahrensstatic int is_fs_snapshot(zfs_handle_t *);
32f884e0ef76c8ab2a6e26895696620c8d49ad05talleystatic int is_pool_name(const char *);
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens/*
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Static functions
fa9e4066f08beec538e775443c5be79dd423fcabahrens */
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens/* Create a DatasetBean */
fa9e4066f08beec538e775443c5be79dd423fcabahrensstatic void
fa9e4066f08beec538e775443c5be79dd423fcabahrensnew_DatasetBean(JNIEnv *env, DatasetBean_t *bean)
fa9e4066f08beec538e775443c5be79dd423fcabahrens{
fa9e4066f08beec538e775443c5be79dd423fcabahrens zjni_Object_t *object = (zjni_Object_t *)bean;
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (object->object == NULL) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens object->class =
fa9e4066f08beec538e775443c5be79dd423fcabahrens (*env)->FindClass(env, ZFSJNI_PACKAGE_DATA "DatasetBean");
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens object->constructor =
fa9e4066f08beec538e775443c5be79dd423fcabahrens (*env)->GetMethodID(env, object->class, "<init>", "()V");
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens object->object =
fa9e4066f08beec538e775443c5be79dd423fcabahrens (*env)->NewObject(env, object->class, object->constructor);
fa9e4066f08beec538e775443c5be79dd423fcabahrens }
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens bean->method_setPoolName = (*env)->GetMethodID(
fa9e4066f08beec538e775443c5be79dd423fcabahrens env, object->class, "setPoolName", "(Ljava/lang/String;)V");
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens bean->method_setParentName = (*env)->GetMethodID(
fa9e4066f08beec538e775443c5be79dd423fcabahrens env, object->class, "setParentName", "(Ljava/lang/String;)V");
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens bean->method_setBaseName = (*env)->GetMethodID(
fa9e4066f08beec538e775443c5be79dd423fcabahrens env, object->class, "setBaseName", "(Ljava/lang/String;)V");
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens bean->method_setProperties = (*env)->GetMethodID(
fa9e4066f08beec538e775443c5be79dd423fcabahrens env, object->class, "setProperties",
fa9e4066f08beec538e775443c5be79dd423fcabahrens "([L" ZFSJNI_PACKAGE_DATA "Property;)V");
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens bean->method_addProperty = (*env)->GetMethodID(
fa9e4066f08beec538e775443c5be79dd423fcabahrens env, object->class, "addProperty",
fa9e4066f08beec538e775443c5be79dd423fcabahrens "(L" ZFSJNI_PACKAGE_DATA "Property;)V");
fa9e4066f08beec538e775443c5be79dd423fcabahrens}
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens/* Create a PoolBean */
fa9e4066f08beec538e775443c5be79dd423fcabahrensstatic void
fa9e4066f08beec538e775443c5be79dd423fcabahrensnew_PoolBean(JNIEnv *env, PoolBean_t *bean)
fa9e4066f08beec538e775443c5be79dd423fcabahrens{
fa9e4066f08beec538e775443c5be79dd423fcabahrens zjni_Object_t *object = (zjni_Object_t *)bean;
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (object->object == NULL) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens object->class =
fa9e4066f08beec538e775443c5be79dd423fcabahrens (*env)->FindClass(env, ZFSJNI_PACKAGE_DATA "PoolBean");
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens object->constructor =
fa9e4066f08beec538e775443c5be79dd423fcabahrens (*env)->GetMethodID(env, object->class, "<init>", "()V");
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens object->object =
fa9e4066f08beec538e775443c5be79dd423fcabahrens (*env)->NewObject(env, object->class, object->constructor);
fa9e4066f08beec538e775443c5be79dd423fcabahrens }
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens new_FileSystemBean(env, (FileSystemBean_t *)bean);
fbfd10ff571cfd0139aa5127460f1b8a53dac971talley new_PoolStats(env, &(bean->interface_PoolStats), object);
fa9e4066f08beec538e775443c5be79dd423fcabahrens}
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens/* Create a FileSystemBean */
fa9e4066f08beec538e775443c5be79dd423fcabahrensstatic void
fa9e4066f08beec538e775443c5be79dd423fcabahrensnew_FileSystemBean(JNIEnv *env, FileSystemBean_t *bean)
fa9e4066f08beec538e775443c5be79dd423fcabahrens{
fa9e4066f08beec538e775443c5be79dd423fcabahrens zjni_Object_t *object = (zjni_Object_t *)bean;
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (object->object == NULL) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens object->class =
fa9e4066f08beec538e775443c5be79dd423fcabahrens (*env)->FindClass(env,
990b4856d0eaada6f8140335733a1b1771ed2746lling ZFSJNI_PACKAGE_DATA "FileSystemBean");
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens object->constructor =
fa9e4066f08beec538e775443c5be79dd423fcabahrens (*env)->GetMethodID(env, object->class, "<init>", "()V");
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens object->object =
fa9e4066f08beec538e775443c5be79dd423fcabahrens (*env)->NewObject(env, object->class, object->constructor);
fa9e4066f08beec538e775443c5be79dd423fcabahrens }
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens new_DatasetBean(env, (DatasetBean_t *)bean);
fa9e4066f08beec538e775443c5be79dd423fcabahrens}
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens/* Create a VolumeBean */
fa9e4066f08beec538e775443c5be79dd423fcabahrensstatic void
fa9e4066f08beec538e775443c5be79dd423fcabahrensnew_VolumeBean(JNIEnv *env, VolumeBean_t *bean)
fa9e4066f08beec538e775443c5be79dd423fcabahrens{
fa9e4066f08beec538e775443c5be79dd423fcabahrens zjni_Object_t *object = (zjni_Object_t *)bean;
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (object->object == NULL) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens object->class =
fa9e4066f08beec538e775443c5be79dd423fcabahrens (*env)->FindClass(env,
990b4856d0eaada6f8140335733a1b1771ed2746lling ZFSJNI_PACKAGE_DATA "VolumeBean");
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens object->constructor =
fa9e4066f08beec538e775443c5be79dd423fcabahrens (*env)->GetMethodID(env, object->class, "<init>", "()V");
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens object->object =
fa9e4066f08beec538e775443c5be79dd423fcabahrens (*env)->NewObject(env, object->class, object->constructor);
fa9e4066f08beec538e775443c5be79dd423fcabahrens }
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens new_DatasetBean(env, (DatasetBean_t *)bean);
fa9e4066f08beec538e775443c5be79dd423fcabahrens}
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens/* Create a SnapshotBean */
fa9e4066f08beec538e775443c5be79dd423fcabahrensstatic void
fa9e4066f08beec538e775443c5be79dd423fcabahrensnew_SnapshotBean(JNIEnv *env, SnapshotBean_t *bean)
fa9e4066f08beec538e775443c5be79dd423fcabahrens{
fa9e4066f08beec538e775443c5be79dd423fcabahrens zjni_Object_t *object = (zjni_Object_t *)bean;
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (object->object == NULL) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens object->class =
fa9e4066f08beec538e775443c5be79dd423fcabahrens (*env)->FindClass(env,
990b4856d0eaada6f8140335733a1b1771ed2746lling ZFSJNI_PACKAGE_DATA "SnapshotBean");
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens object->constructor =
fa9e4066f08beec538e775443c5be79dd423fcabahrens (*env)->GetMethodID(env, object->class, "<init>", "()V");
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens object->object =
fa9e4066f08beec538e775443c5be79dd423fcabahrens (*env)->NewObject(env, object->class, object->constructor);
fa9e4066f08beec538e775443c5be79dd423fcabahrens }
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens new_DatasetBean(env, (DatasetBean_t *)bean);
fa9e4066f08beec538e775443c5be79dd423fcabahrens}
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens/* Create a FileSystemSnapshotBean */
fa9e4066f08beec538e775443c5be79dd423fcabahrensstatic void
fa9e4066f08beec538e775443c5be79dd423fcabahrensnew_FileSystemSnapshotBean(JNIEnv *env, FileSystemSnapshotBean_t *bean)
fa9e4066f08beec538e775443c5be79dd423fcabahrens{
fa9e4066f08beec538e775443c5be79dd423fcabahrens zjni_Object_t *object = (zjni_Object_t *)bean;
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (object->object == NULL) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens object->class =
fa9e4066f08beec538e775443c5be79dd423fcabahrens (*env)->FindClass(env,
990b4856d0eaada6f8140335733a1b1771ed2746lling ZFSJNI_PACKAGE_DATA "FileSystemSnapshotBean");
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens object->constructor =
fa9e4066f08beec538e775443c5be79dd423fcabahrens (*env)->GetMethodID(env, object->class, "<init>", "()V");
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens object->object =
fa9e4066f08beec538e775443c5be79dd423fcabahrens (*env)->NewObject(env, object->class, object->constructor);
fa9e4066f08beec538e775443c5be79dd423fcabahrens }
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens new_SnapshotBean(env, (SnapshotBean_t *)bean);
fa9e4066f08beec538e775443c5be79dd423fcabahrens}
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens/* Create a VolumeSnapshotBean */
fa9e4066f08beec538e775443c5be79dd423fcabahrensstatic void
fa9e4066f08beec538e775443c5be79dd423fcabahrensnew_VolumeSnapshotBean(JNIEnv *env, VolumeSnapshotBean_t *bean)
fa9e4066f08beec538e775443c5be79dd423fcabahrens{
fa9e4066f08beec538e775443c5be79dd423fcabahrens zjni_Object_t *object = (zjni_Object_t *)bean;
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (object->object == NULL) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens object->class =
fa9e4066f08beec538e775443c5be79dd423fcabahrens (*env)->FindClass(env,
990b4856d0eaada6f8140335733a1b1771ed2746lling ZFSJNI_PACKAGE_DATA "VolumeSnapshotBean");
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens object->constructor =
fa9e4066f08beec538e775443c5be79dd423fcabahrens (*env)->GetMethodID(env, object->class, "<init>", "()V");
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens object->object =
fa9e4066f08beec538e775443c5be79dd423fcabahrens (*env)->NewObject(env, object->class, object->constructor);
fa9e4066f08beec538e775443c5be79dd423fcabahrens }
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens new_SnapshotBean(env, (SnapshotBean_t *)bean);
fa9e4066f08beec538e775443c5be79dd423fcabahrens}
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrensstatic int
32f884e0ef76c8ab2a6e26895696620c8d49ad05talleyset_name_in_DatasetBean(JNIEnv *env, char *name, DatasetBean_t *bean)
fa9e4066f08beec538e775443c5be79dd423fcabahrens{
fa9e4066f08beec538e775443c5be79dd423fcabahrens jstring poolUTF;
fa9e4066f08beec538e775443c5be79dd423fcabahrens jstring parentUTF;
fa9e4066f08beec538e775443c5be79dd423fcabahrens jstring baseUTF;
fa9e4066f08beec538e775443c5be79dd423fcabahrens zjni_Object_t *object = (zjni_Object_t *)bean;
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens /*
fa9e4066f08beec538e775443c5be79dd423fcabahrens * zhp->zfs_name has the format
fa9e4066f08beec538e775443c5be79dd423fcabahrens * <pool>[[/<container...>]/<dataset>[@<snapshot>]]
fa9e4066f08beec538e775443c5be79dd423fcabahrens */
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens regex_t re;
fa9e4066f08beec538e775443c5be79dd423fcabahrens regmatch_t matches[REGEX_ZFS_NAME_NGROUPS];
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (regcomp(&re, REGEX_ZFS_NAME, REG_EXTENDED) != 0 ||
fa9e4066f08beec538e775443c5be79dd423fcabahrens regexec(&re, name, REGEX_ZFS_NAME_NGROUPS, matches, 0) != 0) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens regfree(&re);
fa9e4066f08beec538e775443c5be79dd423fcabahrens zjni_throw_exception(env, "invalid name: %s", name);
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (-1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens }
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens regfree(&re);
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* Set names */
fa9e4066f08beec538e775443c5be79dd423fcabahrens poolUTF = zjni_get_matched_string(
fa9e4066f08beec538e775443c5be79dd423fcabahrens env, name, matches + REGEX_ZFS_NAME_POOL_GROUP);
fa9e4066f08beec538e775443c5be79dd423fcabahrens parentUTF = zjni_get_matched_string(
fa9e4066f08beec538e775443c5be79dd423fcabahrens env, name, matches + REGEX_ZFS_NAME_PARENT_GROUP);
fa9e4066f08beec538e775443c5be79dd423fcabahrens baseUTF = zjni_get_matched_string(
fa9e4066f08beec538e775443c5be79dd423fcabahrens env, name, matches + REGEX_ZFS_NAME_BASE_GROUP);
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (poolUTF == NULL) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens poolUTF = baseUTF;
fa9e4066f08beec538e775443c5be79dd423fcabahrens }
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens (*env)->CallVoidMethod(
fa9e4066f08beec538e775443c5be79dd423fcabahrens env, object->object, bean->method_setPoolName, poolUTF);
fa9e4066f08beec538e775443c5be79dd423fcabahrens (*env)->CallVoidMethod(
fa9e4066f08beec538e775443c5be79dd423fcabahrens env, object->object, bean->method_setBaseName, baseUTF);
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (parentUTF != NULL) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens (*env)->CallVoidMethod(
fa9e4066f08beec538e775443c5be79dd423fcabahrens env, object->object, bean->method_setParentName, parentUTF);
fa9e4066f08beec538e775443c5be79dd423fcabahrens }
fa9e4066f08beec538e775443c5be79dd423fcabahrens
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley return (0);
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley}
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley
32f884e0ef76c8ab2a6e26895696620c8d49ad05talleystatic int
32f884e0ef76c8ab2a6e26895696620c8d49ad05talleypopulate_DatasetBean(JNIEnv *env, zfs_handle_t *zhp, DatasetBean_t *bean)
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley{
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley jobjectArray properties;
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley zjni_Object_t *object = (zjni_Object_t *)bean;
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley int result = set_name_in_DatasetBean(
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley env, (char *)zfs_get_name(zhp), bean);
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley if (result != 0) {
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley /* Must not call any more Java methods to preserve exception */
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley return (-1);
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley }
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley
fa9e4066f08beec538e775443c5be79dd423fcabahrens properties = zjni_get_Dataset_properties(env, zhp);
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (properties == NULL) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* Must not call any more Java methods to preserve exception */
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (-1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens }
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens (*env)->CallVoidMethod(
fa9e4066f08beec538e775443c5be79dd423fcabahrens env, object->object, bean->method_setProperties, properties);
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
fa9e4066f08beec538e775443c5be79dd423fcabahrens}
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrensstatic int
32f884e0ef76c8ab2a6e26895696620c8d49ad05talleypopulate_PoolBean(JNIEnv *env, zpool_handle_t *zphp, zfs_handle_t *zhp,
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley PoolBean_t *bean)
fa9e4066f08beec538e775443c5be79dd423fcabahrens{
fbfd10ff571cfd0139aa5127460f1b8a53dac971talley int result = 0;
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley zjni_Object_t *object = (zjni_Object_t *)bean;
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley PoolStatsBean_t *pool_stats = &(bean->interface_PoolStats);
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley DeviceStatsBean_t *dev_stats = (DeviceStatsBean_t *)pool_stats;
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley nvlist_t *devices = zjni_get_root_vdev(zphp);
3349c8dc868dbab8bd2e9355b835f83837de8900talley
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley if (devices == NULL ||
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley populate_DeviceStatsBean(env, devices, dev_stats, object)) {
fbfd10ff571cfd0139aa5127460f1b8a53dac971talley result = -1;
fbfd10ff571cfd0139aa5127460f1b8a53dac971talley } else {
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley char *msgid;
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley /* Override value set in populate_DeviceStatsBean */
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley (*env)->CallVoidMethod(env, object->object,
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley dev_stats->method_setSize,
990b4856d0eaada6f8140335733a1b1771ed2746lling zpool_get_prop_int(zphp, ZPOOL_PROP_SIZE, NULL));
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley (*env)->CallVoidMethod(env, object->object,
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley pool_stats->method_setPoolState,
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley zjni_pool_state_to_obj(
990b4856d0eaada6f8140335733a1b1771ed2746lling env, zpool_get_state(zphp)));
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley (*env)->CallVoidMethod(env, object->object,
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley pool_stats->method_setPoolStatus,
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley zjni_pool_status_to_obj(env,
990b4856d0eaada6f8140335733a1b1771ed2746lling zpool_get_status(zphp, &msgid)));
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley
a55b6846f87afedf14b3f9b64fbb8c0d0a3f2fe2cristian (*env)->CallVoidMethod(env, object->object,
a55b6846f87afedf14b3f9b64fbb8c0d0a3f2fe2cristian pool_stats->method_setPoolVersion,
a55b6846f87afedf14b3f9b64fbb8c0d0a3f2fe2cristian zpool_get_prop_int(zphp, ZPOOL_PROP_VERSION, NULL));
a55b6846f87afedf14b3f9b64fbb8c0d0a3f2fe2cristian
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley /*
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley * If a root file system does not exist for this pool, the pool
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley * is likely faulted, so just set its name in the Java object.
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley * Otherwise, populate all fields of the Java object.
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley */
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley if (zhp == NULL) {
990b4856d0eaada6f8140335733a1b1771ed2746lling result = set_name_in_DatasetBean(env,
990b4856d0eaada6f8140335733a1b1771ed2746lling (char *)zpool_get_name(zphp),
990b4856d0eaada6f8140335733a1b1771ed2746lling (DatasetBean_t *)bean);
fbfd10ff571cfd0139aa5127460f1b8a53dac971talley } else {
990b4856d0eaada6f8140335733a1b1771ed2746lling result = populate_FileSystemBean(
990b4856d0eaada6f8140335733a1b1771ed2746lling env, zhp, (FileSystemBean_t *)bean);
fbfd10ff571cfd0139aa5127460f1b8a53dac971talley }
fbfd10ff571cfd0139aa5127460f1b8a53dac971talley }
3349c8dc868dbab8bd2e9355b835f83837de8900talley
fbfd10ff571cfd0139aa5127460f1b8a53dac971talley return (result != 0);
fa9e4066f08beec538e775443c5be79dd423fcabahrens}
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrensstatic int
fa9e4066f08beec538e775443c5be79dd423fcabahrenspopulate_FileSystemBean(JNIEnv *env, zfs_handle_t *zhp, FileSystemBean_t *bean)
fa9e4066f08beec538e775443c5be79dd423fcabahrens{
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (populate_DatasetBean(env, zhp, (DatasetBean_t *)bean));
fa9e4066f08beec538e775443c5be79dd423fcabahrens}
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrensstatic int
fa9e4066f08beec538e775443c5be79dd423fcabahrenspopulate_VolumeBean(JNIEnv *env, zfs_handle_t *zhp, VolumeBean_t *bean)
fa9e4066f08beec538e775443c5be79dd423fcabahrens{
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (populate_DatasetBean(env, zhp, (DatasetBean_t *)bean));
fa9e4066f08beec538e775443c5be79dd423fcabahrens}
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrensstatic int
fa9e4066f08beec538e775443c5be79dd423fcabahrenspopulate_SnapshotBean(JNIEnv *env, zfs_handle_t *zhp, SnapshotBean_t *bean)
fa9e4066f08beec538e775443c5be79dd423fcabahrens{
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (populate_DatasetBean(env, zhp, (DatasetBean_t *)bean));
fa9e4066f08beec538e775443c5be79dd423fcabahrens}
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrensstatic int
fa9e4066f08beec538e775443c5be79dd423fcabahrenspopulate_FileSystemSnapshotBean(JNIEnv *env, zfs_handle_t *zhp,
fa9e4066f08beec538e775443c5be79dd423fcabahrens FileSystemSnapshotBean_t *bean)
fa9e4066f08beec538e775443c5be79dd423fcabahrens{
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (populate_SnapshotBean(env, zhp, (SnapshotBean_t *)bean));
fa9e4066f08beec538e775443c5be79dd423fcabahrens}
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrensstatic int
fa9e4066f08beec538e775443c5be79dd423fcabahrenspopulate_VolumeSnapshotBean(JNIEnv *env, zfs_handle_t *zhp,
fa9e4066f08beec538e775443c5be79dd423fcabahrens VolumeSnapshotBean_t *bean)
fa9e4066f08beec538e775443c5be79dd423fcabahrens{
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (populate_SnapshotBean(env, zhp, (SnapshotBean_t *)bean));
fa9e4066f08beec538e775443c5be79dd423fcabahrens}
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrensstatic jobject
32f884e0ef76c8ab2a6e26895696620c8d49ad05talleycreate_PoolBean(JNIEnv *env, zpool_handle_t *zphp, zfs_handle_t *zhp)
fa9e4066f08beec538e775443c5be79dd423fcabahrens{
fa9e4066f08beec538e775443c5be79dd423fcabahrens int result;
fa9e4066f08beec538e775443c5be79dd423fcabahrens PoolBean_t bean_obj = {0};
fa9e4066f08beec538e775443c5be79dd423fcabahrens PoolBean_t *bean = &bean_obj;
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* Construct PoolBean */
fa9e4066f08beec538e775443c5be79dd423fcabahrens new_PoolBean(env, bean);
fa9e4066f08beec538e775443c5be79dd423fcabahrens
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley result = populate_PoolBean(env, zphp, zhp, bean);
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (result) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* Must not call any more Java methods to preserve exception */
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (NULL);
fa9e4066f08beec538e775443c5be79dd423fcabahrens }
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (((zjni_Object_t *)bean)->object);
fa9e4066f08beec538e775443c5be79dd423fcabahrens}
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrensstatic jobject
fa9e4066f08beec538e775443c5be79dd423fcabahrenscreate_FileSystemBean(JNIEnv *env, zfs_handle_t *zhp)
fa9e4066f08beec538e775443c5be79dd423fcabahrens{
fa9e4066f08beec538e775443c5be79dd423fcabahrens int result;
fa9e4066f08beec538e775443c5be79dd423fcabahrens FileSystemBean_t bean_obj = {0};
fa9e4066f08beec538e775443c5be79dd423fcabahrens FileSystemBean_t *bean = &bean_obj;
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* Construct FileSystemBean */
fa9e4066f08beec538e775443c5be79dd423fcabahrens new_FileSystemBean(env, bean);
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens result = populate_FileSystemBean(env, zhp, bean);
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (result) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* Must not call any more Java methods to preserve exception */
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (NULL);
fa9e4066f08beec538e775443c5be79dd423fcabahrens }
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (((zjni_Object_t *)bean)->object);
fa9e4066f08beec538e775443c5be79dd423fcabahrens}
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrensstatic jobject
fa9e4066f08beec538e775443c5be79dd423fcabahrenscreate_VolumeBean(JNIEnv *env, zfs_handle_t *zhp)
fa9e4066f08beec538e775443c5be79dd423fcabahrens{
fa9e4066f08beec538e775443c5be79dd423fcabahrens int result;
fa9e4066f08beec538e775443c5be79dd423fcabahrens VolumeBean_t bean_obj = {0};
fa9e4066f08beec538e775443c5be79dd423fcabahrens VolumeBean_t *bean = &bean_obj;
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* Construct VolumeBean */
fa9e4066f08beec538e775443c5be79dd423fcabahrens new_VolumeBean(env, bean);
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens result = populate_VolumeBean(env, zhp, bean);
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (result) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* Must not call any more Java methods to preserve exception */
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (NULL);
fa9e4066f08beec538e775443c5be79dd423fcabahrens }
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (((zjni_Object_t *)bean)->object);
fa9e4066f08beec538e775443c5be79dd423fcabahrens}
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrensstatic jobject
fa9e4066f08beec538e775443c5be79dd423fcabahrenscreate_FileSystemSnapshotBean(JNIEnv *env, zfs_handle_t *zhp)
fa9e4066f08beec538e775443c5be79dd423fcabahrens{
fa9e4066f08beec538e775443c5be79dd423fcabahrens int result;
fa9e4066f08beec538e775443c5be79dd423fcabahrens FileSystemSnapshotBean_t bean_obj = {0};
fa9e4066f08beec538e775443c5be79dd423fcabahrens FileSystemSnapshotBean_t *bean = &bean_obj;
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* Construct FileSystemSnapshotBean */
fa9e4066f08beec538e775443c5be79dd423fcabahrens new_FileSystemSnapshotBean(env, bean);
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens result = populate_FileSystemSnapshotBean(env, zhp, bean);
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (result) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* Must not call any more Java methods to preserve exception */
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (NULL);
fa9e4066f08beec538e775443c5be79dd423fcabahrens }
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (((zjni_Object_t *)bean)->object);
fa9e4066f08beec538e775443c5be79dd423fcabahrens}
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrensstatic jobject
fa9e4066f08beec538e775443c5be79dd423fcabahrenscreate_VolumeSnapshotBean(JNIEnv *env, zfs_handle_t *zhp)
fa9e4066f08beec538e775443c5be79dd423fcabahrens{
fa9e4066f08beec538e775443c5be79dd423fcabahrens int result;
fa9e4066f08beec538e775443c5be79dd423fcabahrens VolumeSnapshotBean_t bean_obj = {0};
fa9e4066f08beec538e775443c5be79dd423fcabahrens VolumeSnapshotBean_t *bean = &bean_obj;
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* Construct VolumeSnapshotBean */
fa9e4066f08beec538e775443c5be79dd423fcabahrens new_VolumeSnapshotBean(env, bean);
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens result = populate_VolumeSnapshotBean(env, zhp, bean);
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (result) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* Must not call any more Java methods to preserve exception */
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (NULL);
fa9e4066f08beec538e775443c5be79dd423fcabahrens }
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (((zjni_Object_t *)bean)->object);
fa9e4066f08beec538e775443c5be79dd423fcabahrens}
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrensstatic jobject
fa9e4066f08beec538e775443c5be79dd423fcabahrenscreate_DatasetBean(JNIEnv *env, zfs_handle_t *zhp)
fa9e4066f08beec538e775443c5be79dd423fcabahrens{
fa9e4066f08beec538e775443c5be79dd423fcabahrens jobject object = NULL;
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens switch (zfs_get_type(zhp)) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens case ZFS_TYPE_FILESYSTEM:
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley object = create_FileSystemBean(env, zhp);
fa9e4066f08beec538e775443c5be79dd423fcabahrens break;
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens case ZFS_TYPE_VOLUME:
fa9e4066f08beec538e775443c5be79dd423fcabahrens object = create_VolumeBean(env, zhp);
fa9e4066f08beec538e775443c5be79dd423fcabahrens break;
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens case ZFS_TYPE_SNAPSHOT:
fa9e4066f08beec538e775443c5be79dd423fcabahrens object = is_fs_snapshot(zhp) ?
fa9e4066f08beec538e775443c5be79dd423fcabahrens create_FileSystemSnapshotBean(env, zhp) :
fa9e4066f08beec538e775443c5be79dd423fcabahrens create_VolumeSnapshotBean(env, zhp);
fa9e4066f08beec538e775443c5be79dd423fcabahrens break;
fa9e4066f08beec538e775443c5be79dd423fcabahrens }
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (object);
fa9e4066f08beec538e775443c5be79dd423fcabahrens}
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens/*
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Determines whether the given snapshot is a snapshot of a file
fa9e4066f08beec538e775443c5be79dd423fcabahrens * system or of a volume.
fa9e4066f08beec538e775443c5be79dd423fcabahrens *
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Returns:
fa9e4066f08beec538e775443c5be79dd423fcabahrens *
fa9e4066f08beec538e775443c5be79dd423fcabahrens * 0 if it is a volume snapshot
fa9e4066f08beec538e775443c5be79dd423fcabahrens * 1 if it is a file system snapshot
fa9e4066f08beec538e775443c5be79dd423fcabahrens * -1 on error
fa9e4066f08beec538e775443c5be79dd423fcabahrens */
fa9e4066f08beec538e775443c5be79dd423fcabahrensstatic int
fa9e4066f08beec538e775443c5be79dd423fcabahrensis_fs_snapshot(zfs_handle_t *zhp)
fa9e4066f08beec538e775443c5be79dd423fcabahrens{
9adfa60d484ce2435f5af77cc99dcd4e692b6660Matthew Ahrens char parent[ZFS_MAX_DATASET_NAME_LEN];
fa9e4066f08beec538e775443c5be79dd423fcabahrens zfs_handle_t *parent_zhp;
fa9e4066f08beec538e775443c5be79dd423fcabahrens int isfs;
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (zfs_get_type(zhp) != ZFS_TYPE_SNAPSHOT) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (-1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens }
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens zjni_get_dataset_from_snapshot(
fa9e4066f08beec538e775443c5be79dd423fcabahrens zfs_get_name(zhp), parent, sizeof (parent));
fa9e4066f08beec538e775443c5be79dd423fcabahrens
990b4856d0eaada6f8140335733a1b1771ed2746lling parent_zhp = zfs_open(g_zfs, parent, ZFS_TYPE_DATASET);
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (parent_zhp == NULL) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (-1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens }
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens isfs = zfs_get_type(parent_zhp) == ZFS_TYPE_FILESYSTEM;
fa9e4066f08beec538e775443c5be79dd423fcabahrens zfs_close(parent_zhp);
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (isfs);
fa9e4066f08beec538e775443c5be79dd423fcabahrens}
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrensstatic int
32f884e0ef76c8ab2a6e26895696620c8d49ad05talleyis_pool_name(const char *name)
fa9e4066f08beec538e775443c5be79dd423fcabahrens{
389056bd4327caca73482e60b80da00f4eaf3de9tomee return (strchr(name, '/') == NULL && strchr(name, '@') == NULL);
fa9e4066f08beec538e775443c5be79dd423fcabahrens}
fa9e4066f08beec538e775443c5be79dd423fcabahrens
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley/*
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley * Package-private functions
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley */
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley/*
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley * Callback function for zpool_iter(). Creates a Pool and adds it to
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley * the given zjni_ArrayList.
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley */
32f884e0ef76c8ab2a6e26895696620c8d49ad05talleyint
32f884e0ef76c8ab2a6e26895696620c8d49ad05talleyzjni_create_add_Pool(zpool_handle_t *zphp, void *data)
fa9e4066f08beec538e775443c5be79dd423fcabahrens{
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley JNIEnv *env = ((zjni_ArrayCallbackData_t *)data)->env;
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley zjni_Collection_t *list = ((zjni_ArrayCallbackData_t *)data)->list;
fa9e4066f08beec538e775443c5be79dd423fcabahrens
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley /* Get root fs for this pool -- may be NULL if pool is faulted */
99653d4ee642c6528e88224f12409a5f23060994eschrock zfs_handle_t *zhp = zfs_open(g_zfs, zpool_get_name(zphp),
99653d4ee642c6528e88224f12409a5f23060994eschrock ZFS_TYPE_FILESYSTEM);
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley jobject bean = create_PoolBean(env, zphp, zhp);
fa9e4066f08beec538e775443c5be79dd423fcabahrens
990b4856d0eaada6f8140335733a1b1771ed2746lling if (zhp != NULL)
990b4856d0eaada6f8140335733a1b1771ed2746lling zfs_close(zhp);
fa9e4066f08beec538e775443c5be79dd423fcabahrens
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley zpool_close(zphp);
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley if (bean == NULL) {
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley /* Must not call any more Java methods to preserve exception */
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley return (-1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens }
fa9e4066f08beec538e775443c5be79dd423fcabahrens
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley /* Add pool to zjni_ArrayList */
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley (*env)->CallBooleanMethod(env, ((zjni_Object_t *)list)->object,
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley ((zjni_Collection_t *)list)->method_add, bean);
fa9e4066f08beec538e775443c5be79dd423fcabahrens
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley return (0);
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley}
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens/*
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Callback function for zfs_iter_children(). Creates the appropriate
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Dataset and adds it to the given zjni_ArrayList. Per the contract
fa9e4066f08beec538e775443c5be79dd423fcabahrens * with zfs_iter_children(), calls zfs_close() on the given
fa9e4066f08beec538e775443c5be79dd423fcabahrens * zfs_handle_t.
fa9e4066f08beec538e775443c5be79dd423fcabahrens */
fa9e4066f08beec538e775443c5be79dd423fcabahrensint
fa9e4066f08beec538e775443c5be79dd423fcabahrenszjni_create_add_Dataset(zfs_handle_t *zhp, void *data)
fa9e4066f08beec538e775443c5be79dd423fcabahrens{
fa9e4066f08beec538e775443c5be79dd423fcabahrens JNIEnv *env = ((zjni_ArrayCallbackData_t *)data)->env;
fa9e4066f08beec538e775443c5be79dd423fcabahrens zjni_Collection_t *list = ((zjni_ArrayCallbackData_t *)data)->list;
fa9e4066f08beec538e775443c5be79dd423fcabahrens zfs_type_t typemask =
fa9e4066f08beec538e775443c5be79dd423fcabahrens ((zjni_DatasetArrayCallbackData_t *)data)->typemask;
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* Only add allowed types */
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (zfs_get_type(zhp) & typemask) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens jobject bean = create_DatasetBean(env, zhp);
fa9e4066f08beec538e775443c5be79dd423fcabahrens zfs_close(zhp);
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (bean == NULL) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens /*
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Must not call any more Java methods to preserve
fa9e4066f08beec538e775443c5be79dd423fcabahrens * exception
fa9e4066f08beec538e775443c5be79dd423fcabahrens */
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (-1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens }
fa9e4066f08beec538e775443c5be79dd423fcabahrens
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley /* Add Dataset to zjni_ArrayList */
fa9e4066f08beec538e775443c5be79dd423fcabahrens (*env)->CallBooleanMethod(env, ((zjni_Object_t *)list)->object,
fa9e4066f08beec538e775443c5be79dd423fcabahrens ((zjni_Collection_t *)list)->method_add, bean);
3ccfa83cd9cddd1e34808ba18082c156758c5ec8ahrens } else {
3ccfa83cd9cddd1e34808ba18082c156758c5ec8ahrens zfs_close(zhp);
fa9e4066f08beec538e775443c5be79dd423fcabahrens }
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
fa9e4066f08beec538e775443c5be79dd423fcabahrens}
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrensjobjectArray
fa9e4066f08beec538e775443c5be79dd423fcabahrenszjni_get_Datasets_below(JNIEnv *env, jstring parentUTF,
fa9e4066f08beec538e775443c5be79dd423fcabahrens zfs_type_t parent_typemask, zfs_type_t child_typemask, char *arrayClass)
fa9e4066f08beec538e775443c5be79dd423fcabahrens{
fa9e4066f08beec538e775443c5be79dd423fcabahrens jobjectArray array = NULL;
fa9e4066f08beec538e775443c5be79dd423fcabahrens
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley if (parentUTF != NULL) {
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley zfs_handle_t *zhp;
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley int error = 1;
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley const char *name =
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley (*env)->GetStringUTFChars(env, parentUTF, NULL);
fa9e4066f08beec538e775443c5be79dd423fcabahrens
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley /* Create an array list to hold the children */
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley zjni_DatasetSet_t list_obj = {0};
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley zjni_DatasetSet_t *list = &list_obj;
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley zjni_new_DatasetSet(env, list);
fa9e4066f08beec538e775443c5be79dd423fcabahrens
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley /* Retrieve parent dataset */
99653d4ee642c6528e88224f12409a5f23060994eschrock zhp = zfs_open(g_zfs, name, parent_typemask);
fa9e4066f08beec538e775443c5be79dd423fcabahrens
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley if (zhp != NULL) {
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley zjni_DatasetArrayCallbackData_t data = {0};
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley data.data.env = env;
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley data.data.list = (zjni_Collection_t *)list;
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley data.typemask = child_typemask;
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley (void) zfs_iter_children(zhp, zjni_create_add_Dataset,
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley &data);
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley zfs_close(zhp);
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley if ((*env)->ExceptionOccurred(env) == NULL) {
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley error = 0;
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley }
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley } else
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley /* Parent is not a dataset -- see if it's a faulted pool */
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley if ((parent_typemask & ZFS_TYPE_FILESYSTEM) &&
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley is_pool_name(name)) {
99653d4ee642c6528e88224f12409a5f23060994eschrock zpool_handle_t *zphp = zpool_open_canfail(g_zfs, name);
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley if (zphp != NULL) {
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley /* A faulted pool has no datasets */
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley error = 0;
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley zpool_close(zphp);
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley }
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley }
fa9e4066f08beec538e775443c5be79dd423fcabahrens
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley (*env)->ReleaseStringUTFChars(env, parentUTF, name);
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley if (!error) {
fbfd10ff571cfd0139aa5127460f1b8a53dac971talley array = zjni_Collection_to_array(
fbfd10ff571cfd0139aa5127460f1b8a53dac971talley env, (zjni_Collection_t *)list, arrayClass);
fbfd10ff571cfd0139aa5127460f1b8a53dac971talley }
fa9e4066f08beec538e775443c5be79dd423fcabahrens }
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (array);
fa9e4066f08beec538e775443c5be79dd423fcabahrens}
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrensjobjectArray
fa9e4066f08beec538e775443c5be79dd423fcabahrenszjni_get_Datasets_dependents(JNIEnv *env, jobjectArray paths)
fa9e4066f08beec538e775443c5be79dd423fcabahrens{
fa9e4066f08beec538e775443c5be79dd423fcabahrens jint i;
fa9e4066f08beec538e775443c5be79dd423fcabahrens jint npaths;
fa9e4066f08beec538e775443c5be79dd423fcabahrens zjni_DatasetArrayCallbackData_t data = {0};
fa9e4066f08beec538e775443c5be79dd423fcabahrens jobjectArray array = NULL;
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* Create a list to hold the children */
fa9e4066f08beec538e775443c5be79dd423fcabahrens zjni_DatasetSet_t list_obj = {0};
fa9e4066f08beec538e775443c5be79dd423fcabahrens zjni_DatasetSet_t *list = &list_obj;
fa9e4066f08beec538e775443c5be79dd423fcabahrens zjni_new_DatasetSet(env, list);
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens data.data.env = env;
fa9e4066f08beec538e775443c5be79dd423fcabahrens data.data.list = (zjni_Collection_t *)list;
990b4856d0eaada6f8140335733a1b1771ed2746lling data.typemask = ZFS_TYPE_DATASET;
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens npaths = (*env)->GetArrayLength(env, paths);
fa9e4066f08beec538e775443c5be79dd423fcabahrens for (i = 0; i < npaths; i++) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens jstring pathUTF = (jstring)
fa9e4066f08beec538e775443c5be79dd423fcabahrens ((*env)->GetObjectArrayElement(env, paths, i));
fa9e4066f08beec538e775443c5be79dd423fcabahrens
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley if (pathUTF != NULL) {
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley const char *path =
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley (*env)->GetStringUTFChars(env, pathUTF, NULL);
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley
990b4856d0eaada6f8140335733a1b1771ed2746lling zfs_handle_t *zhp = zfs_open(g_zfs, path,
990b4856d0eaada6f8140335733a1b1771ed2746lling ZFS_TYPE_DATASET);
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley if (zhp != NULL) {
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley /* Add all dependents of this Dataset to list */
3bb79bece53191f2cf27aa61a72ea1784a7ce700eschrock (void) zfs_iter_dependents(zhp, B_FALSE,
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley zjni_create_add_Dataset, &data);
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley /* Add this Dataset to list (and close zhp) */
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley (void) zjni_create_add_Dataset(zhp, &data);
3ccfa83cd9cddd1e34808ba18082c156758c5ec8ahrens } else if (is_pool_name(path)) {
3ccfa83cd9cddd1e34808ba18082c156758c5ec8ahrens /*
3ccfa83cd9cddd1e34808ba18082c156758c5ec8ahrens * Path is not a dataset -
3ccfa83cd9cddd1e34808ba18082c156758c5ec8ahrens * see if it's a faulted pool
3ccfa83cd9cddd1e34808ba18082c156758c5ec8ahrens */
99653d4ee642c6528e88224f12409a5f23060994eschrock zpool_handle_t *zphp = zpool_open_canfail(g_zfs,
99653d4ee642c6528e88224f12409a5f23060994eschrock path);
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley if (zphp != NULL) {
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley /*
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley * Add this Pool to list (and
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley * close zphp)
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley */
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley (void) zjni_create_add_Pool(zphp,
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley &data.data);
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley }
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley }
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley (*env)->ReleaseStringUTFChars(env, pathUTF, path);
fa9e4066f08beec538e775443c5be79dd423fcabahrens }
fa9e4066f08beec538e775443c5be79dd423fcabahrens }
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens if ((*env)->ExceptionOccurred(env) == NULL) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens array = zjni_Collection_to_array(env, (zjni_Collection_t *)list,
fa9e4066f08beec538e775443c5be79dd423fcabahrens ZFSJNI_PACKAGE_DATA "Dataset");
fa9e4066f08beec538e775443c5be79dd423fcabahrens }
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (array);
fa9e4066f08beec538e775443c5be79dd423fcabahrens}
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens/*
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Gets a Dataset of the given name and type, or NULL if no such
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Dataset exists.
fa9e4066f08beec538e775443c5be79dd423fcabahrens */
fa9e4066f08beec538e775443c5be79dd423fcabahrensjobject
fa9e4066f08beec538e775443c5be79dd423fcabahrenszjni_get_Dataset(JNIEnv *env, jstring nameUTF, zfs_type_t typemask)
fa9e4066f08beec538e775443c5be79dd423fcabahrens{
fa9e4066f08beec538e775443c5be79dd423fcabahrens jobject device = NULL;
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley const char *name = (*env)->GetStringUTFChars(env, nameUTF, NULL);
99653d4ee642c6528e88224f12409a5f23060994eschrock zfs_handle_t *zhp = zfs_open(g_zfs, name, typemask);
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley if ((typemask & ZFS_TYPE_FILESYSTEM) && is_pool_name(name)) {
99653d4ee642c6528e88224f12409a5f23060994eschrock zpool_handle_t *zphp = zpool_open_canfail(g_zfs, name);
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley if (zphp != NULL) {
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley device = create_PoolBean(env, zphp, zhp);
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley zpool_close(zphp);
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley }
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley } else if (zhp != NULL) {
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley /* Creates a Dataset object of the appropriate class */
fbfd10ff571cfd0139aa5127460f1b8a53dac971talley device = create_DatasetBean(env, zhp);
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley }
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley if (zhp != NULL) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens zfs_close(zhp);
fa9e4066f08beec538e775443c5be79dd423fcabahrens }
fa9e4066f08beec538e775443c5be79dd423fcabahrens
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley (*env)->ReleaseStringUTFChars(env, nameUTF, name);
32f884e0ef76c8ab2a6e26895696620c8d49ad05talley
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (device);
fa9e4066f08beec538e775443c5be79dd423fcabahrens}