Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / 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 #if defined(__FreeBSD__)
17 #include <errno.h>
18 #endif
19 #ifdef __linux__
20 #include <sys/syscall.h>   /* For SYS_xxx definitions */
21 #endif
22 #include <algorithm>
23
24 #include "io_priority.h"
25
26 pid_t ceph_gettid(void)
27 {
28 #ifdef __linux__
29   return syscall(SYS_gettid);
30 #else
31   return -ENOSYS;
32 #endif
33 }
34
35 int ceph_ioprio_set(int whence, int who, int ioprio)
36 {
37 #ifdef __linux__
38   return syscall(SYS_ioprio_set, whence, who, ioprio);
39 #else
40   return -ENOSYS;
41 #endif
42 }
43
44 int ceph_ioprio_string_to_class(const std::string& s)
45 {
46   std::string l = s;
47   std::transform(l.begin(), l.end(), l.begin(), ::tolower);
48
49   if (l == "idle")
50     return IOPRIO_CLASS_IDLE;
51   if (l == "be" || l == "besteffort" || l == "best effort")
52     return IOPRIO_CLASS_BE;
53   if (l == "rt" || l == "realtime" || l == "real time")
54     return IOPRIO_CLASS_RT;
55   return -EINVAL;
56 }