Motr  M0
ping_fom.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012-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 #include "rpc/it/ping_fom.h"
23 #include "rpc/it/ping_fop.h"
24 #include "rpc/it/ping_fop_xc.h"
25 #include "lib/errno.h"
26 #include "lib/memory.h"
27 #include "rpc/rpc.h"
28 #include "fop/fom_generic.h"
29 
30 static int ping_fop_fom_create(struct m0_fop *fop, struct m0_fom **m,
31  struct m0_reqh *reqh);
32 
36  .fo_tick = m0_fom_ping_state,
37  .fo_home_locality = m0_fom_ping_home_locality
38 };
39 
43 };
44 
45 M0_INTERNAL size_t m0_fom_ping_home_locality(const struct m0_fom *fom)
46 {
47  static unsigned loc = 0;
48 
49  M0_PRE(fom != NULL);
50 
51  return loc++;
52 }
53 
57 M0_INTERNAL int m0_fom_ping_state(struct m0_fom *fom)
58 {
59  struct m0_fop_ping_rep *ping_fop_rep;
60  struct m0_rpc_item *item;
61  struct m0_fom_ping *fom_obj;
62  struct m0_fop *fop;
63 
64  fom_obj = container_of(fom, struct m0_fom_ping, fp_gen);
66  M0_ASSERT(fop != NULL);
67  ping_fop_rep = m0_fop_data(fop);
68  ping_fop_rep->fpr_rc = 0;
70  m0_rpc_reply_post(&fom_obj->fp_fop->f_item, item);
72  return M0_FSO_WAIT;
73 }
74 
75 /* Init for ping */
76 static int ping_fop_fom_create(struct m0_fop *fop, struct m0_fom **m,
77  struct m0_reqh *reqh)
78 {
79  struct m0_fom *fom;
80  struct m0_fom_ping *fom_obj;
81 
82  M0_PRE(fop != NULL);
83  M0_PRE(m != NULL);
84 
85  fom_obj= m0_alloc(sizeof(struct m0_fom_ping));
86  if (fom_obj == NULL)
87  return -ENOMEM;
88  fom = &fom_obj->fp_gen;
90  NULL, reqh);
91  fom_obj->fp_fop = fop;
92  *m = fom;
93  return 0;
94 }
95 
96 M0_INTERNAL void m0_fop_ping_fom_fini(struct m0_fom *fom)
97 {
98  struct m0_fom_ping *fom_obj;
99 
100  fom_obj = container_of(fom, struct m0_fom_ping, fp_gen);
101  m0_fom_fini(fom);
102  m0_free(fom_obj);
103 }
104 
107 /*
108  * Local variables:
109  * c-indentation-style: "K&R"
110  * c-basic-offset: 8
111  * tab-width: 8
112  * fill-column: 80
113  * scroll-step: 1
114  * End:
115  */
struct m0_fom_ops m0_fom_ping_ops
Definition: ping_fom.c:34
#define M0_PRE(cond)
#define NULL
Definition: misc.h:38
static struct m0_addb2_mach * m
Definition: consumer.c:38
int(* fto_create)(struct m0_fop *fop, struct m0_fom **out, struct m0_reqh *reqh)
Definition: fom.h:650
void * m0_fop_data(const struct m0_fop *fop)
Definition: fop.c:220
int32_t fpr_rc
Definition: ping_fop.h:58
#define container_of(ptr, type, member)
Definition: misc.h:33
static struct m0_rpc_item * item
Definition: item.c:56
struct m0_fom_type ft_fom_type
Definition: fop.h:232
void m0_fom_init(struct m0_fom *fom, const struct m0_fom_type *fom_type, const struct m0_fom_ops *ops, struct m0_fop *fop, struct m0_fop *reply, struct m0_reqh *reqh)
Definition: fom.c:1372
struct m0_fop_type m0_fop_ping_rep_fopt
Definition: ping_fop.c:35
struct m0_fop_type * f_type
Definition: fop.h:81
void m0_fom_fini(struct m0_fom *fom)
Definition: fom.c:1324
#define M0_ASSERT(cond)
static int ping_fop_fom_create(struct m0_fop *fop, struct m0_fom **m, struct m0_reqh *reqh)
Definition: ping_fom.c:76
const struct m0_fom_type_ops m0_fom_ping_type_ops
Definition: ping_fom.c:41
void * m0_alloc(size_t size)
Definition: memory.c:126
Definition: reqh.h:94
Definition: dump.c:103
void m0_rpc_reply_post(struct m0_rpc_item *request, struct m0_rpc_item *reply)
Definition: rpc.c:135
M0_INTERNAL int m0_fom_ping_state(struct m0_fom *fom)
Definition: ping_fom.c:57
M0_INTERNAL void m0_fop_ping_fom_fini(struct m0_fom *fom)
Definition: ping_fom.c:96
struct m0_fop * m0_fop_reply_alloc(struct m0_fop *req, struct m0_fop_type *rept)
Definition: fop.c:129
Definition: fom.h:481
M0_INTERNAL size_t m0_fom_ping_home_locality(const struct m0_fom *fom)
Definition: ping_fom.c:45
struct m0_reqh reqh
Definition: rm_foms.c:48
struct m0_fom fp_gen
Definition: ping_fom.h:36
struct m0_rpc_item * m0_fop_to_rpc_item(const struct m0_fop *fop)
Definition: fop.c:338
static struct m0_fop * fop
Definition: item.c:57
void(* fo_fini)(struct m0_fom *fom)
Definition: fom.h:657
void m0_fom_phase_set(struct m0_fom *fom, int phase)
Definition: fom.c:1688
void m0_free(void *data)
Definition: memory.c:146
struct m0_rpc_item f_item
Definition: fop.h:83
struct m0_fop * fp_fop
Definition: ping_fom.h:38
Definition: fop.h:79