diff options
-rw-r--r-- | xlators/features/quota/src/Makefile.am | 3 | ||||
-rw-r--r-- | xlators/features/quota/src/quota-enforcer-client.c | 46 | ||||
-rw-r--r-- | xlators/features/quota/src/quota-messages.h | 247 | ||||
-rw-r--r-- | xlators/features/quota/src/quota.c | 585 | ||||
-rw-r--r-- | xlators/features/quota/src/quota.h | 6 | ||||
-rw-r--r-- | xlators/features/quota/src/quotad-aggregator.c | 29 |
6 files changed, 594 insertions, 322 deletions
diff --git a/xlators/features/quota/src/Makefile.am b/xlators/features/quota/src/Makefile.am index 7165adc59ef..79bc9290076 100644 --- a/xlators/features/quota/src/Makefile.am +++ b/xlators/features/quota/src/Makefile.am @@ -10,7 +10,8 @@ quota_la_LIBADD = $(top_builddir)/libglusterfs/src/libglusterfs.la quotad_la_SOURCES = quotad.c quotad-helpers.c quotad-aggregator.c quotad_la_LIBADD = $(top_builddir)/libglusterfs/src/libglusterfs.la -noinst_HEADERS = quota-mem-types.h quota.h quotad-aggregator.h quotad-helpers.h +noinst_HEADERS = quota-mem-types.h quota.h quotad-aggregator.h \ + quotad-helpers.h quota-messages.h AM_CPPFLAGS = $(GF_CPPFLAGS) -I$(top_srcdir)/libglusterfs/src \ -I$(top_srcdir)/xlators/cluster/dht/src -I$(top_srcdir)/rpc/xdr/src/ \ diff --git a/xlators/features/quota/src/quota-enforcer-client.c b/xlators/features/quota/src/quota-enforcer-client.c index 9147cf7475f..09df3534a75 100644 --- a/xlators/features/quota/src/quota-enforcer-client.c +++ b/xlators/features/quota/src/quota-enforcer-client.c @@ -39,6 +39,7 @@ #endif #include "quota.h" +#include "quota-messages.h" extern struct rpc_clnt_program quota_enforcer_clnt; @@ -144,7 +145,9 @@ quota_enforcer_lookup_cbk (struct rpc_req *req, struct iovec *iov, ret = xdr_to_generic (*iov, &rsp, (xdrproc_t)xdr_gfs3_lookup_rsp); if (ret < 0) { - gf_log (this->name, GF_LOG_ERROR, "XDR decoding failed"); + gf_msg (this->name, GF_LOG_ERROR, 0, + Q_MSG_XDR_DECODING_FAILED, + "XDR decoding failed"); rsp.op_ret = -1; op_errno = EINVAL; goto out; @@ -165,8 +168,8 @@ quota_enforcer_lookup_cbk (struct rpc_req *req, struct iovec *iov, if ((!gf_uuid_is_null (inode->gfid)) && (gf_uuid_compare (stbuf.ia_gfid, inode->gfid) != 0)) { - gf_log (frame->this->name, GF_LOG_DEBUG, - "gfid changed for %s", local->validate_loc.path); + gf_msg_debug (frame->this->name, ESTALE, + "gfid changed for %s", local->validate_loc.path); rsp.op_ret = -1; op_errno = ESTALE; goto out; @@ -221,14 +224,14 @@ out: if (rsp.op_ret == -1) { /* any error other than ENOENT */ if (rsp.op_errno != ENOENT) - gf_log (this->name, GF_LOG_WARNING, - "remote operation failed: %s. Path: %s (%s)", - strerror (rsp.op_errno), - local->validate_loc.path, + gf_msg (this->name, GF_LOG_WARNING, rsp.op_errno, + Q_MSG_LOOKUP_FAILED, + "Getting cluster-wide size of directory failed " + "(path: %s gfid:%s)", local->validate_loc.path, loc_gfid_utoa (&local->validate_loc)); else - gf_log (this->name, GF_LOG_TRACE, - "not found on remote node"); + gf_msg_trace (this->name, ENOENT, + "not found on remote node"); } else if (local->quotad_conn_retry) { gf_log (this->name, GF_LOG_DEBUG, "connected to quotad after " @@ -258,6 +261,7 @@ _quota_enforcer_lookup (void *data) call_frame_t *frame = NULL; loc_t *loc = NULL; xlator_t *this = NULL; + char *dir_path = NULL; frame = data; local = frame->local; @@ -286,6 +290,11 @@ _quota_enforcer_lookup (void *data) else req.bname = ""; + if (loc->path) + dir_path = (char *)loc->path; + else + dir_path = ""; + ret = quota_enforcer_submit_request (&req, frame, priv->quota_enforcer, GF_AGGREGATOR_LOOKUP, @@ -294,7 +303,10 @@ _quota_enforcer_lookup (void *data) (xdrproc_t)xdr_gfs3_lookup_req); if (ret) { - gf_log (this->name, GF_LOG_WARNING, "failed to send the fop"); + gf_msg (this->name, GF_LOG_WARNING, 0, + Q_MSG_RPC_SUBMIT_FAILED, "Couldn't send the request to " + "fetch cluster wide size of directory (path:%s gfid:%s)" + , dir_path, req.gfid); } GF_FREE (req.xdata.xdata_val); @@ -346,19 +358,19 @@ quota_enforcer_notify (struct rpc_clnt *rpc, void *mydata, switch (event) { case RPC_CLNT_CONNECT: { - gf_log (this->name, GF_LOG_TRACE, "got RPC_CLNT_CONNECT"); + gf_msg_trace (this->name, 0, "got RPC_CLNT_CONNECT"); break; } case RPC_CLNT_DISCONNECT: { - gf_log (this->name, GF_LOG_TRACE, "got RPC_CLNT_DISCONNECT"); + gf_msg_trace (this->name, 0, "got RPC_CLNT_DISCONNECT"); break; } default: - gf_log (this->name, GF_LOG_TRACE, - "got some other RPC event %d", event); + gf_msg_trace (this->name, 0, + "got some other RPC event %d", event); ret = 0; break; } @@ -444,7 +456,9 @@ quota_enforcer_init (xlator_t *this, dict_t *options) ret = rpc_clnt_register_notify (rpc, quota_enforcer_notify, this); if (ret) { - gf_log ("cli", GF_LOG_ERROR, "failed to register notify"); + gf_msg ("quota", GF_LOG_ERROR, 0, + Q_MSG_RPCCLNT_REGISTER_NOTIFY_FAILED, + "failed to register notify"); goto out; } @@ -461,7 +475,7 @@ out: } return rpc; -} + } struct rpc_clnt_procedure quota_enforcer_actors[GF_AGGREGATOR_MAXVALUE] = { [GF_AGGREGATOR_NULL] = {"NULL", NULL}, diff --git a/xlators/features/quota/src/quota-messages.h b/xlators/features/quota/src/quota-messages.h new file mode 100644 index 00000000000..d39b8d00c1c --- /dev/null +++ b/xlators/features/quota/src/quota-messages.h @@ -0,0 +1,247 @@ +/* + Copyright (c) 2013 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 _QUOTA_MESSAGES_H_ +#define _QUOTA_MESSAGES_H_ + +#ifndef _CONFIG_H +#define _CONFIG_H +#include "config.h" +#endif + +#include "glfs-message-id.h" + +/*! \file quota-messages.h + * \brief Quota log-message IDs and their descriptions + * + */ + +/* NOTE: Rules for message additions + * 1) Each instance of a message is _better_ left with a unique message ID, even + * if the message format is the same. Reasoning is that, if the message + * format needs to change in one instance, the other instances are not + * impacted or the new change does not change the ID of the instance being + * modified. + * 2) Addition of a message, + * - Should increment the GLFS_NUM_MESSAGES + * - Append to the list of messages defined, towards the end + * - Retain macro naming as glfs_msg_X (for redability across developers) + * NOTE: Rules for message format modifications + * 3) Check across the code if the message ID macro in question is reused + * anywhere. If reused then the modifications should ensure correctness + * everywhere, or needs a new message ID as (1) above was not adhered to. If + * not used anywhere, proceed with the required modification. + * NOTE: Rules for message deletion + * 4) Check (3) and if used anywhere else, then cannot be deleted. If not used + * anywhere, then can be deleted, but will leave a hole by design, as + * addition rules specify modification to the end of the list and not filling + * holes. + */ + +#define GLFS_QUOTA_BASE GLFS_MSGID_COMP_QUOTA +#define GLFS_NUM_MESSAGES 23 +#define GLFS_MSGID_END (GLFS_QUOTA_BASE + GLFS_NUM_MESSAGES + 1) +/* Messaged with message IDs */ +#define glfs_msg_start_x GLFS_QUOTA_BASE, "Invalid: Start of messages" +/*------------*/ + +/*! + * @messageid 110001 + * @diagnosis Quota enforcement has failed. + * @recommendedaction None + */ +#define Q_MSG_ENFORCEMENT_FAILED (GLFS_QUOTA_BASE + 1) + + +/*! +* @messageid 110002 +* @diagnosis system is out of memory +* @recommendedaction None +*/ +#define Q_MSG_ENOMEM (GLFS_QUOTA_BASE + 2) + +/*! + * @messageid 110003 + * @diagnosis Parent inode is not present in the inode table due to the + * inode table limits or the brick was restarted recently. + * @recommendedaction If it is a brick restart then perform a crawl on the + * file system or the specific directory in which the problem is observed. + * If inode table limit has been reached,please increase the limit of + * network.inode-lru-limit to a higher value(can be set through CLI). + */ +#define Q_MSG_PARENT_NULL (GLFS_QUOTA_BASE + 3) + +/*! + * @messageid 110005 + * @diagnosis This is to inform the admin that the user has crossed the soft limit + * of the quota configured on the directory and expected to cross the hard limit soon. + * @recommendedaction You may reconfigure your quota limits. + */ +#define Q_MSG_CROSSED_SOFT_LIMIT (GLFS_QUOTA_BASE + 4) + +/*! + * @messageid 110007 + * @diagnosis Quota translator failed to connect to quotad. This could be + * due to one or more of the following reasons, (1) Quotad is not running. + * (2) Brick process has run out of memory. + * @recommendedaction If quotad is not running, consider starting quotad. + * else check system memory consumption. + */ +#define Q_MSG_QUOTA_ENFORCER_RPC_INIT_FAILED (GLFS_QUOTA_BASE + 5) + +/*! + * @messageid 110008 + * @diagnosis Getting cluster-wide size failed + * @recommendedaction Restart quotad. Kill quotad by searching + * "ps ax | grep quotad" and use volume start force to restart it. + */ + +#define Q_MSG_REMOTE_OPERATION_FAILED (GLFS_QUOTA_BASE + 6) + +/*! + * @messageid 110009 + * @diagnosis Updation of global quota size failed. This may be due to quotad + * is down or lost connection with quotad. + * @recommendedaction Please restart quotad. + */ + +#define Q_MSG_FAILED_TO_SEND_FOP (GLFS_QUOTA_BASE + 7) + +/*! + * @messageid 110010 + * @diagnosis + * @recommendedaction Check volfile for correctness + */ + +#define Q_MSG_INVALID_VOLFILE (GLFS_QUOTA_BASE + 8) + +/*! + * @messageid 110011 + * @diagnosis + * @recommendedaction + */ + +#define Q_MSG_INODE_PARENT_NOT_FOUND (GLFS_QUOTA_BASE + 9) + +/*! + * @messageid 110012 + * @diagnosis + * @recommendedaction + */ + +#define Q_MSG_XDR_DECODE_ERROR (GLFS_QUOTA_BASE + 10) + +/*! + * @messageid 110013 + * @diagnosis + * @recommendedaction + */ + +#define Q_MSG_DICT_UNSERIALIZE_FAIL (GLFS_QUOTA_BASE + 11) + +/*! + * @messageid 110014 + * @diagnosis + * @recommendedaction + */ + +#define Q_MSG_DICT_SERIALIZE_FAIL (GLFS_QUOTA_BASE + 12) + +/*! + * @messageid 110015 + * @diagnosis + * @recommendedaction + */ + +#define Q_MSG_RPCSVC_INIT_FAILED (GLFS_QUOTA_BASE + 13) + +/*! + * @messageid 110016 + * @diagnosis + * @recommendedaction + */ + +#define Q_MSG_RPCSVC_LISTENER_CREATION_FAILED (GLFS_QUOTA_BASE + 14) + +/*! + * @messageid 110017 + * @diagnosis + * @recommendedaction + */ + +#define Q_MSG_RPCSVC_REGISTER_FAILED (GLFS_QUOTA_BASE + 15) + +/*! + * @messageid 110018 + * @diagnosis + * @recommendedaction + */ + +#define Q_MSG_XDR_DECODING_FAILED (GLFS_QUOTA_BASE + 16) +/*! + * @messageid 110019 + * @diagnosis + * @recommendedaction + */ + +#define Q_MSG_RPCCLNT_REGISTER_NOTIFY_FAILED (GLFS_QUOTA_BASE + 17) +/*! + * @messageid 110020 + * @diagnosis + * @recommendedaction Umount and mount the corresponing volume + */ + +#define Q_MSG_ANCESTRY_BUILD_FAILED (GLFS_QUOTA_BASE + 18) + +/*! + * @messageid 110021 + * @diagnosis + * @recommendedaction + */ + +#define Q_MSG_SIZE_KEY_MISSING (GLFS_QUOTA_BASE + 19) + +/*! + * @messageid 110022 + * @diagnosis + * @recommendedaction + */ + +#define Q_MSG_INODE_CTX_GET_FAILED (GLFS_QUOTA_BASE + 20) + +/*! + * @messageid 110023 + * @diagnosis + * @recommendedaction + */ + +#define Q_MSG_INODE_CTX_SET_FAILED (GLFS_QUOTA_BASE + 21) + +/*! + * @messageid 110024 + * @diagnosis + * @recommendedaction + */ + +#define Q_MSG_LOOKUP_FAILED (GLFS_QUOTA_BASE + 22) + +/*! + * @messageid 110025 + * @diagnosis + * @recommendedaction + */ + +#define Q_MSG_RPC_SUBMIT_FAILED (GLFS_QUOTA_BASE + 23) + +/*------------*/ +#define glfs_msg_end_x GLFS_MSGID_END, "Invalid: End of messages" + +#endif /* !_QUOTA_MESSAGES_H_ */ + diff --git a/xlators/features/quota/src/quota.c b/xlators/features/quota/src/quota.c index 569b3c00aa4..4dc6da0e07d 100644 --- a/xlators/features/quota/src/quota.c +++ b/xlators/features/quota/src/quota.c @@ -14,6 +14,7 @@ #include "defaults.h" #include "statedump.h" #include "quota-common-utils.h" +#include "quota-messages.h" struct volume_options options[]; @@ -40,9 +41,9 @@ __quota_init_inode_ctx (inode_t *inode, xlator_t *this, ret = __inode_ctx_put (inode, this, (uint64_t )(long)ctx); if (ret == -1) { - gf_log (this->name, GF_LOG_WARNING, - "cannot set quota context in inode (gfid:%s)", - uuid_utoa (inode->gfid)); + gf_msg (this->name, GF_LOG_WARNING, 0, + Q_MSG_INODE_CTX_SET_FAILED, "cannot set quota context " + "in inode (gfid:%s)", uuid_utoa (inode->gfid)); } out: return ret; @@ -124,22 +125,21 @@ quota_inode_loc_fill (inode_t *inode, loc_t *loc) parent = inode_parent (inode, 0, NULL); if (!parent) { - gf_log (this->name, GF_LOG_DEBUG, - "cannot find parent for inode (gfid:%s)", - uuid_utoa (inode->gfid)); + gf_msg_debug (this->name, 0, "cannot find parent for " + "inode (gfid:%s)", uuid_utoa (inode->gfid)); } ignore_parent: ret = inode_path (inode, NULL, &resolvedpath); if (ret < 0) { - gf_log (this->name, GF_LOG_DEBUG, - "cannot construct path for inode (gfid:%s)", - uuid_utoa (inode->gfid)); + gf_msg_debug (this->name, 0, "cannot construct path for " + "inode (gfid:%s)", uuid_utoa (inode->gfid)); } ret = quota_loc_fill (loc, inode, parent, resolvedpath); if (ret < 0) { - gf_log (this->name, GF_LOG_WARNING, "cannot fill loc"); + gf_msg (this->name, GF_LOG_WARNING, ENOMEM, Q_MSG_ENOMEM, + "cannot fill loc"); goto err; } @@ -260,7 +260,9 @@ quota_inode_parent (inode_t *inode, uuid_t pargfid, const char *name) parent = __quota_inode_parent (inode, pargfid, name); if (!parent) - gf_log_callingfn (THIS->name, GF_LOG_ERROR, "Failed to find " + gf_msg_callingfn (THIS->name, GF_LOG_ERROR, 0, + Q_MSG_PARENT_NULL, + "Failed to find " "ancestor for inode (%s)", uuid_utoa(inode->gfid)); @@ -349,7 +351,8 @@ check_ancestory_continue (struct list_head *parents, inode_t *inode, local = frame->local; if (parents && list_empty (parents)) { - gf_log (THIS->name, GF_LOG_WARNING, + gf_msg (THIS->name, GF_LOG_WARNING, EIO, + Q_MSG_ANCESTRY_BUILD_FAILED, "Couldn't build ancestry for inode (gfid:%s). " "Without knowing ancestors till root, quota " "cannot be enforced. " @@ -413,7 +416,8 @@ check_ancestory_2_cbk (struct list_head *parents, inode_t *inode, goto out; if (parents == NULL || list_empty (parents)) { - gf_log (THIS->name, GF_LOG_WARNING, + gf_msg (THIS->name, GF_LOG_WARNING, 0, + Q_MSG_ENFORCEMENT_FAILED, "Couldn't build ancestry for inode (gfid:%s). " "Without knowing ancestors till root, quota " "cannot be enforced.", @@ -558,8 +562,9 @@ quota_validate_cbk (call_frame_t *frame, void *cookie, xlator_t *this, ctx = (quota_inode_ctx_t *)(unsigned long)value; if ((ret == -1) || (ctx == NULL)) { - gf_log (this->name, GF_LOG_WARNING, - "quota context is not present in inode (gfid:%s)", + gf_msg (this->name, GF_LOG_WARNING, EINVAL, + Q_MSG_INODE_CTX_GET_FAILED, "quota context is" + " not present in inode (gfid:%s)", uuid_utoa (local->validate_loc.inode->gfid)); op_errno = EINVAL; goto unwind; @@ -567,8 +572,9 @@ quota_validate_cbk (call_frame_t *frame, void *cookie, xlator_t *this, ret = quota_dict_get_meta (xdata, QUOTA_SIZE_KEY, &size); if (ret == -1) { - gf_log (this->name, GF_LOG_WARNING, "dict get failed " - "on quota size"); + gf_msg (this->name, GF_LOG_WARNING, EINVAL, + Q_MSG_SIZE_KEY_MISSING, "quota size key not present " + "in dict"); op_errno = EINVAL; } @@ -662,7 +668,8 @@ quota_build_ancestry_cbk (call_frame_t *frame, void *cookie, xlator_t *this, parent = inode_parent (local->loc.inode, 0, NULL); if (parent == NULL) { - gf_log (this->name, GF_LOG_WARNING, "parent is NULL"); + gf_msg (this->name, GF_LOG_WARNING, EINVAL, + Q_MSG_PARENT_NULL, "parent is NULL"); op_errno = EINVAL; goto err; } @@ -855,8 +862,9 @@ quota_validate (call_frame_t *frame, inode_t *inode, xlator_t *this, ret = quota_inode_loc_fill (inode, &local->validate_loc); if (ret < 0) { - gf_log (this->name, GF_LOG_WARNING, - "cannot fill loc for inode (gfid:%s), hence " + gf_msg (this->name, GF_LOG_WARNING, ENOMEM, + Q_MSG_ENFORCEMENT_FAILED, + "cannot fill loc for inode (gfid:%s), hence " "aborting quota-checks and continuing with fop", uuid_utoa (inode->gfid)); } @@ -876,14 +884,16 @@ quota_validate (call_frame_t *frame, inode_t *inode, xlator_t *this, ret = dict_set_int8 (xdata, QUOTA_SIZE_KEY, 1); if (ret < 0) { - gf_log (this->name, GF_LOG_WARNING, "dict set failed"); + gf_msg (this->name, GF_LOG_WARNING, ENOMEM, + Q_MSG_ENOMEM, "dict set failed"); ret = -ENOMEM; goto err; } ret = dict_set_str (xdata, "volume-uuid", priv->volume_uuid); if (ret < 0) { - gf_log (this->name, GF_LOG_WARNING, "dict set failed"); + gf_msg (this->name, GF_LOG_WARNING, ENOMEM, + Q_MSG_ENOMEM, "dict set failed"); ret = -ENOMEM; goto err; } @@ -919,12 +929,13 @@ quota_check_limit_continuation (struct list_head *parents, inode_t *inode, if ((op_ret < 0) || list_empty (parents)) { if (op_ret >= 0) { - gf_log (this->name, GF_LOG_WARNING, + gf_msg (this->name, GF_LOG_WARNING, EIO, + Q_MSG_ANCESTRY_BUILD_FAILED, "Couldn't build ancestry for inode (gfid:%s). " - "Without knowing ancestors till root, quota " + "Without knowing ancestors till root, quota" "cannot be enforced. " "Hence, failing fop with EIO", - uuid_utoa (inode->gfid)); + uuid_utoa (inode->gfid)); op_errno = EIO; } @@ -1184,7 +1195,8 @@ quota_check_limit (call_frame_t *frame, inode_t *inode, xlator_t *this, goto done; if (ret) { - gf_log (this->name, GF_LOG_ERROR, "Failed to check " + gf_msg (this->name, GF_LOG_ERROR, 0, + Q_MSG_ENFORCEMENT_FAILED, "Failed to check " "quota object limit"); goto err; } @@ -1196,7 +1208,8 @@ quota_check_limit (call_frame_t *frame, inode_t *inode, xlator_t *this, goto done; if (ret) { - gf_log (this->name, GF_LOG_ERROR, "Failed to check " + gf_msg (this->name, GF_LOG_ERROR, 0, + Q_MSG_ENFORCEMENT_FAILED, "Failed to check " "quota size limit"); goto err; } @@ -1334,9 +1347,9 @@ quota_fill_inodectx (xlator_t *this, inode_t *inode, dict_t *dict, ret = quota_inode_ctx_get (inode, this, &ctx, 1); if ((ret == -1) || (ctx == NULL)) { - gf_log (this->name, GF_LOG_WARNING, "cannot create quota " - "context in inode(gfid:%s)", - uuid_utoa (inode->gfid)); + gf_msg (this->name, GF_LOG_WARNING, ENOMEM, + Q_MSG_INODE_CTX_GET_FAILED, "cannot create quota " + "context in inode(gfid:%s)", uuid_utoa (inode->gfid)); ret = -1; *op_errno = ENOMEM; goto out; @@ -1374,11 +1387,12 @@ quota_fill_inodectx (xlator_t *this, inode_t *inode, dict_t *dict, loc->parent->gfid); if (dentry == NULL) { /* - gf_log (this->name, GF_LOG_WARNING, - "cannot create a new dentry (par:%" - PRId64", name:%s) for inode(ino:%" - PRId64", gfid:%s)", - uuid_utoa (local->loc.inode->gfid)); + gf_msg (this->name, GF_LOG_WARNING, ENOMEM, + Q_MSG_ENOMEM, + "cannot create a new dentry (par:%" +- PRId64", name:%s) for inode(ino:%" +- PRId64", gfid:%s)", +- uuid_utoa (local->loc.inode->gfid)); */ ret = -1; *op_errno = ENOMEM; @@ -1457,14 +1471,15 @@ quota_lookup (call_frame_t *frame, xlator_t *this, loc_t *loc, ret = dict_set_int8 (xattr_req, QUOTA_LIMIT_KEY, 1); if (ret < 0) { - gf_log (this->name, GF_LOG_WARNING, - "dict set of key for hard-limit failed"); + gf_msg (this->name, GF_LOG_WARNING, ENOMEM, + Q_MSG_ENOMEM, "dict set of key for " + "hard-limit failed"); goto err; } ret = dict_set_int8 (xattr_req, QUOTA_LIMIT_OBJECTS_KEY, 1); if (ret < 0) { - gf_log (this->name, GF_LOG_WARNING, + gf_msg (this->name, GF_LOG_WARNING, ENOMEM, Q_MSG_ENOMEM, "dict set of key for quota object limit failed"); goto err; } @@ -1509,15 +1524,17 @@ quota_writev_cbk (call_frame_t *frame, void *cookie, xlator_t *this, ret = inode_ctx_get (local->loc.inode, this, &ctx_int); if (ret) { - gf_log (this->name, GF_LOG_WARNING, - "%s: failed to get the context", local->loc.path); + gf_msg (this->name, GF_LOG_WARNING, 0, + Q_MSG_INODE_CTX_GET_FAILED, "%s: failed to get the " + "context", local->loc.path); goto out; } ctx = (quota_inode_ctx_t *)(unsigned long) ctx_int; if (ctx == NULL) { - gf_log (this->name, GF_LOG_WARNING, + gf_msg (this->name, GF_LOG_WARNING, 0, + Q_MSG_INODE_CTX_GET_FAILED, "quota context not set in %s (gfid:%s)", local->loc.path, uuid_utoa (local->loc.inode->gfid)); goto out; @@ -1551,10 +1568,8 @@ quota_writev_helper (call_frame_t *frame, xlator_t *this, fd_t *fd, priv = this->private; local = frame->local; - if (local == NULL) { - gf_log (this->name, GF_LOG_WARNING, "local is NULL"); - goto unwind; - } + + GF_VALIDATE_OR_GOTO ("quota", local, unwind); if (local->op_ret == -1) { op_errno = local->op_errno; @@ -1633,11 +1648,10 @@ quota_writev (call_frame_t *frame, xlator_t *this, fd_t *fd, ret = quota_inode_ctx_get (fd->inode, this, &ctx, 0); if (ctx == NULL) { - gf_log (this->name, GF_LOG_DEBUG, "quota context is NULL on " - "inode (%s). " - "If quota is not enabled recently and crawler has " - "finished crawling, its an error", - uuid_utoa (fd->inode->gfid)); + gf_msg_debug (this->name, 0, "quota context is NULL on inode" + " (%s). If quota is not enabled recently and " + "crawler has finished crawling, its an error", + uuid_utoa (fd->inode->gfid)); } stub = fop_writev_stub (frame, quota_writev_helper, fd, vector, count, @@ -1719,10 +1733,8 @@ quota_mkdir_helper (call_frame_t *frame, xlator_t *this, loc_t *loc, int32_t op_errno = EINVAL; local = frame->local; - if (local == NULL) { - gf_log (this->name, GF_LOG_WARNING, "local is NULL"); - goto unwind; - } + + GF_VALIDATE_OR_GOTO ("quota", local, unwind); op_errno = local->op_errno; @@ -1767,7 +1779,8 @@ quota_mkdir (call_frame_t *frame, xlator_t *this, loc_t *loc, mode_t mode, ret = loc_copy (&local->loc, loc); if (ret) { op_errno = ENOMEM; - gf_log (this->name, GF_LOG_WARNING, "loc_copy failed"); + gf_msg (this->name, GF_LOG_WARNING, ENOMEM, + Q_MSG_ENOMEM, "loc_copy failed"); goto err; } @@ -1822,9 +1835,9 @@ quota_create_cbk (call_frame_t *frame, void *cookie, xlator_t *this, ret = quota_inode_ctx_get (inode, this, &ctx, 1); if ((ret == -1) || (ctx == NULL)) { - gf_log (this->name, GF_LOG_WARNING, "cannot create quota " - "context in inode(gfid:%s)", - uuid_utoa (inode->gfid)); + gf_msg (this->name, GF_LOG_WARNING, ENOMEM, + Q_MSG_INODE_CTX_GET_FAILED, "cannot create quota " + "context in inode(gfid:%s)", uuid_utoa (inode->gfid)); op_ret = -1; op_errno = ENOMEM; goto unwind; @@ -1837,9 +1850,9 @@ quota_create_cbk (call_frame_t *frame, void *cookie, xlator_t *this, dentry = __quota_dentry_new (ctx, (char *)local->loc.name, local->loc.parent->gfid); if (dentry == NULL) { - gf_log (this->name, GF_LOG_WARNING, - "cannot create a new dentry (name:%s) for " - "inode(gfid:%s)", local->loc.name, + gf_msg (this->name, GF_LOG_WARNING, ENOMEM, + Q_MSG_ENOMEM, "cannot create a new dentry " + "(name:%s) for inode(gfid:%s)", local->loc.name, uuid_utoa (local->loc.inode->gfid)); op_ret = -1; op_errno = ENOMEM; @@ -1867,12 +1880,10 @@ quota_create_helper (call_frame_t *frame, xlator_t *this, loc_t *loc, local = frame->local; + GF_VALIDATE_OR_GOTO ("quota", local, unwind); + priv = this->private; - if (local == NULL) { - gf_log (this->name, GF_LOG_WARNING, "local is NULL"); - goto unwind; - } if (local->op_ret == -1) { op_errno = local->op_errno; @@ -1917,7 +1928,8 @@ quota_create (call_frame_t *frame, xlator_t *this, loc_t *loc, int32_t flags, ret = loc_copy (&local->loc, loc); if (ret) { - gf_log (this->name, GF_LOG_WARNING, "loc_copy failed"); + gf_msg (this->name, GF_LOG_WARNING, ENOMEM, + Q_MSG_ENOMEM, "loc_copy failed"); op_errno = ENOMEM; goto err; } @@ -1973,8 +1985,9 @@ quota_unlink_cbk (call_frame_t *frame, void *cookie, xlator_t *this, ctx = (quota_inode_ctx_t *)(unsigned long)value; if (ctx == NULL) { - gf_log (this->name, GF_LOG_WARNING, - "quota context not set in inode (gfid:%s)", + gf_msg (this->name, GF_LOG_WARNING, EINVAL, + Q_MSG_INODE_CTX_GET_FAILED, + "quota context not set inode (gfid:%s)", uuid_utoa (local->loc.inode->gfid)); goto out; } @@ -2022,7 +2035,8 @@ quota_unlink (call_frame_t *frame, xlator_t *this, loc_t *loc, int xflag, ret = loc_copy (&local->loc, loc); if (ret) { - gf_log (this->name, GF_LOG_WARNING, "loc_copy failed"); + gf_msg (this->name, GF_LOG_WARNING, ENOMEM, + Q_MSG_ENOMEM, "loc_copy failed"); goto err; } @@ -2065,11 +2079,10 @@ quota_link_cbk (call_frame_t *frame, void *cookie, xlator_t *this, ret = quota_inode_ctx_get (inode, this, &ctx, 0); if ((ret == -1) || (ctx == NULL)) { - gf_log (this->name, GF_LOG_DEBUG, "quota context is NULL on " - "inode (%s). " - "If quota is not enabled recently and crawler has " - "finished crawling, its an error", - uuid_utoa (inode->gfid)); + gf_msg_debug (this->name, 0, "quota context is NULL on inode" + " (%s). If quota is not enabled recently and " + "crawler has finished crawling, its an error", + uuid_utoa (inode->gfid)); goto out; } @@ -2079,13 +2092,15 @@ quota_link_cbk (call_frame_t *frame, void *cookie, xlator_t *this, if ((strcmp (dentry->name, local->loc.name) == 0) && (gf_uuid_compare (local->loc.parent->gfid, dentry->par) == 0)) { - found = 1; - gf_log (this->name, GF_LOG_WARNING, - "new entry being linked (name:%s) for " - "inode (gfid:%s) is already present " - "in inode-dentry-list", dentry->name, - uuid_utoa (local->loc.inode->gfid)); - break; + found = 1; + + gf_msg_debug (this->name, 0, "new entry being" + " linked (name:%s) for inode " + "(gfid:%s) is already present " + "in inode-dentry-list", + dentry->name, + uuid_utoa (local->loc.inode->gfid)); + break; } } @@ -2094,9 +2109,10 @@ quota_link_cbk (call_frame_t *frame, void *cookie, xlator_t *this, (char *)local->loc.name, local->loc.parent->gfid); if (dentry == NULL) { - gf_log (this->name, GF_LOG_WARNING, - "cannot create a new dentry (name:%s) " - "for inode(gfid:%s)", local->loc.name, + gf_msg (this->name, GF_LOG_WARNING, ENOMEM, + Q_MSG_ENOMEM, + "cannot create a new dentry (name:%s)" + "for inode(gfid:%s)", local->loc.name, uuid_utoa (local->loc.inode->gfid)); op_ret = -1; op_errno = ENOMEM; @@ -2128,10 +2144,8 @@ quota_link_helper (call_frame_t *frame, xlator_t *this, loc_t *oldloc, priv = this->private; local = frame->local; - if (local == NULL) { - gf_log (this->name, GF_LOG_WARNING, "local is NULL"); - goto unwind; - } + + GF_VALIDATE_OR_GOTO ("quota", local, unwind); op_errno = local->op_errno; @@ -2178,7 +2192,8 @@ quota_link_continue (call_frame_t *frame) local->newloc.parent, &common_ancestor); if (ret < 0 || gf_uuid_is_null(common_ancestor)) { - gf_log (this->name, GF_LOG_ERROR, "failed to get " + gf_msg (this->name, GF_LOG_ERROR, ESTALE, + Q_MSG_ANCESTRY_BUILD_FAILED, "failed to get " "common_ancestor for %s and %s", local->oldloc.path, local->newloc.path); op_errno = ESTALE; @@ -2209,11 +2224,10 @@ quota_link_continue (call_frame_t *frame) quota_inode_ctx_get (local->oldloc.inode, this, &ctx, 0); if (ctx == NULL) { - gf_log (this->name, GF_LOG_DEBUG, "quota context is NULL on " - "inode (%s). " - "If quota is not enabled recently and crawler has " - "finished crawling, its an error", - uuid_utoa (local->oldloc.inode->gfid)); + gf_msg_debug (this->name, 0, "quota context is NULL on inode" + " (%s). If quota is not enabled recently and " + "crawler has finished crawling, its an error", + uuid_utoa (local->oldloc.inode->gfid)); } LOCK (&local->lock); @@ -2260,9 +2274,9 @@ quota_link (call_frame_t *frame, xlator_t *this, loc_t *oldloc, loc_t *newloc, /* No need to check quota limit if src and dst parents are same */ if (oldloc->parent && newloc->parent && !gf_uuid_compare(oldloc->parent->gfid, newloc->parent->gfid)) { - gf_log (this->name, GF_LOG_DEBUG, "link %s -> %s are " - "in the same directory, so skip check limit", - oldloc->path, newloc->path); + gf_msg_debug (this->name, GF_LOG_DEBUG, "link %s -> %s are " + "in the same directory, so skip check limit", + oldloc->path, newloc->path); goto off; } @@ -2278,19 +2292,22 @@ quota_link (call_frame_t *frame, xlator_t *this, loc_t *oldloc, loc_t *newloc, ret = loc_copy (&local->loc, newloc); if (ret == -1) { - gf_log (this->name, GF_LOG_WARNING, "loc_copy failed"); + gf_msg (this->name, GF_LOG_WARNING, ENOMEM, + Q_MSG_ENOMEM, "loc_copy failed"); goto err; } ret = loc_copy (&local->oldloc, oldloc); if (ret < 0) { - gf_log (this->name, GF_LOG_WARNING, "loc_copy failed"); + gf_msg (this->name, GF_LOG_WARNING, ENOMEM, Q_MSG_ENOMEM, + "loc_copy failed"); goto err; } ret = loc_copy (&local->newloc, newloc); if (ret < 0) { - gf_log (this->name, GF_LOG_WARNING, "loc_copy failed"); + gf_msg (this->name, GF_LOG_WARNING, ENOMEM, Q_MSG_ENOMEM, + "loc_copy failed"); goto err; } @@ -2345,12 +2362,8 @@ quota_rename_cbk (call_frame_t *frame, void *cookie, xlator_t *this, } local = frame->local; - if (local == NULL) { - op_ret = -1; - op_errno = EINVAL; - gf_log (this->name, GF_LOG_WARNING, "local is NULL"); - goto out; - } + + GF_VALIDATE_OR_GOTO ("quota", local, out); if (QUOTA_REG_OR_LNK_FILE (local->oldloc.inode->ia_type)) { size = buf->ia_blocks * 512; @@ -2362,11 +2375,10 @@ quota_rename_cbk (call_frame_t *frame, void *cookie, xlator_t *this, ret = quota_inode_ctx_get (local->oldloc.inode, this, &ctx, 0); if ((ret == -1) || (ctx == NULL)) { - gf_log (this->name, GF_LOG_DEBUG, "quota context is NULL on " - "inode (%s). " - "If quota is not enabled recently and crawler has " - "finished crawling, its an error", - uuid_utoa (local->oldloc.inode->gfid)); + gf_msg_debug (this->name, 0, "quota context is NULL on inode" + " (%s). If quota is not enabled recently and " + "crawler has finished crawling, its an error", + uuid_utoa (local->oldloc.inode->gfid)); goto out; } @@ -2383,10 +2395,9 @@ quota_rename_cbk (call_frame_t *frame, void *cookie, xlator_t *this, (gf_uuid_compare (local->newloc.parent->gfid, dentry->par) == 0)) { new_dentry_found = 1; - gf_log (this->name, GF_LOG_WARNING, - "new entry being linked (name:%s) for " - "inode (gfid:%s) is already present " - "in inode-dentry-list", dentry->name, + gf_msg_debug (this->name, 0, "new entry being " + "linked (name:%s) for inode (gfid:%s) " + "is in inode-dentry-list", dentry->name, uuid_utoa (local->oldloc.inode->gfid)); } @@ -2397,9 +2408,9 @@ quota_rename_cbk (call_frame_t *frame, void *cookie, xlator_t *this, if (old_dentry != NULL) { __quota_dentry_free (old_dentry); } else { - gf_log (this->name, GF_LOG_WARNING, - "dentry corresponding to the path just renamed " - "(name:%s) is not present", local->oldloc.name); + gf_msg_debug (this->name, 0, "dentry corresponding" + "the path just renamed (name:%s) is not" + " present", local->oldloc.name); } if (!new_dentry_found) { @@ -2407,11 +2418,12 @@ quota_rename_cbk (call_frame_t *frame, void *cookie, xlator_t *this, (char *)local->newloc.name, local->newloc.parent->gfid); if (dentry == NULL) { - gf_log (this->name, GF_LOG_WARNING, - "cannot create a new dentry (name:%s) " - "for inode(gfid:%s)", - local->newloc.name, - uuid_utoa (local->oldloc.inode->gfid)); + gf_msg (this->name, GF_LOG_WARNING, ENOMEM, + Q_MSG_ENOMEM, + "cannot create a new dentry (name:%s) " + "for inode(gfid:%s)", + local->newloc.name, + uuid_utoa (local->newloc.inode->gfid)); op_ret = -1; op_errno = ENOMEM; goto unlock; @@ -2442,10 +2454,8 @@ quota_rename_helper (call_frame_t *frame, xlator_t *this, loc_t *oldloc, priv = this->private; local = frame->local; - if (local == NULL) { - gf_log (this->name, GF_LOG_WARNING, "local is NULL"); - goto unwind; - } + + GF_VALIDATE_OR_GOTO ("quota", local, unwind); op_errno = local->op_errno; @@ -2491,8 +2501,8 @@ quota_rename_get_size_cbk (call_frame_t *frame, void *cookie, xlator_t *this, ret = dict_get_bin (xdata, QUOTA_SIZE_KEY, (void **) &size); if (ret < 0) { - gf_log (this->name, GF_LOG_WARNING, - "size key not present in dict"); + gf_msg (this->name, GF_LOG_WARNING, EINVAL, + Q_MSG_SIZE_KEY_MISSING, "size key not present in dict"); op_errno = EINVAL; goto out; } @@ -2528,7 +2538,8 @@ quota_rename_continue (call_frame_t *frame) local->newloc.parent, &common_ancestor); if (ret < 0 || gf_uuid_is_null(common_ancestor)) { - gf_log (this->name, GF_LOG_ERROR, "failed to get " + gf_msg (this->name, GF_LOG_ERROR, ESTALE, + Q_MSG_ANCESTRY_BUILD_FAILED, "failed to get " "common_ancestor for %s and %s", local->oldloc.path, local->newloc.path); op_errno = ESTALE; @@ -2545,11 +2556,14 @@ quota_rename_continue (call_frame_t *frame) if (QUOTA_REG_OR_LNK_FILE (local->oldloc.inode->ia_type)) { ret = quota_inode_ctx_get (local->oldloc.inode, this, &ctx, 0); if (ctx == NULL) { - gf_log (this->name, GF_LOG_WARNING, + gf_msg (this->name, GF_LOG_WARNING, 0, + Q_MSG_INODE_CTX_GET_FAILED, "quota context not set in inode (gfid:%s), " "considering file size as zero while enforcing " "quota on new ancestry", uuid_utoa (local->oldloc.inode->gfid)); + + local->delta = 0; } else { @@ -2605,9 +2619,9 @@ quota_rename (call_frame_t *frame, xlator_t *this, loc_t *oldloc, /* No need to check quota limit if src and dst parents are same */ if (oldloc->parent && newloc->parent && !gf_uuid_compare(oldloc->parent->gfid, newloc->parent->gfid)) { - gf_log (this->name, GF_LOG_DEBUG, "rename %s -> %s are " - "in the same directory, so skip check limit", - oldloc->path, newloc->path); + gf_msg_debug (this->name, 0, "rename %s -> %s are " + "in the same directory, so skip check limit", + oldloc->path, newloc->path); goto off; } @@ -2620,13 +2634,15 @@ quota_rename (call_frame_t *frame, xlator_t *this, loc_t *oldloc, ret = loc_copy (&local->oldloc, oldloc); if (ret < 0) { - gf_log (this->name, GF_LOG_WARNING, "loc_copy failed"); + gf_msg (this->name, GF_LOG_WARNING, ENOMEM, Q_MSG_ENOMEM, + "loc_copy failed"); goto err; } ret = loc_copy (&local->newloc, newloc); if (ret < 0) { - gf_log (this->name, GF_LOG_WARNING, "loc_copy failed"); + gf_msg (this->name, GF_LOG_WARNING, ENOMEM, Q_MSG_ENOMEM, + "loc_copy failed"); goto err; } @@ -2683,11 +2699,10 @@ quota_symlink_cbk (call_frame_t *frame, void *cookie, xlator_t *this, quota_inode_ctx_get (local->loc.inode, this, &ctx, 1); if (ctx == NULL) { - gf_log (this->name, GF_LOG_DEBUG, "quota context is NULL on " - "inode (%s). " - "If quota is not enabled recently and crawler has " - "finished crawling, its an error", - uuid_utoa (local->loc.inode->gfid)); + gf_msg_debug (this->name, 0, "quota context is NULL on inode" + " (%s). If quota is not enabled recently and " + "crawler has finished crawling, its an error", + uuid_utoa (local->loc.inode->gfid)); goto out; } @@ -2699,10 +2714,11 @@ quota_symlink_cbk (call_frame_t *frame, void *cookie, xlator_t *this, dentry = __quota_dentry_new (ctx, (char *)local->loc.name, local->loc.parent->gfid); if (dentry == NULL) { - gf_log (this->name, GF_LOG_WARNING, - "cannot create a new dentry (name:%s) for " - "inode(gfid:%s)", local->loc.name, - uuid_utoa (local->loc.inode->gfid)); + gf_msg (this->name, GF_LOG_WARNING, ENOMEM, + Q_MSG_ENOMEM, "cannot create " + "a new dentry (name:%s) for inode(gfid:%s)", + local->loc.name, + uuid_utoa (local->loc.inode->gfid)); op_ret = -1; op_errno = ENOMEM; } @@ -2726,10 +2742,8 @@ quota_symlink_helper (call_frame_t *frame, xlator_t *this, const char *linkpath, quota_priv_t *priv = NULL; local = frame->local; - if (local == NULL) { - gf_log (this->name, GF_LOG_WARNING, "local is NULL"); - goto unwind; - } + + GF_VALIDATE_OR_GOTO ("quota", local, unwind); priv = this->private; @@ -2773,7 +2787,8 @@ quota_symlink (call_frame_t *frame, xlator_t *this, const char *linkpath, ret = loc_copy (&local->loc, loc); if (ret < 0) { - gf_log (this->name, GF_LOG_WARNING, "loc_copy failed"); + gf_msg (this->name, GF_LOG_WARNING, ENOMEM, + Q_MSG_ENOMEM, "loc_copy failed"); goto err; } @@ -2821,18 +2836,15 @@ quota_truncate_cbk (call_frame_t *frame, void *cookie, xlator_t *this, } local = frame->local; - if (local == NULL) { - gf_log (this->name, GF_LOG_WARNING, "local is NULL"); - goto out; - } + + GF_VALIDATE_OR_GOTO ("quota", local, out); quota_inode_ctx_get (local->loc.inode, this, &ctx, 0); if (ctx == NULL) { - gf_log (this->name, GF_LOG_DEBUG, "quota context is NULL on " - "inode (%s). " - "If quota is not enabled recently and crawler has " - "finished crawling, its an error", - uuid_utoa (local->loc.inode->gfid)); + gf_msg_debug (this->name, 0, "quota context is NULL on inode" + " (%s). If quota is not enabled recently and " + "crawler has finished crawling, its an error", + uuid_utoa (local->loc.inode->gfid)); goto out; } @@ -2870,7 +2882,8 @@ quota_truncate (call_frame_t *frame, xlator_t *this, loc_t *loc, off_t offset, ret = loc_copy (&local->loc, loc); if (ret < 0) { - gf_log (this->name, GF_LOG_WARNING, "loc_copy failed"); + gf_msg (this->name, GF_LOG_WARNING, ENOMEM, + Q_MSG_ENOMEM, "loc_copy failed"); goto err; } @@ -2903,18 +2916,15 @@ quota_ftruncate_cbk (call_frame_t *frame, void *cookie, xlator_t *this, } local = frame->local; - if (local == NULL) { - gf_log (this->name, GF_LOG_WARNING, "local is NULL"); - goto out; - } + + GF_VALIDATE_OR_GOTO ("quota", local, out); quota_inode_ctx_get (local->loc.inode, this, &ctx, 0); if (ctx == NULL) { - gf_log (this->name, GF_LOG_DEBUG, "quota context is NULL on " - "inode (%s). " - "If quota is not enabled recently and crawler has " - "finished crawling, its an error", - uuid_utoa (local->loc.inode->gfid)); + gf_msg_debug (this->name, 0, "quota context is NULL on inode" + " (%s). If quota is not enabled recently and " + "crawler has finished crawling, its an error", + uuid_utoa (local->loc.inode->gfid)); goto out; } @@ -3004,7 +3014,7 @@ dict_set: if (ret < 0) goto out; - gf_log (this->name, GF_LOG_DEBUG, "str = %s", dir_limit); + gf_msg_debug (this->name, 0, "str = %s", dir_limit); QUOTA_STACK_UNWIND (getxattr, frame, 0, 0, dict, NULL); @@ -3069,19 +3079,15 @@ quota_stat_cbk (call_frame_t *frame, void *cookie, xlator_t *this, } local = frame->local; - if (local == NULL) { - gf_log (this->name, GF_LOG_WARNING, "local is NULL"); - goto out; - } + + GF_VALIDATE_OR_GOTO ("quota", local, out); quota_inode_ctx_get (local->loc.inode, this, &ctx, 0); if (ctx == NULL) { if (!IA_ISDIR (buf->ia_type)) { - gf_log (this->name, GF_LOG_DEBUG, - "quota context is NULL on " - "inode (%s). " - "If quota is not enabled recently and crawler " - "has finished crawling, its an error", + gf_msg_debug (this->name, 0, "quota context is NULL on inode" + " (%s). If quota is not enabled recently and " + "crawler has finished crawling, its an error", uuid_utoa (local->loc.inode->gfid)); } @@ -3120,7 +3126,8 @@ quota_stat (call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *xdata) frame->local = local; ret = loc_copy (&local->loc, loc); if (ret < 0) { - gf_log (this->name, GF_LOG_WARNING, "loc_copy failed"); + gf_msg (this->name, GF_LOG_WARNING, ENOMEM, + Q_MSG_ENOMEM, "loc_copy failed"); goto unwind; } @@ -3154,19 +3161,15 @@ quota_fstat_cbk (call_frame_t *frame, void *cookie, xlator_t *this, } local = frame->local; - if (local == NULL) { - gf_log (this->name, GF_LOG_WARNING, "local is NULL"); - goto out; - } + + GF_VALIDATE_OR_GOTO ("quota", local, out); quota_inode_ctx_get (local->loc.inode, this, &ctx, 0); if (ctx == NULL) { if (!IA_ISDIR (buf->ia_type)) { - gf_log (this->name, GF_LOG_DEBUG, - "quota context is NULL on " - "inode (%s). " - "If quota is not enabled recently and crawler " - "has finished crawling, its an error", + gf_msg_debug (this->name, 0, "quota context is NULL on inode" + " (%s). If quota is not enabled recently and " + "crawler has finished crawling, its an error", uuid_utoa (local->loc.inode->gfid)); } @@ -3235,18 +3238,15 @@ quota_readlink_cbk (call_frame_t *frame, void *cookie, xlator_t *this, } local = frame->local; - if (local == NULL) { - gf_log (this->name, GF_LOG_WARNING, "local is NULL"); - goto out; - } + + GF_VALIDATE_OR_GOTO ("quota", local, out); quota_inode_ctx_get (local->loc.inode, this, &ctx, 0); if (ctx == NULL) { - gf_log (this->name, GF_LOG_DEBUG, "quota context is NULL on " - "inode (%s). " - "If quota is not enabled recently and crawler has " - "finished crawling, its an error", - uuid_utoa (local->loc.inode->gfid)); + gf_msg_debug (this->name, 0, "quota context is NULL on inode" + " (%s). If quota is not enabled recently and " + "crawler has finished crawling, its an error", + uuid_utoa (local->loc.inode->gfid)); goto out; } @@ -3284,7 +3284,8 @@ quota_readlink (call_frame_t *frame, xlator_t *this, loc_t *loc, size_t size, ret = loc_copy (&local->loc, loc); if (ret < 0) { - gf_log (this->name, GF_LOG_WARNING, "loc_copy failed"); + gf_msg (this->name, GF_LOG_WARNING, ENOMEM, + Q_MSG_ENOMEM, "loc_copy failed"); goto unwind; } @@ -3319,18 +3320,15 @@ quota_readv_cbk (call_frame_t *frame, void *cookie, xlator_t *this, } local = frame->local; - if (local == NULL) { - gf_log (this->name, GF_LOG_WARNING, "local is NULL"); - goto out; - } + + GF_VALIDATE_OR_GOTO ("quota", local, out); quota_inode_ctx_get (local->loc.inode, this, &ctx, 0); if (ctx == NULL) { - gf_log (this->name, GF_LOG_DEBUG, "quota context is NULL on " - "inode (%s). " - "If quota is not enabled recently and crawler has " - "finished crawling, its an error", - uuid_utoa (local->loc.inode->gfid)); + gf_msg_debug (this->name, 0, "quota context is NULL on inode" + " (%s). If quota is not enabled recently and " + "crawler has finished crawling, its an error", + uuid_utoa (local->loc.inode->gfid)); goto out; } @@ -3398,18 +3396,15 @@ quota_fsync_cbk (call_frame_t *frame, void *cookie, xlator_t *this, } local = frame->local; - if (local == NULL) { - gf_log (this->name, GF_LOG_WARNING, "local is NULL"); - goto out; - } + + GF_VALIDATE_OR_GOTO ("quota", local, out); quota_inode_ctx_get (local->loc.inode, this, &ctx, 0); if (ctx == NULL) { - gf_log (this->name, GF_LOG_DEBUG, "quota context is NULL on " - "inode (%s). " - "If quota is not enabled recently and crawler has " - "finished crawling, its an error", - uuid_utoa (local->loc.inode->gfid)); + gf_msg_debug (this->name, 0, "quota context is NULL on inode" + " (%s). If quota is not enabled recently and " + "crawler has finished crawling, its an error", + uuid_utoa (local->loc.inode->gfid)); goto out; } @@ -3476,18 +3471,15 @@ quota_setattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this, } local = frame->local; - if (local == NULL) { - gf_log (this->name, GF_LOG_WARNING, "local is NULL"); - goto out; - } + + GF_VALIDATE_OR_GOTO ("quota", local, out); quota_inode_ctx_get (local->loc.inode, this, &ctx, 0); if (ctx == NULL) { if (!IA_ISDIR (statpost->ia_type)) { - gf_log (this->name, GF_LOG_DEBUG, "quota context is " - "NULL on inode (%s). " - "If quota is not enabled recently and crawler " - "has finished crawling, its an error", + gf_msg_debug (this->name, 0, "quota context is NULL on inode" + " (%s). If quota is not enabled recently and " + "crawler has finished crawling, its an error", uuid_utoa (local->loc.inode->gfid)); } @@ -3529,7 +3521,8 @@ quota_setattr (call_frame_t *frame, xlator_t *this, loc_t *loc, ret = loc_copy (&local->loc, loc); if (ret < 0) { - gf_log (this->name, GF_LOG_WARNING, "loc_copy failed"); + gf_msg (this->name, GF_LOG_WARNING, ENOMEM, + Q_MSG_ENOMEM, "loc_copy failed"); goto unwind; } @@ -3563,18 +3556,15 @@ quota_fsetattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this, } local = frame->local; - if (local == NULL) { - gf_log (this->name, GF_LOG_WARNING, "local is NULL"); - goto out; - } + + GF_VALIDATE_OR_GOTO ("quota", local, out); quota_inode_ctx_get (local->loc.inode, this, &ctx, 0); if (ctx == NULL) { if (!IA_ISDIR (statpost->ia_type)) { - gf_log (this->name, GF_LOG_DEBUG, "quota context is " - "NULL on inode (%s). " - "If quota is not enabled recently and crawler " - "has finished crawling, its an error", + gf_msg_debug (this->name, 0, "quota context is NULL on inode" + " (%s). If quota is not enabled recently and " + "crawler has finished crawling, its an error", uuid_utoa (local->loc.inode->gfid)); } @@ -3649,8 +3639,10 @@ quota_mknod_cbk (call_frame_t *frame, void *cookie, xlator_t *this, ret = quota_inode_ctx_get (inode, this, &ctx, 1); if ((ret == -1) || (ctx == NULL)) { - gf_log (this->name, GF_LOG_WARNING, "cannot create quota " - "context in inode (gfid:%s)", uuid_utoa (inode->gfid)); + gf_msg (this->name, GF_LOG_WARNING, 0, + Q_MSG_INODE_CTX_GET_FAILED, + "cannot create quota context in " + "inode(gfid:%s)", uuid_utoa (inode->gfid)); op_ret = -1; op_errno = ENOMEM; goto unwind; @@ -3663,10 +3655,10 @@ quota_mknod_cbk (call_frame_t *frame, void *cookie, xlator_t *this, dentry = __quota_dentry_new (ctx, (char *)local->loc.name, local->loc.parent->gfid); if (dentry == NULL) { - gf_log (this->name, GF_LOG_WARNING, - "cannot create a new dentry (name:%s) for " - "inode(gfid:%s)", local->loc.name, - uuid_utoa (local->loc.inode->gfid)); + gf_msg (this->name, GF_LOG_WARNING, ENOMEM, + Q_MSG_ENOMEM, "cannot create a new dentry " + "(name:%s) for inode(gfid:%s)", local->loc.name, + uuid_utoa (local->loc.inode->gfid)); op_ret = -1; op_errno = ENOMEM; goto unlock; @@ -3691,10 +3683,8 @@ quota_mknod_helper (call_frame_t *frame, xlator_t *this, loc_t *loc, quota_priv_t *priv = NULL; local = frame->local; - if (local == NULL) { - gf_log (this->name, GF_LOG_WARNING, "local is NULL"); - goto unwind; - } + + GF_VALIDATE_OR_GOTO ("quota", local, unwind); priv = this->private; @@ -3739,7 +3729,8 @@ quota_mknod (call_frame_t *frame, xlator_t *this, loc_t *loc, mode_t mode, ret = loc_copy (&local->loc, loc); if (ret) { - gf_log (this->name, GF_LOG_WARNING, "loc_copy failed"); + gf_msg (this->name, GF_LOG_WARNING, ENOMEM, + Q_MSG_ENOMEM, "loc_copy failed"); goto err; } @@ -4097,11 +4088,8 @@ quota_statfs_cbk (call_frame_t *frame, void *cookie, xlator_t *this, * cookie, and it would only do so if the value was non-NULL. This * check is therefore just routine defensive coding. */ - if (!inode) { - gf_log(this->name,GF_LOG_WARNING, - "null inode, cannot adjust for quota"); - goto unwind; - } + + GF_VALIDATE_OR_GOTO ("quota", inode, unwind); inode_ctx_get (inode, this, &value); ctx = (quota_inode_ctx_t *)(unsigned long)value; @@ -4135,8 +4123,9 @@ quota_statfs_cbk (call_frame_t *frame, void *cookie, xlator_t *this, ret = dict_set_int8 (xdata, "quota-deem-statfs", 1); if (-1 == ret) - gf_log (this->name, GF_LOG_ERROR, "Dict set failed, " - "deem-statfs option may have no effect"); + gf_msg (this->name, GF_LOG_ERROR, ENOMEM, + Q_MSG_ENOMEM, "Dict set failed, deem-statfs option may " + "have no effect"); unwind: QUOTA_STACK_UNWIND (statfs, frame, op_ret, op_errno, buf, xdata); @@ -4201,8 +4190,9 @@ quota_statfs_validate_cbk (call_frame_t *frame, void *cookie, xlator_t *this, ctx = (quota_inode_ctx_t *)(unsigned long)value; if ((ret == -1) || (ctx == NULL)) { - gf_log (this->name, GF_LOG_WARNING, - "quota context is not present in inode (gfid:%s)", + gf_msg (this->name, GF_LOG_WARNING, EINVAL, + Q_MSG_INODE_CTX_GET_FAILED, + "quota context is not present in inode (gfid:%s)", uuid_utoa (local->validate_loc.inode->gfid)); op_errno = EINVAL; goto resume; @@ -4210,8 +4200,9 @@ quota_statfs_validate_cbk (call_frame_t *frame, void *cookie, xlator_t *this, ret = quota_dict_get_meta (xdata, QUOTA_SIZE_KEY, &size); if (ret == -1) { - gf_log (this->name, GF_LOG_WARNING, "dict get failed " - "on quota size"); + gf_msg (this->name, GF_LOG_WARNING, EINVAL, + Q_MSG_SIZE_KEY_MISSING, "size key not present in " + "dict"); op_errno = EINVAL; } @@ -4245,7 +4236,8 @@ quota_get_limit_dir_continuation (struct list_head *parents, inode_t *inode, if ((op_ret < 0) || list_empty (parents)) { if (op_ret >= 0) { - gf_log (this->name, GF_LOG_WARNING, + gf_msg (this->name, GF_LOG_WARNING, EIO, + Q_MSG_ANCESTRY_BUILD_FAILED, "Couldn't build ancestry for inode (gfid:%s). " "Without knowing ancestors till root, quota " "cannot be enforced. " @@ -4331,8 +4323,8 @@ quota_get_limit_dir (call_frame_t *frame, inode_t *cur_inode, xlator_t *this) return; off: - gf_log (this->name, GF_LOG_DEBUG, - "No limit set on the inode or it's parents."); + gf_msg_debug (this->name, 0, + "No limit set on the inode or it's parents."); QUOTA_STACK_WIND_TAIL (frame, FIRST_CHILD(this), FIRST_CHILD(this)->fops->statfs, @@ -4415,7 +4407,6 @@ quota_statfs (call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *xdata) gf_log (this->name, GF_LOG_ERROR, "Missing inode, can't adjust for quota"); - off: STACK_WIND_TAIL (frame, FIRST_CHILD(this), FIRST_CHILD(this)->fops->statfs, loc, xdata); @@ -4496,8 +4487,9 @@ quota_readdirp (call_frame_t *frame, xlator_t *this, fd_t *fd, size_t size, if (dict) { ret = dict_set_int8 (dict, QUOTA_LIMIT_KEY, 1); if (ret < 0) { - gf_log (this->name, GF_LOG_WARNING, - "dict set of key for hard-limit failed"); + gf_msg (this->name, GF_LOG_WARNING, ENOMEM, + Q_MSG_ENOMEM, + "dict set of key for hard-limit"); goto err; } } @@ -4505,8 +4497,9 @@ quota_readdirp (call_frame_t *frame, xlator_t *this, fd_t *fd, size_t size, if (dict) { ret = dict_set_int8 (dict, QUOTA_LIMIT_OBJECTS_KEY, 1); if (ret < 0) { - gf_log (this->name, GF_LOG_WARNING, - "dict set of key for hard-limit failed"); + gf_msg (this->name, GF_LOG_WARNING, ENOMEM, + Q_MSG_ENOMEM, "dict set of key for hard-limit " + "failed"); goto err; } } @@ -4554,16 +4547,18 @@ quota_fallocate_cbk(call_frame_t *frame, void *cookie, xlator_t *this, ret = inode_ctx_get (local->loc.inode, this, &ctx_int); if (ret) { - gf_log (this->name, GF_LOG_WARNING, - "%s: failed to get the context", local->loc.path); + gf_msg (this->name, GF_LOG_WARNING, 0, + Q_MSG_INODE_CTX_GET_FAILED, + "%s: failed to get the context", local->loc.path); goto out; } ctx = (quota_inode_ctx_t *)(unsigned long) ctx_int; if (ctx == NULL) { - gf_log (this->name, GF_LOG_WARNING, - "quota context not set in %s (gfid:%s)", + gf_msg (this->name, GF_LOG_WARNING, 0, + Q_MSG_INODE_CTX_GET_FAILED, + "quota context not set in %s (gfid:%s)", local->loc.path, uuid_utoa (local->loc.inode->gfid)); goto out; } @@ -4591,10 +4586,8 @@ quota_fallocate_helper (call_frame_t *frame, xlator_t *this, fd_t *fd, quota_priv_t *priv = NULL; local = frame->local; - if (local == NULL) { - gf_log (this->name, GF_LOG_WARNING, "local is NULL"); - goto unwind; - } + + GF_VALIDATE_OR_GOTO ("quota", local, unwind); priv = this->private; @@ -4646,11 +4639,10 @@ quota_fallocate(call_frame_t *frame, xlator_t *this, fd_t *fd, int32_t mode, ret = quota_inode_ctx_get (fd->inode, this, &ctx, 0); if (ctx == NULL) { - gf_log (this->name, GF_LOG_DEBUG, "quota context is " - "NULL on inode (%s). " - "If quota is not enabled recently and crawler " - "has finished crawling, its an error", - uuid_utoa (local->loc.inode->gfid)); + gf_msg_debug (this->name, 0, "quota context is NULL on inode" + " (%s). If quota is not enabled recently and " + "crawler has finished crawling, its an error", + uuid_utoa (local->loc.inode->gfid)); } stub = fop_fallocate_stub(frame, quota_fallocate_helper, fd, mode, @@ -4718,8 +4710,9 @@ quota_log_helper (char **usage_str, int64_t cur_size, inode_t *inode, *usage_str = gf_uint64_2human_readable (cur_size); if (!(*usage_str)) - gf_log (this->name, GF_LOG_ERROR, "integer to string " - "conversion failed Reason:\"Cannot allocate memory\""); + gf_msg (this->name, GF_LOG_ERROR, ENOMEM, Q_MSG_ENOMEM, + "integer to string conversion failed Reason" + ":\"Cannot allocate memory\""); inode_path (inode, NULL, path); if (!(*path)) @@ -4754,8 +4747,9 @@ quota_log_usage (xlator_t *this, quota_inode_ctx_t *ctx, inode_t *inode, quota_log_helper (&usage_str, cur_size, inode, &path, &cur_time); - gf_log (this->name, GF_LOG_ALERT, "Usage crossed " - "soft limit: %s used by %s", usage_str, path); + gf_msg (this->name, GF_LOG_ALERT, 0, + Q_MSG_CROSSED_SOFT_LIMIT, "Usage crossed soft limit: " + "%s used by %s", usage_str, path); ctx->prev_log = cur_time; } /* Usage is above soft limit */ @@ -4765,8 +4759,9 @@ quota_log_usage (xlator_t *this, quota_inode_ctx_t *ctx, inode_t *inode, quota_log_helper (&usage_str, cur_size, inode, &path, &cur_time); - gf_log (this->name, GF_LOG_ALERT, "Usage is above " - "soft limit: %s used by %s", usage_str, path); + gf_msg (this->name, GF_LOG_ALERT, 0, Q_MSG_CROSSED_SOFT_LIMIT, + "Usage is above soft limit: %s used by %s", + usage_str, path); ctx->prev_log = cur_time; } @@ -4785,8 +4780,8 @@ mem_acct_init (xlator_t *this) ret = xlator_mem_acct_init (this, gf_quota_mt_end + 1); if (ret != 0) { - gf_log (this->name, GF_LOG_WARNING, "Memory accounting" - "init failed"); + gf_msg (this->name, GF_LOG_WARNING, ENOMEM, Q_MSG_ENOMEM, + "Memory accounting init failed"); return ret; } @@ -4834,14 +4829,16 @@ init (xlator_t *this) if ((this->children == NULL) || this->children->next) { - gf_log (this->name, GF_LOG_ERROR, + gf_msg (this->name, GF_LOG_ERROR, 0, + Q_MSG_INVALID_VOLFILE, "FATAL: quota (%s) not configured with " "exactly one child", this->name); return -1; } if (this->parents == NULL) { - gf_log (this->name, GF_LOG_WARNING, + gf_msg (this->name, GF_LOG_WARNING, 0, + Q_MSG_INVALID_VOLFILE, "dangling volume. check volfile"); } @@ -4863,8 +4860,8 @@ init (xlator_t *this) this->local_pool = mem_pool_new (quota_local_t, 64); if (!this->local_pool) { ret = -1; - gf_log (this->name, GF_LOG_ERROR, - "failed to create local_t's memory pool"); + gf_msg (this->name, GF_LOG_ERROR, ENOMEM, + Q_MSG_ENOMEM, "failed to create local_t's memory pool"); goto err; } @@ -4872,8 +4869,9 @@ init (xlator_t *this) rpc = quota_enforcer_init (this, this->options); if (rpc == NULL) { ret = -1; - gf_log (this->name, GF_LOG_WARNING, - "quota enforcer rpc init failed"); + gf_msg (this->name, GF_LOG_WARNING, 0, + Q_MSG_QUOTA_ENFORCER_RPC_INIT_FAILED, + "quota enforcer rpc init failed"); goto err; } @@ -4917,8 +4915,9 @@ reconfigure (xlator_t *this, dict_t *options) this->options); if (priv->rpc_clnt == NULL) { ret = -1; - gf_log (this->name, GF_LOG_WARNING, - "quota enforcer rpc init failed"); + gf_msg (this->name, GF_LOG_WARNING, 0, + Q_MSG_QUOTA_ENFORCER_RPC_INIT_FAILED, + "quota enforcer rpc init failed"); goto out; } diff --git a/xlators/features/quota/src/quota.h b/xlators/features/quota/src/quota.h index 1d0db0d95da..0022089daa0 100644 --- a/xlators/features/quota/src/quota.h +++ b/xlators/features/quota/src/quota.h @@ -31,6 +31,7 @@ #include "compat-errno.h" #include "protocol-common.h" #include "quota-common-utils.h" +#include "quota-messages.h" #define DIRTY "dirty" #define SIZE "size" @@ -74,8 +75,9 @@ var = GF_CALLOC (sizeof (type), 1, \ gf_quota_mt_##type); \ if (!var) { \ - gf_log ("", GF_LOG_ERROR, \ - "out of memory"); \ + gf_msg ("", GF_LOG_ERROR, \ + ENOMEM, Q_MSG_ENOMEM, \ + "out of memory"); \ ret = -1; \ goto label; \ } \ diff --git a/xlators/features/quota/src/quotad-aggregator.c b/xlators/features/quota/src/quotad-aggregator.c index 6f2f6e8a7b0..6c9c40a122f 100644 --- a/xlators/features/quota/src/quotad-aggregator.c +++ b/xlators/features/quota/src/quotad-aggregator.c @@ -90,7 +90,8 @@ quotad_aggregator_submit_reply (call_frame_t *frame, rpcsvc_request_t *req, iob = quotad_serialize_reply (req, arg, &rsp, xdrproc); if (!iob) { - gf_log ("", GF_LOG_ERROR, "Failed to serialize reply"); + gf_msg ("", GF_LOG_ERROR, 0, Q_MSG_DICT_SERIALIZE_FAIL, + "Failed to serialize reply"); goto ret; } @@ -148,7 +149,9 @@ quotad_aggregator_getlimit_cbk (xlator_t *this, call_frame_t *frame, out: rsp->op_ret = ret; if (ret) { - gf_log (this->name, GF_LOG_ERROR, "failed to unserialize " + gf_msg (this->name, GF_LOG_ERROR, 0, + Q_MSG_DICT_UNSERIALIZE_FAIL, + "failed to unserialize " "nameless lookup rsp"); goto reply; } @@ -193,7 +196,8 @@ quotad_aggregator_getlimit (rpcsvc_request_t *req) ret = xdr_to_generic (req->msg[0], &cli_req, (xdrproc_t)xdr_gf_cli_req); if (ret < 0) { //failed to decode msg; - gf_log ("", GF_LOG_ERROR, "xdr decoding error"); + gf_msg ("this->name", GF_LOG_ERROR, 0, Q_MSG_XDR_DECODE_ERROR, + "xdr decoding error"); req->rpc_err = GARBAGE_ARGS; goto err; } @@ -203,8 +207,10 @@ quotad_aggregator_getlimit (rpcsvc_request_t *req) ret = dict_unserialize (cli_req.dict.dict_val, cli_req.dict.dict_len, &dict); if (ret < 0) { - gf_log (this->name, GF_LOG_ERROR, "Failed to " - "unserialize req-buffer to dictionary"); + gf_msg (this->name, GF_LOG_ERROR, 0, + Q_MSG_DICT_UNSERIALIZE_FAIL, + "Failed to unserialize req-buffer to " + "dictionary"); goto err; } } @@ -230,8 +236,8 @@ quotad_aggregator_getlimit (rpcsvc_request_t *req) ret = dict_set_int32 (state->xdata, QUOTA_LIMIT_OBJECTS_KEY, 42); if (ret) { - gf_log (this->name, GF_LOG_ERROR, "Failed to set " - "QUOTA_LIMIT_OBJECTS_KEY"); + gf_msg (this->name, GF_LOG_ERROR, ENOMEM, Q_MSG_ENOMEM, + "Failed to set QUOTA_LIMIT_OBJECTS_KEY"); goto err; } @@ -384,7 +390,8 @@ quotad_aggregator_init (xlator_t *this) /* RPC related */ priv->rpcsvc = rpcsvc_init (this, this->ctx, this->options, 0); if (priv->rpcsvc == NULL) { - gf_log (this->name, GF_LOG_WARNING, + gf_msg (this->name, GF_LOG_WARNING, 0, + Q_MSG_RPCSVC_INIT_FAILED, "creation of rpcsvc failed"); ret = -1; goto out; @@ -393,7 +400,8 @@ quotad_aggregator_init (xlator_t *this) ret = rpcsvc_create_listeners (priv->rpcsvc, this->options, this->name); if (ret < 1) { - gf_log (this->name, GF_LOG_WARNING, + gf_msg (this->name, GF_LOG_WARNING, 0, + Q_MSG_RPCSVC_LISTENER_CREATION_FAILED, "creation of listener failed"); ret = -1; goto out; @@ -404,7 +412,8 @@ quotad_aggregator_init (xlator_t *this) ret = rpcsvc_program_register (priv->rpcsvc, "ad_aggregator_prog); if (ret) { - gf_log (this->name, GF_LOG_WARNING, + gf_msg (this->name, GF_LOG_WARNING, 0, + Q_MSG_RPCSVC_REGISTER_FAILED, "registration of program (name:%s, prognum:%d, " "progver:%d) failed", quotad_aggregator_prog.progname, quotad_aggregator_prog.prognum, |