From 590ae48c65a60c93c2e5407e3f663cef3daacc55 Mon Sep 17 00:00:00 2001 From: Amar Tumballi Date: Wed, 19 Jul 2017 23:08:05 +0530 Subject: glusterfsd: allow subdir mount Changes: 1. Take subdir mount option in client (mount.gluster / glusterfsd) 2. Pass the subdir mount to server-handshake (from client-handshake) 3. Handle subdir-mount dir's lookup in server-first-lookup and handle all fops resolution accordingly with proper gfid of subdir 4. Change the auth/addr module to handle the multiple subdir entries in option, and valid parsing. How to use the feature: `# mount -t glusterfs $hostname:/$volname/$subdir /$mount_point` Or `# mount -t glusterfs $hostname:/$volname -osubdir_mount=$subdir /$mount_point` Option can be set like: `# gluster volume set auth.allow "/subdir1(192.168.1.*),/(192.168.10.*),/subdir2(192.168.8.*)"` Updates #175 Change-Id: I7ea57f76ddbe6c3862cfe02e13f89e8a39719e11 Signed-off-by: Amar Tumballi Reviewed-on: https://review.gluster.org/17141 Smoke: Gluster Build System Reviewed-by: Shyamsundar Ranganathan CentOS-regression: Gluster Build System --- libglusterfs/src/client_t.c | 16 +++++++++++- libglusterfs/src/client_t.h | 8 +++++- libglusterfs/src/glusterfs.h | 3 +++ libglusterfs/src/options.c | 62 +++++++++++++++++++++++++++++++++++++++----- 4 files changed, 81 insertions(+), 8 deletions(-) (limited to 'libglusterfs/src') diff --git a/libglusterfs/src/client_t.c b/libglusterfs/src/client_t.c index 62cfbc422f8..eda1c465827 100644 --- a/libglusterfs/src/client_t.c +++ b/libglusterfs/src/client_t.c @@ -159,7 +159,8 @@ gf_client_clienttable_destroy (clienttable_t *clienttable) * as long as ref.bind is > 0 client should be alive. */ client_t * -gf_client_get (xlator_t *this, struct rpcsvc_auth_data *cred, char *client_uid) +gf_client_get (xlator_t *this, struct rpcsvc_auth_data *cred, char *client_uid, + char *subdir_mount) { client_t *client = NULL; cliententry_t *cliententry = NULL; @@ -204,6 +205,8 @@ gf_client_get (xlator_t *this, struct rpcsvc_auth_data *cred, char *client_uid) } client->this = this; + if (subdir_mount != NULL) + client->subdir_mount = gf_strdup (subdir_mount); LOCK_INIT (&client->scratch_ctx.lock); @@ -373,11 +376,16 @@ client_destroy (client_t *client) list_for_each_entry (gtrav, &client->this->ctx->graphs, list) { gf_client_destroy_recursive (gtrav->top, client); } + + if (client->subdir_inode) + inode_unref (client->subdir_inode); + GF_FREE (client->auth.data); GF_FREE (client->auth.username); GF_FREE (client->auth.passwd); GF_FREE (client->scratch_ctx.ctx); GF_FREE (client->client_uid); + GF_FREE (client->subdir_mount); GF_FREE (client); out: return; @@ -788,6 +796,12 @@ gf_client_dump_fdtables (xlator_t *this) client->client_uid); } + if (client->subdir_mount) { + gf_proc_dump_build_key (key, "conn", + "%d.subdir", count); + gf_proc_dump_write (key, "%s", + client->subdir_mount); + } gf_proc_dump_build_key (key, "conn", "%d.ref", count); gf_proc_dump_write (key, GF_PRI_ATOMIC, diff --git a/libglusterfs/src/client_t.h b/libglusterfs/src/client_t.h index 7666f0132b6..530c0a331ea 100644 --- a/libglusterfs/src/client_t.h +++ b/libglusterfs/src/client_t.h @@ -40,6 +40,11 @@ typedef struct _client { char *username; char *passwd; } auth; + + /* subdir_mount */ + char *subdir_mount; + inode_t *subdir_inode; + uuid_t subdir_gfid; } client_t; #define GF_CLIENTCTX_INITIAL_SIZE 8 @@ -72,7 +77,8 @@ typedef struct clienttable clienttable_t; struct rpcsvc_auth_data; client_t * -gf_client_get (xlator_t *this, struct rpcsvc_auth_data *cred, char *client_uid); +gf_client_get (xlator_t *this, struct rpcsvc_auth_data *cred, + char *client_uid, char *subdir_mount); void gf_client_put (client_t *client, gf_boolean_t *detached); diff --git a/libglusterfs/src/glusterfs.h b/libglusterfs/src/glusterfs.h index b009b94493d..8dcc4a367d0 100644 --- a/libglusterfs/src/glusterfs.h +++ b/libglusterfs/src/glusterfs.h @@ -418,6 +418,9 @@ struct _cmd_args { * dlclose(). */ int valgrind; int localtime_logging; + + /* For the subdir mount */ + char *subdir_mount; }; typedef struct _cmd_args cmd_args_t; diff --git a/libglusterfs/src/options.c b/libglusterfs/src/options.c index 3b1e21b5d0f..f0292eab5d4 100644 --- a/libglusterfs/src/options.c +++ b/libglusterfs/src/options.c @@ -599,21 +599,70 @@ xlator_option_validate_addr_list (xlator_t *xl, const char *key, char *dup_val = NULL; char *addr_tok = NULL; char *save_ptr = NULL; + char *entry = NULL; + char *entry_ptr = NULL; + char *dir_and_addr = NULL; + char *addr_ptr = NULL; + char *addr_list = NULL; + char *addr = NULL; + char *dir = NULL; char errstr[4096] = {0,}; dup_val = gf_strdup (value); if (!dup_val) goto out; - addr_tok = strtok_r (dup_val, ",", &save_ptr); - if (addr_tok == NULL) + if (dup_val[0] != '/' && !strchr (dup_val, '(')) { + /* Possible old format, handle it for back-ward compatibility */ + addr_tok = strtok_r (dup_val, ",", &save_ptr); + while (addr_tok) { + if (!valid_internet_address (addr_tok, _gf_true)) + goto out; + + addr_tok = strtok_r (NULL, ",", &save_ptr); + } + ret = 0; goto out; - while (addr_tok) { - if (!valid_internet_address (addr_tok, _gf_true)) + } + + /* Lets handle the value with new format */ + entry = strtok_r (dup_val, ",", &entry_ptr); + while (entry) { + dir_and_addr = gf_strdup (entry); + if (!dir_and_addr) goto out; - addr_tok = strtok_r (NULL, ",", &save_ptr); + dir = strtok_r (dir_and_addr, "(", &addr_ptr); + if (dir[0] != '/') { + /* Valid format should be starting from '/' */ + goto out; + } + /* dir = strtok_r (NULL, " =", &addr_tmp); */ + addr = strtok_r (NULL, ")", &addr_ptr); + if (!addr) + goto out; + + addr_list = gf_strdup (addr); + if (!addr_list) + goto out; + + /* This format be separated by '|' */ + addr_tok = strtok_r (addr_list, "|", &save_ptr); + if (addr_tok == NULL) + goto out; + while (addr_tok) { + if (!valid_internet_address (addr_tok, _gf_true)) + goto out; + + addr_tok = strtok_r (NULL, "|", &save_ptr); + } + entry = strtok_r (NULL, ",", &entry_ptr); + GF_FREE (dir_and_addr); + GF_FREE (addr_list); + addr_list = NULL; + dir_and_addr = NULL; } + ret = 0; out: @@ -626,7 +675,8 @@ out: *op_errstr = gf_strdup (errstr); } GF_FREE (dup_val); - + GF_FREE (dir_and_addr); + GF_FREE (addr_list); return ret; } -- cgit