org.jvnet.solaris.libzfs
Class LibZFS

java.lang.Object
  extended by org.jvnet.solaris.libzfs.LibZFS
All Implemented Interfaces:
ZFSContainer

public class LibZFS
extends Object
implements ZFSContainer

Entry point to ZFS functionality in Java.

Author:
Kohsuke Kawaguchi

Constructor Summary
LibZFS()
           
 
Method Summary
 List<ZFSFileSystem> children()
          List the children of this ZFS object (but not recursively.)
<T extends ZFSObject>
List<T>
children(Class<T> type)
          List the specific kind of children of this ZFS object (but not recursively.)
<T extends ZFSObject>
T
create(String dataSetName, Class<T> type)
          Create a ZFS Data Set of a given name and zfs type.
 ZFSObject create(String dataSetName, ZFSType type, Map<String,String> props)
          Create a ZFS Data Set of a given name, zfs type and properties.
 List<ZFSObject> descendants()
          List the children of this ZFS object recursively, excluding the 'this' object itself.
<T extends ZFSObject>
List<T>
descendants(Class<T> type)
           
 void dispose()
          Eagerly releases the native resource associated with this wrapper, instead of waiting for GC to take care of it.
 boolean exists(String dataSetName)
          Does a zfs dataset of the given name exist?
 boolean exists(String name, Set<ZFSType> typeMask)
          Does a zfs dataset of the given name and the given types exist?
 boolean exists(String dataSetName, ZFSType type)
          Does a zfs dataset of the given name and the given type exist?
protected  void finalize()
           
 ZFSFileSystem getFileSystemByMountPoint(File dir)
          Gets a ZFSFileSystem mounted at the given directory.
 libzfs_handle_t getHandle()
          Returns libzfs_handle_t that this object wraps.
 ZFSPool getPool(String name)
          Gets the pool of the given name.
 ZFSObject open(String dataSetName)
          Open a ZFS Data Set of a given name.
<T extends ZFSObject>
T
open(String dataSetName, Class<T> type)
          Opens a ZFS dataset of the given name and type.
 ZFSObject open(String dataSetName, int mask)
          Open a ZFS Data Set of a given name and type.
 List<ZFSPool> pools()
          Lists up all the ZFS pools.
 List<ZFSFileSystem> roots()
          List up all the root file systems and return them.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LibZFS

public LibZFS()
Method Detail

roots

public List<ZFSFileSystem> roots()
List up all the root file systems and return them.

In ZFS, each zpool gets a top-level zfs file system automatically. This method returns those top-level file systems.

Returns:
can be empty but never null.

pools

public List<ZFSPool> pools()
Lists up all the ZFS pools.

Returns:
can be empty but never null.

getPool

public ZFSPool getPool(String name)
Gets the pool of the given name.


exists

public boolean exists(String dataSetName)
Does a zfs dataset of the given name exist?

Parameters:
dataSetName - the dataset name of check for.
Returns:
does the dataset exist?

exists

public boolean exists(String name,
                      Set<ZFSType> typeMask)
Does a zfs dataset of the given name and the given types exist?

Parameters:
name - the dataset name of check for.
typeMask - the specific zfs types to check for.
Returns:
does the dataset exist?

exists

public boolean exists(String dataSetName,
                      ZFSType type)
Does a zfs dataset of the given name and the given type exist?

Parameters:
dataSetName - the dataset name of check for.
type - the specific zfs type to check for.
Returns:
does the dataset exist?

create

public <T extends ZFSObject> T create(String dataSetName,
                                      Class<T> type)
Create a ZFS Data Set of a given name and zfs type.

Parameters:
dataSetName - name of the dataset to create.
type - the zfs type of dataset to create.
Returns:
Never null. Created dataset.

create

public ZFSObject create(String dataSetName,
                        ZFSType type,
                        Map<String,String> props)
Create a ZFS Data Set of a given name, zfs type and properties.

Parameters:
dataSetName - Full name of the dataset to create, like "rpool/abc/def".
type - the zfs type of dataset to create. Either ZFSType.FILESYSTEM or ZFSType.VOLUME.
props - zfs dataset properties. Can be null.
Returns:
created dataset.

open

public ZFSObject open(String dataSetName)
Open a ZFS Data Set of a given name.

Parameters:
dataSetName - name of the dataset to open.
Returns:
opened dataset, or null if no such dataset exists.

open

public ZFSObject open(String dataSetName,
                      int mask)
Open a ZFS Data Set of a given name and type.

Parameters:
dataSetName - name of the dataset to open.
mask - the zfs type mask of dataset to open.
Returns:
opened dataset, or null if no such dataset exists.

open

public <T extends ZFSObject> T open(String dataSetName,
                                    Class<T> type)
Opens a ZFS dataset of the given name and type.


getFileSystemByMountPoint

public ZFSFileSystem getFileSystemByMountPoint(File dir)
Gets a ZFSFileSystem mounted at the given directory.

Returns:
null if no such file system exists.

children

public List<ZFSFileSystem> children()
Description copied from interface: ZFSContainer
List the children of this ZFS object (but not recursively.)

Specified by:
children in interface ZFSContainer
Returns:
Never null. Sorted by the in-order of the traversal.

children

public <T extends ZFSObject> List<T> children(Class<T> type)
Description copied from interface: ZFSContainer
List the specific kind of children of this ZFS object (but not recursively.)

Specified by:
children in interface ZFSContainer
Returns:
Never null. Sorted by the in-order of the traversal.

descendants

public List<ZFSObject> descendants()
Description copied from interface: ZFSContainer
List the children of this ZFS object recursively, excluding the 'this' object itself.

Specified by:
descendants in interface ZFSContainer
Returns:
Never null. Sorted by the in-order of the traversal.

descendants

public <T extends ZFSObject> List<T> descendants(Class<T> type)
Specified by:
descendants in interface ZFSContainer

getHandle

public libzfs_handle_t getHandle()
Returns libzfs_handle_t that this object wraps.

If the caller wants to use methods that don't yet have a high-level binding, the returned libzfs_handle_t can be used directly in conjunction with libzfs.LIBZFS.


finalize

protected void finalize()
                 throws Throwable
Overrides:
finalize in class Object
Throws:
Throwable

dispose

public void dispose()
Eagerly releases the native resource associated with this wrapper, instead of waiting for GC to take care of it.



Copyright © 2012. All Rights Reserved.