summaryrefslogtreecommitdiffstats
path: root/libglusterfs/src/latency.c
blob: b22f729500c58944de0cb1ed8a633568faffb7e1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
/*
  Copyright (c) 2008-2012 Red Hat, Inc. <http://www.redhat.com>
  This file is part of GlusterFS.

  This file is licensed to you under your choice of the GNU Lesser
  General Public License, version 3 or any later version (LGPLv3 or
  later), or the GNU General Public License, version 2 (GPLv2), in all
  cases as published by the Free Software Foundation.
*/


/*
 * This file contains functions to support dumping of
 * latencies of FOPs broken down by subvolumes.
 */

#include "glusterfs.h"
#include "stack.h"
#include "xlator.h"
#include "common-utils.h"
#include "statedump.h"


void
gf_set_fop_from_fn_pointer (call_frame_t *frame, struct xlator_fops *fops, void *fn)
{
        glusterfs_fop_t fop = -1;

        if (fops->stat == *(fop_stat_t *)&fn)
                fop = GF_FOP_STAT;
        else if (fops->readlink == *(fop_readlink_t *)&fn)
                fop = GF_FOP_READLINK;
        else if (fops->mknod == *(fop_mknod_t *)&fn)
                fop = GF_FOP_MKNOD;
        else if (fops->mkdir == *(fop_mkdir_t *)&fn)
                fop = GF_FOP_MKDIR;
        else if (fops->unlink == *(fop_unlink_t *)&fn)
                fop = GF_FOP_UNLINK;
        else if (fops->rmdir == *(fop_rmdir_t *)&fn)
                fop = GF_FOP_RMDIR;
        else if (fops->symlink == *(fop_symlink_t *)&fn)
                fop = GF_FOP_SYMLINK;
        else if (fops->rename == *(fop_rename_t *)&fn)
                fop = GF_FOP_RENAME;
        else if (fops->link == *(fop_link_t *)&fn)
                fop = GF_FOP_LINK;
        else if (fops->truncate == *(fop_truncate_t *)&fn)
                fop = GF_FOP_TRUNCATE;
        else if (fops->open == *(fop_open_t *)&fn)
                fop = GF_FOP_OPEN;
        else if (fops->readv == *(fop_readv_t *)&fn)
                fop = GF_FOP_READ;
        else if (fops->writev == *(fop_writev_t *)&fn)
                fop = GF_FOP_WRITE;
        else if (fops->statfs == *(fop_statfs_t *)&fn)
                fop = GF_FOP_STATFS;
        else if (fops->flush == *(fop_flush_t *)&fn)
                fop = GF_FOP_FLUSH;
        else if (fops->fsync == *(fop_fsync_t *)&fn)
                fop = GF_FOP_FSYNC;
        else if (fops->setxattr == *(fop_setxattr_t *)&fn)
                fop = GF_FOP_SETXATTR;
        else if (fops->getxattr == *(fop_getxattr_t *)&fn)
                fop = GF_FOP_GETXATTR;
        else if (fops->removexattr == *(fop_removexattr_t *)&fn)
                fop = GF_FOP_REMOVEXATTR;
        else if (fops->opendir == *(fop_opendir_t *)&fn)
                fop = GF_FOP_OPENDIR;
        else if (fops->fsyncdir == *(fop_fsyncdir_t *)&fn)
                fop = GF_FOP_FSYNCDIR;
        else if (fops->access == *(fop_access_t *)&fn)
                fop = GF_FOP_ACCESS;
        else if (fops->create == *(fop_create_t *)&fn)
                fop = GF_FOP_CREATE;
        else if (fops->ftruncate == *(fop_ftruncate_t *)&fn)
                fop = GF_FOP_FTRUNCATE;
        else if (fops->fstat == *(fop_fstat_t *)&fn)
                fop = GF_FOP_FSTAT;
        else if (fops->lk == *(fop_lk_t *)&fn)
                fop = GF_FOP_LK;
        else if (fops->lookup == *(fop_lookup_t *)&fn)
                fop = GF_FOP_LOOKUP;
        else if (fops->readdir == *(fop_readdir_t *)&fn)
                fop = GF_FOP_READDIR;
        else if (fops->inodelk == *(fop_inodelk_t *)&fn)
                fop = GF_FOP_INODELK;
        else if (fops->finodelk == *(fop_finodelk_t *)&fn)
                fop = GF_FOP_FINODELK;
        else if (fops->entrylk == *(fop_entrylk_t *)&fn)
                fop = GF_FOP_ENTRYLK;
        else if (fops->fentrylk == *(fop_fentrylk_t *)&fn)
                fop = GF_FOP_FENTRYLK;
        else if (fops->xattrop == *(fop_xattrop_t *)&fn)
                fop = GF_FOP_XATTROP;
        else if (fops->fxattrop == *(fop_fxattrop_t *)&fn)
                fop = GF_FOP_FXATTROP;
        else if (fops->fgetxattr == *(fop_fgetxattr_t *)&fn)
                fop = GF_FOP_FGETXATTR;
        else if (fops->fsetxattr == *(fop_fsetxattr_t *)&fn)
                fop = GF_FOP_FSETXATTR;
        else if (fops->rchecksum == *(fop_rchecksum_t *)&fn)
                fop = GF_FOP_RCHECKSUM;
        else if (fops->setattr == *(fop_setattr_t *)&fn)
                fop = GF_FOP_SETATTR;
        else if (fops->fsetattr == *(fop_fsetattr_t *)&fn)
                fop = GF_FOP_FSETATTR;
        else if (fops->readdirp == *(fop_readdirp_t *)&fn)
                fop = GF_FOP_READDIRP;
        else if (fops->getspec == *(fop_getspec_t *)&fn)
                fop = GF_FOP_GETSPEC;
        else
                fop = -1;

        frame->op   = fop;
}


void
gf_update_latency (call_frame_t *frame)
{
        double elapsed;
        struct timeval *begin, *end;

        fop_latency_t *lat;

        begin = &frame->begin;
        end   = &frame->end;

        elapsed = (end->tv_sec - begin->tv_sec) * 1e6
                + (end->tv_usec - begin->tv_usec);

        lat = &frame->this->latencies[frame->op];

        lat->total += elapsed;
        lat->count++;
        lat->mean = lat->mean + (elapsed - lat->mean) / lat->count;
}

void
gf_latency_begin (call_frame_t *frame, void *fn)
{
        gf_set_fop_from_fn_pointer (frame, frame->this->fops, fn);

        gettimeofday (&frame->begin, NULL);
}


void
gf_latency_end (call_frame_t *frame)
{
        gettimeofday (&frame->end, NULL);

        gf_update_latency (frame);
}

void
gf_proc_dump_latency_info (xlator_t *xl)
{
        char key_prefix[GF_DUMP_MAX_BUF_LEN];
        char key[GF_DUMP_MAX_BUF_LEN];
        int i;

        snprintf (key_prefix, GF_DUMP_MAX_BUF_LEN, "%s.latency", xl->name);
        gf_proc_dump_add_section (key_prefix);

        for (i = 0; i < GF_FOP_MAXVALUE; i++) {
                gf_proc_dump_build_key (key, key_prefix,
                                        (char *)gf_fop_list[i]);

                gf_proc_dump_write (key, "%.03f,%"PRId64",%.03f",
                                    xl->latencies[i].mean,
                                    xl->latencies[i].count,
                                    xl->latencies[i].total);
        }

        memset (xl->latencies, 0, sizeof (xl->latencies));
}


void
gf_latency_toggle (int signum, glusterfs_ctx_t *ctx)
{
        if (ctx) {
                ctx->measure_latency = !ctx->measure_latency;
                gf_log ("[core]", GF_LOG_INFO,
                        "Latency measurement turned %s",
                        ctx->measure_latency ? "on" : "off");
        }
}
div>
afr_local_t *local = NULL;
int child_index = (long) cookie;
int call_count = -1;
+ afr_private_t *priv = NULL;
+ priv = this->private;
local = frame->local;
LOCK (&frame->lock);
@@ -249,8 +251,13 @@ __afr_dir_write_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
if (call_count == 0) {
__afr_dir_write_finalize (frame, this);
- if (afr_txn_nothing_failed (frame, this))
- local->transaction.unwind (frame, this);
+ if (afr_txn_nothing_failed (frame, this)) {
+ /*if it did pre-op, it will do post-op changing ctime*/
+ if (priv->consistent_metadata &&
+ afr_needs_changelog_update (local))
+ afr_zero_fill_stat (local);
+ local->transaction.unwind (frame, this);
+ }
afr_mark_entry_pending_changelog (frame, this);
diff --git a/xlators/cluster/afr/src/afr-inode-write.c b/xlators/cluster/afr/src/afr-inode-write.c
index f240b5eec39..36889429657 100644
--- a/xlators/cluster/afr/src/afr-inode-write.c
+++ b/xlators/cluster/afr/src/afr-inode-write.c
@@ -182,7 +182,9 @@ __afr_inode_write_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
afr_local_t *local = NULL;
int child_index = (long) cookie;
int call_count = -1;
+ afr_private_t *priv = NULL;
+ priv = this->private;
local = frame->local;
LOCK (&frame->lock);
@@ -198,8 +200,13 @@ __afr_inode_write_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
if (call_count == 0) {
__afr_inode_write_finalize (frame, this);
- if (afr_txn_nothing_failed (frame, this))
- local->transaction.unwind (frame, this);
+ if (afr_txn_nothing_failed (frame, this)) {
+ /*if it did pre-op, it will do post-op changing ctime*/
+ if (priv->consistent_metadata &&
+ afr_needs_changelog_update (local))
+ afr_zero_fill_stat (local);
+ local->transaction.unwind (frame, this);
+ }
local->transaction.resume (frame, this);
}
@@ -230,8 +237,13 @@ void
afr_writev_unwind (call_frame_t *frame, xlator_t *this)
{
afr_local_t * local = NULL;
+ afr_private_t *priv = this->private;
+
local = frame->local;
+ if (priv->consistent_metadata)
+ afr_zero_fill_stat (local);
+
AFR_STACK_UNWIND (writev, frame,
local->op_ret, local->op_errno,
&local->cont.inode_wfop.prebuf,
diff --git a/xlators/cluster/afr/src/afr-transaction.c b/xlators/cluster/afr/src/afr-transaction.c
index 2acac027122..6fd44ce79f6 100644
--- a/xlators/cluster/afr/src/afr-transaction.c
+++ b/xlators/cluster/afr/src/afr-transaction.c
@@ -36,6 +36,37 @@ afr_changelog_do (call_frame_t *frame, xlator_t *this, dict_t *xattr,
afr_changelog_resume_t changelog_resume,
afr_xattrop_type_t op);
+void
+afr_zero_fill_stat (afr_local_t *local)
+{
+ if (!local)
+ return;
+ if (local->transaction.type == AFR_DATA_TRANSACTION ||
+ local->transaction.type == AFR_METADATA_TRANSACTION) {
+ gf_zero_fill_stat (&local->cont.inode_wfop.prebuf);
+ gf_zero_fill_stat (&local->cont.inode_wfop.postbuf);
+ } else if (local->transaction.type == AFR_ENTRY_TRANSACTION ||
+ local->transaction.type == AFR_ENTRY_RENAME_TRANSACTION) {
+ gf_zero_fill_stat (&local->cont.dir_fop.buf);
+ gf_zero_fill_stat (&local->cont.dir_fop.preparent);
+ gf_zero_fill_stat (&local->cont.dir_fop.postparent);
+ if (local->transaction.type == AFR_ENTRY_TRANSACTION)
+ return;
+ gf_zero_fill_stat (&local->cont.dir_fop.prenewparent);
+ gf_zero_fill_stat (&local->cont.dir_fop.postnewparent);
+ }
+}
+
+gf_boolean_t
+afr_needs_changelog_update (afr_local_t *local)
+{
+ if (local->transaction.type == AFR_DATA_TRANSACTION)
+ return _gf_true;
+ if (!local->optimistic_change_log)
+ return _gf_true;
+ return _gf_false;
+}
+
static int32_t
afr_quorum_errno (afr_private_t *priv)
{
@@ -85,9 +116,21 @@ int
__afr_txn_write_done (call_frame_t *frame, xlator_t *this)
{
afr_local_t *local = NULL;
+ afr_private_t *priv = NULL;
+ gf_boolean_t unwind = _gf_false;
+ priv = this->private;
local = frame->local;
+ if (priv->consistent_metadata) {
+ LOCK (&frame->lock);
+ {
+ unwind = (local->transaction.main_frame != NULL);
+ }
+ UNLOCK (&frame->lock);
+ if (unwind)/*It definitely did post-op*/
+ afr_zero_fill_stat (local);
+ }
local->transaction.unwind (frame, this);
AFR_STACK_DESTROY (frame);
@@ -1232,8 +1275,7 @@ afr_changelog_pre_op (call_frame_t *frame, xlator_t *this)
goto err;
}
- if ((local->transaction.type == AFR_DATA_TRANSACTION ||
- !local->optimistic_change_log)) {
+ if (afr_needs_changelog_update (local)) {
local->dirty[idx] = hton32(1);
diff --git a/xlators/cluster/afr/src/afr-transaction.h b/xlators/cluster/afr/src/afr-transaction.h
index 47d43d88991..c58531eff44 100644
--- a/xlators/cluster/afr/src/afr-transaction.h
+++ b/xlators/cluster/afr/src/afr-transaction.h
@@ -52,5 +52,7 @@ int __afr_txn_write_fop (call_frame_t *frame, xlator_t *this);
int __afr_txn_write_done (call_frame_t *frame, xlator_t *this);
call_frame_t *afr_transaction_detach_fop_frame (call_frame_t *frame);
gf_boolean_t afr_has_quorum (unsigned char *subvols, xlator_t *this);
+gf_boolean_t afr_needs_changelog_update (afr_local_t *local);
+void afr_zero_fill_stat (afr_local_t *local);
#endif /* __TRANSACTION_H__ */
diff --git a/xlators/nfs/server/src/nfs-common.c b/xlators/nfs/server/src/nfs-common.c
index 51a2b7e36f7..d9ea1e1ac47 100644
--- a/xlators/nfs/server/src/nfs-common.c
+++ b/xlators/nfs/server/src/nfs-common.c
@@ -106,25 +106,6 @@ nfs_mntpath_to_xlator (xlator_list_t *cl, char *path)
}
-/* Returns 1 if the stat seems to be filled with zeroes. */
-int
-nfs_zero_filled_stat (struct iatt *buf)
-{
- if (!buf)
- return 1;
-
- /* Do not use st_dev because it is transformed to store the xlator id
- * in place of the device number. Do not use st_ino because by this time
- * we've already mapped the root ino to 1 so it is not guaranteed to be
- * 0.
- */
- if ((buf->ia_nlink == 0) && (buf->ia_ctime == 0))
- return 1;
-
- return 0;
-}
-
-
void
nfs_loc_wipe (loc_t *loc)
{
diff --git a/xlators/nfs/server/src/nfs-common.h b/xlators/nfs/server/src/nfs-common.h
index fa7f4ebf212..77bdfb0bbf0 100644
--- a/xlators/nfs/server/src/nfs-common.h
+++ b/xlators/nfs/server/src/nfs-common.h
@@ -37,9 +37,6 @@ nfs_path_to_xlator (xlator_list_t *cl, char *path);
extern xlator_t *
nfs_mntpath_to_xlator (xlator_list_t *cl, char *path);
-extern int
-nfs_zero_filled_stat (struct iatt *buf);
-
extern void
nfs_loc_wipe (loc_t *loc);
diff --git a/xlators/nfs/server/src/nfs3-helpers.c b/xlators/nfs/server/src/nfs3-helpers.c
index 7eb491142f7..ad4c87e69d7 100644
--- a/xlators/nfs/server/src/nfs3-helpers.c
+++ b/xlators/nfs/server/src/nfs3-helpers.c
@@ -373,7 +373,7 @@ nfs3_stat_to_post_op_attr (struct iatt *buf)
* returning these zeroed out attrs.
*/
attr.attributes_follow = FALSE;
- if (nfs_zero_filled_stat (buf))
+ if (gf_is_zero_filled_stat (buf))
goto out;
nfs3_stat_to_fattr3 (buf, &(attr.post_op_attr_u.attributes));
@@ -394,7 +394,7 @@ nfs3_stat_to_pre_op_attr (struct iatt *pre)
* returning these zeroed out attrs.
*/
poa.attributes_follow = FALSE;
- if (nfs_zero_filled_stat (pre))
+ if (gf_is_zero_filled_stat (pre))
goto out;
poa.attributes_follow = TRUE;