X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Freadahead-common.c;h=67214ec3790639e1da651120fa94c05f230f7439;hb=e99fa3cba5c0a07bdcea22a308bf9b973e88b624;hp=990ffd4d085e3dd9cfd6f6b44c4b8daee02cd84f;hpb=b925e72633bf98438f56a140520e07ec8c959e46;p=elogind.git diff --git a/src/readahead-common.c b/src/readahead-common.c index 990ffd4d0..67214ec37 100644 --- a/src/readahead-common.c +++ b/src/readahead-common.c @@ -154,9 +154,8 @@ bool enough_ram(void) { assert_se(sysinfo(&si) >= 0); - return si.totalram > 127 * 1024*1024; /* Enable readahead only - * with at least 128MB - * memory */ + /* Enable readahead only with at least 128MB memory */ + return si.totalram > 127 * 1024*1024 / si.mem_unit; } int open_inotify(void) { @@ -167,11 +166,11 @@ int open_inotify(void) { return -errno; } - mkdir("/dev/.run/systemd", 0755); - mkdir("/dev/.run/systemd/readahead", 0755); + mkdir("/run/systemd", 0755); + mkdir("/run/systemd/readahead", 0755); - if (inotify_add_watch(fd, "/dev/.run/systemd/readahead", IN_CREATE) < 0) { - log_error("Failed to watch /dev/.run/systemd/readahead: %m"); + if (inotify_add_watch(fd, "/run/systemd/readahead", IN_CREATE) < 0) { + log_error("Failed to watch /run/systemd/readahead: %m"); close_nointr_nofail(fd); return -errno; } @@ -183,10 +182,10 @@ ReadaheadShared *shared_get(void) { int fd; ReadaheadShared *m = NULL; - mkdir("/dev/.run/systemd", 0755); - mkdir("/dev/.run/systemd/readahead", 0755); + mkdir("/run/systemd", 0755); + mkdir("/run/systemd/readahead", 0755); - if ((fd = open("/dev/.run/systemd/readahead/shared", O_CREAT|O_RDWR|O_CLOEXEC, 0644)) < 0) { + if ((fd = open("/run/systemd/readahead/shared", O_CREAT|O_RDWR|O_CLOEXEC, 0644)) < 0) { log_error("Failed to create shared memory segment: %m"); goto finish; } @@ -209,17 +208,14 @@ finish: return m; } - #define BUMP_REQUEST_NR (16*1024) int bump_request_nr(const char *p) { struct stat st; - struct udev *udev = NULL; - struct udev_device *udev_device = NULL, *look_at = NULL; - const char *nr_requests; uint64_t u; - char nr[64], *ap = NULL; + char *ap = NULL, *line = NULL; int r; + dev_t d; assert(p); @@ -229,54 +225,45 @@ int bump_request_nr(const char *p) { if (major(st.st_dev) == 0) return 0; - if (!(udev = udev_new())) - return -ENOMEM; + d = st.st_dev; + block_get_whole_disk(d, &d); - if (!(udev_device = udev_device_new_from_devnum(udev, 'b', st.st_dev))) { - r = -ENOENT; + if (asprintf(&ap, "/sys/dev/block/%u:%u/queue/nr_requests", major(d), minor(d)) < 0) { + r= -ENOMEM; goto finish; } - look_at = udev_device; - if (!(nr_requests = udev_device_get_sysattr_value(look_at, "queue/nr_requests"))) { - - /* Hmm, if the block device doesn't have a queue - * subdir, the let's look in the parent */ - look_at = udev_device_get_parent(udev_device); - nr_requests = udev_device_get_sysattr_value(look_at, "queue/nr_requests"); - } - - if (!nr_requests) { - r = -ENOENT; + r = read_one_line_file(ap, &line); + if (r < 0) { + if (r == -ENOENT) + r = 0; goto finish; } - if (safe_atou64(nr_requests, &u) >= 0 && u >= BUMP_REQUEST_NR) { + r = safe_atou64(line, &u); + if (r >= 0 && u >= BUMP_REQUEST_NR) { r = 0; goto finish; } - if (asprintf(&ap, "%s/queue/nr_requests", udev_device_get_syspath(look_at)) < 0) { + free(line); + line = NULL; + + if (asprintf(&line, "%lu", (unsigned long) BUMP_REQUEST_NR) < 0) { r = -ENOMEM; goto finish; } - snprintf(nr, sizeof(nr), "%lu", (unsigned long) BUMP_REQUEST_NR); - - if ((r = write_one_line_file(ap, nr)) < 0) + r = write_one_line_file(ap, line); + if (r < 0) 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); + 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; finish: - if (udev_device) - udev_device_unref(udev_device); - - if (udev) - udev_unref(udev); - free(ap); + free(line); return r; }