Motr  M0
keepalive.c
Go to the documentation of this file.
1 /* -*- C -*- */
2 /*
3  * Copyright (c) 2016-2020 Seagate Technology LLC and/or its Affiliates
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * For any questions about this software or licensing,
18  * please email opensource@seagate.com or cortx-questions@seagate.com.
19  *
20  */
21 
22 
31 #define M0_TRACE_SUBSYSTEM M0_TRACE_SUBSYS_HA
32 #include "lib/trace.h"
33 
34 #include "motr/keepalive.h"
35 
36 #include "lib/memory.h" /* M0_ALLOC_PTR */
37 #include "lib/time.h" /* m0_time_now */
38 #include "ha/msg.h" /* m0_ha_msg */
39 #include "ha/ha.h" /* m0_ha_send */
40 
42  struct m0_ha *ha,
43  struct m0_ha_link *hl,
44  struct m0_ha_msg *msg,
45  uint64_t tag,
46  void *data)
47 {
48  struct m0_ha_keepalive_handler *ka;
49  struct m0_ha_msg *rep;
50  uint64_t tag_rep;
51 
52  ka = M0_AMB(ka, hh, kah_handler);
53  M0_ASSERT(ka == data);
54 
56  return;
58  if (rep == NULL)
59  return;
60  *rep = (struct m0_ha_msg){
61  .hm_time = m0_time_now(),
62  .hm_data = {
63  .hed_type = M0_HA_MSG_KEEPALIVE_REP,
64  .u.hed_keepalive_rep = {
65  .kap_id =
66  msg->hm_data.u.hed_keepalive_req.kaq_id,
67  .kap_counter =
69  },
70  },
71  };
72  m0_ha_send(ha, hl, rep, &tag_rep);
73  M0_LOG(M0_DEBUG, "kap_id="U128X_F" kap_counter=%" PRIu64 " tag=%"PRIu64,
74  U128_P(&rep->hm_data.u.hed_keepalive_rep.kap_id),
75  rep->hm_data.u.hed_keepalive_rep.kap_counter, tag_rep);
76  m0_free(rep);
77 }
78 
79 M0_INTERNAL int
81  struct m0_ha_dispatcher *hd)
82 {
83  M0_PRE(M0_IS0(ka));
84 
85  ka->kah_dispatcher = hd;
86  ka->kah_handler = (struct m0_ha_handler){
87  .hh_data = ka,
88  .hh_msg_received_cb = &ha_keepalive_msg_received_cb,
89  };
92  return 0;
93 }
94 
95 M0_INTERNAL void
97 {
99 }
100 
101 #undef M0_TRACE_SUBSYSTEM
102 
105 /*
106  * Local variables:
107  * c-indentation-style: "K&R"
108  * c-basic-offset: 8
109  * tab-width: 8
110  * fill-column: 80
111  * scroll-step: 1
112  * End:
113  */
114 /*
115  * vim: tabstop=8 shiftwidth=8 noexpandtab textwidth=80 nowrap
116  */
uint64_t hed_type
Definition: msg.h:88
#define M0_PRE(cond)
#define NULL
Definition: misc.h:38
static uint64_t tag(uint8_t code, uint64_t id)
Definition: addb2.c:1047
#define M0_LOG(level,...)
Definition: trace.h:167
struct m0_bufvec data
Definition: di.c:40
M0_INTERNAL void m0_ha_send(struct m0_ha *ha, struct m0_ha_link *hl, const struct m0_ha_msg *msg, uint64_t *tag)
Definition: ha.c:862
struct m0_ha_msg_data hm_data
Definition: msg.h:122
M0_INTERNAL int m0_ha_keepalive_handler_init(struct m0_ha_keepalive_handler *ka, struct m0_ha_dispatcher *hd)
Definition: keepalive.c:80
struct m0_ha_handler kah_handler
Definition: keepalive.h:52
struct m0_fop_getxattr_rep * rep
Definition: dir.c:455
#define PRIu64
Definition: types.h:58
#define M0_AMB(obj, ptr, field)
Definition: misc.h:320
#define M0_ASSERT(cond)
#define U128_P(x)
Definition: types.h:45
m0_time_t m0_time_now(void)
Definition: time.c:134
struct m0_ha_dispatcher * kah_dispatcher
Definition: keepalive.h:51
Definition: msg.h:115
M0_INTERNAL void m0_ha_dispatcher_attach(struct m0_ha_dispatcher *hd, struct m0_ha_handler *hh)
Definition: dispatcher.c:219
Definition: ha.h:289
#define U128X_F
Definition: types.h:42
static void ha_keepalive_msg_received_cb(struct m0_ha_handler *hh, struct m0_ha *ha, struct m0_ha_link *hl, struct m0_ha_msg *msg, uint64_t tag, void *data)
Definition: keepalive.c:41
union m0_ha_msg_data::@212 u
M0_INTERNAL void m0_ha_dispatcher_detach(struct m0_ha_dispatcher *hd, struct m0_ha_handler *hh)
Definition: dispatcher.c:225
#define M0_IS0(obj)
Definition: misc.h:70
#define M0_ALLOC_PTR(ptr)
Definition: memory.h:86
struct m0_atomic64 kah_counter
Definition: keepalive.h:53
void m0_free(void *data)
Definition: memory.c:146
M0_INTERNAL void m0_ha_keepalive_handler_fini(struct m0_ha_keepalive_handler *ka)
Definition: keepalive.c:96
void * hh_data
Definition: dispatcher.h:70
static int64_t m0_atomic64_add_return(struct m0_atomic64 *a, int64_t d)
static void m0_atomic64_set(struct m0_atomic64 *a, int64_t num)