Motr  M0
client.h
Go to the documentation of this file.
1 /* -*- C -*- */
2 /*
3  * Copyright (c) 2016-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 #pragma once
24 
25 #ifndef __MOTR_CLIENT_H__
26 #define __MOTR_CLIENT_H__
27 
28 #include "lib/vec.h"
29 #include "lib/types.h"
30 #include "sm/sm.h" /* struct m0_sm */
31 #include "rpc/rpc_machine.h" /* M0_RPC_DEF_MAX_RPC_MSG_SIZE */
32 #include "fid/fid.h"
33 #include "lib/cookie.h"
34 #include "xcode/xcode_attr.h"
524  M0_EO_INVALID, /* 0 */
525  M0_EO_CREATE, /* 1 */
526  M0_EO_DELETE, /* 2 */
527  M0_EO_SYNC, /* 3 */
528  M0_EO_OPEN, /* 4 */
529  M0_EO_GETATTR, /* 5 */
530  M0_EO_SETATTR, /* 6 */
533  M0_EO_NR /* 9 */
534 } M0_XCA_ENUM;
535 
539  M0_OC_READ = M0_EO_NR + 1, /* 10 */
541  M0_OC_WRITE, /* 11 */
543  M0_OC_ALLOC, /* 12 */
545  M0_OC_FREE, /* 13 */
546  M0_OC_NR /* 14 */
547 } M0_XCA_ENUM;
548 
549 /* Index operation codes. */
552  M0_IC_GET = M0_OC_NR + 1, /* 15 */
554  M0_IC_PUT, /* 16 */
556  M0_IC_DEL, /* 17 */
558  M0_IC_NEXT, /* 18 */
560  M0_IC_LOOKUP, /* 19 */
562  M0_IC_LIST, /* 20 */
563  M0_IC_NR /* 21 */
564 } M0_XCA_ENUM;
565 
574  M0_OOF_NOHOLE = 1 << 0,
579  M0_OOF_SYNC = 1 << 1
580 } M0_XCA_ENUM;
581 
589 } M0_XCA_ENUM;
590 
626  M0_ENF_META = 1 << 0,
631  M0_ENF_NO_RMW = 1 << 1,
635  M0_ENF_DI = 1 << 2
636  } M0_XCA_ENUM;
637 
641 struct m0_op {
642  uint64_t op_magic;
643 
650  unsigned int op_code;
652  int32_t op_rc;
656  struct m0_sm op_sm;
658  const struct m0_op_ops *op_cbs;
662  m0_time_t op_linger; /* a town in Luxembourg. */
664  size_t op_size;
666  uint64_t op_gen;
673  struct m0_op *op_parent;
678  /* Operation's private data, can be used as arguments for callbacks.*/
679  void *op_datum;
680  uint64_t op_count;
684  void *op_priv;
686 };
687 
699 };
700 
704 struct m0_entity {
732  struct m0_sm en_sm;
738  uint32_t en_flags;
739 };
740 
747 struct m0_obj_attr {
750 
752  uint64_t oa_layout_id;
753 
760  struct m0_fid oa_pool;
761 
763  struct m0_fid oa_pver;
764 
769  size_t oa_buf_size;
770 };
771 
781 };
782 
787 struct m0_client_layout;
788 struct m0_obj {
794 };
795 
799  /* Back pointer to the object it belongs to. */
800  struct m0_obj *ml_obj;
802 };
803 
811 struct m0_idx_attr {
813  uint32_t idx_layout_type;
815  struct m0_fid idx_pver;
816 };
817 
835 struct m0_idx {
838 };
839 
840 #define M0_COMPOSITE_EXTENT_INF (0xffffffffffffffff)
844 };
845 
848 };
849 
855 };
856 
863 struct m0_client;
864 
870 struct m0_realm {
874 };
875 
880 struct m0_container {
882 };
883 
893 struct m0_epoch {
895 };
896 
901 struct m0__dtx {
903 };
904 
908 struct m0_op_ops {
909  void (*oop_executed)(struct m0_op *op);
910  void (*oop_failed)(struct m0_op *op);
911  void (*oop_stable) (struct m0_op *op);
912 };
913 
918 struct m0_config {
926 
931 
933  const char *mc_local_addr;
935  const char *mc_ha_addr;
937  const char *mc_process_fid;
938  const char *mc_profile;
939 
950 
951  /* TODO: This parameter is added for a temporary solution of
952  * layout selection for s3 team. This has to be removed when
953  * sophisticated solution is implemented.*/
954  uint32_t mc_layout_id;
955 
958 
963 };
964 
966 extern const struct m0_uint128 M0_UBER_REALM;
967 
974 extern const struct m0_uint128 M0_ID_APP;
975 
1111 struct m0_rm_lock_req;
1112 
1123 int m0_obj_lock_init(struct m0_obj *obj);
1124 
1134 void m0_obj_lock_fini(struct m0_obj *obj);
1135 
1150 int m0_obj_write_lock_get(struct m0_obj *obj,
1151  struct m0_rm_lock_req *req,
1152  struct m0_clink *clink);
1153 
1168  struct m0_rm_lock_req *req);
1169 
1185 int m0_obj_read_lock_get(struct m0_obj *obj,
1186  struct m0_rm_lock_req *req,
1187  struct m0_clink *clink);
1188 
1204  struct m0_rm_lock_req *req);
1205 
1211 void m0_obj_lock_put(struct m0_rm_lock_req *req);
1212 
1224 void m0_op_setup(struct m0_op *op,
1225  const struct m0_op_ops *cbs,
1226  m0_time_t linger);
1243 void m0_op_launch(struct m0_op **op, uint32_t nr);
1244 
1278 int32_t m0_op_wait(struct m0_op *op, uint64_t bits, m0_time_t to);
1279 
1295 void m0_op_cancel(struct m0_op **op, uint32_t nr);
1296 
1311 void m0_op_kick(struct m0_op *op);
1312 
1323 int32_t m0_rc(const struct m0_op *op);
1324 
1335 void m0_op_fini(struct m0_op *op);
1336 
1345 void m0_op_free(struct m0_op *op);
1346 
1347 void m0_container_init(struct m0_container *con,
1348  struct m0_realm *parent,
1349  const struct m0_uint128 *id,
1350  struct m0_client *instance);
1351 void m0_epoch_init (struct m0_epoch *epoch,
1352  struct m0_realm *parent,
1353  const struct m0_uint128 *id);
1354 void m0__dtx_init (struct m0__dtx *dtx,
1355  struct m0_realm *parent,
1356  const struct m0_uint128 *id);
1357 
1379 void m0_obj_init(struct m0_obj *obj,
1380  struct m0_realm *parent,
1381  const struct m0_uint128 *id,
1382  uint64_t layout_id);
1391 void m0_obj_fini(struct m0_obj *obj);
1392 
1405 void m0_obj_idx_init(struct m0_idx *idx,
1406  const struct m0_obj *obj);
1407 
1455 int m0_obj_op(struct m0_obj *obj,
1456  enum m0_obj_opcode opcode,
1457  struct m0_indexvec *ext,
1458  struct m0_bufvec *data,
1459  struct m0_bufvec *attr,
1460  uint64_t mask,
1461  uint32_t flags,
1462  struct m0_op **op);
1463 
1481 void m0_idx_init(struct m0_idx *idx,
1482  struct m0_realm *parent,
1483  const struct m0_uint128 *id);
1484 
1485 void m0_idx_fini(struct m0_idx *idx);
1486 
1566 int m0_idx_op(struct m0_idx *idx,
1567  enum m0_idx_opcode opcode,
1568  struct m0_bufvec *keys,
1569  struct m0_bufvec *vals,
1570  int32_t *rcs,
1571  uint32_t flags,
1572  struct m0_op **op);
1573 
1574 void m0_realm_create(struct m0_realm *realm,
1575  uint64_t wcount, uint64_t rcount,
1576  struct m0_op **op);
1577 
1578 void m0_realm_open(struct m0_realm *realm,
1579  uint64_t wcount, uint64_t rcount,
1580  struct m0_op **op);
1581 
1582 void m0_realm_close(struct m0_realm *realm,
1583  uint64_t wcount, uint64_t rcount,
1584  struct m0_op **op);
1585 
1600 int m0_entity_create(struct m0_fid *pool,
1601  struct m0_entity *entity,
1602  struct m0_op **op);
1603 int m0_entity_delete(struct m0_entity *entity,
1604  struct m0_op **op);
1618 int m0_entity_open(struct m0_entity *entity,
1619  struct m0_op **op);
1628 void m0_entity_fini(struct m0_entity *entity);
1629 
1635 size_t m0_op_maxsize(void);
1636 
1648 int m0_client_init(struct m0_client **m0c,
1649  struct m0_config *conf,
1650  bool init_m0);
1651 
1657 void m0_client_fini(struct m0_client *m0c, bool fini_m0);
1658 
1667 void m0_process_fid(const struct m0_client *m0c,
1668  struct m0_fid *proc_fid);
1669 
1677 int m0_sync_op_init(struct m0_op **sop);
1678 
1686 int m0_sync_entity_add(struct m0_op *sop,
1687  struct m0_entity *ent);
1695 int m0_sync_op_add(struct m0_op *sop,
1696  struct m0_op *op);
1697 
1705 int m0_entity_sync(struct m0_entity *ent);
1706 
1716 int m0_sync(struct m0_client *m0c, bool wait);
1717 
1727 
1737 
1738 uint64_t m0_client_layout_id(const struct m0_client *instance);
1739 
1747 
1760 int m0_composite_layer_add(struct m0_client_layout *layout,
1761  struct m0_obj *sub_obj, int priority);
1768 void m0_composite_layer_del(struct m0_client_layout *layout,
1769  struct m0_uint128 subobj_id);
1770 
1779 int m0_composite_layer_idx(struct m0_uint128 layer_id,
1780  bool write, struct m0_idx *idx);
1788  void **out_kbuf, m0_bcount_t *out_klen);
1791  void *kbuf);
1794  void **out_vbuf, m0_bcount_t *out_vlen);
1797  void *vbuf);
1798 
1809 int m0_client_layout_op(struct m0_obj *obj,
1810  enum m0_entity_opcode opcode,
1811  struct m0_client_layout *layout,
1812  struct m0_op **op);
1813 
1820 int m0_client_layout_capture(struct m0_client_layout *layout,
1821  struct m0_obj *obj,
1822  struct m0_client_layout **out);
1823 
1824 /* Allocate/free in-memory layout data struct for an object. */
1825 struct m0_client_layout*
1827 void m0_client_layout_free(struct m0_client_layout *layout);
1828 
1829 //** @} end of client group */
1830 
1831 #include "motr/idx.h" /* export m0_idx operations and services to client. */
1832 #include "cas/cas.h"
1833 
1834 #endif /* __MOTR_CLIENT_H__ */
1835 
1836 /*
1837  * Local variables:
1838  * c-indentation-style: "K&R"
1839  * c-basic-offset: 8
1840  * tab-width: 8
1841  * fill-column: 80
1842  * scroll-step: 1
1843  * End:
1844  */
1845 /*
1846  * vim: tabstop=8 shiftwidth=8 noexpandtab textwidth=80 nowrap
1847  */
struct m0_fid idx_pver
Definition: client.h:815
static size_t nr
Definition: dump.c:1505
static struct m0_semaphore wait
Definition: item.c:151
enum m0_client_layout_type m0_obj_layout_type(struct m0_obj *obj)
Definition: obj.c:879
Definition: client.h:835
uint32_t mc_layout_id
Definition: client.h:954
void m0_entity_fini(struct m0_entity *entity)
Definition: client.c:438
struct m0_mutex en_pending_tx_lock
Definition: client.h:737
Definition: client.h:788
void m0_obj_lock_put(struct m0_rm_lock_req *req)
Definition: obj_lock.c:267
int const char const void size_t int flags
Definition: dir.c:328
const struct m0_op_ops * op_cbs
Definition: client.h:658
m0_idx_opcode
Definition: client.h:550
m0_entity_opcode
Definition: client.h:523
uint32_t idx_layout_type
Definition: client.h:813
const char * mc_process_fid
Definition: client.h:937
Definition: idx_mock.c:52
uint64_t op_gen
Definition: client.h:666
void m0_op_fini(struct m0_op *op)
Definition: client.c:847
static struct io_request req
Definition: file.c:100
bool mc_is_addb_init
Definition: client.h:930
int m0_obj_read_lock_get(struct m0_obj *obj, struct m0_rm_lock_req *req, struct m0_clink *clink)
Definition: obj_lock.c:250
uint64_t m0_time_t
Definition: time.h:37
void(* oop_executed)(struct m0_op *op)
Definition: client.h:909
struct m0_mutex op_pending_tx_lock
Definition: client.h:677
int m0_entity_sync(struct m0_entity *ent)
Definition: sync.c:1061
uint64_t op_magic
Definition: client.h:642
uint64_t m0_obj_unit_size_to_layout_id(int unit_size)
Definition: obj.c:836
void m0_process_fid(const struct m0_client *m0c, struct m0_fid *proc_fid)
Definition: client_init.c:1766
struct m0_op * op_parent
Definition: client.h:673
int m0_obj_write_lock_get_sync(struct m0_obj *obj, struct m0_rm_lock_req *req)
Definition: obj_lock.c:242
int32_t m0_rc(const struct m0_op *op)
Definition: client.c:943
void m0_client_fini(struct m0_client *m0c, bool fini_m0)
Definition: client_init.c:1711
int m0_obj_lock_init(struct m0_obj *obj)
Definition: obj_lock.c:82
m0_realm_type
Definition: client.h:850
int m0_obj_write_lock_get(struct m0_obj *obj, struct m0_rm_lock_req *req, struct m0_clink *clink)
Definition: obj_lock.c:233
struct m0_bufvec data
Definition: di.c:40
static struct m0_clovis * m0c
Definition: main.c:25
uint64_t m0_client_layout_id(const struct m0_client *instance)
Definition: obj.c:859
Definition: conf.py:1
enum m0_entity_opcode M0_XCA_ENUM
uint64_t m0_bindex_t
Definition: types.h:80
int m0_sync_op_add(struct m0_op *sop, struct m0_op *op)
Definition: sync.c:1020
uint64_t m0_bcount_t
Definition: types.h:77
void m0_idx_fini(struct m0_idx *idx)
Definition: idx.c:643
Definition: sm.h:504
struct m0_idx_attr in_attr
Definition: client.h:837
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
void m0_obj_lock_fini(struct m0_obj *obj)
Definition: obj_lock.c:144
void m0_composite_layer_idx_val_from_buf(struct m0_composite_layer_idx_val *val, void *vbuf)
void m0__dtx_init(struct m0__dtx *dtx, struct m0_realm *parent, const struct m0_uint128 *id)
static struct foo * obj
Definition: tlist.c:302
struct m0_realm ep_realm
Definition: client.h:894
uint64_t op_count
Definition: client.h:680
const struct m0_uint128 M0_ID_APP
Definition: client.c:92
int32_t m0_op_wait(struct m0_op *op, uint64_t bits, m0_time_t to)
Definition: client.c:739
struct m0_tl en_pending_tx
Definition: client.h:736
int m0_idx_op(struct m0_idx *idx, enum m0_idx_opcode opcode, struct m0_bufvec *keys, struct m0_bufvec *vals, int32_t *rcs, uint32_t flags, struct m0_op **op)
Definition: idx.c:554
op
Definition: libdemo.c:64
unsigned int op_code
Definition: client.h:650
int m0_obj_op(struct m0_obj *obj, enum m0_obj_opcode opcode, struct m0_indexvec *ext, struct m0_bufvec *data, struct m0_bufvec *attr, uint64_t mask, uint32_t flags, struct m0_op **op)
Definition: io.c:717
static uint32_t unit_size
Definition: layout.c:53
struct m0_entity in_entity
Definition: client.h:836
int opcode
Definition: crate.c:301
enum m0_client_layout_type ml_type
Definition: client.h:798
int m0_obj_layout_id_to_unit_size(uint64_t layout_id)
Definition: obj.c:851
size_t op_size
Definition: client.h:664
struct m0_realm co_realm
Definition: client.h:881
struct m0_sm_ast op_parent_ast
Definition: client.h:674
const char * mc_ha_addr
Definition: client.h:935
Definition: client.h:641
struct m0_realm dt_realm
Definition: client.h:902
int m0_obj_read_lock_get_sync(struct m0_obj *obj, struct m0_rm_lock_req *req)
Definition: obj_lock.c:259
struct m0_client_layout * m0_client_layout_alloc(enum m0_client_layout_type type)
Definition: layout.c:473
struct m0_sm op_sm
Definition: client.h:656
static void attr(struct m0_addb2__context *ctx, const uint64_t *v, char *buf)
Definition: dump.c:949
m0_entity_flags
Definition: client.h:595
void(* oop_stable)(struct m0_op *op)
Definition: client.h:911
void m0_composite_layer_idx_key_from_buf(struct m0_composite_layer_idx_key *key, void *kbuf)
struct m0_entity re_entity
Definition: client.h:871
size_t m0_op_maxsize(void)
void m0_realm_open(struct m0_realm *realm, uint64_t wcount, uint64_t rcount, struct m0_op **op)
void m0_client_layout_free(struct m0_client_layout *layout)
Definition: layout.c:504
int m0_composite_layer_idx(struct m0_uint128 layer_id, bool write, struct m0_idx *idx)
int32_t op_rc
Definition: client.h:652
void * op_priv
Definition: client.h:684
void m0_obj_fini(struct m0_obj *obj)
Definition: client.c:467
int m0_composite_layer_idx_key_to_buf(struct m0_composite_layer_idx_key *key, void **out_kbuf, m0_bcount_t *out_klen)
Definition: tlist.h:251
bool mc_is_oostore
Definition: client.h:920
m0_op_state
Definition: client.h:691
void m0_op_launch(struct m0_op **op, uint32_t nr)
Definition: client.c:725
m0_bcount_t oa_bshift
Definition: client.h:749
struct m0_client_layout * ob_layout
Definition: client.h:791
int layout_id
Definition: dir.c:331
int m0_sync_entity_add(struct m0_op *sop, struct m0_entity *ent)
Definition: sync.c:985
m0_time_t op_linger
Definition: client.h:662
void m0_composite_layer_del(struct m0_client_layout *layout, struct m0_uint128 subobj_id)
static char * proc_fid
Definition: m0hsm.c:45
enum m0_realm_type re_type
Definition: client.h:872
struct m0_entity ml_entity
Definition: client.h:797
int m0_sync(struct m0_client *m0c, bool wait)
Definition: sync.c:1093
static struct m0_clink clink[RDWR_REQUEST_MAX]
int m0_sync_op_init(struct m0_op **sop)
Definition: sync.c:972
void(* oop_failed)(struct m0_op *op)
Definition: client.h:910
struct m0_uint128 en_id
Definition: client.h:708
void m0_op_cancel(struct m0_op **op, uint32_t nr)
Definition: client.c:639
bool mc_is_read_verify
Definition: client.h:925
static struct m0_pool pool
Definition: iter_ut.c:58
void * mc_idx_service_conf
Definition: client.h:957
struct m0_uint128 cek_layer_id
Definition: client.h:842
int m0_entity_create(struct m0_fid *pool, struct m0_entity *entity, struct m0_op **op)
Definition: obj.c:801
struct m0_obj * ml_obj
Definition: client.h:800
m0_bcount_t mc_addb_size
Definition: client.h:962
struct m0_realm * en_realm
Definition: client.h:710
struct m0_sm_group en_sm_group
Definition: client.h:734
uint32_t mc_max_rpc_msg_size
Definition: client.h:949
struct m0_sm_group op_sm_group
Definition: client.h:654
const char * mc_local_addr
Definition: client.h:933
int mc_idx_service_id
Definition: client.h:956
Definition: fid.h:38
void m0_obj_idx_init(struct m0_idx *idx, const struct m0_obj *obj)
m0_op_obj_flags
Definition: client.h:569
m0_entity_type
Definition: client.h:585
static struct m0_realm realm
Definition: sync.c:87
struct m0_entity * op_entity
Definition: client.h:660
int m0_composite_layer_add(struct m0_client_layout *layout, struct m0_obj *sub_obj, int priority)
uint32_t mc_tm_recv_queue_min_len
Definition: client.h:944
Definition: sm.h:301
struct m0_entity ob_entity
Definition: client.h:789
int m0_client_layout_op(struct m0_obj *obj, enum m0_entity_opcode opcode, struct m0_client_layout *layout, struct m0_op **op)
Definition: layout.c:436
m0_obj_opcode
Definition: client.h:537
const struct m0_client_layout_ops * ml_ops
Definition: client.h:801
void m0_obj_init(struct m0_obj *obj, struct m0_realm *parent, const struct m0_uint128 *id, uint64_t layout_id)
Definition: client.c:403
m0_client_layout_type
Definition: client.h:776
static struct m0 instance
Definition: main.c:78
size_t oa_buf_size
Definition: client.h:769
void * op_datum
Definition: client.h:679
struct m0_fid oa_pool
Definition: client.h:760
int m0_client_layout_capture(struct m0_client_layout *layout, struct m0_obj *obj, struct m0_client_layout **out)
Definition: layout.c:138
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
struct m0_client * re_instance
Definition: client.h:873
const char * mc_profile
Definition: client.h:938
void m0_op_kick(struct m0_op *op)
Definition: client.c:924
uint32_t en_flags
Definition: client.h:738
#define out(...)
Definition: gen.c:41
void m0_op_free(struct m0_op *op)
Definition: client.c:885
uint64_t oa_layout_id
Definition: client.h:752
struct m0_sm en_sm
Definition: client.h:732
int type
Definition: dir.c:1031
struct m0_tl op_pending_tx
Definition: client.h:676
int m0_entity_open(struct m0_entity *entity, struct m0_op **op)
Definition: obj.c:885
struct m0_cookie ob_cookie
Definition: client.h:793
void m0_realm_close(struct m0_realm *realm, uint64_t wcount, uint64_t rcount, struct m0_op **op)
struct m0_dirent * ent
Definition: dir.c:1029
void m0_realm_create(struct m0_realm *realm, uint64_t wcount, uint64_t rcount, struct m0_op **op)
Definition: mutex.h:47
struct m0_mutex op_priv_lock
Definition: client.h:685
int m0_composite_layer_idx_val_to_buf(struct m0_composite_layer_idx_val *val, void **out_vbuf, m0_bcount_t *out_vlen)
enum m0_entity_type en_type
Definition: client.h:706
void m0_idx_init(struct m0_idx *idx, struct m0_realm *parent, const struct m0_uint128 *id)
Definition: idx.c:626
struct m0_obj_attr ob_attr
Definition: client.h:790
struct m0_fid oa_pver
Definition: client.h:763
Definition: vec.h:145
void m0_epoch_init(struct m0_epoch *epoch, struct m0_realm *parent, const struct m0_uint128 *id)
Definition: idx_mock.c:47
void m0_op_setup(struct m0_op *op, const struct m0_op_ops *cbs, m0_time_t linger)
Definition: client.c:908