This commit is contained in:
Jesper Wilhelmsson 2017-10-30 21:23:10 +01:00
commit 7884ab9ccf
317 changed files with 46678 additions and 66838 deletions

View file

@ -122,6 +122,17 @@ class FileDispatcherImpl extends FileDispatcher {
return false;
}
int setDirectIO(FileDescriptor fd, String path) {
int result = -1;
try {
result = setDirect0(fd);
} catch (IOException e) {
throw new UnsupportedOperationException
("Error setting up DirectIO", e);
}
return result;
}
// -- Native methods --
static native int read0(FileDescriptor fd, long address, int len)
@ -167,6 +178,8 @@ class FileDispatcherImpl extends FileDispatcher {
static native void closeIntFD(int fd) throws IOException;
static native int setDirect0(FileDescriptor fd) throws IOException;
static native void init();
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -64,6 +64,7 @@ class UnixChannelFactory {
boolean deleteOnClose;
boolean sync;
boolean dsync;
boolean direct;
static Flags toFlags(Set<? extends OpenOption> options) {
Flags flags = new Flags();
@ -88,6 +89,12 @@ class UnixChannelFactory {
flags.noFollowLinks = true;
continue;
}
if (ExtendedOptions.DIRECT.matches(option)) {
flags.direct = true;
continue;
}
if (option == null)
throw new NullPointerException();
throw new UnsupportedOperationException(option + " not supported");
@ -103,7 +110,7 @@ class UnixChannelFactory {
static FileChannel newFileChannel(int fd, String path, boolean reading, boolean writing) {
FileDescriptor fdObj = new FileDescriptor();
fdAccess.set(fdObj, fd);
return FileChannelImpl.open(fdObj, path, reading, writing, null);
return FileChannelImpl.open(fdObj, path, reading, writing, false, null);
}
/**
@ -134,7 +141,8 @@ class UnixChannelFactory {
throw new IllegalArgumentException("APPEND + TRUNCATE_EXISTING not allowed");
FileDescriptor fdObj = open(dfd, path, pathForPermissionCheck, flags, mode);
return FileChannelImpl.open(fdObj, path.toString(), flags.read, flags.write, null);
return FileChannelImpl.open(fdObj, path.toString(), flags.read,
flags.write, flags.direct, null);
}
/**
@ -235,6 +243,8 @@ class UnixChannelFactory {
oflags |= O_DSYNC;
if (flags.sync)
oflags |= O_SYNC;
if (flags.direct)
oflags |= O_DIRECT;
// permission check before we open the file
SecurityManager sm = System.getSecurityManager();

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 2017, Oracle and/or its affiliates. All rights reserved.
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
@ -70,6 +70,12 @@ class UnixConstants {
static final int PREFIX_O_NOFOLLOW = 00;
#endif
#ifdef O_DIRECT
static final int PREFIX_O_DIRECT = O_DIRECT;
#else
// not supported (dummy values will not be used at runtime).
static final int PREFIX_O_DIRECT = 00;
#endif
static final int PREFIX_S_IAMB =
(S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IWGRP|S_IXGRP|S_IROTH|S_IWOTH|S_IXOTH);

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -125,6 +125,12 @@ abstract class UnixFileStore
return attrs.blockSize() * attrs.availableBlocks();
}
@Override
public long getBlockSize() throws IOException {
UnixFileStoreAttributes attrs = readAttributes();
return attrs.blockSize();
}
@Override
public long getUnallocatedSpace() throws IOException {
UnixFileStoreAttributes attrs = readAttributes();

View file

@ -50,7 +50,7 @@
#define mmap64 mmap
#endif
static jfieldID chan_fd; /* jobject 'fd' in sun.io.FileChannelImpl */
static jfieldID chan_fd; /* jobject 'fd' in sun.nio.ch.FileChannelImpl */
JNIEXPORT jlong JNICALL
Java_sun_nio_ch_FileChannelImpl_initIDs(JNIEnv *env, jclass clazz)

View file

@ -34,6 +34,7 @@
#include <fcntl.h>
#include <sys/uio.h>
#include <unistd.h>
#include <sys/statvfs.h>
#if defined(__linux__)
#include <linux/fs.h>
#include <sys/ioctl.h>
@ -323,3 +324,58 @@ Java_sun_nio_ch_FileDispatcherImpl_closeIntFD(JNIEnv *env, jclass clazz, jint fd
{
closeFileDescriptor(env, fd);
}
JNIEXPORT jint JNICALL
Java_sun_nio_ch_FileDispatcherImpl_setDirect0(JNIEnv *env, jclass clazz,
jobject fdo)
{
jint fd = fdval(env, fdo);
jint result;
#ifdef MACOSX
struct statvfs file_stat;
#else
struct statvfs64 file_stat;
#endif
#if defined(O_DIRECT) || defined(F_NOCACHE) || defined(DIRECTIO_ON)
#ifdef O_DIRECT
jint orig_flag;
orig_flag = fcntl(fd, F_GETFL);
if (orig_flag == -1) {
JNU_ThrowIOExceptionWithLastError(env, "DirectIO setup failed");
return -1;
}
result = fcntl(fd, F_SETFL, orig_flag | O_DIRECT);
if (result == -1) {
JNU_ThrowIOExceptionWithLastError(env, "DirectIO setup failed");
return result;
}
#elif F_NOCACHE
result = fcntl(fd, F_NOCACHE, 1);
if (result == -1) {
JNU_ThrowIOExceptionWithLastError(env, "DirectIO setup failed");
return result;
}
#elif DIRECTIO_ON
result = directio(fd, DIRECTIO_ON);
if (result == -1) {
JNU_ThrowIOExceptionWithLastError(env, "DirectIO setup failed");
return result;
}
#endif
#ifdef MACOSX
result = fstatvfs(fd, &file_stat);
#else
result = fstatvfs64(fd, &file_stat);
#endif
if(result == -1) {
JNU_ThrowIOExceptionWithLastError(env, "DirectIO setup failed");
return result;
} else {
result = (int)file_stat.f_frsize;
}
#else
result == -1;
#endif
return result;
}