Motr  M0
composite_bootstrap.c
Go to the documentation of this file.
1 /* -*- C -*- */
2 /*
3  * Copyright (c) 2017-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 
24 #include <stdlib.h>
25 #include <stdio.h>
26 #include <unistd.h>
27 #include <errno.h>
28 #include <fcntl.h>
29 #include <sys/time.h>
30 #include <assert.h>
31 
32 #include "motr/client.h"
33 #include "motr/client_internal.h"
34 #include "motr/idx.h"
35 #include "motr/layout.h"
36 
37 
38 /* Client parameters */
39 static char *local_addr;
40 static char *ha_addr;
41 static char *prof;
42 static char *proc_fid;
43 
44 static struct m0_client *m0_instance = NULL;
45 static struct m0_container container;
46 static struct m0_realm uber_realm;
47 static struct m0_config conf;
49 
50 extern struct m0_addb_ctx m0_addb_ctx;
51 
52 static int init(void)
53 {
54  int rc;
55 
56  conf.mc_is_oostore = true;
57  conf.mc_is_read_verify = false;
58  conf.mc_local_addr = local_addr;
59  conf.mc_ha_addr = ha_addr;
60  conf.mc_profile = prof;
61  conf.mc_process_fid = proc_fid;
62  conf.mc_tm_recv_queue_min_len = M0_NET_TM_RECV_QUEUE_DEF_LEN;
63  conf.mc_max_rpc_msg_size = M0_RPC_DEF_MAX_RPC_MSG_SIZE;
64  conf.mc_layout_id = 0;
65 
66  /* Use dix index services. */
67  conf.mc_idx_service_id = M0_IDX_DIX;
68  dix_conf.kc_create_meta = false;
69  conf.mc_idx_service_conf = &dix_conf;
70 
71  /* Client instance */
72  rc = m0_client_init(&m0_instance, &conf, true);
73  if (rc != 0) {
74  fprintf(stderr, "Failed to initialise Client\n");
75  goto err_exit;
76  }
77 
78  /* And finally, client root realm */
81  m0_instance);
83  if (rc != 0) {
84  fprintf(stderr, "Failed to open uber realm\n");
85  goto err_exit;
86  }
88  return 0;
89 
90 err_exit:
91  return rc;
92 }
93 
94 static void fini(void)
95 {
97 }
98 
99 static int create_index(struct m0_fid fid)
100 {
101  int rc;
102  struct m0_op *ops[1] = {NULL};
103  struct m0_idx idx;
104 
105  memset(&idx, 0, sizeof idx);
106  ops[0] = NULL;
107 
108  /* Set an index creation operation. */
109  m0_idx_init(&idx,
110  &container.co_realm, (struct m0_uint128 *)&fid);
111  m0_entity_create(NULL, &idx.in_entity, &ops[0]);
112 
113  /* Launch and wait for op to complete */
114  m0_op_launch(ops, 1);
115  rc = m0_op_wait(ops[0],
117  M0_OS_STABLE),
118  M0_TIME_NEVER);
119  if (rc < 0) return rc;
120 
121  rc = ops[0]->op_sm.sm_rc;
122  if (rc < 0) return rc;
123 
124  /* fini and release */
125  m0_op_fini(ops[0]);
126  m0_op_free(ops[0]);
128 
129  return rc;
130 }
131 
132 static int delete_index(struct m0_fid fid)
133 {
134  int rc;
135  struct m0_op *ops[1] = {NULL};
136  struct m0_idx idx;
137 
138  memset(&idx, 0, sizeof idx);
139  ops[0] = NULL;
140 
141  /* Set an index creation operation. */
142  m0_idx_init(&idx,
143  &container.co_realm, (struct m0_uint128 *)&fid);
144  m0_entity_delete(&idx.in_entity, &ops[0]);
145 
146  /* Launch and wait for op to complete */
147  m0_op_launch(ops, 1);
148  rc = m0_op_wait(ops[0],
150  M0_OS_STABLE),
151  M0_TIME_NEVER);
152  rc = (rc != 0)?rc:ops[0]->op_sm.sm_rc;
153 
154  /* fini and release */
155  m0_op_fini(ops[0]);
156  m0_op_free(ops[0]);
158 
159  return rc;
160 }
161 
162 int main(int argc, char **argv)
163 {
164  int rc;
165 
166  /* Get input parameters */
167  if (argc < 5) {
168  fprintf(stderr,
169  "Usage: m0composite laddr ha_addr prof_opt proc_fid\n");
170  return -1;
171  }
172  local_addr = argv[1];
173  ha_addr = argv[2];
174  prof = argv[3];
175  proc_fid = argv[4];
176 
177  /* Initialise motr and Client */
178  rc = init();
179  if (rc < 0) {
180  fprintf(stderr, "init failed!\n");
181  return rc;
182  }
183 
184  /* Create global extent indices for composite layouts. */
186  if (rc != 0) {
187  fprintf(stderr,
188  "Can't create composite RD extent index, rc=%d!\n", rc);
189  return rc;
190  }
192  if (rc != 0) {
193  fprintf(stderr, "Can't create composite RD extent index!\n");
195  return rc;
196  }
197 
198  /* Clean-up */
199  fini();
200 
201  return 0;
202 }
203 
204 /*
205  * Local variables:
206  * c-indentation-style: "K&R"
207  * c-basic-offset: 8
208  * tab-width: 8
209  * fill-column: 80
210  * scroll-step: 1
211  * End:
212  */
Definition: client.h:835
void m0_entity_fini(struct m0_entity *entity)
Definition: client.c:438
#define NULL
Definition: misc.h:38
static struct m0_realm uber_realm
static char * local_addr
const m0_time_t M0_TIME_NEVER
Definition: time.c:108
void m0_op_fini(struct m0_op *op)
Definition: client.c:847
void m0_client_fini(struct m0_client *m0c, bool fini_m0)
Definition: client_init.c:1711
Definition: idx.h:70
int main(int argc, char **argv)
Definition: conf.py:1
#define M0_BITS(...)
Definition: misc.h:236
struct m0_fid composite_extent_rd_idx_fid
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
static char * proc_fid
struct m0_fid fid
Definition: di.c:46
int32_t m0_op_wait(struct m0_op *op, uint64_t bits, m0_time_t to)
Definition: client.c:739
struct m0_entity in_entity
Definition: client.h:836
struct m0_realm co_realm
Definition: client.h:881
Definition: client.h:641
static int create_index(struct m0_fid fid)
static char * ha_addr
struct m0_entity re_entity
Definition: client.h:871
static int delete_index(struct m0_fid fid)
static struct m0_container container
void m0_op_launch(struct m0_op **op, uint32_t nr)
Definition: client.c:725
int32_t sm_rc
Definition: sm.h:336
int m0_entity_create(struct m0_fid *pool, struct m0_entity *entity, struct m0_op **op)
Definition: obj.c:801
struct m0_fid composite_extent_wr_idx_fid
Definition: fid.h:38
bool kc_create_meta
Definition: idx.h:183
static char * prof
int m0_entity_delete(struct m0_entity *entity, struct m0_op **op)
Definition: obj.c:824
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
static struct m0_idx_dix_config dix_conf
void m0_op_free(struct m0_op *op)
Definition: client.c:885
struct m0_sm en_sm
Definition: client.h:732
static int init(void)
static void fini(void)
struct m0_fom_ops ops
Definition: io_foms.c:623
struct m0_addb_ctx m0_addb_ctx
int32_t rc
Definition: trigger_fop.h:47
void m0_idx_init(struct m0_idx *idx, struct m0_realm *parent, const struct m0_uint128 *id)
Definition: idx.c:626