Motr  M0
m0ctgdump.c
Go to the documentation of this file.
1 /* -*- C -*- */
2 /*
3  * Copyright (c) 2022 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> /* fprintf */
24 #include <unistd.h> /* pause */
25 #include <signal.h> /* sigaction */
26 #include <sys/time.h>
27 #include <sys/resource.h>
28 
29 #define M0_TRACE_SUBSYSTEM M0_TRACE_SUBSYS_CAS
30 #include "lib/trace.h"
31 #include "lib/errno.h"
32 #include "lib/memory.h"
33 #include "lib/misc.h" /* M0_SET0 */
34 #include "lib/uuid.h" /* m0_node_uuid_string_set */
35 
36 #include "motr/setup.h"
37 #include "motr/init.h"
38 #include "motr/version.h"
39 #include "module/instance.h" /* m0 */
40 #include "net/lnet/lnet.h"
41 #include "reqh/reqh_service.h"
42 #include "motr/setup_dix.h"
43 #include "cas/ctg_store.h"
44 
45 M0_INTERNAL int main(int argc, char **argv)
46 {
47  struct m0_motr motr_ctx;
48  static struct m0 instance;
49  struct rlimit rlim = {10240, 10240};
50  char *uuid = NULL;
51  int rc;
52  int i;
53 
54  if (argc > 1 &&
55  (strcmp(argv[1], "-v") == 0 || strcmp(argv[1], "--version") == 0)) {
57  exit(EXIT_SUCCESS);
58  }
59 
60  rc = setrlimit(RLIMIT_NOFILE, &rlim);
61  if (rc != 0) {
62  m0_console_printf("\n Failed to setrlimit\n");
63  goto out;
64  }
65 
66  for (i = 0; i < argc; ++i)
67  if (m0_streq("-u", argv[i])) {
68  uuid = argv[i + 1];
69  break;
70  }
72 
73  errno = 0;
74  M0_SET0(&motr_ctx);
75  rc = m0_init(&instance);
76  if (rc != 0) {
77  m0_console_printf("\n Failed to initialise Motr \n");
78  goto out;
79  }
80 
82  stderr, false /*not mkfs */);
83  if (rc != 0) {
84  m0_console_printf("\n Failed to initialise Motr \n");
85  goto cleanup;
86  }
87 
88  rc = m0_cs_setup_env(&motr_ctx, argc, argv);
89  if (rc != 0) {
90  m0_console_printf("\n Failed to setup cs env \n");
91  goto cs_fini;
92  }
93 
94  /*
95  * Usage of m0ctgdump:
96  * m0ctgdump "cs setup options" + hex (if printing kv pairs in hex)
97  * + index's global fid
98  */
99  M0_ASSERT(argc >= 2);
100  rc = ctgdump(&motr_ctx, argv[argc - 1], argv[argc - 2]);
101  fflush(stdout);
102 
103 cs_fini:
104  m0_cs_fini(&motr_ctx);
105 cleanup:
106  m0_fini();
107 out:
108  errno = rc < 0 ? -rc : rc;
109  return errno;
110 }
111 
112 /*
113  * Local variables:
114  * c-indentation-style: "K&R"
115  * c-basic-offset: 8
116  * tab-width: 8
117  * fill-column: 80
118  * scroll-step: 1
119  * End:
120  */
void cs_fini(struct m0_motr *sctx)
Definition: cp_common.c:221
struct m0_uint128 uuid[1000]
Definition: uuid.c:73
#define NULL
Definition: misc.h:38
void m0_fini(void)
Definition: init.c:318
void m0_console_printf(const char *fmt,...)
Definition: trace.c:801
int m0_cs_setup_env(struct m0_motr *cctx, int argc, char **argv)
Definition: setup.c:2972
void m0_cs_fini(struct m0_motr *cctx)
Definition: setup.c:3029
int m0_init(struct m0 *instance)
Definition: init.c:310
#define M0_SET0(obj)
Definition: misc.h:64
int i
Definition: dir.c:1033
void m0_build_info_print(void)
Definition: version.c:66
#define M0_ASSERT(cond)
void m0_node_uuid_string_set(const char *uuid)
Definition: uuuid.c:64
#define m0_streq(a, b)
Definition: string.h:34
int m0_net_xprt_nr(void)
Definition: net.c:168
Definition: instance.h:80
M0_INTERNAL int main(int argc, char **argv)
Definition: m0ctgdump.c:45
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
Definition: setup.h:354
struct m0_net_xprt ** m0_net_all_xprt_get(void)
Definition: net.c:161
int ctgdump(struct m0_motr *motr_ctx, char *fidstr, char *dump_in_hex_str)
Definition: ctg_store.c:2235
static struct m0 instance
Definition: main.c:78
#define out(...)
Definition: gen.c:41
int32_t rc
Definition: trigger_fop.h:47