xref: /haiku/src/add-ons/kernel/file_systems/nfs4/Cookie.h (revision 040a81419dda83d1014e9dc94936a4cb3f027303)
1 /*
2  * Copyright 2012 Haiku, Inc. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		Paweł Dziepak, pdziepak@quarnos.org
7  */
8 #ifndef COOKIE_H
9 #define COOKIE_H
10 
11 
12 #include <SupportDefs.h>
13 
14 #include "DirectoryCache.h"
15 #include "FileSystem.h"
16 
17 
18 struct OpenState;
19 
20 struct LockOwner {
21 			uint64			fClientId;
22 
23 			uint32			fStateId[3];
24 			uint32			fStateSeq;
25 			uint32			fSequence;
26 
27 			uint32			fOwner;
28 
29 			uint32			fUseCount;
30 
31 			mutex			fLock;
32 
33 			LockOwner*		fNext;
34 			LockOwner*		fPrev;
35 
36 							LockOwner(uint32 owner);
37 							~LockOwner();
38 };
39 
40 struct LockInfo {
41 			LockOwner*		fOwner;
42 
43 			uint64			fStart;
44 			uint64			fLength;
45 			LockType		fType;
46 
47 			LockInfo*		fNext;
48 			LockInfo*		fCookieNext;
49 
50 							LockInfo(LockOwner* owner);
51 							~LockInfo();
52 
53 			bool			operator==(const struct flock& lock) const;
54 			bool			operator==(const LockInfo& lock) const;
55 };
56 
57 struct Cookie {
58 			struct RequestEntry {
59 				RPC::Request*	fRequest;
60 				RequestEntry*	fNext;
61 			};
62 
63 			FileSystem*		fFileSystem;
64 			RequestEntry*	fRequests;
65 			mutex			fRequestLock;
66 
67 			sem_id			fSnoozeCancel;
68 
69 							Cookie(FileSystem* fileSystem);
70 	virtual					~Cookie();
71 
72 			status_t		RegisterRequest(RPC::Request* req);
73 			status_t		UnregisterRequest(RPC::Request* req);
74 			status_t		CancelAll();
75 };
76 
77 struct OpenStateCookie : public Cookie {
78 			OpenState*		fOpenState;
79 			uint32			fMode;
80 
81 							OpenStateCookie(FileSystem* fileSystem);
82 };
83 
84 struct OpenFileCookie : public OpenStateCookie {
85 			LockInfo*		fLocks;
86 
87 			void			AddLock(LockInfo* lock);
88 			void			RemoveLock(LockInfo* lock, LockInfo* prev);
89 
90 							OpenFileCookie(FileSystem* fileSystem);
91 };
92 
93 struct OpenDirCookie : public Cookie {
94 			int							fSpecial;
95 			DirectoryCacheSnapshot*		fSnapshot;
96 			NameCacheEntry*				fCurrent;
97 			bool						fEOF;
98 
99 			bool						fAttrDir;
100 
101 										OpenDirCookie(FileSystem* fileSystem);
102 										~OpenDirCookie();
103 };
104 
105 struct OpenAttrCookie : public OpenStateCookie {
106 							OpenAttrCookie(FileSystem* fileSystem);
107 };
108 
109 
110 #endif	// COOKIE_H
111 
112