glusterfs

Форк
0
/
glusterd-conn-mgmt.c 
182 строки · 4.7 Кб
1
/*
2
   Copyright (c) 2014 Red Hat, Inc. <http://www.redhat.com>
3
   This file is part of GlusterFS.
4

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

11
#include "rpc-clnt.h"
12
#include "glusterd.h"
13
#include "glusterd-conn-mgmt.h"
14
#include "glusterd-conn-helper.h"
15
#include "glusterd-utils.h"
16
#include "glusterd-messages.h"
17

18
int
19
glusterd_conn_init(glusterd_conn_t *conn, char *sockpath, time_t frame_timeout,
20
                   glusterd_conn_notify_t notify)
21
{
22
    int ret = -1;
23
    dict_t *options = NULL;
24
    struct rpc_clnt *rpc = NULL;
25
    xlator_t *this = THIS;
26
    glusterd_svc_t *svc = NULL;
27

28
    options = dict_new();
29
    if (!options) {
30
        gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_DICT_CREATE_FAIL, NULL);
31
        goto out;
32
    }
33

34
    svc = glusterd_conn_get_svc_object(conn);
35
    if (!svc) {
36
        gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_SVC_GET_FAIL,
37
               "Failed to get the service");
38
        goto out;
39
    }
40

41
    ret = rpc_transport_unix_options_build(options, sockpath, frame_timeout);
42
    if (ret)
43
        goto out;
44

45
    ret = dict_set_int32_sizen(options, "transport.socket.ignore-enoent", 1);
46
    if (ret) {
47
        gf_smsg(this->name, GF_LOG_ERROR, -ret, GD_MSG_DICT_SET_FAILED,
48
                "Key=transport.socket.ignore-enoent", NULL);
49
        goto out;
50
    }
51

52
    /* @options is free'd by rpc_transport when destroyed */
53
    rpc = rpc_clnt_new(options, this, (char *)svc->name, 16);
54
    if (!rpc) {
55
        ret = -1;
56
        goto out;
57
    }
58

59
    ret = rpc_clnt_register_notify(rpc, glusterd_conn_common_notify, conn);
60
    if (ret)
61
        goto out;
62

63
    ret = snprintf(conn->sockpath, sizeof(conn->sockpath), "%s", sockpath);
64
    if (ret < 0) {
65
        gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_COPY_FAIL, NULL);
66
        goto out;
67
    } else
68
        ret = 0;
69

70
    conn->rpc = rpc;
71
    conn->notify = notify;
72
out:
73
    if (options)
74
        dict_unref(options);
75
    if (ret) {
76
        if (rpc) {
77
            rpc_clnt_unref(rpc);
78
            rpc = NULL;
79
        }
80
    }
81
    return ret;
82
}
83

84
int
85
glusterd_conn_term(glusterd_conn_t *conn)
86
{
87
    rpc_clnt_unref(conn->rpc);
88
    return 0;
89
}
90

91
int
92
glusterd_conn_connect(glusterd_conn_t *conn)
93
{
94
    return rpc_clnt_start(conn->rpc);
95
}
96

97
int
98
glusterd_conn_disconnect(glusterd_conn_t *conn)
99
{
100
    rpc_clnt_disable(conn->rpc);
101

102
    return 0;
103
}
104

105
int
106
__glusterd_conn_common_notify(struct rpc_clnt *rpc, void *mydata,
107
                              rpc_clnt_event_t event, void *data)
108
{
109
    glusterd_conn_t *conn = mydata;
110

111
    /* Silently ignoring this error, exactly like the current
112
     * implementation */
113
    if (!conn)
114
        return 0;
115

116
    return conn->notify(conn, event);
117
}
118

119
int
120
glusterd_conn_common_notify(struct rpc_clnt *rpc, void *mydata,
121
                            rpc_clnt_event_t event, void *data)
122
{
123
    return glusterd_big_locked_notify(rpc, mydata, event, data,
124
                                      __glusterd_conn_common_notify);
125
}
126

127
int32_t
128
glusterd_conn_build_socket_filepath(char *rundir, uuid_t uuid, char *socketpath,
129
                                    int len)
130
{
131
    char sockfilepath[PATH_MAX] = {
132
        0,
133
    };
134

135
    snprintf(sockfilepath, sizeof(sockfilepath), "%s/run-%s", rundir,
136
             uuid_utoa(uuid));
137

138
    glusterd_set_socket_filepath(sockfilepath, socketpath, len);
139
    return 0;
140
}
141

142
int
143
__glusterd_muxsvc_conn_common_notify(struct rpc_clnt *rpc, void *mydata,
144
                                     rpc_clnt_event_t event, void *data)
145
{
146
    glusterd_conf_t *conf = THIS->private;
147
    glusterd_svc_proc_t *mux_proc = mydata;
148
    int ret = -1;
149

150
    /* Silently ignoring this error, exactly like the current
151
     * implementation */
152
    if (!mux_proc)
153
        return 0;
154

155
    if (event == RPC_CLNT_DESTROY) {
156
        /*RPC_CLNT_DESTROY will only called after mux_proc detached from the
157
         * list. So it is safe to call without lock. Processing
158
         * RPC_CLNT_DESTROY under a lock will lead to deadlock.
159
         */
160
        if (mux_proc->data) {
161
            glusterd_volinfo_unref(mux_proc->data);
162
            mux_proc->data = NULL;
163
        }
164
        GF_FREE(mux_proc);
165
        ret = 0;
166
    } else {
167
        pthread_mutex_lock(&conf->attach_lock);
168
        {
169
            ret = mux_proc->notify(mux_proc, event);
170
        }
171
        pthread_mutex_unlock(&conf->attach_lock);
172
    }
173
    return ret;
174
}
175

176
int
177
glusterd_muxsvc_conn_common_notify(struct rpc_clnt *rpc, void *mydata,
178
                                   rpc_clnt_event_t event, void *data)
179
{
180
    return glusterd_big_locked_notify(rpc, mydata, event, data,
181
                                      __glusterd_muxsvc_conn_common_notify);
182
}
183

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.