// 按照百分比对brick进行设定
gluster volume set test storage.reserve percentage
Option: storage.reserve
Description: Percentage of disk space to be reserved. Set to 0 to disable
Option: storage.reserve-size
Description: If set, priority will be given to storage.reserve-size over storage.reserve
int posix_spawn_disk_space_check_thread(xlator_t *xl)
{
ret = gf_thread_create(&priv->disk_space_check, NULL,
posix_disk_space_check_thread_proc, xl,
"posix_reserve");
}
static void *posix_disk_space_check_thread_proc(void *data) {
posix_disk_space_check(this);
}
void posix_disk_space_check(xlator_t *this)
{
struct posix_private *priv = NULL;
char *subvol_path = NULL;
int op_ret = 0;
double size = 0;
double percent = 0;
struct statvfs buf = {0};
double totsz = 0;
double freesz = 0;
GF_VALIDATE_OR_GOTO("posix-helpers", this, out);
priv = this->private;
GF_VALIDATE_OR_GOTO(this->name, priv, out);
subvol_path = priv->base_path;
// 获取磁盘的总大小
op_ret = sys_statvfs(subvol_path, &buf);
if (op_ret == -1) {
gf_msg(this->name, GF_LOG_ERROR, errno, P_MSG_STATVFS_FAILED,
"statvfs failed on %s", subvol_path);
goto out;
}
// 如果使用的是storage.reserve,则priv->disk_unit值就是'p'
if (priv->disk_unit == 'p') {
percent = priv->disk_reserve;
totsz = (buf.f_blocks * buf.f_bsize);
size = ((totsz * percent) / 100);
} else {
// 如果使用的是storage.reserve-size,则直接是大小,单位是字节。这个字段的初始化是由xlator_option_reconf_percent_or_size来做的
size = priv->disk_reserve;
}
// 计算磁盘剩余的空间大小
freesz = (buf.f_bfree * buf.f_bsize);
// 如果剩余空间小于size,则表示磁盘满了,但是不影响heal线程来检查磁盘的状态
if (freesz <= size) {
priv->disk_space_full = 1;
} else {
priv->disk_space_full = 0;
}
out:
return;
}
GF_OPTION_RECONF("reserve", priv->disk_reserve, options, percent_or_size,out);
// 每个posix操作都会执行 DISK_SPACE_CHECK_AND_GOTO(frame, priv, xdata, ret, ret, unlock) 来检查 disk的空间空间,设置brick对外提供的容量