Motr  M0
main.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 
30 #define M0_TRACE_SUBSYSTEM M0_TRACE_SUBSYS_BE
31 #include "lib/trace.h"
32 
33 #include <stdio.h> /* printf */
34 #include <stdlib.h> /* EXIT_FAILURE */
35 #include <errno.h> /* ERANGE */
36 
37 #include "lib/string.h" /* m0_streq */
38 #include "lib/errno.h" /* ENOMEM */
39 #include "be/tool/st.h" /* m0_betool_st_mkfs */
40 #include "be/tool/common.h" /* m0_betool_m0_init */
41 #include "be/ut/helper.h" /* m0_be_ut_backend */
42 #include "be/alloc_internal.h" /* m0_be_allocator_header */
43 #include "stob/ad_private.h" /* stob_ad_0type_rec */
44 #include "cob/cob.h" /* m0_cob_domain */
45 #include "stob/ad.h" /* m0_stob_ad_domain */
46 #include "be/extmap_internal.h" /* m0_be_emap */
47 #include "balloc/balloc.h" /* m0_balloc */
48 #include "be/domain.h" /*m0_be_segobj_opt_begine,m0_be_segobj_opt_next*/
49 #include "lib/uuid.h" /* m0_node_uuid_string_set */
50 
51 M0_TL_DESCR_DECLARE(zt, M0_EXTERN);
52 M0_TL_DEFINE(zt, M0_EXTERN, struct m0_be_0type);
53 
54 static const char *betool_help = ""
55 "Usage: m0betool [cmd] [path] [size]\n"
56 "where [cmd] is one from (without quotes):\n"
57 "- 'st mkfs'\n"
58 "- 'st run'\n"
59 "- 'be_recovery_run'\n"
60 "- 'be_log_resize'\n"
61 "- 'track_btree'\n"
62 "- 'print_btree'\n"
63 "\n"
64 "Use case for 'st mkfs' and 'st run': run 'st mkfs' once to initialise \n"
65 "BE data structures, then run 'st run' and kill m0betool process during \n"
66 "'st run' execution. When 'st run' is called next time BE recovery will \n"
67 "replay BE log and 'st run' should be able to continue without any issues. \n"
68 "be_log_resize will create BE log file with custom size. \n"
69 "This is an ST for BE recovery.\n"
70 "\n"
71 "'be_recovery_run' runs BE recovery.\n"
72 "\n"
73 "'path' parameter is an optional path to BE domain stob domain location.\n"
74 "Default BE domain stob domain location is used when this parameter is absent:"
75 "\n"
76 "'be_log_resize' create BE log file without mkfs.\n"
77 "\n"
78 "'path' and 'size' mandatory arguments for be_log_resize. 'size' in bytes. \n"
79 "Usage: m0betool be_log_resize <path> <size> \n"
80 "\n";
81 
82 extern void btree_dbg_print(struct m0_be_btree *tree);
83 
84 void track_cob_btrees(struct m0_cob_domain *cdom, bool print_btree)
85 {
86  if (print_btree) {
87  M0_LOG(M0_ALWAYS, "cd_object_index ");
89  M0_LOG(M0_ALWAYS, "cd_namespace ");
91  M0_LOG(M0_ALWAYS, "cd_fileattr_basic ");
94  } else
95  M0_LOG(M0_ALWAYS,"M0_BE:COB "
96  "cd_object_index btree = %p "
97  "cd_namespace btree = %p "
98  "cd_fileattr_basic btree = %p "
99  "cd_fileattr_omg btree = %p "
100  "cd_fileattr_ea btree = %p",
102  &cdom->cd_namespace,
105  &cdom->cd_fileattr_ea);
106 }
107 
108 void track_ad_btrees(struct stob_ad_0type_rec *rec, bool print_btree)
109 {
110  struct m0_balloc *m0balloc;
111 
112  m0balloc = container_of(rec->sa0_ad_domain->sad_ballroom,
113  struct m0_balloc, cb_ballroom);
114 
115  if (print_btree) {
116  M0_LOG(M0_ALWAYS, "em_mapping");
118  M0_LOG(M0_ALWAYS, "grp_exts");
120  M0_LOG(M0_ALWAYS, "grp_dsc");
121  btree_dbg_print(&m0balloc->cb_db_group_desc);
122  } else
123  M0_LOG(M0_ALWAYS,"M0_BE:AD em_mapping = %p"
124  "cb_db_group_extents btree= %p "
125  "cb_db_group_desc btree= %p",
127  &m0balloc->cb_db_group_extents,
128  &m0balloc->cb_db_group_desc);
129 
130 }
131 static void scan_btree(struct m0_be_domain *dom, bool print_btree)
132 {
133  int left;
134  char *suffix;
135  struct m0_buf opt;
136  struct m0_be_seg *seg;
137  struct m0_be_0type *objtype;
138  struct m0_cob_domain *cdom;
139  struct stob_ad_0type_rec *rec ;
140 
142  if (seg == NULL) {
143  return;
144  }
145 
146  m0_tl_for(zt, &dom->bd_0types, objtype) {
147  for (left = m0_be_segobj_opt_begin(seg, objtype, &opt, &suffix);
148  left > 0 ;
149  left = m0_be_segobj_opt_next(seg, objtype,
150  &opt, &suffix)) {
151 
152  M0_LOG(M0_ALWAYS, "object b0_name = '%s' suffix = '%s'"
153  "objtype = %p seg = %p",
154  objtype->b0_name, suffix,
155  objtype, seg );
156 
157  if (m0_streq(objtype->b0_name, "M0_BE:COB") == 0) {
158  cdom = *(struct m0_cob_domain**)opt.b_addr;
159  track_cob_btrees(cdom, print_btree);
160  }
161  else if (m0_streq(objtype->b0_name, "M0_BE:AD") == 0) {
162  rec = (struct stob_ad_0type_rec *)opt.b_addr;
163  track_ad_btrees(rec, print_btree);
164  }
165  }
166  } m0_tl_endfor;
167 
168 }
169 
170 
171 static void be_recovery_run(char *path)
172 {
173  struct m0_be_ut_backend ut_be = {};
174  struct m0_be_domain_cfg cfg = {};
175  char location[0x100] = {};
176  int rc;
177 
180  if (path != NULL) {
181  snprintf((char *)&location, ARRAY_SIZE(location),
182  "linuxstob:%s", path);
183  cfg.bc_stob_domain_location = (char *)&location;
184  }
185  rc = m0_be_ut_backend_init_cfg(&ut_be, &cfg, false);
186  M0_ASSERT_INFO(rc == 0, "rc=%d", rc);
187 
190 }
191 
192 static int be_log_resize(char *path, uint64_t size)
193 {
194  struct m0_be_ut_backend ut_be = {};
195  struct m0_be_domain_cfg cfg = {};
196  char location[0x100] = {};
197  int rc;
198 
201 
202  if (path != NULL) {
203  snprintf((char *)&location, ARRAY_SIZE(location),
204  "linuxstob:%s", path);
205  cfg.bc_stob_domain_location = (char *)&location;
206  }
209 
211  M0_LOG(M0_DEBUG, "rc=%d", rc);
212 
214  return rc;
215 }
216 
217 static void scan(char *path, char *what)
218 {
219  struct m0_be_ut_backend ut_be = {};
220  struct m0_be_domain_cfg cfg = {};
221  struct m0_be_domain *dom;
222  char location[0x100] = {};
223  int rc;
224 
228  if (path != NULL) {
229  snprintf((char *)&location, ARRAY_SIZE(location),
230  "linuxstob:./%s", path);
231  cfg.bc_stob_domain_location = (char *)&location;
232  M0_LOG(M0_ALWAYS, "location=%s", cfg.bc_stob_domain_location);
233  }
234  rc = m0_be_ut_backend_init_cfg(&ut_be, &cfg, false);
235  M0_ASSERT_INFO(rc == 0, "rc=%d", rc);
236  dom = &ut_be.but_dom;
237  if (m0_streq(what, "track_btree"))
238  scan_btree(dom, false);
239  if (m0_streq(what, "print_btree"))
240  scan_btree(dom, true);
243 }
244 
245 int main(int argc, char *argv[])
246 {
247  struct m0_be_domain_cfg cfg = {};
248  char *path;
249  int rc;
250 
251  if (argc > 1 && m0_streq(argv[1], "be_recovery_run")) {
252  path = argc > 2 ? argv[2] : NULL;
253  be_recovery_run(path);
254  return EXIT_SUCCESS;
255  }
256 
257  if (argc > 1 && m0_streq(argv[1], "be_log_resize")) {
258  uint64_t size;
259 
260  if (argc > 3) {
261  path = argv[2];
262  errno = 0;
263  size = strtoul(argv[3], NULL, 10);
264  } else {
265  printf("%s", betool_help);
266  return EXIT_FAILURE;
267  }
268 
269  if (errno == ERANGE || ((size == 0) && (errno != 0))) {
270  printf("%s", betool_help);
271  return EXIT_FAILURE;
272  }
273 
274  rc = be_log_resize(path, size);
275  return rc;
276  }
277  if (argc > 1 && (m0_streq(argv[1], "track_btree") ||
278  m0_streq(argv[1], "print_btree"))) {
279  path = argc > 2 ? argv[2] : NULL;
280  scan(path, argv[1]);
281  return EXIT_SUCCESS;
282  }
283 
284  if (argc == 3 && m0_streq(argv[1], "st") &&
285  (m0_streq(argv[2], "mkfs") || m0_streq(argv[2], "run"))) {
286  if (m0_streq(argv[2], "mkfs") == 0)
287  rc = m0_betool_st_mkfs();
288  else
289  rc = m0_betool_st_run();
290  } else {
293  printf("%s", betool_help);
294  printf("bc_stob_domain_location=%s\n",
296  rc = EXIT_FAILURE;
298  }
299  return rc;
300 }
301 
302 #undef M0_TRACE_SUBSYSTEM
303 
306 /*
307  * Local variables:
308  * c-indentation-style: "K&R"
309  * c-basic-offset: 8
310  * tab-width: 8
311  * fill-column: 80
312  * scroll-step: 1
313  * End:
314  */
315 /*
316  * vim: tabstop=8 shiftwidth=8 noexpandtab textwidth=80 nowrap
317  */
static void scan(char *path, char *what)
Definition: main.c:217
struct m0_be_btree cb_db_group_desc
Definition: balloc.h:241
M0_INTERNAL int m0_be_ut_backend_init_cfg(struct m0_be_ut_backend *ut_be, const struct m0_be_domain_cfg *cfg, bool mkfs)
Definition: stubs.c:231
#define NULL
Definition: misc.h:38
const char * b0_name
Definition: seg0.h:44
struct m0_be_btree cd_object_index
Definition: cob.h:270
int m0_betool_st_mkfs(void)
Definition: st.c:57
void * b_addr
Definition: buf.h:39
#define M0_LOG(level,...)
Definition: trace.h:167
struct m0_be_btree cb_db_group_extents
Definition: balloc.h:239
void track_cob_btrees(struct m0_cob_domain *cdom, bool print_btree)
Definition: main.c:84
static int be_log_resize(char *path, uint64_t size)
Definition: main.c:192
M0_INTERNAL struct m0_be_seg * m0_be_domain_seg0_get(struct m0_be_domain *dom)
Definition: domain.c:466
static int left
Definition: locality.c:280
M0_TL_DEFINE(zt, M0_EXTERN, struct m0_be_0type)
#define container_of(ptr, type, member)
Definition: misc.h:33
struct m0_be_btree cd_fileattr_basic
Definition: cob.h:2389
struct m0_be_btree cd_fileattr_ea
Definition: cob.h:274
static struct m0_cob_domain * cdom
Definition: xform.c:55
static void be_recovery_run(char *path)
Definition: main.c:171
const char * location
Definition: storage.c:50
#define m0_tl_endfor
Definition: tlist.h:700
Definition: buf.h:37
struct m0_ad_balloc * sad_ballroom
Definition: ad.h:115
struct m0_be_log_store_cfg lc_store_cfg
Definition: log.h:250
void m0_be_ut_backend_cfg_default(struct m0_be_domain_cfg *cfg)
Definition: stubs.c:227
struct m0_be_ut_backend ut_be
Definition: ad.c:72
M0_INTERNAL void btree_dbg_print(struct m0_be_btree *tree)
Definition: btree.c:2505
void m0_betool_m0_fini(void)
Definition: common.c:52
void m0_node_uuid_string_set(const char *uuid)
Definition: uuuid.c:64
#define m0_streq(a, b)
Definition: string.h:34
static struct m0_stob_domain * dom
Definition: storage.c:38
m0_bcount_t lsc_size
Definition: log_store.h:171
int m0_betool_st_run(void)
Definition: st.c:261
struct m0_ad_balloc cb_ballroom
Definition: balloc.h:643
Definition: seg.h:66
struct m0_be_domain but_dom
Definition: helper.h:47
struct m0_be_btree em_mapping
struct m0_be_emap sad_adata
Definition: ad.h:129
M0_INTERNAL int m0_be_ut_backend_log_resize(struct m0_be_ut_backend *ut_be, const struct m0_be_domain_cfg *cfg)
Definition: helper.c:405
struct m0_stob_ad_domain * sa0_ad_domain
Definition: ad_private.h:41
const char * bc_stob_domain_location
Definition: domain.h:87
m0_bcount_t size
Definition: di.c:39
void track_ad_btrees(struct stob_ad_0type_rec *rec, bool print_btree)
Definition: main.c:108
void m0_be_ut_backend_fini(struct m0_be_ut_backend *ut_be)
Definition: stubs.c:242
static const char * betool_help
Definition: main.c:54
struct m0_be_log_cfg bc_log
Definition: domain.h:118
static struct m0_be_seg * seg
Definition: btree.c:40
#define M0_ASSERT_INFO(cond, fmt,...)
int main(int argc, char *argv[])
Definition: main.c:245
M0_INTERNAL int m0_be_segobj_opt_next(struct m0_be_seg *dict, const struct m0_be_0type *objtype, struct m0_buf *opt, char **suffix)
Definition: domain.c:89
void m0_betool_m0_init(void)
Definition: common.c:42
static void scan_btree(struct m0_be_domain *dom, bool print_btree)
Definition: main.c:131
struct m0_be_btree cd_fileattr_omg
Definition: cob.h:273
#define m0_tl_for(name, head, obj)
Definition: tlist.h:695
M0_INTERNAL int m0_be_segobj_opt_begin(struct m0_be_seg *dict, const struct m0_be_0type *objtype, struct m0_buf *opt, char **suffix)
Definition: domain.c:97
int32_t rc
Definition: trigger_fop.h:47
#define ARRAY_SIZE(a)
Definition: misc.h:45
struct m0_be_btree cd_namespace
Definition: cob.h:271
M0_TL_DESCR_DECLARE(zt, M0_EXTERN)