@Override public void posixFadviseIfPossible(String name, FileDescriptor fd, long offset, long len, int flags) throws NativeIOException { if ((len < 0) || (len > Integer.MAX_VALUE)) { throw new RuntimeException("invalid length of " + len + " passed to posixFadviseIfPossible"); } if ((offset < 0) || (offset > Integer.MAX_VALUE)) { throw new RuntimeException("invalid offset of " + offset + " passed to posixFadviseIfPossible"); } Stats stats = map.get(name); if (stats == null) { stats = new Stats(name); map.put(name, stats); } stats.fadvise((int)offset, (int)len, flags); super.posixFadviseIfPossible(name, fd, offset, len, flags); }
/** * Open the specified File for write access, ensuring that it does not exist. * @param f the file that we want to create * @param permissions we want to have on the file (if security is enabled) * * @throws AlreadyExistsException if the file already exists * @throws IOException if any other error occurred */ public static FileOutputStream createForWrite(File f, int permissions) throws IOException { if (skipSecurity) { return insecureCreateForWrite(f, permissions); } else { // Use the native wrapper around open(2) try { FileDescriptor fd = NativeIO.open(f.getAbsolutePath(), NativeIO.O_WRONLY | NativeIO.O_CREAT | NativeIO.O_EXCL, permissions); return new FileOutputStream(fd); } catch (NativeIOException nioe) { if (nioe.getErrno() == Errno.EEXIST) { throw new AlreadyExistsException(nioe); } throw nioe; } } }
public void submitSyncFileRangeRequest(FsVolumeImpl volume, final FileDescriptor fd, final long offset, final long nbytes, final int flags) { execute(volume.getCurrentDir(), new Runnable() { @Override public void run() { try { NativeIO.POSIX.syncFileRangeIfPossible(fd, offset, nbytes, flags); } catch (NativeIOException e) { LOG.warn("sync_file_range error", e); } } }); }
public static void rename(File from, File to) throws IOException { try { NativeIO.renameTo(from, to); } catch (NativeIOException e) { throw new IOException("Failed to rename " + from.getCanonicalPath() + " to " + to.getCanonicalPath() + " due to failure in native rename. " + e.toString()); } }
@Override public void close() throws IOException { boolean triedToClose = false, success = false; try { flush(); ((FileOutputStream)out).getChannel().force(true); triedToClose = true; super.close(); success = true; } finally { if (success) { boolean renamed = tmpFile.renameTo(origFile); if (!renamed) { // On windows, renameTo does not replace. if (origFile.exists() && !origFile.delete()) { throw new IOException("Could not delete original file " + origFile); } try { NativeIO.renameTo(tmpFile, origFile); } catch (NativeIOException e) { throw new IOException("Could not rename temporary file " + tmpFile + " to " + origFile + " due to failure in native rename. " + e.toString()); } } } else { if (!triedToClose) { // If we failed when flushing, try to close it to not leak an FD IOUtils.closeStream(out); } // close wasn't successful, try to delete the tmp file if (!tmpFile.delete()) { LOG.warn("Unable to delete tmp file " + tmpFile); } } } }
public void posixFadviseIfPossible(long offset, long len, int flags, boolean sync) throws NativeIOException { if (fd != null) { if (sync) { NativeIO.posixFadviseIfPossible(fd, offset, len, flags); } else { volume.submitNativeIOTask(new PosixFadviseRunnable(fd, offset, len, flags, this)); } } else if (file != null) { DataNode.LOG.warn("Failed to fadvise as file " + file + " is missing file descriptor"); } }
private static native WinutilsProcessStub createTaskAsUser0( String cwd, String jobName, String user, String pidFile, String cmdLine) throws NativeIOException;
public void posixFadviseIfPossible(long offset, long len, int flags) throws NativeIOException { posixFadviseIfPossible(offset, len, flags, false); }
public native void resume() throws NativeIOException;