Motr  M0
mt.c
Go to the documentation of this file.
1 /* -*- C -*- */
2 /*
3  * Copyright (c) 2018-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_CLIENT
24 #include "lib/trace.h" /* M0_ERR */
25 #include <stdlib.h>
26 #include <stdio.h>
27 #include <sys/time.h>
28 #include "motr/client.h"
29 #include "motr/idx.h"
30 #include "lib/getopts.h" /* M0_GETOPTS */
31 #include "module/instance.h" /* m0 */
32 
33 
34 /* Client parameters */
35 static char *local_addr;
36 static char *ha_addr;
37 static char *prof;
38 static char *proc_fid;
39 
40 static struct m0_client *m0_instance = NULL;
41 static struct m0_container container;
42 static struct m0_realm uber_realm;
43 static struct m0_config conf;
44 static bool ls = false;
46 static struct m0 instance;
47 
48 extern void st_mt_inst(struct m0_client *client);
49 void st_lsfid_inst(struct m0_client *client,
50  void (*print)(struct m0_fid*));
51 
52 static void ls_print(struct m0_fid* fid)
53 {
55 }
56 
57 static int init(void)
58 {
59  int rc;
60 
61  conf.mc_is_addb_init = true;
62  conf.mc_is_oostore = true;
63  conf.mc_is_read_verify = false;
64  conf.mc_local_addr = local_addr;
65  conf.mc_ha_addr = ha_addr;
66  conf.mc_profile = prof;
67  conf.mc_process_fid = proc_fid;
68  conf.mc_tm_recv_queue_min_len = M0_NET_TM_RECV_QUEUE_DEF_LEN;
69  conf.mc_max_rpc_msg_size = M0_RPC_DEF_MAX_RPC_MSG_SIZE;
70  conf.mc_idx_service_id = M0_IDX_DIX;
71 
72  dix_conf.kc_create_meta = false;
73  conf.mc_idx_service_conf = &dix_conf;
74 
75  /* Client instance */
76  rc = m0_client_init(&m0_instance, &conf, true);
77  if (rc != 0) {
78  m0_console_printf("Failed to initialise Motr client\n");
79  goto err_exit;
80  }
81 
82  /* And finally, client root realm */
85  m0_instance);
87 
88  if (rc != 0) {
89  m0_console_printf("Failed to open uber realm\n");
90  goto err_exit;
91  }
92 
94  return 0;
95 
96 err_exit:
97  return rc;
98 }
99 
100 static void fini(void)
101 {
103 }
104 
105 int main(int argc, char **argv)
106 {
107  int rc;
108 
111  if (rc != 0) {
112  m0_console_printf("Cannot init module %i\n", rc);
113  return rc;
114  }
115 
116  rc = M0_GETOPTS("m0mt", argc, argv,
117  M0_VOIDARG('s', "List all fids client can see",
118  LAMBDA(void, (void) {
119  ls = true;
120  })),
121  M0_STRINGARG('l', "Local endpoint address",
122  LAMBDA(void, (const char *str) {
123  local_addr = (char*)str;
124  })),
125  M0_STRINGARG('h', "HA address",
126  LAMBDA(void, (const char *str) {
127  ha_addr = (char*)str;
128  })),
129  M0_STRINGARG('f', "Process FID",
130  LAMBDA(void, (const char *str) {
131  proc_fid = (char*)str;
132  })),
133  M0_STRINGARG('p', "Profile options for Motr client",
134  LAMBDA(void, (const char *str) {
135  prof = (char*)str;
136  })));
137  if (rc != 0) {
138  m0_console_printf("Usage: m0mt -l laddr -h ha_addr "
139  "-p prof_opt -f proc_fid [-s]\n");
140  goto mod;
141  }
142 
143  /* Initialise motr and Client */
144  rc = init();
145  if (rc < 0) {
146  m0_console_printf("init failed!\n");
147  goto mod;
148  }
149 
150  if (ls) {
151  m0_console_printf("FIDs seen with client:\n");
152  st_lsfid_inst(m0_instance, ls_print); /* Ls test */
153  } else {
154  m0_console_printf("Up to 500 client requests pending, ~100s on devvm:\n");
155  st_mt_inst(m0_instance); /* Load test */
156  }
157 
158  /* Clean-up */
159  fini();
160 mod:
162 
163  return rc;
164 }
165 
166 /*
167  * Local variables:
168  * c-indentation-style: "K&R"
169  * c-basic-offset: 8
170  * tab-width: 8
171  * fill-column: 80
172  * scroll-step: 1
173  * End:
174  */
#define M0_GETOPTS(progname, argc, argv,...)
Definition: getopts.h:169
static char * local_addr
Definition: mt.c:35
static struct m0_container container
Definition: mt.c:41
static int init(void)
Definition: mt.c:57
#define NULL
Definition: misc.h:38
int main(int argc, char **argv)
Definition: mt.c:105
void m0_console_printf(const char *fmt,...)
Definition: trace.c:801
void st_mt_inst(struct m0_client *client)
Definition: mt_fom.c:377
void m0_client_fini(struct m0_client *m0c, bool fini_m0)
Definition: client_init.c:1711
Definition: idx.h:70
Definition: conf.py:1
M0_INTERNAL void m0_instance_setup(struct m0 *instance)
Definition: instance.c:110
static void fini(void)
Definition: mt.c:100
static struct m0_realm uber_realm
Definition: mt.c:42
int m0_client_init(struct m0_client **m0c, struct m0_config *conf, bool init_m0)
Definition: client_init.c:1533
const struct m0_uint128 M0_UBER_REALM
Definition: client.c:85
#define M0_VOIDARG(ch, desc, func)
Definition: getopts.h:177
struct m0_fid fid
Definition: di.c:46
static struct m0 instance
Definition: mt.c:46
#define M0_STRINGARG(ch, desc, func)
Definition: getopts.h:207
struct m0_realm co_realm
Definition: client.h:881
static M0_UNUSED void print(struct m0_be_list *list)
Definition: list.c:186
#define LAMBDA(T,...)
Definition: thread.h:153
struct m0_entity re_entity
Definition: client.h:871
Definition: client.h:37
Definition: instance.h:80
int32_t sm_rc
Definition: sm.h:336
#define FID_P(f)
Definition: fid.h:77
static void ls_print(struct m0_fid *fid)
Definition: mt.c:52
static char * prof
Definition: mt.c:37
Definition: fid.h:38
bool kc_create_meta
Definition: idx.h:183
void m0_container_init(struct m0_container *con, struct m0_realm *parent, const struct m0_uint128 *id, struct m0_client *instance)
Definition: realm.c:31
struct m0_sm en_sm
Definition: client.h:732
static struct m0_idx_dix_config dix_conf
Definition: mt.c:45
static char * ha_addr
Definition: mt.c:36
static bool ls
Definition: mt.c:44
struct m0_module i_self
Definition: instance.h:88
void st_lsfid_inst(struct m0_client *client, void(*print)(struct m0_fid *))
Definition: mt_fom.c:406
int32_t rc
Definition: trigger_fop.h:47
M0_INTERNAL void m0_module_fini(struct m0_module *module, int level)
Definition: module.c:142
#define FID_F
Definition: fid.h:75
M0_INTERNAL int m0_module_init(struct m0_module *module, int level)
Definition: module.c:131
static char * proc_fid
Definition: mt.c:38