Skip to content

Commit

Permalink
1. Implement ferror, feof and clearerr libc calls. This includes addi…
Browse files Browse the repository at this point in the history
…ng a new variable to NVF struct to store the file stream related flags - namely the EOF flag and the ERROR flag.

2. Fix the offset update and return value in file stream related calls.
3. Fix using the clear_tbl_mmap_entry to clear the correct size. This includes change in interface and corresponding calls.
  • Loading branch information
OmSaran committed Jul 19, 2020
1 parent 411933a commit cf787a1
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 16 deletions.
77 changes: 66 additions & 11 deletions splitfs/fileops_nvp.c
Original file line number Diff line number Diff line change
Expand Up @@ -2045,11 +2045,11 @@ struct NVNode * nvp_get_node(const char *path, struct stat *file_st, int result)
node->is_large_file = 0;
node->dr_mem_used = 0;
if (node->true_length == 0) {
clear_tbl_mmap_entry(&_nvp_tbl_mmaps[file_st->st_ino % APPEND_TBL_MAX]);
clear_tbl_mmap_entry(&_nvp_tbl_mmaps[file_st->st_ino % APPEND_TBL_MAX], NUM_APP_TBL_MMAP_ENTRIES);

#if DATA_JOURNALING_ENABLED

clear_tbl_mmap_entry(&_nvp_over_tbl_mmaps[file_st->st_ino % OVER_TBL_MAX]);
clear_tbl_mmap_entry(&_nvp_over_tbl_mmaps[file_st->st_ino % OVER_TBL_MAX], NUM_OVER_TBL_MMAP_ENTRIES);

#endif // DATA_JOURNALING_ENABLED

Expand Down Expand Up @@ -4994,6 +4994,55 @@ RETT_EXECV _nvp_EXECV(INTF_EXECV) {
return _nvp_fileops->EXECV(CALL_EXECV);
}

#ifdef TRACE_FP_CALLS
RETT_FEOF _nvp_FEOF(INTF_FEOF)
{
CHECK_RESOLVE_FILEOPS(_nvp_);
RETT_FEOF result;

struct NVFile* nvf = &_nvp_fd_lookup[fileno(fp)];

NVP_LOCK_NODE_WR(nvf);
NVP_LOCK_FD_WR(nvf);
result = (nvf->file_stream_flags & NVP_IO_EOF_SEEN) > 0;
NVP_UNLOCK_NODE_WR(nvf);
NVP_UNLOCK_FD_WR(nvf);
return result;
}
#endif

#ifdef TRACE_FP_CALLS
RETT_FERROR _nvp_FERROR(INTF_FERROR)
{
CHECK_RESOLVE_FILEOPS(_nvp_);
RETT_FERROR result;

struct NVFile* nvf = &_nvp_fd_lookup[fileno(fp)];
NVP_LOCK_NODE_WR(nvf);
NVP_LOCK_FD_WR(nvf);
result = (nvf->file_stream_flags & NVP_IO_ERR_SEEN) > 0;
NVP_UNLOCK_NODE_WR(nvf);
NVP_UNLOCK_FD_WR(nvf);
return result;
}
#endif

#ifdef TRACE_FP_CALLS
RETT_CLEARERR _nvp_CLEARERR(INTF_CLEARERR)
{
CHECK_RESOLVE_FILEOPS(_nvp_);
int fd = -1;

struct NVFile* nvf = &_nvp_fd_lookup[fileno(fp)];

NVP_LOCK_NODE_WR(nvf);
NVP_LOCK_FD_WR(nvf);
nvf->file_stream_flags &= ~(NVP_IO_ERR_SEEN | NVP_IO_EOF_SEEN);
NVP_UNLOCK_NODE_WR(nvf);
NVP_UNLOCK_FD_WR(nvf);
}
#endif

#ifdef TRACE_FP_CALLS
RETT_FCLOSE _nvp_FCLOSE(INTF_FCLOSE)
{
Expand Down Expand Up @@ -5064,7 +5113,7 @@ RETT_FREAD _nvp_FREAD(INTF_FREAD)
result = _nvp_do_pread(fileno(fp),
buf,
length*nmemb,
__sync_fetch_and_add(nvf->offset, length),
__sync_fetch_and_add(nvf->offset, (length*nmemb)),
0,
cpuid,
nvf,
Expand All @@ -5081,19 +5130,24 @@ RETT_FREAD _nvp_FREAD(INTF_FREAD)
DEBUG("_nvp_READ: PREAD failed; not changing offset. "
"(returned %i)\n", result);
//assert(0); // TODO: this is for testing only
__sync_fetch_and_sub(nvf->offset, length);
__sync_fetch_and_sub(nvf->offset, (length*nmemb));
if (result < 0)
nvf->file_stream_flags |= NVP_IO_ERR_SEEN;
else
nvf->file_stream_flags |= NVP_IO_EOF_SEEN;
} else {
DEBUG("_nvp_READ: PREAD failed; Not fully read. "
"(returned %i)\n", result);
// assert(0); // TODO: this is for testing only
__sync_fetch_and_sub(nvf->offset, length - result);
__sync_fetch_and_sub(nvf->offset, (length*nmemb) - result);
nvf->file_stream_flags |= NVP_IO_EOF_SEEN;
}

NVP_UNLOCK_FD_RD(nvf, cpuid);

num_read++;
read_size += result;

result = result/length;
return result;
}
#endif
Expand Down Expand Up @@ -5252,7 +5306,7 @@ RETT_FWRITE _nvp_FWRITE(INTF_FWRITE)
result = _nvp_do_pwrite(fileno(fp),
buf,
length*nmemb,
__sync_fetch_and_add(nvf->offset, length),
__sync_fetch_and_add(nvf->offset, (length*nmemb)),
0,
cpuid,
nvf,
Expand All @@ -5265,6 +5319,7 @@ RETT_FWRITE _nvp_FWRITE(INTF_FWRITE)
nvf->node->maplength);

write_size += result;
result = result/length;
return result;
}
#endif
Expand Down Expand Up @@ -5761,8 +5816,8 @@ RETT_FTRUNC64 _nvp_FTRUNC64(INTF_FTRUNC64)
if (nvf->node->true_length >= LARGE_FILE_THRESHOLD)
nvf->node->is_large_file = 1;
START_TIMING(clear_mmap_tbl_t, clear_mmap_tbl_time);
clear_tbl_mmap_entry(tbl_app);
clear_tbl_mmap_entry(tbl_over);
clear_tbl_mmap_entry(tbl_app, NUM_APP_TBL_MMAP_ENTRIES);
clear_tbl_mmap_entry(tbl_over, NUM_OVER_TBL_MMAP_ENTRIES);
END_TIMING(clear_mmap_tbl_t, clear_mmap_tbl_time);

if (tbl_over != NULL)
Expand Down Expand Up @@ -6111,11 +6166,11 @@ RETT_UNLINK _nvp_UNLINK(INTF_UNLINK)
if (tbl_over != NULL) {
TBL_ENTRY_LOCK_WR(tbl_over);
}
clear_tbl_mmap_entry(tbl_app);
clear_tbl_mmap_entry(tbl_app, NUM_APP_TBL_MMAP_ENTRIES);

#if DATA_JOURNALING_ENABLED

clear_tbl_mmap_entry(tbl_over);
clear_tbl_mmap_entry(tbl_over, NUM_OVER_TBL_MMAP_ENTRIES);

#endif // DATA_JOURNALING_ENABLED

Expand Down
3 changes: 3 additions & 0 deletions splitfs/ledger.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#include "timers.h"

#define ENV_NV_FOP "NVP_NV_FOP"
#define NVP_IO_EOF_SEEN 0x0010
#define NVP_IO_ERR_SEEN 0x0020

/******************* Data Structures ********************/

Expand All @@ -33,6 +35,7 @@ struct NVFile
bool posix;
bool debug;
char padding[200];
int file_stream_flags;
};

struct free_dr_pool
Expand Down
21 changes: 19 additions & 2 deletions splitfs/nv_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ int execv_done;

#ifdef TRACE_FP_CALLS

#define ALLOPS_FINITEPARAMS_WPAREN (READ) (FREAD) (WRITE) (FWRITE) (FSEEK) (FTELL) (FTELLO) (CLOSE) (FCLOSE) (SEEK) (FTRUNC) (DUP) (DUP2) (FORK) (VFORK) (READV) (WRITEV) (PIPE) (SOCKETPAIR) OPS_FINITEPARAMS_64 (PREAD) (PWRITE) (FSYNC) (FDSYNC) (SOCKET) (ACCEPT) (UNLINK) (UNLINKAT)
#define ALLOPS_FINITEPARAMS_WPAREN (READ) (FREAD) (CLEARERR) (FEOF) (FERROR) (WRITE) (FWRITE) (FSEEK) (FTELL) (FTELLO) (CLOSE) (FCLOSE) (SEEK) (FTRUNC) (DUP) (DUP2) (FORK) (VFORK) (READV) (WRITEV) (PIPE) (SOCKETPAIR) OPS_FINITEPARAMS_64 (PREAD) (PWRITE) (FSYNC) (FDSYNC) (SOCKET) (ACCEPT) (UNLINK) (UNLINKAT)
//(POSIX_FALLOCATE) (POSIX_FALLOCATE64) (FALLOCATE) (STAT) (STAT64) (FSTAT) (FSTAT64) (LSTAT) (LSTAT64)
#define ALLOPS_WPAREN (OPEN) (OPENAT) (CREAT) (EXECVE) (EXECVP) (EXECV) (FOPEN) (FOPEN64) (IOCTL) (TRUNC) (MKNOD) (MKNODAT) ALLOPS_FINITEPARAMS_WPAREN
#define SHM_WPAREN (SHM_COPY)
Expand All @@ -106,7 +106,7 @@ int execv_done;
//(POSIX_FALLOCATE) (POSIX_FALLOCATE64) (FALLOCATE) (FSTAT) (FSTAT64)

#ifdef TRACE_FP_CALLS
#define FILEOPS_WITH_FP (FREAD) (FWRITE) (FSEEK) (FTELL) (FTELLO)
#define FILEOPS_WITH_FP (FREAD) (CLEARERR) (FEOF) (FERROR) (FWRITE) (FSEEK) (FTELL) (FTELLO)
#endif

//(ACCEPT)
Expand Down Expand Up @@ -203,6 +203,9 @@ struct Fileops_p* default_resolve_fileops(char* tree, char* name);
#define ALIAS_FOPEN fopen
#define ALIAS_FOPEN64 fopen64
#define ALIAS_FREAD fread
#define ALIAS_FEOF feof
#define ALIAS_FERROR ferror
#define ALIAS_CLEARERR clearerr
#define ALIAS_FWRITE fwrite
#define ALIAS_FSEEK fseek
#define ALIAS_FTELL ftell
Expand Down Expand Up @@ -287,6 +290,9 @@ struct Fileops_p* default_resolve_fileops(char* tree, char* name);

#define RETT_READ ssize_t
#define RETT_FREAD size_t
#define RETT_FEOF int
#define RETT_FERROR int
#define RETT_CLEARERR void
#define RETT_WRITE ssize_t
#define RETT_SEEK off_t
#define RETT_CLOSE int
Expand Down Expand Up @@ -355,6 +361,9 @@ struct Fileops_p* default_resolve_fileops(char* tree, char* name);
#define INTF_FOPEN const char* __restrict path, const char* __restrict mode
#define INTF_FOPEN64 const char* __restrict path, const char* __restrict mode
#define INTF_FREAD void* __restrict buf, size_t length, size_t nmemb, FILE* __restrict fp
#define INTF_CLEARERR FILE* fp
#define INTF_FEOF FILE* fp
#define INTF_FERROR FILE* fp
#define INTF_FWRITE const void* __restrict buf, size_t length, size_t nmemb, FILE* __restrict fp
#define INTF_FSEEK FILE* fp, long int offset, int whence
#define INTF_FTELL FILE* fp
Expand Down Expand Up @@ -430,6 +439,9 @@ struct Fileops_p* default_resolve_fileops(char* tree, char* name);
#define CALL_FOPEN path, mode
#define CALL_FOPEN64 path, mode
#define CALL_FREAD buf, length, nmemb, fp
#define CALL_FEOF fp
#define CALL_FERROR fp
#define CALL_CLEARERR fp
#define CALL_FWRITE buf, length, nmemb, fp
#define CALL_FSEEK fp, offset, whence
#define CALL_FTELL fp
Expand Down Expand Up @@ -505,6 +517,7 @@ struct Fileops_p* default_resolve_fileops(char* tree, char* name);
#define PFFS_FOPEN "%s, %s"
#define PFFS_FOPEN64 "%s, %s"
#define PFFS_FREAD "%p, %i, %i, %p"
#define PFFS_FOEF "%p"
#define PFFS_FWRITE "%p, %i, %i, %p"
#define PFFS_FSEEK "%p, %i, %i"
#define PFFS_FTELL "%p"
Expand Down Expand Up @@ -580,6 +593,10 @@ struct Fileops_p* default_resolve_fileops(char* tree, char* name);
#define STD_FOPEN __fopen
#define STD_FOPEN64 __fopen64
#define STD_FREAD __fread
#define STD_FREAD_UNLOCKED __fread_unlocked
#define STD_FEOF _IO_feof
#define STD_FERROR _IO_ferror
#define STD_CLEARERR _IO_CLEARERR
#define STD_FWRITE __fwrite
#define STD_FSEEK __fseek
#define STD_FTELL __ftell
Expand Down
4 changes: 2 additions & 2 deletions splitfs/tbl_mmaps.c
Original file line number Diff line number Diff line change
Expand Up @@ -1111,7 +1111,7 @@ int read_tbl_mmap_entry(struct NVNode *node,
return 0;
}

int clear_tbl_mmap_entry(struct NVTable_maps *tbl)
int clear_tbl_mmap_entry(struct NVTable_maps *tbl, int num_entries)
{
int i = 0;
size_t len = 0;
Expand All @@ -1121,7 +1121,7 @@ int clear_tbl_mmap_entry(struct NVTable_maps *tbl)
if (tbl->tbl_mmap_index > 0) {
deleted_size += tbl->tbl_mmaps[tbl->tbl_mmap_index-1].file_end_off;
DEBUG_FILE("%s: Total size deleted = %lu\n", __func__, deleted_size);
memset((void *)tbl->tbl_mmaps, 0, NUM_OVER_TBL_MMAP_ENTRIES*sizeof(struct table_mmaps));
memset((void *)tbl->tbl_mmaps, 0, num_entries*sizeof(struct table_mmaps));
tbl->tbl_mmap_index = 0;
}

Expand Down
2 changes: 1 addition & 1 deletion splitfs/tbl_mmaps.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ int read_tbl_mmap_entry(struct NVNode *node,
unsigned long *mmap_addr,
size_t *extent_length,
int check_append_entry);
int clear_tbl_mmap_entry(struct NVTable_maps *tbl);
int clear_tbl_mmap_entry(struct NVTable_maps *tbl, int size);

#endif

0 comments on commit cf787a1

Please sign in to comment.