]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
Improve memory mapping.
authorAndre Noll <maan@systemlinux.org>
Mon, 12 Jan 2009 18:57:01 +0000 (19:57 +0100)
committerAndre Noll <maan@systemlinux.org>
Mon, 12 Jan 2009 18:57:01 +0000 (19:57 +0100)
para_mmap(): Do not exit on errors. Fix the only caller in vss.c
accordingly.

mmap_full_file(): Use para_mmap().

error.h
fd.c
fd.h
vss.c

diff --git a/error.h b/error.h
index 897aeb282299cd11bfc0058179bddd2e4e95db82..2a8a6b5a182b1f47713f978791db9e4433068e78 100644 (file)
--- a/error.h
+++ b/error.h
@@ -358,8 +358,6 @@ extern const char **para_errlist[];
 
 #define FD_ERRORS \
        PARA_ERROR(FGETS, "fgets error"), \
 
 #define FD_ERRORS \
        PARA_ERROR(FGETS, "fgets error"), \
-       PARA_ERROR(EMPTY, "file empty"), \
-       PARA_ERROR(MMAP, "mmap error"), \
 
 
 #define WRITE_ERRORS \
 
 
 #define WRITE_ERRORS \
diff --git a/fd.c b/fd.c
index 6d32e93eeca6d205725390ea59b8e97fdd09b376..8759d5099200c4f6c1b6c31e84b66da3372b5540 100644 (file)
--- a/fd.c
+++ b/fd.c
@@ -225,19 +225,26 @@ again:
  * \param flags Exactly one of MAP_SHARED and MAP_PRIVATE.
  * \param fd The file to mmap from.
  * \param offset Mmap start.
  * \param flags Exactly one of MAP_SHARED and MAP_PRIVATE.
  * \param fd The file to mmap from.
  * \param offset Mmap start.
+ * \param map Result pointer.
  *
  *
- * \return This function either returns a valid pointer to the mapped area
- * or calls exit() on errors.
+ * \return Standard.
+ *
+ * \sa mmap(2).
  */
  */
-void *para_mmap(size_t length, int prot, int flags, int fd, off_t offset)
+int para_mmap(size_t length, int prot, int flags, int fd, off_t offset,
+               void *map)
 {
 {
-       void *ret = mmap(NULL, length, prot, flags, fd, offset);
-       if (ret != MAP_FAILED)
-               return ret;
-       PARA_EMERG_LOG("mmap failed: %s\n", strerror(errno));
-       PARA_EMERG_LOG("length: %zu, flags: %d, fd: %d, offset: %zu\n",
-               length, flags, fd, (size_t)offset);
-       exit(EXIT_FAILURE);
+       void **m = map;
+
+       errno = EINVAL;
+       if (!length)
+               goto err;
+       *m = mmap(NULL, length, prot, flags, fd, offset);
+       if (*m != MAP_FAILED)
+               return 1;
+err:
+       *m = NULL;
+       return -ERRNO_TO_PARA_ERROR(errno);
 }
 
 /**
 }
 
 /**
@@ -398,17 +405,7 @@ int mmap_full_file(const char *path, int open_mode, void **map,
                goto out;
        }
        *size = file_status.st_size;
                goto out;
        }
        *size = file_status.st_size;
-       ret = -E_EMPTY;
-       PARA_DEBUG_LOG("%s: size %zu\n", path, *size);
-       if (!*size)
-               goto out;
-       *map = mmap(NULL, *size, mmap_prot, mmap_flags, fd, 0);
-       if (*map == MAP_FAILED) {
-               *map = NULL;
-               ret = -E_MMAP;
-               goto out;
-       }
-       ret = 1;
+       ret = para_mmap(*size, mmap_prot, mmap_flags, fd, 0, map);
 out:
        if (ret < 0 || !fd_ptr)
                close(fd);
 out:
        if (ret < 0 || !fd_ptr)
                close(fd);
diff --git a/fd.h b/fd.h
index 041a7732d3169ced0cbda3d9aa40727d0841f6c5..7c364120a7d3a052c8b67b6867f7da8589aebee2 100644 (file)
--- a/fd.h
+++ b/fd.h
@@ -14,7 +14,8 @@ __must_check int mark_fd_nonblocking(int fd);
 __must_check int mark_fd_blocking(int fd);
 void para_fd_set(int fd, fd_set *fds, int *max_fileno);
 __must_check int para_fgets(char *line, int size, FILE *f);
 __must_check int mark_fd_blocking(int fd);
 void para_fd_set(int fd, fd_set *fds, int *max_fileno);
 __must_check int para_fgets(char *line, int size, FILE *f);
-void *para_mmap(size_t length, int prot, int flags, int fd, off_t offset);
+int para_mmap(size_t length, int prot, int flags, int fd, off_t offset,
+               void *map);
 int para_open(const char *path, int flags, mode_t mode);
 int para_opendir(const char *dirname, DIR **dir, int *cwd);
 int para_mkdir(const char *path, mode_t mode);
 int para_open(const char *path, int flags, mode_t mode);
 int para_opendir(const char *dirname, DIR **dir, int *cwd);
 int para_mkdir(const char *path, mode_t mode);
diff --git a/vss.c b/vss.c
index c11897020d80afb4066b4abd80714798d43f6e4e..d205349370f69a9445ff1db7bb1c269b2d6431a7 100644 (file)
--- a/vss.c
+++ b/vss.c
@@ -382,8 +382,10 @@ static void recv_afs_result(struct vss_task *vsst)
        }
        mmd->size = statbuf.st_size;
        mmd->mtime = statbuf.st_mtime;
        }
        mmd->size = statbuf.st_size;
        mmd->mtime = statbuf.st_mtime;
-       vsst->map = para_mmap(mmd->size, PROT_READ, MAP_PRIVATE,
-               passed_fd, 0);
+       ret = para_mmap(mmd->size, PROT_READ, MAP_PRIVATE, passed_fd,
+               0, &vsst->map);
+       if (ret < 0)
+               goto err;
        close(passed_fd);
        mmd->chunks_sent = 0;
        mmd->current_chunk = 0;
        close(passed_fd);
        mmd->chunks_sent = 0;
        mmd->current_chunk = 0;