xref: /haiku/src/add-ons/kernel/file_systems/nfs4/FileSystem.h (revision 579f1dbca962a2a03df54f69fdc6e9423f91f20e)
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 FILESYSTEM_H
9 #define FILESYSTEM_H
10 
11 
12 #include "Delegation.h"
13 #include "InodeIdMap.h"
14 #include "NFS4Defs.h"
15 #include "NFS4Server.h"
16 
17 
18 class Inode;
19 class RootInode;
20 
21 struct MountConfiguration {
22 	bool		fHard;
23 	int			fRetryLimit;
24 	bigtime_t	fRequestTimeout;
25 
26 	bool		fEmulateNamedAttrs;
27 	bool		fCacheMetadata;
28 
29 	bigtime_t	fDirectoryCacheTime;
30 };
31 
32 class FileSystem : public DoublyLinkedListLinkImpl<FileSystem> {
33 public:
34 	static	status_t			Mount(FileSystem** pfs, RPC::Server* serv,
35 									const char* path, dev_t id,
36 									const MountConfiguration& configuration);
37 								~FileSystem();
38 
39 			status_t			GetInode(ino_t id, Inode** inode);
40 	inline	RootInode*			Root();
41 
42 			status_t			Migrate(const RPC::Server* serv);
43 
44 			DoublyLinkedList<OpenState>&	OpenFilesLock();
45 			void				OpenFilesUnlock();
46 	inline	uint32				OpenFilesCount();
47 			void				AddOpenFile(OpenState* state);
48 			void				RemoveOpenFile(OpenState* state);
49 
50 			DoublyLinkedList<Delegation>&	DelegationsLock();
51 			void				DelegationsUnlock();
52 			void				AddDelegation(Delegation* delegation);
53 			void				RemoveDelegation(Delegation* delegation);
54 			Delegation*			GetDelegation(const FileHandle& handle);
55 
56 	inline	bool				IsAttrSupported(Attribute attr) const;
57 	inline	uint32				ExpireType() const;
58 
59 	inline	RPC::Server*		Server();
60 	inline	NFS4Server*			NFSServer();
61 
62 	inline	const char**		Path() const;
63 	inline	const FileSystemId&	FsId() const;
64 
65 	inline	uint64				AllocFileId();
66 
67 	inline	dev_t				DevId() const;
68 	inline	InodeIdMap*			InoIdMap();
69 
70 	inline	uint64				OpenOwner() const;
71 	inline	uint32				OpenOwnerSequenceLock();
72 	inline	void				OpenOwnerSequenceUnlock(uint32 sequence);
73 
74 	inline	bool				NamedAttrs();
75 	inline	void				SetNamedAttrs(bool attrs);
76 
77 	inline	const MountConfiguration&	GetConfiguration();
78 
79 	inline	mutex&				CreateFileLock();
80 private:
81 								FileSystem(const MountConfiguration& config);
82 
83 	static	status_t			_ParsePath(RequestBuilder& req, uint32& count,
84 									const char* _path);
85 
86 			mutex				fCreateFileLock;
87 
88 			mutex				fDelegationLock;
89 			DoublyLinkedList<Delegation>	fDelegationList;
90 			AVLTreeMap<FileHandle, Delegation*> fHandleToDelegation;
91 
92 			DoublyLinkedList<OpenState>		fOpenFiles;
93 			uint32				fOpenCount;
94 			mutex				fOpenLock;
95 
96 			uint64				fOpenOwner;
97 			uint32				fOpenOwnerSequence;
98 			mutex				fOpenOwnerLock;
99 
100 			uint32				fExpireType;
101 			uint32				fSupAttrs[2];
102 			bool				fNamedAttrs;
103 
104 			FileSystemId		fFsId;
105 			const char**		fPath;
106 
107 			RootInode*			fRoot;
108 
109 			RPC::Server*		fServer;
110 
111 			vint64				fId;
112 			dev_t				fDevId;
113 
114 			InodeIdMap			fInoIdMap;
115 
116 			MountConfiguration	fConfiguration;
117 };
118 
119 
120 inline RootInode*
121 FileSystem::Root()
122 {
123 	return fRoot;
124 }
125 
126 
127 inline uint32
128 FileSystem::OpenFilesCount()
129 {
130 	return fOpenCount;
131 }
132 
133 
134 inline bool
135 FileSystem::IsAttrSupported(Attribute attr) const
136 {
137 	return sIsAttrSet(attr, fSupAttrs, 2);
138 }
139 
140 
141 inline uint32
142 FileSystem::ExpireType() const
143 {
144 	return fExpireType;
145 }
146 
147 
148 inline RPC::Server*
149 FileSystem::Server()
150 {
151 	ASSERT(fServer != NULL);
152 	return fServer;
153 }
154 
155 
156 inline NFS4Server*
157 FileSystem::NFSServer()
158 {
159 	ASSERT(fServer->PrivateData() != NULL);
160 	return reinterpret_cast<NFS4Server*>(fServer->PrivateData());
161 }
162 
163 
164 inline const char**
165 FileSystem::Path() const
166 {
167 	ASSERT(fPath != NULL);
168 	return fPath;
169 }
170 
171 
172 inline const FileSystemId&
173 FileSystem::FsId() const
174 {
175 	return fFsId;
176 }
177 
178 
179 inline uint64
180 FileSystem::AllocFileId()
181 {
182 	return atomic_add64(&fId, 1);
183 }
184 
185 
186 inline dev_t
187 FileSystem::DevId() const
188 {
189 	return fDevId;
190 }
191 
192 
193 inline InodeIdMap*
194 FileSystem::InoIdMap()
195 {
196 	return &fInoIdMap;
197 }
198 
199 
200 inline uint64
201 FileSystem::OpenOwner() const
202 {
203 	return fOpenOwner;
204 }
205 
206 
207 inline uint32
208 FileSystem::OpenOwnerSequenceLock()
209 {
210 	mutex_lock(&fOpenOwnerLock);
211 	return fOpenOwnerSequence;
212 }
213 
214 
215 inline void
216 FileSystem::OpenOwnerSequenceUnlock(uint32 sequence)
217 {
218 	fOpenOwnerSequence = sequence;
219 	mutex_unlock(&fOpenOwnerLock);
220 }
221 
222 
223 inline bool
224 FileSystem::NamedAttrs()
225 {
226 	return fNamedAttrs;
227 }
228 
229 
230 inline void
231 FileSystem::SetNamedAttrs(bool attrs)
232 {
233 	fNamedAttrs = attrs;
234 }
235 
236 
237 inline const MountConfiguration&
238 FileSystem::GetConfiguration()
239 {
240 	return fConfiguration;
241 }
242 
243 
244 inline mutex&
245 FileSystem::CreateFileLock()
246 {
247 	return fCreateFileLock;
248 }
249 
250 
251 #endif	// FILESYSTEM_H
252 
253