From a780f0ac33cbe5dfa1549dca8e7a54dd1737d177 Mon Sep 17 00:00:00 2001 From: Eli Collins Date: Wed, 14 Nov 2012 06:17:19 +0000 Subject: [PATCH] HDFS-4139. fuse-dfs RO mode still allows file truncation. Contributed by Colin Patrick McCabe git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1409088 13f79535-47bb-0310-9956-ffa450edef68 --- hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt | 3 +++ .../src/main/native/fuse-dfs/fuse_context_handle.h | 1 - .../hadoop-hdfs/src/main/native/fuse-dfs/fuse_dfs.c | 12 ++++++++++++ .../src/main/native/fuse-dfs/fuse_impls_mkdir.c | 5 ----- .../src/main/native/fuse-dfs/fuse_impls_rename.c | 5 ----- .../src/main/native/fuse-dfs/fuse_impls_rmdir.c | 6 ------ .../src/main/native/fuse-dfs/fuse_impls_unlink.c | 6 ------ .../hadoop-hdfs/src/main/native/fuse-dfs/fuse_init.c | 1 - 8 files changed, 15 insertions(+), 24 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt index da466d73f6d..0822f36b29c 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt @@ -591,6 +591,9 @@ Release 2.0.3-alpha - Unreleased HDFS-4171. WebHDFS and HttpFs should accept only valid Unix user names. (tucu) + HDFS-4139. fuse-dfs RO mode still allows file truncation. + (Colin Patrick McCabe via eli) + Release 2.0.2-alpha - 2012-09-07 INCOMPATIBLE CHANGES diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/native/fuse-dfs/fuse_context_handle.h b/hadoop-hdfs-project/hadoop-hdfs/src/main/native/fuse-dfs/fuse_context_handle.h index f2b48be29c5..6929062908f 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/native/fuse-dfs/fuse_context_handle.h +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/native/fuse-dfs/fuse_context_handle.h @@ -31,7 +31,6 @@ // typedef struct dfs_context_struct { int debug; - int read_only; int usetrash; int direct_io; char **protectedpaths; diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/native/fuse-dfs/fuse_dfs.c b/hadoop-hdfs-project/hadoop-hdfs/src/main/native/fuse-dfs/fuse_dfs.c index 3d6bb53e8ea..f693032d5c5 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/native/fuse-dfs/fuse_dfs.c +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/native/fuse-dfs/fuse_dfs.c @@ -93,6 +93,18 @@ int main(int argc, char *argv[]) if (!options.no_permissions) { fuse_opt_add_arg(&args, "-odefault_permissions"); } + /* + * FUSE already has a built-in parameter for mounting the filesystem as + * read-only, -r. We defined our own parameter for doing this called -oro. + * We support it by translating it into -r internally. + * The kernel intercepts and returns an error message for any "write" + * operations that the user attempts to perform on a read-only filesystem. + * That means that we don't have to write any code to handle read-only mode. + * See HDFS-4139 for more details. + */ + if (options.read_only) { + fuse_opt_add_arg(&args, "-r"); + } { char buf[80]; diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/native/fuse-dfs/fuse_impls_mkdir.c b/hadoop-hdfs-project/hadoop-hdfs/src/main/native/fuse-dfs/fuse_impls_mkdir.c index 3aef108109b..b05551fb4ce 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/native/fuse-dfs/fuse_impls_mkdir.c +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/native/fuse-dfs/fuse_impls_mkdir.c @@ -39,11 +39,6 @@ int dfs_mkdir(const char *path, mode_t mode) return -EACCES; } - if (dfs->read_only) { - ERROR("HDFS is configured read-only, cannot create directory %s", path); - return -EACCES; - } - ret = fuseConnectAsThreadUid(&conn); if (ret) { fprintf(stderr, "fuseConnectAsThreadUid: failed to open a libhdfs " diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/native/fuse-dfs/fuse_impls_rename.c b/hadoop-hdfs-project/hadoop-hdfs/src/main/native/fuse-dfs/fuse_impls_rename.c index 415539f0abc..ad7c7e5115b 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/native/fuse-dfs/fuse_impls_rename.c +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/native/fuse-dfs/fuse_impls_rename.c @@ -43,11 +43,6 @@ int dfs_rename(const char *from, const char *to) return -EACCES; } - if (dfs->read_only) { - ERROR("HDFS configured read-only, cannot rename directory %s", from); - return -EACCES; - } - ret = fuseConnectAsThreadUid(&conn); if (ret) { fprintf(stderr, "fuseConnectAsThreadUid: failed to open a libhdfs " diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/native/fuse-dfs/fuse_impls_rmdir.c b/hadoop-hdfs-project/hadoop-hdfs/src/main/native/fuse-dfs/fuse_impls_rmdir.c index f79562a8b50..493807f6c4f 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/native/fuse-dfs/fuse_impls_rmdir.c +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/native/fuse-dfs/fuse_impls_rmdir.c @@ -44,12 +44,6 @@ int dfs_rmdir(const char *path) goto cleanup; } - if (dfs->read_only) { - ERROR("HDFS configured read-only, cannot delete directory %s", path); - ret = -EACCES; - goto cleanup; - } - ret = fuseConnectAsThreadUid(&conn); if (ret) { fprintf(stderr, "fuseConnectAsThreadUid: failed to open a libhdfs " diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/native/fuse-dfs/fuse_impls_unlink.c b/hadoop-hdfs-project/hadoop-hdfs/src/main/native/fuse-dfs/fuse_impls_unlink.c index 102c2cd0f3f..45a4501efaf 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/native/fuse-dfs/fuse_impls_unlink.c +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/native/fuse-dfs/fuse_impls_unlink.c @@ -40,12 +40,6 @@ int dfs_unlink(const char *path) goto cleanup; } - if (dfs->read_only) { - ERROR("HDFS configured read-only, cannot create directory %s", path); - ret = -EACCES; - goto cleanup; - } - ret = fuseConnectAsThreadUid(&conn); if (ret) { fprintf(stderr, "fuseConnectAsThreadUid: failed to open a libhdfs " diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/native/fuse-dfs/fuse_init.c b/hadoop-hdfs-project/hadoop-hdfs/src/main/native/fuse-dfs/fuse_init.c index 92220aa17f2..1ec11c1a0b5 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/native/fuse-dfs/fuse_init.c +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/native/fuse-dfs/fuse_init.c @@ -114,7 +114,6 @@ void *dfs_init(void) // initialize the context dfs->debug = options.debug; - dfs->read_only = options.read_only; dfs->usetrash = options.usetrash; dfs->protectedpaths = NULL; dfs->rdbuffer_size = options.rdbuffer_size;