use of alluxio.jnifuse.FuseException in project alluxio by Alluxio.
the class AlluxioFuse method launchFuse.
/**
* Launches Fuse application.
*
* @param fs file system for Fuse client to communicate to servers
* @param conf the alluxio configuration to create Fuse file system
* @param opts the fuse mount options
* @param blocking whether the Fuse application is blocking or not
* @return the Fuse application handler for future Fuse umount operation
*/
public static FuseUmountable launchFuse(FileSystem fs, AlluxioConfiguration conf, FuseMountOptions opts, boolean blocking) throws IOException {
Preconditions.checkNotNull(opts, "Fuse mount options should not be null to launch a Fuse application");
try {
String mountPoint = opts.getMountPoint();
if (!FileUtils.exists(mountPoint)) {
LOG.warn("Mount point on local fs does not exist, creating {}", mountPoint);
FileUtils.createDir(mountPoint);
}
final List<String> fuseOpts = opts.getFuseOpts();
if (conf.getBoolean(PropertyKey.FUSE_JNIFUSE_ENABLED)) {
final AlluxioJniFuseFileSystem fuseFs = new AlluxioJniFuseFileSystem(fs, opts, conf);
FuseSignalHandler fuseSignalHandler = new FuseSignalHandler(fuseFs);
Signal.handle(new Signal("TERM"), fuseSignalHandler);
try {
LOG.info("Mounting AlluxioJniFuseFileSystem: mount point=\"{}\", OPTIONS=\"{}\"", opts.getMountPoint(), fuseOpts.toArray(new String[0]));
fuseFs.mount(blocking, opts.isDebug(), fuseOpts.toArray(new String[0]));
return fuseFs;
} catch (FuseException e) {
// only try to umount file system when exception occurred.
// jni-fuse registers JVM shutdown hook to ensure fs.umount()
// will be executed when this process is exiting.
String errorMessage = String.format("Failed to mount alluxio path %s to mount point %s", opts.getAlluxioRoot(), opts.getMountPoint());
LOG.error(errorMessage, e);
try {
fuseFs.umount(true);
} catch (FuseException fe) {
LOG.error("Failed to unmount Fuse", fe);
}
throw new IOException(errorMessage, e);
}
} else {
// Force direct_io in JNR-FUSE: writes and reads bypass the kernel page
// cache and go directly to alluxio. This avoids extra memory copies
// in the write path.
// TODO(binfan): support kernel_cache (issues#10840)
fuseOpts.add("-odirect_io");
final AlluxioFuseFileSystem fuseFs = new AlluxioFuseFileSystem(fs, opts, conf);
try {
fuseFs.mount(Paths.get(opts.getMountPoint()), blocking, opts.isDebug(), fuseOpts.toArray(new String[0]));
return fuseFs;
} catch (ru.serce.jnrfuse.FuseException e) {
// only try to umount file system when exception occurred.
// jnr-fuse registers JVM shutdown hook to ensure fs.umount()
// will be executed when this process is exiting.
fuseFs.umount();
throw new IOException(String.format("Failed to mount alluxio path %s to mount point %s", opts.getAlluxioRoot(), opts.getMountPoint()), e);
}
}
} catch (Throwable e) {
throw new IOException("Failed to mount Alluxio file system", e);
}
}
Aggregations