Motr  M0
sd_release_fom.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_FDMI
24 #include "lib/trace.h"
25 
26 #include "lib/memory.h"
27 #include "ut/ut.h"
28 struct m0_rpc_conn;
29 #include "rpc/rpc_machine_internal.h" /* m0_rpc_machine_lock */
30 #include "rpc/session_internal.h" /* m0_rpc_session_hold_busy */
31 #include "rpc/item_internal.h" /* m0_rpc_item_sm_init */
32 #include "fdmi/fdmi.h"
33 #include "fdmi/service.h" /* m0_reqh_fdmi_service */
35 #include "fdmi/fops.h" /* m0_fop_fdmi_rec_release */
36 
37 #include "fdmi/ut/sd_common.h"
38 
39 M0_TL_DESCR_DECLARE(fdmi_record_inflight, M0_EXTERN);
40 M0_TL_DECLARE(fdmi_record_inflight, M0_EXTERN, struct m0_fdmi_src_rec);
41 
42 static struct test_rpc_env g_rpc_env;
44 
45 static int test_packet_ready(struct m0_rpc_packet *p);
46 
47 static const struct m0_rpc_frm_ops test_frm_ops = {
49 };
50 
51 
52 static struct m0_semaphore g_sem;
53 static struct m0_semaphore g_sem2;
54 static struct m0_semaphore g_sem3;
55 static struct m0_uint128 rec_id_to_release = M0_UINT128(0xDEAD, 0xBEEF);
56 static struct m0_fdmi_src_rec g_src_rec;
57 static int g_refcount;
58 
59 static int test_fs_node_eval(
60  struct m0_fdmi_src_rec *src_rec,
61  struct m0_fdmi_flt_var_node *value_desc,
62  struct m0_fdmi_flt_operand *value)
63 {
64  M0_UT_ASSERT(false);
65  return 0;
66 }
67 
68 static int test_fs_encode(struct m0_fdmi_src_rec *src_rec,
69  struct m0_buf *buf)
70 {
71  M0_UT_ASSERT(false);
72  return 0;
73 }
74 
75 static void test_fs_get(struct m0_fdmi_src_rec *src_rec)
76 {
77  ++g_refcount;
78 }
79 
80 static void test_fs_put(struct m0_fdmi_src_rec *src_rec)
81 {
82  M0_UT_ASSERT(src_rec != NULL);
89  --g_refcount;
90  if (g_refcount == 0)
92 }
93 
94 static struct m0_fdmi_src *src_alloc()
95 {
96  struct m0_fdmi_src *src;
97  int rc;
98 
100  M0_UT_ASSERT(rc == 0);
101 
102  src->fs_encode = test_fs_encode;
103  src->fs_get = test_fs_get;
104  src->fs_put = test_fs_put;
105  src->fs_node_eval = test_fs_node_eval;
106  return src;
107 }
108 
110 {
112 
114  return 0;
115 }
116 
117 static void my_fop_release(struct m0_ref *ref)
118 {
119  /* call Motr default fop release */
120  m0_fop_release(ref);
122 }
124 {
125  int rc;
126  struct m0_fop *fop;
127  struct m0_fop_fdmi_rec_release *fop_data;
128  struct m0_reqh *reqh;
129  struct m0_rpc_item *rpc_item;
130 
131  M0_ENTRY();
132 
134 
136  &env->tre_rpc_machine);
137  M0_UT_ASSERT(fop != NULL);
138 
139  /* Overwrite to use my own fop release */
141 
142  fop_data = m0_fop_data(fop);
143  fop_data->frr_frid = rec_id_to_release;
144  fop_data->frr_frt = M0_FDMI_REC_TYPE_TEST;
145  rpc_item = &fop->f_item;
146 
149 
150  rpc_item->ri_session = env->tre_session;
151 
155 
159 
162 
163  M0_LEAVE();
164  return rc;
165 }
166 
167 static void g_src_rec_free(struct m0_ref *ref)
168 {
169 }
171 {
172  struct m0_fdmi_src *src = src_alloc();
173  int rc;
174  static struct m0_rpc_conn rpc_conn;
175  static struct m0_rpc_session rpc_session;
176  bool ok;
177  struct m0_fdmi_src_dock *src_dock = m0_fdmi_src_dock_get();
178 
179  M0_ENTRY();
180 
183  &test_frm_ops, false, &rpc_conn, &rpc_session);
188  M0_UT_ASSERT(rc == 0);
194  fdmi_record_inflight_tlist_add_tail(
195  &src_dock->fsdc_rec_inflight, &g_src_rec);
198  M0_UT_ASSERT(rc == 0);
199 
205  M0_UT_ASSERT(ok);
206 
212  M0_UT_ASSERT(ok);
216  M0_UT_ASSERT(ok);
223  M0_UT_ASSERT(ok);
227  M0_LEAVE();
228 }
229 
230 
231 #undef M0_TRACE_SUBSYSTEM
232 
233 /*
234  * Local variables:
235  * c-indentation-style: "K&R"
236  * c-basic-offset: 8
237  * tab-width: 8
238  * fill-column: 80
239  * scroll-step: 1
240  * End:
241  */
242 /*
243  * vim: tabstop=8 shiftwidth=8 noexpandtab textwidth=80 nowrap
244  */
M0_INTERNAL int m0_uint128_cmp(const struct m0_uint128 *u0, const struct m0_uint128 *u1)
Definition: misc.c:45
struct m0_motr motr
Definition: sd_common.h:41
static void my_fop_release(struct m0_ref *ref)
static struct m0_addb2_philter p
Definition: consumer.c:40
void fdmi_sd_release_fom(void)
int imitate_release_fop_recv(struct test_rpc_env *env)
M0_INTERNAL void m0_rpc_item_change_state(struct m0_rpc_item *item, enum m0_rpc_item_state state)
Definition: item.c:728
#define NULL
Definition: misc.h:38
static struct m0_semaphore g_sem2
struct fdmi_sd_ut_ctx g_sd_ut
Definition: sd_common.c:41
M0_INTERNAL bool m0_semaphore_timeddown(struct m0_semaphore *semaphore, const m0_time_t abs_timeout)
Definition: semaphore.c:75
M0_LEAVE()
M0_INTERNAL int m0_reqh_fop_handle(struct m0_reqh *reqh, struct m0_fop *fop)
Definition: reqh.c:546
static int test_fs_node_eval(struct m0_fdmi_src_rec *src_rec, struct m0_fdmi_flt_var_node *value_desc, struct m0_fdmi_flt_operand *value)
struct m0_uint128 fsr_rec_id
Definition: src_rec.h:80
struct m0_rpc_machine tre_rpc_machine
Definition: sd_common.h:56
M0_INTERNAL void m0_fdmi__record_init(struct m0_fdmi_src_rec *src_rec)
Definition: source_dock.c:155
static struct m0_fdmi_src_rec g_src_rec
int const char const void * value
Definition: dir.c:325
void * m0_fop_data(const struct m0_fop *fop)
Definition: fop.c:220
M0_INTERNAL void m0_fdmi_source_free(struct m0_fdmi_src *src)
Definition: source_dock.c:301
m0_fdmi_rec_type_id_t frr_frt
Definition: fops.h:95
static struct m0_rpc_packet * g_sent_rpc_packet
Definition: sock.c:887
M0_INTERNAL void m0_fdmi__fs_get(struct m0_fdmi_src_rec *src_rec)
Definition: source_dock.c:388
static struct m0_semaphore g_sem3
struct m0_ref fsr_ref
Definition: src_rec.h:87
static const struct m0_rpc_frm_ops test_frm_ops
struct m0_fdmi_src * fsr_src
Definition: src_rec.h:72
void fdmi_serv_start_ut(const struct m0_filterc_ops *filterc_ops)
Definition: sd_common.c:66
#define M0_ENTRY(...)
Definition: trace.h:170
Definition: buf.h:37
M0_INTERNAL int m0_fdmi_source_alloc(enum m0_fdmi_rec_type_id type_id, struct m0_fdmi_src **src)
Definition: source_dock.c:285
void m0_fop_rpc_machine_set(struct m0_fop *fop, struct m0_rpc_machine *mach)
Definition: fop.c:352
static struct m0_semaphore g_sem
struct m0_uint128 frr_frid
Definition: fops.h:94
void m0_ref_init(struct m0_ref *ref, int init_num, void(*release)(struct m0_ref *ref))
Definition: refs.c:24
M0_INTERNAL void m0_rpc_machine_unlock(struct m0_rpc_machine *machine)
Definition: rpc_machine.c:558
Definition: refs.h:34
M0_INTERNAL void m0_rpc_session_hold_busy(struct m0_rpc_session *session)
Definition: session.c:782
M0_INTERNAL void m0_rpc_item_sm_init(struct m0_rpc_item *item, enum m0_rpc_item_dir dir)
Definition: item.c:704
M0_INTERNAL void m0_fdmi_source_deregister(struct m0_fdmi_src *src)
Definition: source_dock.c:337
struct m0_reqh rc_reqh
Definition: setup.h:312
M0_INTERNAL struct m0_fdmi_src_dock * m0_fdmi_src_dock_get(void)
Definition: fdmi.c:890
M0_INTERNAL int m0_fdmi_source_register(struct m0_fdmi_src *src)
Definition: source_dock.c:311
struct m0_fop_type m0_fop_fdmi_rec_release_fopt
Definition: fops.c:49
static int g_refcount
M0_INTERNAL int m0_semaphore_init(struct m0_semaphore *semaphore, unsigned value)
Definition: semaphore.c:38
struct m0_rpc_session * tre_session
Definition: sd_common.h:54
int(* fo_packet_ready)(struct m0_rpc_packet *p)
Definition: reqh.h:94
static struct m0_uint128 rec_id_to_release
M0_TL_DESCR_DECLARE(fdmi_record_inflight, M0_EXTERN)
M0_INTERNAL void m0_fdmi__rec_id_gen(struct m0_fdmi_src_rec *src_rec)
Definition: source_dock.c:186
void fdmi_serv_stop_ut(void)
Definition: sd_common.c:121
static struct test_rpc_env g_rpc_env
struct m0_tl fsdc_rec_inflight
struct m0_reqh reqh
Definition: rm_foms.c:48
void prepare_rpc_env(struct test_rpc_env *env, struct m0_reqh *reqh, const struct m0_rpc_frm_ops *frm_ops, bool sender, struct m0_rpc_conn *rpc_conn, struct m0_rpc_session *rpc_session)
Definition: sd_common.c:171
struct m0_reqh_context cc_reqh_ctx
Definition: setup.h:361
struct m0_ref f_ref
Definition: fop.h:80
M0_INTERNAL void m0_rpc_machine_lock(struct m0_rpc_machine *machine)
Definition: rpc_machine.c:551
M0_INTERNAL void m0_fop_release(struct m0_ref *ref)
Definition: fop.c:148
M0_INTERNAL void m0_semaphore_fini(struct m0_semaphore *semaphore)
Definition: semaphore.c:45
m0_time_t m0_time_from_now(uint64_t secs, long ns)
Definition: time.c:96
void unprepare_rpc_env(struct test_rpc_env *env)
Definition: sd_common.c:241
static void test_fs_get(struct m0_fdmi_src_rec *src_rec)
struct m0_rpc_session * ri_session
Definition: item.h:147
void m0_fop_put_lock(struct m0_fop *fop)
Definition: fop.c:199
static struct m0_fop * fop
Definition: item.c:57
static void g_src_rec_free(struct m0_ref *ref)
void fdmi_ut_packet_send_failed(struct m0_rpc_machine *mach, struct m0_rpc_packet *p)
Definition: sd_common.c:154
M0_INTERNAL void m0_fdmi__record_deinit(struct m0_fdmi_src_rec *src_rec)
Definition: source_dock.c:174
#define M0_UINT128(hi, lo)
Definition: types.h:40
const struct m0_filterc_ops filterc_stub_ops
Definition: filterc_stub.c:43
static int test_fs_encode(struct m0_fdmi_src_rec *src_rec, struct m0_buf *buf)
static void test_fs_put(struct m0_fdmi_src_rec *src_rec)
M0_INTERNAL void m0_semaphore_up(struct m0_semaphore *semaphore)
Definition: semaphore.c:65
static int test_packet_ready(struct m0_rpc_packet *p)
struct m0_rpc_item f_item
Definition: fop.h:83
struct m0_pdclust_src_addr src
Definition: fd.c:108
static struct m0_fdmi_src * src_alloc()
int32_t rc
Definition: trigger_fop.h:47
#define M0_UT_ASSERT(a)
Definition: ut.h:46
M0_TL_DECLARE(fdmi_record_inflight, M0_EXTERN, struct m0_fdmi_src_rec)
Definition: fop.h:79
struct m0_fop * m0_fop_alloc(struct m0_fop_type *fopt, void *data, struct m0_rpc_machine *mach)
Definition: fop.c:96