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
Delegation(const OpenDelegationData & data,Inode * inode,uint64 clientID,bool attribute)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 ASSERT(inode != NULL);
25 }
26
27
28 status_t
GiveUp(bool truncate)29 Delegation::GiveUp(bool truncate)
30 {
31 if (!fAttribute && !truncate)
32 fInode->SyncAndCommit(true);
33
34 ReturnDelegation();
35
36 return B_OK;
37 }
38
39
40 status_t
ReturnDelegation()41 Delegation::ReturnDelegation()
42 {
43 uint32 attempt = 0;
44 do {
45 RPC::Server* serv = fFileSystem->Server();
46 Request request(serv, fFileSystem);
47 RequestBuilder& req = request.Builder();
48
49 req.PutFH(fInfo.fHandle);
50 req.DelegReturn(fData.fStateID, fData.fStateSeq);
51
52 status_t result = request.Send();
53 if (result != B_OK)
54 return result;
55
56 ReplyInterpreter& reply = request.Reply();
57
58 if (HandleErrors(attempt, reply.NFS4Error(), serv, NULL,
59 fInode->GetOpenState())) {
60 continue;
61 }
62
63 reply.PutFH();
64
65 return reply.DelegReturn();
66 } while (true);
67 }
68
69