tizen 2.3.1 release
[kernel/api/system-resource.git] / src / common / cgroup.h
1 /*
2  * resourced
3  *
4  * Copyright (c) 2013 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  */
19
20 #include <resourced.h>
21 #include <sys/types.h>
22
23 /*
24  * Cgroup creation interface
25  */
26
27 #ifndef _CGROUP_LIBRARY_CGROUP_H_
28 #define _CGROUP_LIBRARY_CGROUP_H_
29
30 #define DEFAULT_CGROUP          "/sys/fs/cgroup"
31
32 /**
33  * @desc Get one unsigned int value from cgroup
34  * @param cgroup_name - cgroup path
35  * @param file_name - cgroup content to write
36  * @param value - out parameter, value to fill
37  * @return negative value if error
38 */
39 int cgroup_read_node(const char *cgroup_name,
40                 const char *file_name, unsigned int *value);
41
42 /**
43  * @desc Put value to cgroup,
44  * @param cgroup_name - cgroup path
45  * @param file_name - cgroup content to write
46  * @param value - data to write
47  * @return negative value if error
48  */
49 int cgroup_write_node(const char *cgroup_name,  const char *file_name, unsigned int value);
50
51 /**
52  * @desc Put value to cgroup,
53  * @param cgroup_name - cgroup path
54  * @param file_name - cgroup content to write
55  * @param string -string to write
56  * @return negative value if error
57  */
58 int cgroup_write_node_str(const char *cgroup_name,
59                 const char *file_name, char* string);
60
61 /**
62  * @desc make cgroup,
63  * @param parentdir - parent cgroup path
64  * @param cgroup_name - cgroup subdirectory to write
65  * @param cgroup_exists - 1 if subdir already exists, NULL pointer is possible
66  * as formal argument, in this case it will not be filled
67  * @return negative value if error
68  */
69 int make_cgroup_subdir(char* parentdir, char* cgroup_name, int *cgroup_exists);
70
71 /**
72  * @desc mount cgroup,
73  * @param source -cgroup name
74  * @param mount_point - cgroup path
75  * @param opts - mount options
76  * @return negative value if error
77  */
78 int mount_cgroup_subsystem(char* source, char* mount_point, char* opts);
79
80 /**
81  * @desc mount cgroup,
82  * @param source -cgroup name
83  * @param mount_point - cgroup path
84  * @param opts - mount options
85  * @return negative value if error
86  */
87 resourced_ret_c place_pid_to_cgroup(const char *cgroup_subsystem,
88         const char *cgroup_name, const int pid);
89
90 resourced_ret_c place_pid_to_cgroup_by_fullpath(const char *cgroup_full_path,
91         const int pid);
92
93 #endif /*_CGROUP_LIBRARY_CGROUP_H_*/