summaryrefslogtreecommitdiffstats
path: root/libglusterfs/src/stack.c
blob: 0723557b36d9014034e2b5ce5a2ce7581b033a9c (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
/*
  Copyright (c) 2009 Gluster, Inc. <http://www.gluster.com>
  This file is part of GlusterFS.

  GlusterFS is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published
  by the Free Software Foundation; either version 3 of the License,
  or (at your option) any later version.

  GlusterFS is distributed in the hope that it will be useful, but
  WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program.  If not, see
  <http://www.gnu.org/licenses/>.
*/

#include "statedump.h"
#include "stack.h"

static inline
int call_frames_count (call_frame_t *call_frame) 
{
        call_frame_t *pos;
        int32_t count = 0;

        if (!call_frame)
                return count;

        for (pos = call_frame; pos != NULL; pos = pos->next)
                count++;

        return count;
}

void
gf_proc_dump_call_frame (call_frame_t *call_frame, const char *key_buf,...)
{
    
        char prefix[GF_DUMP_MAX_BUF_LEN];
        va_list ap;
        char key[GF_DUMP_MAX_BUF_LEN];
        call_frame_t my_frame;
        int  ret = -1;

        if (!call_frame)
                return;

        assert(key_buf);

        memset(prefix, 0, sizeof(prefix));
        memset(&my_frame, 0, sizeof(my_frame));
        va_start(ap, key_buf);
        vsnprintf(prefix, GF_DUMP_MAX_BUF_LEN, key_buf, ap); 
        va_end(ap);

        ret = TRY_LOCK(&call_frame->lock);
        if (ret) {
                gf_log("", GF_LOG_WARNING, "Unable to dump call frame"
                " errno: %d", errno);
                return;
        }

        memcpy(&my_frame, call_frame, sizeof(my_frame));
        UNLOCK(&call_frame->lock);

	gf_proc_dump_build_key(key, prefix,"ref_count");
        gf_proc_dump_write(key, "%d", my_frame.ref_count);
	gf_proc_dump_build_key(key, prefix,"translator");
        gf_proc_dump_write(key, "%s", my_frame.this->name);
	gf_proc_dump_build_key(key, prefix,"complete");
        gf_proc_dump_write(key, "%d", my_frame.complete);
        if (my_frame.parent) {
                gf_proc_dump_build_key(key, prefix,"parent");
                gf_proc_dump_write(key, "%s", my_frame.parent->this->name);
        }
}


void
gf_proc_dump_call_stack (call_stack_t *call_stack, const char *key_buf,...)
{
        char prefix[GF_DUMP_MAX_BUF_LEN];
        va_list ap;
        call_frame_t *trav;
        int32_t cnt, i;
        char key[GF_DUMP_MAX_BUF_LEN];

        if (!call_stack)
                return;

        assert(key_buf);

        cnt = call_frames_count(&call_stack->frames);

        memset(prefix, 0, sizeof(prefix));
        va_start(ap, key_buf);
        vsnprintf(prefix, GF_DUMP_MAX_BUF_LEN, key_buf, ap); 
        va_end(ap);

	gf_proc_dump_build_key(key, prefix,"uid");
        gf_proc_dump_write(key, "%d", call_stack->uid);
	gf_proc_dump_build_key(key, prefix,"gid");
        gf_proc_dump_write(key, "%d", call_stack->gid);
	gf_proc_dump_build_key(key, prefix,"pid");
        gf_proc_dump_write(key, "%d", call_stack->pid);
	gf_proc_dump_build_key(key, prefix,"unique");
        gf_proc_dump_write(key, "%Ld", call_stack->unique);

	gf_proc_dump_build_key(key, prefix,"op");
        if (call_stack->type == GF_OP_TYPE_FOP)
                gf_proc_dump_write(key, "%s", gf_fop_list[call_stack->op]);
        else if (call_stack->type == GF_OP_TYPE_MGMT)
                gf_proc_dump_write(key, "%s", gf_mgmt_list[call_stack->op]);

	gf_proc_dump_build_key(key, prefix,"type");
        gf_proc_dump_write(key, "%d", call_stack->type);
	gf_proc_dump_build_key(key, prefix,"cnt");
        gf_proc_dump_write(key, "%d", cnt);

        trav = &call_stack->frames;

        for (i = 1; i <= cnt; i++) {
                if (trav) {
                        gf_proc_dump_add_section("%s.frame.%d", prefix, i);
                        gf_proc_dump_call_frame(trav, "%s.frame.%d", prefix, i);
                        trav = trav->next; 
                }
        }
}

void
gf_proc_dump_pending_frames (call_pool_t *call_pool)
{
		
        call_stack_t     *trav = NULL;
        int              i = 1;
        int              ret = -1;

        if (!call_pool)
                return;

        ret = TRY_LOCK (&(call_pool->lock));
        if (ret) {
                gf_log("", GF_LOG_WARNING, "Unable to dump call pool"
                " errno: %d", errno);
                return;
        }

        
        gf_proc_dump_add_section("global.callpool");
        gf_proc_dump_write("global.callpool","%p", call_pool);
        gf_proc_dump_write("global.callpool.cnt","%d", call_pool->cnt);


        list_for_each_entry (trav, &call_pool->all_frames, all_frames) {
                gf_proc_dump_add_section("global.callpool.stack.%d",i);
                gf_proc_dump_call_stack(trav, "global.callpool.stack.%d", i);
                i++;
        }
	UNLOCK (&(call_pool->lock));
}

insertions'>+3 * rpc: implement server.manage-gids for group resolving on the bricksNiels de Vos2014-05-091-0/+5 * glusterd/snapshot : Clean up of old barrier code.Sachin Pandit2014-04-301-29/+0 * glusterd: Ping timer implmentationKrishnan Parthasarathi2014-04-291-2/+0 * gluster: GlusterFS Volume Snapshot FeatureAvra Sengupta2014-04-111-0/+30 * client_t: phase 2, refactor server_ctx and locks_ctx outKaleb S. KEITHLEY2013-10-311-5/+16 * libglusterfs: Add monotonic clocking counter for timer threadHarshavardhana2013-10-151-1/+1 * libglusterfs/client_t client_t implementation, phase 1Kaleb S. KEITHLEY2013-07-291-56/+1 * protocol/server: Change logs to give more info on disconnectsPranith Kumar K2013-05-311-1/+2 * license: xlators/protocol/server dual license GPLv2 and LGPLv3+Kaleb S. KEITHLEY2013-04-121-14/+5 * protocol/server: dump the ltable and fd table related inodes onlyRaghavendra Bhat2012-09-171-1/+2 * rpc: variable name changesAmar Tumballi2012-07-121-1/+1 * protocol/server: do not wind opendir call if fd creation failsRaghavendra Bhat2012-06-011-1/+1 * core: adding extra data for fopsAmar Tumballi2012-03-221-0/+3 * protocol/server: Handle server send reply failure gracefully.Mohammed Junaid2012-03-191-0/+2 * protocol/server: Clear internal locks on disconnectPranith Kumar K2012-03-181-1/+7 * protocol/server: Avoid race in add/del locker, connection_cleanupPranith Kumar K2012-03-171-1/+0 * protocol/server: Remove connection from conf->conns w.o. racePranith Kumar K2012-03-131-0/+5 * protocol/server: Make conn object ref-countedPranith Kumar K2012-03-011-2/+5 * transport/socket: configuring tcp window-sizeRajesh Amaravathi2012-02-291-0/+2 * protocol/client,server: fcntl lock self healing.Mohammed Junaid2012-02-201-1/+4 * core: get xattrs also as part of readdirpAmar Tumballi2012-01-251<