Motr  M0
crate_client_utils.c
Go to the documentation of this file.
1 /* -*- C -*- */
2 /*
3  * Copyright (c) 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 #include <errno.h>
31 #include "lib/trace.h"
32 #include "motr/m0crate/logger.h"
33 #include "motr/client_internal.h" /* m0_instance */
35 
36 #define LOG_PREFIX "utils:"
37 
38 struct crate_conf *conf = NULL;
39 struct m0_config m0_conf = {};
41 static int num_m0_workloads = 0;
43 struct m0_container container = {};
44 static struct m0_realm uber_realm = {};
45 static struct m0_idx_dix_config dix_conf = {};
46 
48 {
50  return &uber_realm;
51 }
52 
54 {
55  int rc = 0;
56 
59 
60  if (m0_thread_tls() != NULL)
61  return M0_RC(rc);
62 
63  rc = m0_thread_adopt(&task->mthread, m0_instance->m0c_motr);
64  if (rc < 0) {
65  crlog(CLL_ERROR, "Motr adoptation failed");
66  }
67 
68  return M0_RC(rc);
69 }
70 
72 {
74 }
75 
77 {
78  conf->kc_create_meta = false;
79 }
80 
81 int init(struct workload *w)
82 {
83  int rc;
84 
86 
87  if (num_m0_workloads != 1) {
88  rc = 0;
89  goto do_exit;
90  }
91 
92  m0_conf.mc_is_addb_init = conf->is_addb_init;
93  m0_conf.mc_addb_size = conf->addb_size;
94  m0_conf.mc_is_oostore = conf->is_oostrore;
95  m0_conf.mc_is_read_verify = conf->is_read_verify;
96  m0_conf.mc_local_addr = conf->local_addr;
97  m0_conf.mc_ha_addr = conf->ha_addr;
98  m0_conf.mc_profile = conf->prof;
99  m0_conf.mc_process_fid = conf->process_fid;
100  m0_conf.mc_tm_recv_queue_min_len = conf->tm_recv_queue_min_len ?:
102  m0_conf.mc_max_rpc_msg_size = conf->max_rpc_msg_size ?:
104  m0_conf.mc_layout_id = conf->layout_id;
105  m0_conf.mc_idx_service_id = conf->index_service_id;
106 
108  cass_conf.cc_cluster_ep = conf->cass_cluster_ep;
109  cass_conf.cc_keyspace = conf->cass_keyspace;
112  } else if (m0_conf.mc_idx_service_id == M0_IDX_DIX ||
116  } else {
117  rc = -EINVAL;
118  cr_log(CLL_ERROR, "Unknown index service id: %d!\n",
120  goto do_exit;
121  }
122 
123  /* Client instance */
124  rc = m0_client_init(&m0_instance, &m0_conf, true);
125  if (rc != 0) {
126  cr_log(CLL_ERROR, "Failed to initialise Client: %d\n", rc);
127  goto do_exit;
128  }
129 
131 
132  /* And finally, client root realm */
135  m0_instance);
136 
138  if (rc != 0) {
139  cr_log(CLL_ERROR, "Failed to open uber realm\n");
140  goto do_exit;
141  }
142 
145 
146 do_exit:
147  return rc;
148 }
149 
151 {
152  m0_free(conf->local_addr);
153  m0_free(conf->ha_addr);
154  m0_free(conf->prof);
155  m0_free(conf->process_fid);
156  m0_free(conf->cass_cluster_ep);
157  m0_free(conf->cass_keyspace);
158  m0_free(conf);
159 }
160 
161 int fini(struct workload *w)
162 {
164  if(num_m0_workloads == 0) {
166  free_m0_conf();
167  }
168  return 0;
169 }
170 
171 void check(struct workload *w)
172 {
173 }
174 
177 /*
178  * Local variables:
179  * c-indentation-style: "K&R"
180  * c-basic-offset: 8
181  * tab-width: 8
182  * fill-column: 80
183  * scroll-step: 1
184  * End:
185  */
186 /*
187  * vim: tabstop=8 shiftwidth=8 noexpandtab textwidth=80 nowrap
188  */
#define M0_PRE(cond)
struct m0_config m0_conf
char * cc_cluster_ep
Definition: idx.h:163
uint32_t mc_layout_id
Definition: client.h:954
static struct m0_realm uber_realm
#define NULL
Definition: misc.h:38
const char * mc_process_fid
Definition: client.h:937
bool mc_is_addb_init
Definition: client.h:930
struct m0_container container
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 int m0_thread_adopt(struct m0_thread *thread, struct m0 *instance)
Definition: thread.c:127
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
char * cc_keyspace
Definition: idx.h:164
int adopt_motr_thread(struct m0_workload_task *task)
return M0_RC(rc)
M0_INTERNAL struct m0_thread_tls * m0_thread_tls(void)
Definition: kthread.c:67
struct m0_thread mthread
Definition: crate_client.h:124
struct m0_realm co_realm
Definition: client.h:881
const char * mc_ha_addr
Definition: client.h:935
struct m0_entity re_entity
Definition: client.h:871
bool mc_is_oostore
Definition: client.h:920
void free_m0_conf()
static void dix_config_init(struct m0_idx_dix_config *conf)
#define M0_POST(cond)
int32_t sm_rc
Definition: sm.h:336
M0_INTERNAL void m0_thread_shun(void)
Definition: thread.c:134
bool mc_is_read_verify
Definition: client.h:925
void * mc_idx_service_conf
Definition: client.h:957
int init(struct workload *w)
m0_bcount_t mc_addb_size
Definition: client.h:962
uint32_t mc_max_rpc_msg_size
Definition: client.h:949
const char * mc_local_addr
Definition: client.h:933
int mc_idx_service_id
Definition: client.h:956
uint32_t mc_tm_recv_queue_min_len
Definition: client.h:944
void cr_log(enum cr_log_level lev, const char *fmt,...)
Definition: logger.c:39
static int num_m0_workloads
int fini(struct workload *w)
void check(struct workload *w)
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_client * re_instance
Definition: client.h:873
const char * mc_profile
Definition: client.h:938
struct m0_realm * crate_uber_realm()
struct m0_sm en_sm
Definition: client.h:732
#define crlog(level,...)
Definition: logger.h:55
void m0_free(void *data)
Definition: memory.c:146
int32_t rc
Definition: trigger_fop.h:47
int cc_max_column_family_num
Definition: idx.h:165
struct m0_idx_cass_config cass_conf
void release_motr_thread(struct m0_workload_task *task)
static struct m0_idx_dix_config dix_conf