xref: /haiku/src/add-ons/kernel/file_systems/nfs4/Cookie.h (revision 204dee708a999d5a71d0cb9497650ee7cef85d0a)
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();
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 
82 struct OpenFileCookie : public OpenStateCookie {
83 			LockInfo*		fLocks;
84 
85 			void			AddLock(LockInfo* lock);
86 			void			RemoveLock(LockInfo* lock, LockInfo* prev);
87 
88 							OpenFileCookie();
89 };
90 
91 struct OpenDirCookie : public Cookie {
92 			int							fSpecial;
93 			DirectoryCacheSnapshot*		fSnapshot;
94 			NameCacheEntry*				fCurrent;
95 			bool						fEOF;
96 
97 			bool						fAttrDir;
98 
99 										~OpenDirCookie();
100 };
101 
102 struct OpenAttrCookie : public OpenStateCookie { };
103 
104 
105 #endif	// COOKIE_H
106 
107