summaryrefslogtreecommitdiffstats
path: root/xlators
diff options
context:
space:
mode:
Diffstat (limited to 'xlators')
-rw-r--r--xlators/cluster/afr/src/afr-common.c313
-rw-r--r--xlators/cluster/afr/src/afr-inode-read.c5
-rw-r--r--xlators/cluster/afr/src/afr-self-heal-data.c21
-rw-r--r--xlators/cluster/afr/src/afr-self-heal-entry.c24
-rw-r--r--xlators/cluster/afr/src/afr-self-heal-metadata.c6
-rw-r--r--xlators/cluster/afr/src/afr-self-heal.h22
-rw-r--r--xlators/cluster/afr/src/afr.h4
7 files changed, 366 insertions, 29 deletions
diff --git a/xlators/cluster/afr/src/afr-common.c b/xlators/cluster/afr/src/afr-common.c
index 1527a47f716..aefad8be959 100644
--- a/xlators/cluster/afr/src/afr-common.c
+++ b/xlators/cluster/afr/src/afr-common.c
@@ -494,7 +494,6 @@ afr_selfheal_enabled (xlator_t *this)
}
-
int
afr_inode_refresh_done (call_frame_t *frame, xlator_t *this)
{
@@ -4032,3 +4031,315 @@ afr_mark_pending_changelog (afr_private_t *priv, unsigned char *pending,
out:
return changelog;
}
+
+gf_boolean_t
+afr_decide_heal_info (afr_private_t *priv, unsigned char *sources, int ret)
+{
+ int sources_count = 0;
+
+ if (ret)
+ goto out;
+
+ sources_count = AFR_COUNT (sources, priv->child_count);
+ if (sources_count == priv->child_count)
+ return _gf_false;
+out:
+ return _gf_true;
+}
+
+int
+afr_selfheal_locked_metadata_inspect (call_frame_t *frame, xlator_t *this,
+ inode_t *inode, gf_boolean_t *msh)
+{
+ int ret = -1;
+ unsigned char *locked_on = NULL;
+ unsigned char *sources = NULL;
+ unsigned char *sinks = NULL;
+ unsigned char *healed_sinks = NULL;
+ struct afr_reply *locked_replies = NULL;
+
+ afr_private_t *priv = this->private;
+
+ locked_on = alloca0 (priv->child_count);
+ sources = alloca0 (priv->child_count);
+ sinks = alloca0 (priv->child_count);
+ healed_sinks = alloca0 (priv->child_count);
+
+ locked_replies = alloca0 (sizeof (*locked_replies) * priv->child_count);
+
+ ret = afr_selfheal_inodelk (frame, this, inode, this->name,
+ LLONG_MAX - 1, 0, locked_on);
+ {
+ if (ret == 0) {
+ /* Not a single lock */
+ ret = -afr_final_errno (frame->local, priv);
+ if (ret == 0)
+ ret = -ENOTCONN;/* all invalid responses */
+ goto out;
+ }
+ ret = __afr_selfheal_metadata_prepare (frame, this, inode,
+ locked_on, sources,
+ sinks, healed_sinks,
+ locked_replies);
+ *msh = afr_decide_heal_info (priv, sources, ret);
+ }
+ afr_selfheal_uninodelk (frame, this, inode, this->name,
+ LLONG_MAX - 1, 0, locked_on);
+out:
+ if (locked_replies)
+ afr_replies_wipe (locked_replies, priv->child_count);
+ return ret;
+}
+
+int
+afr_selfheal_locked_data_inspect (call_frame_t *frame, xlator_t *this,
+ inode_t *inode, gf_boolean_t *dsh)
+{
+ int ret = -1;
+ afr_private_t *priv = NULL;
+ unsigned char *locked_on = NULL;
+ unsigned char *data_lock = NULL;
+ unsigned char *sources = NULL;
+ unsigned char *sinks = NULL;
+ unsigned char *healed_sinks = NULL;
+ struct afr_reply *locked_replies = NULL;
+
+ priv = this->private;
+ locked_on = alloca0 (priv->child_count);
+ data_lock = alloca0 (priv->child_count);
+ sources = alloca0 (priv->child_count);
+ sinks = alloca0 (priv->child_count);
+ healed_sinks = alloca0 (priv->child_count);
+
+ locked_replies = alloca0 (sizeof (*locked_replies) * priv->child_count);
+
+ ret = afr_selfheal_tryinodelk (frame, this, inode, priv->sh_domain,
+ 0, 0, locked_on);
+ {
+ if (ret == 0) {
+ ret = -afr_final_errno (frame->local, priv);
+ if (ret == 0)
+ ret = -ENOTCONN;/* all invalid responses */
+ goto out;
+ }
+ ret = afr_selfheal_inodelk (frame, this, inode, this->name,
+ 0, 0, data_lock);
+ {
+ if (ret == 0) {
+ ret = -afr_final_errno (frame->local, priv);
+ if (ret == 0)
+ ret = -ENOTCONN;
+ /* all invalid responses */
+ goto unlock;
+ }
+ ret = __afr_selfheal_data_prepare (frame, this, inode,
+ data_lock, sources,
+ sinks, healed_sinks,
+ locked_replies);
+ *dsh = afr_decide_heal_info (priv, sources, ret);
+ }
+ afr_selfheal_uninodelk (frame, this, inode, this->name, 0, 0,
+ data_lock);
+ }
+unlock:
+ afr_selfheal_uninodelk (frame, this, inode, priv->sh_domain, 0, 0,
+ locked_on);
+out:
+ if (locked_replies)
+ afr_replies_wipe (locked_replies, priv->child_count);
+ return ret;
+}
+
+int
+afr_selfheal_locked_entry_inspect (call_frame_t *frame, xlator_t *this,
+ inode_t *inode,
+ gf_boolean_t *esh)
+{
+ int ret = -1;
+ int source = -1;
+ afr_private_t *priv = NULL;
+ unsigned char *locked_on = NULL;
+ unsigned char *data_lock = NULL;
+ unsigned char *sources = NULL;
+ unsigned char *sinks = NULL;
+ unsigned char *healed_sinks = NULL;
+ struct afr_reply *locked_replies = NULL;
+
+ priv = this->private;
+ locked_on = alloca0 (priv->child_count);
+ data_lock = alloca0 (priv->child_count);
+ sources = alloca0 (priv->child_count);
+ sinks = alloca0 (priv->child_count);
+ healed_sinks = alloca0 (priv->child_count);
+
+ locked_replies = alloca0 (sizeof (*locked_replies) * priv->child_count);
+
+ ret = afr_selfheal_tryentrylk (frame, this, inode, priv->sh_domain,
+ NULL, locked_on);
+ {
+ if (ret == 0) {
+ ret = -afr_final_errno (frame->local, priv);
+ if (ret == 0)
+ ret = -ENOTCONN;/* all invalid responses */
+ goto out;
+ }
+
+ ret = afr_selfheal_entrylk (frame, this, inode, this->name,
+ NULL, data_lock);
+ {
+ if (ret == 0) {
+ ret = -afr_final_errno (frame->local, priv);
+ if (ret == 0)
+ ret = -ENOTCONN;
+ /* all invalid responses */
+ goto unlock;
+ }
+ ret = __afr_selfheal_entry_prepare (frame, this, inode,
+ data_lock, sources,
+ sinks, healed_sinks,
+ locked_replies,
+ &source);
+ if ((ret == 0) && source < 0)
+ ret = -EIO;
+ *esh = afr_decide_heal_info (priv, sources, ret);
+ }
+ afr_selfheal_unentrylk (frame, this, inode, this->name, NULL,
+ data_lock);
+ }
+unlock:
+ afr_selfheal_unentrylk (frame, this, inode, priv->sh_domain, NULL,
+ locked_on);
+out:
+ if (locked_replies)
+ afr_replies_wipe (locked_replies, priv->child_count);
+ return ret;
+}
+
+int
+afr_selfheal_locked_inspect (call_frame_t *frame, xlator_t *this, uuid_t gfid,
+ inode_t **inode,
+ gf_boolean_t *entry_selfheal,
+ gf_boolean_t *data_selfheal,
+ gf_boolean_t *metadata_selfheal)
+
+{
+ int ret = -1;
+ gf_boolean_t dsh = _gf_false;
+ gf_boolean_t msh = _gf_false;
+ gf_boolean_t esh = _gf_false;
+
+ ret = afr_selfheal_unlocked_inspect (frame, this, gfid, inode,
+ &dsh, &msh, &esh);
+ if (ret)
+ goto out;
+
+ /* For every heal type hold locks and check if it indeed needs heal */
+
+ if (msh) {
+ ret = afr_selfheal_locked_metadata_inspect (frame, this,
+ *inode, &msh);
+ if (ret == -EIO)
+ goto out;
+ }
+
+ if (dsh) {
+ ret = afr_selfheal_locked_data_inspect (frame, this, *inode,
+ &dsh);
+ if (ret == -EIO || (ret == -EAGAIN))
+ goto out;
+ }
+
+ if (esh) {
+ ret = afr_selfheal_locked_entry_inspect (frame, this, *inode,
+ &esh);
+ }
+
+out:
+ *data_selfheal = dsh;
+ *entry_selfheal = esh;
+ *metadata_selfheal = msh;
+ return ret;
+}
+
+dict_t*
+afr_set_heal_info (char *status)
+{
+ dict_t *dict = NULL;
+ int ret = -1;
+
+ dict = dict_new ();
+ if (!dict) {
+ ret = -ENOMEM;
+ goto out;
+ }
+
+ if (!strcmp (status, "heal")) {
+ ret = dict_set_str (dict, "heal-info", "heal");
+ if (ret)
+ gf_log ("", GF_LOG_WARNING,
+ "Failed to set heal-info key to"
+ "heal");
+ } else if (!strcmp (status, "split-brain")) {
+ ret = dict_set_str (dict, "heal-info", "split-brain");
+ if (ret)
+ gf_log ("", GF_LOG_WARNING,
+ "Failed to set heal-info key to"
+ "split-brain");
+ } else if (!strcmp (status, "possibly-healing")) {
+ ret = dict_set_str (dict, "heal-info", "possibly-healing");
+ if (ret)
+ gf_log ("", GF_LOG_WARNING,
+ "Failed to set heal-info key to"
+ "possibly-healing");
+ }
+out:
+ return dict;
+}
+
+int
+afr_get_heal_info (call_frame_t *frame, xlator_t *this, loc_t *loc,
+ dict_t *xdata)
+{
+ gf_boolean_t data_selfheal = _gf_false;
+ gf_boolean_t metadata_selfheal = _gf_false;
+ gf_boolean_t entry_selfheal = _gf_false;
+ dict_t *dict = NULL;
+ int ret = -1;
+ int op_errno = 0;
+ inode_t *inode = NULL;
+
+ ret = afr_selfheal_locked_inspect (frame, this, loc->gfid, &inode,
+ &entry_selfheal,
+ &data_selfheal, &metadata_selfheal);
+
+ if (ret == -ENOMEM) {
+ op_errno = -ret;
+ ret = -1;
+ goto out;
+ }
+
+ if (ret == -EIO) {
+ dict = afr_set_heal_info ("split-brain");
+ } else if (ret == -EAGAIN) {
+ dict = afr_set_heal_info ("possibly-healing");
+ } else if (ret == 0) {
+ if (!data_selfheal && !entry_selfheal &&
+ !metadata_selfheal) {
+ dict = afr_set_heal_info ("no-heal");
+ } else {
+ dict = afr_set_heal_info ("heal");
+ }
+ } else if (ret < 0) {
+ if (data_selfheal || entry_selfheal ||
+ metadata_selfheal) {
+ dict = afr_set_heal_info ("heal");
+ }
+ }
+ ret = 0;
+
+out:
+ AFR_STACK_UNWIND (getxattr, frame, ret, op_errno, dict, NULL);
+ if (dict)
+ dict_unref (dict);
+ return ret;
+}
diff --git a/xlators/cluster/afr/src/afr-inode-read.c b/xlators/cluster/afr/src/afr-inode-read.c
index 4cb219246f7..210d710a2b3 100644
--- a/xlators/cluster/afr/src/afr-inode-read.c
+++ b/xlators/cluster/afr/src/afr-inode-read.c
@@ -1373,6 +1373,11 @@ afr_getxattr (call_frame_t *frame, xlator_t *this,
return 0;
}
+ if (!strcmp (name, GF_AFR_HEAL_INFO)) {
+ afr_get_heal_info (frame, this, loc, xdata);
+ return 0;
+ }
+
/*
* if we are doing getxattr with pathinfo as the key then we
* collect information from all childs
diff --git a/xlators/cluster/afr/src/afr-self-heal-data.c b/xlators/cluster/afr/src/afr-self-heal-data.c
index f7503faa719..0a43d128634 100644
--- a/xlators/cluster/afr/src/afr-self-heal-data.c
+++ b/xlators/cluster/afr/src/afr-self-heal-data.c
@@ -569,10 +569,11 @@ out:
* The return value is the index of the subvolume to be used as the source
* for self-healing, or -1 if no healing is necessary/split brain.
*/
-static int
-__afr_selfheal_data_prepare (call_frame_t *frame, xlator_t *this, fd_t *fd,
- unsigned char *locked_on, unsigned char *sources,
- unsigned char *sinks, unsigned char *healed_sinks,
+int
+__afr_selfheal_data_prepare (call_frame_t *frame, xlator_t *this,
+ inode_t *inode, unsigned char *locked_on,
+ unsigned char *sources, unsigned char *sinks,
+ unsigned char *healed_sinks,
struct afr_reply *replies)
{
int ret = -1;
@@ -582,10 +583,8 @@ __afr_selfheal_data_prepare (call_frame_t *frame, xlator_t *this, fd_t *fd,
priv = this->private;
- ret = afr_selfheal_unlocked_discover (frame, fd->inode, fd->inode->gfid,
+ ret = afr_selfheal_unlocked_discover (frame, inode, inode->gfid,
replies);
- if (ret)
- return ret;
witness = alloca0(priv->child_count * sizeof (*witness));
ret = afr_selfheal_find_direction (frame, this, replies,
@@ -650,8 +649,9 @@ __afr_selfheal_data (call_frame_t *frame, xlator_t *this, fd_t *fd,
goto unlock;
}
- ret = __afr_selfheal_data_prepare (frame, this, fd, data_lock,
- sources, sinks, healed_sinks,
+ ret = __afr_selfheal_data_prepare (frame, this, fd->inode,
+ data_lock, sources, sinks,
+ healed_sinks,
locked_replies);
if (ret < 0)
goto unlock;
@@ -678,7 +678,7 @@ __afr_selfheal_data (call_frame_t *frame, xlator_t *this, fd_t *fd,
unlock:
afr_selfheal_uninodelk (frame, this, fd->inode, this->name, 0, 0,
data_lock);
- if (ret < 0)
+ if (ret < 0)
goto out;
ret = afr_selfheal_data_do (frame, this, fd, source, healed_sinks,
@@ -731,7 +731,6 @@ afr_selfheal_data_open (xlator_t *this, inode_t *inode)
return fd;
}
-
int
afr_selfheal_data (call_frame_t *frame, xlator_t *this, inode_t *inode)
{
diff --git a/xlators/cluster/afr/src/afr-self-heal-entry.c b/xlators/cluster/afr/src/afr-self-heal-entry.c
index 3f753251e7c..63ac61bce31 100644
--- a/xlators/cluster/afr/src/afr-self-heal-entry.c
+++ b/xlators/cluster/afr/src/afr-self-heal-entry.c
@@ -357,11 +357,11 @@ __afr_selfheal_entry_finalize_source (xlator_t *this, unsigned char *sources,
return source;
}
-
-static int
-__afr_selfheal_entry_prepare (call_frame_t *frame, xlator_t *this, fd_t *fd,
- unsigned char *locked_on, unsigned char *sources,
- unsigned char *sinks, unsigned char *healed_sinks,
+int
+__afr_selfheal_entry_prepare (call_frame_t *frame, xlator_t *this,
+ inode_t *inode, unsigned char *locked_on,
+ unsigned char *sources, unsigned char *sinks,
+ unsigned char *healed_sinks,
struct afr_reply *replies, int *source_p)
{
int ret = -1;
@@ -371,11 +371,8 @@ __afr_selfheal_entry_prepare (call_frame_t *frame, xlator_t *this, fd_t *fd,
priv = this->private;
- ret = afr_selfheal_unlocked_discover (frame, fd->inode, fd->inode->gfid,
+ ret = afr_selfheal_unlocked_discover (frame, inode, inode->gfid,
replies);
- if (ret)
- return ret;
-
witness = alloca0 (sizeof (*witness) * priv->child_count);
ret = afr_selfheal_find_direction (frame, this, replies,
AFR_ENTRY_TRANSACTION,
@@ -407,7 +404,6 @@ __afr_selfheal_entry_prepare (call_frame_t *frame, xlator_t *this, fd_t *fd,
return ret;
}
-
static int
afr_selfheal_entry_dirent (call_frame_t *frame, xlator_t *this,
fd_t *fd, char *name)
@@ -445,7 +441,8 @@ afr_selfheal_entry_dirent (call_frame_t *frame, xlator_t *this,
goto unlock;
}
- ret = __afr_selfheal_entry_prepare (frame, this, fd, locked_on,
+ ret = __afr_selfheal_entry_prepare (frame, this, fd->inode,
+ locked_on,
sources, sinks,
healed_sinks, par_replies,
&source);
@@ -593,8 +590,9 @@ __afr_selfheal_entry (call_frame_t *frame, xlator_t *this, fd_t *fd,
goto unlock;
}
- ret = __afr_selfheal_entry_prepare (frame, this, fd, data_lock,
- sources, sinks, healed_sinks,
+ ret = __afr_selfheal_entry_prepare (frame, this, fd->inode,
+ data_lock, sources, sinks,
+ healed_sinks,
locked_replies, &source);
}
unlock:
diff --git a/xlators/cluster/afr/src/afr-self-heal-metadata.c b/xlators/cluster/afr/src/afr-self-heal-metadata.c
index 87600df3bad..c09f19ac5fd 100644
--- a/xlators/cluster/afr/src/afr-self-heal-metadata.c
+++ b/xlators/cluster/afr/src/afr-self-heal-metadata.c
@@ -294,7 +294,8 @@ __afr_selfheal_metadata_finalize_source (call_frame_t *frame, xlator_t *this,
return source;
}
-static int
+
+int
__afr_selfheal_metadata_prepare (call_frame_t *frame, xlator_t *this, inode_t *inode,
unsigned char *locked_on, unsigned char *sources,
unsigned char *sinks, unsigned char *healed_sinks,
@@ -310,9 +311,6 @@ __afr_selfheal_metadata_prepare (call_frame_t *frame, xlator_t *this, inode_t *i
ret = afr_selfheal_unlocked_discover (frame, inode, inode->gfid,
replies);
- if (ret)
- return ret;
-
witness = alloca0 (sizeof (*witness) * priv->child_count);
ret = afr_selfheal_find_direction (frame, this, replies,
AFR_METADATA_TRANSACTION,
diff --git a/xlators/cluster/afr/src/afr-self-heal.h b/xlators/cluster/afr/src/afr-self-heal.h
index bb3f0e7029f..50cff91ccb3 100644
--- a/xlators/cluster/afr/src/afr-self-heal.h
+++ b/xlators/cluster/afr/src/afr-self-heal.h
@@ -200,6 +200,28 @@ gf_boolean_t
afr_does_witness_exist (xlator_t *this, uint64_t *witness);
int
+__afr_selfheal_data_prepare (call_frame_t *frame, xlator_t *this,
+ inode_t *inode, unsigned char *locked_on,
+ unsigned char *sources,
+ unsigned char *sinks, unsigned char *healed_sinks,
+ struct afr_reply *replies);
+
+int
+__afr_selfheal_metadata_prepare (call_frame_t *frame, xlator_t *this,
+ inode_t *inode, unsigned char *locked_on,
+ unsigned char *sources,
+ unsigned char *sinks,
+ unsigned char *healed_sinks,
+ struct afr_reply *replies);
+int
+__afr_selfheal_entry_prepare (call_frame_t *frame, xlator_t *this,
+ inode_t *inode, unsigned char *locked_on,
+ unsigned char *sources,
+ unsigned char *sinks,
+ unsigned char *healed_sinks,
+ struct afr_reply *replies, int *source_p);
+
+int
afr_selfheal_unlocked_inspect (call_frame_t *frame, xlator_t *this,
uuid_t gfid, inode_t **link_inode,
gf_boolean_t *data_selfheal,
diff --git a/xlators/cluster/afr/src/afr.h b/xlators/cluster/afr/src/afr.h
index 51e57e8207f..7e138c54ec0 100644
--- a/xlators/cluster/afr/src/afr.h
+++ b/xlators/cluster/afr/src/afr.h
@@ -1011,4 +1011,8 @@ afr_xattrs_are_equal (dict_t *dict1, dict_t *dict2);
gf_boolean_t
afr_is_xattr_ignorable (char *key);
+
+int
+afr_get_heal_info (call_frame_t *frame, xlator_t *this, loc_t *loc,
+ dict_t *xdata);
#endif /* __AFR_H__ */