Motr  M0
fid.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_FID_FID_H__
26 #define __MOTR_FID_FID_H__
27 
34 /* import */
35 #include "lib/types.h"
36 #include "xcode/xcode_attr.h"
37 
38 struct m0_fid {
39  uint64_t f_container;
40  uint64_t f_key;
41 } M0_XCA_RECORD M0_XCA_DOMAIN(conf|rpc);
42 
43 struct m0_fid_arr {
44  uint32_t af_count;
45  struct m0_fid *af_elems;
46 } M0_XCA_SEQUENCE M0_XCA_DOMAIN(conf|rpc);
47 
48 M0_INTERNAL bool m0_fid_is_set(const struct m0_fid *fid);
49 M0_INTERNAL bool m0_fid_is_valid(const struct m0_fid *fid);
50 M0_INTERNAL bool m0_fid_eq(const struct m0_fid *fid0,
51  const struct m0_fid *fid1);
52 M0_INTERNAL int m0_fid_cmp(const struct m0_fid *fid0,
53  const struct m0_fid *fid1);
54 M0_INTERNAL void m0_fid_set(struct m0_fid *fid,
55  uint64_t container, uint64_t key);
56 M0_INTERNAL void m0_fid_tset(struct m0_fid *fid,
57  uint8_t tid, uint64_t container, uint64_t key);
58 /* Get fid type id. */
59 M0_INTERNAL uint8_t m0_fid_tget(const struct m0_fid *fid);
60 /* Change fid type id. */
61 M0_INTERNAL void m0_fid_tchange(struct m0_fid *fid, uint8_t tid);
62 
63 M0_INTERNAL int m0_fid_sscanf(const char *s, struct m0_fid *fid);
64 M0_INTERNAL int m0_fid_print(char *s, size_t s_len, const struct m0_fid *fid);
65 
66 M0_INTERNAL int m0_fid_init(void);
67 M0_INTERNAL void m0_fid_fini(void);
68 
69 enum {
71  M0_FID_TYPE_MASK = 0x00ffffffffffffffULL,
73 };
74 
75 #define FID_F "<%" PRIx64 ":%" PRIx64 ">"
76 #define FID_SF " < %" SCNx64 " : %" SCNx64 " > "
77 #define FID_P(f) (f)->f_container, (f)->f_key
78 #define FID_S(f) &(f)->f_container, &(f)->f_key
79 
80 #define M0_FID_TCONTAINER(type, container) \
81  ((((uint64_t)(type)) << (64 - 8)) | \
82  (((uint64_t)(container)) & M0_FID_TYPE_MASK))
83 
84 #define M0_FID_INIT(container, key) \
85  ((struct m0_fid) { \
86  .f_container = (container), \
87  .f_key = (key) \
88  })
89 
90 #define M0_FID_TINIT(type, container, key) \
91  M0_FID_INIT(M0_FID_TCONTAINER((type), (container)), (key))
92 
93 #define M0_FID0 M0_FID_INIT(0ULL, 0ULL)
94 
95 #define M0_FID_BUF(fid) ((struct m0_buf){ \
96  .b_nob = sizeof *(fid), \
97  .b_addr = (fid) \
98 })
99 
100 struct m0_fid_type {
101  uint8_t ft_id;
102  const char *ft_name;
103  bool (*ft_is_valid)(const struct m0_fid *fid);
104 };
105 
106 M0_INTERNAL void m0_fid_type_register(const struct m0_fid_type *fidt);
107 M0_INTERNAL void m0_fid_type_unregister(const struct m0_fid_type *fidt);
108 M0_INTERNAL const struct m0_fid_type *m0_fid_type_get(uint8_t id);
109 M0_INTERNAL const struct m0_fid_type *m0_fid_type_gethi(uint64_t id);
110 M0_INTERNAL const struct m0_fid_type *
111 m0_fid_type_getfid(const struct m0_fid *fid);
112 M0_INTERNAL const struct m0_fid_type *m0_fid_type_getname(const char *name);
113 M0_INTERNAL void m0_fid_tassume(struct m0_fid *fid,
114  const struct m0_fid_type *ft);
115 M0_INTERNAL void m0_fid_tgenerate(struct m0_fid *fid,
116  const uint8_t tid);
117 
118 M0_INTERNAL uint64_t m0_fid_hash(const struct m0_fid *fid);
119 
120 M0_INTERNAL int m0_fid_arr_copy(struct m0_fid_arr *to,
121  const struct m0_fid_arr *from);
122 M0_INTERNAL bool m0_fid_arr_eq(const struct m0_fid_arr *a,
123  const struct m0_fid_arr *b);
124 M0_INTERNAL bool m0_fid_arr_all_unique(const struct m0_fid_arr *a);
125 
127 #endif /* __MOTR_FID_FID_H__ */
128 
129 /*
130  * Local variables:
131  * c-indentation-style: "K&R"
132  * c-basic-offset: 8
133  * tab-width: 8
134  * fill-column: 80
135  * scroll-step: 1
136  * End:
137  */
enum @178 M0_XCA_DOMAIN
M0_INTERNAL uint64_t m0_fid_hash(const struct m0_fid *fid)
Definition: fid.c:295
M0_INTERNAL void m0_fid_tset(struct m0_fid *fid, uint8_t tid, uint64_t container, uint64_t key)
Definition: fid.c:126
uint32_t s_len
Definition: string.h:99
struct m0_container container
uint8_t ft_id
Definition: fid.h:101
struct m0_fid * af_elems
Definition: fid.h:45
M0_INTERNAL uint8_t m0_fid_tget(const struct m0_fid *fid)
Definition: fid.c:133
M0_INTERNAL const struct m0_fid_type * m0_fid_type_get(uint8_t id)
Definition: fid.c:64
Definition: conf.py:1
M0_INTERNAL void m0_fid_fini(void)
Definition: fid.c:289
M0_INTERNAL int m0_fid_cmp(const struct m0_fid *fid0, const struct m0_fid *fid1)
Definition: fid.c:170
M0_INTERNAL bool m0_fid_is_set(const struct m0_fid *fid)
Definition: fid.c:106
struct m0_fid fid
Definition: di.c:46
M0_INTERNAL void m0_fid_set(struct m0_fid *fid, uint64_t container, uint64_t key)
Definition: fid.c:116
M0_INTERNAL void m0_fid_type_register(const struct m0_fid_type *fidt)
Definition: fid.c:46
const char * name
Definition: trace.c:110
M0_INTERNAL void m0_fid_tgenerate(struct m0_fid *fid, const uint8_t tid)
Definition: fid.c:155
M0_INTERNAL const struct m0_fid_type * m0_fid_type_gethi(uint64_t id)
Definition: fid.c:70
M0_INTERNAL const struct m0_fid_type * m0_fid_type_getfid(const struct m0_fid *fid)
Definition: fid.c:76
Definition: fid.h:43
uint64_t f_container
Definition: fid.h:39
M0_INTERNAL int m0_fid_print(char *s, size_t s_len, const struct m0_fid *fid)
Definition: fid.c:233
M0_INTERNAL void m0_fid_type_unregister(const struct m0_fid_type *fidt)
Definition: fid.c:55
bool(* ft_is_valid)(const struct m0_fid *fid)
Definition: fid.h:103
M0_INTERNAL bool m0_fid_arr_eq(const struct m0_fid_arr *a, const struct m0_fid_arr *b)
Definition: fid.c:319
M0_INTERNAL int m0_fid_sscanf(const char *s, struct m0_fid *fid)
Definition: fid.c:227
M0_INTERNAL const struct m0_fid_type * m0_fid_type_getname(const char *name)
Definition: fid.c:81
M0_INTERNAL bool m0_fid_eq(const struct m0_fid *fid0, const struct m0_fid *fid1)
Definition: fid.c:164
const char * ft_name
Definition: fid.h:102
M0_INTERNAL void m0_fid_tchange(struct m0_fid *fid, uint8_t tid)
Definition: fid.c:139
Definition: fid.h:38
uint64_t f_key
Definition: fid.h:40
M0_INTERNAL int m0_fid_arr_copy(struct m0_fid_arr *to, const struct m0_fid_arr *from)
Definition: fid.c:303
static struct m0_fop_type * ft[]
Definition: service_ut.c:856
M0_INTERNAL bool m0_fid_is_valid(const struct m0_fid *fid)
Definition: fid.c:96
static struct m0_addb2_source * s
Definition: consumer.c:39
M0_INTERNAL bool m0_fid_arr_all_unique(const struct m0_fid_arr *a)
Definition: fid.c:327
uint32_t af_count
Definition: fid.h:44
Definition: idx_mock.c:47
M0_INTERNAL void m0_fid_tassume(struct m0_fid *fid, const struct m0_fid_type *ft)
Definition: fid.c:146
M0_INTERNAL int m0_fid_init(void)
Definition: fid.c:281