diff options
author | Mohit Agrawal <moagrawal@redhat.com> | 2018-12-10 11:14:04 +0530 |
---|---|---|
committer | Xavi Hernandez <xhernandez@redhat.com> | 2019-01-15 11:52:22 +0000 |
commit | 2261e444a47ffffb5d64305efceee1d5a734cd75 (patch) | |
tree | 06f85f6e3f4ba6c81a62347ad6b4102f6ec2f847 /xlators | |
parent | f578cdad23d8a8428a7012f777f4987507f19ea4 (diff) |
posix: Convert several posix_private members to gf_atomic
Change-Id: I629698d8ddf6f15428880bdc1501d36bc37b8ebb
fixes: bz#1657607
Signed-off-by: Mohit Agrawal <moagrawal@redhat.com>
Diffstat (limited to 'xlators')
-rw-r--r-- | xlators/storage/posix/src/posix-aio.c | 12 | ||||
-rw-r--r-- | xlators/storage/posix/src/posix-common.c | 10 | ||||
-rw-r--r-- | xlators/storage/posix/src/posix-entry-ops.c | 6 | ||||
-rw-r--r-- | xlators/storage/posix/src/posix-inode-fd-ops.c | 32 | ||||
-rw-r--r-- | xlators/storage/posix/src/posix.h | 6 |
5 files changed, 18 insertions, 48 deletions
diff --git a/xlators/storage/posix/src/posix-aio.c b/xlators/storage/posix/src/posix-aio.c index 7ab38edf1b7..971ace94754 100644 --- a/xlators/storage/posix/src/posix-aio.c +++ b/xlators/storage/posix/src/posix-aio.c @@ -133,11 +133,7 @@ posix_aio_readv_complete(struct posix_aio_cb *paiocb, int res, int res2) if (!postbuf.ia_size || (offset + iov.iov_len) >= postbuf.ia_size) op_errno = ENOENT; - LOCK(&priv->lock); - { - priv->read_value += op_ret; - } - UNLOCK(&priv->lock); + GF_ATOMIC_ADD(priv->read_value, op_ret); out: STACK_UNWIND_STRICT(readv, frame, op_ret, op_errno, &iov, 1, &postbuf, @@ -301,11 +297,7 @@ posix_aio_writev_complete(struct posix_aio_cb *paiocb, int res, int res2) op_ret = res; op_errno = 0; - LOCK(&priv->lock); - { - priv->write_value += op_ret; - } - UNLOCK(&priv->lock); + GF_ATOMIC_ADD(priv->write_value, op_ret); out: STACK_UNWIND_STRICT(writev, frame, op_ret, op_errno, &prebuf, &postbuf, diff --git a/xlators/storage/posix/src/posix-common.c b/xlators/storage/posix/src/posix-common.c index af80f28214b..961b6e871eb 100644 --- a/xlators/storage/posix/src/posix-common.c +++ b/xlators/storage/posix/src/posix-common.c @@ -125,9 +125,10 @@ posix_priv(xlator_t *this) gf_proc_dump_write("base_path", "%s", priv->base_path); gf_proc_dump_write("base_path_length", "%d", priv->base_path_length); - gf_proc_dump_write("max_read", "%" PRId64, priv->read_value); - gf_proc_dump_write("max_write", "%" PRId64, priv->write_value); - gf_proc_dump_write("nr_files", "%" PRId64, priv->nr_files); + gf_proc_dump_write("max_read", "%" PRId64, GF_ATOMIC_GET(priv->read_value)); + gf_proc_dump_write("max_write", "%" PRId64, + GF_ATOMIC_GET(priv->write_value)); + gf_proc_dump_write("nr_files", "%ld", GF_ATOMIC_GET(priv->nr_files)); return 0; } @@ -775,6 +776,9 @@ posix_init(xlator_t *this) } LOCK_INIT(&_private->lock); + GF_ATOMIC_INIT(_private->nr_files, 0); + GF_ATOMIC_INIT(_private->read_value, 0); + GF_ATOMIC_INIT(_private->write_value, 0); _private->export_statfs = 1; tmp_data = dict_get(this->options, "export-statfs-size"); diff --git a/xlators/storage/posix/src/posix-entry-ops.c b/xlators/storage/posix/src/posix-entry-ops.c index 4d705586741..fbd83c4aed1 100644 --- a/xlators/storage/posix/src/posix-entry-ops.c +++ b/xlators/storage/posix/src/posix-entry-ops.c @@ -2210,11 +2210,7 @@ fill_stat: gf_msg(this->name, GF_LOG_WARNING, 0, P_MSG_FD_PATH_SETTING_FAILED, "failed to set the fd context path=%s fd=%p", real_path, fd); - LOCK(&priv->lock); - { - priv->nr_files++; - } - UNLOCK(&priv->lock); + GF_ATOMIC_INC(priv->nr_files); op_ret = 0; diff --git a/xlators/storage/posix/src/posix-inode-fd-ops.c b/xlators/storage/posix/src/posix-inode-fd-ops.c index 9867d5fac69..0aabff2615b 100644 --- a/xlators/storage/posix/src/posix-inode-fd-ops.c +++ b/xlators/storage/posix/src/posix-inode-fd-ops.c @@ -1476,12 +1476,7 @@ posix_open(call_frame_t *frame, xlator_t *this, loc_t *loc, int32_t flags, gf_msg(this->name, GF_LOG_WARNING, 0, P_MSG_FD_PATH_SETTING_FAILED, "failed to set the fd context path=%s fd=%p", real_path, fd); - LOCK(&priv->lock); - { - priv->nr_files++; - } - UNLOCK(&priv->lock); - + GF_ATOMIC_INC(priv->nr_files); op_ret = 0; out: @@ -1590,11 +1585,7 @@ posix_readv(call_frame_t *frame, xlator_t *this, fd_t *fd, size_t size, goto out; } - LOCK(&priv->lock); - { - priv->read_value += op_ret; - } - UNLOCK(&priv->lock); + GF_ATOMIC_ADD(priv->read_value, op_ret); vec.iov_base = iobuf->ptr; vec.iov_len = op_ret; @@ -1940,11 +1931,7 @@ posix_writev(call_frame_t *frame, xlator_t *this, fd_t *fd, } } - LOCK(&priv->lock); - { - priv->write_value += op_ret; - } - UNLOCK(&priv->lock); + GF_ATOMIC_ADD(priv->write_value, op_ret); out: @@ -2208,11 +2195,7 @@ posix_copy_file_range(call_frame_t *frame, xlator_t *this, fd_t *fd_in, * this comment (or add comment to explain why it is not * needed). */ - LOCK(&priv->lock); - { - priv->write_value += op_ret; - } - UNLOCK(&priv->lock); + GF_ATOMIC_ADD(priv->write_value, op_ret); out: @@ -2371,12 +2354,7 @@ posix_release(xlator_t *this, fd_t *fd) if (!priv) goto out; - LOCK(&priv->lock); - { - priv->nr_files--; - } - UNLOCK(&priv->lock); - + GF_ATOMIC_DEC(priv->nr_files); out: return 0; } diff --git a/xlators/storage/posix/src/posix.h b/xlators/storage/posix/src/posix.h index 5a3fd29cc09..d5ba08ca593 100644 --- a/xlators/storage/posix/src/posix.h +++ b/xlators/storage/posix/src/posix.h @@ -152,9 +152,9 @@ struct posix_private { time_t last_landfill_check; int32_t janitor_sleep_duration; - int64_t read_value; /* Total read, from init */ - int64_t write_value; /* Total write, from init */ - int64_t nr_files; + gf_atomic_t read_value; /* Total read, from init */ + gf_atomic_t write_value; /* Total write, from init */ + gf_atomic_t nr_files; /* In some cases, two exported volumes may reside on the same partition on the server. Sending statvfs info for both |