From 5989899b7aa5cc86e589c5ff20560476b959d98b Mon Sep 17 00:00:00 2001 From: Mohit Agrawal Date: Fri, 11 Jan 2019 12:42:20 +0530 Subject: [PATCH 503/506] core: brick process is crashed at the time of spawn thread Problem: brick is getting crashed at the time of calling pthread_detach after just call gf_thread_create.If sufficient resources are not available on the system pthread_create returns EAGAIN (non-negative) but the caller function expects negative error code in case of failure Solution: Change the condition in caller function to avoid the crash > Change-Id: Ifeaa49f809957eb6c33aa9792f5af1b55566756d > fixes: bz#1662906 > (Cherry pick from commit 1e28c54c5ec8d84ec8a22493161314010992918e) > (Reviewed on upstream link https://review.gluster.org/#/c/glusterfs/+/21976/) Change-Id: I9e5c3de4b98236de22f834d66268ab21001817a1 BUG: 1662828 Signed-off-by: Mohit Agrawal Reviewed-on: https://code.engineering.redhat.com/gerrit/160409 Tested-by: RHGS Build Bot Reviewed-by: Sunil Kumar Heggodu Gopala Acharya --- xlators/storage/posix/src/posix-helpers.c | 15 ++++++----- xlators/storage/posix/src/posix.c | 31 +++++++++++++++++------ xlators/storage/posix/src/posix.h | 6 ++--- 3 files changed, 35 insertions(+), 17 deletions(-) diff --git a/xlators/storage/posix/src/posix-helpers.c b/xlators/storage/posix/src/posix-helpers.c index ed5d3e55e..1137f1c41 100644 --- a/xlators/storage/posix/src/posix-helpers.c +++ b/xlators/storage/posix/src/posix-helpers.c @@ -1322,7 +1322,7 @@ posix_janitor_thread_proc (void *data) } -void +int posix_spawn_janitor_thread (xlator_t *this) { struct posix_private *priv = NULL; @@ -1337,7 +1337,7 @@ posix_spawn_janitor_thread (xlator_t *this) posix_janitor_thread_proc, this, "posixjan"); - if (ret < 0) { + if (ret) { gf_msg (this->name, GF_LOG_ERROR, errno, P_MSG_THREAD_FAILED, "spawning janitor " "thread failed"); @@ -1349,6 +1349,7 @@ posix_spawn_janitor_thread (xlator_t *this) } unlock: UNLOCK (&priv->lock); + return ret; } static int @@ -1822,7 +1823,7 @@ abort: return NULL; } -void +int posix_spawn_health_check_thread (xlator_t *xl) { struct posix_private *priv = NULL; @@ -1845,7 +1846,7 @@ posix_spawn_health_check_thread (xlator_t *xl) ret = gf_thread_create (&priv->health_check, NULL, posix_health_check_thread_proc, xl, "posixhc"); - if (ret < 0) { + if (ret) { priv->health_check_interval = 0; priv->health_check_active = _gf_false; gf_msg (xl->name, GF_LOG_ERROR, errno, @@ -1858,6 +1859,7 @@ posix_spawn_health_check_thread (xlator_t *xl) } unlock: UNLOCK (&priv->lock); + return ret; } void @@ -1940,7 +1942,7 @@ out: return NULL; } -void +int posix_spawn_disk_space_check_thread (xlator_t *xl) { struct posix_private *priv = NULL; @@ -1959,7 +1961,7 @@ 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"); - if (ret < 0) { + if (ret) { priv->disk_space_check_active = _gf_false; gf_msg (xl->name, GF_LOG_ERROR, errno, P_MSG_DISK_SPACE_CHECK_FAILED, @@ -1971,6 +1973,7 @@ posix_spawn_disk_space_check_thread (xlator_t *xl) } unlock: UNLOCK (&priv->lock); + return ret; } int diff --git a/xlators/storage/posix/src/posix.c b/xlators/storage/posix/src/posix.c index 591119ea9..8a6282d29 100644 --- a/xlators/storage/posix/src/posix.c +++ b/xlators/storage/posix/src/posix.c @@ -7317,12 +7317,19 @@ reconfigure (xlator_t *this, dict_t *options) GF_OPTION_RECONF ("reserve", priv->disk_reserve, options, uint32, out); - if (priv->disk_reserve) - posix_spawn_disk_space_check_thread (this); + if (priv->disk_reserve) { + ret = posix_spawn_disk_space_check_thread (this); + if (ret) + goto out; + } GF_OPTION_RECONF ("health-check-interval", priv->health_check_interval, options, uint32, out); - posix_spawn_health_check_thread (this); + if (priv->health_check_interval) { + ret = posix_spawn_health_check_thread (this); + if (ret) + goto out; + } GF_OPTION_RECONF ("shared-brick-count", priv->shared_brick_count, options, int32, out); @@ -7925,20 +7932,28 @@ init (xlator_t *this) _private->disk_space_full = 0; GF_OPTION_INIT ("reserve", _private->disk_reserve, uint32, out); - if (_private->disk_reserve) - posix_spawn_disk_space_check_thread (this); + if (_private->disk_reserve) { + ret = posix_spawn_disk_space_check_thread (this); + if (ret) + goto out; + } _private->health_check_active = _gf_false; GF_OPTION_INIT ("health-check-interval", _private->health_check_interval, uint32, out); - if (_private->health_check_interval) - posix_spawn_health_check_thread (this); + if (_private->health_check_interval) { + ret = posix_spawn_health_check_thread (this); + if (ret) + goto out; + } pthread_mutex_init (&_private->janitor_lock, NULL); pthread_cond_init (&_private->janitor_cond, NULL); INIT_LIST_HEAD (&_private->janitor_fds); - posix_spawn_janitor_thread (this); + ret = posix_spawn_janitor_thread (this); + if (ret) + goto out; pthread_mutex_init (&_private->fsync_mutex, NULL); pthread_cond_init (&_private->fsync_cond, NULL); diff --git a/xlators/storage/posix/src/posix.h b/xlators/storage/posix/src/posix.h index bda41726c..cb8dc8acc 100644 --- a/xlators/storage/posix/src/posix.h +++ b/xlators/storage/posix/src/posix.h @@ -305,7 +305,7 @@ int posix_handle_pair (xlator_t *this, const char *real_path, char *key, data_t *value, int flags, struct iatt *stbuf); int posix_fhandle_pair (xlator_t *this, int fd, char *key, data_t *value, int flags, struct iatt *stbuf); -void posix_spawn_janitor_thread (xlator_t *this); +int posix_spawn_janitor_thread (xlator_t *this); int posix_acl_xattr_set (xlator_t *this, const char *path, dict_t *xattr_req); int posix_gfid_heal (xlator_t *this, const char *path, loc_t *loc, dict_t *xattr_req); int posix_entry_create_xattr_set (xlator_t *this, const char *path, @@ -320,9 +320,9 @@ gf_boolean_t posix_special_xattr (char **pattern, char *key); void __posix_fd_set_odirect (fd_t *fd, struct posix_fd *pfd, int opflags, off_t offset, size_t size); -void posix_spawn_health_check_thread (xlator_t *this); +int posix_spawn_health_check_thread (xlator_t *this); -void posix_spawn_disk_space_check_thread (xlator_t *this); +int posix_spawn_disk_space_check_thread (xlator_t *this); void *posix_fsyncer (void *); int -- 2.20.1