Blob Blame History Raw
From 42ddc22edb25c9666d01bd81b421d931f4a0d558 Mon Sep 17 00:00:00 2001
From: Kotresh HR <khiremat@redhat.com>
Date: Thu, 25 Aug 2016 22:20:30 +0530
Subject: [PATCH 24/86] glusterd: Improve mountbroker logs

When Mountbroker mount fails, it was just returning
EPERM or EACCESS without logging exact failure.
This patch improves the logging by logging exact
failure.

>Change-Id: I3cd905f95865153f70dfcc3bf1fa4dd19af16455
>BUG: 1346138
>Signed-off-by: Kotresh HR <khiremat@redhat.com>
>Reviewed-on: http://review.gluster.org/15319
>Smoke: Gluster Build System <jenkins@build.gluster.org>
>CentOS-regression: Gluster Build System <jenkins@build.gluster.org>
>NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org>
>Reviewed-by: Atin Mukherjee <amukherj@redhat.com>

Change-Id: I3cd905f95865153f70dfcc3bf1fa4dd19af16455
BUG: 1359607
Signed-off-by: Kotresh HR <khiremat@redhat.com>
Reviewed-on: https://code.engineering.redhat.com/gerrit/84661
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
Tested-by: Atin Mukherjee <amukherj@redhat.com>
---
 xlators/mgmt/glusterd/src/glusterd-messages.h    |   34 +++++++++++++-
 xlators/mgmt/glusterd/src/glusterd-mountbroker.c |   56 ++++++++++++++++++++--
 2 files changed, 84 insertions(+), 6 deletions(-)

diff --git a/xlators/mgmt/glusterd/src/glusterd-messages.h b/xlators/mgmt/glusterd/src/glusterd-messages.h
index 623f4dc..2c76dbf 100644
--- a/xlators/mgmt/glusterd/src/glusterd-messages.h
+++ b/xlators/mgmt/glusterd/src/glusterd-messages.h
@@ -41,7 +41,7 @@
 
 #define GLUSTERD_COMP_BASE      GLFS_MSGID_GLUSTERD
 
-#define GLFS_NUM_MESSAGES       579
+#define GLFS_NUM_MESSAGES       583
 
 #define GLFS_MSGID_END          (GLUSTERD_COMP_BASE + GLFS_NUM_MESSAGES + 1)
 /* Messaged with message IDs */
@@ -4681,6 +4681,38 @@
  */
 #define GD_MSG_PMAP_REGISTRY_REMOVE_FAIL          (GLUSTERD_COMP_BASE + 579)
 
+/*!
+ * @messageid
+ * @diagnosis
+ * @recommendedaction
+ *
+ */
+#define GD_MSG_MNTBROKER_LABEL_NULL                (GLUSTERD_COMP_BASE + 580)
+
+/*!
+ * @messageid
+ * @diagnosis
+ * @recommendedaction
+ *
+ */
+#define GD_MSG_MNTBROKER_LABEL_MISS                (GLUSTERD_COMP_BASE + 581)
+
+/*!
+ * @messageid
+ * @diagnosis
+ * @recommendedaction
+ *
+ */
+#define GD_MSG_MNTBROKER_SPEC_MISMATCH            (GLUSTERD_COMP_BASE + 582)
+
+/*!
+ * @messageid
+ * @diagnosis
+ * @recommendedaction
+ *
+ */
+#define GD_MSG_SYSCALL_FAIL                          (GLUSTERD_COMP_BASE + 583)
+
 /*------------*/
 #define glfs_msg_end_x GLFS_MSGID_END, "Invalid: End of messages"
 #endif /* !_GLUSTERD_MESSAGES_H_ */
diff --git a/xlators/mgmt/glusterd/src/glusterd-mountbroker.c b/xlators/mgmt/glusterd/src/glusterd-mountbroker.c
index 7c069ce..f992adc 100644
--- a/xlators/mgmt/glusterd/src/glusterd-mountbroker.c
+++ b/xlators/mgmt/glusterd/src/glusterd-mountbroker.c
@@ -447,7 +447,7 @@ _arg_parse_uid (char *val, void *data)
 }
 
 static int
-evaluate_mount_request (gf_mount_spec_t *mspec, dict_t *argdict)
+evaluate_mount_request (xlator_t *this, gf_mount_spec_t *mspec, dict_t *argdict)
 {
         struct gf_set_descriptor sd = {{0,},};
         int i                       = 0;
@@ -476,8 +476,14 @@ evaluate_mount_request (gf_mount_spec_t *mspec, dict_t *argdict)
                 if (mspec->patterns[i].negative)
                         match = !match;
 
-                if (!match)
+                if (!match) {
+                        gf_msg (this->name, GF_LOG_ERROR, EPERM,
+                                GD_MSG_MNTBROKER_SPEC_MISMATCH,
+                                "Mountbroker spec mismatch!!! SET: %d "
+                                "COMPONENT: %d. Review the mount args passed",
+                                 mspec->patterns[i].condition, i);
                         return -EPERM;
+                }
         }
 
         ret = seq_dict_foreach (argdict, _arg_parse_uid, &uid);
@@ -526,6 +532,7 @@ glusterd_do_mount (char *label, dict_t *argdict, char **path, int *op_errno)
         int ret                    = 0;
         xlator_t *this             = THIS;
         mode_t orig_umask          = 0;
+        gf_boolean_t found_label   = _gf_false;
 
         priv = this->private;
         GF_ASSERT (priv);
@@ -536,12 +543,19 @@ glusterd_do_mount (char *label, dict_t *argdict, char **path, int *op_errno)
         if (dict_get_str (this->options, "mountbroker-root",
                           &mountbroker_root) != 0) {
                 *op_errno = ENOENT;
+                gf_msg (this->name, GF_LOG_ERROR, 0,
+                        GD_MSG_DICT_GET_FAILED, "'option mountbroker-root' "
+                        "missing in glusterd vol file");
                 goto out;
         }
 
         GF_ASSERT (label);
         if (!*label) {
                 *op_errno = EINVAL;
+                gf_msg (this->name, GF_LOG_ERROR, *op_errno,
+                        GD_MSG_MNTBROKER_LABEL_MISS,
+                        "label is NULL (%s)",
+                        strerror (*op_errno));
                 goto out;
         }
 
@@ -550,11 +564,20 @@ glusterd_do_mount (char *label, dict_t *argdict, char **path, int *op_errno)
                                  speclist) {
                 if (strcmp (mspec->label, label) != 0)
                         continue;
-                uid = evaluate_mount_request (mspec, argdict);
+
+                found_label = _gf_true;
+                uid = evaluate_mount_request (this, mspec, argdict);
                 break;
         }
         if (uid < 0) {
                 *op_errno = -uid;
+                if (!found_label) {
+                        gf_msg (this->name, GF_LOG_ERROR, *op_errno,
+                                GD_MSG_MNTBROKER_LABEL_MISS,
+                                "Missing mspec: Check the corresponding option "
+                                "in glusterd vol file for mountbroker user: %s",
+                                 label);
+                }
                 goto out;
         }
 
@@ -562,11 +585,17 @@ glusterd_do_mount (char *label, dict_t *argdict, char **path, int *op_errno)
         seq_dict_foreach (argdict, _volname_get, &volname);
         if (!volname) {
                 *op_errno = EINVAL;
+                gf_msg (this->name, GF_LOG_ERROR, EINVAL,
+                        GD_MSG_DICT_GET_FAILED,
+                        "Dict get failed for the key 'volname'");
                 goto out;
         }
         if (glusterd_volinfo_find (volname, &vol) != 0 ||
             !glusterd_is_volume_started (vol)) {
                 *op_errno = ENOENT;
+                gf_msg (this->name, GF_LOG_ERROR, *op_errno,
+                        GD_MSG_MOUNT_REQ_FAIL,
+                        "Either volume is not started or volinfo not found");
                 goto out;
         }
 
@@ -596,22 +625,34 @@ glusterd_do_mount (char *label, dict_t *argdict, char **path, int *op_errno)
                 ret = 0;
         if (ret == -1) {
                 *op_errno = errno;
+                gf_msg (this->name, GF_LOG_ERROR, *op_errno,
+                        GD_MSG_SYSCALL_FAIL,
+                        "Mountbroker User directory creation failed");
                 goto out;
         }
         ret = sys_lstat (mtptemp, &st);
         if (ret == -1) {
                 *op_errno = errno;
+                gf_msg (this->name, GF_LOG_ERROR, *op_errno,
+                        GD_MSG_SYSCALL_FAIL,
+                        "stat on mountbroker user directory failed");
                 goto out;
         }
         if (!(S_ISDIR (st.st_mode) && (st.st_mode & ~S_IFMT) == 0700 &&
               st.st_uid == uid && st.st_gid == 0)) {
                 *op_errno = EACCES;
+                gf_msg (this->name, GF_LOG_ERROR, *op_errno,
+                        GD_MSG_MOUNT_REQ_FAIL,
+                        "Incorrect mountbroker user directory attributes");
                 goto out;
         }
         *sla = '/';
 
         if (!mkdtemp (mtptemp)) {
                 *op_errno = errno;
+                gf_msg (this->name, GF_LOG_ERROR, *op_errno,
+                        GD_MSG_SYSCALL_FAIL,
+                        "Mountbroker mount directory creation failed");
                 goto out;
         }
 
@@ -630,6 +671,9 @@ glusterd_do_mount (char *label, dict_t *argdict, char **path, int *op_errno)
         umask(orig_umask);
         if (ret == -1) {
                 *op_errno = errno;
+                gf_msg (this->name, GF_LOG_ERROR, *op_errno,
+                        GD_MSG_SYSCALL_FAIL,
+                        "Mountbroker cookie file creation failed");
                 goto out;
         }
         sys_close (ret);
@@ -652,6 +696,9 @@ glusterd_do_mount (char *label, dict_t *argdict, char **path, int *op_errno)
         *cookieswitch = '\0';
         if (ret == -1) {
                 *op_errno = errno;
+                gf_msg (this->name, GF_LOG_ERROR, *op_errno,
+                        GD_MSG_SYSCALL_FAIL,
+                        "symlink or rename failed");
                 goto out;
         }
 
@@ -674,8 +721,7 @@ glusterd_do_mount (char *label, dict_t *argdict, char **path, int *op_errno)
                 ret = -1;
                 gf_msg (this->name, GF_LOG_WARNING, *op_errno,
                         GD_MSG_MOUNT_REQ_FAIL,
-                        "unsuccessful mount request (%s)",
-                        strerror (*op_errno));
+                        "unsuccessful mount request");
                 if (mtptemp) {
                         *cookieswitch = '/';
                         sys_unlink (mtptemp);
-- 
1.7.1