-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathxsiostat_flt.c
85 lines (73 loc) · 2.07 KB
/
xsiostat_flt.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*
* -----------------------------
* XenServer Storage I/O Stats
* -----------------------------
* xsiostat_flt.c
* ----------------
*
* Copyright (C) 2013, 2014 Citrix Systems Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation; version 2.1 only. with the special
* exception on linking described in file LICENSE.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*/
// Header files
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <sys/queue.h>
#include "xsiostat.h"
int
flt_isset(xsis_flts_t *flts, uint32_t filter){
// Local variables
xsis_flt_t *flt; // Temporary FLT pointer
int isset = 0; // Return code
// Check if filter is already in list
LIST_FOREACH(flt, flts, flts)
if (flt->filter == filter){
isset = 1;
break;
}
// Return
return(isset);
}
int
flt_add(xsis_flts_t *flts, uint32_t filter){
// Local variables
xsis_flt_t *flt; // Temporary FLT pointer
int err = 0; // Return code
// Check if filter is already in list
if (flt_isset(flts, filter))
goto err;
// Allocate new filter and insert into list
if (!(flt = (xsis_flt_t *)calloc(1, sizeof(xsis_flt_t)))){
perror("calloc");
goto err;
}
flt->filter = filter;
LIST_INSERT_HEAD(flts, flt, flts);
out:
// Return
return(err);
err:
err = 1;
goto out;
}
void
flts_free(xsis_flts_t *flts){
// Local variables
xsis_flt_t *flt; // Temporary FLT pointer
// Loop through FLTs, freeing resources
LIST_FOREACH(flt, flts, flts){
LIST_REMOVE(flt, flts);
free(flt);
}
// Return
return;
}