Coda Distributed File System
coda_tsa.h
Go to the documentation of this file.
1/* BLURB lgpl
2
3 Coda File System
4 Release 8
5
6 Copyright (c) 2021-2025 Carnegie Mellon University
7 Additional copyrights listed below
8
9This code is distributed "AS IS" without warranty of any kind under
10the terms of the GNU Library General Public Licence Version 2, as
11shown in the file LICENSE. The technical and financial contributors to
12Coda are listed in the file CREDITS.
13
14 Additional copyrights
15 none currently
16#*/
17
18/* Define annotations to leverage clang's thread safety analysis functionality
19 * to identify problematic RVM transaction usage.
20 * - Forgetting to end a transaction in error paths.
21 * - Making sure any function that uses rvm functionality is called from
22 * places that started a transaction.
23 *
24 * Hoping to add at some point.
25 * - Identifying places where our thread yields during an active transaction.
26 * - Identify variables in RVM that are mutated while not in a transaction.
27 */
28
29#ifndef _CODA_TSA_H_
30#define _CODA_TSA_H_ 1
31
32#ifdef __cplusplus
33extern "C" {
34#endif
35
36/* Probably only works when clang is used as the compiler */
37#if defined(__has_attribute)
38#if __has_attribute(acquire_capability)
39
40/* define a dummy global variables to be used as a unique markers to
41 * indicate if we are in a transaction or not. */
42extern struct __attribute__((capability("mutex"))) {
43 char x;
44} __rvm_transaction__, __no_transaction__;
45
46/* Simple begin transaction, end transaction annotations */
47#define BEGINS_TRANSACTION \
48 __attribute__((release_capability(__no_transaction__))) \
49 __attribute__((acquire_capability(__rvm_transaction__)))
50#define ENDS_TRANSACTION \
51 __attribute__((release_capability(__rvm_transaction__))) \
52 __attribute__((acquire_capability(__no_transaction__)))
53
54/* This formalize the existing 'MUST be called from within transaction'
55 * comments as a traceable annotation on the function prototype. */
56#define REQUIRES_TRANSACTION \
57 __attribute__((requires_capability(__rvm_transaction__)))
58
59/* This indicates the function (or a child) starts a transaction, so we
60 * shouldn't be in a transaction already, also useful to tag yielding functions
61 * that we don't want to call during a transaction.
62 *
63 * Use on function prototypes to declare they should not be called when a RVM
64 * transaction is already active, i.e. the function (or children) start their
65 * own transaction or yield to other LWP threads.
66 *
67 * Should be used in the code to mark entry points such as main() and RPC2
68 * server function implementations. */
69#define EXCLUDES_TRANSACTION \
70 __attribute__((requires_capability(__no_transaction__)))
71// this is the weaker version that doesn't rely on a __no_transaction__ lock.
72// __attribute__((locks_excluded(__rvm_transaction__)))
73
74/* This is more tricky, some functions change their behaviour based on an in
75 * place test (rvm_in_trans) or from a passed argument (recoverable=True).
76 * The first case is probably ok, for the second case we can't actually prove
77 * they were called correctly. Either way, disable analysis to avoid warnings.
78 * It may be useful to split these functions into RVM and non-RVM variants. */
79#define TRANSACTION_OPTIONAL __attribute__((no_thread_safety_analysis))
80
81/* And these should be useful to flag specific variables that should only be
82 * mutated while within a transaction. */
83#define RVM_OBJECT __attribute__((guarded_by(__rvm_transaction__)))
84#define RVM_OBJECT_PTR __attribute__((pt_guarded_by(__rvm_transaction__)))
85
86/* add annotations to some librvm functions */
87#include <rvm/rvm.h>
88
92rvm_return_t rvm_modify_bytes(rvm_tid_t *, void *, const void *,
96
97#endif /* __has_attribute(acquire_capability) */
98#endif /* defined(__has_attribute) */
99
100#ifdef __cplusplus
101}
102#endif
103
104#ifndef REQUIRES_TRANSACTION
105#define BEGINS_TRANSACTION
106#define ENDS_TRANSACTION
107#define REQUIRES_TRANSACTION
108#define EXCLUDES_TRANSACTION
109#define TRANSACTION_OPTIONAL
110#define RVM_OBJECT
111#define RVM_OBJECT_PTR
112#endif
113
114#endif /* _CODA_TSA_H */
#define REQUIRES_TRANSACTION
Definition: coda_tsa.h:107
#define ENDS_TRANSACTION
Definition: coda_tsa.h:106
#define BEGINS_TRANSACTION
Definition: coda_tsa.h:105
x
Definition: pwdtopdbtool.py:40
int rvm_return_t
Definition: rvm.h:94
rvm_return_t rvm_modify_bytes(rvm_tid_t *tid, void *dest, const void *src, rvm_length_t length)
Definition: rvm_trans.c:464
rvm_return_t rvm_abort_transaction(rvm_tid_t *tid)
Definition: rvm_trans.c:888
rvm_mode_t
Definition: rvm.h:82
rvm_return_t rvm_end_transaction(rvm_tid_t *tid, rvm_mode_t mode)
Definition: rvm_trans.c:919
unsigned long rvm_length_t
Definition: rvm.h:140
rvm_return_t rvm_set_range(rvm_tid_t *tid, void *dest, rvm_length_t length)
Definition: rvm_trans.c:426
rvm_return_t rvm_begin_transaction(rvm_tid_t *tid, rvm_mode_t mode)
Definition: rvm_trans.c:853
Definition: cthreads.h:46
Definition: rvm.h:251