diff options
Diffstat (limited to 'xlators/features/snapview-server/src')
7 files changed, 566 insertions, 343 deletions
diff --git a/xlators/features/snapview-server/src/Makefile.am b/xlators/features/snapview-server/src/Makefile.am index 2d39759ff80..2935f138a4c 100644 --- a/xlators/features/snapview-server/src/Makefile.am +++ b/xlators/features/snapview-server/src/Makefile.am @@ -13,7 +13,7 @@ snapview_server_la_LIBADD = $(top_builddir)/libglusterfs/src/libglusterfs.la \ $(RLLIBS) $(top_builddir)/rpc/xdr/src/libgfxdr.la \ $(top_builddir)/rpc/rpc-lib/src/libgfrpc.la -noinst_HEADERS = snapview-server.h snapview-server-mem-types.h +noinst_HEADERS = snapview-server.h snapview-server-mem-types.h snapview-server-messages.h AM_CPPFLAGS = $(GF_CPPFLAGS) -I$(top_srcdir)/libglusterfs/src \ -I$(top_srcdir)/api/src -I$(top_srcdir)/rpc/rpc-lib/src \ diff --git a/xlators/features/snapview-server/src/snapview-server-helpers.c b/xlators/features/snapview-server/src/snapview-server-helpers.c index 2559c4e089b..62c1ddac49c 100644 --- a/xlators/features/snapview-server/src/snapview-server-helpers.c +++ b/xlators/features/snapview-server/src/snapview-server-helpers.c @@ -10,7 +10,7 @@ #include "snapview-server.h" #include "snapview-server-mem-types.h" -#include "xlator.h" +#include <glusterfs/xlator.h> #include "rpc-clnt.h" #include "xdr-generic.h" #include "protocol-common.h" @@ -238,7 +238,7 @@ __svs_fd_ctx_get_or_new(xlator_t *this, fd_t *fd) svs_fd = svs_fd_new(); if (!svs_fd) { - gf_log(this->name, GF_LOG_ERROR, + gf_msg(this->name, GF_LOG_ERROR, 0, SVS_MSG_NEW_FD_CTX_FAILED, "failed to allocate new fd " "context for gfid %s", uuid_utoa(inode->gfid)); @@ -248,7 +248,8 @@ __svs_fd_ctx_get_or_new(xlator_t *this, fd_t *fd) if (fd_is_anonymous(fd)) { inode_ctx = svs_inode_ctx_get(this, inode); if (!inode_ctx) { - gf_log(this->name, GF_LOG_ERROR, + gf_msg(this->name, GF_LOG_ERROR, 0, + SVS_MSG_GET_INODE_CONTEXT_FAILED, "failed to get inode " "context for %s", uuid_utoa(inode->gfid)); @@ -261,7 +262,7 @@ __svs_fd_ctx_get_or_new(xlator_t *this, fd_t *fd) if (inode->ia_type == IA_IFDIR) { glfd = glfs_h_opendir(fs, object); if (!glfd) { - gf_log(this->name, GF_LOG_ERROR, + gf_msg(this->name, GF_LOG_ERROR, errno, SVS_MSG_OPENDIR_FAILED, "failed to " "open the directory %s", uuid_utoa(inode->gfid)); @@ -272,7 +273,7 @@ __svs_fd_ctx_get_or_new(xlator_t *this, fd_t *fd) if (inode->ia_type == IA_IFREG) { glfd = glfs_h_open(fs, object, O_RDONLY | O_LARGEFILE); if (!glfd) { - gf_log(this->name, GF_LOG_ERROR, + gf_msg(this->name, GF_LOG_ERROR, errno, SVS_MSG_OPEN_FAILED, "failed to " "open the file %s", uuid_utoa(inode->gfid)); @@ -285,7 +286,7 @@ __svs_fd_ctx_get_or_new(xlator_t *this, fd_t *fd) ret = __svs_fd_ctx_set(this, fd, svs_fd); if (ret) { - gf_log(this->name, GF_LOG_ERROR, + gf_msg(this->name, GF_LOG_ERROR, 0, SVS_MSG_SET_FD_CONTEXT_FAILED, "failed to set fd context " "for gfid %s", uuid_utoa(inode->gfid)); @@ -293,14 +294,15 @@ __svs_fd_ctx_get_or_new(xlator_t *this, fd_t *fd) if (inode->ia_type == IA_IFDIR) { ret = glfs_closedir(svs_fd->fd); if (ret) - gf_log(this->name, GF_LOG_ERROR, + gf_msg(this->name, GF_LOG_ERROR, errno, + SVS_MSG_CLOSEDIR_FAILED, "failed to close the fd for %s", uuid_utoa(inode->gfid)); } if (inode->ia_type == IA_IFREG) { ret = glfs_close(svs_fd->fd); if (ret) - gf_log(this->name, GF_LOG_ERROR, + gf_msg(this->name, GF_LOG_ERROR, 0, SVS_MSG_CLOSE_FAILED, "failed to close the fd for %s", uuid_utoa(inode->gfid)); } @@ -352,7 +354,7 @@ svs_uuid_generate(xlator_t *this, uuid_t gfid, char *snapname, uuid_utoa(origin_gfid)); if (gf_gfid_generate_from_xxh64(tmp, ino_string)) { - gf_log(this->name, GF_LOG_WARNING, + gf_msg(this->name, GF_LOG_WARNING, 0, SVS_MSG_GFID_GEN_FAILED, "failed to generate " "gfid for object with actual gfid of %s " "(snapname: %s, key: %s)", @@ -364,7 +366,7 @@ svs_uuid_generate(xlator_t *this, uuid_t gfid, char *snapname, ret = 0; - gf_log(this->name, GF_LOG_DEBUG, "gfid generated is %s ", uuid_utoa(gfid)); + gf_msg_debug(this->name, 0, "gfid generated is %s ", uuid_utoa(gfid)); out: return ret; @@ -474,6 +476,7 @@ __svs_initialise_snapshot_volume(xlator_t *this, const char *name, char logfile[PATH_MAX] = { 0, }; + char *volfile_server = NULL; GF_VALIDATE_OR_GOTO("snapview-server", this, out); GF_VALIDATE_OR_GOTO(this->name, this->private, out); @@ -483,10 +486,10 @@ __svs_initialise_snapshot_volume(xlator_t *this, const char *name, dirent = __svs_get_snap_dirent(this, name); if (!dirent) { - gf_log(this->name, GF_LOG_DEBUG, - "snap entry for " - "name %s not found", - name); + gf_msg_debug(this->name, 0, + "snap entry for " + "name %s not found", + name); local_errno = ENOENT; goto out; } @@ -502,21 +505,58 @@ __svs_initialise_snapshot_volume(xlator_t *this, const char *name, fs = glfs_new(volname); if (!fs) { - gf_log(this->name, GF_LOG_ERROR, + local_errno = ENOMEM; + gf_msg(this->name, GF_LOG_ERROR, local_errno, SVS_MSG_GLFS_NEW_FAILED, "glfs instance for snap volume %s " "failed", dirent->name); - local_errno = ENOMEM; goto out; } - ret = glfs_set_volfile_server(fs, "tcp", "localhost", 24007); + /* + * Before, localhost was used as the volfile server. But, with that + * method, accessing snapshots started giving ENOENT error if a + * specific bind address is mentioned in the glusterd volume file. + * Check the bug https://bugzilla.redhat.com/show_bug.cgi?id=1725211. + * So, the new method is tried below, where, snapview-server first + * uses the volfile server used by the snapd (obtained from the + * command line arguments saved in the global context of the process). + * If the volfile server in global context is NULL, then localhost + * is tried (like before). + */ + if (this->ctx->cmd_args.volfile_server) { + volfile_server = gf_strdup(this->ctx->cmd_args.volfile_server); + if (!volfile_server) { + gf_msg(this->name, GF_LOG_WARNING, ENOMEM, + SVS_MSG_VOLFILE_SERVER_GET_FAIL, + "failed to copy volfile server %s. ", + this->ctx->cmd_args.volfile_server); + ret = -1; + goto out; + } + } else { + gf_msg(this->name, GF_LOG_WARNING, ENOMEM, + SVS_MSG_VOLFILE_SERVER_GET_FAIL, + "volfile server is NULL in cmd args. " + "Trying with localhost"); + volfile_server = gf_strdup("localhost"); + if (!volfile_server) { + gf_msg(this->name, GF_LOG_WARNING, ENOMEM, + SVS_MSG_VOLFILE_SERVER_GET_FAIL, + "failed to copy volfile server localhost."); + ret = -1; + goto out; + } + } + + ret = glfs_set_volfile_server(fs, "tcp", volfile_server, 24007); if (ret) { - gf_log(this->name, GF_LOG_ERROR, + gf_msg(this->name, GF_LOG_ERROR, local_errno, + SVS_MSG_SET_VOLFILE_SERVR_FAILED, "setting the " - "volfile server for snap volume %s " + "volfile server %s for snap volume %s " "failed", - dirent->name); + volfile_server, dirent->name); goto out; } @@ -526,7 +566,8 @@ __svs_initialise_snapshot_volume(xlator_t *this, const char *name, ret = glfs_set_logging(fs, logfile, loglevel); if (ret) { - gf_log(this->name, GF_LOG_ERROR, + gf_msg(this->name, GF_LOG_ERROR, local_errno, + SVS_MSG_SET_LOGGING_FAILED, "failed to set the " "log file path"); goto out; @@ -534,7 +575,7 @@ __svs_initialise_snapshot_volume(xlator_t *this, const char *name, ret = glfs_init(fs); if (ret) { - gf_log(this->name, GF_LOG_ERROR, + gf_msg(this->name, GF_LOG_ERROR, local_errno, SVS_MSG_GLFS_INIT_FAILED, "initing the " "fs for %s failed", dirent->name); @@ -557,6 +598,7 @@ out: dirent->fs = fs; } + GF_FREE(volfile_server); return fs; } @@ -659,7 +701,7 @@ svs_inode_glfs_mapping(xlator_t *this, inode_t *inode) inode_ctx = svs_inode_ctx_get(this, inode); if (!inode_ctx) { - gf_log(this->name, GF_LOG_ERROR, + gf_msg(this->name, GF_LOG_ERROR, 0, SVS_MSG_GET_INODE_CONTEXT_FAILED, "inode context not found for" " the inode %s", uuid_utoa(inode->gfid)); diff --git a/xlators/features/snapview-server/src/snapview-server-mem-types.h b/xlators/features/snapview-server/src/snapview-server-mem-types.h index 504c7969bdc..63456b85323 100644 --- a/xlators/features/snapview-server/src/snapview-server-mem-types.h +++ b/xlators/features/snapview-server/src/snapview-server-mem-types.h @@ -11,7 +11,7 @@ #ifndef __SNAP_VIEW_MEM_TYPES_H #define __SNAP_VIEW_MEM_TYPES_H -#include "mem-types.h" +#include <glusterfs/mem-types.h> enum snapview_mem_types { gf_svs_mt_priv_t = gf_common_mt_end + 1, diff --git a/xlators/features/snapview-server/src/snapview-server-messages.h b/xlators/features/snapview-server/src/snapview-server-messages.h new file mode 100644 index 00000000000..f634ab5d2b0 --- /dev/null +++ b/xlators/features/snapview-server/src/snapview-server-messages.h @@ -0,0 +1,54 @@ +/* + Copyright (c) 2018 Red Hat, Inc. <http://www.redhat.com> + This file is part of GlusterFS. + + This file is licensed to you under your choice of the GNU Lesser + General Public License, version 3 or any later version (LGPLv3 or + later), or the GNU General Public License, version 2 (GPLv2), in all + cases as published by the Free Software Foundation. + */ + +#ifndef _SNAPVIEW_SERVER_MESSAGES_H_ +#define _SNAPVIEW_SERVER_MESSAGES_H_ + +#include <glusterfs/glfs-message-id.h> + +/* To add new message IDs, append new identifiers at the end of the list. + * + * Never remove a message ID. If it's not used anymore, you can rename it or + * leave it as it is, but not delete it. This is to prevent reutilization of + * IDs by other messages. + * + * The component name must match one of the entries defined in + * glfs-message-id.h. + */ + +GLFS_MSGID(SNAPVIEW_SERVER, SVS_MSG_NO_MEMORY, SVS_MSG_MEM_ACNT_FAILED, + SVS_MSG_NULL_GFID, SVS_MSG_GET_LATEST_SNAP_FAILED, + SVS_MSG_INVALID_GLFS_CTX, SVS_MSG_LOCK_DESTROY_FAILED, + SVS_MSG_SNAPSHOT_LIST_CHANGED, SVS_MSG_MGMT_INIT_FAILED, + SVS_MSG_GET_SNAPSHOT_LIST_FAILED, SVS_MSG_GET_GLFS_H_OBJECT_FAILED, + SVS_MSG_PARENT_CTX_OR_NAME_NULL, SVS_MSG_SET_INODE_CONTEXT_FAILED, + SVS_MSG_GET_INODE_CONTEXT_FAILED, SVS_MSG_NEW_INODE_CTX_FAILED, + SVS_MSG_DELETE_INODE_CONTEXT_FAILED, SVS_MSG_SET_FD_CONTEXT_FAILED, + SVS_MSG_NEW_FD_CTX_FAILED, SVS_MSG_DELETE_FD_CTX_FAILED, + SVS_MSG_GETXATTR_FAILED, SVS_MSG_LISTXATTR_FAILED, + SVS_MSG_RELEASEDIR_FAILED, SVS_MSG_RELEASE_FAILED, + SVS_MSG_TELLDIR_FAILED, SVS_MSG_STAT_FAILED, SVS_MSG_STATFS_FAILED, + SVS_MSG_OPEN_FAILED, SVS_MSG_READ_FAILED, SVS_MSG_READLINK_FAILED, + SVS_MSG_ACCESS_FAILED, SVS_MSG_GET_FD_CONTEXT_FAILED, + SVS_MSG_DICT_SET_FAILED, SVS_MSG_OPENDIR_FAILED, + SVS_MSG_FS_INSTANCE_INVALID, SVS_MSG_SETFSUID_FAIL, + SVS_MSG_SETFSGID_FAIL, SVS_MSG_SETFSGRPS_FAIL, + SVS_MSG_BUILD_TRNSPRT_OPT_FAILED, SVS_MSG_RPC_INIT_FAILED, + SVS_MSG_REG_NOTIFY_FAILED, SVS_MSG_REG_CBK_PRGM_FAILED, + SVS_MSG_RPC_CLNT_START_FAILED, SVS_MSG_XDR_PAYLOAD_FAILED, + SVS_MSG_NULL_CTX, SVS_MSG_RPC_CALL_FAILED, SVS_MSG_XDR_DECODE_FAILED, + SVS_MSG_RSP_DICT_EMPTY, SVS_MSG_DICT_GET_FAILED, + SVS_MSG_SNAP_LIST_REFRESH_FAILED, SVS_MSG_RPC_REQ_FAILED, + SVS_MSG_CLOSEDIR_FAILED, SVS_MSG_CLOSE_FAILED, + SVS_MSG_GFID_GEN_FAILED, SVS_MSG_GLFS_NEW_FAILED, + SVS_MSG_SET_VOLFILE_SERVR_FAILED, SVS_MSG_SET_LOGGING_FAILED, + SVS_MSG_VOLFILE_SERVER_GET_FAIL, SVS_MSG_GLFS_INIT_FAILED); + +#endif /* !_SNAPVIEW_CLIENT_MESSAGES_H_ */ diff --git a/xlators/features/snapview-server/src/snapview-server-mgmt.c b/xlators/features/snapview-server/src/snapview-server-mgmt.c index aff00221032..ecf31c3b880 100644 --- a/xlators/features/snapview-server/src/snapview-server-mgmt.c +++ b/xlators/features/snapview-server/src/snapview-server-mgmt.c @@ -19,17 +19,18 @@ mgmt_cbk_snap(struct rpc_clnt *rpc, void *mydata, void *data) this = mydata; GF_ASSERT(this); - gf_log("mgmt", GF_LOG_INFO, "list of snapshots changed"); + gf_msg("mgmt", GF_LOG_INFO, 0, SVS_MSG_SNAPSHOT_LIST_CHANGED, + "list of snapshots changed"); svs_get_snapshot_list(this); return 0; } -rpcclnt_cb_actor_t svs_cbk_actors[GF_CBK_MAXVALUE] = { - [GF_CBK_GET_SNAPS] = {"GETSNAPS", GF_CBK_GET_SNAPS, mgmt_cbk_snap}, +static rpcclnt_cb_actor_t svs_cbk_actors[GF_CBK_MAXVALUE] = { + [GF_CBK_GET_SNAPS] = {"GETSNAPS", mgmt_cbk_snap, GF_CBK_GET_SNAPS}, }; -struct rpcclnt_cb_program svs_cbk_prog = { +static struct rpcclnt_cb_program svs_cbk_prog = { .progname = "GlusterFS Callback", .prognum = GLUSTER_CBK_PROGRAM, .progver = GLUSTER_CBK_VERSION, @@ -37,12 +38,12 @@ struct rpcclnt_cb_program svs_cbk_prog = { .numactors = GF_CBK_MAXVALUE, }; -char *clnt_handshake_procs[GF_HNDSK_MAXVALUE] = { +static char *clnt_handshake_procs[GF_HNDSK_MAXVALUE] = { [GF_HNDSK_NULL] = "NULL", [GF_HNDSK_EVENT_NOTIFY] = "EVENTNOTIFY", }; -rpc_clnt_prog_t svs_clnt_handshake_prog = { +static rpc_clnt_prog_t svs_clnt_handshake_prog = { .progname = "GlusterFS Handshake", .prognum = GLUSTER_HNDSK_PROGRAM, .progver = GLUSTER_HNDSK_VERSION, @@ -62,7 +63,8 @@ svs_rpc_notify(struct rpc_clnt *rpc, void *mydata, rpc_clnt_event_t event, case RPC_CLNT_CONNECT: ret = svs_get_snapshot_list(this); if (ret) { - gf_log(this->name, GF_LOG_ERROR, + gf_msg(this->name, GF_LOG_ERROR, EINVAL, + SVS_MSG_GET_SNAPSHOT_LIST_FAILED, "Error in refreshing the snaplist " "infrastructure"); ret = -1; @@ -84,6 +86,7 @@ svs_mgmt_init(xlator_t *this) char *host = NULL; cmd_args_t *cmd_args = NULL; glusterfs_ctx_t *ctx = NULL; + xlator_cmdline_option_t *opt = NULL; GF_VALIDATE_OR_GOTO("snapview-server", this, out); GF_VALIDATE_OR_GOTO(this->name, this->private, out); @@ -98,9 +101,15 @@ svs_mgmt_init(xlator_t *this) if (cmd_args->volfile_server) host = cmd_args->volfile_server; - ret = rpc_transport_inet_options_build(&options, host, port); + options = dict_new(); + if (!options) + goto out; + + opt = find_xlator_option_in_cmd_args_t("address-family", cmd_args); + ret = rpc_transport_inet_options_build(options, host, port, + (opt != NULL ? opt->value : NULL)); if (ret) { - gf_log(this->name, GF_LOG_ERROR, + gf_msg(this->name, GF_LOG_ERROR, 0, SVS_MSG_BUILD_TRNSPRT_OPT_FAILED, "failed to build the " "transport options"); goto out; @@ -108,26 +117,28 @@ svs_mgmt_init(xlator_t *this) priv->rpc = rpc_clnt_new(options, this, this->name, 8); if (!priv->rpc) { - gf_log(this->name, GF_LOG_ERROR, "failed to initialize RPC"); + gf_msg(this->name, GF_LOG_ERROR, 0, SVS_MSG_RPC_INIT_FAILED, + "failed to initialize RPC"); goto out; } ret = rpc_clnt_register_notify(priv->rpc, svs_rpc_notify, this); if (ret) { - gf_log(this->name, GF_LOG_WARNING, + gf_msg(this->name, GF_LOG_WARNING, 0, SVS_MSG_REG_NOTIFY_FAILED, "failed to register notify function"); goto out; } ret = rpcclnt_cbk_program_register(priv->rpc, &svs_cbk_prog, this); if (ret) { - gf_log(this->name, GF_LOG_ERROR, "failed to register callback program"); + gf_msg(this->name, GF_LOG_ERROR, 0, SVS_MSG_REG_CBK_PRGM_FAILED, + "failed to register callback program"); goto out; } ret = rpc_clnt_start(priv->rpc); if (ret) { - gf_log(this->name, GF_LOG_ERROR, + gf_msg(this->name, GF_LOG_ERROR, 0, SVS_MSG_RPC_CLNT_START_FAILED, "failed to start the rpc " "client"); goto out; @@ -135,9 +146,11 @@ svs_mgmt_init(xlator_t *this) ret = 0; - gf_log(this->name, GF_LOG_DEBUG, "svs mgmt init successful"); + gf_msg_debug(this->name, 0, "svs mgmt init successful"); out: + if (options) + dict_unref(options); if (ret) if (priv) { rpc_clnt_connection_cleanup(&priv->rpc->conn); @@ -171,6 +184,9 @@ svs_mgmt_submit_request(void *req, call_frame_t *frame, glusterfs_ctx_t *ctx, iobref = iobref_new(); if (!iobref) { + gf_msg(frame->this->name, GF_LOG_WARNING, ENOMEM, SVS_MSG_NO_MEMORY, + "failed to allocate " + "new iobref"); goto out; } @@ -190,8 +206,8 @@ svs_mgmt_submit_request(void *req, call_frame_t *frame, glusterfs_ctx_t *ctx, /* Create the xdr payload */ ret = xdr_serialize_generic(iov, req, xdrproc); if (ret == -1) { - gf_log(frame->this->name, GF_LOG_WARNING, - "Failed to create XDR payload"); + gf_msg(frame->this->name, GF_LOG_WARNING, 0, + SVS_MSG_XDR_PAYLOAD_FAILED, "Failed to create XDR payload"); goto out; } iov.iov_len = ret; @@ -221,7 +237,8 @@ mgmt_get_snapinfo_cbk(struct rpc_req *req, struct iovec *iov, int count, glusterfs_ctx_t *ctx = NULL; int ret = -1; dict_t *dict = NULL; - char key[1024] = {0}; + char key[32] = {0}; + int len; int snapcount = 0; svs_private_t *priv = NULL; xlator_t *this = NULL; @@ -240,23 +257,24 @@ mgmt_get_snapinfo_cbk(struct rpc_req *req, struct iovec *iov, int count, this = frame->this; ctx = frame->this->ctx; priv = this->private; - old_dirents = priv->dirents; if (!ctx) { - gf_log(frame->this->name, GF_LOG_ERROR, "NULL context"); errno = EINVAL; + gf_msg(frame->this->name, GF_LOG_ERROR, errno, SVS_MSG_NULL_CTX, + "NULL context"); goto out; } if (-1 == req->rpc_status) { - gf_log(frame->this->name, GF_LOG_ERROR, "RPC call is not successful"); errno = EINVAL; + gf_msg(frame->this->name, GF_LOG_ERROR, errno, SVS_MSG_RPC_CALL_FAILED, + "RPC call is not successful"); goto out; } ret = xdr_to_generic(*iov, &rsp, (xdrproc_t)xdr_gf_getsnap_name_uuid_rsp); if (ret < 0) { - gf_log(frame->this->name, GF_LOG_ERROR, + gf_msg(frame->this->name, GF_LOG_ERROR, 0, SVS_MSG_XDR_DECODE_FAILED, "Failed to decode xdr response, rsp.op_ret = %d", rsp.op_ret); goto out; } @@ -268,10 +286,10 @@ mgmt_get_snapinfo_cbk(struct rpc_req *req, struct iovec *iov, int count, } if (!rsp.dict.dict_len) { - gf_log(frame->this->name, GF_LOG_ERROR, - "Response dict is not populated"); ret = -1; errno = EINVAL; + gf_msg(frame->this->name, GF_LOG_ERROR, errno, SVS_MSG_RSP_DICT_EMPTY, + "Response dict is not populated"); goto out; } @@ -284,17 +302,18 @@ mgmt_get_snapinfo_cbk(struct rpc_req *req, struct iovec *iov, int count, ret = dict_unserialize(rsp.dict.dict_val, rsp.dict.dict_len, &dict); if (ret) { - gf_log(frame->this->name, GF_LOG_ERROR, - "Failed to unserialize dictionary"); errno = EINVAL; + gf_msg(frame->this->name, GF_LOG_ERROR, errno, + LG_MSG_DICT_UNSERIAL_FAILED, "Failed to unserialize dictionary"); goto out; } ret = dict_get_int32(dict, "snap-count", (int32_t *)&snapcount); if (ret) { - gf_log(this->name, GF_LOG_ERROR, "Error retrieving snapcount"); errno = EINVAL; ret = -1; + gf_msg(this->name, GF_LOG_ERROR, errno, SVS_MSG_DICT_GET_FAILED, + "Error retrieving snapcount"); goto out; } @@ -303,46 +322,46 @@ mgmt_get_snapinfo_cbk(struct rpc_req *req, struct iovec *iov, int count, dirents = GF_CALLOC(snapcount, sizeof(snap_dirent_t), gf_svs_mt_dirents_t); if (!dirents) { - gf_log(frame->this->name, GF_LOG_ERROR, - "Unable to allocate memory"); errno = ENOMEM; ret = -1; + gf_msg(frame->this->name, GF_LOG_ERROR, errno, SVS_MSG_NO_MEMORY, + "Unable to allocate memory"); goto out; } } for (i = 0; i < snapcount; i++) { - snprintf(key, sizeof(key), "snap-volname.%d", i + 1); - ret = dict_get_str(dict, key, &value); + len = snprintf(key, sizeof(key), "snap-volname.%d", i + 1); + ret = dict_get_strn(dict, key, len, &value); if (ret) { - gf_log(this->name, GF_LOG_ERROR, "Error retrieving snap volname %d", - i + 1); errno = EINVAL; ret = -1; + gf_msg(this->name, GF_LOG_ERROR, errno, SVS_MSG_DICT_GET_FAILED, + "Error retrieving snap volname %d", i + 1); goto out; } strncpy(dirents[i].snap_volname, value, sizeof(dirents[i].snap_volname)); - snprintf(key, sizeof(key), "snap-id.%d", i + 1); - ret = dict_get_str(dict, key, &value); + len = snprintf(key, sizeof(key), "snap-id.%d", i + 1); + ret = dict_get_strn(dict, key, len, &value); if (ret) { - gf_log(this->name, GF_LOG_ERROR, "Error retrieving snap uuid %d", - i + 1); errno = EINVAL; ret = -1; + gf_msg(this->name, GF_LOG_ERROR, errno, SVS_MSG_DICT_GET_FAILED, + "Error retrieving snap uuid %d", i + 1); goto out; } strncpy(dirents[i].uuid, value, sizeof(dirents[i].uuid)); - snprintf(key, sizeof(key), "snapname.%d", i + 1); - ret = dict_get_str(dict, key, &value); + len = snprintf(key, sizeof(key), "snapname.%d", i + 1); + ret = dict_get_strn(dict, key, len, &value); if (ret) { - gf_log(this->name, GF_LOG_ERROR, "Error retrieving snap name %d", - i + 1); errno = EINVAL; ret = -1; + gf_msg(this->name, GF_LOG_ERROR, errno, SVS_MSG_DICT_GET_FAILED, + "Error retrieving snap name %d", i + 1); goto out; } strncpy(dirents[i].name, value, sizeof(dirents[i].name)); @@ -369,6 +388,7 @@ mgmt_get_snapinfo_cbk(struct rpc_req *req, struct iovec *iov, int count, LOCK(&priv->snaplist_lock); { oldcount = priv->num_snaps; + old_dirents = priv->dirents; for (i = 0; i < priv->num_snaps; i++) { for (j = 0; j < snapcount; j++) { if ((!strcmp(old_dirents[i].name, dirents[j].name)) && @@ -388,7 +408,12 @@ mgmt_get_snapinfo_cbk(struct rpc_req *req, struct iovec *iov, int count, if (old_dirents) { for (i = 0; i < oldcount; i++) { if (old_dirents[i].fs) - glfs_fini(old_dirents[i].fs); + gf_msg_debug(this->name, 0, + "calling glfs_fini on " + "name: %s, snap_volname: %s, uuid: %s", + old_dirents[i].name, old_dirents[i].snap_volname, + old_dirents[i].uuid); + glfs_fini(old_dirents[i].fs); } } @@ -404,7 +429,7 @@ out: free(rsp.op_errstr); if (ret && dirents) { - gf_log(this->name, GF_LOG_WARNING, + gf_msg(this->name, GF_LOG_WARNING, 0, SVS_MSG_SNAP_LIST_REFRESH_FAILED, "Could not update dirents with refreshed snap list"); GF_FREE(dirents); } @@ -433,13 +458,14 @@ svs_get_snapshot_list(xlator_t *this) ctx = this->ctx; if (!ctx) { - gf_log(this->name, GF_LOG_ERROR, "ctx is NULL"); + gf_msg(this->name, GF_LOG_ERROR, 0, SVS_MSG_NULL_CTX, "ctx is NULL"); goto out; } frame = create_frame(this, ctx->pool); if (!frame) { - gf_log(this->name, GF_LOG_ERROR, "Error allocating frame"); + gf_msg(this->name, GF_LOG_ERROR, 0, LG_MSG_FRAME_ERROR, + "Error allocating frame"); goto out; } @@ -447,20 +473,23 @@ svs_get_snapshot_list(xlator_t *this) dict = dict_new(); if (!dict) { - gf_log(this->name, GF_LOG_ERROR, "Error allocating dictionary"); + gf_msg(this->name, GF_LOG_ERROR, ENOMEM, SVS_MSG_NO_MEMORY, + "Error allocating dictionary"); goto out; } ret = dict_set_str(dict, "volname", priv->volname); if (ret) { - gf_log(this->name, GF_LOG_ERROR, "Error setting volname in dict"); + gf_msg(this->name, GF_LOG_ERROR, 0, SVS_MSG_DICT_SET_FAILED, + "Error setting volname in dict"); goto out; } ret = dict_allocate_and_serialize(dict, &req.dict.dict_val, &req.dict.dict_len); if (ret) { - gf_log(this->name, GF_LOG_ERROR, "Failed to serialize dictionary"); + gf_msg(this->name, GF_LOG_ERROR, 0, LG_MSG_DICT_UNSERIAL_FAILED, + "Failed to serialize dictionary"); ret = -1; goto out; } @@ -470,7 +499,7 @@ svs_get_snapshot_list(xlator_t *this) mgmt_get_snapinfo_cbk, (xdrproc_t)xdr_gf_getsnap_name_uuid_req); if (ret) { - gf_log(this->name, GF_LOG_ERROR, + gf_msg(this->name, GF_LOG_ERROR, 0, SVS_MSG_RPC_REQ_FAILED, "Error sending snapshot names RPC request"); } diff --git a/xlators/features/snapview-server/src/snapview-server.c b/xlators/features/snapview-server/src/snapview-server.c index 6019be62075..76cccae5914 100644 --- a/xlators/features/snapview-server/src/snapview-server.c +++ b/xlators/features/snapview-server/src/snapview-server.c @@ -9,15 +9,17 @@ */ #include "snapview-server.h" #include "snapview-server-mem-types.h" -#include "compat-errno.h" +#include <glusterfs/compat-errno.h> -#include "xlator.h" +#include <glusterfs/xlator.h> #include "rpc-clnt.h" #include "xdr-generic.h" #include "protocol-common.h" -#include "syscall.h" +#include <glusterfs/syscall.h> #include <pthread.h> +#include "glfs-internal.h" + int gf_setcredentials(uid_t *uid, gid_t *gid, uint16_t ngrps, uint32_t *groups) { @@ -26,7 +28,7 @@ gf_setcredentials(uid_t *uid, gid_t *gid, uint16_t ngrps, uint32_t *groups) if (uid) { ret = glfs_setfsuid(*uid); if (ret != 0) { - gf_log("snapview-server", GF_LOG_ERROR, + gf_msg("snapview-server", GF_LOG_ERROR, 0, SVS_MSG_SETFSUID_FAIL, "failed to set uid " "%u in thread context", *uid); @@ -36,7 +38,7 @@ gf_setcredentials(uid_t *uid, gid_t *gid, uint16_t ngrps, uint32_t *groups) if (gid) { ret = glfs_setfsgid(*gid); if (ret != 0) { - gf_log("snapview-server", GF_LOG_ERROR, + gf_msg("snapview-server", GF_LOG_ERROR, 0, SVS_MSG_SETFSGID_FAIL, "failed to set gid " "%u in thread context", *gid); @@ -47,7 +49,7 @@ gf_setcredentials(uid_t *uid, gid_t *gid, uint16_t ngrps, uint32_t *groups) if (ngrps != 0 && groups) { ret = glfs_setfsgroups(ngrps, groups); if (ret != 0) { - gf_log("snapview-server", GF_LOG_ERROR, + gf_msg("snapview-server", GF_LOG_ERROR, 0, SVS_MSG_SETFSGRPS_FAIL, "failed to set " "groups in thread context"); return ret; @@ -88,12 +90,13 @@ svs_lookup_entry_point(xlator_t *this, loc_t *loc, inode_t *parent, inode_ctx = svs_inode_ctx_get_or_new(this, loc->inode); if (!inode_ctx) { - gf_log(this->name, GF_LOG_ERROR, + op_ret = -1; + *op_errno = ENOMEM; + gf_msg(this->name, GF_LOG_ERROR, *op_errno, + SVS_MSG_NEW_INODE_CTX_FAILED, "failed to " "allocate inode context for entry point " "directory"); - op_ret = -1; - *op_errno = ENOMEM; goto out; } @@ -162,7 +165,7 @@ svs_lookup_gfid(xlator_t *this, loc_t *loc, struct iatt *buf, GF_VALIDATE_OR_GOTO(this->name, postparent, out); if (gf_uuid_is_null(loc->gfid) && gf_uuid_is_null(loc->inode->gfid)) { - gf_log(this->name, GF_LOG_ERROR, "gfid is NULL"); + gf_msg(this->name, GF_LOG_ERROR, 0, SVS_MSG_NULL_GFID, "gfid is NULL"); goto out; } @@ -173,33 +176,36 @@ svs_lookup_gfid(xlator_t *this, loc_t *loc, struct iatt *buf, fs = svs_get_latest_snapshot(this); if (!fs) { - gf_log(this->name, GF_LOG_ERROR, - "failed to get the latest " - "snapshot"); op_ret = -1; *op_errno = EINVAL; + gf_msg(this->name, GF_LOG_ERROR, *op_errno, + SVS_MSG_GET_LATEST_SNAP_FAILED, + "failed to get the latest " + "snapshot"); goto out; } object = glfs_h_create_from_handle(fs, handle_obj, GFAPI_HANDLE_LENGTH, &statbuf); if (!object) { - gf_log(this->name, GF_LOG_ERROR, + op_ret = -1; + *op_errno = ESTALE; + gf_msg(this->name, GF_LOG_ERROR, *op_errno, + SVS_MSG_GET_GLFS_H_OBJECT_FAILED, "failed to do lookup and get " "the handle on the snapshot %s (path: %s, gfid: %s)", loc->name, loc->path, uuid_utoa(loc->gfid)); - op_ret = -1; - *op_errno = ESTALE; goto out; } inode_ctx = svs_inode_ctx_get_or_new(this, loc->inode); if (!inode_ctx) { - gf_log(this->name, GF_LOG_ERROR, - "failed to allocate inode " - "context"); op_ret = -1; *op_errno = ENOMEM; + gf_msg(this->name, GF_LOG_ERROR, *op_errno, + SVS_MSG_NEW_INODE_CTX_FAILED, + "failed to allocate inode " + "context"); goto out; } @@ -255,10 +261,10 @@ svs_lookup_snapshot(xlator_t *this, loc_t *loc, struct iatt *buf, fs = svs_initialise_snapshot_volume(this, loc->name, op_errno); if (!fs) { - gf_log(this->name, GF_LOG_DEBUG, - "failed to " - "create the fs instance for snap %s", - loc->name); + gf_msg_debug(this->name, 0, + "failed to create " + "the fs instance for snap %s", + loc->name); *op_errno = ENOENT; op_ret = -1; goto out; @@ -268,22 +274,24 @@ svs_lookup_snapshot(xlator_t *this, loc_t *loc, struct iatt *buf, object = glfs_h_create_from_handle(fs, handle_obj, GFAPI_HANDLE_LENGTH, &statbuf); if (!object) { - gf_log(this->name, GF_LOG_DEBUG, - "failed to do lookup and " - "get the handle on the snapshot %s", - loc->name); op_ret = -1; *op_errno = errno; + /* Should this be in warning or error mode? */ + gf_msg_debug(this->name, 0, + "failed to do lookup and " + "get the handle on the snapshot %s", + loc->name); goto out; } inode_ctx = svs_inode_ctx_get_or_new(this, loc->inode); if (!inode_ctx) { - gf_log(this->name, GF_LOG_ERROR, - "failed to " - "allocate inode context"); op_ret = -1; *op_errno = ENOMEM; + gf_msg(this->name, GF_LOG_ERROR, *op_errno, + SVS_MSG_NEW_INODE_CTX_FAILED, + "failed to allocate " + "inode context"); goto out; } @@ -355,20 +363,22 @@ svs_lookup_entry(xlator_t *this, loc_t *loc, struct iatt *buf, object = glfs_h_lookupat(fs, parent_object, loc->name, &statbuf, 0); if (!object) { - gf_log(this->name, GF_LOG_DEBUG, - "failed to do lookup and " - "get the handle for entry %s (path: %s)", - loc->name, loc->path); + /* should this be in WARNING or ERROR mode? */ + gf_msg_debug(this->name, 0, + "failed to do lookup and " + "get the handle for entry %s (path: %s)", + loc->name, loc->path); op_ret = -1; *op_errno = errno; goto out; } if (gf_uuid_is_null(object->gfid)) { - gf_log(this->name, GF_LOG_DEBUG, - "gfid from glfs handle is " - "NULL for entry %s (path: %s)", - loc->name, loc->path); + /* should this be in WARNING or ERROR mode? */ + gf_msg_debug(this->name, 0, + "gfid from glfs handle is " + "NULL for entry %s (path: %s)", + loc->name, loc->path); op_ret = -1; *op_errno = errno; goto out; @@ -376,11 +386,12 @@ svs_lookup_entry(xlator_t *this, loc_t *loc, struct iatt *buf, inode_ctx = svs_inode_ctx_get_or_new(this, loc->inode); if (!inode_ctx) { - gf_log(this->name, GF_LOG_ERROR, - "failed to " - "allocate inode context"); op_ret = -1; *op_errno = ENOMEM; + gf_msg(this->name, GF_LOG_ERROR, *op_errno, + SVS_MSG_NEW_INODE_CTX_FAILED, + "failed to allocate " + "inode context"); goto out; } @@ -521,7 +532,8 @@ svs_revalidate(xlator_t *this, loc_t *loc, inode_t *parent, inode_ctx->object = NULL; ret = svs_get_handle(this, loc, inode_ctx, op_errno); if (ret) { - gf_log(this->name, GF_LOG_ERROR, + gf_msg(this->name, GF_LOG_ERROR, *op_errno, + SVS_MSG_GET_GLFS_H_OBJECT_FAILED, "failed to get the handle for " "%s (gfid %s)", loc->path, uuid_utoa_r(loc->inode->gfid, tmp_uuid)); @@ -536,7 +548,8 @@ svs_revalidate(xlator_t *this, loc_t *loc, inode_t *parent, */ if (!loc->name || !parent_ctx) { *op_errno = ESTALE; - gf_log(this->name, GF_LOG_ERROR, "%s is NULL", + gf_msg(this->name, GF_LOG_ERROR, *op_errno, + SVS_MSG_PARENT_CTX_OR_NAME_NULL, "%s is NULL", loc->name ? "parent context" : "loc->name"); goto out; } @@ -577,7 +590,6 @@ svs_lookup(call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *xdata) GF_VALIDATE_OR_GOTO("svs", this, out); GF_VALIDATE_OR_GOTO(this->name, this->private, out); GF_VALIDATE_OR_GOTO(this->name, frame, out); - GF_VALIDATE_OR_GOTO(this->name, frame->root, out); GF_VALIDATE_OR_GOTO(this->name, loc, out); GF_VALIDATE_OR_GOTO(this->name, loc->inode, out); @@ -621,9 +633,9 @@ svs_lookup(call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *xdata) if (xdata && !inode_ctx) { ret = dict_get_str_boolean(xdata, "entry-point", _gf_false); if (ret == -1) { - gf_log(this->name, GF_LOG_DEBUG, - "failed to get the " - "entry point info"); + gf_msg_debug(this->name, 0, + "failed to get the " + "entry point info"); entry_point_key = _gf_false; } else { entry_point_key = ret; @@ -668,12 +680,12 @@ svs_lookup(call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *xdata) */ if (!inode_ctx && !parent_ctx) { if (gf_uuid_is_null(loc->gfid) && gf_uuid_is_null(loc->inode->gfid)) { - gf_log(this->name, GF_LOG_DEBUG, - "gfid is NULL, " - "either the lookup came on missing entry or " - "the entry is stale"); op_ret = -1; op_errno = ESTALE; + gf_msg_debug(this->name, 0, + "gfid is NULL. Either the lookup " + "came on missing entry or the " + "entry is stale"); goto out; } @@ -738,7 +750,6 @@ svs_opendir(call_frame_t *frame, xlator_t *this, loc_t *loc, fd_t *fd, GF_VALIDATE_OR_GOTO("snap-view-daemon", this, out); GF_VALIDATE_OR_GOTO(this->name, frame, out); - GF_VALIDATE_OR_GOTO(this->name, frame->root, out); GF_VALIDATE_OR_GOTO(this->name, fd, out); GF_VALIDATE_OR_GOTO(this->name, loc, out); GF_VALIDATE_OR_GOTO(this->name, loc->inode, out); @@ -752,12 +763,13 @@ svs_opendir(call_frame_t *frame, xlator_t *this, loc_t *loc, fd_t *fd, inode_ctx = svs_inode_ctx_get(this, loc->inode); if (!inode_ctx) { - gf_log(this->name, GF_LOG_ERROR, + op_ret = -1; + op_errno = ESTALE; + gf_msg(this->name, GF_LOG_ERROR, op_errno, + SVS_MSG_GET_INODE_CONTEXT_FAILED, "inode context not found " "for the inode %s", uuid_utoa(loc->inode->gfid)); - op_ret = -1; - op_errno = ESTALE; goto out; } @@ -776,20 +788,21 @@ svs_opendir(call_frame_t *frame, xlator_t *this, loc_t *loc, fd_t *fd, if (!glfd) { op_ret = -1; op_errno = errno; - gf_log(this->name, GF_LOG_ERROR, - "opendir on %s " - "failed (gfid: %s)", + gf_msg(this->name, GF_LOG_ERROR, op_errno, SVS_MSG_OPENDIR_FAILED, + "opendir on %s failed " + "(gfid: %s)", loc->name, uuid_utoa(loc->inode->gfid)); goto out; } svs_fd = svs_fd_ctx_get_or_new(this, fd); if (!svs_fd) { - gf_log(this->name, GF_LOG_ERROR, - "failed to allocate " - "fd context %s (gfid: %s)", - loc->name, uuid_utoa(fd->inode->gfid)); op_ret = -1; op_errno = ENOMEM; + gf_msg(this->name, GF_LOG_ERROR, op_errno, + SVS_MSG_NEW_FD_CTX_FAILED, + "failed to allocate fd context " + "for %s (gfid: %s)", + loc->name, uuid_utoa(fd->inode->gfid)); glfs_closedir(glfd); goto out; } @@ -815,7 +828,8 @@ out: * back into the dict. But to get the values for those xattrs it has to do the * getxattr operation on each xattr which might turn out to be a costly * operation. So for each of the xattrs present in the list, a 0 byte value - * ("") is set into the dict before unwinding. This can be treated as an + * ("") is set into the dict before unwinding. Since ("") is also a valid xattr + * value(in a file system) we use an extra key in the same dictionary as an * indicator to other xlators which want to cache the xattrs (as of now, * md-cache which caches acl and selinux related xattrs) to not to cache the * values of the xattrs present in the dict. @@ -847,7 +861,7 @@ svs_add_xattrs_to_dict(xlator_t *this, dict_t *dict, char *list, ssize_t size) #endif ret = dict_set_str(dict, keybuffer, ""); if (ret < 0) { - gf_log(this->name, GF_LOG_ERROR, + gf_msg(this->name, GF_LOG_ERROR, 0, SVS_MSG_DICT_SET_FAILED, "dict set operation " "for the key %s failed.", keybuffer); @@ -858,6 +872,15 @@ svs_add_xattrs_to_dict(xlator_t *this, dict_t *dict, char *list, ssize_t size) list_offset += strlen(keybuffer) + 1; } /* while (remaining_size > 0) */ + /* Add an additional key to indicate that we don't need to cache these + * xattrs(with value "") */ + ret = dict_set_str(dict, "glusterfs.skip-cache", ""); + if (ret < 0) { + gf_msg(this->name, GF_LOG_ERROR, 0, SVS_MSG_DICT_SET_FAILED, + "dict set operation for the key glusterfs.skip-cache failed."); + goto out; + } + ret = 0; out: @@ -880,7 +903,6 @@ svs_getxattr(call_frame_t *frame, xlator_t *this, loc_t *loc, const char *name, GF_VALIDATE_OR_GOTO("snap-view-daemon", this, out); GF_VALIDATE_OR_GOTO("snap-view-daemon", frame, out); - GF_VALIDATE_OR_GOTO("snap-view-daemon", frame->root, out); GF_VALIDATE_OR_GOTO("snap-view-daemon", loc, out); GF_VALIDATE_OR_GOTO("snap-view-daemon", loc->inode, out); @@ -893,12 +915,13 @@ svs_getxattr(call_frame_t *frame, xlator_t *this, loc_t *loc, const char *name, inode_ctx = svs_inode_ctx_get(this, loc->inode); if (!inode_ctx) { - gf_log(this->name, GF_LOG_ERROR, + op_ret = -1; + op_errno = ESTALE; + gf_msg(this->name, GF_LOG_ERROR, op_errno, + SVS_MSG_GET_INODE_CONTEXT_FAILED, "inode context not found " "for the inode %s", uuid_utoa(loc->inode->gfid)); - op_ret = -1; - op_errno = ESTALE; goto out; } @@ -918,43 +941,49 @@ svs_getxattr(call_frame_t *frame, xlator_t *this, loc_t *loc, const char *name, dict = dict_new(); if (!dict) { - gf_log(this->name, GF_LOG_ERROR, - "failed to " - "allocate dict"); op_ret = -1; op_errno = ENOMEM; + gf_msg(this->name, GF_LOG_ERROR, op_errno, SVS_MSG_NO_MEMORY, + "failed to allocate dict"); goto out; } size = glfs_h_getxattrs(fs, object, name, NULL, 0); if (size == -1) { - gf_log(this->name, errno == ENODATA ? GF_LOG_DEBUG : GF_LOG_ERROR, - "getxattr on %s failed (key: %s) with %s", loc->path, name, - strerror(errno)); op_ret = -1; op_errno = errno; + if (errno == ENODATA) { + gf_msg_debug(this->name, 0, + "getxattr on " + "%s failed (ket: %s) with %s", + loc->path, name, strerror(errno)); + } else { + gf_msg(this->name, GF_LOG_ERROR, op_errno, + SVS_MSG_GETXATTR_FAILED, + "getxattr on %s failed (key: %s) with %s", loc->path, + name, strerror(errno)); + } goto out; } value = GF_CALLOC(size + 1, sizeof(char), gf_common_mt_char); if (!value) { - gf_log(this->name, GF_LOG_ERROR, - "failed to " - "allocate memory for getxattr on %s " - "(key: %s)", - loc->name, name); op_ret = -1; op_errno = ENOMEM; + gf_msg(this->name, GF_LOG_ERROR, op_errno, SVS_MSG_NO_MEMORY, + "failed to allocate memory for getxattr " + "on %s (key: %s)", + loc->name, name); goto out; } size = glfs_h_getxattrs(fs, object, name, value, size); if (size == -1) { - gf_log(this->name, GF_LOG_ERROR, - "failed to " - "get the xattr %s for entry %s", - name, loc->name); op_ret = -1; op_errno = errno; + gf_msg(this->name, GF_LOG_ERROR, op_errno, SVS_MSG_GETXATTR_FAILED, + "failed to get the xattr %s for " + "entry %s", + name, loc->name); goto out; } value[size] = '\0'; @@ -963,10 +992,10 @@ svs_getxattr(call_frame_t *frame, xlator_t *this, loc_t *loc, const char *name, op_ret = dict_set_dynptr(dict, (char *)name, value, size); if (op_ret < 0) { op_errno = -op_ret; - gf_log(this->name, GF_LOG_ERROR, - "dict set " - "operation for %s for the key %s " - "failed.", + gf_msg(this->name, GF_LOG_ERROR, op_errno, + SVS_MSG_DICT_SET_FAILED, + "dict set operation for %s for " + "the key %s failed.", loc->path, name); GF_FREE(value); value = NULL; @@ -975,10 +1004,11 @@ svs_getxattr(call_frame_t *frame, xlator_t *this, loc_t *loc, const char *name, } else { op_ret = svs_add_xattrs_to_dict(this, dict, value, size); if (op_ret == -1) { - gf_log(this->name, GF_LOG_ERROR, - "failed to " - "add the xattrs from the list to dict"); op_errno = ENOMEM; + gf_msg(this->name, GF_LOG_ERROR, op_errno, SVS_MSG_NO_MEMORY, + "failed to add xattrs from the list to " + "dict for %s (gfid: %s)", + loc->path, uuid_utoa(loc->inode->gfid)); goto out; } GF_FREE(value); @@ -1018,35 +1048,37 @@ svs_fgetxattr(call_frame_t *frame, xlator_t *this, fd_t *fd, const char *name, inode_ctx = svs_inode_ctx_get(this, fd->inode); if (!inode_ctx) { - gf_log(this->name, GF_LOG_ERROR, + op_ret = -1; + op_errno = ESTALE; + gf_msg(this->name, GF_LOG_ERROR, op_errno, + SVS_MSG_GET_INODE_CONTEXT_FAILED, "inode context not found " "for the inode %s", uuid_utoa(fd->inode->gfid)); - op_ret = -1; - op_errno = ESTALE; goto out; } if (!(svs_inode_ctx_glfs_mapping(this, inode_ctx))) { - gf_log(this->name, GF_LOG_ERROR, - "glfs instance " - "instance %p to which the inode %s belongs" - "to does not exist. That snapshot might have" - "been deleted or deactivated", - inode_ctx->fs, uuid_utoa(fd->inode->gfid)); op_ret = -1; op_errno = EBADF; + gf_msg(this->name, GF_LOG_ERROR, op_errno, SVS_MSG_FS_INSTANCE_INVALID, + "glfs instance %p to which the inode %s " + "belongs to does not exist. The snapshot " + "corresponding to the instance might have" + "been deleted or deactivated", + inode_ctx->fs, uuid_utoa(fd->inode->gfid)); goto out; } sfd = svs_fd_ctx_get_or_new(this, fd); if (!sfd) { - gf_log(this->name, GF_LOG_ERROR, + op_ret = -1; + op_errno = EBADFD; + gf_msg(this->name, GF_LOG_ERROR, op_errno, + SVS_MSG_GET_FD_CONTEXT_FAILED, "failed to get the fd " "context for %s", uuid_utoa(fd->inode->gfid)); - op_ret = -1; - op_errno = EBADFD; goto out; } @@ -1064,45 +1096,48 @@ svs_fgetxattr(call_frame_t *frame, xlator_t *this, fd_t *fd, const char *name, } else { dict = dict_new(); if (!dict) { - gf_log(this->name, GF_LOG_ERROR, - "failed to " - "allocate dict"); op_ret = -1; op_errno = ENOMEM; + gf_msg(this->name, GF_LOG_ERROR, op_errno, SVS_MSG_NO_MEMORY, + "failed to allocate dict " + "(gfid: %s, key: %s)", + uuid_utoa(fd->inode->gfid), name); goto out; } if (name) { size = glfs_fgetxattr(glfd, name, NULL, 0); if (size == -1) { - gf_log(this->name, GF_LOG_ERROR, - "getxattr on " - "%s failed (key: %s)", - uuid_utoa(fd->inode->gfid), name); op_ret = -1; op_errno = errno; + gf_msg(this->name, GF_LOG_ERROR, op_errno, + SVS_MSG_GETXATTR_FAILED, + "getxattr on %s failed " + "(key: %s)", + uuid_utoa(fd->inode->gfid), name); goto out; } value = GF_CALLOC(size + 1, sizeof(char), gf_common_mt_char); if (!value) { - gf_log(this->name, GF_LOG_ERROR, + op_ret = -1; + op_errno = ENOMEM; + gf_msg(this->name, GF_LOG_ERROR, op_errno, SVS_MSG_NO_MEMORY, "failed to " "allocate memory for getxattr on %s " "(key: %s)", uuid_utoa(fd->inode->gfid), name); - op_ret = -1; - op_errno = ENOMEM; goto out; } size = glfs_fgetxattr(glfd, name, value, size); if (size == -1) { - gf_log(this->name, GF_LOG_ERROR, - "failed to " - "get the xattr %s for inode %s", - name, uuid_utoa(fd->inode->gfid)); op_ret = -1; op_errno = errno; + gf_msg(this->name, GF_LOG_ERROR, op_errno, + SVS_MSG_GETXATTR_FAILED, + "failed to get the xattr %s " + "for inode %s", + name, uuid_utoa(fd->inode->gfid)); goto out; } value[size] = '\0'; @@ -1110,19 +1145,19 @@ svs_fgetxattr(call_frame_t *frame, xlator_t *this, fd_t *fd, const char *name, op_ret = dict_set_dynptr(dict, (char *)name, value, size); if (op_ret < 0) { op_errno = -op_ret; - gf_log(this->name, GF_LOG_ERROR, - "dict set " - "operation for gfid %s for the key %s " - "failed.", + gf_msg(this->name, GF_LOG_ERROR, op_errno, + SVS_MSG_DICT_SET_FAILED, + "dict set operation for gfid %s " + "for the key %s failed.", uuid_utoa(fd->inode->gfid), name); goto out; } } else { size = glfs_flistxattr(glfd, NULL, 0); if (size == -1) { - gf_log(this->name, GF_LOG_ERROR, - "listxattr " - "on %s failed", + op_errno = errno; + gf_msg(this->name, GF_LOG_ERROR, op_errno, + SVS_MSG_LISTXATTR_FAILED, "listxattr on %s failed", uuid_utoa(fd->inode->gfid)); goto out; } @@ -1131,9 +1166,10 @@ svs_fgetxattr(call_frame_t *frame, xlator_t *this, fd_t *fd, const char *name, if (!value) { op_ret = -1; op_errno = ENOMEM; - gf_log(this->name, GF_LOG_ERROR, + gf_msg(this->name, GF_LOG_ERROR, op_errno, SVS_MSG_NO_MEMORY, "failed to " - "allocate buffer for xattr list (%s)", + "allocate buffer for xattr " + "list (%s)", uuid_utoa(fd->inode->gfid)); goto out; } @@ -1142,19 +1178,19 @@ svs_fgetxattr(call_frame_t *frame, xlator_t *this, fd_t *fd, const char *name, if (size == -1) { op_ret = -1; op_errno = errno; - gf_log(this->name, GF_LOG_ERROR, - "listxattr " - "on %s failed", + gf_msg(this->name, GF_LOG_ERROR, op_errno, + SVS_MSG_LISTXATTR_FAILED, "listxattr on %s failed", uuid_utoa(fd->inode->gfid)); goto out; } op_ret = svs_add_xattrs_to_dict(this, dict, value, size); if (op_ret == -1) { - gf_log(this->name, GF_LOG_ERROR, - "failed to " - "add the xattrs from the list to dict"); op_errno = ENOMEM; + gf_msg(this->name, GF_LOG_ERROR, op_errno, SVS_MSG_NO_MEMORY, + "failed to add xattrs from the list " + "to dict (gfid: %s)", + uuid_utoa(fd->inode->gfid)); goto out; } GF_FREE(value); @@ -1191,7 +1227,7 @@ svs_releasedir(xlator_t *this, fd_t *fd) ret = fd_ctx_del(fd, this, &tmp_pfd); if (ret < 0) { - gf_log(this->name, GF_LOG_DEBUG, "pfd from fd=%p is NULL", fd); + gf_msg_debug(this->name, 0, "pfd from fd=%p is NULL", fd); goto out; } @@ -1206,9 +1242,10 @@ svs_releasedir(xlator_t *this, fd_t *fd) if (sfd->fd) { ret = glfs_closedir(sfd->fd); if (ret) - gf_log(this->name, GF_LOG_WARNING, - "failed to close the glfd" - "for directory %s", + gf_msg(this->name, GF_LOG_WARNING, errno, + SVS_MSG_RELEASEDIR_FAILED, + "failed to close the glfd for " + "directory %s", uuid_utoa(fd->inode->gfid)); } } @@ -1232,7 +1269,6 @@ svs_flush(call_frame_t *frame, xlator_t *this, fd_t *fd, dict_t *xdata) GF_VALIDATE_OR_GOTO("snapview-server", this, out); GF_VALIDATE_OR_GOTO(this->name, frame, out); - GF_VALIDATE_OR_GOTO(this->name, frame->root, out); GF_VALIDATE_OR_GOTO(this->name, fd, out); root = frame->root; @@ -1244,19 +1280,21 @@ svs_flush(call_frame_t *frame, xlator_t *this, fd_t *fd, dict_t *xdata) inode_ctx = svs_inode_ctx_get(this, fd->inode); if (!inode_ctx) { - gf_log(this->name, GF_LOG_ERROR, + op_ret = -1; + op_errno = EINVAL; + gf_msg(this->name, GF_LOG_ERROR, op_errno, + SVS_MSG_GET_INODE_CONTEXT_FAILED, "inode context not found for" " the inode %s", uuid_utoa(fd->inode->gfid)); - op_ret = -1; - op_errno = EINVAL; goto out; } ret = fd_ctx_get(fd, this, &value); if (ret < 0 && inode_ctx->type != SNAP_VIEW_ENTRY_POINT_INODE) { op_errno = EINVAL; - gf_log(this->name, GF_LOG_WARNING, "pfd is NULL on fd=%p", fd); + gf_msg(this->name, GF_LOG_WARNING, op_errno, + SVS_MSG_GET_FD_CONTEXT_FAILED, "pfd is NULL on fd=%p", fd); goto out; } @@ -1283,7 +1321,7 @@ svs_release(xlator_t *this, fd_t *fd) ret = fd_ctx_del(fd, this, &tmp_pfd); if (ret < 0) { - gf_log(this->name, GF_LOG_DEBUG, "pfd from fd=%p is NULL", fd); + gf_msg_debug(this->name, 0, "pfd from fd=%p is NULL", fd); goto out; } @@ -1298,7 +1336,8 @@ svs_release(xlator_t *this, fd_t *fd) if (sfd->fd) { ret = glfs_close(sfd->fd); if (ret) - gf_log(this->name, GF_LOG_ERROR, + gf_msg(this->name, GF_LOG_ERROR, errno, + SVS_MSG_RELEASE_FAILED, "failed to close " "the glfd for %s", uuid_utoa(fd->inode->gfid)); @@ -1323,7 +1362,7 @@ svs_forget(xlator_t *this, inode_t *inode) ret = inode_ctx_del(inode, this, &value); if (ret) { - gf_log(this->name, GF_LOG_ERROR, + gf_msg(this->name, GF_LOG_ERROR, 0, SVS_MSG_DELETE_INODE_CONTEXT_FAILED, "failed to delete the inode " "context of %s", uuid_utoa(inode->gfid)); @@ -1337,6 +1376,28 @@ svs_forget(xlator_t *this, inode_t *inode) if (inode_ctx->snapname) GF_FREE(inode_ctx->snapname); + /* + * glfs_h_close leads to unref and forgetting of the + * underlying inode in the gfapi world. i.e. the inode + * which inode_ctx->object points to. + * As of now the only possibility is, this forget came as a + * result of snapdaemon's inode table reaching the lru + * limit and receiving forget as a result of purging of + * extra inodes that exceeded the limit. But, care must + * be taken to ensure that, the gfapi instance to which + * the glfs_h_object belongs to is not deleted. Otherwise + * this might result in access of a freed pointer. + * This will still be helpful in reducing the memory + * footprint of snapdaemon when the fs instance itself is + * valid (i.e. present and not destroyed due to either snap + * deactivate or snap delete), but the lru limit is reached. + * The forget due to lru limit will make the underlying inode + * being unrefed and forgotten. + */ + if (svs_inode_ctx_glfs_mapping(this, inode_ctx)) { + glfs_h_close(inode_ctx->object); + inode_ctx->object = NULL; + } GF_FREE(inode_ctx); out: @@ -1372,7 +1433,7 @@ svs_fill_readdir(xlator_t *this, gf_dirent_t *entries, size_t size, off_t off) entry = gf_dirent_for_name(dirents[i].name); if (!entry) { - gf_log(this->name, GF_LOG_ERROR, + gf_msg(this->name, GF_LOG_ERROR, ENOMEM, SVS_MSG_NO_MEMORY, "failed to allocate dentry for %s", dirents[i].name); goto unlock; } @@ -1427,7 +1488,8 @@ svs_glfs_readdir(xlator_t *this, glfs_fd_t *glfd, gf_dirent_t *entries, while (filled_size < size) { in_case = glfs_telldir(glfd); if (in_case == -1) { - gf_log(this->name, GF_LOG_ERROR, "telldir failed"); + gf_msg(this->name, GF_LOG_ERROR, errno, SVS_MSG_TELLDIR_FAILED, + "telldir failed"); break; } @@ -1450,7 +1512,14 @@ svs_glfs_readdir(xlator_t *this, glfs_fd_t *glfd, gf_dirent_t *entries, entry = gf_dirent_for_name(de.d_name); if (!entry) { - gf_log(this->name, GF_LOG_ERROR, + /* + * Since gf_dirent_for_name can return + * NULL only when it fails to allocate + * memory for the directory entry, + * SVS_MSG_NO_MEMORY is used as the + * message-id. + */ + gf_msg(this->name, GF_LOG_ERROR, errno, SVS_MSG_NO_MEMORY, "could not create gf_dirent " "for entry %s: (%s)", entry->d_name, strerror(errno)); @@ -1546,9 +1615,9 @@ svs_readdirp_fill(xlator_t *this, inode_t *parent, svs_inode_t *parent_ctx, */ inode_ctx = svs_inode_ctx_get_or_new(this, inode); if (!inode_ctx) { - gf_log(this->name, GF_LOG_ERROR, - "failed to " - "allocate inode context for %s", + gf_msg(this->name, GF_LOG_ERROR, ENOMEM, SVS_MSG_NO_MEMORY, + "failed to allocate inode " + "context for %s", entry->d_name); inode_unref(entry->inode); entry->inode = NULL; @@ -1612,7 +1681,6 @@ svs_readdirp(call_frame_t *frame, xlator_t *this, fd_t *fd, size_t size, GF_VALIDATE_OR_GOTO("snap-view-daemon", this, unwind); GF_VALIDATE_OR_GOTO(this->name, frame, unwind); - GF_VALIDATE_OR_GOTO(this->name, frame->root, unwind); GF_VALIDATE_OR_GOTO(this->name, fd, unwind); GF_VALIDATE_OR_GOTO(this->name, fd->inode, unwind); @@ -1627,12 +1695,13 @@ svs_readdirp(call_frame_t *frame, xlator_t *this, fd_t *fd, size_t size, parent_ctx = svs_inode_ctx_get(this, fd->inode); if (!parent_ctx) { - gf_log(this->name, GF_LOG_ERROR, + op_ret = -1; + op_errno = EINVAL; + gf_msg(this->name, GF_LOG_ERROR, op_errno, + SVS_MSG_GET_INODE_CONTEXT_FAILED, "failed to get the inode " "context for %s", uuid_utoa(fd->inode->gfid)); - op_ret = -1; - op_errno = EINVAL; goto unwind; } @@ -1654,12 +1723,13 @@ svs_readdirp(call_frame_t *frame, xlator_t *this, fd_t *fd, size_t size, } else { svs_fd = svs_fd_ctx_get_or_new(this, fd); if (!svs_fd) { - gf_log(this->name, GF_LOG_ERROR, - "failed to get the " - "fd context %s", - uuid_utoa(fd->inode->gfid)); op_ret = -1; op_errno = EBADFD; + gf_msg(this->name, GF_LOG_ERROR, op_errno, + SVS_MSG_GET_FD_CONTEXT_FAILED, + "failed to get the fd context " + "for the inode %s", + uuid_utoa(fd->inode->gfid)); goto unwind; } @@ -1717,12 +1787,13 @@ svs_readdir(call_frame_t *frame, xlator_t *this, fd_t *fd, size_t size, inode_ctx = svs_inode_ctx_get(this, fd->inode); if (!inode_ctx) { - gf_log(this->name, GF_LOG_ERROR, + op_ret = -1; + op_errno = EINVAL; + gf_msg(this->name, GF_LOG_ERROR, op_errno, + SVS_MSG_GET_INODE_CONTEXT_FAILED, "inode context not found in " "the inode %s", uuid_utoa(fd->inode->gfid)); - op_ret = -1; - op_errno = EINVAL; goto unwind; } @@ -1735,12 +1806,13 @@ svs_readdir(call_frame_t *frame, xlator_t *this, fd_t *fd, size_t size, } else { svs_fd = svs_fd_ctx_get_or_new(this, fd); if (!svs_fd) { - gf_log(this->name, GF_LOG_ERROR, - "failed to get the " - "fd context %s", - uuid_utoa(fd->inode->gfid)); op_ret = -1; op_errno = EBADFD; + gf_msg(this->name, GF_LOG_ERROR, op_errno, + SVS_MSG_GET_FD_CONTEXT_FAILED, + "failed to get the fd " + "context for %s", + uuid_utoa(fd->inode->gfid)); goto unwind; } @@ -1855,11 +1927,12 @@ svs_get_handle(xlator_t *this, loc_t *loc, svs_inode_t *inode_ctx, parent_ctx = svs_inode_ctx_get(this, parent); if (!parent_ctx) { - gf_log(this->name, GF_LOG_WARNING, + *op_errno = EINVAL; + gf_msg(this->name, GF_LOG_WARNING, *op_errno, + SVS_MSG_GET_INODE_CONTEXT_FAILED, "failed to get the parent " "context for %s (%s)", loc->path, uuid_utoa_r(loc->inode->gfid, uuid1)); - *op_errno = EINVAL; goto out; } @@ -1898,7 +1971,6 @@ svs_stat(call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *xdata) GF_VALIDATE_OR_GOTO("snap-view-daemon", this, out); GF_VALIDATE_OR_GOTO(this->name, frame, out); - GF_VALIDATE_OR_GOTO(this->name, frame->root, out); GF_VALIDATE_OR_GOTO(this->name, loc, out); GF_VALIDATE_OR_GOTO(this->name, loc->inode, out); @@ -1916,12 +1988,11 @@ svs_stat(call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *xdata) inode_ctx = svs_inode_ctx_get(this, loc->inode); if (!inode_ctx) { - gf_log(this->name, GF_LOG_ERROR, - "inode context not found for" - " %s", - uuid_utoa(loc->inode->gfid)); op_ret = -1; op_errno = EINVAL; + gf_msg(this->name, GF_LOG_ERROR, op_errno, + SVS_MSG_GET_INODE_CONTEXT_FAILED, + "inode context not found for %s", uuid_utoa(loc->inode->gfid)); goto out; } @@ -1934,14 +2005,16 @@ svs_stat(call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *xdata) ret = glfs_h_stat(fs, object, &stat); if (ret) { - gf_log(this->name, GF_LOG_ERROR, - "glfs_h_stat on %s " - "(gfid: %s) failed", - loc->name, uuid_utoa(loc->inode->gfid)); op_ret = -1; op_errno = errno; + gf_msg(this->name, GF_LOG_ERROR, op_errno, SVS_MSG_STAT_FAILED, + "glfs_h_stat on %s (gfid: %s) " + "failed", + loc->name, uuid_utoa(loc->inode->gfid)); goto out; - } + } else + gf_msg_debug(this->name, 0, "stat on %s (%s) successful", loc->path, + uuid_utoa(loc->inode->gfid)); iatt_from_stat(&buf, &stat); gf_uuid_copy(buf.ia_gfid, loc->inode->gfid); @@ -1973,7 +2046,6 @@ svs_fstat(call_frame_t *frame, xlator_t *this, fd_t *fd, dict_t *xdata) GF_VALIDATE_OR_GOTO("snap-view-daemon", this, out); GF_VALIDATE_OR_GOTO(this->name, frame, out); - GF_VALIDATE_OR_GOTO(this->name, frame->root, out); GF_VALIDATE_OR_GOTO(this->name, fd, out); GF_VALIDATE_OR_GOTO(this->name, fd->inode, out); @@ -1991,12 +2063,13 @@ svs_fstat(call_frame_t *frame, xlator_t *this, fd_t *fd, dict_t *xdata) inode_ctx = svs_inode_ctx_get(this, fd->inode); if (!inode_ctx) { - gf_log(this->name, GF_LOG_ERROR, + op_ret = -1; + op_errno = EINVAL; + gf_msg(this->name, GF_LOG_ERROR, op_errno, + SVS_MSG_GET_INODE_CONTEXT_FAILED, "inode context not found for" " the inode %s", uuid_utoa(fd->inode->gfid)); - op_ret = -1; - op_errno = EINVAL; goto out; } @@ -2005,37 +2078,37 @@ svs_fstat(call_frame_t *frame, xlator_t *this, fd_t *fd, dict_t *xdata) op_ret = 0; } else { if (!(svs_inode_ctx_glfs_mapping(this, inode_ctx))) { - gf_log(this->name, GF_LOG_ERROR, - "glfs instance " - "instance %p to which the inode %s belongs " - "to does not exist. That snapshot might have " - "been deleted or deactivated", - inode_ctx->fs, uuid_utoa(fd->inode->gfid)); op_ret = -1; op_errno = EBADF; + gf_msg(this->name, GF_LOG_ERROR, op_errno, + SVS_MSG_FS_INSTANCE_INVALID, + "glfs instance %p to which the inode %s " + "belongs to does not exist. That snapshot " + "corresponding to the fs instance " + "might have been deleted or deactivated.", + inode_ctx->fs, uuid_utoa(fd->inode->gfid)); goto out; } sfd = svs_fd_ctx_get_or_new(this, fd); if (!sfd) { - gf_log(this->name, GF_LOG_ERROR, - "failed to get the " - "fd context for %s", - uuid_utoa(fd->inode->gfid)); op_ret = -1; op_errno = EBADFD; + gf_msg(this->name, GF_LOG_ERROR, op_errno, + SVS_MSG_GET_FD_CONTEXT_FAILED, + "failed to get the fd context " + "for %s", + uuid_utoa(fd->inode->gfid)); goto out; } glfd = sfd->fd; ret = glfs_fstat(glfd, &stat); if (ret) { - gf_log(this->name, GF_LOG_ERROR, - "glfs_fstat on " - "gfid: %s failed", - uuid_utoa(fd->inode->gfid)); op_ret = -1; op_errno = errno; + gf_msg(this->name, GF_LOG_ERROR, op_errno, SVS_MSG_STAT_FAILED, + "glfs_fstat on gfid: %s failed", uuid_utoa(fd->inode->gfid)); goto out; } @@ -2066,7 +2139,6 @@ svs_statfs(call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *xdata) GF_VALIDATE_OR_GOTO("snap-view-daemon", this, out); GF_VALIDATE_OR_GOTO(this->name, frame, out); - GF_VALIDATE_OR_GOTO(this->name, frame->root, out); GF_VALIDATE_OR_GOTO(this->name, loc, out); GF_VALIDATE_OR_GOTO(this->name, loc->inode, out); @@ -2083,12 +2155,11 @@ svs_statfs(call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *xdata) */ inode_ctx = svs_inode_ctx_get(this, loc->inode); if (!inode_ctx) { - gf_log(this->name, GF_LOG_ERROR, - "inode context not found for" - " %s", - uuid_utoa(loc->inode->gfid)); op_ret = -1; op_errno = EINVAL; + gf_msg(this->name, GF_LOG_ERROR, op_errno, + SVS_MSG_GET_INODE_CONTEXT_FAILED, + "inode context not found for %s", uuid_utoa(loc->inode->gfid)); goto out; } @@ -2097,12 +2168,12 @@ svs_statfs(call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *xdata) ret = glfs_h_statfs(fs, object, &buf); if (ret) { - gf_log(this->name, GF_LOG_ERROR, - "glfs_h_statvfs on %s " - "(gfid: %s) failed", - loc->name, uuid_utoa(loc->inode->gfid)); op_ret = -1; op_errno = errno; + gf_msg(this->name, GF_LOG_ERROR, op_errno, SVS_MSG_STATFS_FAILED, + "glfs_h_statvfs on %s (gfid: %s) " + "failed", + loc->name, uuid_utoa(loc->inode->gfid)); goto out; } op_ret = ret; @@ -2127,7 +2198,6 @@ svs_open(call_frame_t *frame, xlator_t *this, loc_t *loc, int32_t flags, GF_VALIDATE_OR_GOTO("snap-view-daemon", this, out); GF_VALIDATE_OR_GOTO(this->name, frame, out); - GF_VALIDATE_OR_GOTO(this->name, frame->root, out); GF_VALIDATE_OR_GOTO(this->name, fd, out); GF_VALIDATE_OR_GOTO(this->name, loc, out); GF_VALIDATE_OR_GOTO(this->name, loc->inode, out); @@ -2136,9 +2206,10 @@ svs_open(call_frame_t *frame, xlator_t *this, loc_t *loc, int32_t flags, inode_ctx = svs_inode_ctx_get(this, loc->inode); if (!inode_ctx) { - gf_log(this->name, GF_LOG_ERROR, - "inode context for %s " - "(gfid: %s) not found", + gf_msg(this->name, GF_LOG_ERROR, op_errno, + SVS_MSG_GET_INODE_CONTEXT_FAILED, + "inode context for %s (gfid: %s) " + "not found", loc->name, uuid_utoa(loc->inode->gfid)); goto out; } @@ -2157,23 +2228,22 @@ svs_open(call_frame_t *frame, xlator_t *this, loc_t *loc, int32_t flags, glfd = glfs_h_open(fs, object, flags); if (!glfd) { - gf_log(this->name, GF_LOG_ERROR, - "glfs_h_open on %s failed " - "(gfid: %s)", - loc->name, uuid_utoa(loc->inode->gfid)); op_ret = -1; op_errno = errno; + gf_msg(this->name, GF_LOG_ERROR, op_errno, SVS_MSG_OPEN_FAILED, + "glfs_h_open on %s failed (gfid: %s)", loc->name, + uuid_utoa(loc->inode->gfid)); goto out; } sfd = svs_fd_ctx_get_or_new(this, fd); if (!sfd) { - gf_log(this->name, GF_LOG_ERROR, - "failed to allocate fd " - "context for %s (gfid: %s)", - loc->name, uuid_utoa(loc->inode->gfid)); op_ret = -1; op_errno = ENOMEM; + gf_msg(this->name, GF_LOG_ERROR, op_errno, SVS_MSG_NO_MEMORY, + "failed to allocate fd context " + "for %s (gfid: %s)", + loc->name, uuid_utoa(loc->inode->gfid)); glfs_close(glfd); goto out; } @@ -2200,7 +2270,7 @@ svs_readv(call_frame_t *frame, xlator_t *this, fd_t *fd, size_t size, }; svs_fd_t *sfd = NULL; int ret = -1; - struct stat fstatbuf = { + struct glfs_stat fstatbuf = { 0, }; glfs_fd_t *glfd = NULL; @@ -2211,7 +2281,6 @@ svs_readv(call_frame_t *frame, xlator_t *this, fd_t *fd, size_t size, GF_VALIDATE_OR_GOTO("snap-view-daemon", this, out); GF_VALIDATE_OR_GOTO(this->name, frame, out); - GF_VALIDATE_OR_GOTO(this->name, frame->root, out); GF_VALIDATE_OR_GOTO(this->name, fd, out); GF_VALIDATE_OR_GOTO(this->name, fd->inode, out); @@ -2226,24 +2295,25 @@ svs_readv(call_frame_t *frame, xlator_t *this, fd_t *fd, size_t size, } if (!svs_inode_glfs_mapping(this, fd->inode)) { - gf_log(this->name, GF_LOG_ERROR, - "glfs instance to " - "which the inode %s receiving read request belongs, " - "does not exist anymore", - uuid_utoa(fd->inode->gfid)); op_ret = -1; op_errno = EBADF; /* should this be some other error? */ + gf_msg(this->name, GF_LOG_ERROR, op_errno, SVS_MSG_FS_INSTANCE_INVALID, + "glfs instance to which the inode " + "%s receiving read request belongs, " + "does not exist anymore", + uuid_utoa(fd->inode->gfid)); goto out; } sfd = svs_fd_ctx_get_or_new(this, fd); if (!sfd) { - gf_log(this->name, GF_LOG_ERROR, + op_ret = -1; + op_errno = EBADFD; + gf_msg(this->name, GF_LOG_ERROR, op_errno, + SVS_MSG_GET_INODE_CONTEXT_FAILED, "failed to get the fd " "context for %s", uuid_utoa(fd->inode->gfid)); - op_ret = -1; - op_errno = EBADFD; goto out; } @@ -2253,6 +2323,11 @@ svs_readv(call_frame_t *frame, xlator_t *this, fd_t *fd, size_t size, if (!iobuf) { op_ret = -1; op_errno = ENOMEM; + gf_msg(this->name, GF_LOG_ERROR, op_errno, SVS_MSG_NO_MEMORY, + "failed to " + "allocate iobuf while reading the " + "file with gfid %s", + uuid_utoa(fd->inode->gfid)); goto out; } @@ -2260,7 +2335,8 @@ svs_readv(call_frame_t *frame, xlator_t *this, fd_t *fd, size_t size, if (ret < 0) { op_ret = -1; op_errno = errno; - gf_log(this->name, GF_LOG_ERROR, "glfs_read failed (%s)", + gf_msg(this->name, GF_LOG_ERROR, op_errno, SVS_MSG_READ_FAILED, + "glfs_read failed on %s (%s)", uuid_utoa(fd->inode->gfid), strerror(op_errno)); goto out; } @@ -2271,7 +2347,7 @@ svs_readv(call_frame_t *frame, xlator_t *this, fd_t *fd, size_t size, iobref = iobref_new(); iobref_add(iobref, iobuf); - iatt_from_stat(&stbuf, &fstatbuf); + glfs_iatt_from_statx(&stbuf, &fstatbuf); gf_uuid_copy(stbuf.ia_gfid, fd->inode->gfid); svs_fill_ino_from_gfid(&stbuf); @@ -2315,7 +2391,6 @@ svs_readlink(call_frame_t *frame, xlator_t *this, loc_t *loc, size_t size, GF_VALIDATE_OR_GOTO("snap-view-daemon", this, out); GF_VALIDATE_OR_GOTO(this->name, frame, out); - GF_VALIDATE_OR_GOTO(this->name, frame->root, out); GF_VALIDATE_OR_GOTO(this->name, loc, out); GF_VALIDATE_OR_GOTO(this->name, loc->inode, out); @@ -2328,12 +2403,13 @@ svs_readlink(call_frame_t *frame, xlator_t *this, loc_t *loc, size_t size, inode_ctx = svs_inode_ctx_get(this, loc->inode); if (!inode_ctx) { - gf_log(this->name, GF_LOG_ERROR, + op_ret = -1; + op_errno = EINVAL; + gf_msg(this->name, GF_LOG_ERROR, op_errno, + SVS_MSG_GET_INODE_CONTEXT_FAILED, "failed to get inode context " "for %s (gfid: %s)", loc->name, uuid_utoa(loc->inode->gfid)); - op_ret = -1; - op_errno = EINVAL; goto out; } @@ -2342,12 +2418,12 @@ svs_readlink(call_frame_t *frame, xlator_t *this, loc_t *loc, size_t size, ret = glfs_h_stat(fs, object, &stat); if (ret) { - gf_log(this->name, GF_LOG_ERROR, - "glfs_h_stat on %s " - "(gfid: %s) failed", - loc->name, uuid_utoa(loc->inode->gfid)); op_ret = -1; op_errno = errno; + gf_msg(this->name, GF_LOG_ERROR, op_errno, SVS_MSG_STAT_FAILED, + "glfs_h_stat on %s (gfid: %s) " + "failed", + loc->name, uuid_utoa(loc->inode->gfid)); goto out; } @@ -2358,11 +2434,10 @@ svs_readlink(call_frame_t *frame, xlator_t *this, loc_t *loc, size_t size, buf = alloca(size + 1); op_ret = glfs_h_readlink(fs, object, buf, size); if (op_ret == -1) { - gf_log(this->name, GF_LOG_ERROR, - "readlink on %s failed " - "(gfid: %s)", - loc->name, uuid_utoa(loc->inode->gfid)); op_errno = errno; + gf_msg(this->name, GF_LOG_ERROR, op_errno, SVS_MSG_READLINK_FAILED, + "readlink on %s failed (gfid: %s)", loc->name, + uuid_utoa(loc->inode->gfid)); goto out; } @@ -2391,7 +2466,6 @@ svs_access(call_frame_t *frame, xlator_t *this, loc_t *loc, int mask, GF_VALIDATE_OR_GOTO("svs", this, out); GF_VALIDATE_OR_GOTO(this->name, this->private, out); GF_VALIDATE_OR_GOTO(this->name, frame, out); - GF_VALIDATE_OR_GOTO(this->name, frame->root, out); GF_VALIDATE_OR_GOTO(this->name, loc, out); GF_VALIDATE_OR_GOTO(this->name, loc->inode, out); @@ -2404,12 +2478,11 @@ svs_access(call_frame_t *frame, xlator_t *this, loc_t *loc, int mask, inode_ctx = svs_inode_ctx_get(this, loc->inode); if (!inode_ctx) { - gf_log(this->name, GF_LOG_ERROR, - "inode context not found for" - " %s", - uuid_utoa(loc->inode->gfid)); op_ret = -1; op_errno = EINVAL; + gf_msg(this->name, GF_LOG_ERROR, op_errno, + SVS_MSG_GET_INODE_CONTEXT_FAILED, + "inode context not found for %s", uuid_utoa(loc->inode->gfid)); goto out; } @@ -2448,12 +2521,11 @@ svs_access(call_frame_t *frame, xlator_t *this, loc_t *loc, int mask, ret = glfs_h_access(fs, object, mask); if (ret < 0) { - gf_log(this->name, GF_LOG_ERROR, - "failed to access %s " - "(gfid: %s)", - loc->path, uuid_utoa(loc->inode->gfid)); op_ret = -1; op_errno = errno; + gf_msg(this->name, GF_LOG_ERROR, op_errno, SVS_MSG_ACCESS_FAILED, + "failed to access %s (gfid: %s)", loc->path, + uuid_utoa(loc->inode->gfid)); goto out; } @@ -2491,7 +2563,7 @@ mem_acct_init(xlator_t *this) ret = xlator_mem_acct_init(this, gf_svs_mt_end + 1); if (ret != 0) { - gf_log(this->name, GF_LOG_WARNING, + gf_msg(this->name, GF_LOG_WARNING, 0, SVS_MSG_MEM_ACNT_FAILED, "Memory accounting" " init failed"); return ret; @@ -2508,12 +2580,16 @@ init(xlator_t *this) /* This can be the top of graph in certain cases */ if (!this->parents) { - gf_log(this->name, GF_LOG_DEBUG, "dangling volume. check volfile "); + gf_msg_debug(this->name, 0, "dangling volume. check volfile "); } priv = GF_CALLOC(1, sizeof(*priv), gf_svs_mt_priv_t); - if (!priv) + if (!priv) { + gf_msg(this->name, GF_LOG_ERROR, ENOMEM, SVS_MSG_NO_MEMORY, + "failed to " + "allocate memory for this->private "); goto out; + } this->private = priv; @@ -2531,7 +2607,7 @@ init(xlator_t *this) /* happen.*/ ret = svs_mgmt_init(this); if (ret) { - gf_log(this->name, GF_LOG_WARNING, + gf_msg(this->name, GF_LOG_WARNING, EINVAL, SVS_MSG_MGMT_INIT_FAILED, "failed to initiate the " "mgmt rpc callback for svs. Dymamic management of the" "snapshots will not happen"); @@ -2541,7 +2617,8 @@ init(xlator_t *this) /* get the list of snaps first to return to client xlator */ ret = svs_get_snapshot_list(this); if (ret) { - gf_log(this->name, GF_LOG_ERROR, + gf_msg(this->name, GF_LOG_ERROR, EINVAL, + SVS_MSG_GET_SNAPSHOT_LIST_FAILED, "Error initializing snaplist infrastructure"); ret = -1; goto out; @@ -2571,12 +2648,14 @@ fini(xlator_t *this) this->private = NULL; ctx = this->ctx; if (!ctx) - gf_log(this->name, GF_LOG_ERROR, "Invalid ctx found"); + gf_msg(this->name, GF_LOG_ERROR, 0, SVS_MSG_INVALID_GLFS_CTX, + "Invalid ctx found"); if (priv) { ret = LOCK_DESTROY(&priv->snaplist_lock); if (ret != 0) { - gf_log(this->name, GF_LOG_WARNING, + gf_msg(this->name, GF_LOG_WARNING, errno, + SVS_MSG_LOCK_DESTROY_FAILED, "Could not destroy mutex snaplist_lock"); } @@ -2626,3 +2705,16 @@ struct volume_options options[] = { }, {.key = {NULL}}, }; + +xlator_api_t xlator_api = { + .init = init, + .fini = fini, + .notify = notify, + .mem_acct_init = mem_acct_init, + .op_version = {1}, + .fops = &fops, + .cbks = &cbks, + .options = options, + .identifier = "snapview-server", + .category = GF_MAINTAINED, +}; diff --git a/xlators/features/snapview-server/src/snapview-server.h b/xlators/features/snapview-server/src/snapview-server.h index e07d3bcad0c..6472422e715 100644 --- a/xlators/features/snapview-server/src/snapview-server.h +++ b/xlators/features/snapview-server/src/snapview-server.h @@ -10,29 +10,28 @@ #ifndef __SNAP_VIEW_H__ #define __SNAP_VIEW_H__ -#include "dict.h" -#include "defaults.h" -#include "mem-types.h" -#include "call-stub.h" -#include "byte-order.h" -#include "iatt.h" +#include <glusterfs/dict.h> +#include <glusterfs/defaults.h> +#include <glusterfs/mem-types.h> +#include <glusterfs/call-stub.h> +#include <glusterfs/byte-order.h> +#include <glusterfs/iatt.h> #include <ctype.h> #include <sys/uio.h> -#include "glusterfs.h" -#include "xlator.h" -#include "logging.h" +#include <glusterfs/glusterfs.h> +#include <glusterfs/logging.h> #include "glfs.h" -#include "common-utils.h" #include "glfs-handles.h" #include "glfs-internal.h" #include "glusterfs3-xdr.h" -#include "glusterfs-acl.h" -#include "syncop.h" -#include "list.h" -#include "timer.h" +#include <glusterfs/glusterfs-acl.h> +#include <glusterfs/syncop.h> +#include <glusterfs/list.h> +#include <glusterfs/timer.h> #include "rpc-clnt.h" #include "protocol-common.h" #include "xdr-generic.h" +#include "snapview-server-messages.h" #define DEFAULT_SVD_LOG_FILE_DIRECTORY DATADIR "/log/glusterfs" @@ -57,9 +56,16 @@ { \ for (i = 0; i < _private->num_snaps; i++) { \ tmp_fs = _private->dirents[i].fs; \ - gf_log(this->name, GF_LOG_DEBUG, "dirent->fs: %p", tmp_fs); \ + gf_log(this->name, GF_LOG_DEBUG, \ + "snap name: %s, snap volume: %s," \ + "dirent->fs: %p", \ + _private->dirents[i].name, \ + _private->dirents[i].snap_volname, tmp_fs); \ if (tmp_fs && fs && (tmp_fs == fs)) { \ found = _gf_true; \ + gf_msg_debug(this->name, 0, \ + "found the fs " \ + "instance"); \ break; \ } \ } \ |
