X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Freadahead-replay.c;h=cb93fae806e7cbd3fd552b3ab4d10e230ec6e008;hp=a5a2936b3e816ce751ddb30d9160d36781af50bc;hb=f015eca2a2f4186208930cf23196967ed425e2c9;hpb=6624768c9c39ab409edebe07cb06ecd93cc6f3ed diff --git a/src/readahead-replay.c b/src/readahead-replay.c index a5a2936b3..cb93fae80 100644 --- a/src/readahead-replay.c +++ b/src/readahead-replay.c @@ -44,6 +44,8 @@ static off_t arg_file_size_max = READAHEAD_FILE_SIZE_MAX; +static ReadaheadShared *shared = NULL; + static int unpack_file(FILE *pack) { char fn[PATH_MAX]; int r = 0, fd = -1; @@ -89,8 +91,8 @@ static int unpack_file(FILE *pack) { any = true; if (fd >= 0) - if (readahead(fd, b * PAGE_SIZE, (c - b) * PAGE_SIZE) < 0) { - log_warning("readahead() failed: %m"); + if (posix_fadvise(fd, b * PAGE_SIZE, (c - b) * PAGE_SIZE, POSIX_FADV_WILLNEED) < 0) { + log_warning("posix_fadvise() failed: %m"); goto finish; } } @@ -100,8 +102,8 @@ static int unpack_file(FILE *pack) { * intended to mean that the whole file shall be * read */ - if (readahead(fd, 0, st.st_size) < 0) { - log_warning("readahead() failed: %m"); + if (posix_fadvise(fd, 0, st.st_size, POSIX_FADV_WILLNEED) < 0) { + log_warning("posix_fadvise() failed: %m"); goto finish; } } @@ -114,7 +116,7 @@ finish: } static int replay(const char *root) { - FILE *pack; + FILE *pack = NULL; char line[LINE_MAX]; int r = 0; char *pack_fn = NULL, c; @@ -143,6 +145,8 @@ static int replay(const char *root) { goto finish; } + posix_fadvise(fileno(pack), 0, 0, POSIX_FADV_WILLNEED); + if ((inotify_fd = open_inotify()) < 0) { r = inotify_fd; goto finish; @@ -338,6 +342,12 @@ int main(int argc, char*argv[]) { return 0; } + if (!(shared = shared_get())) + return 1; + + shared->replay = getpid(); + __sync_synchronize(); + if (replay(optind < argc ? argv[optind] : "/") < 0) return 1;