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