Blob Blame History Raw
From c7aea7a5c2ddcc311cab8f7383d038d2caaf7d35 Mon Sep 17 00:00:00 2001
From: Pranith Kumar K <pkarampu@redhat.com>
Date: Wed, 7 Sep 2016 04:19:32 +0530
Subject: [PATCH 64/86] storage/posix: Integrate important events with gf_event

Patch on master: http://review.gluster.org/#/c/15342/
Patch on release-3.9: http://review.gluster.org/#/c/15497/

Change-Id: Icc23b22de02e45d2b0f8c6339ee628b439a4ffa8
BUG: 1361086
Signed-off-by: Pranith Kumar K <pkarampu@redhat.com>
Reviewed-on: https://code.engineering.redhat.com/gerrit/84803
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
Tested-by: Atin Mukherjee <amukherj@redhat.com>
---
 events/eventskeygen.py                    |    4 +-
 xlators/storage/posix/src/posix-helpers.c |   39 ++++++++-------
 xlators/storage/posix/src/posix.c         |   76 +++++++++++++++++++----------
 3 files changed, 73 insertions(+), 46 deletions(-)

diff --git a/events/eventskeygen.py b/events/eventskeygen.py
index 9906a26..02a9bdb 100644
--- a/events/eventskeygen.py
+++ b/events/eventskeygen.py
@@ -140,9 +140,9 @@ keys = (
     #posix events
     "EVENT_POSIX_SAME_GFID",
     "EVENT_POSIX_ALREADY_PART_OF_VOLUME",
-    "EVENT_POSIX_INVALID_BRICK",
+    "EVENT_POSIX_BRICK_NOT_IN_VOLUME",
     "EVENT_POSIX_BRICK_VERIFICATION_FAILED",
-    "EVENT_POSIX_ACL_NOTSUP",
+    "EVENT_POSIX_ACL_NOT_SUPPORTED",
     "EVENT_POSIX_HEALTH_CHECK_FAILED",
     #afr events
     "EVENT_AFR_QUORUM_MET",
diff --git a/xlators/storage/posix/src/posix-helpers.c b/xlators/storage/posix/src/posix-helpers.c
index f93e815..f52836f 100644
--- a/xlators/storage/posix/src/posix-helpers.c
+++ b/xlators/storage/posix/src/posix-helpers.c
@@ -31,6 +31,7 @@
 #include <alloca.h>
 #endif /* GF_BSD_HOST_OS */
 
+#include <fnmatch.h>
 #include "glusterfs.h"
 #include "checksum.h"
 #include "dict.h"
@@ -49,7 +50,7 @@
 #include "glusterfs3-xdr.h"
 #include "hashfn.h"
 #include "glusterfs-acl.h"
-#include <fnmatch.h>
+#include "events.h"
 
 char *marker_xattrs[] = {"trusted.glusterfs.quota.*",
                          "trusted.glusterfs.*.xtime",
@@ -1746,6 +1747,8 @@ posix_fs_health_check (xlator_t *this)
         time_t  time_sec                = {0,};
         char    buff[64]                = {0};
         char    file_path[PATH_MAX]     = {0};
+        char    *op                     = NULL;
+        int     op_errno                = 0;
 
         GF_VALIDATE_OR_GOTO (this->name, this, out);
         priv = this->private;
@@ -1761,16 +1764,14 @@ posix_fs_health_check (xlator_t *this)
 
         fd = open (file_path, O_CREAT|O_RDWR, 0644);
         if (fd == -1) {
-                gf_msg (this->name, GF_LOG_WARNING, errno,
-                        P_MSG_HEALTHCHECK_FAILED,
-                        "open() on %s returned", file_path);
+                op_errno = errno;
+                op = "open";
                 goto out;
         }
         nofbytes = sys_write (fd, timestamp, timelen);
-        if (nofbytes != timelen) {
-                gf_msg (this->name, GF_LOG_WARNING, errno,
-                        P_MSG_HEALTHCHECK_FAILED,
-                        "write() on %s returned", file_path);
+        if (nofbytes < 0) {
+                op_errno = errno;
+                op = "write";
                 goto out;
         }
         /* Seek the offset to the beginning of the file, so that the offset for
@@ -1778,9 +1779,8 @@ posix_fs_health_check (xlator_t *this)
         sys_lseek(fd, 0, SEEK_SET);
         nofbytes = sys_read (fd, buff, timelen);
         if (nofbytes == -1) {
-                gf_msg (this->name, GF_LOG_WARNING, errno,
-                        P_MSG_HEALTHCHECK_FAILED,
-                        "read() on %s returned", file_path);
+                op_errno = errno;
+                op = "read";
                 goto out;
         }
         ret = 0;
@@ -1788,6 +1788,14 @@ out:
         if (fd != -1) {
                 sys_close (fd);
         }
+        if (ret && file_path[0]) {
+                gf_msg (this->name, GF_LOG_WARNING, errno,
+                        P_MSG_HEALTHCHECK_FAILED,
+                        "%s() on %s returned", op, file_path);
+                gf_event (EVENT_POSIX_HEALTH_CHECK_FAILED,
+                          "op=%s;path=%s;error=%s;brick=%s:%s", op, file_path,
+                          op_errno, priv->hostname, priv->base_path);
+        }
         return ret;
 
 }
@@ -1823,14 +1831,8 @@ posix_health_check_thread_proc (void *data)
 
                 /* Do the health-check.*/
                 ret = posix_fs_health_check (this);
-
-                if (ret < 0) {
-                        gf_msg (this->name, GF_LOG_WARNING, errno,
-                                P_MSG_HEALTHCHECK_FAILED,
-                                "health_check on %s returned",
-                                priv->base_path);
+                if (ret < 0)
                         goto abort;
-                }
 
                 pthread_setcancelstate (PTHREAD_CANCEL_ENABLE, NULL);
         }
@@ -1850,6 +1852,7 @@ abort:
         /* health-check failed */
         gf_msg (this->name, GF_LOG_EMERG, 0, P_MSG_HEALTHCHECK_FAILED,
                 "health-check failed, going down");
+
         xlator_notify (this->parents->xlator, GF_EVENT_CHILD_DOWN, this);
 
         ret = sleep (30);
diff --git a/xlators/storage/posix/src/posix.c b/xlators/storage/posix/src/posix.c
index cecf5dc..2d9e3f6 100644
--- a/xlators/storage/posix/src/posix.c
+++ b/xlators/storage/posix/src/posix.c
@@ -56,6 +56,7 @@
 #include "posix-aio.h"
 #include "glusterfs-acl.h"
 #include "posix-messages.h"
+#include "events.h"
 
 extern char *marker_xattrs[];
 #define ALIGN_SIZE 4096
@@ -1485,6 +1486,12 @@ posix_mkdir (call_frame_t *frame, xlator_t *this,
                                 "and this can lead to inconsistencies.",
                                 loc->path, uuid_utoa (uuid_req),
                                 gfid_path ? gfid_path : "<NULL>");
+
+                        gf_event (EVENT_POSIX_SAME_GFID, "gfid=%s;path=%s;"
+                                  "newpath=%s;brick=%s:%s",
+                                  uuid_utoa (uuid_req),
+                                  gfid_path ? gfid_path : "<NULL>", loc->path,
+                                  priv->hostname, priv->base_path);
                 }
         } else if (!uuid_req && frame->root->pid != GF_SERVER_PID_TRASH) {
                 op_ret = -1;
@@ -6852,6 +6859,31 @@ init (xlator_t *this)
                 goto out;
         }
 
+        _private = GF_CALLOC (1, sizeof (*_private),
+                              gf_posix_mt_posix_private);
+        if (!_private) {
+                ret = -1;
+                goto out;
+        }
+
+        _private->base_path = gf_strdup (dir_data->data);
+        _private->base_path_length = strlen (_private->base_path);
+
+        ret = dict_get_str (this->options, "hostname", &_private->hostname);
+        if (ret) {
+                _private->hostname = GF_CALLOC (256, sizeof (char),
+                                                gf_common_mt_char);
+                if (!_private->hostname) {
+                        goto out;
+                }
+                ret = gethostname (_private->hostname, 256);
+                if (ret < 0) {
+                        gf_msg (this->name, GF_LOG_WARNING, errno,
+                                P_MSG_HOSTNAME_MISSING,
+                                "could not find hostname ");
+                }
+        }
+
         /* Check for Extended attribute support, if not present, log it */
         op_ret = sys_lsetxattr (dir_data->data,
                                 "trusted.glusterfs.test", "working", 8, 0);
@@ -6912,6 +6944,10 @@ init (xlator_t *this)
                                         "mismatching volume-id (%s) received. "
                                         "already is a part of volume %s ",
                                         tmp_data->data, uuid_utoa (old_uuid));
+                                gf_event (EVENT_POSIX_ALREADY_PART_OF_VOLUME,
+                                        "volume-id=%s;brick=%s:%s",
+                                        uuid_utoa (old_uuid),
+                                       _private->hostname, _private->base_path);
                                 ret = -1;
                                 goto out;
                         }
@@ -6921,12 +6957,18 @@ init (xlator_t *this)
                                         P_MSG_VOLUME_ID_ABSENT,
                                         "Extended attribute trusted.glusterfs."
                                         "volume-id is absent");
+                                gf_event (EVENT_POSIX_BRICK_NOT_IN_VOLUME,
+                                        "brick=%s:%s",
+                                       _private->hostname, _private->base_path);
                                 ret = -1;
                                 goto out;
 
                 }  else if ((size == -1) && (errno != ENODATA) &&
                             (errno != ENOATTR)) {
                         /* Wrong 'volume-id' is set, it should be error */
+                        gf_event (EVENT_POSIX_BRICK_VERIFICATION_FAILED,
+                                "brick=%s:%s",
+                                _private->hostname, _private->base_path);
                         gf_msg (this->name, GF_LOG_WARNING, errno,
                                 P_MSG_VOLUME_ID_FETCH_FAILED,
                                 "%s: failed to fetch volume-id",
@@ -6935,6 +6977,9 @@ init (xlator_t *this)
                         goto out;
                 } else {
                         ret = -1;
+                        gf_event (EVENT_POSIX_BRICK_VERIFICATION_FAILED,
+                                "brick=%s:%s",
+                                _private->hostname, _private->base_path);
                         gf_msg (this->name, GF_LOG_ERROR, 0,
                                 P_MSG_VOLUME_ID_FETCH_FAILED,
                                 "failed to fetch proper volume id from export");
@@ -6985,24 +7030,18 @@ init (xlator_t *this)
                 }
         }
 
+        ret = 0;
+
         size = sys_lgetxattr (dir_data->data, POSIX_ACL_ACCESS_XATTR,
                               NULL, 0);
-        if ((size < 0) && (errno == ENOTSUP))
+        if ((size < 0) && (errno == ENOTSUP)) {
                 gf_msg (this->name, GF_LOG_WARNING, errno,
                         P_MSG_ACL_NOTSUP,
                         "Posix access control list is not supported.");
-
-        ret = 0;
-        _private = GF_CALLOC (1, sizeof (*_private),
-                              gf_posix_mt_posix_private);
-        if (!_private) {
-                ret = -1;
-                goto out;
+                gf_event (EVENT_POSIX_ACL_NOT_SUPPORTED,
+                        "brick=%s:%s", _private->hostname, _private->base_path);
         }
 
-        _private->base_path = gf_strdup (dir_data->data);
-        _private->base_path_length = strlen (_private->base_path);
-
         /*
          * _XOPEN_PATH_MAX is the longest file path len we MUST
          * support according to POSIX standard. When prepended
@@ -7040,21 +7079,6 @@ init (xlator_t *this)
 
         LOCK_INIT (&_private->lock);
 
-        ret = dict_get_str (this->options, "hostname", &_private->hostname);
-        if (ret) {
-                _private->hostname = GF_CALLOC (256, sizeof (char),
-                                                gf_common_mt_char);
-                if (!_private->hostname) {
-                        goto out;
-                }
-                ret = gethostname (_private->hostname, 256);
-                if (ret < 0) {
-                        gf_msg (this->name, GF_LOG_WARNING, errno,
-                                P_MSG_HOSTNAME_MISSING,
-                                "could not find hostname ");
-                }
-        }
-
         _private->export_statfs = 1;
         tmp_data = dict_get (this->options, "export-statfs-size");
         if (tmp_data) {
-- 
1.7.1