Motr  M0
helper.h
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 
23 #pragma once
24 #ifndef __MOTR_BE_UT_HELPER_H__
25 #define __MOTR_BE_UT_HELPER_H__
26 
27 #include "lib/types.h" /* bool */
28 #include "lib/buf.h" /* m0_buf */
29 #include "lib/memory.h" /* M0_ALLOC_PTR */
30 #include "sm/sm.h" /* m0_sm */
31 
32 #include "be/domain.h" /* m0_be_domain */
33 #include "be/seg.h" /* m0_be_seg */
34 #include "be/seg0.h" /* m0_be_0type */
35 #include "lib/bob.h" /* M0_BOB_DEFINE */
36 
37 enum {
38  BE_UT_SEG_START_ADDR = 0x400000000000ULL,
41 };
42 
44 struct m0_stob;
45 
48  /* XXX DELETEME
49  * Make sure that ->but_dom_cfg is not needed for m0_be_domain
50  * initialisation and delete it.
51  * See https://seagate.slack.com/archives/motr/p1424896669000401
52  */
55  size_t but_sgt_size;
59  uint64_t but_magix;
60 };
61 
62 extern const struct m0_bob_type m0_ut_be_backend_bobtype;
63 M0_BOB_DECLARE(M0_INTERNAL, m0_be_ut_backend);
64 
65 /*
66  * Fill cfg with default configuration.
67  * @note bec_reqh is not set here
68  */
70 
73 
74 M0_INTERNAL int m0_be_ut_backend_init_cfg(struct m0_be_ut_backend *ut_be,
75  const struct m0_be_domain_cfg *cfg,
76  bool mkfs);
77 
78 M0_INTERNAL int
80  const struct m0_be_domain_cfg *cfg);
81 
82 M0_INTERNAL void
85  bool preallocate,
86  const char *stob_create_cfg,
87  struct m0_be_seg **out);
88 M0_INTERNAL void
90  const struct m0_be_0type_seg_cfg *seg_cfg,
91  struct m0_be_seg **out);
92 M0_INTERNAL void
94  struct m0_be_seg *seg);
95 
96 M0_INTERNAL void m0_be_ut_reqh_create(struct m0_reqh **pptr);
97 M0_INTERNAL void m0_be_ut_reqh_destroy(void);
98 
99 struct m0_sm_group *
101 
102 /*
103  * Runs asts for the current backend sm group.
104  * Waits until at least all asts which were in queue before function call
105  * are complete.
106  */
107 M0_INTERNAL void
109 
111  bool unlocked_new);
112 
114 
115 /* will work with single thread only */
116 void m0_be_ut_tx_init(struct m0_be_tx *tx, struct m0_be_ut_backend *ut_be);
117 
118 struct m0_be_ut_seg {
121 };
122 
124  struct m0_be_ut_backend *ut_be,
125  m0_bcount_t size);
128 
129 M0_INTERNAL void *m0_be_ut_seg_allocate_addr(m0_bcount_t size);
130 M0_INTERNAL uint64_t m0_be_ut_seg_allocate_id(void);
131 
132 /* m0_be_allocator_{init,create,open} */
134  struct m0_be_ut_backend *ut_be);
135 /* m0_be_allocator_{close,destroy,fini} */
137  struct m0_be_ut_backend *ut_be);
138 
139 M0_INTERNAL void m0_be_ut_alloc(struct m0_be_ut_backend *ut_be,
140  struct m0_be_ut_seg *ut_seg,
141  void **ptr,
142  m0_bcount_t size);
143 M0_INTERNAL void m0_be_ut_free(struct m0_be_ut_backend *ut_be,
144  struct m0_be_ut_seg *ut_seg,
145  void *ptr);
146 
147 #define M0_BE_UT_ALLOC_PTR(ut_be, ut_seg, ptr) \
148  m0_be_ut_alloc((ut_be), (ut_seg), \
149  (void **) &(ptr), sizeof(*(ptr)))
150 
151 #define M0_BE_UT_FREE_PTR(ut_be, ut_seg, ptr) \
152  m0_be_ut_free((ut_be), (ut_seg), (ptr))
153 
159 #define M0_BE_UT_TRANSACT(__ut_be, __tx, __cred, __credit_func, __action_func) \
160  do { \
161  struct m0_be_tx_credit __cred = {}; \
162  struct m0_be_tx *__tx; \
163  int __rc; \
164  \
165  M0_ALLOC_PTR(__tx); \
166  M0_ASSERT(__tx != NULL); \
167  m0_be_ut_tx_init(__tx, (__ut_be)); \
168  __credit_func; \
169  m0_be_tx_prep(__tx, &__cred); \
170  __rc = m0_be_tx_open_sync(__tx); \
171  M0_ASSERT_INFO(__rc == 0, "__rc = %d", __rc); \
172  if (__rc == 0) { \
173  __action_func; \
174  m0_be_tx_close_sync(__tx); \
175  } \
176  m0_be_tx_fini(__tx); \
177  m0_free(__tx); \
178  } while (0)
179 
180 #endif /* __MOTR_BE_UT_HELPER_H__ */
181 
182 /*
183  * Local variables:
184  * c-indentation-style: "K&R"
185  * c-basic-offset: 8
186  * tab-width: 8
187  * fill-column: 80
188  * scroll-step: 1
189  * End:
190  */
191 /*
192  * vim: tabstop=8 shiftwidth=8 noexpandtab textwidth=80 nowrap
193  */
void m0_be_ut_tx_init(struct m0_be_tx *tx, struct m0_be_ut_backend *ut_be)
Definition: stubs.c:286
static void ptr(struct m0_addb2__context *ctx, const uint64_t *v, char *buf)
Definition: dump.c:440
void m0_be_ut_seg_reload(struct m0_be_ut_seg *ut_seg)
Definition: stubs.c:272
void m0_be_ut_backend_fini(struct m0_be_ut_backend *ut_be)
Definition: stubs.c:242
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
void m0_be_ut_seg_fini(struct m0_be_ut_seg *ut_seg)
Definition: stubs.c:267
void m0_be_ut_backend_thread_exit(struct m0_be_ut_backend *ut_be)
Definition: stubs.c:282
struct m0_be_seg * bus_seg
Definition: helper.h:119
struct m0_mutex but_sgt_lock
Definition: helper.h:56
void m0_be_ut_backend_init(struct m0_be_ut_backend *ut_be)
Definition: stubs.c:238
char * but_stob_domain_location
Definition: helper.h:58
M0_INTERNAL uint64_t m0_be_ut_seg_allocate_id(void)
Definition: helper.c:124
M0_INTERNAL void m0_be_ut_free(struct m0_be_ut_backend *ut_be, struct m0_be_ut_seg *ut_seg, void *ptr)
Definition: stubs.c:308
struct m0_be_ut_seg ut_seg
Definition: ad.c:73
M0_INTERNAL void m0_be_ut_reqh_destroy(void)
Definition: helper.c:169
uint64_t but_magix
Definition: helper.h:59
uint64_t m0_bcount_t
Definition: types.h:77
M0_INTERNAL void m0_be_ut_alloc(struct m0_be_ut_backend *ut_be, struct m0_be_ut_seg *ut_seg, void **ptr, m0_bcount_t size)
Definition: stubs.c:300
bool but_sm_groups_unlocked
Definition: helper.h:57
const struct m0_bob_type m0_ut_be_backend_bobtype
Definition: helper.c:49
void m0_be_ut_seg_allocator_fini(struct m0_be_ut_seg *ut_seg, struct m0_be_ut_backend *ut_be)
Definition: stubs.c:251
M0_INTERNAL void m0_be_ut_backend_seg_add(struct m0_be_ut_backend *ut_be, const struct m0_be_0type_seg_cfg *seg_cfg, struct m0_be_seg **out)
Definition: helper.c:455
struct m0_be_ut_backend ut_be
Definition: ad.c:72
Definition: stob.h:163
M0_INTERNAL int m0_be_ut_backend_log_resize(struct m0_be_ut_backend *ut_be, const struct m0_be_domain_cfg *cfg)
Definition: helper.c:405
void m0_be_ut_backend_cfg_default(struct m0_be_domain_cfg *cfg)
Definition: stubs.c:227
struct m0_be_ut_sm_group_thread ** but_sgt
Definition: helper.h:54
M0_INTERNAL void * m0_be_ut_seg_allocate_addr(m0_bcount_t size)
Definition: helper.c:107
struct m0_be_ut_backend * bus_backend
Definition: helper.h:120
Definition: reqh.h:94
Definition: seg.h:66
struct m0_be_domain but_dom
Definition: helper.h:47
M0_INTERNAL void m0_be_ut_backend_seg_add2(struct m0_be_ut_backend *ut_be, m0_bcount_t size, bool preallocate, const char *stob_create_cfg, struct m0_be_seg **out)
Definition: helper.c:466
M0_INTERNAL void m0_be_ut_reqh_create(struct m0_reqh **pptr)
Definition: helper.c:142
struct m0_sm_group * m0_be_ut_backend_sm_group_lookup(struct m0_be_ut_backend *ut_be)
Definition: stubs.c:277
size_t but_sgt_size
Definition: helper.h:55
struct m0_be_domain_cfg but_dom_cfg
Definition: helper.h:53
M0_INTERNAL void m0_be_ut_backend_sm_group_asts_run(struct m0_be_ut_backend *ut_be)
Definition: helper.c:572
void m0_be_ut_seg_init(struct m0_be_ut_seg *ut_seg, struct m0_be_ut_backend *ut_be, m0_bcount_t size)
Definition: stubs.c:256
m0_bcount_t size
Definition: di.c:39
void m0_be_ut_backend_new_grp_lock_state_set(struct m0_be_ut_backend *ut_be, bool unlocked_new)
Definition: helper.c:584
static struct m0_be_seg * seg
Definition: btree.c:40
#define out(...)
Definition: gen.c:41
Definition: mutex.h:47
M0_INTERNAL void m0_be_ut_backend_seg_del(struct m0_be_ut_backend *ut_be, struct m0_be_seg *seg)
Definition: helper.c:483
void m0_be_ut_seg_allocator_init(struct m0_be_ut_seg *ut_seg, struct m0_be_ut_backend *ut_be)
Definition: stubs.c:246
M0_BOB_DECLARE(M0_INTERNAL, m0_be_ut_backend)
Definition: tx.h:280