Motr  M0
trigger_fom.c
Go to the documentation of this file.
1 /* -*- C -*- */
2 /*
3  * Copyright (c) 2016-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 
30 #define M0_TRACE_SUBSYSTEM M0_TRACE_SUBSYS_DIXCM
31 #include "fop/fop.h"
32 #include "cm/repreb/trigger_fom.h"
33 #include "cm/repreb/trigger_fop.h"
34 #include "cm/repreb/trigger_fop_xc.h"
35 #include "dix/cm/cm.h"
36 #include "dix/cm/trigger_fop.h"
37 #include "lib/memory.h"
38 #include "lib/errno.h"
39 #include "lib/trace.h"
40 
41 
42 static int dix_trigger_fom_create(struct m0_fop *fop, struct m0_fom **out,
43  struct m0_reqh *reqh);
44 static struct m0_fop_type *dix_fop_type(uint32_t op);
45 static uint64_t dix_progress(struct m0_fom *fom, bool reinit_counter);
46 static void dix_prepare(struct m0_fom *fom);
47 
48 
49 static const struct m0_fom_trigger_ops dix_trigger_ops = {
51  .fto_progress = dix_progress,
52  .fto_prepare = dix_prepare
53 };
54 
57 };
58 
59 static int dix_trigger_fom_create(struct m0_fop *fop, struct m0_fom **out,
60  struct m0_reqh *reqh)
61 {
62  struct m0_trigger_fom *tfom;
63  int rc;
64 
65  M0_ALLOC_PTR(tfom);
66  if (tfom == NULL)
67  return M0_ERR(-ENOMEM);
68  tfom->tf_ops = &dix_trigger_ops;
69  rc = m0_trigger_fom_create(tfom, fop, reqh);
70  if (rc != 0) {
71  m0_free(tfom);
72  return M0_ERR(rc);
73  }
74  *out = &tfom->tf_fom;
75  return 0;
76 }
77 
78 static struct m0_fop_type *dix_fop_type(uint32_t op)
79 {
80  struct m0_fop_type *dix_fop_type[] = {
97  };
99  return dix_fop_type[op];
100 }
101 
102 static uint64_t dix_progress(struct m0_fom *fom, bool reinit_counter)
103 {
104  struct m0_cm *cm = container_of(fom->fo_service,
105  struct m0_cm, cm_service);
106  struct m0_dix_cm *dcm = cm2dix(cm);
107  int progress;
108 
109  if (reinit_counter)
110  dcm->dcm_recs_nr = m0_ctg_rec_nr();
111  progress = dcm->dcm_recs_nr == 0 ? 100 :
112  dcm->dcm_processed_nr * 100 / dcm->dcm_recs_nr;
113  return progress;
114 }
115 
116 static void dix_prepare(struct m0_fom *fom)
117 {
118  struct m0_cm *cm = container_of(fom->fo_service,
119  struct m0_cm, cm_service);
120  struct m0_dix_cm *dcm = cm2dix(cm);
121  struct trigger_fop *treq = m0_fop_data(fom->fo_fop);
122 
123  M0_PRE(dcm != NULL);
124  M0_PRE(treq != NULL);
125  dcm->dcm_op = treq->op;
126 }
127 
128 
129 #undef M0_TRACE_SUBSYSTEM
130 
133 /*
134  * Local variables:
135  * c-indentation-style: "K&R"
136  * c-basic-offset: 8
137  * tab-width: 8
138  * fill-column: 80
139  * scroll-step: 1
140  * End:
141  */
142 /*
143  * vim: tabstop=8 shiftwidth=8 noexpandtab textwidth=80 nowrap
144  */
uint64_t dcm_recs_nr
Definition: cm.h:165
static int dix_trigger_fom_create(struct m0_fop *fop, struct m0_fom **out, struct m0_reqh *reqh)
Definition: trigger_fom.c:59
M0_INTERNAL struct m0_dix_cm * cm2dix(struct m0_cm *cm)
Definition: cm.c:308
#define M0_PRE(cond)
static struct m0_fop_type * dix_fop_type(uint32_t op)
Definition: trigger_fom.c:78
struct m0_fop_type m0_dix_rebalance_abort_rep_fopt
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
#define NULL
Definition: misc.h:38
M0_INTERNAL uint64_t m0_ctg_rec_nr(void)
Definition: ctg_store.c:2145
int(* fto_create)(struct m0_fop *fop, struct m0_fom **out, struct m0_reqh *reqh)
Definition: fom.h:650
struct m0_fop_type m0_dix_repair_quiesce_rep_fopt
void * m0_fop_data(const struct m0_fop *fop)
Definition: fop.c:220
#define container_of(ptr, type, member)
Definition: misc.h:33
uint32_t op
Definition: trigger_fop.h:52
static struct m0_cm * cm
Definition: cm.c:63
op
Definition: libdemo.c:64
const struct m0_fom_type_ops m0_dix_trigger_fom_type_ops
Definition: trigger_fom.c:55
return M0_ERR(-EOPNOTSUPP)
struct m0_fop_type m0_dix_rebalance_trigger_rep_fopt
struct m0_fop_type m0_dix_repair_status_rep_fopt
#define M0_ASSERT(cond)
struct m0_fop_type m0_dix_rebalance_quiesce_rep_fopt
static uint64_t dix_progress(struct m0_fom *fom, bool reinit_counter)
Definition: trigger_fom.c:102
struct m0_fom tf_fom
Definition: trigger_fom.h:47
Definition: reqh.h:94
Definition: dump.c:103
Definition: cm.h:117
Definition: fom.h:481
enum m0_cm_op dcm_op
Definition: cm.h:125
struct m0_reqh reqh
Definition: rm_foms.c:48
struct m0_fop_type m0_dix_rebalance_status_rep_fopt
#define M0_ALLOC_PTR(ptr)
Definition: memory.h:86
struct m0_reqh_service cm_service
Definition: cm.h:191
Definition: cm.h:166
static const struct m0_fom_trigger_ops dix_trigger_ops
Definition: trigger_fom.c:49
static struct m0_fop * fop
Definition: item.c:57
#define IS_IN_ARRAY(idx, array)
Definition: misc.h:311
const struct m0_fom_trigger_ops * tf_ops
Definition: trigger_fom.h:46
struct m0_fop_type m0_dix_repair_abort_rep_fopt
static void dix_prepare(struct m0_fom *fom)
Definition: trigger_fom.c:116
#define out(...)
Definition: gen.c:41
int dcm_processed_nr
Definition: cm.h:160
struct m0_fop_type *(* fto_type)(uint32_t op)
Definition: trigger_fom.h:40
void m0_free(void *data)
Definition: memory.c:146
int32_t rc
Definition: trigger_fop.h:47
Definition: fop.h:79
struct m0_fop_type m0_dix_repair_trigger_rep_fopt