summaryrefslogtreecommitdiffstats
path: root/xlators/mgmt/glusterd/src/glusterd-utils.c
diff options
context:
space:
mode:
authorshishir gowda <shishirng@gluster.com>2010-09-22 05:21:28 +0000
committerVijay Bellur <vijay@dev.gluster.com>2010-09-22 07:44:04 -0700
commit2915e10dd0ffe529ddf747451051cf9924c708f3 (patch)
tree449f4daeb8cc0c8eeab7ef1a789d44644d2b11b9 /xlators/mgmt/glusterd/src/glusterd-utils.c
parent3225d7ccf599e726012fb2d32fe3cc68b979e0ea (diff)
Restart all bricks which are down when glusterd comes up
This is only done is the volume is started. Signed-off-by: shishir gowda <shishirng@gluster.com> Signed-off-by: Vijay Bellur <vijay@dev.gluster.com> BUG: 1562 (insufficient consistency check on start of glusterd) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=1562
Diffstat (limited to 'xlators/mgmt/glusterd/src/glusterd-utils.c')
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-utils.c109
1 files changed, 109 insertions, 0 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.c b/xlators/mgmt/glusterd/src/glusterd-utils.c
index e3592891b..a59a06905 100644
--- a/xlators/mgmt/glusterd/src/glusterd-utils.c
+++ b/xlators/mgmt/glusterd/src/glusterd-utils.c
@@ -41,6 +41,7 @@
#include "glusterd-utils.h"
#include "glusterd-store.h"
#include "glusterd-volgen.h"
+#include "glusterd-pmap.h"
#include <sys/resource.h>
#include <inttypes.h>
@@ -1750,3 +1751,111 @@ glusterd_is_exisiting_brick (char *hostname, char *path)
out:
return ret;
}
+
+int
+glusterd_restart_bricks (glusterd_conf_t *conf, xlator_t *this)
+{
+ glusterd_volinfo_t *volinfo = NULL;
+ glusterd_brickinfo_t *brickinfo = NULL;
+ char pidfile[PATH_MAX] = {0,};
+ char path[PATH_MAX] = {0,};
+ int ret = -1;
+ struct stat stbuf = {0,};
+ struct timespec timeout;
+ sigset_t mask;
+
+ if (sigprocmask(SIG_BLOCK, &mask, NULL) < 0) {
+ perror ("sigprocmask");
+ return -1;
+ }
+
+ sigemptyset (&mask);
+
+ timeout.tv_sec = 5;
+ timeout.tv_nsec = 0;
+
+ sigtimedwait(&mask, NULL, &timeout);
+ GF_ASSERT (conf);
+ GF_ASSERT (this);
+
+ list_for_each_entry (volinfo, &conf->volumes, vol_list) {
+ //If volume status is not started, do not proceed
+ if (volinfo->status == GLUSTERD_STATUS_STARTED) {
+ list_for_each_entry (brickinfo, &volinfo->bricks,
+ brick_list) {
+ //Only bricks on localhost to started
+ if (glusterd_is_local_addr (brickinfo->hostname))
+ continue;
+ //if started, implies already registered with pmap
+ if (!glusterd_is_brick_started(brickinfo))
+ continue;
+ GLUSTERD_GET_VOLUME_DIR (path, volinfo, conf);
+ GLUSTERD_GET_BRICK_PIDFILE (pidfile, path,
+ brickinfo->hostname, brickinfo->path);
+ ret = stat (pidfile, &stbuf);
+ //pid file not found, proceed to start
+ if (ret && errno == ENOENT) {
+ glusterd_volume_start_glusterfs (
+ volinfo, brickinfo, 0);
+ } else if (!ret) {
+ ret = pmap_registry_search (this,
+ brickinfo->path,
+ GF_PMAP_PORT_BRICKSERVER);
+ if (ret)
+ continue;
+ //might be a stale pid file
+ ret = unlink (pidfile);
+ //goto out;
+ glusterd_volume_start_glusterfs (
+ volinfo, brickinfo, 0);
+ }
+ }
+ glusterd_check_generate_start_nfs (volinfo);
+ }
+ }
+ return ret;
+}
+
+int
+glusterd_get_brickinfo (xlator_t *this, const char *brickname, int port,
+ gf_boolean_t localhost, glusterd_brickinfo_t **brickinfo)
+{
+ glusterd_conf_t *priv = NULL;
+ glusterd_volinfo_t *volinfo = NULL;
+ glusterd_brickinfo_t *tmpbrkinfo = NULL;
+ int ret = -1;
+
+ GF_ASSERT (brickname);
+ GF_ASSERT (this);
+
+ priv = this->private;
+ list_for_each_entry (volinfo, &priv->volumes, vol_list) {
+ list_for_each_entry (tmpbrkinfo, &volinfo->bricks,
+ brick_list) {
+ if (localhost && glusterd_is_local_addr (tmpbrkinfo->hostname))
+ continue;
+ if (!strcmp(tmpbrkinfo->path, brickname) &&
+ (tmpbrkinfo->port == port)) {
+ *brickinfo = tmpbrkinfo;
+ return 0;
+ }
+ }
+ }
+ return ret;
+}
+
+void
+glusterd_set_brick_status (glusterd_brickinfo_t *brickinfo,
+ gf_brick_status_t status)
+{
+ GF_ASSERT (brickinfo);
+ brickinfo->status = status;
+}
+
+int
+glusterd_is_brick_started (glusterd_brickinfo_t *brickinfo)
+{
+ GF_ASSERT (brickinfo);
+ return (!(brickinfo->status == GF_BRICK_STARTED));
+}
+