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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
|
/*
Copyright (c) 2009 Z RESEARCH, Inc. <http://www.zresearch.com>
This file is part of GlusterFS.
GlusterFS is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
by the Free Software Foundation; either version 3 of the License,
or (at your option) any later version.
GlusterFS 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
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see
<http://www.gnu.org/licenses/>.
*/
#ifndef _CONFIG_H
#define _CONFIG_H
#include "config.h"
#endif
/* TODO: add NS locking */
#include "glusterfs.h"
#include "xlator.h"
#include "dht-common.h"
#include "defaults.h"
#include <sys/time.h>
int
dht_du_info_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
int op_ret, int op_errno, struct statvfs *statvfs)
{
dht_conf_t *conf = NULL;
dht_local_t *local = NULL;
call_frame_t *prev = NULL;
int this_call_cnt = 0;
int i = 0;
double percent = 0;
local = frame->local;
conf = this->private;
prev = cookie;
if (op_ret == -1)
goto out;
percent = (statvfs->f_bfree * 100) / statvfs->f_blocks;
LOCK (&conf->subvolume_lock);
{
for (i = 0; i < conf->subvolume_cnt; i++)
if (prev->this == conf->subvolumes[i])
conf->du_stats[i].avail_percent = percent;
}
UNLOCK (&conf->subvolume_lock);
out:
this_call_cnt = dht_frame_return (frame);
if (is_last_call (this_call_cnt))
DHT_STACK_DESTROY (frame);
return 0;
}
int
dht_get_du_info (call_frame_t *frame, xlator_t *this, loc_t *loc)
{
int i = 0;
dht_conf_t *conf = NULL;
call_frame_t *statfs_frame = NULL;
dht_local_t *statfs_local = NULL;
struct timeval tv = {0,};
conf = this->private;
gettimeofday (&tv, NULL);
if (tv.tv_sec > (conf->refresh_interval
+ conf->last_stat_fetch.tv_sec)) {
statfs_frame = copy_frame (frame);
if (!statfs_frame) {
gf_log (this->name, GF_LOG_ERROR,
"memory allocation failed :(");
goto err;
}
statfs_local = dht_local_init (statfs_frame);
if (!statfs_local) {
gf_log (this->name, GF_LOG_ERROR,
"memory allocation failed :(");
goto err;
}
loc_copy (&statfs_local->loc, loc);
loc_t tmp_loc = { .inode = NULL,
.path = "/",
};
for (i = 0; i < conf->subvolume_cnt; i++) {
STACK_WIND (statfs_frame, dht_du_info_cbk,
conf->subvolumes[i],
conf->subvolumes[i]->fops->statfs,
&tmp_loc);
}
conf->last_stat_fetch.tv_sec = tv.tv_sec;
}
return 0;
err:
if (statfs_frame)
DHT_STACK_DESTROY (statfs_frame);
return -1;
}
int
dht_is_subvol_filled (xlator_t *this, xlator_t *subvol)
{
int i = 0;
int subvol_filled = 0;
dht_conf_t *conf = NULL;
conf = this->private;
/* Check for values above 90% free disk */
LOCK (&conf->subvolume_lock);
{
for (i = 0; i < conf->subvolume_cnt; i++) {
if ((subvol == conf->subvolumes[i]) &&
(conf->du_stats[i].avail_percent <
conf->min_free_disk)) {
subvol_filled = 1;
break;
}
}
}
UNLOCK (&conf->subvolume_lock);
if (subvol_filled) {
if (!(conf->du_stats[i].log++ % GF_UNIVERSAL_ANSWER)) {
gf_log (this->name, GF_LOG_CRITICAL,
"disk space on subvolume '%s' is getting "
"full(%f), consider adding more nodes",
subvol->name, conf->du_stats[i].avail_percent);
}
}
return subvol_filled;
}
xlator_t *
dht_free_disk_available_subvol (xlator_t *this, xlator_t *subvol)
{
int i = 0;
double max_avail = 0;
xlator_t *avail_subvol = NULL;
dht_conf_t *conf = NULL;
conf = this->private;
avail_subvol = subvol;
LOCK (&conf->subvolume_lock);
{
for (i = 0; i < conf->subvolume_cnt; i++) {
if (conf->du_stats[i].avail_percent > max_avail) {
max_avail = conf->du_stats[i].avail_percent;
avail_subvol = conf->subvolumes[i];
}
}
}
UNLOCK (&conf->subvolume_lock);
if (avail_subvol == subvol) {
gf_log (this->name, GF_LOG_CRITICAL,
"no node has enough free space :O");
}
return avail_subvol;
}
|