Motr  M0
cp_common.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 #include "ioservice/io_service.h" /* m0_ios_cdom_get */
24 #include "motr/setup.h" /* m0_motr */
25 #include "sns/cm/repair/ut/cp_common.h" /* cs_fini */
26 #include "ut/misc.h" /* M0_UT_PATH */
27 #include "ut/ut.h"
28 
29 #include "sns/cm/repair/service.c"
31 
32 /* Global structures for setting up motr service. */
33 const char log_file_name[] = "sr_ut.errlog";
34 char *sns_cm_ut_svc_ad[] = {
35  "m0d", "-T", "AD",
36  "-D", "sr_db", "-S", "sr_stob",
37  "-A", "linuxstob:sr_addb_stob",
38  "-f", M0_UT_CONF_PROCESS,
39  "-w", "10",
40  "-G", M0_NET_XPRT_PREFIX_DEFAULT":0@lo:12345:34:1",
41  "-e", M0_NET_XPRT_PREFIX_DEFAULT":0@lo:12345:34:1",
42  "-H", "0@lo:12345:34:1",
43  "-c", M0_UT_PATH("conf.xc")
44 };
45 
47  "m0d", "-T", "LINUX",
48  "-D", "sr_db", "-S", "sr_stob",
49  "-A", "linuxstob:sr_addb_stob",
50  "-f", M0_UT_CONF_PROCESS,
51  "-w", "10",
52  "-G", M0_NET_XPRT_PREFIX_DEFAULT":0@lo:12345:34:1",
53  "-e", M0_NET_XPRT_PREFIX_DEFAULT":0@lo:12345:34:1",
54  "-H", "0@lo:12345:34:1",
55  "-c", M0_UT_PATH("conf.xc")
56 };
57 
58 FILE *lfile;
59 struct m0_motr sctx;
60 enum {
61  PDCLUST_N = 8,
62  PDCLUST_K = 2,
63  PDCLUST_S = 2,
64  PDCLUST_P = 24,
66 };
67 enum {
69  AD_STOB = 2,
70 };
71 void bv_populate(struct m0_bufvec *b, char data, uint32_t seg_nr,
72  uint32_t seg_size)
73 {
74  int i;
75 
76  for (i = 0; i < seg_nr; ++i) {
78  M0_UT_ASSERT(b->ov_buf[i] != NULL);
79  memset(b->ov_buf[i], data, seg_size);
80  }
81 }
82 
83 /* Populates the bufvec with a character value. */
84 void bv_alloc_populate(struct m0_bufvec *b, char data, uint32_t seg_nr,
85  uint32_t seg_size)
86 {
87  M0_UT_ASSERT(b != NULL);
89  M0_0VEC_SHIFT) == 0);
92 }
93 
94 /* Compares 2 bufvecs and asserts if not equal. */
95 void bv_compare(struct m0_bufvec *b1, struct m0_bufvec *b2, uint32_t seg_nr,
96  uint32_t seg_size)
97 {
98  int i;
99 
100  M0_UT_ASSERT(b1 != NULL);
101  M0_UT_ASSERT(b2 != NULL);
102  M0_UT_ASSERT(b1->ov_vec.v_nr == seg_nr);
103  M0_UT_ASSERT(b2->ov_vec.v_nr == seg_nr);
104 
105  for (i = 0; i < seg_nr; ++i) {
107  M0_UT_ASSERT(b1->ov_buf[i] != NULL);
109  M0_UT_ASSERT(b2->ov_buf[i] != NULL);
110  M0_UT_ASSERT(memcmp(b1->ov_buf[i], b2->ov_buf[i],
111  seg_size) == 0);
112  }
113 }
114 
115 void bv_free(struct m0_bufvec *b)
116 {
117  m0_bufvec_free(b);
118 }
119 
120 void cp_prepare(struct m0_cm_cp *cp, struct m0_net_buffer *buf,
121  uint32_t bv_seg_nr, uint32_t bv_seg_size,
122  struct m0_sns_cm_ag *sns_ag,
123  char data, struct m0_fom_ops *cp_fom_ops,
124  struct m0_reqh *reqh, uint64_t cp_ag_idx, bool is_acc_cp,
125  struct m0_cm *cm)
126 {
127  struct m0_reqh_service *service;
128  struct m0_sns_cm *scm;
129 
130  M0_UT_ASSERT(cp != NULL);
131  M0_UT_ASSERT(buf != NULL);
132  M0_UT_ASSERT(sns_ag != NULL);
133 
134  if (buf->nb_buffer.ov_buf == NULL)
135  bv_alloc_populate(&buf->nb_buffer, data, bv_seg_nr, bv_seg_size);
136  else
137  bv_populate(&buf->nb_buffer, data, bv_seg_nr, bv_seg_size);
138  cp->c_ag = &sns_ag->sag_base;
139  if (cm == NULL) {
142  cm = container_of(service, struct m0_cm, cm_service);
143  M0_UT_ASSERT(cm != NULL);
144  scm = cm2sns(cm);
146  }
147  cp->c_ag->cag_cm = cm;
148  if (!is_acc_cp)
151  m0_cm_cp_fom_init(cm, cp, NULL, NULL);
152  m0_cm_cp_buf_add(cp, buf);
153  cp->c_data_seg_nr = bv_seg_nr;
154  buf->nb_pool->nbp_seg_nr = bv_seg_nr;
155  buf->nb_pool->nbp_seg_size = bv_seg_size;
156  cp->c_fom.fo_ops = cp_fom_ops;
157  cp->c_ag_cp_idx = cp_ag_idx;
158 }
159 
161 {
162  struct m0_reqh_service *service;
163  struct m0_cm *cm;
164 
166  reqh);
168  cm = container_of(service, struct m0_cm, cm_service);
169  M0_UT_ASSERT(cm != NULL);
170  return cm2sns(cm);
171 }
172 
173 static int cs_init_setup_env(struct m0_motr *sctx, int stob_type)
174 {
175  int rc;
176 
177  M0_SET0(sctx);
178 
179  lfile = fopen(log_file_name, "w+");
180  M0_ASSERT(lfile != NULL);
181 
183  lfile, true);
184  if (rc != 0)
185  return rc;
186 
187  if (stob_type == LINUX_STOB) {
190  } else {
193  }
194  if (rc == 0)
195  rc = m0_cs_start(sctx);
196  if (rc != 0)
197  cs_fini(sctx);
198 
199  return rc;
200 }
201 
202 /*
203  * Starts motr service, which internally creates and sets up linux stob domain.
204  * This stob domain is used in read and write phases of the copy packet.
205  */
206 int cs_init(struct m0_motr *sctx)
207 {
209 }
210 
211 /*
212  * Starts motr service, which internally creates and sets up ad stob domain.
213  * This stob domain is used in read and write phases of the copy packet.
214  */
216 {
217  return cs_init_setup_env(sctx, AD_STOB);
218 }
219 
220 /* Finalises the motr service. */
221 void cs_fini(struct m0_motr *sctx)
222 {
223  m0_cs_fini(sctx);
224  fclose(lfile);
225 }
226 
228 {
231  struct m0_pdclust_attr pdattr;
232  int rc;
233 
234  llattr = (struct m0_layout_linear_attr) {
235  .lla_nr = PDCLUST_P,
236  .lla_A = 1,
237  .lla_B = 1,
238  };
239  llenum = NULL;
241  M0_ASSERT(rc == 0);
242 
243  pdattr = (struct m0_pdclust_attr) {
244  .pa_N = PDCLUST_N,
245  .pa_K = PDCLUST_K,
246  .pa_S = PDCLUST_S,
247  .pa_P = PDCLUST_P,
248  .pa_unit_size = PDCLUST_UNIT_SIZE,
249  };
250  m0_uint128_init(&pdattr.pa_seed, "upjumpandpumpim,");
251  rc = m0_pdclust_build(&reqh->rh_ldom, M0_DEFAULT_LAYOUT_ID,
252  &pdattr, &llenum->lle_base, pdlay);
253  M0_ASSERT(rc == 0);
254  M0_ASSERT(*pdlay != NULL);
255 }
256 
258 {
260 }
261 
262 void pool_mach_transit(struct m0_reqh *reqh, struct m0_poolmach *pm,
263  uint64_t fd, enum m0_pool_nd_state state)
264 {
265  struct m0_poolmach_event pme;
266  int rc;
267 
268  M0_SET0(&pme);
269  pme.pe_type = M0_POOL_DEVICE;
270  pme.pe_index = fd;
271  pme.pe_state = state;
272 
273  rc = m0_poolmach_state_transit(pm, &pme);
274  M0_UT_ASSERT(rc == 0);
275 }
276 
277 
278 /*
279  * Local variables:
280  * c-indentation-style: "K&R"
281  * c-basic-offset: 8
282  * tab-width: 8
283  * fill-column: 80
284  * scroll-step: 1
285  * End:
286  */
static m0_bcount_t seg_size
Definition: net.c:118
void cs_fini(struct m0_motr *sctx)
Definition: cp_common.c:221
Definition: cm.h:205
M0_INTERNAL int m0_poolmach_state_transit(struct m0_poolmach *pm, const struct m0_poolmach_event *event)
Definition: pool_machine.c:554
int cs_init_with_ad_stob(struct m0_motr *sctx)
Definition: cp_common.c:215
static uint32_t seg_nr
Definition: net.c:119
#define NULL
Definition: misc.h:38
char * sns_cm_ut_svc_ad[]
Definition: cp_common.c:34
M0_INTERNAL struct m0_sns_cm * cm2sns(struct m0_cm *cm)
Definition: cm.c:389
uint32_t pa_N
Definition: pdclust.h:104
Definition: cp.h:160
int m0_cs_setup_env(struct m0_motr *cctx, int argc, char **argv)
Definition: setup.c:2972
M0_INTERNAL void m0_uint128_init(struct m0_uint128 *u128, const char *magic)
Definition: misc.c:150
const char log_file_name[]
Definition: cp_common.c:33
struct m0_vec ov_vec
Definition: vec.h:147
void m0_cs_fini(struct m0_motr *cctx)
Definition: setup.c:3029
M0_INTERNAL void m0_ios_cdom_get(struct m0_reqh *reqh, struct m0_cob_domain **out)
Definition: io_service.c:463
M0_INTERNAL int m0_linear_enum_build(struct m0_layout_domain *dom, const struct m0_layout_linear_attr *attr, struct m0_layout_linear_enum **out)
Definition: linear_enum.c:138
struct m0_bufvec data
Definition: di.c:40
static struct m0_sns_cm * scm
Definition: cm.c:64
M0_INTERNAL void m0_cm_cp_fom_init(struct m0_cm *cm, struct m0_cm_cp *cp, struct m0_fop *fop, struct m0_fop *r_fop)
Definition: cp.c:610
uint64_t c_ag_cp_idx
Definition: cp.h:175
#define container_of(ptr, type, member)
Definition: misc.h:33
#define M0_SET0(obj)
Definition: misc.h:64
static int cs_init_setup_env(struct m0_motr *sctx, int stob_type)
Definition: cp_common.c:173
void ** ov_buf
Definition: vec.h:149
struct m0_pdclust_layout * pdlay
Definition: xform.c:51
Definition: sock.c:887
int m0_bufvec_alloc_aligned(struct m0_bufvec *bufvec, uint32_t num_segs, m0_bcount_t seg_size, unsigned shift)
Definition: vec.c:355
static struct m0_cm * cm
Definition: cm.c:63
M0_INTERNAL void m0_bufvec_free(struct m0_bufvec *bufvec)
Definition: vec.c:395
const struct m0_cm_cp_ops m0_sns_cm_repair_cp_ops
Definition: cp.c:421
int i
Definition: dir.c:1033
struct m0_layout_enum lle_base
Definition: linear_enum.h:69
stob_type
Definition: setup.h:144
#define M0_NET_XPRT_PREFIX_DEFAULT
Definition: net.h:98
struct m0_striped_layout pl_base
Definition: pdclust.h:148
#define M0_ASSERT(cond)
void bv_compare(struct m0_bufvec *b1, struct m0_bufvec *b2, uint32_t seg_nr, uint32_t seg_size)
Definition: cp_common.c:95
uint32_t c_data_seg_nr
Definition: cp.h:190
m0_pool_nd_state
Definition: pool_machine.h:57
struct m0_cm * cag_cm
Definition: ag.h:70
const struct m0_cm_cp_ops * c_ops
Definition: cp.h:169
M0_INTERNAL void m0_cm_cp_buf_add(struct m0_cm_cp *cp, struct m0_net_buffer *nb)
Definition: cp.c:703
int m0_net_xprt_nr(void)
Definition: net.c:168
M0_EXTERN struct m0_cm_type sns_repair_cmt
Definition: cm.c:383
const struct m0_cm_cp_ops m0_sns_cm_acc_cp_ops
Definition: acc_cp.c:80
char * sns_cm_ut_svc_linux[]
Definition: cp_common.c:46
Definition: reqh.h:94
struct m0_layout_domain rh_ldom
Definition: reqh.h:153
uint32_t v_nr
Definition: vec.h:51
struct m0_cm_aggr_group * c_ag
Definition: cp.h:172
m0_bcount_t * v_count
Definition: vec.h:53
const struct m0_fom_ops * fo_ops
Definition: fom.h:486
struct m0_cob_domain * sc_cob_dom
Definition: cm.h:217
void bv_alloc_populate(struct m0_bufvec *b, char data, uint32_t seg_nr, uint32_t seg_size)
Definition: cp_common.c:84
void layout_destroy(struct m0_pdclust_layout *pdlay)
Definition: cp_common.c:257
struct m0_uint128 pa_seed
Definition: pdclust.h:121
int m0_cs_init(struct m0_motr *cctx, struct m0_net_xprt **xprts, size_t xprts_nr, FILE *out, bool mkfs)
Definition: setup.c:2999
M0_INTERNAL struct m0_reqh_service * m0_reqh_service_find(const struct m0_reqh_service_type *st, const struct m0_reqh *reqh)
Definition: reqh_service.c:538
Definition: setup.h:354
struct m0_reqh reqh
Definition: rm_foms.c:48
struct m0_sns_cm * reqh2snscm(struct m0_reqh *reqh)
Definition: cp_common.c:160
static const struct m0_fom_ops cp_fom_ops
Definition: cp.c:448
#define M0_UT_CONF_PROCESS
Definition: misc.h:45
int cs_init(struct m0_motr *sctx)
Definition: cp_common.c:206
struct m0_net_xprt ** m0_net_all_xprt_get(void)
Definition: net.c:161
struct m0_reqh_service cm_service
Definition: cm.h:191
Definition: cm.h:166
void bv_populate(struct m0_bufvec *b, char data, uint32_t seg_nr, uint32_t seg_size)
Definition: cp_common.c:71
struct m0_layout sl_base
Definition: layout.h:574
static struct m0_layout_linear_attr llattr
Definition: file.c:90
M0_INTERNAL int m0_pdclust_build(struct m0_layout_domain *dom, uint64_t lid, const struct m0_pdclust_attr *attr, struct m0_layout_enum *le, struct m0_pdclust_layout **out)
Definition: pdclust.c:305
void bv_free(struct m0_bufvec *b)
Definition: cp_common.c:115
struct m0_reqh_service_type ct_stype
Definition: cm.h:145
struct m0t1fs_filedata * fd
Definition: dir.c:1030
int m0_cs_start(struct m0_motr *cctx)
Definition: setup.c:2987
struct m0_motr sctx
Definition: cp_common.c:59
#define M0_UT_PATH(name)
Definition: misc.h:41
M0_INTERNAL void m0_layout_put(struct m0_layout *l)
Definition: layout.c:893
struct m0_cm_aggr_group sag_base
Definition: ag.h:46
struct m0_fom c_fom
Definition: cp.h:161
enum m0_pool_nd_state pe_state
Definition: pool_machine.h:199
void layout_gen(struct m0_pdclust_layout **pdlay, struct m0_reqh *reqh)
Definition: cp_common.c:227
void cp_prepare(struct m0_cm_cp *cp, struct m0_net_buffer *buf, uint32_t bv_seg_nr, uint32_t bv_seg_size, struct m0_sns_cm_ag *sns_ag, char data, struct m0_fom_ops *cp_fom_ops, struct m0_reqh *reqh, uint64_t cp_ag_idx, bool is_acc_cp, struct m0_cm *cm)
Definition: cp_common.c:120
static struct m0_pdclust_attr pdattr
Definition: file.c:87
static struct m0_reqh_service * service[REQH_IN_UT_MAX]
Definition: long_lock_ut.c:46
int32_t rc
Definition: trigger_fop.h:47
#define ARRAY_SIZE(a)
Definition: misc.h:45
#define M0_UT_ASSERT(a)
Definition: ut.h:46
void pool_mach_transit(struct m0_reqh *reqh, struct m0_poolmach *pm, uint64_t fd, enum m0_pool_nd_state state)
Definition: cp_common.c:262
Definition: vec.h:145
static struct m0_layout_linear_enum * llenum
Definition: file.c:89
FILE * lfile
Definition: cp_common.c:58