nfs4: Add stub Inode class, fix and extend Filesystem class

Additionally PUTFH support is added to both RequestBuilder and
ReplyInterpreter.
This commit is contained in:
Pawel Dziepak 2012-05-31 00:15:54 +02:00
parent 45aa18ac4c
commit bf31ee39e5
9 changed files with 161 additions and 2 deletions

View File

@ -14,8 +14,12 @@
#include "ReplyInterpreter.h"
#include "RequestBuilder.h"
#include "Inode.h"
Filesystem::Filesystem()
:
fId(0)
{
}
@ -32,7 +36,7 @@ Filesystem::Mount(Filesystem** pfs, RPC::Server* serv, const char* fsPath)
req.PutRootFH();
// Better way of doing this will be needed
uint32 lookupCount;
uint32 lookupCount = 0;
char* path = strdup(fsPath);
char* pathStart = path;
char* pathEnd;
@ -104,7 +108,7 @@ Filesystem::Mount(Filesystem** pfs, RPC::Server* serv, const char* fsPath)
return B_UNSUPPORTED;
}
Filesystem* fs = new Filesystem;
Filesystem* fs = new(std::nothrow) Filesystem;
fs->fFHExpiryType = values[0].fData.fValue32;
memcpy(&fs->fRootFH, &fh, sizeof(Filehandle));
fs->fServer = serv;
@ -116,3 +120,10 @@ Filesystem::Mount(Filesystem** pfs, RPC::Server* serv, const char* fsPath)
return B_OK;
}
Inode*
Filesystem::CreateRootInode()
{
return new(std::nothrow)Inode(this, fRootFH);
}

View File

@ -13,13 +13,19 @@
#include "RPCServer.h"
class Inode;
class Filesystem {
public:
static status_t Mount(Filesystem** pfs, RPC::Server* serv,
const char* path);
~Filesystem();
Inode* CreateRootInode();
inline uint32 FHExpiryType() const;
inline RPC::Server* Server();
inline uint64 GetId();
private:
Filesystem();
@ -29,8 +35,24 @@ private:
Filehandle fRootFH;
RPC::Server* fServer;
vint64 fId;
};
inline RPC::Server*
Filesystem::Server()
{
return fServer;
}
inline uint64
Filesystem::GetId()
{
return atomic_add64(&fId, 1);
}
#endif // FILESYSTEM_H

View File

@ -0,0 +1,55 @@
/*
* Copyright 2012 Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Paweł Dziepak, pdziepak@quarnos.org
*/
#include "Inode.h"
#include <string.h>
#include "ReplyInterpreter.h"
#include "RequestBuilder.h"
// Creating Inode object from Filehandle probably is not a good idea when
// filehandles are volatile.
Inode::Inode(Filesystem* fs, const Filehandle &fh)
:
fFilesystem(fs)
{
memcpy(&fHandle, &fh, sizeof(fh));
RequestBuilder req(ProcCompound);
req.PutFH(fh);
Attribute attr[] = { FATTR4_FILEID };
req.GetAttr(attr, sizeof(attr) / sizeof(Attribute));
RPC::Reply *rpl;
fs->Server()->SendCall(req.Request(), &rpl);
ReplyInterpreter reply(rpl);
status_t result;
result = reply.PutFH();
if (result != B_OK)
return;
AttrValue* values;
uint32 count;
result = reply.GetAttr(&values, &count);
if (result != B_OK)
return;
if (count < 1 || values[0].fAttribute != FATTR4_FILEID) {
// Server does not provide fileid. We need to make something up.
fFileId = fs->GetId();
} else
fFileId = values[0].fData.fValue64;
delete values;
}

View File

@ -0,0 +1,44 @@
/*
* Copyright 2012 Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Paweł Dziepak, pdziepak@quarnos.org
*/
#ifndef INODE_H
#define INODE_H
#include <SupportDefs.h>
#include "Filesystem.h"
#include "NFS4Defs.h"
class Inode {
public:
Inode(Filesystem* fs, const Filehandle &fh);
inline ino_t ID() const;
private:
uint64 fFileId;
Filehandle fHandle;
Filesystem* fFilesystem;
};
inline ino_t
Inode::ID() const
{
if (sizeof(ino_t) >= sizeof(uint64))
return fFileId;
else
return (ino_t)fFileId ^ (fFileId >>
(sizeof(uint64) - sizeof(ino_t)) * 8);
}
#endif // INODE_H

View File

@ -5,6 +5,7 @@ UsePrivateHeaders kernel ;
KernelAddon nfs4 :
Connection.cpp
Filesystem.cpp
Inode.cpp
kernel_interface.cpp
ReplyInterpreter.cpp
RequestBuilder.cpp

View File

@ -29,6 +29,7 @@ enum Opcode {
OpGetAttr = 9,
OpGetFH = 10,
OpLookUp = 15,
OpPutFH = 22,
OpPutRootFH = 24
};

View File

@ -33,6 +33,7 @@ public:
status_t GetAttr(AttrValue** attrs, uint32* count);
status_t GetFH(Filehandle* fh);
inline status_t LookUp();
inline status_t PutFH();
inline status_t PutRootFH();
private:
@ -51,6 +52,13 @@ ReplyInterpreter::LookUp()
}
inline status_t
ReplyInterpreter::PutFH()
{
return _OperationError(OpPutFH);
}
inline status_t
ReplyInterpreter::PutRootFH()
{

View File

@ -114,6 +114,22 @@ RequestBuilder::LookUp(const char* name)
}
status_t
RequestBuilder::PutFH(const Filehandle& fh)
{
if (fProcedure != ProcCompound)
return B_BAD_VALUE;
if (fRequest == NULL)
return B_NO_MEMORY;
fRequest->Stream().AddUInt(OpPutFH);
fRequest->Stream().AddOpaque(fh.fFH, fh.fSize);
fOpCount++;
return B_OK;
}
status_t
RequestBuilder::PutRootFH()
{

View File

@ -25,6 +25,7 @@ public:
status_t GetAttr(Attribute* attrs, uint32 count);
status_t GetFH();
status_t LookUp(const char* name);
status_t PutFH(const Filehandle& fh);
status_t PutRootFH();
RPC::Call* Request();