Motr  M0
helper.c
Go to the documentation of this file.
1 /* -*- C -*- */
2 /*
3  * Copyright (c) 2021 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 #define M0_TRACE_SUBSYSTEM M0_TRACE_SUBSYS_DTM0
22 #include "lib/trace.h"
23 #include "lib/assert.h"
24 #include "lib/memory.h"
25 #include "reqh/reqh_service.h"
26 #include "reqh/reqh.h" /* m0_reqh */
27 #include "be/domain.h"
28 #include "be/dtm0_log.h"
29 #include "module/instance.h" /* m0_get */
30 
31 
32 static int dtm0_log_init(struct m0_be_domain *dom, const char *suffix,
33  const struct m0_buf *data)
34 {
35  struct m0_be_dtm0_log *log0 = *(struct m0_be_dtm0_log**)data->b_addr;
36  struct m0_reqh *reqh = dom->bd_cfg.bc_engine.bec_reqh;
37  unsigned key = m0_get()->i_dtm0_log_key;
38 
39  M0_ENTRY("suffix: %s, data: %p, log0: %p", suffix, data->b_addr, log0);
40 
41  if (m0_reqh_lockers_get(reqh, key) == NULL)
42  m0_reqh_lockers_set(reqh, key, log0);
43 
44  return M0_RC(0);
45 }
46 
47 static void dtm0_log_fini(struct m0_be_domain *dom, const char *suffix,
48  const struct m0_buf *data)
49 {
50  M0_ENTRY();
51  M0_LEAVE();
52 }
53 
55  .b0_name = "M0_BE:DTM_LOG",
56  .b0_init = dtm0_log_init,
57  .b0_fini = dtm0_log_fini,
58 };
59 
60 M0_INTERNAL int m0_dtm0_log_create(struct m0_sm_group *grp,
61  struct m0_be_domain *bedom,
62  struct m0_be_seg *seg)
63 {
64  static const char *logid = "0001";
65  struct m0_be_tx_credit cred = {};
66  struct m0_be_dtm0_log *log;
67  struct m0_be_tx *tx;
68  struct m0_buf data = {};
69  int rc;
70 
71  M0_ALLOC_PTR(tx);
72  if (tx == NULL)
73  return M0_ERR(-ENOMEM);
74 
75  m0_be_0type_add_credit(bedom, &m0_be_dtm0, logid, &data, &cred);
78 
79  m0_be_tx_init(tx, 0, bedom, grp, NULL, NULL, NULL, NULL);
80  m0_be_tx_prep(tx, &cred);
82  if (rc != 0)
83  goto tx_fini;
84 
85  rc = m0_be_dtm0_log_create(tx, seg, &log);
86  if (rc != 0)
87  goto tx_close;
88 
89  data = M0_BUF_INIT_PTR(&log);
90  rc = m0_be_0type_add(&m0_be_dtm0, bedom, tx, logid, &data);
91  if (rc != 0)
92  m0_be_dtm0_log_destroy(tx, &log);
93 tx_close:
95 tx_fini:
96  m0_be_tx_fini(tx);
97  m0_free(tx);
98  return M0_RC(rc);
99 }
100 
101 /*
102  * Local variables:
103  * c-indentation-style: "K&R"
104  * c-basic-offset: 8
105  * tab-width: 8
106  * fill-column: 80
107  * scroll-step: 1
108  * End:
109  */
#define M0_BE_TX_CREDIT_PTR(ptr)
Definition: tx_credit.h:98
void m0_be_0type_add_credit(struct m0_be_domain *dom, const struct m0_be_0type *zt, const char *suffix, const struct m0_buf *data, struct m0_be_tx_credit *credit)
Definition: seg0.c:139
#define NULL
Definition: misc.h:38
const char * b0_name
Definition: seg0.h:44
static struct m0_sm_group * grp
Definition: bytecount.c:38
M0_LEAVE()
M0_INTERNAL void m0_be_tx_fini(struct m0_be_tx *tx)
Definition: stubs.c:163
struct m0_bufvec data
Definition: di.c:40
M0_INTERNAL void m0_be_tx_prep(struct m0_be_tx *tx, const struct m0_be_tx_credit *credit)
Definition: stubs.c:175
M0_INTERNAL struct m0 * m0_get(void)
Definition: instance.c:41
unsigned i_dtm0_log_key
Definition: instance.h:141
struct m0_be_0type m0_be_dtm0
Definition: helper.c:54
static void dtm0_log_fini(struct m0_be_domain *dom, const char *suffix, const struct m0_buf *data)
Definition: helper.c:47
return M0_RC(rc)
#define M0_ENTRY(...)
Definition: trace.h:170
Definition: buf.h:37
return M0_ERR(-EOPNOTSUPP)
M0_INTERNAL int m0_be_dtm0_log_create(struct m0_be_tx *tx, struct m0_be_seg *seg, struct m0_be_dtm0_log **out)
Definition: dtm0_log.c:237
M0_INTERNAL void m0_be_tx_credit_add(struct m0_be_tx_credit *c0, const struct m0_be_tx_credit *c1)
Definition: tx_credit.c:44
static struct m0_stob_domain * dom
Definition: storage.c:38
M0_INTERNAL void m0_be_dtm0_log_destroy(struct m0_be_tx *tx, struct m0_be_dtm0_log **log)
Definition: dtm0_log.c:260
M0_INTERNAL int m0_be_tx_exclusive_open_sync(struct m0_be_tx *tx)
Definition: tx.c:594
static int dtm0_log_init(struct m0_be_domain *dom, const char *suffix, const struct m0_buf *data)
Definition: helper.c:32
Definition: reqh.h:94
Definition: seg.h:66
int m0_be_0type_add(struct m0_be_0type *zt, struct m0_be_domain *dom, struct m0_be_tx *tx, const char *suffix, const struct m0_buf *data)
Definition: seg0.c:79
M0_INTERNAL void m0_be_tx_init(struct m0_be_tx *tx, uint64_t tid, struct m0_be_domain *dom, struct m0_sm_group *sm_group, m0_be_tx_cb_t persistent, m0_be_tx_cb_t discarded, void(*filler)(struct m0_be_tx *tx, void *payload), void *datum)
Definition: stubs.c:150
struct m0_reqh reqh
Definition: rm_foms.c:48
#define M0_BUF_INIT_PTR(p)
Definition: buf.h:69
#define M0_ALLOC_PTR(ptr)
Definition: memory.h:86
M0_INTERNAL void m0_be_dtm0_log_credit(enum m0_be_dtm0_log_credit_op op, struct m0_dtm0_tx_desc *txd, struct m0_buf *payload, struct m0_be_seg *seg, struct m0_dtm0_log_rec *rec, struct m0_be_tx_credit *accum)
Definition: dtm0_log.c:202
static struct m0_be_seg * seg
Definition: btree.c:40
M0_INTERNAL int m0_dtm0_log_create(struct m0_sm_group *grp, struct m0_be_domain *bedom, struct m0_be_seg *seg)
Definition: helper.c:60
void m0_free(void *data)
Definition: memory.c:146
int32_t rc
Definition: trigger_fop.h:47
M0_INTERNAL void m0_be_tx_close_sync(struct m0_be_tx *tx)
Definition: stubs.c:205
Definition: tx.h:280
Definition: idx_mock.c:47