readahead-common.c revision de0671ee7fe465e108f62dcbbbe9366f81dd9e9a
/*-*- 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 "log.h"
#include "readahead-common.h"
#include "util.h"
#include "missing.h"
#include "fileio.h"
#include "libudev.h"
#include "udev-util.h"
return -errno;
}
return 0;
}
return 0;
}
return 1;
}
int fs_on_ssd(const char *p) {
int r;
assert(p);
return -errno;
int mount_id;
/* 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. */
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)
return false;
else
if (!look_at)
return false;
/* First, try high-level property */
if (id)
/* Second, try kernel attribute */
if (rotational)
/* Finally, fallback to heuristics */
if (!look_at)
return false;
if (model)
return false;
}
int fs_on_read_only(const char *p) {
const char *read_only;
assert(p);
return -errno;
return false;
if (!udev)
return -ENOMEM;
if (!udev_device)
return false;
if (read_only)
return false;
}
bool enough_ram(void) {
/* Enable readahead only with at least 128MB memory */
}
static void mkdirs(void) {
log_warning("Failed to create /run/systemd: %m");
log_warning("Failed to create /run/systemd: %m");
}
int open_inotify(void) {
int fd;
if (fd < 0) {
log_error("Failed to create inotify handle: %m");
return -errno;
}
mkdirs();
safe_close(fd);
return -errno;
}
return fd;
}
ReadaheadShared *shared_get(void) {
ReadaheadShared *m = NULL;
mkdirs();
if (fd < 0) {
log_error("Failed to create shared memory segment: %m");
return NULL;
}
log_error("Failed to truncate shared memory segment: %m");
return NULL;
}
if (m == MAP_FAILED) {
log_error("Failed to mmap shared memory segment: %m");
return NULL;
}
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 %u. This is a temporary hack and should be removed one day.", major(d), minor(d), 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;
}