Motr  M0
api.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 
24 /*
25  * Wrappers for each m0_xxx in which we keep track of
26  * the resources used.
27  */
28 
29 #include "motr/client.h"
30 #include "motr/st/st.h"
31 #include "motr/st/st_misc.h"
32 #include "motr/st/st_assert.h"
33 
35  struct m0_realm *parent,
36  const struct m0_uint128 *id,
37  struct m0_client *instance)
38 {
39  m0_container_init(con, parent, id, instance);
40 }
41 
42 void st_obj_init(struct m0_obj *obj,
43  struct m0_realm *parent,
44  const struct m0_uint128 *id, uint64_t layout_id)
45 {
46  m0_obj_init(obj, parent, id, layout_id);
47  st_mark_entity(&obj->ob_entity);
48 }
49 
50 void st_obj_fini(struct m0_obj *obj)
51 {
53  st_unmark_entity(&obj->ob_entity);
54 }
55 
56 void st_idx_init(struct m0_idx *idx,
57  struct m0_realm *parent,
58  const struct m0_uint128 *id)
59 {
60  m0_idx_init(idx, parent, id);
62 }
63 
64 void st_idx_fini(struct m0_idx *idx)
65 {
66  m0_idx_fini(idx);
68 }
69 
70 
72  struct m0_entity *entity,
73  struct m0_op **op)
74 {
75  int rc;
76 
77  rc = m0_entity_create(NULL, entity, op);
78  if (*op != NULL) st_mark_op(*op);
79 
80  return rc;
81 }
82 
83 int st_entity_delete(struct m0_entity *entity,
84  struct m0_op **op)
85 {
86  int rc;
87 
88  rc = m0_entity_delete(entity, op);
89  if (*op != NULL) st_mark_op(*op);
90 
91  return rc;
92 }
93 
94 void st_entity_fini(struct m0_entity *entity)
95 {
96  m0_entity_fini(entity);
97  st_unmark_entity(entity);
98 }
99 
100 void st_obj_op(struct m0_obj *obj,
101  enum m0_obj_opcode opcode,
102  struct m0_indexvec *ext,
103  struct m0_bufvec *data,
104  struct m0_bufvec *attr,
105  uint64_t mask,
106  uint32_t flags,
107  struct m0_op **op)
108 {
109  m0_obj_op(obj, opcode, ext, data, attr, mask, flags, op);
110  if (*op != NULL) st_mark_op(*op);
111 }
112 
113 int st_idx_op(struct m0_idx *idx,
114  enum m0_idx_opcode opcode,
115  struct m0_bufvec *keys,
116  struct m0_bufvec *vals,
117  int *rcs,
118  int flag,
119  struct m0_op **op)
120 {
121  int rc;
122 
123  rc = m0_idx_op(idx, opcode, keys, vals, rcs, flag, op);
124  if (*op != NULL) st_mark_op(*op);
125 
126  return rc;
127 }
128 
129 void st_op_launch(struct m0_op **op, uint32_t nr)
130 {
131  /* nothing to record, call m0_xxx directly */
132  m0_op_launch(op, nr);
133  return;
134 }
135 
136 int32_t st_op_wait(struct m0_op *op, uint64_t bits, m0_time_t to)
137 {
138  /* nothing to record, call m0_xxx directly */
139  return m0_op_wait(op, bits, to);
140 }
141 
142 void st_op_fini(struct m0_op *op)
143 {
144  m0_op_fini(op);
145 }
146 
147 void st_op_free(struct m0_op *op)
148 {
149  m0_op_free(op);
150  st_unmark_op(op);
151 }
152 
153 void st_entity_open(struct m0_entity *entity)
154 {
155  struct m0_op *ops[1] = {NULL};
156  int rc;
157 
158  m0_entity_open(entity, &ops[0]);
159  if (ops[0] != NULL) st_mark_op(ops[0]);
160  st_op_launch(ops, 1);
162  M0_OS_STABLE),
163  m0_time_from_now(5, 0));
164  if ( rc == -ETIMEDOUT) {
165  m0_op_cancel(ops, 1);
166 
167  m0_op_wait(ops[0],
169  M0_OS_STABLE),
170  M0_TIME_NEVER);
171  }
172  st_op_fini(ops[0]);
173  st_op_free(ops[0]);
174 }
175 
176 void st_idx_open(struct m0_entity *entity)
177 {
178  struct m0_op *ops[1] = {NULL};
179 
180  m0_entity_open(entity, &ops[0]);
181 }
182 
183 int st_layout_op(struct m0_obj *obj,
185  struct m0_client_layout *layout,
186  struct m0_op **op)
187 {
188  int rc;
189 
190  rc = m0_client_layout_op(obj, opcode, layout, op);
191  if (*op != NULL) st_mark_op(*op);
192 
193  return rc;
194 }
195 /*
196  * Local variables:
197  * c-indentation-style: "K&R"
198  * c-basic-offset: 8
199  * tab-width: 8
200  * fill-column: 80
201  * scroll-step: 1
202  * End:
203  */
void st_idx_init(struct m0_idx *idx, struct m0_realm *parent, const struct m0_uint128 *id)
Definition: api.c:56
static size_t nr
Definition: dump.c:1505
int st_entity_create(struct m0_fid *pool, struct m0_entity *entity, struct m0_op **op)
Definition: api.c:71
void st_idx_open(struct m0_entity *entity)
Definition: api.c:176
Definition: client.h:835
void m0_entity_fini(struct m0_entity *entity)
Definition: client.c:438
void st_op_free(struct m0_op *op)
Definition: api.c:147
Definition: client.h:788
int const char const void size_t int flags
Definition: dir.c:328
#define NULL
Definition: misc.h:38
m0_idx_opcode
Definition: client.h:550
m0_entity_opcode
Definition: client.h:523
const m0_time_t M0_TIME_NEVER
Definition: time.c:108
void m0_op_fini(struct m0_op *op)
Definition: client.c:847
uint64_t m0_time_t
Definition: time.h:37
void st_obj_fini(struct m0_obj *obj)
Definition: api.c:50
void st_idx_fini(struct m0_idx *idx)
Definition: api.c:64
void st_unmark_op(struct m0_op *op)
Definition: st_assert.c:156
struct m0_bufvec data
Definition: di.c:40
#define M0_BITS(...)
Definition: misc.h:236
int st_idx_op(struct m0_idx *idx, enum m0_idx_opcode opcode, struct m0_bufvec *keys, struct m0_bufvec *vals, int *rcs, int flag, struct m0_op **op)
Definition: api.c:113
void m0_idx_fini(struct m0_idx *idx)
Definition: idx.c:643
static struct foo * obj
Definition: tlist.c:302
int32_t m0_op_wait(struct m0_op *op, uint64_t bits, m0_time_t to)
Definition: client.c:739
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
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
struct m0_entity in_entity
Definition: client.h:836
int opcode
Definition: crate.c:301
Definition: client.h:641
static void attr(struct m0_addb2__context *ctx, const uint64_t *v, char *buf)
Definition: dump.c:949
void st_container_init(struct m0_container *con, struct m0_realm *parent, const struct m0_uint128 *id, struct m0_client *instance)
Definition: api.c:34
void st_mark_op(struct m0_op *op)
Definition: st_assert.c:131
void m0_obj_fini(struct m0_obj *obj)
Definition: client.c:467
void m0_op_launch(struct m0_op **op, uint32_t nr)
Definition: client.c:725
int layout_id
Definition: dir.c:331
void st_unmark_entity(struct m0_entity *entity)
Definition: st_assert.c:198
void m0_op_cancel(struct m0_op **op, uint32_t nr)
Definition: client.c:639
void st_obj_init(struct m0_obj *obj, struct m0_realm *parent, const struct m0_uint128 *id, uint64_t layout_id)
Definition: api.c:42
static struct m0_pool pool
Definition: iter_ut.c:58
int m0_entity_create(struct m0_fid *pool, struct m0_entity *entity, struct m0_op **op)
Definition: obj.c:801
void st_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: api.c:100
Definition: fid.h:38
m0_time_t m0_time_from_now(uint64_t secs, long ns)
Definition: time.c:96
static bool flag
Definition: nucleus.c:266
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
void st_op_launch(struct m0_op **op, uint32_t nr)
Definition: api.c:129
void st_entity_fini(struct m0_entity *entity)
Definition: api.c:94
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
static struct m0 instance
Definition: main.c:78
int m0_entity_delete(struct m0_entity *entity, struct m0_op **op)
Definition: obj.c:824
int st_entity_delete(struct m0_entity *entity, struct m0_op **op)
Definition: api.c:83
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
void st_entity_open(struct m0_entity *entity)
Definition: api.c:153
void st_mark_entity(struct m0_entity *entity)
Definition: st_assert.c:177
void m0_op_free(struct m0_op *op)
Definition: client.c:885
int m0_entity_open(struct m0_entity *entity, struct m0_op **op)
Definition: obj.c:885
struct m0_fom_ops ops
Definition: io_foms.c:623
int32_t st_op_wait(struct m0_op *op, uint64_t bits, m0_time_t to)
Definition: api.c:136
void st_op_fini(struct m0_op *op)
Definition: api.c:142
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
Definition: vec.h:145
int st_layout_op(struct m0_obj *obj, enum m0_entity_opcode opcode, struct m0_client_layout *layout, struct m0_op **op)
Definition: api.c:183