Motr  M0
msg.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 
29 #define M0_TRACE_SUBSYSTEM M0_TRACE_SUBSYS_HA
30 #include "lib/trace.h"
31 
32 #include "ha/msg.h"
33 
34 #include "lib/misc.h" /* memcmp */
35 
36 M0_INTERNAL uint64_t m0_ha_msg_tag(const struct m0_ha_msg *msg)
37 {
38  return msg->hm_tag;
39 }
40 
41 M0_INTERNAL enum m0_ha_msg_type m0_ha_msg_type_get(const struct m0_ha_msg *msg)
42 {
43  return msg->hm_data.hed_type;
44 }
45 
46 M0_INTERNAL bool m0_ha_msg_eq(const struct m0_ha_msg *msg1,
47  const struct m0_ha_msg *msg2)
48 {
49  return m0_fid_eq(&msg1->hm_fid, &msg2->hm_fid) &&
52  msg1->hm_time == msg2->hm_time &&
53  msg1->hm_data.hed_type == msg2->hm_data.hed_type &&
54  /*
55  * Note: it's not reqired by the standard because structs can
56  * have padding bytes. Please remove this memcmp if you see any
57  * problem with it.
58  */
59  memcmp(&msg1->hm_data,
60  &msg2->hm_data, sizeof msg1->hm_data) == 0;
61 }
62 
63 M0_INTERNAL void m0_ha_msg_debug_print(const struct m0_ha_msg *msg,
64  const char *prefix)
65 {
66  const struct m0_ha_msg_data *data = &msg->hm_data;
67  const struct m0_ha_msg_nvec *nvec;
68  uint32_t ha_state;
69  int i;
70 
71  M0_LOG(M0_DEBUG, "%s: msg=%p hm_fid="FID_F" hm_source_process="FID_F" "
72  "hm_source_service="FID_F" hm_time=%"PRIu64,
73  prefix, msg, FID_P(&msg->hm_fid), FID_P(&msg->hm_source_process),
74  FID_P(&msg->hm_source_service), msg->hm_time);
75  M0_LOG(M0_DEBUG, "%s: msg=%p hm_tag=%" PRIu64 " hm_epoch=%"PRIu64,
76  prefix, msg, msg->hm_tag, msg->hm_epoch);
77 
78  switch ((enum m0_ha_msg_type)data->hed_type) {
79  case M0_HA_MSG_INVALID:
80  M0_LOG(M0_WARN, "message has INVALID type");
81  return;
82  case M0_HA_MSG_STOB_IOQ:
83  M0_LOG(M0_DEBUG, "STOB_IOQ msg=%p conf_sdev="FID_F
84  " stob_id="STOB_ID_F" fd=%"PRId64,
85  msg,
86  FID_P(&data->u.hed_stob_ioq.sie_conf_sdev),
87  STOB_ID_P(&data->u.hed_stob_ioq.sie_stob_id),
88  data->u.hed_stob_ioq.sie_fd);
89  M0_LOG(M0_DEBUG, "STOB_IOQ msg=%p opcode=%" PRId64 " rc=%"PRId64
90  " bshift=%"PRIu32" size=%" PRIu64 " offset=%"PRIu64,
91  msg,
92  data->u.hed_stob_ioq.sie_opcode,
93  data->u.hed_stob_ioq.sie_rc,
94  data->u.hed_stob_ioq.sie_bshift,
95  data->u.hed_stob_ioq.sie_size,
96  data->u.hed_stob_ioq.sie_offset);
97  return;
98  case M0_HA_MSG_NVEC:
99  nvec = &data->u.hed_nvec;
100  M0_LOG(M0_DEBUG, "NVEC hmnv_type=%" PRIu64 " hmnv_nr=%" PRIu64 " "
101  "hmnv_id_of_get=%" PRIu64 " "
102  "hmnv_ignore_same_state=%"PRIu64,
103  nvec->hmnv_type, nvec->hmnv_nr, nvec->hmnv_id_of_get,
104  nvec->hmnv_ignore_same_state);
105  for (i = 0; i < data->u.hed_nvec.hmnv_nr; ++i) {
106  M0_LOG(M0_DEBUG, "hmnv_arr.hmna_arr[%d]=(no_id="FID_F" "
107  "no_state=%"PRIu32")", i,
108  FID_P(&nvec->hmnv_arr.hmna_arr[i].no_id),
109  nvec->hmnv_arr.hmna_arr[i].no_state);
110  if (nvec->hmnv_arr.hmna_arr[i].no_id.f_container <
111  0x10000000000UL) {
112  M0_LOG(M0_ERROR, "invalid note: no_id="FID_F" "
113  "no_state=%"PRIu32,
114  FID_P(&nvec->hmnv_arr.hmna_arr[i].no_id),
115  nvec->hmnv_arr.hmna_arr[i].no_state);
116  }
117 
118  }
119  return;
121  M0_LOG(M0_DEBUG, "FAILURE_VEC_REQ mvq_pool="FID_F,
122  FID_P(&data->u.hed_fvec_req.mfq_pool));
123  return;
125  M0_LOG(M0_DEBUG, "FAILURE_VEC_REP mvp_pool="FID_F" "
126  "mvp_nr=%"PRIu32, FID_P(&data->u.hed_fvec_rep.mfp_pool),
127  data->u.hed_fvec_rep.mfp_nr);
128  for (i = 0; i < data->u.hed_fvec_rep.mfp_nr; ++i) {
129  ha_state =
130  data->u.hed_fvec_rep.mfp_vec.hmna_arr[i].no_state;
131  M0_LOG(M0_DEBUG, "mvf_nvec[%d]=(no_id="FID_F","
132  "no_state = %"PRIu32")", i,
133  FID_P(&data->u.hed_fvec_rep.mfp_vec.hmna_arr[i].no_id),
134  ha_state);
135  }
136  return;
138  M0_LOG(M0_DEBUG, "KEEPALIVE_REQ hm_fid="FID_F" kaq_id="U128X_F,
139  FID_P(&msg->hm_fid),
140  U128_P(&data->u.hed_keepalive_req.kaq_id));
141  return;
143  M0_LOG(M0_DEBUG, "KEEPALIVE_REP hm_fid="FID_F" "
144  "kap_id="U128X_F" kap_counter=%"PRIu64,
145  FID_P(&msg->hm_fid),
146  U128_P(&data->u.hed_keepalive_rep.kap_id),
147  data->u.hed_keepalive_rep.kap_counter);
148  return;
150  M0_LOG(M0_DEBUG, "EVENT_PROCESS hm_fid="FID_F" "
151  "chp_event=%" PRIu64 " chp_type=%" PRIu64 " chp_pid=%"PRIu64,
152  FID_P(&msg->hm_fid),
153  data->u.hed_event_process.chp_event,
154  data->u.hed_event_process.chp_type,
155  data->u.hed_event_process.chp_pid);
156  return;
158  M0_LOG(M0_DEBUG, "EVENT_SERVICE hm_fid="FID_F" "
159  "chs_event=%" PRIu64 " chs_type=%"PRIu64,
160  FID_P(&msg->hm_fid),
161  data->u.hed_event_service.chs_event,
162  data->u.hed_event_service.chs_type);
163  return;
164  case M0_HA_MSG_EVENT_RPC:
165  M0_LOG(M0_DEBUG, "EVENT_RPC hm_fid="FID_F" "
166  "hmr_state=%" PRIu64 " hmr_attempts=%"PRIu64,
167  FID_P(&msg->hm_fid),
168  data->u.hed_event_rpc.hmr_state,
169  data->u.hed_event_rpc.hmr_attempts);
170  return;
171  case M0_HA_MSG_BE_IO_ERR:
172  M0_LOG(M0_DEBUG, "BE_IO_ERR hm_fid="FID_F" "
173  "ber_errcode=%"PRIu32" ber_location=%u ber_io_opcode=%u",
174  FID_P(&msg->hm_fid),
175  data->u.hed_be_io_err.ber_errcode,
176  data->u.hed_be_io_err.ber_location,
177  data->u.hed_be_io_err.ber_io_opcode);
178  return;
179  case M0_HA_MSG_SNS_ERR:
180  M0_LOG(M0_DEBUG, "HA_SNS_ERR hm_fid="FID_F" "
181  "hse_errcode=%"PRIu32" hse_opcode=%u",
182  FID_P(&msg->hm_fid),
183  data->u.hed_ha_sns_err.hse_errcode,
184  data->u.hed_ha_sns_err.hse_opcode);
185  return;
186  default:
187  M0_LOG(M0_WARN, "unknown m0_ha_msg type: %"PRIu64,
188  data->hed_type);
189  }
190 }
191 
192 #undef M0_TRACE_SUBSYSTEM
193 
195 /*
196  * Local variables:
197  * c-indentation-style: "K&R"
198  * c-basic-offset: 8
199  * tab-width: 8
200  * fill-column: 80
201  * scroll-step: 1
202  * End:
203  */
204 /*
205  * vim: tabstop=8 shiftwidth=8 noexpandtab textwidth=80 nowrap
206  */
uint64_t hed_type
Definition: msg.h:88
uint64_t hmnv_type
Definition: note.h:226
struct m0_fid hm_fid
Definition: msg.h:117
struct m0_ha_msg_nvec_array hmnv_arr
Definition: note.h:265
M0_INTERNAL enum m0_ha_msg_type m0_ha_msg_type_get(const struct m0_ha_msg *msg)
Definition: msg.c:41
#define M0_LOG(level,...)
Definition: trace.h:167
static struct m0_uint128 prefix
Definition: extmap.c:45
struct m0_bufvec data
Definition: di.c:40
struct m0_ha_msg_data hm_data
Definition: msg.h:122
struct m0_ha_note hmna_arr[M0_HA_STATE_UPDATE_LIMIT]
Definition: note.h:221
struct m0_fid hm_source_process
Definition: msg.h:118
int i
Definition: dir.c:1033
#define PRIu64
Definition: types.h:58
uint64_t hm_epoch
Definition: msg.h:121
#define STOB_ID_P(si)
Definition: stob.h:109
#define U128_P(x)
Definition: types.h:45
m0_ha_msg_type
Definition: msg.h:72
uint64_t hm_tag
Definition: msg.h:125
uint64_t hmnv_ignore_same_state
Definition: note.h:263
M0_INTERNAL bool m0_ha_msg_eq(const struct m0_ha_msg *msg1, const struct m0_ha_msg *msg2)
Definition: msg.c:46
Definition: msg.h:115
uint64_t f_container
Definition: fid.h:39
uint64_t hmnv_id_of_get
Definition: note.h:227
M0_INTERNAL uint64_t m0_ha_msg_tag(const struct m0_ha_msg *msg)
Definition: msg.c:36
#define FID_P(f)
Definition: fid.h:77
struct m0_fid no_id
Definition: note.h:180
#define PRId64
Definition: types.h:57
#define U128X_F
Definition: types.h:42
M0_INTERNAL bool m0_fid_eq(const struct m0_fid *fid0, const struct m0_fid *fid1)
Definition: fid.c:164
#define PRIu32
Definition: types.h:66
m0_time_t hm_time
Definition: msg.h:120
uint64_t hmnv_nr
Definition: note.h:264
#define STOB_ID_F
Definition: stob.h:108
M0_INTERNAL void m0_ha_msg_debug_print(const struct m0_ha_msg *msg, const char *prefix)
Definition: msg.c:63
struct m0_fid hm_source_service
Definition: msg.h:119
#define FID_F
Definition: fid.h:75
Definition: trace.h:478
uint32_t no_state
Definition: note.h:182