summaryrefslogtreecommitdiffstats
path: root/xlators/mgmt/glusterd/src/glusterd-quota.c
diff options
context:
space:
mode:
Diffstat (limited to 'xlators/mgmt/glusterd/src/glusterd-quota.c')
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-quota.c101
1 files changed, 68 insertions, 33 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-quota.c b/xlators/mgmt/glusterd/src/glusterd-quota.c
index d2fefeff9f0..8370c174ce3 100644
--- a/xlators/mgmt/glusterd/src/glusterd-quota.c
+++ b/xlators/mgmt/glusterd/src/glusterd-quota.c
@@ -7,22 +7,21 @@
later), or the GNU General Public License, version 2 (GPLv2), in all
cases as published by the Free Software Foundation.
*/
-#include "common-utils.h"
+#include <glusterfs/common-utils.h>
#include "cli1-xdr.h"
#include "xdr-generic.h"
#include "glusterd.h"
#include "glusterd-op-sm.h"
#include "glusterd-store.h"
#include "glusterd-utils.h"
-#include "glusterd-nfs-svc.h"
#include "glusterd-quotad-svc.h"
#include "glusterd-volgen.h"
#include "glusterd-messages.h"
-#include "run.h"
-#include "syscall.h"
-#include "byte-order.h"
-#include "compat-errno.h"
-#include "quota-common-utils.h"
+#include <glusterfs/run.h>
+#include <glusterfs/syscall.h>
+#include <glusterfs/byte-order.h>
+#include <glusterfs/compat-errno.h>
+#include <glusterfs/quota-common-utils.h>
#include "glusterd-quota.h"
#include <sys/wait.h>
@@ -40,6 +39,49 @@
/* Any negative pid to make it special client */
#define QUOTA_CRAWL_PID "-100"
+#define GLUSTERFS_GET_QUOTA_LIMIT_MOUNT_PIDFILE(pidfile, volname) \
+ { \
+ snprintf(pidfile, PATH_MAX - 1, \
+ DEFAULT_VAR_RUN_DIRECTORY "/%s_quota_limit.pid", volname); \
+ }
+
+#define GLUSTERFS_GET_QUOTA_LIST_MOUNT_PIDFILE(pidfile, volname) \
+ { \
+ snprintf(pidfile, PATH_MAX - 1, \
+ DEFAULT_VAR_RUN_DIRECTORY "/%s_quota_list.pid", volname); \
+ }
+
+#define GLUSTERD_GET_QUOTA_CRAWL_PIDDIR(piddir, volinfo, type) \
+ do { \
+ char _volpath[PATH_MAX] = { \
+ 0, \
+ }; \
+ int32_t _crawl_pid_len; \
+ GLUSTERD_GET_VOLUME_DIR(_volpath, volinfo, priv); \
+ if (type == GF_QUOTA_OPTION_TYPE_ENABLE || \
+ type == GF_QUOTA_OPTION_TYPE_ENABLE_OBJECTS) \
+ _crawl_pid_len = snprintf(piddir, PATH_MAX, "%s/run/quota/enable", \
+ _volpath); \
+ else \
+ _crawl_pid_len = snprintf(piddir, PATH_MAX, \
+ "%s/run/quota/disable", _volpath); \
+ if ((_crawl_pid_len < 0) || (_crawl_pid_len >= PATH_MAX)) { \
+ piddir[0] = 0; \
+ } \
+ } while (0)
+
+#define GLUSTERD_GET_TMP_PATH(abspath, path) \
+ do { \
+ snprintf(abspath, sizeof(abspath) - 1, \
+ DEFAULT_VAR_RUN_DIRECTORY "/tmp%s", path); \
+ } while (0)
+
+#define GLUSTERD_GET_QUOTA_LIST_MOUNT_PATH(abspath, volname, path) \
+ do { \
+ snprintf(abspath, sizeof(abspath) - 1, \
+ DEFAULT_VAR_RUN_DIRECTORY "/%s_quota_list%s", volname, path); \
+ } while (0)
+
const char *gd_quota_op_list[GF_QUOTA_OPTION_TYPE_MAX + 1] = {
[GF_QUOTA_OPTION_TYPE_NONE] = "none",
[GF_QUOTA_OPTION_TYPE_ENABLE] = "enable",
@@ -266,7 +308,7 @@ _glusterd_quota_initiate_fs_crawl(glusterd_conf_t *priv,
GF_VALIDATE_OR_GOTO("glusterd", THIS, out);
GLUSTERD_GET_TMP_PATH(mountdir, "/");
- ret = sys_mkdir(mountdir, 0777);
+ ret = sys_mkdir(mountdir, 0755);
if (ret && errno != EEXIST) {
gf_msg(THIS->name, GF_LOG_WARNING, errno, GD_MSG_MOUNT_REQ_FAIL,
"failed to create temporary "
@@ -436,8 +478,9 @@ glusterd_stop_all_quota_crawl_service(glusterd_conf_t *priv,
if (dir == NULL)
return;
- GF_SKIP_IRRELEVANT_ENTRIES(entry, dir, scratch);
- while (entry) {
+ while ((entry = sys_readdir(dir, scratch))) {
+ if (gf_irrelevant_entry(entry))
+ continue;
len = snprintf(pidfile, sizeof(pidfile), "%s/%s", pid_dir,
entry->d_name);
if ((len >= 0) && (len < sizeof(pidfile))) {
@@ -445,8 +488,6 @@ glusterd_stop_all_quota_crawl_service(glusterd_conf_t *priv,
_gf_true);
sys_unlink(pidfile);
}
-
- GF_SKIP_IRRELEVANT_ENTRIES(entry, dir, scratch);
}
sys_closedir(dir);
}
@@ -470,7 +511,7 @@ glusterd_quota_initiate_fs_crawl(glusterd_conf_t *priv,
goto out;
}
- ret = mkdir_p(DEFAULT_QUOTA_CRAWL_LOG_DIRECTORY, 0777, _gf_true);
+ ret = mkdir_p(DEFAULT_QUOTA_CRAWL_LOG_DIRECTORY, 0755, _gf_true);
if (ret) {
gf_msg(THIS->name, GF_LOG_ERROR, errno, GD_MSG_GLUSTERD_OP_FAILED,
"failed to create dir %s: %s", DEFAULT_QUOTA_CRAWL_LOG_DIRECTORY,
@@ -479,7 +520,7 @@ glusterd_quota_initiate_fs_crawl(glusterd_conf_t *priv,
}
GLUSTERD_GET_QUOTA_CRAWL_PIDDIR(pid_dir, volinfo, type);
- ret = mkdir_p(pid_dir, 0777, _gf_true);
+ ret = mkdir_p(pid_dir, 0755, _gf_true);
if (ret) {
gf_msg(THIS->name, GF_LOG_ERROR, errno, GD_MSG_GLUSTERD_OP_FAILED,
"failed to create dir %s: %s", pid_dir, strerror(errno));
@@ -540,8 +581,7 @@ glusterd_quota_get_default_soft_limit(glusterd_volinfo_t *volinfo,
else
val = gf_strdup("80%");
- ret = dict_set_dynstrn(rsp_dict, "default-soft-limit",
- SLEN("default-soft-limit"), val);
+ ret = dict_set_dynstr_sizen(rsp_dict, "default-soft-limit", val);
if (ret) {
gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED,
"Failed to set default "
@@ -771,6 +811,7 @@ glusterd_set_quota_limit(char *volname, char *path, char *hard_limit,
0,
};
double soft_limit_double = 0;
+ int64_t local_hl = 0;
this = THIS;
GF_ASSERT(this);
@@ -820,11 +861,11 @@ glusterd_set_quota_limit(char *volname, char *path, char *hard_limit,
new_limit.sl = hton64(new_limit.sl);
- ret = gf_string2bytesize_int64(hard_limit, &new_limit.hl);
+ ret = gf_string2bytesize_int64(hard_limit, &local_hl);
if (ret)
goto out;
- new_limit.hl = hton64(new_limit.hl);
+ new_limit.hl = hton64(local_hl);
ret = sys_lsetxattr(abspath, key, (char *)(void *)&new_limit,
sizeof(new_limit), 0);
@@ -1766,10 +1807,12 @@ glusterd_op_quota(dict_t *dict, char **op_errstr, dict_t *rsp_dict)
goto out;
}
+#if BUILD_GNFS
if (GLUSTERD_STATUS_STARTED == volinfo->status) {
if (priv->op_version == GD_OP_VERSION_MIN)
(void)priv->nfs_svc.manager(&(priv->nfs_svc), NULL, 0);
}
+#endif
if (rsp_dict && start_crawl == _gf_true)
glusterd_quota_initiate_fs_crawl(priv, volinfo, type);
@@ -1856,10 +1899,9 @@ glusterd_get_gfid_from_brick(dict_t *dict, glusterd_volinfo_t *volinfo,
}
ret = sys_lgetxattr(backend_path, GFID_XATTR_KEY, gfid, 16);
if (ret < 0) {
- gf_msg(this->name, GF_LOG_INFO, errno, GD_MSG_SETXATTR_FAIL,
- "Failed to get "
- "extended attribute %s for directory %s. ",
- GFID_XATTR_KEY, backend_path);
+ gf_smsg(this->name, GF_LOG_INFO, errno, GD_MSG_GET_XATTR_FAIL,
+ "Attribute=%s, Directory=%s", GFID_XATTR_KEY, backend_path,
+ NULL);
ret = 0;
continue;
}
@@ -1995,7 +2037,7 @@ glusterd_create_quota_auxiliary_mount(xlator_t *this, char *volname, int type)
fclose(file);
}
- ret = sys_mkdir(mountdir, 0777);
+ ret = sys_mkdir(mountdir, 0755);
if (ret && errno != EEXIST) {
gf_msg(this->name, GF_LOG_ERROR, errno, GD_MSG_MOUNT_REQ_FAIL,
"Failed to create auxiliary "
@@ -2003,8 +2045,8 @@ glusterd_create_quota_auxiliary_mount(xlator_t *this, char *volname, int type)
mountdir);
goto out;
}
- snprintf(logfile, PATH_MAX - 1, "%s/quota-mount-%s.log",
- DEFAULT_LOG_FILE_DIRECTORY, volname);
+ snprintf(logfile, PATH_MAX - 1, "%s/quota-mount-%s.log", priv->logdir,
+ volname);
snprintf(qpid, 15, "%d", GF_CLIENT_PID_QUOTA_MOUNT);
if (dict_get_strn(this->options, "transport.socket.bind-address",
@@ -2051,7 +2093,6 @@ glusterd_op_stage_quota(dict_t *dict, char **op_errstr, dict_t *rsp_dict)
{
int ret = 0;
char *volname = NULL;
- gf_boolean_t exists = _gf_false;
int type = 0;
xlator_t *this = NULL;
glusterd_conf_t *priv = NULL;
@@ -2075,12 +2116,6 @@ glusterd_op_stage_quota(dict_t *dict, char **op_errstr, dict_t *rsp_dict)
goto out;
}
- exists = glusterd_check_volume_exists(volname);
- if (!exists) {
- gf_asprintf(op_errstr, FMTSTR_CHECK_VOL_EXISTS, volname);
- ret = -1;
- goto out;
- }
ret = glusterd_volinfo_find(volname, &volinfo);
if (ret) {
gf_asprintf(op_errstr, FMTSTR_CHECK_VOL_EXISTS, volname);
@@ -2174,7 +2209,7 @@ glusterd_op_stage_quota(dict_t *dict, char **op_errstr, dict_t *rsp_dict)
gf_asprintf(op_errstr,
"Hard-limit "
"value out of range (0 - %" PRId64 "): %s",
- hard_limit_str);
+ hard_limit, hard_limit_str);
else
gf_msg(this->name, GF_LOG_ERROR, errno,
GD_MSG_CONVERSION_FAILED,