Motr  M0
device_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/memory.h"
24 #include "lib/misc.h"
25 #include "lib/types.h"
26 #include "conf/obj.h" /* M0_CONF_DRIVE_TYPE */
27 #include "sm/sm.h"
28 #include "fop/fop.h"
29 #include "fop/fom.h"
30 #include "fop/fop_item_type.h"
31 #include "fop/fom_generic.h"
32 #include "rpc/rpc_opcodes.h"
33 #include "rpc/item.h"
34 #include "sss/device_foms.h"
35 #include "sss/device_fops.h"
36 #include "sss/device_fops_xc.h"
37 #include "sss/ss_svc.h"
38 
41 
43 extern const struct m0_sm_conf sss_device_fom_conf;
44 extern const struct m0_fom_type_ops sss_device_fom_type_ops;
45 
46 M0_INTERNAL int m0_sss_device_fops_init(void)
47 {
50 
51  /*
52  * Extend phases this FOM needs to open separate BE transaction.
53  * Because extend phases execute before M0_FOPH_TXN_INIT phase.
54  * FOM handler catch M0_FOPH_TXN_INIT phase. If it first time then
55  * move to extended phase else simple way.
56  */
59 
62 
64  .name = "Device-fop",
66  .xt = m0_sss_device_fop_xc,
67  .rpc_flags = M0_RPC_ITEM_TYPE_REQUEST,
68  .fom_ops = &sss_device_fom_type_ops,
69  .svc_type = &m0_ss_svc_type,
70  .sm = &sss_device_fom_conf);
71 
73  .name = "Device-reply-fop",
75  .xt = m0_sss_device_fop_rep_xc,
76  .rpc_flags = M0_RPC_ITEM_TYPE_REPLY);
77  return 0;
78 }
79 
80 M0_INTERNAL void m0_sss_device_fops_fini(void)
81 {
84 }
85 
86 M0_INTERNAL struct m0_fop *m0_sss_device_fop_create(struct m0_rpc_machine *mach,
87  uint32_t cmd,
88  const struct m0_fid *fid)
89 {
90  struct m0_fop *fop;
91  struct m0_sss_device_fop *req;
92 
93  M0_PRE(mach != NULL);
96 
98  if (fop == NULL)
99  return NULL;
100 
102  req->ssd_cmd = cmd;
103  req->ssd_fid = *fid;
104 
105  return fop;
106 }
107 
108 M0_INTERNAL bool m0_sss_fop_is_dev_req(const struct m0_fop *fop)
109 {
110  M0_PRE(fop != NULL);
111  return fop->f_type == &m0_sss_fop_device_fopt;
112 }
113 
114 M0_INTERNAL struct m0_sss_device_fop *m0_sss_fop_to_dev_req(struct m0_fop *fop)
115 {
116  M0_PRE(fop != NULL);
118 
119  return m0_fop_data(fop);
120 }
121 
122 M0_INTERNAL bool m0_sss_fop_is_dev_rep(const struct m0_fop *fop)
123 {
124  M0_PRE(fop != NULL);
126 }
127 
128 M0_INTERNAL
130 {
131  M0_PRE(fop != NULL);
133 
134  return m0_fop_data(fop);
135 }
136 
137 /*
138  * Local variables:
139  * c-indentation-style: "K&R"
140  * c-basic-offset: 8
141  * tab-width: 8
142  * fill-column: 80
143  * scroll-step: 1
144  * End:
145  */
struct m0_fop_type m0_sss_fop_device_rep_fopt
Definition: device_fops.c:40
#define M0_PRE(cond)
M0_INTERNAL struct m0_fop * m0_sss_device_fop_create(struct m0_rpc_machine *mach, uint32_t cmd, const struct m0_fid *fid)
Definition: device_fops.c:86
#define NULL
Definition: misc.h:38
M0_INTERNAL void m0_sss_device_fops_fini(void)
Definition: device_fops.c:80
#define M0_FOP_TYPE_INIT(ft,...)
Definition: fop.h:307
Definition: sm.h:350
static struct io_request req
Definition: file.c:100
const struct m0_conf_obj_type * m0_conf_fid_type(const struct m0_fid *fid)
Definition: obj.c:368
struct m0_fop_type m0_sss_fop_device_fopt
Definition: device_fops.c:39
uint64_t sd_allowed
Definition: sm.h:422
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
#define M0_BITS(...)
Definition: misc.h:236
static struct m0_xcode_type ** xt[]
Definition: protocol.c:64
const struct m0_sm_conf m0_generic_conf
Definition: fom_generic.c:838
M0_INTERNAL struct m0_sss_device_fop * m0_sss_fop_to_dev_req(struct m0_fop *fop)
Definition: device_fops.c:114
struct m0_fid fid
Definition: di.c:46
M0_INTERNAL bool m0_sss_fop_is_dev_req(const struct m0_fop *fop)
Definition: device_fops.c:108
int opcode
Definition: crate.c:301
struct m0_fop_type * f_type
Definition: fop.h:81
const char * name
Definition: trace.c:110
const struct m0_sm_conf sss_device_fom_conf
Definition: device_foms.c:193
struct m0_sm_state_descr sss_device_fom_phases_desc[]
Definition: device_foms.c:129
const struct m0_fom_type_ops sss_device_fom_type_ops
Definition: device_foms.c:125
uint32_t scf_nr_states
Definition: sm.h:354
struct m0_reqh_service_type m0_ss_svc_type
Definition: ss_svc.c:159
const struct m0_conf_obj_type M0_CONF_DRIVE_TYPE
Definition: drive.c:108
M0_INTERNAL struct m0_sss_device_fop_rep * m0_sss_fop_to_dev_rep(struct m0_fop *fop)
Definition: device_fops.c:129
M0_INTERNAL int m0_sss_device_fops_init(void)
Definition: device_fops.c:46
struct m0_sm_state_descr * scf_state
Definition: sm.h:356
Definition: fid.h:38
static struct m0_fop * fop
Definition: item.c:57
M0_INTERNAL bool m0_sss_fop_is_dev_rep(const struct m0_fop *fop)
Definition: device_fops.c:122
uint64_t ft_magix
Definition: fop.h:236
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