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 */
567  M0_IC_LIST, /* 20 */
568  M0_IC_NR /* 21 */
569 } M0_XCA_ENUM;
570 
580  M0_OOF_HOLE = 1 << 0,
585  M0_OOF_SYNC = 1 << 1
586 } M0_XCA_ENUM;
587 
595 } M0_XCA_ENUM;
596 
632  M0_ENF_META = 1 << 0,
637  M0_ENF_NO_RMW = 1 << 1,
641  M0_ENF_DI = 1 << 2
642  } M0_XCA_ENUM;
643 
647 struct m0_op {
648  uint64_t op_magic;
649 
656  unsigned int op_code;
658  int32_t op_rc;
662  struct m0_sm op_sm;
664  const struct m0_op_ops *op_cbs;
668  m0_time_t op_linger; /* a town in Luxembourg. */
670  size_t op_size;
672  uint64_t op_gen;
679  struct m0_op *op_parent;
684  /* Operation's private data, can be used as arguments for callbacks.*/
685  void *op_datum;
686  uint64_t op_count;
690  void *op_priv;
692 };
693 
705 };
706 
710 struct m0_entity {
738  struct m0_sm en_sm;
744  uint32_t en_flags;
745 };
746 
753 struct m0_obj_attr {
756 
758  uint64_t oa_layout_id;
759 
766  struct m0_fid oa_pool;
767 
769  struct m0_fid oa_pver;
770 
775  size_t oa_buf_size;
776 };
777 
787 };
788 
793 struct m0_client_layout;
794 struct m0_obj {
800 };
801 
805  /* Back pointer to the object it belongs to. */
806  struct m0_obj *ml_obj;
808 };
809 
817 struct m0_idx_attr {
819  uint32_t idx_layout_type;
821  struct m0_fid idx_pver;
822 };
823 
841 struct m0_idx {
844 };
845 
846 #define M0_COMPOSITE_EXTENT_INF (0xffffffffffffffff)
850 };
851 
854 };
855 
861 };
862 
869 struct m0_client;
870 
876 struct m0_realm {
880 };
881 
886 struct m0_container {
888 };
889 
899 struct m0_epoch {
901 };
902 
907 struct m0__dtx {
909 };
910 
914 struct m0_op_ops {
915  void (*oop_executed)(struct m0_op *op);
916  void (*oop_failed)(struct m0_op *op);
917  void (*oop_stable) (struct m0_op *op);
918 };
919 
924 struct m0_config {
932 
937 
939  const char *mc_local_addr;
941  const char *mc_ha_addr;
943  const char *mc_process_fid;
944  const char *mc_profile;
945 
956 
957  /* TODO: This parameter is added for a temporary solution of
958  * layout selection for s3 team. This has to be removed when
959  * sophisticated solution is implemented.*/
960  uint32_t mc_layout_id;
961 
964 
969 };
970 
972 extern const struct m0_uint128 M0_UBER_REALM;
973 
980 extern const struct m0_uint128 M0_ID_APP;
981 
1117 struct m0_rm_lock_req;
1118 
1129 int m0_obj_lock_init(struct m0_obj *obj);
1130 
1140 void m0_obj_lock_fini(struct m0_obj *obj);
1141 
1156 int m0_obj_write_lock_get(struct m0_obj *obj,
1157  struct m0_rm_lock_req *req,
1158  struct m0_clink *clink);
1159 
1174  struct m0_rm_lock_req *req);
1175 
1191 int m0_obj_read_lock_get(struct m0_obj *obj,
1192  struct m0_rm_lock_req *req,
1193  struct m0_clink *clink);
1194 
1210  struct m0_rm_lock_req *req);
1211 
1217 void m0_obj_lock_put(struct m0_rm_lock_req *req);
1218 
1230 void m0_op_setup(struct m0_op *op,
1231  const struct m0_op_ops *cbs,
1232  m0_time_t linger);
1249 void m0_op_launch(struct m0_op **op, uint32_t nr);
1250 
1284 int32_t m0_op_wait(struct m0_op *op, uint64_t bits, m0_time_t to);
1285 
1301 void m0_op_cancel(struct m0_op **op, uint32_t nr);
1302 
1317 void m0_op_kick(struct m0_op *op);
1318 
1329 int32_t m0_rc(const struct m0_op *op);
1330 
1341 void m0_op_fini(struct m0_op *op);
1342 
1351 void m0_op_free(struct m0_op *op);
1352 
1353 void m0_container_init(struct m0_container *con,
1354  struct m0_realm *parent,
1355  const struct m0_uint128 *id,
1356  struct m0_client *instance);
1357 void m0_epoch_init (struct m0_epoch *epoch,
1358  struct m0_realm *parent,
1359  const struct m0_uint128 *id);
1360 void m0__dtx_init (struct m0__dtx *dtx,
1361  struct m0_realm *parent,
1362  const struct m0_uint128 *id);
1363 
1385 void m0_obj_init(struct m0_obj *obj,
1386  struct m0_realm *parent,
1387  const struct m0_uint128 *id,
1388  uint64_t layout_id);
1397 void m0_obj_fini(struct m0_obj *obj);
1398 
1411 void m0_obj_idx_init(struct m0_idx *idx,
1412  const struct m0_obj *obj);
1413 
1461 int m0_obj_op(struct m0_obj *obj,
1462  enum m0_obj_opcode opcode,
1463  struct m0_indexvec *ext,
1464  struct m0_bufvec *data,
1465  struct m0_bufvec *attr,
1466  uint64_t mask,
1467  uint32_t flags,
1468  struct m0_op **op);
1469 
1487 void m0_idx_init(struct m0_idx *idx,
1488  struct m0_realm *parent,
1489  const struct m0_uint128 *id);
1490 
1491 void m0_idx_fini(struct m0_idx *idx);
1492 
1572 int m0_idx_op(struct m0_idx *idx,
1573  enum m0_idx_opcode opcode,
1574  struct m0_bufvec *keys,
1575  struct m0_bufvec *vals,
1576  int32_t *rcs,
1577  uint32_t flags,
1578  struct m0_op **op);
1579 
1580 void m0_realm_create(struct m0_realm *realm,
1581  uint64_t wcount, uint64_t rcount,
1582  struct m0_op **op);
1583 
1584 void m0_realm_open(struct m0_realm *realm,
1585  uint64_t wcount, uint64_t rcount,
1586  struct m0_op **op);
1587 
1588 void m0_realm_close(struct m0_realm *realm,
1589  uint64_t wcount, uint64_t rcount,
1590  struct m0_op **op);
1591 
1606 int m0_entity_create(struct m0_fid *pool,
1607  struct m0_entity *entity,
1608  struct m0_op **op);
1609 int m0_entity_delete(struct m0_entity *entity,
1610  struct m0_op **op);
1624 int m0_entity_open(struct m0_entity *entity,
1625  struct m0_op **op);
1634 void m0_entity_fini(struct m0_entity *entity);
1635 
1641 size_t m0_op_maxsize(void);
1642 
1654 int m0_client_init(struct m0_client **m0c,
1655  struct m0_config *conf,
1656  bool init_m0);
1657 
1663 void m0_client_fini(struct m0_client *m0c, bool fini_m0);
1664 
1673 void m0_process_fid(const struct m0_client *m0c,
1674  struct m0_fid *proc_fid);
1675 
1683 int m0_sync_op_init(struct m0_op **sop);
1684 
1692 int m0_sync_entity_add(struct m0_op *sop,
1693  struct m0_entity *ent);
1701 int m0_sync_op_add(struct m0_op *sop,
1702  struct m0_op *op);
1703 
1711 int m0_entity_sync(struct m0_entity *ent);
1712 
1722 int m0_sync(struct m0_client *m0c, bool wait);
1723 
1733 
1743 
1744 uint64_t m0_client_layout_id(const struct m0_client *instance);
1745 
1753 
1766 int m0_composite_layer_add(struct m0_client_layout *layout,
1767  struct m0_obj *sub_obj, int priority);
1774 void m0_composite_layer_del(struct m0_client_layout *layout,
1775  struct m0_uint128 subobj_id);
1776 
1785 int m0_composite_layer_idx(struct m0_uint128 layer_id,
1786  bool write, struct m0_idx *idx);
1794  void **out_kbuf, m0_bcount_t *out_klen);
1797  void *kbuf);
1800  void **out_vbuf, m0_bcount_t *out_vlen);
1803  void *vbuf);
1804 
1815 int m0_client_layout_op(struct m0_obj *obj,
1816  enum m0_entity_opcode opcode,
1817  struct m0_client_layout *layout,
1818  struct m0_op **op);
1819 
1826 int m0_client_layout_capture(struct m0_client_layout *layout,
1827  struct m0_obj *obj,
1828  struct m0_client_layout **out);
1829 
1830 /* Allocate/free in-memory layout data struct for an object. */
1831 struct m0_client_layout*
1833 void m0_client_layout_free(struct m0_client_layout *layout);
1834 
1835 //** @} end of client group */
1836 
1837 #include "motr/idx.h" /* export m0_idx operations and services to client. */
1838 #include "cas/cas.h"
1839 
1840 #endif /* __MOTR_CLIENT_H__ */
1841 
1842 /*
1843  * Local variables:
1844  * c-indentation-style: "K&R"
1845  * c-basic-offset: 8
1846  * tab-width: 8
1847  * fill-column: 80
1848  * scroll-step: 1
1849  * End:
1850  */
1851 /*
1852  * vim: tabstop=8 shiftwidth=8 noexpandtab textwidth=80 nowrap
1853  */
struct m0_fid idx_pver
Definition: client.h:821
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:841
uint32_t mc_layout_id
Definition: client.h:960
void m0_entity_fini(struct m0_entity *entity)
Definition: client.c:438
struct m0_mutex en_pending_tx_lock
Definition: client.h:743
Definition: client.h:794
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:664
m0_idx_opcode
Definition: client.h:550
m0_entity_opcode
Definition: client.h:523
uint32_t idx_layout_type
Definition: client.h:819
const char * mc_process_fid
Definition: client.h:943
Definition: idx_mock.c:52
uint64_t op_gen
Definition: client.h:672
void m0_op_fini(struct m0_op *op)
Definition: client.c:848
static struct io_request req
Definition: file.c:100
bool mc_is_addb_init
Definition: client.h:936
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:915
struct m0_mutex op_pending_tx_lock
Definition: client.h:683
int m0_entity_sync(struct m0_entity *ent)
Definition: sync.c:1061
uint64_t op_magic
Definition: client.h:648
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:679
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:944
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:856
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:644
Definition: sm.h:504
struct m0_idx_attr in_attr
Definition: client.h:843
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:900
uint64_t op_count
Definition: client.h:686
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:738
struct m0_tl en_pending_tx
Definition: client.h:742
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:555
op
Definition: libdemo.c:64
unsigned int op_code
Definition: client.h:656
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:842
int opcode
Definition: crate.c:301
enum m0_client_layout_type ml_type
Definition: client.h:804
int m0_obj_layout_id_to_unit_size(uint64_t layout_id)
Definition: obj.c:851
size_t op_size
Definition: client.h:670
struct m0_realm co_realm
Definition: client.h:887
struct m0_sm_ast op_parent_ast
Definition: client.h:680
const char * mc_ha_addr
Definition: client.h:941
Definition: client.h:647
struct m0_realm dt_realm
Definition: client.h:908
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:662
static void attr(struct m0_addb2__context *ctx, const uint64_t *v, char *buf)
Definition: dump.c:949
m0_entity_flags
Definition: client.h:601
void(* oop_stable)(struct m0_op *op)
Definition: client.h:917
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:877
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:658
void * op_priv
Definition: client.h:690
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:926
m0_op_state
Definition: client.h:697
void m0_op_launch(struct m0_op **op, uint32_t nr)
Definition: client.c:724
m0_bcount_t oa_bshift
Definition: client.h:755
struct m0_client_layout * ob_layout
Definition: client.h:797
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:668
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:878
struct m0_entity ml_entity
Definition: client.h:803
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:916
struct m0_uint128 en_id
Definition: client.h:714
void m0_op_cancel(struct m0_op **op, uint32_t nr)
Definition: client.c:638
bool mc_is_read_verify
Definition: client.h:931
static struct m0_pool pool
Definition: iter_ut.c:58
void * mc_idx_service_conf
Definition: client.h:963
struct m0_uint128 cek_layer_id
Definition: client.h:848
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:806
m0_bcount_t mc_addb_size
Definition: client.h:968
struct m0_realm * en_realm
Definition: client.h:716
struct m0_sm_group en_sm_group
Definition: client.h:740
uint32_t mc_max_rpc_msg_size
Definition: client.h:955
struct m0_sm_group op_sm_group
Definition: client.h:660
const char * mc_local_addr
Definition: client.h:939
int mc_idx_service_id
Definition: client.h:962
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:574
m0_entity_type
Definition: client.h:591
static struct m0_realm realm
Definition: sync.c:87
struct m0_entity * op_entity
Definition: client.h:666
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:950
Definition: sm.h:301
struct m0_entity ob_entity
Definition: client.h:795
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:807
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:782
static struct m0 instance
Definition: main.c:78
size_t oa_buf_size
Definition: client.h:775
void * op_datum
Definition: client.h:685
struct m0_fid oa_pool
Definition: client.h:766
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:879
const char * mc_profile
Definition: client.h:944
void m0_op_kick(struct m0_op *op)
Definition: client.c:925
uint32_t en_flags
Definition: client.h:744
#define out(...)
Definition: gen.c:41
void m0_op_free(struct m0_op *op)
Definition: client.c:886
uint64_t oa_layout_id
Definition: client.h:758
struct m0_sm en_sm
Definition: client.h:738
int type
Definition: dir.c:1031
struct m0_tl op_pending_tx
Definition: client.h:682
int m0_entity_open(struct m0_entity *entity, struct m0_op **op)
Definition: obj.c:885
struct m0_cookie ob_cookie
Definition: client.h:799
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:691
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:712
void m0_idx_init(struct m0_idx *idx, struct m0_realm *parent, const struct m0_uint128 *id)
Definition: idx.c:627
struct m0_obj_attr ob_attr
Definition: client.h:796
struct m0_fid oa_pver
Definition: client.h:769
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:909