summaryrefslogtreecommitdiffstats
path: root/libglusterfs
diff options
context:
space:
mode:
authorvmallika <vmallika@redhat.com>2015-04-15 17:35:07 +0530
committerVijay Bellur <vbellur@redhat.com>2015-05-04 03:46:08 -0700
commit821b1fdc893c0dd603d4c43a0b31f1ea495a46c9 (patch)
treea8593c6bc0b1ecbd58350b071b7ae4b5658ea57d /libglusterfs
parent40df2ed4d098d4cd2c6abbed23e497ac3e2e5804 (diff)
quota: support for inode quota in quota.conf
Currently when quota limit is set, corresponding gfid is set in quota.conf. This patch supports storing inode-quota limits in quota.conf and also stores additional byte for each gfid to differentiate between usage quota limit and inode quota limit. Change-Id: I444d7399407594edd280e640681679a784d4c46a BUG: 1202244 Signed-off-by: vmallika <vmallika@redhat.com> Signed-off-by: Sachin Pandit <spandit@redhat.com> Reviewed-on: http://review.gluster.org/10069 Tested-by: NetBSD Build System Tested-by: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Vijay Bellur <vbellur@redhat.com>
Diffstat (limited to 'libglusterfs')
-rw-r--r--libglusterfs/src/common-utils.c45
-rw-r--r--libglusterfs/src/common-utils.h6
-rw-r--r--libglusterfs/src/glusterfs.h1
-rw-r--r--libglusterfs/src/quota-common-utils.c154
-rw-r--r--libglusterfs/src/quota-common-utils.h27
5 files changed, 232 insertions, 1 deletions
diff --git a/libglusterfs/src/common-utils.c b/libglusterfs/src/common-utils.c
index b57066d41da..fc4ae123916 100644
--- a/libglusterfs/src/common-utils.c
+++ b/libglusterfs/src/common-utils.c
@@ -3939,3 +3939,48 @@ glusterfs_is_local_pathinfo (char *pathinfo, gf_boolean_t *is_local)
out:
return ret;
}
+
+ssize_t
+gf_nread (int fd, void *buf, size_t count)
+{
+ ssize_t ret = 0;
+ ssize_t read_bytes = 0;
+
+ for (read_bytes = 0; read_bytes < count; read_bytes += ret) {
+ ret = read (fd, buf + read_bytes, count - read_bytes);
+ if (ret == 0) {
+ break;
+ } else if (ret < 0) {
+ if (errno == EINTR)
+ ret = 0;
+ else
+ goto out;
+ }
+ }
+
+ ret = read_bytes;
+out:
+ return ret;
+}
+
+ssize_t
+gf_nwrite (int fd, const void *buf, size_t count)
+{
+ ssize_t ret = 0;
+ ssize_t written = 0;
+
+ for (written = 0; written != count; written += ret) {
+ ret = write (fd, buf + written, count - written);
+ if (ret < 0) {
+ if (errno == EINTR)
+ ret = 0;
+ else
+ goto out;
+ }
+ }
+
+ ret = written;
+out:
+ return ret;
+}
+
diff --git a/libglusterfs/src/common-utils.h b/libglusterfs/src/common-utils.h
index 235db5fe34b..e8b5fc83591 100644
--- a/libglusterfs/src/common-utils.h
+++ b/libglusterfs/src/common-utils.h
@@ -719,4 +719,10 @@ glusterfs_is_local_pathinfo (char *pathinfo, gf_boolean_t *local);
int
gf_thread_cleanup_xint (pthread_t thread);
+ssize_t
+gf_nread (int fd, void *buf, size_t count);
+
+ssize_t
+gf_nwrite (int fd, const void *buf, size_t count);
+
#endif /* _COMMON_UTILS_H */
diff --git a/libglusterfs/src/glusterfs.h b/libglusterfs/src/glusterfs.h
index 9926d314874..50c86d91467 100644
--- a/libglusterfs/src/glusterfs.h
+++ b/libglusterfs/src/glusterfs.h
@@ -370,7 +370,6 @@ typedef enum {
GF_XATTROP_AND_ARRAY
} gf_xattrop_flags_t;
-
typedef enum {
GF_UPCALL_EVENT_NULL,
GF_UPCALL_CACHE_INVALIDATION,
diff --git a/libglusterfs/src/quota-common-utils.c b/libglusterfs/src/quota-common-utils.c
index ab153209d0d..97965b09947 100644
--- a/libglusterfs/src/quota-common-utils.c
+++ b/libglusterfs/src/quota-common-utils.c
@@ -13,6 +13,7 @@
#include "logging.h"
#include "byte-order.h"
#include "quota-common-utils.h"
+#include "common-utils.h"
int32_t
quota_data_to_meta (data_t *data, char *key, quota_meta_t *meta)
@@ -112,3 +113,156 @@ out:
return ret;
}
+int32_t
+quota_conf_read_header (int fd, char *buf)
+{
+ int header_len = 0;
+ int ret = 0;
+
+ header_len = strlen (QUOTA_CONF_HEADER);
+
+ ret = gf_nread (fd, buf, header_len);
+ if (ret <= 0) {
+ goto out;
+ } else if (ret > 0 && ret != header_len) {
+ ret = -1;
+ goto out;
+ }
+
+ buf[header_len-1] = 0;
+
+out:
+ if (ret < 0)
+ gf_log_callingfn ("quota", GF_LOG_ERROR, "failed to read "
+ "header from a quota conf");
+
+ return ret;
+}
+
+int32_t
+quota_conf_read_version (int fd, float *version)
+{
+ int ret = 0;
+ char buf[PATH_MAX] = "";
+ char *tail = NULL;
+ float value = 0.0f;
+
+ ret = quota_conf_read_header (fd, buf);
+ if (ret == 0) {
+ /* quota.conf is empty */
+ value = GF_QUOTA_CONF_VERSION;
+ goto out;
+ } else if (ret < 0) {
+ goto out;
+ }
+
+ value = strtof ((buf + strlen(buf) - 3), &tail);
+ if (tail[0] != '\0') {
+ ret = -1;
+ gf_log_callingfn ("quota", GF_LOG_ERROR, "invalid quota conf "
+ "version");
+ goto out;
+ }
+
+ ret = 0;
+
+out:
+ if (ret >= 0)
+ *version = value;
+ else
+ gf_log_callingfn ("quota", GF_LOG_ERROR, "failed to read "
+ "version from a quota conf header");
+
+ return ret;
+}
+
+int32_t
+quota_conf_write_header (int fd)
+{
+ int header_len = 0;
+ int ret = 0;
+
+ header_len = strlen (QUOTA_CONF_HEADER);
+
+ ret = gf_nwrite (fd, QUOTA_CONF_HEADER, header_len);
+ if (ret != header_len) {
+ ret = -1;
+ goto out;
+ }
+
+ ret = 0;
+
+out:
+ if (ret < 0)
+ gf_log_callingfn ("quota", GF_LOG_ERROR, "failed to write "
+ "header to a quota conf");
+
+ return ret;
+}
+
+int32_t
+quota_conf_write_gfid (int fd, void *buf, char type)
+{
+ int ret = 0;
+
+ ret = gf_nwrite (fd, buf, 16);
+ if (ret != 16) {
+ ret = -1;
+ goto out;
+ }
+
+ ret = gf_nwrite (fd, &type, 1);
+ if (ret != 1) {
+ ret = -1;
+ goto out;
+ }
+
+ ret = 0;
+
+out:
+ if (ret < 0)
+ gf_log_callingfn ("quota", GF_LOG_ERROR, "failed to write "
+ "gfid %s to a quota conf", uuid_utoa (buf));
+
+ return ret;
+}
+
+int32_t
+quota_conf_read_gfid (int fd, void *buf, char *type, float version)
+{
+ int ret = 0;
+
+ ret = gf_nread (fd, buf, 16);
+ if (ret <= 0)
+ goto out;
+
+ if (ret != 16) {
+ ret = -1;
+ goto out;
+ }
+
+ if (version >= 1.2f) {
+ ret = gf_nread (fd, type, 1);
+ if (ret != 1) {
+ ret = -1;
+ goto out;
+ }
+ ret = 17;
+ } else {
+ *type = GF_QUOTA_CONF_TYPE_USAGE;
+ }
+
+out:
+ if (ret < 0)
+ gf_log_callingfn ("quota", GF_LOG_ERROR, "failed to read "
+ "gfid from a quota conf");
+
+ return ret;
+}
+
+int32_t
+quota_conf_skip_header (int fd)
+{
+ return gf_skip_header_section (fd, strlen (QUOTA_CONF_HEADER));
+}
+
diff --git a/libglusterfs/src/quota-common-utils.h b/libglusterfs/src/quota-common-utils.h
index eff86850dd5..e80c74cba72 100644
--- a/libglusterfs/src/quota-common-utils.h
+++ b/libglusterfs/src/quota-common-utils.h
@@ -13,6 +13,15 @@
#include "iatt.h"
+#define GF_QUOTA_CONF_VERSION 1.2
+#define QUOTA_CONF_HEADER \
+ "GlusterFS Quota conf | version: v1.2\n"
+
+typedef enum {
+ GF_QUOTA_CONF_TYPE_USAGE = 1,
+ GF_QUOTA_CONF_TYPE_OBJECTS
+} gf_quota_conf_type_t;
+
struct _quota_limits {
int64_t hl;
int64_t sl;
@@ -36,4 +45,22 @@ int32_t
quota_dict_set_meta (dict_t *dict, char *key, const quota_meta_t *meta,
ia_type_t ia_type);
+int32_t
+quota_conf_read_header (int fd, char *buf);
+
+int32_t
+quota_conf_read_version (int fd, float *version);
+
+int32_t
+quota_conf_write_header (int fd);
+
+int32_t
+quota_conf_write_gfid (int fd, void *buf, char type);
+
+int32_t
+quota_conf_read_gfid (int fd, void *buf, char *type, float version);
+
+int32_t
+quota_conf_skip_header (int fd);
+
#endif /* _QUOTA_COMMON_UTILS_H */