Motr  M0
fi_command_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_OTHER
24 
25 #include "lib/trace.h"
26 #include "lib/memory.h" /* M0_ALLOC_PTR, m0_free */
27 #include "lib/buf.h" /* m0_buf_strdup */
28 #include "lib/finject.h" /* M0_FI_ENABLED */
29 
30 #include "fis/fi_command.h"
31 #include "fis/fi_command_fops.h"
32 #include "fop/fom_generic.h"
33 #include "fop/fop.h"
34 #include "rpc/rpc.h"
35 #include "sm/sm.h"
36 
46 
54  struct m0_fom fcf_gen;
56  struct m0_fop *fcf_fop;
57 };
58 
59 extern const struct m0_fom_ops fi_command_fom_ops;
60 
61 static int fi_command_fom_create(struct m0_fop *fop, struct m0_fom **out,
62  struct m0_reqh *reqh)
63 {
64  struct m0_fom *fom;
65  struct m0_fi_command_fom *fom_obj;
66  struct m0_fop *fop_rep;
67 
68  M0_ENTRY();
69  M0_PRE(fop != NULL);
70  M0_PRE(out != NULL);
71 
72  fop_rep = M0_FI_ENABLED("no_mem") ? NULL :
74  M0_ALLOC_PTR(fom_obj);
75  if (fop_rep == NULL || fom_obj == NULL)
76  goto no_mem;
77  fom = &fom_obj->fcf_gen;
79  fop_rep, reqh);
80  fom_obj->fcf_fop = fop;
81  *out = fom;
82  return M0_RC(0);
83 no_mem:
84  m0_free(fop_rep);
85  m0_free(fom_obj);
86  return M0_ERR(-ENOMEM);
87 }
88 
89 static void fi_command_fom_fini(struct m0_fom *fom)
90 {
91  struct m0_fi_command_fom *fom_obj = M0_AMB(fom_obj, fom, fcf_gen);
92 
94  m0_free(fom_obj);
95 }
96 
97 static int fi_command_execute(const struct m0_fi_command_req *req)
98 {
99  char *func = m0_buf_strdup(&req->fcr_func);
100  char *tag = m0_buf_strdup(&req->fcr_tag);
101  int rc = 0;
102 
103  M0_ENTRY("func=%s tag=%s disp=%d", func, tag, req->fcr_disp);
104  if (func == NULL || tag == NULL) {
105  rc = -ENOMEM;
106  goto out;
107  }
108  switch (req->fcr_disp) {
109  case M0_FI_DISP_ENABLE:
110  m0_fi_enable(func, tag);
111  break;
112  case M0_FI_DISP_DISABLE:
113  m0_fi_disable(func, tag);
114  break;
116  m0_fi_enable_once(func, tag);
117  break;
119  m0_fi_enable_random(func, tag, req->fcr_num1);
120  break;
122  m0_fi_enable_off_n_on_m(func, tag, req->fcr_num1,
123  req->fcr_num2);
124  break;
125  default:
126  rc = -EINVAL;
127  }
128 out:
129  m0_free(func);
130  m0_free(tag);
131  return rc == 0 ? M0_RC(rc) : M0_ERR(rc);
132 }
133 
134 static int fi_command_fom_tick(struct m0_fom *fom)
135 {
136  struct m0_fi_command_fom *fcf = M0_AMB(fcf, fom, fcf_gen);
137  struct m0_fi_command_req *req = m0_fop_data(fcf->fcf_fop);
138  struct m0_fop *fop = fom->fo_rep_fop;
140 
141  rep->fcp_rc = fi_command_execute(req);
144  return M0_FSO_WAIT;
145 }
146 
147 static size_t fi_command_fom_locality(const struct m0_fom *fom)
148 {
149  static size_t locality = 0;
150 
151  return locality++;
152 }
153 
156 };
157 
160  .fo_tick = fi_command_fom_tick,
161  .fo_home_locality = fi_command_fom_locality
162 };
163 
165 #undef M0_TRACE_SUBSYSTEM
166 
167 /*
168  * Local variables:
169  * c-indentation-style: "K&R"
170  * c-basic-offset: 8
171  * tab-width: 8
172  * fill-column: 80
173  * scroll-step: 1
174  * End:
175  */
#define M0_PRE(cond)
static int fi_command_fom_tick(struct m0_fom *fom)
#define NULL
Definition: misc.h:38
struct m0_fom fcf_gen
static size_t locality(const struct m0_fom *fom)
Definition: rm_foms.c:269
static int fi_command_execute(const struct m0_fi_command_req *req)
static struct io_request req
Definition: file.c:100
static uint64_t tag(uint8_t code, uint64_t id)
Definition: addb2.c:1047
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
static void m0_fi_enable_random(const char *func, const char *tag, uint32_t p)
Definition: finject.h:321
const struct m0_fom_type_ops m0_fi_command_fom_type_ops
struct m0_fop_getxattr_rep * rep
Definition: dir.c:455
struct m0_fom_type ft_fom_type
Definition: fop.h:232
return M0_RC(rc)
#define M0_ENTRY(...)
Definition: trace.h:170
struct m0_fop_type m0_fi_command_rep_fopt
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)
static int fi_command_fom_create(struct m0_fop *fop, struct m0_fom **out, struct m0_reqh *reqh)
#define M0_AMB(obj, ptr, field)
Definition: misc.h:320
M0_INTERNAL void m0_fi_disable(const char *fp_func, const char *fp_tag)
Definition: finject.c:485
static void m0_fi_enable(const char *func, const char *tag)
Definition: finject.h:276
void m0_fom_fini(struct m0_fom *fom)
Definition: fom.c:1324
static size_t fi_command_fom_locality(const struct m0_fom *fom)
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
static void m0_fi_enable_off_n_on_m(const char *func, const char *tag, uint32_t n, uint32_t m)
Definition: finject.h:346
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 char * m0_buf_strdup(const struct m0_buf *buf)
Definition: buf.c:140
struct m0_reqh reqh
Definition: rm_foms.c:48
#define M0_FI_ENABLED(tag)
Definition: finject.h:231
#define M0_ALLOC_PTR(ptr)
Definition: memory.h:86
struct m0_rpc_item * m0_fop_to_rpc_item(const struct m0_fop *fop)
Definition: fop.c:338
static void fi_command_fom_fini(struct m0_fom *fom)
static struct m0_fop * fop
Definition: item.c:57
const struct m0_fom_ops fi_command_fom_ops
static void m0_fi_enable_once(const char *func, const char *tag)
Definition: finject.h:301
void(* fo_fini)(struct m0_fom *fom)
Definition: fom.h:657
struct m0_fop * fcf_fop
#define out(...)
Definition: gen.c:41
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
int32_t rc
Definition: trigger_fop.h:47
Definition: fop.h:79