readahead-common.c revision a5c32cff1f56afe6f0c6c70d91a88a7a8238b2d7
/*-*- 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 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser 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"
#include "missing.h"
#include "fileio.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;
int r;
assert(p);
return -errno;
int mount_id;
struct file_handle *h;
/* Might be btrfs, which exposes "ssd" as mount flag if it is on ssd.
*
* We first determine the mount ID here, if we can,
* and then lookup the mount ID in mountinfo to find
* the mount options. */
h = alloca(MAX_HANDLE_SZ);
h->handle_bytes = MAX_HANDLE_SZ;
if (r < 0)
return false;
if (!f)
return false;
for (;;) {
int mid;
return false;
continue;
continue;
if (!e)
continue;
continue;
if (streq(opts, "ssd") || startswith(opts, "ssd,") || endswith(opts, ",ssd") || strstr(opts, ",ssd,"))
return true;
}
return false;
}
if (!udev)
return -ENOMEM;
if (!udev_device)
goto finish;
else
if (!look_at)
goto finish;
/* First, try high-level property */
if (id) {
goto finish;
}
/* Second, try kernel attribute */
if (rotational) {
goto finish;
}
/* Finally, fallback to heuristics */
if (!look_at)
goto finish;
if (model)
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) {
/* Enable readahead only 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;
}
/* We use 20K instead of the more human digestable 16K here. Why?
Simply so that it is more unlikely that users end up picking this
value too so that we can recognize better whether the user changed
the value while we had it temporarily bumped. */
int block_bump_request_nr(const char *p) {
uint64_t u;
int r;
dev_t d;
assert(p);
return -errno;
return 0;
block_get_whole_disk(d, &d);
r= -ENOMEM;
goto finish;
}
if (r < 0) {
if (r == -ENOENT)
r = 0;
goto finish;
}
r = safe_atou64(line, &u);
if (r >= 0 && u >= BUMP_REQUEST_NR) {
r = 0;
goto finish;
}
r = -ENOMEM;
goto finish;
}
if (r < 0)
goto finish;
log_info("Bumped block_nr parameter of %u:%u to %lu. This is a temporary hack and should be removed one day.", major(d), minor(d), (unsigned long) BUMP_REQUEST_NR);
r = 1;
return r;
}
int r;
dev_t d;
uint64_t u;
assert(p);
return -errno;
return 0;
block_get_whole_disk(d, &d);
r = -ENOMEM;
goto finish;
}
if (r < 0)
goto finish;
r = safe_atou64(line, &u);
if (r < 0)
goto finish;
*bytes = u * 1024ULL;
return r;
}
int r;
dev_t d;
assert(p);
return -errno;
return 0;
block_get_whole_disk(d, &d);
r = -ENOMEM;
goto finish;
}
r = -ENOMEM;
goto finish;
}
if (r < 0)
goto finish;
return r;
}