Skip to content

Commit cf787a1

Browse files
committed
1. Implement ferror, feof and clearerr libc calls. This includes adding 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.
1 parent 411933a commit cf787a1

File tree

5 files changed

+91
-16
lines changed

5 files changed

+91
-16
lines changed

splitfs/fileops_nvp.c

Lines changed: 66 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2045,11 +2045,11 @@ struct NVNode * nvp_get_node(const char *path, struct stat *file_st, int result)
20452045
node->is_large_file = 0;
20462046
node->dr_mem_used = 0;
20472047
if (node->true_length == 0) {
2048-
clear_tbl_mmap_entry(&_nvp_tbl_mmaps[file_st->st_ino % APPEND_TBL_MAX]);
2048+
clear_tbl_mmap_entry(&_nvp_tbl_mmaps[file_st->st_ino % APPEND_TBL_MAX], NUM_APP_TBL_MMAP_ENTRIES);
20492049

20502050
#if DATA_JOURNALING_ENABLED
20512051

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

20542054
#endif // DATA_JOURNALING_ENABLED
20552055

@@ -4994,6 +4994,55 @@ RETT_EXECV _nvp_EXECV(INTF_EXECV) {
49944994
return _nvp_fileops->EXECV(CALL_EXECV);
49954995
}
49964996

4997+
#ifdef TRACE_FP_CALLS
4998+
RETT_FEOF _nvp_FEOF(INTF_FEOF)
4999+
{
5000+
CHECK_RESOLVE_FILEOPS(_nvp_);
5001+
RETT_FEOF result;
5002+
5003+
struct NVFile* nvf = &_nvp_fd_lookup[fileno(fp)];
5004+
5005+
NVP_LOCK_NODE_WR(nvf);
5006+
NVP_LOCK_FD_WR(nvf);
5007+
result = (nvf->file_stream_flags & NVP_IO_EOF_SEEN) > 0;
5008+
NVP_UNLOCK_NODE_WR(nvf);
5009+
NVP_UNLOCK_FD_WR(nvf);
5010+
return result;
5011+
}
5012+
#endif
5013+
5014+
#ifdef TRACE_FP_CALLS
5015+
RETT_FERROR _nvp_FERROR(INTF_FERROR)
5016+
{
5017+
CHECK_RESOLVE_FILEOPS(_nvp_);
5018+
RETT_FERROR result;
5019+
5020+
struct NVFile* nvf = &_nvp_fd_lookup[fileno(fp)];
5021+
NVP_LOCK_NODE_WR(nvf);
5022+
NVP_LOCK_FD_WR(nvf);
5023+
result = (nvf->file_stream_flags & NVP_IO_ERR_SEEN) > 0;
5024+
NVP_UNLOCK_NODE_WR(nvf);
5025+
NVP_UNLOCK_FD_WR(nvf);
5026+
return result;
5027+
}
5028+
#endif
5029+
5030+
#ifdef TRACE_FP_CALLS
5031+
RETT_CLEARERR _nvp_CLEARERR(INTF_CLEARERR)
5032+
{
5033+
CHECK_RESOLVE_FILEOPS(_nvp_);
5034+
int fd = -1;
5035+
5036+
struct NVFile* nvf = &_nvp_fd_lookup[fileno(fp)];
5037+
5038+
NVP_LOCK_NODE_WR(nvf);
5039+
NVP_LOCK_FD_WR(nvf);
5040+
nvf->file_stream_flags &= ~(NVP_IO_ERR_SEEN | NVP_IO_EOF_SEEN);
5041+
NVP_UNLOCK_NODE_WR(nvf);
5042+
NVP_UNLOCK_FD_WR(nvf);
5043+
}
5044+
#endif
5045+
49975046
#ifdef TRACE_FP_CALLS
49985047
RETT_FCLOSE _nvp_FCLOSE(INTF_FCLOSE)
49995048
{
@@ -5064,7 +5113,7 @@ RETT_FREAD _nvp_FREAD(INTF_FREAD)
50645113
result = _nvp_do_pread(fileno(fp),
50655114
buf,
50665115
length*nmemb,
5067-
__sync_fetch_and_add(nvf->offset, length),
5116+
__sync_fetch_and_add(nvf->offset, (length*nmemb)),
50685117
0,
50695118
cpuid,
50705119
nvf,
@@ -5081,19 +5130,24 @@ RETT_FREAD _nvp_FREAD(INTF_FREAD)
50815130
DEBUG("_nvp_READ: PREAD failed; not changing offset. "
50825131
"(returned %i)\n", result);
50835132
//assert(0); // TODO: this is for testing only
5084-
__sync_fetch_and_sub(nvf->offset, length);
5133+
__sync_fetch_and_sub(nvf->offset, (length*nmemb));
5134+
if (result < 0)
5135+
nvf->file_stream_flags |= NVP_IO_ERR_SEEN;
5136+
else
5137+
nvf->file_stream_flags |= NVP_IO_EOF_SEEN;
50855138
} else {
50865139
DEBUG("_nvp_READ: PREAD failed; Not fully read. "
50875140
"(returned %i)\n", result);
50885141
// assert(0); // TODO: this is for testing only
5089-
__sync_fetch_and_sub(nvf->offset, length - result);
5142+
__sync_fetch_and_sub(nvf->offset, (length*nmemb) - result);
5143+
nvf->file_stream_flags |= NVP_IO_EOF_SEEN;
50905144
}
50915145

50925146
NVP_UNLOCK_FD_RD(nvf, cpuid);
50935147

50945148
num_read++;
50955149
read_size += result;
5096-
5150+
result = result/length;
50975151
return result;
50985152
}
50995153
#endif
@@ -5252,7 +5306,7 @@ RETT_FWRITE _nvp_FWRITE(INTF_FWRITE)
52525306
result = _nvp_do_pwrite(fileno(fp),
52535307
buf,
52545308
length*nmemb,
5255-
__sync_fetch_and_add(nvf->offset, length),
5309+
__sync_fetch_and_add(nvf->offset, (length*nmemb)),
52565310
0,
52575311
cpuid,
52585312
nvf,
@@ -5265,6 +5319,7 @@ RETT_FWRITE _nvp_FWRITE(INTF_FWRITE)
52655319
nvf->node->maplength);
52665320

52675321
write_size += result;
5322+
result = result/length;
52685323
return result;
52695324
}
52705325
#endif
@@ -5761,8 +5816,8 @@ RETT_FTRUNC64 _nvp_FTRUNC64(INTF_FTRUNC64)
57615816
if (nvf->node->true_length >= LARGE_FILE_THRESHOLD)
57625817
nvf->node->is_large_file = 1;
57635818
START_TIMING(clear_mmap_tbl_t, clear_mmap_tbl_time);
5764-
clear_tbl_mmap_entry(tbl_app);
5765-
clear_tbl_mmap_entry(tbl_over);
5819+
clear_tbl_mmap_entry(tbl_app, NUM_APP_TBL_MMAP_ENTRIES);
5820+
clear_tbl_mmap_entry(tbl_over, NUM_OVER_TBL_MMAP_ENTRIES);
57665821
END_TIMING(clear_mmap_tbl_t, clear_mmap_tbl_time);
57675822

57685823
if (tbl_over != NULL)
@@ -6111,11 +6166,11 @@ RETT_UNLINK _nvp_UNLINK(INTF_UNLINK)
61116166
if (tbl_over != NULL) {
61126167
TBL_ENTRY_LOCK_WR(tbl_over);
61136168
}
6114-
clear_tbl_mmap_entry(tbl_app);
6169+
clear_tbl_mmap_entry(tbl_app, NUM_APP_TBL_MMAP_ENTRIES);
61156170

61166171
#if DATA_JOURNALING_ENABLED
61176172

6118-
clear_tbl_mmap_entry(tbl_over);
6173+
clear_tbl_mmap_entry(tbl_over, NUM_OVER_TBL_MMAP_ENTRIES);
61196174

61206175
#endif // DATA_JOURNALING_ENABLED
61216176

splitfs/ledger.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
#include "timers.h"
1313

1414
#define ENV_NV_FOP "NVP_NV_FOP"
15+
#define NVP_IO_EOF_SEEN 0x0010
16+
#define NVP_IO_ERR_SEEN 0x0020
1517

1618
/******************* Data Structures ********************/
1719

@@ -33,6 +35,7 @@ struct NVFile
3335
bool posix;
3436
bool debug;
3537
char padding[200];
38+
int file_stream_flags;
3639
};
3740

3841
struct free_dr_pool

splitfs/nv_common.h

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ int execv_done;
8585

8686
#ifdef TRACE_FP_CALLS
8787

88-
#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)
88+
#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)
8989
//(POSIX_FALLOCATE) (POSIX_FALLOCATE64) (FALLOCATE) (STAT) (STAT64) (FSTAT) (FSTAT64) (LSTAT) (LSTAT64)
9090
#define ALLOPS_WPAREN (OPEN) (OPENAT) (CREAT) (EXECVE) (EXECVP) (EXECV) (FOPEN) (FOPEN64) (IOCTL) (TRUNC) (MKNOD) (MKNODAT) ALLOPS_FINITEPARAMS_WPAREN
9191
#define SHM_WPAREN (SHM_COPY)
@@ -106,7 +106,7 @@ int execv_done;
106106
//(POSIX_FALLOCATE) (POSIX_FALLOCATE64) (FALLOCATE) (FSTAT) (FSTAT64)
107107

108108
#ifdef TRACE_FP_CALLS
109-
#define FILEOPS_WITH_FP (FREAD) (FWRITE) (FSEEK) (FTELL) (FTELLO)
109+
#define FILEOPS_WITH_FP (FREAD) (CLEARERR) (FEOF) (FERROR) (FWRITE) (FSEEK) (FTELL) (FTELLO)
110110
#endif
111111

112112
//(ACCEPT)
@@ -203,6 +203,9 @@ struct Fileops_p* default_resolve_fileops(char* tree, char* name);
203203
#define ALIAS_FOPEN fopen
204204
#define ALIAS_FOPEN64 fopen64
205205
#define ALIAS_FREAD fread
206+
#define ALIAS_FEOF feof
207+
#define ALIAS_FERROR ferror
208+
#define ALIAS_CLEARERR clearerr
206209
#define ALIAS_FWRITE fwrite
207210
#define ALIAS_FSEEK fseek
208211
#define ALIAS_FTELL ftell
@@ -287,6 +290,9 @@ struct Fileops_p* default_resolve_fileops(char* tree, char* name);
287290

288291
#define RETT_READ ssize_t
289292
#define RETT_FREAD size_t
293+
#define RETT_FEOF int
294+
#define RETT_FERROR int
295+
#define RETT_CLEARERR void
290296
#define RETT_WRITE ssize_t
291297
#define RETT_SEEK off_t
292298
#define RETT_CLOSE int
@@ -355,6 +361,9 @@ struct Fileops_p* default_resolve_fileops(char* tree, char* name);
355361
#define INTF_FOPEN const char* __restrict path, const char* __restrict mode
356362
#define INTF_FOPEN64 const char* __restrict path, const char* __restrict mode
357363
#define INTF_FREAD void* __restrict buf, size_t length, size_t nmemb, FILE* __restrict fp
364+
#define INTF_CLEARERR FILE* fp
365+
#define INTF_FEOF FILE* fp
366+
#define INTF_FERROR FILE* fp
358367
#define INTF_FWRITE const void* __restrict buf, size_t length, size_t nmemb, FILE* __restrict fp
359368
#define INTF_FSEEK FILE* fp, long int offset, int whence
360369
#define INTF_FTELL FILE* fp
@@ -430,6 +439,9 @@ struct Fileops_p* default_resolve_fileops(char* tree, char* name);
430439
#define CALL_FOPEN path, mode
431440
#define CALL_FOPEN64 path, mode
432441
#define CALL_FREAD buf, length, nmemb, fp
442+
#define CALL_FEOF fp
443+
#define CALL_FERROR fp
444+
#define CALL_CLEARERR fp
433445
#define CALL_FWRITE buf, length, nmemb, fp
434446
#define CALL_FSEEK fp, offset, whence
435447
#define CALL_FTELL fp
@@ -505,6 +517,7 @@ struct Fileops_p* default_resolve_fileops(char* tree, char* name);
505517
#define PFFS_FOPEN "%s, %s"
506518
#define PFFS_FOPEN64 "%s, %s"
507519
#define PFFS_FREAD "%p, %i, %i, %p"
520+
#define PFFS_FOEF "%p"
508521
#define PFFS_FWRITE "%p, %i, %i, %p"
509522
#define PFFS_FSEEK "%p, %i, %i"
510523
#define PFFS_FTELL "%p"
@@ -580,6 +593,10 @@ struct Fileops_p* default_resolve_fileops(char* tree, char* name);
580593
#define STD_FOPEN __fopen
581594
#define STD_FOPEN64 __fopen64
582595
#define STD_FREAD __fread
596+
#define STD_FREAD_UNLOCKED __fread_unlocked
597+
#define STD_FEOF _IO_feof
598+
#define STD_FERROR _IO_ferror
599+
#define STD_CLEARERR _IO_CLEARERR
583600
#define STD_FWRITE __fwrite
584601
#define STD_FSEEK __fseek
585602
#define STD_FTELL __ftell

splitfs/tbl_mmaps.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,7 +1111,7 @@ int read_tbl_mmap_entry(struct NVNode *node,
11111111
return 0;
11121112
}
11131113

1114-
int clear_tbl_mmap_entry(struct NVTable_maps *tbl)
1114+
int clear_tbl_mmap_entry(struct NVTable_maps *tbl, int num_entries)
11151115
{
11161116
int i = 0;
11171117
size_t len = 0;
@@ -1121,7 +1121,7 @@ int clear_tbl_mmap_entry(struct NVTable_maps *tbl)
11211121
if (tbl->tbl_mmap_index > 0) {
11221122
deleted_size += tbl->tbl_mmaps[tbl->tbl_mmap_index-1].file_end_off;
11231123
DEBUG_FILE("%s: Total size deleted = %lu\n", __func__, deleted_size);
1124-
memset((void *)tbl->tbl_mmaps, 0, NUM_OVER_TBL_MMAP_ENTRIES*sizeof(struct table_mmaps));
1124+
memset((void *)tbl->tbl_mmaps, 0, num_entries*sizeof(struct table_mmaps));
11251125
tbl->tbl_mmap_index = 0;
11261126
}
11271127

splitfs/tbl_mmaps.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@ int read_tbl_mmap_entry(struct NVNode *node,
2626
unsigned long *mmap_addr,
2727
size_t *extent_length,
2828
int check_append_entry);
29-
int clear_tbl_mmap_entry(struct NVTable_maps *tbl);
29+
int clear_tbl_mmap_entry(struct NVTable_maps *tbl, int size);
3030

3131
#endif

0 commit comments

Comments
 (0)