diff options
author | Vikas Gorur <vikas@gluster.com> | 2009-09-04 01:43:43 +0000 |
---|---|---|
committer | Anand V. Avati <avati@dev.gluster.com> | 2009-09-08 03:22:31 -0700 |
commit | 8c95c2b69c08fa5c7d845e73d0e63fb2f001c511 (patch) | |
tree | 6a43cbe1adba73904d5d5e89a2c35c4211815152 | |
parent | fdef6f360f0755847d2520d79a4c7f0af35c7b0a (diff) |
storage/posix: Synchronize access to this->private.
Hold lock on priv while updating variables inside it.
Signed-off-by: Anand V. Avati <avati@dev.gluster.com>
BUG: 175 (Statistics for number of open files in Posix incorrect)
URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=175
-rw-r--r-- | xlators/storage/posix/src/posix.c | 73 | ||||
-rw-r--r-- | xlators/storage/posix/src/posix.h | 2 |
2 files changed, 52 insertions, 23 deletions
diff --git a/xlators/storage/posix/src/posix.c b/xlators/storage/posix/src/posix.c index 0c2259132..2d6673e64 100644 --- a/xlators/storage/posix/src/posix.c +++ b/xlators/storage/posix/src/posix.c @@ -47,6 +47,7 @@ #include "byte-order.h" #include "syscall.h" #include "statedump.h" +#include "locking.h" #undef HAVE_SET_FSID #ifdef HAVE_SET_FSID @@ -1490,7 +1491,11 @@ posix_create (call_frame_t *frame, xlator_t *this, fd_ctx_set (fd, this, (uint64_t)(long)pfd); - ((struct posix_private *)this->private)->stats.nr_files++; + LOCK (&priv->lock); + { + priv->stats.nr_files++; + } + UNLOCK (&priv->lock); op_ret = 0; @@ -1561,7 +1566,11 @@ posix_open (call_frame_t *frame, xlator_t *this, fd_ctx_set (fd, this, (uint64_t)(long)pfd); - ((struct posix_private *)this->private)->stats.nr_files++; + LOCK (&priv->lock); + { + priv->stats.nr_files++; + } + UNLOCK (&priv->lock); #ifndef HAVE_SET_FSID if (flags & O_CREAT) { @@ -1666,8 +1675,12 @@ posix_readv (call_frame_t *frame, xlator_t *this, goto out; } - priv->read_value += op_ret; - priv->interval_read += op_ret; + LOCK (&priv->lock); + { + priv->read_value += op_ret; + priv->interval_read += op_ret; + } + UNLOCK (&priv->lock); vec.iov_base = iobuf->ptr; vec.iov_len = op_ret; @@ -1813,8 +1826,12 @@ posix_writev (call_frame_t *frame, xlator_t *this, } } - priv->write_value += op_ret; - priv->interval_write += op_ret; + LOCK (&priv->lock); + { + priv->write_value += op_ret; + priv->interval_write += op_ret; + } + UNLOCK (&priv->lock); if (op_ret >= 0) { /* wiretv successful, we also need to get the stat of @@ -1942,7 +1959,11 @@ posix_release (xlator_t *this, priv = this->private; - priv->stats.nr_files--; + LOCK (&priv->lock); + { + priv->stats.nr_files--; + } + UNLOCK (&priv->lock); ret = fd_ctx_get (fd, this, &tmp_pfd); if (ret < 0) { @@ -3811,27 +3832,31 @@ posix_stats (call_frame_t *frame, xlator_t *this, goto out; } - /* Read */ - _time_ms = (tv.tv_sec - priv->init_time.tv_sec) * 1000 + - ((tv.tv_usec - priv->init_time.tv_usec) / 1000); + LOCK (&priv->lock); + { + /* Read */ + _time_ms = (tv.tv_sec - priv->init_time.tv_sec) * 1000 + + ((tv.tv_usec - priv->init_time.tv_usec) / 1000); - avg_read = (_time_ms) ? (priv->read_value / _time_ms) : 0; /* KBps */ - avg_write = (_time_ms) ? (priv->write_value / _time_ms) : 0; /* KBps */ + avg_read = (_time_ms) ? (priv->read_value / _time_ms) : 0; /* KBps */ + avg_write = (_time_ms) ? (priv->write_value / _time_ms) : 0; /* KBps */ - _time_ms = (tv.tv_sec - priv->prev_fetch_time.tv_sec) * 1000 + - ((tv.tv_usec - priv->prev_fetch_time.tv_usec) / 1000); + _time_ms = (tv.tv_sec - priv->prev_fetch_time.tv_sec) * 1000 + + ((tv.tv_usec - priv->prev_fetch_time.tv_usec) / 1000); - if (_time_ms && ((priv->interval_read / _time_ms) > priv->max_read)) { - priv->max_read = (priv->interval_read / _time_ms); - } + if (_time_ms && ((priv->interval_read / _time_ms) > priv->max_read)) { + priv->max_read = (priv->interval_read / _time_ms); + } - if (_time_ms && - ((priv->interval_write / _time_ms) > priv->max_write)) { - priv->max_write = priv->interval_write / _time_ms; - } + if (_time_ms && + ((priv->interval_write / _time_ms) > priv->max_write)) { + priv->max_write = priv->interval_write / _time_ms; + } - stats->read_usage = avg_read / priv->max_read; - stats->write_usage = avg_write / priv->max_write; + stats->read_usage = avg_read / priv->max_read; + stats->write_usage = avg_write / priv->max_write; + } + UNLOCK (&priv->lock); op_ret = gettimeofday (&(priv->prev_fetch_time), NULL); if (op_ret == -1) { @@ -4080,6 +4105,8 @@ init (xlator_t *this) _private->base_path = strdup (dir_data->data); _private->base_path_length = strlen (_private->base_path); + LOCK_INIT (&_private->lock); + ret = gethostname (_private->hostname, 256); if (ret < 0) { gf_log (this->name, GF_LOG_WARNING, diff --git a/xlators/storage/posix/src/posix.h b/xlators/storage/posix/src/posix.h index 15829db18..9db6c94cd 100644 --- a/xlators/storage/posix/src/posix.h +++ b/xlators/storage/posix/src/posix.h @@ -65,6 +65,8 @@ struct posix_private { char *base_path; int32_t base_path_length; + gf_lock_t lock; + char hostname[256]; /* Statistics, provides activity of the server */ struct xlator_stats stats; |