3604df
From 42ddc22edb25c9666d01bd81b421d931f4a0d558 Mon Sep 17 00:00:00 2001
3604df
From: Kotresh HR <khiremat@redhat.com>
3604df
Date: Thu, 25 Aug 2016 22:20:30 +0530
3604df
Subject: [PATCH 24/86] glusterd: Improve mountbroker logs
3604df
3604df
When Mountbroker mount fails, it was just returning
3604df
EPERM or EACCESS without logging exact failure.
3604df
This patch improves the logging by logging exact
3604df
failure.
3604df
3604df
>Change-Id: I3cd905f95865153f70dfcc3bf1fa4dd19af16455
3604df
>BUG: 1346138
3604df
>Signed-off-by: Kotresh HR <khiremat@redhat.com>
3604df
>Reviewed-on: http://review.gluster.org/15319
3604df
>Smoke: Gluster Build System <jenkins@build.gluster.org>
3604df
>CentOS-regression: Gluster Build System <jenkins@build.gluster.org>
3604df
>NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org>
3604df
>Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
3604df
3604df
Change-Id: I3cd905f95865153f70dfcc3bf1fa4dd19af16455
3604df
BUG: 1359607
3604df
Signed-off-by: Kotresh HR <khiremat@redhat.com>
3604df
Reviewed-on: https://code.engineering.redhat.com/gerrit/84661
3604df
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
3604df
Tested-by: Atin Mukherjee <amukherj@redhat.com>
3604df
---
3604df
 xlators/mgmt/glusterd/src/glusterd-messages.h    |   34 +++++++++++++-
3604df
 xlators/mgmt/glusterd/src/glusterd-mountbroker.c |   56 ++++++++++++++++++++--
3604df
 2 files changed, 84 insertions(+), 6 deletions(-)
3604df
3604df
diff --git a/xlators/mgmt/glusterd/src/glusterd-messages.h b/xlators/mgmt/glusterd/src/glusterd-messages.h
3604df
index 623f4dc..2c76dbf 100644
3604df
--- a/xlators/mgmt/glusterd/src/glusterd-messages.h
3604df
+++ b/xlators/mgmt/glusterd/src/glusterd-messages.h
3604df
@@ -41,7 +41,7 @@
3604df
 
3604df
 #define GLUSTERD_COMP_BASE      GLFS_MSGID_GLUSTERD
3604df
 
3604df
-#define GLFS_NUM_MESSAGES       579
3604df
+#define GLFS_NUM_MESSAGES       583
3604df
 
3604df
 #define GLFS_MSGID_END          (GLUSTERD_COMP_BASE + GLFS_NUM_MESSAGES + 1)
3604df
 /* Messaged with message IDs */
3604df
@@ -4681,6 +4681,38 @@
3604df
  */
3604df
 #define GD_MSG_PMAP_REGISTRY_REMOVE_FAIL          (GLUSTERD_COMP_BASE + 579)
3604df
 
3604df
+/*!
3604df
+ * @messageid
3604df
+ * @diagnosis
3604df
+ * @recommendedaction
3604df
+ *
3604df
+ */
3604df
+#define GD_MSG_MNTBROKER_LABEL_NULL                (GLUSTERD_COMP_BASE + 580)
3604df
+
3604df
+/*!
3604df
+ * @messageid
3604df
+ * @diagnosis
3604df
+ * @recommendedaction
3604df
+ *
3604df
+ */
3604df
+#define GD_MSG_MNTBROKER_LABEL_MISS                (GLUSTERD_COMP_BASE + 581)
3604df
+
3604df
+/*!
3604df
+ * @messageid
3604df
+ * @diagnosis
3604df
+ * @recommendedaction
3604df
+ *
3604df
+ */
3604df
+#define GD_MSG_MNTBROKER_SPEC_MISMATCH            (GLUSTERD_COMP_BASE + 582)
3604df
+
3604df
+/*!
3604df
+ * @messageid
3604df
+ * @diagnosis
3604df
+ * @recommendedaction
3604df
+ *
3604df
+ */
3604df
+#define GD_MSG_SYSCALL_FAIL                          (GLUSTERD_COMP_BASE + 583)
3604df
+
3604df
 /*------------*/
3604df
 #define glfs_msg_end_x GLFS_MSGID_END, "Invalid: End of messages"
3604df
 #endif /* !_GLUSTERD_MESSAGES_H_ */
3604df
diff --git a/xlators/mgmt/glusterd/src/glusterd-mountbroker.c b/xlators/mgmt/glusterd/src/glusterd-mountbroker.c
3604df
index 7c069ce..f992adc 100644
3604df
--- a/xlators/mgmt/glusterd/src/glusterd-mountbroker.c
3604df
+++ b/xlators/mgmt/glusterd/src/glusterd-mountbroker.c
3604df
@@ -447,7 +447,7 @@ _arg_parse_uid (char *val, void *data)
3604df
 }
3604df
 
3604df
 static int
3604df
-evaluate_mount_request (gf_mount_spec_t *mspec, dict_t *argdict)
3604df
+evaluate_mount_request (xlator_t *this, gf_mount_spec_t *mspec, dict_t *argdict)
3604df
 {
3604df
         struct gf_set_descriptor sd = {{0,},};
3604df
         int i                       = 0;
3604df
@@ -476,8 +476,14 @@ evaluate_mount_request (gf_mount_spec_t *mspec, dict_t *argdict)
3604df
                 if (mspec->patterns[i].negative)
3604df
                         match = !match;
3604df
 
3604df
-                if (!match)
3604df
+                if (!match) {
3604df
+                        gf_msg (this->name, GF_LOG_ERROR, EPERM,
3604df
+                                GD_MSG_MNTBROKER_SPEC_MISMATCH,
3604df
+                                "Mountbroker spec mismatch!!! SET: %d "
3604df
+                                "COMPONENT: %d. Review the mount args passed",
3604df
+                                 mspec->patterns[i].condition, i);
3604df
                         return -EPERM;
3604df
+                }
3604df
         }
3604df
 
3604df
         ret = seq_dict_foreach (argdict, _arg_parse_uid, &uid);
3604df
@@ -526,6 +532,7 @@ glusterd_do_mount (char *label, dict_t *argdict, char **path, int *op_errno)
3604df
         int ret                    = 0;
3604df
         xlator_t *this             = THIS;
3604df
         mode_t orig_umask          = 0;
3604df
+        gf_boolean_t found_label   = _gf_false;
3604df
 
3604df
         priv = this->private;
3604df
         GF_ASSERT (priv);
3604df
@@ -536,12 +543,19 @@ glusterd_do_mount (char *label, dict_t *argdict, char **path, int *op_errno)
3604df
         if (dict_get_str (this->options, "mountbroker-root",
3604df
                           &mountbroker_root) != 0) {
3604df
                 *op_errno = ENOENT;
3604df
+                gf_msg (this->name, GF_LOG_ERROR, 0,
3604df
+                        GD_MSG_DICT_GET_FAILED, "'option mountbroker-root' "
3604df
+                        "missing in glusterd vol file");
3604df
                 goto out;
3604df
         }
3604df
 
3604df
         GF_ASSERT (label);
3604df
         if (!*label) {
3604df
                 *op_errno = EINVAL;
3604df
+                gf_msg (this->name, GF_LOG_ERROR, *op_errno,
3604df
+                        GD_MSG_MNTBROKER_LABEL_MISS,
3604df
+                        "label is NULL (%s)",
3604df
+                        strerror (*op_errno));
3604df
                 goto out;
3604df
         }
3604df
 
3604df
@@ -550,11 +564,20 @@ glusterd_do_mount (char *label, dict_t *argdict, char **path, int *op_errno)
3604df
                                  speclist) {
3604df
                 if (strcmp (mspec->label, label) != 0)
3604df
                         continue;
3604df
-                uid = evaluate_mount_request (mspec, argdict);
3604df
+
3604df
+                found_label = _gf_true;
3604df
+                uid = evaluate_mount_request (this, mspec, argdict);
3604df
                 break;
3604df
         }
3604df
         if (uid < 0) {
3604df
                 *op_errno = -uid;
3604df
+                if (!found_label) {
3604df
+                        gf_msg (this->name, GF_LOG_ERROR, *op_errno,
3604df
+                                GD_MSG_MNTBROKER_LABEL_MISS,
3604df
+                                "Missing mspec: Check the corresponding option "
3604df
+                                "in glusterd vol file for mountbroker user: %s",
3604df
+                                 label);
3604df
+                }
3604df
                 goto out;
3604df
         }
3604df
 
3604df
@@ -562,11 +585,17 @@ glusterd_do_mount (char *label, dict_t *argdict, char **path, int *op_errno)
3604df
         seq_dict_foreach (argdict, _volname_get, &volname);
3604df
         if (!volname) {
3604df
                 *op_errno = EINVAL;
3604df
+                gf_msg (this->name, GF_LOG_ERROR, EINVAL,
3604df
+                        GD_MSG_DICT_GET_FAILED,
3604df
+                        "Dict get failed for the key 'volname'");
3604df
                 goto out;
3604df
         }
3604df
         if (glusterd_volinfo_find (volname, &vol) != 0 ||
3604df
             !glusterd_is_volume_started (vol)) {
3604df
                 *op_errno = ENOENT;
3604df
+                gf_msg (this->name, GF_LOG_ERROR, *op_errno,
3604df
+                        GD_MSG_MOUNT_REQ_FAIL,
3604df
+                        "Either volume is not started or volinfo not found");
3604df
                 goto out;
3604df
         }
3604df
 
3604df
@@ -596,22 +625,34 @@ glusterd_do_mount (char *label, dict_t *argdict, char **path, int *op_errno)
3604df
                 ret = 0;
3604df
         if (ret == -1) {
3604df
                 *op_errno = errno;
3604df
+                gf_msg (this->name, GF_LOG_ERROR, *op_errno,
3604df
+                        GD_MSG_SYSCALL_FAIL,
3604df
+                        "Mountbroker User directory creation failed");
3604df
                 goto out;
3604df
         }
3604df
         ret = sys_lstat (mtptemp, &st);
3604df
         if (ret == -1) {
3604df
                 *op_errno = errno;
3604df
+                gf_msg (this->name, GF_LOG_ERROR, *op_errno,
3604df
+                        GD_MSG_SYSCALL_FAIL,
3604df
+                        "stat on mountbroker user directory failed");
3604df
                 goto out;
3604df
         }
3604df
         if (!(S_ISDIR (st.st_mode) && (st.st_mode & ~S_IFMT) == 0700 &&
3604df
               st.st_uid == uid && st.st_gid == 0)) {
3604df
                 *op_errno = EACCES;
3604df
+                gf_msg (this->name, GF_LOG_ERROR, *op_errno,
3604df
+                        GD_MSG_MOUNT_REQ_FAIL,
3604df
+                        "Incorrect mountbroker user directory attributes");
3604df
                 goto out;
3604df
         }
3604df
         *sla = '/';
3604df
 
3604df
         if (!mkdtemp (mtptemp)) {
3604df
                 *op_errno = errno;
3604df
+                gf_msg (this->name, GF_LOG_ERROR, *op_errno,
3604df
+                        GD_MSG_SYSCALL_FAIL,
3604df
+                        "Mountbroker mount directory creation failed");
3604df
                 goto out;
3604df
         }
3604df
 
3604df
@@ -630,6 +671,9 @@ glusterd_do_mount (char *label, dict_t *argdict, char **path, int *op_errno)
3604df
         umask(orig_umask);
3604df
         if (ret == -1) {
3604df
                 *op_errno = errno;
3604df
+                gf_msg (this->name, GF_LOG_ERROR, *op_errno,
3604df
+                        GD_MSG_SYSCALL_FAIL,
3604df
+                        "Mountbroker cookie file creation failed");
3604df
                 goto out;
3604df
         }
3604df
         sys_close (ret);
3604df
@@ -652,6 +696,9 @@ glusterd_do_mount (char *label, dict_t *argdict, char **path, int *op_errno)
3604df
         *cookieswitch = '\0';
3604df
         if (ret == -1) {
3604df
                 *op_errno = errno;
3604df
+                gf_msg (this->name, GF_LOG_ERROR, *op_errno,
3604df
+                        GD_MSG_SYSCALL_FAIL,
3604df
+                        "symlink or rename failed");
3604df
                 goto out;
3604df
         }
3604df
 
3604df
@@ -674,8 +721,7 @@ glusterd_do_mount (char *label, dict_t *argdict, char **path, int *op_errno)
3604df
                 ret = -1;
3604df
                 gf_msg (this->name, GF_LOG_WARNING, *op_errno,
3604df
                         GD_MSG_MOUNT_REQ_FAIL,
3604df
-                        "unsuccessful mount request (%s)",
3604df
-                        strerror (*op_errno));
3604df
+                        "unsuccessful mount request");
3604df
                 if (mtptemp) {
3604df
                         *cookieswitch = '/';
3604df
                         sys_unlink (mtptemp);
3604df
-- 
3604df
1.7.1
3604df