nfs4: Use FileInfo instead of filehandle to identify a file

This commit is contained in:
Pawel Dziepak 2012-07-03 01:33:41 +02:00
parent 1a0820703b
commit a28e873222
9 changed files with 74 additions and 83 deletions

View File

@ -74,7 +74,7 @@ struct OpenFileCookie : public Cookie {
uint32 fMode;
Filehandle fHandle;
FileInfo fInfo;
uint32 fStateId[3];
uint32 fStateSeq;

View File

@ -32,7 +32,7 @@ struct Filehandle {
// since OPEN requires both parent filehandle and file name (just like LOOKUP).
struct FileInfo {
uint64 fFileId;
Filehandle fFH;
Filehandle fHandle;
Filehandle fParent;
const char* fName;
@ -101,7 +101,7 @@ inline
FileInfo::FileInfo(const FileInfo& fi)
:
fFileId(fi.fFileId),
fFH(fi.fFH),
fHandle(fi.fHandle),
fParent(fi.fParent),
fName(strdup(fi.fName)),
fPath(strdup(fi.fPath))
@ -113,7 +113,7 @@ inline FileInfo&
FileInfo::operator=(const FileInfo& fi)
{
fFileId = fi.fFileId;
fFH = fi.fFH;
fHandle = fi.fHandle;
fParent = fi.fParent;
free(const_cast<char*>(fName));

View File

@ -170,7 +170,7 @@ Filesystem::Mount(Filesystem** pfs, RPC::Server* serv, const char* fsPath,
fs->fDevId = id;
fs->fFsId = *fsid;
fi.fFH = fh;
fi.fHandle = fh;
fi.fParent = fh;
fi.fPath = strdup(sGetPath(fs->fPath, fsPath));

View File

@ -34,18 +34,15 @@ Inode::CreateInode(Filesystem* fs, const FileInfo &fi, Inode** _inode)
if (inode == NULL)
return B_NO_MEMORY;
inode->fHandle = fi.fFH;
inode->fInfo = fi;
inode->fFilesystem = fs;
inode->fParentFH = fi.fParent;
inode->fName = strdup(fi.fName);
inode->fPath = strdup(fi.fPath);
do {
RPC::Server* serv = fs->Server();
Request request(serv);
RequestBuilder& req = request.Builder();
req.PutFH(inode->fHandle);
req.PutFH(inode->fInfo.fHandle);
Attribute attr[] = { FATTR4_TYPE, FATTR4_FSID, FATTR4_FILEID };
req.GetAttr(attr, sizeof(attr) / sizeof(Attribute));
@ -69,11 +66,11 @@ Inode::CreateInode(Filesystem* fs, const FileInfo &fi, Inode** _inode)
if (fi.fFileId == 0) {
if (count < 3 || values[2].fAttribute != FATTR4_FILEID)
inode->fFileId = fs->AllocFileId();
inode->fInfo.fFileId = fs->AllocFileId();
else
inode->fFileId = values[2].fData.fValue64;
inode->fInfo.fFileId = values[2].fData.fValue64;
} else
inode->fFileId = fi.fFileId;
inode->fInfo.fFileId = fi.fFileId;
// FATTR4_TYPE is mandatory
inode->fType = values[0].fData.fValue32;
@ -97,7 +94,7 @@ Inode::CreateInode(Filesystem* fs, const FileInfo &fi, Inode** _inode)
Inode::~Inode()
{
free(const_cast<char*>(fName));
free(const_cast<char*>(fInfo.fName));
}
@ -117,7 +114,7 @@ Inode::LookUp(const char* name, ino_t* id)
Request request(serv);
RequestBuilder& req = request.Builder();
req.PutFH(fHandle);
req.PutFH(fInfo.fHandle);
if (!strcmp(name, ".."))
req.LookUpUp();
@ -174,13 +171,13 @@ Inode::LookUp(const char* name, ino_t* id)
FileInfo fi;
fi.fFileId = fileId;
fi.fFH = fh;
fi.fParent = fHandle;
fi.fHandle = fh;
fi.fParent = fInfo.fHandle;
fi.fName = strdup(name);
char* path = reinterpret_cast<char*>(malloc(strlen(name) + 2 +
strlen(fPath)));
strcpy(path, fPath);
strlen(fInfo.fPath)));
strcpy(path, fInfo.fPath);
strcat(path, "/");
strcat(path, name);
fi.fPath = path;
@ -200,9 +197,9 @@ Inode::Link(Inode* dir, const char* name)
Request request(serv);
RequestBuilder& req = request.Builder();
req.PutFH(fHandle);
req.PutFH(fInfo.fHandle);
req.SaveFH();
req.PutFH(dir->fHandle);
req.PutFH(dir->fInfo.fHandle);
req.Link(name);
status_t result = request.Send();
@ -244,7 +241,7 @@ Inode::Remove(const char* name, FileType type)
Request request(serv);
RequestBuilder& req = request.Builder();
req.PutFH(fHandle);
req.PutFH(fInfo.fHandle);
req.LookUp(name);
AttrValue attr;
attr.fAttribute = FATTR4_TYPE;
@ -255,7 +252,7 @@ Inode::Remove(const char* name, FileType type)
else
req.Nverify(&attr, 1);
req.PutFH(fHandle);
req.PutFH(fInfo.fHandle);
req.Remove(name);
status_t result = request.Send();
@ -305,9 +302,9 @@ Inode::Rename(Inode* from, Inode* to, const char* fromName, const char* toName)
Request request(serv);
RequestBuilder& req = request.Builder();
req.PutFH(from->fHandle);
req.PutFH(from->fInfo.fHandle);
req.SaveFH();
req.PutFH(to->fHandle);
req.PutFH(to->fInfo.fHandle);
req.Rename(fromName, toName);
status_t result = request.Send();
@ -346,7 +343,7 @@ Inode::CreateLink(const char* name, const char* path, int mode)
Request request(serv);
RequestBuilder& req = request.Builder();
req.PutFH(fHandle);
req.PutFH(fInfo.fHandle);
AttrValue attr;
attr.fAttribute = FATTR4_MODE;
@ -381,7 +378,7 @@ Inode::ReadLink(void* buffer, size_t* length)
Request request(serv);
RequestBuilder& req = request.Builder();
req.PutFH(fHandle);
req.PutFH(fInfo.fHandle);
req.ReadLink();
status_t result = request.Send();
@ -412,7 +409,7 @@ Inode::Access(int mode)
Request request(serv);
RequestBuilder& req = request.Builder();
req.PutFH(fHandle);
req.PutFH(fInfo.fHandle);
req.Access();
status_t result = request.Send();
@ -460,7 +457,7 @@ Inode::Stat(struct stat* st)
Request request(serv);
RequestBuilder& req = request.Builder();
req.PutFH(fHandle);
req.PutFH(fInfo.fHandle);
Attribute attr[] = { FATTR4_SIZE, FATTR4_MODE, FATTR4_NUMLINKS,
FATTR4_TIME_ACCESS, FATTR4_TIME_CREATE,
@ -499,7 +496,7 @@ Inode::Stat(struct stat* st)
} else {
// Try to guess using ACCESS request
request.Reset();
request.Builder().PutFH(fHandle);
request.Builder().PutFH(fInfo.fHandle);
request.Builder().Access();
result = request.Send();
if (result != B_OK)
@ -617,7 +614,7 @@ Inode::WriteStat(const struct stat* st, uint32 mask)
Request request(serv);
RequestBuilder& req = request.Builder();
req.PutFH(fHandle);
req.PutFH(fInfo.fHandle);
if ((mask & B_STAT_SIZE) != 0)
req.SetAttr(cookie->fStateId, cookie->fStateSeq, attr, i);
else
@ -690,7 +687,7 @@ Inode::TestLock(OpenFileCookie* cookie, struct flock* lock)
Request request(serv);
RequestBuilder& req = request.Builder();
req.PutFH(fHandle);
req.PutFH(fInfo.fHandle);
req.LockT(sGetLockType(lock->l_type, false), lock->l_start,
lock->l_len, cookie);
@ -760,7 +757,7 @@ Inode::AcquireLock(OpenFileCookie* cookie, const struct flock* lock,
Request request(serv);
RequestBuilder& req = request.Builder();
req.PutFH(fHandle);
req.PutFH(fInfo.fHandle);
req.Lock(cookie, linfo);
status_t result = request.Send();
@ -829,7 +826,7 @@ Inode::ReleaseLock(OpenFileCookie* cookie, const struct flock* lock)
Request request(serv);
RequestBuilder& req = request.Builder();
req.PutFH(fHandle);
req.PutFH(fInfo.fHandle);
req.LockU(linfo);
status_t result = request.Send();
@ -874,7 +871,7 @@ Inode::ReleaseAllLocks(OpenFileCookie* cookie)
Request request(serv);
RequestBuilder& req = request.Builder();
req.PutFH(fHandle);
req.PutFH(fInfo.fHandle);
req.LockU(linfo);
status_t result = request.Send();
@ -1021,7 +1018,7 @@ Inode::_LookUpFilehandle()
uint32 lookupCount = 0;
sParsePath(req, &lookupCount, fFilesystem->Path());
sParsePath(req, &lookupCount, fPath);
sParsePath(req, &lookupCount, fInfo.fPath);
req.GetFH();
@ -1029,7 +1026,7 @@ Inode::_LookUpFilehandle()
AttrValue attr;
attr.fAttribute = FATTR4_FILEID;
attr.fFreePointer = false;
attr.fData.fValue64 = fFileId;
attr.fData.fValue64 = fInfo.fFileId;
req.Verify(&attr, 1);
}
@ -1043,7 +1040,7 @@ Inode::_LookUpFilehandle()
for (uint32 i = 0; i < lookupCount; i++)
reply.LookUp();
result = reply.GetFH(&fHandle);
result = reply.GetFH(&fInfo.fHandle);
if (result != B_OK)
return result;

View File

@ -90,16 +90,10 @@ protected:
static inline ino_t _FileIdToInoT(uint64 fileid);
uint64 fFileId;
uint32 fType;
Filehandle fHandle;
FileInfo fInfo;
Filesystem* fFilesystem;
Filehandle fParentFH;
const char* fName;
const char* fPath;
};
@ -117,7 +111,7 @@ Inode::_FileIdToInoT(uint64 fileid)
inline ino_t
Inode::ID() const
{
return _FileIdToInoT(fFileId);
return _FileIdToInoT(fInfo.fFileId);
}
@ -131,7 +125,7 @@ Inode::Type() const
inline const char*
Inode::Name() const
{
return fName;
return fInfo.fName;
}

View File

@ -24,7 +24,7 @@ Inode::CreateDir(const char* name, int mode)
Request request(serv);
RequestBuilder& req = request.Builder();
req.PutFH(fHandle);
req.PutFH(fInfo.fHandle);
AttrValue attr;
attr.fAttribute = FATTR4_MODE;
@ -59,7 +59,7 @@ Inode::OpenDir(OpenDirCookie* cookie)
Request request(serv);
RequestBuilder& req = request.Builder();
req.PutFH(fHandle);
req.PutFH(fInfo.fHandle);
req.Access();
status_t result = request.Send();
@ -99,7 +99,7 @@ Inode::_ReadDirOnce(DirEntry** dirents, uint32* count, OpenDirCookie* cookie,
Request request(serv);
RequestBuilder& req = request.Builder();
req.PutFH(fHandle);
req.PutFH(fInfo.fHandle);
Attribute attr[] = { FATTR4_FSID, FATTR4_FILEID };
req.ReadDir(*count, cookie->fCookie, cookie->fCookieVerf, attr,
@ -151,7 +151,7 @@ Inode::_ReadDirUp(struct dirent* de, uint32 pos, uint32 size)
Request request(serv);
RequestBuilder& req = request.Builder();
req.PutFH(fHandle);
req.PutFH(fInfo.fHandle);
req.LookUpUp();
req.GetFH();
@ -214,7 +214,7 @@ Inode::ReadDir(void* _buffer, uint32 size, uint32* _count,
if (cookie->fCookie == 0 && cookie->fCookieVerf == 2 && count < *_count) {
struct dirent* de = reinterpret_cast<dirent*>(buffer + pos);
_FillDirEntry(de, fFileId, ".", pos, size);
_FillDirEntry(de, fInfo.fFileId, ".", pos, size);
pos += de->d_reclen;
count++;
@ -224,10 +224,10 @@ Inode::ReadDir(void* _buffer, uint32 size, uint32* _count,
if (cookie->fCookie == 0 && cookie->fCookieVerf == 1 && count < *_count) {
struct dirent* de = reinterpret_cast<dirent*>(buffer + pos);
if (strcmp(fName, "/"))
if (strcmp(fInfo.fName, "/"))
_ReadDirUp(de, pos, size);
else
_FillDirEntry(de, _FileIdToInoT(fFileId), "..", pos, size);
_FillDirEntry(de, _FileIdToInoT(fInfo.fFileId), "..", pos, size);
pos += de->d_reclen;
count++;

View File

@ -75,7 +75,7 @@ Inode::Create(const char* name, int mode, int perms, OpenFileCookie* cookie,
cookie->fOwnerId = atomic_add64(&cookie->fLastOwnerId, 1);
req.PutFH(fHandle);
req.PutFH(fInfo.fHandle);
AttrValue cattr[2];
uint32 i = 0;
@ -130,13 +130,13 @@ Inode::Create(const char* name, int mode, int perms, OpenFileCookie* cookie,
FileInfo fi;
fi.fFileId = fileId;
fi.fFH = fh;
fi.fParent = fHandle;
fi.fHandle = fh;
fi.fParent = fInfo.fHandle;
fi.fName = strdup(name);
char* path = reinterpret_cast<char*>(malloc(strlen(name) + 2 +
strlen(fPath)));
strcpy(path, fPath);
strlen(fInfo.fPath)));
strcpy(path, fInfo.fPath);
strcat(path, "/");
strcat(path, name);
fi.fPath = path;
@ -144,7 +144,7 @@ Inode::Create(const char* name, int mode, int perms, OpenFileCookie* cookie,
fFilesystem->InoIdMap()->AddEntry(fi, *id);
cookie->fFilesystem = fFilesystem;
cookie->fHandle = fh;
cookie->fInfo = fi;
break;
} while (true);
@ -165,7 +165,7 @@ Inode::Open(int mode, OpenFileCookie* cookie)
status_t result;
cookie->fFilesystem = fFilesystem;
cookie->fHandle = fHandle;
cookie->fInfo = fInfo;
cookie->fMode = mode;
cookie->fSequence = 0;
cookie->fLocks = NULL;
@ -182,36 +182,36 @@ Inode::Open(int mode, OpenFileCookie* cookie)
// Since we are opening the file using a pair (parentFH, name) we
// need to check for race conditions.
if (fFilesystem->IsAttrSupported(FATTR4_FILEID)) {
req.PutFH(fParentFH);
req.LookUp(fName);
req.PutFH(fInfo.fParent);
req.LookUp(fInfo.fName);
AttrValue attr;
attr.fAttribute = FATTR4_FILEID;
attr.fFreePointer = false;
attr.fData.fValue64 = fFileId;
attr.fData.fValue64 = fInfo.fFileId;
req.Verify(&attr, 1);
} else if (fFilesystem->ExpireType() == FH4_PERSISTENT) {
req.PutFH(fParentFH);
req.LookUp(fName);
req.PutFH(fInfo.fParent);
req.LookUp(fInfo.fName);
AttrValue attr;
attr.fAttribute = FATTR4_FILEHANDLE;
attr.fFreePointer = true;
attr.fData.fPointer = malloc(sizeof(fHandle));
memcpy(attr.fData.fPointer, &fHandle, sizeof(fHandle));
attr.fData.fPointer = malloc(sizeof(fInfo.fHandle));
memcpy(attr.fData.fPointer, &fInfo.fHandle, sizeof(fInfo.fHandle));
req.Verify(&attr, 1);
}
req.PutFH(fParentFH);
req.PutFH(fInfo.fParent);
if ((mode & O_TRUNC) == O_TRUNC) {
AttrValue attr;
attr.fAttribute = FATTR4_SIZE;
attr.fFreePointer = false;
attr.fData.fValue64 = 0;
req.Open(CLAIM_NULL, cookie->fSequence++, sModeToAccess(mode),
cookie->fClientId, OPEN4_CREATE, cookie->fOwnerId, fName, &attr,
1, false);
cookie->fClientId, OPEN4_CREATE, cookie->fOwnerId, fInfo.fName,
&attr, 1, false);
} else
req.Open(CLAIM_NULL, cookie->fSequence++, sModeToAccess(mode),
cookie->fClientId, OPEN4_NOCREATE, cookie->fOwnerId, fName);
cookie->fClientId, OPEN4_NOCREATE, cookie->fOwnerId, fInfo.fName);
result = request.Send();
if (result != B_OK)
@ -248,7 +248,7 @@ Inode::Open(int mode, OpenFileCookie* cookie)
fFilesystem->AddOpenFile(cookie);
if (confirm)
return _ConfirmOpen(fHandle, cookie);
return _ConfirmOpen(fInfo.fHandle, cookie);
else
return B_OK;
}
@ -264,7 +264,7 @@ Inode::Close(OpenFileCookie* cookie)
Request request(serv);
RequestBuilder& req = request.Builder();
req.PutFH(fHandle);
req.PutFH(fInfo.fHandle);
req.Close(cookie->fSequence++, cookie->fStateId,
cookie->fStateSeq);
@ -302,7 +302,7 @@ Inode::Read(OpenFileCookie* cookie, off_t pos, void* buffer, size_t* _length)
Request request(serv);
RequestBuilder& req = request.Builder();
req.PutFH(fHandle);
req.PutFH(fInfo.fHandle);
req.Read(cookie->fStateId, cookie->fStateSeq, pos + size,
*_length - size);
@ -358,7 +358,7 @@ Inode::Write(OpenFileCookie* cookie, off_t pos, const void* _buffer,
pos = fileSize;
}
req.PutFH(fHandle);
req.PutFH(fInfo.fHandle);
if ((cookie->fMode & O_APPEND) == O_APPEND) {
AttrValue attr;
attr.fAttribute = FATTR4_SIZE;

View File

@ -77,7 +77,7 @@ NFS4Server::_ReclaimOpen(OpenFileCookie* cookie)
Request request(fServer);
RequestBuilder& req = request.Builder();
req.PutFH(cookie->fHandle);
req.PutFH(cookie->fInfo.fHandle);
req.Open(CLAIM_PREVIOUS, cookie->fSequence++, sModeToAccess(cookie->fMode),
cookie->fClientId, OPEN4_NOCREATE, cookie->fOwnerId, NULL);
@ -97,7 +97,7 @@ NFS4Server::_ReclaimOpen(OpenFileCookie* cookie)
if (confirm) {
request.Reset();
req.PutFH(cookie->fHandle);
req.PutFH(cookie->fInfo.fHandle);
req.OpenConfirm(cookie->fSequence++, cookie->fStateId,
cookie->fStateSeq);
@ -131,7 +131,7 @@ NFS4Server::_ReclaimLocks(OpenFileCookie* cookie)
Request request(fServer);
RequestBuilder& req = request.Builder();
req.PutFH(cookie->fHandle);
req.PutFH(cookie->fInfo.fHandle);
req.Lock(cookie, linfo, true);
status_t result = request.Send();

View File

@ -22,7 +22,7 @@ RootInode::ReadInfo(struct fs_info* info)
Request request(serv);
RequestBuilder& req = request.Builder();
req.PutFH(fHandle);
req.PutFH(fInfo.fHandle);
Attribute attr[] = { FATTR4_FILES_FREE, FATTR4_FILES_TOTAL,
FATTR4_MAXREAD, FATTR4_MAXWRITE, FATTR4_SPACE_FREE,
FATTR4_SPACE_TOTAL };
@ -87,7 +87,7 @@ RootInode::ReadInfo(struct fs_info* info)
} while (true);
info->flags = 0;
strncpy(info->volume_name, fName, B_FILE_NAME_LENGTH);
strncpy(info->volume_name, fInfo.fName, B_FILE_NAME_LENGTH);
return B_OK;
}
@ -101,7 +101,7 @@ RootInode::ProbeMigration()
Request request(serv);
RequestBuilder& req = request.Builder();
req.PutFH(fHandle);
req.PutFH(fInfo.fHandle);
req.Access();
status_t result = request.Send();
@ -130,7 +130,7 @@ RootInode::GetLocations(AttrValue** attrv)
Request request(serv);
RequestBuilder& req = request.Builder();
req.PutFH(fHandle);
req.PutFH(fInfo.fHandle);
Attribute attr[] = { FATTR4_FS_LOCATIONS };
req.GetAttr(attr, sizeof(attr) / sizeof(Attribute));