xref: /haiku/src/add-ons/kernel/file_systems/nfs4/NFS4Server.h (revision 9216fc01782e67a039b918399d45c8c0c9199d71)
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 NFS4SERVER_H
9 #define NFS4SERVER_H
10 
11 
12 #include <util/AutoLock.h>
13 
14 #include "ReplyBuilder.h"
15 #include "RequestInterpreter.h"
16 #include "RPCServer.h"
17 
18 
19 class FileSystem;
20 struct OpenFileCookie;
21 
22 class NFS4Server : public RPC::ProgramData {
23 public:
24 							NFS4Server(RPC::Server* serv);
25 	virtual					~NFS4Server();
26 
27 			uint64			ServerRebooted(uint64 clientId);
28 			status_t		FileSystemMigrated();
29 
30 			void			AddFileSystem(FileSystem* fs);
31 			void			RemoveFileSystem(FileSystem* fs);
32 
33 	inline	void			IncUsage();
34 	inline	void			DecUsage();
35 
36 			uint64			ClientId(uint64 prevId = 0, bool forceNew = false);
37 
38 	inline	uint32			LeaseTime();
39 
40 	virtual	status_t		ProcessCallback(RPC::CallbackRequest* request,
41 								Connection* connection);
42 
43 			status_t		CallbackRecall(RequestInterpreter* request,
44 								ReplyBuilder* reply);
45 			status_t		RecallAll();
46 
47 			status_t		CallbackGetAttr(RequestInterpreter* request,
48 								ReplyBuilder* reply);
49 private:
50 			status_t		_GetLeaseTime();
51 
52 			status_t		_StartRenewing();
53 			status_t		_Renewal();
54 	static	status_t		_RenewalThreadStart(void* ptr);
55 
56 			thread_id		fThread;
57 			bool			fThreadCancel;
58 			sem_id			fWaitCancel;
59 			mutex			fThreadStartLock;
60 
61 			uint32			fLeaseTime;
62 
63 			uint64			fClientId;
64 			time_t			fClientIdLastUse;
65 			mutex			fClientIdLock;
66 
67 			uint32			fUseCount;
68 			DoublyLinkedList<FileSystem>	fFileSystems;
69 			mutex			fFSLock;
70 
71 			RPC::Server*	fServer;
72 };
73 
74 
75 inline void
IncUsage()76 NFS4Server::IncUsage()
77 {
78 	MutexLocker _(fFSLock);
79 	fUseCount++;
80 	_StartRenewing();
81 	fClientIdLastUse = time(NULL);
82 }
83 
84 
85 inline void
DecUsage()86 NFS4Server::DecUsage()
87 {
88 	MutexLocker _(fFSLock);
89 	fClientIdLastUse = time(NULL);
90 	fUseCount--;
91 }
92 
93 
94 inline uint32
LeaseTime()95 NFS4Server::LeaseTime()
96 {
97 	if (fLeaseTime == 0)
98 		_GetLeaseTime();
99 
100 	return fLeaseTime;
101 }
102 
103 
104 #endif	// NFS4SERVER_H
105 
106