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 "rpc/rpc_opcodes.h"
30 #include "cas/cas.h"
31 #include "cas/cas_xc.h"
32 #include "mdservice/fsync_foms.h" /* m0_fsync_fom_conf */
33 #include "mdservice/fsync_fops.h" /* m0_fsync_fom_ops */
34 #include "mdservice/fsync_fops_xc.h" /* m0_fop_fsync_xc */
35 #include "cas/client.h" /* m0_cas_sm_conf_init */
36 
37 struct m0_fom_type_ops;
38 struct m0_sm_conf;
40 
47 M0_INTERNAL struct m0_fop_type cas_get_fopt;
48 M0_INTERNAL struct m0_fop_type cas_put_fopt;
49 M0_INTERNAL struct m0_fop_type cas_del_fopt;
50 M0_INTERNAL struct m0_fop_type cas_cur_fopt;
51 M0_INTERNAL struct m0_fop_type cas_rep_fopt;
52 M0_INTERNAL struct m0_fop_type cas_gc_fopt;
54 
55 static int cas_fops_init(const struct m0_sm_conf *sm_conf,
56  const struct m0_fom_type_ops *fom_ops,
57  const struct m0_reqh_service_type *svctype)
58 {
60  .name = "cas-get",
62  .rpc_flags = M0_RPC_ITEM_TYPE_REQUEST,
63  .xt = m0_cas_op_xc,
64  .fom_ops = fom_ops,
65  .sm = sm_conf,
66  .svc_type = svctype);
68  .name = "cas-put",
70  .rpc_flags = M0_RPC_ITEM_TYPE_REQUEST |
72  .xt = m0_cas_op_xc,
73  .fom_ops = fom_ops,
74  .sm = sm_conf,
75  .svc_type = svctype);
77  .name = "cas-del",
79  .rpc_flags = M0_RPC_ITEM_TYPE_REQUEST |
81  .xt = m0_cas_op_xc,
82  .fom_ops = fom_ops,
83  .sm = sm_conf,
84  .svc_type = svctype);
86  .name = "cas-cur",
88  .rpc_flags = M0_RPC_ITEM_TYPE_REQUEST,
89  .xt = m0_cas_op_xc,
90  .fom_ops = fom_ops,
91  .sm = sm_conf,
92  .svc_type = svctype);
94  .name = "cas-rep",
96  .rpc_flags = M0_RPC_ITEM_TYPE_REPLY,
97  .xt = m0_cas_rep_xc,
98  .svc_type = svctype);
100  .name = "cas-gc-wait",
102  .rpc_flags = M0_RPC_ITEM_TYPE_REQUEST,
103  .xt = m0_cas_op_xc,
104  .fom_ops = fom_ops,
105  .sm = sm_conf,
106  .svc_type = svctype);
108  .name = "fsync-cas",
110  .xt = m0_fop_fsync_xc,
111 #ifndef __KERNEL__
112  .svc_type = svctype,
113  .sm = &m0_fsync_fom_conf,
114  .fom_ops = &m0_fsync_fom_ops,
115 #endif
116  .rpc_flags = M0_RPC_ITEM_TYPE_REQUEST);
123 }
124 
125 static void cas_fops_fini(void)
126 {
140 }
141 
146 M0_INTERNAL const struct m0_fid m0_cas_meta_fid = M0_FID_TINIT('i', 0, 0);
147 
151 M0_INTERNAL const struct m0_fid m0_cas_ctidx_fid = M0_FID_TINIT('i', 0, 1);
152 
156 M0_INTERNAL const struct m0_fid m0_cas_dead_index_fid = M0_FID_TINIT('i', 0, 2);
157 
158 M0_INTERNAL const struct m0_fid_type m0_cas_index_fid_type = {
159  .ft_id = 'i',
160  .ft_name = "cas-index"
161 };
162 
163 M0_INTERNAL const struct m0_fid_type m0_cctg_fid_type = {
164  .ft_id = 'T',
165  .ft_name = "component-catalogue"
166 };
167 
168 M0_INTERNAL const struct m0_fid_type m0_dix_fid_type = {
169  .ft_id = 'x',
170  .ft_name = "distributed-index"
171 };
172 
173 M0_INTERNAL int m0_cas_module_init(void)
174 {
175  struct m0_sm_conf *sm_conf;
176  const struct m0_fom_type_ops *fom_ops;
177  struct m0_reqh_service_type *svctype;
178 
182  m0_cas_svc_init();
183  m0_cas_svc_fop_args(&sm_conf, &fom_ops, &svctype);
184  return cas_fops_init(sm_conf, fom_ops, svctype) ?:
186 }
187 
188 M0_INTERNAL void m0_cas_module_fini(void)
189 {
191  cas_fops_fini();
192  m0_cas_svc_fini();
196 }
197 
198 M0_INTERNAL void m0_cas_id_fini(struct m0_cas_id *cid)
199 {
200  M0_PRE(cid != NULL);
201 
203  m0_dix_ldesc_fini(&cid->ci_layout.u.dl_desc);
204  M0_SET0(cid);
205 }
206 
207 M0_INTERNAL bool m0_cas_id_invariant(const struct m0_cas_id *cid)
208 {
209  return _0C(cid != NULL) &&
210  _0C(M0_IN(m0_fid_type_getfid(&cid->ci_fid),
212  &m0_dix_fid_type))) &&
213  _0C(M0_IN(cid->ci_layout.dl_type, (DIX_LTYPE_UNKNOWN,
217  M0_IS0(&cid->ci_layout)));
218 }
219 
220 M0_INTERNAL bool cas_in_ut(void)
221 {
222  return M0_FI_ENABLED("ut");
223 }
224 
225 M0_INTERNAL bool m0_crv_tbs(const struct m0_crv *crv)
226 {
227  return crv->crv_encoded & M0_CRV_TBS;
228 }
229 
230 M0_INTERNAL void m0_crv_tbs_set(struct m0_crv *crv, bool tbs)
231 {
232  if (tbs)
233  crv->crv_encoded |= M0_CRV_TBS;
234  else
235  crv->crv_encoded &= ~M0_CRV_TBS;
236 }
237 
238 M0_INTERNAL struct m0_dtm0_ts m0_crv_ts(const struct m0_crv *crv)
239 {
240  return (struct m0_dtm0_ts) {
241  .dts_phys = crv->crv_encoded & ~M0_CRV_TBS
242  };
243 }
244 
245 M0_INTERNAL void m0_crv_ts_set(struct m0_crv *crv,
246  const struct m0_dtm0_ts *ts)
247 {
248  crv->crv_encoded = (crv->crv_encoded & M0_CRV_TBS) | ts->dts_phys;
249 }
250 
251 M0_INTERNAL void m0_crv_init(struct m0_crv *crv,
252  const struct m0_dtm0_ts *ts,
253  bool tbs)
254 {
255  uint64_t version = ts->dts_phys;
256 
259 
260  m0_crv_ts_set(crv, ts);
261  m0_crv_tbs_set(crv, tbs);
262 
263  M0_POST(equi(m0_crv_tbs(crv), tbs));
265 }
266 
275 M0_INTERNAL int m0_crv_cmp(const struct m0_crv *left,
276  const struct m0_crv *right)
277 {
278  return M0_3WAY(m0_crv_ts(left).dts_phys, m0_crv_ts(right).dts_phys) ?:
279  M0_3WAY(m0_crv_tbs(left), m0_crv_tbs(right));
280 }
281 
282 M0_INTERNAL bool m0_crv_is_none(const struct m0_crv *crv)
283 {
284  return memcmp(crv, &M0_CRV_INIT_NONE, sizeof(*crv)) == 0;
285 }
286 
287 #undef M0_TRACE_SUBSYSTEM
288 
291 /*
292  * Local variables:
293  * c-indentation-style: "K&R"
294  * c-basic-offset: 8
295  * tab-width: 8
296  * fill-column: 80
297  * scroll-step: 1
298  * End:
299  */
300 /*
301  * vim: tabstop=8 shiftwidth=8 noexpandtab textwidth=80 nowrap
302  */
#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:307
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:493
M0_INTERNAL void m0_cas_id_fini(struct m0_cas_id *cid)
Definition: cas.c:198
uint64_t crv_encoded
Definition: cas.h:158
M0_INTERNAL const struct m0_fid m0_cas_meta_fid
Definition: cas.c:146
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:158
void m0_fop_type_fini(struct m0_fop_type *fopt)
Definition: fop.c:232
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:207
M0_INTERNAL void m0_cas_module_fini(void)
Definition: cas.c:188
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:245
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:238
Definition: cas.h:157
M0_INTERNAL const struct m0_fid_type m0_dix_fid_type
Definition: cas.c:168
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:230
M0_INTERNAL bool cas_in_ut(void)
Definition: cas.c:220
M0_INTERNAL int m0_cas_sm_conf_init(void)
Definition: client.c:1883
M0_INTERNAL int m0_crv_cmp(const struct m0_crv *left, const struct m0_crv *right)
Definition: cas.c:275
M0_INTERNAL struct m0_fop_type cas_get_fopt
Definition: cas.c:47
M0_INTERNAL const struct m0_fid_type m0_cctg_fid_type
Definition: cas.c:163
M0_INTERNAL const struct m0_fid_type * m0_fid_type_getfid(const struct m0_fid *fid)
Definition: fid.c:76
#define M0_POST(cond)
M0_INTERNAL struct m0_fop_type cas_cur_fopt
Definition: cas.c:50
M0_INTERNAL bool m0_crv_tbs(const struct m0_crv *crv)
Definition: cas.c:225
uint32_t dl_type
Definition: layout.h:100
static void cas_fops_fini(void)
Definition: cas.c:125
M0_INTERNAL const struct m0_fid m0_cas_dead_index_fid
Definition: cas.c:156
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:55
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:52
M0_INTERNAL struct m0_fop_type cas_del_fopt
Definition: cas.c:49
M0_INTERNAL void m0_cas_sm_conf_fini(void)
Definition: client.c:1891
M0_INTERNAL bool m0_crv_is_none(const struct m0_crv *crv)
Definition: cas.c:282
#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:53
M0_INTERNAL int m0_cas_module_init(void)
Definition: cas.c:173
int m0_fop_type_addb2_instrument(struct m0_fop_type *type)
Definition: fop.c:461
M0_INTERNAL void m0_crv_init(struct m0_crv *crv, const struct m0_dtm0_ts *ts, bool tbs)
Definition: cas.c:251
#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:48
M0_INTERNAL const struct m0_fid m0_cas_ctidx_fid
Definition: cas.c:151
#define M0_CRV_INIT_NONE
Definition: cas.h:511
Definition: cas.h:107
M0_INTERNAL struct m0_fop_type cas_rep_fopt
Definition: cas.c:51