Motr  M0
root.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013-2020 Seagate Technology LLC and/or its Affiliates
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  * For any questions about this software or licensing,
17  * please email opensource@seagate.com or cortx-questions@seagate.com.
18  *
19  */
20 
21 
22 #define M0_TRACE_SUBSYSTEM M0_TRACE_SUBSYS_CONF
23 #include "lib/trace.h"
24 
25 #include "lib/string.h" /* m0_strings_free */
26 #include "conf/objs/common.h"
27 #include "conf/onwire_xc.h" /* m0_confx_root_xc */
28 #include "motr/magic.h" /* M0_CONF_ROOT_MAGIC */
29 
30 #define XCAST(xobj) ((struct m0_confx_root *)(&(xobj)->xo_u))
32 
33 static bool root_check(const void *bob)
34 {
35  const struct m0_conf_root *self = bob;
36  const struct m0_conf_obj *self_obj = &self->rt_obj;
37 
39 
40  return _0C(m0_fid_eq(&self->rt_obj.co_id, &M0_CONF_ROOT_FID)) &&
41  _0C(self_obj->co_parent == NULL) &&
42  _0C(m0_conf_obj_is_stub(self_obj) || self->rt_verno > 0);
43 }
44 
47 
48 static int
49 root_decode(struct m0_conf_obj *dest, const struct m0_confx_obj *src)
50 {
51  int rc;
52  const struct m0_confx_root *s = XCAST(src);
54 
55  if (s->xt_verno == 0
56  || !m0_conf_fid_is_valid(&s->xt_mdpool)
57  || m0_conf_fid_type(&s->xt_mdpool) != &M0_CONF_POOL_TYPE
58  || (m0_fid_is_set(&s->xt_imeta_pver)
59  && (!m0_conf_fid_is_valid(&s->xt_imeta_pver) ||
60  m0_conf_fid_type(&s->xt_imeta_pver) != &M0_CONF_PVER_TYPE)))
61  return M0_ERR(-EINVAL);
62 
63  d->rt_verno = s->xt_verno;
64  d->rt_rootfid = s->xt_rootfid;
65  d->rt_mdpool = s->xt_mdpool;
66  d->rt_imeta_pver = s->xt_imeta_pver;
67  d->rt_mdredundancy = s->xt_mdredundancy;
68 
69  rc = m0_bufs_to_strings(&d->rt_params, &s->xt_params);
70  if (rc != 0)
71  return M0_ERR(rc);
72 
73  rc = rc ?:
75  &CONF_DIR_ENTRIES(&M0_CONF_ROOT_NODES_FID,
77  &s->xt_nodes), dest) ?:
79  &CONF_DIR_ENTRIES(&M0_CONF_ROOT_SITES_FID,
81  &s->xt_sites), dest) ?:
83  &CONF_DIR_ENTRIES(&M0_CONF_ROOT_POOLS_FID,
85  &s->xt_pools), dest) ?:
87  &CONF_DIR_ENTRIES(&M0_CONF_ROOT_PROFILES_FID,
89  &s->xt_profiles), dest) ?:
91  &CONF_DIR_ENTRIES(&M0_CONF_ROOT_FDMI_FLT_GRPS_FID,
93  &s->xt_fdmi_flt_grps), dest);
94  if (rc != 0) {
96  d->rt_params = NULL; /* make invariant happy */
97  }
98 
99  return M0_RC(rc);
100 }
101 
102 static int root_encode(struct m0_confx_obj *dest, const struct m0_conf_obj *src)
103 {
104  int rc;
105  const struct m0_conf_root *s = M0_CONF_CAST(src, m0_conf_root);
106  struct m0_confx_root *d = XCAST(dest);
107  const struct conf_dir_encoding_pair dirs[] = {
108  { s->rt_nodes, &d->xt_nodes },
109  { s->rt_sites, &d->xt_sites },
110  { s->rt_pools, &d->xt_pools },
111  { s->rt_profiles, &d->xt_profiles },
112  { s->rt_fdmi_flt_grps, &d->xt_fdmi_flt_grps }
113  };
114 
116 
117  d->xt_verno = s->rt_verno;
118  d->xt_rootfid = s->rt_rootfid;
119  d->xt_mdpool = s->rt_mdpool;
120  d->xt_imeta_pver = s->rt_imeta_pver;
121  d->xt_mdredundancy = s->rt_mdredundancy;
122 
123  rc = m0_bufs_from_strings(&d->xt_params, s->rt_params);
124  if (rc != 0)
125  return M0_ERR(rc);
126 
127  rc = conf_dirs_encode(dirs, ARRAY_SIZE(dirs));
128  if (rc != 0)
129  m0_bufs_free(&d->xt_params);
130 
131  if (rc == 0 && s->rt_fdmi_flt_grps != NULL)
136  rc = arrfid_from_dir(&d->xt_fdmi_flt_grps, s->rt_fdmi_flt_grps);
137  return M0_RC(rc);
138 }
139 
140 static bool
141 root_match(const struct m0_conf_obj *cached, const struct m0_confx_obj *flat)
142 {
143  const struct m0_confx_root *xobj = XCAST(flat);
144  const struct m0_conf_root *obj = M0_CONF_CAST(cached, m0_conf_root);
145 
146  return obj->rt_verno == xobj->xt_verno &&
147  m0_fid_eq(&obj->rt_rootfid, &xobj->xt_rootfid) &&
148  m0_fid_eq(&obj->rt_mdpool, &xobj->xt_mdpool) &&
149  m0_fid_eq(&obj->rt_imeta_pver, &xobj->xt_imeta_pver) &&
150  obj->rt_mdredundancy == xobj->xt_mdredundancy &&
151  m0_bufs_streq(&xobj->xt_params, obj->rt_params) &&
152  m0_conf_dir_elems_match(obj->rt_nodes, &xobj->xt_nodes) &&
153  m0_conf_dir_elems_match(obj->rt_sites, &xobj->xt_sites) &&
154  m0_conf_dir_elems_match(obj->rt_pools, &xobj->xt_pools) &&
155  m0_conf_dir_elems_match(obj->rt_profiles, &xobj->xt_profiles) &&
156  m0_conf_dir_elems_match(obj->rt_fdmi_flt_grps,
157  &xobj->xt_fdmi_flt_grps);
158 }
159 
160 static int root_lookup(const struct m0_conf_obj *parent,
161  const struct m0_fid *name,
162  struct m0_conf_obj **out)
163 {
164  struct m0_conf_root *root = M0_CONF_CAST(parent, m0_conf_root);
165  const struct conf_dir_relation dirs[] = {
166  { root->rt_nodes, &M0_CONF_ROOT_NODES_FID },
167  { root->rt_sites, &M0_CONF_ROOT_SITES_FID },
168  { root->rt_pools, &M0_CONF_ROOT_POOLS_FID },
169  { root->rt_profiles, &M0_CONF_ROOT_PROFILES_FID },
170  { root->rt_fdmi_flt_grps, &M0_CONF_ROOT_FDMI_FLT_GRPS_FID }
171  };
172 
173  M0_PRE(parent->co_status == M0_CS_READY);
174  return M0_RC(conf_dirs_lookup(out, name, dirs, ARRAY_SIZE(dirs)));
175 }
176 
177 static const struct m0_fid **root_downlinks(const struct m0_conf_obj *obj)
178 {
179  static const struct m0_fid *rels[] = {
180  &M0_CONF_ROOT_NODES_FID,
181  &M0_CONF_ROOT_SITES_FID,
182  &M0_CONF_ROOT_POOLS_FID,
183  &M0_CONF_ROOT_PROFILES_FID,
184  &M0_CONF_ROOT_FDMI_FLT_GRPS_FID,
185  NULL
186  };
187 
189  return rels;
190 }
191 
192 static void root_delete(struct m0_conf_obj *obj)
193 {
195 
197  m0_conf_root_bob_fini(root);
198  m0_free(root);
199 }
200 
201 static const struct m0_conf_obj_ops root_ops = {
202  .coo_invariant = root_invariant,
203  .coo_decode = root_decode,
204  .coo_encode = root_encode,
205  .coo_match = root_match,
206  .coo_lookup = root_lookup,
207  .coo_readdir = NULL,
208  .coo_downlinks = root_downlinks,
209  .coo_delete = root_delete
210 };
211 
213 
215  .cot_ftype = {
216  .ft_id = M0_CONF__ROOT_FT_ID,
217  .ft_name = "conf_root"
218  },
219  .cot_create = &root_create,
220  .cot_xt = &m0_confx_root_xc,
221  .cot_branch = "u_root",
222  .cot_xc_init = &m0_xc_m0_confx_root_struct_init,
223  .cot_magic = M0_CONF_ROOT_MAGIC
224 };
225 
226 const struct m0_fid M0_CONF_ROOT_FID = M0_FID_TINIT(M0_CONF__ROOT_FT_ID, 1, 0);
227 
228 #undef XCAST
229 #undef M0_TRACE_SUBSYSTEM
230 
231 /*
232  * Local variables:
233  * c-indentation-style: "K&R"
234  * c-basic-offset: 8
235  * tab-width: 8
236  * fill-column: 80
237  * scroll-step: 1
238  * End:
239  */
240 /*
241  * vim: tabstop=8 shiftwidth=8 noexpandtab textwidth=80 nowrap
242  */
const struct m0_conf_obj_type * m0_conf_obj_type(const struct m0_conf_obj *obj)
Definition: obj.c:363
M0_INTERNAL int conf_dirs_encode(const struct conf_dir_encoding_pair *how, size_t how_nr)
Definition: common.c:43
struct m0_fid rt_rootfid
Definition: obj.h:392
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
#define M0_PRE(cond)
struct m0_fid xt_rootfid
Definition: onwire.h:63
#define NULL
Definition: misc.h:38
#define XCAST(xobj)
Definition: root.c:30
const struct m0_conf_obj_type M0_CONF_PROFILE_TYPE
Definition: profile.c:97
M0_CONF__BOB_DEFINE(m0_conf_root, M0_CONF_ROOT_MAGIC, root_check)
struct m0_fid_arr xt_sites
Definition: onwire.h:69
#define CONF_DIR_ENTRIES(relfid, entry_type, entries)
Definition: common.h:88
const struct m0_conf_obj_type M0_CONF_SITE_TYPE
Definition: site.c:121
const struct m0_conf_obj_type * m0_conf_fid_type(const struct m0_fid *fid)
Definition: obj.c:368
const struct m0_conf_obj_type M0_CONF_PVER_TYPE
Definition: pver.c:260
uint8_t ft_id
Definition: fid.h:101
bool(* coo_invariant)(const struct m0_conf_obj *obj)
Definition: obj_ops.h:79
static void root_delete(struct m0_conf_obj *obj)
Definition: root.c:192
const struct m0_conf_obj_type M0_CONF_ROOT_TYPE
Definition: root.c:214
const struct m0_conf_obj_type M0_CONF_POOL_TYPE
Definition: pool.c:249
struct m0_conf_obj * co_parent
Definition: obj.h:223
M0_INTERNAL bool m0_fid_is_set(const struct m0_fid *fid)
Definition: fid.c:106
M0_INTERNAL bool m0_conf_obj_is_stub(const struct m0_conf_obj *obj)
Definition: obj.c:302
static const struct m0_fid ** root_downlinks(const struct m0_conf_obj *obj)
Definition: root.c:177
static struct foo * obj
Definition: tlist.c:302
return M0_RC(rc)
struct m0_confx_header xt_header
Definition: onwire.h:120
struct m0_bufs xt_params
Definition: onwire.h:67
static int root_encode(struct m0_confx_obj *dest, const struct m0_conf_obj *src)
Definition: root.c:102
struct m0_conf_root * root
Definition: note.c:50
struct m0_conf_dir * rt_fdmi_flt_grps
Definition: obj.h:382
return M0_ERR(-EOPNOTSUPP)
const char * name
Definition: trace.c:110
#define M0_FID_TINIT(type, container, key)
Definition: fid.h:90
static int root_lookup(const struct m0_conf_obj *parent, const struct m0_fid *name, struct m0_conf_obj **out)
Definition: root.c:160
struct m0_fid xt_mdpool
Definition: onwire.h:64
struct m0_fid rt_imeta_pver
Definition: obj.h:403
const struct m0_fid_type cot_ftype
Definition: obj.h:314
M0_INTERNAL bool m0_bufs_streq(const struct m0_bufs *bufs, const char **strs)
Definition: buf.c:217
struct m0_conf_dir * rt_nodes
Definition: obj.h:373
M0_INTERNAL void m0_bufs_free(struct m0_bufs *bufs)
Definition: buf.c:229
static int root_decode(struct m0_conf_obj *dest, const struct m0_confx_obj *src)
Definition: root.c:49
M0_CONF__INVARIANT_DEFINE(root_invariant, m0_conf_root)
M0_INTERNAL void confx_encode(struct m0_confx_obj *dest, const struct m0_conf_obj *src)
Definition: common.c:110
static const struct m0_conf_obj_ops root_ops
Definition: root.c:201
struct m0_conf_dir * rt_sites
Definition: obj.h:374
const char ** rt_params
Definition: obj.h:411
static bool root_check(const void *bob)
Definition: root.c:33
uint32_t rt_mdredundancy
Definition: obj.h:405
struct m0_fid_arr xt_profiles
Definition: onwire.h:71
struct m0_fid rt_mdpool
Definition: obj.h:394
uint64_t rt_verno
Definition: obj.h:390
#define M0_CONF_CAST(ptr, type)
Definition: obj.h:780
M0_INTERNAL int arrfid_from_dir(struct m0_fid_arr *dest, const struct m0_conf_dir *dir)
Definition: common.c:82
M0_BASSERT(offsetof(struct m0_confx_root, xt_header)==0)
struct m0_conf_dir * rt_profiles
Definition: obj.h:376
struct m0_conf_dir * rt_pools
Definition: obj.h:375
uint32_t xt_mdredundancy
Definition: onwire.h:66
bool m0_conf_fid_is_valid(const struct m0_fid *fid)
Definition: obj.c:378
M0_INTERNAL bool m0_fid_eq(const struct m0_fid *fid0, const struct m0_fid *fid1)
Definition: fid.c:164
M0_INTERNAL void m0_strings_free(const char **arr)
Definition: string.c:45
Definition: fid.h:38
const struct m0_conf_obj_type M0_CONF_NODE_TYPE
Definition: node.c:128
static bool root_match(const struct m0_conf_obj *cached, const struct m0_confx_obj *flat)
Definition: root.c:141
const struct m0_fid M0_CONF_ROOT_FID
Definition: root.c:226
struct m0_fid_arr xt_pools
Definition: onwire.h:70
struct m0_fid xt_imeta_pver
Definition: onwire.h:65
M0_INTERNAL int m0_bufs_to_strings(const char ***dest, const struct m0_bufs *src)
Definition: buf.c:188
struct m0_fid_arr xt_nodes
Definition: onwire.h:68
#define _0C(exp)
Definition: assert.h:311
enum m0_conf_status co_status
Definition: obj.h:210
const struct m0_conf_obj_type M0_CONF_FDMI_FLT_GRP_TYPE
Definition: fdmi_flt_grp.c:151
M0_CONF_REL_FIDS 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
#define out(...)
Definition: gen.c:41
uint64_t xt_verno
Definition: onwire.h:62
void m0_free(void *data)
Definition: memory.c:146
static struct m0_addb2_source * s
Definition: consumer.c:39
M0_INTERNAL bool m0_conf_dir_elems_match(const struct m0_conf_dir *dir, const struct m0_fid_arr *fids)
Definition: dir.c:63
struct m0_pdclust_src_addr src
Definition: fd.c:108
struct m0_fid_arr xt_fdmi_flt_grps
Definition: onwire.h:72
int32_t rc
Definition: trigger_fop.h:47
M0_INTERNAL int m0_bufs_from_strings(struct m0_bufs *dest, const char **src)
Definition: buf.c:157
#define ARRAY_SIZE(a)
Definition: misc.h:45
#define offsetof(typ, memb)
Definition: misc.h:29
M0_CONF__CTOR_DEFINE(root_create, m0_conf_root, &root_ops)