You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by cm...@apache.org on 2014/05/01 04:10:16 UTC

svn commit: r1591534 [1/3] - in /hadoop/common/branches/HADOOP-10388/hadoop-native-core: ./ common/ hdfs/ rpc/

Author: cmccabe
Date: Thu May  1 02:10:15 2014
New Revision: 1591534

URL: http://svn.apache.org/r1591534
Log:
HADOOP-10389. Native RPCv9 client (cmccabe)

Added:
    hadoop/common/branches/HADOOP-10388/hadoop-native-core/
    hadoop/common/branches/HADOOP-10388/hadoop-native-core/CMakeLists.txt
    hadoop/common/branches/HADOOP-10388/hadoop-native-core/GenerateProtobufs.cmake
    hadoop/common/branches/HADOOP-10388/hadoop-native-core/common/
    hadoop/common/branches/HADOOP-10388/hadoop-native-core/common/hadoop_err-unit.c
    hadoop/common/branches/HADOOP-10388/hadoop-native-core/common/hadoop_err.c
    hadoop/common/branches/HADOOP-10388/hadoop-native-core/common/hadoop_err.h
    hadoop/common/branches/HADOOP-10388/hadoop-native-core/common/net.c
    hadoop/common/branches/HADOOP-10388/hadoop-native-core/common/net.h
    hadoop/common/branches/HADOOP-10388/hadoop-native-core/common/queue.h
    hadoop/common/branches/HADOOP-10388/hadoop-native-core/common/string.c
    hadoop/common/branches/HADOOP-10388/hadoop-native-core/common/string.h
    hadoop/common/branches/HADOOP-10388/hadoop-native-core/common/test.c
    hadoop/common/branches/HADOOP-10388/hadoop-native-core/common/test.h
    hadoop/common/branches/HADOOP-10388/hadoop-native-core/common/tree.h
    hadoop/common/branches/HADOOP-10388/hadoop-native-core/hdfs/
    hadoop/common/branches/HADOOP-10388/hadoop-native-core/hdfs/namenode-rpc-unit.c
    hadoop/common/branches/HADOOP-10388/hadoop-native-core/rpc/
    hadoop/common/branches/HADOOP-10388/hadoop-native-core/rpc/call.c
    hadoop/common/branches/HADOOP-10388/hadoop-native-core/rpc/call.h
    hadoop/common/branches/HADOOP-10388/hadoop-native-core/rpc/client_id.c
    hadoop/common/branches/HADOOP-10388/hadoop-native-core/rpc/client_id.h
    hadoop/common/branches/HADOOP-10388/hadoop-native-core/rpc/conn.c
    hadoop/common/branches/HADOOP-10388/hadoop-native-core/rpc/conn.h
    hadoop/common/branches/HADOOP-10388/hadoop-native-core/rpc/messenger.c
    hadoop/common/branches/HADOOP-10388/hadoop-native-core/rpc/messenger.h
    hadoop/common/branches/HADOOP-10388/hadoop-native-core/rpc/protoc-gen-hrpc.cc
    hadoop/common/branches/HADOOP-10388/hadoop-native-core/rpc/proxy.c
    hadoop/common/branches/HADOOP-10388/hadoop-native-core/rpc/proxy.h
    hadoop/common/branches/HADOOP-10388/hadoop-native-core/rpc/reactor.c
    hadoop/common/branches/HADOOP-10388/hadoop-native-core/rpc/reactor.h
    hadoop/common/branches/HADOOP-10388/hadoop-native-core/rpc/shorten.c
    hadoop/common/branches/HADOOP-10388/hadoop-native-core/rpc/varint-unit.c
    hadoop/common/branches/HADOOP-10388/hadoop-native-core/rpc/varint.c
    hadoop/common/branches/HADOOP-10388/hadoop-native-core/rpc/varint.h

Added: hadoop/common/branches/HADOOP-10388/hadoop-native-core/CMakeLists.txt
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HADOOP-10388/hadoop-native-core/CMakeLists.txt?rev=1591534&view=auto
==============================================================================
--- hadoop/common/branches/HADOOP-10388/hadoop-native-core/CMakeLists.txt (added)
+++ hadoop/common/branches/HADOOP-10388/hadoop-native-core/CMakeLists.txt Thu May  1 02:10:15 2014
@@ -0,0 +1,122 @@
+cmake_minimum_required(VERSION 2.6)
+set(CMAKE_BUILD_TYPE, Release) # Default to release builds
+enable_testing()
+MESSAGE(STATUS "Building hadoop-native-core, the native Hadoop core libraries.")
+
+set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -Wall -Wextra -O2 -fno-strict-aliasing")
+set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_REENTRANT -D_GNU_SOURCE")
+set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64")
+set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -Wno-unused")
+
+macro(add_utest utest)
+    add_test(${utest} ${CMAKE_CURRENT_BINARY_DIR}/${utest} ${utest})
+endmacro(add_utest)
+
+# Find libuv
+find_library(LIBUV_LIB NAMES uv PATHS lib/libuv)
+find_path(LIBUV_HEADER_PATH NAMES uv.h PATHS lib/libuv/include uv/include)
+if (NOT (LIBUV_LIB AND LIBUV_HEADER_PATH))
+    MESSAGE(FATAL_ERROR "Failed to find libuv.  Please install libuv.  LIBUV_LIB=${LIBUV_LIB}, LIBUV_HEADER_PATH=${LIBUV_HEADER_PATH}") 
+endif ()
+include_directories(
+    lib/libuv/include
+    uv/include)
+
+# Find protobuf-c
+find_library(PROTOBUFC_LIB NAMES protobuf-c 
+    HINTS /usr/lib64 /usr/lib)
+find_program(PROTOBUFC_EXE NAMES protoc-c)
+if (NOT (PROTOBUFC_LIB AND PROTOBUFC_EXE))
+    MESSAGE(FATAL_ERROR "Failed to find protobuf-c.  Please install protobuf-c.  PROTOBUFC_LIB=${PROTOBUFC_LIB}, PROTOBUFC_EXE=${PROTOBUFC_EXE}")
+endif()
+
+# Find protobuf
+find_library(PROTOC_LIB NAMES libprotoc.so
+    HINTS /usr/lib /usr/lib64)
+find_library(PROTOBUF_LIB NAMES libprotobuf.so
+    HINTS /usr/lib /usr/lib64)
+find_program(PROTOC_EXE NAMES protoc)
+find_path(PROTOC_HEADER_PATH NAMES 
+    google/protobuf/compiler/command_line_interface.h
+    HINTS /usr/include)
+if (NOT (PROTOC_LIB AND PROTOBUF_LIB AND PROTOC_EXE AND PROTOC_HEADER_PATH))
+    MESSAGE(FATAL_ERROR "Failed to find the C++ protobuf libraries, which are needed for RPC code generation.  PROTOC_LIB=${PROTOC_LIB}, PROTOBUF_LIB=${PROTOBUF_LIB}, PROTOC_EXE=${PROTOC_EXE}, PROTOC_HEADER_PATH=${PROTOC_HEADER_PATH}")
+endif ()
+
+include_directories(
+    ${CMAKE_CURRENT_SOURCE_DIR}
+    ${CMAKE_CURRENT_BINARY_DIR}
+    ${PROTOBUF_HEADER_PATH})
+
+include(GenerateProtobufs.cmake NO_POLICY_SCOPE)
+
+set(COMMON_SRCS
+    common/hadoop_err.c
+    common/net.c
+    common/string.c
+    common/test.c
+)
+set(COMMON_DEPS
+    pthread
+)
+
+set(RPC_SRCS
+    rpc/call.c
+    rpc/client_id.c
+    rpc/conn.c
+    rpc/messenger.c
+    rpc/proxy.c
+    rpc/reactor.c
+    rpc/varint.c
+    ${COMMON_PROTOBUF_SRCS}
+)
+set(RPC_DEPS
+    ${LIBUV_LIB}
+    ${PROTOBUFC_LIB}
+)
+
+add_executable(varint-unit rpc/varint-unit.c
+    rpc/varint.c common/test.c)
+add_utest(varint-unit)
+
+add_executable(hadoop_err-unit common/hadoop_err-unit.c
+    common/hadoop_err.c common/test.c)
+add_utest(hadoop_err-unit)
+target_link_libraries(hadoop_err-unit uv)
+
+add_executable(namenode-rpc-unit hdfs/namenode-rpc-unit.c)
+target_link_libraries(namenode-rpc-unit hdfs-core)
+
+add_library(hdfs-core SHARED
+    ${COMMON_SRCS}
+    ${RPC_SRCS}
+    ${HDFS_PROTOBUF_SRCS}
+)
+target_link_libraries(hdfs-core 
+    ${COMMON_DEPS}
+    ${RPC_DEPS}
+)
+set(HDFS_CORE_VERSION_MAJOR 1)
+set(HDFS_CORE_VERSION_MINOR 0)
+set(HDFS_CORE_VERSION_PATCH 0)
+set(HDFS_CORE_VERSION_STRING "${HDFS_CORE_VERSION_MAJOR}.${HDFS_CORE_VERSION_MINOR}.${HDFS_CORE_VERSION_PATCH}")
+set_target_properties(hdfs-core PROPERTIES
+    VERSION ${HDFS_CORE_VERSION_STRING}
+    SOVERSION ${HDFS_CORE_VERSION_MAJOR})
+
+add_library(yarn-core SHARED
+    ${COMMON_SRCS}
+    ${RPC_SRCS}
+    ${YARN_PROTOBUF_SRCS}
+)
+target_link_libraries(yarn-core 
+    ${COMMON_DEPS}
+    ${RPC_DEPS}
+)
+set(YARN_CORE_VERSION_MAJOR 1)
+set(YARN_CORE_VERSION_MINOR 0)
+set(YARN_CORE_VERSION_PATCH 0)
+set(YARN_CORE_VERSION_STRING ${YARN_CORE_VERSION_MAJOR}.${YARN_CORE_VERSION_MINOR}.${YARN_CORE_VERSION_PATCH})
+set_target_properties(yarn-core PROPERTIES
+    VERSION ${YARN_CORE_VERSION_STRING}
+    SOVERSION ${YARN_CORE_VERSION_MAJOR})

Added: hadoop/common/branches/HADOOP-10388/hadoop-native-core/GenerateProtobufs.cmake
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HADOOP-10388/hadoop-native-core/GenerateProtobufs.cmake?rev=1591534&view=auto
==============================================================================
--- hadoop/common/branches/HADOOP-10388/hadoop-native-core/GenerateProtobufs.cmake (added)
+++ hadoop/common/branches/HADOOP-10388/hadoop-native-core/GenerateProtobufs.cmake Thu May  1 02:10:15 2014
@@ -0,0 +1,93 @@
+MESSAGE(STATUS "Processing hadoop-core protobuf definitions.")
+
+add_executable(shorten rpc/shorten.c)
+
+include_directories(${PROTOC_HEADER_PATH})
+add_executable(protoc-gen-hrpc rpc/protoc-gen-hrpc.cc)
+target_link_libraries(protoc-gen-hrpc ${PROTOC_LIB} ${PROTOBUF_LIB})
+
+function(DECLARE_PROTOS OUTPUT_SRC_LIST GENERATOR_DIR INCLUDE_DIRS)
+    if (NOT ARGN)
+        message(SEND_ERROR "Error: DECLARE_PROTOS requires protobuf files as arguments.")
+    endif()
+    set(CFILES)
+    set(HFILES)
+    get_filename_component(GENERATOR_DIR "${GENERATOR_DIR}" REALPATH)
+    set(INCLUDE_FLAGS)
+    foreach(IDIR ${INCLUDE_DIRS})
+        set(INCLUDE_FLAGS ${INCLUDE_FLAGS} -I ${IDIR})
+    endforeach()
+    foreach(PB_FILE ${ARGN})
+        get_filename_component(DIRNAME_F ${PB_FILE} PATH)
+        get_filename_component(ABSNAME_F ${PB_FILE} ABSOLUTE)
+        get_filename_component(BASENAME_F ${PB_FILE} NAME_WE)
+        set(PB_C_FILE "${GENERATOR_DIR}/${BASENAME_F}.pb-c.c")
+        set(PB_H_FILE "${GENERATOR_DIR}/${BASENAME_F}.pb-c.h")
+        set(CALL_C_FILE "${GENERATOR_DIR}/${BASENAME_F}.call.c")
+        set(CALL_H_FILE "${GENERATOR_DIR}/${BASENAME_F}.call.h")
+        execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${GENERATOR_DIR})
+        add_custom_command(
+            OUTPUT ${PB_C_FILE} ${PB_H_FILE} ${CALL_C_FILE} ${CALL_H_FILE}
+            COMMAND  ${PROTOBUFC_EXE}
+                ARGS --c_out  ${GENERATOR_DIR} ${INCLUDE_FLAGS} --proto_path ${DIRNAME_F} ${ABSNAME_F}
+                COMMENT "Running protoc-c on ${PB_FILE}"
+                DEPENDS ${ABSNAME_F}
+                VERBATIM 
+            COMMAND  "${CMAKE_CURRENT_BINARY_DIR}/shorten"
+                ARGS ${PB_H_FILE}
+                COMMENT "Processing ${PB_H_FILE}"
+                DEPENDS ${ABSNAME_F} shorten
+                VERBATIM 
+            COMMAND "${PROTOC_EXE}"
+                ARGS --plugin=protoc-gen-hrpc --hrpc_out ${GENERATOR_DIR} ${INCLUDE_FLAGS} ${ABSNAME_F}
+                COMMENT "Running HRPC protocol buffer compiler on ${ABSNAME_F}"
+                DEPENDS ${ABSNAME_F} protoc-gen-hrpc
+                VERBATIM
+            )
+        list(APPEND CFILES ${PB_C_FILE} ${CALL_C_FILE})
+        list(APPEND HFILES ${PB_H_FILE} ${PB_H_FILE}.s ${CALL_H_FILE})
+        set_source_files_properties(${PB_C_FILE} ${PB_H_FILE} "${PB_H_FILE}.s" PROPERTIES GENERATED TRUE)
+    endforeach()
+    #MESSAGE(STATUS "OUTPUT_SRC_LIST = ${OUTPUT_SRC_LIST}, CFILES = ${CFILES}, HFILES = ${HFILES}")
+    set(${OUTPUT_SRC_LIST} ${CFILES} ${HFILES} PARENT_SCOPE)
+endfunction()
+
+get_filename_component(R "${CMAKE_CURRENT_LIST_DIR}/.." REALPATH)
+
+# Common protobuf files.  In general, the other subprojects such as HDFS and
+# YARN may rely on definitions in these protobuf files.
+DECLARE_PROTOS(
+    COMMON_PROTOBUF_SRCS
+    ${CMAKE_CURRENT_BINARY_DIR}/protobuf
+    "${R}/hadoop-common-project/hadoop-common/src/main/proto/"
+    ${R}/hadoop-common-project/hadoop-common/src/main/proto/GetUserMappingsProtocol.proto
+    ${R}/hadoop-common-project/hadoop-common/src/main/proto/HAServiceProtocol.proto
+    ${R}/hadoop-common-project/hadoop-common/src/main/proto/IpcConnectionContext.proto
+    ${R}/hadoop-common-project/hadoop-common/src/main/proto/ProtobufRpcEngine.proto
+    ${R}/hadoop-common-project/hadoop-common/src/main/proto/ProtocolInfo.proto
+    ${R}/hadoop-common-project/hadoop-common/src/main/proto/RefreshAuthorizationPolicyProtocol.proto
+    ${R}/hadoop-common-project/hadoop-common/src/main/proto/RefreshCallQueueProtocol.proto
+    ${R}/hadoop-common-project/hadoop-common/src/main/proto/RefreshUserMappingsProtocol.proto
+    ${R}/hadoop-common-project/hadoop-common/src/main/proto/RpcHeader.proto
+    ${R}/hadoop-common-project/hadoop-common/src/main/proto/Security.proto
+    ${R}/hadoop-common-project/hadoop-common/src/main/proto/ZKFCProtocol.proto
+)
+
+# HDFS protobuf files.
+DECLARE_PROTOS(
+    HDFS_PROTOBUF_SRCS
+    ${CMAKE_CURRENT_BINARY_DIR}/protobuf
+    "${R}/hadoop-common-project/hadoop-common/src/main/proto/;${R}/hadoop-hdfs-project/hadoop-hdfs/src/main/proto/"
+    #${R}/hadoop-hdfs-project/hadoop-hdfs/src/main/proto/DatanodeProtocol.proto
+    ${R}/hadoop-hdfs-project/hadoop-hdfs/src/main/proto/HAZKInfo.proto
+    ${R}/hadoop-hdfs-project/hadoop-hdfs/src/main/proto/ClientDatanodeProtocol.proto
+    ${R}/hadoop-hdfs-project/hadoop-hdfs/src/main/proto/acl.proto
+    ${R}/hadoop-hdfs-project/hadoop-hdfs/src/main/proto/fsimage.proto
+    ${R}/hadoop-hdfs-project/hadoop-hdfs/src/main/proto/hdfs.proto
+    ${R}/hadoop-hdfs-project/hadoop-hdfs/src/main/proto/datatransfer.proto
+    ${R}/hadoop-hdfs-project/hadoop-hdfs/src/main/proto/InterDatanodeProtocol.proto
+    #${R}/hadoop-hdfs-project/hadoop-hdfs/src/main/proto/QJournalProtocol.proto
+    ${R}/hadoop-hdfs-project/hadoop-hdfs/src/main/proto/JournalProtocol.proto
+    ${R}/hadoop-hdfs-project/hadoop-hdfs/src/main/proto/NamenodeProtocol.proto
+    ${R}/hadoop-hdfs-project/hadoop-hdfs/src/main/proto/ClientNamenodeProtocol.proto
+)

Added: hadoop/common/branches/HADOOP-10388/hadoop-native-core/common/hadoop_err-unit.c
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HADOOP-10388/hadoop-native-core/common/hadoop_err-unit.c?rev=1591534&view=auto
==============================================================================
--- hadoop/common/branches/HADOOP-10388/hadoop-native-core/common/hadoop_err-unit.c (added)
+++ hadoop/common/branches/HADOOP-10388/hadoop-native-core/common/hadoop_err-unit.c Thu May  1 02:10:15 2014
@@ -0,0 +1,40 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "common/hadoop_err.h"
+#include "common/test.h"
+
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <uv.h>
+
+int main(void)
+{
+    struct hadoop_err *err;
+
+    err = hadoop_lerr_alloc(EINVAL, "foo bar baz %d", 101);
+    EXPECT_STR_EQ("org.apache.hadoop.native.HadoopCore.InvalidRequestException: "
+              "foo bar baz 101", hadoop_err_msg(err));
+    EXPECT_INT_EQ(EINVAL, hadoop_err_code(err));
+    hadoop_err_free(err);
+
+    return EXIT_SUCCESS;
+}
+
+// vim: ts=4:sw=4:tw=79:et

Added: hadoop/common/branches/HADOOP-10388/hadoop-native-core/common/hadoop_err.c
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HADOOP-10388/hadoop-native-core/common/hadoop_err.c?rev=1591534&view=auto
==============================================================================
--- hadoop/common/branches/HADOOP-10388/hadoop-native-core/common/hadoop_err.c (added)
+++ hadoop/common/branches/HADOOP-10388/hadoop-native-core/common/hadoop_err.c Thu May  1 02:10:15 2014
@@ -0,0 +1,199 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "hadoop_err.h"
+
+#include <errno.h>
+#include <stdarg.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <uv.h>
+
+struct hadoop_err {
+    int code;
+    char *msg;
+    int malloced;
+};
+
+#define SUFFIX ": "
+#define SUFFIX_LEN (sizeof(SUFFIX) - 1)
+
+#define RUNTIME_EXCEPTION_ERROR_CODE EFAULT
+
+#define RUNTIME_EXCEPTION_CLASS \
+    "org.apache.hadoop.native.HadoopCore.RuntimeException"
+
+static const struct hadoop_err HADOOP_OOM_ERR = {
+    RUNTIME_EXCEPTION_ERROR_CODE,
+    RUNTIME_EXCEPTION_CLASS": Failed to allcoate memory for an error message.",
+    0
+};
+
+static const struct hadoop_err HADOOP_VSNPRINTF_ERR = {
+    RUNTIME_EXCEPTION_ERROR_CODE,
+    RUNTIME_EXCEPTION_CLASS": vsnprintf error while preparing an error "
+        "message.",
+    0
+};
+
+static const char *errno_to_class(int code)
+{
+    switch (code) {
+    case RUNTIME_EXCEPTION_ERROR_CODE:
+        return RUNTIME_EXCEPTION_CLASS;
+    case EINVAL:
+        return "org.apache.hadoop.native.HadoopCore.InvalidRequestException";
+    case ENOMEM:
+        return "org.apache.hadoop.native.HadoopCore.OutOfMemory";
+    default:
+        return "org.apache.hadoop.native.HadoopCore.IOException";
+    }
+}
+
+static const char *uv_code_to_class(int code)
+{
+    switch (code) {
+    case UV_EOF:
+        return "org.apache.hadoop.native.HadoopCore.EOFException";
+    case UV_EINVAL:
+        return "org.apache.hadoop.native.HadoopCore.InvalidRequestException";
+    case UV_ECONNREFUSED:
+        return "org.apache.hadoop.native.HadoopCore.ConnectionRefusedException";
+    case UV_ENOMEM:
+        return "org.apache.hadoop.native.HadoopCore.OutOfMemoryException";
+    default:
+        return "org.apache.hadoop.native.HadoopCore.IOException";
+    }
+}
+
+struct hadoop_err *hadoop_lerr_alloc(int code, const char *fmt, ...)
+{
+    struct hadoop_err *err = NULL, *ierr = NULL;
+    va_list ap, ap2;
+    const char *class;
+    char test_buf[1];
+    int fmt_len, class_len, msg_len;
+
+    err = calloc(1, sizeof(*err));
+    if (!err) {
+        ierr = (struct hadoop_err*)&HADOOP_OOM_ERR;
+        goto done;
+    }
+    err->code = code;
+    err->malloced = 1;
+    va_start(ap, fmt);
+    va_copy(ap2, ap);
+    fmt_len = vsnprintf(test_buf, sizeof(test_buf), fmt, ap);
+    if (fmt_len < 0) {
+        ierr = (struct hadoop_err*)&HADOOP_VSNPRINTF_ERR;
+        goto done;
+    }
+    class = errno_to_class(code);
+    class_len = strlen(class);
+    msg_len = class_len + SUFFIX_LEN + fmt_len + 1;
+    err->msg = malloc(msg_len);
+    if (!err->msg) {
+        ierr = (struct hadoop_err*)&HADOOP_OOM_ERR;
+        goto done;
+    }
+    strcpy(err->msg, class);
+    strcpy(err->msg + class_len, SUFFIX);
+    vsprintf(err->msg + class_len + SUFFIX_LEN, fmt, ap2);
+    va_end(ap2);
+    va_end(ap);
+
+done:
+    if (ierr) {
+        hadoop_err_free(err);
+        return ierr;
+    }
+    return err;
+}
+
+struct hadoop_err *hadoop_uverr_alloc(int code, const char *fmt, ...)
+{
+    struct hadoop_err *err = NULL, *ierr = NULL;
+    va_list ap, ap2;
+    const char *class;
+    const char *umsg;
+    char test_buf[1];
+    int fmt_len, umsg_len, class_len, msg_len;
+
+    err = calloc(1, sizeof(*err));
+    if (!err) {
+        ierr = (struct hadoop_err*)&HADOOP_OOM_ERR;
+        goto done;
+    }
+    err->code = code;
+    umsg = uv_strerror(code);
+    umsg_len = strlen(umsg);
+    err->malloced = 1;
+    va_start(ap, fmt);
+    va_copy(ap2, ap);
+    fmt_len = vsnprintf(test_buf, sizeof(test_buf), fmt, ap);
+    if (fmt_len < 0) {
+        ierr = (struct hadoop_err*)&HADOOP_VSNPRINTF_ERR;
+        goto done;
+    }
+    class = uv_code_to_class(err->code);
+    class_len = strlen(class);
+    msg_len = class_len + SUFFIX_LEN + umsg_len + SUFFIX_LEN + fmt_len + 1;
+    err->msg = malloc(msg_len);
+    if (!err->msg) {
+        ierr = (struct hadoop_err*)&HADOOP_OOM_ERR;
+        goto done;
+    }
+    strcpy(err->msg, class);
+    strcpy(err->msg + class_len, SUFFIX);
+    strcpy(err->msg + class_len + SUFFIX_LEN, umsg);
+    strcpy(err->msg + class_len + SUFFIX_LEN + umsg_len, SUFFIX);
+    vsprintf(err->msg + class_len + SUFFIX_LEN + umsg_len + SUFFIX_LEN,
+        fmt, ap2);
+    va_end(ap2);
+    va_end(ap);
+
+done:
+    if (ierr) {
+        hadoop_err_free(err);
+        return ierr;
+    }
+    return err;
+}
+
+void hadoop_err_free(struct hadoop_err *err)
+{
+    if (!err)
+        return;
+    if (!err->malloced)
+        return;
+    free(err->msg);
+    free(err);
+}
+
+int hadoop_err_code(const struct hadoop_err *err)
+{
+    return err->code;
+}
+
+const char *hadoop_err_msg(const struct hadoop_err *err)
+{
+    return err->msg;
+}
+
+// vim: ts=4:sw=4:tw=79:et

Added: hadoop/common/branches/HADOOP-10388/hadoop-native-core/common/hadoop_err.h
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HADOOP-10388/hadoop-native-core/common/hadoop_err.h?rev=1591534&view=auto
==============================================================================
--- hadoop/common/branches/HADOOP-10388/hadoop-native-core/common/hadoop_err.h (added)
+++ hadoop/common/branches/HADOOP-10388/hadoop-native-core/common/hadoop_err.h Thu May  1 02:10:15 2014
@@ -0,0 +1,81 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef HADOOP_CORE_COMMON_HADOOP_ERR
+#define HADOOP_CORE_COMMON_HADOOP_ERR
+
+#include <uv.h> /* for uv_loop_t */
+
+/**
+ * A Hadoop error.  This is the libhadoop-core version of an IOException.
+ */
+struct hadoop_err;
+
+/**
+ * Allocate a new local error.
+ *
+ * @param code          Error code.
+ * @param fmt           printf-style format.
+ * @param ...           printf-style arguments.
+ *
+ * @return              A new error message.  This will never be NULL.
+ */
+struct hadoop_err *hadoop_lerr_alloc(int code, const char *fmt, ...)
+    __attribute__((format(printf, 2, 3)));
+
+/**
+ * Allocate a new error object based on a libuv error.
+ *
+ * @param loop          The libuv loop to check.
+ * @param fmt           printf-style format.
+ * @param ...           printf-style arguments.
+ *
+ * @return              A new error message.  This will never be NULL.
+ */
+struct hadoop_err *hadoop_uverr_alloc(int cod, const char *fmt, ...)
+    __attribute__((format(printf, 2, 3)));
+
+/**
+ * Given a hadoop error, get the error code.
+ *
+ * @param err       The hadoop error.
+ *
+ * @return          The error code.
+ */
+int hadoop_err_code(const struct hadoop_err *err);
+
+/**
+ * Given a hadoop error, get the error message.
+ *
+ * @param err       The hadoop error.
+ *
+ * @return          The error message.  Valid until the hadoop_err
+ *                  object is freed.
+ */
+const char *hadoop_err_msg(const struct hadoop_err *err);
+
+/**
+ * Free a hadoop error.
+ *
+ * @param err       The hadoop error.
+ */
+void hadoop_err_free(struct hadoop_err *err);
+
+#endif
+
+// vim: ts=4:sw=4:tw=79:et

Added: hadoop/common/branches/HADOOP-10388/hadoop-native-core/common/net.c
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HADOOP-10388/hadoop-native-core/common/net.c?rev=1591534&view=auto
==============================================================================
--- hadoop/common/branches/HADOOP-10388/hadoop-native-core/common/net.c (added)
+++ hadoop/common/branches/HADOOP-10388/hadoop-native-core/common/net.c Thu May  1 02:10:15 2014
@@ -0,0 +1,31 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <netinet/in.h>
+#include <unistd.h>
+#include <uv.h>
+
+const char *net_ipv4_name(struct sockaddr_in *src, char *dst, size_t size)
+{
+  if (uv_ip4_name(src, dst, size) < 0) {
+    return "(uv_ip4_name error)";
+  }
+  return dst;
+}
+
+// vim: ts=4:sw=4:tw=79:et

Added: hadoop/common/branches/HADOOP-10388/hadoop-native-core/common/net.h
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HADOOP-10388/hadoop-native-core/common/net.h?rev=1591534&view=auto
==============================================================================
--- hadoop/common/branches/HADOOP-10388/hadoop-native-core/common/net.h (added)
+++ hadoop/common/branches/HADOOP-10388/hadoop-native-core/common/net.h Thu May  1 02:10:15 2014
@@ -0,0 +1,30 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef HADOOP_CORE_COMMON_NET
+#define HADOOP_CORE_COMMON_NET
+
+#include <stddef.h>
+
+struct sockaddr_in;
+
+const char *net_ipv4_name(struct sockaddr_in *src, char *dst, size_t size);
+
+#endif
+
+// vim: ts=4:sw=4:tw=79:et

Added: hadoop/common/branches/HADOOP-10388/hadoop-native-core/common/queue.h
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HADOOP-10388/hadoop-native-core/common/queue.h?rev=1591534&view=auto
==============================================================================
--- hadoop/common/branches/HADOOP-10388/hadoop-native-core/common/queue.h (added)
+++ hadoop/common/branches/HADOOP-10388/hadoop-native-core/common/queue.h Thu May  1 02:10:15 2014
@@ -0,0 +1,694 @@
+/*-
+ * Copyright (c) 1991, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ *	@(#)queue.h	8.5 (Berkeley) 8/20/94
+ * $FreeBSD$
+ */
+
+#ifndef _SYS_QUEUE_H_
+#define	_SYS_QUEUE_H_
+
+#include <sys/cdefs.h>
+
+/*
+ * This file defines four types of data structures: singly-linked lists,
+ * singly-linked tail queues, lists and tail queues.
+ *
+ * A singly-linked list is headed by a single forward pointer. The elements
+ * are singly linked for minimum space and pointer manipulation overhead at
+ * the expense of O(n) removal for arbitrary elements. New elements can be
+ * added to the list after an existing element or at the head of the list.
+ * Elements being removed from the head of the list should use the explicit
+ * macro for this purpose for optimum efficiency. A singly-linked list may
+ * only be traversed in the forward direction.  Singly-linked lists are ideal
+ * for applications with large datasets and few or no removals or for
+ * implementing a LIFO queue.
+ *
+ * A singly-linked tail queue is headed by a pair of pointers, one to the
+ * head of the list and the other to the tail of the list. The elements are
+ * singly linked for minimum space and pointer manipulation overhead at the
+ * expense of O(n) removal for arbitrary elements. New elements can be added
+ * to the list after an existing element, at the head of the list, or at the
+ * end of the list. Elements being removed from the head of the tail queue
+ * should use the explicit macro for this purpose for optimum efficiency.
+ * A singly-linked tail queue may only be traversed in the forward direction.
+ * Singly-linked tail queues are ideal for applications with large datasets
+ * and few or no removals or for implementing a FIFO queue.
+ *
+ * A list is headed by a single forward pointer (or an array of forward
+ * pointers for a hash table header). The elements are doubly linked
+ * so that an arbitrary element can be removed without a need to
+ * traverse the list. New elements can be added to the list before
+ * or after an existing element or at the head of the list. A list
+ * may be traversed in either direction.
+ *
+ * A tail queue is headed by a pair of pointers, one to the head of the
+ * list and the other to the tail of the list. The elements are doubly
+ * linked so that an arbitrary element can be removed without a need to
+ * traverse the list. New elements can be added to the list before or
+ * after an existing element, at the head of the list, or at the end of
+ * the list. A tail queue may be traversed in either direction.
+ *
+ * For details on the use of these macros, see the queue(3) manual page.
+ *
+ *
+ *				SLIST	LIST	STAILQ	TAILQ
+ * _HEAD			+	+	+	+
+ * _HEAD_INITIALIZER		+	+	+	+
+ * _ENTRY			+	+	+	+
+ * _INIT			+	+	+	+
+ * _EMPTY			+	+	+	+
+ * _FIRST			+	+	+	+
+ * _NEXT			+	+	+	+
+ * _PREV			-	+	-	+
+ * _LAST			-	-	+	+
+ * _FOREACH			+	+	+	+
+ * _FOREACH_FROM		+	+	+	+
+ * _FOREACH_SAFE		+	+	+	+
+ * _FOREACH_FROM_SAFE		+	+	+	+
+ * _FOREACH_REVERSE		-	-	-	+
+ * _FOREACH_REVERSE_FROM	-	-	-	+
+ * _FOREACH_REVERSE_SAFE	-	-	-	+
+ * _FOREACH_REVERSE_FROM_SAFE	-	-	-	+
+ * _INSERT_HEAD			+	+	+	+
+ * _INSERT_BEFORE		-	+	-	+
+ * _INSERT_AFTER		+	+	+	+
+ * _INSERT_TAIL			-	-	+	+
+ * _CONCAT			-	-	+	+
+ * _REMOVE_AFTER		+	-	+	-
+ * _REMOVE_HEAD			+	-	+	-
+ * _REMOVE			+	+	+	+
+ * _SWAP			+	+	+	+
+ *
+ */
+#ifdef QUEUE_MACRO_DEBUG
+/* Store the last 2 places the queue element or head was altered */
+struct qm_trace {
+	unsigned long	 lastline;
+	unsigned long	 prevline;
+	const char	*lastfile;
+	const char	*prevfile;
+};
+
+#define	TRACEBUF	struct qm_trace trace;
+#define	TRACEBUF_INITIALIZER	{ __FILE__, __LINE__, NULL, 0 } ,
+#define	TRASHIT(x)	do {(x) = (void *)-1;} while (0)
+#define	QMD_SAVELINK(name, link)	void **name = (void *)&(link)
+
+#define	QMD_TRACE_HEAD(head) do {					\
+	(head)->trace.prevline = (head)->trace.lastline;		\
+	(head)->trace.prevfile = (head)->trace.lastfile;		\
+	(head)->trace.lastline = __LINE__;				\
+	(head)->trace.lastfile = __FILE__;				\
+} while (0)
+
+#define	QMD_TRACE_ELEM(elem) do {					\
+	(elem)->trace.prevline = (elem)->trace.lastline;		\
+	(elem)->trace.prevfile = (elem)->trace.lastfile;		\
+	(elem)->trace.lastline = __LINE__;				\
+	(elem)->trace.lastfile = __FILE__;				\
+} while (0)
+
+#else
+#define	QMD_TRACE_ELEM(elem)
+#define	QMD_TRACE_HEAD(head)
+#define	QMD_SAVELINK(name, link)
+#define	TRACEBUF
+#define	TRACEBUF_INITIALIZER
+#define	TRASHIT(x)
+#endif	/* QUEUE_MACRO_DEBUG */
+
+/*
+ * Singly-linked List declarations.
+ */
+#define	SLIST_HEAD(name, type)						\
+struct name {								\
+	struct type *slh_first;	/* first element */			\
+}
+
+#define	SLIST_HEAD_INITIALIZER(head)					\
+	{ NULL }
+
+#define	SLIST_ENTRY(type)						\
+struct {								\
+	struct type *sle_next;	/* next element */			\
+}
+
+/*
+ * Singly-linked List functions.
+ */
+#define	SLIST_EMPTY(head)	((head)->slh_first == NULL)
+
+#define	SLIST_FIRST(head)	((head)->slh_first)
+
+#define	SLIST_FOREACH(var, head, field)					\
+	for ((var) = SLIST_FIRST((head));				\
+	    (var);							\
+	    (var) = SLIST_NEXT((var), field))
+
+#define	SLIST_FOREACH_FROM(var, head, field)				\
+	for ((var) = ((var) ? (var) : SLIST_FIRST((head)));		\
+	    (var);							\
+	    (var) = SLIST_NEXT((var), field))
+
+#define	SLIST_FOREACH_SAFE(var, head, field, tvar)			\
+	for ((var) = SLIST_FIRST((head));				\
+	    (var) && ((tvar) = SLIST_NEXT((var), field), 1);		\
+	    (var) = (tvar))
+
+#define	SLIST_FOREACH_FROM_SAFE(var, head, field, tvar)			\
+	for ((var) = ((var) ? (var) : SLIST_FIRST((head)));		\
+	    (var) && ((tvar) = SLIST_NEXT((var), field), 1);		\
+	    (var) = (tvar))
+
+#define	SLIST_FOREACH_PREVPTR(var, varp, head, field)			\
+	for ((varp) = &SLIST_FIRST((head));				\
+	    ((var) = *(varp)) != NULL;					\
+	    (varp) = &SLIST_NEXT((var), field))
+
+#define	SLIST_INIT(head) do {						\
+	SLIST_FIRST((head)) = NULL;					\
+} while (0)
+
+#define	SLIST_INSERT_AFTER(slistelm, elm, field) do {			\
+	SLIST_NEXT((elm), field) = SLIST_NEXT((slistelm), field);	\
+	SLIST_NEXT((slistelm), field) = (elm);				\
+} while (0)
+
+#define	SLIST_INSERT_HEAD(head, elm, field) do {			\
+	SLIST_NEXT((elm), field) = SLIST_FIRST((head));			\
+	SLIST_FIRST((head)) = (elm);					\
+} while (0)
+
+#define	SLIST_NEXT(elm, field)	((elm)->field.sle_next)
+
+#define	SLIST_REMOVE(head, elm, type, field) do {			\
+	QMD_SAVELINK(oldnext, (elm)->field.sle_next);			\
+	if (SLIST_FIRST((head)) == (elm)) {				\
+		SLIST_REMOVE_HEAD((head), field);			\
+	}								\
+	else {								\
+		struct type *curelm = SLIST_FIRST((head));		\
+		while (SLIST_NEXT(curelm, field) != (elm))		\
+			curelm = SLIST_NEXT(curelm, field);		\
+		SLIST_REMOVE_AFTER(curelm, field);			\
+	}								\
+	TRASHIT(*oldnext);						\
+} while (0)
+
+#define SLIST_REMOVE_AFTER(elm, field) do {				\
+	SLIST_NEXT(elm, field) =					\
+	    SLIST_NEXT(SLIST_NEXT(elm, field), field);			\
+} while (0)
+
+#define	SLIST_REMOVE_HEAD(head, field) do {				\
+	SLIST_FIRST((head)) = SLIST_NEXT(SLIST_FIRST((head)), field);	\
+} while (0)
+
+#define SLIST_SWAP(head1, head2, type) do {				\
+	struct type *swap_first = SLIST_FIRST(head1);			\
+	SLIST_FIRST(head1) = SLIST_FIRST(head2);			\
+	SLIST_FIRST(head2) = swap_first;				\
+} while (0)
+
+/*
+ * Singly-linked Tail queue declarations.
+ */
+#define	STAILQ_HEAD(name, type)						\
+struct name {								\
+	struct type *stqh_first;/* first element */			\
+	struct type **stqh_last;/* addr of last next element */		\
+}
+
+#define	STAILQ_HEAD_INITIALIZER(head)					\
+	{ NULL, &(head).stqh_first }
+
+#define	STAILQ_ENTRY(type)						\
+struct {								\
+	struct type *stqe_next;	/* next element */			\
+}
+
+/*
+ * Singly-linked Tail queue functions.
+ */
+#define	STAILQ_CONCAT(head1, head2) do {				\
+	if (!STAILQ_EMPTY((head2))) {					\
+		*(head1)->stqh_last = (head2)->stqh_first;		\
+		(head1)->stqh_last = (head2)->stqh_last;		\
+		STAILQ_INIT((head2));					\
+	}								\
+} while (0)
+
+#define	STAILQ_EMPTY(head)	((head)->stqh_first == NULL)
+
+#define	STAILQ_FIRST(head)	((head)->stqh_first)
+
+#define	STAILQ_FOREACH(var, head, field)				\
+	for((var) = STAILQ_FIRST((head));				\
+	   (var);							\
+	   (var) = STAILQ_NEXT((var), field))
+
+#define	STAILQ_FOREACH_FROM(var, head, field)				\
+	for ((var) = ((var) ? (var) : STAILQ_FIRST((head)));		\
+	   (var);							\
+	   (var) = STAILQ_NEXT((var), field))
+
+#define	STAILQ_FOREACH_SAFE(var, head, field, tvar)			\
+	for ((var) = STAILQ_FIRST((head));				\
+	    (var) && ((tvar) = STAILQ_NEXT((var), field), 1);		\
+	    (var) = (tvar))
+
+#define	STAILQ_FOREACH_FROM_SAFE(var, head, field, tvar)		\
+	for ((var) = ((var) ? (var) : STAILQ_FIRST((head)));		\
+	    (var) && ((tvar) = STAILQ_NEXT((var), field), 1);		\
+	    (var) = (tvar))
+
+#define	STAILQ_INIT(head) do {						\
+	STAILQ_FIRST((head)) = NULL;					\
+	(head)->stqh_last = &STAILQ_FIRST((head));			\
+} while (0)
+
+#define	STAILQ_INSERT_AFTER(head, tqelm, elm, field) do {		\
+	if ((STAILQ_NEXT((elm), field) = STAILQ_NEXT((tqelm), field)) == NULL)\
+		(head)->stqh_last = &STAILQ_NEXT((elm), field);		\
+	STAILQ_NEXT((tqelm), field) = (elm);				\
+} while (0)
+
+#define	STAILQ_INSERT_HEAD(head, elm, field) do {			\
+	if ((STAILQ_NEXT((elm), field) = STAILQ_FIRST((head))) == NULL)	\
+		(head)->stqh_last = &STAILQ_NEXT((elm), field);		\
+	STAILQ_FIRST((head)) = (elm);					\
+} while (0)
+
+#define	STAILQ_INSERT_TAIL(head, elm, field) do {			\
+	STAILQ_NEXT((elm), field) = NULL;				\
+	*(head)->stqh_last = (elm);					\
+	(head)->stqh_last = &STAILQ_NEXT((elm), field);			\
+} while (0)
+
+#define	STAILQ_LAST(head, type, field)					\
+	(STAILQ_EMPTY((head)) ? NULL :					\
+	    __containerof((head)->stqh_last, struct type, field.stqe_next))
+
+#define	STAILQ_NEXT(elm, field)	((elm)->field.stqe_next)
+
+#define	STAILQ_REMOVE(head, elm, type, field) do {			\
+	QMD_SAVELINK(oldnext, (elm)->field.stqe_next);			\
+	if (STAILQ_FIRST((head)) == (elm)) {				\
+		STAILQ_REMOVE_HEAD((head), field);			\
+	}								\
+	else {								\
+		struct type *curelm = STAILQ_FIRST((head));		\
+		while (STAILQ_NEXT(curelm, field) != (elm))		\
+			curelm = STAILQ_NEXT(curelm, field);		\
+		STAILQ_REMOVE_AFTER(head, curelm, field);		\
+	}								\
+	TRASHIT(*oldnext);						\
+} while (0)
+
+#define STAILQ_REMOVE_AFTER(head, elm, field) do {			\
+	if ((STAILQ_NEXT(elm, field) =					\
+	     STAILQ_NEXT(STAILQ_NEXT(elm, field), field)) == NULL)	\
+		(head)->stqh_last = &STAILQ_NEXT((elm), field);		\
+} while (0)
+
+#define	STAILQ_REMOVE_HEAD(head, field) do {				\
+	if ((STAILQ_FIRST((head)) =					\
+	     STAILQ_NEXT(STAILQ_FIRST((head)), field)) == NULL)		\
+		(head)->stqh_last = &STAILQ_FIRST((head));		\
+} while (0)
+
+#define STAILQ_SWAP(head1, head2, type) do {				\
+	struct type *swap_first = STAILQ_FIRST(head1);			\
+	struct type **swap_last = (head1)->stqh_last;			\
+	STAILQ_FIRST(head1) = STAILQ_FIRST(head2);			\
+	(head1)->stqh_last = (head2)->stqh_last;			\
+	STAILQ_FIRST(head2) = swap_first;				\
+	(head2)->stqh_last = swap_last;					\
+	if (STAILQ_EMPTY(head1))					\
+		(head1)->stqh_last = &STAILQ_FIRST(head1);		\
+	if (STAILQ_EMPTY(head2))					\
+		(head2)->stqh_last = &STAILQ_FIRST(head2);		\
+} while (0)
+
+
+/*
+ * List declarations.
+ */
+#define	LIST_HEAD(name, type)						\
+struct name {								\
+	struct type *lh_first;	/* first element */			\
+}
+
+#define	LIST_HEAD_INITIALIZER(head)					\
+	{ NULL }
+
+#define	LIST_ENTRY(type)						\
+struct {								\
+	struct type *le_next;	/* next element */			\
+	struct type **le_prev;	/* address of previous next element */	\
+}
+
+/*
+ * List functions.
+ */
+
+#if (defined(_KERNEL) && defined(INVARIANTS))
+#define	QMD_LIST_CHECK_HEAD(head, field) do {				\
+	if (LIST_FIRST((head)) != NULL &&				\
+	    LIST_FIRST((head))->field.le_prev !=			\
+	     &LIST_FIRST((head)))					\
+		panic("Bad list head %p first->prev != head", (head));	\
+} while (0)
+
+#define	QMD_LIST_CHECK_NEXT(elm, field) do {				\
+	if (LIST_NEXT((elm), field) != NULL &&				\
+	    LIST_NEXT((elm), field)->field.le_prev !=			\
+	     &((elm)->field.le_next))					\
+	     	panic("Bad link elm %p next->prev != elm", (elm));	\
+} while (0)
+
+#define	QMD_LIST_CHECK_PREV(elm, field) do {				\
+	if (*(elm)->field.le_prev != (elm))				\
+		panic("Bad link elm %p prev->next != elm", (elm));	\
+} while (0)
+#else
+#define	QMD_LIST_CHECK_HEAD(head, field)
+#define	QMD_LIST_CHECK_NEXT(elm, field)
+#define	QMD_LIST_CHECK_PREV(elm, field)
+#endif /* (_KERNEL && INVARIANTS) */
+
+#define	LIST_EMPTY(head)	((head)->lh_first == NULL)
+
+#define	LIST_FIRST(head)	((head)->lh_first)
+
+#define	LIST_FOREACH(var, head, field)					\
+	for ((var) = LIST_FIRST((head));				\
+	    (var);							\
+	    (var) = LIST_NEXT((var), field))
+
+#define	LIST_FOREACH_FROM(var, head, field)				\
+	for ((var) = ((var) ? (var) : LIST_FIRST((head)));		\
+	    (var);							\
+	    (var) = LIST_NEXT((var), field))
+
+#define	LIST_FOREACH_SAFE(var, head, field, tvar)			\
+	for ((var) = LIST_FIRST((head));				\
+	    (var) && ((tvar) = LIST_NEXT((var), field), 1);		\
+	    (var) = (tvar))
+
+#define	LIST_FOREACH_FROM_SAFE(var, head, field, tvar)			\
+	for ((var) = ((var) ? (var) : LIST_FIRST((head)));		\
+	    (var) && ((tvar) = LIST_NEXT((var), field), 1);		\
+	    (var) = (tvar))
+
+#define	LIST_INIT(head) do {						\
+	LIST_FIRST((head)) = NULL;					\
+} while (0)
+
+#define	LIST_INSERT_AFTER(listelm, elm, field) do {			\
+	QMD_LIST_CHECK_NEXT(listelm, field);				\
+	if ((LIST_NEXT((elm), field) = LIST_NEXT((listelm), field)) != NULL)\
+		LIST_NEXT((listelm), field)->field.le_prev =		\
+		    &LIST_NEXT((elm), field);				\
+	LIST_NEXT((listelm), field) = (elm);				\
+	(elm)->field.le_prev = &LIST_NEXT((listelm), field);		\
+} while (0)
+
+#define	LIST_INSERT_BEFORE(listelm, elm, field) do {			\
+	QMD_LIST_CHECK_PREV(listelm, field);				\
+	(elm)->field.le_prev = (listelm)->field.le_prev;		\
+	LIST_NEXT((elm), field) = (listelm);				\
+	*(listelm)->field.le_prev = (elm);				\
+	(listelm)->field.le_prev = &LIST_NEXT((elm), field);		\
+} while (0)
+
+#define	LIST_INSERT_HEAD(head, elm, field) do {				\
+	QMD_LIST_CHECK_HEAD((head), field);				\
+	if ((LIST_NEXT((elm), field) = LIST_FIRST((head))) != NULL)	\
+		LIST_FIRST((head))->field.le_prev = &LIST_NEXT((elm), field);\
+	LIST_FIRST((head)) = (elm);					\
+	(elm)->field.le_prev = &LIST_FIRST((head));			\
+} while (0)
+
+#define	LIST_NEXT(elm, field)	((elm)->field.le_next)
+
+#define	LIST_PREV(elm, head, type, field)				\
+	((elm)->field.le_prev == &LIST_FIRST((head)) ? NULL :		\
+	    __containerof((elm)->field.le_prev, struct type, field.le_next))
+
+#define	LIST_REMOVE(elm, field) do {					\
+	QMD_SAVELINK(oldnext, (elm)->field.le_next);			\
+	QMD_SAVELINK(oldprev, (elm)->field.le_prev);			\
+	QMD_LIST_CHECK_NEXT(elm, field);				\
+	QMD_LIST_CHECK_PREV(elm, field);				\
+	if (LIST_NEXT((elm), field) != NULL)				\
+		LIST_NEXT((elm), field)->field.le_prev = 		\
+		    (elm)->field.le_prev;				\
+	*(elm)->field.le_prev = LIST_NEXT((elm), field);		\
+	TRASHIT(*oldnext);						\
+	TRASHIT(*oldprev);						\
+} while (0)
+
+#define LIST_SWAP(head1, head2, type, field) do {			\
+	struct type *swap_tmp = LIST_FIRST((head1));			\
+	LIST_FIRST((head1)) = LIST_FIRST((head2));			\
+	LIST_FIRST((head2)) = swap_tmp;					\
+	if ((swap_tmp = LIST_FIRST((head1))) != NULL)			\
+		swap_tmp->field.le_prev = &LIST_FIRST((head1));		\
+	if ((swap_tmp = LIST_FIRST((head2))) != NULL)			\
+		swap_tmp->field.le_prev = &LIST_FIRST((head2));		\
+} while (0)
+
+/*
+ * Tail queue declarations.
+ */
+#define	TAILQ_HEAD(name, type)						\
+struct name {								\
+	struct type *tqh_first;	/* first element */			\
+	struct type **tqh_last;	/* addr of last next element */		\
+	TRACEBUF							\
+}
+
+#define	TAILQ_HEAD_INITIALIZER(head)					\
+	{ NULL, &(head).tqh_first, TRACEBUF_INITIALIZER }
+
+#define	TAILQ_ENTRY(type)						\
+struct {								\
+	struct type *tqe_next;	/* next element */			\
+	struct type **tqe_prev;	/* address of previous next element */	\
+	TRACEBUF							\
+}
+
+/*
+ * Tail queue functions.
+ */
+#if (defined(_KERNEL) && defined(INVARIANTS))
+#define	QMD_TAILQ_CHECK_HEAD(head, field) do {				\
+	if (!TAILQ_EMPTY(head) &&					\
+	    TAILQ_FIRST((head))->field.tqe_prev !=			\
+	     &TAILQ_FIRST((head)))					\
+		panic("Bad tailq head %p first->prev != head", (head));	\
+} while (0)
+
+#define	QMD_TAILQ_CHECK_TAIL(head, field) do {				\
+	if (*(head)->tqh_last != NULL)					\
+	    	panic("Bad tailq NEXT(%p->tqh_last) != NULL", (head)); 	\
+} while (0)
+
+#define	QMD_TAILQ_CHECK_NEXT(elm, field) do {				\
+	if (TAILQ_NEXT((elm), field) != NULL &&				\
+	    TAILQ_NEXT((elm), field)->field.tqe_prev !=			\
+	     &((elm)->field.tqe_next))					\
+		panic("Bad link elm %p next->prev != elm", (elm));	\
+} while (0)
+
+#define	QMD_TAILQ_CHECK_PREV(elm, field) do {				\
+	if (*(elm)->field.tqe_prev != (elm))				\
+		panic("Bad link elm %p prev->next != elm", (elm));	\
+} while (0)
+#else
+#define	QMD_TAILQ_CHECK_HEAD(head, field)
+#define	QMD_TAILQ_CHECK_TAIL(head, headname)
+#define	QMD_TAILQ_CHECK_NEXT(elm, field)
+#define	QMD_TAILQ_CHECK_PREV(elm, field)
+#endif /* (_KERNEL && INVARIANTS) */
+
+#define	TAILQ_CONCAT(head1, head2, field) do {				\
+	if (!TAILQ_EMPTY(head2)) {					\
+		*(head1)->tqh_last = (head2)->tqh_first;		\
+		(head2)->tqh_first->field.tqe_prev = (head1)->tqh_last;	\
+		(head1)->tqh_last = (head2)->tqh_last;			\
+		TAILQ_INIT((head2));					\
+		QMD_TRACE_HEAD(head1);					\
+		QMD_TRACE_HEAD(head2);					\
+	}								\
+} while (0)
+
+#define	TAILQ_EMPTY(head)	((head)->tqh_first == NULL)
+
+#define	TAILQ_FIRST(head)	((head)->tqh_first)
+
+#define	TAILQ_FOREACH(var, head, field)					\
+	for ((var) = TAILQ_FIRST((head));				\
+	    (var);							\
+	    (var) = TAILQ_NEXT((var), field))
+
+#define	TAILQ_FOREACH_FROM(var, head, field)				\
+	for ((var) = ((var) ? (var) : TAILQ_FIRST((head)));		\
+	    (var);							\
+	    (var) = TAILQ_NEXT((var), field))
+
+#define	TAILQ_FOREACH_SAFE(var, head, field, tvar)			\
+	for ((var) = TAILQ_FIRST((head));				\
+	    (var) && ((tvar) = TAILQ_NEXT((var), field), 1);		\
+	    (var) = (tvar))
+
+#define	TAILQ_FOREACH_FROM_SAFE(var, head, field, tvar)			\
+	for ((var) = ((var) ? (var) : TAILQ_FIRST((head)));		\
+	    (var) && ((tvar) = TAILQ_NEXT((var), field), 1);		\
+	    (var) = (tvar))
+
+#define	TAILQ_FOREACH_REVERSE(var, head, headname, field)		\
+	for ((var) = TAILQ_LAST((head), headname);			\
+	    (var);							\
+	    (var) = TAILQ_PREV((var), headname, field))
+
+#define	TAILQ_FOREACH_REVERSE_FROM(var, head, headname, field)		\
+	for ((var) = ((var) ? (var) : TAILQ_LAST((head), headname));	\
+	    (var);							\
+	    (var) = TAILQ_PREV((var), headname, field))
+
+#define	TAILQ_FOREACH_REVERSE_SAFE(var, head, headname, field, tvar)	\
+	for ((var) = TAILQ_LAST((head), headname);			\
+	    (var) && ((tvar) = TAILQ_PREV((var), headname, field), 1);	\
+	    (var) = (tvar))
+
+#define	TAILQ_FOREACH_REVERSE_FROM_SAFE(var, head, headname, field, tvar) \
+	for ((var) = ((var) ? (var) : TAILQ_LAST((head), headname));	\
+	    (var) && ((tvar) = TAILQ_PREV((var), headname, field), 1);	\
+	    (var) = (tvar))
+
+#define	TAILQ_INIT(head) do {						\
+	TAILQ_FIRST((head)) = NULL;					\
+	(head)->tqh_last = &TAILQ_FIRST((head));			\
+	QMD_TRACE_HEAD(head);						\
+} while (0)
+
+#define	TAILQ_INSERT_AFTER(head, listelm, elm, field) do {		\
+	QMD_TAILQ_CHECK_NEXT(listelm, field);				\
+	if ((TAILQ_NEXT((elm), field) = TAILQ_NEXT((listelm), field)) != NULL)\
+		TAILQ_NEXT((elm), field)->field.tqe_prev = 		\
+		    &TAILQ_NEXT((elm), field);				\
+	else {								\
+		(head)->tqh_last = &TAILQ_NEXT((elm), field);		\
+		QMD_TRACE_HEAD(head);					\
+	}								\
+	TAILQ_NEXT((listelm), field) = (elm);				\
+	(elm)->field.tqe_prev = &TAILQ_NEXT((listelm), field);		\
+	QMD_TRACE_ELEM(&(elm)->field);					\
+	QMD_TRACE_ELEM(&listelm->field);				\
+} while (0)
+
+#define	TAILQ_INSERT_BEFORE(listelm, elm, field) do {			\
+	QMD_TAILQ_CHECK_PREV(listelm, field);				\
+	(elm)->field.tqe_prev = (listelm)->field.tqe_prev;		\
+	TAILQ_NEXT((elm), field) = (listelm);				\
+	*(listelm)->field.tqe_prev = (elm);				\
+	(listelm)->field.tqe_prev = &TAILQ_NEXT((elm), field);		\
+	QMD_TRACE_ELEM(&(elm)->field);					\
+	QMD_TRACE_ELEM(&listelm->field);				\
+} while (0)
+
+#define	TAILQ_INSERT_HEAD(head, elm, field) do {			\
+	QMD_TAILQ_CHECK_HEAD(head, field);				\
+	if ((TAILQ_NEXT((elm), field) = TAILQ_FIRST((head))) != NULL)	\
+		TAILQ_FIRST((head))->field.tqe_prev =			\
+		    &TAILQ_NEXT((elm), field);				\
+	else								\
+		(head)->tqh_last = &TAILQ_NEXT((elm), field);		\
+	TAILQ_FIRST((head)) = (elm);					\
+	(elm)->field.tqe_prev = &TAILQ_FIRST((head));			\
+	QMD_TRACE_HEAD(head);						\
+	QMD_TRACE_ELEM(&(elm)->field);					\
+} while (0)
+
+#define	TAILQ_INSERT_TAIL(head, elm, field) do {			\
+	QMD_TAILQ_CHECK_TAIL(head, field);				\
+	TAILQ_NEXT((elm), field) = NULL;				\
+	(elm)->field.tqe_prev = (head)->tqh_last;			\
+	*(head)->tqh_last = (elm);					\
+	(head)->tqh_last = &TAILQ_NEXT((elm), field);			\
+	QMD_TRACE_HEAD(head);						\
+	QMD_TRACE_ELEM(&(elm)->field);					\
+} while (0)
+
+#define	TAILQ_LAST(head, headname)					\
+	(*(((struct headname *)((head)->tqh_last))->tqh_last))
+
+#define	TAILQ_NEXT(elm, field) ((elm)->field.tqe_next)
+
+#define	TAILQ_PREV(elm, headname, field)				\
+	(*(((struct headname *)((elm)->field.tqe_prev))->tqh_last))
+
+#define	TAILQ_REMOVE(head, elm, field) do {				\
+	QMD_SAVELINK(oldnext, (elm)->field.tqe_next);			\
+	QMD_SAVELINK(oldprev, (elm)->field.tqe_prev);			\
+	QMD_TAILQ_CHECK_NEXT(elm, field);				\
+	QMD_TAILQ_CHECK_PREV(elm, field);				\
+	if ((TAILQ_NEXT((elm), field)) != NULL)				\
+		TAILQ_NEXT((elm), field)->field.tqe_prev = 		\
+		    (elm)->field.tqe_prev;				\
+	else {								\
+		(head)->tqh_last = (elm)->field.tqe_prev;		\
+		QMD_TRACE_HEAD(head);					\
+	}								\
+	*(elm)->field.tqe_prev = TAILQ_NEXT((elm), field);		\
+	TRASHIT(*oldnext);						\
+	TRASHIT(*oldprev);						\
+	QMD_TRACE_ELEM(&(elm)->field);					\
+} while (0)
+
+#define TAILQ_SWAP(head1, head2, type, field) do {			\
+	struct type *swap_first = (head1)->tqh_first;			\
+	struct type **swap_last = (head1)->tqh_last;			\
+	(head1)->tqh_first = (head2)->tqh_first;			\
+	(head1)->tqh_last = (head2)->tqh_last;				\
+	(head2)->tqh_first = swap_first;				\
+	(head2)->tqh_last = swap_last;					\
+	if ((swap_first = (head1)->tqh_first) != NULL)			\
+		swap_first->field.tqe_prev = &(head1)->tqh_first;	\
+	else								\
+		(head1)->tqh_last = &(head1)->tqh_first;		\
+	if ((swap_first = (head2)->tqh_first) != NULL)			\
+		swap_first->field.tqe_prev = &(head2)->tqh_first;	\
+	else								\
+		(head2)->tqh_last = &(head2)->tqh_first;		\
+} while (0)
+
+#endif /* !_SYS_QUEUE_H_ */

Added: hadoop/common/branches/HADOOP-10388/hadoop-native-core/common/string.c
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HADOOP-10388/hadoop-native-core/common/string.c?rev=1591534&view=auto
==============================================================================
--- hadoop/common/branches/HADOOP-10388/hadoop-native-core/common/string.c (added)
+++ hadoop/common/branches/HADOOP-10388/hadoop-native-core/common/string.c Thu May  1 02:10:15 2014
@@ -0,0 +1,46 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "common/string.h"
+
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+void hex_buf_print(FILE *fp, const void *buf, int32_t buf_len,
+                   const char *fmt, ...)
+{
+    int32_t i, j = 0;
+    va_list ap;
+    const uint8_t *b = buf;
+
+    va_start(ap, fmt);
+    vfprintf(fp, fmt, ap);
+    va_end(ap);
+    for (i = 0; i < buf_len; i++) {
+        const char *suffix = " ";
+
+        if (++j == 8) {
+            suffix = "\n";
+            j = 0;
+        }
+        fprintf(fp, "%02x%s", b[i], suffix);
+    }
+}
+
+// vim: ts=4:sw=4:tw=79:et

Added: hadoop/common/branches/HADOOP-10388/hadoop-native-core/common/string.h
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HADOOP-10388/hadoop-native-core/common/string.h?rev=1591534&view=auto
==============================================================================
--- hadoop/common/branches/HADOOP-10388/hadoop-native-core/common/string.h (added)
+++ hadoop/common/branches/HADOOP-10388/hadoop-native-core/common/string.h Thu May  1 02:10:15 2014
@@ -0,0 +1,39 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef HADOOP_CORE_COMMON_STRING
+#define HADOOP_CORE_COMMON_STRING
+
+#include <stdio.h>
+#include <stdint.h>
+
+/**
+ * Print out a buffer in hexadecimal.
+ *
+ * @param fp        The FILE* to print to.
+ * @param buf       The buffer to print.
+ * @param buf_len   The length of the buffer.
+ * @param fmt       Printf-style format.
+ * @param ...       Printf-style arguments.
+ */
+void hex_buf_print(FILE *fp, const void *buf, int32_t buf_len,
+        const char *fmt, ...) __attribute__((format(printf, 4, 5)));
+
+#endif
+
+// vim: ts=4:sw=4:tw=79:et

Added: hadoop/common/branches/HADOOP-10388/hadoop-native-core/common/test.c
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HADOOP-10388/hadoop-native-core/common/test.c?rev=1591534&view=auto
==============================================================================
--- hadoop/common/branches/HADOOP-10388/hadoop-native-core/common/test.c (added)
+++ hadoop/common/branches/HADOOP-10388/hadoop-native-core/common/test.c Thu May  1 02:10:15 2014
@@ -0,0 +1,136 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "common/test.h"
+
+#include <dirent.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <stdarg.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+
+void fail(const char *fmt, ...)
+{
+    va_list ap;
+
+    va_start(ap, fmt);
+    vfprintf(stderr, fmt, ap);
+    va_end(ap);
+    exit(1);
+}
+
+static int vexpect_decode(const char *expected, const char *text, int ty,
+        const char *str)
+{
+    switch (ty) {
+    case TEST_ERROR_EQ:
+        if (strcmp(expected, str) != 0) {
+            fprintf(stderr, "error: expected '%s', but got '%s', which "
+                   "is not equal. %s\n", expected, str, text);
+            return -1;
+        }
+        break;
+    case TEST_ERROR_GE:
+        if (strcmp(expected, str) > 0) {
+            fprintf(stderr, "error: expected '%s', but got '%s'. "
+                   "Expected something greater or equal.  %s\n",
+                   expected, str, text);
+            return -1;
+        }
+        break;
+    case TEST_ERROR_GT:
+        if (strcmp(expected, str) >= 0) {
+            fprintf(stderr, "error: expected '%s', but got '%s'. "
+                   "Expected something greater.  %s\n",
+                   expected, str, text);
+            return -1;
+        }
+        break;
+    case TEST_ERROR_LE:
+        if (strcmp(expected, str) < 0) {
+            fprintf(stderr, "error: expected '%s', but got '%s'. "
+                   "Expected something less or equal.  %s\n",
+                   expected, str, text);
+            return -1;
+        }
+        break;
+    case TEST_ERROR_LT:
+        if (strcmp(expected, str) <= 0) {
+            fprintf(stderr, "error: expected '%s', but got '%s'. "
+                   "Expected something less.  %s\n",
+                   expected, str, text);
+            return -1;
+        }
+        break;
+    case TEST_ERROR_NE:
+        if (strcmp(expected, str) == 0) {
+            fprintf(stderr, "error: did not expect '%s': '%s'\n",
+                   expected, text);
+            return -1;
+        }
+        break;
+    default:
+        fprintf(stderr, "runtime error: invalid type %d passed in: '%s'\n",
+                ty, text);
+        return -1;
+    }
+    return 0;
+}
+
+int vexpect(const char *expected, const char *text, int ty,
+        const char *fmt, va_list ap)
+{
+    char *str = NULL;
+    int ret;
+
+    if (vasprintf(&str, fmt, ap) < 0) { // TODO: portability
+        fprintf(stderr, "error: vasprintf failed: %s\n", text);
+        return -1;
+    }
+    ret = vexpect_decode(expected, text, ty, str);
+    free(str);
+    return ret;
+}
+
+int expect(const char *expected, const char *text, int ty,
+        const char *fmt, ...)
+{
+    int ret;
+    va_list ap;
+
+    va_start(ap, fmt);
+    ret = vexpect(expected, text, ty, fmt, ap);
+    va_end(ap);
+    return ret;
+}
+
+void *xcalloc(size_t len)
+{
+    void *v = calloc(1, len);
+    if (!v) {
+        abort();
+    }
+    return v;
+}
+
+// vim: ts=4:sw=4:tw=79:et

Added: hadoop/common/branches/HADOOP-10388/hadoop-native-core/common/test.h
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HADOOP-10388/hadoop-native-core/common/test.h?rev=1591534&view=auto
==============================================================================
--- hadoop/common/branches/HADOOP-10388/hadoop-native-core/common/test.h (added)
+++ hadoop/common/branches/HADOOP-10388/hadoop-native-core/common/test.h Thu May  1 02:10:15 2014
@@ -0,0 +1,154 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef HADOOP_CORE_COMMON_TEST_H
+#define HADOOP_CORE_COMMON_TEST_H
+
+#include <inttypes.h> /* for PRIdPTR */
+#include <stdarg.h> /* for va_list */
+#include <unistd.h> /* for size_t */
+
+#define TEST_ERROR_EQ 0
+#define TEST_ERROR_GE 1
+#define TEST_ERROR_GT 2
+#define TEST_ERROR_LE 3
+#define TEST_ERROR_LT 4
+#define TEST_ERROR_NE 5
+
+/**
+ * Fail with an error message.
+ *
+ * @param fmt       printf-style format string.
+ * @param ...       printf-style arguments.
+ */
+void fail(const char *fmt, ...);
+
+/**
+ * Check for a test condition.
+ *
+ * @param expected  The string which is expected.
+ * @param text      Some text that will be printed out if the test
+ *                      condition fails.
+ * @param ty        Comparison type.  See TEST_ERROR_* constants.
+ * @param fmt       printf-style format string.
+ * @param ap        printf-style arguments.
+ *
+ * @return      0 on success; 1 on failure.
+ */
+int vexpect(const char *expected, const char *text, int ty,
+        const char *fmt, va_list ap);
+
+/**
+ * Check for a test condition.
+ *
+ * @param expected  The string which is expected.
+ * @param text      Some text that will be printed out if the test
+ *                      condition fails.
+ * @param ty        Comparison type.  See TEST_ERROR_* constants.
+ * @param fmt       printf-style format string.
+ * @param ...       printf-style arguments.
+ *
+ * @return          0 on success; 1 on failure.
+ */
+int expect(const char *expected, const char *text, int ty,
+        const char *fmt, ...);
+
+/**
+ * Allocate a zero-initialized region of memory, or die.
+ *
+ * @param len       The length
+ *
+ * @return          A pointer to a zero-initialized malloc'ed region.
+ */
+void *xcalloc(size_t len);
+
+#define TEST_ERROR_GET_LINE_HELPER2(x) #x
+#define TEST_ERROR_GET_LINE_HELPER(x) TEST_ERROR_GET_LINE_HELPER2(x)
+#define TEST_ERROR_LOCATION_TEXT __FILE__ " at line " \
+    TEST_ERROR_GET_LINE_HELPER(__LINE__)
+
+#define EXPECT(...) do { if (expect(__VA_ARGS__)) return 1; } while (0);
+
+#define EXPECT_EQ(expected, fmt, ...) \
+    EXPECT(expected, TEST_ERROR_LOCATION_TEXT, TEST_ERROR_EQ, \
+           fmt, __VA_ARGS__);
+
+#define EXPECT_STR_EQ(expected, str) \
+    EXPECT_EQ(expected, "%s", str)
+
+#define EXPECT_GE(expected, fmt, ...) \
+    EXPECT(expected, TEST_ERROR_LOCATION_TEXT, TEST_ERROR_GE, \
+           fmt, __VA_ARGS__);
+
+#define EXPECT_GT(expected, fmt, ...) \
+    EXPECT(expected, TEST_ERROR_LOCATION_TEXT, TEST_ERROR_GT, \
+           fmt, __VA_ARGS__);
+
+#define EXPECT_LE(expected, fmt, ...) \
+    EXPECT(expected, TEST_ERROR_LOCATION_TEXT, TEST_ERROR_LE, \
+           fmt, __VA_ARGS__);
+
+#define EXPECT_LT(expected, fmt, ...) \
+    EXPECT(expected, TEST_ERROR_LOCATION_TEXT, TEST_ERROR_LT, \
+           fmt, __VA_ARGS__);
+
+#define EXPECT_NE(expected, fmt, ...) \
+    EXPECT(expected, TEST_ERROR_LOCATION_TEXT, TEST_ERROR_NE, \
+           fmt, __VA_ARGS__);
+
+#define COMMON_TEST__TO_STR(x) #x
+#define COMMON_TEST__TO_STR2(x) COMMON_TEST__TO_STR(x)
+
+#define EXPECT_INT_EQ(expected, x) do { \
+  char expected_buf[16] = { 0 }; \
+  snprintf(expected_buf, sizeof(expected_buf), "%d", expected); \
+  EXPECT(expected_buf, TEST_ERROR_LOCATION_TEXT, TEST_ERROR_EQ, "%d", x); \
+} while(0);
+
+#define EXPECT_INT64_EQ(expected, x) do { \
+  char expected_buf[32] = { 0 }; \
+  snprintf(expected_buf, sizeof(expected_buf), "%" PRId64, expected); \
+  EXPECT(expected_buf, TEST_ERROR_LOCATION_TEXT, TEST_ERROR_EQ, \
+         "%" PRId64, x); \
+} while(0);
+
+#define EXPECT_NO_HADOOP_ERR(expr) do { \
+  struct hadoop_err *err = expr; \
+  EXPECT("", TEST_ERROR_LOCATION_TEXT, TEST_ERROR_EQ, \
+         "%s", (err ? hadoop_err_msg(err) : "")); \
+} while(0);
+
+#define EXPECT_INT_ZERO(x) \
+    EXPECT("0", TEST_ERROR_LOCATION_TEXT, TEST_ERROR_EQ, \
+           "%d", x);
+
+#define EXPECT_TRUE(x) \
+    EXPECT("1", TEST_ERROR_LOCATION_TEXT, TEST_ERROR_EQ, \
+           "%d", (!!x));
+
+#define EXPECT_FALSE(x) \
+    EXPECT("0", TEST_ERROR_LOCATION_TEXT, TEST_ERROR_EQ, \
+           "%d", (!!x));
+
+#define EXPECT_NONNULL(x) \
+    EXPECT("0", TEST_ERROR_LOCATION_TEXT, TEST_ERROR_NE, \
+           "%"PRIdPTR, x);
+
+#endif
+
+// vim: ts=4:sw=4:tw=79:et