Motr  M0
ag.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_SNSCM
24 #include "lib/trace.h"
25 
26 #include "lib/memory.h"
27 #include "lib/errno.h"
28 #include "lib/misc.h"
29 
30 #include "fid/fid.h"
31 #include "sns/parity_repair.h"
32 
33 #include "cm/proxy.h"
34 #include "sns/cm/cm_utils.h"
35 #include "sns/cm/rebalance/ag.h"
36 #include "sns/cm/cp.h"
37 #include "sns/cm/cm.h"
38 #include "sns/cm/iter.h"
39 #include "sns/cm/file.h"
40 
47 M0_INTERNAL struct m0_sns_cm_rebalance_ag *
49 {
51 }
52 
53 static void rebalance_ag_fini(struct m0_cm_aggr_group *ag)
54 {
56  struct m0_sns_cm_ag *sag;
57  struct m0_sns_cm *scm;
58  struct m0_pdclust_layout *pl;
59  uint32_t nr_cp_bufs;
60  uint32_t unused_cps;
61  uint32_t nr_bufs;
62 
63 
64  M0_ENTRY();
65  M0_PRE(ag != NULL);
66 
67  sag = ag2snsag(ag);
69  scm = cm2sns(ag->cag_cm);
71  nr_cp_bufs = m0_sns_cm_cp_buf_nr(&scm->sc_ibp.sb_bp,
73  if (ag->cag_has_incoming) {
74  unused_cps = sag->sag_not_coming * sag->sag_local_tgts_nr;
75  nr_bufs = unused_cps * nr_cp_bufs;
77  }
79  m0_free(rag);
80 
81  M0_LEAVE();
82 }
83 
84 static bool rebalance_ag_can_fini(const struct m0_cm_aggr_group *ag)
85 {
86  struct m0_sns_cm_ag *sag = ag2snsag(ag);
87 
88  M0_PRE(ag != NULL);
89 
90  if (ag->cag_is_frozen || ag->cag_rc != 0)
91  return ag->cag_ref == 0;
92  if (ag->cag_has_incoming) {
93  return ag->cag_freed_cp_nr == sag->sag_incoming_cp_nr +
94  ag->cag_cp_local_nr;
95  } else
96  return ag->cag_freed_cp_nr == ag->cag_cp_local_nr;
97 }
98 
101  .cago_fini = rebalance_ag_fini,
102  .cago_local_cp_nr = m0_sns_cm_ag_local_cp_nr,
103  .cago_has_incoming_from = m0_sns_cm_ag_has_incoming_from,
104  .cago_is_frozen_on = m0_sns_cm_ag_is_frozen_on
105 };
106 
107 M0_INTERNAL int m0_sns_cm_rebalance_ag_alloc(struct m0_cm *cm,
108  const struct m0_cm_ag_id *id,
109  bool has_incoming,
110  struct m0_cm_aggr_group **out)
111 {
112  struct m0_sns_cm_rebalance_ag *rag;
113  struct m0_sns_cm_ag *sag;
114  int rc = 0;
115 
116  M0_ENTRY("scm: %p, ag id:%p", cm, id);
117  M0_PRE(cm != NULL && id != NULL && out != NULL);
119 
120  /* Allocate new aggregation group. */
121  M0_ALLOC_PTR(rag);
122  if (rag == NULL)
123  return M0_ERR(-ENOMEM);
124  sag = &rag->rag_base;
126  has_incoming);
127  if (rc != 0) {
128  m0_free(rag);
129  return M0_RC(rc);
130  }
131 
133  *out = &sag->sag_base;
134  M0_LEAVE("ag: %p", &sag->sag_base);
135  return M0_RC(rc);
136 }
137 
139  struct m0_pdclust_layout *pl)
140 {
141  return 0;
142 }
143 
145 #undef M0_TRACE_SUBSYSTEM
146 
147 /*
148  * Local variables:
149  * c-indentation-style: "K&R"
150  * c-basic-offset: 8
151  * tab-width: 8
152  * fill-column: 79
153  * scroll-step: 1
154  * End:
155  */
Definition: cm.h:205
uint32_t sag_not_coming
Definition: ag.h:81
M0_INTERNAL uint64_t m0_sns_cm_ag_local_cp_nr(const struct m0_cm_aggr_group *ag)
Definition: ag.c:420
#define M0_PRE(cond)
#define NULL
Definition: misc.h:38
M0_INTERNAL struct m0_sns_cm * cm2sns(struct m0_cm *cm)
Definition: cm.c:389
static const struct m0_cm_aggr_group_ops sns_cm_rebalance_ag_ops
Definition: ag.c:99
M0_LEAVE()
M0_INTERNAL int m0_sns_cm_rebalance_ag_setup(struct m0_sns_cm_ag *sag, struct m0_pdclust_layout *pl)
Definition: ag.c:138
struct m0_layout * sf_layout
Definition: file.h:74
static struct m0_sns_cm * scm
Definition: cm.c:64
M0_INTERNAL void m0_sns_cm_ag_fini(struct m0_sns_cm_ag *sag)
Definition: ag.c:443
struct m0_sns_cm_buf_pool sc_ibp
Definition: cm.h:227
#define container_of(ptr, type, member)
Definition: misc.h:33
return M0_RC(rc)
static struct m0_cm * cm
Definition: cm.c:63
#define M0_ENTRY(...)
Definition: trace.h:170
bool cag_is_frozen
Definition: ag.h:106
M0_INTERNAL struct m0_sns_cm_rebalance_ag * sag2rebalanceag(const struct m0_sns_cm_ag *sag)
Definition: ag.c:48
static struct m0_sns_cm_ag * sag
Definition: cm.c:66
return M0_ERR(-EOPNOTSUPP)
M0_INTERNAL bool m0_sns_cm_ag_is_frozen_on(struct m0_cm_aggr_group *ag, struct m0_cm_proxy *pxy)
Definition: ag.c:541
struct m0_sns_cm_ag rag_base
Definition: ag.h:77
struct m0_sns_cm_ag rag_base
Definition: ag.h:39
int cag_rc
Definition: ag.h:126
M0_INTERNAL bool m0_sns_cm_ag_has_incoming_from(struct m0_cm_aggr_group *ag, struct m0_cm_proxy *proxy)
Definition: ag.c:528
struct m0_cm * cag_cm
Definition: ag.h:70
M0_INTERNAL uint64_t m0_sns_cm_cp_buf_nr(struct m0_net_buffer_pool *bp, uint64_t data_seg_nr)
Definition: cm.c:795
uint64_t cag_ref
Definition: ag.h:80
M0_INTERNAL struct m0_pdclust_layout * m0_layout_to_pdl(const struct m0_layout *l)
Definition: pdclust.c:382
static bool rebalance_ag_can_fini(const struct m0_cm_aggr_group *ag)
Definition: ag.c:84
uint32_t sag_incoming_cp_nr
Definition: ag.h:72
struct m0_sns_cm_file_ctx * sag_fctx
Definition: ag.h:48
M0_INTERNAL int m0_sns_cm_ag_init(struct m0_sns_cm_ag *sag, struct m0_cm *cm, const struct m0_cm_ag_id *id, const struct m0_cm_aggr_group_ops *ag_ops, bool has_incoming)
Definition: ag.c:464
struct m0_net_buffer_pool sb_bp
Definition: cm.h:135
uint64_t cag_freed_cp_nr
Definition: ag.h:98
M0_INTERNAL uint64_t m0_sns_cm_data_seg_nr(struct m0_sns_cm *scm, struct m0_pdclust_layout *pl)
Definition: cm.c:845
uint32_t sag_local_tgts_nr
Definition: ag.h:78
#define M0_ALLOC_PTR(ptr)
Definition: memory.h:86
Definition: cm.h:166
uint64_t cag_cp_local_nr
Definition: ag.h:92
M0_INTERNAL void m0_sns_cm_cancel_reservation(struct m0_sns_cm *scm, size_t nr_bufs)
Definition: cm.c:926
static struct m0_sns_cm_repair_ag rag
Definition: net.c:54
bool cag_has_incoming
Definition: ag.h:101
#define out(...)
Definition: gen.c:41
struct m0_cm_aggr_group sag_base
Definition: ag.h:46
bool(* cago_ag_can_fini)(const struct m0_cm_aggr_group *ag)
Definition: ag.h:137
M0_INTERNAL bool m0_cm_is_locked(const struct m0_cm *cm)
Definition: cm.c:560
void m0_free(void *data)
Definition: memory.c:146
static void rebalance_ag_fini(struct m0_cm_aggr_group *ag)
Definition: ag.c:53
M0_INTERNAL struct m0_sns_cm_ag * ag2snsag(const struct m0_cm_aggr_group *ag)
Definition: ag.c:391
int32_t rc
Definition: trigger_fop.h:47
M0_INTERNAL int m0_sns_cm_rebalance_ag_alloc(struct m0_cm *cm, const struct m0_cm_ag_id *id, bool has_incoming, struct m0_cm_aggr_group **out)
Definition: ag.c:107
Definition: ag.h:49
static uint nr_bufs