diff options
Diffstat (limited to 'xlators/nfs/server/src')
34 files changed, 350 insertions, 274 deletions
diff --git a/xlators/nfs/server/src/acl3.c b/xlators/nfs/server/src/acl3.c index ff4bcfd8f4b..7e3bbf16086 100644 --- a/xlators/nfs/server/src/acl3.c +++ b/xlators/nfs/server/src/acl3.c @@ -8,13 +8,13 @@ * cases as published by the Free Software Foundation. */ -#include "defaults.h" +#include <glusterfs/defaults.h> #include "rpcsvc.h" -#include "dict.h" -#include "xlator.h" +#include <glusterfs/dict.h> +#include <glusterfs/xlator.h> #include "nfs.h" -#include "mem-pool.h" -#include "logging.h" +#include <glusterfs/mem-pool.h> +#include <glusterfs/logging.h> #include "nfs-fops.h" #include "nfs3.h" #include "nfs-mem-types.h" @@ -22,8 +22,8 @@ #include "nfs3-fh.h" #include "nfs-generics.h" #include "acl3.h" -#include "byte-order.h" -#include "compat-errno.h" +#include <glusterfs/byte-order.h> +#include <glusterfs/compat-errno.h> #include "nfs-messages.h" static int @@ -571,6 +571,12 @@ acl3_setacl_resume(void *carg) acl3_check_fh_resolve_status(cs, stat, acl3err); nfs_request_user_init(&nfu, cs->req); xattr = dict_new(); + if (xattr == NULL) { + gf_msg(GF_NLM, GF_LOG_ERROR, ENOMEM, NFS_MSG_GFID_DICT_CREATE_FAIL, + "dict allocation failed"); + goto acl3err; + } + if (cs->aclcount) ret = dict_set_static_bin(xattr, POSIX_ACL_ACCESS_XATTR, cs->aclxattr, posix_acl_xattr_size(cs->aclcount)); @@ -701,13 +707,13 @@ rpcerr: return ret; } -rpcsvc_actor_t acl3svc_actors[ACL3_PROC_COUNT] = { - {"NULL", ACL3_NULL, acl3svc_null, NULL, 0, DRC_NA}, - {"GETACL", ACL3_GETACL, acl3svc_getacl, NULL, 0, DRC_NA}, - {"SETACL", ACL3_SETACL, acl3svc_setacl, NULL, 0, DRC_NA}, +static rpcsvc_actor_t acl3svc_actors[ACL3_PROC_COUNT] = { + {"NULL", acl3svc_null, NULL, ACL3_NULL, DRC_NA, 0}, + {"GETACL", acl3svc_getacl, NULL, ACL3_GETACL, DRC_NA, 0}, + {"SETACL", acl3svc_setacl, NULL, ACL3_SETACL, DRC_NA, 0}, }; -rpcsvc_program_t acl3prog = { +static rpcsvc_program_t acl3prog = { .progname = "ACL3", .prognum = ACL_PROGRAM, .progver = ACLV3_VERSION, @@ -724,7 +730,6 @@ acl3svc_init(xlator_t *nfsx) struct nfs_state *nfs = NULL; dict_t *options = NULL; int ret = -1; - char *portstr = NULL; static gf_boolean_t acl3_inited = _gf_false; /* Already inited */ @@ -742,12 +747,13 @@ acl3svc_init(xlator_t *nfsx) acl3prog.private = ns; options = dict_new(); - - ret = gf_asprintf(&portstr, "%d", GF_ACL3_PORT); - if (ret == -1) + if (options == NULL) { + gf_msg(GF_ACL, GF_LOG_ERROR, ENOMEM, NFS_MSG_GFID_DICT_CREATE_FAIL, + "dict allocation failed"); goto err; + } - ret = dict_set_dynstr(options, "transport.socket.listen-port", portstr); + ret = dict_set_str(options, "transport.socket.listen-port", GF_ACL3_PORT); if (ret == -1) goto err; ret = dict_set_str(options, "transport-type", "socket"); @@ -783,13 +789,17 @@ acl3svc_init(xlator_t *nfsx) if (ret == -1) { gf_msg(GF_ACL, GF_LOG_ERROR, errno, NFS_MSG_LISTENERS_CREATE_FAIL, "Unable to create listeners"); - dict_unref(options); goto err; } + if (options) + dict_unref(options); + acl3_inited = _gf_true; return &acl3prog; err: + if (options) + dict_unref(options); return NULL; } diff --git a/xlators/nfs/server/src/acl3.h b/xlators/nfs/server/src/acl3.h index 500d2ef6ae5..762fbb04a0f 100644 --- a/xlators/nfs/server/src/acl3.h +++ b/xlators/nfs/server/src/acl3.h @@ -11,14 +11,14 @@ #ifndef _ACL3_H #define _ACL3_H -#include "glusterfs-acl.h" +#include <glusterfs/glusterfs-acl.h> #define ACL3_NULL 0 #define ACL3_GETACL 1 #define ACL3_SETACL 2 #define ACL3_PROC_COUNT 3 -#define GF_ACL3_PORT 38469 +#define GF_ACL3_PORT "38469" #define GF_ACL GF_NFS "-ACL" /* Flags for the getacl/setacl mode */ diff --git a/xlators/nfs/server/src/auth-cache.c b/xlators/nfs/server/src/auth-cache.c index 248a90b0587..ffbf5b6cad6 100644 --- a/xlators/nfs/server/src/auth-cache.c +++ b/xlators/nfs/server/src/auth-cache.c @@ -11,7 +11,7 @@ cases as published by the Free Software Foundation. */ -#include "refcount.h" +#include <glusterfs/refcount.h> #include "auth-cache.h" #include "nfs3.h" #include "exports.h" @@ -40,16 +40,12 @@ make_hashkey(struct nfs3_fh *fh, const char *host) char exportid[256] = { 0, }; - char gfid[256] = { - 0, - }; char mountid[256] = { 0, }; size_t nbytes = 0; gf_uuid_unparse(fh->exportid, exportid); - gf_uuid_unparse(fh->gfid, gfid); gf_uuid_unparse(fh->mountid, mountid); nbytes = strlen(exportid) + strlen(host) + strlen(mountid) + 3; @@ -145,7 +141,7 @@ auth_cache_add(struct auth_cache *cache, char *hashkey, { int ret = -1; data_t *entry_data = NULL; - + int hashkey_len; GF_VALIDATE_OR_GOTO(GF_NFS, cache, out); GF_VALIDATE_OR_GOTO(GF_NFS, cache->cache_dict, out); @@ -168,9 +164,10 @@ auth_cache_add(struct auth_cache *cache, char *hashkey, * auth_cache_entry is released */ entry->data = data_ref(entry_data); + hashkey_len = strlen(hashkey); LOCK(&cache->lock); { - ret = dict_set(cache->cache_dict, hashkey, entry_data); + ret = dict_setn(cache->cache_dict, hashkey, hashkey_len, entry_data); } UNLOCK(&cache->lock); @@ -192,7 +189,7 @@ out: static int _auth_cache_expired(struct auth_cache *cache, struct auth_cache_entry *entry) { - return ((time(NULL) - entry->timestamp) > cache->ttl_sec); + return ((gf_time() - entry->timestamp) > cache->ttl_sec); } /** @@ -477,7 +474,7 @@ cache_nfs_fh(struct auth_cache *cache, struct nfs3_fh *fh, goto out; } - entry->timestamp = time(NULL); + entry->timestamp = gf_time(); /* Update entry->item if it is pointing to a different export_item */ if (entry->item && entry->item != export_item) { GF_REF_PUT(entry->item); diff --git a/xlators/nfs/server/src/auth-cache.h b/xlators/nfs/server/src/auth-cache.h index d48c6f64e43..4c9d09207f8 100644 --- a/xlators/nfs/server/src/auth-cache.h +++ b/xlators/nfs/server/src/auth-cache.h @@ -17,7 +17,7 @@ #include "nfs-mem-types.h" #include "exports.h" -#include "dict.h" +#include <glusterfs/dict.h> #include "nfs3.h" struct auth_cache { diff --git a/xlators/nfs/server/src/exports.c b/xlators/nfs/server/src/exports.c index 342ad503a6a..d7e39934851 100644 --- a/xlators/nfs/server/src/exports.c +++ b/xlators/nfs/server/src/exports.c @@ -13,8 +13,8 @@ */ #include "exports.h" -#include "hashfn.h" -#include "parse-utils.h" +#include <glusterfs/hashfn.h> +#include <glusterfs/parse-utils.h> #include "nfs-messages.h" static void @@ -203,7 +203,9 @@ _export_dir_deinit(struct export_dir *dir) GF_VALIDATE_OR_GOTO(GF_EXP, dir, out); GF_FREE(dir->dir_name); _exp_dict_destroy(dir->netgroups); + dict_unref(dir->netgroups); _exp_dict_destroy(dir->hosts); + dict_unref(dir->hosts); GF_FREE(dir); out: @@ -645,6 +647,7 @@ __exp_line_opt_parse(const char *opt_str, struct export_options **exp_opts) if (!opts) { ret = -ENOMEM; parser_unset_string(options_parser); + GF_FREE(strmatch); goto out; } } @@ -675,7 +678,7 @@ __exp_line_opt_parse(const char *opt_str, struct export_options **exp_opts) _export_options_deinit(opts); goto out; } - } else + } else { /* Cannot change to gf_msg. * gf_msg not giving output to STDOUT * Bug id : BZ1215017 @@ -684,6 +687,7 @@ __exp_line_opt_parse(const char *opt_str, struct export_options **exp_opts) "Could not find any valid options for " "string: %s", strmatch); + } GF_FREE(strmatch); } @@ -1446,7 +1450,7 @@ exp_file_parse(const char *filepath, struct exports_file **expfile, GF_CHECK_ALLOC_AND_LOG(GF_EXP, file, ret, "Allocation error while " "allocating file struct", - parse_done); + free_and_done); file->filename = gf_strdup(filepath); GF_CHECK_ALLOC_AND_LOG(GF_EXP, file, ret, @@ -1468,7 +1472,9 @@ exp_file_parse(const char *filepath, struct exports_file **expfile, goto parse_done; free_and_done: - exp_file_deinit(file); + if (file) + exp_file_deinit(file); + _export_dir_deinit(expdir); parse_done: if (fp) diff --git a/xlators/nfs/server/src/exports.h b/xlators/nfs/server/src/exports.h index d44e32e3f74..ad35ad8c3a0 100644 --- a/xlators/nfs/server/src/exports.h +++ b/xlators/nfs/server/src/exports.h @@ -16,7 +16,7 @@ #define _EXPORTS_H_ #include "nfs-mem-types.h" -#include "dict.h" +#include <glusterfs/dict.h> #include "nfs.h" #define GF_EXP GF_NFS "-exports" diff --git a/xlators/nfs/server/src/mount3-auth.c b/xlators/nfs/server/src/mount3-auth.c index 37839c230e8..10e57c84cdb 100644 --- a/xlators/nfs/server/src/mount3-auth.c +++ b/xlators/nfs/server/src/mount3-auth.c @@ -38,7 +38,7 @@ #include "mount3-auth.h" #include "exports.h" #include "netgroups.h" -#include "mem-pool.h" +#include <glusterfs/mem-pool.h> #include "nfs-messages.h" /** diff --git a/xlators/nfs/server/src/mount3.c b/xlators/nfs/server/src/mount3.c index 3d5be6a6a6b..a34d9104c17 100644 --- a/xlators/nfs/server/src/mount3.c +++ b/xlators/nfs/server/src/mount3.c @@ -9,27 +9,27 @@ */ #include "rpcsvc.h" -#include "dict.h" -#include "xlator.h" +#include <glusterfs/dict.h> +#include <glusterfs/xlator.h> #include "mount3.h" #include "xdr-nfs3.h" #include "msg-nfs3.h" -#include "iobuf.h" +#include <glusterfs/iobuf.h> #include "nfs-common.h" #include "nfs3-fh.h" #include "nfs-fops.h" #include "nfs-inodes.h" #include "nfs-generics.h" -#include "locking.h" -#include "iatt.h" +#include <glusterfs/locking.h> +#include <glusterfs/iatt.h> #include "nfs-mem-types.h" #include "nfs.h" -#include "common-utils.h" -#include "store.h" +#include <glusterfs/common-utils.h> +#include <glusterfs/store.h> #include "glfs-internal.h" #include "glfs.h" #include "mount3-auth.h" -#include "hashfn.h" +#include <glusterfs/hashfn.h> #include "nfs-messages.h" #include <errno.h> @@ -920,14 +920,11 @@ mnt3svc_volume_mount(rpcsvc_request_t *req, struct mount3_state *ms, { inode_t *exportinode = NULL; int ret = -EFAULT; - uuid_t rootgfid = { - 0, - }; + static uuid_t rootgfid = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}; if ((!req) || (!exp) || (!ms)) return ret; - rootgfid[15] = 1; exportinode = inode_find(exp->vol->itable, rootgfid); if (!exportinode) { gf_msg(GF_MNT, GF_LOG_ERROR, ENOENT, NFS_MSG_GET_ROOT_INODE_FAIL, @@ -1372,9 +1369,7 @@ __mnt3_resolve_subdir(mnt3_resolve_t *mres) nfs_user_t nfu = { 0, }; - uuid_t rootgfid = { - 0, - }; + static uuid_t rootgfid = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}; if (!mres) return ret; @@ -1385,7 +1380,6 @@ __mnt3_resolve_subdir(mnt3_resolve_t *mres) if (!firstcomp) goto err; - rootgfid[15] = 1; ret = nfs_entry_loc_fill(mres->mstate->nfsx, mres->exp->vol->itable, rootgfid, firstcomp, &mres->resolveloc, NFS_RESOLVE_CREATE, NULL); @@ -2337,7 +2331,7 @@ __build_mountlist(struct mount3_state *ms, int *count) goto free_list; } - strcat(mlist->ml_hostname, me->hostname); + strcpy(mlist->ml_hostname, me->hostname); gf_msg_debug(GF_MNT, 0, "mount entry: dir: %s, host: %s", mlist->ml_directory, mlist->ml_hostname); @@ -3205,6 +3199,12 @@ mnt3_export_parse_auth_param(struct mnt3_export *exp, char *exportpath) struct host_auth_spec *host = NULL; int ret = 0; + if (exportpath == NULL) { + gf_msg(GF_MNT, GF_LOG_ERROR, EINVAL, NFS_MSG_PARSE_HOSTSPEC_FAIL, + "Export path is NULL"); + return -1; + } + /* Using exportpath directly in strtok_r because we want * to strip off AUTH parameter from exportpath. */ token = strtok_r(exportpath, "(", &savPtr); @@ -3656,20 +3656,26 @@ out: return ret; } -rpcsvc_actor_t mnt3svc_actors[MOUNT3_PROC_COUNT] = { - {"NULL", MOUNT3_NULL, mnt3svc_null, NULL, 0, DRC_NA}, - {"MNT", MOUNT3_MNT, mnt3svc_mnt, NULL, 0, DRC_NA}, - {"DUMP", MOUNT3_DUMP, mnt3svc_dump, NULL, 0, DRC_NA}, - {"UMNT", MOUNT3_UMNT, mnt3svc_umnt, NULL, 0, DRC_NA}, - {"UMNTALL", MOUNT3_UMNTALL, mnt3svc_umntall, NULL, 0, DRC_NA}, - {"EXPORT", MOUNT3_EXPORT, mnt3svc_export, NULL, 0, DRC_NA}}; +static rpcsvc_actor_t mnt3svc_actors[MOUNT3_PROC_COUNT] = { + { + "NULL", + mnt3svc_null, + NULL, + MOUNT3_NULL, + DRC_NA, + }, + {"MNT", mnt3svc_mnt, NULL, MOUNT3_MNT, DRC_NA, 0}, + {"DUMP", mnt3svc_dump, NULL, MOUNT3_DUMP, DRC_NA, 0}, + {"UMNT", mnt3svc_umnt, NULL, MOUNT3_UMNT, DRC_NA, 0}, + {"UMNTALL", mnt3svc_umntall, NULL, MOUNT3_UMNTALL, DRC_NA, 0}, + {"EXPORT", mnt3svc_export, NULL, MOUNT3_EXPORT, DRC_NA, 0}}; /* Static init parts are assigned here, dynamic ones are done in * mnt3svc_init and mnt3_init_state. * Making MOUNT3 a synctask so that the blocking DNS calls during rpc auth * gets offloaded to syncenv, keeping the main/poll thread unblocked */ -rpcsvc_program_t mnt3prog = { +static rpcsvc_program_t mnt3prog = { .progname = "MOUNT3", .prognum = MOUNT_PROGRAM, .progver = MOUNT_V3, @@ -4056,6 +4062,11 @@ mnt3svc_init(xlator_t *nfsx) mnt3prog.private = mstate; options = dict_new(); + if (options == NULL) { + gf_msg(GF_NFS, GF_LOG_ERROR, ENOMEM, NFS_MSG_GFID_DICT_CREATE_FAIL, + "dict allocation failed"); + goto err; + } ret = gf_asprintf(&portstr, "%d", GF_MOUNTV3_PORT); if (ret == -1) @@ -4091,7 +4102,6 @@ mnt3svc_init(xlator_t *nfsx) if (ret == -1) { gf_msg(GF_NFS, GF_LOG_ERROR, errno, NFS_MSG_LISTENERS_CREATE_FAIL, "Unable to create listeners"); - dict_unref(options); goto err; } @@ -4102,20 +4112,25 @@ mnt3svc_init(xlator_t *nfsx) gf_msg_debug(GF_MNT, GF_LOG_DEBUG, "Thread creation failed"); } } + if (options) + dict_unref(options); + return &mnt3prog; err: + if (options) + dict_unref(options); return NULL; } -rpcsvc_actor_t mnt1svc_actors[MOUNT1_PROC_COUNT] = { - {"NULL", MOUNT1_NULL, mnt3svc_null, NULL, 0, DRC_NA}, - {"MNT", MOUNT1_MNT, NULL, NULL, 0, DRC_NA}, - {"DUMP", MOUNT1_DUMP, mnt3svc_dump, NULL, 0, DRC_NA}, - {"UMNT", MOUNT1_UMNT, mnt3svc_umnt, NULL, 0, DRC_NA}, - {"UMNTALL", MOUNT1_UMNTALL, NULL, NULL, 0, DRC_NA}, - {"EXPORT", MOUNT1_EXPORT, mnt3svc_export, NULL, 0, DRC_NA}}; +static rpcsvc_actor_t mnt1svc_actors[MOUNT1_PROC_COUNT] = { + {"NULL", mnt3svc_null, NULL, MOUNT1_NULL, DRC_NA, 0}, + {"MNT", NULL, NULL, MOUNT1_MNT, DRC_NA, 0}, + {"DUMP", mnt3svc_dump, NULL, MOUNT1_DUMP, DRC_NA, 0}, + {"UMNT", mnt3svc_umnt, NULL, MOUNT1_UMNT, DRC_NA, 0}, + {"UMNTALL", NULL, NULL, MOUNT1_UMNTALL, DRC_NA, 0}, + {"EXPORT", mnt3svc_export, NULL, MOUNT1_EXPORT, DRC_NA, 0}}; -rpcsvc_program_t mnt1prog = { +static rpcsvc_program_t mnt1prog = { .progname = "MOUNT1", .prognum = MOUNT_PROGRAM, .progver = MOUNT_V1, @@ -4151,6 +4166,11 @@ mnt1svc_init(xlator_t *nfsx) mnt1prog.private = mstate; options = dict_new(); + if (options == NULL) { + gf_msg(GF_NFS, GF_LOG_ERROR, ENOMEM, NFS_MSG_GFID_DICT_CREATE_FAIL, + "dict allocation failed"); + goto err; + } ret = gf_asprintf(&portstr, "%d", GF_MOUNTV1_PORT); if (ret == -1) diff --git a/xlators/nfs/server/src/mount3.h b/xlators/nfs/server/src/mount3.h index 9b0f73e3af7..b185df835ae 100644 --- a/xlators/nfs/server/src/mount3.h +++ b/xlators/nfs/server/src/mount3.h @@ -12,15 +12,15 @@ #define _MOUNT3_H_ #include "rpcsvc.h" -#include "dict.h" -#include "xlator.h" -#include "iobuf.h" +#include <glusterfs/dict.h> +#include <glusterfs/xlator.h> +#include <glusterfs/iobuf.h> #include "nfs.h" -#include "list.h" +#include <glusterfs/list.h> #include "xdr-nfs3.h" -#include "locking.h" +#include <glusterfs/locking.h> #include "nfs3-fh.h" -#include "compat-uuid.h" +#include <glusterfs/compat-uuid.h> #include "exports.h" #include "mount3-auth.h" #include "auth-cache.h" diff --git a/xlators/nfs/server/src/mount3udp_svc.c b/xlators/nfs/server/src/mount3udp_svc.c index d542e2951c3..1a2b0f85453 100644 --- a/xlators/nfs/server/src/mount3udp_svc.c +++ b/xlators/nfs/server/src/mount3udp_svc.c @@ -9,8 +9,8 @@ */ #include "xdr-nfs3.h" -#include "logging.h" -#include "mem-pool.h" +#include <glusterfs/logging.h> +#include <glusterfs/mem-pool.h> #include "nfs-mem-types.h" #include "nfs-messages.h" #include "mount3.h" @@ -216,11 +216,7 @@ mount3udp_thread(void *argv) GF_ASSERT(nfsx); - if (glusterfs_this_set(nfsx)) { - gf_msg(GF_MNT, GF_LOG_ERROR, ENOMEM, NFS_MSG_XLATOR_SET_FAIL, - "Failed to set xlator, nfs.mount-udp will not work"); - return NULL; - } + THIS = nfsx; transp = svcudp_create(RPC_ANYSOCK); if (transp == NULL) { diff --git a/xlators/nfs/server/src/netgroups.c b/xlators/nfs/server/src/netgroups.c index 092d4707205..f68a7f14a26 100644 --- a/xlators/nfs/server/src/netgroups.c +++ b/xlators/nfs/server/src/netgroups.c @@ -13,7 +13,7 @@ */ #include "netgroups.h" -#include "parse-utils.h" +#include <glusterfs/parse-utils.h> #include "nfs-messages.h" static void diff --git a/xlators/nfs/server/src/netgroups.h b/xlators/nfs/server/src/netgroups.h index 1bb666b9596..9c715f75d3c 100644 --- a/xlators/nfs/server/src/netgroups.h +++ b/xlators/nfs/server/src/netgroups.h @@ -16,7 +16,7 @@ #define _NETGROUPS_H #include "nfs-mem-types.h" -#include "dict.h" +#include <glusterfs/dict.h> #include "nfs.h" #define GF_NG GF_NFS "-netgroup" diff --git a/xlators/nfs/server/src/nfs-common.c b/xlators/nfs/server/src/nfs-common.c index 2e8d401ba52..b8f6b6f318e 100644 --- a/xlators/nfs/server/src/nfs-common.c +++ b/xlators/nfs/server/src/nfs-common.c @@ -9,16 +9,16 @@ */ #include "rpcsvc.h" -#include "dict.h" -#include "xlator.h" +#include <glusterfs/dict.h> +#include <glusterfs/xlator.h> #include "xdr-nfs3.h" #include "msg-nfs3.h" -#include "iobuf.h" +#include <glusterfs/iobuf.h> #include "nfs-common.h" #include "nfs-fops.h" #include "nfs-mem-types.h" #include "rpcsvc.h" -#include "iatt.h" +#include <glusterfs/iatt.h> #include "nfs-messages.h" #include <libgen.h> @@ -272,11 +272,8 @@ err: int nfs_root_loc_fill(inode_table_t *itable, loc_t *loc) { - uuid_t rootgfid = { - 0, - }; + static uuid_t rootgfid = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}; - rootgfid[15] = 1; return nfs_gfid_loc_fill(itable, rootgfid, loc, NFS_RESOLVE_EXIST); } @@ -432,7 +429,7 @@ nfs_fix_generation(xlator_t *this, inode_t *inode) priv = this->private; if (inode_ctx_get(inode, this, &raw_ctx) == 0) { - ictx = (struct nfs_inode_ctx *)raw_ctx; + ictx = (struct nfs_inode_ctx *)(uintptr_t)raw_ctx; ictx->generation = priv->generation; } else { ictx = GF_CALLOC(1, sizeof(struct nfs_inode_ctx), gf_nfs_mt_inode_ctx); @@ -443,7 +440,7 @@ nfs_fix_generation(xlator_t *this, inode_t *inode) } INIT_LIST_HEAD(&ictx->shares); ictx->generation = priv->generation; - ret = inode_ctx_put(inode, this, (uint64_t)ictx); + ret = inode_ctx_put(inode, this, (uint64_t)(uintptr_t)ictx); if (ret) { gf_msg(this->name, GF_LOG_ERROR, 0, NFS_MSG_INODE_CTX_STORE_FAIL, "could not store nfs inode ctx"); diff --git a/xlators/nfs/server/src/nfs-common.h b/xlators/nfs/server/src/nfs-common.h index 46147757ef5..bd80d8b3be5 100644 --- a/xlators/nfs/server/src/nfs-common.h +++ b/xlators/nfs/server/src/nfs-common.h @@ -13,10 +13,10 @@ #include <unistd.h> -#include "xlator.h" +#include <glusterfs/xlator.h> #include "rpcsvc.h" -#include "iatt.h" -#include "compat-uuid.h" +#include <glusterfs/iatt.h> +#include <glusterfs/compat-uuid.h> // NFS_PATH_MAX hard-coded to 4096 as a work around for bug 2476. // nfs server crashes when path received is longer than PATH_MAX diff --git a/xlators/nfs/server/src/nfs-fops.c b/xlators/nfs/server/src/nfs-fops.c index e78cef7f0b4..4d8540c2c3e 100644 --- a/xlators/nfs/server/src/nfs-fops.c +++ b/xlators/nfs/server/src/nfs-fops.c @@ -10,10 +10,10 @@ #include <pwd.h> -#include "dict.h" -#include "xlator.h" -#include "iobuf.h" -#include "call-stub.h" +#include <glusterfs/dict.h> +#include <glusterfs/xlator.h> +#include <glusterfs/iobuf.h> +#include <glusterfs/call-stub.h> #include "nfs.h" #include "nfs-fops.h" #include "nfs-common.h" @@ -327,7 +327,7 @@ nfs_gfid_dict(inode_t *inode) unsigned char *dyngfid = NULL; dict_t *dictgfid = NULL; int ret = -1; - uuid_t rootgfid = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}; + static uuid_t rootgfid = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}; dyngfid = GF_MALLOC(sizeof(uuid_t), gf_common_mt_char); if (dyngfid == NULL) diff --git a/xlators/nfs/server/src/nfs-fops.h b/xlators/nfs/server/src/nfs-fops.h index 1f7c3b2d1f9..005cb788a45 100644 --- a/xlators/nfs/server/src/nfs-fops.h +++ b/xlators/nfs/server/src/nfs-fops.h @@ -11,10 +11,10 @@ #ifndef _NFS_FOPS_H_ #define _NFS_FOPS_H_ -#include "dict.h" -#include "xlator.h" -#include "iobuf.h" -#include "call-stub.h" +#include <glusterfs/dict.h> +#include <glusterfs/xlator.h> +#include <glusterfs/iobuf.h> +#include <glusterfs/call-stub.h> #include "nfs.h" #include "nfs-common.h" #include "nfs-messages.h" diff --git a/xlators/nfs/server/src/nfs-generics.c b/xlators/nfs/server/src/nfs-generics.c index feadb4cfb3f..009991877cb 100644 --- a/xlators/nfs/server/src/nfs-generics.c +++ b/xlators/nfs/server/src/nfs-generics.c @@ -14,7 +14,7 @@ #include "nfs-fops.h" #include "nfs-inodes.h" #include "nfs-generics.h" -#include "xlator.h" +#include <glusterfs/xlator.h> int nfs_fstat(xlator_t *nfsx, xlator_t *xl, nfs_user_t *nfu, fd_t *fd, diff --git a/xlators/nfs/server/src/nfs-generics.h b/xlators/nfs/server/src/nfs-generics.h index f71b45a513d..07a79994a4b 100644 --- a/xlators/nfs/server/src/nfs-generics.h +++ b/xlators/nfs/server/src/nfs-generics.h @@ -12,7 +12,7 @@ #define _NFS_GENERICS_H_ #include "nfs.h" -#include "xlator.h" +#include <glusterfs/xlator.h> #include "nfs-fops.h" #include "nfs-inodes.h" diff --git a/xlators/nfs/server/src/nfs-inodes.c b/xlators/nfs/server/src/nfs-inodes.c index 9999e884ffa..6f34ca705ba 100644 --- a/xlators/nfs/server/src/nfs-inodes.c +++ b/xlators/nfs/server/src/nfs-inodes.c @@ -13,7 +13,7 @@ #include "nfs.h" #include "nfs-inodes.h" #include "nfs-fops.h" -#include "xlator.h" +#include <glusterfs/xlator.h> #include "nfs-messages.h" #include <libgen.h> diff --git a/xlators/nfs/server/src/nfs-inodes.h b/xlators/nfs/server/src/nfs-inodes.h index 7a874c8a4ce..e8efd1e127c 100644 --- a/xlators/nfs/server/src/nfs-inodes.h +++ b/xlators/nfs/server/src/nfs-inodes.h @@ -11,10 +11,10 @@ #ifndef _NFS_INODES_H_ #define _NFS_INODES_H_ -#include "dict.h" -#include "xlator.h" -#include "iobuf.h" -#include "call-stub.h" +#include <glusterfs/dict.h> +#include <glusterfs/xlator.h> +#include <glusterfs/iobuf.h> +#include <glusterfs/call-stub.h> #include "nfs-fops.h" extern int diff --git a/xlators/nfs/server/src/nfs-mem-types.h b/xlators/nfs/server/src/nfs-mem-types.h index 5737aae6a09..0a3c887eff1 100644 --- a/xlators/nfs/server/src/nfs-mem-types.h +++ b/xlators/nfs/server/src/nfs-mem-types.h @@ -11,7 +11,7 @@ #ifndef __NFS_MEM_TYPES_H__ #define __NFS_MEM_TYPES_H__ -#include "mem-types.h" +#include <glusterfs/mem-types.h> enum gf_nfs_mem_types_ { gf_nfs_mt_mountentry = gf_common_mt_end + 1, @@ -21,29 +21,22 @@ enum gf_nfs_mem_types_ { gf_nfs_mt_exportnode, gf_nfs_mt_groupnode, gf_nfs_mt_mount3_state, - gf_nfs_mt_write3args, gf_nfs_mt_nfs3_export, gf_nfs_mt_nfs3_state, gf_nfs_mt_entry3, gf_nfs_mt_entryp3, - gf_nfs_mt_nfs3_fd_entry, gf_nfs_mt_nfs3_fh, gf_nfs_mt_nfs_initer_list, gf_nfs_mt_xlator_t, - gf_nfs_mt_list_head, gf_nfs_mt_mnt3_resolve, gf_nfs_mt_mnt3_export, gf_nfs_mt_mnt3_auth_params, gf_nfs_mt_int, gf_nfs_mt_mountres3, gf_nfs_mt_mountstat3, - gf_nfs_mt_inode_q, - gf_nfs_mt_nlm4_state, - gf_nfs_mt_nlm4_cm, gf_nfs_mt_nlm4_fde, gf_nfs_mt_nlm4_nlmclnt, gf_nfs_mt_nlm4_share, - gf_nfs_mt_aux_gids, gf_nfs_mt_inode_ctx, gf_nfs_mt_auth_spec, gf_nfs_mt_arr, diff --git a/xlators/nfs/server/src/nfs-messages.h b/xlators/nfs/server/src/nfs-messages.h index b8fe99e45d3..04e15cbe78c 100644 --- a/xlators/nfs/server/src/nfs-messages.h +++ b/xlators/nfs/server/src/nfs-messages.h @@ -10,7 +10,7 @@ #ifndef _NFS_MESSAGES_H_ #define _NFS_MESSAGES_H_ -#include "glfs-message-id.h" +#include <glusterfs/glfs-message-id.h> /* To add new message IDs, append new identifiers at the end of the list. * diff --git a/xlators/nfs/server/src/nfs.c b/xlators/nfs/server/src/nfs.c index a20fab3ef79..39b73f88ac3 100644 --- a/xlators/nfs/server/src/nfs.c +++ b/xlators/nfs/server/src/nfs.c @@ -12,25 +12,26 @@ * Every other protocol version gets initialized from here. */ -#include "defaults.h" +#include <glusterfs/defaults.h> #include "rpcsvc.h" -#include "dict.h" -#include "xlator.h" +#include <glusterfs/dict.h> +#include <glusterfs/xlator.h> #include "nfs.h" -#include "mem-pool.h" -#include "logging.h" +#include <glusterfs/mem-pool.h> +#include <glusterfs/logging.h> #include "nfs-fops.h" #include "mount3.h" #include "nfs3.h" #include "nfs-mem-types.h" #include "nfs3-helpers.h" #include "nlm4.h" -#include "options.h" +#include <glusterfs/options.h> #include "acl3.h" #include "rpc-drc.h" -#include "syscall.h" +#include <glusterfs/syscall.h> #include "rpcsvc.h" #include "nfs-messages.h" +#include "glusterfs/statedump.h" #define OPT_SERVER_AUX_GIDS "nfs.server-aux-gids" #define OPT_SERVER_GID_CACHE_TIMEOUT "nfs.server.aux-gid-timeout" @@ -1114,7 +1115,7 @@ nfs_init_state(xlator_t *this) GF_OPTION_INIT("nfs.event-threads", nfs->event_threads, uint32, free_foppool); - event_reconfigure_threads(this->ctx->event_pool, nfs->event_threads); + gf_event_reconfigure_threads(this->ctx->event_pool, nfs->event_threads); this->private = (void *)nfs; INIT_LIST_HEAD(&nfs->versions); @@ -1156,7 +1157,7 @@ out: return ret; } -int +static int nfs_reconfigure_state(xlator_t *this, dict_t *options) { int ret = 0; @@ -1166,8 +1167,8 @@ nfs_reconfigure_state(xlator_t *this, dict_t *options) gf_boolean_t optbool; uint32_t optuint32; struct nfs_state *nfs = NULL; - char *blacklist_keys[] = {"nfs.port", "nfs.transport-type", - "nfs.mem-factor", NULL}; + static char *options_require_restart[] = {"nfs.port", "nfs.transport-type", + "nfs.mem-factor", NULL}; GF_VALIDATE_OR_GOTO(GF_NFS, this, out); GF_VALIDATE_OR_GOTO(GF_NFS, this->private, out); @@ -1175,14 +1176,14 @@ nfs_reconfigure_state(xlator_t *this, dict_t *options) nfs = (struct nfs_state *)this->private; - /* Black listed options can't be reconfigured, they need + /* Some listed options can't be reconfigured, they need * NFS to be restarted. There are two cases 1. SET 2. UNSET. * 1. SET */ - while (blacklist_keys[keyindx]) { - if (dict_get(options, blacklist_keys[keyindx])) { + while (options_require_restart[keyindx]) { + if (dict_get(options, options_require_restart[keyindx])) { gf_msg(GF_NFS, GF_LOG_ERROR, 0, NFS_MSG_RECONFIG_FAIL, "Reconfiguring %s needs NFS restart", - blacklist_keys[keyindx]); + options_require_restart[keyindx]); goto out; } keyindx++; @@ -1337,7 +1338,7 @@ nfs_reconfigure_state(xlator_t *this, dict_t *options) GF_OPTION_RECONF("nfs.event-threads", nfs->event_threads, options, uint32, out); - event_reconfigure_threads(this->ctx->event_pool, nfs->event_threads); + gf_event_reconfigure_threads(this->ctx->event_pool, nfs->event_threads); ret = 0; out: @@ -1529,7 +1530,7 @@ notify(xlator_t *this, int32_t event, void *data, ...) return 0; } -int +void fini(xlator_t *this) { struct nfs_state *nfs = NULL; @@ -1539,7 +1540,7 @@ fini(xlator_t *this) gf_msg_debug(GF_NFS, 0, "NFS service going down"); nfs_deinit_versions(&nfs->versions, this); GF_FREE(this->instance_name); - return 0; + return; } int32_t @@ -1551,7 +1552,7 @@ nfs_forget(xlator_t *this, inode_t *inode) if (inode_ctx_del(inode, this, &ctx)) return -1; - ictx = (struct nfs_inode_ctx *)ctx; + ictx = (struct nfs_inode_ctx *)(uintptr_t)ctx; GF_FREE(ictx); return 0; @@ -1667,6 +1668,20 @@ out: return ret; } +int32_t +nfs_itable_dump(xlator_t *this) +{ + if (!this) + return -1; + + if (this->next && this->next->itable) { + gf_proc_dump_add_section("xlator.nfs.itable"); + inode_table_dump(this->next->itable, "xlator.nfs.itable"); + } + + return 0; +} + struct xlator_cbks cbks = { .forget = nfs_forget, }; @@ -1676,6 +1691,7 @@ struct xlator_fops fops; struct xlator_dumpops dumpops = { .priv = nfs_priv, .priv_to_dict = nfs_priv_to_dict, + .inode = nfs_itable_dump, }; /* TODO: If needed, per-volume options below can be extended to be export @@ -2030,7 +2046,7 @@ struct volume_options options[] = { .type = GF_OPTION_TYPE_SIZET, .min = 1, .max = 32, - .default_value = "1", + .default_value = "2", .description = "Specifies the number of event threads to execute in" "in parallel. Larger values would help process" " responses faster, depending on available processing" @@ -2040,3 +2056,18 @@ struct volume_options options[] = { }, {.key = {NULL}}, }; + +xlator_api_t xlator_api = { + .init = init, + .fini = fini, + .notify = notify, + .reconfigure = reconfigure, + .mem_acct_init = mem_acct_init, + .op_version = {1}, + .dumpops = &dumpops, + .fops = &fops, + .cbks = &cbks, + .options = options, + .identifier = "gnfs", + .category = GF_MAINTAINED, +}; diff --git a/xlators/nfs/server/src/nfs.h b/xlators/nfs/server/src/nfs.h index 531a269071c..e3daaed17a6 100644 --- a/xlators/nfs/server/src/nfs.h +++ b/xlators/nfs/server/src/nfs.h @@ -12,10 +12,10 @@ #define __NFS_H__ #include "rpcsvc.h" -#include "dict.h" -#include "xlator.h" -#include "lkowner.h" -#include "gidcache.h" +#include <glusterfs/dict.h> +#include <glusterfs/xlator.h> +#include <glusterfs/lkowner.h> +#include <glusterfs/gidcache.h> #define GF_NFS "nfs" diff --git a/xlators/nfs/server/src/nfs3-fh.c b/xlators/nfs/server/src/nfs3-fh.c index c63f9328f57..caa3cfa6995 100644 --- a/xlators/nfs/server/src/nfs3-fh.c +++ b/xlators/nfs/server/src/nfs3-fh.c @@ -9,15 +9,15 @@ */ #include "rpcsvc.h" -#include "dict.h" -#include "xlator.h" +#include <glusterfs/dict.h> +#include <glusterfs/xlator.h> #include "xdr-nfs3.h" #include "msg-nfs3.h" -#include "iobuf.h" +#include <glusterfs/iobuf.h> #include "nfs3-fh.h" #include "nfs-common.h" -#include "iatt.h" -#include "common-utils.h" +#include <glusterfs/iatt.h> +#include <glusterfs/common-utils.h> #include "nfs-messages.h" int @@ -64,7 +64,7 @@ nfs3_fh_build_indexed_root_fh(xlator_list_t *cl, xlator_t *xl) struct iatt buf = { 0, }; - uuid_t root = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}; + static uuid_t root = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}; if ((!cl) || (!xl)) return fh; @@ -85,7 +85,7 @@ nfs3_fh_build_uuid_root_fh(uuid_t volumeid, uuid_t mountid) struct iatt buf = { 0, }; - uuid_t root = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}; + static uuid_t root = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}; gf_uuid_copy(buf.ia_gfid, root); nfs3_fh_init(&fh, &buf); @@ -98,7 +98,7 @@ nfs3_fh_build_uuid_root_fh(uuid_t volumeid, uuid_t mountid) int nfs3_fh_is_root_fh(struct nfs3_fh *fh) { - uuid_t rootgfid = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}; + static uuid_t rootgfid = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}; if (!fh) return 0; diff --git a/xlators/nfs/server/src/nfs3-fh.h b/xlators/nfs/server/src/nfs3-fh.h index 442f6feeb25..cd7916b892d 100644 --- a/xlators/nfs/server/src/nfs3-fh.h +++ b/xlators/nfs/server/src/nfs3-fh.h @@ -11,11 +11,11 @@ #ifndef _NFS_FH_H_ #define _NFS_FH_H_ -#include "xlator.h" +#include <glusterfs/xlator.h> #include "xdr-nfs3.h" -#include "iatt.h" +#include <glusterfs/iatt.h> #include <sys/types.h> -#include "compat-uuid.h" +#include <glusterfs/compat-uuid.h> /* BIG FAT WARNING: The file handle code is tightly coupled to NFSv3 file * handles for now. This will change if and when we need v4. */ diff --git a/xlators/nfs/server/src/nfs3-helpers.c b/xlators/nfs/server/src/nfs3-helpers.c index 7fa278fdc24..897fb42b071 100644 --- a/xlators/nfs/server/src/nfs3-helpers.c +++ b/xlators/nfs/server/src/nfs3-helpers.c @@ -10,18 +10,18 @@ #include <inttypes.h> -#include "xlator.h" +#include <glusterfs/xlator.h> #include "nfs3.h" #include "nfs3-fh.h" #include "msg-nfs3.h" -#include "rbthash.h" +#include <glusterfs/rbthash.h> #include "nfs-fops.h" #include "nfs-inodes.h" #include "nfs-generics.h" #include "nfs3-helpers.h" #include "nfs-mem-types.h" -#include "iatt.h" -#include "common-utils.h" +#include <glusterfs/iatt.h> +#include <glusterfs/common-utils.h> #include "nfs-messages.h" #include "mount3.h" #include <string.h> @@ -1072,7 +1072,7 @@ nfs3_sattr3_to_setattr_valid(sattr3 *sattr, struct iatt *buf, mode_t *omode) if (sattr->atime.set_it == SET_TO_SERVER_TIME) { valid |= GF_SET_ATTR_ATIME; if (buf) - buf->ia_atime = time(NULL); + buf->ia_atime = gf_time(); } if (sattr->mtime.set_it == SET_TO_CLIENT_TIME) { @@ -1084,7 +1084,7 @@ nfs3_sattr3_to_setattr_valid(sattr3 *sattr, struct iatt *buf, mode_t *omode) if (sattr->mtime.set_it == SET_TO_SERVER_TIME) { valid |= GF_SET_ATTR_MTIME; if (buf) - buf->ia_mtime = time(NULL); + buf->ia_mtime = gf_time(); } return valid; @@ -3556,6 +3556,12 @@ nfs3_fh_resolve_entry_lookup_cbk(call_frame_t *frame, void *cookie, inode_lookup(linked_inode); inode_unref(cs->resolvedloc.inode); cs->resolvedloc.inode = linked_inode; + } else { + /* nfs3_fh_resolve_entry_hard() use to resolve entire path if needed. + * So the ctx for inode obtained from here need to set properly, + * otherwise it may result in a crash. + */ + nfs_fix_generation(this, inode); } err: nfs3_call_resume(cs); diff --git a/xlators/nfs/server/src/nfs3-helpers.h b/xlators/nfs/server/src/nfs3-helpers.h index 7c70c20b787..aead636c831 100644 --- a/xlators/nfs/server/src/nfs3-helpers.h +++ b/xlators/nfs/server/src/nfs3-helpers.h @@ -11,7 +11,7 @@ #ifndef _NFS3_HELPER_H_ #define _NFS3_HELPER_H_ -#include "xlator.h" +#include <glusterfs/xlator.h> #include "nfs3.h" #include "nfs3-fh.h" #include "msg-nfs3.h" diff --git a/xlators/nfs/server/src/nfs3.c b/xlators/nfs/server/src/nfs3.c index d8e41680008..f9042bc3b3f 100644 --- a/xlators/nfs/server/src/nfs3.c +++ b/xlators/nfs/server/src/nfs3.c @@ -9,15 +9,15 @@ */ #include "rpcsvc.h" -#include "dict.h" -#include "xlator.h" +#include <glusterfs/dict.h> +#include <glusterfs/xlator.h> #include "mount3.h" #include "xdr-nfs3.h" #include "msg-nfs3.h" -#include "iobuf.h" +#include <glusterfs/iobuf.h> #include "nfs3.h" -#include "mem-pool.h" -#include "logging.h" +#include <glusterfs/mem-pool.h> +#include <glusterfs/logging.h> #include "nfs-common.h" #include "nfs-fops.h" #include "nfs-inodes.h" @@ -914,7 +914,7 @@ nfs3_getattr_resume(void *carg) * haven't been validated since the state change are affected. */ if (inode_ctx_get(cs->resolvedloc.inode, cs->nfsx, &raw_ctx) == 0) { - ictx = (struct nfs_inode_ctx *)raw_ctx; + ictx = (struct nfs_inode_ctx *)(uintptr_t)raw_ctx; priv = cs->nfsx->private; if (ictx->generation != priv->generation) { ret = nfs_lookup(cs->nfsx, cs->vol, &nfu, &cs->resolvedloc, @@ -2587,14 +2587,15 @@ nfs3svc_create_stat_cbk(call_frame_t *frame, void *cookie, xlator_t *this, if ((cs->stbuf.ia_mtime == buf->ia_mtime) && (cs->stbuf.ia_atime == buf->ia_atime)) { - gf_msg_debug(GF_NFS3, 0, "Create req retransmitted verf %ld %ld", + gf_msg_debug(GF_NFS3, 0, + "Create req retransmitted verf %" PRId64 " %" PRId64, cs->stbuf.ia_mtime, cs->stbuf.ia_atime); stat = NFS3_OK; nfs3_fh_build_child_fh(&cs->parent, buf, &cs->fh); } else { gf_msg_debug(GF_NFS3, 0, - "File already exist new_verf %ld %ld" - "old_verf %ld %ld", + "File already exist new_verf %" PRId64 " %" PRId64 + "old_verf %" PRId64 " %" PRId64, cs->stbuf.ia_mtime, cs->stbuf.ia_atime, buf->ia_mtime, buf->ia_atime); stat = NFS3ERR_EXIST; @@ -5191,32 +5192,32 @@ rpcerr: return ret; } -rpcsvc_actor_t nfs3svc_actors[NFS3_PROC_COUNT] = { - {"NULL", NFS3_NULL, nfs3svc_null, NULL, 0, DRC_IDEMPOTENT}, - {"GETATTR", NFS3_GETATTR, nfs3svc_getattr, NULL, 0, DRC_IDEMPOTENT}, - {"SETATTR", NFS3_SETATTR, nfs3svc_setattr, NULL, 0, DRC_NON_IDEMPOTENT}, - {"LOOKUP", NFS3_LOOKUP, nfs3svc_lookup, NULL, 0, DRC_IDEMPOTENT}, - {"ACCESS", NFS3_ACCESS, nfs3svc_access, NULL, 0, DRC_IDEMPOTENT}, - {"READLINK", NFS3_READLINK, nfs3svc_readlink, NULL, 0, DRC_IDEMPOTENT}, - {"READ", NFS3_READ, nfs3svc_read, NULL, 0, DRC_IDEMPOTENT}, - {"WRITE", NFS3_WRITE, nfs3svc_write, nfs3svc_write_vecsizer, 0, - DRC_NON_IDEMPOTENT}, - {"CREATE", NFS3_CREATE, nfs3svc_create, NULL, 0, DRC_NON_IDEMPOTENT}, - {"MKDIR", NFS3_MKDIR, nfs3svc_mkdir, NULL, 0, DRC_NON_IDEMPOTENT}, - {"SYMLINK", NFS3_SYMLINK, nfs3svc_symlink, NULL, 0, DRC_NON_IDEMPOTENT}, - {"MKNOD", NFS3_MKNOD, nfs3svc_mknod, NULL, 0, DRC_NON_IDEMPOTENT}, - {"REMOVE", NFS3_REMOVE, nfs3svc_remove, NULL, 0, DRC_NON_IDEMPOTENT}, - {"RMDIR", NFS3_RMDIR, nfs3svc_rmdir, NULL, 0, DRC_NON_IDEMPOTENT}, - {"RENAME", NFS3_RENAME, nfs3svc_rename, NULL, 0, DRC_NON_IDEMPOTENT}, - {"LINK", NFS3_LINK, nfs3svc_link, NULL, 0, DRC_NON_IDEMPOTENT}, - {"READDIR", NFS3_READDIR, nfs3svc_readdir, NULL, 0, DRC_IDEMPOTENT}, - {"READDIRPLUS", NFS3_READDIRP, nfs3svc_readdirp, NULL, 0, DRC_IDEMPOTENT}, - {"FSSTAT", NFS3_FSSTAT, nfs3svc_fsstat, NULL, 0, DRC_IDEMPOTENT}, - {"FSINFO", NFS3_FSINFO, nfs3svc_fsinfo, NULL, 0, DRC_IDEMPOTENT}, - {"PATHCONF", NFS3_PATHCONF, nfs3svc_pathconf, NULL, 0, DRC_IDEMPOTENT}, - {"COMMIT", NFS3_COMMIT, nfs3svc_commit, NULL, 0, DRC_IDEMPOTENT}}; - -rpcsvc_program_t nfs3prog = { +static rpcsvc_actor_t nfs3svc_actors[NFS3_PROC_COUNT] = { + {"NULL", nfs3svc_null, NULL, NFS3_NULL, DRC_IDEMPOTENT, 0}, + {"GETATTR", nfs3svc_getattr, NULL, NFS3_GETATTR, DRC_IDEMPOTENT, 0}, + {"SETATTR", nfs3svc_setattr, NULL, NFS3_SETATTR, DRC_NON_IDEMPOTENT, 0}, + {"LOOKUP", nfs3svc_lookup, NULL, NFS3_LOOKUP, DRC_IDEMPOTENT, 0}, + {"ACCESS", nfs3svc_access, NULL, NFS3_ACCESS, DRC_IDEMPOTENT, 0}, + {"READLINK", nfs3svc_readlink, NULL, NFS3_READLINK, DRC_IDEMPOTENT, 0}, + {"READ", nfs3svc_read, NULL, NFS3_READ, DRC_IDEMPOTENT, 0}, + {"WRITE", nfs3svc_write, nfs3svc_write_vecsizer, NFS3_WRITE, DRC_IDEMPOTENT, + 0}, + {"CREATE", nfs3svc_create, NULL, NFS3_CREATE, DRC_NON_IDEMPOTENT, 0}, + {"MKDIR", nfs3svc_mkdir, NULL, NFS3_MKDIR, DRC_NON_IDEMPOTENT, 0}, + {"SYMLINK", nfs3svc_symlink, NULL, NFS3_SYMLINK, DRC_NON_IDEMPOTENT, 0}, + {"MKNOD", nfs3svc_mknod, NULL, NFS3_MKNOD, DRC_NON_IDEMPOTENT, 0}, + {"REMOVE", nfs3svc_remove, NULL, NFS3_REMOVE, DRC_NON_IDEMPOTENT, 0}, + {"RMDIR", nfs3svc_rmdir, NULL, NFS3_RMDIR, DRC_NON_IDEMPOTENT, 0}, + {"RENAME", nfs3svc_rename, NULL, NFS3_RENAME, DRC_NON_IDEMPOTENT, 0}, + {"LINK", nfs3svc_link, NULL, NFS3_LINK, DRC_NON_IDEMPOTENT, 0}, + {"READDIR", nfs3svc_readdir, NULL, NFS3_READDIR, DRC_IDEMPOTENT, 0}, + {"READDIRPLUS", nfs3svc_readdirp, NULL, NFS3_READDIRP, DRC_IDEMPOTENT, 0}, + {"FSSTAT", nfs3svc_fsstat, NULL, NFS3_FSSTAT, DRC_IDEMPOTENT, 0}, + {"FSINFO", nfs3svc_fsinfo, NULL, NFS3_FSINFO, DRC_IDEMPOTENT, 0}, + {"PATHCONF", nfs3svc_pathconf, NULL, NFS3_PATHCONF, DRC_IDEMPOTENT, 0}, + {"COMMIT", nfs3svc_commit, NULL, NFS3_COMMIT, DRC_IDEMPOTENT, 0}}; + +static rpcsvc_program_t nfs3prog = { .progname = "NFS3", .prognum = NFS_PROGRAM, .progver = NFS_V3, @@ -5650,7 +5651,7 @@ nfs3_init_state(xlator_t *nfsx) goto free_localpool; } - nfs3->serverstart = (uint64_t)time(NULL); + nfs3->serverstart = (uint64_t)gf_time(); INIT_LIST_HEAD(&nfs3->fdlru); LOCK_INIT(&nfs3->fdlrulock); nfs3->fdcount = 0; diff --git a/xlators/nfs/server/src/nfs3.h b/xlators/nfs/server/src/nfs3.h index f6d98d9f308..cdb7e03a619 100644 --- a/xlators/nfs/server/src/nfs3.h +++ b/xlators/nfs/server/src/nfs3.h @@ -12,18 +12,18 @@ #define _NFS3_H_ #include "rpcsvc.h" -#include "dict.h" -#include "xlator.h" -#include "iobuf.h" +#include <glusterfs/dict.h> +#include <glusterfs/xlator.h> +#include <glusterfs/iobuf.h> #include "nfs.h" #include "nfs3-fh.h" #include "nfs-common.h" #include "xdr-nfs3.h" -#include "mem-pool.h" +#include <glusterfs/mem-pool.h> #include "nlm4.h" #include "acl3-xdr.h" #include "acl3.h" -#include "refcount.h" +#include <glusterfs/refcount.h> #include <sys/statvfs.h> #define GF_NFS3 GF_NFS "-nfsv3" diff --git a/xlators/nfs/server/src/nfsserver.sym b/xlators/nfs/server/src/nfsserver.sym index 2126634962a..dce7d964e9e 100644 --- a/xlators/nfs/server/src/nfsserver.sym +++ b/xlators/nfs/server/src/nfsserver.sym @@ -1,12 +1,3 @@ -init -fini -fops -cbks -options -notify -mem_acct_init -reconfigure -dumpops exp_file_parse exp_file_print exp_file_get_dir @@ -18,3 +9,4 @@ ng_file_parse ng_file_get_netgroup ng_file_print ng_file_deinit +xlator_api diff --git a/xlators/nfs/server/src/nlm4.c b/xlators/nfs/server/src/nlm4.c index 6fd952fd338..577e8543966 100644 --- a/xlators/nfs/server/src/nlm4.c +++ b/xlators/nfs/server/src/nlm4.c @@ -8,14 +8,14 @@ cases as published by the Free Software Foundation. */ -#include "defaults.h" +#include <glusterfs/defaults.h> #include "rpcsvc.h" -#include "dict.h" -#include "xlator.h" +#include <glusterfs/dict.h> +#include <glusterfs/xlator.h> #include "nfs.h" -#include "mem-pool.h" -#include "logging.h" -#include "syscall.h" +#include <glusterfs/mem-pool.h> +#include <glusterfs/logging.h> +#include <glusterfs/syscall.h> #include "nfs-fops.h" #include "mount3.h" #include "nfs3.h" @@ -28,13 +28,13 @@ #include "nfs-generics.h" #include "rpc-clnt.h" #include "nsm-xdr.h" -#include "run.h" +#include <glusterfs/run.h> #include "nfs-messages.h" #include <unistd.h> #include <rpc/pmap_clnt.h> #include <rpc/rpc.h> #include <rpc/xdr.h> -#include <statedump.h> +#include <glusterfs/statedump.h> #define KILLALL_CMD "pkill" @@ -57,6 +57,8 @@ gf_lock_t nlm_client_list_lk; /* race on this is harmless */ int nlm_grace_period = 50; +static gf_boolean_t nlm4_inited = _gf_false; + #define nlm4_validate_nfs3_state(request, state, status, label, retval) \ do { \ state = rpcsvc_request_program_private(request); \ @@ -639,7 +641,7 @@ nlm4_file_open_and_resume(nfs3_call_state_t *cs, nlm4_resume_fn_t resume) goto err; } cs->resume_fn = resume; - fd = fd_lookup_uint64(cs->resolvedloc.inode, (uint64_t)nlmclnt); + fd = fd_lookup_uint64(cs->resolvedloc.inode, (uint64_t)(uintptr_t)nlmclnt); if (fd) { cs->fd = fd; cs->resolve_ret = 0; @@ -648,7 +650,7 @@ nlm4_file_open_and_resume(nfs3_call_state_t *cs, nlm4_resume_fn_t resume) goto err; } - fd = fd_create_uint64(cs->resolvedloc.inode, (uint64_t)nlmclnt); + fd = fd_create_uint64(cs->resolvedloc.inode, (uint64_t)(uintptr_t)nlmclnt); if (fd == NULL) { gf_msg(GF_NLM, GF_LOG_ERROR, ENOLCK, NFS_MSG_NO_MEMORY, "fd_create_uint64() returned NULL"); @@ -1009,7 +1011,8 @@ nlm4_establish_callback(nfs3_call_state_t *cs, call_frame_t *cbk_frame) int port = -1; struct nlm4_notify_args *ncf = NULL; - glusterfs_this_set(cs->nfsx); + GF_ASSERT(cs->nfsx); + THIS = cs->nfsx; rpc_transport_get_peeraddr(cs->trans, NULL, 0, &sock_union.storage, sizeof(sock_union.storage)); @@ -1052,6 +1055,12 @@ nlm4_establish_callback(nfs3_call_state_t *cs, call_frame_t *cbk_frame) } options = dict_new(); + if (options == NULL) { + gf_msg(GF_NLM, GF_LOG_ERROR, ENOMEM, NFS_MSG_GFID_DICT_CREATE_FAIL, + "dict allocation failed"); + goto err; + } + ret = dict_set_str(options, "transport-type", "socket"); if (ret == -1) { gf_msg(GF_NLM, GF_LOG_ERROR, errno, NFS_MSG_DICT_SET_FAILED, @@ -1121,6 +1130,8 @@ nlm4_establish_callback(nfs3_call_state_t *cs, call_frame_t *cbk_frame) ret = 0; err: + if (options) + dict_unref(options); if (ret == -1) { if (rpc_clnt) rpc_clnt_unref(rpc_clnt); @@ -1654,7 +1665,8 @@ nlm4_cancel_resume(void *carg) "nlm_get_uniq() returned NULL"); goto nlm4err; } - cs->fd = fd_lookup_uint64(cs->resolvedloc.inode, (uint64_t)nlmclnt); + cs->fd = fd_lookup_uint64(cs->resolvedloc.inode, + (uint64_t)(uintptr_t)nlmclnt); if (cs->fd == NULL) { gf_msg(GF_NLM, GF_LOG_ERROR, errno, NFS_MSG_FD_LOOKUP_NULL, "fd_lookup_uint64 retrned NULL"); @@ -1814,7 +1826,8 @@ nlm4_unlock_resume(void *carg) "nlm_get_uniq() returned NULL for %s", caller_name); goto nlm4err; } - cs->fd = fd_lookup_uint64(cs->resolvedloc.inode, (uint64_t)nlmclnt); + cs->fd = fd_lookup_uint64(cs->resolvedloc.inode, + (uint64_t)(uintptr_t)nlmclnt); if (cs->fd == NULL) { stat = nlm4_granted; gf_msg(GF_NLM, GF_LOG_WARNING, 0, NFS_MSG_FD_LOOKUP_NULL, @@ -1964,14 +1977,14 @@ nlm4_add_share_to_inode(nlm_share_t *share) head = &ictx->shares; INIT_LIST_HEAD(head); - ret = inode_ctx_put(inode, this, (uint64_t)ictx); + ret = inode_ctx_put(inode, this, (uint64_t)(uintptr_t)ictx); if (ret) { gf_msg(this->name, GF_LOG_ERROR, 0, NFS_MSG_SHARE_LIST_STORE_FAIL, "could not store share list"); goto out; } } else { - ictx = (struct nfs_inode_ctx *)ctx; + ictx = (struct nfs_inode_ctx *)(uintptr_t)ctx; head = &ictx->shares; } @@ -2006,7 +2019,7 @@ nlm4_approve_share_reservation(nfs3_call_state_t *cs) ret = 0; goto out; } - ictx = (struct nfs_inode_ctx *)ctx; + ictx = (struct nfs_inode_ctx *)(uintptr_t)ctx; head = &ictx->shares; if (!head || list_empty(head)) @@ -2226,7 +2239,7 @@ nlm4_remove_share_reservation(nfs3_call_state_t *cs) inode->gfid, caller); goto out; } - ictx = (struct nfs_inode_ctx *)ctx; + ictx = (struct nfs_inode_ctx *)(uintptr_t)ctx; head = &ictx->shares; if (list_empty(head)) { @@ -2499,39 +2512,39 @@ out: return ret; } -rpcsvc_actor_t nlm4svc_actors[NLM4_PROC_COUNT] = { +static rpcsvc_actor_t nlm4svc_actors[NLM4_PROC_COUNT] = { /* 0 */ - {"NULL", NLM4_NULL, nlm4svc_null, NULL, 0, DRC_IDEMPOTENT}, - {"TEST", NLM4_TEST, nlm4svc_test, NULL, 0, DRC_IDEMPOTENT}, - {"LOCK", NLM4_LOCK, nlm4svc_lock, NULL, 0, DRC_NON_IDEMPOTENT}, - {"CANCEL", NLM4_CANCEL, nlm4svc_cancel, NULL, 0, DRC_NON_IDEMPOTENT}, - {"UNLOCK", NLM4_UNLOCK, nlm4svc_unlock, NULL, 0, DRC_NON_IDEMPOTENT}, + {"NULL", nlm4svc_null, NULL, NLM4_NULL, DRC_IDEMPOTENT, 0}, + {"TEST", nlm4svc_test, NULL, NLM4_TEST, DRC_IDEMPOTENT, 0}, + {"LOCK", nlm4svc_lock, NULL, NLM4_LOCK, DRC_IDEMPOTENT, 0}, + {"CANCEL", nlm4svc_cancel, NULL, NLM4_CANCEL, DRC_NON_IDEMPOTENT, 0}, + {"UNLOCK", nlm4svc_unlock, NULL, NLM4_UNLOCK, DRC_NON_IDEMPOTENT, 0}, /* 5 */ - {"GRANTED", NLM4_GRANTED, NULL, NULL, 0, DRC_NA}, - {"TEST", NLM4_TEST_MSG, NULL, NULL, 0, DRC_NA}, - {"LOCK", NLM4_LOCK_MSG, NULL, NULL, 0, DRC_NA}, - {"CANCEL", NLM4_CANCEL_MSG, NULL, NULL, 0, DRC_NA}, - {"UNLOCK", NLM4_UNLOCK_MSG, NULL, NULL, 0, DRC_NA}, + {"GRANTED", NULL, NULL, NLM4_GRANTED, DRC_NA, 0}, + {"TEST", NULL, NULL, NLM4_TEST_MSG, DRC_NA, 0}, + {"LOCK", NULL, NULL, NLM4_LOCK_MSG, DRC_NA, 0}, + {"CANCEL", NULL, NULL, NLM4_CANCEL_MSG, DRC_NA, 0}, + {"UNLOCK", NULL, NULL, NLM4_UNLOCK_MSG, DRC_NA, 0}, /* 10 */ - {"GRANTED", NLM4_GRANTED_MSG, NULL, NULL, 0, DRC_NA}, - {"TEST", NLM4_TEST_RES, NULL, NULL, 0, DRC_NA}, - {"LOCK", NLM4_LOCK_RES, NULL, NULL, 0, DRC_NA}, - {"CANCEL", NLM4_CANCEL_RES, NULL, NULL, 0, DRC_NA}, - {"UNLOCK", NLM4_UNLOCK_RES, NULL, NULL, 0, DRC_NA}, + {"GRANTED", NULL, NULL, NLM4_GRANTED_MSG, DRC_NA, 0}, + {"TEST", NULL, NULL, NLM4_TEST_RES, DRC_NA, 0}, + {"LOCK", NULL, NULL, NLM4_LOCK_RES, DRC_NA, 0}, + {"CANCEL", NULL, NULL, NLM4_CANCEL_RES, DRC_NA, 0}, + {"UNLOCK", NULL, NULL, NLM4_UNLOCK_RES, DRC_NA, 0}, /* 15 ; procedures 17,18,19 are not defined by nlm */ - {"GRANTED", NLM4_GRANTED_RES, NULL, NULL, 0, DRC_NA}, - {"SM_NOTIFY", NLM4_SM_NOTIFY, NULL, NULL, 0, DRC_NA}, - {"SEVENTEEN", NLM4_SEVENTEEN, NULL, NULL, 0, DRC_NA}, - {"EIGHTEEN", NLM4_EIGHTEEN, NULL, NULL, 0, DRC_NA}, - {"NINETEEN", NLM4_NINETEEN, NULL, NULL, 0, DRC_NA}, + {"GRANTED", NULL, NULL, NLM4_GRANTED_RES, DRC_NA, 0}, + {"SM_NOTIFY", NULL, NULL, NLM4_SM_NOTIFY, DRC_NA, 0}, + {"SEVENTEEN", NULL, NULL, NLM4_SEVENTEEN, DRC_NA, 0}, + {"EIGHTEEN", NULL, NULL, NLM4_EIGHTEEN, DRC_NA, 0}, + {"NINETEEN", NULL, NULL, NLM4_NINETEEN, DRC_NA, 0}, /* 20 */ - {"SHARE", NLM4_SHARE, nlm4svc_share, NULL, 0, DRC_NON_IDEMPOTENT}, - {"UNSHARE", NLM4_UNSHARE, nlm4svc_unshare, NULL, 0, DRC_NON_IDEMPOTENT}, - {"NM_LOCK", NLM4_NM_LOCK, nlm4svc_nm_lock, NULL, 0, DRC_NON_IDEMPOTENT}, - {"FREE_ALL", NLM4_FREE_ALL, nlm4svc_free_all, NULL, 0, DRC_IDEMPOTENT}, + {"SHARE", nlm4svc_share, NULL, NLM4_SHARE, DRC_NON_IDEMPOTENT, 0}, + {"UNSHARE", nlm4svc_unshare, NULL, NLM4_UNSHARE, DRC_NON_IDEMPOTENT, 0}, + {"NM_LOCK", nlm4svc_nm_lock, NULL, NLM4_NM_LOCK, DRC_NON_IDEMPOTENT, 0}, + {"FREE_ALL", nlm4svc_free_all, NULL, NLM4_FREE_ALL, DRC_IDEMPOTENT, 0}, }; -rpcsvc_program_t nlm4prog = { +static rpcsvc_program_t nlm4prog = { .progname = "NLM4", .prognum = NLM_PROGRAM, .progver = NLM_V4, @@ -2570,7 +2583,6 @@ nlm4svc_init(xlator_t *nfsx) }; FILE *pidfile = NULL; pid_t pid = -1; - static gf_boolean_t nlm4_inited = _gf_false; /* Already inited */ if (nlm4_inited) @@ -2587,6 +2599,11 @@ nlm4svc_init(xlator_t *nfsx) nlm4prog.private = ns; options = dict_new(); + if (options == NULL) { + gf_msg(GF_NLM, GF_LOG_ERROR, ENOMEM, NFS_MSG_GFID_DICT_CREATE_FAIL, + "dict allocation failed"); + goto err; + } ret = gf_asprintf(&portstr, "%d", GF_NLM4_PORT); if (ret == -1) @@ -2628,7 +2645,6 @@ nlm4svc_init(xlator_t *nfsx) if (ret == -1) { gf_msg(GF_NLM, GF_LOG_ERROR, errno, NFS_MSG_LISTENERS_CREATE_FAIL, "Unable to create listeners"); - dict_unref(options); goto err; } INIT_LIST_HEAD(&nlm_client_list); @@ -2699,15 +2715,20 @@ nlm4svc_init(xlator_t *nfsx) goto err; } - (void)gf_thread_create(&thr, NULL, nsm_thread, (void *)NULL, "nfsnsm"); + (void)gf_thread_create(&thr, NULL, nsm_thread, nfsx, "nfsnsm"); timeout.tv_sec = nlm_grace_period; timeout.tv_nsec = 0; gf_timer_call_after(nfsx->ctx, timeout, nlm_grace_period_over, NULL); nlm4_inited = _gf_true; + + if (options) + dict_unref(options); return &nlm4prog; err: + if (options) + dict_unref(options); return NULL; } @@ -2724,7 +2745,7 @@ nlm_priv(xlator_t *this) gf_proc_dump_add_section("nfs.nlm"); - if (TRY_LOCK(&nlm_client_list_lk)) + if ((nlm4_inited == _gf_false) || TRY_LOCK(&nlm_client_list_lk)) goto out; list_for_each_entry(client, &nlm_client_list, nlm_clients) @@ -2735,7 +2756,7 @@ nlm_priv(xlator_t *this) file_count = 0; list_for_each_entry(fde, &client->fdes, fde_list) { - gf_proc_dump_build_key(key, "file", "%ld.gfid", file_count); + gf_proc_dump_build_key(key, "file", "%" PRIu64 ".gfid", file_count); memset(gfid_str, 0, 64); uuid_utoa_r(fde->fd->inode->gfid, gfid_str); gf_proc_dump_write(key, "%s", gfid_str); @@ -2743,7 +2764,7 @@ nlm_priv(xlator_t *this) } gf_proc_dump_build_key(key, "client", "files-locked"); - gf_proc_dump_write(key, "%ld\n", file_count); + gf_proc_dump_write(key, "%" PRIu64 "\n", file_count); client_count++; } @@ -2757,7 +2778,8 @@ out: gf_proc_dump_build_key(key, "nlm", "statedump_error"); gf_proc_dump_write(key, "Unable to dump nlm state because " - "nlm_client_list_lk lock couldn't be acquired"); + "nlm is not initialised or nlm_client_list_lk " + "lock couldn't be acquired"); } return ret; diff --git a/xlators/nfs/server/src/nlm4.h b/xlators/nfs/server/src/nlm4.h index 4755c83f3dc..a22032cac69 100644 --- a/xlators/nfs/server/src/nlm4.h +++ b/xlators/nfs/server/src/nlm4.h @@ -14,17 +14,17 @@ #include <sys/types.h> #include <signal.h> #include "rpcsvc.h" -#include "dict.h" -#include "xlator.h" -#include "iobuf.h" +#include <glusterfs/dict.h> +#include <glusterfs/xlator.h> +#include <glusterfs/iobuf.h> #include "nfs.h" -#include "list.h" +#include <glusterfs/list.h> #include "xdr-nfs3.h" -#include "locking.h" +#include <glusterfs/locking.h> #include "nfs3-fh.h" -#include "compat-uuid.h" +#include <glusterfs/compat-uuid.h> #include "nlm4-xdr.h" -#include "lkowner.h" +#include <glusterfs/lkowner.h> #define NLM4_NULL 0 #define NLM4_TEST 1 diff --git a/xlators/nfs/server/src/nlmcbk_svc.c b/xlators/nfs/server/src/nlmcbk_svc.c index 1d57f415e2c..eaa7b916190 100644 --- a/xlators/nfs/server/src/nlmcbk_svc.c +++ b/xlators/nfs/server/src/nlmcbk_svc.c @@ -14,7 +14,7 @@ */ #include "nlm4.h" -#include "logging.h" +#include <glusterfs/logging.h> #include "nfs-messages.h" #include <stdio.h> #include <stdlib.h> @@ -84,9 +84,14 @@ nlmcbk_program_0(struct svc_req *rqstp, register SVCXPRT *transp) void * nsm_thread(void *argv) { + xlator_t *nfsx = argv; register SVCXPRT *transp; int ret = 0; + GF_ASSERT(nfsx); + + THIS = nfsx; + ret = pmap_unset(NLMCBK_PROGRAM, NLMCBK_V1); if (ret == 0) { gf_msg(GF_NLM, GF_LOG_ERROR, 0, NFS_MSG_PMAP_UNSET_FAIL, |
