-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathlockmgmt.h
More file actions
203 lines (157 loc) · 4.57 KB
/
lockmgmt.h
File metadata and controls
203 lines (157 loc) · 4.57 KB
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
#ifndef _LOCKMGMT_H_
#define _LOCKMGMT_H_
#include "inc/xplatcfg.h"
#include "inc/sal/types.h"
#include "inc/netdisk/conn.h"
#define NDAS_MAX_DEVICE_LOCK_COUNT 4 /* for HW version 1.1 and version 2.0 */
#define NDAS_DEVLOCK_ID_NONE 0
#define NDAS_DEVLOCK_ID_XIFS 1
#define NDAS_DEVLOCK_ID_EXTLOCK 2
#define NDAS_DEVLOCK_ID_BUFFLOCK 3
typedef struct _NDAS_DEVLOCK_STATUS {
xuchar Acquired:1; // Lock acquired
xuchar AddressRangeValid:1; // Valid is IOs' address range that requires lock acquisition
xuchar Lost:1; // Lock lost during reconnection.
xuchar Reserved1:5;
xuchar Reserved2[3];
xuint64 StartingAddress; // IO address range
xuint64 EndingAddress; // IO address range
} NDAS_DEVLOCK_STATUS, *PNDAS_DEVLOCK_STATUS;
typedef struct _NDAS_DEVLOCK_INFO {
xuint32 AcquiredLockCount;
xuint32 LostLockCount;
// Index value is lock ID.
NDAS_DEVLOCK_STATUS DevLockStatus[NDAS_MAX_DEVICE_LOCK_COUNT];
} NDAS_DEVLOCK_INFO;
typedef struct _BUFFLOCK_CONTROL {
#if 0
// System timer resolution. time per tick ( time is in 100 nanosecond unit )
xuint32 TimerResolution;
#endif
// All lock operation should take place in quantum scale.
sal_msec Quantum;
// Priority wait time
sal_msec PriorityWaitTime;
// Maximum time of IO operations with the buffer lock acquisition.
sal_msec AcquisitionMaxTime;
sal_msec AcquisitionExpireTime; // CurrentTime + AcquisitionMaxTime
// Maximum amount of the IO size with the buffer lock acquisition.
xuint32 MaxIOBytes;
// Accumulated IO length
xuint64 AccumulatedIOBytes;
// Release the buffer lock if there is no IO for a while.
sal_msec IoIdleTimeOut;
// Set if idle routine is expired.
// Clear if the buffer lock request arrives.
xbool IoIdle;
// IO idle event
// The IO thread waits for this event.
dpc_id IoIdleTimerExpire;
// sal_semaphore IoIdleTimerExpire;
// Host count connected to the NDAS device including myself.
xuint32 ConnectedHosts;
// The number of the buffer lock acquisition from all connected hosts
// after the NDAS device powers up.
xuint32 CurrentLockCount;
//
// Acquisition request pending count
//
xuint32 MyRequestCount;
// Lock acquisition priority
xuint32 LockCountWhenReleased;
xuint32 RequestCountWhenReleased;
xuint32 Priority;
// Indicate that buffer lock collision control works.
xbool BufferLockConrol;
// Indicate that buffer lock is controlled by the parent node.
xbool BufferLockParent;
} BUFFLOCK_CONTROL, *PBUFFLOCK_CONTROL;
void
LockCacheAllLocksLost(
IN NDAS_DEVLOCK_INFO* LockInfo
);
xbool
LockCacheAcquiredLocksExistsExceptForBufferLock(
IN NDAS_DEVLOCK_INFO* LockInfo
);
xbool
LockCacheCheckLostLockIORange(
IN NDAS_DEVLOCK_INFO* LockInfo,
IN xuint64 StartingAddress,
IN xuint64 EndingAddress
);
ndas_error_t
WaitForBufferLockRelease(
IN PBUFFLOCK_CONTROL BuffLockCtl,
IN uconn_t* conn,
OUT xuchar* LockData,
OUT xbool* LockAcquired
);
ndas_error_t
NdasAcquireBufferLock(
IN PBUFFLOCK_CONTROL BuffLockCtl,
IN uconn_t* conn,
IN NDAS_DEVLOCK_INFO* LockInfo,
OUT xuchar* LockData,
IN sal_msec TimeOut
);
ndas_error_t
NdasReleaseBufferLock(
IN PBUFFLOCK_CONTROL BuffLockCtl,
IN uconn_t* conn,
IN NDAS_DEVLOCK_INFO* LockInfo,
OUT xuchar* LockData,
IN sal_msec TimeOut,
IN xbool Force,
IN xuint32 TransferredIoLength
);
/* To do: remove udev from StartIoIdleTimer to remove dependency on udev */
struct _udev_t;
ndas_error_t
StartIoIdleTimer(
PBUFFLOCK_CONTROL BuffLockCtl,
struct _udev_t* udev
);
ndas_error_t
StopIoIdleTimer(
PBUFFLOCK_CONTROL BuffLockCtl
);
ndas_error_t
EnterBufferLockIoIdle(
IN PBUFFLOCK_CONTROL BuffLockCtl,
IN uconn_t* conn,
IN NDAS_DEVLOCK_INFO* LockInfo
);
ndas_error_t
LMInitialize(
IN uconn_t* conn,
IN PBUFFLOCK_CONTROL BuffLockCtl,
IN xbool InitialState
);
void
LMEnable(
IN PBUFFLOCK_CONTROL BuffLockCtl,
IN xbool Activate,
IN xbool ParentControl
);
ndas_error_t
LMDestroy(
IN PBUFFLOCK_CONTROL BuffLockCtl
);
ndas_error_t
OpAcquireDevLock(
IN uconn_t* conn,
IN xuint32 LockIndex,
OUT xuchar* LockData,
IN sal_msec TimeOut,
IN xbool RetryWhenFailure
);
ndas_error_t
OpReleaseDevLock(
IN uconn_t* conn,
IN xuint32 LockIndex,
IN xuchar* LockData,
IN sal_msec TimeOut
);
#define TARGETDATA_REQUEST_COUNT_MASK 0x0000000000ffffffLL
#endif