|
|
c5d8c8 |
From a7a56c079df2eb0253efdd53e1538656c0ce9095 Mon Sep 17 00:00:00 2001
|
|
|
c5d8c8 |
From: Yaniv Kaul <ykaul@redhat.com>
|
|
|
c5d8c8 |
Date: Mon, 25 Nov 2019 15:37:46 +0200
|
|
|
c5d8c8 |
Subject: [PATCH 564/584] store.c/glusterd-store.c: remove sys_stat calls
|
|
|
c5d8c8 |
|
|
|
c5d8c8 |
Instead of querying for the file size and allocating a char array
|
|
|
c5d8c8 |
according to its size, let's just use a fixed size.
|
|
|
c5d8c8 |
Those calls are not really needed, and are either expensive or
|
|
|
c5d8c8 |
cached anyway. Since we do dynamic allocation/free, let's just use
|
|
|
c5d8c8 |
a fixed array instead.
|
|
|
c5d8c8 |
|
|
|
c5d8c8 |
I'll see if there are other sys_stat() calls that are not really
|
|
|
c5d8c8 |
useful and try to eliminate them in separate patches.
|
|
|
c5d8c8 |
|
|
|
c5d8c8 |
Backport of:
|
|
|
c5d8c8 |
> Upstream-patch: https://review.gluster.org/#/c/glusterfs/+/23752/
|
|
|
c5d8c8 |
> Change-Id: I76b40e78a52ab38f613fc0cdef4be60e6253bf20
|
|
|
c5d8c8 |
> updates: bz#1193929
|
|
|
c5d8c8 |
> Signed-off-by: Yaniv Kaul <ykaul@redhat.com>
|
|
|
c5d8c8 |
|
|
|
c5d8c8 |
BUG: 1925425
|
|
|
c5d8c8 |
Change-Id: I76b40e78a52ab38f613fc0cdef4be60e6253bf20
|
|
|
c5d8c8 |
Signed-off-by: Yaniv Kaul <ykaul@redhat.com>
|
|
|
c5d8c8 |
Reviewed-on: https://code.engineering.redhat.com/gerrit/c/rhs-glusterfs/+/244958
|
|
|
c5d8c8 |
Tested-by: RHGS Build Bot <nigelb@redhat.com>
|
|
|
c5d8c8 |
Reviewed-by: Sunil Kumar Heggodu Gopala Acharya <sheggodu@redhat.com>
|
|
|
c5d8c8 |
---
|
|
|
c5d8c8 |
libglusterfs/src/glusterfs/store.h | 4 +-
|
|
|
c5d8c8 |
libglusterfs/src/store.c | 71 ++++--------------------------
|
|
|
c5d8c8 |
xlators/mgmt/glusterd/src/glusterd-store.c | 5 +--
|
|
|
c5d8c8 |
3 files changed, 12 insertions(+), 68 deletions(-)
|
|
|
c5d8c8 |
|
|
|
c5d8c8 |
diff --git a/libglusterfs/src/glusterfs/store.h b/libglusterfs/src/glusterfs/store.h
|
|
|
c5d8c8 |
index 3b3a24c..f63bd05 100644
|
|
|
c5d8c8 |
--- a/libglusterfs/src/glusterfs/store.h
|
|
|
c5d8c8 |
+++ b/libglusterfs/src/glusterfs/store.h
|
|
|
c5d8c8 |
@@ -59,8 +59,8 @@ int32_t
|
|
|
c5d8c8 |
gf_store_unlink_tmppath(gf_store_handle_t *shandle);
|
|
|
c5d8c8 |
|
|
|
c5d8c8 |
int
|
|
|
c5d8c8 |
-gf_store_read_and_tokenize(FILE *file, char *str, int size, char **iter_key,
|
|
|
c5d8c8 |
- char **iter_val, gf_store_op_errno_t *store_errno);
|
|
|
c5d8c8 |
+gf_store_read_and_tokenize(FILE *file, char **iter_key, char **iter_val,
|
|
|
c5d8c8 |
+ gf_store_op_errno_t *store_errno);
|
|
|
c5d8c8 |
|
|
|
c5d8c8 |
int32_t
|
|
|
c5d8c8 |
gf_store_retrieve_value(gf_store_handle_t *handle, char *key, char **value);
|
|
|
c5d8c8 |
diff --git a/libglusterfs/src/store.c b/libglusterfs/src/store.c
|
|
|
c5d8c8 |
index cdf0aea..fa3649b 100644
|
|
|
c5d8c8 |
--- a/libglusterfs/src/store.c
|
|
|
c5d8c8 |
+++ b/libglusterfs/src/store.c
|
|
|
c5d8c8 |
@@ -184,8 +184,8 @@ out:
|
|
|
c5d8c8 |
}
|
|
|
c5d8c8 |
|
|
|
c5d8c8 |
int
|
|
|
c5d8c8 |
-gf_store_read_and_tokenize(FILE *file, char *str, int size, char **iter_key,
|
|
|
c5d8c8 |
- char **iter_val, gf_store_op_errno_t *store_errno)
|
|
|
c5d8c8 |
+gf_store_read_and_tokenize(FILE *file, char **iter_key, char **iter_val,
|
|
|
c5d8c8 |
+ gf_store_op_errno_t *store_errno)
|
|
|
c5d8c8 |
{
|
|
|
c5d8c8 |
int32_t ret = -1;
|
|
|
c5d8c8 |
char *savetok = NULL;
|
|
|
c5d8c8 |
@@ -193,15 +193,15 @@ gf_store_read_and_tokenize(FILE *file, char *str, int size, char **iter_key,
|
|
|
c5d8c8 |
char *value = NULL;
|
|
|
c5d8c8 |
char *temp = NULL;
|
|
|
c5d8c8 |
size_t str_len = 0;
|
|
|
c5d8c8 |
+ char str[8192];
|
|
|
c5d8c8 |
|
|
|
c5d8c8 |
GF_ASSERT(file);
|
|
|
c5d8c8 |
- GF_ASSERT(str);
|
|
|
c5d8c8 |
GF_ASSERT(iter_key);
|
|
|
c5d8c8 |
GF_ASSERT(iter_val);
|
|
|
c5d8c8 |
GF_ASSERT(store_errno);
|
|
|
c5d8c8 |
|
|
|
c5d8c8 |
retry:
|
|
|
c5d8c8 |
- temp = fgets(str, size, file);
|
|
|
c5d8c8 |
+ temp = fgets(str, 8192, file);
|
|
|
c5d8c8 |
if (temp == NULL || feof(file)) {
|
|
|
c5d8c8 |
ret = -1;
|
|
|
c5d8c8 |
*store_errno = GD_STORE_EOF;
|
|
|
c5d8c8 |
@@ -241,13 +241,8 @@ int32_t
|
|
|
c5d8c8 |
gf_store_retrieve_value(gf_store_handle_t *handle, char *key, char **value)
|
|
|
c5d8c8 |
{
|
|
|
c5d8c8 |
int32_t ret = -1;
|
|
|
c5d8c8 |
- char *scan_str = NULL;
|
|
|
c5d8c8 |
char *iter_key = NULL;
|
|
|
c5d8c8 |
char *iter_val = NULL;
|
|
|
c5d8c8 |
- char *free_str = NULL;
|
|
|
c5d8c8 |
- struct stat st = {
|
|
|
c5d8c8 |
- 0,
|
|
|
c5d8c8 |
- };
|
|
|
c5d8c8 |
gf_store_op_errno_t store_errno = GD_STORE_SUCCESS;
|
|
|
c5d8c8 |
|
|
|
c5d8c8 |
GF_ASSERT(handle);
|
|
|
c5d8c8 |
@@ -279,32 +274,9 @@ gf_store_retrieve_value(gf_store_handle_t *handle, char *key, char **value)
|
|
|
c5d8c8 |
} else {
|
|
|
c5d8c8 |
fseek(handle->read, 0, SEEK_SET);
|
|
|
c5d8c8 |
}
|
|
|
c5d8c8 |
- ret = sys_fstat(handle->fd, &st);
|
|
|
c5d8c8 |
- if (ret < 0) {
|
|
|
c5d8c8 |
- gf_msg("", GF_LOG_WARNING, errno, LG_MSG_FILE_OP_FAILED,
|
|
|
c5d8c8 |
- "stat on file %s failed", handle->path);
|
|
|
c5d8c8 |
- ret = -1;
|
|
|
c5d8c8 |
- store_errno = GD_STORE_STAT_FAILED;
|
|
|
c5d8c8 |
- goto out;
|
|
|
c5d8c8 |
- }
|
|
|
c5d8c8 |
-
|
|
|
c5d8c8 |
- /* "st.st_size + 1" is used as we are fetching each
|
|
|
c5d8c8 |
- * line of a file using fgets, fgets will append "\0"
|
|
|
c5d8c8 |
- * to the end of the string
|
|
|
c5d8c8 |
- */
|
|
|
c5d8c8 |
- scan_str = GF_CALLOC(1, st.st_size + 1, gf_common_mt_char);
|
|
|
c5d8c8 |
-
|
|
|
c5d8c8 |
- if (scan_str == NULL) {
|
|
|
c5d8c8 |
- ret = -1;
|
|
|
c5d8c8 |
- store_errno = GD_STORE_ENOMEM;
|
|
|
c5d8c8 |
- goto out;
|
|
|
c5d8c8 |
- }
|
|
|
c5d8c8 |
-
|
|
|
c5d8c8 |
- free_str = scan_str;
|
|
|
c5d8c8 |
-
|
|
|
c5d8c8 |
do {
|
|
|
c5d8c8 |
- ret = gf_store_read_and_tokenize(handle->read, scan_str, st.st_size + 1,
|
|
|
c5d8c8 |
- &iter_key, &iter_val, &store_errno);
|
|
|
c5d8c8 |
+ ret = gf_store_read_and_tokenize(handle->read, &iter_key, &iter_val,
|
|
|
c5d8c8 |
+ &store_errno);
|
|
|
c5d8c8 |
if (ret < 0) {
|
|
|
c5d8c8 |
gf_msg_trace("", 0,
|
|
|
c5d8c8 |
"error while reading key '%s': "
|
|
|
c5d8c8 |
@@ -334,8 +306,6 @@ out:
|
|
|
c5d8c8 |
sys_close(handle->fd);
|
|
|
c5d8c8 |
}
|
|
|
c5d8c8 |
|
|
|
c5d8c8 |
- GF_FREE(free_str);
|
|
|
c5d8c8 |
-
|
|
|
c5d8c8 |
return ret;
|
|
|
c5d8c8 |
}
|
|
|
c5d8c8 |
|
|
|
c5d8c8 |
@@ -561,40 +531,16 @@ gf_store_iter_get_next(gf_store_iter_t *iter, char **key, char **value,
|
|
|
c5d8c8 |
gf_store_op_errno_t *op_errno)
|
|
|
c5d8c8 |
{
|
|
|
c5d8c8 |
int32_t ret = -1;
|
|
|
c5d8c8 |
- char *scan_str = NULL;
|
|
|
c5d8c8 |
char *iter_key = NULL;
|
|
|
c5d8c8 |
char *iter_val = NULL;
|
|
|
c5d8c8 |
- struct stat st = {
|
|
|
c5d8c8 |
- 0,
|
|
|
c5d8c8 |
- };
|
|
|
c5d8c8 |
gf_store_op_errno_t store_errno = GD_STORE_SUCCESS;
|
|
|
c5d8c8 |
|
|
|
c5d8c8 |
GF_ASSERT(iter);
|
|
|
c5d8c8 |
GF_ASSERT(key);
|
|
|
c5d8c8 |
GF_ASSERT(value);
|
|
|
c5d8c8 |
|
|
|
c5d8c8 |
- ret = sys_stat(iter->filepath, &st);
|
|
|
c5d8c8 |
- if (ret < 0) {
|
|
|
c5d8c8 |
- gf_msg("", GF_LOG_WARNING, errno, LG_MSG_FILE_OP_FAILED,
|
|
|
c5d8c8 |
- "stat on file failed");
|
|
|
c5d8c8 |
- ret = -1;
|
|
|
c5d8c8 |
- store_errno = GD_STORE_STAT_FAILED;
|
|
|
c5d8c8 |
- goto out;
|
|
|
c5d8c8 |
- }
|
|
|
c5d8c8 |
-
|
|
|
c5d8c8 |
- /* "st.st_size + 1" is used as we are fetching each
|
|
|
c5d8c8 |
- * line of a file using fgets, fgets will append "\0"
|
|
|
c5d8c8 |
- * to the end of the string
|
|
|
c5d8c8 |
- */
|
|
|
c5d8c8 |
- scan_str = GF_CALLOC(1, st.st_size + 1, gf_common_mt_char);
|
|
|
c5d8c8 |
- if (!scan_str) {
|
|
|
c5d8c8 |
- ret = -1;
|
|
|
c5d8c8 |
- store_errno = GD_STORE_ENOMEM;
|
|
|
c5d8c8 |
- goto out;
|
|
|
c5d8c8 |
- }
|
|
|
c5d8c8 |
-
|
|
|
c5d8c8 |
- ret = gf_store_read_and_tokenize(iter->file, scan_str, st.st_size + 1,
|
|
|
c5d8c8 |
- &iter_key, &iter_val, &store_errno);
|
|
|
c5d8c8 |
+ ret = gf_store_read_and_tokenize(iter->file, &iter_key, &iter_val,
|
|
|
c5d8c8 |
+ &store_errno);
|
|
|
c5d8c8 |
if (ret < 0) {
|
|
|
c5d8c8 |
goto out;
|
|
|
c5d8c8 |
}
|
|
|
c5d8c8 |
@@ -619,7 +565,6 @@ gf_store_iter_get_next(gf_store_iter_t *iter, char **key, char **value,
|
|
|
c5d8c8 |
ret = 0;
|
|
|
c5d8c8 |
|
|
|
c5d8c8 |
out:
|
|
|
c5d8c8 |
- GF_FREE(scan_str);
|
|
|
c5d8c8 |
if (ret) {
|
|
|
c5d8c8 |
GF_FREE(*key);
|
|
|
c5d8c8 |
GF_FREE(*value);
|
|
|
c5d8c8 |
diff --git a/xlators/mgmt/glusterd/src/glusterd-store.c b/xlators/mgmt/glusterd/src/glusterd-store.c
|
|
|
c5d8c8 |
index 4fa8116..da63c03 100644
|
|
|
c5d8c8 |
--- a/xlators/mgmt/glusterd/src/glusterd-store.c
|
|
|
c5d8c8 |
+++ b/xlators/mgmt/glusterd/src/glusterd-store.c
|
|
|
c5d8c8 |
@@ -4092,7 +4092,6 @@ out:
|
|
|
c5d8c8 |
int32_t
|
|
|
c5d8c8 |
glusterd_store_retrieve_missed_snaps_list(xlator_t *this)
|
|
|
c5d8c8 |
{
|
|
|
c5d8c8 |
- char buf[PATH_MAX] = "";
|
|
|
c5d8c8 |
char path[PATH_MAX] = "";
|
|
|
c5d8c8 |
char *snap_vol_id = NULL;
|
|
|
c5d8c8 |
char *missed_node_info = NULL;
|
|
|
c5d8c8 |
@@ -4129,8 +4128,8 @@ glusterd_store_retrieve_missed_snaps_list(xlator_t *this)
|
|
|
c5d8c8 |
}
|
|
|
c5d8c8 |
|
|
|
c5d8c8 |
do {
|
|
|
c5d8c8 |
- ret = gf_store_read_and_tokenize(
|
|
|
c5d8c8 |
- fp, buf, sizeof(buf), &missed_node_info, &value, &store_errno);
|
|
|
c5d8c8 |
+ ret = gf_store_read_and_tokenize(fp, &missed_node_info, &value,
|
|
|
c5d8c8 |
+ &store_errno);
|
|
|
c5d8c8 |
if (ret) {
|
|
|
c5d8c8 |
if (store_errno == GD_STORE_EOF) {
|
|
|
c5d8c8 |
gf_msg_debug(this->name, 0, "EOF for missed_snap_list");
|
|
|
c5d8c8 |
--
|
|
|
c5d8c8 |
1.8.3.1
|
|
|
c5d8c8 |
|