Motr  M0
profile.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 "conf/objs/common.h"
26 #include "conf/onwire_xc.h" /* m0_confx_profile_xc */
27 #include "motr/magic.h" /* M0_CONF_PROFILE_MAGIC */
28 
29 #define XCAST(xobj) ((struct m0_confx_profile *)(&(xobj)->xo_u))
31 
32 static bool profile_check(const void *bob)
33 {
34  const struct m0_conf_profile *self = bob;
35 
36  M0_PRE(m0_conf_obj_type(&self->cp_obj) == &M0_CONF_PROFILE_TYPE);
37 
38  return m0_conf_obj_is_stub(&self->cp_obj) ||
39  _0C(m0_fid_arr_all_unique(&self->cp_pools));
40 }
41 
43 M0_CONF__INVARIANT_DEFINE(profile_invariant, m0_conf_profile);
44 
45 static int
47 {
48  const struct m0_confx_profile *s = XCAST(src);
50 
51  M0_PRE(equi(s->xp_pools.af_count == 0, s->xp_pools.af_elems == NULL));
52 
53  return M0_RC(m0_fid_arr_copy(&d->cp_pools, &s->xp_pools));
54 }
55 
56 static int
58 {
60  struct m0_confx_profile *d = XCAST(dest);
61 
63 
64  return M0_RC(m0_fid_arr_copy(&d->xp_pools, &s->cp_pools));
65 }
66 
67 static bool
68 profile_match(const struct m0_conf_obj *cached, const struct m0_confx_obj *flat)
69 {
70  const struct m0_confx_profile *xobj = XCAST(flat);
71  const struct m0_conf_profile *obj = M0_CONF_CAST(cached,
73  return m0_fid_arr_eq(&obj->cp_pools, &xobj->xp_pools);
74 }
75 
76 static void profile_delete(struct m0_conf_obj *obj)
77 {
79 
80  m0_conf_profile_bob_fini(x);
81  m0_free(x);
82 }
83 
84 static const struct m0_conf_obj_ops profile_ops = {
85  .coo_invariant = profile_invariant,
86  .coo_decode = profile_decode,
87  .coo_encode = profile_encode,
88  .coo_match = profile_match,
89  .coo_lookup = conf_obj_lookup_denied,
90  .coo_readdir = NULL,
91  .coo_downlinks = conf_obj_downlinks_none,
92  .coo_delete = profile_delete
93 };
94 
96 
98  .cot_ftype = {
99  .ft_id = M0_CONF__PROFILE_FT_ID,
100  .ft_name = "conf_profile"
101  },
102  .cot_create = &profile_create,
103  .cot_xt = &m0_confx_profile_xc,
104  .cot_branch = "u_profile",
105  .cot_xc_init = &m0_xc_m0_confx_profile_struct_init,
106  .cot_magic = M0_CONF_PROFILE_MAGIC
107 };
108 
109 #undef XCAST
110 #undef M0_TRACE_SUBSYSTEM
111 
112 /*
113  * Local variables:
114  * c-indentation-style: "K&R"
115  * c-basic-offset: 8
116  * tab-width: 8
117  * fill-column: 80
118  * scroll-step: 1
119  * End:
120  */
121 /*
122  * vim: tabstop=8 shiftwidth=8 noexpandtab textwidth=80 nowrap
123  */
const struct m0_conf_obj_type * m0_conf_obj_type(const struct m0_conf_obj *obj)
Definition: obj.c:363
M0_INTERNAL const struct m0_fid ** conf_obj_downlinks_none(const struct m0_conf_obj *obj)
Definition: common.c:226
#define M0_PRE(cond)
static int profile_decode(struct m0_conf_obj *dest, const struct m0_confx_obj *src)
Definition: profile.c:46
#define NULL
Definition: misc.h:38
const struct m0_conf_obj_type M0_CONF_PROFILE_TYPE
Definition: profile.c:97
static bool x
Definition: sm.c:168
M0_CONF__CTOR_DEFINE(profile_create, m0_conf_profile, &profile_ops)
M0_CONF__INVARIANT_DEFINE(profile_invariant, m0_conf_profile)
uint8_t ft_id
Definition: fid.h:101
bool(* coo_invariant)(const struct m0_conf_obj *obj)
Definition: obj_ops.h:79
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
static int profile_encode(struct m0_confx_obj *dest, const struct m0_conf_obj *src)
Definition: profile.c:57
M0_INTERNAL bool m0_conf_obj_is_stub(const struct m0_conf_obj *obj)
Definition: obj.c:302
static struct foo * obj
Definition: tlist.c:302
return M0_RC(rc)
#define equi(a, b)
Definition: misc.h:297
static bool profile_check(const void *bob)
Definition: profile.c:32
static bool profile_match(const struct m0_conf_obj *cached, const struct m0_confx_obj *flat)
Definition: profile.c:68
const struct m0_fid_type cot_ftype
Definition: obj.h:314
struct m0_fid_arr cp_pools
Definition: obj.h:424
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
M0_BASSERT(offsetof(struct m0_confx_profile, xp_header)==0)
M0_INTERNAL bool m0_fid_arr_eq(const struct m0_fid_arr *a, const struct m0_fid_arr *b)
Definition: fid.c:319
#define M0_CONF_CAST(ptr, type)
Definition: obj.h:780
M0_CONF__BOB_DEFINE(m0_conf_profile, M0_CONF_PROFILE_MAGIC, profile_check)
static const struct m0_conf_obj_ops profile_ops
Definition: profile.c:84
static void profile_delete(struct m0_conf_obj *obj)
Definition: profile.c:76
M0_INTERNAL int m0_fid_arr_copy(struct m0_fid_arr *to, const struct m0_fid_arr *from)
Definition: fid.c:303
#define _0C(exp)
Definition: assert.h:311
struct m0_fid_arr xp_pools
Definition: onwire.h:77
#define XCAST(xobj)
Definition: profile.c:29
void m0_free(void *data)
Definition: memory.c:146
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
struct m0_pdclust_src_addr src
Definition: fd.c:108
#define offsetof(typ, memb)
Definition: misc.h:29