8171452: (ch) linux io_util_md: Operation not supported exception after 8168628

On Linux, fall back to ftruncate64() if fallocate64() fails

Reviewed-by: mdoerr, alanb
This commit is contained in:
Brian Burkhalter 2016-12-20 10:11:05 -08:00
parent cfb01751b1
commit 622df39570
2 changed files with 16 additions and 8 deletions
jdk/src/java.base/unix/native

@ -1,5 +1,5 @@
/*
* Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2001, 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
@ -226,7 +226,12 @@ handleSetLength(FD fd, jlong length)
if (fstat64(fd, &sb) == 0 && length > sb.st_blocks*512) {
RESTARTABLE(fallocate64(fd, 0, 0, length), result);
return result;
// Return on success or if errno is neither EOPNOTSUPP nor ENOSYS
if (result == 0) {
return 0;
} else if (errno != EOPNOTSUPP && errno != ENOSYS) {
return result;
}
}
#endif
RESTARTABLE(ftruncate64(fd, length), result);

@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 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
@ -197,14 +197,17 @@ Java_sun_nio_ch_FileDispatcherImpl_allocate0(JNIEnv *env, jobject this,
* any blocks which can cause a SIGBUS error if the file is subsequently
* memory-mapped.
*/
return handle(env,
fallocate64(fdval(env, fdo), 0, 0, size),
"Allocation failed");
#else
// Return on success or if errno is neither EOPNOTSUPP nor ENOSYS
int result = fallocate64(fdval(env, fdo), 0, 0, size);
if (result == 0) {
return 0;
} else if (errno != EOPNOTSUPP && errno != ENOSYS) {
return handle(env, result, "Allocation failed");
}
#endif
return handle(env,
ftruncate64(fdval(env, fdo), size),
"Truncation failed");
#endif
}
JNIEXPORT jlong JNICALL