summaryrefslogtreecommitdiffstats
path: root/xlators/cluster
diff options
context:
space:
mode:
authorAmar Tumballi <amar@gluster.com>2010-10-04 22:15:57 +0000
committerVijay Bellur <vijay@dev.gluster.com>2010-10-05 02:48:14 -0700
commit6658fdde8f6e328e232d9d40067df8ae4b16e8b2 (patch)
tree20159c078f04c9aa5886685883d81aa30cea43f1 /xlators/cluster
parent372ed08f25da2eb7e09f27685cb1773b88c62173 (diff)
distribute: check for 'conf' before dereferencing it
Signed-off-by: Amar Tumballi <amar@gluster.com> Signed-off-by: Vijay Bellur <vijay@dev.gluster.com> BUG: 1806 () URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=1806
Diffstat (limited to 'xlators/cluster')
-rw-r--r--xlators/cluster/dht/src/dht-common.c54
-rw-r--r--xlators/cluster/dht/src/dht-helper.c19
-rw-r--r--xlators/cluster/dht/src/dht-layout.c23
-rw-r--r--xlators/cluster/dht/src/dht.c4
4 files changed, 85 insertions, 15 deletions
diff --git a/xlators/cluster/dht/src/dht-common.c b/xlators/cluster/dht/src/dht-common.c
index 2beb0ec2d3f..d537c1178bb 100644
--- a/xlators/cluster/dht/src/dht-common.c
+++ b/xlators/cluster/dht/src/dht-common.c
@@ -294,6 +294,8 @@ dht_do_fresh_lookup_on_root (xlator_t *this, call_frame_t *frame)
local = frame->local;
conf = this->private;
+ if (!conf)
+ goto err;
if (local->layout) {
dht_layout_unref (this, local->layout);
@@ -351,6 +353,8 @@ dht_revalidate_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
local = frame->local;
prev = cookie;
conf = this->private;
+ if (!conf)
+ goto out;
LOCK (&frame->lock);
{
@@ -431,14 +435,14 @@ dht_revalidate_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
}
unlock:
UNLOCK (&frame->lock);
-
+out:
this_call_cnt = dht_frame_return (frame);
if (is_last_call (this_call_cnt)) {
if (!IA_ISDIR (local->stbuf.ia_type)
&& (local->hashed_subvol != local->cached_subvol)
&& (local->stbuf.ia_nlink == 1)
- && (conf->unhashed_sticky_bit)) {
+ && (conf && conf->unhashed_sticky_bit)) {
local->stbuf.ia_prot.sticky = 1;
}
@@ -496,7 +500,7 @@ dht_lookup_linkfile_create_cbk (call_frame_t *frame, void *cookie,
local->op_ret = 0;
if ((local->stbuf.ia_nlink == 1)
- && (conf->unhashed_sticky_bit)) {
+ && (conf && conf->unhashed_sticky_bit)) {
local->stbuf.ia_prot.sticky = 1;
}
@@ -686,6 +690,8 @@ dht_lookup_everywhere (call_frame_t *frame, xlator_t *this, loc_t *loc)
conf = this->private;
local = frame->local;
+ if (!conf)
+ goto out;
call_cnt = conf->subvolume_cnt;
local->call_cnt = call_cnt;
@@ -700,7 +706,10 @@ dht_lookup_everywhere (call_frame_t *frame, xlator_t *this, loc_t *loc)
loc, local->xattr_req);
}
- return 0;
+ return 0;
+out:
+ DHT_STACK_UNWIND (lookup, frame, -1, EINVAL, NULL, NULL, NULL, NULL);
+ return 0;
}
@@ -745,7 +754,7 @@ dht_lookup_linkfile_cbk (call_frame_t *frame, void *cookie,
}
if ((stbuf->ia_nlink == 1)
- && (conf->unhashed_sticky_bit)) {
+ && (conf && conf->unhashed_sticky_bit)) {
stbuf->ia_prot.sticky = 1;
}
dht_itransform (this, prev->this, stbuf->ia_ino, &stbuf->ia_ino);
@@ -788,17 +797,19 @@ dht_lookup_directory (call_frame_t *frame, xlator_t *this, loc_t *loc)
conf = this->private;
local = frame->local;
+ if (!conf)
+ goto unwind;
+
call_cnt = conf->subvolume_cnt;
local->call_cnt = call_cnt;
-
+
local->layout = dht_layout_new (this, conf->subvolume_cnt);
if (!local->layout) {
gf_log (this->name, GF_LOG_ERROR,
"Out of memory");
- DHT_STACK_UNWIND (lookup, frame, -1, ENOMEM, NULL, NULL, NULL, NULL);
- return 0;
+ goto unwind;
}
-
+
for (i = 0; i < call_cnt; i++) {
STACK_WIND (frame, dht_lookup_dir_cbk,
conf->subvolumes[i],
@@ -806,6 +817,10 @@ dht_lookup_directory (call_frame_t *frame, xlator_t *this, loc_t *loc)
&local->loc, local->xattr_req);
}
return 0;
+unwind:
+ DHT_STACK_UNWIND (lookup, frame, -1, ENOMEM, NULL, NULL, NULL, NULL);
+ return 0;
+
}
@@ -827,6 +842,8 @@ dht_lookup_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
dht_layout_t *parent_layout = NULL;
conf = this->private;
+ if (!conf)
+ goto out;
prev = cookie;
local = frame->local;
@@ -952,6 +969,8 @@ dht_lookup (call_frame_t *frame, xlator_t *this,
VALIDATE_OR_GOTO (loc->path, err);
conf = this->private;
+ if (!conf)
+ goto err;
local = dht_local_init (frame);
if (!local) {
@@ -1818,6 +1837,7 @@ dht_getxattr (call_frame_t *frame, xlator_t *this,
VALIDATE_OR_GOTO (loc, err);
VALIDATE_OR_GOTO (loc->inode, err);
VALIDATE_OR_GOTO (loc->path, err);
+ VALIDATE_OR_GOTO (this->private, err);
conf = this->private;
layout = dht_layout_get (this, loc->inode);
@@ -2466,6 +2486,7 @@ dht_statfs (call_frame_t *frame, xlator_t *this, loc_t *loc)
VALIDATE_OR_GOTO (loc, err);
VALIDATE_OR_GOTO (loc->inode, err);
VALIDATE_OR_GOTO (loc->path, err);
+ VALIDATE_OR_GOTO (this->private, err);
conf = this->private;
@@ -2501,6 +2522,7 @@ dht_opendir (call_frame_t *frame, xlator_t *this, loc_t *loc, fd_t *fd)
VALIDATE_OR_GOTO (frame, err);
VALIDATE_OR_GOTO (this, err);
VALIDATE_OR_GOTO (fd, err);
+ VALIDATE_OR_GOTO (this->private, err);
conf = this->private;
@@ -2809,6 +2831,8 @@ dht_readdir (call_frame_t *frame, xlator_t *this, fd_t *fd, size_t size,
int i = 0;
conf = this->private;
+ if (!conf)
+ goto out;
for (i = 0; i < conf->subvolume_cnt; i++) {
if (!conf->subvolume_status[i]) {
@@ -2820,6 +2844,7 @@ dht_readdir (call_frame_t *frame, xlator_t *this, fd_t *fd, size_t size,
if (conf->use_readdirp)
op = GF_FOP_READDIRP;
+out:
dht_do_readdir (frame, this, fd, size, yoff, op);
return 0;
}
@@ -2874,6 +2899,7 @@ dht_fsyncdir (call_frame_t *frame, xlator_t *this, fd_t *fd, int datasync)
VALIDATE_OR_GOTO (frame, err);
VALIDATE_OR_GOTO (this, err);
VALIDATE_OR_GOTO (fd, err);
+ VALIDATE_OR_GOTO (this->private, err);
conf = this->private;
@@ -3628,6 +3654,8 @@ dht_mkdir_hashed_cbk (call_frame_t *frame, void *cookie,
int i = 0;
xlator_t *hashed_subvol = NULL;
+ VALIDATE_OR_GOTO (this->private, err);
+
local = frame->local;
prev = cookie;
layout = local->layout;
@@ -3693,6 +3721,7 @@ dht_mkdir (call_frame_t *frame, xlator_t *this,
VALIDATE_OR_GOTO (loc, err);
VALIDATE_OR_GOTO (loc->inode, err);
VALIDATE_OR_GOTO (loc->path, err);
+ VALIDATE_OR_GOTO (this->private, err);
conf = this->private;
@@ -3848,6 +3877,8 @@ dht_rmdir_do (call_frame_t *frame, xlator_t *this)
dht_conf_t *conf = NULL;
int i = 0;
+ VALIDATE_OR_GOTO (this->private, err);
+
conf = this->private;
local = frame->local;
@@ -4141,6 +4172,7 @@ dht_rmdir (call_frame_t *frame, xlator_t *this, loc_t *loc, int flags)
VALIDATE_OR_GOTO (loc, err);
VALIDATE_OR_GOTO (loc->inode, err);
VALIDATE_OR_GOTO (loc->path, err);
+ VALIDATE_OR_GOTO (this->private, err);
conf = this->private;
@@ -4683,6 +4715,8 @@ dht_init_subvolumes (xlator_t *this, dht_conf_t *conf)
xlator_list_t *subvols = NULL;
int cnt = 0;
+ if (!conf)
+ return -1;
for (subvols = this->children; subvols; subvols = subvols->next)
cnt++;
@@ -4727,6 +4761,8 @@ dht_notify (xlator_t *this, int event, void *data, ...)
int notify = 1;
conf = this->private;
+ if (!conf)
+ return ret;
switch (event) {
case GF_EVENT_CHILD_UP:
diff --git a/xlators/cluster/dht/src/dht-helper.c b/xlators/cluster/dht/src/dht-helper.c
index 3467bfe019c..9e21713f7a6 100644
--- a/xlators/cluster/dht/src/dht-helper.c
+++ b/xlators/cluster/dht/src/dht-helper.c
@@ -64,6 +64,8 @@ dht_itransform (xlator_t *this, xlator_t *subvol, uint64_t x, uint64_t *y_p)
}
conf = this->private;
+ if (!conf)
+ goto out;
max = conf->subvolume_cnt;
cnt = dht_subvol_cnt (this, subvol);
@@ -147,6 +149,8 @@ dht_deitransform (xlator_t *this, uint64_t y, xlator_t **subvol_p,
uint64_t x = 0;
xlator_t *subvol = 0;
+ if (!this->private)
+ goto out;
conf = this->private;
max = conf->subvolume_cnt;
@@ -162,6 +166,7 @@ dht_deitransform (xlator_t *this, uint64_t y, xlator_t **subvol_p,
if (x_p)
*x_p = x;
+out:
return 0;
}
@@ -262,6 +267,8 @@ dht_first_up_subvol (xlator_t *this)
int i = 0;
conf = this->private;
+ if (!conf)
+ goto out;
LOCK (&conf->subvolume_lock);
{
@@ -274,6 +281,7 @@ dht_first_up_subvol (xlator_t *this)
}
UNLOCK (&conf->subvolume_lock);
+out:
return child;
}
@@ -285,6 +293,9 @@ dht_last_up_subvol (xlator_t *this)
int i = 0;
conf = this->private;
+ if (!conf)
+ goto out;
+
LOCK (&conf->subvolume_lock);
{
for (i = conf->subvolume_cnt-1; i >= 0; i--) {
@@ -296,6 +307,7 @@ dht_last_up_subvol (xlator_t *this)
}
UNLOCK (&conf->subvolume_lock);
+out:
return child;
}
@@ -369,6 +381,8 @@ dht_subvol_next (xlator_t *this, xlator_t *prev)
xlator_t *next = NULL;
conf = this->private;
+ if (!conf)
+ goto out;
for (i = 0; i < conf->subvolume_cnt; i++) {
if (conf->subvolumes[i] == prev) {
@@ -378,6 +392,7 @@ dht_subvol_next (xlator_t *this, xlator_t *prev)
}
}
+out:
return next;
}
@@ -389,8 +404,9 @@ dht_subvol_cnt (xlator_t *this, xlator_t *subvol)
int ret = -1;
dht_conf_t *conf = NULL;
-
conf = this->private;
+ if (!conf)
+ goto out;
for (i = 0; i < conf->subvolume_cnt; i++) {
if (subvol == conf->subvolumes[i]) {
@@ -399,6 +415,7 @@ dht_subvol_cnt (xlator_t *this, xlator_t *subvol)
}
}
+out:
return ret;
}
diff --git a/xlators/cluster/dht/src/dht-layout.c b/xlators/cluster/dht/src/dht-layout.c
index a9ecc587483..a11b78f8d06 100644
--- a/xlators/cluster/dht/src/dht-layout.c
+++ b/xlators/cluster/dht/src/dht-layout.c
@@ -72,6 +72,9 @@ dht_layout_get (xlator_t *this, inode_t *inode)
int ret = -1;
conf = this->private;
+ if (!conf)
+ goto out;
+
LOCK (&conf->layout_lock);
{
ret = inode_ctx_get (inode, this, &layout_int);
@@ -82,6 +85,7 @@ dht_layout_get (xlator_t *this, inode_t *inode)
}
UNLOCK (&conf->layout_lock);
+out:
return layout;
}
@@ -96,6 +100,9 @@ dht_layout_set (xlator_t *this, inode_t *inode, dht_layout_t *layout)
uint64_t old_layout_int;
conf = this->private;
+ if (!conf)
+ goto out;
+
LOCK (&conf->layout_lock);
{
oldret = inode_ctx_get (inode, this, &old_layout_int);
@@ -111,6 +118,7 @@ dht_layout_set (xlator_t *this, inode_t *inode, dht_layout_t *layout)
dht_layout_unref (this, old_layout);
}
+out:
return ret;
}
@@ -121,10 +129,11 @@ dht_layout_unref (xlator_t *this, dht_layout_t *layout)
dht_conf_t *conf = NULL;
int ref = 0;
- if (layout->preset)
+ if (layout->preset || !this->private)
return;
conf = this->private;
+
LOCK (&conf->layout_lock);
{
ref = --layout->ref;
@@ -141,7 +150,7 @@ dht_layout_ref (xlator_t *this, dht_layout_t *layout)
{
dht_conf_t *conf = NULL;
- if (layout->preset)
+ if (layout->preset || !this->private)
return layout;
conf = this->private;
@@ -197,8 +206,9 @@ dht_layout_for_subvol (xlator_t *this, xlator_t *subvol)
dht_layout_t *layout = NULL;
int i = 0;
-
conf = this->private;
+ if (!conf)
+ goto out;
for (i = 0; i < conf->subvolume_cnt; i++) {
if (conf->subvolumes[i] == subvol) {
@@ -207,6 +217,7 @@ dht_layout_for_subvol (xlator_t *this, xlator_t *subvol)
}
}
+out:
return layout;
}
@@ -217,7 +228,9 @@ dht_layouts_init (xlator_t *this, dht_conf_t *conf)
dht_layout_t *layout = NULL;
int i = 0;
int ret = -1;
-
+
+ if (!conf)
+ goto out;
conf->file_layouts = GF_CALLOC (conf->subvolume_cnt,
sizeof (dht_layout_t *),
@@ -691,6 +704,8 @@ dht_layout_preset (xlator_t *this, xlator_t *subvol, inode_t *inode)
dht_conf_t *conf = NULL;
conf = this->private;
+ if (!conf)
+ goto out;
layout = dht_layout_for_subvol (this, subvol);
if (!layout) {
diff --git a/xlators/cluster/dht/src/dht.c b/xlators/cluster/dht/src/dht.c
index 06623014a86..2c2f1750755 100644
--- a/xlators/cluster/dht/src/dht.c
+++ b/xlators/cluster/dht/src/dht.c
@@ -208,7 +208,7 @@ fini (xlator_t *this)
dht_conf_t *conf = NULL;
conf = this->private;
-
+ this->private = NULL;
if (conf) {
if (conf->file_layouts) {
for (i = 0; i < conf->subvolume_cnt; i++) {
@@ -262,6 +262,8 @@ reconfigure (xlator_t *this, dict_t *options)
conf = this->private;
+ if (!conf)
+ return 0;
if (dict_get_str (options, "lookup-unhashed", &temp_str) == 0) {
/* If option is not "auto", other options _should_ be boolean*/