-
Notifications
You must be signed in to change notification settings - Fork 0
/
fileops_nvp.h
123 lines (103 loc) · 3.32 KB
/
fileops_nvp.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
// Header file for nvmfileops.c
#include "nv_common.h"
#define ENV_NV_FOP "NVP_NV_FOP"
#define _NVP_USE_DEFAULT_FILEOPS NULL
/******************* Data Structures ********************/
struct NVFile
{
NVP_LOCK_DECL;
volatile bool valid;
int fd;
volatile size_t* offset;
bool canRead;
bool canWrite;
bool append;
bool aligned;
ino_t serialno; // duplicated so that iterating doesn't require following every node*
struct NVNode* node;
bool posix;
bool debug;
};
struct NVNode
{
ino_t serialno;
NVP_LOCK_DECL;
// char* volatile data; // the pointer itself is volatile
volatile size_t length;
volatile size_t maplength;
unsigned long *root;
unsigned int height;
int reference;
// volatile int maxPerms;
// volatile int valid; // for debugging purposes
};
/******************* Locking ********************/
#define NVP_LOCK_FD_RD(nvf, cpuid) NVP_LOCK_RD( nvf->lock, cpuid)
#define NVP_UNLOCK_FD_RD(nvf, cpuid) NVP_LOCK_UNLOCK_RD(nvf->lock, cpuid)
#define NVP_LOCK_FD_WR(nvf) NVP_LOCK_WR( nvf->lock)
#define NVP_UNLOCK_FD_WR(nvf) NVP_LOCK_UNLOCK_WR(nvf->lock)
#define NVP_LOCK_NODE_RD(nvf, cpuid) NVP_LOCK_RD( nvf->node->lock, cpuid)
#define NVP_UNLOCK_NODE_RD(nvf, cpuid) NVP_LOCK_UNLOCK_RD(nvf->node->lock, cpuid)
#define NVP_LOCK_NODE_WR(nvf) NVP_LOCK_WR( nvf->node->lock)
#define NVP_UNLOCK_NODE_WR(nvf) NVP_LOCK_UNLOCK_WR(nvf->node->lock)
/******************* MMAP ********************/
#define IS_ERR(x) ((unsigned long)(x) >= (unsigned long)-4095)
#define MAX_MMAP_SIZE 2097152
#define ALIGN_MMAP_DOWN(addr) ((addr) & ~(MAX_MMAP_SIZE - 1))
#define DO_ALIGNMENT_CHECKS 0
#define DO_MSYNC(nvf) do{ \
DEBUG("NOT doing a msync\n"); }while(0)
/*
DEBUG("Doing a msync on fd %i (node %p)\n", nvf->fd, nvf->node); \
if(msync(nvf->node->data, nvf->node->maplength, MS_SYNC|MS_INVALIDATE)) { \
ERROR("Failed to msync for fd %i\n", nvf->fd); \
assert(0); \
} }while(0)
*/
/******************* Checking ********************/
#define NOSANITYCHECK 1
#if NOSANITYCHECK
#define SANITYCHECK(x)
#else
#define SANITYCHECK(x) if(UNLIKELY(!(x))) { ERROR("NVP_SANITY("#x") failed!\n"); exit(101); }
#endif
#define NVP_CHECK_NVF_VALID(nvf) do{ \
if(UNLIKELY(!nvf->valid)) { \
DEBUG("Invalid file descriptor: %i\n", file); \
errno = EBADF; \
NVP_UNLOCK_FD_RD(nvf, cpuid); \
return -1; \
} \
else \
{ \
DEBUG("this function is operating on node %p\n", nvf->node); \
SANITYCHECKNVF(nvf); \
DO_MSYNC(nvf); \
} \
} while(0)
#define NVP_CHECK_NVF_VALID_WR(nvf) do{ \
if(UNLIKELY(!nvf->valid)) { \
DEBUG("Invalid file descriptor: %i\n", file); \
errno = EBADF; \
NVP_UNLOCK_FD_WR(nvf); \
return -1; \
} \
else \
{ \
DEBUG("this function is operating on node %p\n", nvf->node); \
SANITYCHECKNVF(nvf); \
DO_MSYNC(nvf); \
} \
} while(0)
#define SANITYCHECKNVF(nvf) \
SANITYCHECK(nvf->valid); \
SANITYCHECK(nvf->node != NULL); \
SANITYCHECK(nvf->fd >= 0); \
SANITYCHECK(nvf->fd < OPEN_MAX); \
SANITYCHECK(nvf->offset != NULL); \
SANITYCHECK(*nvf->offset >= 0); \
SANITYCHECK(nvf->serialno != 0); \
SANITYCHECK(nvf->serialno == nvf->node->serialno); \
SANITYCHECK(nvf->node->length >=0); \
SANITYCHECK(nvf->node->maplength >= nvf->node->length); \
SANITYCHECK(nvf->node->data != NULL)