summaryrefslogtreecommitdiff
path: root/src/util.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2011-08-21 00:28:30 +0200
committerLennart Poettering <lennart@poettering.net>2011-08-21 20:07:45 +0200
commit94959f0fa0c19ae1db0e63d9a5dfc94c660825ba (patch)
tree22733bd2908d5001892f454cb786c279cd538e1f /src/util.c
parent9e37286844f67ca7c59e923dd27ad193dfdda7eb (diff)
exec: allow passing arbitrary path names to blkio cgroup attributes
If a device node is specified, then adjust the bandwidth/weight of it, otherwise find the backing block device of the file system the path refers to and adjust its bandwidth/weight.
Diffstat (limited to 'src/util.c')
-rw-r--r--src/util.c61
1 files changed, 61 insertions, 0 deletions
diff --git a/src/util.c b/src/util.c
index c24c749a5a..017b995897 100644
--- a/src/util.c
+++ b/src/util.c
@@ -5614,6 +5614,67 @@ bool is_main_thread(void) {
return cached > 0;
}
+int block_get_whole_disk(dev_t d, dev_t *ret) {
+ char *p, *s;
+ int r;
+ unsigned n, m;
+
+ assert(ret);
+
+ /* If it has a queue this is good enough for us */
+ if (asprintf(&p, "/sys/dev/block/%u:%u/queue", major(d), minor(d)) < 0)
+ return -ENOMEM;
+
+ r = access(p, F_OK);
+ free(p);
+
+ if (r >= 0) {
+ *ret = d;
+ return 0;
+ }
+
+ /* If it is a partition find the originating device */
+ if (asprintf(&p, "/sys/dev/block/%u:%u/partition", major(d), minor(d)) < 0)
+ return -ENOMEM;
+
+ r = access(p, F_OK);
+ free(p);
+
+ if (r < 0)
+ return -ENOENT;
+
+ /* Get parent dev_t */
+ if (asprintf(&p, "/sys/dev/block/%u:%u/../dev", major(d), minor(d)) < 0)
+ return -ENOMEM;
+
+ r = read_one_line_file(p, &s);
+ free(p);
+
+ if (r < 0)
+ return r;
+
+ r = sscanf(s, "%u:%u", &m, &n);
+ free(s);
+
+ if (r != 2)
+ return -EINVAL;
+
+ /* Only return this if it is really good enough for us. */
+ if (asprintf(&p, "/sys/dev/block/%u:%u/queue", m, n) < 0)
+ return -ENOMEM;
+
+ r = access(p, F_OK);
+ free(p);
+
+ if (r >= 0) {
+ *ret = makedev(m, n);
+ return 0;
+ }
+
+ return -ENOENT;
+}
+
+
static const char *const ioprio_class_table[] = {
[IOPRIO_CLASS_NONE] = "none",
[IOPRIO_CLASS_RT] = "realtime",