Motr  M0
sw_onwire_fom.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_CM
24 #include "lib/trace.h"
25 #include "lib/errno.h"
26 #include "lib/assert.h"
27 #include "lib/memory.h"
28 #include "lib/arith.h" /* m0_rnd() */
29 
30 #include "rpc/rpc.h"
31 
32 #include "fop/fop.h"
33 #include "fop/fop_item_type.h"
34 #include "fop/fom.h"
35 
36 #include "cm/proxy.h"
37 #include "cm/cm.h"
40 
48  [SWOPH_START] = {
50  .sd_name = "Start",
51  .sd_allowed = M0_BITS(SWOPH_FINI)
52  },
53  [SWOPH_FINI] = {
54  .sd_flags = M0_SDF_TERMINAL,
55  .sd_name = "Fini",
56  .sd_allowed = 0
57  },
58 };
59 
61  .scf_name = "Repair/re-balance sw update",
62  .scf_nr_states = ARRAY_SIZE(repreb_sw_fom_phases),
63  .scf_state = repreb_sw_fom_phases
64 };
65 
66 static int repreb_sw_fom_tick(struct m0_fom *fom)
67 {
68  struct m0_reqh_service *service;
69  struct m0_cm *cm;
70  struct m0_cm_sw_onwire *swo_fop;
71  struct m0_cm_sw_onwire_rep *swo_rep;
72  struct m0_cm_proxy *cm_proxy;
73  struct m0_fop *rfop;
74  int rc = 0;
75  const char *ep;
76 
77  service = fom->fo_service;
78  switch (m0_fom_phase(fom)) {
79  case SWOPH_START:
80  swo_fop = m0_fop_data(fom->fo_fop);
82  if (cm == NULL)
83  return M0_ERR(-EINVAL);
84  M0_LOG(M0_DEBUG, "Rcvd from %s hi: "M0_AG_F
85  " [%" PRIu64 "] [%" PRIu64 "] [%" PRIu64 "]",
86  swo_fop->swo_cm_ep.ep,
87  M0_AG_P(&swo_fop->swo_in_interval.sw_hi),
90  cm->cm_proxy_nr);
91 
92  ep = swo_fop->swo_cm_ep.ep;
93  m0_cm_lock(cm);
94  cm_proxy = m0_cm_proxy_locate(cm, ep);
95  if (cm_proxy != NULL) {
96  ID_LOG("proxy hi", &cm_proxy->px_sw.sw_hi);
97  rc = m0_cm_proxy_update(cm_proxy,
98  &swo_fop->swo_in_interval,
99  &swo_fop->swo_out_interval,
100  swo_fop->swo_cm_status,
101  swo_fop->swo_cm_epoch);
102  } else
103  rc = -ENOENT;
104  m0_cm_unlock(cm);
105 
106  rfop = fom->fo_rep_fop;
107  swo_rep = m0_fop_data(rfop);
108  swo_rep->swr_rc = rc;
109  m0_rpc_reply_post(&fom->fo_fop->f_item, &rfop->f_item);
111  break;
112  default:
113  M0_IMPOSSIBLE("Invalid fop");
114  return M0_ERR(-EINVAL);
115  }
116  return M0_FSO_WAIT;
117 }
118 
119 static void repreb_sw_fom_fini(struct m0_fom *fom)
120 {
121  M0_PRE(fom != NULL);
122 
123  m0_fom_fini(fom);
124  m0_free(fom);
125 }
126 
127 static size_t repreb_sw_fom_home_locality(const struct m0_fom *fom)
128 {
129  struct m0_cm_sw_onwire *swo_fop;
130 
131  swo_fop = m0_fop_data(fom->fo_fop);
132  return m0_rnd(1 << 30, &swo_fop->swo_sender_id);
133 }
134 
135 static const struct m0_fom_ops repreb_sw_fom_ops = {
137  .fo_tick = repreb_sw_fom_tick,
138  .fo_home_locality = repreb_sw_fom_home_locality,
139 };
140 
142  struct m0_fop *r_fop,
143  struct m0_fom **out,
144  struct m0_reqh *reqh)
145 {
146  struct m0_fom *fom;
147 
148  M0_PRE(fop != NULL);
149  M0_PRE(out != NULL);
150 
151  M0_ALLOC_PTR(fom);
152  if (fom == NULL)
153  return M0_ERR(-ENOMEM);
154 
156  r_fop, reqh);
157 
158  *out = fom;
159  return 0;
160 }
161 
162 #undef M0_TRACE_SUBSYSTEM
163 
165 /*
166  * Local variables:
167  * c-indentation-style: "K&R"
168  * c-basic-offset: 8
169  * tab-width: 8
170  * fill-column: 80
171  * scroll-step: 1
172  * End:
173  */
uint64_t cm_aggr_grps_in_nr
Definition: cm.h:205
M0_INTERNAL void m0_cm_lock(struct m0_cm *cm)
Definition: cm.c:545
#define M0_PRE(cond)
#define NULL
Definition: misc.h:38
#define M0_AG_P(ag)
Definition: ag.h:55
#define ID_LOG(prefix, id)
Definition: ag.h:57
struct m0_cm_sw swo_in_interval
Definition: sw.h:70
Definition: sm.h:350
m0_time_t swo_cm_epoch
Definition: sw.h:62
struct m0_cm_ag_id sw_hi
Definition: sw.h:47
#define M0_LOG(level,...)
Definition: trace.h:167
void * m0_fop_data(const struct m0_fop *fop)
Definition: fop.c:220
#define M0_BITS(...)
Definition: misc.h:236
struct m0_cm_local_ep swo_cm_ep
Definition: sw.h:67
uint64_t cm_aggr_grps_out_nr
Definition: cm.h:233
m0_fom_phase
Definition: fom.h:372
struct m0_fom_type ft_fom_type
Definition: fop.h:232
static struct m0_cm * cm
Definition: cm.c:63
Definition: sock.c:754
M0_INTERNAL void m0_cm_unlock(struct m0_cm *cm)
Definition: cm.c:550
#define M0_AG_F
Definition: ag.h:54
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
#define PRIu64
Definition: types.h:58
return M0_ERR(-EOPNOTSUPP)
M0_INTERNAL uint64_t m0_rnd(uint64_t max, uint64_t *seed)
Definition: misc.c:115
char * ep
Definition: sw.h:53
static int repreb_sw_fom_tick(struct m0_fom *fom)
Definition: sw_onwire_fom.c:66
void m0_fom_fini(struct m0_fom *fom)
Definition: fom.c:1324
const char * scf_name
Definition: sm.h:352
struct m0_cm_sw px_sw
Definition: proxy.h:68
struct m0_cm_sw swo_out_interval
Definition: sw.h:73
Definition: reqh.h:94
static void repreb_sw_fom_fini(struct m0_fom *fom)
Definition: dump.c:103
M0_INTERNAL int m0_cm_proxy_update(struct m0_cm_proxy *pxy, struct m0_cm_sw *in_interval, struct m0_cm_sw *out_interval, uint32_t px_status, m0_time_t px_epoch)
Definition: proxy.c:327
void m0_rpc_reply_post(struct m0_rpc_item *request, struct m0_rpc_item *reply)
Definition: rpc.c:135
static const struct m0_fom_ops repreb_sw_fom_ops
M0_INTERNAL struct m0_cm * m0_cmsvc2cm(struct m0_reqh_service *cmsvc)
Definition: cm.c:497
uint32_t sd_flags
Definition: sm.h:378
Definition: fom.h:481
uint64_t cm_proxy_nr
Definition: cm.h:250
struct m0_reqh reqh
Definition: rm_foms.c:48
char * ep
Definition: sw.h:132
#define M0_ALLOC_PTR(ptr)
Definition: memory.h:86
static size_t repreb_sw_fom_home_locality(const struct m0_fom *fom)
static struct m0_sm_state_descr repreb_sw_fom_phases[]
Definition: sw_onwire_fom.c:47
Definition: cm.h:166
M0_INTERNAL struct m0_cm_proxy * m0_cm_proxy_locate(struct m0_cm *cm, const char *addr)
Definition: proxy.c:161
static struct m0_fop * fop
Definition: item.c:57
void(* fo_fini)(struct m0_fom *fom)
Definition: fom.h:657
const struct m0_sm_conf m0_cm_repreb_sw_onwire_conf
Definition: sw_onwire_fom.c:60
#define out(...)
Definition: gen.c:41
void m0_fom_phase_set(struct m0_fom *fom, int phase)
Definition: fom.c:1688
uint32_t swo_cm_status
Definition: sw.h:75
M0_INTERNAL int m0_cm_repreb_sw_onwire_fom_create(struct m0_fop *fop, struct m0_fop *r_fop, struct m0_fom **out, struct m0_reqh *reqh)
uint64_t swo_sender_id
Definition: sw.h:64
void m0_free(void *data)
Definition: memory.c:146
struct m0_rpc_item f_item
Definition: fop.h:83
static struct m0_reqh_service * service[REQH_IN_UT_MAX]
Definition: long_lock_ut.c:46
int32_t rc
Definition: trigger_fop.h:47
#define ARRAY_SIZE(a)
Definition: misc.h:45
Definition: fop.h:79
#define M0_IMPOSSIBLE(fmt,...)