summaryrefslogtreecommitdiffstats
path: root/xlators/cluster/ec/src/ec-heal.c
diff options
context:
space:
mode:
authorXavier Hernandez <xhernandez@datalab.es>2014-07-16 13:50:53 +0200
committerVijay Bellur <vbellur@redhat.com>2014-08-03 07:53:23 -0700
commitb0f2326bbf2127792a4dc090785948d55c53b6e5 (patch)
tree6f6f48a0ff59df7c810b68171ec9b70263628aa9 /xlators/cluster/ec/src/ec-heal.c
parente55e1e0ee1352bbbbd847c6e188950cf1fccc8d5 (diff)
ec: Fixed coverity scan issues
CID list: 1226163 Logically dead code 1226166 Missing break in switch 1226167 Missing break in switch 1226168 Missing break in switch 1226169 Missing break in switch 1226170 Missing break in switch 1226171 Missing break in switch 1226172 Missing break in switch 1226173 Missing break in switch 1226174 Missing break in switch 1226175 Missing break in switch 1226176 Missing break in switch 1226177 Missing break in switch 1226178 Data race condition 1226179 Data race condition 1226180 Data race condition 1226181 Thread deadlock 1226182 Uninitialized pointer read 1226183 Uninitialized pointer read 1226184 Read from pointer after free Change-Id: I4d33aa42289371927175c43bb29e018df64fb943 BUG: 1122834 Signed-off-by: Xavier Hernandez <xhernandez@datalab.es> Reviewed-on: http://review.gluster.org/8372 Tested-by: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Vijay Bellur <vbellur@redhat.com>
Diffstat (limited to 'xlators/cluster/ec/src/ec-heal.c')
-rw-r--r--xlators/cluster/ec/src/ec-heal.c62
1 files changed, 34 insertions, 28 deletions
diff --git a/xlators/cluster/ec/src/ec-heal.c b/xlators/cluster/ec/src/ec-heal.c
index fe18a0b5f1e..f6ee0076373 100644
--- a/xlators/cluster/ec/src/ec-heal.c
+++ b/xlators/cluster/ec/src/ec-heal.c
@@ -91,6 +91,10 @@ void ec_heal_lookup_resume(ec_fop_data_t * fop)
}
}
+ /* Heal lookups are not executed concurrently with anything else. So, when
+ * a lookup finishes, it's safe to access heal->good and heal->bad without
+ * acquiring any lock.
+ */
heal->good = good;
heal->bad = bad;
@@ -456,43 +460,20 @@ int32_t ec_heal_init(ec_fop_data_t * fop)
return ENODATA;
}
- LOCK(&inode->lock);
-
- ctx = __ec_inode_get(inode, fop->xl);
- if (ctx == NULL)
- {
- error = EIO;
-
- goto out;
- }
-
- if (ctx->heal != NULL)
- {
- error = EEXIST;
-
- goto out;
- }
-
heal = GF_MALLOC(sizeof(ec_heal_t), ec_mt_ec_heal_t);
if (heal == NULL)
{
- error = ENOMEM;
-
- goto out;
+ return ENOMEM;
}
memset(heal, 0, sizeof(ec_heal_t));
- if (loc_copy(&heal->loc, &fop->loc[0]) != 0)
+ if (!ec_loc_from_loc(fop->xl, &heal->loc, &fop->loc[0]))
{
error = ENOMEM;
goto out;
}
- if (uuid_is_null(heal->loc.gfid))
- {
- uuid_copy(heal->loc.gfid, heal->loc.inode->gfid);
- }
LOCK_INIT(&heal->lock);
@@ -501,14 +482,31 @@ int32_t ec_heal_init(ec_fop_data_t * fop)
pool = fop->xl->ctx->iobuf_pool;
heal->size = iobpool_default_pagesize(pool) * ec->fragments;
+ LOCK(&inode->lock);
+
+ ctx = __ec_inode_get(inode, fop->xl);
+ if (ctx == NULL)
+ {
+ error = EIO;
+
+ goto unlock;
+ }
+
+ if (ctx->heal != NULL)
+ {
+ error = EEXIST;
+
+ goto unlock;
+ }
+
fop->data = heal;
ctx->heal = heal;
heal = NULL;
-out:
+unlock:
UNLOCK(&inode->lock);
-
+out:
GF_FREE(heal);
return error;
@@ -943,6 +941,10 @@ int32_t ec_heal_needs_data_rebuild(ec_heal_t * heal)
}
}
+ /* This function can only be called concurrently with entrylk, which do
+ * not modify heal structure, so it's safe to access heal->bad without
+ * acquiring any lock.
+ */
heal->bad = bad;
return (bad != 0);
@@ -1122,7 +1124,7 @@ void ec_heal_dispatch(ec_heal_t * heal)
GF_FREE(heal);
- ec_fop_set_error(heal->fop, error);
+ ec_fop_set_error(fop, error);
}
void ec_wind_heal(ec_t * ec, ec_fop_data_t * fop, int32_t idx)
@@ -1162,6 +1164,8 @@ int32_t ec_manager_heal(ec_fop_data_t * fop, int32_t state)
return EC_STATE_REPORT;
}
+ /* Fall through */
+
case EC_STATE_DISPATCH:
ec_heal_entrylk(fop->data, ENTRYLK_LOCK);
@@ -1222,6 +1226,8 @@ int32_t ec_manager_heal(ec_fop_data_t * fop, int32_t state)
case EC_STATE_HEAL_UNLOCK:
ec_heal_inodelk(heal, F_UNLCK, 0, 0, 0);
+ /* Fall through */
+
case -EC_STATE_HEAL_ENTRY_PREPARE:
case -EC_STATE_HEAL_PRE_INODELK_LOCK:
case -EC_STATE_HEAL_PRE_INODE_LOOKUP: