Motr  M0
stob.h
Go to the documentation of this file.
1 /* -*- C -*- */
2 /*
3  * Copyright (c) 2012-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_STOB_STOB_H__
26 #define __MOTR_STOB_STOB_H__
27 
28 #include "lib/atomic.h"
29 #include "lib/types.h" /* m0_uint128 */
30 #include "lib/vec.h"
31 #include "lib/chan.h"
32 #include "lib/rwlock.h"
33 #include "lib/tlist.h"
34 #include "fid/fid.h"
35 #include "sm/sm.h"
36 #include "stob/cache.h" /* m0_stob_cache */
37 #include "fid/fid_xc.h"
38 #include "be/extmap.h" /* m0_be_emap_seg */
39 
40 #ifndef MAXPATHLEN
41 #define MAXPATHLEN 1024
42 #endif
43 
44 /* import */
45 struct m0_dtx;
46 struct m0_chan;
47 struct m0_indexvec;
48 struct m0_io_scope;
49 
50 struct m0_be_tx_credit;
51 struct m0_be_seg;
52 struct m0_dtx;
53 
70 struct m0_stob_type_ops;
71 struct m0_stob_domain_ops;
72 struct m0_stob_domain;
73 struct m0_stob_ops;
74 struct m0_stob;
75 struct m0_stob_io;
76 
94 };
95 
101 struct m0_stob_id {
102  /* Stob domain fid. @see m0_stob_domain, m0_stob */
104  /* Stob fid. @see m0_stob */
105  struct m0_fid si_fid;
106 } M0_XCA_RECORD M0_XCA_DOMAIN(be|rpc);
107 
108 #define STOB_ID_F "{" FID_F "," FID_F "}"
109 #define STOB_ID_P(si) FID_P(&(si)->si_domain_fid), FID_P(&(si)->si_fid)
110 
163 struct m0_stob {
164  const struct m0_stob_ops *so_ops;
168  uint64_t so_ref;
171  /* so_ref_chan protection. */
174  uint64_t so_cache_magic;
175  void *so_private;
176 };
177 
179 struct m0_stob_ops {
187  void (*sop_fini)(struct m0_stob *stob);
189  void (*sop_destroy_credit)(struct m0_stob *stob,
190  struct m0_be_tx_credit *accum);
192  int (*sop_destroy)(struct m0_stob *stob, struct m0_dtx *dtx);
195  struct m0_indexvec *want,
196  struct m0_indexvec *got,
197  struct m0_be_tx_credit *accum);
199  int (*sop_punch)(struct m0_stob *stob, struct m0_indexvec *range,
200  struct m0_dtx *dtx);
202  int (*sop_io_init)(struct m0_stob *stob, struct m0_stob_io *io);
204  uint32_t (*sop_block_shift)(struct m0_stob *stob);
206  int (*sop_fd)(struct m0_stob *stob);
207 };
208 
222 M0_INTERNAL int m0_stob_find(const struct m0_stob_id *id, struct m0_stob **out);
223 M0_INTERNAL int m0_stob_find_by_key(struct m0_stob_domain *dom,
224  const struct m0_fid *stob_fid,
225  struct m0_stob **out);
226 
228 M0_INTERNAL int m0_stob_lookup(const struct m0_stob_id *id,
229  struct m0_stob **out);
230 M0_INTERNAL int m0_stob_lookup_by_key(struct m0_stob_domain *dom,
231  const struct m0_fid *stob_fid,
232  struct m0_stob **out);
233 
241 M0_INTERNAL int m0_stob_locate(struct m0_stob *stob);
242 
244 M0_INTERNAL void m0_stob_create_credit(struct m0_stob_domain *dom,
245  struct m0_be_tx_credit *accum);
255 M0_INTERNAL int m0_stob_create(struct m0_stob *stob,
256  struct m0_dtx *dtx,
257  const char *str_cfg);
258 
260 M0_INTERNAL void m0_stob_destroy_credit(struct m0_stob *stob,
261  struct m0_be_tx_credit *accum);
262 
277 M0_INTERNAL void m0_stob_delete_mark(struct m0_stob *stob);
278 
279 /*
280  * Destroys stob.
281  *
282  * @pre stob->so_state != CSS_UNKNOWN
283  * @pre stob->so_ref == 1
284  */
285 M0_INTERNAL int m0_stob_destroy(struct m0_stob *stob, struct m0_dtx *dtx);
286 
293 M0_INTERNAL int m0_stob_punch_credit(struct m0_stob *stob,
294  struct m0_indexvec *want,
295  struct m0_indexvec *got,
296  struct m0_be_tx_credit *accum);
297 
299 M0_INTERNAL int m0_stob_punch(struct m0_stob *stob,
300  struct m0_indexvec *range,
301  struct m0_dtx *dtx);
302 
307 M0_INTERNAL uint32_t m0_stob_block_shift(struct m0_stob *stob);
308 
314 M0_INTERNAL void m0_stob_get(struct m0_stob *stob);
315 
323 M0_INTERNAL void m0_stob_put(struct m0_stob *stob);
324 
326 M0_INTERNAL struct m0_stob_domain *m0_stob_dom_get(struct m0_stob *stob);
327 
332 M0_INTERNAL enum m0_stob_state m0_stob_state_get(struct m0_stob *stob);
333 
335 M0_INTERNAL uint64_t m0_stob_dom_id_get(struct m0_stob *stob);
337 M0_INTERNAL const struct m0_stob_id *m0_stob_id_get(struct m0_stob *stob);
339 M0_INTERNAL const struct m0_fid *m0_stob_fid_get(struct m0_stob *stob);
341 M0_INTERNAL uint64_t m0_stob_id_dom_id_get(const struct m0_stob_id *stob_id);
343 M0_INTERNAL void m0_stob_id_make(uint64_t container,
344  uint64_t key,
345  const struct m0_fid *dom_id,
346  struct m0_stob_id *stob_id);
347 
348 M0_INTERNAL bool m0_stob_id_eq(const struct m0_stob_id *stob_id0,
349  const struct m0_stob_id *stob_id1);
350 
355 M0_INTERNAL int m0_stob_fd(struct m0_stob *stob);
356 
357 M0_INTERNAL int m0_stob_mod_init(void);
358 M0_INTERNAL void m0_stob_mod_fini(void);
359 
361 #endif /* __MOTR_STOB_STOB_H__ */
362 
363 /*
364  * Local variables:
365  * c-indentation-style: "K&R"
366  * c-basic-offset: 8
367  * tab-width: 8
368  * fill-column: 80
369  * scroll-step: 1
370  * End:
371  */
M0_INTERNAL struct m0_stob_domain * m0_stob_dom_get(struct m0_stob *stob)
Definition: stob.c:338
Definition: dtm.h:554
int(* sop_punch)(struct m0_stob *stob, struct m0_indexvec *range, struct m0_dtx *dtx)
Definition: stob.h:199
void(* sop_destroy_credit)(struct m0_stob *stob, struct m0_be_tx_credit *accum)
Definition: stob.h:189
M0_INTERNAL int m0_stob_locate(struct m0_stob *stob)
Definition: stob.c:128
struct m0_fid si_domain_fid
Definition: stob.h:103
const struct m0_stob_ops * so_ops
Definition: stob.h:164
M0_INTERNAL int m0_stob_mod_init(void)
Definition: stob.c:367
M0_INTERNAL int m0_stob_find_by_key(struct m0_stob_domain *dom, const struct m0_fid *stob_fid, struct m0_stob **out)
Definition: stob.c:65
struct m0_container container
int(* sop_io_init)(struct m0_stob *stob, struct m0_stob_io *io)
Definition: stob.h:202
int(* sop_destroy)(struct m0_stob *stob, struct m0_dtx *dtx)
Definition: stob.h:192
M0_INTERNAL const struct m0_fid * m0_stob_fid_get(struct m0_stob *stob)
Definition: stob.c:255
void * so_private
Definition: stob.h:175
struct m0_mutex so_ref_mutex
Definition: stob.h:172
struct m0_stob_domain * so_domain
Definition: stob.h:165
M0_INTERNAL uint32_t m0_stob_block_shift(struct m0_stob *stob)
Definition: stob.c:270
M0_INTERNAL int m0_stob_lookup(const struct m0_stob_id *id, struct m0_stob **out)
Definition: stob.c:119
uint32_t(* sop_block_shift)(struct m0_stob *stob)
Definition: stob.h:204
M0_INTERNAL const struct m0_stob_id * m0_stob_id_get(struct m0_stob *stob)
Definition: stob.c:250
Definition: stob.h:163
enum m0_stob_state so_state
Definition: stob.h:167
static struct m0_stob * stob
Definition: storage.c:39
M0_INTERNAL void m0_stob_mod_fini(void)
Definition: stob.c:373
M0_INTERNAL void m0_stob_destroy_credit(struct m0_stob *stob, struct m0_be_tx_credit *accum)
Definition: stob.c:187
M0_INTERNAL uint64_t m0_stob_dom_id_get(struct m0_stob *stob)
Definition: stob.c:245
int(* sop_punch_credit)(struct m0_stob *stob, struct m0_indexvec *want, struct m0_indexvec *got, struct m0_be_tx_credit *accum)
Definition: stob.h:194
static struct m0_stob_domain * dom
Definition: storage.c:38
M0_INTERNAL void m0_stob_id_make(uint64_t container, uint64_t key, const struct m0_fid *dom_id, struct m0_stob_id *stob_id)
Definition: stob.c:343
M0_INTERNAL int m0_stob_lookup_by_key(struct m0_stob_domain *dom, const struct m0_fid *stob_fid, struct m0_stob **out)
Definition: stob.c:102
struct m0_fid si_fid
Definition: stob.h:105
struct m0_chan so_ref_chan
Definition: stob.h:170
Definition: chan.h:229
Definition: io.h:285
uint64_t so_ref
Definition: stob.h:168
Definition: seg.h:66
static struct m0_stob_io io
Definition: ad.c:59
struct m0_stob M0_XCA_DOMAIN
M0_INTERNAL int m0_stob_create(struct m0_stob *stob, struct m0_dtx *dtx, const char *str_cfg)
Definition: stob.c:154
M0_INTERNAL int m0_stob_punch_credit(struct m0_stob *stob, struct m0_indexvec *want, struct m0_indexvec *got, struct m0_be_tx_credit *accum)
Definition: stob.c:223
M0_INTERNAL int m0_stob_destroy(struct m0_stob *stob, struct m0_dtx *dtx)
Definition: stob.c:200
M0_INTERNAL enum m0_stob_state m0_stob_state_get(struct m0_stob *stob)
Definition: stob.c:265
void(* sop_fini)(struct m0_stob *stob)
Definition: stob.h:187
Definition: stob.h:91
uint64_t so_cache_magic
Definition: stob.h:174
Definition: fid.h:38
M0_INTERNAL int m0_stob_fd(struct m0_stob *stob)
Definition: stob.c:360
m0_stob_state
Definition: stob.h:81
M0_INTERNAL uint64_t m0_stob_id_dom_id_get(const struct m0_stob_id *stob_id)
Definition: stob.c:260
M0_INTERNAL bool m0_stob_id_eq(const struct m0_stob_id *stob_id0, const struct m0_stob_id *stob_id1)
Definition: stob.c:352
M0_INTERNAL int m0_stob_find(const struct m0_stob_id *id, struct m0_stob **out)
Definition: stob.c:92
int(* sop_fd)(struct m0_stob *stob)
Definition: stob.h:206
M0_INTERNAL void m0_stob_delete_mark(struct m0_stob *stob)
Definition: stob.c:193
#define out(...)
Definition: gen.c:41
M0_INTERNAL int m0_stob_punch(struct m0_stob *stob, struct m0_indexvec *range, struct m0_dtx *dtx)
Definition: stob.c:232
M0_INTERNAL void m0_stob_create_credit(struct m0_stob_domain *dom, struct m0_be_tx_credit *accum)
Definition: stob.c:148
Definition: mutex.h:47
struct m0_tlink so_cache_linkage
Definition: stob.h:173
M0_INTERNAL void m0_stob_get(struct m0_stob *stob)
Definition: stob.c:275
struct m0_stob_id so_id
Definition: stob.h:166
M0_INTERNAL void m0_stob_put(struct m0_stob *stob)
Definition: stob.c:291
static struct m0_be_ut_backend be
Definition: service_ut.c:59
Definition: idx_mock.c:47