Motr  M0
tx_desc.h
Go to the documentation of this file.
1 /* -*- C -*- */
2 /*
3  * Copyright (c) 2021 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 #pragma once
24 
25 #ifndef __MOTR_DTM0_TX_DESC_H__
26 #define __MOTR_DTM0_TX_DESC_H__
27 
28 /* Transaction descriptor
29  * ----------------------
30  *
31  * Transaction descriptor is a on-wire/on-disk used to attach the following
32  * information to RPC messages and log records:
33  * * unique TX id;
34  * * list of participants and their states;
35  *
36  * Use-cases
37  * ---------
38  *
39  * 1. Tx descriptor as a part of a log record:
40  * @verbatim
41  * struct log_record {
42  * tx_descr td;
43  * request req;
44  * tlink vlog_linkage;
45  * };
46  *
47  * ...
48  * log_record *rec = alloc();
49  * tx_desc_copy((fop.data as kvs_op).td, rec.td);
50  * rec->req = fop.data.copy();
51  * log_add(rec);
52  * ...
53  *
54  * @endverbatim
55  *
56  * 2. Tx descriptor as a part of a data/metadata message:
57  * @verbatim
58  * struct kvs_op {
59  * tx_descr td;
60  * kv_pairs kv;
61  * };
62  *
63  * ...
64  * kvs_op op;
65  * nr_devices = layout.nr_devices();
66  * tx_desc_init(&op->td, nr_devices);
67  * ...
68  *
69  * @endverbatim
70  *
71  * 3. Tx descriptor as a part of a notice:
72  * @verbatim
73  * struct persistent_notice_op {
74  * tx_descr td;
75  * };
76  *
77  * ...
78  * log_record = fom.log_record;
79  * persistent_notice_op item;
80  * tx_desc_copy(&item->td, log_record->td);
81  * post_item(persistent);
82  * ....
83  *
84  * @endverbatim
85  */
86 
87 #include "fid/fid.h" /* m0_fid */
88 #include "fid/fid_xc.h"
89 #include "dtm0/clk_src.h" /* ts and cs */
90 #include "dtm0/clk_src_xc.h"
91 #include "xcode/xcode.h" /* XCA */
92 
93 struct m0_dtm0_tid {
95  struct m0_fid dti_fid;
96 } M0_XCA_RECORD M0_XCA_DOMAIN(rpc|be);
97 
98 #define DTID0_F "{" DTS0_F "," FID_F "}"
99 #define DTID0_P(__tid) DTS0_P(&(__tid)->dti_ts), FID_P(&(__tid)->dti_fid)
100 
102  M0_DTPS_INIT,
106  M0_DTPS_NR,
108 
110  struct m0_fid p_fid;
111  uint32_t p_state M0_XCA_FENUM(m0_dtm0_tx_pa_state);
112 } M0_XCA_RECORD M0_XCA_DOMAIN(rpc|be);
113 
116  uint32_t dtp_nr;
118 } M0_XCA_SEQUENCE M0_XCA_DOMAIN(rpc|be);
119 
123 } M0_XCA_RECORD M0_XCA_DOMAIN(rpc|be);
124 
126 M0_INTERNAL int m0_dtm0_tx_desc_copy(const struct m0_dtm0_tx_desc *src,
127  struct m0_dtm0_tx_desc *dst);
128 
130 M0_INTERNAL int m0_dtm0_tx_desc_init(struct m0_dtm0_tx_desc *td,
131  uint32_t nr_pa);
132 
133 M0_INTERNAL void m0_dtm0_tx_desc_fini(struct m0_dtm0_tx_desc *td);
134 
135 M0_INTERNAL int m0_dtm0_tid_cmp(struct m0_dtm0_clk_src *cs,
136  const struct m0_dtm0_tid *left,
137  const struct m0_dtm0_tid *right);
138 
139 M0_INTERNAL void m0_dtm0_tx_desc_init_none(struct m0_dtm0_tx_desc *td);
140 M0_INTERNAL bool m0_dtm0_tx_desc_is_none(const struct m0_dtm0_tx_desc *td);
141 
142 M0_INTERNAL bool m0_dtm0_tid__invariant(const struct m0_dtm0_tid *tid);
143 M0_INTERNAL bool m0_dtm0_tx_desc__invariant(const struct m0_dtm0_tx_desc *td);
144 
148 M0_INTERNAL bool m0_dtm0_tx_desc_state_eq(const struct m0_dtm0_tx_desc *txd,
149  enum m0_dtm0_tx_pa_state state);
150 
158 M0_INTERNAL void m0_dtm0_tx_desc_apply(struct m0_dtm0_tx_desc *tgt,
159  const struct m0_dtm0_tx_desc *upd);
160 
161 /* TODO: move them to a dtm0 internal header? */
162 
163 #define dtds_forall(__txd, __exp) \
164  m0_forall(i, (__txd)->dtd_ps.dtp_nr, \
165  (__txd)->dtd_ps.dtp_pa[i].p_state __exp)
166 
167 #define dtds_exists(__txd, __exp) !dtds_forall(__txd, __exp)
168 
169 
170 
171 #endif /* __MOTR_DTM0_TX_DESC_H__ */
172 
173 /*
174  * Local variables:
175  * c-indentation-style: "K&R"
176  * c-basic-offset: 8
177  * tab-width: 8
178  * fill-column: 80
179  * scroll-step: 1
180  * End:
181  */
182 /*
183  * vim: tabstop=8 shiftwidth=8 noexpandtab textwidth=80 nowrap
184  */
M0_INTERNAL int m0_dtm0_tx_desc_init(struct m0_dtm0_tx_desc *td, uint32_t nr_pa)
Definition: tx_desc.c:97
static struct m0_bufvec dst
Definition: xform.c:61
uint32_t p_state M0_XCA_FENUM(m0_dtm0_tx_pa_state)
struct m0_dtm0_ts dti_ts
Definition: tx_desc.h:94
M0_DTPS_INPROGRESS
Definition: tx_desc.h:164
static int left
Definition: locality.c:280
M0_INTERNAL bool m0_dtm0_tx_desc__invariant(const struct m0_dtm0_tx_desc *td)
Definition: tx_desc.c:49
M0_INTERNAL void m0_dtm0_tx_desc_init_none(struct m0_dtm0_tx_desc *td)
Definition: tx_desc.c:39
M0_INTERNAL void m0_dtm0_tx_desc_apply(struct m0_dtm0_tx_desc *tgt, const struct m0_dtm0_tx_desc *upd)
Definition: tx_desc.c:127
struct m0_dtm0_tid dtd_id
Definition: tx_desc.h:121
static void upd(void)
Definition: client_ut.c:2974
struct m0_dtm0_tid M0_XCA_DOMAIN(rpc|be)
M0_INTERNAL bool m0_dtm0_tid__invariant(const struct m0_dtm0_tid *tid)
Definition: tx_desc.c:68
M0_DTPS_NR
Definition: tx_desc.h:164
M0_DTPS_EXECUTED
Definition: tx_desc.h:164
struct m0_fid p_fid
Definition: tx_desc.h:110
M0_INTERNAL int m0_dtm0_tx_desc_copy(const struct m0_dtm0_tx_desc *src, struct m0_dtm0_tx_desc *dst)
Definition: tx_desc.c:76
struct m0_dtm0_tx_pa * dtp_pa
Definition: tx_desc.h:117
struct m0_pdclust_tgt_addr tgt
Definition: fd.c:110
M0_INTERNAL bool m0_dtm0_tx_desc_is_none(const struct m0_dtm0_tx_desc *td)
Definition: tx_desc.c:44
Definition: fid.h:38
M0_DTPS_PERSISTENT
Definition: tx_desc.h:164
m0_dtm0_tx_pa_state
Definition: tx_desc.h:101
struct m0_fid dti_fid
Definition: tx_desc.h:95
M0_INTERNAL int m0_dtm0_tid_cmp(struct m0_dtm0_clk_src *cs, const struct m0_dtm0_tid *left, const struct m0_dtm0_tid *right)
Definition: tx_desc.c:119
M0_INTERNAL bool m0_dtm0_tx_desc_state_eq(const struct m0_dtm0_tx_desc *txd, enum m0_dtm0_tx_pa_state state)
Definition: tx_desc.c:155
struct m0_dtm0_tx_participants dtd_ps
Definition: tx_desc.h:122
M0_DTPS_INIT
Definition: tx_desc.h:164
#define M0_XCA_ENUM
Definition: xcode_attr.h:54
M0_INTERNAL void m0_dtm0_tx_desc_fini(struct m0_dtm0_tx_desc *td)
Definition: tx_desc.c:111
struct m0_pdclust_src_addr src
Definition: fd.c:108
static struct m0_be_ut_backend be
Definition: service_ut.c:59