Motr  M0
enclosure.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_enclosure_xc */
27 #include "motr/magic.h" /* M0_CONF_ENCLOSURE_MAGIC */
28 
29 #define XCAST(xobj) ((struct m0_confx_enclosure *)(&(xobj)->xo_u))
31 
32 static bool enclosure_check(const void *bob)
33 {
34  const struct m0_conf_enclosure *self = bob;
35 
37 
38  return true;
39 }
40 
43 M0_CONF__INVARIANT_DEFINE(enclosure_invariant, m0_conf_enclosure);
44 
45 static int
47 {
48  int rc;
49  struct m0_conf_obj *obj;
52  const struct m0_confx_enclosure *s = XCAST(src);
53 
54  rc = m0_conf_obj_find(dest->co_cache, &s->xe_node, &obj);
55  if (rc != 0)
56  return M0_ERR(rc);
57 
59 
61  &d->ce_ctrls,
62  &CONF_DIR_ENTRIES(&M0_CONF_ENCLOSURE_CTRLS_FID,
64  &s->xe_ctrls), dest) ?:
65  conf_pvers_decode(&d->ce_pvers, &s->xe_pvers,
66  dest->co_cache));
67 }
68 
69 static int
71 {
73  struct m0_confx_enclosure *d = XCAST(dest);
74  const struct conf_dir_encoding_pair dirs[] = {
75  { s->ce_ctrls, &d->xe_ctrls }
76  };
77 
79  if (s->ce_node != NULL)
80  d->xe_node = s->ce_node->cn_obj.co_id;
81 
82  return M0_RC(conf_dirs_encode(dirs, ARRAY_SIZE(dirs)) ?:
84  &d->xe_pvers,
85  (const struct m0_conf_pver**)s->ce_pvers));
86 }
87 
88 static bool enclosure_match(const struct m0_conf_obj *cached,
89  const struct m0_confx_obj *flat)
90 {
91  const struct m0_confx_enclosure *xobj = XCAST(flat);
92  const struct m0_conf_enclosure *obj =
94 
95  return m0_fid_eq(&obj->ce_node->cn_obj.co_id, &xobj->xe_node) &&
96  m0_conf_dir_elems_match(obj->ce_ctrls, &xobj->xe_ctrls);
97 }
98 
99 static int enclosure_lookup(const struct m0_conf_obj *parent,
100  const struct m0_fid *name, struct m0_conf_obj **out)
101 {
102  struct m0_conf_enclosure *e = M0_CONF_CAST(parent, m0_conf_enclosure);
103  const struct conf_dir_relation dirs[] = {
104  { e->ce_ctrls, &M0_CONF_ENCLOSURE_CTRLS_FID }
105  };
106 
107  M0_PRE(parent->co_status == M0_CS_READY);
108  return M0_RC(conf_dirs_lookup(out, name, dirs, ARRAY_SIZE(dirs)));
109 }
110 
111 static const struct m0_fid **enclosure_downlinks(const struct m0_conf_obj *obj)
112 {
113  static const struct m0_fid *rels[] = { &M0_CONF_ENCLOSURE_CTRLS_FID,
114  NULL };
116  return rels;
117 }
118 
119 static void enclosure_delete(struct m0_conf_obj *obj)
120 {
122  m0_conf_enclosure_bob_fini(x);
123  m0_free(x->ce_pvers);
124  m0_free(x);
125 }
126 
127 static const struct m0_conf_obj_ops enclosure_ops = {
128  .coo_invariant = enclosure_invariant,
129  .coo_decode = enclosure_decode,
130  .coo_encode = enclosure_encode,
131  .coo_match = enclosure_match,
132  .coo_lookup = enclosure_lookup,
133  .coo_readdir = NULL,
134  .coo_downlinks = enclosure_downlinks,
135  .coo_delete = enclosure_delete,
136 };
137 
139 
141  .cot_ftype = {
142  .ft_id = M0_CONF__ENCLOSURE_FT_ID,
143  .ft_name = "conf_enclosure"
144  },
145  .cot_create = &enclosure_create,
146  .cot_xt = &m0_confx_enclosure_xc,
147  .cot_branch = "u_enclosure",
148  .cot_xc_init = &m0_xc_m0_confx_enclosure_struct_init,
149  .cot_magic = M0_CONF_ENCLOSURE_MAGIC
150 };
151 
152 #undef XCAST
153 #undef M0_TRACE_SUBSYSTEM
154 
155 /*
156  * Local variables:
157  * c-indentation-style: "K&R"
158  * c-basic-offset: 8
159  * tab-width: 8
160  * fill-column: 80
161  * scroll-step: 1
162  * End:
163  */
164 /*
165  * vim: tabstop=8 shiftwidth=8 noexpandtab textwidth=80 nowrap
166  */
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_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
#define CONF_DIR_ENTRIES(relfid, entry_type, entries)
Definition: common.h:88
static int enclosure_encode(struct m0_confx_obj *dest, const struct m0_conf_obj *src)
Definition: enclosure.c:70
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
struct m0_conf_pver ** ce_pvers
Definition: obj.h:690
struct m0_fid_arr xe_pvers
Definition: onwire.h:204
static int enclosure_lookup(const struct m0_conf_obj *parent, const struct m0_fid *name, struct m0_conf_obj **out)
Definition: enclosure.c:99
struct m0_confx_header xe_header
Definition: onwire.h:120
static struct foo * obj
Definition: tlist.c:302
const struct m0_conf_obj_type M0_CONF_CONTROLLER_TYPE
Definition: controller.c:131
return M0_RC(rc)
struct m0_conf_dir * ce_ctrls
Definition: obj.h:684
M0_BASSERT(offsetof(struct m0_confx_enclosure, xe_header)==0)
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
return M0_ERR(-EOPNOTSUPP)
static bool enclosure_check(const void *bob)
Definition: enclosure.c:32
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
static const struct m0_fid ** enclosure_downlinks(const struct m0_conf_obj *obj)
Definition: enclosure.c:111
struct m0_fid_arr xe_ctrls
Definition: onwire.h:203
static bool enclosure_match(const struct m0_conf_obj *cached, const struct m0_confx_obj *flat)
Definition: enclosure.c:88
M0_INTERNAL void confx_encode(struct m0_confx_obj *dest, const struct m0_conf_obj *src)
Definition: common.c:110
M0_INTERNAL int m0_conf_obj_find(struct m0_conf_cache *cache, const struct m0_fid *id, struct m0_conf_obj **out)
Definition: obj_ops.c:136
#define M0_CONF_CAST(ptr, type)
Definition: obj.h:780
#define XCAST(xobj)
Definition: enclosure.c:29
struct m0_conf_node * ce_node
Definition: obj.h:682
M0_INTERNAL bool m0_fid_eq(const struct m0_fid *fid0, const struct m0_fid *fid1)
Definition: fid.c:164
Definition: fid.h:38
static int enclosure_decode(struct m0_conf_obj *dest, const struct m0_confx_obj *src)
Definition: enclosure.c:46
M0_CONF__BOB_DEFINE(m0_conf_enclosure, M0_CONF_ENCLOSURE_MAGIC, enclosure_check)
static const struct m0_conf_obj_ops enclosure_ops
Definition: enclosure.c:127
struct m0_fid xe_node
Definition: onwire.h:202
M0_CONF__CTOR_DEFINE(enclosure_create, m0_conf_enclosure, &enclosure_ops)
enum m0_conf_status co_status
Definition: obj.h:210
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
void m0_free(void *data)
Definition: memory.c:146
static struct m0_addb2_source * s
Definition: consumer.c:39
M0_CONF__INVARIANT_DEFINE(enclosure_invariant, m0_conf_enclosure)
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
int32_t rc
Definition: trigger_fop.h:47
#define ARRAY_SIZE(a)
Definition: misc.h:45
#define offsetof(typ, memb)
Definition: misc.h:29
static void enclosure_delete(struct m0_conf_obj *obj)
Definition: enclosure.c:119