Motr  M0
fol.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 
30 #include "lib/types.h" /* m0_uint128 */
31 #include "lib/assert.h" /* M0_IMPOSSIBLE */
32 #include "lib/errno.h" /* EPROTO */
33 
34 #include "dtm/dtm_internal.h" /* nu_dtm */
35 #include "dtm/catalogue.h"
36 #include "dtm/remote.h"
37 #include "dtm/dtm.h"
38 #include "dtm/fol.h"
39 
40 #define M0_TRACE_SUBSYSTEM M0_TRACE_SUBSYS_DTM
41 #include "lib/trace.h"
42 
43 static const struct m0_dtm_history_ops fol_ops;
44 static const struct m0_dtm_history_ops fol_remote_ops;
45 
46 M0_INTERNAL void m0_dtm_fol_init(struct m0_dtm_fol *fol, struct m0_dtm *dtm)
47 {
48  struct m0_dtm_history *history = &fol->fo_ch.ch_history;
49 
50  m0_dtm_controlh_init(&fol->fo_ch, dtm);
51  history->h_hi.hi_flags |= M0_DHF_OWNED;
52  history->h_ops = &fol_ops;
53  history->h_rem = NULL;
54 }
55 
56 M0_INTERNAL void m0_dtm_fol_fini(struct m0_dtm_fol *fol)
57 {
59 }
60 
61 M0_INTERNAL void m0_dtm_fol_add(struct m0_dtm_fol *fol,
62  struct m0_dtm_oper *oper)
63 {
64  m0_dtm_controlh_add(&fol->fo_ch, oper);
65 }
66 
67 static const struct m0_uint128 *fol_id(const struct m0_dtm_history *history)
68 {
69  return &HISTORY_DTM(history)->d_id;
70 }
71 
72 enum {
75 };
76 
77 static struct m0_dtm_catalogue *rem_fol_cat(struct m0_dtm *dtm)
78 {
79  return &dtm->d_cat[M0_DTM_HTYPE_FOL_REM];
80 }
81 
82 static void fol_persistent(struct m0_dtm_history *history)
83 {
84  struct m0_dtm_catalogue *cat = rem_fol_cat(HISTORY_DTM(history));
85  struct m0_dtm_history *scan;
86 
87  m0_tl_for(cat, &cat->ca_el, scan) {
88  scan->h_rem->re_ops->reo_persistent(scan->h_rem, history);
89  } m0_tl_endfor;
90 }
91 
92 static void fol_fixed(struct m0_dtm_history *history)
93 {
94  M0_IMPOSSIBLE("Fixing fol?");
95 }
96 
97 static int fol_find(struct m0_dtm *dtm, const struct m0_dtm_history_type *ht,
98  const struct m0_uint128 *id, struct m0_dtm_history **out)
99 {
100  if (m0_uint128_eq(id, &dtm->d_id)) {
101  *out = &dtm->d_fol.fo_ch.ch_history;
102  return 0;
103  } else
104  return M0_ERR(-EPROTO);
105 }
106 
107 static const struct m0_dtm_history_type_ops fol_htype_ops = {
108  .hito_find = &fol_find
109 };
110 
111 M0_INTERNAL const struct m0_dtm_history_type m0_dtm_fol_htype = {
113  .hit_rem_id = M0_DTM_HTYPE_FOL_REM,
114  .hit_name = "fol",
115  .hit_ops = &fol_htype_ops
116 };
117 
118 static const struct m0_dtm_history_ops fol_ops = {
120  .hio_id = &fol_id,
121  .hio_persistent = &fol_persistent,
122  .hio_fixed = &fol_fixed,
123  .hio_update = &m0_dtm_controlh_update
124 };
125 
126 M0_INTERNAL void m0_dtm_fol_remote_init(struct m0_dtm_fol_remote *frem,
127  struct m0_dtm *dtm,
128  struct m0_dtm_remote *remote)
129 {
130  struct m0_dtm_history *history = &frem->rfo_ch.ch_history;
131 
132  m0_dtm_controlh_init(&frem->rfo_ch, dtm);
133  history->h_ops = &fol_remote_ops;
134  history->h_rem = remote;
135  m0_dtm_catalogue_add(rem_fol_cat(dtm), history);
136 }
137 
138 M0_INTERNAL void m0_dtm_fol_remote_fini(struct m0_dtm_fol_remote *frem)
139 {
140  struct m0_dtm_history *history = &frem->rfo_ch.ch_history;
141 
142  m0_dtm_catalogue_del(rem_fol_cat(HISTORY_DTM(history)), history);
144 }
145 
146 M0_INTERNAL void m0_dtm_fol_remote_add(struct m0_dtm_fol_remote *frem,
147  struct m0_dtm_oper *oper)
148 {
149  m0_dtm_controlh_add(&frem->rfo_ch, oper);
150 }
151 
152 static const struct m0_uint128 *
153 fol_remote_id(const struct m0_dtm_history *history)
154 {
155  return &history->h_rem->re_id;
156 }
157 
158 static void fol_remote_persistent(struct m0_dtm_history *history)
159 {}
160 
161 static int fol_remote_find(struct m0_dtm *dtm,
162  const struct m0_dtm_history_type *ht,
163  const struct m0_uint128 *id,
164  struct m0_dtm_history **out)
165 {
166  return m0_dtm_catalogue_lookup(rem_fol_cat(dtm), id, out);
167 }
168 
171 };
172 
173 M0_INTERNAL const struct m0_dtm_history_type m0_dtm_fol_remote_htype = {
175  .hit_rem_id = M0_DTM_HTYPE_FOL,
176  .hit_name = "remote fol",
177  .hit_ops = &fol_remote_htype_ops
178 };
179 
180 static const struct m0_dtm_history_ops fol_remote_ops = {
182  .hio_id = &fol_remote_id,
183  .hio_persistent = &fol_remote_persistent,
184  .hio_update = &m0_dtm_controlh_update
185 };
186 
189 #undef M0_TRACE_SUBSYSTEM
190 
191 /*
192  * Local variables:
193  * c-indentation-style: "K&R"
194  * c-basic-offset: 8
195  * tab-width: 8
196  * fill-column: 80
197  * scroll-step: 1
198  * End:
199  */
200 /*
201  * vim: tabstop=8 shiftwidth=8 noexpandtab textwidth=80 nowrap
202  */
static const struct m0_uint128 * fol_id(const struct m0_dtm_history *history)
Definition: fol.c:67
M0_INTERNAL void m0_dtm_controlh_fini(struct m0_dtm_controlh *ch)
Definition: history.c:340
#define NULL
Definition: misc.h:38
M0_INTERNAL void m0_dtm_fol_remote_init(struct m0_dtm_fol_remote *frem, struct m0_dtm *dtm, struct m0_dtm_remote *remote)
Definition: fol.c:126
M0_INTERNAL bool m0_uint128_eq(const struct m0_uint128 *u0, const struct m0_uint128 *u1)
Definition: misc.c:39
uint64_t hi_flags
Definition: nucleus.h:65
struct m0_dtm_remote * h_rem
Definition: history.h:59
M0_INTERNAL void m0_dtm_controlh_init(struct m0_dtm_controlh *ch, struct m0_dtm *dtm)
Definition: history.c:328
static void fol_persistent(struct m0_dtm_history *history)
Definition: fol.c:82
uint8_t hit_id
Definition: history.h:88
static struct m0_dtm_catalogue * rem_fol_cat(struct m0_dtm *dtm)
Definition: fol.c:77
static int fol_remote_find(struct m0_dtm *dtm, const struct m0_dtm_history_type *ht, const struct m0_uint128 *id, struct m0_dtm_history **out)
Definition: fol.c:161
struct m0_dtm_hi h_hi
Definition: history.h:56
struct m0_dtm_catalogue d_cat[M0_DTM_HISTORY_TYPE_NR]
Definition: dtm.h:541
struct m0_tl ca_el
Definition: catalogue.h:46
struct m0_dtm_controlh fo_ch
Definition: fol.h:45
#define m0_tl_endfor
Definition: tlist.h:700
struct m0_dtm_fol d_fol
Definition: dtm.h:542
struct m0_dtm_history ch_history
Definition: history.h:102
M0_INTERNAL const struct m0_dtm_history_type m0_dtm_fol_htype
Definition: fol.c:111
static void fol_fixed(struct m0_dtm_history *history)
Definition: fol.c:92
static void fol_remote_persistent(struct m0_dtm_history *history)
Definition: fol.c:158
return M0_ERR(-EOPNOTSUPP)
static const struct m0_dtm_history_type_ops fol_remote_htype_ops
Definition: fol.c:169
M0_INTERNAL int m0_dtm_catalogue_add(struct m0_dtm_catalogue *cat, struct m0_dtm_history *history)
Definition: catalogue.c:78
struct m0_uint128 d_id
Definition: dtm.h:540
#define HISTORY_DTM(history)
Definition: dtm_internal.h:106
M0_INTERNAL void m0_dtm_fol_init(struct m0_dtm_fol *fol, struct m0_dtm *dtm)
Definition: fol.c:46
Definition: fol.h:44
static const struct m0_dtm_history_ops fol_ops
Definition: fol.c:43
struct m0_dtm_controlh rfo_ch
Definition: fol.h:56
static const struct m0_dtm_history_ops fol_remote_ops
Definition: fol.c:44
M0_INTERNAL void m0_dtm_fol_add(struct m0_dtm_fol *fol, struct m0_dtm_oper *oper)
Definition: fol.c:61
M0_INTERNAL void m0_dtm_fol_remote_fini(struct m0_dtm_fol_remote *frem)
Definition: fol.c:138
M0_INTERNAL const struct m0_dtm_history_type m0_dtm_fol_remote_htype
Definition: fol.c:173
struct m0_uint128 re_id
Definition: remote.h:55
int(* hito_find)(struct m0_dtm *dtm, const struct m0_dtm_history_type *ht, const struct m0_uint128 *id, struct m0_dtm_history **out)
Definition: history.h:95
const struct m0_dtm_history_type * hio_type
Definition: history.h:79
M0_INTERNAL int m0_dtm_controlh_update(struct m0_dtm_history *history, uint8_t id, struct m0_dtm_update *update)
Definition: history.c:393
static struct m0_rm_remote * remote
Definition: rm_fops.c:35
M0_INTERNAL void m0_dtm_fol_remote_add(struct m0_dtm_fol_remote *frem, struct m0_dtm_oper *oper)
Definition: fol.c:146
static const struct m0_uint128 * fol_remote_id(const struct m0_dtm_history *history)
Definition: fol.c:153
Definition: dtm.h:529
static const struct m0_dtm_history_type_ops fol_htype_ops
Definition: fol.c:107
#define out(...)
Definition: gen.c:41
M0_INTERNAL void m0_dtm_controlh_add(struct m0_dtm_controlh *ch, struct m0_dtm_oper *oper)
Definition: history.c:352
static int scan(struct scanner *s)
Definition: beck.c:963
#define m0_tl_for(name, head, obj)
Definition: tlist.h:695
static int fol_find(struct m0_dtm *dtm, const struct m0_dtm_history_type *ht, const struct m0_uint128 *id, struct m0_dtm_history **out)
Definition: fol.c:97
M0_INTERNAL void m0_dtm_fol_fini(struct m0_dtm_fol *fol)
Definition: fol.c:56
M0_INTERNAL int m0_dtm_catalogue_lookup(struct m0_dtm_catalogue *cat, const struct m0_uint128 *id, struct m0_dtm_history **out)
Definition: catalogue.c:69
const struct m0_dtm_history_ops * h_ops
Definition: history.h:65
#define M0_IMPOSSIBLE(fmt,...)
M0_INTERNAL int m0_dtm_catalogue_del(struct m0_dtm_catalogue *cat, struct m0_dtm_history *history)
Definition: catalogue.c:85