forked from Light-Dedup/Light-Dedup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nova_def.h
203 lines (168 loc) · 6.18 KB
/
nova_def.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
/*
* FILE NAME include/linux/nova_fs.h
*
* BRIEF DESCRIPTION
*
* Definitions for the NOVA filesystem.
*
* Copyright 2015-2016 Regents of the University of California,
* UCSD Non-Volatile Systems Lab, Andiry Xu <[email protected]>
* Copyright 2012-2013 Intel Corporation
* Copyright 2009-2011 Marco Stornelli <[email protected]>
* Copyright 2003 Sony Corporation
* Copyright 2003 Matsushita Electric Industrial Co., Ltd.
* 2003-2004 (c) MontaVista Software, Inc. , Steve Longerbeam
*
* This file is licensed under the terms of the GNU General Public
* License version 2. This program is licensed "as is" without any
* warranty of any kind, whether express or implied.
*/
#ifndef _LINUX_NOVA_DEF_H
#define _LINUX_NOVA_DEF_H
#include <linux/types.h>
#include <linux/magic.h>
#include <linux/cpufeature.h>
#define NOVA_SUPER_MAGIC 0x4E4F5641 /* NOVA */
/*
* The NOVA filesystem constants/structures
*/
/*
* Mount flags
*/
#define NOVA_MOUNT_PROTECT 0x000001 /* wprotect CR0.WP */
#define NOVA_MOUNT_XATTR_USER 0x000002 /* Extended user attributes */
#define NOVA_MOUNT_POSIX_ACL 0x000004 /* POSIX Access Control Lists */
#define NOVA_MOUNT_DAX 0x000008 /* Direct Access */
#define NOVA_MOUNT_ERRORS_CONT 0x000010 /* Continue on errors */
#define NOVA_MOUNT_ERRORS_RO 0x000020 /* Remount fs ro on errors */
#define NOVA_MOUNT_ERRORS_PANIC 0x000040 /* Panic on errors */
#define NOVA_MOUNT_HUGEMMAP 0x000080 /* Huge mappings with mmap */
#define NOVA_MOUNT_HUGEIOREMAP 0x000100 /* Huge mappings with ioremap */
#define NOVA_MOUNT_FORMAT 0x000200 /* was FS formatted on mount? */
#define NOVA_MOUNT_DATA_COW 0x000400 /* Copy-on-write for data integrity */
/*
* Maximal count of links to a file
*/
#define NOVA_LINK_MAX 32000
#define NOVA_DEF_BLOCK_SIZE_4K 4096
#define NOVA_INODE_BITS 7
#define NOVA_INODE_SIZE 128 /* must be power of two */
#define NOVA_NAME_LEN 255
#define MAX_CPUS 1024
/* NOVA supported data blocks */
#define NOVA_BLOCK_TYPE_4K 0
#define NOVA_BLOCK_TYPE_2M 1
#define NOVA_BLOCK_TYPE_1G 2
#define NOVA_BLOCK_TYPE_MAX 3
#define META_BLK_SHIFT 9
/*
* Play with this knob to change the default block type.
* By changing the NOVA_DEFAULT_BLOCK_TYPE to 2M or 1G,
* we should get pretty good coverage in testing.
*/
#define NOVA_DEFAULT_BLOCK_TYPE NOVA_BLOCK_TYPE_4K
/* ======================= Write ordering ========================= */
#define CACHELINE_SIZE (64)
#define CACHELINE_MASK (~(CACHELINE_SIZE - 1))
#define CACHELINE_ALIGN(addr) (((addr)+CACHELINE_SIZE-1) & CACHELINE_MASK)
static inline bool arch_has_clwb(void)
{
return static_cpu_has(X86_FEATURE_CLWB);
}
extern int support_clwb;
#define _mm_clflush(addr)\
asm volatile("clflush %0" : "+m" (*(volatile char *)(addr)))
#define _mm_clflushopt(addr)\
asm volatile(".byte 0x66; clflush %0" : "+m" \
(*(volatile char *)(addr)))
#define _mm_clwb(addr)\
asm volatile(".byte 0x66; xsaveopt %0" : "+m" \
(*(volatile char *)(addr)))
/* Provides ordering from all previous clflush too */
static inline void PERSISTENT_MARK(void)
{
/* TODO: Fix me. */
}
static inline void PERSISTENT_BARRIER(void)
{
asm volatile ("sfence\n" : : );
}
static inline void nova_flush_buffer(void *buf, size_t len, bool fence)
{
size_t i;
len = len + ((unsigned long)(buf) & (CACHELINE_SIZE - 1));
if (support_clwb) {
for (i = 0; i < len; i += CACHELINE_SIZE)
_mm_clwb(buf + i);
} else {
for (i = 0; i < len; i += CACHELINE_SIZE)
_mm_clflush(buf + i);
}
/* Do a fence only if asked. We often don't need to do a fence
* immediately after clflush because even if we get context switched
* between clflush and subsequent fence, the context switch operation
* provides implicit fence.
*/
if (fence)
PERSISTENT_BARRIER();
}
static inline void nova_flush_cacheline(void *buf, bool fence)
{
if (support_clwb)
_mm_clwb(buf);
else
_mm_clflush(buf);
if (fence)
PERSISTENT_BARRIER();
}
/* =============== Integrity and Recovery Parameters =============== */
#define NOVA_META_CSUM_LEN (4)
#define NOVA_DATA_CSUM_LEN (4)
/* This is to set the initial value of checksum state register.
* For CRC32C this should not matter and can be set to any value.
*/
#define NOVA_INIT_CSUM (1)
#define ADDR_ALIGN(p, bytes) ((void *) (((unsigned long) p) & ~(bytes - 1)))
/* Data stripe size in bytes and shift.
* In NOVA this size determines the size of a checksummed stripe, and it
* equals to the affordable lost size of data per block (page).
* Its value should be no less than the poison radius size of media errors.
*
* Support NOVA_STRIPE_SHIFT <= PAGE_SHIFT (NOVA file block size shift).
*/
#define POISON_RADIUS (512)
#define POISON_MASK (~(POISON_RADIUS - 1))
#define NOVA_STRIPE_SHIFT (9) /* size should be no less than PR_SIZE */
#define NOVA_STRIPE_SIZE (1 << NOVA_STRIPE_SHIFT)
/*
* Debug code
*/
#ifdef pr_fmt
#undef pr_fmt
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#endif
/* #define nova_dbg(s, args...) pr_debug(s, ## args) */
#define nova_dbg(s, args ...) pr_info(s, ## args)
#define nova_dbg1(s, args ...)
#define nova_err(sb, s, args ...) nova_error_mng(sb, s, ## args)
#define nova_warn(s, args ...) pr_warn(s, ## args)
#define nova_info(s, args ...) pr_info(s, ## args)
extern unsigned int nova_dbgmask;
#define NOVA_DBGMASK_MMAPHUGE (0x00000001)
#define NOVA_DBGMASK_MMAP4K (0x00000002)
#define NOVA_DBGMASK_MMAPVERBOSE (0x00000004)
#define NOVA_DBGMASK_MMAPVVERBOSE (0x00000008)
#define NOVA_DBGMASK_VERBOSE (0x00000010)
#define NOVA_DBGMASK_TRANSACTION (0x00000020)
#define nova_dbg_mmap4k(s, args ...) \
((nova_dbgmask & NOVA_DBGMASK_MMAP4K) ? nova_dbg(s, args) : 0)
#define nova_dbg_mmapv(s, args ...) \
((nova_dbgmask & NOVA_DBGMASK_MMAPVERBOSE) ? nova_dbg(s, args) : 0)
#define nova_dbg_mmapvv(s, args ...) \
((nova_dbgmask & NOVA_DBGMASK_MMAPVVERBOSE) ? nova_dbg(s, args) : 0)
#define nova_dbg_verbose(s, args ...) \
((nova_dbgmask & NOVA_DBGMASK_VERBOSE) ? nova_dbg(s, ##args) : 0)
#define nova_dbgv(s, args ...) nova_dbg_verbose(s, ##args)
#define nova_dbg_trans(s, args ...) \
((nova_dbgmask & NOVA_DBGMASK_TRANSACTION) ? nova_dbg(s, ##args) : 0)
#endif /* _LINUX_NOVA_DEF_H */