blob: bf54460fc9326e4e1d481bc01a7bd48051cea596 [file] [log] [blame]
Dmitry V. Levinfc4727d2014-02-05 17:27:43 +00001#include "defs.h"
2
3enum {
4 IOPRIO_WHO_PROCESS = 1,
5 IOPRIO_WHO_PGRP,
6 IOPRIO_WHO_USER
7};
8
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +00009#include "xlat/ioprio_who.h"
Dmitry V. Levinfc4727d2014-02-05 17:27:43 +000010
11enum {
12 IOPRIO_CLASS_NONE,
13 IOPRIO_CLASS_RT,
14 IOPRIO_CLASS_BE,
15 IOPRIO_CLASS_IDLE
16};
17
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +000018#include "xlat/ioprio_class.h"
Dmitry V. Levinfc4727d2014-02-05 17:27:43 +000019
20#define IOPRIO_CLASS_SHIFT (13)
21#define IOPRIO_PRIO_MASK ((1ul << IOPRIO_CLASS_SHIFT) - 1)
22
23#define IOPRIO_PRIO_CLASS(mask) ((mask) >> IOPRIO_CLASS_SHIFT)
24#define IOPRIO_PRIO_DATA(mask) ((mask) & IOPRIO_PRIO_MASK)
25
26static const char *
27sprint_ioprio(int ioprio)
28{
29 static char outstr[256];
30 const char *str;
31 int class, data;
32
33 class = IOPRIO_PRIO_CLASS(ioprio);
34 data = IOPRIO_PRIO_DATA(ioprio);
35 str = xlookup(ioprio_class, class);
36 if (str)
37 sprintf(outstr, "IOPRIO_PRIO_VALUE(%s,%d)", str, data);
38 else
39 sprintf(outstr, "IOPRIO_PRIO_VALUE(%#x /* %s */,%d)",
40 class, "IOPRIO_CLASS_???", data);
41
42 return outstr;
43}
44
Dmitry V. Levina0bd3742015-04-07 01:36:50 +000045SYS_FUNC(ioprio_get)
Dmitry V. Levinfc4727d2014-02-05 17:27:43 +000046{
47 if (entering(tcp)) {
48 /* int which */
49 printxval(ioprio_who, tcp->u_arg[0], "IOPRIO_WHO_???");
50 /* int who */
51 tprintf(", %d", (int) tcp->u_arg[1]);
52 return 0;
53 } else {
54 if (syserror(tcp))
55 return 0;
56
57 tcp->auxstr = sprint_ioprio(tcp->u_rval);
58 return RVAL_STR;
59 }
60}
61
Dmitry V. Levina0bd3742015-04-07 01:36:50 +000062SYS_FUNC(ioprio_set)
Dmitry V. Levinfc4727d2014-02-05 17:27:43 +000063{
Dmitry V. Levina58ad742015-07-20 10:42:49 +000064 /* int which */
65 printxval(ioprio_who, tcp->u_arg[0], "IOPRIO_WHO_???");
66 /* int who */
67 tprintf(", %d, ", (int) tcp->u_arg[1]);
68 /* int ioprio */
69 tprints(sprint_ioprio(tcp->u_arg[2]));
70
71 return RVAL_DECODED;
Dmitry V. Levinfc4727d2014-02-05 17:27:43 +000072}