From 186a86f342625a9dce53fe537f8237c6099d5c54 Mon Sep 17 00:00:00 2001 From: Shehjar Tikoo Date: Thu, 1 Oct 2009 06:58:46 +0000 Subject: Global: Introduce setattr and fsetattr fops Signed-off-by: Anand V. Avati BUG: 146 (Add setattr FOP) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=146 --- xlators/cluster/afr/src/afr-inode-write.c | 1173 +++++----------------- xlators/cluster/afr/src/afr-inode-write.h | 8 + xlators/cluster/afr/src/afr-self-heal-common.c | 61 +- xlators/cluster/afr/src/afr-self-heal-entry.c | 114 +-- xlators/cluster/afr/src/afr-self-heal-metadata.c | 58 +- xlators/cluster/afr/src/afr.c | 2 + xlators/cluster/afr/src/afr.h | 16 + 7 files changed, 373 insertions(+), 1059 deletions(-) (limited to 'xlators/cluster/afr/src') diff --git a/xlators/cluster/afr/src/afr-inode-write.c b/xlators/cluster/afr/src/afr-inode-write.c index 6a2774bee..591f7cd49 100644 --- a/xlators/cluster/afr/src/afr-inode-write.c +++ b/xlators/cluster/afr/src/afr-inode-write.c @@ -48,874 +48,6 @@ #include "afr-transaction.h" -/* {{{ chmod */ - - -int -afr_chmod_unwind (call_frame_t *frame, xlator_t *this) -{ - afr_local_t * local = NULL; - afr_private_t * priv = NULL; - call_frame_t *main_frame = NULL; - - struct stat * unwind_buf = NULL; - - local = frame->local; - priv = this->private; - - LOCK (&frame->lock); - { - if (local->transaction.main_frame) - main_frame = local->transaction.main_frame; - local->transaction.main_frame = NULL; - } - UNLOCK (&frame->lock); - - if (main_frame) { - if (local->cont.chmod.read_child_buf.st_ino) { - unwind_buf = &local->cont.chmod.read_child_buf; - } else { - unwind_buf = &local->cont.chmod.buf; - } - - unwind_buf->st_ino = local->cont.chmod.ino; - - AFR_STACK_UNWIND (main_frame, local->op_ret, local->op_errno, - unwind_buf); - } - return 0; -} - - -int -afr_chmod_wind_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, struct stat *buf) -{ - afr_local_t * local = NULL; - afr_private_t * priv = NULL; - - int call_count = -1; - int child_index = (long) cookie; - int need_unwind = 0; - int read_child = 0; - - local = frame->local; - priv = this->private; - - read_child = afr_read_child (this, local->loc.inode); - - LOCK (&frame->lock); - { - if (child_index == read_child) { - local->read_child_returned = _gf_true; - } - - if (afr_fop_failed (op_ret, op_errno)) - afr_transaction_fop_failed (frame, this, child_index); - - if (op_ret != -1) { - if (local->success_count == 0) { - local->op_ret = op_ret; - local->cont.chmod.buf = *buf; - } - - if (child_index == read_child) { - local->cont.chmod.read_child_buf = *buf; - } - - local->success_count++; - - if ((local->success_count >= priv->wait_count) - && local->read_child_returned) { - need_unwind = 1; - } - } - - local->op_errno = op_errno; - } - UNLOCK (&frame->lock); - - if (need_unwind) - afr_chmod_unwind (frame, this); - - call_count = afr_frame_return (frame); - - if (call_count == 0) { - local->transaction.resume (frame, this); - } - - return 0; -} - - -int -afr_chmod_wind (call_frame_t *frame, xlator_t *this) -{ - afr_local_t * local = NULL; - afr_private_t * priv = NULL; - - int i = 0; - int call_count = -1; - - local = frame->local; - priv = this->private; - - call_count = afr_up_children_count (priv->child_count, local->child_up); - - if (call_count == 0) { - local->transaction.resume (frame, this); - return 0; - } - - local->call_count = call_count; - - for (i = 0; i < priv->child_count; i++) { - if (local->child_up[i]) { - STACK_WIND_COOKIE (frame, afr_chmod_wind_cbk, (void *) (long) i, - priv->children[i], - priv->children[i]->fops->chmod, - &local->loc, - local->cont.chmod.mode); - - if (!--call_count) - break; - } - } - - return 0; -} - - -int -afr_chmod_done (call_frame_t *frame, xlator_t *this) -{ - afr_local_t * local = NULL; - - local = frame->local; - - local->transaction.unwind (frame, this); - - AFR_STACK_DESTROY (frame); - - return 0; -} - - -int32_t -afr_chmod (call_frame_t *frame, xlator_t *this, - loc_t *loc, mode_t mode) -{ - afr_private_t * priv = NULL; - afr_local_t * local = NULL; - call_frame_t * transaction_frame = NULL; - - int ret = -1; - - int op_ret = -1; - int op_errno = 0; - - VALIDATE_OR_GOTO (frame, out); - VALIDATE_OR_GOTO (this, out); - VALIDATE_OR_GOTO (this->private, out); - - priv = this->private; - - transaction_frame = copy_frame (frame); - if (!transaction_frame) { - gf_log (this->name, GF_LOG_ERROR, - "Out of memory."); - goto out; - } - - ALLOC_OR_GOTO (local, afr_local_t, out); - ret = AFR_LOCAL_INIT (local, priv); - if (ret < 0) { - op_errno = -ret; - goto out; - } - - transaction_frame->local = local; - - local->cont.chmod.mode = mode; - local->cont.chmod.ino = loc->inode->ino; - - local->transaction.fop = afr_chmod_wind; - local->transaction.done = afr_chmod_done; - local->transaction.unwind = afr_chmod_unwind; - - loc_copy (&local->loc, loc); - - local->transaction.main_frame = frame; - local->transaction.start = LLONG_MAX - 1; - local->transaction.len = 0; - - afr_transaction (transaction_frame, this, AFR_METADATA_TRANSACTION); - - op_ret = 0; -out: - if (op_ret == -1) { - if (transaction_frame) - AFR_STACK_DESTROY (transaction_frame); - AFR_STACK_UNWIND (frame, op_ret, op_errno, NULL); - } - - return 0; -} - -/* }}} */ - - -/* {{{ fchmod */ - -int -afr_fchmod_unwind (call_frame_t *frame, xlator_t *this) -{ - afr_local_t * local = NULL; - afr_private_t * priv = NULL; - call_frame_t *main_frame = NULL; - struct stat *unwind_buf = NULL; - - local = frame->local; - priv = this->private; - - LOCK (&frame->lock); - { - if (local->transaction.main_frame) - main_frame = local->transaction.main_frame; - local->transaction.main_frame = NULL; - } - UNLOCK (&frame->lock); - - if (main_frame) { - if (local->cont.fchmod.read_child_buf.st_ino) { - unwind_buf = &local->cont.fchmod.read_child_buf; - } else { - unwind_buf = &local->cont.fchmod.buf; - } - - unwind_buf->st_ino = local->cont.fchmod.ino; - - AFR_STACK_UNWIND (main_frame, local->op_ret, local->op_errno, - unwind_buf); - } - return 0; -} - - -int -afr_fchmod_wind_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, struct stat *buf) -{ - afr_local_t * local = NULL; - afr_private_t * priv = NULL; - - int call_count = -1; - int child_index = (long) cookie; - int need_unwind = 0; - int read_child = 0; - - local = frame->local; - priv = this->private; - - read_child = afr_read_child (this, local->fd->inode); - - LOCK (&frame->lock); - { - if (child_index == read_child) { - local->read_child_returned = _gf_true; - } - - if (afr_fop_failed (op_ret, op_errno)) - afr_transaction_fop_failed (frame, this, child_index); - - if (op_ret != -1) { - if (local->success_count == 0) { - local->op_ret = op_ret; - local->cont.fchmod.buf = *buf; - } - - if (child_index == read_child) { - local->cont.fchmod.read_child_buf = *buf; - } - - local->success_count++; - - if ((local->success_count >= priv->wait_count) - && local->read_child_returned) { - need_unwind = 1; - } - } - - local->op_errno = op_errno; - } - UNLOCK (&frame->lock); - - if (need_unwind) - afr_fchmod_unwind (frame, this); - - call_count = afr_frame_return (frame); - - if (call_count == 0) { - local->transaction.resume (frame, this); - } - - return 0; -} - - -int -afr_fchmod_wind (call_frame_t *frame, xlator_t *this) -{ - afr_local_t * local = NULL; - afr_private_t * priv = NULL; - - int i = 0; - int call_count = -1; - - local = frame->local; - priv = this->private; - - call_count = afr_up_children_count (priv->child_count, local->child_up); - - if (call_count == 0) { - local->transaction.resume (frame, this); - return 0; - } - - local->call_count = call_count; - - for (i = 0; i < priv->child_count; i++) { - if (local->child_up[i]) { - STACK_WIND_COOKIE (frame, afr_fchmod_wind_cbk, (void *) (long) i, - priv->children[i], - priv->children[i]->fops->fchmod, - local->fd, - local->cont.fchmod.mode); - - if (!--call_count) - break; - } - } - - return 0; -} - - -int -afr_fchmod_done (call_frame_t *frame, xlator_t *this) -{ - afr_local_t * local = NULL; - - local = frame->local; - - local->transaction.unwind (frame, this); - - AFR_STACK_DESTROY (frame); - - return 0; -} - - -int32_t -afr_fchmod (call_frame_t *frame, xlator_t *this, - fd_t *fd, mode_t mode) -{ - afr_private_t * priv = NULL; - afr_local_t * local = NULL; - call_frame_t * transaction_frame = NULL; - - int ret = -1; - - int op_ret = -1; - int op_errno = 0; - - VALIDATE_OR_GOTO (frame, out); - VALIDATE_OR_GOTO (this, out); - VALIDATE_OR_GOTO (this->private, out); - - priv = this->private; - - transaction_frame = copy_frame (frame); - if (!transaction_frame) { - gf_log (this->name, GF_LOG_ERROR, - "Out of memory."); - goto out; - } - - ALLOC_OR_GOTO (local, afr_local_t, out); - ret = AFR_LOCAL_INIT (local, priv); - if (ret < 0) { - op_errno = -ret; - goto out; - } - - transaction_frame->local = local; - - local->cont.fchmod.mode = mode; - local->cont.fchmod.ino = fd->inode->ino; - - local->transaction.fop = afr_fchmod_wind; - local->transaction.done = afr_fchmod_done; - local->transaction.unwind = afr_fchmod_unwind; - - local->fd = fd_ref (fd); - - local->transaction.main_frame = frame; - local->transaction.start = LLONG_MAX - 1; - local->transaction.len = 0; - - afr_transaction (transaction_frame, this, AFR_METADATA_TRANSACTION); - - op_ret = 0; -out: - if (op_ret == -1) { - if (transaction_frame) - AFR_STACK_DESTROY (transaction_frame); - AFR_STACK_UNWIND (frame, op_ret, op_errno, NULL); - } - - return 0; -} - -/* }}} */ - -/* {{{ chown */ - -int -afr_chown_unwind (call_frame_t *frame, xlator_t *this) -{ - afr_local_t * local = NULL; - afr_private_t * priv = NULL; - call_frame_t *main_frame = NULL; - - struct stat * unwind_buf = NULL; - - local = frame->local; - priv = this->private; - - LOCK (&frame->lock); - { - if (local->transaction.main_frame) - main_frame = local->transaction.main_frame; - local->transaction.main_frame = NULL; - } - UNLOCK (&frame->lock); - - if (main_frame) { - if (local->cont.chown.read_child_buf.st_ino) { - unwind_buf = &local->cont.chown.read_child_buf; - } else { - unwind_buf = &local->cont.chown.buf; - } - - unwind_buf->st_ino = local->cont.chown.ino; - - AFR_STACK_UNWIND (main_frame, local->op_ret, local->op_errno, - unwind_buf); - } - return 0; -} - - -int -afr_chown_wind_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, struct stat *buf) -{ - afr_local_t * local = NULL; - afr_private_t * priv = NULL; - - int call_count = -1; - int child_index = (long) cookie; - int need_unwind = 0; - int read_child = 0; - - local = frame->local; - priv = this->private; - - read_child = afr_read_child (this, local->loc.inode); - - LOCK (&frame->lock); - { - if (child_index == read_child) { - local->read_child_returned = _gf_true; - } - - if (afr_fop_failed (op_ret, op_errno)) - afr_transaction_fop_failed (frame, this, child_index); - - if (op_ret != -1) { - if (local->success_count == 0) { - local->op_ret = op_ret; - local->cont.chown.buf = *buf; - } - - if (child_index == read_child) { - local->cont.chown.read_child_buf = *buf; - } - - local->success_count++; - - if ((local->success_count >= priv->wait_count) - && local->read_child_returned) { - need_unwind = 1; - } - } - - local->op_errno = op_errno; - } - UNLOCK (&frame->lock); - - if (need_unwind) { - local->transaction.unwind (frame, this); - } - - call_count = afr_frame_return (frame); - - if (call_count == 0) { - local->transaction.resume (frame, this); - } - - return 0; -} - - -int -afr_chown_wind (call_frame_t *frame, xlator_t *this) -{ - afr_local_t * local = NULL; - afr_private_t * priv = NULL; - - int call_count = -1; - int i = 0; - - local = frame->local; - priv = this->private; - - call_count = afr_up_children_count (priv->child_count, local->child_up); - - if (call_count == 0) { - local->transaction.resume (frame, this); - return 0; - } - - local->call_count = call_count; - - for (i = 0; i < priv->child_count; i++) { - if (local->child_up[i]) { - STACK_WIND_COOKIE (frame, afr_chown_wind_cbk, (void *) (long) i, - priv->children[i], - priv->children[i]->fops->chown, - &local->loc, local->cont.chown.uid, - local->cont.chown.gid); - - if (!--call_count) - break; - } - } - - return 0; -} - - -int -afr_chown_done (call_frame_t *frame, xlator_t *this) -{ - afr_local_t *local = NULL; - - local = frame->local; - - local->transaction.unwind (frame, this); - - AFR_STACK_DESTROY (frame); - - return 0; -} - - -int -afr_chown (call_frame_t *frame, xlator_t *this, - loc_t *loc, uid_t uid, gid_t gid) -{ - afr_private_t * priv = NULL; - afr_local_t * local = NULL; - call_frame_t *transaction_frame = NULL; - - int ret = -1; - - int op_ret = -1; - int op_errno = 0; - - VALIDATE_OR_GOTO (frame, out); - VALIDATE_OR_GOTO (this, out); - VALIDATE_OR_GOTO (this->private, out); - - priv = this->private; - - transaction_frame = copy_frame (frame); - if (!transaction_frame) { - gf_log (this->name, GF_LOG_ERROR, - "Out of memory."); - goto out; - } - - ALLOC_OR_GOTO (local, afr_local_t, out); - - ret = AFR_LOCAL_INIT (local, priv); - if (ret < 0) { - op_errno = -ret; - goto out; - } - - transaction_frame->local = local; - - local->cont.chown.uid = uid; - local->cont.chown.gid = gid; - local->cont.chown.ino = loc->inode->ino; - - local->transaction.fop = afr_chown_wind; - local->transaction.done = afr_chown_done; - local->transaction.unwind = afr_chown_unwind; - - loc_copy (&local->loc, loc); - - local->transaction.main_frame = frame; - local->transaction.start = LLONG_MAX - 1; - local->transaction.len = 0; - - afr_transaction (transaction_frame, this, AFR_METADATA_TRANSACTION); - - op_ret = 0; -out: - if (op_ret == -1) { - if (transaction_frame) - AFR_STACK_DESTROY (transaction_frame); - AFR_STACK_UNWIND (frame, op_ret, op_errno, NULL); - } - - return 0; -} - - -/* }}} */ - -/* {{{ chown */ - -int -afr_fchown_unwind (call_frame_t *frame, xlator_t *this) -{ - afr_local_t * local = NULL; - afr_private_t * priv = NULL; - call_frame_t *main_frame = NULL; - - struct stat * unwind_buf = NULL; - - local = frame->local; - priv = this->private; - - LOCK (&frame->lock); - { - if (local->transaction.main_frame) - main_frame = local->transaction.main_frame; - local->transaction.main_frame = NULL; - } - UNLOCK (&frame->lock); - - if (main_frame) { - if (local->cont.fchown.read_child_buf.st_ino) { - unwind_buf = &local->cont.fchown.read_child_buf; - } else { - unwind_buf = &local->cont.fchown.buf; - } - - unwind_buf->st_ino = local->cont.fchown.ino; - - AFR_STACK_UNWIND (main_frame, local->op_ret, local->op_errno, - unwind_buf); - } - return 0; -} - - -int -afr_fchown_wind_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, struct stat *buf) -{ - afr_local_t * local = NULL; - afr_private_t * priv = NULL; - - int call_count = -1; - int child_index = (long) cookie; - int need_unwind = 0; - int read_child = 0; - - local = frame->local; - priv = this->private; - - read_child = afr_read_child (this, local->fd->inode); - - LOCK (&frame->lock); - { - if (child_index == read_child) { - local->read_child_returned = _gf_true; - } - - if (afr_fop_failed (op_ret, op_errno)) - afr_transaction_fop_failed (frame, this, child_index); - - if (op_ret != -1) { - if (local->success_count == 0) { - local->op_ret = op_ret; - local->cont.fchown.buf = *buf; - } - - if (child_index == read_child) { - local->cont.fchown.read_child_buf = *buf; - } - - local->success_count++; - - if ((local->success_count >= priv->wait_count) - && local->read_child_returned) { - need_unwind = 1; - } - } - - local->op_errno = op_errno; - } - UNLOCK (&frame->lock); - - if (need_unwind) { - local->transaction.unwind (frame, this); - } - - call_count = afr_frame_return (frame); - - if (call_count == 0) { - local->transaction.resume (frame, this); - } - - return 0; -} - - -int -afr_fchown_wind (call_frame_t *frame, xlator_t *this) -{ - afr_local_t * local = NULL; - afr_private_t * priv = NULL; - - int call_count = -1; - int i = 0; - - local = frame->local; - priv = this->private; - - call_count = afr_up_children_count (priv->child_count, local->child_up); - - if (call_count == 0) { - local->transaction.resume (frame, this); - return 0; - } - - local->call_count = call_count; - - for (i = 0; i < priv->child_count; i++) { - if (local->child_up[i]) { - STACK_WIND_COOKIE (frame, afr_fchown_wind_cbk, (void *) (long) i, - priv->children[i], - priv->children[i]->fops->fchown, - local->fd, local->cont.fchown.uid, - local->cont.fchown.gid); - - if (!--call_count) - break; - } - } - - return 0; -} - - -int -afr_fchown_done (call_frame_t *frame, xlator_t *this) -{ - afr_local_t *local = NULL; - - local = frame->local; - - local->transaction.unwind (frame, this); - - AFR_STACK_DESTROY (frame); - - return 0; -} - - -int -afr_fchown (call_frame_t *frame, xlator_t *this, - fd_t *fd, uid_t uid, gid_t gid) -{ - afr_private_t * priv = NULL; - afr_local_t * local = NULL; - call_frame_t *transaction_frame = NULL; - - int ret = -1; - - int op_ret = -1; - int op_errno = 0; - - VALIDATE_OR_GOTO (frame, out); - VALIDATE_OR_GOTO (this, out); - VALIDATE_OR_GOTO (this->private, out); - - priv = this->private; - - transaction_frame = copy_frame (frame); - if (!transaction_frame) { - gf_log (this->name, GF_LOG_ERROR, - "Out of memory."); - goto out; - } - - ALLOC_OR_GOTO (local, afr_local_t, out); - - ret = AFR_LOCAL_INIT (local, priv); - if (ret < 0) { - op_errno = -ret; - goto out; - } - - transaction_frame->local = local; - - local->cont.fchown.uid = uid; - local->cont.fchown.gid = gid; - local->cont.fchown.ino = fd->inode->ino; - - local->transaction.fop = afr_fchown_wind; - local->transaction.done = afr_fchown_done; - local->transaction.unwind = afr_fchown_unwind; - - local->fd = fd_ref (fd); - - local->transaction.main_frame = frame; - local->transaction.start = LLONG_MAX - 1; - local->transaction.len = 0; - - afr_transaction (transaction_frame, this, AFR_METADATA_TRANSACTION); - - op_ret = 0; -out: - if (op_ret == -1) { - if (transaction_frame) - AFR_STACK_DESTROY (transaction_frame); - AFR_STACK_UNWIND (frame, op_ret, op_errno, NULL); - } - - return 0; -} - -/* }}} */ - /* {{{ writev */ int @@ -1589,18 +721,15 @@ out: /* }}} */ -/* {{{ utimens */ - +/* {{{ setattr */ int -afr_utimens_unwind (call_frame_t *frame, xlator_t *this) +afr_setattr_unwind (call_frame_t *frame, xlator_t *this) { afr_local_t * local = NULL; afr_private_t * priv = NULL; call_frame_t *main_frame = NULL; - struct stat * unwind_buf = NULL; - local = frame->local; priv = this->private; @@ -1613,35 +742,252 @@ afr_utimens_unwind (call_frame_t *frame, xlator_t *this) UNLOCK (&frame->lock); if (main_frame) { - if (local->cont.utimens.read_child_buf.st_ino) { - unwind_buf = &local->cont.utimens.read_child_buf; - } else { - unwind_buf = &local->cont.utimens.buf; + local->cont.setattr.preop_buf.st_ino = local->cont.setattr.ino; + local->cont.setattr.postop_buf.st_ino = local->cont.setattr.ino; + + AFR_STACK_UNWIND (main_frame, local->op_ret, local->op_errno, + &local->cont.setattr.preop_buf, + &local->cont.setattr.postop_buf); + } + + return 0; +} + + +int +afr_setattr_wind_cbk (call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, + struct stat *preop, struct stat *postop) +{ + afr_local_t * local = NULL; + afr_private_t * priv = NULL; + + int child_index = (long) cookie; + int read_child = 0; + int call_count = -1; + int need_unwind = 0; + + local = frame->local; + priv = this->private; + + read_child = afr_read_child (this, local->loc.inode); + + LOCK (&frame->lock); + { + if (child_index == read_child) { + local->read_child_returned = _gf_true; } - unwind_buf->st_ino = local->cont.utimens.ino; + if (afr_fop_failed (op_ret, op_errno)) + afr_transaction_fop_failed (frame, this, child_index); - AFR_STACK_UNWIND (main_frame, local->op_ret, local->op_errno, - unwind_buf); + if (op_ret != -1) { + if (local->success_count == 0) { + local->op_ret = op_ret; + local->cont.setattr.preop_buf = *preop; + local->cont.setattr.postop_buf = *postop; + } + + if (child_index == read_child) { + local->cont.setattr.preop_buf = *preop; + local->cont.setattr.postop_buf = *postop; + } + + local->success_count++; + + if ((local->success_count >= priv->wait_count) + && local->read_child_returned) { + need_unwind = 1; + } + } + local->op_errno = op_errno; + } + UNLOCK (&frame->lock); + + if (need_unwind) + local->transaction.unwind (frame, this); + + call_count = afr_frame_return (frame); + + if (call_count == 0) { + local->transaction.resume (frame, this); + } + + return 0; +} + + +int32_t +afr_setattr_wind (call_frame_t *frame, xlator_t *this) +{ + afr_local_t *local = NULL; + afr_private_t *priv = NULL; + + int call_count = -1; + int i = 0; + + local = frame->local; + priv = this->private; + + call_count = afr_up_children_count (priv->child_count, local->child_up); + + if (call_count == 0) { + local->transaction.resume (frame, this); + return 0; + } + + local->call_count = call_count; + + for (i = 0; i < priv->child_count; i++) { + if (local->child_up[i]) { + STACK_WIND_COOKIE (frame, afr_setattr_wind_cbk, + (void *) (long) i, + priv->children[i], + priv->children[i]->fops->setattr, + &local->loc, + &local->cont.setattr.in_buf, + local->cont.setattr.valid); + + if (!--call_count) + break; + } + } + + return 0; +} + + +int +afr_setattr_done (call_frame_t *frame, xlator_t *this) +{ + afr_local_t *local = NULL; + + local = frame->local; + + local->transaction.unwind (frame, this); + + AFR_STACK_DESTROY (frame); + + return 0; +} + + +int +afr_setattr (call_frame_t *frame, xlator_t *this, + loc_t *loc, struct stat *buf, int32_t valid) +{ + afr_private_t * priv = NULL; + afr_local_t * local = NULL; + call_frame_t *transaction_frame = NULL; + + int ret = -1; + + int op_ret = -1; + int op_errno = 0; + + VALIDATE_OR_GOTO (frame, out); + VALIDATE_OR_GOTO (this, out); + VALIDATE_OR_GOTO (this->private, out); + + priv = this->private; + + transaction_frame = copy_frame (frame); + if (!transaction_frame) { + gf_log (this->name, GF_LOG_ERROR, + "Out of memory."); + goto out; + } + + ALLOC_OR_GOTO (local, afr_local_t, out); + + ret = AFR_LOCAL_INIT (local, priv); + if (ret < 0) { + op_errno = -ret; + goto out; + } + + transaction_frame->local = local; + + local->op_ret = -1; + + local->cont.setattr.ino = loc->inode->ino; + + local->cont.setattr.in_buf = *buf; + local->cont.setattr.valid = valid; + + local->transaction.fop = afr_setattr_wind; + local->transaction.done = afr_setattr_done; + local->transaction.unwind = afr_setattr_unwind; + + loc_copy (&local->loc, loc); + + local->transaction.main_frame = frame; + local->transaction.start = LLONG_MAX - 1; + local->transaction.len = 0; + + afr_transaction (transaction_frame, this, AFR_METADATA_TRANSACTION); + + op_ret = 0; +out: + if (op_ret == -1) { + if (transaction_frame) + AFR_STACK_DESTROY (transaction_frame); + AFR_STACK_UNWIND (frame, op_ret, op_errno, NULL); + } + + return 0; +} + +/* {{{ fsetattr */ + +int +afr_fsetattr_unwind (call_frame_t *frame, xlator_t *this) +{ + afr_local_t * local = NULL; + afr_private_t * priv = NULL; + call_frame_t *main_frame = NULL; + + local = frame->local; + priv = this->private; + + LOCK (&frame->lock); + { + if (local->transaction.main_frame) + main_frame = local->transaction.main_frame; + local->transaction.main_frame = NULL; } + UNLOCK (&frame->lock); + + if (main_frame) { + local->cont.fsetattr.preop_buf.st_ino = + local->cont.fsetattr.ino; + local->cont.fsetattr.postop_buf.st_ino = + local->cont.fsetattr.ino; + + AFR_STACK_UNWIND (main_frame, local->op_ret, local->op_errno, + &local->cont.fsetattr.preop_buf, + &local->cont.fsetattr.postop_buf); + } + return 0; } int -afr_utimens_wind_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, struct stat *buf) +afr_fsetattr_wind_cbk (call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, + struct stat *preop, struct stat *postop) { afr_local_t * local = NULL; afr_private_t * priv = NULL; int child_index = (long) cookie; - int call_count = -1; - int need_unwind = 1; int read_child = 0; + int call_count = -1; + int need_unwind = 0; local = frame->local; - priv = this->private; + priv = this->private; read_child = afr_read_child (this, local->loc.inode); @@ -1657,11 +1003,13 @@ afr_utimens_wind_cbk (call_frame_t *frame, void *cookie, xlator_t *this, if (op_ret != -1) { if (local->success_count == 0) { local->op_ret = op_ret; - local->cont.utimens.buf = *buf; + local->cont.fsetattr.preop_buf = *preop; + local->cont.fsetattr.postop_buf = *postop; } if (child_index == read_child) { - local->cont.utimens.read_child_buf = *buf; + local->cont.fsetattr.preop_buf = *preop; + local->cont.fsetattr.postop_buf = *postop; } local->success_count++; @@ -1671,7 +1019,6 @@ afr_utimens_wind_cbk (call_frame_t *frame, void *cookie, xlator_t *this, need_unwind = 1; } } - local->op_errno = op_errno; } UNLOCK (&frame->lock); @@ -1684,17 +1031,17 @@ afr_utimens_wind_cbk (call_frame_t *frame, void *cookie, xlator_t *this, if (call_count == 0) { local->transaction.resume (frame, this); } - + return 0; } -int -afr_utimens_wind (call_frame_t *frame, xlator_t *this) +int32_t +afr_fsetattr_wind (call_frame_t *frame, xlator_t *this) { afr_local_t *local = NULL; afr_private_t *priv = NULL; - + int call_count = -1; int i = 0; @@ -1710,28 +1057,29 @@ afr_utimens_wind (call_frame_t *frame, xlator_t *this) local->call_count = call_count; - for (i = 0; i < priv->child_count; i++) { + for (i = 0; i < priv->child_count; i++) { if (local->child_up[i]) { - STACK_WIND_COOKIE (frame, afr_utimens_wind_cbk, - (void *) (long) i, - priv->children[i], - priv->children[i]->fops->utimens, - &local->loc, - local->cont.utimens.tv); + STACK_WIND_COOKIE (frame, afr_fsetattr_wind_cbk, + (void *) (long) i, + priv->children[i], + priv->children[i]->fops->fsetattr, + local->fd, + &local->cont.fsetattr.in_buf, + local->cont.fsetattr.valid); if (!--call_count) break; } } - + return 0; } int -afr_utimens_done (call_frame_t *frame, xlator_t *this) +afr_fsetattr_done (call_frame_t *frame, xlator_t *this) { - afr_local_t * local = NULL; + afr_local_t *local = NULL; local = frame->local; @@ -1744,8 +1092,8 @@ afr_utimens_done (call_frame_t *frame, xlator_t *this) int -afr_utimens (call_frame_t *frame, xlator_t *this, - loc_t *loc, struct timespec tv[2]) +afr_fsetattr (call_frame_t *frame, xlator_t *this, + fd_t *fd, struct stat *buf, int32_t valid) { afr_private_t * priv = NULL; afr_local_t * local = NULL; @@ -1781,17 +1129,17 @@ afr_utimens (call_frame_t *frame, xlator_t *this, local->op_ret = -1; - local->cont.utimens.tv[0] = tv[0]; - local->cont.utimens.tv[1] = tv[1]; + local->cont.fsetattr.ino = fd->inode->ino; - local->cont.utimens.ino = loc->inode->ino; + local->cont.fsetattr.in_buf = *buf; + local->cont.fsetattr.valid = valid; - local->transaction.fop = afr_utimens_wind; - local->transaction.done = afr_utimens_done; - local->transaction.unwind = afr_utimens_unwind; + local->transaction.fop = afr_fsetattr_wind; + local->transaction.done = afr_fsetattr_done; + local->transaction.unwind = afr_fsetattr_unwind; + + local->fd = fd_ref (fd); - loc_copy (&local->loc, loc); - local->transaction.main_frame = frame; local->transaction.start = LLONG_MAX - 1; local->transaction.len = 0; @@ -1809,7 +1157,6 @@ out: return 0; } -/* }}} */ /* {{{ setxattr */ diff --git a/xlators/cluster/afr/src/afr-inode-write.h b/xlators/cluster/afr/src/afr-inode-write.h index 358d25b52..b92a66e1f 100644 --- a/xlators/cluster/afr/src/afr-inode-write.h +++ b/xlators/cluster/afr/src/afr-inode-write.h @@ -53,6 +53,14 @@ int32_t afr_utimens (call_frame_t *frame, xlator_t *this, loc_t *loc, struct timespec tv[2]); +int +afr_setattr (call_frame_t *frame, xlator_t *this, + loc_t *loc, struct stat *buf, int32_t valid); + +int +afr_fsetattr (call_frame_t *frame, xlator_t *this, + fd_t *fd, struct stat *buf, int32_t valid); + int32_t afr_setxattr (call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *dict, int32_t flags); diff --git a/xlators/cluster/afr/src/afr-self-heal-common.c b/xlators/cluster/afr/src/afr-self-heal-common.c index 38fe1e6e7..4a260ed90 100644 --- a/xlators/cluster/afr/src/afr-self-heal-common.c +++ b/xlators/cluster/afr/src/afr-self-heal-common.c @@ -808,7 +808,8 @@ sh_missing_entries_finish (call_frame_t *frame, xlator_t *this) static int sh_destroy_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int op_errno, struct stat *stbuf) + int32_t op_ret, int op_errno, + struct stat *preop, struct stat *postop) { afr_local_t *local = NULL; @@ -830,67 +831,59 @@ static int sh_missing_entries_newentry_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno, - inode_t *inode, struct stat *stbuf) + inode_t *inode, struct stat *buf) { afr_local_t *local = NULL; afr_self_heal_t *sh = NULL; afr_private_t *priv = NULL; - call_frame_t *chown_frame = NULL; + call_frame_t *setattr_frame = NULL; int call_count = 0; int child_index = 0; - struct stat *buf = NULL; - - struct timespec ts[2]; + + struct stat stbuf; + int32_t valid = 0; local = frame->local; sh = &local->self_heal; priv = this->private; - buf = &sh->buf[sh->source]; child_index = (long) cookie; #ifdef HAVE_STRUCT_STAT_ST_ATIM_TV_NSEC - ts[0] = sh->buf[sh->source].st_atim; - ts[1] = sh->buf[sh->source].st_mtim; + stbuf.st_atim = sh->buf[sh->source].st_atim; + stbuf.st_mtim = sh->buf[sh->source].st_mtim; #elif HAVE_STRUCT_STAT_ST_ATIMESPEC_TV_NSEC - ts[0] = sh->buf[sh->source].st_atimespec; - ts[1] = sh->buf[sh->source].st_mtimespec; + stbuf.st_atimespec = sh->buf[sh->source].st_atimespec; + stbuf.st_mtimespec = sh->buf[sh->source].st_mtimespec; #else - ts[0].tv_sec = sh->buf[sh->source].st_atime; - ts[1].tv_sec = sh->buf[sh->source].st_mtime; + stbuf.st_atime = sh->buf[sh->source].st_atime; + stbuf.st_mtime = sh->buf[sh->source].st_mtime; #endif + stbuf.st_uid = sh->buf[sh->source].st_uid; + stbuf.st_gid = sh->buf[sh->source].st_gid; + + valid = GF_SET_ATTR_UID | GF_SET_ATTR_GID | + GF_SET_ATTR_ATIME | GF_SET_ATTR_MTIME; + if (op_ret == 0) { - chown_frame = copy_frame (frame); + setattr_frame = copy_frame (frame); - chown_frame->local = CALLOC (1, sizeof (afr_local_t)); + setattr_frame->local = CALLOC (1, sizeof (afr_local_t)); - ((afr_local_t *)chown_frame->local)->call_count = 2; + ((afr_local_t *)setattr_frame->local)->call_count = 1; gf_log (this->name, GF_LOG_TRACE, - "chown %s to %d %d on subvolume %s", - local->loc.path, buf->st_uid, buf->st_gid, - priv->children[child_index]->name); + "setattr (%s) on subvolume %s", + local->loc.path, priv->children[child_index]->name); - STACK_WIND (chown_frame, sh_destroy_cbk, + STACK_WIND (setattr_frame, sh_destroy_cbk, priv->children[child_index], - priv->children[child_index]->fops->chown, - &local->loc, - buf->st_uid, buf->st_gid); - - STACK_WIND (chown_frame, sh_destroy_cbk, - priv->children[child_index], - priv->children[child_index]->fops->utimens, - &local->loc, ts); - + priv->children[child_index]->fops->setattr, + &local->loc, &stbuf, valid); } - LOCK (&frame->lock); - { - } - UNLOCK (&frame->lock); - call_count = afr_frame_return (frame); if (call_count == 0) { diff --git a/xlators/cluster/afr/src/afr-self-heal-entry.c b/xlators/cluster/afr/src/afr-self-heal-entry.c index 80608dbd2..b3bb67209 100644 --- a/xlators/cluster/afr/src/afr-self-heal-entry.c +++ b/xlators/cluster/afr/src/afr-self-heal-entry.c @@ -908,9 +908,10 @@ afr_sh_entry_impunge_entry_done (call_frame_t *frame, xlator_t *this, int -afr_sh_entry_impunge_utimens_cbk (call_frame_t *impunge_frame, void *cookie, - xlator_t *this, int32_t op_ret, - int32_t op_errno, struct stat *stbuf) +afr_sh_entry_impunge_setattr_cbk (call_frame_t *impunge_frame, void *cookie, + xlator_t *this, + int32_t op_ret, int32_t op_errno, + struct stat *preop, struct stat *postop) { int call_count = 0; afr_private_t *priv = NULL; @@ -933,12 +934,12 @@ afr_sh_entry_impunge_utimens_cbk (call_frame_t *impunge_frame, void *cookie, if (op_ret == 0) { gf_log (this->name, GF_LOG_TRACE, - "utimes set for %s on %s", + "setattr done for %s on %s", impunge_local->loc.path, priv->children[child_index]->name); } else { gf_log (this->name, GF_LOG_DEBUG, - "setting utimes of %s on %s failed (%s)", + "setattr (%s) on %s failed (%s)", impunge_local->loc.path, priv->children[child_index]->name, strerror (op_errno)); @@ -959,76 +960,6 @@ afr_sh_entry_impunge_utimens_cbk (call_frame_t *impunge_frame, void *cookie, } -int -afr_sh_entry_impunge_chown_cbk (call_frame_t *impunge_frame, void *cookie, - xlator_t *this, int32_t op_ret, - int32_t op_errno, struct stat *stbuf) -{ - int call_count = 0; - afr_private_t *priv = NULL; - afr_local_t *impunge_local = NULL; - afr_self_heal_t *impunge_sh = NULL; - call_frame_t *frame = NULL; - int active_src = 0; - int child_index = 0; - struct timespec ts[2]; - - - priv = this->private; - impunge_local = impunge_frame->local; - impunge_sh = &impunge_local->self_heal; - frame = impunge_sh->sh_frame; - child_index = (long) cookie; - - if (op_ret == 0) { - gf_log (this->name, GF_LOG_TRACE, - "ownership of %s on %s changed", - impunge_local->loc.path, - priv->children[child_index]->name); - } else { - gf_log (this->name, GF_LOG_DEBUG, - "setting ownership of %s on %s failed (%s)", - impunge_local->loc.path, - priv->children[child_index]->name, - strerror (op_errno)); - goto out; - } - -#ifdef HAVE_STRUCT_STAT_ST_ATIM_TV_NSEC - ts[0] = impunge_local->cont.lookup.buf.st_atim; - ts[1] = impunge_local->cont.lookup.buf.st_mtim; -#elif HAVE_STRUCT_STAT_ST_ATIMESPEC_TV_NSEC - ts[0] = impunge_local->cont.lookup.buf.st_atimespec; - ts[1] = impunge_local->cont.lookup.buf.st_mtimespec; -#else - ts[0].tv_sec = impunge_local->cont.lookup.buf.st_atime; - ts[1].tv_sec = impunge_local->cont.lookup.buf.st_mtime; -#endif - STACK_WIND_COOKIE (impunge_frame, - afr_sh_entry_impunge_utimens_cbk, - (void *) (long) child_index, - priv->children[child_index], - priv->children[child_index]->fops->utimens, - &impunge_local->loc, ts); - - return 0; - -out: - LOCK (&impunge_frame->lock); - { - call_count = --impunge_local->call_count; - } - UNLOCK (&impunge_frame->lock); - - if (call_count == 0) { - AFR_STACK_DESTROY (impunge_frame); - afr_sh_entry_impunge_entry_done (frame, this, active_src); - } - - return 0; -} - - int afr_sh_entry_impunge_xattrop_cbk (call_frame_t *impunge_frame, void *cookie, xlator_t *this, @@ -1041,11 +972,13 @@ afr_sh_entry_impunge_xattrop_cbk (call_frame_t *impunge_frame, void *cookie, call_frame_t *frame = NULL; int child_index = 0; + struct stat stbuf; + int32_t valid = 0; - priv = this->private; + priv = this->private; impunge_local = impunge_frame->local; - impunge_sh = &impunge_local->self_heal; - frame = impunge_sh->sh_frame; + impunge_sh = &impunge_local->self_heal; + frame = impunge_sh->sh_frame; child_index = (long) cookie; @@ -1056,13 +989,30 @@ afr_sh_entry_impunge_xattrop_cbk (call_frame_t *impunge_frame, void *cookie, impunge_local->cont.lookup.buf.st_uid, impunge_local->cont.lookup.buf.st_gid); - STACK_WIND_COOKIE (impunge_frame, afr_sh_entry_impunge_chown_cbk, +#ifdef HAVE_STRUCT_STAT_ST_ATIM_TV_NSEC + stbuf.st_atim = impunge_local->cont.lookup.buf.st_atim; + stbuf.st_mtim = impunge_local->cont.lookup.buf.st_mtim; + +#elif HAVE_STRUCT_STAT_ST_ATIMESPEC_TV_NSEC + stbuf.st_atimespec = impunge_local->cont.lookup.buf.st_atimespec; + stbuf.st_mtimespec = impunge_local->cont.lookup.buf.st_mtimespec; +#else + stbuf.st_atime = impunge_local->cont.lookup.buf.st_atime; + stbuf.st_mtime = impunge_local->cont.lookup.buf.st_mtime; +#endif + + stbuf.st_uid = impunge_local->cont.lookup.buf.st_uid; + stbuf.st_gid = impunge_local->cont.lookup.buf.st_gid; + + valid = GF_SET_ATTR_UID | GF_SET_ATTR_GID | + GF_SET_ATTR_ATIME | GF_SET_ATTR_MTIME; + + STACK_WIND_COOKIE (impunge_frame, afr_sh_entry_impunge_setattr_cbk, (void *) (long) child_index, priv->children[child_index], - priv->children[child_index]->fops->chown, + priv->children[child_index]->fops->setattr, &impunge_local->loc, - impunge_local->cont.lookup.buf.st_uid, - impunge_local->cont.lookup.buf.st_gid); + &stbuf, valid); return 0; } diff --git a/xlators/cluster/afr/src/afr-self-heal-metadata.c b/xlators/cluster/afr/src/afr-self-heal-metadata.c index 966b754b3..686446b5f 100644 --- a/xlators/cluster/afr/src/afr-self-heal-metadata.c +++ b/xlators/cluster/afr/src/afr-self-heal-metadata.c @@ -306,8 +306,9 @@ afr_sh_metadata_sync_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int -afr_sh_metadata_attr_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, struct stat *buf) +afr_sh_metadata_setattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, + struct stat *preop, struct stat *postop) { afr_sh_metadata_sync_cbk (frame, cookie, this, op_ret, op_errno); @@ -335,8 +336,9 @@ afr_sh_metadata_sync (call_frame_t *frame, xlator_t *this, dict_t *xattr) int active_sinks = 0; int call_count = 0; int i = 0; - struct timespec ts[2]; + struct stat stbuf; + int32_t valid = 0; local = frame->local; sh = &local->self_heal; @@ -346,26 +348,36 @@ afr_sh_metadata_sync (call_frame_t *frame, xlator_t *this, dict_t *xattr) active_sinks = sh->active_sinks; /* - * 4 calls per sink - chown, chmod, utimes, setxattr + * 2 calls per sink - setattr, setxattr */ if (xattr) - call_count = active_sinks * 4; + call_count = active_sinks * 2; else - call_count = active_sinks * 3; + call_count = active_sinks; local->call_count = call_count; #ifdef HAVE_STRUCT_STAT_ST_ATIM_TV_NSEC - ts[0] = sh->buf[source].st_atim; - ts[1] = sh->buf[source].st_mtim; + stbuf.st_atim = sh->buf[source].st_atim; + stbuf.st_mtim = sh->buf[source].st_mtim; + #elif HAVE_STRUCT_STAT_ST_ATIMESPEC_TV_NSEC - ts[0] = sh->buf[source].st_atimespec; - ts[1] = sh->buf[source].st_mtimespec; + stbuf.st_atimespec = sh->buf[source].st_atimespec; + stbuf.st_mtimespec = sh->buf[source].st_mtimespec; #else - ts[0].tv_sec = sh->buf[source].st_atime; - ts[1].tv_sec = sh->buf[source].st_mtime; + stbuf.st_atime = sh->buf[source].st_atime; + stbuf.st_mtime = sh->buf[source].st_mtime; #endif + stbuf.st_uid = sh->buf[source].st_uid; + stbuf.st_gid = sh->buf[source].st_gid; + + stbuf.st_mode = sh->buf[source].st_mode; + + valid = GF_SET_ATTR_MODE | + GF_SET_ATTR_UID | GF_SET_ATTR_GID | + GF_SET_ATTR_ATIME | GF_SET_ATTR_MTIME; + for (i = 0; i < priv->child_count; i++) { if (call_count == 0) { break; @@ -378,27 +390,13 @@ afr_sh_metadata_sync (call_frame_t *frame, xlator_t *this, dict_t *xattr) local->loc.path, priv->children[source]->name, priv->children[i]->name); - STACK_WIND_COOKIE (frame, afr_sh_metadata_attr_cbk, - (void *) (long) i, - priv->children[i], - priv->children[i]->fops->chown, - &local->loc, - sh->buf[source].st_uid, - sh->buf[source].st_gid); - - STACK_WIND_COOKIE (frame, afr_sh_metadata_attr_cbk, + STACK_WIND_COOKIE (frame, afr_sh_metadata_setattr_cbk, (void *) (long) i, priv->children[i], - priv->children[i]->fops->chmod, - &local->loc, sh->buf[source].st_mode); + priv->children[i]->fops->setattr, + &local->loc, &stbuf, valid); - STACK_WIND_COOKIE (frame, afr_sh_metadata_attr_cbk, - (void *) (long) i, - priv->children[i], - priv->children[i]->fops->utimens, - &local->loc, ts); - - call_count = call_count - 3; + call_count--; if (!xattr) continue; diff --git a/xlators/cluster/afr/src/afr.c b/xlators/cluster/afr/src/afr.c index 5c2320715..ef93e5078 100644 --- a/xlators/cluster/afr/src/afr.c +++ b/xlators/cluster/afr/src/afr.c @@ -2628,6 +2628,8 @@ struct xlator_fops fops = { .ftruncate = afr_ftruncate, .utimens = afr_utimens, .setxattr = afr_setxattr, + .setattr = afr_setattr, + .fsetattr = afr_fsetattr, .removexattr = afr_removexattr, /* dir read */ diff --git a/xlators/cluster/afr/src/afr.h b/xlators/cluster/afr/src/afr.h index 210cd2e20..37dc13959 100644 --- a/xlators/cluster/afr/src/afr.h +++ b/xlators/cluster/afr/src/afr.h @@ -340,6 +340,22 @@ typedef struct _afr_local { struct stat read_child_buf; } utimens; + struct { + ino_t ino; + struct stat in_buf; + int32_t valid; + struct stat preop_buf; + struct stat postop_buf; + } setattr; + + struct { + ino_t ino; + struct stat in_buf; + int32_t valid; + struct stat preop_buf; + struct stat postop_buf; + } fsetattr; + struct { dict_t *dict; int32_t flags; -- cgit