Motr  M0
note_foms.c
Go to the documentation of this file.
1 /* -*- C -*- */
2 /*
3  * Copyright (c) 2013-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_HA
24 #include "lib/trace.h"
25 
26 #include "lib/memory.h"
27 #include "lib/string.h" /* m0_strdup */
28 #include "fop/fom_generic.h"
29 #include "fop/fop.h"
30 #include "fop/fom.h"
31 #include "ha/note.h"
32 #include "ha/note_fops.h" /* m0_ha_state_fop */
33 #include "rpc/rpc.h"
34 #include "reqh/reqh.h"
35 #include "conf/confc.h" /* m0_conf_cache */
36 
37 static void ha_state_fom_fini(struct m0_fom *fom)
38 {
40  m0_free(fom);
41 }
42 
43 static size_t ha_state_fom_home_locality(const struct m0_fom *fom)
44 {
45  return m0_fop_opcode(fom->fo_fop);
46 }
47 
48 static int ha_state_set_fom_tick(struct m0_fom *fom)
49 {
51  m0_ha_state_accept(m0_fop_data(fom->fo_fop), false);
53  m0_rpc_reply_post(&fom->fo_fop->f_item, &fom->fo_rep_fop->f_item);
55  return M0_FSO_WAIT;
56 }
57 
60  .fo_fini = &ha_state_fom_fini,
61  .fo_home_locality = &ha_state_fom_home_locality,
62 };
63 
64 static int ha_state_set_fom_create(struct m0_fop *fop,
65  struct m0_fom **m,
66  struct m0_reqh *reqh)
67 {
68  struct m0_fom *fom;
69  struct m0_fop *reply;
70  struct m0_fop_generic_reply *rep;
71 
72  M0_PRE(fop != NULL);
73  M0_PRE(m != NULL);
74 
77  if (fom == NULL || reply == NULL) {
78  m0_free(fom);
79  if (reply != NULL)
81  return M0_ERR(-ENOMEM);
82  }
84  fop, reply, reqh);
85 
87  rep->gr_rc = 0;
88  rep->gr_msg.s_len = 0;
89  *m = fom;
90  return 0;
91 }
92 
93 static void ha_state_get(struct m0_conf_cache *cache,
94  struct m0_ha_nvec *req_fop,
95  struct m0_ha_state_fop *rep_fop)
96 {
97  struct m0_conf_obj *obj;
98  struct m0_ha_nvec *note_vec = &rep_fop->hs_note;
99  int i;
100 
101  M0_ENTRY();
102  M0_NVEC_PRINT(req_fop, " in ", M0_DEBUG);
103  note_vec->nv_nr = req_fop->nv_nr;
105  for (i = 0; i < req_fop->nv_nr; ++i) {
106  obj = m0_conf_cache_lookup(cache, &req_fop->nv_note[i].no_id);
107  if (obj != NULL) {
108  note_vec->nv_note[i].no_id = obj->co_id;
109  note_vec->nv_note[i].no_state = obj->co_ha_state;
110  }
111  }
113  M0_NVEC_PRINT(note_vec, " out ", M0_DEBUG);
114  M0_LEAVE();
115 }
116 
117 static int ha_state_get_fom_tick(struct m0_fom *fom)
118 {
119  struct m0_ha_nvec *req_fop;
120  struct m0_ha_state_fop *rep_fop;
122 
123  req_fop = m0_fop_data(fom->fo_fop);
124  rep_fop = m0_fop_data(fom->fo_rep_fop);
125 
126  ha_state_get(&confc->cc_cache, req_fop, rep_fop);
127 
128  m0_rpc_reply_post(&fom->fo_fop->f_item, &fom->fo_rep_fop->f_item);
130  return M0_FSO_WAIT;
131 }
132 
135  .fo_fini = ha_state_fom_fini,
136  .fo_home_locality = ha_state_fom_home_locality,
137 };
138 
139 static int ha_state_get_fom_create(struct m0_fop *fop,
140  struct m0_fom **m,
141  struct m0_reqh *reqh)
142 {
143  struct m0_fom *fom;
144  struct m0_ha_state_fop *ha_state_fop;
145  struct m0_ha_nvec *req_fop;
146 
147  M0_PRE(fop != NULL);
148  M0_PRE(m != NULL);
149 
150  M0_ALLOC_PTR(fom);
151  if (fom == NULL)
152  return M0_ERR(-ENOMEM);
153 
154  M0_ALLOC_PTR(ha_state_fop);
155  if (ha_state_fop == NULL){
156  m0_free(fom);
157  return M0_ERR(-ENOMEM);
158  }
159 
160  req_fop = m0_fop_data(fop);
161  M0_ALLOC_ARR(ha_state_fop->hs_note.nv_note, req_fop->nv_nr);
162  if (ha_state_fop->hs_note.nv_note == NULL){
163  m0_free(ha_state_fop);
164  m0_free(fom);
165  return M0_ERR(-ENOMEM);
166  }
167 
168  fom->fo_rep_fop = m0_fop_alloc(&m0_ha_state_get_rep_fopt, ha_state_fop,
170  if (fom->fo_rep_fop == NULL) {
171  m0_free(ha_state_fop->hs_note.nv_note);
172  m0_free(ha_state_fop);
173  m0_free(fom);
174  return M0_ERR(-ENOMEM);
175  }
176 
178  fop, fom->fo_rep_fop, reqh);
179 
180  *m = fom;
181  return M0_RC(0);
182 }
183 static const struct m0_fom_type_ops ha_get_fomt_ops = {
185 };
186 
187 static const struct m0_fom_type_ops ha_set_fomt_ops = {
189 };
190 
193 
194 #undef M0_TRACE_SUBSYSTEM
195 
196 /*
197  * Local variables:
198  * c-indentation-style: "K&R"
199  * c-basic-offset: 8
200  * tab-width: 8
201  * fill-column: 80
202  * scroll-step: 1
203  * End:
204  */
205 /*
206  * vim: tabstop=8 shiftwidth=8 noexpandtab textwidth=80 nowrap
207  */
Definition: beck.c:235
uint32_t m0_fop_opcode(const struct m0_fop *fop)
Definition: fop.c:226
#define M0_PRE(cond)
#define M0_ALLOC_ARR(arr, nr)
Definition: memory.h:84
M0_INTERNAL void m0_fom_block_enter(struct m0_fom *fom)
Definition: fom.c:538
#define NULL
Definition: misc.h:38
static struct m0_addb2_mach * m
Definition: consumer.c:38
const struct m0_fom_ops m0_ha_state_set_fom_ops
Definition: note_foms.c:58
int(* fo_tick)(struct m0_fom *fom)
Definition: fom.h:663
M0_INTERNAL struct m0_conf_obj * m0_conf_cache_lookup(const struct m0_conf_cache *cache, const struct m0_fid *id)
Definition: cache.c:106
static void ha_state_get(struct m0_conf_cache *cache, struct m0_ha_nvec *req_fop, struct m0_ha_state_fop *rep_fop)
Definition: note_foms.c:93
M0_LEAVE()
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 int ha_state_set_fom_tick(struct m0_fom *fom)
Definition: note_foms.c:48
static size_t ha_state_fom_home_locality(const struct m0_fom *fom)
Definition: note_foms.c:43
const struct m0_fom_ops ha_state_get_fom_ops
Definition: note_foms.c:133
struct m0_fop_getxattr_rep * rep
Definition: dir.c:455
static struct foo * obj
Definition: tlist.c:302
struct m0_fom_type ft_fom_type
Definition: fop.h:232
return M0_RC(rc)
#define M0_ENTRY(...)
Definition: trace.h:170
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
int i
Definition: dir.c:1033
struct m0_fop_type * f_type
Definition: fop.h:81
struct m0_rpc_machine * m0_fop_rpc_machine(const struct m0_fop *fop)
Definition: fop.c:360
int32_t nv_nr
Definition: note.h:196
return M0_ERR(-EOPNOTSUPP)
#define M0_NVEC_PRINT(nvec_, label, level)
Definition: note.h:268
M0_INTERNAL struct m0_confc * m0_reqh2confc(struct m0_reqh *reqh)
Definition: reqh.c:753
const struct m0_fom_type_ops * m0_ha_state_set_fom_type_ops
Definition: note_foms.c:192
void m0_fom_fini(struct m0_fom *fom)
Definition: fom.c:1324
static struct m0_confc * confc
Definition: file.c:94
static const struct m0_fom_type_ops ha_get_fomt_ops
Definition: note_foms.c:183
M0_INTERNAL void m0_fom_block_leave(struct m0_fom *fom)
Definition: fom.c:582
struct m0_fop_type m0_ha_state_get_rep_fopt
Definition: note_fops.c:34
struct m0_conf_cache cc_cache
Definition: confc.h:394
Definition: reqh.h:94
static const struct m0_fom_type_ops ha_set_fomt_ops
Definition: note_foms.c:187
Definition: dump.c:103
void m0_rpc_reply_post(struct m0_rpc_item *request, struct m0_rpc_item *reply)
Definition: rpc.c:135
struct m0_fid no_id
Definition: note.h:180
struct m0_fop_type m0_fop_generic_reply_fopt
Definition: fom_generic.c:50
struct m0_fop * m0_fop_reply_alloc(struct m0_fop *req, struct m0_fop_type *rept)
Definition: fop.c:129
Definition: fom.h:481
static int ha_state_get_fom_tick(struct m0_fom *fom)
Definition: note_foms.c:117
struct m0_reqh reqh
Definition: rm_foms.c:48
const struct m0_fom_type_ops * m0_ha_state_get_fom_type_ops
Definition: note_foms.c:191
#define M0_ALLOC_PTR(ptr)
Definition: memory.h:86
void m0_fop_put_lock(struct m0_fop *fop)
Definition: fop.c:199
static struct m0_fop * fop
Definition: item.c:57
static int ha_state_set_fom_create(struct m0_fop *fop, struct m0_fom **m, struct m0_reqh *reqh)
Definition: note_foms.c:64
void m0_fom_phase_set(struct m0_fom *fom, int phase)
Definition: fom.c:1688
struct m0_ha_note * nv_note
Definition: note.h:197
M0_INTERNAL void m0_ha_state_accept(const struct m0_ha_nvec *note, bool ignore_same_state)
Definition: note.c:189
M0_INTERNAL void m0_conf_cache_lock(struct m0_conf_cache *cache)
Definition: cache.c:50
static struct m0_dtm_oper_descr reply
Definition: transmit.c:94
void m0_free(void *data)
Definition: memory.c:146
struct m0_ha_nvec hs_note
Definition: note_fops.h:47
static int ha_state_get_fom_create(struct m0_fop *fop, struct m0_fom **m, struct m0_reqh *reqh)
Definition: note_foms.c:139
M0_INTERNAL struct m0_reqh * m0_fom2reqh(const struct m0_fom *fom)
Definition: fom.c:1749
M0_INTERNAL void m0_conf_cache_unlock(struct m0_conf_cache *cache)
Definition: cache.c:55
Definition: fop.h:79
struct m0_fop * rep_fop
Definition: dir.c:334
struct m0_fop * m0_fop_alloc(struct m0_fop_type *fopt, void *data, struct m0_rpc_machine *mach)
Definition: fop.c:96
uint32_t no_state
Definition: note.h:182
static void ha_state_fom_fini(struct m0_fom *fom)
Definition: note_foms.c:37