Motr  M0
controller.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_controller_xc */
27 #include "motr/magic.h" /* M0_CONF_CONTROLLER_MAGIC */
28 
29 #define XCAST(xobj) ((struct m0_confx_controller *)(&(xobj)->xo_u))
31 
32 static bool controller_check(const void *bob)
33 {
34  const struct m0_conf_controller *self = bob;
35  const struct m0_conf_obj *self_obj = &self->cc_obj;
36 
38 
39  return true;
40 }
41 
44 M0_CONF__INVARIANT_DEFINE(controller_invariant, m0_conf_controller);
45 
46 static int
48 {
49  int rc;
50  const struct m0_confx_controller *s = XCAST(src);
51  struct m0_conf_controller *d =
53 
55  &CONF_DIR_ENTRIES(&M0_CONF_CONTROLLER_DRIVES_FID,
56  &M0_CONF_DRIVE_TYPE, &s->xc_drives),
57  dest) ?:
58  conf_pvers_decode(&d->cc_pvers, &s->xc_pvers, dest->co_cache);
59 
60  return M0_RC(rc);
61 }
62 
63 static int
65 {
67  struct m0_confx_controller *d = XCAST(dest);
68  const struct conf_dir_encoding_pair dirs[] = {
69  { s->cc_drives, &d->xc_drives }
70  };
71 
73  return M0_RC(conf_dirs_encode(dirs, ARRAY_SIZE(dirs)) ?:
75  &d->xc_pvers,
76  (const struct m0_conf_pver**)s->cc_pvers));
77 }
78 
79 static bool controller_match(const struct m0_conf_obj *cached,
80  const struct m0_confx_obj *flat)
81 {
82  const struct m0_confx_controller *xobj = XCAST(flat);
83  const struct m0_conf_controller *obj =
85 
86  return m0_conf_dir_elems_match(obj->cc_drives, &xobj->xc_drives);
87 }
88 
89 static int controller_lookup(const struct m0_conf_obj *parent,
90  const struct m0_fid *name,
91  struct m0_conf_obj **out)
92 {
94  const struct conf_dir_relation dirs[] = {
95  { c->cc_drives, &M0_CONF_CONTROLLER_DRIVES_FID }
96  };
97 
98  M0_PRE(parent->co_status == M0_CS_READY);
99  return M0_RC(conf_dirs_lookup(out, name, dirs, ARRAY_SIZE(dirs)));
100 }
101 
102 static const struct m0_fid **controller_downlinks(const struct m0_conf_obj *obj)
103 {
104  static const struct m0_fid *rels[] = { &M0_CONF_CONTROLLER_DRIVES_FID,
105  NULL };
107  return rels;
108 }
109 
110 static void controller_delete(struct m0_conf_obj *obj)
111 {
113  m0_conf_controller_bob_fini(x);
114  m0_free(x->cc_pvers);
115  m0_free(x);
116 }
117 
118 static const struct m0_conf_obj_ops controller_ops = {
119  .coo_invariant = controller_invariant,
120  .coo_decode = controller_decode,
121  .coo_encode = controller_encode,
122  .coo_match = controller_match,
123  .coo_lookup = controller_lookup,
124  .coo_readdir = NULL,
125  .coo_downlinks = controller_downlinks,
126  .coo_delete = controller_delete
127 };
128 
130 
132  .cot_ftype = {
133  .ft_id = M0_CONF__CONTROLLER_FT_ID,
134  .ft_name = "conf_controller"
135  },
136  .cot_create = &controller_create,
137  .cot_xt = &m0_confx_controller_xc,
138  .cot_branch = "u_controller",
139  .cot_xc_init = &m0_xc_m0_confx_controller_struct_init,
140  .cot_magic = M0_CONF_CONTROLLER_MAGIC
141 };
142 
143 #undef XCAST
144 #undef M0_TRACE_SUBSYSTEM
145 
146 /*
147  * Local variables:
148  * c-indentation-style: "K&R"
149  * c-basic-offset: 8
150  * tab-width: 8
151  * fill-column: 80
152  * scroll-step: 1
153  * End:
154  */
155 /*
156  * vim: tabstop=8 shiftwidth=8 noexpandtab textwidth=80 nowrap
157  */
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 bool x
Definition: sm.c:168
uint8_t ft_id
Definition: fid.h:101
struct m0_conf_pver ** cc_pvers
Definition: obj.h:703
bool(* coo_invariant)(const struct m0_conf_obj *obj)
Definition: obj_ops.h:79
static bool controller_match(const struct m0_conf_obj *cached, const struct m0_confx_obj *flat)
Definition: controller.c:79
M0_CONF__INVARIANT_DEFINE(controller_invariant, m0_conf_controller)
static void controller_delete(struct m0_conf_obj *obj)
Definition: controller.c:110
static const struct m0_fid ** controller_downlinks(const struct m0_conf_obj *obj)
Definition: controller.c:102
static struct foo * obj
Definition: tlist.c:302
M0_BASSERT(offsetof(struct m0_confx_controller, xc_header)==0)
const struct m0_conf_obj_type M0_CONF_CONTROLLER_TYPE
Definition: controller.c:131
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
M0_CONF__BOB_DEFINE(m0_conf_controller, M0_CONF_CONTROLLER_MAGIC, controller_check)
M0_CONF__CTOR_DEFINE(controller_create, m0_conf_controller, &controller_ops)
struct m0_conf_dir * cc_drives
Definition: obj.h:697
const struct m0_fid_type cot_ftype
Definition: obj.h:314
#define XCAST(xobj)
Definition: controller.c:29
M0_INTERNAL int conf_pvers_encode(struct m0_fid_arr *dest, const struct m0_conf_pver **src)
Definition: common.c:194
static struct m0_addb2_callback c
Definition: consumer.c:41
static bool controller_check(const void *bob)
Definition: controller.c:32
struct m0_fid_arr xc_pvers
Definition: onwire.h:210
static int controller_lookup(const struct m0_conf_obj *parent, const struct m0_fid *name, struct m0_conf_obj **out)
Definition: controller.c:89
M0_INTERNAL void confx_encode(struct m0_confx_obj *dest, const struct m0_conf_obj *src)
Definition: common.c:110
const struct m0_conf_obj_type M0_CONF_DRIVE_TYPE
Definition: drive.c:108
static const struct m0_conf_obj_ops controller_ops
Definition: controller.c:118
#define M0_CONF_CAST(ptr, type)
Definition: obj.h:780
static int controller_encode(struct m0_confx_obj *dest, const struct m0_conf_obj *src)
Definition: controller.c:64
Definition: fid.h:38
struct m0_fid_arr xc_drives
Definition: onwire.h:209
enum m0_conf_status co_status
Definition: obj.h:210
struct m0_confx_header xc_header
Definition: onwire.h:120
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_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 int controller_decode(struct m0_conf_obj *dest, const struct m0_confx_obj *src)
Definition: controller.c:47