summaryrefslogtreecommitdiffstats
path: root/xlators/features/bit-rot/src/bitd/bit-rot-scrub.c
diff options
context:
space:
mode:
authorGaurav Kumar Garg <garg.gaurav52@gmail.com>2015-11-25 17:38:43 +0530
committerVenky Shankar <vshankar@redhat.com>2015-12-17 19:29:00 -0800
commit530533fe44f08f30d1230c65db0054be7c6d3281 (patch)
treef28c4122cb9a18d8fb55df6a91495987bbbda146 /xlators/features/bit-rot/src/bitd/bit-rot-scrub.c
parent459314829691e3cb0c31f4971111d7dadfb199d8 (diff)
bitrot: getting correct value of scrub stat's
This patch is backport of: http://review.gluster.org/#/c/12776/ When user execute bitrot scrub status command then gluster is not giving correct value of Number of Scrubbed files, Number of Unsigned files, Last completed scrub time, Duration of last scrub. With this patch scrub status will give correct value for all the above fields. >> Change-Id: Ic966f76d22db5b0c889e6386a1c2219afbda1f49 >> BUG: 1285989 >> Signed-off-by: Gaurav Kumar Garg <ggarg@redhat.com> >> Signed-off-by: Kotresh HR <khiremat@redhat.com> >> Reviewed-on: http://review.gluster.org/12776 >> Tested-by: NetBSD Build System <jenkins@build.gluster.org> >> Tested-by: Gluster Build System <jenkins@build.gluster.com> >> Reviewed-by: Venky Shankar <vshankar@redhat.com> Change-Id: Ic966f76d22db5b0c889e6386a1c2219afbda1f49 BUG: 1291546 Signed-off-by: Gaurav Kumar Garg <ggarg@redhat.com> (cherry picked from commit 22827d51c232c44a8f5ac003529d907d93baf7b0) Change-Id: Icef24cce35c8d54ffdfa5282491338318e78780b Reviewed-on: http://review.gluster.org/12966 Tested-by: Gluster Build System <jenkins@build.gluster.com> Tested-by: NetBSD Build System <jenkins@build.gluster.org> Reviewed-by: Venky Shankar <vshankar@redhat.com>
Diffstat (limited to 'xlators/features/bit-rot/src/bitd/bit-rot-scrub.c')
-rw-r--r--xlators/features/bit-rot/src/bitd/bit-rot-scrub.c137
1 files changed, 120 insertions, 17 deletions
diff --git a/xlators/features/bit-rot/src/bitd/bit-rot-scrub.c b/xlators/features/bit-rot/src/bitd/bit-rot-scrub.c
index 768b3bc98cd..9a9a9a6bb70 100644
--- a/xlators/features/bit-rot/src/bitd/bit-rot-scrub.c
+++ b/xlators/features/bit-rot/src/bitd/bit-rot-scrub.c
@@ -79,6 +79,20 @@ bitd_fetch_signature (xlator_t *this, br_child_t *child,
}
+static void
+br_inc_unsigned_file_count (xlator_t *this)
+{
+ br_private_t *priv = NULL;
+
+ priv = this->private;
+
+ pthread_mutex_lock (&priv->scrub_stat.lock);
+ {
+ priv->scrub_stat.unsigned_files++;
+ }
+ pthread_mutex_unlock (&priv->scrub_stat.lock);
+}
+
/**
* POST COMPUTE CHECK
*
@@ -112,6 +126,7 @@ bitd_scrub_post_compute_check (xlator_t *this,
* The log entry looks pretty ugly, but helps in debugging..
*/
if (signptr->stale || (signptr->version != version)) {
+ br_inc_unsigned_file_count (this);
gf_msg_debug (this->name, 0, "<STAGE: POST> Object [GFID: %s] "
"either has a stale signature OR underwent "
"signing during checksumming {Stale: %d | "
@@ -186,6 +201,7 @@ bitd_scrub_pre_compute_check (xlator_t *this, br_child_t *child,
ret = bitd_signature_staleness (this, child, fd, &stale, version);
if (!ret && stale) {
+ br_inc_unsigned_file_count (this);
gf_msg_debug (this->name, 0, "<STAGE: PRE> Object [GFID: %s] "
"has stale signature",
uuid_utoa (fd->inode->gfid));
@@ -258,6 +274,16 @@ bitd_compare_ckum (xlator_t *this,
return ret;
}
+static void
+br_inc_scrubbed_file (br_private_t *priv)
+{
+ pthread_mutex_lock (&priv->scrub_stat.lock);
+ {
+ priv->scrub_stat.scrubbed_files++;
+ }
+ pthread_mutex_unlock (&priv->scrub_stat.lock);
+}
+
/**
* "The Scrubber"
*
@@ -268,19 +294,20 @@ bitd_compare_ckum (xlator_t *this,
int
br_scrubber_scrub_begin (xlator_t *this, struct br_fsscan_entry *fsentry)
{
- int32_t ret = -1;
- fd_t *fd = NULL;
- loc_t loc = {0, };
- struct iatt iatt = {0, };
- struct iatt parent_buf = {0, };
- pid_t pid = 0;
- br_child_t *child = NULL;
- unsigned char *md = NULL;
- inode_t *linked_inode = NULL;
- br_isignature_out_t *sign = NULL;
- unsigned long signedversion = 0;
- gf_dirent_t *entry = NULL;
- loc_t *parent = NULL;
+ int32_t ret = -1;
+ fd_t *fd = NULL;
+ loc_t loc = {0, };
+ struct iatt iatt = {0, };
+ struct iatt parent_buf = {0, };
+ pid_t pid = 0;
+ br_child_t *child = NULL;
+ unsigned char *md = NULL;
+ inode_t *linked_inode = NULL;
+ br_isignature_out_t *sign = NULL;
+ unsigned long signedversion = 0;
+ gf_dirent_t *entry = NULL;
+ br_private_t *priv = NULL;
+ loc_t *parent = NULL;
GF_VALIDATE_OR_GOTO ("bit-rot", fsentry, out);
@@ -288,9 +315,12 @@ br_scrubber_scrub_begin (xlator_t *this, struct br_fsscan_entry *fsentry)
parent = &fsentry->parent;
child = fsentry->data;
+ priv = this->private;
+
GF_VALIDATE_OR_GOTO ("bit-rot", entry, out);
GF_VALIDATE_OR_GOTO ("bit-rot", parent, out);
GF_VALIDATE_OR_GOTO ("bit-rot", child, out);
+ GF_VALIDATE_OR_GOTO ("bit-rot", priv, out);
pid = GF_CLIENT_PID_SCRUB;
@@ -377,6 +407,9 @@ br_scrubber_scrub_begin (xlator_t *this, struct br_fsscan_entry *fsentry)
ret = bitd_compare_ckum (this, sign, md,
linked_inode, entry, fd, child, &loc);
+ /* Increment of total number of scrubbed file counter */
+ br_inc_scrubbed_file (priv);
+
GF_FREE (sign); /* alloced on post-compute */
/** fd_unref() takes care of closing fd.. like syncop_close() */
@@ -555,21 +588,72 @@ br_fsscan_deactivate (xlator_t *this, br_child_t *child)
return 0;
}
+static void
+br_update_scrub_start_time (xlator_t *this, struct timeval *tv)
+{
+ br_private_t *priv = NULL;
+ static int child;
+
+ priv = this->private;
+
+
+ /* Setting scrubber starting time for first child only */
+ if (child == 0) {
+ pthread_mutex_lock (&priv->scrub_stat.lock);
+ {
+ priv->scrub_stat.scrub_start_tv.tv_sec = tv->tv_sec;
+ }
+ pthread_mutex_unlock (&priv->scrub_stat.lock);
+ }
+
+ if (++child == priv->up_children) {
+ child = 0;
+ }
+}
+
+static void
+br_update_scrub_finish_time (xlator_t *this, char *timestr, struct timeval *tv)
+{
+ br_private_t *priv = NULL;
+ static int child;
+
+ priv = this->private;
+
+ /*Setting scrubber finishing time at time time of last child operation*/
+ if (++child == priv->up_children) {
+ pthread_mutex_lock (&priv->scrub_stat.lock);
+ {
+ priv->scrub_stat.scrub_end_tv.tv_sec = tv->tv_sec;
+
+ priv->scrub_stat.scrub_duration =
+ priv->scrub_stat.scrub_end_tv.tv_sec -
+ priv->scrub_stat.scrub_start_tv.tv_sec;
+
+ strncpy (priv->scrub_stat.last_scrub_time, timestr,
+ sizeof (priv->scrub_stat.last_scrub_time));
+
+ child = 0;
+ }
+ pthread_mutex_unlock (&priv->scrub_stat.lock);
+ }
+}
static inline void
br_fsscanner_log_time (xlator_t *this, br_child_t *child, const char *sfx)
{
- struct timeval tv = {0,};
- char timestr[1024] = {0,};
+ char timestr[1024] = {0,};
+ struct timeval tv = {0,};
gettimeofday (&tv, NULL);
gf_time_fmt (timestr, sizeof (timestr), tv.tv_sec, gf_timefmt_FT);
if (strcasecmp (sfx, "started") == 0) {
+ br_update_scrub_start_time (this, &tv);
gf_msg (this->name, GF_LOG_INFO, 0, BRB_MSG_SCRUB_START,
"Scrubbing \"%s\" %s at %s", child->brick_path, sfx,
timestr);
} else {
+ br_update_scrub_finish_time (this, timestr, &tv);
gf_msg (this->name, GF_LOG_INFO, 0, BRB_MSG_SCRUB_FINISH,
"Scrubbing \"%s\" %s at %s", child->brick_path, sfx,
timestr);
@@ -577,14 +661,33 @@ br_fsscanner_log_time (xlator_t *this, br_child_t *child, const char *sfx)
}
static void
-br_fsscanner_wait_until_kicked (struct br_scanfs *fsscan)
+br_fsscanner_wait_until_kicked (xlator_t *this, struct br_scanfs *fsscan)
{
+ static int i;
+ br_private_t *priv = NULL;
+
+ priv = this->private;
+
pthread_cleanup_push (_br_lock_cleaner, &fsscan->wakelock);
pthread_mutex_lock (&fsscan->wakelock);
{
while (!fsscan->kick)
pthread_cond_wait (&fsscan->wakecond,
&fsscan->wakelock);
+
+ /* resetting total number of scrubbed file when scrubbing
+ * done for all of its children */
+ if (i == priv->up_children) {
+ pthread_mutex_lock (&priv->scrub_stat.lock);
+ {
+ priv->scrub_stat.scrubbed_files = 0;
+ priv->scrub_stat.unsigned_files = 0;
+ i = 0;
+ }
+ pthread_mutex_unlock (&priv->scrub_stat.lock);
+ }
+ ++i;
+
fsscan->kick = _gf_false;
}
pthread_mutex_unlock (&fsscan->wakelock);
@@ -642,7 +745,7 @@ br_fsscanner (void *arg)
loc.inode = child->table->root;
while (1) {
- br_fsscanner_wait_until_kicked (fsscan);
+ br_fsscanner_wait_until_kicked (this, fsscan);
{
/* precursor for scrub */
br_fsscanner_entry_control (this, child);