Motr  M0
domain.c
Go to the documentation of this file.
1 /* -*- C -*- */
2 /*
3  * Copyright (c) 2014-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 <stdio.h> /* snprintf */
24 
25 #include "be/ut/helper.h"
26 #include "lib/errno.h"
27 #include "lib/memory.h" /* m0_free */
28 #include "ut/ut.h" /* M0_UT_ASSERT */
29 #include "ut/stob.h" /* m0_ut_stob_linux_get */
30 
31 #include "stob/ad.h" /* m0_stob_ad_cfg_make */
32 #include "stob/domain.h"
33 #include "stob/stob.h"
34 #include "stob/stob_internal.h"
35 
36 static void stob_ut_stob_domain(const char *location, const char *cfg,
37  const char *init_cfg)
38 {
39  struct m0_stob_domain *dom;
40  uint64_t dom_key = 0xec0de;
41  struct m0_fid dom_id;
42  int rc;
43 
44  rc = m0_stob_domain_init(location, init_cfg, &dom);
45  M0_UT_ASSERT(rc == -ENOENT);
47  M0_UT_ASSERT(rc == 0 || rc == -ENOENT);
48  rc = m0_stob_domain_create(location, init_cfg, dom_key, cfg, &dom);
49  M0_UT_ASSERT(rc == 0);
50  M0_UT_ASSERT(dom != NULL);
52 
53  rc = m0_stob_domain_create(location, init_cfg, dom_key, cfg, &dom);
54  M0_UT_ASSERT(rc == -EEXIST);
55 
56  rc = m0_stob_domain_init(location, init_cfg, &dom);
57  M0_UT_ASSERT(rc == 0);
58  M0_UT_ASSERT(dom != NULL);
60  dom_key);
61 
62  /* Find existent domain */
63  dom_id = *m0_stob_domain_id_get(dom);
65 
66  /* Find non-existent domain */
67  dom_id.f_key ^= (1ULL << 56) - 1;
69 
71  M0_UT_ASSERT(rc == 0);
72 
73  rc = m0_stob_domain_create(location, init_cfg, dom_key, cfg, &dom);
74  M0_UT_ASSERT(rc == 0);
77  M0_UT_ASSERT(rc == 0);
78 }
79 
81 {
82  stob_ut_stob_domain("nullstob:./__s", NULL, NULL);
83 }
84 
85 #ifndef __KERNEL__
87 {
88  stob_ut_stob_domain("linuxstob:./__s", NULL, NULL);
89 }
90 
92 {
93  stob_ut_stob_domain("perfstob:./__s", NULL, NULL);
94 }
95 
97 {
98  stob_ut_stob_domain("perfstob:./__s", "null=true", NULL);
99 }
100 
101 extern void m0_stob_ut_ad_init(struct m0_be_ut_backend *ut_be,
102  struct m0_be_ut_seg *ut_seg);
103 extern void m0_stob_ut_ad_fini(struct m0_be_ut_backend *ut_be,
104  struct m0_be_ut_seg *ut_seg);
105 
107 {
108  struct m0_be_ut_backend ut_be;
109  struct m0_be_ut_seg ut_seg;
110  struct m0_stob *stob;
111  char *cfg;
112  char *init_cfg;
113 
116  M0_UT_ASSERT(stob != NULL);
118  M0_UT_ASSERT(cfg != NULL);
120  M0_UT_ASSERT(init_cfg != NULL);
121 
122  stob_ut_stob_domain("adstob:some_suffix", cfg, init_cfg);
123 
124  m0_free(cfg);
125  m0_ut_stob_put(stob, true);
127 }
128 #endif
129 
130 /*
131  * Local variables:
132  * c-indentation-style: "K&R"
133  * c-basic-offset: 8
134  * tab-width: 8
135  * fill-column: 80
136  * scroll-step: 1
137  * End:
138  */
139 /*
140  * vim: tabstop=8 shiftwidth=8 noexpandtab textwidth=80 nowrap
141  */
M0_INTERNAL uint64_t m0_stob_domain__dom_key(const struct m0_fid *dom_id)
Definition: domain.c:322
M0_INTERNAL struct m0_stob_domain * m0_stob_domain_find(const struct m0_fid *dom_id)
Definition: domain.c:278
#define NULL
Definition: misc.h:38
M0_INTERNAL const struct m0_fid * m0_stob_domain_id_get(const struct m0_stob_domain *dom)
Definition: domain.c:300
M0_INTERNAL int m0_stob_domain_destroy(struct m0_stob_domain *dom)
Definition: domain.c:227
struct m0_be_seg * bus_seg
Definition: helper.h:119
void m0_stob_ut_stob_domain_null(void)
Definition: domain.c:80
struct m0_be_ut_seg ut_seg
Definition: ad.c:73
M0_INTERNAL void m0_stob_ad_init_cfg_make(char **str, struct m0_be_domain *dom)
Definition: ad.c:212
static void stob_ut_stob_domain(const char *location, const char *cfg, const char *init_cfg)
Definition: domain.c:36
const char * location
Definition: storage.c:50
M0_INTERNAL struct m0_stob * m0_ut_stob_linux_get(void)
Definition: stob.c:169
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
struct m0_be_ut_backend ut_be
Definition: ad.c:72
M0_INTERNAL const struct m0_stob_id * m0_stob_id_get(struct m0_stob *stob)
Definition: stob.c:250
Definition: stob.h:163
static struct m0_stob * stob
Definition: storage.c:39
void m0_stob_ut_stob_domain_ad(void)
Definition: domain.c:106
static struct m0_stob_domain * dom
Definition: storage.c:38
struct m0_be_domain but_dom
Definition: helper.h:47
M0_INTERNAL void m0_ut_stob_put(struct m0_stob *stob, bool destroy)
Definition: stob.c:185
M0_INTERNAL void m0_stob_domain_fini(struct m0_stob_domain *dom)
Definition: domain.c:204
M0_INTERNAL int m0_stob_domain_destroy_location(const char *location)
Definition: domain.c:242
void m0_stob_ut_stob_domain_perf(void)
Definition: domain.c:91
M0_INTERNAL int m0_stob_domain_init(const char *location, const char *str_cfg_init, struct m0_stob_domain **out)
Definition: domain.c:195
Definition: fid.h:38
uint64_t f_key
Definition: fid.h:40
void m0_stob_ut_ad_init(struct m0_be_ut_backend *ut_be, struct m0_be_ut_seg *ut_seg)
void m0_stob_ut_stob_domain_linux(void)
Definition: domain.c:86
M0_INTERNAL void m0_stob_ad_cfg_make(char **str, const struct m0_be_seg *seg, const struct m0_stob_id *bstore_id, const m0_bcount_t size)
Definition: ad.c:220
void m0_stob_ut_ad_fini(struct m0_be_ut_backend *ut_be, struct m0_be_ut_seg *ut_seg)
Definition: ad.c:106
void m0_free(void *data)
Definition: memory.c:146
int32_t rc
Definition: trigger_fop.h:47
#define M0_UT_ASSERT(a)
Definition: ut.h:46
void m0_stob_ut_stob_domain_perf_null(void)
Definition: domain.c:96