mirror of
https://github.com/drasko/codezero.git
synced 2026-01-12 10:53:16 +01:00
Fixed minor faults during close path.
FIXME: write/close/open/read sequence does not read the initially written data. Investigate.
This commit is contained in:
@@ -93,7 +93,8 @@ struct vnode *vfs_create(struct tcb *task, struct pathdata *pdata,
|
||||
return newnode;
|
||||
}
|
||||
|
||||
/* Pager notifies vfs about a closed file descriptor.
|
||||
/*
|
||||
* Pager notifies vfs about a closed file descriptor.
|
||||
*
|
||||
* FIXME: fsync + close could be done under a single "close" ipc
|
||||
* from pager. Currently there are 2 ipcs: 1 fsync + 1 fd close.
|
||||
@@ -103,9 +104,10 @@ int pager_sys_close(l4id_t sender, l4id_t closer, int fd)
|
||||
struct tcb *task;
|
||||
int err;
|
||||
|
||||
BUG_ON(!(task = find_task(sender)));
|
||||
BUG_ON(!(task = find_task(closer)));
|
||||
|
||||
if ((err = id_del(task->fdpool, task->fd[fd])) < 0) {
|
||||
printf("Deleting fd: %d\n", fd);
|
||||
if ((err = id_del(task->fdpool, fd)) < 0) {
|
||||
printf("%s: Error releasing fd identifier.\n",
|
||||
__FUNCTION__);
|
||||
l4_ipc_return(err);
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
#define VMA_ANONYMOUS (1 << 5)
|
||||
/* Private copy of a file */
|
||||
#define VMA_PRIVATE (1 << 6)
|
||||
/* Copy-on-write semantics */
|
||||
/* For wired pages */
|
||||
#define VMA_FIXED (1 << 7)
|
||||
/* Set when the page is dirty in cache but not written to disk */
|
||||
#define VM_DIRTY (1 << 8)
|
||||
|
||||
@@ -146,7 +146,7 @@ int vfs_receive_sys_open(l4id_t sender, l4id_t opener, int fd,
|
||||
|
||||
/*
|
||||
* Inserts the page to vmfile's list in order of page frame offset.
|
||||
* We use an ordered list instead of a radix or btree for now.
|
||||
* We use an ordered list instead of a better data structure for now.
|
||||
*/
|
||||
int insert_page_olist(struct page *this, struct vm_object *vmo)
|
||||
{
|
||||
@@ -321,7 +321,7 @@ int flush_file_pages(struct vm_file *f)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Given a task and fd syncs all IO on it */
|
||||
/* Given a task and fd, syncs all IO on it */
|
||||
int fsync_common(l4id_t sender, int fd)
|
||||
{
|
||||
struct vm_file *f;
|
||||
@@ -352,6 +352,8 @@ int fd_close(l4id_t sender, int fd)
|
||||
/* Get the task */
|
||||
BUG_ON(!(task = find_task(sender)));
|
||||
|
||||
printf("%s: Closing fd: %d on task %d\n", __FUNCTION__,
|
||||
fd, task->tid);
|
||||
if ((err = vfs_close(task->tid, fd)) < 0)
|
||||
return err;
|
||||
|
||||
@@ -364,16 +366,21 @@ int fd_close(l4id_t sender, int fd)
|
||||
|
||||
int sys_close(l4id_t sender, int fd)
|
||||
{
|
||||
int err;
|
||||
int retval;
|
||||
|
||||
/* Sync the file and update stats */
|
||||
if ((err = fsync_common(sender, fd)) < 0) {
|
||||
l4_ipc_return(err);
|
||||
if ((retval = fsync_common(sender, fd)) < 0) {
|
||||
l4_ipc_return(retval);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Close the file descriptor. */
|
||||
return fd_close(sender, fd);
|
||||
retval = fd_close(sender, fd);
|
||||
printf("%s: Closed fd %d. Returning %d\n",
|
||||
__TASKNAME__, fd, retval);
|
||||
l4_ipc_return(retval);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sys_fsync(l4id_t sender, int fd)
|
||||
|
||||
@@ -7,5 +7,6 @@ int shmtest(void);
|
||||
int mmaptest(void);
|
||||
int dirtest(void);
|
||||
int fileio(void);
|
||||
int fileio2(void);
|
||||
|
||||
#endif /* __TEST0_TESTS_H__ */
|
||||
|
||||
@@ -28,7 +28,18 @@ void main(void)
|
||||
wait_pager(0);
|
||||
|
||||
dirtest();
|
||||
fileio();
|
||||
printf("File IO test 1:\n");
|
||||
if (fileio() == 0)
|
||||
printf("-- PASSED --\n");
|
||||
else
|
||||
printf("-- FAILED --\n");
|
||||
|
||||
printf("File IO test 2:\n");
|
||||
if (fileio2() == 0)
|
||||
printf("-- PASSED --\n");
|
||||
else
|
||||
printf("-- FAILED --\n");
|
||||
|
||||
while (1)
|
||||
wait_pager(0);
|
||||
#if 0
|
||||
|
||||
@@ -7,6 +7,63 @@
|
||||
#include <string.h>
|
||||
#include <tests.h>
|
||||
|
||||
int fileio2(void)
|
||||
{
|
||||
int fd;
|
||||
ssize_t cnt;
|
||||
int err;
|
||||
char buf[128];
|
||||
off_t offset;
|
||||
|
||||
char *str = "I WROTE TO THIS FILE\n";
|
||||
|
||||
if ((fd = open("/home/bahadir/newfile2.txt", O_RDWR | O_CREAT | O_TRUNC, S_IRWXU)) < 0) {
|
||||
perror("OPEN");
|
||||
return -1;
|
||||
}
|
||||
printf("Created newfile.txt\n");
|
||||
|
||||
printf("%s: write.\n", __TASKNAME__);
|
||||
if ((int)(cnt = write(fd, str, strlen(str))) < 0) {
|
||||
perror("WRITE");
|
||||
return -1;
|
||||
}
|
||||
printf("%s: close.\n", __TASKNAME__);
|
||||
if ((err = close(fd)) < 0) {
|
||||
printf("Close failed.\n");
|
||||
perror("CLOSE");
|
||||
return -1;
|
||||
}
|
||||
printf("%s: re-open.\n", __TASKNAME__);
|
||||
if ((fd = open("/home/bahadir/newfile2.txt", O_RDWR, S_IRWXU)) < 0) {
|
||||
perror("OPEN");
|
||||
return -1;
|
||||
}
|
||||
|
||||
printf("%s: lseek.\n", __TASKNAME__);
|
||||
if ((int)(offset = lseek(fd, 0, SEEK_SET)) < 0) {
|
||||
perror("LSEEK");
|
||||
return -1;
|
||||
}
|
||||
printf("%s: read.\n", __TASKNAME__);
|
||||
if ((int)(cnt = read(fd, buf, strlen(str))) < 0) {
|
||||
perror("READ");
|
||||
return -1;
|
||||
}
|
||||
|
||||
printf("Read: %d bytes from file.\n", cnt);
|
||||
if (cnt) {
|
||||
printf("Read string: %s\n", buf);
|
||||
}
|
||||
|
||||
if ((err = close(fd)) < 0) {
|
||||
perror("CLOSE");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int fileio(void)
|
||||
{
|
||||
int fd;
|
||||
@@ -56,9 +113,18 @@ int fileio(void)
|
||||
#if defined(HOST_TESTS)
|
||||
int main(void)
|
||||
{
|
||||
printf("File IO test:\n");
|
||||
printf("File IO test 1:\n");
|
||||
if (fileio() == 0)
|
||||
printf("-- PASSED --\n");
|
||||
else
|
||||
printf("-- FAILED --\n");
|
||||
|
||||
printf("File IO test 2:\n");
|
||||
if (fileio2() == 0)
|
||||
printf("-- PASSED --\n");
|
||||
else
|
||||
printf("-- FAILED --\n");
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user