Motr  M0
load.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 
23 
24 #define M0_TRACE_SUBSYSTEM M0_TRACE_SUBSYS_UT
25 #include "lib/trace.h"
26 
27 #include "lib/memory.h" /* M0_ALLOC_PTR */
28 #include "lib/errno.h"
29 #include "lib/locality.h" /* m0_locality0_get */
30 #include "lib/misc.h" /* M0_QUOTE */
31 #include "lib/string.h"
32 #include "lib/finject.h"
33 #include "ut/ut.h"
34 #include "conf/confd_stob.h"
35 #include "conf/flip_fom.h"
36 #include "conf/flip_fop.h"
37 #include "conf/load_fom.h"
38 #include "conf/load_fop.h"
39 #include "reqh/reqh.h" /* m0_reqh */
40 #include "fop/fop.h" /* m0_fop */
41 #include "fop/fom.h" /* m0_fom */
42 #include "rpc/rpc_machine.h" /* m0_rpc_machine */
43 #include "sm/sm.h"
45 
46 #define STR_LEN 1000
47 
55  struct m0_reqh cur_reqh;
57 };
58 
60 
61 
62 extern const struct m0_fom_ops conf_load_fom_ops;
63 extern const struct m0_fom_ops conf_flip_fom_ops;
64 
65 static void conf_fop_ut_release(struct m0_ref *ref)
66 {
67  struct m0_fop *fop;
68 
69  fop = M0_AMB(fop, ref, f_ref);
70  m0_free(fop);
71 }
72 
78 static void conf_load_fom_create_fail(void)
79 {
80  int rc;
81  struct m0_fop *fop;
82  struct m0_fom *fom;
83  struct m0_reqh *reqh;
84 
86  M0_UT_ASSERT(fop != NULL);
88  M0_UT_ASSERT(fom != NULL);
91 
95 
96  m0_fi_enable_once("m0_alloc", "fail_allocation");
98  M0_UT_ASSERT(rc == -ENOMEM);
99 
100  m0_fi_enable_off_n_on_m("m0_alloc", "fail_allocation", 1, 1);
102  m0_fi_disable("m0_alloc", "fail_allocation");
103  M0_UT_ASSERT(rc == -ENOMEM);
104 
105  m0_free(fop);
106  m0_free(fom);
107  m0_free(reqh);
108 }
109 
115 static void conf_flip_fom_create_fail(void)
116 {
117  int rc;
118  struct m0_fop *fop;
119  struct m0_fom *fom;
120  struct m0_reqh *reqh;
121 
122  M0_ALLOC_PTR(fop);
123  M0_ALLOC_PTR(fom);
125 
129 
130  m0_fi_enable_once("m0_alloc", "fail_allocation");
132  M0_UT_ASSERT(rc == -ENOMEM);
133 
134  m0_fi_enable_off_n_on_m("m0_alloc", "fail_allocation", 1, 1);
136  m0_fi_disable("m0_alloc", "fail_allocation");
137  M0_UT_ASSERT(rc == -ENOMEM);
138 
139  m0_free(fop);
140  m0_free(fom);
141  m0_free(reqh);
142 }
143 
149 static void conf_save_load(void)
150 {
151  struct m0_stob *stob;
152  char linux_location[] = "linuxstob:./__s";
153  struct m0_fid confd_fid = M0_CONFD_FID(1, 2, 12345);
154  int rc;
155  char *str_write;
156  char *str_read;
157  int i;
158 
159  rc = m0_confd_stob_init(&stob, linux_location, &confd_fid);
160  M0_UT_ASSERT(rc == 0);
161 
163  for (i = 0; i < STR_LEN; ++i)
164  str_write[i] = '0' + (i % 10);
165  str_write[STR_LEN - 1] = 0;
166 
167  rc = m0_confd_stob_write(stob, str_write);
168  M0_UT_ASSERT(rc == 0);
169 
170  rc = m0_confd_stob_read(stob, &str_read);
171  M0_UT_ASSERT(rc == 0);
172  M0_UT_ASSERT(strcmp(str_write, str_read) == 0);
173 
176 
178  M0_UT_ASSERT(rc == 0);
179 
181 }
182 
188 static void conf_save_load_fail(void)
189 {
190  struct m0_stob *stob;
191  char linux_location[] = "linuxstob:./__s";
192  char fail_location[] = "fail_location";
193  struct m0_fid confd_fid = M0_CONFD_FID(1, 2, 12345);
194  int rc;
195  char *str_write;
196  char *str_read;
197  int i;
198 
199  /* Test create fail*/
200  rc = m0_confd_stob_init(&stob, fail_location, &confd_fid);
201  M0_UT_ASSERT(rc == -EINVAL);
202 
203  rc = m0_confd_stob_init(&stob, linux_location, &confd_fid);
204  M0_UT_ASSERT(rc == 0);
205 
206  /* test save fail */
208  for (i = 0; i < STR_LEN; ++i)
209  str_write[i] = '0' + (i % 10);
210  str_write[STR_LEN - 1] = 0;
211 
212  rc = m0_confd_stob_write(stob, str_write);
213  M0_UT_ASSERT(rc == 0);
214 
215  /* test load fail */
216  m0_fi_enable_once("m0_alloc_aligned", "fail_allocation");
217  rc = m0_confd_stob_read(stob, &str_read);
218  M0_UT_ASSERT(rc == -ENOMEM);
219 
220  m0_fi_enable_off_n_on_m("m0_alloc", "fail_allocation", 0, 1);
221  rc = m0_confd_stob_read(stob, &str_read);
222  m0_fi_disable("m0_alloc", "fail_allocation");
223  M0_UT_ASSERT(rc == -ENOMEM);
224 
225  rc = m0_confd_stob_read(stob, &str_read);
226  M0_UT_ASSERT(rc == 0);
227  M0_UT_ASSERT(strcmp(str_write, str_read) == 0);
228 
229  /* Finish */
232 
234  M0_UT_ASSERT(rc == 0);
235 
237 }
238 
243  const char *ep_addr)
244 {
246  enum { NR_TMS = 1 };
247  int rc;
248 
251  if (rc != 0)
252  return rc;
253 
258  NR_TMS),
259  NR_TMS);
260  if (rc != 0)
261  goto net;
262 
264  .rhia_dtm = (void *)1,
265  .rhia_mdstore = (void *)1,
266  .rhia_fid = &g_process_fid);
267  if (rc != 0)
268  goto buf_pool;
270 
277 
278  if (rc == 0) {
279  return 0;
280  }
281 buf_pool:
283 net:
285  return rc;
286 }
287 
292 {
298 }
299 
303 static int conf_load_ut_init()
304 {
305  int rc;
306  const char *ep = SERVER_ENDPOINT_ADDR;
307 
310  M0_UT_ASSERT(rc == 0);
311  return 0;
312 }
313 
317 static int conf_load_ut_fini()
318 {
321  return 0;
322 }
323 
325  .ts_name = "conf-load-ut",
326  .ts_init = conf_load_ut_init,
327  .ts_fini = conf_load_ut_fini,
328  .ts_tests = {
329  { "load-fom-create-fail", conf_load_fom_create_fail },
330  { "flip-fom-create-fail", conf_flip_fom_create_fail },
331  { "confd-save-load", conf_save_load },
332  { "confd-save-load-fail", conf_save_load_fail },
333  { NULL, NULL },
334  },
335 };
336 M0_EXPORTED(conf_load_ut);
337 
338 #undef M0_TRACE_SUBSYSTEM
339 
340 /*
341  * Local variables:
342  * c-indentation-style: "K&R"
343  * c-basic-offset: 8
344  * tab-width: 8
345  * fill-column: 80
346  * scroll-step: 1
347  * End:
348  */
#define M0_CONFD_FID(old_version, new_version, tx_id)
Definition: confd_stob.h:39
void m0_rpc_machine_fini(struct m0_rpc_machine *machine)
Definition: rpc_machine.c:233
M0_INTERNAL void m0_reqh_services_terminate(struct m0_reqh *reqh)
Definition: reqh.c:675
void m0_net_domain_fini(struct m0_net_domain *dom)
Definition: domain.c:71
#define NULL
Definition: misc.h:38
static void conf_ut_reqh_fini(struct m0_conf_ut_reqh *conf_reqh)
Definition: load.c:291
static const char * ep_addr
Definition: rpc_machine.c:35
#define M0_REQH_INIT(reqh,...)
Definition: reqh.h:262
M0_INTERNAL void m0_fop_init(struct m0_fop *fop, struct m0_fop_type *fopt, void *data, void(*fop_release)(struct m0_ref *))
Definition: fop.c:79
M0_INTERNAL void m0_free_aligned(void *data, size_t size, unsigned shift)
Definition: memory.c:192
#define M0_SET0(obj)
Definition: misc.h:64
Definition: ut.h:77
M0_INTERNAL void m0_reqh_fini(struct m0_reqh *reqh)
Definition: reqh.c:320
static void conf_save_load_fail(void)
Definition: load.c:188
M0_INTERNAL uint32_t m0_stob_block_shift(struct m0_stob *stob)
Definition: stob.c:270
struct m0_fop_type m0_fop_conf_load_fopt
Definition: fop.c:58
Definition: sock.c:754
#define STR_LEN
Definition: load.c:46
int i
Definition: dir.c:1033
void m0_confd_stob_fini(struct m0_stob *stob)
Definition: confd_stob.c:104
static int conf_ut_reqh_init(struct m0_conf_ut_reqh *conf_reqh, const char *ep_addr)
Definition: load.c:242
#define M0_AMB(obj, ptr, field)
Definition: misc.h:320
Definition: refs.h:34
M0_INTERNAL void m0_fi_disable(const char *fp_func, const char *fp_tag)
Definition: finject.c:485
Definition: stob.h:163
static struct m0_stob * stob
Definition: storage.c:39
static void conf_flip_fom_create_fail(void)
Definition: load.c:115
M0_INTERNAL int m0_rpc_net_buffer_pool_setup(struct m0_net_domain *ndom, struct m0_net_buffer_pool *app_pool, uint32_t bufs_nr, uint32_t tm_nr)
Definition: rpc.c:229
const struct m0_fom_ops conf_flip_fom_ops
Definition: flip_fom.c:63
struct m0_net_domain cur_net_dom
Definition: load.c:53
M0_INTERNAL uint32_t m0_rpc_bufs_nr(uint32_t len, uint32_t tms_nr)
Definition: rpc.c:271
int m0_confd_stob_init(struct m0_stob **stob, const char *location, struct m0_fid *confd_fid)
Definition: confd_stob.c:50
M0_INTERNAL int m0_rpc_machine_init(struct m0_rpc_machine *machine, struct m0_net_domain *net_dom, const char *ep_addr, struct m0_reqh *reqh, struct m0_net_buffer_pool *receive_pool, uint32_t colour, m0_bcount_t msg_size, uint32_t queue_len)
Definition: rpc_machine.c:123
struct m0_net_xprt * m0_net_xprt_default_get(void)
Definition: net.c:151
Definition: reqh.h:94
Definition: dump.c:103
int m0_confd_stob_write(struct m0_stob *stob, char *str)
Definition: confd_stob.c:168
static void conf_load_fom_create_fail(void)
Definition: load.c:78
static void m0_fi_enable_off_n_on_m(const char *func, const char *tag, uint32_t n, uint32_t m)
Definition: finject.h:346
struct m0_net_buffer_pool cur_buf_pool
Definition: load.c:54
Definition: fom.h:481
M0_INTERNAL int m0_stob_domain_destroy_location(const char *location)
Definition: domain.c:242
const char * ts_name
Definition: ut.h:99
M0_INTERNAL void m0_reqh_start(struct m0_reqh *reqh)
Definition: reqh.c:711
struct m0_conf_ut_reqh * conf_reqh
Definition: load.c:59
struct m0_reqh reqh
Definition: rm_foms.c:48
int m0_net_domain_init(struct m0_net_domain *dom, const struct m0_net_xprt *xprt)
Definition: domain.c:36
static void conf_save_load(void)
Definition: load.c:149
struct m0_ref f_ref
Definition: fop.h:80
Definition: fid.h:38
#define M0_ALLOC_PTR(ptr)
Definition: memory.h:86
static int conf_load_ut_fini()
Definition: load.c:317
struct m0_rpc_machine cur_rmachine
Definition: load.c:56
struct m0_fop_type m0_fop_conf_flip_fopt
Definition: fop.c:67
static struct m0_fop * fop
Definition: item.c:57
static void m0_fi_enable_once(const char *func, const char *tag)
Definition: finject.h:301
static void conf_fop_ut_release(struct m0_ref *ref)
Definition: load.c:65
static struct m0_addb2_net * net
Definition: net.c:27
static struct m0_net_buffer_pool * buf_pool
Definition: bulkio_ut.c:261
#define SERVER_ENDPOINT_ADDR
Definition: common.h:30
int m0_confd_stob_read(struct m0_stob *stob, char **str)
Definition: confd_stob.c:135
static int conf_load_ut_init()
Definition: load.c:303
struct m0_reqh cur_reqh
Definition: load.c:55
struct m0_net_xprt * xprt
Definition: module.c:61
void m0_rpc_net_buffer_pool_cleanup(struct m0_net_buffer_pool *app_pool)
Definition: rpc.c:264
M0_INTERNAL void * m0_alloc_aligned(size_t size, unsigned shift)
Definition: memory.c:168
struct m0_rpc_machine * ri_rmachine
Definition: item.h:160
const struct m0_fom_ops conf_load_fom_ops
Definition: load_fom.c:50
void m0_free(void *data)
Definition: memory.c:146
struct m0_ut_suite conf_load_ut
Definition: load.c:324
M0_INTERNAL int m0_conf_flip_fom_create(struct m0_fop *fop, struct m0_fom **out, struct m0_reqh *reqh)
Definition: flip_fom.c:121
struct m0_rpc_item f_item
Definition: fop.h:83
int32_t rc
Definition: trigger_fop.h:47
struct m0_fid g_process_fid
Definition: ut.c:689
#define M0_UT_ASSERT(a)
Definition: ut.h:46
Definition: fop.h:79
static const char linux_location[]
Definition: adieu.c:63
M0_INTERNAL int m0_conf_load_fom_create(struct m0_fop *fop, struct m0_fom **out, struct m0_reqh *reqh)
Definition: load_fom.c:119