Motr  M0
pool.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014-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 "conf/objs/common.h"
26 #include "conf/onwire_xc.h" /* m0_confx_pool_xc */
27 #include "motr/magic.h" /* M0_CONF_POOL_MAGIC */
28 #include "fid/fid.h"
29 
159 
160 #define XCAST(xobj) ((struct m0_confx_pool *)(&(xobj)->xo_u))
162 
163 static bool pool_check(const void *bob)
164 {
165  const struct m0_conf_pool *self = bob;
166 
167  M0_PRE(m0_conf_obj_type(&self->pl_obj) == &M0_CONF_POOL_TYPE);
168 
169  return true;
170 }
171 
173 M0_CONF__INVARIANT_DEFINE(pool_invariant, m0_conf_pool);
174 
175 static int pool_decode(struct m0_conf_obj *dest, const struct m0_confx_obj *src)
176 {
178  const struct m0_confx_pool *s = XCAST(src);
179 
180  M0_ENTRY("dest="FID_F, FID_P(&dest->co_id));
181  d->pl_pver_policy = s->xp_pver_policy;
182  return M0_RC(m0_conf_dir_new(dest, &M0_CONF_POOL_PVERS_FID,
183  &M0_CONF_PVER_TYPE, &s->xp_pvers,
184  &d->pl_pvers));
185 }
186 
187 static int
188 pool_encode(struct m0_confx_obj *dest, const struct m0_conf_obj *src)
189 {
191  struct m0_confx_pool *d = XCAST(dest);
192 
194  d->xp_pver_policy = s->pl_pver_policy;
195  return M0_RC(arrfid_from_dir(&d->xp_pvers, s->pl_pvers));
196 }
197 
198 static bool
199 pool_match(const struct m0_conf_obj *cached, const struct m0_confx_obj *flat)
200 {
201  const struct m0_confx_pool *xobj = XCAST(flat);
202  const struct m0_conf_pool *obj = M0_CONF_CAST(cached, m0_conf_pool);
203 
204  return obj->pl_pver_policy == xobj->xp_pver_policy &&
205  m0_conf_dir_elems_match(obj->pl_pvers, &xobj->xp_pvers);
206 }
207 
208 static int pool_lookup(const struct m0_conf_obj *parent,
209  const struct m0_fid *name, struct m0_conf_obj **out)
210 {
211  struct m0_conf_pool *pool = M0_CONF_CAST(parent, m0_conf_pool);
212  const struct conf_dir_relation dirs[] = {
213  { pool->pl_pvers, &M0_CONF_POOL_PVERS_FID }
214  };
215 
216  M0_PRE(parent->co_status == M0_CS_READY);
217  return M0_RC(conf_dirs_lookup(out, name, dirs, ARRAY_SIZE(dirs)));
218 }
219 
220 static const struct m0_fid **pool_downlinks(const struct m0_conf_obj *obj)
221 {
222  static const struct m0_fid *rels[] = { &M0_CONF_POOL_PVERS_FID,
223  NULL };
225  return rels;
226 }
227 
228 static void pool_delete(struct m0_conf_obj *obj)
229 {
231 
232  m0_conf_pool_bob_fini(x);
233  m0_free(x);
234 }
235 
236 static const struct m0_conf_obj_ops pool_ops = {
237  .coo_invariant = pool_invariant,
238  .coo_decode = pool_decode,
239  .coo_encode = pool_encode,
240  .coo_match = pool_match,
241  .coo_lookup = pool_lookup,
242  .coo_readdir = NULL,
243  .coo_downlinks = pool_downlinks,
244  .coo_delete = pool_delete
245 };
246 
248 
250  .cot_ftype = {
251  .ft_id = M0_CONF__POOL_FT_ID,
252  .ft_name = "conf_pool"
253  },
254  .cot_create = &pool_create,
255  .cot_xt = &m0_confx_pool_xc,
256  .cot_branch = "u_pool",
257  .cot_xc_init = &m0_xc_m0_confx_pool_struct_init,
258  .cot_magic = M0_CONF_POOL_MAGIC
259 };
260 
261 #undef XCAST
262 #undef M0_TRACE_SUBSYSTEM
263 
264 /*
265  * Local variables:
266  * c-indentation-style: "K&R"
267  * c-basic-offset: 8
268  * tab-width: 8
269  * fill-column: 80
270  * scroll-step: 1
271  * End:
272  */
273 /*
274  * vim: tabstop=8 shiftwidth=8 noexpandtab textwidth=80 nowrap
275  */
const struct m0_conf_obj_type * m0_conf_obj_type(const struct m0_conf_obj *obj)
Definition: obj.c:363
static const struct m0_conf_obj_ops pool_ops
Definition: pool.c:236
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)
#define NULL
Definition: misc.h:38
struct m0_fid_arr xp_pvers
Definition: onwire.h:83
static bool x
Definition: sm.c:168
static int pool_decode(struct m0_conf_obj *dest, const struct m0_confx_obj *src)
Definition: pool.c:175
static void pool_delete(struct m0_conf_obj *obj)
Definition: pool.c:228
const struct m0_conf_obj_type M0_CONF_PVER_TYPE
Definition: pver.c:260
static int pool_encode(struct m0_confx_obj *dest, const struct m0_conf_obj *src)
Definition: pool.c:188
uint8_t ft_id
Definition: fid.h:101
bool(* coo_invariant)(const struct m0_conf_obj *obj)
Definition: obj_ops.h:79
static bool pool_check(const void *bob)
Definition: pool.c:163
const struct m0_conf_obj_type M0_CONF_POOL_TYPE
Definition: pool.c:249
static struct foo * obj
Definition: tlist.c:302
return M0_RC(rc)
uint32_t pl_pver_policy
Definition: obj.h:449
#define M0_ENTRY(...)
Definition: trace.h:170
M0_INTERNAL int m0_conf_dir_new(struct m0_conf_obj *parent, const struct m0_fid *relfid, const struct m0_conf_obj_type *children_type, const struct m0_fid_arr *children_ids, struct m0_conf_dir **out)
Definition: dir.c:159
struct m0_conf_dir * pl_pvers
Definition: obj.h:439
const char * name
Definition: trace.c:110
const struct m0_fid_type cot_ftype
Definition: obj.h:314
M0_CONF__BOB_DEFINE(m0_conf_pool, M0_CONF_POOL_MAGIC, pool_check)
struct m0_confx_header xp_header
Definition: onwire.h:120
M0_INTERNAL void confx_encode(struct m0_confx_obj *dest, const struct m0_conf_obj *src)
Definition: common.c:110
#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
static bool pool_match(const struct m0_conf_obj *cached, const struct m0_confx_obj *flat)
Definition: pool.c:199
#define FID_P(f)
Definition: fid.h:77
static struct m0_pool pool
Definition: iter_ut.c:58
M0_CONF__CTOR_DEFINE(pool_create, m0_conf_pool, &pool_ops)
#define XCAST(xobj)
Definition: pool.c:160
M0_BASSERT(offsetof(struct m0_confx_pool, xp_header)==0)
Definition: fid.h:38
static int pool_lookup(const struct m0_conf_obj *parent, const struct m0_fid *name, struct m0_conf_obj **out)
Definition: pool.c:208
enum m0_conf_status co_status
Definition: obj.h:210
#define out(...)
Definition: gen.c:41
static const struct m0_fid ** pool_downlinks(const struct m0_conf_obj *obj)
Definition: pool.c:220
void m0_free(void *data)
Definition: memory.c:146
static struct m0_addb2_source * s
Definition: consumer.c:39
M0_CONF__INVARIANT_DEFINE(pool_invariant, m0_conf_pool)
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
#define ARRAY_SIZE(a)
Definition: misc.h:45
#define offsetof(typ, memb)
Definition: misc.h:29
#define FID_F
Definition: fid.h:75