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