Motr  M0
trigger_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_SNSCM
24 #include "lib/trace.h"
25 
26 #include "lib/errno.h"
27 #include "lib/assert.h"
28 #include "lib/memory.h"
29 
30 #include "fop/fop.h"
31 #include "fop/fom.h"
32 #include "fop/fom_generic.h"
33 
34 #include "cm/cm.h"
35 #include "cm/repreb/trigger_fom.h"
36 #include "cm/repreb/trigger_fop.h"
37 #include "sns/cm/trigger_fop.h"
38 #include "sns/cm/cm.h"
39 #include "sns/cm/repair/ag.h"
40 
41 /*
42  * Implements a simplistic sns repair trigger FOM for corresponding trigger FOP.
43  * This is solely for testing purpose and a separate trigger FOP/FOM will be
44  * implemented later, which would be similar to this one.
45  */
46 
47 
48 static int sns_trigger_fom_create(struct m0_fop *fop, struct m0_fom **out,
49  struct m0_reqh *reqh);
50 static struct m0_fop_type *sns_fop_type(uint32_t op);
51 static uint64_t sns_progress(struct m0_fom *fom, bool reinit_counter);
52 static void sns_prepare(struct m0_fom *fom);
53 
54 static const struct m0_fom_trigger_ops sns_trigger_ops = {
56  .fto_progress = sns_progress,
57  .fto_prepare = sns_prepare
58 };
59 
62 };
63 
64 static int sns_trigger_fom_create(struct m0_fop *fop, struct m0_fom **out,
65  struct m0_reqh *reqh)
66 {
67  struct m0_trigger_fom *tfom;
68  int rc;
69 
70  M0_ALLOC_PTR(tfom);
71  if (tfom == NULL)
72  return M0_ERR(-ENOMEM);
73  tfom->tf_ops = &sns_trigger_ops;
74  rc = m0_trigger_fom_create(tfom, fop, reqh);
75  if (rc != 0) {
76  m0_free(tfom);
77  return M0_ERR(rc);
78  }
79  *out = &tfom->tf_fom;
80  return 0;
81 }
82 
83 static struct m0_fop_type *sns_fop_type(uint32_t op)
84 {
85  struct m0_fop_type *sns_fop_type[] = {
102  };
104  return sns_fop_type[op];
105 }
106 
107 static void print__ag(const struct m0_tl_descr *descr, const struct m0_tl *head)
108 {
109  struct m0_cm_aggr_group *ag;
110 
111  m0_tlist_for(descr, head, ag) {
113  M0_LOG(M0_DEBUG, " freed=%u local_cp=%u transformed=%u ref=%u",
114  (unsigned)ag->cag_freed_cp_nr, (unsigned)ag->cag_cp_local_nr,
115  (unsigned)ag->cag_transformed_cp_nr, (unsigned)ag->cag_ref);
116  } m0_tlist_endfor;
117 }
118 
119 static void print_ag(struct m0_cm *cm)
120 {
121  print__ag(&aggr_grps_in_tl, &cm->cm_aggr_grps_in);
122  print__ag(&aggr_grps_out_tl, &cm->cm_aggr_grps_out);
123 }
124 
125 static uint64_t sns_progress(struct m0_fom *fom, bool reinit_counter)
126 {
127  static uint64_t progress = 0;
128  struct m0_cm *cm = container_of(fom->fo_service,
129  struct m0_cm, cm_service);
130 
131  M0_PRE(cm != NULL);
132  if (reinit_counter)
133  progress = 0;
134  /* For debugging purpose. */
135  if (progress > 10)
136  print_ag(cm);
137  return progress++;
138 }
139 
140 static void sns_prepare(struct m0_fom *fom)
141 {
142  struct m0_cm *cm = M0_AMB(cm, fom->fo_service, cm_service);
143  struct m0_sns_cm *scm = cm2sns(cm);
144  struct trigger_fop *treq = m0_fop_data(fom->fo_fop);
145 
146  M0_PRE(scm != NULL);
147  M0_PRE(treq != NULL);
148  M0_PRE(M0_IN(treq->op, (CM_OP_REPAIR, CM_OP_REPAIR_RESUME,
150 
151  if (M0_IN(treq->op, (CM_OP_REPAIR, CM_OP_REBALANCE))) {
152  cm->cm_reset = true;
153  scm->sc_op = treq->op;
154  } else
157 }
158 
159 #undef M0_TRACE_SUBSYSTEM
160 /*
161  * Local variables:
162  * c-indentation-style: "K&R"
163  * c-basic-offset: 8
164  * tab-width: 8
165  * fill-column: 80
166  * scroll-step: 1
167  * End:
168  */
static void print__ag(const struct m0_tl_descr *descr, const struct m0_tl *head)
Definition: trigger_fom.c:107
Definition: cm.h:205
#define M0_PRE(cond)
M0_INTERNAL int m0_trigger_fom_create(struct m0_trigger_fom *tfom, struct m0_fop *fop, struct m0_reqh *reqh)
Definition: trigger_fom.c:84
static struct m0_fop_type * sns_fop_type(uint32_t op)
Definition: trigger_fom.c:83
#define NULL
Definition: misc.h:38
#define M0_AG_P(ag)
Definition: ag.h:55
M0_INTERNAL struct m0_sns_cm * cm2sns(struct m0_cm *cm)
Definition: cm.c:389
#define M0_LOG(level,...)
Definition: trace.h:167
int(* fto_create)(struct m0_fop *fop, struct m0_fom **out, struct m0_reqh *reqh)
Definition: fom.h:650
struct m0_cm_ag_id cag_id
Definition: ag.h:72
static struct m0_sns_cm * scm
Definition: cm.c:64
void * m0_fop_data(const struct m0_fop *fop)
Definition: fop.c:220
struct m0_fop_type m0_sns_repair_status_rep_fopt
#define container_of(ptr, type, member)
Definition: misc.h:33
struct m0_fop_type m0_sns_repair_trigger_rep_fopt
struct m0_fop_type m0_sns_rebalance_abort_rep_fopt
uint32_t op
Definition: trigger_fop.h:52
struct m0_fop_type m0_sns_repair_quiesce_rep_fopt
static const struct m0_fom_trigger_ops sns_trigger_ops
Definition: trigger_fom.c:54
static struct m0_cm * cm
Definition: cm.c:63
op
Definition: libdemo.c:64
static int head(struct m0_sm *mach)
Definition: sm.c:468
enum m0_cm_op sc_op
Definition: cm.h:209
#define M0_AG_F
Definition: ag.h:54
bool cm_reset
Definition: cm.h:271
return M0_ERR(-EOPNOTSUPP)
struct m0_fop_type m0_sns_rebalance_status_rep_fopt
#define M0_AMB(obj, ptr, field)
Definition: misc.h:320
#define M0_ASSERT(cond)
const struct m0_fom_type_ops m0_sns_trigger_fom_type_ops
Definition: trigger_fom.c:60
Definition: tlist.h:251
uint64_t cag_ref
Definition: ag.h:80
struct m0_fom tf_fom
Definition: trigger_fom.h:47
static void sns_prepare(struct m0_fom *fom)
Definition: trigger_fom.c:140
Definition: reqh.h:94
Definition: dump.c:103
static uint64_t sns_progress(struct m0_fom *fom, bool reinit_counter)
Definition: trigger_fom.c:125
uint64_t cag_transformed_cp_nr
Definition: ag.h:95
Definition: fom.h:481
struct m0_tl cm_aggr_grps_out
Definition: cm.h:231
struct m0_reqh reqh
Definition: rm_foms.c:48
uint64_t cag_freed_cp_nr
Definition: ag.h:98
#define M0_ALLOC_PTR(ptr)
Definition: memory.h:86
struct m0_reqh_service cm_service
Definition: cm.h:191
Definition: cm.h:166
static struct m0_fop * fop
Definition: item.c:57
uint64_t cag_cp_local_nr
Definition: ag.h:92
#define IS_IN_ARRAY(idx, array)
Definition: misc.h:311
struct m0_fop_type m0_sns_repair_abort_rep_fopt
#define m0_tlist_endfor
Definition: tlist.h:448
const struct m0_fom_trigger_ops * tf_ops
Definition: trigger_fom.h:46
#define m0_tlist_for(descr, head, obj)
Definition: tlist.h:435
#define out(...)
Definition: gen.c:41
struct m0_fop_type *(* fto_type)(uint32_t op)
Definition: trigger_fom.h:40
struct m0_tl cm_aggr_grps_in
Definition: cm.h:203
void m0_free(void *data)
Definition: memory.c:146
int32_t rc
Definition: trigger_fop.h:47
static void print_ag(struct m0_cm *cm)
Definition: trigger_fom.c:119
Definition: fop.h:79
struct m0_fop_type m0_sns_rebalance_quiesce_rep_fopt
static int sns_trigger_fom_create(struct m0_fop *fop, struct m0_fom **out, struct m0_reqh *reqh)
Definition: trigger_fom.c:64
struct m0_fop_type m0_sns_rebalance_trigger_rep_fopt