Motr  M0
site.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018-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_site_xc */
27 #include "motr/magic.h" /* M0_CONF_SITE_MAGIC */
28 
29 #define XCAST(xobj) ((struct m0_confx_site *)(&(xobj)->xo_u))
31 
32 static bool site_check(const void *bob)
33 {
34  const struct m0_conf_site *self = bob;
35 
36  M0_PRE(m0_conf_obj_type(&self->ct_obj) == &M0_CONF_SITE_TYPE);
37 
38  return true;
39 }
40 
43 
44 static int site_decode(struct m0_conf_obj *dest,
45  const struct m0_confx_obj *src)
46 {
48  const struct m0_confx_site *s = XCAST(src);
49 
51  &CONF_DIR_ENTRIES(&M0_CONF_SITE_RACKS_FID,
53  &s->xi_racks), dest) ?:
54  conf_pvers_decode(&d->ct_pvers, &s->xi_pvers,
55  dest->co_cache));
56 }
57 
58 static int
59 site_encode(struct m0_confx_obj *dest, const struct m0_conf_obj *src)
60 {
62  struct m0_confx_site *d = XCAST(dest);
63  const struct conf_dir_encoding_pair dirs[] = {
64  { s->ct_racks, &d->xi_racks }
65  };
66 
68  return M0_RC(conf_dirs_encode(dirs, ARRAY_SIZE(dirs)) ?:
70  (const struct m0_conf_pver**)s->ct_pvers));
71 }
72 
73 static bool
74 site_match(const struct m0_conf_obj *cached, const struct m0_confx_obj *flat)
75 {
76  const struct m0_confx_site *xobj = XCAST(flat);
77  const struct m0_conf_site *obj = M0_CONF_CAST(cached, m0_conf_site);
78 
79  return m0_conf_dir_elems_match(obj->ct_racks, &xobj->xi_racks);
80 }
81 
82 static int site_lookup(const struct m0_conf_obj *parent,
83  const struct m0_fid *name, struct m0_conf_obj **out)
84 {
85  struct m0_conf_site *r = M0_CONF_CAST(parent, m0_conf_site);
86  const struct conf_dir_relation dirs[] = {
87  { r->ct_racks, &M0_CONF_SITE_RACKS_FID } };
88 
89  M0_PRE(parent->co_status == M0_CS_READY);
90  return M0_RC(conf_dirs_lookup(out, name, dirs, ARRAY_SIZE(dirs)));
91 }
92 
93 static const struct m0_fid **site_downlinks(const struct m0_conf_obj *obj)
94 {
95  static const struct m0_fid *rels[] = { &M0_CONF_SITE_RACKS_FID, NULL };
97  return rels;
98 }
99 
100 static void site_delete(struct m0_conf_obj *obj)
101 {
103  m0_conf_site_bob_fini(x);
104  m0_free(x->ct_pvers);
105  m0_free(x);
106 }
107 
108 static const struct m0_conf_obj_ops site_ops = {
109  .coo_invariant = site_invariant,
110  .coo_decode = site_decode,
111  .coo_encode = site_encode,
112  .coo_match = site_match,
113  .coo_lookup = site_lookup,
114  .coo_readdir = NULL,
115  .coo_downlinks = site_downlinks,
116  .coo_delete = site_delete
117 };
118 
120 
122  .cot_ftype = {
123  .ft_id = M0_CONF__SITE_FT_ID,
124  .ft_name = "conf_site"
125  },
126  .cot_create = &site_create,
127  .cot_xt = &m0_confx_site_xc,
128  .cot_branch = "u_site",
129  .cot_xc_init = &m0_xc_m0_confx_site_struct_init,
130  .cot_magic = M0_CONF_SITE_MAGIC
131 };
132 
133 #undef XCAST
134 #undef M0_TRACE_SUBSYSTEM
135 
136 /*
137  * Local variables:
138  * c-indentation-style: "K&R"
139  * c-basic-offset: 8
140  * tab-width: 8
141  * fill-column: 80
142  * scroll-step: 1
143  * End:
144  */
145 /*
146  * vim: tabstop=8 shiftwidth=8 noexpandtab textwidth=80 nowrap
147  */
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
M0_CONF__CTOR_DEFINE(site_create, m0_conf_site, &site_ops)
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)
static int site_decode(struct m0_conf_obj *dest, const struct m0_confx_obj *src)
Definition: site.c:44
#define NULL
Definition: misc.h:38
#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
static bool x
Definition: sm.c:168
M0_BASSERT(offsetof(struct m0_confx_site, xi_header)==0)
uint8_t ft_id
Definition: fid.h:101
static void site_delete(struct m0_conf_obj *obj)
Definition: site.c:100
bool(* coo_invariant)(const struct m0_conf_obj *obj)
Definition: obj_ops.h:79
#define XCAST(xobj)
Definition: site.c:29
struct m0_fid_arr xi_racks
Definition: onwire.h:190
struct m0_confx_header xi_header
Definition: onwire.h:120
M0_CONF__BOB_DEFINE(m0_conf_site, M0_CONF_SITE_MAGIC, site_check)
static struct foo * obj
Definition: tlist.c:302
return M0_RC(rc)
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
const char * name
Definition: trace.c:110
const struct m0_fid_type cot_ftype
Definition: obj.h:314
struct m0_conf_pver ** ct_pvers
Definition: obj.h:662
M0_INTERNAL int conf_pvers_encode(struct m0_fid_arr *dest, const struct m0_conf_pver **src)
Definition: common.c:194
static int site_encode(struct m0_confx_obj *dest, const struct m0_conf_obj *src)
Definition: site.c:59
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_CONF__INVARIANT_DEFINE(site_invariant, m0_conf_site)
static const struct m0_fid ** site_downlinks(const struct m0_conf_obj *obj)
Definition: site.c:93
static bool site_match(const struct m0_conf_obj *cached, const struct m0_confx_obj *flat)
Definition: site.c:74
Definition: fid.h:38
struct m0_fid_arr xi_pvers
Definition: onwire.h:191
static int r[NR]
Definition: thread.c:46
enum m0_conf_status co_status
Definition: obj.h:210
struct m0_conf_dir * ct_racks
Definition: obj.h:656
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
static const struct m0_conf_obj_ops site_ops
Definition: site.c:108
static bool site_check(const void *bob)
Definition: site.c:32
static int site_lookup(const struct m0_conf_obj *parent, const struct m0_fid *name, struct m0_conf_obj **out)
Definition: site.c:82
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
#define ARRAY_SIZE(a)
Definition: misc.h:45
#define offsetof(typ, memb)
Definition: misc.h:29
const struct m0_conf_obj_type M0_CONF_RACK_TYPE
Definition: rack.c:124