Motr  M0
drive.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_drive_xc */
27 #include "motr/magic.h" /* M0_CONF_DRIVE_MAGIC */
28 
29 #define XCAST(xobj) ((struct m0_confx_drive *)(&(xobj)->xo_u))
31 
32 static bool drive_check(const void *bob)
33 {
34  const struct m0_conf_drive *self = bob;
35 
36  M0_PRE(m0_conf_obj_type(&self->ck_obj) == &M0_CONF_DRIVE_TYPE);
37 
38  return true;
39 }
40 
43 
44 static int
45 drive_decode(struct m0_conf_obj *dest, const struct m0_confx_obj *src)
46 {
48  struct m0_confx_drive *s = XCAST(src);
49  struct m0_conf_obj *child;
50  int rc;
51 
52  rc = m0_conf_obj_find(dest->co_cache, &s->xk_sdev, &child);
53  if (rc == 0) {
54  d->ck_sdev = M0_CONF_CAST(child, m0_conf_sdev);
55  /* back pointer to drive objects */
56  d->ck_sdev->sd_drive = dest->co_id;
57  }
58  return M0_RC(conf_pvers_decode(&d->ck_pvers, &s->xk_pvers,
59  dest->co_cache));
60 
61 }
62 
63 static int
64 drive_encode(struct m0_confx_obj *dest, const struct m0_conf_obj *src)
65 {
67  struct m0_confx_drive *d = XCAST(dest);
68 
70  if (s->ck_sdev != NULL)
71  XCAST(dest)->xk_sdev = s->ck_sdev->sd_obj.co_id;
72  return M0_RC(conf_pvers_encode(&d->xk_pvers,
73  (const struct m0_conf_pver**)s->ck_pvers));
74 }
75 
76 static bool
77 drive_match(const struct m0_conf_obj *cached, const struct m0_confx_obj *flat)
78 {
79  const struct m0_confx_drive *xobj = XCAST(flat);
80  const struct m0_conf_sdev *child =
81  M0_CONF_CAST(cached, m0_conf_drive)->ck_sdev;
82 
83  return m0_fid_eq(&child->sd_obj.co_id, &xobj->xk_sdev);
84 }
85 
86 static void drive_delete(struct m0_conf_obj *obj)
87 {
89 
90  m0_conf_drive_bob_fini(x);
91  m0_free(x->ck_pvers);
92  m0_free(x);
93 }
94 
95 static const struct m0_conf_obj_ops drive_ops = {
96  .coo_invariant = drive_invariant,
97  .coo_decode = drive_decode,
98  .coo_encode = drive_encode,
99  .coo_match = drive_match,
100  .coo_lookup = conf_obj_lookup_denied,
101  .coo_readdir = NULL,
102  .coo_downlinks = conf_obj_downlinks_none,
103  .coo_delete = drive_delete
104 };
105 
107 
109  .cot_ftype = {
110  .ft_id = M0_CONF__DRIVE_FT_ID,
111  .ft_name = "conf_drive"
112  },
113  .cot_create = &drive_create,
114  .cot_xt = &m0_confx_drive_xc,
115  .cot_branch = "u_drive",
116  .cot_xc_init = &m0_xc_m0_confx_drive_struct_init,
117  .cot_magic = M0_CONF_DRIVE_MAGIC
118 };
119 
120 #undef XCAST
121 #undef M0_TRACE_SUBSYSTEM
122 
123 /*
124  * Local variables:
125  * c-indentation-style: "K&R"
126  * c-basic-offset: 8
127  * tab-width: 8
128  * fill-column: 80
129  * scroll-step: 1
130  * End:
131  */
132 /*
133  * vim: tabstop=8 shiftwidth=8 noexpandtab textwidth=80 nowrap
134  */
const struct m0_conf_obj_type * m0_conf_obj_type(const struct m0_conf_obj *obj)
Definition: obj.c:363
struct m0_fid co_id
Definition: obj.h:208
M0_INTERNAL const struct m0_fid ** conf_obj_downlinks_none(const struct m0_conf_obj *obj)
Definition: common.c:226
#define M0_PRE(cond)
static int drive_decode(struct m0_conf_obj *dest, const struct m0_confx_obj *src)
Definition: drive.c:45
struct m0_fid_arr xk_pvers
Definition: onwire.h:216
static const struct m0_conf_obj_ops drive_ops
Definition: drive.c:95
#define NULL
Definition: misc.h:38
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
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
struct m0_conf_pver ** ck_pvers
Definition: obj.h:715
static struct foo * obj
Definition: tlist.c:302
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
static int drive_encode(struct m0_confx_obj *dest, const struct m0_conf_obj *src)
Definition: drive.c:64
const struct m0_fid_type cot_ftype
Definition: obj.h:314
#define XCAST(xobj)
Definition: drive.c:29
M0_INTERNAL int conf_pvers_encode(struct m0_fid_arr *dest, const struct m0_conf_pver **src)
Definition: common.c:194
M0_INTERNAL void confx_encode(struct m0_confx_obj *dest, const struct m0_conf_obj *src)
Definition: common.c:110
static bool drive_check(const void *bob)
Definition: drive.c:32
const struct m0_conf_obj_type M0_CONF_DRIVE_TYPE
Definition: drive.c:108
M0_BASSERT(offsetof(struct m0_confx_drive, xk_header)==0)
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
struct m0_conf_sdev * ck_sdev
Definition: obj.h:710
M0_INTERNAL bool m0_fid_eq(const struct m0_fid *fid0, const struct m0_fid *fid1)
Definition: fid.c:164
M0_CONF__INVARIANT_DEFINE(drive_invariant, m0_conf_drive)
struct m0_conf_obj sd_obj
Definition: obj.h:616
M0_CONF__BOB_DEFINE(m0_conf_drive, M0_CONF_DRIVE_MAGIC, drive_check)
struct m0_fid xk_sdev
Definition: onwire.h:215
struct m0_fid sd_drive
Definition: obj.h:628
void m0_free(void *data)
Definition: memory.c:146
static struct m0_addb2_source * s
Definition: consumer.c:39
M0_CONF__CTOR_DEFINE(drive_create, m0_conf_drive, &drive_ops)
struct m0_pdclust_src_addr src
Definition: fd.c:108
struct m0_confx_header xk_header
Definition: onwire.h:120
int32_t rc
Definition: trigger_fop.h:47
static bool drive_match(const struct m0_conf_obj *cached, const struct m0_confx_obj *flat)
Definition: drive.c:77
#define offsetof(typ, memb)
Definition: misc.h:29
static void drive_delete(struct m0_conf_obj *obj)
Definition: drive.c:86