Motr  M0
fdmi_flt_grp.c
Go to the documentation of this file.
1 /* -*- C -*- */
2 /*
3  * Copyright (c) 2017-2020 Seagate Technology LLC and/or its Affiliates
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * For any questions about this software or licensing,
18  * please email opensource@seagate.com or cortx-questions@seagate.com.
19  *
20  */
21 
22 
23 #define M0_TRACE_SUBSYSTEM M0_TRACE_SUBSYS_CONF
24 #include "lib/trace.h"
25 
26 #include "conf/objs/common.h"
27 #include "conf/onwire_xc.h" /* m0_confx_fdmi_filter_xc */
28 #include "motr/magic.h" /* M0_CONF_FDMI_FILTER_MAGIC */
29 
30 static bool fdmi_flt_grp_check(const void *bob)
31 {
32  const struct m0_conf_fdmi_flt_grp *self = bob;
33  const struct m0_conf_obj *self_obj = &self->ffg_obj;
34 
36  return true; /* XXX IMPLEMENTME */
37 }
38 
41 
42 M0_CONF__INVARIANT_DEFINE(fdmi_flt_grp_invariant, m0_conf_fdmi_flt_grp);
43 
44 #define XCAST(xobj) ((struct m0_confx_fdmi_flt_grp *)(&(xobj)->xo_u))
46 
47 static int
49 {
50  int rc;
51  const struct m0_confx_fdmi_flt_grp *s = XCAST(src);
54 
55  M0_ENTRY();
56  d->ffg_rec_type = s->xfg_rec_type;
57  rc = m0_conf_dir_new(dest, &M0_CONF_FDMI_FGRP_FILTERS_FID,
58  &M0_CONF_FDMI_FILTER_TYPE, &s->xfg_filters,
59  &d->ffg_filters);
60  if (rc == 0)
62  return M0_RC(rc);
63 }
64 
65 static int
67 {
68  int rc;
69  struct m0_confx_fdmi_flt_grp *d = XCAST(dest);
72 
73  M0_ENTRY();
75  rc = arrfid_from_dir(&d->xfg_filters, s->ffg_filters);
76  if (rc == 0)
77  d->xfg_rec_type = s->ffg_rec_type;
78  return M0_RC(rc);
79 }
80 
81 static bool fdmi_flt_grp_match(const struct m0_conf_obj *cached,
82  const struct m0_confx_obj *flat)
83 {
84  const struct m0_confx_fdmi_flt_grp *xobj = XCAST(flat);
85  const struct m0_conf_fdmi_flt_grp *obj = M0_CONF_CAST(
86  cached, m0_conf_fdmi_flt_grp);
87 
88  M0_ENTRY();
89  M0_PRE(xobj->xfg_filters.af_count != 0);
90 
91  /* XXX TODO: Compare ffg_filters dir */
92  return M0_RC(xobj->xfg_rec_type == obj->ffg_rec_type);
93 }
94 
95 static int fdmi_flt_grp_lookup(const struct m0_conf_obj *parent,
96  const struct m0_fid *name,
97  struct m0_conf_obj **out)
98 {
99  M0_ENTRY();
100  M0_PRE(parent->co_status == M0_CS_READY);
101 
102  if (!m0_fid_eq(name, &M0_CONF_FDMI_FGRP_FILTERS_FID))
103  return M0_ERR(-ENOENT);
104 
105  *out = &M0_CONF_CAST(parent, m0_conf_fdmi_flt_grp)->ffg_filters->cd_obj;
107  return M0_RC(0);
108 }
109 
110 static void fdmi_flt_grp_delete(struct m0_conf_obj *obj)
111 {
114  m0_conf_fdmi_flt_grp_bob_fini(x);
115  m0_free(x);
116 }
117 
118 static const struct m0_fid **fdmi_flt_grp_downlinks(const struct m0_conf_obj *obj)
119 {
120  static const struct m0_fid *rels[] = { &M0_CONF_FDMI_FGRP_FILTERS_FID,
121  NULL };
123  return rels;
124 }
125 
126 static const struct m0_conf_obj_ops conf_fdmi_flt_grp_ops = {
128  .coo_invariant = fdmi_flt_grp_invariant,
129  .coo_decode = fdmi_flt_grp_decode,
130  .coo_encode = fdmi_flt_grp_encode,
131  .coo_match = fdmi_flt_grp_match,
132  .coo_lookup = fdmi_flt_grp_lookup,
133  .coo_readdir = NULL,
134  .coo_delete = fdmi_flt_grp_delete
135 };
136 
137 static struct m0_conf_obj *fdmi_flt_grp_create(void)
138 {
139  struct m0_conf_fdmi_flt_grp *x;
140  struct m0_conf_obj *ret;
141 
142  M0_ALLOC_PTR(x);
143  if (x == NULL)
144  return NULL;
145  m0_conf_fdmi_flt_grp_bob_init(x);
146  ret = &x->ffg_obj;
148  return ret;
149 }
150 
152  .cot_ftype = {
153  .ft_id = M0_CONF__FDMI_FLT_GRP_FT_ID,
154  .ft_name = "conf_fdmi_flt_grp"
155  },
156  .cot_create = &fdmi_flt_grp_create,
157  .cot_xt = &m0_confx_fdmi_flt_grp_xc,
158  .cot_branch = "u_fdmi_flt_grp",
159  .cot_xc_init = &m0_xc_m0_confx_fdmi_flt_grp_struct_init,
160  .cot_magic = M0_CONF_FDMI_FLT_GRP_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
#define M0_PRE(cond)
#define NULL
Definition: misc.h:38
struct m0_conf_obj cd_obj
Definition: obj.h:358
static bool x
Definition: sm.c:168
M0_CONF__INVARIANT_DEFINE(fdmi_flt_grp_invariant, m0_conf_fdmi_flt_grp)
uint8_t ft_id
Definition: fid.h:101
static void fdmi_flt_grp_delete(struct m0_conf_obj *obj)
Definition: fdmi_flt_grp.c:110
enum m0_fdmi_rec_type_id ffg_rec_type
Definition: obj.h:722
static bool fdmi_flt_grp_match(const struct m0_conf_obj *cached, const struct m0_confx_obj *flat)
Definition: fdmi_flt_grp.c:81
M0_BASSERT(offsetof(struct m0_confx_fdmi_flt_grp, xfg_header)==0)
static struct foo * obj
Definition: tlist.c:302
return M0_RC(rc)
struct m0_confx_header xfg_header
Definition: onwire.h:120
static struct m0_conf_obj * fdmi_flt_grp_create(void)
Definition: fdmi_flt_grp.c:137
static int fdmi_flt_grp_lookup(const struct m0_conf_obj *parent, const struct m0_fid *name, struct m0_conf_obj **out)
Definition: fdmi_flt_grp.c:95
#define M0_ENTRY(...)
Definition: trace.h:170
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 XCAST(xobj)
Definition: fdmi_flt_grp.c:44
return M0_ERR(-EOPNOTSUPP)
M0_INTERNAL void m0_conf_child_adopt(struct m0_conf_obj *parent, struct m0_conf_obj *child)
Definition: obj.c:425
M0_CONF__BOB_DEFINE(m0_conf_fdmi_flt_grp, M0_CONF_FDMI_FLT_GRP_MAGIC, fdmi_flt_grp_check)
const char * name
Definition: trace.c:110
const struct m0_fid_type cot_ftype
Definition: obj.h:314
const struct m0_fid **(* coo_downlinks)(const struct m0_conf_obj *obj)
Definition: obj_ops.h:151
M0_INTERNAL void confx_encode(struct m0_confx_obj *dest, const struct m0_conf_obj *src)
Definition: common.c:110
#define M0_POST(cond)
static const struct m0_conf_obj_ops conf_fdmi_flt_grp_ops
Definition: fdmi_flt_grp.c:126
#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
uint32_t xfg_rec_type
Definition: onwire.h:221
M0_INTERNAL bool m0_fid_eq(const struct m0_fid *fid0, const struct m0_fid *fid1)
Definition: fid.c:164
Definition: fid.h:38
#define M0_ALLOC_PTR(ptr)
Definition: memory.h:86
struct m0_fid_arr xfg_filters
Definition: onwire.h:222
struct m0_conf_dir * ffg_filters
Definition: obj.h:724
static int fdmi_flt_grp_decode(struct m0_conf_obj *dest, const struct m0_confx_obj *src)
Definition: fdmi_flt_grp.c:48
enum m0_conf_status co_status
Definition: obj.h:210
static bool fdmi_flt_grp_check(const void *bob)
Definition: fdmi_flt_grp.c:30
const struct m0_conf_obj_type M0_CONF_FDMI_FLT_GRP_TYPE
Definition: fdmi_flt_grp.c:151
#define out(...)
Definition: gen.c:41
static const struct m0_fid ** fdmi_flt_grp_downlinks(const struct m0_conf_obj *obj)
Definition: fdmi_flt_grp.c:118
static int fdmi_flt_grp_encode(struct m0_confx_obj *dest, const struct m0_conf_obj *src)
Definition: fdmi_flt_grp.c:66
void m0_free(void *data)
Definition: memory.c:146
static struct m0_addb2_source * s
Definition: consumer.c:39
struct m0_pdclust_src_addr src
Definition: fd.c:108
int32_t rc
Definition: trigger_fop.h:47
#define offsetof(typ, memb)
Definition: misc.h:29
M0_INTERNAL bool m0_conf_obj_invariant(const struct m0_conf_obj *obj)
Definition: obj_ops.c:52
uint32_t af_count
Definition: fid.h:44
const struct m0_conf_obj_type M0_CONF_FDMI_FILTER_TYPE
Definition: fdmi_filter.c:199
const struct m0_conf_obj_ops * co_ops
Definition: obj.h:212