Skip to content

Commit dca98b3

Browse files
committed
Changes to support using posix test suite on SplitFS
1. Delegate the handling of STDIO files (stdin, stdout, stderr) to posix. 2. Use the originally initialised fileop handlers instead of setting it to NULL when a file is closed. 3. Use posix system call to truncate the SHM file in SplitFS' execvp implementation (similar to execve).  4. Use PID for the shared memory regions as mentioned in paper. 5. Honour file descriptors passing on exec without needing to compile with workload_tar flag.
1 parent 89f238c commit dca98b3

File tree

3 files changed

+45
-31
lines changed

3 files changed

+45
-31
lines changed

splitfs/fileops_hub.c

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -363,9 +363,6 @@ int hub_check_resolve_fileops(char* tree)
363363
{
364364
_hub_fd_lookup[i] = _hub_fileops;
365365
}
366-
_hub_fd_lookup[0] = _hub_managed_fileops;
367-
_hub_fd_lookup[1] = _hub_managed_fileops;
368-
_hub_fd_lookup[2] = _hub_managed_fileops;
369366

370367
return 0;
371368
}
@@ -815,6 +812,8 @@ RETT_OPENAT _hub_OPENAT(INTF_OPENAT)
815812
}
816813

817814
RETT_EXECVE _hub_EXECVE(INTF_EXECVE) {
815+
int pid = getpid();
816+
char buf[BUF_SIZE];
818817

819818
HUB_CHECK_RESOLVE_FILEOPS(_hub_, EXECVE);
820819

@@ -832,7 +831,8 @@ RETT_EXECVE _hub_EXECVE(INTF_EXECVE) {
832831
hub_ops[i] = 2;
833832
}
834833

835-
exec_hub_fd = shm_open("exec-hub", O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
834+
sprintf(buf, "exec-hub-%d", pid);
835+
exec_hub_fd = shm_open(buf, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
836836
if (exec_hub_fd == -1) {
837837
printf("%s: %s\n", __func__, strerror(errno));
838838
assert(0);
@@ -864,6 +864,8 @@ RETT_EXECVE _hub_EXECVE(INTF_EXECVE) {
864864
}
865865

866866
RETT_EXECVP _hub_EXECVP(INTF_EXECVP) {
867+
int pid = getpid();
868+
char buf[BUF_SIZE];
867869

868870
HUB_CHECK_RESOLVE_FILEOPS(_hub_, EXECVP);
869871

@@ -881,13 +883,14 @@ RETT_EXECVP _hub_EXECVP(INTF_EXECVP) {
881883
hub_ops[i] = 2;
882884
}
883885

884-
exec_hub_fd = shm_open("exec-hub", O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
886+
sprintf(buf, "exec-hub-%d", pid);
887+
exec_hub_fd = shm_open(buf, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
885888
if (exec_hub_fd == -1) {
886889
printf("%s: %s\n", __func__, strerror(errno));
887890
assert(0);
888891
}
889892

890-
int res = _hub_managed_fileops->FTRUNC64(exec_hub_fd, (1024*1024));
893+
int res = _hub_fileops->FTRUNC64(exec_hub_fd, (1024*1024));
891894
if (res == -1) {
892895
printf("%s: ftruncate failed. Err = %s\n", __func__, strerror(errno));
893896
assert(0);
@@ -918,8 +921,11 @@ RETT_SHM_COPY _hub_SHM_COPY() {
918921
int exec_hub_fd = -1, i = 0;
919922
int hub_ops[1024];
920923
unsigned long offset_in_map = 0;
924+
int pid = getpid();
925+
char buf[BUF_SIZE];
921926

922-
exec_hub_fd = shm_open("exec-hub", O_RDONLY, 0666);
927+
sprintf(buf, "exec-hub-%d", pid);
928+
exec_hub_fd = shm_open(buf, O_RDONLY, 0666);
923929
if (exec_hub_fd == -1) {
924930
MSG("%s: %s\n", __func__, strerror(errno));
925931
assert(0);
@@ -946,7 +952,7 @@ RETT_SHM_COPY _hub_SHM_COPY() {
946952
}
947953

948954
munmap(shm_area, 1024*1024);
949-
shm_unlink("exec-hub");
955+
shm_unlink(buf);
950956

951957
return _hub_managed_fileops->SHM_COPY();
952958
}
@@ -1101,16 +1107,18 @@ RETT_CLOSE _hub_CLOSE(INTF_CLOSE)
11011107
DEBUG("_hub_CLOSE is calling %s->CLOSE\n", _hub_fd_lookup[file]->name);
11021108

11031109
struct Fileops_p* temp = _hub_fd_lookup[file];
1104-
_hub_fd_lookup[file] = NULL;
1110+
1111+
// Restore it to the state similar to the initialised state.
1112+
_hub_fd_lookup[file] = _hub_fileops;
11051113
int result = temp->CLOSE(CALL_CLOSE);
11061114

11071115
if(result) {
11081116
DEBUG("call to %s->CLOSE failed: %s\n", _hub_fileops->name, strerror(errno));
1109-
return 0;
1117+
return result;
11101118
}
11111119

11121120
DEBUG_FILE("%s: Return = %d\n", __func__, result);
1113-
return 0;
1121+
return result;
11141122
}
11151123

11161124
#ifdef TRACE_FP_CALLS
@@ -1225,12 +1233,6 @@ RETT_DUP2 _hub_DUP2(INTF_DUP2)
12251233
else
12261234
{
12271235
DEBUG("DUP2 call completed successfully.\n");
1228-
1229-
if(result != fd2)
1230-
{
1231-
DEBUG("_hub_DUP2: result!=fd2 (%i != %i), so let's update the table...\n", result, fd2);
1232-
_hub_fd_lookup[fd2] = NULL;
1233-
}
12341236

12351237
DEBUG("Hub(dup2) managing new FD %i with same ops (\"%s\") as initial FD (%i)\n",
12361238
result, _hub_fd_lookup[file]->name, file);
@@ -1479,3 +1481,4 @@ RETT_CLONE _hub_CLONE(INTF_CLONE)
14791481
*/
14801482

14811483
// breaking the build
1484+

splitfs/fileops_nvp.c

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,8 +1021,11 @@ void _nvp_SHM_COPY() {
10211021
int exec_ledger_fd = -1;
10221022
int i,j;
10231023
unsigned long offset_in_map = 0;
1024-
1025-
exec_ledger_fd = shm_open("exec-ledger", O_RDONLY, 0666);
1024+
int pid = getpid();
1025+
char buf[BUF_SIZE];
1026+
1027+
sprintf(buf, "exec-ledger-%d", pid);
1028+
exec_ledger_fd = shm_open(buf, O_RDONLY, 0666);
10261029

10271030
if (exec_ledger_fd == -1) {
10281031
printf("%s: shm_open failed. Err = %s\n", __func__, strerror(errno));
@@ -1096,7 +1099,7 @@ void _nvp_SHM_COPY() {
10961099
}
10971100

10981101
munmap(shm_area, 10*1024*1024);
1099-
shm_unlink("exec-ledger");
1102+
shm_unlink(buf);
11001103
}
11011104

11021105
void _mm_cache_flush(void const* p) {
@@ -1244,13 +1247,11 @@ void _nvp_init2(void)
12441247
if (!_nvp_node_lookup[i])
12451248
assert(0);
12461249

1247-
#if WORKLOAD_TAR | WORKLOAD_GIT | WORKLOAD_RSYNC
12481250
_nvp_backup_roots[i] = (struct backupRoots*)calloc(OPEN_MAX,
12491251
sizeof(struct backupRoots));
12501252
if (!_nvp_backup_roots[i])
12511253
assert(0);
12521254

1253-
#endif // WORKLOAD_TAR
12541255

12551256
memset((void *)_nvp_node_lookup[i], 0, OPEN_MAX * sizeof(struct NVNode));
12561257
// Allocating and initializing all the dynamic structs inside struct NVNode
@@ -1276,11 +1277,9 @@ void _nvp_init2(void)
12761277
// Allocating and Initializing DR root of the node
12771278
memset((void *)&_nvp_node_lookup[i][j].dr_info, 0, sizeof(struct free_dr_pool));
12781279

1279-
#if WORKLOAD_TAR | WORKLOAD_GIT | WORKLOAD_RSYNC
12801280
_nvp_backup_roots[i][j].root = _nvp_node_lookup[i][j].root;
12811281
_nvp_backup_roots[i][j].merkle_root = _nvp_node_lookup[i][j].merkle_root;
12821282
_nvp_backup_roots[i][j].root_dirty_cache = _nvp_node_lookup[i][j].root_dirty_cache;
1283-
#endif // WORKLOAD_TAR
12841283

12851284
}
12861285
}
@@ -1555,15 +1554,15 @@ void _nvp_init2(void)
15551554
*/
15561555
atexit(nvp_exit_handler);
15571556

1558-
#if WORKLOAD_TAR | WORKLOAD_GIT | WORKLOAD_RSYNC
1557+
int pid = getpid();
1558+
char buf[BUF_SIZE];
15591559

1560-
if (access("/dev/shm/exec-ledger", F_OK ) != -1)
1560+
sprintf(buf, "/dev/shm/exec-ledger-%d", pid);
1561+
if (access(buf, F_OK ) != -1)
15611562
execv_done = 1;
15621563
else
15631564
execv_done = 0;
15641565

1565-
#endif // WORKLOAD_TAR
1566-
15671566
}
15681567

15691568
void nvp_transfer_to_free_dr_pool(struct NVNode *node)
@@ -4744,6 +4743,8 @@ RETT_EXECVE _nvp_EXECVE(INTF_EXECVE) {
47444743

47454744
int exec_ledger_fd = -1, i = 0;
47464745
unsigned long offset_in_map = 0;
4746+
int pid = getpid();
4747+
char buf[BUF_SIZE];
47474748

47484749
for (i = 0; i < 1024; i++) {
47494750
if (_nvp_fd_lookup[i].offset != NULL)
@@ -4752,7 +4753,8 @@ RETT_EXECVE _nvp_EXECVE(INTF_EXECVE) {
47524753
execve_fd_passing[i] = 0;
47534754
}
47544755

4755-
exec_ledger_fd = shm_open("exec-ledger", O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
4756+
sprintf(buf, "exec-ledger-%d", pid);
4757+
exec_ledger_fd = shm_open(buf, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
47564758
if (exec_ledger_fd == -1) {
47574759
printf("%s: %s\n", __func__, strerror(errno));
47584760
assert(0);
@@ -4813,6 +4815,8 @@ RETT_EXECVP _nvp_EXECVP(INTF_EXECVP) {
48134815

48144816
int exec_ledger_fd = -1, i = 0;
48154817
unsigned long offset_in_map = 0;
4818+
int pid = getpid();
4819+
char buf[BUF_SIZE];
48164820

48174821
for (i = 0; i < 1024; i++) {
48184822
if (_nvp_fd_lookup[i].offset != NULL)
@@ -4825,8 +4829,9 @@ RETT_EXECVP _nvp_EXECVP(INTF_EXECVP) {
48254829
if (_nvp_fd_lookup[i].node != NULL && _nvp_fd_lookup[i].valid)
48264830
_nvp_FSYNC(_nvp_fd_lookup[i].fd);
48274831
}
4828-
4829-
exec_ledger_fd = shm_open("exec-ledger", O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
4832+
4833+
sprintf(buf, "exec-ledger-%d", pid);
4834+
exec_ledger_fd = shm_open(buf, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
48304835
if (exec_ledger_fd == -1) {
48314836
printf("%s: %s\n", __func__, strerror(errno));
48324837
assert(0);
@@ -5911,6 +5916,9 @@ RETT_DUP2 _nvp_DUP2(INTF_DUP2)
59115916
nvf2->node = nvf->node;
59125917
nvf2->valid = nvf->valid;
59135918
nvf2->posix = nvf->posix;
5919+
// Increment the refernce count as this file
5920+
// descriptor is pointing to the same NVFNode
5921+
nvf2->node->reference++;
59145922

59155923
SANITYCHECK(nvf2->node != NULL);
59165924
SANITYCHECK(nvf2->valid);
@@ -6541,3 +6549,4 @@ RETT_FALLOCATE _nvp_FALLOCATE(INTF_FALLOCATE)
65416549
return result;
65426550
}
65436551
*/
6552+

splitfs/nv_common.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
#include "boost/preprocessor/seq/for_each.hpp"
3333
//#include "boost/preprocessor/cat.hpp"
3434

35+
#define BUF_SIZE 40
36+
3537
#define MIN(X,Y) (((X)<(Y))?(X):(Y))
3638
#define MAX(X,Y) (((X)>(Y))?(X):(Y))
3739

0 commit comments

Comments
 (0)