Motr  M0
sw.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 
25 #include "lib/trace.h"
26 #include "lib/time.h"
27 #include "lib/misc.h"
28 #include "lib/memory.h"
29 #include "lib/locality.h"
30 
31 #include "fop/fop.h"
32 #include "rpc/rpc.h"
33 #include "motr/setup.h" /* CS_MAX_EP_ADDR_LEN */
34 
35 #include "cm/proxy.h"
36 #include "cm/sw.h"
37 #include "cm/cm.h"
38 
45 M0_INTERNAL bool m0_cm_sw_is_set(const struct m0_cm_sw *sw)
46 {
47  return m0_cm_ag_id_is_set(&sw->sw_lo) ||
49 }
50 
51 M0_INTERNAL bool m0_cm_sw_cmp(const struct m0_cm_sw *sw0, const struct m0_cm_sw *sw1)
52 {
53  return m0_cm_ag_id_cmp(&sw0->sw_lo, &sw1->sw_lo) ?:
54  m0_cm_ag_id_cmp(&sw0->sw_hi, &sw1->sw_hi);
55 }
56 
57 M0_INTERNAL void m0_cm_sw_set(struct m0_cm_sw *dst,
58  const struct m0_cm_ag_id *lo,
59  const struct m0_cm_ag_id *hi)
60 {
61  M0_PRE(dst != NULL && lo != NULL && hi != NULL);
62 
63  m0_cm_ag_id_copy(&dst->sw_lo, lo);
64  m0_cm_ag_id_copy(&dst->sw_hi, hi);
65 }
66 
67 M0_INTERNAL void m0_cm_sw_copy(struct m0_cm_sw *dst,
68  const struct m0_cm_sw *src)
69 {
70  M0_PRE(dst != NULL && src != NULL);
71 
72  m0_cm_ag_id_copy(&dst->sw_lo, &src->sw_lo);
73  m0_cm_ag_id_copy(&dst->sw_hi, &src->sw_hi);
74 }
75 
76 M0_INTERNAL int m0_cm_sw_onwire_init(struct m0_cm *cm,
77  struct m0_cm_sw_onwire *sw_onwire,
78  uint64_t proxy_id, const char *ep,
79  const struct m0_cm_sw *sw,
80  const struct m0_cm_sw *out_interval)
81 {
83  M0_PRE(sw_onwire != NULL && ep != NULL && sw != NULL);
84 
85  M0_ENTRY("cm %p, done %d", cm, (int)cm->cm_done);
86  m0_cm_sw_copy(&sw_onwire->swo_in_interval, sw);
87  m0_cm_sw_copy(&sw_onwire->swo_out_interval, out_interval);
89  sw_onwire->swo_cm_epoch = cm->cm_epoch;
90  sw_onwire->swo_sender_id = proxy_id;
92  if (sw_onwire->swo_cm_ep.ep == NULL )
93  return M0_ERR(-ENOMEM);
94  strncpy(sw_onwire->swo_cm_ep.ep, ep, CS_MAX_EP_ADDR_LEN);
96  sw_onwire->swo_cm_status = M0_PX_FAILED;
97  else if (m0_cm_state_get(cm) == M0_CMS_READY)
98  sw_onwire->swo_cm_status = M0_PX_READY;
99  else if ((!m0_cm_cp_pump_is_complete(&cm->cm_cp_pump) ||
102  sw_onwire->swo_cm_status = M0_PX_ACTIVE;
106  sw_onwire->swo_cm_status = M0_PX_COMPLETE;
107  else
108  sw_onwire->swo_cm_status = M0_PX_STOP;
109 
110  M0_LOG(M0_DEBUG, "local ep=%s state=%u",
111  sw_onwire->swo_cm_ep.ep,
112  sw_onwire->swo_cm_status);
113 
114  return M0_RC(0);
115 }
116 
117 M0_INTERNAL int m0_cm_sw_local_update(struct m0_cm *cm)
118 {
119  int rc;
120 
121  M0_ENTRY("cm: %p", cm);
122  M0_PRE(cm != NULL);
124 
126 
127  return M0_RC(rc);
128 }
129 
130 M0_INTERNAL int m0_cm_sw_remote_update(struct m0_cm *cm)
131 {
132  struct m0_cm_proxy *pxy;
133  struct m0_cm_sw in_interval;
134  struct m0_cm_sw out_interval;
135  bool start = false;
136  int rc = 0;
137  M0_ENTRY();
138 
139  M0_PRE(cm != NULL);
141 
142  m0_cm_ag_in_interval(cm, &in_interval);
143  /* We reset in_interval::sw_hi in M0_CMS_READY state to
144  * struct m0_cm::cm_sw_last_updated_hi, read from persistent
145  * store, saved from previous sns operation which could have
146  * been quiesced and in-order to resume from the same.
147  */
149  if (m0_cm_state_get(cm) == M0_CMS_READY) {
150  start = true;
151  }
152  m0_cm_ag_out_interval(cm, &out_interval);
153  m0_tl_for(proxy, &cm->cm_proxies, pxy) {
155  M0_LOG(M0_DEBUG, "proxy %p (%s) last updated"M0_AG_F,
156  pxy, pxy->px_endpoint,
158  if ((start || pxy->px_send_final_update || cm->cm_quiesce ||
159  cm->cm_abort ||
160  !m0_cm_proxy_is_updated(pxy, &in_interval)) &&
161  pxy->px_update_rc == 0) {
162  rc = m0_cm_proxy_remote_update(pxy, &in_interval,
163  &out_interval);
164  if (rc != 0)
165  break;
166  }
167  } m0_tl_endfor;
168 
169  return M0_RC(rc);
170 }
171 
172 #undef M0_TRACE_SUBSYSTEM
173 
175 /*
176 * Local variables:
177 * c-indentation-style: "K&R"
178 * c-basic-offset: 8
179 * tab-width: 8
180 * fill-column: 80
181 * scroll-step: 1
182 * End:
183 */
M0_INTERNAL void m0_cm_ag_id_copy(struct m0_cm_ag_id *dst, const struct m0_cm_ag_id *src)
Definition: ag.c:83
#define M0_PRE(cond)
#define M0_ALLOC_ARR(arr, nr)
Definition: memory.h:84
Definition: sw.h:45
#define NULL
Definition: misc.h:38
#define M0_AG_P(ag)
Definition: ag.h:55
static struct m0_bufvec dst
Definition: xform.c:61
struct m0_cm_sw swo_in_interval
Definition: sw.h:70
bool cm_quiesce
Definition: cm.h:277
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
struct m0_cm_sw px_last_sw_onwire_sent
Definition: proxy.h:71
bool cm_done
Definition: cm.h:265
M0_INTERNAL void m0_cm_ag_in_interval(const struct m0_cm *cm, struct m0_cm_sw *in_interval)
Definition: ag.c:436
struct m0_cm_local_ep swo_cm_ep
Definition: sw.h:67
M0_INTERNAL bool m0_cm_proxy_is_updated(struct m0_cm_proxy *proxy, struct m0_cm_sw *in_interval)
Definition: proxy.c:390
int px_update_rc
Definition: proxy.h:98
M0_INTERNAL bool m0_cm_ag_id_is_set(const struct m0_cm_ag_id *id)
Definition: ag.c:95
#define m0_tl_endfor
Definition: tlist.h:700
return M0_RC(rc)
static struct m0_cm * cm
Definition: cm.c:63
Definition: sock.c:754
struct m0_tl cm_proxies
Definition: cm.h:246
#define M0_ENTRY(...)
Definition: trace.h:170
#define M0_AG_F
Definition: ag.h:54
M0_INTERNAL void m0_cm_sw_set(struct m0_cm_sw *dst, const struct m0_cm_ag_id *lo, const struct m0_cm_ag_id *hi)
Definition: sw.c:57
return M0_ERR(-EOPNOTSUPP)
uint32_t ep_size
Definition: sw.h:52
M0_INTERNAL void m0_cm_sw_copy(struct m0_cm_sw *dst, const struct m0_cm_sw *src)
Definition: sw.c:67
M0_INTERNAL bool m0_cm_sw_is_set(const struct m0_cm_sw *sw)
Definition: sw.c:45
char * ep
Definition: sw.h:53
const char * px_endpoint
Definition: proxy.h:118
M0_INTERNAL int m0_cm_ag_id_cmp(const struct m0_cm_ag_id *id0, const struct m0_cm_ag_id *id1)
Definition: ag.c:73
M0_INTERNAL int m0_cm_sw_onwire_init(struct m0_cm *cm, struct m0_cm_sw_onwire *sw_onwire, uint64_t proxy_id, const char *ep, const struct m0_cm_sw *sw, const struct m0_cm_sw *out_interval)
Definition: sw.c:76
struct m0_cm_ag_id sw_lo
Definition: sw.h:46
struct m0_cm_sw swo_out_interval
Definition: sw.h:73
bool swu_is_complete
Definition: sw.h:85
bool px_send_final_update
Definition: proxy.h:142
bool m0_cm_cp_pump_is_complete(const struct m0_cm_cp_pump *cp_pump)
Definition: pump.c:420
struct m0_cm_sw_update cm_sw_update
Definition: cm.h:259
M0_INTERNAL void m0_cm_ag_out_interval(const struct m0_cm *cm, struct m0_cm_sw *out_interval)
Definition: ag.c:454
M0_INTERNAL int m0_cm_sw_remote_update(struct m0_cm *cm)
Definition: sw.c:130
M0_INTERNAL int m0_cm_ag_advance(struct m0_cm *cm)
Definition: ag.c:377
Definition: cm.h:166
M0_INTERNAL bool m0_cm_aggr_group_tlists_are_empty(struct m0_cm *cm)
Definition: ag.c:355
static int start(struct m0_fom *fom)
Definition: trigger_fom.c:321
M0_INTERNAL enum m0_cm_state m0_cm_state_get(const struct m0_cm *cm)
Definition: cm.c:565
struct m0_cm_cp_pump cm_cp_pump
Definition: cm.h:257
uint32_t swo_cm_status
Definition: sw.h:75
M0_INTERNAL bool m0_cm_is_locked(const struct m0_cm *cm)
Definition: cm.c:560
uint64_t swo_sender_id
Definition: sw.h:64
#define m0_tl_for(name, head, obj)
Definition: tlist.h:695
M0_INTERNAL bool m0_cm_sw_cmp(const struct m0_cm_sw *sw0, const struct m0_cm_sw *sw1)
Definition: sw.c:51
M0_INTERNAL int m0_cm_proxy_remote_update(struct m0_cm_proxy *proxy, struct m0_cm_sw *in_interval, struct m0_cm_sw *out_interval)
Definition: proxy.c:553
struct m0_pdclust_src_addr src
Definition: fd.c:108
int32_t rc
Definition: trigger_fop.h:47
bool cm_abort
Definition: cm.h:282
static void hi(void)
Definition: nucleus.c:93
m0_time_t cm_epoch
Definition: cm.h:177
Definition: ag.h:49
struct m0_cm_ag_id cm_sw_last_updated_hi
Definition: cm.h:220
M0_INTERNAL int m0_cm_sw_local_update(struct m0_cm *cm)
Definition: sw.c:117