Motr  M0
node.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_node_xc */
27 #include "lib/arith.h" /* M0_CNT_INC */
28 #include "motr/magic.h" /* M0_CONF_NODE_MAGIC */
29 
30 #define XCAST(xobj) ((struct m0_confx_node *)(&(xobj)->xo_u))
32 
33 static bool node_check(const void *bob)
34 {
35  const struct m0_conf_node *self = bob;
36 
37  M0_PRE(m0_conf_obj_type(&self->cn_obj) == &M0_CONF_NODE_TYPE);
38 
39  return true;
40 }
41 
44 
45 static int node_decode(struct m0_conf_obj *dest, const struct m0_confx_obj *src)
46 {
48  const struct m0_confx_node *s = XCAST(src);
49 
50  d->cn_memsize = s->xn_memsize;
51  d->cn_nr_cpu = s->xn_nr_cpu;
52  d->cn_last_state = s->xn_last_state;
53  d->cn_flags = s->xn_flags;
54 
55  return M0_RC(m0_conf_dir_new(dest, &M0_CONF_NODE_PROCESSES_FID,
56  &M0_CONF_PROCESS_TYPE, &s->xn_processes,
57  &d->cn_processes));
58 }
59 
60 static int node_encode(struct m0_confx_obj *dest, const struct m0_conf_obj *src)
61 {
63  struct m0_confx_node *d = XCAST(dest);
64 
66  d->xn_memsize = s->cn_memsize;
67  d->xn_nr_cpu = s->cn_nr_cpu;
68  d->xn_last_state = s->cn_last_state;
69  d->xn_flags = s->cn_flags;
70 
71  return arrfid_from_dir(&d->xn_processes, s->cn_processes);
72 }
73 
74 static bool
75 node_match(const struct m0_conf_obj *cached, const struct m0_confx_obj *flat)
76 {
77  const struct m0_confx_node *xobj = XCAST(flat);
78  const struct m0_conf_node *obj = M0_CONF_CAST(cached, m0_conf_node);
79 
80  return obj->cn_memsize == xobj->xn_memsize &&
81  obj->cn_nr_cpu == xobj->xn_nr_cpu &&
82  obj->cn_last_state == xobj->xn_last_state &&
83  obj->cn_flags == xobj->xn_flags &&
84  m0_conf_dir_elems_match(obj->cn_processes, &xobj->xn_processes);
85 }
86 
87 static int node_lookup(const struct m0_conf_obj *parent,
88  const struct m0_fid *name, struct m0_conf_obj **out)
89 {
90  struct m0_conf_node *node = M0_CONF_CAST(parent, m0_conf_node);
91  const struct conf_dir_relation dirs[] = {
92  { node->cn_processes, &M0_CONF_NODE_PROCESSES_FID }
93  };
94 
95  M0_PRE(parent->co_status == M0_CS_READY);
96  return M0_RC(conf_dirs_lookup(out, name, dirs, ARRAY_SIZE(dirs)));
97 }
98 
99 static const struct m0_fid **node_downlinks(const struct m0_conf_obj *obj)
100 {
101  static const struct m0_fid *rels[] = { &M0_CONF_NODE_PROCESSES_FID,
102  NULL };
104  return rels;
105 }
106 
107 static void node_delete(struct m0_conf_obj *obj)
108 {
110 
111  m0_conf_node_bob_fini(x);
112  m0_free(x);
113 }
114 
115 static const struct m0_conf_obj_ops node_ops = {
116  .coo_invariant = node_invariant,
117  .coo_decode = node_decode,
118  .coo_encode = node_encode,
119  .coo_match = node_match,
120  .coo_lookup = node_lookup,
121  .coo_readdir = NULL,
122  .coo_downlinks = node_downlinks,
123  .coo_delete = node_delete
124 };
125 
127 
129  .cot_ftype = {
130  .ft_id = M0_CONF__NODE_FT_ID,
131  .ft_name = "conf_node"
132  },
133  .cot_create = &node_create,
134  .cot_xt = &m0_confx_node_xc,
135  .cot_branch = "u_node",
136  .cot_xc_init = &m0_xc_m0_confx_node_struct_init,
137  .cot_magic = M0_CONF_NODE_MAGIC
138 };
139 
140 #undef XCAST
141 #undef M0_TRACE_SUBSYSTEM
142 
143 /*
144  * Local variables:
145  * c-indentation-style: "K&R"
146  * c-basic-offset: 8
147  * tab-width: 8
148  * fill-column: 80
149  * scroll-step: 1
150  * End:
151  */
152 /*
153  * vim: tabstop=8 shiftwidth=8 noexpandtab textwidth=80 nowrap
154  */
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_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 node_lookup(const struct m0_conf_obj *parent, const struct m0_fid *name, struct m0_conf_obj **out)
Definition: node.c:87
#define NULL
Definition: misc.h:38
static bool x
Definition: sm.c:168
uint8_t ft_id
Definition: fid.h:101
static const struct m0_conf_obj_ops node_ops
Definition: node.c:115
bool(* coo_invariant)(const struct m0_conf_obj *obj)
Definition: obj_ops.h:79
static struct net_test_cmd_node * node
Definition: commands.c:72
uint64_t xn_last_state
Definition: onwire.h:146
uint64_t xn_flags
Definition: onwire.h:147
static struct foo * obj
Definition: tlist.c:302
return M0_RC(rc)
M0_INTERNAL int m0_conf_dir_new(struct m0_conf_obj *parent, const struct m0_fid *relfid, const struct m0_conf_obj_type *children_type, const struct m0_fid_arr *children_ids, struct m0_conf_dir **out)
Definition: dir.c:159
static int node_decode(struct m0_conf_obj *dest, const struct m0_confx_obj *src)
Definition: node.c:45
static bool node_check(const void *bob)
Definition: node.c:33
uint64_t cn_last_state
Definition: obj.h:570
const char * name
Definition: trace.c:110
uint32_t cn_memsize
Definition: obj.h:566
uint32_t xn_memsize
Definition: onwire.h:144
M0_CONF__BOB_DEFINE(m0_conf_node, M0_CONF_NODE_MAGIC, node_check)
struct m0_confx_header xn_header
Definition: onwire.h:120
const struct m0_fid_type cot_ftype
Definition: obj.h:314
static bool node_match(const struct m0_conf_obj *cached, const struct m0_confx_obj *flat)
Definition: node.c:75
static void node_delete(struct m0_conf_obj *obj)
Definition: node.c:107
uint64_t cn_flags
Definition: obj.h:572
#define XCAST(xobj)
Definition: node.c:30
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_INTERNAL int arrfid_from_dir(struct m0_fid_arr *dest, const struct m0_conf_dir *dir)
Definition: common.c:82
M0_BASSERT(offsetof(struct m0_confx_node, xn_header)==0)
Definition: fid.h:38
const struct m0_conf_obj_type M0_CONF_NODE_TYPE
Definition: node.c:128
uint32_t cn_nr_cpu
Definition: obj.h:568
static const struct m0_fid ** node_downlinks(const struct m0_conf_obj *obj)
Definition: node.c:99
uint32_t xn_nr_cpu
Definition: onwire.h:145
enum m0_conf_status co_status
Definition: obj.h:210
M0_CONF__INVARIANT_DEFINE(node_invariant, m0_conf_node)
const struct m0_conf_obj_type M0_CONF_PROCESS_TYPE
Definition: process.c:161
#define out(...)
Definition: gen.c:41
struct m0_conf_dir * cn_processes
Definition: obj.h:563
M0_CONF__CTOR_DEFINE(node_create, m0_conf_node, &node_ops)
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
static int node_encode(struct m0_confx_obj *dest, const struct m0_conf_obj *src)
Definition: node.c:60
struct m0_fid_arr xn_processes
Definition: onwire.h:148