Motr  M0
recovery.c
Go to the documentation of this file.
1 /* -*- C -*- */
2 /*
3  * Copyright (c) 2015-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 "be/io.h"
24 #include "be/log.h"
25 #include "be/recovery.h"
26 #include "lib/memory.h"
27 #include "stob/domain.h"
28 #include "stob/stob.h"
29 #include "ut/stob.h"
30 #include "ut/ut.h"
31 
32 enum {
33  BE_UT_RECOVERY_LOG_SIZE = 1024 * 1024,
39 };
40 
41 const char *be_ut_recovery_log_sdom_location = "linuxstob:./log";
42 const char *be_ut_recovery_log_sdom_init_cfg = "directio=true";
44 
50 };
51 
52 static void be_ut_log_got_space_cb(struct m0_be_log *log)
53 {
54 }
55 
56 static void be_ut_recovery_log_cfg_set(struct m0_be_log_cfg *log_cfg,
57  struct m0_stob_domain *sdom,
58  struct m0_mutex *lock)
59 {
60  *log_cfg = (struct m0_be_log_cfg){
61  .lc_store_cfg = {
62  /* temporary solution BEGIN */
63  .lsc_stob_domain_location = "linuxstob:./log_store-tmp",
64  .lsc_stob_domain_init_cfg = "directio=true",
65  .lsc_stob_domain_key = 0x1000,
66  .lsc_stob_domain_create_cfg = NULL,
67  /* temporary solution END */
68  .lsc_size = BE_UT_RECOVERY_LOG_SIZE,
69  .lsc_stob_create_cfg = NULL,
70  .lsc_rbuf_nr = BE_UT_RECOVERY_LOG_RBUF_NR,
71  },
72  .lc_got_space_cb = &be_ut_log_got_space_cb,
73  .lc_lock = lock,
74  };
77  &log_cfg->lc_store_cfg.lsc_stob_id);
78 }
79 
81 {
82  struct m0_be_log_cfg log_cfg;
83  int rc;
84 
85  m0_mutex_init(&ctx->burc_lock);
90  &ctx->burc_sdom);
91  M0_UT_ASSERT(rc == 0);
92  be_ut_recovery_log_cfg_set(&log_cfg, ctx->burc_sdom, &ctx->burc_lock);
93  rc = m0_be_log_create(&ctx->burc_log, &log_cfg);
94  M0_UT_ASSERT(rc == 0);
95 }
96 
98 {
99  int rc;
100 
101  m0_be_log_destroy(&ctx->burc_log);
102  rc = m0_stob_domain_destroy(ctx->burc_sdom);
103  M0_UT_ASSERT(rc == 0);
104  m0_mutex_fini(&ctx->burc_lock);
105 }
106 
108 {
109  struct m0_be_log_cfg log_cfg;
110  int rc;
111 
112  be_ut_recovery_log_cfg_set(&log_cfg, ctx->burc_sdom, &ctx->burc_lock);
113  rc = m0_be_log_open(&ctx->burc_log, &log_cfg);
114  M0_UT_ASSERT(rc == 0);
115 }
116 
118 {
119  m0_be_log_close(&ctx->burc_log);
120 }
121 
123 {
125  M0_SET0(&ctx->burc_log);
127 }
128 
130  struct m0_be_log *log)
131 {
132  int rc;
133 
136  M0_UT_ASSERT(rc == 0);
138  M0_UT_ASSERT(rc == 0);
139 }
140 
142 {
145 }
146 
148  int record_nr,
149  int discard_nr,
150  bool last_incomplete)
151 {
152  struct m0_be_log *log = &ctx->burc_log;
153  struct m0_mutex *lock = &ctx->burc_lock;
154  struct m0_be_log_record *record;
155  int i;
156  int rc;
157 
158  M0_ALLOC_ARR(ctx->burc_records, record_nr);
159  M0_UT_ASSERT(ctx->burc_records != NULL);
160 
161  for (i = 0; i < record_nr; ++i) {
162  record = &ctx->burc_records[i];
166  M0_UT_ASSERT(rc == 0);
174  bo_sm.sm_rc);
175  M0_UT_ASSERT(rc == 0);
176 
178  if (i < discard_nr) {
180  record->lgr_size);
181  } else {
183  }
185  }
186 
187  for (i = 0; i < record_nr; ++i) {
188  record = &ctx->burc_records[i];
190  }
191  m0_free(ctx->burc_records);
192 }
193 
195 {
196  struct m0_be_log *log = &ctx->burc_log;
197  struct m0_mutex *lock = &ctx->burc_lock;
198  struct m0_be_log_record record = {};
199  struct m0_be_log_record_iter iter = {};
200  int count = 0;
201  int rc;
202 
205  M0_UT_ASSERT(rc == 0);
207  m0_be_log_recovery_record_get(log, &iter);
208  ++count;
209 
210  /* discard this record to move log's pointers */
211  m0_be_log_record_assign(&record, &iter, true);
217  bo_sm.sm_rc);
218  M0_UT_ASSERT(rc == 0);
220  m0_be_log_record_discard(record.lgr_log, record.lgr_size);
223  }
226 
227  return count;
228 }
229 
231 {
232  struct be_ut_recovery_ctx ctx = {};
233  int count;
234  int nr;
235 
237 
238  /* empty log */
240  M0_UT_ASSERT(count == 0);
241 
242  be_ut_recovery_log_fill(&ctx, 10, 10, false);
245  M0_UT_ASSERT(count == 0);
246 
247  be_ut_recovery_log_fill(&ctx, 10, 5, false);
250  M0_UT_ASSERT(count == 5);
251 
253  be_ut_recovery_log_fill(&ctx, nr, nr - 5, false);
256  M0_UT_ASSERT(count == 5);
257 
260  M0_UT_ASSERT(count == 0);
261 
263 }
264 
265 /*
266  * Local variables:
267  * c-indentation-style: "K&R"
268  * c-basic-offset: 8
269  * tab-width: 8
270  * fill-column: 80
271  * scroll-step: 1
272  * End:
273  */
274 /*
275  * vim: tabstop=8 shiftwidth=8 noexpandtab textwidth=80 nowrap
276  */
M0_INTERNAL void m0_be_log_record_io_size_set(struct m0_be_log_record *record, int index, m0_bcount_t size)
Definition: log.c:636
static struct m0_mutex lock
Definition: transmit.c:326
static void be_ut_recovery_log_fill(struct be_ut_recovery_ctx *ctx, int record_nr, int discard_nr, bool last_incomplete)
Definition: recovery.c:147
static size_t nr
Definition: dump.c:1505
const char * be_ut_recovery_log_sdom_location
Definition: recovery.c:41
#define M0_ALLOC_ARR(arr, nr)
Definition: memory.h:84
static int be_ut_recovery_iter_count(struct be_ut_recovery_ctx *ctx)
Definition: recovery.c:194
M0_INTERNAL void m0_mutex_unlock(struct m0_mutex *mutex)
Definition: mutex.c:66
#define NULL
Definition: misc.h:38
Definition: io.h:230
static void be_ut_recovery_log_reopen(struct be_ut_recovery_ctx *ctx)
Definition: recovery.c:122
M0_INTERNAL int m0_be_log_record_iter_init(struct m0_be_log_record_iter *iter)
Definition: log.c:1151
char * lsc_stob_domain_location
Definition: log_store.h:144
M0_INTERNAL bool m0_be_log_recovery_record_available(struct m0_be_log *log)
Definition: log.c:1214
M0_INTERNAL int m0_be_log_record_allocate(struct m0_be_log_record *record)
Definition: log.c:615
M0_INTERNAL void m0_be_log_record_io_launch(struct m0_be_log_record *record, struct m0_be_op *op)
Definition: log.c:795
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
static void be_ut_recovery_log_close(struct be_ut_recovery_ctx *ctx)
Definition: recovery.c:117
M0_INTERNAL int m0_be_log_open(struct m0_be_log *log, struct m0_be_log_cfg *log_cfg)
Definition: log.c:281
M0_INTERNAL void m0_be_log_record_io_prepare(struct m0_be_log_record *record, enum m0_stob_io_opcode opcode, m0_bcount_t size_reserved)
Definition: log.c:660
struct m0_mutex burc_lock
Definition: recovery.c:47
#define M0_SET0(obj)
Definition: misc.h:64
M0_INTERNAL void m0_mutex_lock(struct m0_mutex *mutex)
Definition: mutex.c:49
static void be_ut_log_got_space_cb(struct m0_be_log *log)
Definition: recovery.c:52
static m0_bcount_t count
Definition: xcode.c:167
M0_INTERNAL int m0_be_log_record_io_create(struct m0_be_log_record *record, m0_bcount_t size_max)
Definition: log.c:558
op
Definition: libdemo.c:64
static void be_ut_recovery_log_record_fini_one(struct m0_be_log_record *record)
Definition: recovery.c:141
const char * be_ut_recovery_log_sdom_init_cfg
Definition: recovery.c:42
int i
Definition: dir.c:1033
struct m0_be_log_store_cfg lc_store_cfg
Definition: log.h:250
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
M0_INTERNAL void m0_be_log_record_assign(struct m0_be_log_record *record, struct m0_be_log_record_iter *iter, bool need_discard)
Definition: log.c:467
static void be_ut_recovery_log_open(struct be_ut_recovery_ctx *ctx)
Definition: recovery.c:107
M0_INTERNAL void m0_be_log_close(struct m0_be_log *log)
Definition: log.c:287
#define M0_BE_OP_SYNC_RET(op_obj, action, member)
Definition: op.h:243
static void be_ut_recovery_log_init(struct be_ut_recovery_ctx *ctx)
Definition: recovery.c:80
const char * be_ut_recovery_log_sdom_create_cfg
Definition: recovery.c:43
struct m0_be_log burc_log
Definition: recovery.c:46
static void be_ut_recovery_log_fini(struct be_ut_recovery_ctx *ctx)
Definition: recovery.c:97
M0_INTERNAL void m0_be_log_record_fini(struct m0_be_log_record *record)
Definition: log.c:410
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
void m0_be_ut_recovery(void)
Definition: recovery.c:230
M0_INTERNAL int m0_be_log_create(struct m0_be_log *log, struct m0_be_log_cfg *log_cfg)
Definition: log.c:292
M0_INTERNAL void m0_mutex_init(struct m0_mutex *mutex)
Definition: mutex.c:35
struct m0_stob_domain * burc_sdom
Definition: recovery.c:48
M0_INTERNAL void m0_be_log_record_discard(struct m0_be_log *log, m0_bcount_t size)
Definition: log.c:523
M0_INTERNAL void m0_be_log_record_reset(struct m0_be_log_record *record)
Definition: log.c:433
M0_INTERNAL int m0_be_log_reserve(struct m0_be_log *log, m0_bcount_t size)
Definition: log.c:850
M0_INTERNAL void m0_be_log_recovery_record_get(struct m0_be_log *log, struct m0_be_log_record_iter *iter)
Definition: log.c:1221
M0_INTERNAL void m0_be_log_destroy(struct m0_be_log *log)
Definition: log.c:298
M0_INTERNAL void m0_mutex_fini(struct m0_mutex *mutex)
Definition: mutex.c:42
static void be_ut_recovery_log_record_init_one(struct m0_be_log_record *record, struct m0_be_log *log)
Definition: recovery.c:129
Definition: record.py:1
M0_INTERNAL void m0_be_log_record_iter_fini(struct m0_be_log_record_iter *iter)
Definition: log.c:1156
static void be_ut_recovery_log_cfg_set(struct m0_be_log_cfg *log_cfg, struct m0_stob_domain *sdom, struct m0_mutex *lock)
Definition: recovery.c:56
Definition: nucleus.c:42
Definition: log.h:261
M0_INTERNAL void m0_be_log_record_deallocate(struct m0_be_log_record *record)
Definition: log.c:630
Definition: io.h:229
struct m0_be_log_record * burc_records
Definition: recovery.c:49
M0_INTERNAL void m0_be_log_record_skip_discard(struct m0_be_log_record *record)
Definition: log.c:505
void m0_free(void *data)
Definition: memory.c:146
Definition: mutex.h:47
M0_INTERNAL void m0_be_log_record_init(struct m0_be_log_record *record, struct m0_be_log *log)
Definition: log.c:390
int32_t rc
Definition: trigger_fop.h:47
#define M0_UT_ASSERT(a)
Definition: ut.h:46
struct m0_stob_id lsc_stob_id
Definition: log_store.h:135
static struct m0_stob_domain * sdom
Definition: reqh_fom_ut.c:73