Skip to content

Commit 91ca492

Browse files
Merge pull request #21 from OmSaran/cleanup2
Unlink the DR files during its cleanup
2 parents 69b29c4 + e0cd72c commit 91ca492

File tree

3 files changed

+171
-3
lines changed

3 files changed

+171
-3
lines changed

splitfs/fileops_hub.c

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,9 @@ RETT_EXECVE _hub_EXECVE(INTF_EXECVE);
254254
RETT_EXECVP ALIAS_EXECVP(INTF_EXECVP) WEAK_ALIAS("_hub_EXECVP");
255255
RETT_EXECVP _hub_EXECVP(INTF_EXECVP);
256256

257+
RETT_EXECV ALIAS_EXECV(INTF_EXECV) WEAK_ALIAS("_hub_EXECV");
258+
RETT_EXECV _hub_EXECV(INTF_EXECV);
259+
257260
RETT_MKNOD ALIAS_MKNOD(INTF_MKNOD) WEAK_ALIAS("_hub_MKNOD");
258261
RETT_MKNOD _hub_MKNOD(INTF_MKNOD);
259262

@@ -937,6 +940,58 @@ RETT_EXECVP _hub_EXECVP(INTF_EXECVP) {
937940
return result;
938941
}
939942

943+
RETT_EXECV _hub_EXECV(INTF_EXECV) {
944+
int pid = getpid();
945+
char exec_hub_filename[BUF_SIZE];
946+
947+
HUB_CHECK_RESOLVE_FILEOPS(_hub_, EXECV);
948+
949+
struct Fileops_p* op_to_use = NULL;
950+
int result = -1, exec_hub_fd = -1, i = 0;
951+
int hub_ops[1024];
952+
unsigned long offset_in_map = 0;
953+
954+
for (i = 0; i < 1024; i++) {
955+
if (_hub_fd_lookup[i] == NULL)
956+
hub_ops[i] = 0;
957+
if (_hub_fd_lookup[i] == _hub_fileops)
958+
hub_ops[i] = 1;
959+
if (_hub_fd_lookup[i] == _hub_managed_fileops)
960+
hub_ops[i] = 2;
961+
}
962+
963+
sprintf(exec_hub_filename, "exec-hub-%d", pid);
964+
exec_hub_fd = shm_open(exec_hub_filename, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
965+
if (exec_hub_fd == -1) {
966+
printf("%s: %s\n", __func__, strerror(errno));
967+
assert(0);
968+
}
969+
970+
int res = _hub_fileops->FTRUNC64(exec_hub_fd, (1024*1024));
971+
if (res == -1) {
972+
printf("%s: ftruncate failed. Err = %s\n", __func__, strerror(errno));
973+
assert(0);
974+
}
975+
976+
char *shm_area = mmap(NULL, 1024*1024, PROT_READ | PROT_WRITE, MAP_SHARED, exec_hub_fd, 0);
977+
if (shm_area == NULL) {
978+
printf("%s: mmap failed. Err = %s\n", __func__, strerror(errno));
979+
assert(0);
980+
}
981+
982+
if (memcpy(shm_area + offset_in_map, hub_ops, 1024 * sizeof(int)) == NULL) {
983+
printf("%s: memcpy of hub ops failed. Err = %s\n", __func__, strerror(errno));
984+
assert(0);
985+
}
986+
987+
offset_in_map += (1024 * sizeof(int));
988+
989+
op_to_use = _hub_managed_fileops;
990+
result = op_to_use->EXECV(CALL_EXECV);
991+
992+
return result;
993+
}
994+
940995
RETT_SHM_COPY _hub_SHM_COPY() {
941996

942997
HUB_CHECK_RESOLVE_FILEOPS(_hub_, SHM_COPY);

splitfs/fileops_nvp.c

Lines changed: 108 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1618,12 +1618,26 @@ void nvp_free_dr_mmaps()
16181618
unsigned long offset_in_page = 0;
16191619
struct free_dr_pool *temp_free_pool_of_dr_mmaps;
16201620
int i = 0;
1621+
ssize_t file_name_size = 0;
16211622

16221623
while( lfds711_queue_umm_dequeue(&qs, &qe) ) {
16231624
temp_free_pool_of_dr_mmaps = LFDS711_QUEUE_UMM_GET_VALUE_FROM_ELEMENT( *qe );
16241625
addr = temp_free_pool_of_dr_mmaps->start_addr;
16251626
munmap((void *)addr, DR_SIZE);
1627+
1628+
// Fetch the name of the file before closing it.
1629+
char fd_str[256];
1630+
char new_path[256];
1631+
sprintf(fd_str, "/proc/self/fd/%d", temp_free_pool_of_dr_mmaps->dr_fd);
1632+
file_name_size = readlink(fd_str, new_path, sizeof(new_path));
1633+
if (file_name_size == -1)
1634+
assert(0);
1635+
new_path[file_name_size] = '\0';
1636+
16261637
close(temp_free_pool_of_dr_mmaps->dr_fd);
1638+
1639+
// Remove the file.
1640+
_nvp_fileops->UNLINK(new_path);
16271641
__atomic_fetch_sub(&num_drs_left, 1, __ATOMIC_SEQ_CST);
16281642
}
16291643
lfds711_queue_umm_cleanup( &qs, NULL );
@@ -1634,7 +1648,20 @@ void nvp_free_dr_mmaps()
16341648
temp_free_pool_of_dr_mmaps = LFDS711_QUEUE_UMM_GET_VALUE_FROM_ELEMENT( *qe_over );
16351649
addr = temp_free_pool_of_dr_mmaps->start_addr;
16361650
munmap((void *)addr, DR_OVER_SIZE);
1651+
1652+
// Fetch the name of the file before closing it.
1653+
char fd_str[256];
1654+
char new_path[256];
1655+
sprintf(fd_str, "/proc/self/fd/%d", temp_free_pool_of_dr_mmaps->dr_fd);
1656+
file_name_size = readlink(fd_str, new_path, sizeof(new_path));
1657+
if (readlink(file_name_size == -1)
1658+
assert(0);
1659+
new_path[file_name_size] = '\0';
1660+
16371661
close(temp_free_pool_of_dr_mmaps->dr_fd);
1662+
1663+
// Remove the file.
1664+
_nvp_fileops->UNLINK(new_path);
16381665
__atomic_fetch_sub(&num_drs_left, 1, __ATOMIC_SEQ_CST);
16391666
}
16401667
lfds711_queue_umm_cleanup( &qs_over, NULL );
@@ -4805,6 +4832,7 @@ RETT_EXECVE _nvp_EXECVE(INTF_EXECVE) {
48054832
assert(0);
48064833
}
48074834

4835+
nvp_free_dr_mmaps();
48084836
offset_in_map += (1024 * sizeof(struct StackNode));
48094837

48104838
return _nvp_fileops->EXECVE(CALL_EXECVE);
@@ -4883,10 +4911,89 @@ RETT_EXECVP _nvp_EXECVP(INTF_EXECVP) {
48834911
}
48844912

48854913
offset_in_map += (1024 * sizeof(struct StackNode));
4886-
4914+
4915+
nvp_free_dr_mmaps();
48874916
return _nvp_fileops->EXECVP(CALL_EXECVP);
48884917
}
48894918

4919+
RETT_EXECV _nvp_EXECV(INTF_EXECV) {
4920+
4921+
int exec_ledger_fd = -1, i = 0;
4922+
unsigned long offset_in_map = 0;
4923+
int pid = getpid();
4924+
char exec_nvp_filename[BUF_SIZE];
4925+
4926+
for (i = 0; i < 1024; i++) {
4927+
if (_nvp_fd_lookup[i].offset != NULL)
4928+
execve_fd_passing[i] = *(_nvp_fd_lookup[i].offset);
4929+
else
4930+
execve_fd_passing[i] = 0;
4931+
}
4932+
4933+
for (i = 0; i < OPEN_MAX; i++) {
4934+
if (_nvp_fd_lookup[i].node != NULL && _nvp_fd_lookup[i].valid)
4935+
_nvp_FSYNC(_nvp_fd_lookup[i].fd);
4936+
}
4937+
4938+
sprintf(exec_nvp_filename, "exec-ledger-%d", pid);
4939+
exec_ledger_fd = shm_open(exec_nvp_filename, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
4940+
if (exec_ledger_fd == -1) {
4941+
printf("%s: %s\n", __func__, strerror(errno));
4942+
assert(0);
4943+
}
4944+
4945+
int res = _nvp_fileops->FTRUNC64(exec_ledger_fd, (10*1024*1024));
4946+
if (res == -1) {
4947+
printf("%s: ftruncate failed. Err = %s\n", __func__, strerror(errno));
4948+
assert(0);
4949+
}
4950+
4951+
char *shm_area = mmap(NULL, 10*1024*1024, PROT_READ | PROT_WRITE, MAP_SHARED, exec_ledger_fd, 0);
4952+
if (shm_area == NULL) {
4953+
printf("%s: mmap failed. Err = %s\n", __func__, strerror(errno));
4954+
assert(0);
4955+
}
4956+
4957+
if (memcpy(shm_area + offset_in_map, _nvp_fd_lookup, 1024 * sizeof(struct NVFile)) == NULL) {
4958+
printf("%s: memcpy of fd lookup failed. Err = %s\n", __func__, strerror(errno));
4959+
assert(0);
4960+
}
4961+
4962+
offset_in_map += (1024 * sizeof(struct NVFile));
4963+
4964+
if (memcpy(shm_area + offset_in_map, execve_fd_passing, 1024 * sizeof(int)) == NULL) {
4965+
printf("%s: memcpy of execve offset failed. Err = %s\n", __func__, strerror(errno));
4966+
assert(0);
4967+
}
4968+
4969+
offset_in_map += (1024 * sizeof(int));
4970+
4971+
4972+
if (memcpy(shm_area + offset_in_map, _nvp_node_lookup[0], 1024*sizeof(struct NVNode)) == NULL) {
4973+
printf("%s: memcpy of node lookup failed. Err = %s\n", __func__, strerror(errno));
4974+
assert(0);
4975+
}
4976+
4977+
offset_in_map += (1024*sizeof(struct NVNode));
4978+
4979+
if (memcpy(shm_area + offset_in_map, _nvp_ino_lookup, 1024 * sizeof(int)) == NULL) {
4980+
printf("%s: memcpy of ino lookup failed. Err = %s\n", __func__, strerror(errno));
4981+
assert(0);
4982+
}
4983+
4984+
offset_in_map += (1024 * sizeof(int));
4985+
4986+
if (memcpy(shm_area + offset_in_map, _nvp_free_node_list[0], 1024*sizeof(struct StackNode)) == NULL) {
4987+
printf("%s: memcpy of free node list failed. Err = %s\n", __func__, strerror(errno));
4988+
assert(0);
4989+
}
4990+
4991+
offset_in_map += (1024 * sizeof(struct StackNode));
4992+
4993+
nvp_free_dr_mmaps();
4994+
return _nvp_fileops->EXECV(CALL_EXECV);
4995+
}
4996+
48904997
#ifdef TRACE_FP_CALLS
48914998
RETT_FCLOSE _nvp_FCLOSE(INTF_FCLOSE)
48924999
{

splitfs/nv_common.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ int execv_done;
8787

8888
#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)
8989
//(POSIX_FALLOCATE) (POSIX_FALLOCATE64) (FALLOCATE) (STAT) (STAT64) (FSTAT) (FSTAT64) (LSTAT) (LSTAT64)
90-
#define ALLOPS_WPAREN (OPEN) (OPENAT) (CREAT) (EXECVE) (EXECVP) (FOPEN) (FOPEN64) (IOCTL) (TRUNC) (MKNOD) (MKNODAT) ALLOPS_FINITEPARAMS_WPAREN
90+
#define ALLOPS_WPAREN (OPEN) (OPENAT) (CREAT) (EXECVE) (EXECVP) (EXECV) (FOPEN) (FOPEN64) (IOCTL) (TRUNC) (MKNOD) (MKNODAT) ALLOPS_FINITEPARAMS_WPAREN
9191
#define SHM_WPAREN (SHM_COPY)
9292
// NOTE: clone is missing on purpose.(MMAP) (MUNMAP) (MSYNC) (CLONE) (MMAP64)
9393
#define METAOPS (MKDIR) (RENAME) (LINK) (SYMLINK) (RMDIR) (SYMLINKAT) (MKDIRAT)
@@ -96,7 +96,7 @@ int execv_done;
9696

9797
#define ALLOPS_FINITEPARAMS_WPAREN (READ) (WRITE) (CLOSE) (SEEK) (FTRUNC) (DUP) (DUP2) (FORK) (VFORK) (READV) (WRITEV) (PIPE) (SOCKETPAIR) OPS_FINITEPARAMS_64 (PREAD) (PWRITE) (FSYNC) (FDSYNC) (SOCKET) (ACCEPT) (UNLINK) (UNLINKAT)
9898
//(POSIX_FALLOCATE) (POSIX_FALLOCATE64) (FALLOCATE) (STAT) (STAT64) (FSTAT) (FSTAT64) (LSTAT) (LSTAT64)
99-
#define ALLOPS_WPAREN (OPEN) (OPENAT) (CREAT) (EXECVE) (EXECVP) (IOCTL) (TRUNC) (MKNOD) (MKNODAT) ALLOPS_FINITEPARAMS_WPAREN
99+
#define ALLOPS_WPAREN (OPEN) (OPENAT) (CREAT) (EXECVE) (EXECVP) (EXECV) (IOCTL) (TRUNC) (MKNOD) (MKNODAT) ALLOPS_FINITEPARAMS_WPAREN
100100
#define SHM_WPAREN (SHM_COPY)
101101
#define METAOPS (MKDIR) (RENAME) (LINK) (SYMLINK) (RMDIR) (SYMLINKAT) (MKDIRAT)
102102

@@ -195,6 +195,7 @@ struct Fileops_p* default_resolve_fileops(char* tree, char* name);
195195
#define ALIAS_CREAT creat
196196
#define ALIAS_EXECVE execve
197197
#define ALIAS_EXECVP execvp
198+
#define ALIAS_EXECV execv
198199
#define ALIAS_MKNOD __xmknod
199200
#define ALIAS_MKNODAT __xmknodat
200201

@@ -269,6 +270,7 @@ struct Fileops_p* default_resolve_fileops(char* tree, char* name);
269270
#define RETT_CREAT int
270271
#define RETT_EXECVE int
271272
#define RETT_EXECVP int
273+
#define RETT_EXECV int
272274
#define RETT_SHM_COPY void
273275
#define RETT_MKNOD int
274276
#define RETT_MKNODAT int
@@ -344,6 +346,7 @@ struct Fileops_p* default_resolve_fileops(char* tree, char* name);
344346
#define INTF_CREAT const char *path, mode_t mode
345347
#define INTF_EXECVE const char *filename, char *const argv[], char *const envp[]
346348
#define INTF_EXECVP const char *file, char *const argv[]
349+
#define INTF_EXECV const char *path, char *const argv[]
347350
#define INTF_SHM_COPY void
348351
#define INTF_MKNOD int ver, const char* path, mode_t mode, dev_t* dev
349352
#define INTF_MKNODAT int ver, int dirfd, const char* path, mode_t mode, dev_t* dev
@@ -419,6 +422,7 @@ struct Fileops_p* default_resolve_fileops(char* tree, char* name);
419422
#define CALL_CREAT path, mode
420423
#define CALL_EXECVE filename, argv, envp
421424
#define CALL_EXECVP file, argv
425+
#define CALL_EXECV path, argv
422426
#define CALL_MKNOD ver, path, mode, dev
423427
#define CALL_MKNODAT ver, dirfd, path, mode, dev
424428

@@ -492,6 +496,7 @@ struct Fileops_p* default_resolve_fileops(char* tree, char* name);
492496
#define PFFS_CREAT "%s, %i"
493497
#define PFFS_EXECVE "%s, %s, %s"
494498
#define PFFS_EXECVP "%s, %s"
499+
#define PFFS_EXECV "%s, %s"
495500
#define PFFS_SHM_COPY ""
496501
#define PFFS_MKNOD "%i, %s, %i, %p"
497502
#define PFFS_MKNODAT "%i, %i, %s, %i, %p"
@@ -567,6 +572,7 @@ struct Fileops_p* default_resolve_fileops(char* tree, char* name);
567572
#define STD_CREAT __creat
568573
#define STD_EXECVE __execve
569574
#define STD_EXECVP __execvp
575+
#define STD_EXECV __execv
570576
#define STD_MKNOD __xmknod
571577
#define STD_MKNODAT __xmknodat
572578

0 commit comments

Comments
 (0)