Motr  M0
adieu.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011-2020 Seagate Technology LLC and/or its Affiliates
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  * For any questions about this software or licensing,
17  * please email opensource@seagate.com or cortx-questions@seagate.com.
18  *
19  */
20 
21 
22 #include <stdlib.h> /* system */
23 #include <stdio.h> /* fopen, fgetc, ... */
24 #include <unistd.h> /* unlink */
25 #include <sys/stat.h> /* mkdir */
26 #include <sys/types.h> /* mkdir */
27 
28 #include "lib/misc.h" /* M0_SET0 */
29 #include "lib/memory.h" /* m0_alloc_align */
30 #include "lib/errno.h"
31 #include "lib/finject.h" /* M0_FI_ENABLED */
32 #include "lib/ub.h"
33 #include "ut/stob.h"
34 #include "ut/ut.h"
35 #include "lib/assert.h"
36 #include "lib/arith.h"
37 #include "stob/domain.h"
38 #include "stob/io.h"
39 #include "stob/stob.h"
40 #include "fol/fol.h"
41 #include "balloc/balloc.h" /* M0_BALLOC_NON_SPARE_ZONE */
42 
48 #define AD_ADIEU_CS_SZ 16
49 
50 enum {
51  NR = 4,
52  NR_SORT = 256,
53  MIN_BUF_SIZE = 4096,
55 };
56 
57 enum {
60 };
61 
63 static const char linux_location[] = "linuxstob:./__s";
64 static const char perf_location[] = "perfstob:./__s";
65 static struct m0_stob_domain *dom;
66 static struct m0_stob *obj;
67 static const char linux_path[] = "./__s/o/100000000000000:2";
68 static const char perf_path[] = "./__s/backstore/o/100000000000000:2";
69 static struct m0_stob_io io;
71 static char *user_buf[NR];
72 static char *user_cksm_buf[NR];
73 static char *read_buf[NR];
74 static char *read_cksm_buf[NR];
75 static char *user_bufs[NR];
76 static char *read_bufs[NR];
78 static struct m0_clink clink;
79 static FILE *f;
80 static uint32_t block_shift;
81 static uint32_t buf_size;
82 
83 static int test_adieu_init(const char *location,
84  const char *dom_cfg,
85  const char *stob_cfg)
86 {
87  int i;
88  int rc;
89  struct m0_stob_id stob_id;
90  char cs_char = 'a';
91 
93  NULL, M0_STOB_UT_DOMAIN_KEY, dom_cfg, &dom);
94  M0_ASSERT(rc == 0);
95  M0_ASSERT(dom != NULL);
96 
98  rc = m0_stob_find(&stob_id, &obj);
99  M0_ASSERT(rc == 0);
100  rc = m0_stob_locate(obj);
101  M0_ASSERT(rc == 0);
102  rc = m0_ut_stob_create(obj, stob_cfg, NULL);
103  M0_ASSERT(rc == 0);
104 
106  /* buf_size is chosen so it would be at least MIN_BUF_SIZE in bytes
107  * or it would consist of at least MIN_BUF_SIZE_IN_BLOCKS blocks */
110 
111  for (i = 0; i < ARRAY_SIZE(user_buf); ++i) {
113  M0_ASSERT(user_buf[i] != NULL);
114  }
115 
116  // Allocate contigious buffer for i/p checksums
119  memset( user_cksm_buf[0], cs_char++, AD_ADIEU_CS_SZ);
120  for (i = 1; i < ARRAY_SIZE(user_cksm_buf); ++i) {
122  memset( user_cksm_buf[i], cs_char++, AD_ADIEU_CS_SZ);
123  }
124 
125  for (i = 0; i < ARRAY_SIZE(read_buf); ++i) {
127  M0_ASSERT(read_buf[i] != NULL);
128  }
129 
130  // Allocate contigious buffer for o/p checksums
133  memset( read_cksm_buf[0], 0, AD_ADIEU_CS_SZ);
134  for (i = 1; i < ARRAY_SIZE(read_cksm_buf); ++i) {
136  memset( read_cksm_buf[i], 0, AD_ADIEU_CS_SZ);
137  }
138 
139  for (i = 0; i < NR; ++i) {
143  stob_vec[i] = (buf_size * (2 * i + 1)) >> block_shift;
144  memset(user_buf[i], ('a' + i)|1, buf_size);
145  }
146  return rc;
147 }
148 
149 static void test_adieu_fini(void)
150 {
151  int i;
152  int rc;
153 
155  M0_ASSERT(rc == 0);
157  M0_ASSERT(rc == 0);
158 
159  for (i = 0; i < ARRAY_SIZE(user_buf); ++i)
160  m0_free(user_buf[i]);
161 
163 
164  for (i = 0; i < ARRAY_SIZE(read_buf); ++i)
165  m0_free(read_buf[i]);
166 
168 }
169 
170 static void test_write(int i)
171 {
172  int rc;
173  struct m0_fol_frag *fol_frag;
174 
175  M0_ALLOC_PTR(fol_frag);
176  M0_UB_ASSERT(fol_frag != NULL);
177 
179 
181  io.si_flags = 0;
182  io.si_fol_frag = fol_frag;
183  io.si_user.ov_vec.v_nr = i;
185  io.si_user.ov_buf = (void **)user_bufs;
186 
187  io.si_stob.iv_vec.v_nr = i;
190 
193  // Checksum for i buf_size blocks
195  io.si_cksum.b_nob = ( i * AD_ADIEU_CS_SZ );
196 
199 
201  M0_ASSERT(rc == 0);
202 
204 
205  M0_ASSERT(io.si_rc == 0);
207 
210 
212 }
213 
214 static void test_read(int i)
215 {
216  int rc;
217 
219 
221  io.si_flags = 0;
222  io.si_user.ov_vec.v_nr = i;
224  io.si_user.ov_buf = (void **)read_bufs;
225 
226  io.si_stob.iv_vec.v_nr = i;
229 
232  // Checksum for i buf_size blocks
234  io.si_cksum.b_nob = ( i * AD_ADIEU_CS_SZ );
235 
238 
240  M0_ASSERT(rc == 0);
241 
243 
244  M0_ASSERT(io.si_rc == 0);
246 
249 
251 }
252 
256 static void test_adieu(const char *path)
257 {
258  int ch;
259  int i;
260  int j;
261 
262  for (i = 1; i < NR; ++i) {
263  test_write(i);
264 
265  /* this works only for linuxstob */
266  f = fopen(path, "r");
267  for (j = 0; j < i; ++j) {
268  int k;
269 
270  for (k = 0; k < buf_size; ++k) {
271  ch = fgetc(f);
272  M0_ASSERT(ch == '\0');
273  M0_ASSERT(!feof(f));
274  }
275  for (k = 0; k < buf_size; ++k) {
276  ch = fgetc(f);
277  M0_ASSERT(ch != '\0');
278  M0_ASSERT(!feof(f));
279  }
280  }
281  ch = fgetc(f);
282  M0_ASSERT(ch == EOF);
283  fclose(f);
284  }
285 
286  for (i = 1; i < NR; ++i) {
287  test_read(i);
288  M0_ASSERT(memcmp(user_buf[i - 1], read_buf[i - 1], buf_size) == 0);
289  // TODO: Check how this can be enabled for linux stob
290  // M0_ASSERT(memcmp(user_cksm_buf[i - 1], read_cksm_buf[i - 1], AD_ADIEU_CS_SZ) == 0);
291  }
292 }
293 
295 {
296  int rc;
297 
299  M0_ASSERT(rc == 0);
301  test_adieu_fini();
302 }
303 
305 {
306  int rc;
307 
309  M0_ASSERT(rc == 0);
311  test_adieu_fini();
312 }
313 
314 /*
315  Adieu unit-benchmark
316  */
317 
318 static void ub_write(int i)
319 {
320  test_write(NR - 1);
321 }
322 
323 static void ub_read(int i)
324 {
325  test_read(NR - 1);
326 }
327 
329 static char *user_bufs1[NR_SORT];
331 
332 static void ub_iovec_init()
333 {
334  int i;
335 
336  for (i = 0; i < NR_SORT ; i++)
337  stob_vec1[i] = MIN_BUF_SIZE * i;
338 
340 
342  io.si_flags = 0;
343 
346  io.si_user.ov_buf = (void **)user_bufs1;
347 
351 }
352 
353 static void ub_iovec_invert()
354 {
355  int i;
356  bool swapped;
357 
358  /* Reverse sort index vecs. */
359  do {
360  swapped = false;
361  for (i = 0; i < NR_SORT - 1; i++) {
362  if (stob_vec1[i] < stob_vec1[i + 1]) {
363  m0_bindex_t tmp = stob_vec1[i];
364  stob_vec1[i] = stob_vec1[i + 1];
365  stob_vec1[i + 1] = tmp;
366  swapped = true;
367  }
368  }
369  } while(swapped);
370 }
371 
372 static void ub_iovec_sort()
373 {
375 }
376 
377 static void ub_iovec_sort_invert()
378 {
379  ub_iovec_invert();
381 }
382 
383 static int ub_init(const char *opts M0_UNUSED)
384 {
386 }
387 
388 static void ub_fini(void)
389 {
390  test_adieu_fini();
391 }
392 
393 enum {
394  UB_ITER = 100,
395  UB_ITER_SORT = 100000
396 };
397 
399  .us_name = "adieu-ub",
400  .us_init = ub_init,
401  .us_fini = ub_fini,
402  .us_run = {
403  { .ub_name = "write-prime",
404  .ub_iter = 1,
405  .ub_round = ub_write,
406  .ub_block_size = MIN_BUF_SIZE,
407  .ub_blocks_per_op = MIN_BUF_SIZE_IN_BLOCKS },
408 
409  { .ub_name = "write",
410  .ub_iter = UB_ITER,
411  .ub_block_size = MIN_BUF_SIZE,
412  .ub_blocks_per_op = MIN_BUF_SIZE_IN_BLOCKS,
413  .ub_round = ub_write },
414 
415  { .ub_name = "read",
416  .ub_iter = UB_ITER,
417  .ub_block_size = MIN_BUF_SIZE,
418  .ub_blocks_per_op = MIN_BUF_SIZE_IN_BLOCKS,
419  .ub_round = ub_read },
420 
421  { .ub_name = "iovec-sort",
422  .ub_iter = UB_ITER_SORT,
423  .ub_init = ub_iovec_init,
424  .ub_block_size = MIN_BUF_SIZE,
425  .ub_blocks_per_op = MIN_BUF_SIZE_IN_BLOCKS,
426  .ub_round = ub_iovec_sort },
427 
428  { .ub_name = "iovec-sort-invert",
429  .ub_iter = UB_ITER_SORT,
430  .ub_init = ub_iovec_init,
431  .ub_block_size = MIN_BUF_SIZE,
432  .ub_blocks_per_op = MIN_BUF_SIZE_IN_BLOCKS,
433  .ub_round = ub_iovec_sort_invert },
434 
435  { .ub_name = NULL }
436  }
437 };
438 
441 /*
442  * Local variables:
443  * c-indentation-style: "K&R"
444  * c-basic-offset: 8
445  * tab-width: 8
446  * fill-column: 80
447  * scroll-step: 1
448  * End:
449  */
M0_INTERNAL void m0_chan_wait(struct m0_clink *link)
Definition: chan.c:336
static void ub_iovec_init()
Definition: adieu.c:332
enum m0_stob_io_flags si_flags
Definition: io.h:290
M0_INTERNAL void m0_stob_io_fini(struct m0_stob_io *io)
Definition: io.c:122
m0_bindex_t si_unit_sz
Definition: io.h:414
#define NULL
Definition: misc.h:38
M0_INTERNAL void m0_clink_init(struct m0_clink *link, m0_chan_cb_t cb)
Definition: chan.c:201
static void ub_iovec_sort()
Definition: adieu.c:372
Definition: io.h:230
M0_INTERNAL int m0_stob_locate(struct m0_stob *stob)
Definition: stob.c:128
M0_INTERNAL void m0_clink_del_lock(struct m0_clink *link)
Definition: chan.c:293
#define M0_UB_ASSERT(cond)
Definition: ub.h:37
static void ub_fini(void)
Definition: adieu.c:388
void * b_addr
Definition: buf.h:39
static FILE * f
Definition: adieu.c:79
static m0_bindex_t stob_vec1[NR_SORT]
Definition: adieu.c:330
static struct m0_stob_domain * dom
Definition: adieu.c:65
M0_INTERNAL int m0_stob_domain_destroy(struct m0_stob_domain *dom)
Definition: domain.c:227
static void ub_read(int i)
Definition: adieu.c:323
static char * user_buf[NR]
Definition: adieu.c:71
struct m0_vec ov_vec
Definition: vec.h:147
#define max_check(a, b)
Definition: arith.h:95
static int ub_init(const char *opts M0_UNUSED)
Definition: adieu.c:383
static char * read_cksm_buf[NR]
Definition: adieu.c:74
static const char perf_location[]
Definition: adieu.c:64
static void test_adieu_fini(void)
Definition: adieu.c:149
uint64_t m0_bindex_t
Definition: types.h:80
struct m0_chan si_wait
Definition: io.h:318
uint64_t m0_bcount_t
Definition: types.h:77
struct m0_ub_set m0_adieu_ub
Definition: adieu.c:398
static m0_bcount_t user_vec[NR]
Definition: adieu.c:70
static void ub_iovec_sort_invert()
Definition: adieu.c:377
void ** ov_buf
Definition: vec.h:149
const char * location
Definition: storage.c:50
Definition: adieu.c:51
static void test_read(int i)
Definition: adieu.c:214
struct m0_vec iv_vec
Definition: vec.h:139
M0_INTERNAL uint32_t m0_stob_block_shift(struct m0_stob *stob)
Definition: stob.c:270
struct m0_bufvec si_user
Definition: io.h:300
void m0_stob_ut_adieu_linux(void)
Definition: adieu.c:294
m0_bindex_t * iv_index
Definition: vec.h:141
static char * user_bufs1[NR_SORT]
Definition: adieu.c:329
int i
Definition: dir.c:1033
M0_INTERNAL int m0_stob_domain_create(const char *location, const char *str_cfg_init, uint64_t dom_key, const char *str_cfg_create, struct m0_stob_domain **out)
Definition: domain.c:217
static int test_adieu_init(const char *location, const char *dom_cfg, const char *stob_cfg)
Definition: adieu.c:83
#define AD_ADIEU_CS_SZ
Definition: adieu.c:48
M0_INTERNAL int m0_stob_io_prepare_and_launch(struct m0_stob_io *io, struct m0_stob *obj, struct m0_dtx *tx, struct m0_io_scope *scope)
Definition: io.c:219
struct m0_buf si_cksum
Definition: io.h:412
Definition: stob.h:163
struct m0_indexvec si_stob
Definition: io.h:311
int32_t si_rc
Definition: io.h:334
static const char linux_path[]
Definition: adieu.c:67
static const char perf_path[]
Definition: adieu.c:68
m0_bcount_t b_nob
Definition: buf.h:38
#define M0_ASSERT(cond)
const char * us_name
Definition: ub.h:76
M0_INTERNAL void m0_stob_id_make(uint64_t container, uint64_t key, const struct m0_fid *dom_id, struct m0_stob_id *stob_id)
Definition: stob.c:343
M0_INTERNAL void * m0_stob_addr_pack(const void *buf, uint32_t shift)
Definition: io.c:293
void * m0_alloc(size_t size)
Definition: memory.c:126
static struct m0_stob * obj
Definition: adieu.c:66
struct m0_fol_frag * si_fol_frag
Definition: io.h:390
uint32_t v_nr
Definition: vec.h:51
static char * user_cksm_buf[NR]
Definition: adieu.c:72
Definition: io.h:285
static m0_bindex_t stob_vec[NR]
Definition: adieu.c:77
m0_bcount_t * v_count
Definition: vec.h:53
m0_bcount_t si_cksum_sz
Definition: io.h:416
static void test_write(int i)
Definition: adieu.c:170
static struct m0_stob_io io
Definition: adieu.c:69
m0_bcount_t si_count
Definition: io.h:340
void m0_clink_add_lock(struct m0_chan *chan, struct m0_clink *link)
Definition: chan.c:255
struct m0_fid sd_id
Definition: domain.h:96
M0_INTERNAL int m0_stob_destroy(struct m0_stob *stob, struct m0_dtx *dtx)
Definition: stob.c:200
static char * read_bufs[NR]
Definition: adieu.c:76
#define M0_ALLOC_PTR(ptr)
Definition: memory.h:86
M0_INTERNAL void m0_stob_iovec_sort(struct m0_stob_io *stob)
Definition: io.c:311
static char * read_buf[NR]
Definition: adieu.c:73
Definition: adieu.c:52
M0_INTERNAL void m0_clink_fini(struct m0_clink *link)
Definition: chan.c:208
M0_INTERNAL void m0_stob_io_init(struct m0_stob_io *io)
Definition: io.c:111
M0_INTERNAL int m0_stob_find(const struct m0_stob_id *id, struct m0_stob **out)
Definition: stob.c:92
static uint32_t buf_size
Definition: adieu.c:81
static char * user_bufs[NR]
Definition: adieu.c:75
static m0_bcount_t user_vec1[NR_SORT]
Definition: adieu.c:328
static uint32_t block_shift
Definition: adieu.c:80
M0_INTERNAL int m0_ut_stob_create(struct m0_stob *stob, const char *str_cfg, struct m0_be_domain *be_dom)
Definition: stob.c:202
Definition: adieu.c:394
M0_INTERNAL void * m0_alloc_aligned(size_t size, unsigned shift)
Definition: memory.c:168
Definition: io.h:229
static void ub_write(int i)
Definition: adieu.c:318
void m0_free(void *data)
Definition: memory.c:146
void m0_stob_ut_adieu_perf(void)
Definition: adieu.c:304
int32_t rc
Definition: trigger_fop.h:47
#define ARRAY_SIZE(a)
Definition: misc.h:45
Definition: ub.h:74
static struct m0_clink clink
Definition: adieu.c:78
static void ub_iovec_invert()
Definition: adieu.c:353
static void test_adieu(const char *path)
Definition: adieu.c:256
static const char linux_location[]
Definition: adieu.c:63
enum m0_stob_io_opcode si_opcode
Definition: io.h:286
#define M0_UNUSED
Definition: misc.h:380