nfs4: Add numerous assertion checks

This commit is contained in:
Pawel Dziepak
2012-11-01 00:17:34 +01:00
parent bb03552636
commit 1e67a2cdd9
31 changed files with 362 additions and 9 deletions
@@ -59,6 +59,8 @@ CacheRevalidator::_StartRevalidator()
status_t
CacheRevalidator::_DirectoryRevalidatorStart(void* object)
{
ASSERT(object != NULL);
CacheRevalidator* revalidator = reinterpret_cast<CacheRevalidator*>(object);
revalidator->_DirectoryCacheRevalidator();
return B_OK;
@@ -59,6 +59,8 @@ CacheRevalidator::Unlock()
inline void
CacheRevalidator::AddDirectory(DirectoryCache* cache)
{
ASSERT(cache != NULL);
if (!cache->fRevalidated) {
cache->fRevalidated = true;
fDirectoryCaches.InsertAfter(fDirectoryCaches.Tail(), cache);
@@ -69,6 +71,8 @@ CacheRevalidator::AddDirectory(DirectoryCache* cache)
inline void
CacheRevalidator::RemoveDirectory(DirectoryCache* cache)
{
ASSERT(cache != NULL);
if (cache->fRevalidated == true)
fDirectoryCaches.Remove(cache);
cache->fRevalidated = false;
@@ -15,6 +15,7 @@
#include <string.h>
#include <unistd.h>
#include <AutoDeleter.h>
#include <util/kernel_cpp.h>
#include <net/dns_resolver.h>
@@ -81,6 +82,8 @@ PeerAddress::ProtocolString() const
void
PeerAddress::SetProtocol(const char* protocol)
{
ASSERT(protocol != NULL);
if (strcmp(protocol, "tcp") == 0)
fProtocol = IPPROTO_TCP;
else if (strcmp(protocol, "udp") == 0)
@@ -189,6 +192,9 @@ PeerAddress::InAddrSize() const
status_t
PeerAddress::ResolveName(const char* name, PeerAddress* address)
{
ASSERT(name != NULL);
ASSERT(address != NULL);
address->fProtocol = IPPROTO_TCP;
// getaddrinfo() is very expensive when called from kernel, so we do not
@@ -284,6 +290,8 @@ ConnectionBase::~ConnectionBase()
status_t
ConnectionBase::GetLocalAddress(PeerAddress* address)
{
ASSERT(address != NULL);
address->fProtocol = fPeerAddress.fProtocol;
socklen_t addressSize = sizeof(address->fAddress);
@@ -295,11 +303,14 @@ ConnectionBase::GetLocalAddress(PeerAddress* address)
status_t
ConnectionStream::Send(const void* buffer, uint32 size)
{
ASSERT(buffer != NULL);
status_t result;
uint32* buf = (uint32*)malloc(size + sizeof(uint32));
uint32* buf = reinterpret_cast<uint32*>(malloc(size + sizeof(uint32)));
if (buf == NULL)
return B_NO_MEMORY;
MemoryDeleter _(buf);
buf[0] = htonl(size | LAST_FRAGMENT);
memcpy(buf + 1, buffer, size);
@@ -315,14 +326,10 @@ ConnectionStream::Send(const void* buffer, uint32 size)
mutex_unlock(&fSocketLock);
if (result < 0) {
result = errno;
free(buf);
return result;
} else if (result == 0) {
free(buf);
} else if (result == 0)
return B_IO_ERROR;
}
free(buf);
return B_OK;
}
@@ -330,6 +337,9 @@ ConnectionStream::Send(const void* buffer, uint32 size)
status_t
ConnectionPacket::Send(const void* buffer, uint32 size)
{
ASSERT(buffer != NULL);
ASSERT(size < 65535);
// send on DGRAM sockets is atomic. No need to lock.
status_t result = send(fSocket, buffer, size, 0);
if (result < 0)
@@ -341,6 +351,9 @@ ConnectionPacket::Send(const void* buffer, uint32 size)
status_t
ConnectionStream::Receive(void** _buffer, uint32* _size)
{
ASSERT(_buffer != NULL);
ASSERT(_size != NULL);
status_t result;
uint32 size = 0;
@@ -420,6 +433,9 @@ ConnectionStream::Receive(void** _buffer, uint32* _size)
status_t
ConnectionPacket::Receive(void** _buffer, uint32* _size)
{
ASSERT(_buffer != NULL);
ASSERT(_size != NULL);
status_t result;
int32 size = MAX_PACKET_SIZE;
void* buffer = malloc(size);
@@ -482,6 +498,8 @@ Connection::CreateObject(const PeerAddress& address)
status_t
Connection::Connect(Connection **_connection, const PeerAddress& address)
{
ASSERT(_connection != NULL);
Connection* conn = CreateObject(address);
if (conn == NULL)
return B_NO_MEMORY;
@@ -509,6 +527,9 @@ status_t
Connection::SetTo(Connection **_connection, int socket,
const PeerAddress& address)
{
ASSERT(_connection != NULL);
ASSERT(socket != -1);
Connection* conn = CreateObject(address);
if (conn == NULL)
return B_NO_MEMORY;
@@ -637,6 +658,8 @@ ConnectionBase::Disconnect()
status_t
ConnectionListener::Listen(ConnectionListener** listener, uint16 port)
{
ASSERT(listener != NULL);
int sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (sock < 0)
return errno;
@@ -684,6 +707,8 @@ ConnectionListener::Listen(ConnectionListener** listener, uint16 port)
status_t
ConnectionListener::AcceptConnection(Connection** connection)
{
ASSERT(connection != NULL);
object_wait_info object[2];
object[0].object = fWaitCancel;
object[0].type = B_OBJECT_TYPE_SEMAPHORE;
@@ -36,6 +36,7 @@ LockInfo::LockInfo(LockOwner* owner)
:
fOwner(owner)
{
ASSERT(owner != NULL);
fOwner->fUseCount++;
}
@@ -86,6 +87,8 @@ Cookie::~Cookie()
status_t
Cookie::RegisterRequest(RPC::Request* req)
{
ASSERT(req != NULL);
RequestEntry* ent = new RequestEntry;
if (ent == NULL)
return B_NO_MEMORY;
@@ -102,6 +105,8 @@ Cookie::RegisterRequest(RPC::Request* req)
status_t
Cookie::UnregisterRequest(RPC::Request* req)
{
ASSERT(req != NULL);
MutexLocker _(fRequestLock);
RequestEntry* ent = fRequests;
RequestEntry* prev = NULL;
@@ -148,6 +153,8 @@ OpenFileCookie::OpenFileCookie()
void
OpenFileCookie::AddLock(LockInfo* lock)
{
ASSERT(lock != NULL);
lock->fCookieNext = fLocks;
fLocks = lock;
}
@@ -158,9 +165,11 @@ OpenFileCookie::RemoveLock(LockInfo* lock, LockInfo* prev)
{
if (prev != NULL)
prev->fCookieNext = lock->fCookieNext;
else
else {
ASSERT(prev == NULL && fLocks == lock);
fLocks = lock->fCookieNext;
}
}
OpenDirCookie::~OpenDirCookie()
@@ -21,6 +21,7 @@ Delegation::Delegation(const OpenDelegationData& data, Inode* inode,
fInode(inode),
fAttribute(attribute)
{
ASSERT(inode != NULL);
}
@@ -21,6 +21,7 @@ NameCacheEntry::NameCacheEntry(const char* name, ino_t node)
fNode(node),
fName(strdup(name))
{
ASSERT(name != NULL);
}
@@ -55,6 +56,8 @@ DirectoryCache::DirectoryCache(Inode* inode, bool attr)
fAttrDir(attr),
fTrashed(true)
{
ASSERT(inode != NULL);
mutex_init(&fLock, NULL);
}
@@ -97,6 +100,8 @@ DirectoryCache::Trash()
status_t
DirectoryCache::AddEntry(const char* name, ino_t node, bool created)
{
ASSERT(name != NULL);
NameCacheEntry* entry = new(std::nothrow) NameCacheEntry(name, node);
if (entry == NULL)
return B_NO_MEMORY;
@@ -132,6 +137,8 @@ DirectoryCache::AddEntry(const char* name, ino_t node, bool created)
void
DirectoryCache::RemoveEntry(const char* name)
{
ASSERT(name != NULL);
SinglyLinkedList<NameCacheEntry>::Iterator iterator
= fNameCache.GetIterator();
NameCacheEntry* previous = NULL;
@@ -229,6 +236,9 @@ void
DirectoryCache::NotifyChanges(DirectoryCacheSnapshot* oldSnapshot,
DirectoryCacheSnapshot* newSnapshot)
{
ASSERT(newSnapshot != NULL);
ASSERT(oldSnapshot != NULL);
MutexLocker _(newSnapshot->fLock);
SinglyLinkedList<NameCacheEntry>::Iterator oldIt
@@ -18,6 +18,8 @@
status_t
FileInfo::ParsePath(RequestBuilder& req, uint32& count, const char* _path)
{
ASSERT(_path != NULL);
char* path = strdup(_path);
if (path == NULL)
return B_NO_MEMORY;
@@ -49,6 +51,8 @@ FileInfo::ParsePath(RequestBuilder& req, uint32& count, const char* _path)
status_t
FileInfo::CreateName(const char* dirPath, const char* name)
{
ASSERT(name != NULL);
free(const_cast<char*>(fName));
fName = strdup(name);
if (fName == NULL)
@@ -81,6 +85,8 @@ FileInfo::CreateName(const char* dirPath, const char* name)
status_t
FileInfo::UpdateFileHandles(FileSystem* fs)
{
ASSERT(fs != NULL);
Request request(fs->Server(), fs);
RequestBuilder& req = request.Builder();
@@ -60,6 +60,9 @@ FileSystem::~FileSystem()
static const char*
GetPath(const char* root, const char* path)
{
ASSERT(root != NULL);
ASSERT(path != NULL);
int slash = 0;
int i;
for (i = 0; path[i] != '\0'; i++) {
@@ -78,9 +81,13 @@ GetPath(const char* root, const char* path)
status_t
FileSystem::Mount(FileSystem** pfs, RPC::Server* serv, const char* fsPath,
FileSystem::Mount(FileSystem** _fs, RPC::Server* serv, const char* fsPath,
dev_t id, const MountConfiguration& configuration)
{
ASSERT(_fs != NULL);
ASSERT(serv != NULL);
ASSERT(fsPath != NULL);
FileSystem* fs = new(std::nothrow) FileSystem(configuration);
if (fs == NULL)
return B_NO_MEMORY;
@@ -187,7 +194,7 @@ FileSystem::Mount(FileSystem** pfs, RPC::Server* serv, const char* fsPath,
fs->fRoot = reinterpret_cast<RootInode*>(inode);
fs->NFSServer()->AddFileSystem(fs);
*pfs = fs;
*_fs = fs;
fsDeleter.Detach();
return B_OK;
@@ -197,6 +204,8 @@ FileSystem::Mount(FileSystem** pfs, RPC::Server* serv, const char* fsPath,
status_t
FileSystem::GetInode(ino_t id, Inode** _inode)
{
ASSERT(_inode != NULL);
FileInfo fi;
status_t result = fInoIdMap.GetFileInfo(&fi, id);
if (result == B_ENTRY_NOT_FOUND)
@@ -218,6 +227,8 @@ FileSystem::GetInode(ino_t id, Inode** _inode)
status_t
FileSystem::Migrate(const RPC::Server* serv)
{
ASSERT(serv != NULL);
MutexLocker _(fOpenLock);
if (serv != fServer)
return B_OK;
@@ -295,6 +306,8 @@ FileSystem::OpenFilesUnlock()
void
FileSystem::AddOpenFile(OpenState* state)
{
ASSERT(state != NULL);
MutexLocker _(fOpenLock);
fOpenFiles.InsertBefore(fOpenFiles.Head(), state);
@@ -306,6 +319,8 @@ FileSystem::AddOpenFile(OpenState* state)
void
FileSystem::RemoveOpenFile(OpenState* state)
{
ASSERT(state != NULL);
MutexLocker _(fOpenLock);
fOpenFiles.Remove(state);
@@ -332,6 +347,8 @@ FileSystem::DelegationsUnlock()
void
FileSystem::AddDelegation(Delegation* delegation)
{
ASSERT(delegation != NULL);
MutexLocker _(fDelegationLock);
fDelegationList.InsertBefore(fDelegationList.Head(), delegation);
@@ -344,6 +361,8 @@ FileSystem::AddDelegation(Delegation* delegation)
void
FileSystem::RemoveDelegation(Delegation* delegation)
{
ASSERT(delegation != NULL);
MutexLocker _(fDelegationLock);
fDelegationList.Remove(delegation);
@@ -153,6 +153,7 @@ FileSystem::ExpireType() const
inline RPC::Server*
FileSystem::Server()
{
ASSERT(fServer != NULL);
return fServer;
}
@@ -160,6 +161,7 @@ FileSystem::Server()
inline NFS4Server*
FileSystem::NFSServer()
{
ASSERT(fServer->PrivateData() != NULL);
return reinterpret_cast<NFS4Server*>(fServer->PrivateData());
}
@@ -167,6 +169,7 @@ FileSystem::NFSServer()
inline const char*
FileSystem::Path() const
{
ASSERT(fPath != NULL);
return fPath;
}
@@ -38,6 +38,7 @@ IdMap::~IdMap()
uid_t
IdMap::GetUserId(const char* owner)
{
ASSERT(owner != NULL);
return _GetValue<uid_t>(owner, MsgNameToUID);
}
@@ -45,6 +46,7 @@ IdMap::GetUserId(const char* owner)
gid_t
IdMap::GetGroupId(const char* ownerGroup)
{
ASSERT(ownerGroup != NULL);
return _GetValue<gid_t>(ownerGroup, MsgNameToGID);
}
@@ -67,6 +69,8 @@ template<typename T>
T
IdMap::_GetValue(const char* buffer, int32 code)
{
ASSERT(buffer != NULL);
MutexLocker _(fLock);
do {
status_t result = write_port(fRequestPort, MsgNameToUID, buffer,
@@ -41,6 +41,9 @@ Inode::Inode()
status_t
Inode::CreateInode(FileSystem* fs, const FileInfo& fi, Inode** _inode)
{
ASSERT(fs != NULL);
ASSERT(_inode != NULL);
Inode* inode = NULL;
if (fs->Root() == NULL)
inode = new(std::nothrow) RootInode;
@@ -175,6 +178,9 @@ Inode::RevalidateFileCache()
status_t
Inode::LookUp(const char* name, ino_t* id)
{
ASSERT(name != NULL);
ASSERT(id != NULL);
if (fType != NF4DIR)
return B_NOT_A_DIRECTORY;
@@ -218,6 +224,9 @@ Inode::LookUp(const char* name, ino_t* id)
status_t
Inode::Link(Inode* dir, const char* name)
{
ASSERT(dir != NULL);
ASSERT(name != NULL);
ChangeInfo changeInfo;
status_t result = NFS4Inode::Link(dir, name, &changeInfo);
if (result != B_OK)
@@ -253,6 +262,8 @@ Inode::Link(Inode* dir, const char* name)
status_t
Inode::Remove(const char* name, FileType type, ino_t* id)
{
ASSERT(name != NULL);
MemoryDeleter nameDeleter;
if (type == NF4NAMEDATTR) {
status_t result = LoadAttrDirHandle();
@@ -303,6 +314,11 @@ status_t
Inode::Rename(Inode* from, Inode* to, const char* fromName, const char* toName,
bool attribute, ino_t* id)
{
ASSERT(from != NULL);
ASSERT(fromName != NULL);
ASSERT(to != NULL);
ASSERT(toName != NULL);
if (from->fFileSystem != to->fFileSystem)
return B_DONT_DO_THAT;
@@ -386,6 +402,9 @@ Inode::CreateLink(const char* name, const char* path, int mode)
status_t
Inode::CreateObject(const char* name, const char* path, int mode, FileType type)
{
ASSERT(name != NULL);
ASSERT(type != NF4LNK || path != NULL);
ChangeInfo changeInfo;
uint64 fileID;
FileHandle handle;
@@ -455,6 +474,8 @@ Inode::Access(int mode)
status_t
Inode::Stat(struct stat* st, OpenAttrCookie* attr)
{
ASSERT(st != NULL);
if (attr != NULL)
return GetStat(st, attr);
@@ -479,6 +500,8 @@ Inode::Stat(struct stat* st, OpenAttrCookie* attr)
status_t
Inode::GetStat(struct stat* st, OpenAttrCookie* attr)
{
ASSERT(st != NULL);
AttrValue* values;
uint32 count;
status_t result = NFS4Inode::GetStat(&values, &count, attr);
@@ -566,6 +589,8 @@ Inode::GetStat(struct stat* st, OpenAttrCookie* attr)
status_t
Inode::WriteStat(const struct stat* st, uint32 mask, OpenAttrCookie* cookie)
{
ASSERT(st != NULL);
status_t result;
AttrValue attr[6];
uint32 i = 0;
@@ -616,6 +641,7 @@ Inode::WriteStat(const struct stat* st, uint32 mask, OpenAttrCookie* cookie)
if (cookie == NULL) {
MutexLocker stateLocker(fStateLock);
ASSERT(fOpenState != NULL);
result = NFS4Inode::WriteStat(fOpenState, attr, i);
stateLocker.Unlock();
@@ -657,6 +683,9 @@ Inode::CheckLockType(short ltype, uint32 mode)
status_t
Inode::TestLock(OpenFileCookie* cookie, struct flock* lock)
{
ASSERT(cookie != NULL);
ASSERT(lock != NULL);
if (lock->l_type == F_UNLCK)
return B_OK;
@@ -691,6 +720,9 @@ status_t
Inode::AcquireLock(OpenFileCookie* cookie, const struct flock* lock,
bool wait)
{
ASSERT(cookie != NULL);
ASSERT(lock != NULL);
OpenState* state = cookie->fOpenState;
status_t result = CheckLockType(lock->l_type, cookie->fMode);
@@ -732,6 +764,9 @@ Inode::AcquireLock(OpenFileCookie* cookie, const struct flock* lock,
status_t
Inode::ReleaseLock(OpenFileCookie* cookie, const struct flock* lock)
{
ASSERT(cookie != NULL);
ASSERT(lock != NULL);
SyncAndCommit();
LockInfo* prev = NULL;
@@ -782,6 +817,8 @@ Inode::ReleaseLock(OpenFileCookie* cookie, const struct flock* lock)
status_t
Inode::ReleaseAllLocks(OpenFileCookie* cookie)
{
ASSERT(cookie != NULL);
SyncAndCommit();
OpenState* state = cookie->fOpenState;
@@ -816,6 +853,8 @@ status_t
Inode::ChildAdded(const char* name, uint64 fileID,
const FileHandle& fileHandle)
{
ASSERT(name != NULL);
fFileSystem->Root()->MakeInfoInvalid();
FileInfo fi;
@@ -840,6 +879,8 @@ Inode::Name() const
void
Inode::SetDelegation(Delegation* delegation)
{
ASSERT(delegation != NULL);
WriteLocker _(fDelegationLock);
fMetaCache.InvalidateStat();
@@ -187,6 +187,7 @@ Inode::Type() const
inline FileSystem*
Inode::GetFileSystem() const
{
ASSERT(fFileSystem != NULL);
return fFileSystem;
}
@@ -201,6 +202,7 @@ Inode::FileCache()
inline void
Inode::SetOpenState(OpenState* state)
{
ASSERT(state != NULL);
MutexLocker _(fStateLock);
fOpenState = state;
}
@@ -27,6 +27,8 @@ Inode::CreateDir(const char* name, int mode)
status_t
Inode::OpenDir(OpenDirCookie* cookie)
{
ASSERT(cookie != NULL);
if (fType != NF4DIR)
return B_NOT_A_DIRECTORY;
@@ -48,6 +50,8 @@ Inode::OpenDir(OpenDirCookie* cookie)
status_t
Inode::OpenAttrDir(OpenDirCookie* cookie)
{
ASSERT(cookie != NULL);
cookie->fFileSystem = fFileSystem;
cookie->fSpecial = 0;
cookie->fSnapshot = NULL;
@@ -116,6 +120,9 @@ status_t
Inode::FillDirEntry(struct dirent* de, ino_t id, const char* name, uint32 pos,
uint32 size)
{
ASSERT(de != NULL);
ASSERT(name != NULL);
uint32 nameSize = strlen(name);
const uint32 entSize = sizeof(struct dirent);
@@ -137,6 +144,8 @@ Inode::FillDirEntry(struct dirent* de, ino_t id, const char* name, uint32 pos,
status_t
Inode::ReadDirUp(struct dirent* de, uint32 pos, uint32 size)
{
ASSERT(de != NULL);
do {
RPC::Server* serv = fFileSystem->Server();
Request request(serv, fFileSystem);
@@ -189,6 +198,8 @@ Inode::ReadDirUp(struct dirent* de, uint32 pos, uint32 size)
static char*
FileToAttrName(const char* path)
{
ASSERT(path != NULL);
char* name = strdup(path);
if (name == NULL)
return NULL;
@@ -214,6 +225,8 @@ status_t
Inode::GetDirSnapshot(DirectoryCacheSnapshot** _snapshot,
OpenDirCookie* cookie, uint64* _change, bool attribute)
{
ASSERT(_snapshot != NULL);
DirectoryCacheSnapshot* snapshot = new DirectoryCacheSnapshot;
if (snapshot == NULL)
return B_NO_MEMORY;
@@ -292,6 +305,10 @@ status_t
Inode::ReadDir(void* _buffer, uint32 size, uint32* _count,
OpenDirCookie* cookie)
{
ASSERT(_buffer != NULL);
ASSERT(_count != NULL);
ASSERT(cookie != NULL);
if (cookie->fEOF) {
*_count = 0;
return B_OK;
@@ -69,6 +69,8 @@ InodeIdMap::RemoveEntry(ino_t id)
inline status_t
InodeIdMap::GetFileInfo(FileInfo* fi, ino_t id)
{
ASSERT(fi != NULL);
MutexLocker _(fLock);
AVLTreeMap<ino_t, FileInfo>::Iterator it = fMap.Find(id);
if (!it.HasCurrent())
@@ -23,6 +23,10 @@
status_t
Inode::CreateState(const char* name, int mode, int perms, OpenState* state,
OpenDelegationData* delegationData) {
ASSERT(name != NULL);
ASSERT(state != NULL);
ASSERT(delegationData != NULL);
uint64 fileID;
FileHandle handle;
ChangeInfo changeInfo;
@@ -64,6 +68,10 @@ status_t
Inode::Create(const char* name, int mode, int perms, OpenFileCookie* cookie,
OpenDelegationData* data, ino_t* id)
{
ASSERT(name != NULL);
ASSERT(cookie != NULL);
ASSERT(data != NULL);
cookie->fMode = mode;
cookie->fLocks = NULL;
@@ -94,6 +102,8 @@ Inode::Create(const char* name, int mode, int perms, OpenFileCookie* cookie,
status_t
Inode::Open(int mode, OpenFileCookie* cookie)
{
ASSERT(cookie != NULL);
MutexLocker locker(fStateLock);
OpenDelegationData data;
@@ -178,6 +188,8 @@ Inode::Open(int mode, OpenFileCookie* cookie)
status_t
Inode::Close(OpenFileCookie* cookie)
{
ASSERT(cookie != NULL);
SyncAndCommit();
MutexLocker _(fStateLock);
@@ -190,6 +202,8 @@ Inode::Close(OpenFileCookie* cookie)
char*
Inode::AttrToFileName(const char* path)
{
ASSERT(path != NULL);
char* name = strdup(path);
if (name == NULL)
return NULL;
@@ -215,6 +229,9 @@ status_t
Inode::OpenAttr(const char* _name, int mode, OpenAttrCookie* cookie,
bool create, int32 type)
{
ASSERT(_name != NULL);
ASSERT(cookie != NULL);
(void)type;
status_t result = LoadAttrDirHandle();
@@ -272,6 +289,8 @@ Inode::OpenAttr(const char* _name, int mode, OpenAttrCookie* cookie,
status_t
Inode::CloseAttr(OpenAttrCookie* cookie)
{
ASSERT(cookie != NULL);
if (cookie->fOpenState->fDelegation != NULL) {
cookie->fOpenState->fDelegation->GiveUp();
fFileSystem->RemoveDelegation(cookie->fOpenState->fDelegation);
@@ -287,6 +306,11 @@ status_t
Inode::ReadDirect(OpenStateCookie* cookie, off_t pos, void* buffer,
size_t* _length, bool* eof)
{
ASSERT(cookie != NULL || fOpenState != NULL);
ASSERT(buffer != NULL);
ASSERT(_length != NULL);
ASSERT(eof != NULL);
*eof = false;
uint32 size = 0;
@@ -318,6 +342,10 @@ Inode::ReadDirect(OpenStateCookie* cookie, off_t pos, void* buffer,
status_t
Inode::Read(OpenFileCookie* cookie, off_t pos, void* buffer, size_t* _length)
{
ASSERT(cookie != NULL);
ASSERT(buffer != NULL);
ASSERT(_length != NULL);
bool eof = false;
if ((cookie->fMode & O_NOCACHE) != 0)
return ReadDirect(cookie, pos, buffer, _length, &eof);
@@ -329,6 +357,10 @@ status_t
Inode::WriteDirect(OpenStateCookie* cookie, off_t pos, const void* _buffer,
size_t* _length)
{
ASSERT(cookie != NULL || fOpenState != NULL);
ASSERT(_buffer != NULL);
ASSERT(_length != NULL);
uint32 size = 0;
const char* buffer = reinterpret_cast<const char*>(_buffer);
@@ -372,6 +404,10 @@ status_t
Inode::Write(OpenFileCookie* cookie, off_t pos, const void* _buffer,
size_t* _length)
{
ASSERT(cookie != NULL);
ASSERT(_buffer != NULL);
ASSERT(_length != NULL);
struct stat st;
status_t result = Stat(&st);
if (result != B_OK)
@@ -21,6 +21,7 @@ MetadataCache::MetadataCache(Inode* inode)
fInode(inode),
fInited(false)
{
ASSERT(inode != NULL);
mutex_init(&fLock, NULL);
}
@@ -34,6 +35,8 @@ MetadataCache::~MetadataCache()
status_t
MetadataCache::GetStat(struct stat* st)
{
ASSERT(st != NULL);
MutexLocker _(fLock);
if (fForceValid || fExpire > time(NULL)) {
// Do not touch other members of struct stat
@@ -79,6 +82,8 @@ MetadataCache::GrowFile(size_t newSize)
status_t
MetadataCache::GetAccess(uid_t uid, uint32* allowed)
{
ASSERT(allowed != NULL);
MutexLocker _(fLock);
AVLTreeMap<uid_t, AccessEntry>::Iterator it = fAccessCache.Find(uid);
if (!it.HasCurrent())
@@ -141,6 +146,9 @@ void
MetadataCache::NotifyChanges(const struct stat* oldStat,
const struct stat* newStat)
{
ASSERT(oldStat != NULL);
ASSERT(newStat != NULL);
uint32 flags = 0;
if (oldStat->st_size != newStat->st_size)
flags |= B_STAT_SIZE;
@@ -16,6 +16,8 @@
status_t
NFS4Inode::GetChangeInfo(uint64* change, bool attrDir)
{
ASSERT(change != NULL);
do {
RPC::Server* serv = fFileSystem->Server();
Request request(serv, fFileSystem);
@@ -84,6 +86,8 @@ NFS4Inode::CommitWrites()
status_t
NFS4Inode::Access(uint32* allowed)
{
ASSERT(allowed != NULL);
do {
RPC::Server* serv = fFileSystem->Server();
Request request(serv, fFileSystem);
@@ -112,6 +116,11 @@ status_t
NFS4Inode::LookUp(const char* name, uint64* change, uint64* fileID,
FileHandle* handle, bool parent)
{
ASSERT(name != NULL);
ASSERT(change != NULL);
ASSERT(fileID != NULL);
ASSERT(handle != NULL);
do {
RPC::Server* serv = fFileSystem->Server();
Request request(serv, fFileSystem);
@@ -197,6 +206,10 @@ NFS4Inode::LookUp(const char* name, uint64* change, uint64* fileID,
status_t
NFS4Inode::Link(Inode* dir, const char* name, ChangeInfo* changeInfo)
{
ASSERT(dir != NULL);
ASSERT(name != NULL);
ASSERT(changeInfo != NULL);
do {
RPC::Server* serv = fFileSystem->Server();
Request request(serv, fFileSystem);
@@ -229,6 +242,9 @@ NFS4Inode::Link(Inode* dir, const char* name, ChangeInfo* changeInfo)
status_t
NFS4Inode::ReadLink(void* buffer, size_t* length)
{
ASSERT(buffer != NULL);
ASSERT(length != NULL);
do {
RPC::Server* serv = fFileSystem->Server();
Request request(serv, fFileSystem);
@@ -260,6 +276,9 @@ NFS4Inode::ReadLink(void* buffer, size_t* length)
status_t
NFS4Inode::GetStat(AttrValue** values, uint32* count, OpenAttrCookie* cookie)
{
ASSERT(values != NULL);
ASSERT(count != NULL);
do {
RPC::Server* serv = fFileSystem->Server();
Request request(serv, fFileSystem);
@@ -295,6 +314,8 @@ NFS4Inode::GetStat(AttrValue** values, uint32* count, OpenAttrCookie* cookie)
status_t
NFS4Inode::WriteStat(OpenState* state, AttrValue* attrs, uint32 attrCount)
{
ASSERT(attrs != NULL);
do {
RPC::Server* serv = fFileSystem->Server();
Request request(serv, fFileSystem);
@@ -333,6 +354,13 @@ NFS4Inode::RenameNode(Inode* from, Inode* to, const char* fromName,
const char* toName, ChangeInfo* fromChange, ChangeInfo* toChange,
uint64* fileID, bool attribute)
{
ASSERT(from != NULL);
ASSERT(to != NULL);
ASSERT(fromName != NULL);
ASSERT(toName != NULL);
ASSERT(fromChange != NULL);
ASSERT(toChange != NULL);
do {
RPC::Server* serv = from->fFileSystem->Server();
Request request(serv, from->fFileSystem);
@@ -419,6 +447,12 @@ NFS4Inode::CreateFile(const char* name, int mode, int perms, OpenState* state,
ChangeInfo* changeInfo, uint64* fileID, FileHandle* handle,
OpenDelegationData* delegation)
{
ASSERT(name != NULL);
ASSERT(state != NULL);
ASSERT(changeInfo != NULL);
ASSERT(handle != NULL);
ASSERT(delegation != NULL);
bool confirm;
status_t result;
@@ -511,6 +545,9 @@ NFS4Inode::CreateFile(const char* name, int mode, int perms, OpenState* state,
status_t
NFS4Inode::OpenFile(OpenState* state, int mode, OpenDelegationData* delegation)
{
ASSERT(state != NULL);
ASSERT(delegation != NULL);
bool confirm;
status_t result;
uint32 sequence = fFileSystem->OpenOwnerSequenceLock();
@@ -612,6 +649,10 @@ status_t
NFS4Inode::OpenAttr(OpenState* state, const char* name, int mode,
OpenDelegationData* delegation, bool create)
{
ASSERT(name != NULL);
ASSERT(state != NULL);
ASSERT(delegation != NULL);
bool confirm;
status_t result;
uint32 sequence = fFileSystem->OpenOwnerSequenceLock();
@@ -669,6 +710,11 @@ status_t
NFS4Inode::ReadFile(OpenStateCookie* cookie, OpenState* state, uint64 position,
uint32* length, void* buffer, bool* eof)
{
ASSERT(state != NULL);
ASSERT(length != NULL);
ASSERT(buffer != NULL);
ASSERT(eof != NULL);
do {
RPC::Server* serv = fFileSystem->Server();
Request request(serv, fFileSystem);
@@ -700,6 +746,9 @@ status_t
NFS4Inode::WriteFile(OpenStateCookie* cookie, OpenState* state, uint64 position,
uint32* length, const void* buffer, bool commit)
{
ASSERT(state != NULL);
ASSERT(length != NULL);
ASSERT(buffer != NULL);
do {
RPC::Server* serv = fFileSystem->Server();
@@ -736,6 +785,10 @@ NFS4Inode::CreateObject(const char* name, const char* path, int mode,
FileType type, ChangeInfo* changeInfo, uint64* fileID, FileHandle* handle,
bool parent)
{
ASSERT(name != NULL);
ASSERT(changeInfo != NULL);
ASSERT(handle != NULL);
do {
RPC::Server* serv = fFileSystem->Server();
Request request(serv, fFileSystem);
@@ -814,6 +867,9 @@ status_t
NFS4Inode::RemoveObject(const char* name, FileType type, ChangeInfo* changeInfo,
uint64* fileID)
{
ASSERT(name != NULL);
ASSERT(changeInfo != NULL);
do {
RPC::Server* serv = fFileSystem->Server();
Request request(serv, fFileSystem);
@@ -890,6 +946,10 @@ NFS4Inode::ReadDirOnce(DirEntry** dirents, uint32* count, OpenDirCookie* cookie,
bool* eof, uint64* change, uint64* dirCookie, uint64* dirCookieVerf,
bool attribute)
{
ASSERT(dirents != NULL);
ASSERT(count != NULL);
ASSERT(eof != NULL);
do {
RPC::Server* serv = fFileSystem->Server();
Request request(serv, fFileSystem);
@@ -960,6 +1020,8 @@ NFS4Inode::ReadDirOnce(DirEntry** dirents, uint32* count, OpenDirCookie* cookie,
status_t
NFS4Inode::OpenAttrDir(FileHandle* handle)
{
ASSERT(handle != NULL);
do {
RPC::Server* serv = fFileSystem->Server();
Request request(serv, fFileSystem);
@@ -992,6 +1054,11 @@ status_t
NFS4Inode::TestLock(OpenFileCookie* cookie, LockType* type, uint64* position,
uint64* length, bool& conflict)
{
ASSERT(cookie != NULL);
ASSERT(type != NULL);
ASSERT(position != NULL);
ASSERT(length != NULL);
do {
RPC::Server* serv = fFileSystem->Server();
Request request(serv, fFileSystem);
@@ -1026,6 +1093,9 @@ NFS4Inode::TestLock(OpenFileCookie* cookie, LockType* type, uint64* position,
status_t
NFS4Inode::AcquireLock(OpenFileCookie* cookie, LockInfo* lockInfo, bool wait)
{
ASSERT(cookie != NULL);
ASSERT(lockInfo != NULL);
uint32 sequence = fFileSystem->OpenOwnerSequenceLock();
do {
MutexLocker ownerLocker(lockInfo->fOwner->fLock);
@@ -1073,6 +1143,9 @@ NFS4Inode::AcquireLock(OpenFileCookie* cookie, LockInfo* lockInfo, bool wait)
status_t
NFS4Inode::ReleaseLock(OpenFileCookie* cookie, LockInfo* lockInfo)
{
ASSERT(cookie != NULL);
ASSERT(lockInfo != NULL);
do {
MutexLocker ownerLocker(lockInfo->fOwner->fLock);
@@ -143,6 +143,9 @@ status_t
NFS4Object::ConfirmOpen(const FileHandle& fh, OpenState* state,
uint32* sequence)
{
ASSERT(state != NULL);
ASSERT(sequence != NULL);
do {
RPC::Server* serv = fFileSystem->Server();
Request request(serv, fFileSystem);
@@ -24,6 +24,8 @@ NFS4Server::NFS4Server(RPC::Server* serv)
fFileSystems(NULL),
fServer(serv)
{
ASSERT(serv != NULL);
mutex_init(&fClientIdLock, NULL);
mutex_init(&fFSLock, NULL);
mutex_init(&fThreadStartLock, NULL);
@@ -78,6 +80,8 @@ NFS4Server::ServerRebooted(uint64 clientId)
void
NFS4Server::AddFileSystem(FileSystem* fs)
{
ASSERT(fs != NULL);
MutexLocker _(fFSLock);
fs->fPrev = NULL;
fs->fNext = fFileSystems;
@@ -93,6 +97,8 @@ NFS4Server::AddFileSystem(FileSystem* fs)
void
NFS4Server::RemoveFileSystem(FileSystem* fs)
{
ASSERT(fs != NULL);
MutexLocker _(fFSLock);
if (fs == fFileSystems)
fFileSystems = fs->fNext;
@@ -270,6 +276,7 @@ NFS4Server::_Renewal()
status_t
NFS4Server::_RenewalThreadStart(void* ptr)
{
ASSERT(ptr != NULL);
NFS4Server* server = reinterpret_cast<NFS4Server*>(ptr);
return server->_Renewal();
}
@@ -279,6 +286,9 @@ status_t
NFS4Server::ProcessCallback(RPC::CallbackRequest* request,
Connection* connection)
{
ASSERT(request != NULL);
ASSERT(connection != NULL);
RequestInterpreter req(request);
ReplyBuilder reply(request->XID());
@@ -311,6 +321,9 @@ NFS4Server::ProcessCallback(RPC::CallbackRequest* request,
status_t
NFS4Server::CallbackRecall(RequestInterpreter* request, ReplyBuilder* reply)
{
ASSERT(request != NULL);
ASSERT(reply != NULL);
uint32 stateID[3];
uint32 stateSeq;
bool truncate;
@@ -352,6 +365,9 @@ NFS4Server::CallbackRecall(RequestInterpreter* request, ReplyBuilder* reply)
status_t
NFS4Server::CallbackGetAttr(RequestInterpreter* request, ReplyBuilder* reply)
{
ASSERT(request != NULL);
ASSERT(reply != NULL);
FileHandle handle;
int mask;
@@ -112,6 +112,8 @@ OpenState::DeleteLock(LockInfo* lock)
status_t
OpenState::_ReleaseLockOwner(LockOwner* owner)
{
ASSERT(owner != NULL);
do {
RPC::Server* server = fFileSystem->Server();
Request request(server, fFileSystem);
@@ -9,6 +9,7 @@
#include "RPCCall.h"
#include <debug.h>
#include <util/kernel_cpp.h>
#include "RPCDefs.h"
@@ -25,6 +26,9 @@ Call::Call()
Call*
Call::Create(uint32 proc, const Auth* creds, const Auth* ver)
{
ASSERT(creds != NULL);
ASSERT(ver != NULL);
Call* call = new(std::nothrow) Call;
if (call == NULL)
return NULL;
@@ -26,6 +26,8 @@ Callback::Callback(Server* server)
status_t
Callback::EnqueueRequest(CallbackRequest* request, Connection* connection)
{
ASSERT(request != NULL);
ASSERT(connection != NULL);
return fServer->PrivateData()->ProcessCallback(request, connection);
}
@@ -11,6 +11,8 @@
#include <stdlib.h>
#include <debug.h>
#include "NFS4Defs.h"
#include "RPCDefs.h"
@@ -25,6 +27,8 @@ CallbackRequest::CallbackRequest(void* buffer, int size)
fStream(buffer, size),
fBuffer(buffer)
{
ASSERT(buffer != NULL);
fXID = fStream.GetUInt();
if (fStream.GetUInt() != CALL)
@@ -50,6 +50,8 @@ CallbackServer::~CallbackServer()
status_t
CallbackServer::RegisterCallback(Callback* callback)
{
ASSERT(callback != NULL);
status_t result = StartServer();
if (result != B_OK)
return result;
@@ -88,6 +90,8 @@ CallbackServer::RegisterCallback(Callback* callback)
status_t
CallbackServer::UnregisterCallback(Callback* callback)
{
ASSERT(callback != NULL);
int32 id = callback->ID();
WriteLocker _(fArrayLock);
@@ -161,6 +165,8 @@ CallbackServer::StopServer()
status_t
CallbackServer::NewConnection(Connection* connection)
{
ASSERT(connection != NULL);
ConnectionEntry* entry = new ConnectionEntry;
entry->fConnection = connection;
entry->fPrev = NULL;
@@ -205,6 +211,8 @@ CallbackServer::NewConnection(Connection* connection)
status_t
CallbackServer::ReleaseConnection(ConnectionEntry* entry)
{
ASSERT(entry != NULL);
MutexLocker _(fConnectionLock);
if (entry->fNext != NULL)
entry->fNext->fPrev = entry->fPrev;
@@ -222,6 +230,8 @@ CallbackServer::ReleaseConnection(ConnectionEntry* entry)
status_t
CallbackServer::ConnectionThreadLauncher(void* object)
{
ASSERT(object != NULL);
void** objects = reinterpret_cast<void**>(object);
CallbackServer* server = reinterpret_cast<CallbackServer*>(objects[0]);
ConnectionEntry* entry = reinterpret_cast<ConnectionEntry*>(objects[1]);
@@ -234,6 +244,8 @@ CallbackServer::ConnectionThreadLauncher(void* object)
status_t
CallbackServer::ConnectionThread(ConnectionEntry* entry)
{
ASSERT(entry != NULL);
Connection* connection = entry->fConnection;
CallbackReply* reply;
@@ -287,6 +299,8 @@ CallbackServer::ConnectionThread(ConnectionEntry* entry)
status_t
CallbackServer::ListenerThreadLauncher(void* object)
{
ASSERT(object != NULL);
CallbackServer* server = reinterpret_cast<CallbackServer*>(object);
return server->ListenerThread();
}
@@ -9,6 +9,7 @@
#include "RPCReply.h"
#include <debug.h>
#include <util/kernel_cpp.h>
#include "RPCDefs.h"
@@ -23,6 +24,8 @@ Reply::Reply(void* buffer, int size)
fStream(buffer, size),
fBuffer(buffer)
{
ASSERT(buffer != NULL);
fXID = fStream.GetUInt();
if (fStream.GetInt() != REPLY) {
fError = B_BAD_VALUE;
@@ -38,6 +38,8 @@ RequestManager::~RequestManager()
void
RequestManager::AddRequest(Request* request)
{
ASSERT(request != NULL);
MutexLocker _(fLock);
if (fQueueTail != NULL)
fQueueTail->fNext = request;
@@ -81,6 +83,9 @@ Server::Server(Connection* connection, PeerAddress* address)
fCallback(NULL),
fXID(rand() << 1)
{
ASSERT(connection != NULL);
ASSERT(address != NULL);
mutex_init(&fCallbackLock, NULL);
_StartListening();
@@ -129,6 +134,9 @@ Server::_StartListening()
status_t
Server::SendCall(Call* call, Reply** reply)
{
ASSERT(call != NULL);
ASSERT(reply != NULL);
Request* req;
status_t result = SendCallAsync(call, reply, &req);
if (result != B_OK)
@@ -149,6 +157,10 @@ Server::SendCall(Call* call, Reply** reply)
status_t
Server::SendCallAsync(Call* call, Reply** reply, Request** request)
{
ASSERT(call != NULL);
ASSERT(reply != NULL);
ASSERT(request != NULL);
if (fThreadError != B_OK)
return fThreadError;
@@ -175,6 +187,9 @@ Server::SendCallAsync(Call* call, Reply** reply, Request** request)
status_t
Server::ResendCallAsync(Call* call, Request* request)
{
ASSERT(call != NULL);
ASSERT(request != NULL);
if (fThreadError != B_OK) {
fRequests.FindRequest(request->fXID);
delete request;
@@ -196,6 +211,8 @@ Server::ResendCallAsync(Call* call, Request* request)
status_t
Server::WakeCall(Request* request)
{
ASSERT(request != NULL);
Request* req = fRequests.FindRequest(request->fXID);
if (req == NULL)
return B_OK;
@@ -281,6 +298,8 @@ Server::_Listener()
status_t
Server::_ListenerThreadStart(void* object)
{
ASSERT(object != NULL);
Server* server = reinterpret_cast<Server*>(object);
return server->_Listener();
}
@@ -304,6 +323,9 @@ status_t
ServerManager::Acquire(Server** _server, const PeerAddress& address,
ProgramData* (*createPrivateData)(Server*))
{
ASSERT(_server != NULL);
ASSERT(createPrivateData != NULL);
status_t result;
MutexLocker locker(fLock);
@@ -357,6 +379,8 @@ ServerManager::Acquire(Server** _server, const PeerAddress& address,
void
ServerManager::Release(Server* server)
{
ASSERT(server != NULL);
MutexLocker _(fLock);
ServerNode* node = _Find(server->ID());
if (node != NULL) {
@@ -391,6 +415,8 @@ ServerManager::_Find(const PeerAddress& address)
void
ServerManager::_Delete(ServerNode* node)
{
ASSERT(node != NULL);
bool found = false;
ServerNode* previous = NULL;
ServerNode* current = fRoot;
@@ -452,6 +478,8 @@ ServerManager::_Delete(ServerNode* node)
ServerNode*
ServerManager::_Insert(ServerNode* node)
{
ASSERT(node != NULL);
ServerNode* previous = NULL;
ServerNode* current = fRoot;
while (current != NULL) {
@@ -46,6 +46,7 @@ Request::Request(RPC::Server* server, FileSystem* fileSystem)
fServer(server),
fFileSystem(fileSystem)
{
ASSERT(server != NULL);
}
@@ -35,6 +35,8 @@ RootInode::~RootInode()
status_t
RootInode::ReadInfo(struct fs_info* info)
{
ASSERT(info != NULL);
status_t result = _UpdateInfo();
if (result != B_OK)
return result;
@@ -172,6 +174,8 @@ RootInode::ProbeMigration()
status_t
RootInode::GetLocations(AttrValue** attrv)
{
ASSERT(attrv != NULL);
do {
RPC::Server* server = fFileSystem->Server();
Request request(server, fFileSystem);
@@ -209,6 +213,7 @@ RootInode::GetLocations(AttrValue** attrv)
const char*
RootInode::Name() const
{
ASSERT(fName != NULL);
return fName;
}
@@ -63,6 +63,8 @@ RootInode::IOSize()
inline void
RootInode::SetName(const char* name)
{
ASSERT(name != NULL);
free(const_cast<char*>(fName));
fName = strdup(name);
}
@@ -74,6 +74,8 @@ WorkQueue::EnqueueJob(JobType type, void* args)
status_t
WorkQueue::LaunchWorkingThread(void* object)
{
ASSERT(object != NULL);
WorkQueue* queue = reinterpret_cast<WorkQueue*>(object);
return queue->WorkingThread();
}
@@ -115,6 +117,7 @@ WorkQueue::DequeueJob()
MutexLocker locker(fQueueLock);
WorkQueueEntry* entry = fQueue.RemoveHead();
ASSERT(entry != NULL);
void* args = entry->fArguments;
switch (entry->fType) {
@@ -133,6 +136,7 @@ WorkQueue::DequeueJob()
void
WorkQueue::JobRecall(DelegationRecallArgs* args)
{
ASSERT(args != NULL);
args->fDelegation->GetInode()->RecallDelegation(args->fTruncate);
}
@@ -140,6 +144,8 @@ WorkQueue::JobRecall(DelegationRecallArgs* args)
void
WorkQueue::JobIO(IORequestArgs* args)
{
ASSERT(args != NULL);
uint64 offset = io_request_offset(args->fRequest);
uint64 length = io_request_length(args->fRequest);
@@ -14,6 +14,7 @@
#include <fs_interface.h>
#include "Connection.h"
#include "Debug.h"
#include "FileSystem.h"
#include "IdMap.h"
#include "Inode.h"