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 ASSERT(inode != NULL); 25 } 26 27 28 status_t 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 41 Delegation::ReturnDelegation() 42 { 43 do { 44 RPC::Server* serv = fFileSystem->Server(); 45 Request request(serv, fFileSystem); 46 RequestBuilder& req = request.Builder(); 47 48 req.PutFH(fInfo.fHandle); 49 req.DelegReturn(fData.fStateID, fData.fStateSeq); 50 51 status_t result = request.Send(); 52 if (result != B_OK) 53 return result; 54 55 ReplyInterpreter& reply = request.Reply(); 56 57 if (HandleErrors(reply.NFS4Error(), serv, NULL, fInode->GetOpenState())) 58 continue; 59 60 reply.PutFH(); 61 62 return reply.DelegReturn(); 63 } while (true); 64 } 65 66