8164900: Add support for O_DIRECT

Add support for Direct I/O in FileChannel

Co-authored-by: Volker Simonis <volker.simonis@gmail.com>
Reviewed-by: alanb, bpb, alanbur, coffeys, aph, clanger, plevart, mli, psandoz, simonis
This commit is contained in:
Lucy Lu 2017-10-17 16:51:11 -07:00 committed by Brian Burkhalter
parent 97db013bd3
commit ec1c3bce45
30 changed files with 1523 additions and 45 deletions

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");
@ -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();