summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUlf Lilleengen <lulf@carrot.studby.ntnu.no>2008-08-16 10:15:25 +0200
committerUlf Lilleengen <lulf@carrot.studby.ntnu.no>2008-08-16 10:15:25 +0200
commit938edcd71b163255959b363a5a2b1e590da9619d (patch)
tree0f914061dadbc95b938b5f9e9ea441c04f51e29c
parent1d2495b60e05fd2072ef1e6ea5a09ec87ed304fc (diff)
- Use the fi->fh filehandle to store the file descriptor, so we don't need to
run an sql query each time we want to read a block from the file. This should improve performance significantly. Currently, it's not done for config file reading, but if not for performance reasons, we should perhaps change it to be "correct" in the file system way of doing things.
-rwxr-xr-xsrc/mfs_vnops.c26
1 files changed, 11 insertions, 15 deletions
diff --git a/src/mfs_vnops.c b/src/mfs_vnops.c
index bfb4fe1..55907d9 100755
--- a/src/mfs_vnops.c
+++ b/src/mfs_vnops.c
@@ -154,8 +154,7 @@ static int mfs_open (const char *path, struct fuse_file_info *fi)
return (-ENOENT);
if (fd.fd < 0)
return (-EIO);
- close(fd.fd);
-
+ fi->fh = fd.fd;
return (0);
/*
@@ -171,9 +170,7 @@ static int mfs_open (const char *path, struct fuse_file_info *fi)
static int mfs_read (const char *path, char *buf, size_t size, off_t offset,
struct fuse_file_info *fi)
{
- struct file_data fd;
- fd.fd = -1;
- fd.found = 0;
+ int fd;
size_t bytes;
DEBUG("read: path(%s) offset(%d) size(%d)\n", path, (int)offset,
@@ -188,17 +185,10 @@ static int mfs_read (const char *path, char *buf, size_t size, off_t offset,
return (bytes);
}
- int status = mfs_file_data_for_path(path, &fd);
- if (status != 0)
- return (status);
-
- if (!fd.found)
- return (-ENOENT);
- if (fd.fd < 0)
+ fd = fi->fh;
+ if (fd < 0)
return (-EIO);
- lseek(fd.fd, offset, SEEK_CUR);
- bytes = read(fd.fd, buf, size);
- close(fd.fd);
+ bytes = read(fd, buf, size);
return (bytes);
/*
@@ -277,6 +267,8 @@ static int mfs_fsync(const char *path, int datasync,
static int mfs_release(const char *path, struct fuse_file_info *fi)
{
+ int fd;
+
DEBUG("release %s\n", path);
if (strcmp(path, "/.config") == 0) {
@@ -284,6 +276,10 @@ static int mfs_release(const char *path, struct fuse_file_info *fi)
mfs_reload_config();
}
+ fd = fi->fh;
+ if (fd >= 0)
+ close(fd);
+
return (0);
}