Motr  M0
ha.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 
23 
30 #define M0_TRACE_SUBSYSTEM M0_TRACE_SUBSYS_CONF
31 #include "lib/trace.h"
32 
33 #include "conf/ha.h"
34 
35 #include "lib/memory.h" /* M0_ALLOC_PTR */
36 #include "lib/time.h" /* m0_time_now */
37 #include "lib/types.h" /* PRIu64 */
38 
39 #include "fid/fid.h" /* FID_P */
40 #include "module/instance.h" /* m0_get */
41 #include "ha/msg.h" /* m0_ha_msg */
42 #include "ha/ha.h" /* m0_ha_send */
43 
44 M0_INTERNAL void
46  struct m0_ha_link *hl,
47  const struct m0_fid *process_fid,
48  uint64_t pid,
49  enum m0_conf_ha_process_event event,
51 {
52  struct m0_ha_msg *msg;
53  uint64_t tag;
54 
55  M0_ENTRY("process_fid="FID_F" event=%d", FID_P(process_fid), event);
56  M0_ALLOC_PTR(msg);
57  if (msg == NULL) {
58  M0_LOG(M0_ERROR, "can't allocate memory for msg");
59  M0_LEAVE();
60  return;
61  }
62  *msg = (struct m0_ha_msg){
63  .hm_fid = *process_fid,
64  .hm_time = m0_time_now(),
65  .hm_data = {
66  .hed_type = M0_HA_MSG_EVENT_PROCESS,
67  .u.hed_event_process = {
68  .chp_event = event,
69  .chp_type = type,
70  .chp_pid = pid,
71  },
72  },
73  };
74  m0_ha_send(ha, hl, msg, &tag);
75  m0_free(msg);
76  M0_LEAVE("tag=%"PRIu64, tag);
77 }
78 
79 M0_INTERNAL void
81  struct m0_ha_link *hl,
82  const struct m0_fid *source_process_fid,
83  const struct m0_fid *source_service_fid,
84  const struct m0_fid *service_fid,
85  uint64_t pid,
86  enum m0_conf_ha_service_event event,
87  enum m0_conf_service_type service_type)
88 {
89  struct m0_ha_msg *msg;
90  uint64_t tag;
91 
92  M0_ENTRY("ha=%p hl=%p service_fid="FID_F" source_process_fid="FID_F" "
93  "source_service_fid="FID_F" event=%d",
94  ha, hl, FID_P(service_fid),
95  FID_P(source_process_fid), FID_P(source_service_fid), event);
96  M0_LOG(M0_DEBUG, "service_type=%d", service_type);
97  M0_ALLOC_PTR(msg);
98  if (msg == NULL) {
99  M0_LOG(M0_ERROR, "can't allocate memory for msg");
100  M0_LEAVE();
101  return;
102  }
103  *msg = (struct m0_ha_msg){
104  .hm_fid = *service_fid,
105  .hm_source_process = *source_process_fid,
106  .hm_source_service = *source_service_fid,
107  .hm_time = m0_time_now(),
108  .hm_data = {
109  .hed_type = M0_HA_MSG_EVENT_SERVICE,
110  .u.hed_event_service = {
111  .chs_event = event,
112  .chs_type = service_type,
113  .chs_pid = pid,
114  },
115  },
116  };
117  m0_ha_send(ha, hl, msg, &tag);
118  m0_free(msg);
119  M0_LEAVE("tag=%"PRIu64, tag);
120 }
121 
122 #undef M0_TRACE_SUBSYSTEM
123 
126 /*
127  * Local variables:
128  * c-indentation-style: "K&R"
129  * c-basic-offset: 8
130  * tab-width: 8
131  * fill-column: 80
132  * scroll-step: 1
133  * End:
134  */
135 /*
136  * vim: tabstop=8 shiftwidth=8 noexpandtab textwidth=80 nowrap
137  */
struct m0_fid hm_fid
Definition: msg.h:117
m0_conf_ha_process_event
Definition: ha.h:49
#define NULL
Definition: misc.h:38
M0_INTERNAL void m0_conf_ha_service_event_post(struct m0_ha *ha, struct m0_ha_link *hl, const struct m0_fid *source_process_fid, const struct m0_fid *source_service_fid, const struct m0_fid *service_fid, uint64_t pid, enum m0_conf_ha_service_event event, enum m0_conf_service_type service_type)
Definition: ha.c:80
m0_conf_service_type
Definition: schema.h:194
m0_conf_ha_service_event
Definition: ha.h:119
static uint64_t tag(uint8_t code, uint64_t id)
Definition: addb2.c:1047
#define M0_LOG(level,...)
Definition: trace.h:167
M0_LEAVE()
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
m0_conf_ha_process_type
Definition: ha.h:86
#define M0_ENTRY(...)
Definition: trace.h:170
#define PRIu64
Definition: types.h:58
m0_time_t m0_time_now(void)
Definition: time.c:134
Definition: msg.h:115
#define FID_P(f)
Definition: fid.h:77
Definition: ha.h:289
Definition: fid.h:38
#define M0_ALLOC_PTR(ptr)
Definition: memory.h:86
M0_INTERNAL void m0_conf_ha_process_event_post(struct m0_ha *ha, struct m0_ha_link *hl, const struct m0_fid *process_fid, uint64_t pid, enum m0_conf_ha_process_event event, enum m0_conf_ha_process_type type)
Definition: ha.c:45
int type
Definition: dir.c:1031
void m0_free(void *data)
Definition: memory.c:146
static const char * process_fid
Definition: idx_dix.c:73
#define FID_F
Definition: fid.h:75