X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Freadahead%2Freadahead-common.c;h=10b0ccc548e6abbe17a28588426b8ab59a640c19;hp=99dbac2525a8aa739830d613b1ea97e626d6a762;hb=a8b10efaec5005b8e4fcc2bebdf86993ad14993d;hpb=6de338a2d9904ef5a67552b024491700523074a3 diff --git a/src/readahead/readahead-common.c b/src/readahead/readahead-common.c index 99dbac252..10b0ccc54 100644 --- a/src/readahead/readahead-common.c +++ b/src/readahead/readahead-common.c @@ -71,14 +71,16 @@ int fs_on_ssd(const char *p) { if (major(st.st_dev) == 0) return false; - if (!(udev = udev_new())) + udev = udev_new(); + if (!udev) return -ENOMEM; - if (!(udev_device = udev_device_new_from_devnum(udev, 'b', st.st_dev))) + udev_device = udev_device_new_from_devnum(udev, 'b', st.st_dev); + if (!udev_device) goto finish; - if ((devtype = udev_device_get_property_value(udev_device, "DEVTYPE")) && - streq(devtype, "partition")) + devtype = udev_device_get_property_value(udev_device, "DEVTYPE"); + if (devtype && streq(devtype, "partition")) look_at = udev_device_get_parent(udev_device); else look_at = udev_device; @@ -87,21 +89,25 @@ int fs_on_ssd(const char *p) { goto finish; /* First, try high-level property */ - if ((id = udev_device_get_property_value(look_at, "ID_SSD"))) { + id = udev_device_get_property_value(look_at, "ID_SSD"); + if (id) { b = streq(id, "1"); goto finish; } /* Second, try kernel attribute */ - if ((rotational = udev_device_get_sysattr_value(look_at, "queue/rotational"))) + rotational = udev_device_get_sysattr_value(look_at, "queue/rotational"); + if (rotational) if ((b = streq(rotational, "0"))) goto finish; /* Finally, fallback to heuristics */ - if (!(look_at = udev_device_get_parent(look_at))) + look_at = udev_device_get_parent(look_at); + if (!look_at) goto finish; - if ((model = udev_device_get_sysattr_value(look_at, "model"))) + model = udev_device_get_sysattr_value(look_at, "model"); + if (model) b = !!strstr(model, "SSD"); finish: @@ -208,7 +214,11 @@ finish: return m; } -#define BUMP_REQUEST_NR (16*1024) +/* 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. */ +#define BUMP_REQUEST_NR (20*1024) int block_bump_request_nr(const char *p) { struct stat st;