Motr  M0
cas.c
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 #define M0_TRACE_SUBSYSTEM M0_TRACE_SUBSYS_CAS
24 
25 #include "lib/trace.h"
26 #include "lib/finject.h" /* M0_FI_ENABLED */
27 #include "fid/fid.h" /* m0_fid_type_register */
28 #include "fop/fop.h"
29 #include "fop/wire_xc.h"
30 #include "rpc/rpc_opcodes.h"
31 #include "cas/cas.h"
32 #include "cas/cas_xc.h"
33 #include "mdservice/fsync_foms.h" /* m0_fsync_fom_conf */
34 #include "mdservice/fsync_fops.h" /* m0_fsync_fom_ops */
35 #include "mdservice/fsync_fops_xc.h" /* m0_fop_fsync_xc */
36 #include "cas/client.h" /* m0_cas_sm_conf_init */
37 
38 struct m0_fom_type_ops;
39 struct m0_sm_conf;
41 
48 M0_INTERNAL struct m0_fop_type cas_get_fopt;
49 M0_INTERNAL struct m0_fop_type cas_put_fopt;
50 M0_INTERNAL struct m0_fop_type cas_del_fopt;
51 M0_INTERNAL struct m0_fop_type cas_cur_fopt;
52 M0_INTERNAL struct m0_fop_type cas_rep_fopt;
53 M0_INTERNAL struct m0_fop_type cas_gc_fopt;
55 
56 static int cas_fops_init(const struct m0_sm_conf *sm_conf,
57  const struct m0_fom_type_ops *fom_ops,
58  const struct m0_reqh_service_type *svctype)
59 {
61  .name = "cas-get",
63  .rpc_flags = M0_RPC_ITEM_TYPE_REQUEST,
64  .xt = m0_cas_op_xc,
65  .fom_ops = fom_ops,
66  .sm = sm_conf,
67  .svc_type = svctype);
69  .name = "cas-put",
71  .rpc_flags = M0_RPC_ITEM_TYPE_REQUEST |
73  .xt = m0_cas_op_xc,
74  .fom_ops = fom_ops,
75  .sm = sm_conf,
76  .svc_type = svctype);
78  .name = "cas-del",
80  .rpc_flags = M0_RPC_ITEM_TYPE_REQUEST |
82  .xt = m0_cas_op_xc,
83  .fom_ops = fom_ops,
84  .sm = sm_conf,
85  .svc_type = svctype);
87  .name = "cas-cur",
89  .rpc_flags = M0_RPC_ITEM_TYPE_REQUEST,
90  .xt = m0_cas_op_xc,
91  .fom_ops = fom_ops,
92  .sm = sm_conf,
93  .svc_type = svctype);
95  .name = "cas-rep",
97  .rpc_flags = M0_RPC_ITEM_TYPE_REPLY,
98  .xt = m0_cas_rep_xc,
99  .svc_type = svctype);
101  .name = "cas-gc-wait",
103  .rpc_flags = M0_RPC_ITEM_TYPE_REQUEST,
104  .xt = m0_cas_op_xc,
105  .fom_ops = fom_ops,
106  .sm = sm_conf,
107  .svc_type = svctype);
109  .name = "fsync-cas",
111  .xt = m0_fop_fsync_xc,
112 #ifndef __KERNEL__
113  .svc_type = svctype,
114  .sm = &m0_fsync_fom_conf,
115  .fom_ops = &m0_fsync_fom_ops,
116 #endif
117  .rpc_flags = M0_RPC_ITEM_TYPE_REQUEST);
124 }
125 
126 static void cas_fops_fini(void)
127 {
141 }
142 
147 M0_INTERNAL const struct m0_fid m0_cas_meta_fid = M0_FID_TINIT('i', 0, 0);
148 
152 M0_INTERNAL const struct m0_fid m0_cas_ctidx_fid = M0_FID_TINIT('i', 0, 1);
153 
157 M0_INTERNAL const struct m0_fid m0_cas_dead_index_fid = M0_FID_TINIT('i', 0, 2);
158 
159 M0_INTERNAL const struct m0_fid_type m0_cas_index_fid_type = {
160  .ft_id = 'i',
161  .ft_name = "cas-index"
162 };
163 
164 M0_INTERNAL const struct m0_fid_type m0_cctg_fid_type = {
165  .ft_id = 'T',
166  .ft_name = "component-catalogue"
167 };
168 
169 M0_INTERNAL const struct m0_fid_type m0_dix_fid_type = {
170  .ft_id = 'x',
171  .ft_name = "distributed-index"
172 };
173 
174 M0_INTERNAL int m0_cas_module_init(void)
175 {
176  struct m0_sm_conf *sm_conf;
177  const struct m0_fom_type_ops *fom_ops;
178  struct m0_reqh_service_type *svctype;
179 
183  m0_cas_svc_init();
184  m0_cas_svc_fop_args(&sm_conf, &fom_ops, &svctype);
185  return cas_fops_init(sm_conf, fom_ops, svctype) ?:
187 }
188 
189 M0_INTERNAL void m0_cas_module_fini(void)
190 {
192  cas_fops_fini();
193  m0_cas_svc_fini();
197 }
198 
199 M0_INTERNAL void m0_cas_id_fini(struct m0_cas_id *cid)
200 {
201  M0_PRE(cid != NULL);
202 
204  m0_dix_ldesc_fini(&cid->ci_layout.u.dl_desc);
205  M0_SET0(cid);
206 }
207 
208 M0_INTERNAL bool m0_cas_id_invariant(const struct m0_cas_id *cid)
209 {
210  return _0C(cid != NULL) &&
211  _0C(M0_IN(m0_fid_type_getfid(&cid->ci_fid),
213  &m0_dix_fid_type))) &&
214  _0C(M0_IN(cid->ci_layout.dl_type, (DIX_LTYPE_UNKNOWN,
218  M0_IS0(&cid->ci_layout)));
219 }
220 
221 M0_INTERNAL bool cas_in_ut(void)
222 {
223  return M0_FI_ENABLED("ut");
224 }
225 
226 M0_INTERNAL bool m0_crv_tbs(const struct m0_crv *crv)
227 {
228  return crv->crv_encoded & M0_CRV_TBS;
229 }
230 
231 M0_INTERNAL void m0_crv_tbs_set(struct m0_crv *crv, bool tbs)
232 {
233  if (tbs)
234  crv->crv_encoded |= M0_CRV_TBS;
235  else
236  crv->crv_encoded &= ~M0_CRV_TBS;
237 }
238 
239 M0_INTERNAL struct m0_dtm0_ts m0_crv_ts(const struct m0_crv *crv)
240 {
241  return (struct m0_dtm0_ts) {
242  .dts_phys = crv->crv_encoded & ~M0_CRV_TBS
243  };
244 }
245 
246 M0_INTERNAL void m0_crv_ts_set(struct m0_crv *crv,
247  const struct m0_dtm0_ts *ts)
248 {
249  crv->crv_encoded = (crv->crv_encoded & M0_CRV_TBS) | ts->dts_phys;
250 }
251 
252 M0_INTERNAL void m0_crv_init(struct m0_crv *crv,
253  const struct m0_dtm0_ts *ts,
254  bool tbs)
255 {
256  uint64_t version = ts->dts_phys;
257 
260 
261  m0_crv_ts_set(crv, ts);
262  m0_crv_tbs_set(crv, tbs);
263 
264  M0_POST(equi(m0_crv_tbs(crv), tbs));
266 }
267 
276 M0_INTERNAL int m0_crv_cmp(const struct m0_crv *left,
277  const struct m0_crv *right)
278 {
279  return M0_3WAY(m0_crv_ts(left).dts_phys, m0_crv_ts(right).dts_phys) ?:
280  M0_3WAY(m0_crv_tbs(left), m0_crv_tbs(right));
281 }
282 
283 M0_INTERNAL bool m0_crv_is_none(const struct m0_crv *crv)
284 {
285  return memcmp(crv, &M0_CRV_INIT_NONE, sizeof(*crv)) == 0;
286 }
287 
288 #undef M0_TRACE_SUBSYSTEM
289 
292 /*
293  * Local variables:
294  * c-indentation-style: "K&R"
295  * c-basic-offset: 8
296  * tab-width: 8
297  * fill-column: 80
298  * scroll-step: 1
299  * End:
300  */
301 /*
302  * vim: tabstop=8 shiftwidth=8 noexpandtab textwidth=80 nowrap
303  */
#define M0_PRE(cond)
#define NULL
Definition: misc.h:38
#define ergo(a, b)
Definition: misc.h:293
#define M0_3WAY(v0, v1)
Definition: arith.h:199
#define M0_FOP_TYPE_INIT(ft,...)
Definition: fop.h:308
Definition: sm.h:350
M0_INTERNAL void m0_cas_svc_init(void)
Definition: service.c:515
uint8_t ft_id
Definition: fid.h:101
void m0_fop_type_addb2_deinstrument(struct m0_fop_type *type)
Definition: fop.c:492
M0_INTERNAL void m0_cas_id_fini(struct m0_cas_id *cid)
Definition: cas.c:199
uint64_t crv_encoded
Definition: cas.h:158
M0_INTERNAL const struct m0_fid m0_cas_meta_fid
Definition: cas.c:147
struct m0_dix_layout ci_layout
Definition: cas.h:120
M0_INTERNAL const struct m0_fid_type m0_cas_index_fid_type
Definition: cas.c:159
void m0_fop_type_fini(struct m0_fop_type *fopt)
Definition: fop.c:231
static int left
Definition: locality.c:280
#define M0_SET0(obj)
Definition: misc.h:64
static struct m0_xcode_type ** xt[]
Definition: protocol.c:64
M0_INTERNAL bool m0_cas_id_invariant(const struct m0_cas_id *cid)
Definition: cas.c:208
M0_INTERNAL void m0_cas_module_fini(void)
Definition: cas.c:189
M0_INTERNAL struct m0_sm_conf m0_fsync_fom_conf
Definition: fsync_foms.c:123
#define equi(a, b)
Definition: misc.h:297
M0_INTERNAL void m0_crv_ts_set(struct m0_crv *crv, const struct m0_dtm0_ts *ts)
Definition: cas.c:246
const struct m0_fom_type_ops m0_fsync_fom_ops
Definition: fsync_fops.c:62
m0_time_t dts_phys
Definition: clk_src.h:93
int opcode
Definition: crate.c:301
M0_INTERNAL void m0_fid_type_register(const struct m0_fid_type *fidt)
Definition: fid.c:46
string version
Definition: conf.py:40
const char * name
Definition: trace.c:110
#define M0_FID_TINIT(type, container, key)
Definition: fid.h:90
M0_INTERNAL struct m0_dtm0_ts m0_crv_ts(const struct m0_crv *crv)
Definition: cas.c:239
Definition: cas.h:157
M0_INTERNAL const struct m0_fid_type m0_dix_fid_type
Definition: cas.c:169
M0_INTERNAL void m0_cas_svc_fini(void)
Definition: service.c:529
M0_INTERNAL void m0_crv_tbs_set(struct m0_crv *crv, bool tbs)
Definition: cas.c:231
M0_INTERNAL bool cas_in_ut(void)
Definition: cas.c:221
M0_INTERNAL int m0_cas_sm_conf_init(void)
Definition: client.c:1892
M0_INTERNAL int m0_crv_cmp(const struct m0_crv *left, const struct m0_crv *right)
Definition: cas.c:276
struct m0_xcode_type * m0_cas_op_xc
Definition: cas_xc.c:17
M0_INTERNAL struct m0_fop_type cas_get_fopt
Definition: cas.c:48
M0_INTERNAL const struct m0_fid_type m0_cctg_fid_type
Definition: cas.c:164
M0_INTERNAL const struct m0_fid_type * m0_fid_type_getfid(const struct m0_fid *fid)
Definition: fid.c:76
struct m0_xcode_type * m0_cas_rep_xc
Definition: cas_xc.c:18
#define M0_POST(cond)
M0_INTERNAL struct m0_fop_type cas_cur_fopt
Definition: cas.c:51
M0_INTERNAL bool m0_crv_tbs(const struct m0_crv *crv)
Definition: cas.c:226
uint32_t dl_type
Definition: layout.h:100
static void cas_fops_fini(void)
Definition: cas.c:126
M0_INTERNAL const struct m0_fid m0_cas_dead_index_fid
Definition: cas.c:157
struct m0_fid ci_fid
Definition: cas.h:113
M0_INTERNAL void m0_fid_type_unregister(const struct m0_fid_type *fidt)
Definition: fid.c:55
union m0_dix_layout::@145 u
static int cas_fops_init(const struct m0_sm_conf *sm_conf, const struct m0_fom_type_ops *fom_ops, const struct m0_reqh_service_type *svctype)
Definition: cas.c:56
M0_INTERNAL void m0_cas_svc_fop_args(struct m0_sm_conf **sm_conf, const struct m0_fom_type_ops **fom_ops, struct m0_reqh_service_type **svctype)
Definition: service.c:536
M0_INTERNAL void m0_dix_ldesc_fini(struct m0_dix_ldesc *ld)
Definition: layout.c:197
M0_INTERNAL struct m0_fop_type cas_gc_fopt
Definition: cas.c:53
M0_INTERNAL struct m0_fop_type cas_del_fopt
Definition: cas.c:50
M0_INTERNAL void m0_cas_sm_conf_fini(void)
Definition: client.c:1900
M0_INTERNAL bool m0_crv_is_none(const struct m0_crv *crv)
Definition: cas.c:283
struct m0_xcode_type * m0_fop_fsync_xc
Definition: fsync_fops_xc.c:10
#define M0_FI_ENABLED(tag)
Definition: finject.h:231
Definition: fid.h:38
#define M0_IS0(obj)
Definition: misc.h:70
struct m0_fop_type m0_fop_fsync_cas_fopt
Definition: cas.c:54
M0_INTERNAL int m0_cas_module_init(void)
Definition: cas.c:174
int m0_fop_type_addb2_instrument(struct m0_fop_type *type)
Definition: fop.c:460
M0_INTERNAL void m0_crv_init(struct m0_crv *crv, const struct m0_dtm0_ts *ts, bool tbs)
Definition: cas.c:252
#define _0C(exp)
Definition: assert.h:311
m0_time_t dts_phys
Definition: clk_src.h:34
M0_INTERNAL struct m0_fop_type cas_put_fopt
Definition: cas.c:49
M0_INTERNAL const struct m0_fid m0_cas_ctidx_fid
Definition: cas.c:152
#define M0_CRV_INIT_NONE
Definition: cas.h:515
Definition: cas.h:107
M0_INTERNAL struct m0_fop_type cas_rep_fopt
Definition: cas.c:52