summaryrefslogtreecommitdiff
path: root/src/readahead/readahead-replay.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2012-05-04 00:34:12 +0200
committerLennart Poettering <lennart@poettering.net>2012-05-04 00:34:12 +0200
commit189455ab08a70f0c80a11847b65ce38563b9332a (patch)
tree9ab1a187c42f9b1ff9b5f7e7cf9fea848b8c62e9 /src/readahead/readahead-replay.c
parent4019a16d5b65633e5f6d671c16d3215d7f7f29fc (diff)
readahead: store inode numbers in pack file
If the inode nr for each file is available in the pack file we can easily detect replaced files (like they result from package upgrades) which we can then skip to readahead.
Diffstat (limited to 'src/readahead/readahead-replay.c')
-rw-r--r--src/readahead/readahead-replay.c23
1 files changed, 20 insertions, 3 deletions
diff --git a/src/readahead/readahead-replay.c b/src/readahead/readahead-replay.c
index a6529f8bac..886e16f296 100644
--- a/src/readahead/readahead-replay.c
+++ b/src/readahead/readahead-replay.c
@@ -53,6 +53,7 @@ static int unpack_file(FILE *pack) {
int r = 0, fd = -1;
bool any = false;
struct stat st;
+ uint64_t inode;
assert(pack);
@@ -62,7 +63,8 @@ static int unpack_file(FILE *pack) {
char_array_0(fn);
truncate_nl(fn);
- if ((fd = open(fn, O_RDONLY|O_CLOEXEC|O_NOATIME|O_NOCTTY|O_NOFOLLOW)) < 0) {
+ fd = open(fn, O_RDONLY|O_CLOEXEC|O_NOATIME|O_NOCTTY|O_NOFOLLOW);
+ if (fd < 0) {
if (errno != ENOENT && errno != EPERM && errno != EACCES)
log_warning("open(%s) failed: %m", fn);
@@ -72,6 +74,21 @@ static int unpack_file(FILE *pack) {
fd = -1;
}
+ if (fread(&inode, sizeof(inode), 1, pack) != 1) {
+ log_error("Premature end of pack file.");
+ r = -EIO;
+ goto finish;
+ }
+
+ if (fd >= 0) {
+ /* If the inode changed the file got deleted, so just
+ * ignore this entry */
+ if (st.st_ino != (uint64_t) inode) {
+ close_nointr_nofail(fd);
+ fd = -1;
+ }
+ }
+
for (;;) {
uint32_t b, c;
@@ -166,8 +183,8 @@ static int replay(const char *root) {
char_array_0(line);
- if (!streq(line, CANONICAL_HOST "\n")) {
- log_debug("Pack file host type mismatch.");
+ if (!streq(line, CANONICAL_HOST ";VERSION=2\n")) {
+ log_debug("Pack file host or version type mismatch.");
goto finish;
}