Motr  M0
xform.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 "fid/fid.h"
27 #include "reqh/reqh.h"
28 
29 #include "cm/cm.h"
30 
31 #include "sns/cm/ag.h"
32 #include "sns/cm/cp.h"
33 
34 #include "sns/cm/cm_utils.h"
35 
41 M0_INTERNAL int m0_sns_cm_rebalance_tgt_info(struct m0_sns_cm_ag *sag,
42  struct m0_sns_cm_cp *scp);
43 
50 M0_INTERNAL int m0_sns_cm_rebalance_cp_xform(struct m0_cm_cp *cp)
51 {
52  struct m0_sns_cm_ag *sns_ag;
53  struct m0_sns_cm_cp *scp;
54  struct m0_cm_aggr_group *ag;
55  struct m0_cm_ag_id id;
56  struct m0_cm *cm;
57  struct m0_cm_cp *tgt_cp;
58  enum m0_cm_cp_phase phase;
59  int rc;
60 
61  M0_PRE(cp != NULL && m0_fom_phase(&cp->c_fom) == M0_CCP_XFORM);
62 
63  ag = cp->c_ag;
64  id = ag->cag_id;
65  sns_ag = ag2snsag(ag);
66  scp = cp2snscp(cp);
67  cm = ag->cag_cm;
68  m0_cm_ag_lock(ag);
69 
70  M0_LOG(M0_DEBUG, "xform: id ["M0_AG_F"] local_cp_nr: [%" PRIu64 "]"
71  "transformed_cp_nr: [%" PRIu64 "] has_incoming: %d\n",
72  M0_AG_P(&id), ag->cag_cp_local_nr,
74 
75  /* Increment number of transformed copy packets in the accumulator. */
77  if (!ag->cag_has_incoming)
79 
83  if (rc == 0) {
84  /*
85  * Handle concurrancy of multiple copy packet foms writing
86  * to the same stob through different reqh localities by
87  * starting a duplicate copy packet fom for writing and
88  * finalising the source copy packet @cp.
89  * Concurrancy is handled by running the copy packet foms
90  * doing i/o to a same stob in the same reqh locality.
91  */
92  rc = m0_sns_cm_cp_dup(cp, &tgt_cp);
93  if (rc == 0) {
94  if (scp->sc_is_local) {
97  } else
99 
100  rc = m0_cm_cp_enqueue(cm, tgt_cp);
101  }
102  }
103 
104  if (rc == 0 || rc == -ENOENT) {
105  phase = M0_CCP_FINI;
106  rc = 0;
107  } else
108  phase = M0_CCP_FAIL;
109  m0_fom_phase_move(&cp->c_fom, rc, phase);
110  rc = phase == M0_CCP_FAIL ? M0_FSO_AGAIN : M0_FSO_WAIT;
111  m0_cm_ag_unlock(ag);
112 
113  return M0_RC(rc);
114 }
115 
116 #undef M0_TRACE_SUBSYSTEM
117 
118 /*
119  * Local variables:
120  * c-indentation-style: "K&R"
121  * c-basic-offset: 8
122  * tab-width: 8
123  * fill-column: 80
124  * scroll-step: 1
125  * End:
126  */
uint64_t id
Definition: cob.h:2380
M0_INTERNAL void m0_cm_ag_unlock(struct m0_cm_aggr_group *ag)
Definition: ag.c:63
#define M0_PRE(cond)
#define NULL
Definition: misc.h:38
#define M0_AG_P(ag)
Definition: ag.h:55
#define M0_LOG(level,...)
Definition: trace.h:167
Definition: cp.h:160
struct m0_cm_ag_id cag_id
Definition: ag.h:72
M0_INTERNAL bool m0_fid_is_set(const struct m0_fid *fid)
Definition: fid.c:106
m0_fom_phase
Definition: fom.h:372
return M0_RC(rc)
struct m0_fid sc_cobfid
Definition: cp.h:42
#define M0_AG_F
Definition: ag.h:54
static struct m0_sns_cm_ag * sag
Definition: cm.c:66
#define PRIu64
Definition: types.h:58
M0_INTERNAL void m0_cm_ag_lock(struct m0_cm_aggr_group *ag)
Definition: ag.c:58
#define M0_ASSERT(cond)
void m0_fom_phase_move(struct m0_fom *fom, int32_t rc, int phase)
Definition: fom.c:1699
struct m0_cm * cag_cm
Definition: ag.h:70
M0_INTERNAL int m0_sns_cm_cp_dup(struct m0_cm_cp *src, struct m0_cm_cp **dest)
Definition: cp.c:400
struct m0_cm_aggr_group * c_ag
Definition: cp.h:172
uint32_t sag_incoming_cp_nr
Definition: ag.h:72
M0_INTERNAL struct m0_sns_cm_cp * cp2snscp(const struct m0_cm_cp *cp)
Definition: cp.c:57
M0_INTERNAL int m0_sns_cm_rebalance_cp_xform(struct m0_cm_cp *cp)
Definition: xform.c:50
M0_INTERNAL int m0_sns_cm_rebalance_tgt_info(struct m0_sns_cm_ag *sag, struct m0_sns_cm_cp *scp)
Definition: helpers.c:190
uint64_t cag_transformed_cp_nr
Definition: ag.h:95
M0_INTERNAL int m0_cm_cp_enqueue(struct m0_cm *cm, struct m0_cm_cp *cp)
Definition: cp.c:688
#define M0_CNT_INC(cnt)
Definition: arith.h:226
static struct m0_sns_cm_cp scp
Definition: cm.c:65
bool sc_is_local
Definition: cp.h:53
Definition: cm.h:166
uint64_t cag_cp_local_nr
Definition: ag.h:92
uint32_t sag_cp_created_nr
Definition: ag.h:60
static struct m0_cm * cm
Definition: xform.c:52
bool cag_has_incoming
Definition: ag.h:101
struct m0_fom c_fom
Definition: cp.h:161
m0_cm_cp_phase
Definition: cp.h:100
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
Definition: ag.h:49