Motr  M0
m0t1fs.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012-2020 Seagate Technology LLC and/or its Affiliates
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  * For any questions about this software or licensing,
17  * please email opensource@seagate.com or cortx-questions@seagate.com.
18  *
19  */
20 
21 
22 #include "lib/assert.h"
23 #include "desim/sim.h"
24 #include "desim/net.h"
25 #include "desim/m0t1fs.h"
26 #include "layout/linear_enum.h" /* struct m0_layout_linear_enum */
27 #include "cob/cob.h" /* m0_cob_fid_type */
28 #include "ioservice/fid_convert.h" /* m0_fid_convert_cob2adstob */
29 
35 static void thread_loop(struct sim *s, struct sim_thread *t, void *arg)
36 {
37  struct m0t1fs_thread *cth = arg;
38  struct m0t1fs_client *cl = cth->cth_client;
39  struct m0t1fs_conf *conf = cl->cc_conf;
40  struct m0_pdclust_instance *pi;
41  struct m0_pdclust_layout *pl;
42  uint32_t pl_N;
43  uint32_t pl_K;
44  struct m0_layout_enum *le;
45  int64_t nob;
47  m0_bcount_t unit;
48 
49  M0_ASSERT(t == &cth->cth_thread);
50 
53  pl_N = pl->pl_attr.pa_N;
54  pl_K = pl->pl_attr.pa_K;
55  sim_log(s, SLL_TRACE, "thread [%i:%i]: seed: ["U128X_F"]\n",
56  cl->cc_id, cth->cth_id, U128_P(&pl->pl_attr.pa_seed));
57 
58  unit = conf->ct_unitsize;
60  for (nob = conf->ct_total, grp = 0; nob > 0;
61  nob -= unit * (pl_N + pl_K), grp++) {
62  unsigned idx;
63 
64  sim_sleep(t, sim_rnd(conf->ct_delay_min, conf->ct_delay_max));
65  /* loop over data and parity units, skip spare units. */
66  for (idx = 0; idx < pl_N + pl_K; ++idx) {
67  const struct m0_pdclust_src_addr src = {
68  .sa_group = grp,
69  .sa_unit = idx
70  };
71  struct m0_pdclust_tgt_addr tgt;
72  uint32_t obj;
73  uint32_t srv;
74  struct m0t1fs_conn *conn;
75  struct m0_fid fid;
76  struct m0_stob_id stob_id;
77 
79  /* @todo for parity unit waste some time calculating
80  parity. Limit bus bandwidth. */
81  obj = tgt.ta_obj;
82  M0_ASSERT(obj < conf->ct_pool_version.pv_attr.pa_P);
83  srv = obj / conf->ct_nr_devices;
84  conn = &cl->cc_srv[srv];
85  le->le_ops->leo_get(le, obj, &pi->pi_base.li_gfid,
86  &fid);
87 
89  "%c [%3i:%3i] -> %4u@%3u "FID_F" %6" PRId64 "\n",
90  "DPS"[m0_pdclust_unit_classify(pl, idx)],
91  cl->cc_id, cth->cth_id, obj, srv,
92  FID_P(&fid), tgt.ta_frame);
93 
94  /* wait until rpc can be send to the server. */
95  while (conn->cs_inflight >= conf->ct_inflight_max)
96  sim_chan_wait(&conn->cs_wakeup, t);
97  conn->cs_inflight++;
99  m0_fid_convert_cob2adstob(&fid, &stob_id);
100  net_rpc_process(t, conf->ct_net, &conf->ct_srv[srv],
101  &stob_id, tgt.ta_frame * unit, unit);
102  conn->cs_inflight--;
103  sim_chan_signal(&conn->cs_wakeup);
104  }
105  }
107 }
108 
109 static int threads_start(struct sim_callout *call)
110 {
111  struct m0t1fs_conf *conf = call->sc_datum;
112  unsigned i;
113  unsigned j;
114 
115  for (i = 0; i < conf->ct_nr_clients; ++i) {
116  struct m0t1fs_client *c = &conf->ct_client[i];
117 
118  for (j = 0; j < conf->ct_nr_threads; ++j) {
119  struct m0t1fs_thread *t = &c->cc_thread[j];
120 
121  sim_thread_init(call->sc_sim, &t->cth_thread, 0,
122  thread_loop, t);
123  }
124  }
125  return 1;
126 }
127 
128 static void layout_build(struct m0t1fs_conf *conf)
129 {
130  int result;
131  struct m0_layout_linear_attr lin_attr;
132  struct m0_layout_linear_enum *lin_enum;
133  struct m0_pdclust_attr pl_attr;
134  uint64_t lid;
135 
136  result = m0_layout_domain_init(&conf->ct_l_dom);
137  M0_ASSERT(result == 0);
138 
139  result = m0_layout_standard_types_register(&conf->ct_l_dom);
140  M0_ASSERT(result == 0);
141 
142  lin_attr.lla_nr = conf->ct_pool_version.pv_attr.pa_P;
143  lin_attr.lla_A = 0;
144  lin_attr.lla_B = 1;
145  result = m0_linear_enum_build(&conf->ct_l_dom, &lin_attr, &lin_enum);
146  M0_ASSERT(result == 0);
147 
148  pl_attr.pa_N = conf->ct_N;
149  pl_attr.pa_K = conf->ct_K;
150  pl_attr.pa_S = conf->ct_S;
151  pl_attr.pa_P = conf->ct_pool_version.pv_attr.pa_P;
152  pl_attr.pa_unit_size = conf->ct_unitsize;
153  lid = 0x4332543146535349; /* M0T1FSSI */
154  m0_uint128_init(&pl_attr.pa_seed, "m0t1fs_si_pdclus");
155 
156  result = m0_pdclust_build(&conf->ct_l_dom, lid, &pl_attr,
157  &lin_enum->lle_base, &conf->ct_pdclust);
158  M0_ASSERT(result == 0);
159 }
160 
161 static void m0t1fs_layout_fini(struct m0t1fs_conf *conf)
162 {
163  /*
164  * Delete the reference on the layout object that was acquired in
165  * layout_build() so that the layout gets deleted.
166  */
167  m0_layout_put(&conf->ct_pdclust->pl_base.sl_base);
168 
170  m0_layout_domain_fini(&conf->ct_l_dom);
171 }
172 
173 M0_INTERNAL void m0t1fs_init(struct sim *s, struct m0t1fs_conf *conf)
174 {
175  unsigned i;
176  unsigned j;
177  struct m0_fid gfid0;
178  struct m0_fid p_id = {0x123, 0x456};
179  struct m0_fid pv_id = {0x789, 0x101112};
180  int result;
181 
182  m0_pool_init(&conf->ct_pool, &p_id, 0);
183  m0_pool_version_init(&conf->ct_pool_version, &pv_id, &conf->ct_pool,
184  conf->ct_nr_servers * conf->ct_nr_devices,
185  conf->ct_nr_servers, conf->ct_N, conf->ct_K, conf->ct_S);
186  conf->ct_srv = sim_alloc(conf->ct_nr_servers * sizeof conf->ct_srv[0]);
187  for (i = 0; i < conf->ct_nr_servers; ++i) {
188  struct net_srv *srv = &conf->ct_srv[i];
189 
190  *srv = *conf->ct_srv0;
191  srv->ns_nr_devices = conf->ct_nr_devices;
192  net_srv_init(s, srv);
193  sim_name_set(&srv->ns_name, "%u", i);
194  }
195 
196  conf->ct_client = sim_alloc(conf->ct_nr_clients *
197  sizeof conf->ct_client[0]);
198 
200  m0_fid_set(&gfid0, 0, 999);
201 
202  for (i = 0; i < conf->ct_nr_clients; ++i) {
203  struct m0t1fs_client *c = &conf->ct_client[i];
204 
205  c->cc_conf = conf;
206  c->cc_id = i;
207  c->cc_thread = sim_alloc(conf->ct_nr_threads *
208  sizeof c->cc_thread[0]);
209  c->cc_srv = sim_alloc(conf->ct_nr_servers *
210  sizeof c->cc_srv[0]);
211  for (j = 0; j < conf->ct_nr_servers; ++j)
212  sim_chan_init(&c->cc_srv[j].cs_wakeup,
213  "inflight:%i:%i", i, j);
214  for (j = 0; j < conf->ct_nr_threads; ++j) {
215  struct m0t1fs_thread *th = &c->cc_thread[j];
216  uint64_t delta;
217  struct m0_fid gfid;
218 
219  th->cth_id = j;
220  th->cth_client = c;
221 
222  delta = i * conf->ct_client_step +
223  j * conf->ct_thread_step;
224 
225  gfid.f_container = gfid0.f_container + delta;
226  gfid.f_key = gfid0.f_key - delta;
227 
228  result = m0_layout_instance_build(
229  m0_pdl_to_layout(conf->ct_pdclust),
230  &gfid, &th->cth_layout_instance);
231  M0_ASSERT(result == 0);
232  }
233  }
235 }
236 
237 M0_INTERNAL void m0t1fs_fini(struct m0t1fs_conf *conf)
238 {
239  unsigned i;
240  unsigned j;
241 
242  if (conf->ct_client != NULL) {
243  for (i = 0; i < conf->ct_nr_clients; ++i) {
244  struct m0t1fs_client *c = &conf->ct_client[i];
245 
246  if (c->cc_thread != NULL) {
247  for (j = 0; j < conf->ct_nr_threads; ++j) {
248  struct m0t1fs_thread *cth;
249 
250  cth = &c->cc_thread[j];
253  cth->cth_layout_instance);
254  }
255  sim_free(c->cc_thread);
256  }
257  if (c->cc_srv != NULL) {
258  for (j = 0; j < conf->ct_nr_servers; ++j)
259  sim_chan_fini(&c->cc_srv[j].cs_wakeup);
260  sim_free(c->cc_srv);
261  }
262  }
263  sim_free(conf->ct_client);
264  }
265  if (conf->ct_srv != NULL) {
266  for (i = 0; i < conf->ct_nr_servers; ++i)
267  net_srv_fini(&conf->ct_srv[i]);
268  }
270  m0_pool_fini(&conf->ct_pool);
271 }
272 
275 /*
276  * Local variables:
277  * c-indentation-style: "K&R"
278  * c-basic-offset: 8
279  * tab-width: 8
280  * fill-column: 80
281  * scroll-step: 1
282  * End:
283  */
M0_INTERNAL void sim_thread_init(struct sim *state, struct sim_thread *thread, unsigned stacksize, sim_func_t func, void *arg)
Definition: sim.c:293
M0_INTERNAL void m0_pool_fini(struct m0_pool *pool)
Definition: pool.c:322
Definition: sim.h:152
struct m0_layout * li_l
Definition: layout.h:590
uint64_t sa_group
Definition: pdclust.h:241
#define NULL
Definition: misc.h:38
uint64_t pa_unit_size
Definition: pdclust.h:118
M0_INTERNAL int m0_layout_domain_init(struct m0_layout_domain *dom)
Definition: layout.c:610
M0_INTERNAL void sim_chan_fini(struct sim_chan *chan)
Definition: sim.c:400
uint32_t pa_N
Definition: pdclust.h:104
static struct m0_sm_group * grp
Definition: bytecount.c:38
M0_INTERNAL void sim_free(void *ptr)
Definition: sim.c:98
M0_INTERNAL struct m0_layout_enum * m0_striped_layout_to_enum(const struct m0_striped_layout *stl)
Definition: layout.c:1056
struct m0_layout_instance pi_base
Definition: pdclust.h:173
M0_INTERNAL void m0_uint128_init(struct m0_uint128 *u128, const char *magic)
Definition: misc.c:150
uint32_t pa_K
Definition: pdclust.h:107
M0_INTERNAL void m0_layout_domain_fini(struct m0_layout_domain *dom)
Definition: layout.c:633
M0_INTERNAL void m0_fid_convert_cob2adstob(const struct m0_fid *cob_fid, struct m0_stob_id *stob_id)
Definition: fid_convert.c:38
M0_INTERNAL int m0_linear_enum_build(struct m0_layout_domain *dom, const struct m0_layout_linear_attr *attr, struct m0_layout_linear_enum **out)
Definition: linear_enum.c:138
const struct m0_fid_type m0_cob_fid_type
Definition: cob.c:117
uint64_t ta_obj
Definition: pdclust.h:256
Definition: net.h:57
M0_INTERNAL void sim_log(struct sim *s, enum sim_log_level level, const char *format,...)
Definition: sim.c:527
struct m0t1fs_client * cth_client
Definition: m0t1fs.h:46
Definition: conf.py:1
uint64_t m0_bindex_t
Definition: types.h:80
uint32_t pa_S
Definition: pdclust.h:110
uint64_t m0_bcount_t
Definition: types.h:77
struct m0_pdclust_attr pl_attr
Definition: pdclust.h:150
unsigned cth_id
Definition: m0t1fs.h:47
static struct foo * obj
Definition: tlist.c:302
M0_INTERNAL void net_rpc_process(struct sim_thread *t, struct net_conf *net, struct net_srv *srv, struct m0_stob_id *stob_id, unsigned long long offset, unsigned long count)
Definition: net.c:222
M0_INTERNAL void sim_chan_init(struct sim_chan *chan, char *format,...)
Definition: sim.c:385
M0_INTERNAL void sim_thread_exit(struct sim_thread *thread)
Definition: sim.c:346
M0_INTERNAL int m0_layout_instance_build(struct m0_layout *l, const struct m0_fid *fid, struct m0_layout_instance **out)
Definition: layout.c:1113
M0_INTERNAL int m0_pool_init(struct m0_pool *pool, const struct m0_fid *id, enum m0_pver_policy_code pver_policy)
Definition: pool.c:307
struct m0_fid fid
Definition: di.c:46
int i
Definition: dir.c:1033
static void layout_build(struct m0t1fs_conf *conf)
Definition: m0t1fs.c:128
M0_INTERNAL void m0_fid_set(struct m0_fid *fid, uint64_t container, uint64_t key)
Definition: fid.c:116
struct m0_layout_enum lle_base
Definition: linear_enum.h:69
M0_INTERNAL void sim_thread_fini(struct sim_thread *thread)
Definition: sim.c:333
const struct m0_layout_enum_ops * le_ops
Definition: layout.h:423
struct m0_striped_layout pl_base
Definition: pdclust.h:148
static int threads_start(struct sim_callout *call)
Definition: m0t1fs.c:109
#define M0_ASSERT(cond)
struct crate_conf * conf
M0_INTERNAL void m0t1fs_fini(struct m0t1fs_conf *conf)
Definition: m0t1fs.c:237
#define U128_P(x)
Definition: types.h:45
M0_INTERNAL void m0t1fs_init(struct sim *s, struct m0t1fs_conf *conf)
Definition: m0t1fs.c:173
static struct m0_addb2_callback c
Definition: consumer.c:41
uint8_t p_id[64]
Definition: protocol.h:187
uint64_t ta_frame
Definition: pdclust.h:254
static struct m0_thread t[8]
Definition: service_ut.c:1230
M0_INTERNAL int m0_pool_version_init(struct m0_pool_version *pv, const struct m0_fid *id, struct m0_pool *pool, uint32_t pool_width, uint32_t nr_nodes, uint32_t nr_data, uint32_t nr_failures, uint32_t nr_spare)
Definition: pool.c:522
M0_INTERNAL void sim_timer_add(struct sim *state, sim_time_t delta, sim_call_t *cfunc, void *datum)
Definition: sim.c:189
struct m0t1fs_conf * cc_conf
Definition: m0t1fs.h:58
M0_INTERNAL struct m0_pdclust_layout * m0_layout_to_pdl(const struct m0_layout *l)
Definition: pdclust.c:382
M0_INTERNAL void sim_sleep(struct sim_thread *thread, sim_time_t nap)
Definition: sim.c:372
unsigned cc_id
Definition: m0t1fs.h:53
struct m0_pdclust_instance pi
Definition: fd.c:107
M0_INTERNAL void sim_chan_wait(struct sim_chan *chan, struct sim_thread *thread)
Definition: sim.c:411
uint64_t f_container
Definition: fid.h:39
M0_INTERNAL void sim_chan_signal(struct sim_chan *chan)
Definition: sim.c:447
M0_INTERNAL unsigned long long sim_rnd(unsigned long long a, unsigned long long b)
Definition: sim.c:471
struct m0_rpc_conn conn
Definition: fsync.c:96
M0_INTERNAL void * sim_alloc(size_t size)
Definition: sim.c:85
M0_INTERNAL void m0_pdclust_instance_map(struct m0_pdclust_instance *pi, const struct m0_pdclust_src_addr *src, struct m0_pdclust_tgt_addr *tgt)
Definition: pdclust.c:701
M0_INTERNAL int m0_layout_standard_types_register(struct m0_layout_domain *dom)
Definition: layout.c:671
#define FID_P(f)
Definition: fid.h:77
void(* leo_get)(const struct m0_layout_enum *e, uint32_t idx, const struct m0_fid *gfid, struct m0_fid *out)
Definition: layout.h:437
M0_INTERNAL void net_srv_init(struct sim *s, struct net_srv *srv)
Definition: net.c:101
#define PRId64
Definition: types.h:57
struct m0_layout_instance * cth_layout_instance
Definition: m0t1fs.h:48
struct m0_uint128 pa_seed
Definition: pdclust.h:121
struct m0_fid li_gfid
Definition: layout.h:587
M0_INTERNAL struct m0_layout * m0_pdl_to_layout(struct m0_pdclust_layout *pl)
Definition: pdclust.c:393
#define U128X_F
Definition: types.h:42
void * sc_datum
Definition: sim.h:138
struct sim * sc_sim
Definition: sim.h:142
struct m0_pdclust_tgt_addr tgt
Definition: fd.c:110
unsigned ns_nr_devices
Definition: net.h:59
Definition: fid.h:38
struct m0t1fs_client::m0t1fs_conn * cc_srv
uint64_t f_key
Definition: fid.h:40
uint32_t pa_P
Definition: pdclust.h:115
char * ns_name
Definition: net.h:69
M0_INTERNAL enum m0_pdclust_unit_type m0_pdclust_unit_classify(const struct m0_pdclust_layout *pl, int unit)
Definition: pdclust.c:425
static void m0t1fs_layout_fini(struct m0t1fs_conf *conf)
Definition: m0t1fs.c:161
M0_INTERNAL int m0_pdclust_build(struct m0_layout_domain *dom, uint64_t lid, const struct m0_pdclust_attr *attr, struct m0_layout_enum *le, struct m0_pdclust_layout **out)
Definition: pdclust.c:305
M0_INTERNAL void m0_layout_standard_types_unregister(struct m0_layout_domain *dom)
Definition: layout.c:697
M0_INTERNAL void m0_layout_instance_fini(struct m0_layout_instance *li)
Definition: layout.c:1123
M0_INTERNAL struct m0_pdclust_instance * m0_layout_instance_to_pdi(const struct m0_layout_instance *li)
Definition: pdclust.c:400
static void thread_loop(struct sim *s, struct sim_thread *t, void *arg)
Definition: m0t1fs.c:35
M0_INTERNAL void m0_layout_put(struct m0_layout *l)
Definition: layout.c:893
struct m0_fid gfid
Definition: dir.c:626
M0_INTERNAL void sim_name_set(char **name, const char *format,...)
Definition: sim.c:500
M0_INTERNAL void net_srv_fini(struct net_srv *srv)
Definition: net.c:110
static struct m0_addb2_source * s
Definition: consumer.c:39
struct m0_pdclust_src_addr src
Definition: fd.c:108
Definition: sim.h:287
#define FID_F
Definition: fid.h:75
struct sim_thread cth_thread
Definition: m0t1fs.h:45
static struct net_srv srv
Definition: net_test.c:52
M0_INTERNAL void m0_fid_tassume(struct m0_fid *fid, const struct m0_fid_type *ft)
Definition: fid.c:146