Copyright 2010 Lennart Poettering
systemd is free software; you can redistribute it and/or modify it
- under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
+ under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 2.1 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.
+ Lesser General Public License for more details.
- You should have received a copy of the GNU General Public License
+ You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
int r = 0, fd = -1;
bool any = false;
struct stat st;
+ uint64_t inode;
assert(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);
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;
assert(root);
- write_one_line_file("/proc/self/oom_score_adj", "1000");
- bump_request_nr(root);
+ block_bump_request_nr(root);
if (asprintf(&pack_fn, "%s/.readahead", root) < 0) {
log_error("Out of memory");
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;
}
if (on_ssd)
prio = IOPRIO_PRIO_VALUE(IOPRIO_CLASS_IDLE, 0);
else
- prio = IOPRIO_PRIO_VALUE(IOPRIO_CLASS_RT, 7);
+ /* We are not using RT here, since we'd starve IO that
+ we didn't record (which is for example blkid, since
+ its disk accesses go directly to the block device and
+ are thus not visible in fallocate) to death. However,
+ we do ask for an IO prio that is slightly higher than
+ the default (which is BE. 4) */
+ prio = IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 2);
if (ioprio_set(IOPRIO_WHO_PROCESS, getpid(), prio) < 0)
log_warning("Failed to set IDLE IO priority class: %m");
int r;
const char *root;
- log_set_target(LOG_TARGET_SYSLOG_OR_KMSG);
+ log_set_target(LOG_TARGET_SAFE);
log_parse_environment();
log_open();
umask(0022);
- if ((r = parse_argv(argc, argv)) <= 0)
+ r = parse_argv(argc, argv);
+ if (r <= 0)
return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
root = optind < argc ? argv[optind] : "/";
return 0;
}
- if (detect_virtualization(NULL) > 0) {
- log_info("Disabling readahead replay due to execution in virtualized environment.");
- return 0;
- }
-
- if (!(shared = shared_get()))
+ shared = shared_get();
+ if (!shared)
return 1;
shared->replay = getpid();