Motr  M0
common.h
Go to the documentation of this file.
1 /* -*- C -*- */
2 /*
3  * Copyright (c) 2013-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 #pragma once
23 #ifndef __MOTR_CONF_OBJS_COMMON_H__
24 #define __MOTR_CONF_OBJS_COMMON_H__
25 
26 /* ================================================================
27  * DO NOT #include "conf/objs/common.h"!
28  * It should only be used by files in conf/objs/ directory.
29  * ================================================================ */
30 
31 #include "conf/obj.h" /* m0_conf_obj */
32 #include "conf/obj_ops.h" /* m0_conf_obj_ops */
33 #include "conf/onwire.h" /* m0_confx_obj */
34 #include "conf/dir.h" /* m0_conf_dir_elems_match */
35 #include "fid/fid.h"
36 #include "lib/memory.h" /* m0_free */
37 #include "lib/errno.h" /* ENOMEM, ENOENT */
38 #include "lib/misc.h" /* M0_IN */
39 
40 enum {
41 #define X_CONF(_, NAME, ft_id) \
42  M0_CONF__ ## NAME ## _FT_ID = ft_id,
43 
45 #undef X_CONF
46 };
47 
48 #define M0_CONF__BOB_DEFINE(type, magic, check) \
49 const struct m0_bob_type type ## _bob = { \
50  .bt_name = #type, \
51  .bt_magix_offset = M0_MAGIX_OFFSET(struct type, \
52  type ## _cast_field.co_con_magic), \
53  .bt_magix = magic, \
54  .bt_check = check \
55 }; \
56 M0_BOB_DEFINE(static, &type ## _bob, type)
57 
58 #define M0_CONF__INVARIANT_DEFINE(name, type) \
59 static bool name(const struct m0_conf_obj *obj) \
60 { \
61  return type ## _bob_check(container_of(obj, struct type, \
62  type ## _cast_field)); \
63 } \
64 struct __ ## type ## _semicolon_catcher
65 
66 #define M0_CONF__CTOR_DEFINE(name, type, ops) \
67 static struct m0_conf_obj *name(void) \
68 { \
69  struct type *x; \
70  struct m0_conf_obj *ret; \
71  \
72  M0_ALLOC_PTR(x); \
73  if (x == NULL) \
74  return NULL; \
75  \
76  type ## _bob_init(x); \
77  ret = &x->type ## _cast_field; \
78  ret->co_ops = ops; \
79  return ret; \
80 } \
81 struct __ ## type ## _semicolon_catcher
82 
84  const struct m0_fid *de_relfid;
86  const struct m0_fid_arr *de_entries;
87 };
88 #define CONF_DIR_ENTRIES(relfid, entry_type, entries) \
89  ((struct conf_dir_entries){ (relfid), (entry_type), (entries) })
90 
91 M0_INTERNAL int dir_create_and_populate(struct m0_conf_dir **result,
92  const struct conf_dir_entries *de,
93  struct m0_conf_obj *dir_parent);
94 
96  const struct m0_conf_dir *dep_src;
98 };
99 
100 M0_INTERNAL int conf_dirs_encode(const struct conf_dir_encoding_pair *how,
101  size_t how_nr);
102 
105  const struct m0_fid *dr_relfid;
106 };
107 
108 M0_INTERNAL int conf_dirs_lookup(struct m0_conf_obj **out,
109  const struct m0_fid *name,
110  const struct conf_dir_relation *rels,
111  size_t nr_rels);
112 
113 M0_INTERNAL bool arrays_eq(const char **cached, const struct m0_bufs *flat);
114 
115 M0_INTERNAL int arrfid_from_dir(struct m0_fid_arr *dest,
116  const struct m0_conf_dir *dir);
117 M0_INTERNAL void arrfid_free(struct m0_fid_arr *arr);
118 
119 M0_INTERNAL void confx_encode(struct m0_confx_obj *dest,
120  const struct m0_conf_obj *src);
121 
122 M0_INTERNAL int u32arr_decode(const struct arr_u32 *src, uint32_t **dest);
123 M0_INTERNAL int u32arr_encode(struct arr_u32 *dest, const uint32_t *src,
124  uint32_t src_nr);
125 M0_INTERNAL bool u32arr_cmp(const struct arr_u32 *a1, const uint32_t *a2,
126  uint32_t a2_nr);
127 M0_INTERNAL void u32arr_free(struct arr_u32 *arr);
128 
129 M0_INTERNAL int conf_pvers_decode(struct m0_conf_pver ***dest,
130  const struct m0_fid_arr *src,
131  struct m0_conf_cache *cache);
132 
133 M0_INTERNAL int conf_pvers_encode(struct m0_fid_arr *dest,
134  const struct m0_conf_pver **src);
135 
136 M0_INTERNAL int conf_obj_lookup_denied(const struct m0_conf_obj *parent,
137  const struct m0_fid *name,
138  struct m0_conf_obj **out);
139 
140 M0_INTERNAL const struct m0_fid **
142 
143 #endif /* __MOTR_CONF_OBJS_COMMON_H__ */
144 
145 /*
146  * Local variables:
147  * c-indentation-style: "K&R"
148  * c-basic-offset: 8
149  * tab-width: 8
150  * fill-column: 80
151  * scroll-step: 1
152  * End:
153  */
154 /*
155  * vim: tabstop=8 shiftwidth=8 noexpandtab textwidth=80 nowrap
156  */
Definition: beck.c:235
M0_INTERNAL int conf_dirs_encode(const struct conf_dir_encoding_pair *how, size_t how_nr)
Definition: common.c:43
const struct m0_fid_arr * de_entries
Definition: common.h:86
M0_INTERNAL void arrfid_free(struct m0_fid_arr *arr)
Definition: common.c:104
const struct m0_conf_obj_type * de_entry_type
Definition: common.h:85
Definition: onwire.h:44
struct m0_fid_arr * dep_dest
Definition: common.h:97
M0_INTERNAL int conf_pvers_encode(struct m0_fid_arr *dest, const struct m0_conf_pver **src)
Definition: common.c:194
M0_INTERNAL int dir_create_and_populate(struct m0_conf_dir **result, const struct conf_dir_entries *de, struct m0_conf_obj *dir_parent)
Definition: common.c:33
M0_INTERNAL bool arrays_eq(const char **cached, const struct m0_bufs *flat)
static struct foo * obj
Definition: tlist.c:302
const struct m0_fid * dr_relfid
Definition: common.h:105
M0_INTERNAL int conf_obj_lookup_denied(const struct m0_conf_obj *parent, const struct m0_fid *name, struct m0_conf_obj **out)
Definition: common.c:217
const char * name
Definition: trace.c:110
const struct m0_fid * de_relfid
Definition: common.h:84
M0_INTERNAL void confx_encode(struct m0_confx_obj *dest, const struct m0_conf_obj *src)
Definition: common.c:110
M0_INTERNAL int conf_dirs_lookup(struct m0_conf_obj **out, const struct m0_fid *name, const struct conf_dir_relation *rels, size_t nr_rels)
Definition: common.c:64
M0_INTERNAL int arrfid_from_dir(struct m0_fid_arr *dest, const struct m0_conf_dir *dir)
Definition: common.c:82
Definition: fid.h:43
M0_INTERNAL const struct m0_fid ** conf_obj_downlinks_none(const struct m0_conf_obj *obj)
Definition: common.c:226
struct m0_conf_dir * dr_dir
Definition: common.h:104
M0_INTERNAL int u32arr_decode(const struct arr_u32 *src, uint32_t **dest)
Definition: common.c:116
Definition: fid.h:38
M0_INTERNAL int u32arr_encode(struct arr_u32 *dest, const uint32_t *src, uint32_t src_nr)
Definition: common.c:129
M0_INTERNAL int conf_pvers_decode(struct m0_conf_pver ***dest, const struct m0_fid_arr *src, struct m0_conf_cache *cache)
Definition: common.c:161
Definition: buf.h:43
struct inode * dir
Definition: dir.c:1028
#define out(...)
Definition: gen.c:41
M0_INTERNAL bool u32arr_cmp(const struct arr_u32 *a1, const uint32_t *a2, uint32_t a2_nr)
Definition: common.c:145
M0_INTERNAL void u32arr_free(struct arr_u32 *arr)
Definition: common.c:151
struct m0_pdclust_src_addr src
Definition: fd.c:108
const struct m0_conf_dir * dep_src
Definition: common.h:96