Motr  M0
sw_update_fom.c
Go to the documentation of this file.
1 /* -*- C -*- */
2 /*
3  * Copyright (c) 2012-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 
26 #include "lib/bob.h"
27 #include "lib/misc.h" /* M0_BITS */
28 #include "lib/errno.h" /* ENOENT EPERM */
29 
30 #include "reqh/reqh.h"
31 #include "sm/sm.h"
32 #include "rpc/rpc_opcodes.h" /* M0_CM_SW_UPDATE_OPCODE */
33 
34 #include "cm/sw.h"
35 #include "cm/cm.h"
36 #include "cm/proxy.h"
37 
38 #include "be/op.h" /* M0_BE_OP_SYNC */
39 
57 };
58 
60 };
61 
63  [SWU_UPDATE] = {
65  .sd_name = "Update",
66  .sd_allowed = M0_BITS(SWU_FINI)
67  },
68  [SWU_FINI] = {
69  .sd_flags = M0_SDF_TERMINAL,
70  .sd_name = "Fini",
71  .sd_allowed = 0
72  },
73 };
74 
76  .scf_name = "sm: sw update conf",
77  .scf_nr_states = ARRAY_SIZE(cm_sw_update_sd),
78  .scf_state = cm_sw_update_sd,
79 };
80 
81 static struct m0_cm *cm_swu2cm(struct m0_cm_sw_update *swu)
82 {
83  return container_of(swu, struct m0_cm, cm_sw_update);
84 }
85 
86 static struct m0_cm_sw_update *cm_fom2swu(struct m0_fom *fom)
87 {
88  return container_of(fom, struct m0_cm_sw_update, swu_fom);
89 }
90 
91 static int swu_update(struct m0_cm_sw_update *swu)
92 {
93  struct m0_cm *cm = cm_swu2cm(swu);
94  int rc;
95  M0_ENTRY();
96 
98  return M0_RC(rc);
99 }
100 
101 static int (*swu_action[]) (struct m0_cm_sw_update *swu) = {
103 };
104 
105 static uint64_t cm_swu_fom_locality(const struct m0_fom *fom)
106 {
107  return fom->fo_type->ft_id;
108 }
109 static int cm_swu_fom_tick(struct m0_fom *fom)
110 {
111  struct m0_cm *cm;
112  struct m0_cm_sw_update *swu;
113  int phase = m0_fom_phase(fom);
114  int rc;
115  M0_ENTRY();
116 
117  swu = cm_fom2swu(fom);
118  cm = cm_swu2cm(swu);
119  m0_cm_lock(cm);
120  rc = swu_action[phase](swu);
121  if (rc != 0) {
122  if (!M0_IN(rc, (-ENOBUFS, -ENODATA)))
123  M0_LOG(M0_ERROR, "SWU phase=%d rc=%d.", phase, rc);
124  else
125  M0_LOG(M0_DEBUG, "SWU phase=%d rc=%d.", phase, rc);
126 
128  }
129  if (rc < 0) {
130  if (rc != -ENOBUFS) {
131  M0_LOG(M0_DEBUG, "Sliding window update"
132  " fom complete with rc: %d", rc);
135  if (!M0_IN(rc, (-ENOBUFS, -ENODATA)))
136  m0_cm_abort(cm, rc);
138  }
139  rc = M0_FSO_WAIT;
141  }
142  m0_cm_unlock(cm);
143 
144  return M0_RC(rc);
145 }
146 
147 static void cm_swu_fom_fini(struct m0_fom *fom)
148 {
149  m0_fom_fini(fom);
150 }
151 
152 static const struct m0_fom_ops cm_sw_update_fom_ops = {
154  .fo_tick = cm_swu_fom_tick,
155  .fo_home_locality = cm_swu_fom_locality
156 };
157 
158 M0_INTERNAL void m0_cm_sw_update_init(struct m0_cm_type *cmtype)
159 {
160  m0_fom_type_init(&cmtype->ct_swu_fomt, cmtype->ct_fom_id + 1,
162  &cmtype->ct_stype, &cm_sw_update_conf);
163 }
164 
165 M0_INTERNAL void m0_cm_sw_update_start(struct m0_cm *cm)
166 {
167  struct m0_cm_sw_update *swu = &cm->cm_sw_update;
168  struct m0_fom *fom = &swu->swu_fom;
169 
170  M0_ENTRY();
171 
172  swu->swu_is_complete = false;
175  m0_fom_queue(fom);
176 
177  M0_LEAVE();
178 }
179 
180 M0_INTERNAL void m0_cm_sw_update_complete(struct m0_cm *cm)
181 {
182  struct m0_cm_sw_update *swu = &cm->cm_sw_update;
183 
184  swu->swu_is_complete = true;
185 }
186 
187 #undef M0_TRACE_SUBSYSTEM
188 
191 /*
192  * Local variables:
193  * c-indentation-style: "K&R"
194  * c-basic-offset: 8
195  * tab-width: 8
196  * fill-column: 80
197  * scroll-step: 1
198  * End:
199  */
static const struct m0_fom_ops cm_sw_update_fom_ops
M0_INTERNAL void m0_cm_lock(struct m0_cm *cm)
Definition: cm.c:545
const struct m0_cm_type * cm_type
Definition: cm.h:194
uint64_t ft_id
Definition: fom.h:613
#define NULL
Definition: misc.h:38
Definition: sm.h:350
#define M0_LOG(level,...)
Definition: trace.h:167
M0_LEAVE()
static struct m0_cm * cm_swu2cm(struct m0_cm_sw_update *swu)
Definition: sw_update_fom.c:81
static uint64_t cm_swu_fom_locality(const struct m0_fom *fom)
#define M0_BITS(...)
Definition: misc.h:236
#define container_of(ptr, type, member)
Definition: misc.h:33
m0_fom_phase
Definition: fom.h:372
const struct m0_fom_type * fo_type
Definition: dump.c:107
return M0_RC(rc)
static struct m0_cm * cm
Definition: cm.c:63
M0_INTERNAL void m0_cm_unlock(struct m0_cm *cm)
Definition: cm.c:550
#define M0_ENTRY(...)
Definition: trace.h:170
M0_INTERNAL void m0_cm_complete_notify(struct m0_cm *cm)
Definition: cm.c:1133
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
static struct m0_sm_state_descr cm_sw_update_sd[SWU_NR]
Definition: sw_update_fom.c:62
void m0_fom_fini(struct m0_fom *fom)
Definition: fom.c:1324
const char * scf_name
Definition: sm.h:352
void m0_fom_phase_move(struct m0_fom *fom, int32_t rc, int phase)
Definition: fom.c:1699
uint64_t ct_fom_id
Definition: cm.h:148
static struct m0_cm_sw_update * cm_fom2swu(struct m0_fom *fom)
Definition: sw_update_fom.c:86
M0_INTERNAL void m0_fom_type_init(struct m0_fom_type *type, uint64_t id, const struct m0_fom_type_ops *ops, const struct m0_reqh_service_type *svc_type, const struct m0_sm_conf *sm)
Definition: fom.c:1596
M0_INTERNAL void m0_cm_sw_update_start(struct m0_cm *cm)
static int cm_swu_fom_tick(struct m0_fom *fom)
Definition: dump.c:103
bool swu_is_complete
Definition: sw.h:85
static const struct m0_fom_type_ops cm_sw_update_fom_type_ops
Definition: sw_update_fom.c:59
struct m0_fom swu_fom
Definition: sw.h:83
struct m0_fom_type ct_swu_fomt
Definition: cm.h:152
struct m0_sm_conf cm_sw_update_conf
Definition: sw_update_fom.c:75
static void cm_swu_fom_fini(struct m0_fom *fom)
static int(* swu_action[])(struct m0_cm_sw_update *swu)
uint32_t sd_flags
Definition: sm.h:378
static int swu_update(struct m0_cm_sw_update *swu)
Definition: sw_update_fom.c:91
Definition: fom.h:481
Definition: cm.h:143
M0_INTERNAL void m0_cm_sw_update_complete(struct m0_cm *cm)
cm_sw_update_fom_phase
Definition: sw_update_fom.c:53
struct m0_cm_sw_update cm_sw_update
Definition: cm.h:259
M0_INTERNAL int m0_cm_sw_remote_update(struct m0_cm *cm)
Definition: sw.c:130
struct m0_reqh_service cm_service
Definition: cm.h:191
Definition: cm.h:166
struct m0_reqh_service_type ct_stype
Definition: cm.h:145
M0_INTERNAL void m0_fom_queue(struct m0_fom *fom)
Definition: fom.c:624
M0_INTERNAL void m0_cm_sw_update_init(struct m0_cm_type *cmtype)
void(* fo_fini)(struct m0_fom *fom)
Definition: fom.h:657
M0_INTERNAL void m0_cm_abort(struct m0_cm *cm, int rc)
Definition: cm.c:1181
struct m0_reqh * rs_reqh
Definition: reqh_service.h:259
int32_t rc
Definition: trigger_fop.h:47
#define ARRAY_SIZE(a)
Definition: misc.h:45
M0_INTERNAL int m0_cm_sw_local_update(struct m0_cm *cm)
Definition: sw.c:117