commit 4589e373fff0c98840470d28d0271c905eb65d32 from: Stefan Sperling date: Sat Mar 17 14:41:39 2018 UTC remove mmap() stuff; checkout is fast enough for now commit - 0bd0053c348d6c7ff2adec2bec651f15f2317f23 commit + 4589e373fff0c98840470d28d0271c905eb65d32 blob - 0e20e105346024022013f73bc6715c61bd7deb98 blob + 497c9c20139eece533dba83c6938dd6847ab1049 --- lib/got_pack_lib.h +++ lib/got_pack_lib.h @@ -14,30 +14,14 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* A pack file segment mapped with mmap(2). */ -struct got_pack_mapping { - TAILQ_ENTRY(got_pack_mapping) entry; - int fd; - uint8_t *addr; - off_t offset; - size_t len; -}; - -#define GOT_PACK_MAX_OPEN_MAPPINGS 512 -#define GOT_PACK_MAPPING_MIN_SIZE 8192 -#define GOT_PACK_MAPPING_MAX_SIZE (2048 * GOT_PACK_MAPPING_MIN_SIZE) - /* An open pack file. */ struct got_pack { char *path_packfile; FILE *packfile; size_t filesize; - int nmappings; - - TAILQ_HEAD(, got_pack_mapping) mappings; }; -const struct got_error *got_pack_close(struct got_pack *); +void got_pack_close(struct got_pack *); /* See Documentation/technical/pack-format.txt in Git. */ blob - f9bf359965c62584d6d45d87cd96d72668bf8a6e blob + 98c06d20b5a8631ff13b186324035c8eb68c1152 --- lib/pack.c +++ lib/pack.c @@ -17,7 +17,6 @@ #include #include #include -#include #include #include @@ -500,59 +499,9 @@ read_packfile_hdr(FILE *f, struct got_packidx_v2_hdr * err = got_error(GOT_ERR_BAD_PACKFILE); return err; -} - -#ifdef notyet -static const struct got_error * -map_packfile_segment(struct got_pack_mapping **map, const char *path_packfile, - off_t offset, size_t len) -{ - const struct got_error *err = NULL; - - if (len < GOT_PACK_MAPPING_MIN_SIZE) - len = GOT_PACK_MAPPING_MIN_SIZE; - - if (len > GOT_PACK_MAPPING_MAX_SIZE) - return got_error(GOT_ERR_NO_SPACE); - - *map = calloc(1, sizeof(**map)); - if (*map == NULL) - return got_error(GOT_ERR_NO_MEM); - - (*map)->fd = open(path_packfile, O_RDONLY | O_NOFOLLOW); - if ((*map)->fd == -1) { - err = got_error_from_errno(); - free((*map)); - *map = NULL; - return err; - } - - (*map)->addr = mmap(NULL, len, PROT_READ, MAP_PRIVATE, (*map)->fd, offset); - if ((*map)->addr == NULL) { - err = got_error_from_errno(); - close((*map)->fd); - free((*map)); - *map = NULL; - return err; - } - - (*map)->offset = offset; - (*map)->len = len; - - return NULL; } -#endif static const struct got_error * -unmap_packfile_segment(struct got_pack_mapping *map) -{ - if (munmap(map->addr, map->len) == -1 || close(map->fd) == -1) - return got_error_from_errno(); - free(map); - return NULL; -} - -static const struct got_error * open_packfile(FILE **packfile, const char *path_packfile, struct got_repository *repo, struct got_packidx_v2_hdr *packidx) { @@ -576,29 +525,14 @@ open_packfile(FILE **packfile, const char *path_packfi return err; } -const struct got_error * +void got_pack_close(struct got_pack *pack) { - const struct got_error *err = NULL; - - while (!TAILQ_EMPTY(&pack->mappings)) { - struct got_pack_mapping *map = TAILQ_FIRST(&pack->mappings); - err = unmap_packfile_segment(map); - if (err) - break; - TAILQ_REMOVE(&pack->mappings, map, entry); - pack->nmappings--; - } - - if (err == NULL) { - fclose(pack->packfile); - pack->packfile = NULL; - free(pack->path_packfile); - pack->path_packfile = NULL; - pack->filesize = 0; - } - - return err; + fclose(pack->packfile); + pack->packfile = NULL; + free(pack->path_packfile); + pack->path_packfile = NULL; + pack->filesize = 0; } static const struct got_error * @@ -628,8 +562,6 @@ cache_pack(struct got_pack **packp, const char *path_p } pack = &repo->packs[i]; - - TAILQ_INIT(&pack->mappings); pack->path_packfile = strdup(path_packfile); if (pack->path_packfile == NULL) {