Motr  M0
rack.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_rack_xc */
27 #include "motr/magic.h" /* M0_CONF_RACK_MAGIC */
28 
29 #define XCAST(xobj) ((struct m0_confx_rack *)(&(xobj)->xo_u))
31 
32 static bool rack_check(const void *bob)
33 {
34  const struct m0_conf_rack *self = bob;
35 
36  M0_PRE(m0_conf_obj_type(&self->cr_obj) == &M0_CONF_RACK_TYPE);
37 
38  return true;
39 }
40 
43 
44 static int
45 rack_decode(struct m0_conf_obj *dest, const struct m0_confx_obj *src)
46 {
48  const struct m0_confx_rack *s = XCAST(src);
49 
51  &d->cr_encls,
52  &CONF_DIR_ENTRIES(&M0_CONF_RACK_ENCLS_FID,
54  &s->xr_encls), dest) ?:
55  conf_pvers_decode(&d->cr_pvers, &s->xr_pvers,
56  dest->co_cache));
57 }
58 
59 static int
60 rack_encode(struct m0_confx_obj *dest, const struct m0_conf_obj *src)
61 {
63  struct m0_confx_rack *d = XCAST(dest);
64  const struct conf_dir_encoding_pair dirs[] = {
65  { s->cr_encls, &d->xr_encls }
66  };
67 
69  return M0_RC(conf_dirs_encode(dirs, ARRAY_SIZE(dirs)) ?:
71  &d->xr_pvers,
72  (const struct m0_conf_pver**)s->cr_pvers));
73 }
74 
75 static bool
76 rack_match(const struct m0_conf_obj *cached, const struct m0_confx_obj *flat)
77 {
78  const struct m0_confx_rack *xobj = XCAST(flat);
79  const struct m0_conf_rack *obj = M0_CONF_CAST(cached, m0_conf_rack);
80 
81  return m0_conf_dir_elems_match(obj->cr_encls, &xobj->xr_encls);
82 }
83 
84 static int rack_lookup(const struct m0_conf_obj *parent,
85  const struct m0_fid *name, struct m0_conf_obj **out)
86 {
87  struct m0_conf_rack *r = M0_CONF_CAST(parent, m0_conf_rack);
88  const struct conf_dir_relation dirs[] = {
89  { r->cr_encls, &M0_CONF_RACK_ENCLS_FID }
90  };
91 
92  M0_PRE(parent->co_status == M0_CS_READY);
93  return M0_RC(conf_dirs_lookup(out, name, dirs, ARRAY_SIZE(dirs)));
94 }
95 
96 static const struct m0_fid **rack_downlinks(const struct m0_conf_obj *obj)
97 {
98  static const struct m0_fid *rels[] = { &M0_CONF_RACK_ENCLS_FID, NULL };
100  return rels;
101 }
102 
103 static void rack_delete(struct m0_conf_obj *obj)
104 {
106  m0_conf_rack_bob_fini(x);
107  m0_free(x->cr_pvers);
108  m0_free(x);
109 }
110 
111 static const struct m0_conf_obj_ops rack_ops = {
112  .coo_invariant = rack_invariant,
113  .coo_decode = rack_decode,
114  .coo_encode = rack_encode,
115  .coo_match = rack_match,
116  .coo_lookup = rack_lookup,
117  .coo_readdir = NULL,
118  .coo_downlinks = rack_downlinks,
119  .coo_delete = rack_delete
120 };
121 
123 
125  .cot_ftype = {
126  .ft_id = M0_CONF__RACK_FT_ID,
127  .ft_name = "conf_rack"
128  },
129  .cot_create = &rack_create,
130  .cot_xt = &m0_confx_rack_xc,
131  .cot_branch = "u_rack",
132  .cot_xc_init = &m0_xc_m0_confx_rack_struct_init,
133  .cot_magic = M0_CONF_RACK_MAGIC
134 };
135 
136 #undef XCAST
137 #undef M0_TRACE_SUBSYSTEM
138 
139 /*
140  * Local variables:
141  * c-indentation-style: "K&R"
142  * c-basic-offset: 8
143  * tab-width: 8
144  * fill-column: 80
145  * scroll-step: 1
146  * End:
147  */
148 /*
149  * vim: tabstop=8 shiftwidth=8 noexpandtab textwidth=80 nowrap
150  */
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
static int rack_lookup(const struct m0_conf_obj *parent, const struct m0_fid *name, struct m0_conf_obj **out)
Definition: rack.c:84
struct m0_conf_pver ** cr_pvers
Definition: obj.h:675
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
static void rack_delete(struct m0_conf_obj *obj)
Definition: rack.c:103
#define M0_PRE(cond)
struct m0_fid_arr xr_encls
Definition: onwire.h:196
#define NULL
Definition: misc.h:38
#define CONF_DIR_ENTRIES(relfid, entry_type, entries)
Definition: common.h:88
static bool x
Definition: sm.c:168
uint8_t ft_id
Definition: fid.h:101
bool(* coo_invariant)(const struct m0_conf_obj *obj)
Definition: obj_ops.h:79
static bool rack_match(const struct m0_conf_obj *cached, const struct m0_confx_obj *flat)
Definition: rack.c:76
static int rack_decode(struct m0_conf_obj *dest, const struct m0_confx_obj *src)
Definition: rack.c:45
static struct foo * obj
Definition: tlist.c:302
M0_CONF__INVARIANT_DEFINE(rack_invariant, m0_conf_rack)
static int rack_encode(struct m0_confx_obj *dest, const struct m0_conf_obj *src)
Definition: rack.c:60
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
M0_CONF__CTOR_DEFINE(rack_create, m0_conf_rack, &rack_ops)
struct m0_fid_arr xr_pvers
Definition: onwire.h:197
#define XCAST(xobj)
Definition: rack.c:29
const char * name
Definition: trace.c:110
const struct m0_conf_obj_type M0_CONF_ENCLOSURE_TYPE
Definition: enclosure.c:140
const struct m0_fid_type cot_ftype
Definition: obj.h:314
M0_INTERNAL int conf_pvers_encode(struct m0_fid_arr *dest, const struct m0_conf_pver **src)
Definition: common.c:194
struct m0_confx_header xr_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_CONF__BOB_DEFINE(m0_conf_rack, M0_CONF_RACK_MAGIC, rack_check)
Definition: fid.h:38
static const struct m0_conf_obj_ops rack_ops
Definition: rack.c:111
static int r[NR]
Definition: thread.c:46
enum m0_conf_status co_status
Definition: obj.h:210
struct m0_conf_dir * cr_encls
Definition: obj.h:669
static const struct m0_fid ** rack_downlinks(const struct m0_conf_obj *obj)
Definition: rack.c:96
M0_BASSERT(offsetof(struct m0_confx_rack, xr_header)==0)
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 bool rack_check(const void *bob)
Definition: rack.c:32
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