Motr  M0
process_fops.c
Go to the documentation of this file.
1 /* -*- C -*- */
2 /*
3  * Copyright (c) 2015-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/finject.h" /* M0_FI_ENABLED */
24 #include "lib/memory.h"
25 #include "lib/misc.h"
26 #include "lib/types.h"
27 #include "lib/refs.h"
28 #include "sm/sm.h"
29 #include "fop/fop.h"
30 #include "fop/fom.h"
31 #include "fop/fop_item_type.h"
32 #include "fop/fom_generic.h"
33 #include "rpc/rpc_opcodes.h"
34 #include "rpc/item.h"
35 #include "sss/process_fops.h"
36 #include "sss/process_fops_xc.h"
37 #include "sss/ss_svc.h"
38 #ifndef __KERNEL__
39 #include <unistd.h>
40 #endif
41 
45 
47 extern struct m0_sm_conf ss_process_fom_conf;
48 extern const struct m0_fom_type_ops ss_process_fom_type_ops;
51 
54 };
55 
56 M0_INTERNAL int m0_ss_process_fops_init(void)
57 {
58 #ifndef __KERNEL__
62 #endif
66 
68  .name = "Process fop",
70  .xt = m0_ss_process_req_xc,
71  .rpc_flags = M0_RPC_ITEM_TYPE_REQUEST,
72  .fop_ops = &ss_process_fop_type_ops,
73  .fom_ops = &ss_process_fom_type_ops,
74  .sm = &ss_process_fom_conf,
75  .svc_type = &m0_ss_svc_type,
77 
79  .name = "Process reply fop",
81  .xt = m0_ss_process_rep_xc,
82  .rpc_flags = M0_RPC_ITEM_TYPE_REPLY,
83  .fop_ops = &ss_process_fop_type_ops,
84  .fom_ops = &ss_process_fom_type_ops,
85  .sm = &ss_process_fom_conf,
86  .svc_type = &m0_ss_svc_type,
88 
90  .name = "Process services list reply fop",
92  .xt = m0_ss_process_svc_list_rep_xc,
93  .rpc_flags = M0_RPC_ITEM_TYPE_REPLY,
95  .fom_ops = &ss_process_fom_type_ops,
96  .sm = &ss_process_fom_conf,
97  .svc_type = &m0_ss_svc_type,
99  return 0;
100 }
101 
102 M0_INTERNAL void m0_ss_process_fops_fini(void)
103 {
107 }
108 
109 static bool ss_fop_is_process_rep(const struct m0_fop *fop)
110 {
111  M0_PRE(fop != NULL);
112  return fop->f_type == &m0_fop_process_rep_fopt;
113 }
114 
115 static bool ss_fop_is_process_svc_list_rep(const struct m0_fop *fop)
116 {
117  M0_PRE(fop != NULL);
119 }
120 
121 M0_INTERNAL void m0_ss_process_rep_fop_release(struct m0_ref *ref)
122 {
123  struct m0_ss_process_rep *rep;
124  struct m0_fop *fop = container_of(ref, struct m0_fop, f_ref);
125 
126  M0_PRE(fop != NULL);
128 
129  rep = m0_fop_data(fop);
130  m0_buf_free(&rep->sspr_bckey);
131  m0_buf_free(&rep->sspr_bcrec);
132  m0_fop_fini(fop);
133  m0_free(fop);
134 }
135 
136 
137 M0_INTERNAL void m0_ss_process_stop_fop_release(struct m0_ref *ref)
138 {
139 #ifndef __KERNEL__
140  int pid = getpid();
141 #endif
142  struct m0_fop *fop = container_of(ref, struct m0_fop, f_ref);
143 
144  M0_PRE(fop != NULL);
146 
147  m0_fop_fini(fop);
148  m0_free(fop);
149 
150 #ifndef __KERNEL__
151  if (!M0_FI_ENABLED("no_kill"))
152  kill(pid, SIGQUIT);
153 #endif
154 }
155 
157  uint32_t cmd,
158  const struct m0_fid *fid)
159 {
160  struct m0_fop *fop;
161  struct m0_ss_process_req *req;
162 
163  M0_PRE(mach != NULL);
164  M0_PRE(cmd < M0_PROCESS_NR);
165 
167  if (fop == NULL)
168  return NULL;
169 
171  req->ssp_cmd = cmd;
172  req->ssp_id = *fid;
173 
174  return fop;
175 }
176 
177 M0_INTERNAL bool m0_ss_fop_is_process_req(const struct m0_fop *fop)
178 {
179  M0_PRE(fop != NULL);
180  return fop->f_type == &m0_fop_process_fopt;
181 }
182 
183 M0_INTERNAL struct m0_ss_process_req *m0_ss_fop_process_req(struct m0_fop *fop)
184 {
185  M0_PRE(fop != NULL);
187 
188  return m0_fop_data(fop);
189 }
190 
191 M0_INTERNAL struct m0_ss_process_rep *m0_ss_fop_process_rep(struct m0_fop *fop)
192 {
193  M0_PRE(fop != NULL);
195 
196  return m0_fop_data(fop);
197 }
198 
199 M0_INTERNAL struct m0_ss_process_svc_list_rep *
201 {
202  M0_PRE(fop != NULL);
204  return m0_fop_data(fop);
205 }
206 
207 /*
208  * Local variables:
209  * c-indentation-style: "K&R"
210  * c-basic-offset: 8
211  * tab-width: 8
212  * fill-column: 80
213  * scroll-step: 1
214  * End:
215  */
const struct m0_fom_type_ops ss_process_fom_type_ops
Definition: process_foms.c:87
#define M0_PRE(cond)
ss_process_fom_phases
Definition: process_foms.c:68
#define NULL
Definition: misc.h:38
#define M0_FOP_TYPE_INIT(ft,...)
Definition: fop.h:307
Definition: sm.h:350
static struct io_request req
Definition: file.c:100
struct m0_sm_conf ss_process_fom_conf
Definition: process_foms.c:143
M0_INTERNAL bool m0_ss_fop_is_process_req(const struct m0_fop *fop)
Definition: process_fops.c:177
const struct m0_fop_type_ops ss_process_fop_type_ops
Definition: process_fops.c:49
void * m0_fop_data(const struct m0_fop *fop)
Definition: fop.c:220
void m0_fop_type_fini(struct m0_fop_type *fopt)
Definition: fop.c:232
M0_INTERNAL void m0_sm_conf_extend(const struct m0_sm_state_descr *base, struct m0_sm_state_descr *sub, uint32_t nr)
Definition: sm.c:763
static struct m0_addb2_mach * mach
Definition: storage.c:42
const struct m0_fop_type_ops ss_process_svc_list_fop_type_ops
Definition: process_fops.c:50
M0_INTERNAL struct m0_ss_process_rep * m0_ss_fop_process_rep(struct m0_fop *fop)
Definition: process_fops.c:191
#define container_of(ptr, type, member)
Definition: misc.h:33
static struct m0_xcode_type ** xt[]
Definition: protocol.c:64
M0_INTERNAL struct m0_fop * m0_ss_process_fop_create(struct m0_rpc_machine *mach, uint32_t cmd, const struct m0_fid *fid)
Definition: process_fops.c:156
const struct m0_sm_conf m0_generic_conf
Definition: fom_generic.c:838
struct m0_fop_getxattr_rep * rep
Definition: dir.c:455
M0_INTERNAL void m0_ss_process_fops_fini(void)
Definition: process_fops.c:102
static bool ss_fop_is_process_rep(const struct m0_fop *fop)
Definition: process_fops.c:109
struct m0_fop_type m0_fop_process_fopt
Definition: process_fops.c:42
struct m0_fid fid
Definition: di.c:46
int opcode
Definition: crate.c:301
struct m0_fop_type * f_type
Definition: fop.h:81
static const struct m0_reqh_service_ops rpc_ops
Definition: service.c:92
const char * name
Definition: trace.c:110
Definition: refs.h:34
uint32_t scf_nr_states
Definition: sm.h:354
struct m0_fop_type m0_fop_process_rep_fopt
Definition: process_fops.c:43
struct m0_fop_type m0_fop_process_svc_list_rep_fopt
Definition: process_fops.c:44
M0_INTERNAL struct m0_ss_process_req * m0_ss_fop_process_req(struct m0_fop *fop)
Definition: process_fops.c:183
struct m0_reqh_service_type m0_ss_svc_type
Definition: ss_svc.c:159
M0_INTERNAL void m0_buf_free(struct m0_buf *buf)
Definition: buf.c:55
M0_INTERNAL void m0_fop_fini(struct m0_fop *fop)
Definition: fop.c:136
M0_INTERNAL int m0_ss_process_fops_init(void)
Definition: process_fops.c:56
struct m0_sm_state_descr * scf_state
Definition: sm.h:356
#define M0_FI_ENABLED(tag)
Definition: finject.h:231
struct m0_ref f_ref
Definition: fop.h:80
Definition: fid.h:38
static struct m0_fop * fop
Definition: item.c:57
static const struct m0_rpc_item_type_ops ss_process_item_type_ops
Definition: process_fops.c:52
M0_INTERNAL void m0_ss_process_rep_fop_release(struct m0_ref *ref)
Definition: process_fops.c:121
M0_INTERNAL void m0_ss_process_stop_fop_release(struct m0_ref *ref)
Definition: process_fops.c:137
static bool ss_fop_is_process_svc_list_rep(const struct m0_fop *fop)
Definition: process_fops.c:115
void m0_free(void *data)
Definition: memory.c:146
M0_INTERNAL struct m0_ss_process_svc_list_rep * m0_ss_fop_process_svc_list_rep(struct m0_fop *fop)
Definition: process_fops.c:200
uint64_t ft_magix
Definition: fop.h:236
#define M0_FOP_DEFAULT_ITEM_TYPE_OPS
Definition: fop.h:184
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