]> git.proxmox.com Git - ceph.git/blob - ceph/src/common/io_priority.cc
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / common / io_priority.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3 /*
4 * Ceph - scalable distributed file system
5 *
6 * Copyright (C) 2012 Red Hat
7 *
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
12 *
13 */
14
15 #include <unistd.h>
16 #ifdef __linux__
17 #include <sys/syscall.h> /* For SYS_xxx definitions */
18 #endif
19 #include <algorithm>
20 #include <errno.h>
21
22 #include "io_priority.h"
23
24 pid_t ceph_gettid(void)
25 {
26 #ifdef __linux__
27 return syscall(SYS_gettid);
28 #else
29 return -ENOSYS;
30 #endif
31 }
32
33 int ceph_ioprio_set(int whence, int who, int ioprio)
34 {
35 #ifdef __linux__
36 return syscall(SYS_ioprio_set, whence, who, ioprio);
37 #else
38 return -ENOSYS;
39 #endif
40 }
41
42 int ceph_ioprio_string_to_class(const std::string& s)
43 {
44 std::string l = s;
45 std::transform(l.begin(), l.end(), l.begin(), ::tolower);
46
47 if (l == "idle")
48 return IOPRIO_CLASS_IDLE;
49 if (l == "be" || l == "besteffort" || l == "best effort")
50 return IOPRIO_CLASS_BE;
51 if (l == "rt" || l == "realtime" || l == "real time")
52 return IOPRIO_CLASS_RT;
53 return -EINVAL;
54 }