Motr  M0
obj.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 #include "motr/client.h"
24 #include "motr/client_internal.h"
25 #include "motr/layout.h"
26 #include "motr/idx.h"
27 #include "motr/sync.h"
28 
29 #include "lib/errno.h"
30 #include "fid/fid.h" /* m0_fid */
31 #include "lib/locality.h" /* m0_locality_here() */
32 #include "lib/misc.h" /* m0_strtou64() */
33 #include "ioservice/fid_convert.h" /* m0_fid_convert_ */
34 #include "layout/layout.h" /* m0_lid_to_unit_map */
35 #include "conf/helpers.h" /* m0_confc_root_open */
36 
37 #define M0_TRACE_SUBSYSTEM M0_TRACE_SUBSYS_CLIENT
38 #include "lib/trace.h"
39 #include "lib/finject.h"
40 
41 
42 M0_INTERNAL struct m0_client*
44 {
45  M0_PRE(oo != NULL);
46 
48 }
49 
50 M0_INTERNAL struct m0_obj*
51 m0__obj_entity(struct m0_entity *entity)
52 {
53  struct m0_obj *obj;
54 
55  M0_PRE(entity != NULL);
56 
57  return M0_AMB(obj, entity, ob_entity);
58 }
59 
67 static bool m0_op_common_invariant(struct m0_op_common *oc)
68 {
69  return M0_RC(oc != NULL &&
70  m0_op_common_bob_check(oc));
71 }
72 
73 M0_INTERNAL bool m0_op_obj_ast_rc_invariant(struct m0_ast_rc *ar)
74 {
75  return M0_RC(ar != NULL &&
76  m0_ast_rc_bob_check(ar));
77 }
78 
79 M0_INTERNAL bool m0_op_obj_invariant(struct m0_op_obj *oo)
80 {
81  return M0_RC(oo != NULL &&
82  m0_op_obj_bob_check(oo) &&
83  oo->oo_oc.oc_op.op_size >= sizeof *oo &&
86 }
87 
95 static bool obj_op_obj_invariant(struct m0_op_obj *oo)
96 {
97  bool rc;
98 
99  /* Don't use a m0__xxx_instance, as they assert */
100  if(oo == NULL)
101  rc = false;
102  else if(oo->oo_oc.oc_op.op_entity == NULL)
103  rc = false;
104  else if(oo->oo_oc.oc_op.op_entity->en_realm == NULL)
105  rc = false;
106  else if(oo->oo_oc.oc_op.op_entity->en_realm->re_instance == NULL)
107  rc = false;
108  else
109  rc = true;
110 
111  return M0_RC(rc);
112 }
113 
114 static bool obj_layout_id_invariant(uint64_t layout_id)
115 {
116 
117  int ltype = M0_OBJ_LAYOUT_TYPE(layout_id);
118  uint64_t lid = M0_OBJ_LAYOUT_ID(layout_id);
119 
120  return M0_RC(M0_IN(ltype, (M0_LT_PDCLUST,
122  M0_LT_CAPTURE)) &&
123  lid > 0 && lid < m0_lid_to_unit_map_nr);
124 }
125 
126 M0_INTERNAL uint64_t m0__obj_lid(struct m0_obj *obj)
127 {
128  uint64_t lid;
129 
130  M0_ENTRY();
131  M0_PRE(obj != NULL);
132  M0_PRE(obj_layout_id_invariant(obj->ob_attr.oa_layout_id));
133  lid = M0_OBJ_LAYOUT_ID(obj->ob_attr.oa_layout_id);
134  M0_LEAVE();
135  return lid;
136 }
137 
138 M0_INTERNAL enum m0_client_layout_type
140 {
141  int type;
142 
143  M0_ENTRY();
144  M0_PRE(obj != NULL);
145  M0_PRE(obj_layout_id_invariant(obj->ob_attr.oa_layout_id));
146  type = M0_OBJ_LAYOUT_TYPE(obj->ob_attr.oa_layout_id);
147  M0_LEAVE();
148  return type;
149 }
150 
151 M0_INTERNAL void m0__obj_attr_set(struct m0_obj *obj,
152  struct m0_fid pver,
153  uint64_t layout_id)
154 {
155  M0_ENTRY();
156  M0_PRE(obj != NULL);
158  obj->ob_attr.oa_layout_id = layout_id;
159  obj->ob_attr.oa_pver = pver;
160  M0_LEAVE();
161 }
162 
163 M0_INTERNAL struct m0_fid m0__obj_pver(struct m0_obj *obj)
164 {
165  return obj->ob_attr.oa_pver;
166 }
167 
168 M0_INTERNAL bool
170 {
171  struct m0_client *cinst;
172 
173  M0_PRE(obj != NULL);
174  cinst = m0__entity_instance(&obj->ob_entity);
175  return m0_conf_fid_is_valid(&obj->ob_attr.oa_pver) && (
177  &obj->ob_attr.oa_pver) != NULL);
178 }
179 
187 static void obj_namei_cb_cancel(struct m0_op_common *oc)
188 {
189  int rc;
190  struct m0_op_obj *oo;
191  struct m0_op *op;
192 
193  M0_ENTRY();
194 
195  M0_PRE(oc != NULL);
196  op = &oc->oc_op;
197  M0_PRE(op->op_entity != NULL);
198  M0_PRE(m0_sm_group_is_locked(&op->op_sm_group));
199  M0_PRE(M0_IN(op->op_code, (M0_EO_CREATE,
200  M0_EO_DELETE,
201  M0_EO_OPEN)));
202 
203  oo = bob_of(oc, struct m0_op_obj, oo_oc, &oo_bobtype);
205 
207  op->op_rc = rc;
208  M0_LEAVE();
209 }
210 
219 static void obj_namei_cb_launch(struct m0_op_common *oc)
220 {
221  int rc;
222  struct m0_op_obj *oo;
223  struct m0_op *op;
224 
225  M0_ENTRY();
226 
227  M0_PRE(oc != NULL);
228  op = &oc->oc_op;
229  M0_PRE(op->op_entity != NULL);
231  &op->op_entity->en_id) < 0);
232  M0_PRE(M0_IN(op->op_code, (M0_EO_CREATE,
233  M0_EO_DELETE,
234  M0_EO_OPEN)));
235  M0_PRE(M0_IN(op->op_entity->en_sm.sm_state, (M0_ES_INIT,
236  M0_ES_OPEN)));
237  M0_PRE(m0_sm_group_is_locked(&op->op_sm_group));
238  M0_ASSERT(entity_invariant_full(op->op_entity));
239 
240  oo = bob_of(oc, struct m0_op_obj, oo_oc, &oo_bobtype);
242 
243  /* Move to a different state and call the control function. */
244  m0_sm_group_lock(&op->op_entity->en_sm_group);
245  switch (op->op_code) {
246  case M0_EO_CREATE:
247  m0_sm_move(&op->op_entity->en_sm, 0,
249  break;
250  case M0_EO_DELETE:
251  m0_sm_move(&op->op_entity->en_sm, 0,
253  break;
254  case M0_EO_OPEN:
255  m0_sm_move(&op->op_entity->en_sm, 0,
256  M0_ES_OPENING);
257  break;
258  default:
259  M0_IMPOSSIBLE("Management operation not implemented");
260  }
261  m0_sm_group_unlock(&op->op_entity->en_sm_group);
262 
263  rc = m0__obj_namei_send(oo);
264  if (rc == 0) {
265  m0_sm_move(&op->op_sm, 0, M0_OS_LAUNCHED);
266  } else if (rc == MOTR_MDCOB_LOOKUP_SKIP) {
267  /* This means meta-data lookup is skipped and op state is
268  * already moved to LAUNCHED --> EXECUTED --> STABLE, so
269  * skipped m0_sm_move() and resetting rc state to 0
270  * */
271  (void)rc;
272  }
273 
274  M0_LEAVE();
275 }
276 
285 static void obj_namei_cb_free(struct m0_op_common *oc)
286 {
287  struct m0_op_obj *oo;
288 
289  M0_ENTRY();
290 
291  M0_PRE(oc != NULL);
292  M0_PRE((oc->oc_op.op_size >= sizeof *oo));
293 
294  /* By now, fini() has been called and bob_of cannot be used */
295  oo = M0_AMB(oo, oc, oo_oc);
297 
298  m0_free(oo);
299 
300  M0_LEAVE();
301 }
302 
311 static void obj_namei_cb_fini(struct m0_op_common *oc)
312 {
313  struct m0_op_obj *oo;
314  struct m0_client *cinst;
315 
316  M0_ENTRY();
317  M0_PRE(oc != NULL);
318  M0_PRE(oc->oc_op.op_size >= sizeof *oo);
319 
320  oo = bob_of(oc, struct m0_op_obj, oo_oc, &oo_bobtype);
322 
323  cinst = m0__oo_instance(oo);
324  M0_ASSERT(cinst != NULL);
325 
326  if (oo->oo_layout_instance != NULL) {
328  oo->oo_layout_instance = NULL;
329  }
330 
331  m0_op_common_bob_fini(&oo->oo_oc);
332  m0_ast_rc_bob_fini(&oo->oo_ar);
333  m0_op_obj_bob_fini(oo);
334 
335  M0_SET0(&oo->oo_fid);
336 
337 #ifdef CLIENT_FOR_M0T1FS
338  M0_SET0(&oo->oo_pfid);
339  m0_buf_free(&oo->oo_name);
340 #endif
341 
342  M0_LEAVE();
343 }
344 
345 M0_INTERNAL int
347  struct m0_pool_version **pv)
348 {
349  int rc;
350  struct m0_client *cinst;
351  struct m0_fid *pool;
352 
353  M0_ENTRY();
354 
356 
357  if (pv == NULL)
358  return M0_ERR(-ENOENT);
359 
360  if (M0_FI_ENABLED("fake_pool_version")) {
362  return 0;
363  }
364 
368  &obj->ob_attr.oa_pver);
369  rc = (*pv != NULL)? 0 : -ENOENT;
370  } else {
371  pool = m0_fid_is_set(&obj->ob_attr.oa_pool)?
372  &obj->ob_attr.oa_pool : NULL;
374  if (rc != 0)
375  return M0_ERR(rc);
376  M0_ASSERT(*pv != NULL);
377  obj->ob_attr.oa_pver = (*pv)->pv_id;
378  }
379 
380  return M0_RC(rc);
381 }
382 
383 M0_INTERNAL uint64_t
385 {
386  uint64_t lid;
387  struct m0_obj *obj;
388 
389  M0_ENTRY();
390 
391  if (M0_FI_ENABLED("fake_obj_layout_id"))
392  return 1;
393 
395  M0_ASSERT(obj_layout_id_invariant(obj->ob_attr.oa_layout_id));
396  lid = M0_OBJ_LAYOUT_ID(obj->ob_attr.oa_layout_id);
397 
398  M0_LEAVE();
399  return lid;
400 }
401 
402 M0_INTERNAL int
404  const uint64_t layout_id,
405  const struct m0_fid *fid,
406  struct m0_layout_instance **linst)
407 {
408  int rc = -EINVAL;
409  struct m0_layout *layout;
410 
411  M0_PRE(cinst != NULL);
412  M0_PRE(linst != NULL);
413  M0_PRE(fid != NULL);
414 
415  /*
416  * All the layouts should already be generated on startup and added
417  * to the list unless wrong layout_id is used.
418  */
420  if (layout != NULL) {
421  *linst = NULL;
422  rc = m0_layout_instance_build(layout, fid, linst);
423  m0_layout_put(layout);
424  }
425 
426  return M0_RC(rc);
427 }
428 
429 #ifdef CLIENT_FOR_M0T1FS
430 
438 int obj_fid_make_name(char *name, size_t name_len,
439  const struct m0_fid *fid)
440 {
441  int rc;
442 
443  M0_PRE(name != NULL);
444  M0_PRE(name_len > 0);
445  M0_PRE(fid != NULL);
446 
447  rc = snprintf(name, name_len, "%" PRIx64 ":%"PRIx64, FID_P(fid));
448  M0_ASSERT(rc >= 0 && rc < name_len);
449  return M0_RC(0);
450 }
451 #endif
452 
462 static int obj_namei_op_init(struct m0_entity *entity,
463  struct m0_op *op)
464 {
465  int rc;
466  char *obj_name;
467  uint64_t obj_key;
468  uint64_t obj_container;
469  uint64_t lid;
470  struct m0_op_obj *oo;
471  struct m0_op_common *oc;
472  struct m0_layout_instance *linst;
473  struct m0_client *cinst;
474 
475  M0_ENTRY();
476 
477  M0_PRE(entity != NULL);
478  M0_PRE(op != NULL);
479 
480  if (M0_FI_ENABLED("fake_msg_size")) {
481  rc = M0_ERR(-EMSGSIZE);
482  goto error;
483  }
484 
485  if (op->op_size < sizeof *oo) {
486  rc = M0_ERR(-EMSGSIZE);
487  goto error;
488  }
489 
490  oc = bob_of(op, struct m0_op_common, oc_op, &oc_bobtype);
492  oo = bob_of(oc, struct m0_op_obj, oo_oc, &oo_bobtype);
494 
495  cinst = m0__oo_instance(oo);
496  M0_ASSERT(cinst != NULL);
497 
498  /* Set the op_common's callbacks. */
503 
504  /*
505  * Set the object's fid.
506  *
507  * Something about the fid at current motr implementation (fid_convert.h)
508  * (1) fid is 128 bits long, global fid and cob fid both use the highest
509  * 8 bits to represent object type and the lowest 96 bits to store object
510  * id. The interpretion of these 96 bits depends on the users. For
511  * example, as the name of fid::f_container suggests, the 32 bits (or
512  * any number of bits) in f_container can be viewed as 'application
513  * container' id, so supporting multiple application containers is
514  * possible in current Motr implementation.
515  *
516  * (2) The difference of global fid and cob fid is in the 24 bits in
517  * fid::f_container. cob fid uses these 24 bits to store device id in a
518  * layout (md is 0, and devices in ioservices ranges from 1 to P).
519  *
520  * (3) Does Client need to check if an object's container id matches
521  * the container id inside its fid?
522  */
523  obj_container = entity->en_id.u_hi;
524  obj_key = entity->en_id.u_lo;
525  m0_fid_gob_make(&oo->oo_fid, obj_container, obj_key);
526 
527  /* Get a layout instance for the object. */
531  &oo->oo_fid, &linst);
532  if (rc != 0) {
533  M0_ERR(rc);
534  goto error;
535  }
536  oo->oo_layout_instance = linst;
537 
538 #ifdef CLIENT_FOR_M0T1FS
539  /* Set the object's parent's fid. */
540  if (!m0_fid_is_set(&cinst->m0c_root_fid) ||
542  rc = M0_ERR(-EINVAL);
543  goto error;
544  }
545  oo->oo_pfid = cinst->m0c_root_fid;
546 
547  /* Generate a valid oo_name. */
548  obj_name = m0_alloc(M0_OBJ_NAME_MAX_LEN);
549  rc = obj_fid_make_name(obj_name, M0_OBJ_NAME_MAX_LEN, &oo->oo_fid);
550  if (rc != 0) {
551  M0_ERR(rc);
552  goto error;
553  }
554  m0_buf_init(&oo->oo_name, obj_name, strlen(obj_name));
555 #endif
556  M0_ASSERT(rc == 0);
557  return M0_RC(rc);
558 
559 error:
560  M0_ASSERT(rc != 0);
561  return M0_ERR(rc);
562 }
563 
568 static void obj_optimal_lid_set(struct m0_obj *obj,
569  struct m0_layout_domain *ldom)
570 {
571  uint64_t *lid;
572 
573  lid = &obj->ob_attr.oa_layout_id;
574 
575  /* Find optimal layout id when pver id is set and layout id is not */
576  if (*lid == 0 && m0_fid_is_set(&obj->ob_attr.oa_pver)) {
577  *lid = m0_layout_find_by_buffsize(ldom, &obj->ob_attr.oa_pver,
578  obj->ob_attr.oa_buf_size);
579  }
580  /* Set default layout id when both layout id and pver id is unset */
581  else if (*lid == 0 && !m0_fid_is_set(&obj->ob_attr.oa_pver)) {
582  *lid = M0_DEFAULT_LAYOUT_ID;
583  }
584 }
585 
592 static int obj_op_obj_init(struct m0_op_obj *oo)
593 {
594  int rc;
595  struct m0_locality *locality;
596  struct m0_pool_version *pv;
597  struct m0_obj *obj;
598  struct m0_client *cinst;
599  struct m0_layout_domain *ldom;
600 
601  M0_ENTRY();
602  M0_PRE(oo != NULL);
603  M0_PRE(M0_IN(OP_OBJ2CODE(oo), (M0_EO_CREATE,
604  M0_EO_DELETE,
605  M0_EO_OPEN)));
606 
610  if (OP_OBJ2CODE(oo) == M0_EO_CREATE) {
612  if (rc != 0)
613  return M0_ERR(rc);
614  oo->oo_pver = pv->pv_id;
615 
616  ldom = &cinst->m0c_reqh.rh_ldom;
617  obj_optimal_lid_set(obj, ldom);
618  } else if (OP_OBJ2CODE(oo) == M0_EO_OPEN) {
619  /*
620  * XXX:Not required to assign pool version for operation other
621  * than OBJECT CREATE.
622  * OBJECT OPEN operation will fetch pool version from meta-data
623  * and cache it to m0_obj::ob_layout::oa_pver
624  * MOTR-2871 will fix and verify this issue separately.
625  */
627  M0_ASSERT(pv != NULL);
628  oo->oo_pver = pv->pv_id;
629  } else {
630  oo->oo_pver = m0__obj_pver(obj);
631  }
634  M0_ASSERT(locality != NULL);
635  oo->oo_sm_grp = locality->lo_grp;
636  M0_SET0(&oo->oo_ar);
637 
638  oo->oo_layout_instance = NULL;
639  M0_SET0(&oo->oo_fid);
640 
641 #ifdef CLIENT_FOR_M0T1FS
642  M0_SET0(&oo->oo_pfid);
643  M0_SET0(&oo->oo_name);
644 #endif
645 
646  m0_op_obj_bob_init(oo);
647  m0_ast_rc_bob_init(&oo->oo_ar);
648 
650  return M0_RC(0);
651 }
652 
665 static int obj_op_prepare(struct m0_entity *entity,
666  struct m0_op **op,
668 {
669  int rc;
670  bool alloced = false;
671  struct m0_op_common *oc;
672  struct m0_op_obj *oo;
673 
674  M0_ENTRY();
675 
676  M0_PRE(entity != NULL);
678  M0_PRE(M0_IN(entity->en_sm.sm_state, (M0_ES_INIT,
679  M0_ES_OPEN)));
680  M0_PRE(op != NULL);
681  /* We may want to gain this lock, check we don't already hold it. */
682  M0_PRE(*op == NULL ||
683  !m0_sm_group_is_locked(&(*op)->op_sm_group));
684 
685  /* Allocate the op if necessary. */
686  if (*op == NULL) {
687  rc = m0_op_alloc(op, sizeof *oo);
688  if (rc != 0)
689  return M0_ERR(rc);
690  alloced = true;
691  } else {
692  size_t cached_size = (*op)->op_size;
693 
694  if ((*op)->op_size < sizeof *oo)
695  return M0_ERR(-EMSGSIZE);
696 
697  /* 0 the pre-allocated operation. */
698  memset(*op, 0, cached_size);
699  (*op)->op_size = cached_size;
700  }
701  m0_mutex_init(&(*op)->op_pending_tx_lock);
702  spti_tlist_init(&(*op)->op_pending_tx);
703 
704  /* Initialise the operation's generic part. */
705  (*op)->op_code = opcode;
706  rc = m0_op_init(*op, &m0_op_conf, entity);
707  if (rc != 0)
708  goto op_free;
709 
710  /* No bob_init()'s have been called yet: we use M0_AMB(). */
711  oc = M0_AMB(oc, *op, oc_op);
712  m0_op_common_bob_init(oc);
713 
714  /* Init the m0_op_obj part. */
715  oo = M0_AMB(oo, oc, oo_oc);
716  rc = obj_op_obj_init(oo);
717  if (rc != 0)
718  goto op_fini;
719 
720  return M0_RC(0);
721 
722 op_fini:
723  m0_op_fini(*op);
724 op_free:
725  if (alloced) {
726  m0_op_free(*op);
727  *op = NULL;
728  }
729 
730  return M0_RC(rc);
731 }
732 
743 static int entity_namei_op(struct m0_entity *entity,
744  struct m0_op **op,
746 {
747  int rc;
748  bool pre_allocated = false;
749 
750  M0_ENTRY();
751 
752  M0_PRE(entity != NULL);
754  M0_PRE(M0_IN(entity->en_sm.sm_state, (M0_ES_INIT,
755  M0_ES_OPEN)));
756  M0_PRE(op != NULL);
757  M0_PRE(M0_IN(opcode, (M0_EO_CREATE,
758  M0_EO_DELETE,
759  M0_EO_OPEN)));
760 
761  switch (entity->en_type) {
762  case M0_ET_OBJ:
763  pre_allocated = (*op != NULL);
764  /* Allocate an op on an object and initialise common stuff. */
765  rc = obj_op_prepare(entity, op, opcode);
766  if (rc != 0)
767  goto error;
768 
769  /* Initialise the stuff specific to a obj namespace operation. */
770  rc = obj_namei_op_init(entity, *op);
771  if (rc != 0)
772  goto op_fini;
773  break;
774  case M0_ET_IDX:
775  rc = m0_idx_op_namei(entity, op, opcode);
776  if (rc != 0)
777  goto error;
778  break;
779  default:
780  M0_IMPOSSIBLE("Entity type not yet implemented.");
781  }
782 
783  M0_POST(rc == 0);
784  M0_POST(*op != NULL);
785  m0_sm_group_lock(&(*op)->op_sm_group);
786  M0_POST((*op)->op_sm.sm_rc == 0);
787  m0_sm_group_unlock(&(*op)->op_sm_group);
788 
789  return M0_RC(0);
790 op_fini:
791  m0_op_fini(*op);
792  if (!pre_allocated) {
793  m0_op_free(*op);
794  *op = NULL;
795  }
796 error:
797  M0_ASSERT(rc != 0);
798  return M0_ERR(rc);
799 }
800 
802  struct m0_entity *entity,
803  struct m0_op **op)
804 {
805  struct m0_obj *obj;
806 
807  M0_ENTRY();
808  if (entity->en_flags & M0_ENF_META)
809  M0_LOG(M0_DEBUG, "M0_ENF_META FLAG is set from application");
810 
811  M0_PRE(entity != NULL);
812  M0_PRE(op != NULL);
813 
814  /* Currently, pool selection is only for objects. */
815  if (entity->en_type == M0_ET_OBJ && pool != NULL) {
816  obj = M0_AMB(obj, entity, ob_entity);
817  obj->ob_attr.oa_pool = *pool;
818  }
819 
820  return M0_RC(entity_namei_op(entity, op, M0_EO_CREATE));
821 }
822 M0_EXPORTED(m0_entity_create);
823 
824 int m0_entity_delete(struct m0_entity *entity,
825  struct m0_op **op)
826 {
827  M0_ENTRY();
828 
829  M0_PRE(entity != NULL);
830  M0_PRE(op != NULL);
831 
832  return M0_RC(entity_namei_op(entity, op, M0_EO_DELETE));
833 }
834 M0_EXPORTED(m0_entity_delete);
835 
837 {
838  uint64_t i;
839 
840  for (i = 0; i < m0_lid_to_unit_map_nr; i++)
842  break;
843 
844  if (i == m0_lid_to_unit_map_nr)
845  return 0;
846  else
847  return i;
848 }
849 M0_EXPORTED(m0_obj_unit_size_to_layout_id);
850 
852 {
854 
856 }
857 M0_EXPORTED(m0_obj_layout_id_to_unit_size);
858 
859 uint64_t m0_client_layout_id(const struct m0_client *instance)
860 {
861  uint64_t lid = M0_DEFAULT_LAYOUT_ID;
862 
863  M0_ENTRY();
864  M0_PRE(instance != NULL);
865 
866  /*
867  * TODO:This layout selection is a temporary solution for s3 team
868  * requirement. In future this has to be replaced by more sophisticated
869  * solution.
870  */
871  if (instance->m0c_config->mc_layout_id != 0)
872  lid = instance->m0c_config->mc_layout_id;
873 
874  M0_LEAVE("lid=%"PRIu64, lid);
875  return lid;
876 }
877 M0_EXPORTED(m0_client_layout_id);
878 
880 {
881  return M0_OBJ_LAYOUT_TYPE(obj->ob_attr.oa_layout_id);
882 }
883 M0_EXPORTED(m0_obj_layout_type);
884 
885 int m0_entity_open(struct m0_entity *entity,
886  struct m0_op **op)
887 {
888  M0_ENTRY();
889 
890  M0_PRE(entity != NULL);
891  M0_PRE(op != NULL);
892 
893  if (entity->en_type == M0_ET_IDX) {
894  /* Since pool version for index entity is got by index query,
895  * move the entity state into OPEN and return success. */
896  m0_sm_group_lock(&entity->en_sm_group);
897  m0_sm_move(&entity->en_sm, 0, M0_ES_OPENING);
898  m0_sm_move(&entity->en_sm, 0, M0_ES_OPEN);
900  return M0_RC(0);
901  } else
902  return M0_RC(entity_namei_op(entity, op,
903  M0_EO_OPEN));
904 }
905 M0_EXPORTED(m0_entity_open);
906 
907 #undef M0_TRACE_SUBSYSTEM
908 
909 /*
910  * Local variables:
911  * c-indentation-style: "K&R"
912  * c-basic-offset: 8
913  * tab-width: 8
914  * fill-column: 80
915  * scroll-step: 1
916  * End:
917  */
918 /*
919  * vim: tabstop=8 shiftwidth=8 noexpandtab textwidth=80 nowrap
920  */
M0_INTERNAL int m0_uint128_cmp(const struct m0_uint128 *u0, const struct m0_uint128 *u1)
Definition: misc.c:45
M0_INTERNAL struct m0_layout * m0_layout_find(struct m0_layout_domain *dom, uint64_t lid)
Definition: layout.c:861
struct m0_fid m0c_root_fid
static void obj_optimal_lid_set(struct m0_obj *obj, struct m0_layout_domain *ldom)
Definition: obj.c:568
const struct m0_bob_type oo_bobtype
Definition: client.c:45
#define M0_PRE(cond)
enum m0_client_layout_type m0_obj_layout_type(struct m0_obj *obj)
Definition: obj.c:879
M0_INTERNAL void m0_fid_gob_make(struct m0_fid *gob_fid, uint32_t container, uint64_t key)
Definition: fid_convert.c:46
Definition: client.h:788
M0_INTERNAL struct m0_client * m0__oo_instance(struct m0_op_obj *oo)
Definition: obj.c:43
#define NULL
Definition: misc.h:38
m0_entity_opcode
Definition: client.h:523
M0_INTERNAL bool entity_invariant_full(struct m0_entity *ent)
Definition: client.c:300
M0_INTERNAL int m0__obj_pool_version_get(struct m0_obj *obj, struct m0_pool_version **pv)
Definition: obj.c:346
static size_t locality(const struct m0_fom *fom)
Definition: rm_foms.c:269
struct m0_buf oo_name
void m0_op_fini(struct m0_op *op)
Definition: client.c:847
M0_INTERNAL struct m0_pool_version * m0_pool_version_find(struct m0_pools_common *pc, const struct m0_fid *id)
Definition: pool.c:586
M0_INTERNAL enum m0_client_layout_type m0__obj_layout_type(struct m0_obj *obj)
Definition: obj.c:139
struct m0_pool_version * pv
Definition: dir.c:629
#define M0_LOG(level,...)
Definition: trace.h:167
M0_LEAVE()
static int obj_op_prepare(struct m0_entity *entity, struct m0_op **op, enum m0_entity_opcode opcode)
Definition: obj.c:665
struct m0_sm_group * oo_sm_grp
static void obj_namei_cb_cancel(struct m0_op_common *oc)
Definition: obj.c:187
uint64_t m0_obj_unit_size_to_layout_id(int unit_size)
Definition: obj.c:836
#define M0_OBJ_LAYOUT_TYPE(lid)
Definition: layout.h:108
M0_INTERNAL int obj_fid_make_name(char *name, size_t name_len, const struct m0_fid *fid)
M0_INTERNAL void m0_buf_init(struct m0_buf *buf, void *data, uint32_t nob)
Definition: buf.c:37
struct m0_op oc_op
M0_INTERNAL int m0_op_init(struct m0_op *op, const struct m0_sm_conf *conf, struct m0_entity *entity)
Definition: client.c:806
M0_INTERNAL bool m0__obj_pool_version_is_valid(const struct m0_obj *obj)
Definition: obj.c:169
uint64_t m0_client_layout_id(const struct m0_client *instance)
Definition: obj.c:859
M0_INTERNAL void m0__obj_attr_set(struct m0_obj *obj, struct m0_fid pver, uint64_t layout_id)
Definition: obj.c:151
static int error
Definition: mdstore.c:64
struct m0_ast_rc oo_ar
#define M0_SET0(obj)
Definition: misc.h:64
M0_INTERNAL uint64_t m0__obj_layout_id_get(struct m0_op_obj *oo)
Definition: obj.c:384
M0_INTERNAL int m0__obj_namei_send(struct m0_op_obj *oo)
Definition: cob.c:1804
M0_INTERNAL bool m0_fid_is_set(const struct m0_fid *fid)
Definition: fid.c:106
static struct foo * obj
Definition: tlist.c:302
#define PRIx64
Definition: types.h:61
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
int m0_lid_to_unit_map[]
Definition: layout_pver.c:99
const struct m0_uint128 M0_ID_APP
Definition: client.c:92
struct m0_fid fid
Definition: di.c:46
return M0_RC(rc)
op
Definition: libdemo.c:64
M0_INTERNAL int m0_idx_op_namei(struct m0_entity *entity, struct m0_op **op, enum m0_entity_opcode opcode)
Definition: idx.c:603
M0_INTERNAL bool m0_op_obj_invariant(struct m0_op_obj *oo)
Definition: obj.c:79
static uint32_t unit_size
Definition: layout.c:53
#define M0_ENTRY(...)
Definition: trace.h:170
struct m0_fid oo_pver
M0_INTERNAL struct m0_pool_version * m0_pool_version_md_get(const struct m0_pools_common *pc)
Definition: pool.c:841
M0_INTERNAL int m0__obj_namei_cancel(struct m0_op *op)
Definition: cob.c:1915
M0_INTERNAL void m0_sm_group_unlock(struct m0_sm_group *grp)
Definition: sm.c:96
int opcode
Definition: crate.c:301
int m0_obj_layout_id_to_unit_size(uint64_t layout_id)
Definition: obj.c:851
M0_INTERNAL struct m0_obj * m0__obj_entity(struct m0_entity *entity)
Definition: obj.c:51
int i
Definition: dir.c:1033
size_t op_size
Definition: client.h:664
#define PRIu64
Definition: types.h:58
struct m0_pools_common m0c_pools_common
Definition: client.h:641
#define M0_OBJ_LAYOUT_ID(lid)
Definition: io_foms.c:566
const struct m0_bob_type oc_bobtype
Definition: client.c:44
void(* oc_cb_free)(struct m0_op_common *oc)
return M0_ERR(-EOPNOTSUPP)
const char * name
Definition: trace.c:110
M0_INTERNAL uint64_t m0_pool_version2layout_id(const struct m0_fid *pv_fid, uint64_t lid)
Definition: pool.c:1900
M0_INTERNAL int m0_pool_version_get(struct m0_pools_common *pc, const struct m0_fid *pool, struct m0_pool_version **pv)
Definition: pool.c:662
#define M0_AMB(obj, ptr, field)
Definition: misc.h:320
struct m0_fid pv_id
Definition: pool.h:113
#define M0_ASSERT(cond)
static void obj_namei_cb_launch(struct m0_op_common *oc)
Definition: obj.c:219
struct m0_fid pver
Definition: idx_dix.c:74
static void obj_namei_cb_free(struct m0_op_common *oc)
Definition: obj.c:285
struct m0_reqh m0c_reqh
#define bob_of(ptr, type, field, bt)
Definition: bob.h:140
static void obj_namei_cb_fini(struct m0_op_common *oc)
Definition: obj.c:311
int layout_id
Definition: dir.c:331
struct m0_fid oo_pfid
uint64_t u_hi
Definition: types.h:36
void * m0_alloc(size_t size)
Definition: memory.c:126
static void * obj_key(const struct m0_ht_descr *hd, void *obj)
Definition: hash.c:70
M0_INTERNAL void m0_mutex_init(struct m0_mutex *mutex)
Definition: mutex.c:35
#define M0_POST(cond)
struct m0_fid oo_fid
static bool obj_layout_id_invariant(uint64_t layout_id)
Definition: obj.c:114
Definition: xcode.c:55
M0_INTERNAL uint64_t m0__obj_lid(struct m0_obj *obj)
Definition: obj.c:126
struct m0_layout_domain rh_ldom
Definition: reqh.h:153
void(* oc_cb_fini)(struct m0_op_common *oc)
M0_INTERNAL void m0_buf_free(struct m0_buf *buf)
Definition: buf.c:55
struct m0_uint128 en_id
Definition: client.h:708
struct m0_op_common oo_oc
bool m0_conf_fid_is_valid(const struct m0_fid *fid)
Definition: obj.c:378
#define FID_P(f)
Definition: fid.h:77
static struct m0_pool pool
Definition: iter_ut.c:58
#define MOTR_MDCOB_LOOKUP_SKIP
int m0_entity_create(struct m0_fid *pool, struct m0_entity *entity, struct m0_op **op)
Definition: obj.c:801
static struct m0_client cinst
Definition: sync.c:84
M0_INTERNAL int64_t m0_layout_find_by_buffsize(struct m0_layout_domain *dom, struct m0_fid *pver, size_t buffsize)
Definition: layout.c:810
struct m0_realm * en_realm
Definition: client.h:710
struct m0_sm_group en_sm_group
Definition: client.h:734
static bool m0_op_common_invariant(struct m0_op_common *oc)
Definition: obj.c:67
M0_INTERNAL bool m0_op_obj_ast_rc_invariant(struct m0_ast_rc *ar)
Definition: obj.c:73
const int m0_lid_to_unit_map_nr
Definition: layout_pver.c:116
static int obj_namei_op_init(struct m0_entity *entity, struct m0_op *op)
Definition: obj.c:462
#define M0_FI_ENABLED(tag)
Definition: finject.h:231
Definition: fid.h:38
struct m0_entity * op_entity
Definition: client.h:660
M0_INTERNAL struct m0_locality * m0__locality_pick(struct m0_client *cinst)
Definition: client.c:290
M0_INTERNAL struct m0_fid m0__obj_pver(struct m0_obj *obj)
Definition: obj.c:163
void(* oc_cb_cancel)(struct m0_op_common *oc)
struct m0_entity ob_entity
Definition: client.h:789
M0_INTERNAL void m0_sm_move(struct m0_sm *mach, int32_t rc, int state)
Definition: sm.c:485
static int entity_namei_op(struct m0_entity *entity, struct m0_op **op, enum m0_entity_opcode opcode)
Definition: obj.c:743
m0_client_layout_type
Definition: client.h:776
static struct m0 instance
Definition: main.c:78
M0_INTERNAL void m0_sm_group_lock(struct m0_sm_group *grp)
Definition: sm.c:83
M0_INTERNAL struct m0_client * m0__obj_instance(const struct m0_obj *obj)
Definition: client.c:261
M0_INTERNAL int m0_op_alloc(struct m0_op **op, size_t op_size)
Definition: client.c:779
int m0_entity_delete(struct m0_entity *entity, struct m0_op **op)
Definition: obj.c:824
static int obj_op_obj_init(struct m0_op_obj *oo)
Definition: obj.c:592
M0_INTERNAL void m0_layout_instance_fini(struct m0_layout_instance *li)
Definition: layout.c:1123
struct m0_client * re_instance
Definition: client.h:873
M0_INTERNAL int m0__obj_layout_instance_build(struct m0_client *cinst, const uint64_t layout_id, const struct m0_fid *fid, struct m0_layout_instance **linst)
Definition: obj.c:403
uint32_t en_flags
Definition: client.h:738
struct m0_pool_version * pc_cur_pver
Definition: pool.h:220
#define OP_OBJ2CODE(op_obj)
M0_INTERNAL void m0_layout_put(struct m0_layout *l)
Definition: layout.c:893
void m0_op_free(struct m0_op *op)
Definition: client.c:885
struct m0_sm en_sm
Definition: client.h:732
int type
Definition: dir.c:1031
struct m0_layout_instance * oo_layout_instance
int m0_entity_open(struct m0_entity *entity, struct m0_op **op)
Definition: obj.c:885
M0_INTERNAL bool m0_fid_is_valid(const struct m0_fid *fid)
Definition: fid.c:96
void(* oc_cb_launch)(struct m0_op_common *oc)
uint64_t u_lo
Definition: types.h:37
void m0_free(void *data)
Definition: memory.c:146
uint32_t sm_state
Definition: sm.h:307
int32_t rc
Definition: trigger_fop.h:47
static bool obj_op_obj_invariant(struct m0_op_obj *oo)
Definition: obj.c:95
enum m0_entity_type en_type
Definition: client.h:706
M0_INTERNAL bool m0_sm_group_is_locked(const struct m0_sm_group *grp)
Definition: sm.c:107
struct m0_sm_conf m0_op_conf
Definition: client.c:145
#define M0_IMPOSSIBLE(fmt,...)
M0_INTERNAL struct m0_client * m0__entity_instance(const struct m0_entity *entity)
Definition: client.c:226