PrintStream out = listener.getLogger(); LibZFS zfs = new LibZFS(); ZFSFileSystem existing = zfs.getFileSystemByMountPoint(home); if(existing!=null) { String name = computeHudsonFileSystemName(zfs, zfs.roots().get(0)); out.println("Creating "+name); ZFSFileSystem hudson = zfs.create(name, ZFSFileSystem.class);
LibZFS zfs = new LibZFS(); ZFSFileSystem existing = zfs.getFileSystemByMountPoint(home); if(existing!=null) { out.println(home+" is already on ZFS. Doing nothing"); ZFSFileSystem hudson = zfs.open(target, ZFSFileSystem.class); hudson.setMountPoint(tmpDir); hudson.setProperty("hudson:managed-by","hudson"); // mark this file system as "managed by Hudson"
@Override public Void invoke(File f, VirtualChannel channel) throws IOException { ZFSFileSystem fs = libzfs.getFileSystemByMountPoint(f); if(fs!=null) return null; // already on ZFS // nope. create a file system String fullName = rootDataset + '/' + name; listener.getLogger().println("Creating a ZFS file system "+fullName+" at "+f); fs = libzfs.create(fullName, ZFSFileSystem.class); fs.setMountPoint(f); fs.mount(); return null; } }
private boolean shouldBeActive() { if(!System.getProperty("os.name").equals("SunOS") || disabled) // on systems that don't have ZFS, we don't need this monitor return false; try { LibZFS zfs = new LibZFS(); List<ZFSFileSystem> roots = zfs.roots(); if(roots.isEmpty()) return false; // no active ZFS pool // if we don't run on a ZFS file system, activate ZFSFileSystem hudsonZfs = zfs.getFileSystemByMountPoint(Jenkins.getInstance().getRootDir()); if(hudsonZfs!=null) return false; // already on ZFS // decide what file system we'll create ZFSFileSystem pool = roots.get(0); prospectiveZfsFileSystemName = computeHudsonFileSystemName(zfs,pool); return true; } catch (Exception e) { LOGGER.log(Level.WARNING, "Failed to detect whether Hudson is on ZFS",e); return false; } catch (LinkageError e) { LOGGER.info("No ZFS available. If you believe this is an error, increase the logging level to get the stack trace"); LOGGER.log(Level.FINE,"Stack trace of failed ZFS load",e); return false; } }
/** * Open a ZFS Data Set of a given name. * * @param dataSetName * name of the dataset to open. * @return opened dataset, or null if no such dataset exists. */ public ZFSObject open(final String dataSetName) { final ZFSObject dataSet = open(dataSetName, zfs_type_t.DATASET); return dataSet; }
@Override protected void doRun() { ZFSFileSystem fs=null; try { if(isInsideEC2()) fs = new LibZFS().getFileSystemByMountPoint(Hudson.getInstance().getRootDir()); } catch (LinkageError e) { // probably not running on OpenSolaris } if(fs==null) { cancel(); return; } ZFSPool pool = fs.getPool(); long a = pool.getAvailableSize(); long t = pool.getSize(); // if the disk is 90% filled up and the available space is less than 1GB, // notify the user ZPoolExpandNotice zen = AdministrativeMonitor.all().get(ZPoolExpandNotice.class); zen.activated = t/a>10 && a<1000L*1000*1000; }
@Override public String invoke(File f, VirtualChannel channel) throws IOException { ZFSFileSystem fs = libzfs.getFileSystemByMountPoint(f); if(fs!=null) return fs.getName(); // TODO: for now, only support agents that are already on ZFS. throw new IOException("Not on ZFS"); } }
public List<ZFSFileSystem> children() { return roots(); }
@Override public NativeZfsFileSystem createZfs(String mountName) throws NativeAccessException { ZFSFileSystem fs = zfs.create(mountName, ZFSFileSystem.class); return new ZfsFileSystemImpl(fs); }
final boolean recursive) { String fullName = name + '@' + snapshotName; String abi = library.getFeature("LIBZFS4J_ABI_zfs_snapshot"); if (abi.equals("pre-nv96")) { if (LIBZFS.zfs_snapshot(library.getHandle(), fullName, recursive) != 0) { throw new ZFSException(library); if (LIBZFS.zfs_snapshot(library.getHandle(), fullName, recursive, null) != 0) { throw new ZFSException(library); final ZFSSnapshot dataSet = (ZFSSnapshot) library.open(fullName, zfs_type_t.SNAPSHOT); return dataSet;
/** * Take a snapshot of this ZFS dataset and recursively for all child * datasets. * * @param snapshotName * the name of the Snapshot to create, i.e. 'monday', * 'before-test'. * @param recursive * should snapshot recursively create snapshot for all descendant * datasets. Snapshots are taken atomically, so that all * recursive snapshots correspond to the same moment in time. * @return the created snapshot of this dataset. */ public ZFSSnapshot createSnapshot(final String snapshotName, final boolean recursive) { String fullName = name + '@' + snapshotName; /* * nv96 prototype: if(LIBZFS.zfs_snapshot(library.getHandle(), * fullName,recursive, null)!=0) pre-nv96 prototype: * if(LIBZFS.zfs_snapshot(library.getHandle(), fullName,recursive)!=0) */ if (LIBZFS.zfs_snapshot(library.getHandle(), fullName, recursive, null) != 0) { throw new ZFSException(library); } final ZFSSnapshot dataSet = (ZFSSnapshot) library.open(fullName, zfs_type_t.SNAPSHOT); return dataSet; }
@DataBoundConstructor public JnaZfsSupport() { try { zfs = new LibZFS(); } catch (Throwable thr) { // Never mind. Native ZFS library could not be loaded // We don't support ZFS after all } }
@Override protected void finalize() throws Throwable { super.finalize(); dispose(); }
public List<ZFSObject> descendants() { return children(ZFSObject.class); }
/** * Gets a {@link ZFSFileSystem} mounted at the given directory. * * @return * null if no such file system exists. */ public ZFSFileSystem getFileSystemByMountPoint(File dir) { dir = dir.getAbsoluteFile(); for (ZFSFileSystem f : descendants(ZFSFileSystem.class)) { File mp = f.getMountPoint(); if(mp!=null && mp.equals(dir)) return f; } return null; }