Motr  M0
console_fom.c
Go to the documentation of this file.
1 /* -*- C -*- */
2 /*
3  * Copyright (c) 2012-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" /* EINVAL */
24 #include "lib/memory.h" /* M0_ALLOC_PTR */
25 #include "fop/fom_generic.h" /* M0_FOPH_FAILURE */
26 
27 #include "console/console_fom.h"
28 #include "console/console_fop.h"
29 #include "console/console_fop_xc.h"
30 #include "rpc/rpc.h"
31 
32 #define M0_TRACE_SUBSYSTEM M0_TRACE_SUBSYS_CONSOLE
33 #include "lib/trace.h"
34 
40 static int console_fom_create(struct m0_fop *fop, struct m0_reqh *reqh,
41  const struct m0_fom_ops *fom_ops,
42  struct m0_fom **m)
43 {
44  struct m0_fom *fom;
45  struct m0_fop *rep_fop;
46 
47  M0_PRE(fop != NULL);
48  M0_PRE(m != NULL);
49 
50  /*
51  * XXX
52  * The proper way to do this is to do
53  * struct m0_cons_fom {
54  * struct m0_fom cf_fom;
55  * struct m0_fop cf_reply;
56  * struct m0_cons_fop_reply cf_reply_data;
57  * };
58  * Then fom, reply fop and its data packet can be allocated at once,
59  * simplifying memory management.
60  */
62  if (fom == NULL)
63  return M0_ERR(-ENOMEM);
65  if (rep_fop == NULL) {
66  m0_free(fom);
67  return M0_ERR(-ENOMEM);
68  }
69 
77  fom_ops, fop, rep_fop, reqh);
78  *m = fom;
79 
80  return 0;
81 }
82 
83 static size_t console_fom_home_locality(const struct m0_fom *fom)
84 {
85  M0_PRE(fom != NULL);
86 
87  return m0_fop_opcode(fom->fo_fop);
88 }
89 
90 static void console_fom_fini(struct m0_fom *fom)
91 {
93  m0_free(fom);
94 }
95 
96 static int console_device_fom_create(struct m0_fop *fop, struct m0_fom **m,
97  struct m0_reqh *reqh)
98 {
99  M0_PRE(fop != NULL);
100  M0_PRE(m != NULL);
102 
104 }
105 
106 static int console_fom_tick(struct m0_fom *fom)
107 {
109  struct m0_rpc_item *reply_item;
110  struct m0_rpc_item *req_item;
111  struct m0_fop *fop;
112  struct m0_fop *rfop;
113 
114  M0_PRE(fom != NULL && fom->fo_fop != NULL && fom->fo_rep_fop != NULL);
115 
116  fop = fom->fo_fop;
117  rfop = fom->fo_rep_fop;
118 
119 
120  /* Reply fop */
121  reply_fop = m0_fop_data(rfop);
122  if (reply_fop == NULL) {
124  return M0_FSO_AGAIN;
125  }
126 
127  /* Request item */
128  req_item = &fop->f_item;
129 
130  /* Set reply FOP */
131  reply_fop->cons_notify_type = req_item->ri_type->rit_opcode;
132  reply_fop->cons_return = 0;
133 
134  /* Reply item */
135  reply_item = &rfop->f_item;
137  m0_rpc_reply_post(req_item, reply_item);
138  return M0_FSO_WAIT;
139 }
140 
143  .fo_fini = console_fom_fini,
144  .fo_home_locality = console_fom_home_locality
145 };
146 
149 };
150 
151 static int console_test_fom_create(struct m0_fop *fop,
152  struct m0_fom **m,
153  struct m0_reqh *reqh)
154 {
155  M0_PRE(fop != NULL);
156  M0_PRE(m != NULL);
158 
160 }
161 
164  .fo_tick = console_fom_tick,
165  .fo_home_locality = console_fom_home_locality
166 };
167 
170 };
171 
172 #undef M0_TRACE_SUBSYSTEM
173 
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  */
static size_t console_fom_home_locality(const struct m0_fom *fom)
Definition: console_fom.c:83
uint32_t rit_opcode
Definition: item.h:474
uint32_t m0_fop_opcode(const struct m0_fop *fop)
Definition: fop.c:226
#define M0_PRE(cond)
#define NULL
Definition: misc.h:38
static struct m0_addb2_mach * m
Definition: consumer.c:38
int(* fo_tick)(struct m0_fom *fom)
Definition: fom.h:663
struct m0_fop_type m0_cons_fop_reply_fopt
Definition: console_fop.c:39
struct m0_fop_type m0_cons_fop_test_fopt
Definition: console_fop.c:40
int(* fto_create)(struct m0_fop *fop, struct m0_fom **out, struct m0_reqh *reqh)
Definition: fom.h:650
struct m0_fop_type m0_cons_fop_device_fopt
Definition: console_fop.c:38
void * m0_fop_data(const struct m0_fop *fop)
Definition: fop.c:220
static void console_fom_fini(struct m0_fom *fom)
Definition: console_fom.c:90
struct m0_fom_type ft_fom_type
Definition: fop.h:232
const struct m0_fom_type_ops m0_console_fom_type_device_ops
Definition: console_fom.c:147
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 * f_type
Definition: fop.h:81
return M0_ERR(-EOPNOTSUPP)
const struct m0_fom_type_ops m0_console_fom_type_test_ops
Definition: console_fom.c:168
void m0_fom_fini(struct m0_fom *fom)
Definition: fom.c:1324
static struct m0_fop reply_fop
Definition: fsync.c:64
static int console_test_fom_create(struct m0_fop *fop, struct m0_fom **m, struct m0_reqh *reqh)
Definition: console_fom.c:151
const struct m0_rpc_item_type * ri_type
Definition: item.h:200
Definition: reqh.h:94
Definition: dump.c:103
struct m0_fom_ops m0_console_fom_test_ops
Definition: console_fom.c:162
void m0_rpc_reply_post(struct m0_rpc_item *request, struct m0_rpc_item *reply)
Definition: rpc.c:135
static int console_fom_tick(struct m0_fom *fom)
Definition: console_fom.c:106
struct m0_fop * m0_fop_reply_alloc(struct m0_fop *req, struct m0_fop_type *rept)
Definition: fop.c:129
Definition: fom.h:481
struct m0_reqh reqh
Definition: rm_foms.c:48
#define M0_ALLOC_PTR(ptr)
Definition: memory.h:86
const struct m0_fom_ops m0_console_fom_device_ops
Definition: console_fom.c:141
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
static int console_device_fom_create(struct m0_fop *fop, struct m0_fom **m, struct m0_reqh *reqh)
Definition: console_fom.c:96
void m0_free(void *data)
Definition: memory.c:146
struct m0_rpc_item f_item
Definition: fop.h:83
Definition: fop.h:79
struct m0_fop * rep_fop
Definition: dir.c:334
static int console_fom_create(struct m0_fop *fop, struct m0_reqh *reqh, const struct m0_fom_ops *fom_ops, struct m0_fom **m)
Definition: console_fom.c:40