Motr  M0
cs_service.c
Go to the documentation of this file.
1 /* -*- C -*- */
2 /*
3  * Copyright (c) 2011-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 #include "lib/errno.h"
24 #include "lib/memory.h"
25 
26 #include "reqh/reqh_service.h"
27 #include "ut/cs_fop.h"
28 
29 static int ds1_service_start(struct m0_reqh_service *service);
30 static int ds2_service_start(struct m0_reqh_service *service);
31 static void ds1_service_stop(struct m0_reqh_service *service);
32 static void ds2_service_stop(struct m0_reqh_service *service);
33 static int ds1_service_allocate(struct m0_reqh_service **service,
34  const struct m0_reqh_service_type *stype);
35 static int ds2_service_allocate(struct m0_reqh_service **service,
36  const struct m0_reqh_service_type *stype);
37 static void ds_service_fini(struct m0_reqh_service *service);
38 
41 };
42 
45 };
46 
47 static const struct m0_reqh_service_ops ds1_service_ops = {
49  .rso_start_async = m0_reqh_service_async_start_simple,
50  .rso_stop = ds1_service_stop,
51  .rso_fini = ds_service_fini
52 };
53 
54 static const struct m0_reqh_service_ops ds2_service_ops = {
56  .rso_stop = ds2_service_stop,
57  .rso_fini = ds_service_fini
58 };
59 
61  .rst_name = "M0_CST_DS1",
62  .rst_ops = &ds1_service_type_ops,
63  .rst_level = M0_RS_LEVEL_NORMAL,
64 };
65 
67  .rst_name = "M0_CST_DS2",
68  .rst_ops = &ds2_service_type_ops,
69  .rst_level = M0_RS_LEVEL_NORMAL,
70 };
71 
75 };
76 
78 
79 static int _ds_alloc(struct m0_reqh_service **service,
80  const struct m0_reqh_service_type *stype,
81  const struct m0_reqh_service_ops *ops)
82 {
83  struct m0_reqh_service *s;
84 
85  M0_PRE(stype != NULL && service != NULL && ops != NULL);
86 
87  M0_ALLOC_PTR(s);
88  if (s == NULL)
89  return -ENOMEM;
90 
91  s->rs_type = stype;
92  s->rs_ops = ops;
93  *service = s;
94 
95  return 0;
96 }
97 
99  const struct m0_reqh_service_type *stype)
100 {
102 }
103 
105  const struct m0_reqh_service_type *stype)
106 {
108 }
109 
111 {
112  int rc;
113 
114  M0_PRE(service != NULL);
115 
116  /*Initialise service fops.*/
118  M0_ASSERT(rc == 0);
119 
120  return rc;
121 }
122 
124 {
125  int rc;
126 
127  M0_PRE(service != NULL);
128 
129  /*Initialise service fops.*/
131  M0_ASSERT(rc == 0);
132 
133  return rc;
134 }
135 
137 {
138 
139  M0_PRE(service != NULL);
140 
141  /* Finalise service fops */
143 }
144 
146 {
147 
148  M0_PRE(service != NULL);
149 
150  /* Finalise service fops */
152 }
153 
155 {
156  M0_PRE(service != NULL);
157 
158  m0_free(service);
159 }
160 
162 {
163  int i;
164  int rc = 0;
165 
166  for (i = 0; i < m0_cs_default_stypes_nr; ++i) {
168  if (rc != 0)
169  break;
170  }
171  return rc;
172 }
173 
175 {
176  int i;
177 
178  for (i = 0; i < m0_cs_default_stypes_nr; ++i)
180 }
181 
182 /*
183  * Local variables:
184  * c-indentation-style: "K&R"
185  * c-basic-offset: 8
186  * tab-width: 8
187  * fill-column: 80
188  * scroll-step: 1
189  * End:
190  */
static void ds1_service_stop(struct m0_reqh_service *service)
Definition: cs_service.c:136
static int ds2_service_start(struct m0_reqh_service *service)
Definition: cs_service.c:123
#define M0_PRE(cond)
int(* rso_start)(struct m0_reqh_service *service)
Definition: reqh_service.h:360
void m0_cs_ut_ds1_fop_fini(void)
Definition: cs_fop.c:122
#define NULL
Definition: misc.h:38
int m0_cs_default_stypes_init(void)
Definition: cs_service.c:161
int m0_cs_ut_ds2_fop_init(void)
Definition: cs_fop.c:161
static void ds_service_fini(struct m0_reqh_service *service)
Definition: cs_service.c:154
int m0_reqh_service_type_register(struct m0_reqh_service_type *rstype)
Definition: reqh_service.c:473
struct m0_reqh_service_type ds2_service_type
Definition: cs_service.c:66
static void ds2_service_stop(struct m0_reqh_service *service)
Definition: cs_service.c:145
int i
Definition: dir.c:1033
static const struct m0_reqh_service_type_ops ds1_service_type_ops
Definition: cs_service.c:39
static const struct socktype stype[]
Definition: sock.c:1156
#define M0_ASSERT(cond)
const char * rst_name
Definition: reqh_service.h:447
static int _ds_alloc(struct m0_reqh_service **service, const struct m0_reqh_service_type *stype, const struct m0_reqh_service_ops *ops)
Definition: cs_service.c:79
static int ds1_service_start(struct m0_reqh_service *service)
Definition: cs_service.c:110
int m0_cs_ut_ds1_fop_init(void)
Definition: cs_fop.c:129
void m0_cs_ut_ds2_fop_fini(void)
Definition: cs_fop.c:154
static int ds1_service_allocate(struct m0_reqh_service **service, const struct m0_reqh_service_type *stype)
Definition: cs_service.c:98
int m0_reqh_service_async_start_simple(struct m0_reqh_service_start_async_ctx *asc)
Definition: reqh_service.c:601
int(* rsto_service_allocate)(struct m0_reqh_service **service, const struct m0_reqh_service_type *stype)
Definition: reqh_service.h:435
#define M0_ALLOC_PTR(ptr)
Definition: memory.h:86
static const struct m0_reqh_service_type_ops ds2_service_type_ops
Definition: cs_service.c:43
struct m0_reqh_service_type * m0_cs_default_stypes[]
Definition: cs_service.c:72
static const struct m0_reqh_service_ops ds2_service_ops
Definition: cs_service.c:54
const size_t m0_cs_default_stypes_nr
Definition: cs_service.c:77
struct m0_fom_ops ops
Definition: io_foms.c:623
void m0_free(void *data)
Definition: memory.c:146
static struct m0_addb2_source * s
Definition: consumer.c:39
void m0_reqh_service_type_unregister(struct m0_reqh_service_type *rstype)
Definition: reqh_service.c:490
static struct m0_reqh_service * service[REQH_IN_UT_MAX]
Definition: long_lock_ut.c:46
static const struct m0_reqh_service_ops ds1_service_ops
Definition: cs_service.c:47
int32_t rc
Definition: trigger_fop.h:47
#define ARRAY_SIZE(a)
Definition: misc.h:45
struct m0_reqh_service_type ds1_service_type
Definition: cs_service.c:60
static int ds2_service_allocate(struct m0_reqh_service **service, const struct m0_reqh_service_type *stype)
Definition: cs_service.c:104
void m0_cs_default_stypes_fini(void)
Definition: cs_service.c:174