Blob Blame History Raw
From 28802dc69d4b2110ae6a74d67356669d4e104157 Mon Sep 17 00:00:00 2001
From: Nandaja Varma <nandaja.varma@gmail.com>
Date: Thu, 30 Apr 2015 16:57:00 +0530
Subject: [PATCH 092/101] quota/glusterd: porting to new logging framework

Change-Id: I879a181b6d6b97119a6b4fab90a12b8386635383
BUG: 1231771
Signed-off-by: Nandaja Varma <nvarma@redhat.com>
Reviewed-on: https://code.engineering.redhat.com/gerrit/50910
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
Tested-by: Atin Mukherjee <amukherj@redhat.com>
---
 xlators/mgmt/glusterd/src/glusterd-quota.c |  159 +++++++++++++++++-----------
 1 files changed, 97 insertions(+), 62 deletions(-)

diff --git a/xlators/mgmt/glusterd/src/glusterd-quota.c b/xlators/mgmt/glusterd/src/glusterd-quota.c
index 7238032..f4fc831 100644
--- a/xlators/mgmt/glusterd/src/glusterd-quota.c
+++ b/xlators/mgmt/glusterd/src/glusterd-quota.c
@@ -22,6 +22,7 @@
 #include "glusterd-nfs-svc.h"
 #include "glusterd-quotad-svc.h"
 #include "glusterd-volgen.h"
+#include "glusterd-messages.h"
 #include "run.h"
 #include "syscall.h"
 #include "byte-order.h"
@@ -142,7 +143,8 @@ __glusterd_handle_quota (rpcsvc_request_t *req)
                                         cli_req.dict.dict_len,
                                         &dict);
                 if (ret < 0) {
-                        gf_log (this->name, GF_LOG_ERROR, "failed to "
+                        gf_msg (this->name, GF_LOG_ERROR, 0,
+                                GD_MSG_DICT_UNSERIALIZE_FAIL, "failed to "
                                     "unserialize req-buffer to dictionary");
                         snprintf (msg, sizeof (msg), "Unable to decode the "
                                   "command");
@@ -155,7 +157,8 @@ __glusterd_handle_quota (rpcsvc_request_t *req)
         ret = dict_get_str (dict, "volname", &volname);
         if (ret) {
                 snprintf (msg, sizeof (msg), "Unable to get volume name");
-                gf_log (this->name, GF_LOG_ERROR, "Unable to get volume name, "
+                gf_msg (this->name, GF_LOG_ERROR, 0,
+                        GD_MSG_DICT_GET_FAILED, "Unable to get volume name, "
                         "while handling quota command");
                 goto out;
         }
@@ -163,7 +166,8 @@ __glusterd_handle_quota (rpcsvc_request_t *req)
         ret = dict_get_int32 (dict, "type", &type);
         if (ret) {
                 snprintf (msg, sizeof (msg), "Unable to get type of command");
-                gf_log (this->name, GF_LOG_ERROR, "Unable to get type of cmd, "
+                gf_msg (this->name, GF_LOG_ERROR, 0,
+                        GD_MSG_DICT_GET_FAILED, "Unable to get type of cmd, "
                         "while handling quota command");
                 goto out;
         }
@@ -204,7 +208,9 @@ glusterd_check_if_quota_trans_enabled (glusterd_volinfo_t *volinfo)
 
         flag = glusterd_volinfo_get_boolean (volinfo, VKEY_FEATURES_QUOTA);
         if (flag == -1) {
-                gf_log ("", GF_LOG_ERROR, "failed to get the quota status");
+                gf_msg ("glusterd", GF_LOG_ERROR, 0,
+                        GD_MSG_QUOTA_GET_STAT_FAIL,
+                        "failed to get the quota status");
                 ret = -1;
                 goto out;
         }
@@ -230,7 +236,7 @@ glusterd_quota_initiate_fs_crawl (glusterd_conf_t *priv, char *volname,
         runner_t                   runner            = {0};
 
         if (mkdtemp (mountdir) == NULL) {
-                gf_log ("glusterd", GF_LOG_DEBUG,
+                gf_msg_debug ("glusterd", 0,
                         "failed to create a temporary mount directory");
                 ret = -1;
                 goto out;
@@ -257,7 +263,8 @@ glusterd_quota_initiate_fs_crawl (glusterd_conf_t *priv, char *volname,
         runner_end (&runner);
 
         if ((pid = fork ()) < 0) {
-                gf_log ("glusterd", GF_LOG_WARNING, "fork from parent failed");
+                gf_msg ("glusterd", GF_LOG_WARNING, 0,
+                        GD_MSG_FORK_FAIL, "fork from parent failed");
                 ret = -1;
                 goto out;
         } else if (pid == 0) {//first child
@@ -270,8 +277,9 @@ glusterd_quota_initiate_fs_crawl (glusterd_conf_t *priv, char *volname,
 
                 ret = chdir (mountdir);
                 if (ret == -1) {
-                        gf_log ("glusterd", GF_LOG_WARNING, "chdir %s failed, "
-                                "reason: %s", mountdir, strerror (errno));
+                        gf_msg ("glusterd", GF_LOG_WARNING, errno,
+                                GD_MSG_DIR_OP_FAILED, "chdir %s failed",
+                                mountdir);
                         exit (EXIT_FAILURE);
                 }
                 runinit (&runner);
@@ -348,7 +356,8 @@ glusterd_quota_get_default_soft_limit (glusterd_volinfo_t *volinfo,
 
         ret = dict_set_dynstr (rsp_dict, "default-soft-limit", val);
         if (ret) {
-                gf_log (this->name, GF_LOG_ERROR, "Failed to set default "
+                gf_msg (this->name, GF_LOG_ERROR, 0,
+                        GD_MSG_DICT_SET_FAILED, "Failed to set default "
                         "soft-limit into dict");
                 goto out;
         }
@@ -445,14 +454,16 @@ glusterd_quota_enable (glusterd_volinfo_t *volinfo, char **op_errstr,
         ret = dict_set_dynstr_with_alloc (volinfo->dict, VKEY_FEATURES_QUOTA,
                                           "on");
         if (ret) {
-                gf_log (this->name, GF_LOG_ERROR, "dict set failed");
+                gf_msg (this->name, GF_LOG_ERROR, errno,
+                        GD_MSG_DICT_SET_FAILED, "dict set failed");
                 goto out;
         }
 
         ret = dict_set_dynstr_with_alloc (volinfo->dict,
                                           VKEY_FEATURES_INODE_QUOTA, "on");
         if (ret) {
-                gf_log (this->name, GF_LOG_ERROR, "dict set failed");
+                gf_msg (this->name, GF_LOG_ERROR, 0,
+                        GD_MSG_DICT_SET_FAILED, "dict set failed");
                 goto out;
         }
 
@@ -512,23 +523,25 @@ glusterd_quota_disable (glusterd_volinfo_t *volinfo, char **op_errstr,
         ret = dict_set_dynstr_with_alloc (volinfo->dict, VKEY_FEATURES_QUOTA,
                                           "off");
         if (ret) {
-                gf_log (this->name, GF_LOG_ERROR, "dict set failed");
+                gf_msg (this->name, GF_LOG_ERROR, errno,
+                        GD_MSG_DICT_SET_FAILED, "dict set failed");
                 goto out;
         }
 
         ret = dict_set_dynstr_with_alloc (volinfo->dict,
                                           VKEY_FEATURES_INODE_QUOTA, "off");
         if (ret) {
-                gf_log (this->name, GF_LOG_ERROR, "dict set failed");
+                gf_msg (this->name, GF_LOG_ERROR, 0,
+                        GD_MSG_DICT_SET_FAILED, "dict set failed");
                 goto out;
         }
 
         for (i = 0; quota_options [i]; i++) {
                 ret = glusterd_volinfo_get (volinfo, quota_options[i], &value);
                 if (ret) {
-                        gf_log (this->name, GF_LOG_INFO, "failed to get option"
-                                                         " %s",
-                                                         quota_options[i]);
+                        gf_msg (this->name, GF_LOG_INFO, 0,
+                                GD_MSG_VOLINFO_GET_FAIL, "failed to get option"
+                                " %s", quota_options[i]);
                 } else {
                 dict_del (volinfo->dict, quota_options[i]);
                 }
@@ -755,16 +768,17 @@ glusterd_copy_to_tmp_file (int src_fd, int dst_fd)
 
         while ((bytes_read = read (src_fd, (void *)&buf, entry_sz)) > 0) {
                 if (bytes_read % 16 != 0) {
-                        gf_log (this->name, GF_LOG_ERROR, "quota.conf "
+                        gf_msg (this->name, GF_LOG_ERROR, 0,
+                                GD_MSG_QUOTA_CONF_CORRUPT, "quota.conf "
                                 "corrupted");
                         ret = -1;
                         goto out;
                 }
                 ret = write (dst_fd, (void *) buf, bytes_read);
                 if (ret == -1) {
-                        gf_log (this->name, GF_LOG_ERROR,
-                                "write into quota.conf failed. Reason : %s",
-                                strerror (errno));
+                        gf_msg (this->name, GF_LOG_ERROR, errno,
+                                GD_MSG_QUOTA_CONF_WRITE_FAIL,
+                                "write into quota.conf failed.");
                         goto out;
                 }
         }
@@ -958,7 +972,8 @@ glusterd_store_quota_config (glusterd_volinfo_t *volinfo, char *path,
                         break;
                 }
                 if ((bytes_read % quota_conf_line_sz) != 0) {
-                        gf_log (this->name, GF_LOG_ERROR, "quota.conf "
+                        gf_msg (this->name, GF_LOG_ERROR, 0,
+                                GD_MSG_QUOTA_CONF_CORRUPT, "quota.conf "
                                 "corrupted");
                         ret = -1;
                         goto out;
@@ -968,9 +983,9 @@ glusterd_store_quota_config (glusterd_volinfo_t *volinfo, char *path,
 
                 ret = write (fd, (void *) buf, bytes_to_write);
                 if (ret == -1) {
-                        gf_log (this->name, GF_LOG_ERROR,
-                                "write into quota.conf failed. Reason : %s",
-                                strerror (errno));
+                        gf_msg (this->name, GF_LOG_ERROR, errno,
+                                GD_MSG_QUOTA_CONF_WRITE_FAIL,
+                                "write into quota.conf failed.");
                         goto out;
                 }
 
@@ -993,10 +1008,9 @@ glusterd_store_quota_config (glusterd_volinfo_t *volinfo, char *path,
                         ret = glusterd_quota_conf_write_gfid (fd, gfid,
                                                      GF_QUOTA_CONF_TYPE_USAGE);
                         if (ret == -1) {
-                                gf_log (this->name, GF_LOG_ERROR,
-                                        "write into quota.conf failed. "
-                                        "Reason : %s",
-                                        strerror (errno));
+                                gf_msg (this->name, GF_LOG_ERROR, errno,
+                                        GD_MSG_QUOTA_CONF_WRITE_FAIL,
+                                        "write into quota.conf failed. ");
                                 goto out;
                         }
                         modified = _gf_true;
@@ -1007,10 +1021,9 @@ glusterd_store_quota_config (glusterd_volinfo_t *volinfo, char *path,
                         ret = glusterd_quota_conf_write_gfid (fd, gfid,
                                                    GF_QUOTA_CONF_TYPE_OBJECTS);
                         if (ret == -1) {
-                                gf_log (this->name, GF_LOG_ERROR,
-                                        "write into quota.conf failed. "
-                                        "Reason : %s",
-                                        strerror (errno));
+                                gf_msg (this->name, GF_LOG_ERROR, errno,
+                                        GD_MSG_QUOTA_CONF_WRITE_FAIL,
+                                        "write into quota.conf failed. ");
                                 goto out;
                         }
                         modified = _gf_true;
@@ -1060,7 +1073,8 @@ out:
                 if (modified) {
                         ret = glusterd_compute_cksum (volinfo, _gf_true);
                         if (ret) {
-                                gf_log (this->name, GF_LOG_ERROR, "Failed to "
+                                gf_msg (this->name, GF_LOG_ERROR, 0,
+                                        GD_MSG_CKSUM_COMPUTE_FAIL, "Failed to "
                                         "compute cksum for quota conf file");
                                 return ret;
                         }
@@ -1068,7 +1082,9 @@ out:
                         ret = glusterd_store_save_quota_version_and_cksum
                                                                       (volinfo);
                         if (ret)
-                                gf_log (this->name, GF_LOG_ERROR, "Failed to "
+                                gf_msg (this->name, GF_LOG_ERROR, 0,
+                                        GD_MSG_VERS_CKSUM_STORE_FAIL,
+                                        "Failed to "
                                         "store quota version and cksum");
                 }
         }
@@ -1103,7 +1119,8 @@ glusterd_quota_limit_usage (glusterd_volinfo_t *volinfo, dict_t *dict,
 
         ret = dict_get_str (dict, "path", &path);
         if (ret) {
-                gf_log (this->name, GF_LOG_ERROR, "Unable to fetch path");
+                gf_msg (this->name, GF_LOG_ERROR, 0,
+                        GD_MSG_DICT_GET_FAILED, "Unable to fetch path");
                 goto out;
         }
         ret = gf_canonicalize_path (path);
@@ -1112,14 +1129,16 @@ glusterd_quota_limit_usage (glusterd_volinfo_t *volinfo, dict_t *dict,
 
         ret = dict_get_str (dict, "hard-limit", &hard_limit);
         if (ret) {
-                gf_log (this->name, GF_LOG_ERROR, "Unable to fetch hard limit");
+                gf_msg (this->name, GF_LOG_ERROR, 0,
+                        GD_MSG_DICT_GET_FAILED, "Unable to fetch hard limit");
                 goto out;
         }
 
         if (dict_get (dict, "soft-limit")) {
                 ret = dict_get_str (dict, "soft-limit", &soft_limit);
                 if (ret) {
-                        gf_log (this->name, GF_LOG_ERROR, "Unable to fetch "
+                        gf_msg (this->name, GF_LOG_ERROR, 0,
+                                GD_MSG_DICT_GET_FAILED, "Unable to fetch "
                                 "soft limit");
                         goto out;
                 }
@@ -1143,7 +1162,8 @@ glusterd_quota_limit_usage (glusterd_volinfo_t *volinfo, dict_t *dict,
 
         ret = dict_get_str (dict, "gfid", &gfid_str);
         if (ret) {
-                gf_log (this->name, GF_LOG_ERROR, "Failed to get gfid of path "
+                gf_msg (this->name, GF_LOG_ERROR, 0,
+                        GD_MSG_DICT_GET_FAILED, "Failed to get gfid of path "
                         "%s", path);
                 goto out;
         }
@@ -1234,7 +1254,8 @@ glusterd_quota_remove_limits (glusterd_volinfo_t *volinfo, dict_t *dict,
 
         ret = dict_get_str (dict, "path", &path);
         if (ret) {
-                gf_log (this->name, GF_LOG_ERROR, "Unable to fetch path");
+                gf_msg (this->name, GF_LOG_ERROR, 0,
+                        GD_MSG_DICT_GET_FAILED, "Unable to fetch path");
                 goto out;
         }
 
@@ -1251,7 +1272,8 @@ glusterd_quota_remove_limits (glusterd_volinfo_t *volinfo, dict_t *dict,
 
         ret = dict_get_str (dict, "gfid", &gfid_str);
         if (ret) {
-                gf_log (this->name, GF_LOG_ERROR, "Failed to get gfid of path "
+                gf_msg (this->name, GF_LOG_ERROR, 0,
+                        GD_MSG_DICT_GET_FAILED, "Failed to get gfid of path "
                         "%s", path);
                 goto out;
         }
@@ -1289,14 +1311,16 @@ glusterd_set_quota_option (glusterd_volinfo_t *volinfo, dict_t *dict,
 
         ret = dict_get_str (dict, "value", &value);
         if(ret) {
-                gf_log (this->name, GF_LOG_ERROR, "Option value absent.");
+                gf_msg (this->name, GF_LOG_ERROR, 0,
+                        GD_MSG_DICT_GET_FAILED, "Option value absent.");
                 return -1;
         }
 
         option = gf_strdup (value);
         ret = dict_set_dynstr (volinfo->dict, key, option);
         if(ret) {
-                gf_log (this->name, GF_LOG_ERROR, "Failed to set option %s",
+                gf_msg (this->name, GF_LOG_ERROR, 0,
+                        GD_MSG_DICT_GET_FAILED, "Failed to set option %s",
                         key);
                 return -1;
         }
@@ -1358,7 +1382,8 @@ glusterd_op_quota (dict_t *dict, char **op_errstr, dict_t *rsp_dict)
 
         ret = dict_get_str (dict, "volname", &volname);
         if (ret) {
-                gf_log (this->name, GF_LOG_ERROR, "Unable to get volume name");
+                gf_msg (this->name, GF_LOG_ERROR, 0,
+                        GD_MSG_DICT_GET_FAILED, "Unable to get volume name");
                 goto out;
         }
 
@@ -1469,7 +1494,8 @@ glusterd_op_quota (dict_t *dict, char **op_errstr, dict_t *rsp_dict)
 
         ret = glusterd_create_volfiles_and_notify_services (volinfo);
         if (ret) {
-                gf_log (this->name, GF_LOG_ERROR, "Unable to re-create "
+                gf_msg (this->name, GF_LOG_ERROR, 0,
+                        GD_MSG_VOLFILE_CREATE_FAIL, "Unable to re-create "
                                                   "volfiles");
                 ret = -1;
                 goto out;
@@ -1520,14 +1546,16 @@ glusterd_get_gfid_from_brick (dict_t *dict, glusterd_volinfo_t *volinfo,
 
         ret = dict_get_str (dict, "path", &path);
         if (ret) {
-                gf_log (this->name, GF_LOG_ERROR, "Failed to get path");
+                gf_msg (this->name, GF_LOG_ERROR, 0,
+                        GD_MSG_DICT_GET_FAILED, "Failed to get path");
                 goto out;
         }
 
         cds_list_for_each_entry (brickinfo, &volinfo->bricks, brick_list) {
                 ret = glusterd_resolve_brick (brickinfo);
                 if (ret) {
-                        gf_log (this->name, GF_LOG_ERROR, FMTSTR_RESOLVE_BRICK,
+                        gf_msg (this->name, GF_LOG_ERROR, 0,
+                                GD_MSG_RESOLVE_BRICK_FAIL, FMTSTR_RESOLVE_BRICK,
                                 brickinfo->hostname, brickinfo->path);
                         goto out;
                 }
@@ -1543,18 +1571,18 @@ glusterd_get_gfid_from_brick (dict_t *dict, glusterd_volinfo_t *volinfo,
 
                 ret = gf_lstat_dir (backend_path, NULL);
                 if (ret) {
-                        gf_log (this->name, GF_LOG_INFO, "Failed to find "
-                                "directory %s. Reason : %s", backend_path,
-                                strerror (errno));
+                        gf_msg (this->name, GF_LOG_INFO, errno,
+                                GD_MSG_DIR_OP_FAILED, "Failed to find "
+                                "directory %s.", backend_path);
                         ret = 0;
                         continue;
                 }
                 ret = sys_lgetxattr (backend_path, GFID_XATTR_KEY, gfid, 16);
                 if (ret < 0) {
-                        gf_log (this->name, GF_LOG_INFO, "Failed to get "
-                                "extended attribute %s for directory %s. "
-                                "Reason : %s", GFID_XATTR_KEY, backend_path,
-                                     strerror (errno));
+                        gf_msg (this->name, GF_LOG_INFO, errno,
+                                GD_MSG_SETXATTR_FAIL, "Failed to get "
+                                "extended attribute %s for directory %s. ",
+                                GFID_XATTR_KEY, backend_path);
                         ret = 0;
                         continue;
                 }
@@ -1568,7 +1596,8 @@ glusterd_get_gfid_from_brick (dict_t *dict, glusterd_volinfo_t *volinfo,
 
                 ret = dict_set_dynstr (rsp_dict, key, gfid_str);
                 if (ret) {
-                        gf_log (this->name, GF_LOG_ERROR, "Failed to place "
+                        gf_msg (this->name, GF_LOG_ERROR, 0,
+                                GD_MSG_DICT_SET_FAILED, "Failed to place "
                                 "gfid of %s in dict", backend_path);
                         GF_FREE (gfid_str);
                         goto out;
@@ -1578,7 +1607,8 @@ glusterd_get_gfid_from_brick (dict_t *dict, glusterd_volinfo_t *volinfo,
 
         ret = dict_set_int32 (rsp_dict, "count", count);
         if (ret) {
-                gf_log (this->name, GF_LOG_ERROR, "Failed to set count");
+                gf_msg (this->name, GF_LOG_ERROR, 0,
+                        GD_MSG_DICT_SET_FAILED, "Failed to set count");
                 goto out;
         }
 
@@ -1620,12 +1650,14 @@ _glusterd_validate_quota_opts (dict_t *dict, int type, char **errstr)
         opt = xlator_volume_option_get_list (&opt_list, key);
         if (!opt) {
                 ret = -1;
-                gf_log (this->name, GF_LOG_ERROR, "Unknown option: %s", key);
+                gf_msg (this->name, GF_LOG_ERROR, EINVAL,
+                        GD_MSG_UNKNOWN_KEY, "Unknown option: %s", key);
                 goto out;
         }
         ret = dict_get_str (dict, "value", &value);
         if (ret) {
-                gf_log (this->name, GF_LOG_ERROR, "Value not found for key %s",
+                gf_msg (this->name, GF_LOG_ERROR, 0,
+                        GD_MSG_DICT_GET_FAILED, "Value not found for key %s",
                         key);
                 goto out;
         }
@@ -1664,7 +1696,8 @@ glusterd_op_stage_quota (dict_t *dict, char **op_errstr, dict_t *rsp_dict)
 
         ret = dict_get_str (dict, "volname", &volname);
         if (ret) {
-                gf_log (this->name, GF_LOG_ERROR, "Unable to get volume name");
+                gf_msg (this->name, GF_LOG_ERROR, 0,
+                        GD_MSG_DICT_GET_FAILED, "Unable to get volume name");
                 goto out;
         }
 
@@ -1742,7 +1775,8 @@ glusterd_op_stage_quota (dict_t *dict, char **op_errstr, dict_t *rsp_dict)
         case GF_QUOTA_OPTION_TYPE_LIMIT_USAGE:
                 ret = dict_get_str (dict, "hard-limit", &hard_limit_str);
                 if (ret) {
-                        gf_log (this->name, GF_LOG_ERROR,
+                        gf_msg (this->name, GF_LOG_ERROR, 0,
+                                GD_MSG_DICT_GET_FAILED,
                                 "Faild to get hard-limit from dict");
                         goto out;
                 }
@@ -1753,9 +1787,10 @@ glusterd_op_stage_quota (dict_t *dict, char **op_errstr, dict_t *rsp_dict)
                                         "value out of range (0 - %"PRId64
                                         "): %s", hard_limit_str);
                         else
-                                gf_log (this->name, GF_LOG_ERROR,
+                                gf_msg (this->name, GF_LOG_ERROR, errno,
+                                        GD_MSG_CONVERSION_FAILED,
                                         "Failed to convert hard-limit "
-                                        "from string to bytes");
+                                        "string to value");
                         goto out;
                 }
                 get_gfid = _gf_true;
@@ -1794,7 +1829,7 @@ glusterd_op_stage_quota (dict_t *dict, char **op_errstr, dict_t *rsp_dict)
  out:
         if (ret && op_errstr && *op_errstr)
                 gf_log (this->name, GF_LOG_ERROR, "%s", *op_errstr);
-        gf_log (this->name, GF_LOG_DEBUG, "Returning %d", ret);
+        gf_msg_debug (this->name, 0, "Returning %d", ret);
 
          return ret;
 }
-- 
1.7.1