Motr  M0
fom_interpose.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 #include "lib/assert.h"
24 #include "lib/misc.h"
25 #include "lib/buf.h"
26 #include "fop/fop.h"
27 
28 #include "fop/fom_interpose.h"
29 
30 enum { INTERPOSE_CONT = M0_FSO_NR + 1 };
31 
32 static int thrall_finish(struct m0_fom *fom, struct m0_fom_interpose *proxy,
33  int result);
34 
35 static const struct m0_fom_interpose_ops thrall_ops = {
36  .io_post = {
38  }
39 };
40 
41 static int interpose_tick(struct m0_fom *fom)
42 {
43  struct m0_fom_interpose *proxy = M0_AMB(proxy, fom->fo_ops, fi_shim);
44  int phase = m0_fom_phase(fom);
45  int result;
46 
47  M0_PRE(IS_IN_ARRAY(phase, proxy->fi_ops->io_pre));
48  M0_PRE(IS_IN_ARRAY(phase, proxy->fi_ops->io_post));
49  if (proxy->fi_ops->io_pre[phase] != NULL) {
50  result = (proxy->fi_ops->io_pre[phase])(fom, proxy);
51  if (result != INTERPOSE_CONT)
52  return result;
53  }
54  /*
55  * Perhaps restore original fom->fo_ops around this call?
56  */
57  result = proxy->fi_orig->fo_tick(fom);
58  M0_ASSERT(result != INTERPOSE_CONT);
59  if (proxy->fi_ops->io_post[phase] != NULL)
60  result = (proxy->fi_ops->io_post[phase])(fom, proxy, result);
61  M0_POST(M0_IN(result, (M0_FSO_WAIT, M0_FSO_AGAIN)));
62  return result;
63 }
64 
65 static int thrall_finish(struct m0_fom *fom, struct m0_fom_interpose *proxy,
66  int result)
67 {
68  struct m0_fom_thralldom *thrall = M0_AMB(thrall, proxy, ft_fief);
69  int phase = m0_fom_phase(fom);
70 
71  if (phase == M0_FOM_PHASE_FINISH) {
72  /* Mors liberat. */
74  if (thrall->ft_end != NULL)
77  }
78  return result;
79 }
80 
81 M0_INTERNAL void m0_fom_interpose_enter(struct m0_fom *fom,
82  struct m0_fom_interpose *proxy)
83 {
84  M0_PRE(proxy->fi_ops != NULL);
85  /*
86  * Activate the interposition. Substitute shim fom operation vector for
87  * the original one after saving the original in proxy->fi_orig.
88  */
89  proxy->fi_orig = fom->fo_ops;
90  proxy->fi_shim = *fom->fo_ops;
91  proxy->fi_shim.fo_tick = &interpose_tick;
92  fom->fo_ops = &proxy->fi_shim;
93 }
94 
95 M0_INTERNAL void m0_fom_interpose_leave(struct m0_fom *fom,
96  struct m0_fom_interpose *proxy)
97 {
98  M0_PRE(fom->fo_ops == &proxy->fi_shim);
99  fom->fo_ops = proxy->fi_orig;
100 }
101 
102 M0_INTERNAL void m0_fom_enthrall(struct m0_fom *leader, struct m0_fom *serf,
103  struct m0_fom_thralldom *thrall,
104  void (*end)(struct m0_fom_thralldom *thrall,
105  struct m0_fom *serf))
106 {
107  thrall->ft_leader = leader;
109  thrall->ft_end = end;
111 }
112 
113 /*
114  * Local variables:
115  * c-indentation-style: "K&R"
116  * c-basic-offset: 8
117  * tab-width: 8
118  * fill-column: 80
119  * scroll-step: 1
120  * End:
121  */
int(* io_post[64])(struct m0_fom *fom, struct m0_fom_interpose *proxy, int result)
Definition: fom_interpose.h:71
M0_INTERNAL void m0_fom_wakeup(struct m0_fom *fom)
Definition: fom.c:532
#define M0_PRE(cond)
#define NULL
Definition: misc.h:38
int(* fo_tick)(struct m0_fom *fom)
Definition: fom.h:663
void(* ft_end)(struct m0_fom_thralldom *thrall, struct m0_fom *serf)
Definition: fom_interpose.h:88
struct m0_fom * ft_leader
Definition: fom_interpose.h:81
m0_fom_phase
Definition: fom.h:372
int(* io_pre[64])(struct m0_fom *fom, struct m0_fom_interpose *proxy)
Definition: fom_interpose.h:62
M0_INTERNAL void m0_fom_interpose_enter(struct m0_fom *fom, struct m0_fom_interpose *proxy)
Definition: fom_interpose.c:81
Definition: fom.h:644
#define M0_AMB(obj, ptr, field)
Definition: misc.h:320
struct m0_fom_thralldom thrall
Definition: ms_fom_ut.c:110
#define M0_ASSERT(cond)
static int thrall_finish(struct m0_fom *fom, struct m0_fom_interpose *proxy, int result)
Definition: fom_interpose.c:65
M0_INTERNAL void m0_fom_enthrall(struct m0_fom *leader, struct m0_fom *serf, struct m0_fom_thralldom *thrall, void(*end)(struct m0_fom_thralldom *thrall, struct m0_fom *serf))
#define M0_POST(cond)
const struct m0_fom_ops * fi_orig
Definition: fom_interpose.h:45
Definition: dump.c:103
struct m0_fom_ops fi_shim
Definition: fom_interpose.h:44
Definition: fom.h:481
#define IS_IN_ARRAY(idx, array)
Definition: misc.h:311
const struct m0_fom_interpose_ops * fi_ops
Definition: fom_interpose.h:46
static const struct m0_fom_interpose_ops thrall_ops
Definition: fom_interpose.c:35
struct m0_fom_interpose ft_fief
Definition: fom_interpose.h:86
M0_INTERNAL void m0_fom_interpose_leave(struct m0_fom *fom, struct m0_fom_interpose *proxy)
Definition: fom_interpose.c:95
static int interpose_tick(struct m0_fom *fom)
Definition: fom_interpose.c:41
#define ARRAY_SIZE(a)
Definition: misc.h:45