Motr  M0
ha.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016-2020 Seagate Technology LLC and/or its Affiliates
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  * For any questions about this software or licensing,
17  * please email opensource@seagate.com or cortx-questions@seagate.com.
18  *
19  */
20 
21 
28 #define M0_TRACE_SUBSYSTEM M0_TRACE_SUBSYS_BE
29 #include "lib/trace.h"
30 
31 #include "be/ha.h"
32 #include "ha/msg.h" /* M0_HA_MSG_BE_IO_ERR */
33 #include "ha/ha.h" /* m0_ha_send */
34 #include "module/instance.h" /* m0_get */
35 #include "lib/memory.h" /* M0_ALLOC_PTR */
36 
37 M0_INTERNAL void
38 m0_be_io_err_send(uint32_t errcode, uint8_t location, uint8_t io_opcode)
39 {
40  struct m0_ha_msg *msg;
41  uint64_t tag;
42 
43  M0_ENTRY("errcode=%d location=%u io_opcode=%u",
44  errcode, location, io_opcode);
45  M0_PRE(errcode < 0);
47  M0_PRE(SIO_INVALID <= io_opcode && io_opcode <= SIO_SYNC);
48 
49  M0_ALLOC_PTR(msg);
50  if (msg == NULL) {
51  M0_LOG(M0_ERROR, "m0_ha_msg allocation failed");
52  } else {
53  *msg = (struct m0_ha_msg){
54  .hm_time = m0_time_now(),
55  .hm_data = {
56  .hed_type = M0_HA_MSG_BE_IO_ERR,
57  .u.hed_be_io_err = (struct m0_be_io_err){
58  .ber_errcode = errcode,
59  .ber_location = location,
60  .ber_io_opcode = io_opcode
61  }
62  }
63  };
64  m0_ha_send(m0_get()->i_ha, m0_get()->i_ha_link, msg, &tag);
65  m0_free(msg);
66  }
67  /*
68  * Enter infinite loop.
69  *
70  * If you ever decide to delete this loop, update the function
71  * documentation.
72  */
73  while (1)
74  m0_nanosleep(m0_time(1, 0), NULL);
75 }
76 
77 #undef M0_TRACE_SUBSYSTEM
78 
#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
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_INTERNAL struct m0 * m0_get(void)
Definition: instance.c:41
m0_time_t m0_time(uint64_t secs, long ns)
Definition: time.c:41
const char * location
Definition: storage.c:50
#define M0_ENTRY(...)
Definition: trace.h:170
M0_INTERNAL void m0_be_io_err_send(uint32_t errcode, uint8_t location, uint8_t io_opcode)
Definition: ha.c:38
Definition: io.h:232
m0_time_t m0_time_now(void)
Definition: time.c:134
Definition: msg.h:115
#define M0_ALLOC_PTR(ptr)
Definition: memory.h:86
m0_time_t hm_time
Definition: msg.h:120
void m0_free(void *data)
Definition: memory.c:146
int m0_nanosleep(const m0_time_t req, m0_time_t *rem)
Definition: ktime.c:73