xref: /haiku/src/add-ons/kernel/file_systems/nfs4/Delegation.cpp (revision 20d1b02eefc137b62fac748323e6747c7f9e6ef3)
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 
9 
10 #include "Delegation.h"
11 
12 #include "Inode.h"
13 #include "Request.h"
14 
15 
16 Delegation::Delegation(const OpenDelegationData& data, Inode* inode,
17 	uint64 clientID, bool attribute)
18 	:
19 	fClientID(clientID),
20 	fData(data),
21 	fInode(inode),
22 	fAttribute(attribute)
23 {
24 }
25 
26 
27 status_t
28 Delegation::GiveUp(bool truncate)
29 {
30 	if (!fAttribute && !truncate)
31 		fInode->SyncAndCommit(true);
32 
33 	ReturnDelegation();
34 
35 	return B_OK;
36 }
37 
38 
39 status_t
40 Delegation::ReturnDelegation()
41 {
42 	do {
43 		RPC::Server* serv = fFileSystem->Server();
44 		Request request(serv);
45 		RequestBuilder& req = request.Builder();
46 
47 		req.PutFH(fInfo.fHandle);
48 		req.DelegReturn(fData.fStateID, fData.fStateSeq);
49 
50 		status_t result = request.Send();
51 		if (result != B_OK)
52 			return result;
53 
54 		ReplyInterpreter& reply = request.Reply();
55 
56 		if (HandleErrors(reply.NFS4Error(), serv))
57 			continue;
58 
59 		reply.PutFH();
60 
61 		return reply.DelegReturn();
62 	} while (true);
63 }
64 
65