1 Following is the list of functions that are currently exported in libresourced.so
7 * @brief Datausage quota
13 resman_state_t quota_type;
14 } resman_datausage_quota;
17 * @brief return type of the counters callback
20 PCL_CANCEL = 0, /**< cancel */
21 PCL_CONTINUE = 1, /**< continue */
25 * @brief callback for enumerate counters and restrictions
27 typedef resman_cb_ret(*resman_perf_info_cb) (const resman_perf_info * info,
31 * @brief Selection rule applied for data usage enumeration
38 } data_usage_selection_rule;
44 typedef resman_ret_c(*resman_sql_exec) (const resman_exec_context *context);
47 resman_perf_info_cb info_cb;
49 resman_perf_selection_rule *rule;
50 } resman_exec_context;
52 typedef resman_cb_ret(*resman_perf_info_cb) (const resman_perf_info * info,
55 * @brief Bundle structure for bringing all together application identification
57 * app_id - application identification - copy it if you in
58 * callback function, don't store raw pointer on it
59 * iface - interface name, NULL means all interfaces,
60 * don't store raw pointer on it in the callback function, copy it by value
61 * interval - time interval for given result, NULL means entire interval
62 * foreground - foreground restrictions and counters
63 * background - background restrictions and counters
68 resman_tm_interval *interval;
69 resman_common_info foreground;
70 resman_common_info background;
74 * @brief Commulative structure for holding data usage information
78 resman_restrictions rst;
86 resman_ret_c - return value of most functions.
89 PCL_ERROR_NOTIMPL = -7,
90 PCL_ERROR_UNINITIALIZED = -6,
91 PCL_ERROR_NO_DATA = -5,
92 PCL_ERROR_INVALID_PARAMETER = -4,
93 PCL_ERROR_OUT_OF_MEMORY = -3,
94 PCL_ERROR_DB_FAILED = -2,
100 * cpu_usage: percent of cpu usage
101 * mem_usage: percent of mem usage
102 * incomming_rate_limit: rate limit for incomming packets in bytes per second
103 * outgoing_rate_limit: rate limit for outgoing packets in bytes per second
108 int incoming_rate_limit;
109 int outgoing_rate_limit;
110 } resman_restrictions;
113 * @brief Selection rule applied for enumeration
114 * order - order field resman_order_t
115 * filter - fiter field resman_filter
116 * groupping - on what we should groupping our result
119 unsigned char version;
121 resman_filter filter;
123 } resman_perf_selection_rule;
128 int apply_net_restriction(u_int32_t classid, int incoming_rate_limit, int outgoing_rate_limit)
130 Applies network rate limit to application having the supplied network class ID
132 classid - network class ID
133 incoming_rate_limit - rate limit for incoming traffic
134 outgoing_rate_limit - rate limit for outgoing traffic
137 Non-zero values mean errors while communicating with kernel module
140 - Currently incoming_rate_limit must be 0, otherwise PCL_ERROR_NOTIMPL will be returned
142 --------------------------------------------------------------------------------
143 resman_ret_c apply_restriction(const char *app_id, const resman_restrictions *foreground, const resman_restrictions *background)
145 Stores restrictions into database to be applied when application is started again.
147 app_id - zero-terminated string containing package name of application to be restricted
148 foreground - set of restrictions applied to application while in foreground
149 background - set of restrictions applied to application while in background
151 Non-OK return values:
152 PCL_ERROR_INVALID_PARAMETER - app_id is NULL
153 PCL_ERROR_INVALID_PARAMETER - both foreground and background are NULL
154 PCL_ERROR_FAIL - could not determine network class ID for the application
155 PCL_ERROR_DB_FAILED - error while storing restrictions to database
156 PCL_ERROR_NOTIMPL - incoming_rate_limit is set
157 ???? - apply_net_restriction can return any non-zero integer value (see above) which will be returned as is
160 - Does not apply CPU and memory restrictions if application is already running
161 - Background settings are ignored
162 - Return meaningful result in case apply_net_restriction fails
164 --------------------------------------------------------------------------------
165 resman_ret_c bind_statement(sqlite3_stmt *stm, const resman_perf_selection_rule *rule)
167 Applies selection rule to the statement.
169 stm - sqlite statement to bind parameters to
170 rule - ???? parameters to be bound to statement
172 Non-OK return values:
173 PCL_ERROR_INVALID_PARAMETER - stm is NULL
174 PCL_ERROR_INVALID_PARAMETER - rule filter type is not PCL_FILTER_UNDEF and rule filter value is NULL
175 PCL_ERROR_DB_FAILED - database error
178 The function assumes that bound parameter is always the first parameter to bind. This might break on some statements.
180 --------------------------------------------------------------------------------
181 resman_base_query create_exec(const resman_perf_selection_rule *rule)
183 Returns a query to be executed based on rule supplied
185 --------------------------------------------------------------------------------
186 int create_netlink(int protocol, int groups)
188 Create netlink socket.
190 Results: Created socket on success and -1 on failure.
192 --------------------------------------------------------------------------------
193 resman_ret_c data_usage_details_foreach(const char *app_id,
194 data_usage_selection_rule *rule,
195 resman_perf_info_cb info_cb, void *user_data)
197 Process data usage details for application on given interval.
199 app_id - null-terminated string containing package name of the application or NULL for all applications
200 rule - parameters of query
201 - from - start of interval
202 - to - end of interval
203 - iface - name of interface or NULL for all interfaces
204 - granularity - split data usage into granularity-sized chunks
205 info_cb - pointer to callback to be executed on each record
206 user_data - pointer to data which will be passed as argument 3 to callback
208 Interval is given as a pair of unix timestamps.
209 If granularity is not supplied the result is the total data usage on the whole interval. Otherwise there will be one record for each chunk.
210 If iface is not supplied there will be one record for each interface.
211 If app_id is not supplied then records will contain total amount of data usage by all applications.
213 info_cb must return PCL_CONTINUE to keep processing results or PCL_CANCEL to stop processing and discard the rest.
216 Callbacks are issued synchronously. When data_usage_details_foreach returns, all callbacks are guaranteed to have been executed already.
217 The function is not thread-safe.
218 If granularity is supplied, interval is split into chunks and each record contains traffic during that chunk.
219 If interface or granularity is supplied and a record contains no traffic, the record is omitted.
222 PCL_ERROR_INVALID_PARAMETER - rule or info_cb is NULL
223 PCL_ERROR_DB_FAILED - database error
225 --------------------------------------------------------------------------------
226 void data_usage_finalize(void)
228 Finalizes queries used in data usage functions
230 --------------------------------------------------------------------------------
231 resman_ret_c data_usage_foreach(const data_usage_selection_rule *rule,
232 resman_perf_info_cb info_cb, void *user_data)
234 Process data usage on given interval.
236 rule - parameters of query
237 - from - start of interval
238 - to - end of interval
239 - iface - name of interface or NULL for all interfaces
240 - granularity - split data usage into granularity-sized chunks
241 info_cb - pointer to callback to be executed on each record
242 user_data - pointer to data which will be passed as argument 3 to callback
244 Interval is given as a pair of unix timestamps. The result contains records for all applications that used network during that interval.
245 If granularity is not supplied each record is the total data usage on the whole interval. Otherwise there is a record for each chunk.
246 If iface is supplied the result is limited to that interface. Otherwise the result is a total of all interfaces.
248 info_cb must return PCL_CONTINUE to keep processing results or PCL_CANCEL to stop processing and discard the rest.
251 Callbacks are issued synchronously. When data_usage_foreach returns, all callbacks are guaranteed to have been executed already.
252 The function is not thread-safe.
253 If granularity is supplied, interval is split into chunks and each record contains traffic during that chunk. If any record contains no traffic, the record is omitted.
256 PCL_ERROR_INVALID_PARAMETER - rule or info_cb is NULL
257 PCL_ERROR_DB_FAILED - database error
259 --------------------------------------------------------------------------------
260 int data_usage_init(sqlite3 *db)
262 Initializes queries used in data usage functions.
264 --------------------------------------------------------------------------------
265 void datausage_quota_finalize(void)
267 Finalizes queries used in data usage quota functions.
269 --------------------------------------------------------------------------------
270 int datausage_quota_init(sqlite3 *db)
272 Initializes queries used in data usage quota functions.
274 --------------------------------------------------------------------------------
275 u_int32_t get_classid_by_pkg_name(const char *pkg_name, int create)
277 Converts application package name to network class.
279 pkg_name - zero-terminated string containing the package name
280 create - if non-zero attempts to create the cgroup for pkg_name before fetching network class ID
282 Returns class ID or 0 in case of error.
284 --------------------------------------------------------------------------------
285 sqlite3 *resourced_get_database(void)
287 Returns the handler to PCL database containing restrictions and statistics.
289 --------------------------------------------------------------------------------
290 int get_family_id(int sock, pid_t pid)
292 Probe the controller in genetlink to find the family id for the TRAF_STAT family. (Helper function)
294 --------------------------------------------------------------------------------
295 void get_in_info(int sock, const pid_t pid, const int family_id,
296 in_traffic_event_list **list)
298 Get list of incoming traffic records from the kernel module.
300 --------------------------------------------------------------------------------
301 void get_out_info(int sock, const pid_t pid,
302 const int family_id, out_traffic_event_list **list)
304 Get list of outgoing traffic records from the kernel module.
306 --------------------------------------------------------------------------------
307 int make_cgroup_with_pid(char *dpg_name, char *app_path)
309 Creates a cgroup named dkg_name if needed and place current process to that cgroup.
311 dpkg_name - name of cgroup
312 app_path - used only for debugging
314 Returns 0 on success -errno on error
317 The name is misleading, PID is not even accepted as a parameter.
318 app_path is used only for debugging and not anywhere in the code
320 --------------------------------------------------------------------------------
321 void notify_daemon(void)
323 Sends SIGUSR1 to the daemon.
325 --------------------------------------------------------------------------------
326 resman_ret_c resman_perf_info_foreach(const resman_perf_selection_rule *rule,
327 resman_perf_info_cb info_cb, void *user_data)
329 Processes network usage statistics based on supplied rule.
331 rule - the rule used for statistics selection
332 info_cb - callback performed on each record
333 user_data - pointer passed as argument 3 to the callback
336 Actual behavior depends largely on the rule.
338 --------------------------------------------------------------------------------
339 resman_ret_c resman_sql_rules_exec(const resman_exec_context *context)
341 Performs the actual query and calls callback on each record.
343 context - contains the rule and callback
348 --------------------------------------------------------------------------------
349 resman_ret_c resman_sql_simple_exec(const resman_exec_context *context)
351 Performs the basic statistics query and calls callback on each record.
353 context - contains the rule and callback
358 --------------------------------------------------------------------------------
359 void put_attr(rt_param *arg, int type, const void *data, int data_len)
361 Write attribute to netlink packet. Helper function.
363 --------------------------------------------------------------------------------
364 int receive_answer(int sock, const int attr_type, char **out_buffer, __u16 *arg_count)
366 Read answer from kernel module. Helper function.
368 --------------------------------------------------------------------------------
369 int revert_net_restriction(u_int32_t classid)
371 Removes network restrictions set by apply_net_restriction.
373 classid - network class ID which will be unrestricted
375 Returns 0 on success, non-zero on failure.
378 Name is a bit misleading in that it removes restrictions, not reverts to previous ones.
380 --------------------------------------------------------------------------------
381 resman_ret_c revert_restriction(const char *app_id)
383 Removes restrictions set by apply_restriction.
385 app_id - zero-terminated string containing package name of application.
388 PCL_ERROR_DB_FAILED - database error
389 ???? - any non-zero value could be returned by revert_net_restriction
392 Does not actually modify CPU or memory limits, only writes new settings to database.
393 Name is misleading in that the function removes restrictions, not reverts to previous ones.
395 --------------------------------------------------------------------------------
396 int send_command(int sock, const pid_t pid, const int family_id, __u8 cmd)
398 Helper function for sending commands to kernel module.
400 --------------------------------------------------------------------------------
401 int send_restriction(int sock, const pid_t pid, const int family_id,
402 const u_int32_t *classids, const u_int16_t classid_count,
403 const enum traffic_restriction_type restriction_type)
405 Internal function used for setting network restrictions.
407 --------------------------------------------------------------------------------
408 void send_start(int sock, const pid_t pid, const int family_id)
410 Helper function used in communicating with kernel module.
412 --------------------------------------------------------------------------------
413 resman_ret_c set_datausage_quota(const char *app_id,
414 const resman_datausage_quota *quota)
416 Sets network traffic quota for application.
418 app_id - zero-terminated string containing package name of the application.
419 quota - network traffic quota to be applied to the application
422 PCL_ERROR_OK - success
423 PCL_ERROR_INVALID_PARAMETER - app_id or quota is NULL
426 Currently only writes quota limits to the database.