Motr  M0
process.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_process_xc */
27 #include "motr/magic.h" /* M0_CONF_PROCESS_MAGIC */
28 
29 #define XCAST(xobj) ((struct m0_confx_process *)(&(xobj)->xo_u))
31 
32 static bool process_check(const void *bob)
33 {
34  const struct m0_conf_process *self = bob;
35  const struct m0_conf_obj *self_obj = &self->pc_obj;
36 
38 
39  return m0_conf_obj_is_stub(self_obj) || _0C(self->pc_endpoint != NULL);
40 }
41 
43 M0_CONF__INVARIANT_DEFINE(process_invariant, m0_conf_process);
44 
45 static size_t _bitmap_width(const struct m0_bitmap_onwire *bow)
46 {
47  return bow->bo_size * CHAR_BIT * sizeof bow->bo_words[0];
48 }
49 
50 static int
52 {
53  int rc;
55  const struct m0_confx_process *s = XCAST(src);
56 
57  rc = m0_bitmap_init(&d->pc_cores, _bitmap_width(&s->xr_cores));
58  if (rc != 0)
59  return M0_ERR(rc);
60  m0_bitmap_load(&s->xr_cores, &d->pc_cores);
61 
62  d->pc_memlimit_as = s->xr_mem_limit_as;
63  d->pc_memlimit_rss = s->xr_mem_limit_rss;
64  d->pc_memlimit_stack = s->xr_mem_limit_stack;
65  d->pc_memlimit_memlock = s->xr_mem_limit_memlock;
66 
67  d->pc_endpoint = m0_buf_strdup(&s->xr_endpoint);
68  if (d->pc_endpoint == NULL) {
70  return M0_ERR(-ENOMEM);
71  }
72  return M0_RC(m0_conf_dir_new(dest, &M0_CONF_PROCESS_SERVICES_FID,
73  &M0_CONF_SERVICE_TYPE, &s->xr_services,
74  &d->pc_services));
75 }
76 
77 static int
79 {
80  int rc;
82  struct m0_confx_process *d = XCAST(dest);
83 
85 
86  rc = m0_bitmap_onwire_init(&d->xr_cores, s->pc_cores.b_nr);
87  if (rc != 0)
88  return M0_ERR(rc);
89  if (s->pc_cores.b_words != NULL)
90  m0_bitmap_store(&s->pc_cores, &d->xr_cores);
91 
92  d->xr_mem_limit_as = s->pc_memlimit_as;
93  d->xr_mem_limit_rss = s->pc_memlimit_rss;
94  d->xr_mem_limit_stack = s->pc_memlimit_stack;
95  d->xr_mem_limit_memlock = s->pc_memlimit_memlock;
96  return M0_RC((s->pc_endpoint == NULL ? 0 :
98  &M0_BUF_INITS((char *)s->pc_endpoint))) ?:
99  arrfid_from_dir(&d->xr_services, s->pc_services));
100 }
101 
102 static bool
103 process_match(const struct m0_conf_obj *cached, const struct m0_confx_obj *flat)
104 {
105  const struct m0_confx_process *xobj = XCAST(flat);
106  const struct m0_conf_process *obj =
107  M0_CONF_CAST(cached, m0_conf_process);
108 
109  return obj->pc_memlimit_as == xobj->xr_mem_limit_as &&
110  obj->pc_memlimit_rss == xobj->xr_mem_limit_rss &&
111  obj->pc_memlimit_stack == xobj->xr_mem_limit_stack &&
112  obj->pc_memlimit_memlock == xobj->xr_mem_limit_memlock &&
113  m0_buf_streq(&xobj->xr_endpoint, obj->pc_endpoint) &&
114  m0_conf_dir_elems_match(obj->pc_services, &xobj->xr_services);
115 }
116 
117 static int process_lookup(const struct m0_conf_obj *parent,
118  const struct m0_fid *name, struct m0_conf_obj **out)
119 {
120  struct m0_conf_process *proc = M0_CONF_CAST(parent, m0_conf_process);
121  const struct conf_dir_relation dirs[] = {
122  { proc->pc_services, &M0_CONF_PROCESS_SERVICES_FID }
123  };
124 
125  M0_PRE(parent->co_status == M0_CS_READY);
126  return M0_RC(conf_dirs_lookup(out, name, dirs, ARRAY_SIZE(dirs)));
127 }
128 
129 static const struct m0_fid **process_downlinks(const struct m0_conf_obj *obj)
130 {
131  static const struct m0_fid *rels[] = { &M0_CONF_PROCESS_SERVICES_FID,
132  NULL };
134  return rels;
135 }
136 
137 static void process_delete(struct m0_conf_obj *obj)
138 {
140 
141  m0_free((void *)x->pc_endpoint);
142  m0_conf_process_bob_fini(x);
143  if (x->pc_cores.b_nr != 0)
144  m0_bitmap_fini(&x->pc_cores);
145  m0_free(x);
146 }
147 
148 static const struct m0_conf_obj_ops process_ops = {
149  .coo_invariant = process_invariant,
150  .coo_decode = process_decode,
151  .coo_encode = process_encode,
152  .coo_match = process_match,
153  .coo_lookup = process_lookup,
154  .coo_readdir = NULL,
155  .coo_downlinks = process_downlinks,
156  .coo_delete = process_delete
157 };
158 
160 
162  .cot_ftype = {
163  .ft_id = M0_CONF__PROCESS_FT_ID,
164  .ft_name = "conf_process",
165  },
166  .cot_create = &process_create,
167  .cot_xt = &m0_confx_process_xc,
168  .cot_branch = "u_process",
169  .cot_xc_init = &m0_xc_m0_confx_process_struct_init,
170  .cot_magic = M0_CONF_PROCESS_MAGIC
171 };
172 
173 #undef XCAST
174 #undef M0_TRACE_SUBSYSTEM
175 
176 /*
177  * Local variables:
178  * c-indentation-style: "K&R"
179  * c-basic-offset: 8
180  * tab-width: 8
181  * fill-column: 80
182  * scroll-step: 1
183  * End:
184  */
185 /*
186  * vim: tabstop=8 shiftwidth=8 noexpandtab textwidth=80 nowrap
187  */
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
const char * pc_endpoint
Definition: obj.h:590
#define M0_PRE(cond)
M0_INTERNAL int m0_bitmap_init(struct m0_bitmap *map, size_t nr)
Definition: bitmap.c:86
static int process_lookup(const struct m0_conf_obj *parent, const struct m0_fid *name, struct m0_conf_obj **out)
Definition: process.c:117
#define NULL
Definition: misc.h:38
struct m0_buf xr_endpoint
Definition: onwire.h:158
M0_INTERNAL void m0_bitmap_fini(struct m0_bitmap *map)
Definition: bitmap.c:97
static const struct m0_conf_obj_ops process_ops
Definition: process.c:148
static bool process_check(const void *bob)
Definition: process.c:32
static bool x
Definition: sm.c:168
uint64_t xr_mem_limit_as
Definition: onwire.h:154
uint64_t pc_memlimit_memlock
Definition: obj.h:588
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
const struct m0_conf_obj_type M0_CONF_SERVICE_TYPE
Definition: service.c:156
bool(* coo_invariant)(const struct m0_conf_obj *obj)
Definition: obj_ops.h:79
M0_CONF__BOB_DEFINE(m0_conf_process, M0_CONF_PROCESS_MAGIC, process_check)
M0_INTERNAL bool m0_conf_obj_is_stub(const struct m0_conf_obj *obj)
Definition: obj.c:302
uint64_t xr_mem_limit_memlock
Definition: onwire.h:157
static struct foo * obj
Definition: tlist.c:302
M0_BASSERT(offsetof(struct m0_confx_process, xr_header)==0)
static bool process_match(const struct m0_conf_obj *cached, const struct m0_confx_obj *flat)
Definition: process.c:103
uint64_t pc_memlimit_as
Definition: obj.h:585
return M0_RC(rc)
M0_INTERNAL void m0_bitmap_store(const struct m0_bitmap *im_map, struct m0_bitmap_onwire *ow_map)
Definition: bitmap.c:200
struct m0_fid_arr xr_services
Definition: onwire.h:159
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
uint64_t xr_mem_limit_stack
Definition: onwire.h:156
uint64_t pc_memlimit_stack
Definition: obj.h:587
return M0_ERR(-EOPNOTSUPP)
const char * name
Definition: trace.c:110
const struct m0_fid_type cot_ftype
Definition: obj.h:314
M0_INTERNAL int m0_bitmap_onwire_init(struct m0_bitmap_onwire *ow_map, size_t nr)
Definition: bitmap.c:182
#define XCAST(xobj)
Definition: process.c:29
struct m0_confx_header xr_header
Definition: onwire.h:120
static size_t _bitmap_width(const struct m0_bitmap_onwire *bow)
Definition: process.c:45
uint64_t * bo_words
Definition: bitmap.h:53
M0_INTERNAL void confx_encode(struct m0_confx_obj *dest, const struct m0_conf_obj *src)
Definition: common.c:110
size_t bo_size
Definition: bitmap.h:51
#define M0_BUF_INITS(str)
Definition: buf.h:70
struct m0_bitmap pc_cores
Definition: obj.h:584
#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
uint64_t xr_mem_limit_rss
Definition: onwire.h:155
M0_INTERNAL int m0_buf_copy(struct m0_buf *dest, const struct m0_buf *src)
Definition: buf.c:104
static int process_decode(struct m0_conf_obj *dest, const struct m0_confx_obj *src)
Definition: process.c:51
struct m0_bitmap_onwire xr_cores
Definition: onwire.h:153
struct m0_conf_dir * pc_services
Definition: obj.h:582
M0_INTERNAL char * m0_buf_strdup(const struct m0_buf *buf)
Definition: buf.c:140
static int process_encode(struct m0_confx_obj *dest, const struct m0_conf_obj *src)
Definition: process.c:78
Definition: fid.h:38
#define _0C(exp)
Definition: assert.h:311
enum m0_conf_status co_status
Definition: obj.h:210
const struct m0_conf_obj_type M0_CONF_PROCESS_TYPE
Definition: process.c:161
#define out(...)
Definition: gen.c:41
#define CHAR_BIT
Definition: misc.h:32
static const struct m0_fid ** process_downlinks(const struct m0_conf_obj *obj)
Definition: process.c:129
M0_CONF__CTOR_DEFINE(process_create, m0_conf_process, &process_ops)
M0_INTERNAL void m0_bitmap_load(const struct m0_bitmap_onwire *ow_map, struct m0_bitmap *im_map)
Definition: bitmap.c:213
void m0_free(void *data)
Definition: memory.c:146
static struct m0_addb2_source * s
Definition: consumer.c:39
uint64_t pc_memlimit_rss
Definition: obj.h:586
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
#define offsetof(typ, memb)
Definition: misc.h:29
static void process_delete(struct m0_conf_obj *obj)
Definition: process.c:137
M0_CONF__INVARIANT_DEFINE(process_invariant, m0_conf_process)