mirror of
https://github.com/systemd/systemd.git
synced 2025-01-26 14:04:03 +03:00
readahead: disable collector automatically on read-only media
This commit is contained in:
parent
c1b664d055
commit
2b590e135f
2
TODO
2
TODO
@ -40,8 +40,6 @@ Features:
|
||||
|
||||
* invoke vhangup() before and after invoking getty
|
||||
|
||||
* skip readahead on physically r/o media
|
||||
|
||||
* support "auto" and "comment=systemd.automount" at the same time for an fstab entry
|
||||
|
||||
* Make use of UnknownInterface, UnknownObject
|
||||
|
@ -639,6 +639,7 @@ static int parse_argv(int argc, char *argv[]) {
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int r;
|
||||
const char *root;
|
||||
|
||||
log_set_target(LOG_TARGET_SYSLOG_OR_KMSG);
|
||||
log_parse_environment();
|
||||
@ -647,6 +648,13 @@ int main(int argc, char *argv[]) {
|
||||
if ((r = parse_argv(argc, argv)) <= 0)
|
||||
return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
|
||||
|
||||
root = optind < argc ? argv[optind] : "/";
|
||||
|
||||
if (fs_on_read_only(root) > 0) {
|
||||
log_info("Disabling readahead collector due to read-only media.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!enough_ram()) {
|
||||
log_info("Disabling readahead collector due to low memory.");
|
||||
return 0;
|
||||
@ -663,7 +671,7 @@ int main(int argc, char *argv[]) {
|
||||
shared->collect = getpid();
|
||||
__sync_synchronize();
|
||||
|
||||
if (collect(optind < argc ? argv[optind] : "/") < 0)
|
||||
if (collect(root) < 0)
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
|
@ -114,6 +114,41 @@ finish:
|
||||
return b;
|
||||
}
|
||||
|
||||
int fs_on_read_only(const char *p) {
|
||||
struct stat st;
|
||||
struct udev *udev = NULL;
|
||||
struct udev_device *udev_device = NULL;
|
||||
bool b = false;
|
||||
const char *read_only;
|
||||
|
||||
assert(p);
|
||||
|
||||
if (stat(p, &st) < 0)
|
||||
return -errno;
|
||||
|
||||
if (major(st.st_dev) == 0)
|
||||
return false;
|
||||
|
||||
if (!(udev = udev_new()))
|
||||
return -ENOMEM;
|
||||
|
||||
if (!(udev_device = udev_device_new_from_devnum(udev, 'b', st.st_dev)))
|
||||
goto finish;
|
||||
|
||||
if ((read_only = udev_device_get_sysattr_value(udev_device, "ro")))
|
||||
if ((b = streq(read_only, "1")))
|
||||
goto finish;
|
||||
|
||||
finish:
|
||||
if (udev_device)
|
||||
udev_device_unref(udev_device);
|
||||
|
||||
if (udev)
|
||||
udev_unref(udev);
|
||||
|
||||
return b;
|
||||
}
|
||||
|
||||
bool enough_ram(void) {
|
||||
struct sysinfo si;
|
||||
|
||||
|
@ -32,6 +32,7 @@
|
||||
int file_verify(int fd, const char *fn, off_t file_size_max, struct stat *st);
|
||||
|
||||
int fs_on_ssd(const char *p);
|
||||
int fs_on_read_only(const char *p);
|
||||
|
||||
bool enough_ram(void);
|
||||
|
||||
|
@ -333,6 +333,7 @@ static int parse_argv(int argc, char *argv[]) {
|
||||
|
||||
int main(int argc, char*argv[]) {
|
||||
int r;
|
||||
const char *root;
|
||||
|
||||
log_set_target(LOG_TARGET_SYSLOG_OR_KMSG);
|
||||
log_parse_environment();
|
||||
@ -341,6 +342,8 @@ int main(int argc, char*argv[]) {
|
||||
if ((r = parse_argv(argc, argv)) <= 0)
|
||||
return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
|
||||
|
||||
root = optind < argc ? argv[optind] : "/";
|
||||
|
||||
if (!enough_ram()) {
|
||||
log_info("Disabling readahead replay due to low memory.");
|
||||
return 0;
|
||||
@ -357,7 +360,7 @@ int main(int argc, char*argv[]) {
|
||||
shared->replay = getpid();
|
||||
__sync_synchronize();
|
||||
|
||||
if (replay(optind < argc ? argv[optind] : "/") < 0)
|
||||
if (replay(root) < 0)
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user