Motr  M0
dtm.c
Go to the documentation of this file.
1 /* -*- C -*- */
2 /*
3  * Copyright (c) 2013-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 
28 #include "lib/misc.h" /* m0_forall, ARRAY_SIZE */
29 
30 #include "dtm/nucleus.h"
31 #include "dtm/fol.h"
32 #include "dtm/dtm.h"
33 #include "dtm/dtm_internal.h"
34 #include "dtm/dtm_update_xc.h"
35 #include "dtm/update_xc.h"
36 #include "dtm/operation_xc.h"
37 
38 #define M0_TRACE_SUBSYSTEM M0_TRACE_SUBSYS_DTM
39 #include "lib/trace.h"
40 
41 M0_INTERNAL void m0_dtm_init(struct m0_dtm *dtm, struct m0_uint128 *id)
42 {
43  int i;
44 
45  dtm->d_id = *id;
46  m0_dtm_nu_init(&dtm->d_nu);
48  m0_dtm_fol_init(&dtm->d_fol, dtm);
49  exc_tlist_init(&dtm->d_excited);
50  for (i = 0; i < ARRAY_SIZE(dtm->d_cat); ++i)
52 }
53 
54 M0_INTERNAL void m0_dtm_fini(struct m0_dtm *dtm)
55 {
56  int i;
57 
58  for (i = 0; i < ARRAY_SIZE(dtm->d_cat); ++i)
60  exc_tlist_fini(&dtm->d_excited);
61  m0_dtm_fol_fini(&dtm->d_fol);
63  M0_PRE(m0_forall(i, ARRAY_SIZE(dtm->d_htype), dtm->d_htype[i] == NULL));
64  m0_dtm_nu_fini(&dtm->d_nu);
65 }
66 
67 M0_INTERNAL void m0_dtx_init(struct m0_dtx *tx,
68  struct m0_be_domain *be_domain,
69  struct m0_sm_group *sm_group)
70 {
71  M0_PRE(be_domain != NULL);
72 
73  m0_be_tx_init(&tx->tx_betx, 0, be_domain, sm_group,
74  NULL, NULL, NULL, NULL);
75  tx->tx_betx_cred = M0_BE_TX_CREDIT(0, 0);
76  tx->tx_state = M0_DTX_INIT;
78 }
79 
80 M0_INTERNAL void m0_dtx_prep(struct m0_dtx *tx,
81  const struct m0_be_tx_credit *cred)
82 {
83  m0_be_tx_prep(&tx->tx_betx, cred);
84 }
85 
86 M0_INTERNAL void m0_dtx_open(struct m0_dtx *tx)
87 {
88  M0_PRE(tx->tx_state == M0_DTX_INIT);
91  m0_be_tx_open(&tx->tx_betx);
92 }
93 
94 M0_INTERNAL void m0_dtx_opened(struct m0_dtx *tx)
95 {
96  M0_PRE(tx->tx_state == M0_DTX_INIT);
98  tx->tx_state = M0_DTX_OPEN;
99 }
100 
101 M0_INTERNAL int m0_dtx_open_sync(struct m0_dtx *tx)
102 {
103  int rc;
104 
105  m0_dtx_open(tx);
108  M0_TIME_NEVER);
109  if (m0_be_tx_state(&tx->tx_betx) == M0_BTS_ACTIVE)
110  m0_dtx_opened(tx);
111 
112  return M0_RC(rc);
113 }
114 
115 M0_INTERNAL void m0_dtx_done(struct m0_dtx *tx)
116 {
117  M0_PRE(M0_IN(tx->tx_state, (M0_DTX_INIT, M0_DTX_OPEN)));
118  m0_be_tx_close(&tx->tx_betx);
119  tx->tx_state = M0_DTX_DONE;
120 }
121 
122 M0_INTERNAL int m0_dtx_done_sync(struct m0_dtx *tx)
123 {
124  int rc;
125 
126  m0_dtx_done(tx);
128  M0_TIME_NEVER);
130 
131  return M0_RC(rc);
132 }
133 
134 M0_INTERNAL void m0_dtx_fini(struct m0_dtx *tx)
135 {
136  M0_PRE(M0_IN(tx->tx_state, (M0_DTX_INIT, M0_DTX_DONE)));
137  m0_be_tx_fini(&tx->tx_betx);
139  tx->tx_state = M0_DTX_INVALID;
140 }
141 
142 M0_INTERNAL int m0_dtm_global_init(void)
143 {
145  return m0_dtm_remote_global_init();
146 }
147 
148 M0_INTERNAL void m0_dtm_global_fini(void)
149 {
152 }
153 
154 M0_INTERNAL struct m0_dtm *nu_dtm(struct m0_dtm_nu *nu)
155 {
156  return container_of(nu, struct m0_dtm, d_nu);
157 }
158 
159 M0_INTERNAL void dtm_lock(struct m0_dtm *dtm)
160 {
161  nu_lock(&dtm->d_nu);
162 }
163 
164 M0_INTERNAL void dtm_unlock(struct m0_dtm *dtm)
165 {
166  nu_unlock(&dtm->d_nu);
167 }
168 
169 M0_INTERNAL int m0_dtx_fol_add(struct m0_dtx *tx)
170 {
171  return m0_be_tx_fol_add(&tx->tx_betx, &tx->tx_fol_rec);
172 }
173 
174 #undef M0_TRACE_SUBSYSTEM
175 
178 /*
179  * Local variables:
180  * c-indentation-style: "K&R"
181  * c-basic-offset: 8
182  * tab-width: 8
183  * fill-column: 80
184  * scroll-step: 1
185  * End:
186  */
uint64_t id
Definition: cob.h:2380
#define M0_PRE(cond)
Definition: dtm.h:554
M0_INTERNAL void m0_dtm_fini(struct m0_dtm *dtm)
Definition: dtm.c:54
#define NULL
Definition: misc.h:38
M0_INTERNAL void m0_fol_rec_fini(struct m0_fol_rec *rec)
Definition: fol.c:104
M0_INTERNAL int m0_be_tx_timedwait(struct m0_be_tx *tx, uint64_t states, m0_time_t deadline)
Definition: stubs.c:215
m0_be_tx_state
Definition: tx.h:214
const m0_time_t M0_TIME_NEVER
Definition: time.c:108
M0_INTERNAL int m0_dtm_global_init(void)
Definition: dtm.c:142
M0_INTERNAL void m0_be_tx_fini(struct m0_be_tx *tx)
Definition: stubs.c:163
M0_INTERNAL void m0_dtx_init(struct m0_dtx *tx, struct m0_be_domain *be_domain, struct m0_sm_group *sm_group)
Definition: dtm.c:67
M0_INTERNAL void m0_dtm_nuclei_init(void)
Definition: nucleus.c:528
M0_INTERNAL void m0_dtx_opened(struct m0_dtx *tx)
Definition: dtm.c:94
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_dtm * nu_dtm(struct m0_dtm_nu *nu)
Definition: dtm.c:154
struct m0_dtm_catalogue d_cat[M0_DTM_HISTORY_TYPE_NR]
Definition: dtm.h:541
#define M0_BITS(...)
Definition: misc.h:236
M0_INTERNAL void m0_dtm_catalogue_init(struct m0_dtm_catalogue *cat)
Definition: catalogue.c:44
#define container_of(ptr, type, member)
Definition: misc.h:33
M0_INTERNAL void dtm_lock(struct m0_dtm *dtm)
Definition: dtm.c:159
M0_INTERNAL void m0_dtm_remote_global_fini(void)
Definition: remote.c:209
M0_INTERNAL int m0_dtx_done_sync(struct m0_dtx *tx)
Definition: dtm.c:122
return M0_RC(rc)
struct m0_dtm_fol d_fol
Definition: dtm.h:542
#define M0_BE_TX_CREDIT(nr, size)
Definition: tx_credit.h:94
M0_INTERNAL void m0_fol_rec_init(struct m0_fol_rec *rec, struct m0_fol *fol)
Definition: fol.c:98
M0_INTERNAL void m0_dtm_history_type_register(struct m0_dtm *dtm, const struct m0_dtm_history_type *ht)
Definition: history.c:216
M0_INTERNAL const struct m0_dtm_history_type m0_dtm_fol_htype
Definition: fol.c:111
int i
Definition: dir.c:1033
M0_INTERNAL void m0_dtm_nu_init(struct m0_dtm_nu *nu)
Definition: nucleus.c:365
M0_INTERNAL int m0_dtx_fol_add(struct m0_dtx *tx)
Definition: dtm.c:169
M0_INTERNAL void m0_dtx_open(struct m0_dtx *tx)
Definition: dtm.c:86
#define M0_ASSERT(cond)
struct m0_uint128 d_id
Definition: dtm.h:540
static void nu(void)
Definition: nucleus.c:87
struct m0_dtm_nu d_nu
Definition: dtm.h:533
M0_INTERNAL void m0_dtm_fol_init(struct m0_dtm_fol *fol, struct m0_dtm *dtm)
Definition: fol.c:46
struct m0_be_tx_credit tx_betx_cred
Definition: dtm.h:560
M0_INTERNAL void m0_be_tx_close(struct m0_be_tx *tx)
Definition: stubs.c:194
M0_INTERNAL void m0_dtm_catalogue_fini(struct m0_dtm_catalogue *cat)
Definition: catalogue.c:49
M0_INTERNAL void m0_dtx_fini(struct m0_dtx *tx)
Definition: dtm.c:134
const struct m0_dtm_history_type * d_htype[M0_DTM_HISTORY_TYPE_NR]
Definition: dtm.h:544
struct m0_fol_rec tx_fol_rec
Definition: dtm.h:561
M0_INTERNAL void nu_lock(struct m0_dtm_nu *nu)
Definition: nucleus.c:538
M0_INTERNAL void m0_dtm_history_type_deregister(struct m0_dtm *dtm, const struct m0_dtm_history_type *ht)
Definition: history.c:225
M0_INTERNAL void m0_dtx_done(struct m0_dtx *tx)
Definition: dtm.c:115
struct m0_tl d_excited
Definition: dtm.h:543
M0_INTERNAL void m0_dtm_nuclei_fini(void)
Definition: nucleus.c:534
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
#define m0_forall(var, nr,...)
Definition: misc.h:112
M0_INTERNAL void nu_unlock(struct m0_dtm_nu *nu)
Definition: nucleus.c:543
M0_INTERNAL void m0_dtm_init(struct m0_dtm *dtm, struct m0_uint128 *id)
Definition: dtm.c:41
M0_INTERNAL void m0_dtm_global_fini(void)
Definition: dtm.c:148
struct m0_be_tx tx_betx
Definition: dtm.h:559
M0_INTERNAL void m0_be_tx_open(struct m0_be_tx *tx)
Definition: stubs.c:184
M0_INTERNAL void dtm_unlock(struct m0_dtm *dtm)
Definition: dtm.c:164
enum m0_dtx_state tx_state
Definition: dtm.h:558
M0_INTERNAL int m0_dtx_open_sync(struct m0_dtx *tx)
Definition: dtm.c:101
Definition: dtm.h:529
M0_INTERNAL void m0_dtm_nu_fini(struct m0_dtm_nu *nu)
Definition: nucleus.c:370
int m0_be_tx_fol_add(struct m0_be_tx *tx, struct m0_fol_rec *rec)
Definition: stubs.c:295
M0_INTERNAL int m0_dtm_remote_global_init(void)
Definition: remote.c:195
int32_t rc
Definition: trigger_fop.h:47
#define ARRAY_SIZE(a)
Definition: misc.h:45
M0_INTERNAL void m0_dtm_fol_fini(struct m0_dtm_fol *fol)
Definition: fol.c:56
M0_INTERNAL void m0_dtx_prep(struct m0_dtx *tx, const struct m0_be_tx_credit *cred)
Definition: dtm.c:80