summaryrefslogtreecommitdiffstats
path: root/xlators/cluster
diff options
context:
space:
mode:
authorHarshavardhana <fharshav@redhat.com>2011-11-21 16:28:47 -0800
committerVijay Bellur <vijay@gluster.com>2011-12-06 02:02:02 -0800
commit254fbfd92d4088c97ddde79a37b4e08e80c8eff3 (patch)
tree229df761122889997a14a4cc310095a438e2f3ff /xlators/cluster
parent2b64c93c9f7f69fab506bdfca163a2805a2ea46c (diff)
cluster/distribute: Assert checks at known locations
and new function dict_get_ptr_and_len(). Change-Id: I653a1cc8123baa36d750250d02721aa98b196f38 BUG: 3158 Signed-off-by: Harshavardhana <fharshav@redhat.com> Reviewed-on: http://review.gluster.com/744 Tested-by: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Vijay Bellur <vijay@gluster.com>
Diffstat (limited to 'xlators/cluster')
-rw-r--r--xlators/cluster/dht/src/dht-common.h2
-rw-r--r--xlators/cluster/dht/src/dht-layout.c34
2 files changed, 26 insertions, 10 deletions
diff --git a/xlators/cluster/dht/src/dht-common.h b/xlators/cluster/dht/src/dht-common.h
index 54cef6cd9d4..c1b9364ba72 100644
--- a/xlators/cluster/dht/src/dht-common.h
+++ b/xlators/cluster/dht/src/dht-common.h
@@ -314,7 +314,7 @@ int dht_layout_merge (xlator_t *this, dht_layout_t *layout, xlator_t *subvol,
int dht_disk_layout_extract (xlator_t *this, dht_layout_t *layout,
int pos, int32_t **disk_layout_p);
int dht_disk_layout_merge (xlator_t *this, dht_layout_t *layout,
- int pos, void *disk_layout_raw);
+ int pos, void *disk_layout_raw, int disk_layout_len);
int dht_frame_return (call_frame_t *frame);
diff --git a/xlators/cluster/dht/src/dht-layout.c b/xlators/cluster/dht/src/dht-layout.c
index 33dcc4067b0..3c8f63f5b1b 100644
--- a/xlators/cluster/dht/src/dht-layout.c
+++ b/xlators/cluster/dht/src/dht-layout.c
@@ -289,7 +289,7 @@ out:
int
dht_disk_layout_merge (xlator_t *this, dht_layout_t *layout,
- int pos, void *disk_layout_raw)
+ int pos, void *disk_layout_raw, int disk_layout_len)
{
int cnt = 0;
int type = 0;
@@ -297,9 +297,15 @@ dht_disk_layout_merge (xlator_t *this, dht_layout_t *layout,
int stop_off = 0;
int disk_layout[4];
- /* TODO: assert disk_layout_ptr is of required length */
+ if (!disk_layout_raw) {
+ gf_log (this->name, GF_LOG_CRITICAL,
+ "error no layout on disk for merge");
+ return -1;
+ }
- memcpy (disk_layout, disk_layout_raw, sizeof (disk_layout));
+ GF_ASSERT (disk_layout_len == sizeof (disk_layout));
+
+ memcpy (disk_layout, disk_layout_raw, disk_layout_len);
cnt = ntoh32 (disk_layout[0]);
if (cnt != 1) {
@@ -308,8 +314,17 @@ dht_disk_layout_merge (xlator_t *this, dht_layout_t *layout,
return -1;
}
- /* TODO: assert type is compatible */
- type = ntoh32 (disk_layout[1]);
+ switch (disk_layout[1]) {
+ case DHT_HASH_TYPE_DM:
+ type = ntoh32 (disk_layout[1]);
+ break;
+ default:
+ gf_log (this->name, GF_LOG_CRITICAL,
+ "Catastrophic error layout with unknown type found %d",
+ disk_layout[1]);
+ return -1;
+ }
+
start_off = ntoh32 (disk_layout[2]);
stop_off = ntoh32 (disk_layout[3]);
@@ -333,7 +348,7 @@ dht_layout_merge (xlator_t *this, dht_layout_t *layout, xlator_t *subvol,
int ret = -1;
int err = -1;
void *disk_layout_raw = NULL;
-
+ int disk_layout_len = 0;
if (op_ret != 0) {
err = op_errno;
@@ -354,8 +369,8 @@ dht_layout_merge (xlator_t *this, dht_layout_t *layout, xlator_t *subvol,
if (xattr) {
/* during lookup and not mkdir */
- ret = dict_get_ptr (xattr, "trusted.glusterfs.dht",
- &disk_layout_raw);
+ ret = dict_get_ptr_and_len (xattr, "trusted.glusterfs.dht",
+ &disk_layout_raw, &disk_layout_len);
}
if (ret != 0) {
@@ -367,7 +382,8 @@ dht_layout_merge (xlator_t *this, dht_layout_t *layout, xlator_t *subvol,
goto out;
}
- ret = dht_disk_layout_merge (this, layout, i, disk_layout_raw);
+ ret = dht_disk_layout_merge (this, layout, i, disk_layout_raw,
+ disk_layout_len);
if (ret != 0) {
gf_log (this->name, GF_LOG_DEBUG,
"layout merge from subvolume %s failed",