Motr  M0
storage.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 #define M0_TRACE_SUBSYSTEM M0_TRACE_SUBSYS_SNSCM
24 #include "lib/trace.h"
25 #include "lib/misc.h"
26 #include "lib/locality.h"
27 #include "lib/finject.h"
28 #include "lib/hash.h"
29 #include "reqh/reqh.h"
30 #include "motr/setup.h"
31 #include "net/net.h"
33 #include "sns/cm/file.h"
34 #include "ioservice/fid_convert.h" /* m0_fid_convert_cob2stob */
35 #include "sns/cm/cm.h"
36 
37 M0_INTERNAL void cob_delete(struct m0_cob_domain *cdom,
38  struct m0_be_domain *bedom,
39  uint64_t cont, const struct m0_fid *gfid);
40 
41 static struct m0_sns_cm *scm;
42 static struct m0_reqh *reqh;
43 static struct m0_semaphore sem;
44 static struct m0_net_buffer_pool nbp;
45 
46 /* Global structures for write copy packet. */
47 static struct m0_sns_cm_ag w_sag;
48 static struct m0_sns_cm_cp w_sns_cp;
49 static struct m0_net_buffer w_buf;
50 
51 /* Global structures for read copy packet. */
52 static struct m0_sns_cm_ag r_sag;
53 static struct m0_sns_cm_cp r_sns_cp;
54 static struct m0_net_buffer r_buf;
55 
56 static struct m0_fid gob_fid;
57 static struct m0_fid cob_fid;
58 
59 static const struct m0_fid M0_SNS_CM_REPAIR_UT_PVER = M0_FID_TINIT('v', 1, 8);
60 
61 /*
62  * Copy packet will typically have a single segment with its size equal to
63  * size of copy packet (unit).
64  */
65 enum {
66  SEG_NR = 1,
67  SEG_SIZE = 4096,
68 };
69 
70 /* Over-ridden copy packet FOM fini. */
71 static void dummy_fom_fini(struct m0_fom *fom)
72 {
73  m0_cm_cp_fini(container_of(fom, struct m0_cm_cp, c_fom));
74 }
75 
76 /* Over-ridden copy packet FOM locality (using single locality). */
77 static uint64_t dummy_fom_locality(const struct m0_fom *fom)
78 {
79  return 0;
80 }
81 
82 /*
83  * Over-ridden copy packet FOM tick. This is not taken from production code
84  * to keep things simple.
85  */
86 static int dummy_fom_tick(struct m0_fom *fom)
87 {
88  int rc;
89  struct m0_cm_cp *cp = container_of(fom, struct m0_cm_cp, c_fom);
90 
91  M0_ENTRY("cp=%p phase=%d", cp, m0_fom_phase(fom));
92 
93  rc = cp->c_ops->co_action[m0_fom_phase(fom)](cp);
94 
95  return M0_RC(rc);
96 }
97 
98 /* Over-ridden copy packet FOM ops. */
99 static struct m0_fom_ops dummy_cp_fom_ops = {
101  .fo_tick = dummy_fom_tick,
102  .fo_home_locality = dummy_fom_locality
103 };
104 
105 /* Over-ridden copy packet init phase. */
106 static int dummy_cp_init(struct m0_cm_cp *cp)
107 {
108  /* This is used to ensure that ast has been posted. */
110  return cp->c_ops->co_phase_next(cp);
111 }
112 
113 /*
114  * Over-ridden copy packet read phase. This is used when write operation of
115  * copy packet has to be tested. In this case, read phase will simply be a
116  * passthrough phase.
117  */
118 static int dummy_cp_read(struct m0_cm_cp *cp)
119 {
120  cp->c_io_op = M0_CM_CP_READ;
121  cp->c_ops->co_phase_next(cp);
122  return M0_FSO_AGAIN;
123 }
124 
125 /*
126  * Over-ridden copy packet write phase. This is used when read operation of
127  * copy packet has to be tested. In this case, write phase will simply be a
128  * passthrough phase.
129  */
130 static int dummy_cp_write(struct m0_cm_cp *cp)
131 {
132  cp->c_io_op = M0_CM_CP_WRITE;
133  cp->c_ops->co_phase_next(cp);
134  return M0_FSO_AGAIN;
135 }
136 
137 /* Passthorugh phase for testing purpose. */
138 static int dummy_cp_phase(struct m0_cm_cp *cp)
139 {
140  return cp->c_ops->co_phase_next(cp);
141 }
142 
143 /* Passthorugh for testing purpose. */
144 static void dummy_cp_complete(struct m0_cm_cp *cp)
145 {
146 }
147 
148 /* Passthorugh for testing purpose. */
149 static int dummy_cp_fini(struct m0_cm_cp *cp)
150 {
151  return cp->c_ops->co_phase_next(cp);
152 }
153 
154 /*
155  * Over-ridden copy packet read io wait phase. This is used when write operation
156  * of copy packet has to be tested. In this case, read io wait phase will
157  * simply be a passthrough phase.
158  */
159 static int dummy_cp_read_io_wait(struct m0_cm_cp *cp)
160 {
161  return cp->c_io_op == M0_CM_CP_READ ?
162  cp->c_ops->co_phase_next(cp) :
164 }
165 
166 /*
167  * Over-ridden copy packet write io wait phase. This is used when read operation
168  * of copy packet has to be tested. In this case, write io wait phase will
169  * simply be a passthrough phase.
170  */
171 static int dummy_cp_write_io_wait(struct m0_cm_cp *cp)
172 {
173  return cp->c_io_op == M0_CM_CP_WRITE ?
174  cp->c_ops->co_phase_next(cp) :
176 }
177 
179  .co_action = {
193  },
194  .co_action_nr = M0_CCP_NR,
195  .co_phase_next = &m0_sns_cm_cp_phase_next,
196  .co_invariant = &m0_sns_cm_cp_invariant,
197  .co_complete = &dummy_cp_complete,
198 };
199 
201 {
202  struct m0_sns_cm_file_ctx fctx;
203  struct m0_motr *motr;
204  struct m0_pool_version *pv;
205 
206  m0_semaphore_init(&sem, 0);
207  w_buf.nb_pool = &nbp;
208  w_sag.sag_fctx = &fctx;
210  &w_sag, 'e', &dummy_cp_fom_ops, reqh, 0, false, &scm->sc_base);
214  w_sag.sag_fctx->sf_attr.ca_lid = M0_DEFAULT_LAYOUT_ID;
221  w_sag.sag_fnr = 1;
222 
224 
225  /* Wait till ast gets posted. */
228 }
229 
231  .co_action = {
245  },
246  .co_action_nr = M0_CCP_NR,
247  .co_phase_next = &m0_sns_cm_cp_phase_next,
248  .co_invariant = &m0_sns_cm_cp_invariant,
249  .co_complete = &dummy_cp_complete,
250 };
251 
252 static void read_post(struct m0_pdclust_layout *pdlay)
253 {
254  struct m0_sns_cm_file_ctx fctx;
255  struct m0_pool_version pv;
256  struct m0_poolmach pm;
257  m0_semaphore_init(&sem, 0);
258 
259  pm.pm_pver = &pv;
260  fctx.sf_pm = ±
262  r_buf.nb_pool = &nbp;
263  /*
264  * Purposefully fill the read bv with spaces i.e. ' '. This should get
265  * replaced by 'e', when the data is read. This is due to the fact
266  * that write operation is writing 'e' to the bv.
267  */
269  &r_sag, ' ', &dummy_cp_fom_ops, reqh, 0, false, &scm->sc_base);
272  r_sag.sag_fnr = 1;
273  r_sag.sag_fctx = &fctx;
277 
278  /* Wait till ast gets posted. */
281 }
282 
283 static void test_cp_write_read(void)
284 {
285  struct m0_pdclust_layout *pdlay;
286  int rc;
287 
288  scm = NULL;
289  reqh = NULL;
290  M0_SET0(&sem);
291  M0_SET0(&nbp);
292 
293  /* Global structures for write copy packet. */
294  M0_SET0(&w_sag);
295  M0_SET0(&w_sns_cp);
296  M0_SET0(&w_buf);
297 
298  /* Global structures for read copy packet. */
299  M0_SET0(&r_sag);
300  M0_SET0(&r_sns_cp);
301  M0_SET0(&r_buf);
302 
303  M0_SET0(&gob_fid);
304  M0_SET0(&cob_fid);
305 
306 
308  M0_ASSERT(rc == 0);
309 
310  m0_fi_enable("m0_sns_cm_tgt_ep", "local-ep");
314  layout_gen(&pdlay, reqh);
315  /*
316  * Write using a dummy copy packet. This data which is written, will
317  * be used by the next copy packet to read.
318  */
319  write_post(pdlay);
320 
321  /* Read the previously written bv. */
322  read_post(pdlay);
324 
325  /*
326  * Compare the bv that is read with the previously written bv.
327  * This verifies the correctness of both write and read operation.
328  */
330 
331  /*
332  * Ensure the subsequent write on the same offsets frees the previously
333  * used extent before allocating the new extent.
334  */
335  m0_fi_enable("ext_punch", "test-ext-release");
336  M0_SET0(&w_sns_cp);
337  M0_SET0(&r_sns_cp);
338  layout_gen(&pdlay, reqh);
339  write_post(pdlay);
340 
341  read_post(pdlay);
343  m0_fi_disable("ext_punch", "test-ext-release");
344 
345  /* IO failure due to cp_stob_io_init() failure in sns/cm/storage.c */
346  m0_fi_enable("cp_stob_io_init", "no-stob");
347 
348  M0_SET0(&w_sns_cp);
349  M0_SET0(&r_sns_cp);
350  layout_gen(&pdlay, reqh);
351  write_post(pdlay);
352 
353  read_post(pdlay);
355 
356  m0_fi_disable("cp_stob_io_init", "no-stob");
357 
358  /* IO failure test case. */
359  m0_fi_enable("cp_io", "io-fail");
360 
361  M0_SET0(&w_sns_cp);
362  M0_SET0(&r_sns_cp);
363 
364  layout_gen(&pdlay, reqh);
365  write_post(pdlay);
366 
367  read_post(pdlay);
369  m0_fi_disable("cp_io", "io-fail");
370 
373 
375  m0_fi_disable("m0_sns_cm_tgt_ep", "local-ep");
376 
377  cs_fini(&sctx);
378 }
379 
381  .ts_name = "snscm_storage-ut",
382  .ts_init = NULL,
383  .ts_fini = NULL,
384  .ts_tests = {
385  { "cp_write_read", test_cp_write_read },
386  { NULL, NULL }
387  }
388 };
389 
390 /*
391  * Local variables:
392  * c-indentation-style: "K&R"
393  * c-basic-offset: 8
394  * tab-width: 8
395  * fill-column: 80
396  * scroll-step: 1
397  * End:
398  */
void cs_fini(struct m0_motr *sctx)
Definition: cp_common.c:221
uint64_t ca_lid
Definition: cob.h:380
static int dummy_fom_tick(struct m0_fom *fom)
Definition: storage.c:86
Definition: cm.h:205
struct m0_be_domain * bs_domain
Definition: seg.h:82
static void dummy_cp_complete(struct m0_cm_cp *cp)
Definition: storage.c:144
M0_INTERNAL void m0_fid_gob_make(struct m0_fid *gob_fid, uint32_t container, uint64_t key)
Definition: fid_convert.c:46
struct m0_net_buffer_pool * nb_pool
Definition: net.h:1508
struct m0_reqh * m0_cs_reqh_get(struct m0_motr *cctx)
Definition: setup.c:1762
int cs_init_with_ad_stob(struct m0_motr *sctx)
Definition: cp_common.c:215
static struct m0_semaphore sem
Definition: storage.c:43
static struct m0_sns_cm_ag w_sag
Definition: storage.c:47
#define NULL
Definition: misc.h:38
static int dummy_cp_write(struct m0_cm_cp *cp)
Definition: storage.c:130
struct m0_stob_id sc_stob_id
Definition: cp.h:45
struct m0_bufvec nb_buffer
Definition: net.h:1322
static struct m0_fom_ops dummy_cp_fom_ops
Definition: storage.c:99
M0_INTERNAL struct m0_sns_cm * cm2sns(struct m0_cm *cm)
Definition: cm.c:389
struct m0_pool_version * pm_pver
Definition: pool_machine.h:172
M0_INTERNAL struct m0_pool_version * m0_pool_version_find(struct m0_pools_common *pc, const struct m0_fid *id)
Definition: pool.c:586
struct m0_pool_version * pv
Definition: dir.c:629
struct m0_poolmach pv_mach
Definition: pool.h:133
Definition: cp.h:160
static int cp_prepare(struct m0_cm_cp *cp, struct m0_indexvec *dst_ivec, struct m0_bufvec *dst_bvec, m0_bindex_t start_idx, uint32_t bshift)
Definition: storage.c:117
static void read_post(struct m0_pdclust_layout *pdlay)
Definition: storage.c:252
static int dummy_cp_write_io_wait(struct m0_cm_cp *cp)
Definition: storage.c:171
struct m0_layout * sf_layout
Definition: file.h:74
#define container_of(ptr, type, member)
Definition: misc.h:33
#define M0_SET0(obj)
Definition: misc.h:64
struct m0_poolmach * sf_pm
Definition: file.h:70
Definition: ut.h:77
static struct m0_sns_cm * scm
Definition: storage.c:41
static struct m0_cob_domain * cdom
Definition: xform.c:55
m0_fom_phase
Definition: fom.h:372
struct m0_pdclust_layout * pdlay
Definition: xform.c:51
uint32_t sag_fnr
Definition: ag.h:51
M0_INTERNAL int m0_sns_cm_cp_write_pre(struct m0_cm_cp *cp)
Definition: storage.c:330
return M0_RC(rc)
void write_post(struct m0_pdclust_layout *pdlay)
Definition: storage.c:200
#define M0_ENTRY(...)
Definition: trace.h:170
Definition: cp.h:151
struct m0_fid sc_cobfid
Definition: cp.h:42
struct m0_cm_cp sc_base
Definition: cp.h:39
static struct m0_net_buffer r_buf
Definition: storage.c:54
static struct m0_fid gob_fid
Definition: storage.c:56
enum m0_cm_cp_io_op c_io_op
Definition: cp.h:196
static int dummy_cp_fini(struct m0_cm_cp *cp)
Definition: storage.c:149
#define M0_FID_TINIT(type, container, key)
Definition: fid.h:90
const struct m0_cm_cp_ops read_cp_dummy_ops
Definition: storage.c:230
M0_INTERNAL void m0_fi_disable(const char *fp_func, const char *fp_tag)
Definition: finject.c:485
static void m0_fi_enable(const char *func, const char *tag)
Definition: finject.h:276
#define M0_ASSERT(cond)
M0_INTERNAL int m0_sns_cm_cp_write(struct m0_cm_cp *cp)
Definition: storage.c:335
static struct m0_fid cob_fid
Definition: storage.c:57
static uint64_t dummy_fom_locality(const struct m0_fom *fom)
Definition: storage.c:77
void bv_compare(struct m0_bufvec *b1, struct m0_bufvec *b2, uint32_t seg_nr, uint32_t seg_size)
Definition: cp_common.c:95
M0_INTERNAL int m0_sns_cm_cp_io_wait(struct m0_cm_cp *cp)
Definition: storage.c:341
static int dummy_cp_phase(struct m0_cm_cp *cp)
Definition: storage.c:138
M0_INTERNAL int m0_sns_cm_cp_phase_next(struct m0_cm_cp *cp)
Definition: cp.c:261
M0_INTERNAL void m0_fid_convert_cob2stob(const struct m0_fid *cob_fid, struct m0_stob_id *stob_id)
Definition: fid_convert.c:141
struct m0_cm * cag_cm
Definition: ag.h:70
const struct m0_cm_cp_ops write_cp_dummy_ops
Definition: storage.c:178
M0_INTERNAL void m0_cm_cp_fini(struct m0_cm_cp *cp)
Definition: cp.c:682
M0_INTERNAL void cob_delete(struct m0_cob_domain *cdom, struct m0_be_domain *bedom, uint64_t cont, const struct m0_fid *gfid)
Definition: cm.c:231
const struct m0_cm_cp_ops * c_ops
Definition: cp.h:169
static struct m0_net_buffer_pool nbp
Definition: storage.c:44
M0_INTERNAL bool m0_sns_cm_cp_invariant(const struct m0_cm_cp *cp)
Definition: cp.c:62
int(* co_action[])(struct m0_cm_cp *cp)
Definition: cp.h:259
M0_INTERNAL int m0_semaphore_init(struct m0_semaphore *semaphore, unsigned value)
Definition: semaphore.c:38
static struct m0_rpc_server_ctx sctx
Definition: console.c:88
Definition: reqh.h:94
static int dummy_cp_read(struct m0_cm_cp *cp)
Definition: storage.c:118
Definition: dump.c:103
struct m0_cob_domain * sc_cob_dom
Definition: cm.h:217
void layout_destroy(struct m0_pdclust_layout *pdlay)
Definition: cp_common.c:257
M0_INTERNAL void m0_reqh_idle_wait(struct m0_reqh *reqh)
Definition: reqh.c:606
M0_INTERNAL struct m0_layout * m0_pdl_to_layout(struct m0_pdclust_layout *pl)
Definition: pdclust.c:393
static struct m0_net_buffer w_buf
Definition: storage.c:49
Definition: fom.h:481
const char * ts_name
Definition: ut.h:99
struct m0_ut_suite snscm_storage_ut
Definition: storage.c:380
struct m0_sns_cm_file_ctx * sag_fctx
Definition: ag.h:48
Definition: setup.h:354
M0_INTERNAL int m0_sns_cm_cp_read(struct m0_cm_cp *cp)
Definition: storage.c:324
Definition: fid.h:38
M0_INTERNAL const struct m0_fid M0_MDSERVICE_START_FID
Definition: md_fid.c:68
static struct m0_sns_cm_ag r_sag
Definition: storage.c:52
uint64_t f_key
Definition: fid.h:40
struct m0_motr motr
struct m0_reqh_service cm_service
Definition: cm.h:191
static struct m0_reqh * reqh
Definition: storage.c:42
M0_INTERNAL int m0_sns_cm_cp_fail(struct m0_cm_cp *cp)
Definition: cp.c:216
uint64_t cag_cp_local_nr
Definition: ag.h:92
int(* co_phase_next)(struct m0_cm_cp *cp)
Definition: cp.h:232
void bv_free(struct m0_bufvec *b)
Definition: cp_common.c:115
struct m0_be_seg * rh_beseg
Definition: reqh.h:112
Definition: storage.c:66
M0_INTERNAL void m0_fom_queue(struct m0_fom *fom)
Definition: fom.c:624
static void dummy_fom_fini(struct m0_fom *fom)
Definition: storage.c:71
void(* fo_fini)(struct m0_fom *fom)
Definition: fom.h:657
struct m0_cm sc_base
Definition: cm.h:206
struct m0_cob_attr sf_attr
Definition: file.h:65
static struct m0_sns_cm_file_ctx fctx
Definition: net.c:55
static const struct m0_fid M0_SNS_CM_REPAIR_UT_PVER
Definition: storage.c:59
M0_INTERNAL void m0_semaphore_down(struct m0_semaphore *semaphore)
Definition: semaphore.c:49
M0_INTERNAL void m0_fid_convert_gob2cob(const struct m0_fid *gob_fid, struct m0_fid *cob_fid, uint32_t device_id)
Definition: fid_convert.c:55
static struct m0_sns_cm_cp r_sns_cp
Definition: storage.c:53
struct m0_cm_aggr_group sag_base
Definition: ag.h:46
struct m0_fid gfid
Definition: dir.c:626
M0_INTERNAL void m0_semaphore_up(struct m0_semaphore *semaphore)
Definition: semaphore.c:65
struct m0_pools_common cc_pools_common
Definition: setup.h:356
struct m0_fom c_fom
Definition: cp.h:161
static int dummy_cp_read_io_wait(struct m0_cm_cp *cp)
Definition: storage.c:159
void layout_gen(struct m0_pdclust_layout **pdlay, struct m0_reqh *reqh)
Definition: cp_common.c:227
struct m0_reqh * rs_reqh
Definition: reqh_service.h:259
static struct m0_sns_cm_cp w_sns_cp
Definition: storage.c:48
M0_INTERNAL struct m0_motr * m0_cs_ctx_get(struct m0_reqh *reqh)
Definition: setup.c:1778
static int dummy_cp_init(struct m0_cm_cp *cp)
Definition: storage.c:106
int32_t rc
Definition: trigger_fop.h:47
static void test_cp_write_read(void)
Definition: storage.c:283