Motr  M0
active_record.c
Go to the documentation of this file.
1 /* -*- C -*- */
2 /*
3  * Copyright (c) 2011-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 #include "ut/ut.h"
24 #include "lib/misc.h"
25 #include "lib/memory.h"
26 #include "reqh/reqh.h"
27 #include "be/ut/helper.h"
28 #include "be/active_record.h"
29 #include "module/instance.h"
30 
31 static struct m0_be_seg *seg0;
32 static struct m0_be_ut_backend ut_be;
36 
37 
38 static void ut_tx_open(struct m0_be_tx *tx, struct m0_be_tx_credit *credit)
39 {
40  int rc;
41 
42  m0_be_ut_tx_init(tx, &ut_be);
43  m0_be_tx_prep(tx, credit);
45  M0_UT_ASSERT(rc == 0);
47 }
48 
49 /*
50  * 1. Create data structures, store them on disk.
51  * 2. Then, load them back from disk
52  */
53 static void actrec_mkfs(void)
54 {
55  struct m0_be_tx tx_;
56  struct m0_be_tx *tx = &tx_;
57  struct m0_be_tx_credit accum = {};
58  int rc;
59 
60  M0_SET0(&ut_be);
63  dummy.ard_seg = seg0;
64 
66  ut_tx_open(tx, &accum);
68  M0_BUF_INITS("xxx"),
69  M0_BUF_INITS("yyy"),
70  M0_BUF_INITS("zzz"));
71  M0_UT_ASSERT(rc == 0);
72 
74  M0_UT_ASSERT(rc == 0);
75 
77  m0_be_tx_fini(tx);
78 
81 
83 }
84 
85 static void actrec_init(void)
86 {
87  struct m0_reqh *reqh;
88  struct m0_be_seg *seg0;
89 
90  M0_SET0(&ut_be);
92 
94  dom = m0_reqh_lockers_get(reqh, m0_get()->i_actrec_dom_key);
95  M0_UT_ASSERT(dom != NULL);
97 
100 }
101 
102 static void actrec_fini(void)
103 {
104  struct m0_be_tx tx_;
105  struct m0_be_tx *tx = &tx_;
106  struct m0_be_tx_credit accum = {};
107  int rc;
108 
110  ut_tx_open(tx, &accum);
112  M0_UT_ASSERT(rc == 0);
114  m0_be_tx_fini(tx);
115 
117 }
118 
119 static void actrec_case(void)
120 {
121  struct m0_be_tx tx_;
122  struct m0_be_tx *tx = &tx_;
123  struct m0_be_tx_credit create = {};
124  struct m0_be_tx_credit destroy = {};
125  struct m0_be_tx_credit add = {};
126  struct m0_be_tx_credit del = {};
127  struct m0_be_tx_credit accum = {};
128  struct m0_be_active_record dummy = { .ar_dom = dom };
129  struct m0_be_active_record *rec1;
130  struct m0_be_active_record *rec2;
131  struct m0_be_active_record *rec3;
132  int rc;
133 
135  m0_be_tx_credit_mac(&accum, &create, 3);
136 
138  m0_be_tx_credit_mac(&accum, &add, 3);
139 
141  m0_be_tx_credit_mac(&accum, &del, 3);
142 
144  m0_be_tx_credit_mac(&accum, &destroy, 3);
145 
146  ut_tx_open(tx, &accum);
147 
148  rc =
149  m0_be_active_record_create(&rec1, tx, dom) ?:
150  m0_be_active_record_create(&rec2, tx, dom) ?:
151  m0_be_active_record_create(&rec3, tx, dom) ?:
152 
153  m0_be_active_record_add("xxx", rec1, tx) ?:
154  m0_be_active_record_add("yyy", rec2, tx) ?:
155  m0_be_active_record_add("xxx", rec3, tx) ?:
156 
157  m0_be_active_record_del("xxx", rec1, tx) ?:
158  m0_be_active_record_del("yyy", rec2, tx) ?:
159  m0_be_active_record_del("xxx", rec3, tx) ?:
160 
161  m0_be_active_record_destroy(rec1, tx) ?:
162  m0_be_active_record_destroy(rec2, tx) ?:
163  m0_be_active_record_destroy(rec3, tx);
164 
165  M0_UT_ASSERT(rc == 0);
166 
168  m0_be_tx_fini(tx);
169 }
170 
172 {
173  actrec_mkfs();
174  actrec_init();
175  actrec_case();
176  actrec_fini();
177 }
178 
179 /*
180  * Local variables:
181  * c-indentation-style: "K&R"
182  * c-basic-offset: 8
183  * tab-width: 8
184  * fill-column: 80
185  * scroll-step: 1
186  * End:
187  */
static struct m0_be_active_record_domain dummy
Definition: active_record.c:35
M0_INTERNAL int m0_be_ut_backend_init_cfg(struct m0_be_ut_backend *ut_be, const struct m0_be_domain_cfg *cfg, bool mkfs)
Definition: stubs.c:231
#define NULL
Definition: misc.h:38
M0_INTERNAL bool m0_be_active_record_domain__invariant(struct m0_be_active_record_domain *dom)
m0_be_tx_state
Definition: tx.h:214
M0_INTERNAL void m0_be_tx_fini(struct m0_be_tx *tx)
Definition: stubs.c:163
static void create(void)
Definition: service_ut.c:546
M0_INTERNAL void m0_be_active_record_domain_fini(struct m0_be_active_record_domain *dom)
M0_INTERNAL void m0_be_active_record_domain_init(struct m0_be_active_record_domain *dom, struct m0_be_seg *seg)
Definition: active_record.c:98
M0_INTERNAL struct m0_be_seg * m0_be_domain_seg0_get(struct m0_be_domain *dom)
Definition: domain.c:466
static struct m0_be_ut_backend ut_be
Definition: active_record.c:32
M0_INTERNAL int m0_be_active_record_del(const char *subsys, struct m0_be_active_record *rec, struct m0_be_tx *tx)
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
void m0_be_ut_actrec_test(void)
static struct m0_be_active_record_domain * dom_created
Definition: active_record.c:33
#define M0_SET0(obj)
Definition: misc.h:64
M0_INTERNAL void m0_be_active_record_credit(struct m0_be_active_record *rec, enum m0_be_active_record_op op, struct m0_be_tx_credit *accum)
struct m0_reqh * bec_reqh
Definition: engine.h:84
M0_INTERNAL int m0_be_active_record_destroy(struct m0_be_active_record *rec, struct m0_be_tx *tx)
static void actrec_mkfs(void)
Definition: active_record.c:53
static struct m0_be_active_record_domain * dom
Definition: active_record.c:34
static void del(void)
Definition: client_ut.c:3157
M0_INTERNAL int m0_be_active_record_add(const char *subsys, struct m0_be_active_record *rec, struct m0_be_tx *tx)
M0_INTERNAL void m0_be_tx_credit_mac(struct m0_be_tx_credit *c, const struct m0_be_tx_credit *c1, m0_bcount_t k)
Definition: tx_credit.c:88
static void ut_tx_open(struct m0_be_tx *tx, struct m0_be_tx_credit *credit)
Definition: active_record.c:38
M0_INTERNAL int m0_be_tx_exclusive_open_sync(struct m0_be_tx *tx)
Definition: tx.c:594
static void actrec_fini(void)
#define M0_BUF_INITS(str)
Definition: buf.h:70
Definition: reqh.h:94
Definition: seg.h:66
M0_INTERNAL void m0_be_active_record_domain_credit(struct m0_be_active_record_domain *dom, enum m0_be_active_record_domain_op op, uint8_t subsys_nr, struct m0_be_tx_credit *accum)
struct m0_be_domain but_dom
Definition: helper.h:47
static void actrec_case(void)
static void actrec_init(void)
Definition: active_record.c:85
struct m0_be_domain_cfg but_dom_cfg
Definition: helper.h:53
struct m0_reqh reqh
Definition: rm_foms.c:48
M0_INTERNAL int m0_be_active_record_domain_destroy(struct m0_be_active_record_domain *dom, struct m0_be_tx *tx)
#define m0_be_active_record_domain_create(dom, tx, seg,...)
void m0_be_ut_tx_init(struct m0_be_tx *tx, struct m0_be_ut_backend *ut_be)
Definition: stubs.c:286
static struct m0_be_seg * seg0
Definition: active_record.c:31
void m0_be_ut_backend_fini(struct m0_be_ut_backend *ut_be)
Definition: stubs.c:242
struct m0_be_engine_cfg bc_engine
Definition: domain.h:79
struct m0_be_seg * ard_seg
Definition: active_record.h:73
int32_t rc
Definition: trigger_fop.h:47
#define M0_UT_ASSERT(a)
Definition: ut.h:46
M0_INTERNAL void m0_be_tx_close_sync(struct m0_be_tx *tx)
Definition: stubs.c:205
Definition: tx.h:280
M0_INTERNAL int m0_be_active_record_create(struct m0_be_active_record **rec, struct m0_be_tx *tx, struct m0_be_active_record_domain *ar_dom)
static void add(struct m0_addb2_mach *mach, uint64_t id, int n, const uint64_t *value)
Definition: addb2.c:934