Motr  M0
sdev.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_sdev_xc */
27 #include "motr/magic.h" /* M0_CONF_SDEV_MAGIC */
28 #include "ioservice/fid_convert.h" /* M0_FID_DEVICE_ID_MAX */
29 
30 #define XCAST(xobj) ((struct m0_confx_sdev *)(&(xobj)->xo_u))
32 
33 static bool sdev_check(const void *bob)
34 {
35  const struct m0_conf_sdev *self = bob;
36  const struct m0_conf_obj *self_obj = &self->sd_obj;
37 
39 
40  return m0_conf_obj_is_stub(self_obj) ||
41  (_0C(self->sd_dev_idx <= M0_FID_DEVICE_ID_MAX) &&
42  _0C(self->sd_filename != NULL));
43 }
44 
47 
48 static int sdev_decode(struct m0_conf_obj *dest, const struct m0_confx_obj *src)
49 {
51  const struct m0_confx_sdev *s = XCAST(src);
52 
53  d->sd_dev_idx = s->xd_dev_idx;
54  d->sd_iface = s->xd_iface;
55  d->sd_media = s->xd_media;
56  d->sd_bsize = s->xd_bsize;
57  d->sd_size = s->xd_size;
58  d->sd_last_state = s->xd_last_state;
59  d->sd_flags = s->xd_flags;
60 
61  d->sd_filename = m0_buf_strdup(&s->xd_filename);
62  if (d->sd_filename == NULL)
63  return M0_ERR(-ENOMEM);
64  return 0;
65 }
66 
67 static int sdev_encode(struct m0_confx_obj *dest, const struct m0_conf_obj *src)
68 {
69  const struct m0_conf_sdev *s = M0_CONF_CAST(src, m0_conf_sdev);
70  struct m0_confx_sdev *d = XCAST(dest);
71 
73  d->xd_dev_idx = s->sd_dev_idx;
74  d->xd_iface = s->sd_iface;
75  d->xd_media = s->sd_media;
76  d->xd_bsize = s->sd_bsize;
77  d->xd_size = s->sd_size;
78  d->xd_last_state = s->sd_last_state;
79  d->xd_flags = s->sd_flags;
80 
81  return m0_buf_copy(&d->xd_filename,
82  &M0_BUF_INITS((char *)s->sd_filename));
83 }
84 
85 static bool
86 sdev_match(const struct m0_conf_obj *cached, const struct m0_confx_obj *flat)
87 {
88  const struct m0_confx_sdev *xobj = XCAST(flat);
89  const struct m0_conf_sdev *obj = M0_CONF_CAST(cached, m0_conf_sdev);
90 
91  return obj->sd_iface == xobj->xd_iface &&
92  obj->sd_media == xobj->xd_media &&
93  obj->sd_size == xobj->xd_size &&
94  obj->sd_last_state == xobj->xd_last_state &&
95  obj->sd_flags == xobj->xd_flags &&
96  obj->sd_dev_idx == xobj->xd_dev_idx &&
97  m0_buf_streq(&xobj->xd_filename, obj->sd_filename);
98 }
99 
100 static void sdev_delete(struct m0_conf_obj *obj)
101 {
103 
104  m0_free((void *)x->sd_filename);
105  m0_conf_sdev_bob_fini(x);
106  m0_free(x);
107 }
108 
109 static const struct m0_conf_obj_ops sdev_ops = {
110  .coo_invariant = sdev_invariant,
111  .coo_decode = sdev_decode,
112  .coo_encode = sdev_encode,
113  .coo_match = sdev_match,
114  .coo_lookup = conf_obj_lookup_denied,
115  .coo_readdir = NULL,
116  .coo_downlinks = conf_obj_downlinks_none,
117  .coo_delete = sdev_delete
118 };
119 
121 
123  .cot_ftype = {
124  .ft_id = M0_CONF__SDEV_FT_ID,
125  .ft_name = "conf_sdev"
126  },
127  .cot_create = &sdev_create,
128  .cot_xt = &m0_confx_sdev_xc,
129  .cot_branch = "u_sdev",
130  .cot_xc_init = &m0_xc_m0_confx_sdev_struct_init,
131  .cot_magic = M0_CONF_SDEV_MAGIC
132 };
133 
134 #undef XCAST
135 #undef M0_TRACE_SUBSYSTEM
136 
137 /*
138  * Local variables:
139  * c-indentation-style: "K&R"
140  * c-basic-offset: 8
141  * tab-width: 8
142  * fill-column: 80
143  * scroll-step: 1
144  * End:
145  */
146 /*
147  * vim: tabstop=8 shiftwidth=8 noexpandtab textwidth=80 nowrap
148  */
const struct m0_conf_obj_type * m0_conf_obj_type(const struct m0_conf_obj *obj)
Definition: obj.c:363
const char * sd_filename
Definition: obj.h:649
M0_INTERNAL const struct m0_fid ** conf_obj_downlinks_none(const struct m0_conf_obj *obj)
Definition: common.c:226
#define M0_PRE(cond)
#define XCAST(xobj)
Definition: sdev.c:30
#define NULL
Definition: misc.h:38
static void sdev_delete(struct m0_conf_obj *obj)
Definition: sdev.c:100
static bool x
Definition: sm.c:168
M0_INTERNAL bool m0_buf_streq(const struct m0_buf *buf, const char *str)
Definition: buf.c:132
uint8_t ft_id
Definition: fid.h:101
bool(* coo_invariant)(const struct m0_conf_obj *obj)
Definition: obj_ops.h:79
static const struct m0_conf_obj_ops sdev_ops
Definition: sdev.c:109
const struct m0_conf_obj_type M0_CONF_SDEV_TYPE
Definition: sdev.c:122
static int sdev_encode(struct m0_confx_obj *dest, const struct m0_conf_obj *src)
Definition: sdev.c:67
M0_INTERNAL int conf_obj_lookup_denied(const struct m0_conf_obj *parent, const struct m0_fid *name, struct m0_conf_obj **out)
Definition: common.c:217
M0_BASSERT(offsetof(struct m0_confx_sdev, xd_header)==0)
uint64_t sd_flags
Definition: obj.h:647
static bool sdev_check(const void *bob)
Definition: sdev.c:33
M0_INTERNAL bool m0_conf_obj_is_stub(const struct m0_conf_obj *obj)
Definition: obj.c:302
static struct foo * obj
Definition: tlist.c:302
uint64_t xd_flags
Definition: onwire.h:180
uint32_t sd_media
Definition: obj.h:639
uint32_t sd_dev_idx
Definition: obj.h:635
return M0_ERR(-EOPNOTSUPP)
uint64_t xd_last_state
Definition: onwire.h:179
const struct m0_fid_type cot_ftype
Definition: obj.h:314
M0_CONF__CTOR_DEFINE(sdev_create, m0_conf_sdev, &sdev_ops)
M0_INTERNAL void confx_encode(struct m0_confx_obj *dest, const struct m0_conf_obj *src)
Definition: common.c:110
static bool sdev_match(const struct m0_conf_obj *cached, const struct m0_confx_obj *flat)
Definition: sdev.c:86
#define M0_BUF_INITS(str)
Definition: buf.h:70
struct m0_confx_header xd_header
Definition: onwire.h:120
uint64_t sd_size
Definition: obj.h:643
#define M0_CONF_CAST(ptr, type)
Definition: obj.h:780
M0_INTERNAL int m0_buf_copy(struct m0_buf *dest, const struct m0_buf *src)
Definition: buf.c:104
uint64_t xd_size
Definition: onwire.h:178
uint32_t xd_bsize
Definition: onwire.h:177
uint32_t sd_iface
Definition: obj.h:637
M0_INTERNAL char * m0_buf_strdup(const struct m0_buf *buf)
Definition: buf.c:140
uint32_t xd_dev_idx
Definition: onwire.h:172
static int sdev_decode(struct m0_conf_obj *dest, const struct m0_confx_obj *src)
Definition: sdev.c:48
#define _0C(exp)
Definition: assert.h:311
M0_CONF__INVARIANT_DEFINE(sdev_invariant, m0_conf_sdev)
M0_CONF__BOB_DEFINE(m0_conf_sdev, M0_CONF_SDEV_MAGIC, sdev_check)
uint32_t sd_bsize
Definition: obj.h:641
uint64_t sd_last_state
Definition: obj.h:645
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
struct m0_buf xd_filename
Definition: onwire.h:181
#define offsetof(typ, memb)
Definition: misc.h:29