readahead-replay.c revision 22be093ffb403a1c474037939ca9b88b1ee39f77
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
Copyright 2010 Lennart Poettering
under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <errno.h>
#include <inttypes.h>
#include <fcntl.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "missing.h"
#include "util.h"
#include "set.h"
#include "sd-daemon.h"
#include "ioprio.h"
#include "readahead-common.h"
int r = 0, fd = -1;
bool any = false;
return 0;
fd = -1;
}
for (;;) {
uint32_t b, c;
log_error("Premature end of pack file.");
r = -EIO;
goto finish;
}
if (b == 0 && c == 0)
break;
if (c <= b) {
log_error("Invalid pack file.");
r = -EIO;
goto finish;
}
any = true;
if (fd >= 0)
log_warning("readahead() failed: %m");
goto finish;
}
}
/* if no range is encoded in the pack file this is
* intended to mean that the whole file shall be
* read */
log_warning("readahead() failed: %m");
goto finish;
}
}
if (fd >= 0)
return r;
}
int r = 0;
bool on_ssd;
int prio;
log_error("Out of memory");
r = -ENOMEM;
goto finish;
}
log_debug("No pack file found.");
else {
log_error("Failed to open pack file: %m");
r = -errno;
}
goto finish;
}
log_error("Premature end of pack file.");
r = -EIO;
goto finish;
}
log_debug("Pack file host type mismatch.");
goto finish;
}
log_debug("Premature end of pack file.");
r = -EIO;
goto finish;
}
/* We do not retest SSD here, so that we can start replaying
* before udev is up.*/
on_ssd = c == 'S';
if (on_ssd)
else
log_warning("Failed to set IDLE IO priority class: %m");
sd_notify(0,
"READY=1\n"
"STATUS=Replaying readahead data");
log_debug("Replaying...");
int k;
if ((k = unpack_file(pack)) < 0) {
r = k;
goto finish;
}
}
log_error("Failed to read pack file.");
r = -EIO;
goto finish;
}
log_debug("Done.");
if (pack)
return r;
}
/* log_set_target(LOG_TARGET_SYSLOG_OR_KMSG); */
log_open();
if (replay("/") < 0)
return 1;
return 0;
}