Motr  M0
objv.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_objv_xc */
27 #include "lib/arith.h" /* M0_CNT_INC */
28 #include "motr/magic.h" /* M0_CONF_OBJV_MAGIC */
29 
30 #define XCAST(xobj) ((struct m0_confx_objv *)(&(xobj)->xo_u))
32 
33 static const struct m0_fid **objv_downlinks(const struct m0_conf_obj *obj);
34 
35 static bool objv_check(const void *bob)
36 {
37  const struct m0_conf_objv *self = bob;
38 
39  M0_PRE(m0_conf_obj_type(&self->cv_obj) == &M0_CONF_OBJV_TYPE);
40 
41  return true;
42 }
43 
46 
47 static int objv_decode(struct m0_conf_obj *dest, const struct m0_confx_obj *src)
48 {
50  const struct m0_confx_objv *s = XCAST(src);
51  const struct m0_fid *relfid;
52  int rc;
53 
54  d->cv_ix = -1;
55  rc = m0_conf_obj_find(dest->co_cache, &s->xj_real, &d->cv_real);
56  if (rc != 0)
57  return M0_ERR(rc);
58  relfid = objv_downlinks(dest)[0];
59  if (relfid == NULL)
60  return s->xj_children.af_count == 0 ?
61  M0_RC(0) /* no children */ :
62  M0_ERR_INFO(-EINVAL, FID_F": No children expected",
63  FID_P(&dest->co_id));
65  &s->xj_children, &d->cv_children));
66 }
67 
68 static int
69 objv_encode(struct m0_confx_obj *dest, const struct m0_conf_obj *src)
70 {
72  struct m0_confx_objv *d = XCAST(dest);
73 
75  if (s->cv_real != NULL)
76  XCAST(dest)->xj_real = s->cv_real->co_id;
77  return s->cv_children == NULL ? 0 :
78  arrfid_from_dir(&d->xj_children, s->cv_children);
79 }
80 
81 static bool
82 objv_match(const struct m0_conf_obj *cached, const struct m0_confx_obj *flat)
83 {
84  const struct m0_confx_objv *xobj = XCAST(flat);
85  const struct m0_conf_objv *obj = M0_CONF_CAST(cached, m0_conf_objv);
86 
87  M0_PRE(obj->cv_real != NULL);
88  return m0_fid_eq(&obj->cv_real->co_id, &xobj->xj_real) &&
89  m0_conf_dir_elems_match(obj->cv_children, &xobj->xj_children);
90 }
91 
92 static int objv_lookup(const struct m0_conf_obj *parent,
93  const struct m0_fid *name,
94  struct m0_conf_obj **out)
95 {
96  struct m0_conf_objv *objv = M0_CONF_CAST(parent, m0_conf_objv);
97  const struct conf_dir_relation dirs[] = {
98  { objv->cv_children, parent->co_ops->coo_downlinks(parent)[0] }
99  };
100 
101  M0_PRE(parent->co_status == M0_CS_READY);
102  return M0_RC(conf_dirs_lookup(out, name, dirs, ARRAY_SIZE(dirs)));
103 }
104 
105 static const struct m0_fid **objv_downlinks(const struct m0_conf_obj *obj)
106 {
107  enum { SITE, RACK, ENCL, CTRL, DISK };
108  static const struct m0_fid *downlinks[][2] = {
109  [SITE] = { &M0_CONF_SITEV_RACKVS_FID, NULL },
110  [RACK] = { &M0_CONF_RACKV_ENCLVS_FID, NULL },
111  [ENCL] = { &M0_CONF_ENCLV_CTRLVS_FID, NULL },
112  [CTRL] = { &M0_CONF_CTRLV_DRIVEVS_FID, NULL },
113  [DISK] = { NULL, NULL } /* no downlinks */
114  };
115  const struct m0_conf_obj_type *real =
117 
118  if (real == &M0_CONF_SITE_TYPE)
119  return downlinks[SITE];
120  if (real == &M0_CONF_RACK_TYPE)
121  return downlinks[RACK];
122  if (real == &M0_CONF_ENCLOSURE_TYPE)
123  return downlinks[ENCL];
124  if (real == &M0_CONF_CONTROLLER_TYPE)
125  return downlinks[CTRL];
126  M0_ASSERT(real == &M0_CONF_DRIVE_TYPE);
127  return downlinks[DISK];
128 }
129 
130 static void objv_delete(struct m0_conf_obj *obj)
131 {
133 
134  m0_conf_objv_bob_fini(x);
135  m0_free(x);
136 }
137 
138 static const struct m0_conf_obj_ops objv_ops = {
139  .coo_invariant = objv_invariant,
140  .coo_decode = objv_decode,
141  .coo_encode = objv_encode,
142  .coo_match = objv_match,
143  .coo_lookup = objv_lookup,
144  .coo_readdir = NULL,
145  .coo_downlinks = objv_downlinks,
146  .coo_delete = objv_delete
147 };
148 
150 
152  .cot_ftype = {
153  .ft_id = M0_CONF__OBJV_FT_ID,
154  .ft_name = "conf_objv"
155  },
156  .cot_create = &objv_create,
157  .cot_xt = &m0_confx_objv_xc,
158  .cot_branch = "u_objv",
159  .cot_xc_init = &m0_xc_m0_confx_objv_struct_init,
160  .cot_magic = M0_CONF_OBJV_MAGIC
161 };
162 
163 #undef XCAST
164 #undef M0_TRACE_SUBSYSTEM
165 
166 /*
167  * Local variables:
168  * c-indentation-style: "K&R"
169  * c-basic-offset: 8
170  * tab-width: 8
171  * fill-column: 80
172  * scroll-step: 1
173  * End:
174  */
175 /*
176  * vim: tabstop=8 shiftwidth=8 noexpandtab textwidth=80 nowrap
177  */
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)
const struct m0_conf_obj_type M0_CONF_OBJV_TYPE
Definition: objv.c:151
#define NULL
Definition: misc.h:38
const struct m0_conf_obj_type M0_CONF_SITE_TYPE
Definition: site.c:121
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_confx_header xj_header
Definition: onwire.h:120
static void objv_delete(struct m0_conf_obj *obj)
Definition: objv.c:130
static bool objv_match(const struct m0_conf_obj *cached, const struct m0_confx_obj *flat)
Definition: objv.c:82
static struct foo * obj
Definition: tlist.c:302
const struct m0_conf_obj_type M0_CONF_CONTROLLER_TYPE
Definition: controller.c:131
static int objv_encode(struct m0_confx_obj *dest, const struct m0_conf_obj *src)
Definition: objv.c:69
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
#define M0_ERR_INFO(rc, fmt,...)
Definition: trace.h:215
return M0_ERR(-EOPNOTSUPP)
const char * name
Definition: trace.c:110
const struct m0_conf_obj_type M0_CONF_ENCLOSURE_TYPE
Definition: enclosure.c:140
int cv_ix
Definition: obj.h:550
const struct m0_fid_type cot_ftype
Definition: obj.h:314
#define M0_ASSERT(cond)
static const struct m0_conf_obj_ops objv_ops
Definition: objv.c:138
const struct m0_fid **(* coo_downlinks)(const struct m0_conf_obj *obj)
Definition: obj_ops.h:151
#define XCAST(xobj)
Definition: objv.c:30
M0_INTERNAL void confx_encode(struct m0_confx_obj *dest, const struct m0_conf_obj *src)
Definition: common.c:110
static const struct m0_fid ** objv_downlinks(const struct m0_conf_obj *obj)
Definition: objv.c:105
const struct m0_conf_obj_type M0_CONF_DRIVE_TYPE
Definition: drive.c:108
static int objv_decode(struct m0_conf_obj *dest, const struct m0_confx_obj *src)
Definition: objv.c:47
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
M0_INTERNAL int arrfid_from_dir(struct m0_fid_arr *dest, const struct m0_conf_dir *dir)
Definition: common.c:82
#define FID_P(f)
Definition: fid.h:77
static bool objv_check(const void *bob)
Definition: objv.c:35
M0_INTERNAL bool m0_fid_eq(const struct m0_fid *fid0, const struct m0_fid *fid1)
Definition: fid.c:164
struct m0_fid xj_real
Definition: onwire.h:134
M0_CONF__BOB_DEFINE(m0_conf_objv, M0_CONF_OBJV_MAGIC, objv_check)
Definition: fid.h:38
enum m0_conf_status co_status
Definition: obj.h:210
struct m0_conf_dir * cv_children
Definition: obj.h:545
Definition: diter.c:55
#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
M0_CONF__CTOR_DEFINE(objv_create, m0_conf_objv, &objv_ops)
#define offsetof(typ, memb)
Definition: misc.h:29
const struct m0_conf_obj_type M0_CONF_RACK_TYPE
Definition: rack.c:124
M0_CONF__INVARIANT_DEFINE(objv_invariant, m0_conf_objv)
struct m0_conf_obj * cv_real
Definition: obj.h:558
#define FID_F
Definition: fid.h:75
M0_BASSERT(offsetof(struct m0_confx_objv, xj_header)==0)
struct m0_fid_arr xj_children
Definition: onwire.h:135
const struct m0_conf_obj_ops * co_ops
Definition: obj.h:212
static int objv_lookup(const struct m0_conf_obj *parent, const struct m0_fid *name, struct m0_conf_obj **out)
Definition: objv.c:92