HDFS-3710. libhdfs misuses O_RDONLY/WRONLY/RDWR. Contributed by Andy Isaacson.
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1370898 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
4920387b8a
commit
b587af4631
@ -568,6 +568,8 @@ Branch-2 ( Unreleased changes )
|
|||||||
|
|
||||||
HDFS-3760. primitiveCreate is a write, not a read. (Andy Isaacson via atm)
|
HDFS-3760. primitiveCreate is a write, not a read. (Andy Isaacson via atm)
|
||||||
|
|
||||||
|
HDFS-3710. libhdfs misuses O_RDONLY/WRONLY/RDWR. (Andy Isaacson via atm)
|
||||||
|
|
||||||
BREAKDOWN OF HDFS-3042 SUBTASKS
|
BREAKDOWN OF HDFS-3042 SUBTASKS
|
||||||
|
|
||||||
HDFS-2185. HDFS portion of ZK-based FailoverController (todd)
|
HDFS-2185. HDFS portion of ZK-based FailoverController (todd)
|
||||||
|
@ -657,6 +657,7 @@ hdfsFile hdfsOpenFile(hdfsFS fs, const char* path, int flags,
|
|||||||
*/
|
*/
|
||||||
/* Get the JNIEnv* corresponding to current thread */
|
/* Get the JNIEnv* corresponding to current thread */
|
||||||
JNIEnv* env = getJNIEnv();
|
JNIEnv* env = getJNIEnv();
|
||||||
|
int accmode = flags & O_ACCMODE;
|
||||||
|
|
||||||
if (env == NULL) {
|
if (env == NULL) {
|
||||||
errno = EINTERNAL;
|
errno = EINTERNAL;
|
||||||
@ -672,10 +673,16 @@ hdfsFile hdfsOpenFile(hdfsFS fs, const char* path, int flags,
|
|||||||
hdfsFile file = NULL;
|
hdfsFile file = NULL;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (flags & O_RDWR) {
|
if (accmode == O_RDONLY || accmode == O_WRONLY) {
|
||||||
|
/* yay */
|
||||||
|
} else if (accmode == O_RDWR) {
|
||||||
fprintf(stderr, "ERROR: cannot open an hdfs file in O_RDWR mode\n");
|
fprintf(stderr, "ERROR: cannot open an hdfs file in O_RDWR mode\n");
|
||||||
errno = ENOTSUP;
|
errno = ENOTSUP;
|
||||||
return NULL;
|
return NULL;
|
||||||
|
} else {
|
||||||
|
fprintf(stderr, "ERROR: cannot open an hdfs file in mode 0x%x\n", accmode);
|
||||||
|
errno = EINVAL;
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((flags & O_CREAT) && (flags & O_EXCL)) {
|
if ((flags & O_CREAT) && (flags & O_EXCL)) {
|
||||||
@ -683,12 +690,19 @@ hdfsFile hdfsOpenFile(hdfsFS fs, const char* path, int flags,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* The hadoop java api/signature */
|
/* The hadoop java api/signature */
|
||||||
const char* method = ((flags & O_WRONLY) == 0) ? "open" : (flags & O_APPEND) ? "append" : "create";
|
const char* method = NULL;
|
||||||
const char* signature = ((flags & O_WRONLY) == 0) ?
|
const char* signature = NULL;
|
||||||
JMETHOD2(JPARAM(HADOOP_PATH), "I", JPARAM(HADOOP_ISTRM)) :
|
|
||||||
(flags & O_APPEND) ?
|
if (accmode == O_RDONLY) {
|
||||||
JMETHOD1(JPARAM(HADOOP_PATH), JPARAM(HADOOP_OSTRM)) :
|
method = "open";
|
||||||
JMETHOD2(JPARAM(HADOOP_PATH), "ZISJ", JPARAM(HADOOP_OSTRM));
|
signature = JMETHOD2(JPARAM(HADOOP_PATH), "I", JPARAM(HADOOP_ISTRM));
|
||||||
|
} else if (flags & O_APPEND) {
|
||||||
|
method = "append";
|
||||||
|
signature = JMETHOD1(JPARAM(HADOOP_PATH), JPARAM(HADOOP_OSTRM));
|
||||||
|
} else {
|
||||||
|
method = "create";
|
||||||
|
signature = JMETHOD2(JPARAM(HADOOP_PATH), "ZISJ", JPARAM(HADOOP_OSTRM));
|
||||||
|
}
|
||||||
|
|
||||||
/* Create an object of org.apache.hadoop.fs.Path */
|
/* Create an object of org.apache.hadoop.fs.Path */
|
||||||
jthr = constructNewObjectOfPath(env, path, &jPath);
|
jthr = constructNewObjectOfPath(env, path, &jPath);
|
||||||
@ -741,9 +755,7 @@ hdfsFile hdfsOpenFile(hdfsFS fs, const char* path, int flags,
|
|||||||
jBufferSize = jVal.i;
|
jBufferSize = jVal.i;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((flags & O_WRONLY) && (flags & O_APPEND) == 0) {
|
if ((accmode == O_WRONLY) && (flags & O_APPEND) == 0) {
|
||||||
//replication
|
|
||||||
|
|
||||||
if (!replication) {
|
if (!replication) {
|
||||||
jthr = invokeMethod(env, &jVal, INSTANCE, jConfiguration,
|
jthr = invokeMethod(env, &jVal, INSTANCE, jConfiguration,
|
||||||
HADOOP_CONF, "getInt", "(Ljava/lang/String;I)I",
|
HADOOP_CONF, "getInt", "(Ljava/lang/String;I)I",
|
||||||
@ -776,10 +788,10 @@ hdfsFile hdfsOpenFile(hdfsFS fs, const char* path, int flags,
|
|||||||
FSDataOutputStream references jobject jStream */
|
FSDataOutputStream references jobject jStream */
|
||||||
|
|
||||||
// READ?
|
// READ?
|
||||||
if ((flags & O_WRONLY) == 0) {
|
if (accmode == O_RDONLY) {
|
||||||
jthr = invokeMethod(env, &jVal, INSTANCE, jFS, HADOOP_FS,
|
jthr = invokeMethod(env, &jVal, INSTANCE, jFS, HADOOP_FS,
|
||||||
method, signature, jPath, jBufferSize);
|
method, signature, jPath, jBufferSize);
|
||||||
} else if ((flags & O_WRONLY) && (flags & O_APPEND)) {
|
} else if ((accmode == O_WRONLY) && (flags & O_APPEND)) {
|
||||||
// WRITE/APPEND?
|
// WRITE/APPEND?
|
||||||
jthr = invokeMethod(env, &jVal, INSTANCE, jFS, HADOOP_FS,
|
jthr = invokeMethod(env, &jVal, INSTANCE, jFS, HADOOP_FS,
|
||||||
method, signature, jPath);
|
method, signature, jPath);
|
||||||
|
@ -80,6 +80,9 @@ static int doTestHdfsOperations(struct tlhThreadInfo *ti, hdfsFS fs)
|
|||||||
/* There should not be any file to open for reading. */
|
/* There should not be any file to open for reading. */
|
||||||
EXPECT_NULL(hdfsOpenFile(fs, tmp, O_RDONLY, 0, 0, 0));
|
EXPECT_NULL(hdfsOpenFile(fs, tmp, O_RDONLY, 0, 0, 0));
|
||||||
|
|
||||||
|
/* hdfsOpenFile should not accept mode = 3 */
|
||||||
|
EXPECT_NULL(hdfsOpenFile(fs, tmp, 3, 0, 0, 0));
|
||||||
|
|
||||||
file = hdfsOpenFile(fs, tmp, O_WRONLY, 0, 0, 0);
|
file = hdfsOpenFile(fs, tmp, O_WRONLY, 0, 0, 0);
|
||||||
EXPECT_NONNULL(file);
|
EXPECT_NONNULL(file);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user