readahead-common.c revision 2b590e135f53a1bd3e771bdc555f7bf28c4cd232
/*-*- 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 <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <libudev.h>
#include "log.h"
#include "readahead-common.h"
#include "util.h"
return -errno;
}
return 0;
}
log_debug("Not preloading file %s with size out of bounds %llu", fn, (unsigned long long) st->st_size);
return 0;
}
return 1;
}
int fs_on_ssd(const char *p) {
bool b = false;
assert(p);
return -errno;
return false;
return -ENOMEM;
goto finish;
else
if (!look_at)
goto finish;
/* First, try high-level property */
goto finish;
}
/* Second, try kernel attribute */
goto finish;
/* Finally, fallback to heuristics */
goto finish;
if (udev_device)
if (udev)
return b;
}
int fs_on_read_only(const char *p) {
bool b = false;
const char *read_only;
assert(p);
return -errno;
return false;
return -ENOMEM;
goto finish;
goto finish;
if (udev_device)
if (udev)
return b;
}
bool enough_ram(void) {
* with at least 128MB
* memory */
}
int open_inotify(void) {
int fd;
log_error("Failed to create inotify handle: %m");
return -errno;
}
return -errno;
}
return fd;
}
ReadaheadShared *shared_get(void) {
int fd;
ReadaheadShared *m = NULL;
log_error("Failed to create shared memory segment: %m");
goto finish;
}
log_error("Failed to truncate shared memory segment: %m");
goto finish;
}
if ((m = mmap(NULL, sizeof(ReadaheadShared), PROT_WRITE|PROT_READ, MAP_SHARED, fd, 0)) == MAP_FAILED) {
log_error("Failed to mmap shared memory segment: %m");
m = NULL;
goto finish;
}
if (fd >= 0)
return m;
}
int bump_request_nr(const char *p) {
const char *nr_requests;
uint64_t u;
int r;
assert(p);
return -errno;
return 0;
return -ENOMEM;
r = -ENOENT;
goto finish;
}
/* Hmm, if the block device doesn't have a queue
* subdir, the let's look in the parent */
}
if (!nr_requests) {
r = -ENOENT;
goto finish;
}
r = 0;
goto finish;
}
r = -ENOMEM;
goto finish;
}
goto finish;
log_info("Bumped block_nr parameter of %s to %lu. This is a temporary hack and should be removed one day.", udev_device_get_devnode(look_at), (unsigned long) BUMP_REQUEST_NR);
r = 1;
if (udev_device)
if (udev)
return r;
}