diff options
author | Shehjar Tikoo <shehjart@gluster.com> | 2009-10-01 06:58:46 +0000 |
---|---|---|
committer | Anand V. Avati <avati@dev.gluster.com> | 2009-10-01 07:22:42 -0700 |
commit | 186a86f342625a9dce53fe537f8237c6099d5c54 (patch) | |
tree | 63ee2f3def75293b9f50acf9e49081fb1caad8ae /xlators | |
parent | dca4b2a23cb55e1e15fb393e7cbfd39b59280c9c (diff) |
Global: Introduce setattr and fsetattr fops
Signed-off-by: Anand V. Avati <avati@dev.gluster.com>
BUG: 146 (Add setattr FOP)
URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=146
Diffstat (limited to 'xlators')
33 files changed, 2179 insertions, 5092 deletions
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,11 +48,10 @@ #include "afr-transaction.h" -/* {{{ chmod */ - +/* {{{ writev */ int -afr_chmod_unwind (call_frame_t *frame, xlator_t *this) +afr_writev_unwind (call_frame_t *frame, xlator_t *this) { afr_local_t * local = NULL; afr_private_t * priv = NULL; @@ -72,13 +71,13 @@ afr_chmod_unwind (call_frame_t *frame, xlator_t *this) UNLOCK (&frame->lock); if (main_frame) { - if (local->cont.chmod.read_child_buf.st_ino) { - unwind_buf = &local->cont.chmod.read_child_buf; + if (local->cont.writev.read_child_buf.st_ino) { + unwind_buf = &local->cont.writev.read_child_buf; } else { - unwind_buf = &local->cont.chmod.buf; + unwind_buf = &local->cont.writev.buf; } - unwind_buf->st_ino = local->cont.chmod.ino; + unwind_buf->st_ino = local->cont.writev.ino; AFR_STACK_UNWIND (main_frame, local->op_ret, local->op_errno, unwind_buf); @@ -88,234 +87,19 @@ afr_chmod_unwind (call_frame_t *frame, xlator_t *this) 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_writev_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; + priv = this->private; read_child = afr_read_child (this, local->fd->inode); @@ -330,12 +114,12 @@ afr_fchmod_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.fchmod.buf = *buf; + local->op_ret = op_ret; + local->cont.writev.buf = *buf; } if (child_index == read_child) { - local->cont.fchmod.read_child_buf = *buf; + local->cont.writev.read_child_buf = *buf; } local->success_count++; @@ -350,12 +134,11 @@ afr_fchmod_wind_cbk (call_frame_t *frame, void *cookie, xlator_t *this, } UNLOCK (&frame->lock); - if (need_unwind) - afr_fchmod_unwind (frame, this); - call_count = afr_frame_return (frame); if (call_count == 0) { + local->transaction.unwind (frame, this); + local->transaction.resume (frame, this); } @@ -364,16 +147,16 @@ afr_fchmod_wind_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int -afr_fchmod_wind (call_frame_t *frame, xlator_t *this) +afr_writev_wind (call_frame_t *frame, xlator_t *this) { - afr_local_t * local = NULL; - afr_private_t * priv = NULL; + afr_local_t *local = NULL; + afr_private_t *priv = NULL; int i = 0; int call_count = -1; local = frame->local; - priv = this->private; + priv = this->private; call_count = afr_up_children_count (priv->child_count, local->child_up); @@ -386,11 +169,15 @@ afr_fchmod_wind (call_frame_t *frame, xlator_t *this) for (i = 0; i < priv->child_count; i++) { if (local->child_up[i]) { - STACK_WIND_COOKIE (frame, afr_fchmod_wind_cbk, (void *) (long) i, + STACK_WIND_COOKIE (frame, afr_writev_wind_cbk, + (void *) (long) i, priv->children[i], - priv->children[i]->fops->fchmod, + priv->children[i]->fops->writev, local->fd, - local->cont.fchmod.mode); + local->cont.writev.vector, + local->cont.writev.count, + local->cont.writev.offset, + local->cont.writev.iobref); if (!--call_count) break; @@ -402,228 +189,15 @@ afr_fchmod_wind (call_frame_t *frame, xlator_t *this) 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_writev_done (call_frame_t *frame, xlator_t *this) { afr_local_t *local = NULL; local = frame->local; + iobref_unref (local->cont.writev.iobref); + local->cont.writev.iobref = NULL; + local->transaction.unwind (frame, this); AFR_STACK_DESTROY (frame); @@ -633,8 +207,9 @@ afr_chown_done (call_frame_t *frame, xlator_t *this) int -afr_chown (call_frame_t *frame, xlator_t *this, - loc_t *loc, uid_t uid, gid_t gid) +afr_writev (call_frame_t *frame, xlator_t *this, fd_t *fd, + struct iovec *vector, int32_t count, off_t offset, + struct iobref *iobref) { afr_private_t * priv = NULL; afr_local_t * local = NULL; @@ -668,21 +243,29 @@ afr_chown (call_frame_t *frame, xlator_t *this, transaction_frame->local = local; - local->cont.chown.uid = uid; - local->cont.chown.gid = gid; - local->cont.chown.ino = loc->inode->ino; + local->op = GF_FOP_WRITE; + local->cont.writev.vector = iov_dup (vector, count); + local->cont.writev.count = count; + local->cont.writev.offset = offset; + local->cont.writev.ino = fd->inode->ino; + local->cont.writev.iobref = iobref_ref (iobref); - local->transaction.fop = afr_chown_wind; - local->transaction.done = afr_chown_done; - local->transaction.unwind = afr_chown_unwind; + local->transaction.fop = afr_writev_wind; + local->transaction.done = afr_writev_done; + local->transaction.unwind = afr_writev_unwind; - loc_copy (&local->loc, loc); + local->fd = fd_ref (fd); local->transaction.main_frame = frame; - local->transaction.start = LLONG_MAX - 1; - local->transaction.len = 0; + if (fd->flags & O_APPEND) { + local->transaction.start = 0; + local->transaction.len = 0; + } else { + local->transaction.start = offset; + local->transaction.len = iov_length (vector, count); + } - afr_transaction (transaction_frame, this, AFR_METADATA_TRANSACTION); + afr_transaction (transaction_frame, this, AFR_DATA_TRANSACTION); op_ret = 0; out: @@ -698,10 +281,10 @@ out: /* }}} */ -/* {{{ chown */ +/* {{{ truncate */ int -afr_fchown_unwind (call_frame_t *frame, xlator_t *this) +afr_truncate_unwind (call_frame_t *frame, xlator_t *this) { afr_local_t * local = NULL; afr_private_t * priv = NULL; @@ -721,255 +304,39 @@ afr_fchown_unwind (call_frame_t *frame, xlator_t *this) UNLOCK (&frame->lock); if (main_frame) { - if (local->cont.fchown.read_child_buf.st_ino) { - unwind_buf = &local->cont.fchown.read_child_buf; + if (local->cont.truncate.read_child_buf.st_ino) { + unwind_buf = &local->cont.truncate.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; + unwind_buf = &local->cont.truncate.buf; } - 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 -afr_writev_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.writev.read_child_buf.st_ino) { - unwind_buf = &local->cont.writev.read_child_buf; - } else { - unwind_buf = &local->cont.writev.buf; - } + unwind_buf->st_ino = local->cont.truncate.ino; - unwind_buf->st_ino = local->cont.writev.ino; + AFR_STACK_UNWIND (main_frame, local->op_ret, + local->op_errno, + unwind_buf); + } - AFR_STACK_UNWIND (main_frame, local->op_ret, local->op_errno, - unwind_buf); - } return 0; } int -afr_writev_wind_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, struct stat *buf) +afr_truncate_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 child_index = (long) cookie; + int read_child = 0; int call_count = -1; int need_unwind = 0; - int read_child = 0; local = frame->local; - priv = this->private; + priv = this->private; - read_child = afr_read_child (this, local->fd->inode); + read_child = afr_read_child (this, local->loc.inode); LOCK (&frame->lock); { @@ -982,12 +349,12 @@ afr_writev_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.writev.buf = *buf; + local->op_ret = op_ret; + local->cont.truncate.buf = *buf; } if (child_index == read_child) { - local->cont.writev.read_child_buf = *buf; + local->cont.truncate.read_child_buf = *buf; } local->success_count++; @@ -997,16 +364,16 @@ afr_writev_wind_cbk (call_frame_t *frame, void *cookie, xlator_t *this, 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.unwind (frame, this); - local->transaction.resume (frame, this); } @@ -1014,14 +381,14 @@ afr_writev_wind_cbk (call_frame_t *frame, void *cookie, xlator_t *this, } -int -afr_writev_wind (call_frame_t *frame, xlator_t *this) +int32_t +afr_truncate_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; + int i = 0; local = frame->local; priv = this->private; @@ -1037,16 +404,13 @@ afr_writev_wind (call_frame_t *frame, xlator_t *this) for (i = 0; i < priv->child_count; i++) { if (local->child_up[i]) { - STACK_WIND_COOKIE (frame, afr_writev_wind_cbk, + STACK_WIND_COOKIE (frame, afr_truncate_wind_cbk, (void *) (long) i, priv->children[i], - priv->children[i]->fops->writev, - local->fd, - local->cont.writev.vector, - local->cont.writev.count, - local->cont.writev.offset, - local->cont.writev.iobref); - + priv->children[i]->fops->truncate, + &local->loc, + local->cont.truncate.offset); + if (!--call_count) break; } @@ -1057,15 +421,12 @@ afr_writev_wind (call_frame_t *frame, xlator_t *this) int -afr_writev_done (call_frame_t *frame, xlator_t *this) +afr_truncate_done (call_frame_t *frame, xlator_t *this) { afr_local_t *local = NULL; local = frame->local; - iobref_unref (local->cont.writev.iobref); - local->cont.writev.iobref = NULL; - local->transaction.unwind (frame, this); AFR_STACK_DESTROY (frame); @@ -1075,9 +436,8 @@ afr_writev_done (call_frame_t *frame, xlator_t *this) int -afr_writev (call_frame_t *frame, xlator_t *this, fd_t *fd, - struct iovec *vector, int32_t count, off_t offset, - struct iobref *iobref) +afr_truncate (call_frame_t *frame, xlator_t *this, + loc_t *loc, off_t offset) { afr_private_t * priv = NULL; afr_local_t * local = NULL; @@ -1111,27 +471,20 @@ afr_writev (call_frame_t *frame, xlator_t *this, fd_t *fd, transaction_frame->local = local; - local->op = GF_FOP_WRITE; - local->cont.writev.vector = iov_dup (vector, count); - local->cont.writev.count = count; - local->cont.writev.offset = offset; - local->cont.writev.ino = fd->inode->ino; - local->cont.writev.iobref = iobref_ref (iobref); + local->op_ret = -1; - local->transaction.fop = afr_writev_wind; - local->transaction.done = afr_writev_done; - local->transaction.unwind = afr_writev_unwind; + local->cont.truncate.offset = offset; + local->cont.truncate.ino = loc->inode->ino; - local->fd = fd_ref (fd); + local->transaction.fop = afr_truncate_wind; + local->transaction.done = afr_truncate_done; + local->transaction.unwind = afr_truncate_unwind; + + loc_copy (&local->loc, loc); local->transaction.main_frame = frame; - if (fd->flags & O_APPEND) { - local->transaction.start = 0; - local->transaction.len = 0; - } else { - local->transaction.start = offset; - local->transaction.len = iov_length (vector, count); - } + local->transaction.start = 0; + local->transaction.len = offset; afr_transaction (transaction_frame, this, AFR_DATA_TRANSACTION); @@ -1149,10 +502,11 @@ out: /* }}} */ -/* {{{ truncate */ +/* {{{ ftruncate */ + int -afr_truncate_unwind (call_frame_t *frame, xlator_t *this) +afr_ftruncate_unwind (call_frame_t *frame, xlator_t *this) { afr_local_t * local = NULL; afr_private_t * priv = NULL; @@ -1172,39 +526,37 @@ afr_truncate_unwind (call_frame_t *frame, xlator_t *this) UNLOCK (&frame->lock); if (main_frame) { - if (local->cont.truncate.read_child_buf.st_ino) { - unwind_buf = &local->cont.truncate.read_child_buf; + if (local->cont.ftruncate.read_child_buf.st_ino) { + unwind_buf = &local->cont.ftruncate.read_child_buf; } else { - unwind_buf = &local->cont.truncate.buf; + unwind_buf = &local->cont.ftruncate.buf; } - unwind_buf->st_ino = local->cont.truncate.ino; - - AFR_STACK_UNWIND (main_frame, local->op_ret, - local->op_errno, - unwind_buf); - } + unwind_buf->st_ino = local->cont.ftruncate.ino; + AFR_STACK_UNWIND (main_frame, local->op_ret, local->op_errno, + unwind_buf); + } return 0; } int -afr_truncate_wind_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, struct stat *buf) +afr_ftruncate_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 child_index = (long) cookie; - int read_child = 0; int call_count = -1; int need_unwind = 0; + int read_child = 0; local = frame->local; priv = this->private; - read_child = afr_read_child (this, local->loc.inode); + read_child = afr_read_child (this, local->fd->inode); LOCK (&frame->lock); { @@ -1218,11 +570,11 @@ afr_truncate_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.truncate.buf = *buf; + local->cont.ftruncate.buf = *buf; } if (child_index == read_child) { - local->cont.truncate.read_child_buf = *buf; + local->cont.ftruncate.read_child_buf = *buf; } local->success_count++; @@ -1249,8 +601,8 @@ afr_truncate_wind_cbk (call_frame_t *frame, void *cookie, xlator_t *this, } -int32_t -afr_truncate_wind (call_frame_t *frame, xlator_t *this) +int +afr_ftruncate_wind (call_frame_t *frame, xlator_t *this) { afr_local_t *local = NULL; afr_private_t *priv = NULL; @@ -1272,12 +624,11 @@ afr_truncate_wind (call_frame_t *frame, xlator_t *this) for (i = 0; i < priv->child_count; i++) { if (local->child_up[i]) { - STACK_WIND_COOKIE (frame, afr_truncate_wind_cbk, + STACK_WIND_COOKIE (frame, afr_ftruncate_wind_cbk, (void *) (long) i, priv->children[i], - priv->children[i]->fops->truncate, - &local->loc, - local->cont.truncate.offset); + priv->children[i]->fops->ftruncate, + local->fd, local->cont.ftruncate.offset); if (!--call_count) break; @@ -1289,7 +640,7 @@ afr_truncate_wind (call_frame_t *frame, xlator_t *this) int -afr_truncate_done (call_frame_t *frame, xlator_t *this) +afr_ftruncate_done (call_frame_t *frame, xlator_t *this) { afr_local_t *local = NULL; @@ -1304,8 +655,8 @@ afr_truncate_done (call_frame_t *frame, xlator_t *this) int -afr_truncate (call_frame_t *frame, xlator_t *this, - loc_t *loc, off_t offset) +afr_ftruncate (call_frame_t *frame, xlator_t *this, + fd_t *fd, off_t offset) { afr_private_t * priv = NULL; afr_local_t * local = NULL; @@ -1339,16 +690,17 @@ afr_truncate (call_frame_t *frame, xlator_t *this, transaction_frame->local = local; + local->op = GF_FOP_FTRUNCATE; local->op_ret = -1; - local->cont.truncate.offset = offset; - local->cont.truncate.ino = loc->inode->ino; + local->cont.ftruncate.offset = offset; + local->cont.ftruncate.ino = fd->inode->ino; - local->transaction.fop = afr_truncate_wind; - local->transaction.done = afr_truncate_done; - local->transaction.unwind = afr_truncate_unwind; + local->transaction.fop = afr_ftruncate_wind; + local->transaction.done = afr_ftruncate_done; + local->transaction.unwind = afr_ftruncate_unwind; - loc_copy (&local->loc, loc); + local->fd = fd_ref (fd); local->transaction.main_frame = frame; local->transaction.start = 0; @@ -1367,21 +719,17 @@ out: return 0; } - /* }}} */ -/* {{{ ftruncate */ - +/* {{{ setattr */ int -afr_ftruncate_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; @@ -1394,37 +742,35 @@ afr_ftruncate_unwind (call_frame_t *frame, xlator_t *this) UNLOCK (&frame->lock); if (main_frame) { - if (local->cont.ftruncate.read_child_buf.st_ino) { - unwind_buf = &local->cont.ftruncate.read_child_buf; - } else { - unwind_buf = &local->cont.ftruncate.buf; - } + local->cont.setattr.preop_buf.st_ino = local->cont.setattr.ino; + local->cont.setattr.postop_buf.st_ino = local->cont.setattr.ino; - unwind_buf->st_ino = local->cont.ftruncate.ino; + AFR_STACK_UNWIND (main_frame, local->op_ret, local->op_errno, + &local->cont.setattr.preop_buf, + &local->cont.setattr.postop_buf); + } - AFR_STACK_UNWIND (main_frame, local->op_ret, local->op_errno, - unwind_buf); - } return 0; } int -afr_ftruncate_wind_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, struct stat *buf) +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; - int read_child = 0; local = frame->local; priv = this->private; - read_child = afr_read_child (this, local->fd->inode); + read_child = afr_read_child (this, local->loc.inode); LOCK (&frame->lock); { @@ -1438,11 +784,13 @@ afr_ftruncate_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.ftruncate.buf = *buf; + local->cont.setattr.preop_buf = *preop; + local->cont.setattr.postop_buf = *postop; } if (child_index == read_child) { - local->cont.ftruncate.read_child_buf = *buf; + local->cont.setattr.preop_buf = *preop; + local->cont.setattr.postop_buf = *postop; } local->success_count++; @@ -1464,17 +812,17 @@ afr_ftruncate_wind_cbk (call_frame_t *frame, void *cookie, xlator_t *this, if (call_count == 0) { local->transaction.resume (frame, this); } - + return 0; } -int -afr_ftruncate_wind (call_frame_t *frame, xlator_t *this) +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; @@ -1490,25 +838,27 @@ afr_ftruncate_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_ftruncate_wind_cbk, - (void *) (long) i, - priv->children[i], - priv->children[i]->fops->ftruncate, - local->fd, local->cont.ftruncate.offset); + 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_ftruncate_done (call_frame_t *frame, xlator_t *this) +afr_setattr_done (call_frame_t *frame, xlator_t *this) { afr_local_t *local = NULL; @@ -1523,8 +873,8 @@ afr_ftruncate_done (call_frame_t *frame, xlator_t *this) int -afr_ftruncate (call_frame_t *frame, xlator_t *this, - fd_t *fd, off_t offset) +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; @@ -1558,23 +908,24 @@ afr_ftruncate (call_frame_t *frame, xlator_t *this, transaction_frame->local = local; - local->op = GF_FOP_FTRUNCATE; local->op_ret = -1; - local->cont.ftruncate.offset = offset; - local->cont.ftruncate.ino = fd->inode->ino; + local->cont.setattr.ino = loc->inode->ino; - local->transaction.fop = afr_ftruncate_wind; - local->transaction.done = afr_ftruncate_done; - local->transaction.unwind = afr_ftruncate_unwind; + local->cont.setattr.in_buf = *buf; + local->cont.setattr.valid = valid; - local->fd = fd_ref (fd); + 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 = 0; - local->transaction.len = offset; + local->transaction.start = LLONG_MAX - 1; + local->transaction.len = 0; - afr_transaction (transaction_frame, this, AFR_DATA_TRANSACTION); + afr_transaction (transaction_frame, this, AFR_METADATA_TRANSACTION); op_ret = 0; out: @@ -1587,20 +938,15 @@ out: return 0; } -/* }}} */ - -/* {{{ utimens */ - +/* {{{ fsetattr */ int -afr_utimens_unwind (call_frame_t *frame, xlator_t *this) +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; - struct stat * unwind_buf = NULL; - local = frame->local; priv = this->private; @@ -1613,35 +959,35 @@ 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; - } - - unwind_buf->st_ino = local->cont.utimens.ino; + 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); + } - AFR_STACK_UNWIND (main_frame, local->op_ret, local->op_errno, - unwind_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)); @@ -960,76 +961,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, int32_t op_ret, int32_t op_errno, @@ -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 @@ -341,6 +341,22 @@ typedef struct _afr_local { } 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; } setxattr; diff --git a/xlators/cluster/dht/src/dht-common.c b/xlators/cluster/dht/src/dht-common.c index 62f3822a5..d5d6f4c3e 100644 --- a/xlators/cluster/dht/src/dht-common.c +++ b/xlators/cluster/dht/src/dht-common.c @@ -998,299 +998,6 @@ err: int -dht_chmod (call_frame_t *frame, xlator_t *this, - loc_t *loc, mode_t mode) -{ - dht_layout_t *layout = NULL; - dht_local_t *local = NULL; - int op_errno = -1; - int i = -1; - - - VALIDATE_OR_GOTO (frame, err); - VALIDATE_OR_GOTO (this, err); - VALIDATE_OR_GOTO (loc, err); - VALIDATE_OR_GOTO (loc->inode, err); - VALIDATE_OR_GOTO (loc->path, err); - - layout = dht_layout_get (this, loc->inode); - - if (!layout) { - gf_log (this->name, GF_LOG_DEBUG, - "no layout for path=%s", loc->path); - op_errno = EINVAL; - goto err; - } - - if (!layout_is_sane (layout)) { - gf_log (this->name, GF_LOG_DEBUG, - "layout is not sane for path=%s", loc->path); - op_errno = EINVAL; - goto err; - } - - local = dht_local_init (frame); - if (!local) { - op_errno = ENOMEM; - gf_log (this->name, GF_LOG_DEBUG, - "memory allocation failed :("); - goto err; - } - - local->inode = inode_ref (loc->inode); - local->call_cnt = layout->cnt; - - for (i = 0; i < layout->cnt; i++) { - STACK_WIND (frame, dht_attr_cbk, - layout->list[i].xlator, - layout->list[i].xlator->fops->chmod, - loc, mode); - } - - return 0; - -err: - op_errno = (op_errno == -1) ? errno : op_errno; - DHT_STACK_UNWIND (frame, -1, op_errno, NULL); - - return 0; -} - - -int -dht_chown (call_frame_t *frame, xlator_t *this, - loc_t *loc, uid_t uid, gid_t gid) -{ - dht_layout_t *layout = NULL; - dht_local_t *local = NULL; - int op_errno = -1; - int i = -1; - - - VALIDATE_OR_GOTO (frame, err); - VALIDATE_OR_GOTO (this, err); - VALIDATE_OR_GOTO (loc, err); - VALIDATE_OR_GOTO (loc->inode, err); - VALIDATE_OR_GOTO (loc->path, err); - - layout = dht_layout_get (this, loc->inode); - if (!layout) { - gf_log (this->name, GF_LOG_DEBUG, - "no layout for path=%s", loc->path); - op_errno = EINVAL; - goto err; - } - - if (!layout_is_sane (layout)) { - gf_log (this->name, GF_LOG_DEBUG, - "layout is not sane for path=%s", loc->path); - op_errno = EINVAL; - goto err; - } - - local = dht_local_init (frame); - if (!local) { - op_errno = ENOMEM; - gf_log (this->name, GF_LOG_ERROR, - "Out of memory"); - goto err; - } - - local->inode = inode_ref (loc->inode); - local->call_cnt = layout->cnt; - - for (i = 0; i < layout->cnt; i++) { - STACK_WIND (frame, dht_attr_cbk, - layout->list[i].xlator, - layout->list[i].xlator->fops->chown, - loc, uid, gid); - } - - return 0; - -err: - op_errno = (op_errno == -1) ? errno : op_errno; - DHT_STACK_UNWIND (frame, -1, op_errno, NULL); - - return 0; -} - - -int -dht_fchmod (call_frame_t *frame, xlator_t *this, - fd_t *fd, mode_t mode) -{ - dht_layout_t *layout = NULL; - dht_local_t *local = NULL; - int op_errno = -1; - int i = -1; - - - VALIDATE_OR_GOTO (frame, err); - VALIDATE_OR_GOTO (this, err); - VALIDATE_OR_GOTO (fd, err); - - - layout = dht_layout_get (this, fd->inode); - if (!layout) { - gf_log (this->name, GF_LOG_DEBUG, - "no layout for fd=%p", fd); - op_errno = EINVAL; - goto err; - } - - if (!layout_is_sane (layout)) { - gf_log (this->name, GF_LOG_DEBUG, - "layout is not sane for fd=%p", fd); - op_errno = EINVAL; - goto err; - } - - local = dht_local_init (frame); - if (!local) { - op_errno = ENOMEM; - gf_log (this->name, GF_LOG_ERROR, - "Out of memory"); - goto err; - } - - local->inode = inode_ref (fd->inode); - local->call_cnt = layout->cnt; - - for (i = 0; i < layout->cnt; i++) { - STACK_WIND (frame, dht_attr_cbk, - layout->list[i].xlator, - layout->list[i].xlator->fops->fchmod, - fd, mode); - } - - return 0; - -err: - op_errno = (op_errno == -1) ? errno : op_errno; - DHT_STACK_UNWIND (frame, -1, op_errno, NULL); - - return 0; -} - - -int -dht_fchown (call_frame_t *frame, xlator_t *this, - fd_t *fd, uid_t uid, gid_t gid) -{ - dht_layout_t *layout = NULL; - dht_local_t *local = NULL; - int op_errno = -1; - int i = -1; - - - VALIDATE_OR_GOTO (frame, err); - VALIDATE_OR_GOTO (this, err); - VALIDATE_OR_GOTO (fd, err); - - layout = dht_layout_get (this, fd->inode); - if (!layout) { - gf_log (this->name, GF_LOG_DEBUG, - "no layout for fd=%p", fd); - op_errno = EINVAL; - goto err; - } - - if (!layout_is_sane (layout)) { - gf_log (this->name, GF_LOG_DEBUG, - "layout is not sane for fd=%p", fd); - op_errno = EINVAL; - goto err; - } - - local = dht_local_init (frame); - if (!local) { - op_errno = ENOMEM; - gf_log (this->name, GF_LOG_ERROR, - "Out of memory"); - goto err; - } - - local->inode = inode_ref (fd->inode); - local->call_cnt = layout->cnt; - - for (i = 0; i < layout->cnt; i++) { - STACK_WIND (frame, dht_attr_cbk, - layout->list[i].xlator, - layout->list[i].xlator->fops->fchown, - fd, uid, gid); - } - - return 0; - -err: - op_errno = (op_errno == -1) ? errno : op_errno; - DHT_STACK_UNWIND (frame, -1, op_errno, NULL); - - return 0; -} - - -int -dht_utimens (call_frame_t *frame, xlator_t *this, - loc_t *loc, struct timespec tv[2]) -{ - dht_layout_t *layout = NULL; - dht_local_t *local = NULL; - int op_errno = -1; - int i = -1; - - - VALIDATE_OR_GOTO (frame, err); - VALIDATE_OR_GOTO (this, err); - VALIDATE_OR_GOTO (loc, err); - VALIDATE_OR_GOTO (loc->inode, err); - VALIDATE_OR_GOTO (loc->path, err); - - layout = dht_layout_get (this, loc->inode); - if (!layout) { - gf_log (this->name, GF_LOG_DEBUG, - "no layout for path=%s", loc->path); - op_errno = EINVAL; - goto err; - } - - if (!layout_is_sane (layout)) { - gf_log (this->name, GF_LOG_DEBUG, - "layout is not sane for path=%s", loc->path); - op_errno = EINVAL; - goto err; - } - - local = dht_local_init (frame); - if (!local) { - op_errno = ENOMEM; - gf_log (this->name, GF_LOG_ERROR, - "Out of memory"); - goto err; - } - - local->inode = inode_ref (loc->inode); - local->call_cnt = layout->cnt; - - for (i = 0; i < layout->cnt; i++) { - STACK_WIND (frame, dht_attr_cbk, - layout->list[i].xlator, - layout->list[i].xlator->fops->utimens, - loc, tv); - } - - return 0; - -err: - op_errno = (op_errno == -1) ? errno : op_errno; - DHT_STACK_UNWIND (frame, -1, op_errno, NULL); - - return 0; -} - - -int dht_truncate (call_frame_t *frame, xlator_t *this, loc_t *loc, off_t offset) { @@ -3575,6 +3282,168 @@ err: int +dht_setattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this, + int op_ret, int op_errno, struct stat *statpre, + struct stat *statpost) +{ + dht_local_t *local = NULL; + int this_call_cnt = 0; + call_frame_t *prev = NULL; + + + local = frame->local; + prev = cookie; + + LOCK (&frame->lock); + { + if (op_ret == -1) { + local->op_errno = op_errno; + gf_log (this->name, GF_LOG_DEBUG, + "subvolume %s returned -1 (%s)", + prev->this->name, strerror (op_errno)); + goto unlock; + } + + dht_stat_merge (this, &local->stpre, statpre, prev->this); + dht_stat_merge (this, &local->stpost, statpost, prev->this); + + if (local->inode) { + local->stpre.st_ino = local->inode->ino; + local->stpost.st_ino = local->inode->ino; + } + + local->op_ret = 0; + } +unlock: + UNLOCK (&frame->lock); + + this_call_cnt = dht_frame_return (frame); + if (is_last_call (this_call_cnt)) + DHT_STACK_UNWIND (frame, local->op_ret, local->op_errno, + &local->stpre, &local->stpost); + + return 0; +} + + +int32_t +dht_setattr (call_frame_t *frame, xlator_t *this, loc_t *loc, + struct stat *stbuf, int32_t valid) +{ + dht_layout_t *layout = NULL; + dht_local_t *local = NULL; + int op_errno = -1; + int i = -1; + + + VALIDATE_OR_GOTO (frame, err); + VALIDATE_OR_GOTO (this, err); + VALIDATE_OR_GOTO (loc, err); + VALIDATE_OR_GOTO (loc->inode, err); + VALIDATE_OR_GOTO (loc->path, err); + + layout = dht_layout_get (this, loc->inode); + + if (!layout) { + gf_log (this->name, GF_LOG_DEBUG, + "no layout for path=%s", loc->path); + op_errno = EINVAL; + goto err; + } + + if (!layout_is_sane (layout)) { + gf_log (this->name, GF_LOG_DEBUG, + "layout is not sane for path=%s", loc->path); + op_errno = EINVAL; + goto err; + } + + local = dht_local_init (frame); + if (!local) { + op_errno = ENOMEM; + gf_log (this->name, GF_LOG_DEBUG, + "memory allocation failed :("); + goto err; + } + + local->inode = inode_ref (loc->inode); + local->call_cnt = layout->cnt; + + for (i = 0; i < layout->cnt; i++) { + STACK_WIND (frame, dht_setattr_cbk, + layout->list[i].xlator, + layout->list[i].xlator->fops->setattr, + loc, stbuf, valid); + } + + return 0; + +err: + op_errno = (op_errno == -1) ? errno : op_errno; + DHT_STACK_UNWIND (frame, -1, op_errno, NULL, NULL); + + return 0; +} + + +int32_t +dht_fsetattr (call_frame_t *frame, xlator_t *this, fd_t *fd, struct stat *stbuf, + int32_t valid) +{ + dht_layout_t *layout = NULL; + dht_local_t *local = NULL; + int op_errno = -1; + int i = -1; + + + VALIDATE_OR_GOTO (frame, err); + VALIDATE_OR_GOTO (this, err); + VALIDATE_OR_GOTO (fd, err); + + layout = dht_layout_get (this, fd->inode); + if (!layout) { + gf_log (this->name, GF_LOG_DEBUG, + "no layout for fd=%p", fd); + op_errno = EINVAL; + goto err; + } + + if (!layout_is_sane (layout)) { + gf_log (this->name, GF_LOG_DEBUG, + "layout is not sane for fd=%p", fd); + op_errno = EINVAL; + goto err; + } + + local = dht_local_init (frame); + if (!local) { + op_errno = ENOMEM; + gf_log (this->name, GF_LOG_ERROR, + "Out of memory"); + goto err; + } + + local->inode = inode_ref (fd->inode); + local->call_cnt = layout->cnt; + + for (i = 0; i < layout->cnt; i++) { + STACK_WIND (frame, dht_setattr_cbk, + layout->list[i].xlator, + layout->list[i].xlator->fops->fsetattr, + fd, stbuf, valid); + } + + return 0; + +err: + op_errno = (op_errno == -1) ? errno : op_errno; + DHT_STACK_UNWIND (frame, -1, op_errno, NULL, NULL); + + return 0; +} + + +int dht_forget (xlator_t *this, inode_t *inode) { uint64_t tmp_layout = 0; diff --git a/xlators/cluster/dht/src/dht-common.h b/xlators/cluster/dht/src/dht-common.h index f5c95b4cb..8573b9f5b 100644 --- a/xlators/cluster/dht/src/dht-common.h +++ b/xlators/cluster/dht/src/dht-common.h @@ -57,6 +57,8 @@ struct dht_local { int op_errno; int layout_mismatch; struct stat stbuf; + struct stat stpre; + struct stat stpost; struct statvfs statvfs; fd_t *fd; inode_t *inode; diff --git a/xlators/cluster/dht/src/dht.c b/xlators/cluster/dht/src/dht.c index 46f3b8700..770629711 100644 --- a/xlators/cluster/dht/src/dht.c +++ b/xlators/cluster/dht/src/dht.c @@ -353,12 +353,7 @@ struct xlator_fops fops = { .create = dht_create, .stat = dht_stat, - .chmod = dht_chmod, - .chown = dht_chown, - .fchown = dht_fchown, - .fchmod = dht_fchmod, .fstat = dht_fstat, - .utimens = dht_utimens, .truncate = dht_truncate, .ftruncate = dht_ftruncate, .access = dht_access, @@ -388,6 +383,8 @@ struct xlator_fops fops = { .fentrylk = dht_fentrylk, .xattrop = dht_xattrop, .fxattrop = dht_fxattrop, + .setattr = dht_setattr, + .fsetattr = dht_fsetattr, #if 0 .setdents = dht_setdents, .getdents = dht_getdents, diff --git a/xlators/cluster/dht/src/nufa.c b/xlators/cluster/dht/src/nufa.c index c8ce7fdee..6be7206bf 100644 --- a/xlators/cluster/dht/src/nufa.c +++ b/xlators/cluster/dht/src/nufa.c @@ -674,12 +674,7 @@ struct xlator_fops fops = { .mknod = nufa_mknod, .stat = dht_stat, - .chmod = dht_chmod, - .chown = dht_chown, - .fchown = dht_fchown, - .fchmod = dht_fchmod, .fstat = dht_fstat, - .utimens = dht_utimens, .truncate = dht_truncate, .ftruncate = dht_ftruncate, .access = dht_access, @@ -709,6 +704,7 @@ struct xlator_fops fops = { .fentrylk = dht_fentrylk, .xattrop = dht_xattrop, .fxattrop = dht_fxattrop, + .setattr = dht_setattr, #if 0 .setdents = dht_setdents, .getdents = dht_getdents, diff --git a/xlators/cluster/ha/src/ha.c b/xlators/cluster/ha/src/ha.c index b938071ed..b380cb1e9 100644 --- a/xlators/cluster/ha/src/ha.c +++ b/xlators/cluster/ha/src/ha.c @@ -229,135 +229,25 @@ err: return 0; } - int32_t -ha_chmod_cbk (call_frame_t *frame, - void *cookie, - xlator_t *this, - int32_t op_ret, - int32_t op_errno, - struct stat *buf) -{ - int ret = -1; - - ret = ha_handle_cbk (frame, cookie, op_ret, op_errno); - - if (ret == 0) { - STACK_UNWIND (frame, - op_ret, - op_errno, - buf); - } - return 0; -} - int32_t -ha_chmod (call_frame_t *frame, - xlator_t *this, - loc_t *loc, - mode_t mode) -{ - ha_local_t *local = NULL; - int op_errno = 0; - - op_errno = ha_alloc_init_inode (frame, loc->inode); - if (op_errno < 0) { - op_errno = -op_errno; - goto err; - } - local = frame->local; - local->stub = fop_chmod_stub (frame, ha_chmod, loc, mode); - - STACK_WIND_COOKIE (frame, - ha_chmod_cbk, - (void *)(long)local->active, - HA_ACTIVE_CHILD(this, local), - HA_ACTIVE_CHILD(this, local)->fops->chmod, - loc, - mode); - return 0; -err: - STACK_UNWIND (frame, -1, op_errno, NULL); - return 0; -} - - int32_t -ha_fchmod_cbk (call_frame_t *frame, - void *cookie, - xlator_t *this, - int32_t op_ret, - int32_t op_errno, - struct stat *buf) +ha_setattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, struct stat *statpre, + struct stat *statpost) { int ret = -1; ret = ha_handle_cbk (frame, cookie, op_ret, op_errno); if (ret == 0) { - STACK_UNWIND (frame, - op_ret, - op_errno, - buf); - } - return 0; -} - -int32_t -ha_fchmod (call_frame_t *frame, - xlator_t *this, - fd_t *fd, - mode_t mode) -{ - ha_local_t *local = NULL; - int op_errno = 0; - - op_errno = ha_alloc_init_fd (frame, fd); - if (op_errno < 0) { - op_errno = -op_errno; - goto err; + STACK_UNWIND (frame, op_ret, op_errno, statpre, statpost); } - local = frame->local; - local->stub = fop_fchmod_stub (frame, ha_fchmod, fd, mode); - - STACK_WIND_COOKIE (frame, - ha_fchmod_cbk, - (void *)(long)local->active, - HA_ACTIVE_CHILD(this, local), - HA_ACTIVE_CHILD(this, local)->fops->fchmod, - fd, - mode); - return 0; -err: - STACK_UNWIND (frame, -1, op_errno, NULL); return 0; } - int32_t -ha_chown_cbk (call_frame_t *frame, - void *cookie, - xlator_t *this, - int32_t op_ret, - int32_t op_errno, - struct stat *buf) -{ - int ret = -1; - - ret = ha_handle_cbk (frame, cookie, op_ret, op_errno); - - if (ret == 0) { - STACK_UNWIND (frame, - op_ret, - op_errno, - buf); - } - return 0; -} int32_t -ha_chown (call_frame_t *frame, - xlator_t *this, - loc_t *loc, - uid_t uid, - gid_t gid) +ha_setattr (call_frame_t *frame, xlator_t *this, loc_t *loc, struct stat *stbuf, + int32_t valid) { ha_local_t *local = NULL; int op_errno = 0; @@ -368,49 +258,24 @@ ha_chown (call_frame_t *frame, goto err; } local = frame->local; - local->stub = fop_chown_stub (frame, ha_chown, loc, uid, gid); + local->stub = fop_setattr_stub (frame, ha_setattr, loc, stbuf, valid); - STACK_WIND_COOKIE (frame, - ha_chown_cbk, + STACK_WIND_COOKIE (frame, + ha_setattr_cbk, (void *)(long)local->active, HA_ACTIVE_CHILD(this, local), - HA_ACTIVE_CHILD(this, local)->fops->chown, - loc, - uid, - gid); + HA_ACTIVE_CHILD(this, local)->fops->setattr, + loc, stbuf, valid); return 0; err: - STACK_UNWIND (frame, -1, ENOTCONN, NULL); + STACK_UNWIND (frame, -1, op_errno, NULL, NULL); return 0; } - int32_t -ha_fchown_cbk (call_frame_t *frame, - void *cookie, - xlator_t *this, - int32_t op_ret, - int32_t op_errno, - struct stat *buf) -{ - int ret = -1; - - ret = ha_handle_cbk (frame, cookie, op_ret, op_errno); - - if (ret == 0) { - STACK_UNWIND (frame, - op_ret, - op_errno, - buf); - } - return 0; -} -int32_t -ha_fchown (call_frame_t *frame, - xlator_t *this, - fd_t *fd, - uid_t uid, - gid_t gid) +int32_t +ha_fsetattr (call_frame_t *frame, xlator_t *this, fd_t *fd, struct stat *stbuf, + int32_t valid) { ha_local_t *local = NULL; int op_errno = 0; @@ -421,23 +286,22 @@ ha_fchown (call_frame_t *frame, goto err; } local = frame->local; - local->stub = fop_fchown_stub (frame, ha_fchown, fd, uid, gid); + local->stub = fop_fsetattr_stub (frame, ha_fsetattr, fd, stbuf, valid); STACK_WIND_COOKIE (frame, - ha_fchown_cbk, + ha_setattr_cbk, (void *)(long)local->active, HA_ACTIVE_CHILD(this, local), - HA_ACTIVE_CHILD(this, local)->fops->fchown, - fd, - uid, - gid); + HA_ACTIVE_CHILD(this, local)->fops->fsetattr, + fd, stbuf, valid); return 0; err: - STACK_UNWIND (frame, -1, op_errno, NULL); + STACK_UNWIND (frame, -1, op_errno, NULL, NULL); return 0; } - int32_t + +int32_t ha_truncate_cbk (call_frame_t *frame, void *cookie, xlator_t *this, @@ -538,57 +402,6 @@ err: return 0; } -int32_t -ha_utimens_cbk (call_frame_t *frame, - void *cookie, - xlator_t *this, - int32_t op_ret, - int32_t op_errno, - struct stat *buf) -{ - int ret = -1; - - ret = ha_handle_cbk (frame, cookie, op_ret, op_errno); - - if (ret == 0) { - STACK_UNWIND (frame, - op_ret, - op_errno, - buf); - } - return 0; -} - -int32_t -ha_utimens (call_frame_t *frame, - xlator_t *this, - loc_t *loc, - struct timespec tv[2]) -{ - ha_local_t *local = NULL; - int op_errno = 0; - - op_errno = ha_alloc_init_inode (frame, loc->inode); - if (op_errno < 0) { - op_errno = -op_errno; - goto err; - } - local = frame->local; - local->stub = fop_utimens_stub (frame, ha_utimens, loc, tv); - - STACK_WIND_COOKIE (frame, - ha_utimens_cbk, - (void *)(long)local->active, - HA_ACTIVE_CHILD(this, local), - HA_ACTIVE_CHILD(this, local)->fops->utimens, - loc, - tv); - return 0; -err: - STACK_UNWIND (frame, -1, op_errno, NULL); - return 0; -} - int32_t ha_access_cbk (call_frame_t *frame, void *cookie, @@ -3462,10 +3275,7 @@ struct xlator_fops fops = { .symlink = ha_symlink, .rename = ha_rename, .link = ha_link, - .chmod = ha_chmod, - .chown = ha_chown, .truncate = ha_truncate, - .utimens = ha_utimens, .create = ha_create, .open = ha_open, .readv = ha_readv, @@ -3484,13 +3294,13 @@ struct xlator_fops fops = { .ftruncate = ha_ftruncate, .fstat = ha_fstat, .lk = ha_lk, - .fchmod = ha_fchmod, - .fchown = ha_fchown, .setdents = ha_setdents, .lookup_cbk = ha_lookup_cbk, .checksum = ha_checksum, .xattrop = ha_xattrop, - .fxattrop = ha_fxattrop + .fxattrop = ha_fxattrop, + .setattr = ha_setattr, + .fsetattr = ha_fsetattr, }; struct xlator_mops mops = { diff --git a/xlators/cluster/map/src/map.c b/xlators/cluster/map/src/map.c index 98d6b33b0..3eb49e2ed 100644 --- a/xlators/cluster/map/src/map.c +++ b/xlators/cluster/map/src/map.c @@ -48,75 +48,41 @@ map_stat_cbk (call_frame_t *frame, return 0; } - static int32_t -map_chmod_cbk (call_frame_t *frame, - void *cookie, - xlator_t *this, - int32_t op_ret, - int32_t op_errno, - struct stat *buf) +map_setattr_cbk (call_frame_t *frame, + void *cookie, + xlator_t *this, + int32_t op_ret, + int32_t op_errno, + struct stat *statpre, + struct stat *statpost) { call_frame_t *prev = NULL; prev = cookie; - - map_itransform (this, prev->this, buf->st_ino, &buf->st_ino); - - STACK_UNWIND (frame, op_ret, op_errno, buf); - return 0; -} - -static int32_t -map_fchmod_cbk (call_frame_t *frame, - void *cookie, - xlator_t *this, - int32_t op_ret, - int32_t op_errno, - struct stat *buf) -{ - call_frame_t *prev = NULL; - prev = cookie; - - map_itransform (this, prev->this, buf->st_ino, &buf->st_ino); + map_itransform (this, prev->this, statpre->st_ino, &statpre->st_ino); + map_itransform (this, prev->this, statpost->st_ino, &statpost->st_ino); - STACK_UNWIND (frame, op_ret, op_errno, buf); + STACK_UNWIND (frame, op_ret, op_errno, statpre, statpost); return 0; } - static int32_t -map_chown_cbk (call_frame_t *frame, - void *cookie, - xlator_t *this, - int32_t op_ret, - int32_t op_errno, - struct stat *buf) +map_fsetattr_cbk (call_frame_t *frame, + void *cookie, + xlator_t *this, + int32_t op_ret, + int32_t op_errno, + struct stat *statpre, + struct stat *statpost) { call_frame_t *prev = NULL; prev = cookie; - - map_itransform (this, prev->this, buf->st_ino, &buf->st_ino); - - STACK_UNWIND (frame, op_ret, op_errno, buf); - return 0; -} - -static int32_t -map_fchown_cbk (call_frame_t *frame, - void *cookie, - xlator_t *this, - int32_t op_ret, - int32_t op_errno, - struct stat *buf) -{ - call_frame_t *prev = NULL; - prev = cookie; - - map_itransform (this, prev->this, buf->st_ino, &buf->st_ino); + map_itransform (this, prev->this, statpre->st_ino, &statpre->st_ino); + map_itransform (this, prev->this, statpost->st_ino, &statpost->st_ino); - STACK_UNWIND (frame, op_ret, op_errno, buf); + STACK_UNWIND (frame, op_ret, op_errno, statpre, statpost); return 0; } @@ -154,23 +120,6 @@ map_ftruncate_cbk (call_frame_t *frame, return 0; } -int32_t -map_utimens_cbk (call_frame_t *frame, - void *cookie, - xlator_t *this, - int32_t op_ret, - int32_t op_errno, - struct stat *buf) -{ - call_frame_t *prev = NULL; - prev = cookie; - - map_itransform (this, prev->this, buf->st_ino, &buf->st_ino); - - STACK_UNWIND (frame, op_ret, op_errno, buf); - return 0; -} - static int32_t map_access_cbk (call_frame_t *frame, @@ -928,82 +877,22 @@ map_stat (call_frame_t *frame, return 0; } - -int32_t -map_chmod (call_frame_t *frame, - xlator_t *this, - loc_t *loc, - mode_t mode) -{ - int32_t op_errno = 1; - xlator_t *subvol = NULL; - - VALIDATE_OR_GOTO (frame, err); - VALIDATE_OR_GOTO (this, err); - VALIDATE_OR_GOTO (loc, err); - VALIDATE_OR_GOTO (loc->inode, err); - VALIDATE_OR_GOTO (loc->path, err); - - subvol = get_mapping_subvol_from_ctx (this, loc->inode); - if (!subvol) { - op_errno = EINVAL; - goto err; - } - - STACK_WIND (frame, map_chmod_cbk, subvol, - subvol->fops->chmod, loc, mode); - return 0; - err: - STACK_UNWIND (frame, -1, op_errno, NULL, NULL); - - return 0; -} - -int32_t -map_fchmod (call_frame_t *frame, - xlator_t *this, - fd_t *fd, - mode_t mode) -{ - int32_t op_errno = 1; - xlator_t *subvol = NULL; - - VALIDATE_OR_GOTO (frame, err); - VALIDATE_OR_GOTO (this, err); - VALIDATE_OR_GOTO (fd, err); - VALIDATE_OR_GOTO (fd->inode, err); - - subvol = get_mapping_subvol_from_ctx (this, fd->inode); - if (!subvol) { - op_errno = EINVAL; - goto err; - } - - STACK_WIND (frame, map_fchmod_cbk, subvol, - subvol->fops->fchmod, fd, mode); - - return 0; - err: - STACK_UNWIND (frame, -1, op_errno, NULL, NULL); - - return 0; -} - int32_t -map_chown (call_frame_t *frame, - xlator_t *this, - loc_t *loc, - uid_t uid, - gid_t gid) +map_setattr (call_frame_t *frame, + xlator_t *this, + loc_t *loc, + struct stat *stbuf, + int32_t valid) { int32_t op_errno = 1; xlator_t *subvol = NULL; - VALIDATE_OR_GOTO (frame, err); - VALIDATE_OR_GOTO (this, err); - VALIDATE_OR_GOTO (loc, err); - VALIDATE_OR_GOTO (loc->inode, err); - VALIDATE_OR_GOTO (loc->path, err); + GF_VALIDATE_OR_GOTO ("map", this, err); + GF_VALIDATE_OR_GOTO (this->name, frame, err); + GF_VALIDATE_OR_GOTO (this->name, loc, err); + GF_VALIDATE_OR_GOTO (this->name, loc->inode, err); + GF_VALIDATE_OR_GOTO (this->name, loc->path, err); + GF_VALIDATE_OR_GOTO (this->name, stbuf, err); subvol = get_mapping_subvol_from_ctx (this, loc->inode); if (!subvol) { @@ -1011,8 +900,8 @@ map_chown (call_frame_t *frame, goto err; } - STACK_WIND (frame, map_chown_cbk, subvol, - subvol->fops->chown, loc, uid, gid); + STACK_WIND (frame, map_setattr_cbk, subvol, + subvol->fops->setattr, loc, stbuf, valid); return 0; err: STACK_UNWIND (frame, -1, op_errno, NULL, NULL); @@ -1021,19 +910,19 @@ map_chown (call_frame_t *frame, } int32_t -map_fchown (call_frame_t *frame, - xlator_t *this, - fd_t *fd, - uid_t uid, - gid_t gid) +map_fsetattr (call_frame_t *frame, + xlator_t *this, + fd_t *fd, + struct stat *stbuf, + int32_t valid) { int32_t op_errno = 1; xlator_t *subvol = NULL; - VALIDATE_OR_GOTO (frame, err); - VALIDATE_OR_GOTO (this, err); - VALIDATE_OR_GOTO (fd, err); - VALIDATE_OR_GOTO (fd->inode, err); + GF_VALIDATE_OR_GOTO ("map", this, err); + GF_VALIDATE_OR_GOTO (this->name, frame, err); + GF_VALIDATE_OR_GOTO (this->name, fd, err); + GF_VALIDATE_OR_GOTO (this->name, stbuf, err); subvol = get_mapping_subvol_from_ctx (this, fd->inode); if (!subvol) { @@ -1041,9 +930,8 @@ map_fchown (call_frame_t *frame, goto err; } - STACK_WIND (frame, map_fchown_cbk, subvol, - subvol->fops->fchown, fd, uid, gid); - + STACK_WIND (frame, map_fsetattr_cbk, subvol, + subvol->fops->fsetattr, fd, stbuf, valid); return 0; err: STACK_UNWIND (frame, -1, op_errno, NULL, NULL); @@ -1113,37 +1001,6 @@ map_ftruncate (call_frame_t *frame, } int32_t -map_utimens (call_frame_t *frame, - xlator_t *this, - loc_t *loc, - struct timespec tv[2]) -{ - int32_t op_errno = 1; - xlator_t *subvol = NULL; - - VALIDATE_OR_GOTO (frame, err); - VALIDATE_OR_GOTO (this, err); - VALIDATE_OR_GOTO (loc, err); - VALIDATE_OR_GOTO (loc->inode, err); - VALIDATE_OR_GOTO (loc->path, err); - - subvol = get_mapping_subvol_from_ctx (this, loc->inode); - if (!subvol) { - op_errno = EINVAL; - goto err; - } - - STACK_WIND (frame, map_utimens_cbk, subvol, - subvol->fops->utimens, loc, tv); - - return 0; - err: - STACK_UNWIND (frame, -1, op_errno, NULL, NULL); - - return 0; -} - -int32_t map_access (call_frame_t *frame, xlator_t *this, loc_t *loc, @@ -2557,12 +2414,7 @@ struct xlator_fops fops = { .create = map_create, .stat = map_stat, - .chmod = map_chmod, - .chown = map_chown, - .fchown = map_fchown, - .fchmod = map_fchmod, .fstat = map_fstat, - .utimens = map_utimens, .truncate = map_truncate, .ftruncate = map_ftruncate, .access = map_access, @@ -2597,6 +2449,8 @@ struct xlator_fops fops = { .setdents = map_setdents, .getdents = map_getdents, .checksum = map_checksum, + .setattr = map_setattr, + .fsetattr = map_fsetattr, }; struct xlator_mops mops = { diff --git a/xlators/cluster/stripe/src/stripe.c b/xlators/cluster/stripe/src/stripe.c index ee230a9c3..5a02d17bc 100644 --- a/xlators/cluster/stripe/src/stripe.c +++ b/xlators/cluster/stripe/src/stripe.c @@ -498,124 +498,6 @@ stripe_stat (call_frame_t *frame, xlator_t *this, loc_t *loc) /** - * stripe_chmod - - */ -int32_t -stripe_chmod (call_frame_t *frame, xlator_t *this, loc_t *loc, mode_t mode) -{ - int send_fop_to_all = 0; - xlator_list_t *trav = NULL; - stripe_local_t *local = NULL; - stripe_private_t *priv = NULL; - int32_t op_errno = 1; - - VALIDATE_OR_GOTO (frame, err); - VALIDATE_OR_GOTO (this, err); - VALIDATE_OR_GOTO (loc, err); - VALIDATE_OR_GOTO (loc->path, err); - VALIDATE_OR_GOTO (loc->inode, err); - - priv = this->private; - trav = this->children; - - if (priv->first_child_down) { - op_errno = ENOTCONN; - goto err; - } - - if (S_ISDIR (loc->inode->st_mode) || S_ISREG (loc->inode->st_mode)) - send_fop_to_all = 1; - - if (!send_fop_to_all) { - STACK_WIND (frame, stripe_common_buf_cbk, FIRST_CHILD(this), - FIRST_CHILD(this)->fops->chmod, loc, mode); - } else { - /* Initialization */ - local = CALLOC (1, sizeof (stripe_local_t)); - if (!local) { - op_errno = ENOMEM; - goto err; - } - local->op_ret = -1; - frame->local = local; - local->inode = loc->inode; - local->call_count = priv->child_count; - - while (trav) { - STACK_WIND (frame, stripe_stack_unwind_buf_cbk, - trav->xlator, trav->xlator->fops->chmod, - loc, mode); - trav = trav->next; - } - } - return 0; - err: - STACK_UNWIND (frame, -1, op_errno, NULL); - return 0; -} - - -/** - * stripe_chown - - */ -int32_t -stripe_chown (call_frame_t *frame, xlator_t *this, loc_t *loc, uid_t uid, - gid_t gid) -{ - int send_fop_to_all = 0; - xlator_list_t *trav = NULL; - stripe_local_t *local = NULL; - stripe_private_t *priv = NULL; - int32_t op_errno = 1; - - VALIDATE_OR_GOTO (frame, err); - VALIDATE_OR_GOTO (this, err); - VALIDATE_OR_GOTO (loc, err); - VALIDATE_OR_GOTO (loc->path, err); - VALIDATE_OR_GOTO (loc->inode, err); - - priv = this->private; - trav = this->children; - - if (priv->first_child_down) { - op_errno = ENOTCONN; - goto err; - } - - if (S_ISDIR (loc->inode->st_mode) || S_ISREG (loc->inode->st_mode)) - send_fop_to_all = 1; - - if (!send_fop_to_all) { - STACK_WIND (frame, stripe_common_buf_cbk, trav->xlator, - trav->xlator->fops->chown, loc, uid, gid); - } else { - /* Initialization */ - local = CALLOC (1, sizeof (stripe_local_t)); - if (!local) { - op_errno = ENOMEM; - goto err; - } - local->op_ret = -1; - frame->local = local; - local->inode = loc->inode; - local->call_count = priv->child_count; - - while (trav) { - STACK_WIND (frame, stripe_stack_unwind_buf_cbk, - trav->xlator, trav->xlator->fops->chown, - loc, uid, gid); - trav = trav->next; - } - } - - return 0; - err: - STACK_UNWIND (frame, -1, op_errno, NULL); - return 0; -} - - -/** * stripe_statfs_cbk - */ int32_t @@ -758,12 +640,91 @@ stripe_truncate (call_frame_t *frame, xlator_t *this, loc_t *loc, off_t offset) } -/** - * stripe_utimens - - */ int32_t -stripe_utimens (call_frame_t *frame, xlator_t *this, loc_t *loc, - struct timespec tv[2]) +stripe_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) +{ + int32_t callcnt = 0; + stripe_local_t *local = NULL; + + local = frame->local; + + LOCK (&frame->lock); + { + callcnt = --local->call_count; + + if (op_ret == -1) { + gf_log (this->name, GF_LOG_DEBUG, + "%s returned error %s", + ((call_frame_t *)cookie)->this->name, + strerror (op_errno)); + local->op_errno = op_errno; + if (op_errno == ENOTCONN) + local->failed = 1; + } + + if (op_ret == 0) { + local->op_ret = 0; + + if (local->stbuf.st_blksize == 0) { + local->preop_buf = *preop; + local->stbuf = *postop; + + /* Because st_blocks gets added again */ + + local->preop_buf.st_blocks = 0; + local->stbuf.st_blocks = 0; + } + + if (FIRST_CHILD(this) == + ((call_frame_t *)cookie)->this) { + /* Always, pass the inode number of + first child to the above layer */ + + local->preop_buf.st_ino = preop->st_ino; + local->preop_buf.st_mtime = preop->st_mtime; + + local->stbuf.st_ino = postop->st_ino; + local->stbuf.st_mtime = postop->st_mtime; + } + + local->preop_buf.st_blocks += preop->st_blocks; + local->stbuf.st_blocks += postop->st_blocks; + + + if (local->stbuf.st_size < postop->st_size) + local->preop_buf.st_size = preop->st_size; + local->stbuf.st_size = postop->st_size; + + if (local->stbuf.st_blksize != postop->st_blksize) { + /* TODO: add to blocks in terms of + original block size */ + } + } + } + UNLOCK (&frame->lock); + + if (!callcnt) { + if (local->failed) + local->op_ret = -1; + + if (local->loc.path) + loc_wipe (&local->loc); + if (local->loc2.path) + loc_wipe (&local->loc2); + + STACK_UNWIND (frame, local->op_ret, local->op_errno, + &local->preop_buf, &local->stbuf); + } + + return 0; +} + + +int32_t +stripe_setattr (call_frame_t *frame, xlator_t *this, loc_t *loc, + struct stat *stbuf, int32_t valid) { int send_fop_to_all = 0; xlator_list_t *trav = NULL; @@ -789,8 +750,8 @@ stripe_utimens (call_frame_t *frame, xlator_t *this, loc_t *loc, send_fop_to_all = 1; if (!send_fop_to_all) { - STACK_WIND (frame, stripe_common_buf_cbk, trav->xlator, - trav->xlator->fops->utimens, loc, tv); + STACK_WIND (frame, stripe_setattr_cbk, trav->xlator, + trav->xlator->fops->setattr, loc, stbuf, valid); } else { /* Initialization */ local = CALLOC (1, sizeof (stripe_local_t)); @@ -804,16 +765,57 @@ stripe_utimens (call_frame_t *frame, xlator_t *this, loc_t *loc, local->call_count = priv->child_count; while (trav) { - STACK_WIND (frame, stripe_stack_unwind_buf_cbk, - trav->xlator, trav->xlator->fops->utimens, - loc, tv); + STACK_WIND (frame, stripe_setattr_cbk, + trav->xlator, trav->xlator->fops->setattr, + loc, stbuf, valid); trav = trav->next; } } return 0; err: - STACK_UNWIND (frame, -1, op_errno, NULL); + STACK_UNWIND (frame, -1, op_errno, NULL, NULL); + return 0; +} + + +int32_t +stripe_fsetattr (call_frame_t *frame, xlator_t *this, fd_t *fd, + struct stat *stbuf, int32_t valid) +{ + stripe_local_t *local = NULL; + stripe_private_t *priv = NULL; + xlator_list_t *trav = NULL; + int32_t op_errno = 1; + + VALIDATE_OR_GOTO (frame, err); + VALIDATE_OR_GOTO (this, err); + VALIDATE_OR_GOTO (fd, err); + VALIDATE_OR_GOTO (fd->inode, err); + + priv = this->private; + trav = this->children; + + /* Initialization */ + local = CALLOC (1, sizeof (stripe_local_t)); + if (!local) { + op_errno = ENOMEM; + goto err; + } + local->op_ret = -1; + frame->local = local; + local->inode = fd->inode; + local->call_count = priv->child_count; + + while (trav) { + STACK_WIND (frame, stripe_setattr_cbk, trav->xlator, + trav->xlator->fops->fsetattr, fd, stbuf, valid); + trav = trav->next; + } + + return 0; + err: + STACK_UNWIND (frame, -1, op_errno, NULL, NULL); return 0; } @@ -2520,93 +2522,6 @@ stripe_fstat (call_frame_t *frame, /** - * stripe_fchmod - - */ -int32_t -stripe_fchmod (call_frame_t *frame, xlator_t *this, fd_t *fd, mode_t mode) -{ - stripe_local_t *local = NULL; - stripe_private_t *priv = NULL; - xlator_list_t *trav = NULL; - int32_t op_errno = 1; - - VALIDATE_OR_GOTO (frame, err); - VALIDATE_OR_GOTO (this, err); - VALIDATE_OR_GOTO (fd, err); - VALIDATE_OR_GOTO (fd->inode, err); - - priv = this->private; - trav = this->children; - - /* Initialization */ - local = CALLOC (1, sizeof (stripe_local_t)); - if (!local) { - op_errno = ENOMEM; - goto err; - } - local->op_ret = -1; - frame->local = local; - local->inode = fd->inode; - local->call_count = priv->child_count; - - while (trav) { - STACK_WIND (frame, stripe_stack_unwind_buf_cbk, trav->xlator, - trav->xlator->fops->fchmod, fd, mode); - trav = trav->next; - } - - return 0; - err: - STACK_UNWIND (frame, -1, op_errno, NULL); - return 0; -} - - -/** - * stripe_fchown - - */ -int32_t -stripe_fchown (call_frame_t *frame, xlator_t *this, fd_t *fd, uid_t uid, - gid_t gid) -{ - stripe_local_t *local = NULL; - stripe_private_t *priv = NULL; - xlator_list_t *trav = NULL; - int32_t op_errno = 1; - - VALIDATE_OR_GOTO (frame, err); - VALIDATE_OR_GOTO (this, err); - VALIDATE_OR_GOTO (fd, err); - VALIDATE_OR_GOTO (fd->inode, err); - - priv = this->private; - trav = this->children; - - /* Initialization */ - local = CALLOC (1, sizeof (stripe_local_t)); - if (!local) { - op_errno = ENOMEM; - goto err; - } - local->op_ret = -1; - frame->local = local; - local->inode = fd->inode; - local->call_count = priv->child_count; - - while (trav) { - STACK_WIND (frame, stripe_stack_unwind_buf_cbk, trav->xlator, - trav->xlator->fops->fchown, fd, uid, gid); - trav = trav->next; - } - - return 0; - err: - STACK_UNWIND (frame, -1, op_errno, NULL); - return 0; -} - - -/** * stripe_ftruncate - */ int32_t @@ -3423,10 +3338,7 @@ struct xlator_fops fops = { .symlink = stripe_symlink, .rename = stripe_rename, .link = stripe_link, - .chmod = stripe_chmod, - .chown = stripe_chown, .truncate = stripe_truncate, - .utimens = stripe_utimens, .create = stripe_create, .open = stripe_open, .readv = stripe_readv, @@ -3446,8 +3358,8 @@ struct xlator_fops fops = { .lk = stripe_lk, .opendir = stripe_opendir, .fsyncdir = stripe_fsyncdir, - .fchmod = stripe_fchmod, - .fchown = stripe_fchown, + .setattr = stripe_setattr, + .fsetattr = stripe_fsetattr, .lookup = stripe_lookup, .setdents = stripe_setdents, .mknod = stripe_mknod, diff --git a/xlators/cluster/stripe/src/stripe.h b/xlators/cluster/stripe/src/stripe.h index 5ffbc3670..7c72f5c8f 100644 --- a/xlators/cluster/stripe/src/stripe.h +++ b/xlators/cluster/stripe/src/stripe.h @@ -93,6 +93,8 @@ struct stripe_local { /* Used by _cbk functions */ struct stat stbuf; + struct stat preop_buf; + struct readv_replies *replies; struct statvfs statvfs_buf; dir_entry_t *entry; diff --git a/xlators/cluster/unify/src/unify.c b/xlators/cluster/unify/src/unify.c index 35c108963..b641fb330 100644 --- a/xlators/cluster/unify/src/unify.c +++ b/xlators/cluster/unify/src/unify.c @@ -1763,72 +1763,78 @@ unify_opendir (call_frame_t *frame, } -/** - * unify_chmod - - */ int32_t -unify_chmod (call_frame_t *frame, - xlator_t *this, - loc_t *loc, - mode_t mode) +unify_setattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, struct stat *statpre, + struct stat *statpost) { - unify_local_t *local = NULL; - unify_private_t *priv = this->private; - int32_t index = 0; int32_t callcnt = 0; - uint64_t tmp_list = 0; - - UNIFY_CHECK_INODE_CTX_AND_UNWIND_ON_ERR (loc); + unify_private_t *priv = this->private; + unify_local_t *local = frame->local; + call_frame_t *prev_frame = cookie; - /* Initialization */ - INIT_LOCAL (frame, local); + LOCK (&frame->lock); + { + callcnt = --local->call_count; + + if (op_ret == -1) { + gf_log (this->name, GF_LOG_ERROR, + "%s(): child(%s): path(%s): %s", + gf_fop_list[frame->root->op], + prev_frame->this->name, + (local->loc1.path)?local->loc1.path:"", + strerror (op_errno)); - loc_copy (&local->loc1, loc); - local->st_ino = loc->inode->ino; + local->op_errno = op_errno; + if ((op_errno == ENOENT) && priv->optimist) + local->op_ret = 0; + } - if (S_ISDIR (loc->inode->st_mode)) { - local->call_count = priv->child_count + 1; - - for (index = 0; index < (priv->child_count + 1); index++) { - STACK_WIND (frame, - unify_buf_cbk, - priv->xl_array[index], - priv->xl_array[index]->fops->chmod, - loc, mode); - } - } else { - inode_ctx_get (loc->inode, this, &tmp_list); - local->list = (int16_t *)(long)tmp_list; + if (op_ret >= 0) { + local->op_ret = 0; - for (index = 0; local->list[index] != -1; index++) { - local->call_count++; - callcnt++; - } - - for (index = 0; local->list[index] != -1; index++) { - STACK_WIND (frame, - unify_buf_cbk, - priv->xl_array[local->list[index]], - priv->xl_array[local->list[index]]->fops->chmod, - loc, - mode); - if (!--callcnt) - break; + if (NS (this) == prev_frame->this) { + local->st_ino = statpost->st_ino; + /* If the entry is directory, get the stat + from NS node */ + if (S_ISDIR (statpost->st_mode) || + !local->stpost.st_blksize) { + local->stpre = *statpre; + local->stpost = *statpost; + } + } + + if ((!S_ISDIR (statpost->st_mode)) && + (NS (this) != prev_frame->this)) { + /* If file, take the stat info from Storage + node. */ + local->stpre = *statpre; + local->stpost = *statpost; + } } } + UNLOCK (&frame->lock); + + if (!callcnt) { + /* If the inode number is not filled, operation should + fail */ + if (!local->st_ino) + local->op_ret = -1; + + local->stpre.st_ino = local->st_ino; + local->stpost.st_ino = local->st_ino; + unify_local_wipe (local); + STACK_UNWIND (frame, local->op_ret, local->op_errno, + &local->stpre, &local->stpost); + } return 0; } -/** - * unify_chown - - */ + int32_t -unify_chown (call_frame_t *frame, - xlator_t *this, - loc_t *loc, - uid_t uid, - gid_t gid) +unify_setattr (call_frame_t *frame, xlator_t *this, loc_t *loc, + struct stat *stbuf, int32_t valid) { unify_local_t *local = NULL; unify_private_t *priv = this->private; @@ -1836,24 +1842,24 @@ unify_chown (call_frame_t *frame, int32_t callcnt = 0; uint64_t tmp_list = 0; - UNIFY_CHECK_INODE_CTX_AND_UNWIND_ON_ERR (loc); + if (!(loc && loc->inode)) { + STACK_UNWIND (frame, -1, EINVAL, NULL, NULL); + return 0; + } /* Initialization */ INIT_LOCAL (frame, local); loc_copy (&local->loc1, loc); - local->st_ino = loc->inode->ino; if (S_ISDIR (loc->inode->st_mode)) { - local->call_count = priv->child_count + 1; + local->call_count = 1; - for (index = 0; index < (priv->child_count + 1); index++) { - STACK_WIND (frame, - unify_buf_cbk, - priv->xl_array[index], - priv->xl_array[index]->fops->chown, - loc, uid, gid); - } - } else { + STACK_WIND (frame, + unify_setattr_cbk, + NS (this), + NS (this)->fops->setattr, + loc, stbuf, valid); + } else { inode_ctx_get (loc->inode, this, &tmp_list); local->list = (int16_t *)(long)tmp_list; @@ -1864,10 +1870,11 @@ unify_chown (call_frame_t *frame, for (index = 0; local->list[index] != -1; index++) { STACK_WIND (frame, - unify_buf_cbk, + unify_setattr_cbk, priv->xl_array[local->list[index]], - priv->xl_array[local->list[index]]->fops->chown, - loc, uid, gid); + priv->xl_array[local->list[index]]->fops->setattr, + loc, stbuf, valid); + if (!--callcnt) break; } @@ -1877,6 +1884,42 @@ unify_chown (call_frame_t *frame, } +int32_t +unify_fsetattr (call_frame_t *frame, xlator_t *this, fd_t *fd, + struct stat *stbuf, int32_t valid) +{ + unify_local_t *local = NULL; + xlator_t *child = NULL; + uint64_t tmp_child = 0; + + UNIFY_CHECK_FD_AND_UNWIND_ON_ERR(fd); + + /* Initialization */ + INIT_LOCAL (frame, local); + + if (!fd_ctx_get (fd, this, &tmp_child)) { + /* If its set, then its file */ + child = (xlator_t *)(long)tmp_child; + + local->call_count = 2; + + STACK_WIND (frame, unify_setattr_cbk, child, + child->fops->fsetattr, fd, stbuf, valid); + + STACK_WIND (frame, unify_setattr_cbk, NS(this), + NS(this)->fops->fsetattr, fd, stbuf, valid); + } else { + local->call_count = 1; + + STACK_WIND (frame, unify_setattr_cbk, + NS(this), NS(this)->fops->fsetattr, + fd, stbuf, valid); + } + + return 0; +} + + /** * unify_truncate_cbk - */ @@ -1942,6 +1985,7 @@ unify_truncate_cbk (call_frame_t *frame, return 0; } + /** * unify_truncate - */ @@ -2005,62 +2049,6 @@ unify_truncate (call_frame_t *frame, } /** - * unify_utimens - - */ -int32_t -unify_utimens (call_frame_t *frame, - xlator_t *this, - loc_t *loc, - struct timespec tv[2]) -{ - unify_local_t *local = NULL; - unify_private_t *priv = this->private; - int32_t index = 0; - int32_t callcnt = 0; - uint64_t tmp_list = 0; - - UNIFY_CHECK_INODE_CTX_AND_UNWIND_ON_ERR (loc); - - /* Initialization */ - INIT_LOCAL (frame, local); - loc_copy (&local->loc1, loc); - local->st_ino = loc->inode->ino; - - if (S_ISDIR (loc->inode->st_mode)) { - local->call_count = priv->child_count + 1; - - for (index = 0; index < (priv->child_count + 1); index++) { - STACK_WIND (frame, - unify_buf_cbk, - priv->xl_array[index], - priv->xl_array[index]->fops->utimens, - loc, tv); - } - } else { - inode_ctx_get (loc->inode, this, &tmp_list); - local->list = (int16_t *)(long)tmp_list; - - for (index = 0; local->list[index] != -1; index++) { - local->call_count++; - callcnt++; - } - - for (index = 0; local->list[index] != -1; index++) { - STACK_WIND (frame, - unify_buf_cbk, - priv->xl_array[local->list[index]], - priv->xl_array[local->list[index]]->fops->utimens, - loc, - tv); - if (!--callcnt) - break; - } - } - - return 0; -} - -/** * unify_readlink_cbk - */ int32_t @@ -2332,90 +2320,6 @@ unify_ftruncate (call_frame_t *frame, /** - * unify_fchmod - - */ -int32_t -unify_fchmod (call_frame_t *frame, - xlator_t *this, - fd_t *fd, - mode_t mode) -{ - unify_local_t *local = NULL; - xlator_t *child = NULL; - uint64_t tmp_child = 0; - - UNIFY_CHECK_FD_AND_UNWIND_ON_ERR(fd); - - /* Initialization */ - INIT_LOCAL (frame, local); - local->st_ino = fd->inode->ino; - - if (!fd_ctx_get (fd, this, &tmp_child)) { - /* If its set, then its file */ - child = (xlator_t *)(long)tmp_child; - - local->call_count = 2; - - STACK_WIND (frame, unify_buf_cbk, child, - child->fops->fchmod, fd, mode); - - STACK_WIND (frame, unify_buf_cbk, NS(this), - NS(this)->fops->fchmod, fd, mode); - - } else { - /* this is an directory */ - local->call_count = 1; - - STACK_WIND (frame, unify_buf_cbk, - NS(this), NS(this)->fops->fchmod, fd, mode); - } - - return 0; -} - -/** - * unify_fchown - - */ -int32_t -unify_fchown (call_frame_t *frame, - xlator_t *this, - fd_t *fd, - uid_t uid, - gid_t gid) -{ - unify_local_t *local = NULL; - xlator_t *child = NULL; - uint64_t tmp_child = 0; - - UNIFY_CHECK_FD_AND_UNWIND_ON_ERR(fd); - - /* Initialization */ - INIT_LOCAL (frame, local); - local->st_ino = fd->inode->ino; - - if (!fd_ctx_get (fd, this, &tmp_child)) { - /* If its set, then its file */ - child = (xlator_t *)(long)tmp_child; - - local->call_count = 2; - - STACK_WIND (frame, unify_buf_cbk, child, - child->fops->fchown, fd, uid, gid); - - STACK_WIND (frame, unify_buf_cbk, NS(this), - NS(this)->fops->fchown, fd, uid, gid); - } else { - local->call_count = 1; - - STACK_WIND (frame, unify_buf_cbk, - NS(this), NS(this)->fops->fchown, - fd, uid, gid); - } - - return 0; -} - -/** * unify_flush_cbk - */ int32_t @@ -4436,7 +4340,6 @@ fini (xlator_t *this) struct xlator_fops fops = { .stat = unify_stat, - .chmod = unify_chmod, .readlink = unify_readlink, .mknod = unify_mknod, .mkdir = unify_mkdir, @@ -4445,7 +4348,6 @@ struct xlator_fops fops = { .symlink = unify_symlink, .rename = unify_rename, .link = unify_link, - .chown = unify_chown, .truncate = unify_truncate, .create = unify_create, .open = unify_open, @@ -4464,9 +4366,6 @@ struct xlator_fops fops = { .ftruncate = unify_ftruncate, .fstat = unify_fstat, .lk = unify_lk, - .fchown = unify_fchown, - .fchmod = unify_fchmod, - .utimens = unify_utimens, .lookup = unify_lookup, .getdents = unify_getdents, .checksum = unify_checksum, @@ -4475,7 +4374,9 @@ struct xlator_fops fops = { .entrylk = unify_entrylk, .fentrylk = unify_fentrylk, .xattrop = unify_xattrop, - .fxattrop = unify_fxattrop + .fxattrop = unify_fxattrop, + .setattr = unify_setattr, + .fsetattr = unify_fsetattr, }; struct xlator_mops mops = { diff --git a/xlators/cluster/unify/src/unify.h b/xlators/cluster/unify/src/unify.h index 9841e5c7a..a745a9414 100644 --- a/xlators/cluster/unify/src/unify.h +++ b/xlators/cluster/unify/src/unify.h @@ -97,6 +97,8 @@ struct _unify_local_t { int32_t count; // dir_entry_t count; fd_t *fd; struct stat stbuf; + struct stat stpre; + struct stat stpost; struct statvfs statvfs_buf; struct timespec tv[2]; char *name; diff --git a/xlators/debug/error-gen/src/error-gen.c b/xlators/debug/error-gen/src/error-gen.c index a14d7beda..5aee0af41 100644 --- a/xlators/debug/error-gen/src/error-gen.c +++ b/xlators/debug/error-gen/src/error-gen.c @@ -129,157 +129,67 @@ error_gen_stat (call_frame_t *frame, } int32_t -error_gen_chmod_cbk (call_frame_t *frame, - void *cookie, - xlator_t *this, - int32_t op_ret, - int32_t op_errno, - struct stat *buf) +error_gen_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) { STACK_UNWIND (frame, op_ret, op_errno, - buf); + preop, postop); return 0; } int32_t -error_gen_chmod (call_frame_t *frame, - xlator_t *this, - loc_t *loc, - mode_t mode) +error_gen_setattr (call_frame_t *frame, + xlator_t *this, + loc_t *loc, + struct stat *stbuf, + int32_t valid) { int op_errno = 0; op_errno = error_gen(this); if (op_errno) { GF_ERROR(this, "unwind(-1, %s)", strerror (op_errno)); - STACK_UNWIND (frame, -1, op_errno, NULL); + STACK_UNWIND (frame, -1, op_errno, NULL, NULL); return 0; } STACK_WIND (frame, - error_gen_chmod_cbk, + error_gen_setattr_cbk, FIRST_CHILD(this), - FIRST_CHILD(this)->fops->chmod, + FIRST_CHILD(this)->fops->setattr, loc, - mode); + stbuf, valid); return 0; } - int32_t -error_gen_fchmod_cbk (call_frame_t *frame, - void *cookie, - xlator_t *this, - int32_t op_ret, - int32_t op_errno, - struct stat *buf) -{ - STACK_UNWIND (frame, - op_ret, - op_errno, - buf); - return 0; -} - -int32_t -error_gen_fchmod (call_frame_t *frame, - xlator_t *this, - fd_t *fd, - mode_t mode) +error_gen_fsetattr (call_frame_t *frame, + xlator_t *this, + fd_t *fd, + struct stat *stbuf, + int32_t valid) { int op_errno = 0; op_errno = error_gen(this); if (op_errno) { GF_ERROR(this, "unwind(-1, %s)", strerror (op_errno)); - STACK_UNWIND (frame, -1, op_errno, NULL); + STACK_UNWIND (frame, -1, op_errno, NULL, NULL); return 0; } STACK_WIND (frame, - error_gen_fchmod_cbk, + error_gen_setattr_cbk, FIRST_CHILD(this), - FIRST_CHILD(this)->fops->fchmod, + FIRST_CHILD(this)->fops->fsetattr, fd, - mode); - return 0; -} - -int32_t -error_gen_chown_cbk (call_frame_t *frame, - void *cookie, - xlator_t *this, - int32_t op_ret, - int32_t op_errno, - struct stat *buf) -{ - STACK_UNWIND (frame, - op_ret, - op_errno, - buf); - return 0; -} - -int32_t -error_gen_chown (call_frame_t *frame, - xlator_t *this, - loc_t *loc, - uid_t uid, - gid_t gid) -{ - int op_errno = 0; - op_errno = error_gen(this); - if (op_errno) { - GF_ERROR(this, "unwind(-1, %s)", strerror (op_errno)); - STACK_UNWIND (frame, -1, op_errno, NULL); - return 0; - } - STACK_WIND (frame, - error_gen_chown_cbk, - FIRST_CHILD(this), - FIRST_CHILD(this)->fops->chown, - loc, - uid, - gid); + stbuf, valid); return 0; } -int32_t -error_gen_fchown_cbk (call_frame_t *frame, - void *cookie, - xlator_t *this, - int32_t op_ret, - int32_t op_errno, - struct stat *buf) -{ - STACK_UNWIND (frame, - op_ret, - op_errno, - buf); - return 0; -} - -int32_t -error_gen_fchown (call_frame_t *frame, - xlator_t *this, - fd_t *fd, - uid_t uid, - gid_t gid) -{ - int op_errno = 0; - op_errno = error_gen(this); - if (op_errno) { - GF_ERROR(this, "unwind(-1, %s)", strerror (op_errno)); - STACK_UNWIND (frame, -1, op_errno, NULL); - return 0; - } - STACK_WIND (frame, - error_gen_fchown_cbk, - FIRST_CHILD(this), - FIRST_CHILD(this)->fops->fchown, - fd, - uid, - gid); - return 0; -} int32_t error_gen_truncate_cbk (call_frame_t *frame, @@ -355,43 +265,6 @@ error_gen_ftruncate (call_frame_t *frame, return 0; } -int32_t -error_gen_utimens_cbk (call_frame_t *frame, - void *cookie, - xlator_t *this, - int32_t op_ret, - int32_t op_errno, - struct stat *buf) -{ - STACK_UNWIND (frame, - op_ret, - op_errno, - buf); - return 0; -} - - -int32_t -error_gen_utimens (call_frame_t *frame, - xlator_t *this, - loc_t *loc, - struct timespec tv[2]) -{ - int op_errno = 0; - op_errno = error_gen(this); - if (op_errno) { - GF_ERROR(this, "unwind(-1, %s)", strerror (op_errno)); - STACK_UNWIND (frame, -1, op_errno, NULL); - return 0; - } - STACK_WIND (frame, - error_gen_utimens_cbk, - FIRST_CHILD(this), - FIRST_CHILD(this)->fops->utimens, - loc, - tv); - return 0; -} int32_t error_gen_access_cbk (call_frame_t *frame, @@ -1740,10 +1613,7 @@ struct xlator_fops fops = { .symlink = error_gen_symlink, .rename = error_gen_rename, .link = error_gen_link, - .chmod = error_gen_chmod, - .chown = error_gen_chown, .truncate = error_gen_truncate, - .utimens = error_gen_utimens, .create = error_gen_create, .open = error_gen_open, .readv = error_gen_readv, @@ -1762,8 +1632,6 @@ struct xlator_fops fops = { .ftruncate = error_gen_ftruncate, .fstat = error_gen_fstat, .lk = error_gen_lk, - .fchmod = error_gen_fchmod, - .fchown = error_gen_fchown, .setdents = error_gen_setdents, .lookup_cbk = error_gen_lookup_cbk, .checksum = error_gen_checksum, @@ -1772,7 +1640,9 @@ struct xlator_fops fops = { .inodelk = error_gen_inodelk, .finodelk = error_gen_finodelk, .entrylk = error_gen_entrylk, - .fentrylk = error_gen_fentrylk + .fentrylk = error_gen_fentrylk, + .setattr = error_gen_setattr, + .fsetattr = error_gen_fsetattr, }; struct xlator_mops mops = { diff --git a/xlators/debug/io-stats/src/io-stats.c b/xlators/debug/io-stats/src/io-stats.c index c07685017..662762100 100644 --- a/xlators/debug/io-stats/src/io-stats.c +++ b/xlators/debug/io-stats/src/io-stats.c @@ -187,50 +187,15 @@ io_stats_fsync_cbk (call_frame_t *frame, } int32_t -io_stats_chown_cbk (call_frame_t *frame, - void *cookie, - xlator_t *this, - int32_t op_ret, - int32_t op_errno, - struct stat *buf) -{ - STACK_UNWIND (frame, op_ret, op_errno, buf); - return 0; -} - -int32_t -io_stats_chmod_cbk (call_frame_t *frame, - void *cookie, - xlator_t *this, - int32_t op_ret, - int32_t op_errno, - struct stat *buf) -{ - STACK_UNWIND (frame, op_ret, op_errno, buf); - return 0; -} - -int32_t -io_stats_fchmod_cbk (call_frame_t *frame, - void *cookie, - xlator_t *this, - int32_t op_ret, - int32_t op_errno, - struct stat *buf) -{ - STACK_UNWIND (frame, op_ret, op_errno, buf); - return 0; -} - -int32_t -io_stats_fchown_cbk (call_frame_t *frame, - void *cookie, - xlator_t *this, - int32_t op_ret, - int32_t op_errno, - struct stat *buf) +io_stats_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) { - STACK_UNWIND (frame, op_ret, op_errno, buf); + STACK_UNWIND (frame, op_ret, op_errno, preop, postop); return 0; } @@ -857,39 +822,20 @@ io_stats_link (call_frame_t *frame, } int32_t -io_stats_chmod (call_frame_t *frame, - xlator_t *this, - loc_t *loc, - mode_t mode) -{ - BUMP_HIT(CHMOD); - - STACK_WIND (frame, - io_stats_chmod_cbk, - FIRST_CHILD(this), - FIRST_CHILD(this)->fops->chmod, - loc, - mode); - - return 0; -} - -int32_t -io_stats_chown (call_frame_t *frame, - xlator_t *this, - loc_t *loc, - uid_t uid, - gid_t gid) +io_stats_setattr (call_frame_t *frame, + xlator_t *this, + loc_t *loc, + struct stat *stbuf, + int32_t valid) { - BUMP_HIT(CHOWN); + BUMP_HIT(SETATTR); STACK_WIND (frame, - io_stats_chown_cbk, + io_stats_setattr_cbk, FIRST_CHILD(this), - FIRST_CHILD(this)->fops->chown, + FIRST_CHILD(this)->fops->setattr, loc, - uid, - gid); + stbuf, valid); return 0; } @@ -913,24 +859,6 @@ io_stats_truncate (call_frame_t *frame, } int32_t -io_stats_utimens (call_frame_t *frame, - xlator_t *this, - loc_t *loc, - struct timespec tv[2]) -{ - BUMP_HIT(UTIMENS); - - STACK_WIND (frame, - io_stats_utimens_cbk, - FIRST_CHILD(this), - FIRST_CHILD(this)->fops->utimens, - loc, - tv); - - return 0; -} - -int32_t io_stats_open (call_frame_t *frame, xlator_t *this, loc_t *loc, @@ -1238,38 +1166,20 @@ io_stats_ftruncate (call_frame_t *frame, } int32_t -io_stats_fchown (call_frame_t *frame, - xlator_t *this, - fd_t *fd, - uid_t uid, - gid_t gid) -{ - BUMP_HIT(FCHOWN); - - STACK_WIND (frame, - io_stats_fchown_cbk, - FIRST_CHILD(this), - FIRST_CHILD(this)->fops->fchown, - fd, - uid, - gid); - return 0; -} - -int32_t -io_stats_fchmod (call_frame_t *frame, - xlator_t *this, - fd_t *fd, - mode_t mode) +io_stats_fsetattr (call_frame_t *frame, + xlator_t *this, + fd_t *fd, + struct stat *stbuf, + int32_t valid) { - BUMP_HIT(FCHMOD); + BUMP_HIT(FSETATTR); STACK_WIND (frame, - io_stats_fchmod_cbk, + io_stats_setattr_cbk, FIRST_CHILD(this), - FIRST_CHILD(this)->fops->fchmod, + FIRST_CHILD(this)->fops->fsetattr, fd, - mode); + stbuf, valid); return 0; } @@ -1513,10 +1423,7 @@ struct xlator_fops fops = { .symlink = io_stats_symlink, .rename = io_stats_rename, .link = io_stats_link, - .chmod = io_stats_chmod, - .chown = io_stats_chown, .truncate = io_stats_truncate, - .utimens = io_stats_utimens, .open = io_stats_open, .readv = io_stats_readv, .writev = io_stats_writev, @@ -1533,8 +1440,6 @@ struct xlator_fops fops = { .ftruncate = io_stats_ftruncate, .fstat = io_stats_fstat, .create = io_stats_create, - .fchown = io_stats_fchown, - .fchmod = io_stats_fchmod, .lk = io_stats_lk, .inodelk = io_stats_inodelk, .finodelk = io_stats_finodelk, @@ -1545,6 +1450,8 @@ struct xlator_fops fops = { .checksum = io_stats_checksum, .xattrop = io_stats_xattrop, .fxattrop = io_stats_fxattrop, + .setattr = io_stats_setattr, + .fsetattr = io_stats_fsetattr, }; struct xlator_mops mops = { diff --git a/xlators/debug/trace/src/trace.c b/xlators/debug/trace/src/trace.c index 2c10c7515..2b66720a0 100644 --- a/xlators/debug/trace/src/trace.c +++ b/xlators/debug/trace/src/trace.c @@ -296,138 +296,123 @@ trace_fsync_cbk (call_frame_t *frame, return 0; } -int32_t -trace_chown_cbk (call_frame_t *frame, - void *cookie, - xlator_t *this, - int32_t op_ret, - int32_t op_errno, - struct stat *buf) -{ - char atime_buf[256], mtime_buf[256], ctime_buf[256]; - ERR_EINVAL_NORETURN (!this ); - - if (trace_fop_names[GF_FOP_CHOWN].enabled) { - if (op_ret >= 0) { - strftime (atime_buf, 256, "[%b %d %H:%M:%S]", localtime (&buf->st_atime)); - strftime (mtime_buf, 256, "[%b %d %H:%M:%S]", localtime (&buf->st_mtime)); - strftime (ctime_buf, 256, "[%b %d %H:%M:%S]", localtime (&buf->st_ctime)); - - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64": (op_ret=%d, *buf {st_ino=%"PRIu64", st_mode=%o, " - "st_uid=%d, st_gid=%d, st_atime=%s, st_mtime=%s, st_ctime=%s})", - frame->root->unique, op_ret, buf->st_ino, buf->st_mode, - buf->st_uid, buf->st_gid, atime_buf, mtime_buf, ctime_buf); - } else { - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64": (op_ret=%d, op_errno=%d)", - frame->root->unique, op_ret, op_errno); - } - } - - STACK_UNWIND (frame, op_ret, op_errno, buf); - return 0; -} +int32_t +trace_setattr_cbk (call_frame_t *frame, + void *cookie, + xlator_t *this, + int32_t op_ret, + int32_t op_errno, + struct stat *statpre, + struct stat *statpost) +{ + char atime_pre[256] = {0,}; + char mtime_pre[256] = {0,}; + char ctime_pre[256] = {0,}; + char atime_post[256] = {0,}; + char mtime_post[256] = {0,}; + char ctime_post[256] = {0,}; -int32_t -trace_chmod_cbk (call_frame_t *frame, - void *cookie, - xlator_t *this, - int32_t op_ret, - int32_t op_errno, - struct stat *buf) -{ - char atime_buf[256], mtime_buf[256], ctime_buf[256]; ERR_EINVAL_NORETURN (!this ); - if (trace_fop_names[GF_FOP_CHMOD].enabled) { + if (trace_fop_names[GF_FOP_SETATTR].enabled) { if (op_ret >= 0) { - strftime (atime_buf, 256, "[%b %d %H:%M:%S]", localtime (&buf->st_atime)); - strftime (mtime_buf, 256, "[%b %d %H:%M:%S]", localtime (&buf->st_mtime)); - strftime (ctime_buf, 256, "[%b %d %H:%M:%S]", localtime (&buf->st_ctime)); + strftime (atime_pre, 256, "[%b %d %H:%M:%S]", + localtime (&statpre->st_atime)); + strftime (mtime_pre, 256, "[%b %d %H:%M:%S]", + localtime (&statpre->st_mtime)); + strftime (ctime_pre, 256, "[%b %d %H:%M:%S]", + localtime (&statpre->st_ctime)); + + strftime (atime_post, 256, "[%b %d %H:%M:%S]", + localtime (&statpost->st_atime)); + strftime (mtime_post, 256, "[%b %d %H:%M:%S]", + localtime (&statpost->st_mtime)); + strftime (ctime_post, 256, "[%b %d %H:%M:%S]", + localtime (&statpost->st_ctime)); - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64": (op_ret=%d, *buf {st_ino=%"PRIu64", st_mode=%o, " - "st_atime=%s, st_mtime=%s, st_ctime=%s})", - frame->root->unique, op_ret, buf->st_ino, buf->st_mode, - atime_buf, mtime_buf, ctime_buf); + gf_log (this->name, GF_LOG_NORMAL, + "%"PRId64": (op_ret=%d, *statpre " + "{st_ino=%"PRIu64", st_mode=%o, st_uid=%d, " + "st_gid=%d, st_atime=%s, st_mtime=%s, " + "st_ctime=%s}, *statpost {st_ino=%"PRIu64", " + "st_mode=%o, st_uid=%d, st_gid=%d, st_atime=%s," + " st_mtime=%s, st_ctime=%s})", + frame->root->unique, op_ret, statpre->st_ino, + statpre->st_mode, statpre->st_uid, + statpre->st_gid, atime_pre, mtime_pre, + ctime_pre, statpost->st_ino, statpost->st_mode, + statpost->st_uid, statpost->st_gid, atime_post, + mtime_post, ctime_post); } else { - gf_log (this->name, GF_LOG_NORMAL, + gf_log (this->name, GF_LOG_NORMAL, "%"PRId64": (op_ret=%d, op_errno=%d)", frame->root->unique, op_ret, op_errno); } } - STACK_UNWIND (frame, op_ret, op_errno, buf); + STACK_UNWIND (frame, op_ret, op_errno, statpre, statpost); return 0; } -int32_t -trace_fchmod_cbk (call_frame_t *frame, - void *cookie, - xlator_t *this, - int32_t op_ret, - int32_t op_errno, - struct stat *buf) -{ - char atime_buf[256], mtime_buf[256], ctime_buf[256]; - ERR_EINVAL_NORETURN (!this ); - - if (trace_fop_names[GF_FOP_FCHMOD].enabled) { - if (op_ret >= 0) { - strftime (atime_buf, 256, "[%b %d %H:%M:%S]", localtime (&buf->st_atime)); - strftime (mtime_buf, 256, "[%b %d %H:%M:%S]", localtime (&buf->st_mtime)); - strftime (ctime_buf, 256, "[%b %d %H:%M:%S]", localtime (&buf->st_ctime)); - - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64": (op_ret=%d, *buf {st_ino=%"PRIu64", st_mode=%o, " - "st_atime=%s, st_mtime=%s, st_ctime=%s})", - frame->root->unique, op_ret, buf->st_ino, buf->st_mode, - atime_buf, mtime_buf, ctime_buf); - } else { - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64": (op_ret=%d, op_errno=%d)", - frame->root->unique, op_ret, op_errno); - } - } - - STACK_UNWIND (frame, op_ret, op_errno, buf); - return 0; -} +int32_t +trace_fsetattr_cbk (call_frame_t *frame, + void *cookie, + xlator_t *this, + int32_t op_ret, + int32_t op_errno, + struct stat *statpre, + struct stat *statpost) +{ + char atime_pre[256] = {0,}; + char mtime_pre[256] = {0,}; + char ctime_pre[256] = {0,}; + char atime_post[256] = {0,}; + char mtime_post[256] = {0,}; + char ctime_post[256] = {0,}; -int32_t -trace_fchown_cbk (call_frame_t *frame, - void *cookie, - xlator_t *this, - int32_t op_ret, - int32_t op_errno, - struct stat *buf) -{ - char atime_buf[256], mtime_buf[256], ctime_buf[256]; ERR_EINVAL_NORETURN (!this ); - if (trace_fop_names[GF_FOP_FCHOWN].enabled) { + if (trace_fop_names[GF_FOP_FSETATTR].enabled) { if (op_ret >= 0) { - strftime (atime_buf, 256, "[%b %d %H:%M:%S]", localtime (&buf->st_atime)); - strftime (mtime_buf, 256, "[%b %d %H:%M:%S]", localtime (&buf->st_mtime)); - strftime (ctime_buf, 256, "[%b %d %H:%M:%S]", localtime (&buf->st_ctime)); + strftime (atime_pre, 256, "[%b %d %H:%M:%S]", + localtime (&statpre->st_atime)); + strftime (mtime_pre, 256, "[%b %d %H:%M:%S]", + localtime (&statpre->st_mtime)); + strftime (ctime_pre, 256, "[%b %d %H:%M:%S]", + localtime (&statpre->st_ctime)); + + strftime (atime_post, 256, "[%b %d %H:%M:%S]", + localtime (&statpost->st_atime)); + strftime (mtime_post, 256, "[%b %d %H:%M:%S]", + localtime (&statpost->st_mtime)); + strftime (ctime_post, 256, "[%b %d %H:%M:%S]", + localtime (&statpost->st_ctime)); - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64": (op_ret=%d, *buf {st_ino=%"PRIu64", st_mode=%o, " - "st_uid=%d, st_gid=%d, st_atime=%s, st_mtime=%s, st_ctime=%s})", - frame->root->unique, op_ret, buf->st_ino, buf->st_mode, - buf->st_uid, buf->st_gid, atime_buf, mtime_buf, ctime_buf); + gf_log (this->name, GF_LOG_NORMAL, + "%"PRId64": (op_ret=%d, *statpre " + "{st_ino=%"PRIu64", st_mode=%o, st_uid=%d, " + "st_gid=%d, st_atime=%s, st_mtime=%s, " + "st_ctime=%s}, *statpost {st_ino=%"PRIu64", " + "st_mode=%o, st_uid=%d, st_gid=%d, st_atime=%s," + " st_mtime=%s, st_ctime=%s})", + frame->root->unique, op_ret, statpre->st_ino, + statpre->st_mode, statpre->st_uid, + statpre->st_gid, atime_pre, mtime_pre, + ctime_pre, statpost->st_ino, statpost->st_mode, + statpost->st_uid, statpost->st_gid, atime_post, + mtime_post, ctime_post); } else { - gf_log (this->name, GF_LOG_NORMAL, + gf_log (this->name, GF_LOG_NORMAL, "%"PRId64": (op_ret=%d, op_errno=%d)", frame->root->unique, op_ret, op_errno); } } - STACK_UNWIND (frame, op_ret, op_errno, buf); + STACK_UNWIND (frame, op_ret, op_errno, statpre, statpost); return 0; } + int32_t trace_unlink_cbk (call_frame_t *frame, void *cookie, @@ -737,38 +722,6 @@ trace_truncate_cbk (call_frame_t *frame, } int32_t -trace_utimens_cbk (call_frame_t *frame, - void *cookie, - xlator_t *this, - int32_t op_ret, - int32_t op_errno, - struct stat *buf) -{ - char atime_buf[256], mtime_buf[256], ctime_buf[256]; - ERR_EINVAL_NORETURN (!this ); - - if (trace_fop_names[GF_FOP_UTIMENS].enabled) { - if (op_ret >= 0) { - strftime (atime_buf, 256, "[%b %d %H:%M:%S]", localtime (&buf->st_atime)); - strftime (mtime_buf, 256, "[%b %d %H:%M:%S]", localtime (&buf->st_mtime)); - strftime (ctime_buf, 256, "[%b %d %H:%M:%S]", localtime (&buf->st_ctime)); - - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64": (op_ret=%d, *buf {st_atime=%s, st_mtime=%s, " - "st_ctime=%s})", - frame->root->unique, op_ret, atime_buf, mtime_buf, ctime_buf); - } else { - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64": (op_ret=%d, op_errno=%d)", - frame->root->unique, op_ret, op_errno); - } - } - - STACK_UNWIND (frame, op_ret, op_errno, buf); - return 0; -} - -int32_t trace_statfs_cbk (call_frame_t *frame, void *cookie, xlator_t *this, @@ -1469,52 +1422,105 @@ trace_link (call_frame_t *frame, return 0; } -int32_t -trace_chmod (call_frame_t *frame, - xlator_t *this, - loc_t *loc, - mode_t mode) -{ - ERR_EINVAL_NORETURN (!this || !loc); - - if (trace_fop_names[GF_FOP_CHMOD].enabled) { - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64": (loc {path=%s, ino=%"PRIu64"}, mode=%o)", - frame->root->unique, loc->path, loc->inode->ino, mode); +int32_t +trace_setattr (call_frame_t *frame, + xlator_t *this, + loc_t *loc, + struct stat *stbuf, + int32_t valid) +{ + char actime_str[256] = {0,}; + char modtime_str[256] = {0,}; + + ERR_EINVAL_NORETURN (!this || !loc || !stbuf); + + if (trace_fop_names[GF_FOP_SETATTR].enabled) { + if (valid & GF_SET_ATTR_MODE) { + gf_log (this->name, GF_LOG_NORMAL, + "%"PRId64": (loc {path=%s, ino=%"PRIu64"}," + " mode=%o)", frame->root->unique, loc->path, + loc->inode->ino, stbuf->st_mode); + } + + if (valid & (GF_SET_ATTR_UID | GF_SET_ATTR_GID)) { + gf_log (this->name, GF_LOG_NORMAL, + "%"PRId64": (loc {path=%s, ino=%"PRIu64"}," + " uid=%o, gid=%o)", + frame->root->unique, loc->path, loc->inode->ino, + stbuf->st_uid, stbuf->st_gid); + } + + if (valid & (GF_SET_ATTR_ATIME | GF_SET_ATTR_MTIME)) { + strftime (actime_str, 256, "[%b %d %H:%M:%S]", + localtime (&stbuf->st_atime)); + strftime (modtime_str, 256, "[%b %d %H:%M:%S]", + localtime (&stbuf->st_mtime)); + + gf_log (this->name, GF_LOG_NORMAL, + "%"PRId64": (loc {path=%s, ino=%"PRIu64"}, " + "*stbuf=%p {st_atime=%s, st_mtime=%s})", + frame->root->unique, loc->path, loc->inode->ino, + stbuf, actime_str, modtime_str); + } } - STACK_WIND (frame, - trace_chmod_cbk, - FIRST_CHILD(this), - FIRST_CHILD(this)->fops->chmod, + STACK_WIND (frame, + trace_setattr_cbk, + FIRST_CHILD(this), + FIRST_CHILD(this)->fops->setattr, loc, - mode); - + stbuf, valid); + return 0; } -int32_t -trace_chown (call_frame_t *frame, - xlator_t *this, - loc_t *loc, - uid_t uid, - gid_t gid) -{ - ERR_EINVAL_NORETURN (!this || !loc); - - if (trace_fop_names[GF_FOP_CHOWN].enabled) { - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64": (loc {path=%s, ino=%"PRIu64"}, uid=%d, gid=%d)", - frame->root->unique, loc->path, loc->inode->ino, uid, gid); +int32_t +trace_fsetattr (call_frame_t *frame, + xlator_t *this, + fd_t *fd, + struct stat *stbuf, + int32_t valid) +{ + char actime_str[256] = {0,}; + char modtime_str[256] = {0,}; + + ERR_EINVAL_NORETURN (!this || !fd || !stbuf); + + if (trace_fop_names[GF_FOP_FSETATTR].enabled) { + if (valid & GF_SET_ATTR_MODE) { + gf_log (this->name, GF_LOG_NORMAL, + "%"PRId64": (*fd=%p, mode=%o)", + frame->root->unique, fd, + stbuf->st_mode); + } + + if (valid & (GF_SET_ATTR_UID | GF_SET_ATTR_GID)) { + gf_log (this->name, GF_LOG_NORMAL, + "%"PRId64": (*fd=%p, uid=%o, gid=%o)", + frame->root->unique, fd, + stbuf->st_uid, stbuf->st_gid); + } + + if (valid & (GF_SET_ATTR_ATIME | GF_SET_ATTR_MTIME)) { + strftime (actime_str, 256, "[%b %d %H:%M:%S]", + localtime (&stbuf->st_atime)); + strftime (modtime_str, 256, "[%b %d %H:%M:%S]", + localtime (&stbuf->st_mtime)); + + gf_log (this->name, GF_LOG_NORMAL, + "%"PRId64": (*fd=%p" + "*stbuf=%p {st_atime=%s, st_mtime=%s})", + frame->root->unique, fd, stbuf, actime_str, + modtime_str); + } } - STACK_WIND (frame, - trace_chown_cbk, - FIRST_CHILD(this), - FIRST_CHILD(this)->fops->chown, - loc, - uid, - gid); + STACK_WIND (frame, + trace_fsetattr_cbk, + FIRST_CHILD(this), + FIRST_CHILD(this)->fops->fsetattr, + fd, + stbuf, valid); return 0; } @@ -1544,38 +1550,6 @@ trace_truncate (call_frame_t *frame, } int32_t -trace_utimens (call_frame_t *frame, - xlator_t *this, - loc_t *loc, - struct timespec tv[2]) -{ - char actime_str[256]; - char modtime_str[256]; - - ERR_EINVAL_NORETURN (!this || !loc || !tv); - - if (trace_fop_names[GF_FOP_UTIMENS].enabled) { - strftime (actime_str, 256, "[%b %d %H:%M:%S]", localtime (&tv[0].tv_sec)); - strftime (modtime_str, 256, "[%b %d %H:%M:%S]", localtime (&tv[1].tv_sec)); - - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64": (loc {path=%s, ino=%"PRIu64"}, " - "*tv=%p {actime=%s, modtime=%s})", - frame->root->unique, loc->path, loc->inode->ino, - tv, actime_str, modtime_str); - } - - STACK_WIND (frame, - trace_utimens_cbk, - FIRST_CHILD(this), - FIRST_CHILD(this)->fops->utimens, - loc, - tv); - - return 0; -} - -int32_t trace_open (call_frame_t *frame, xlator_t *this, loc_t *loc, @@ -1972,54 +1946,6 @@ trace_ftruncate (call_frame_t *frame, } int32_t -trace_fchown (call_frame_t *frame, - xlator_t *this, - fd_t *fd, - uid_t uid, - gid_t gid) -{ - ERR_EINVAL_NORETURN (!this || !fd); - - if (trace_fop_names[GF_FOP_FCHOWN].enabled) { - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64": (*fd=%p, uid=%d, gid=%d)", - frame->root->unique, fd, uid, gid); - } - - STACK_WIND (frame, - trace_fchown_cbk, - FIRST_CHILD(this), - FIRST_CHILD(this)->fops->fchown, - fd, - uid, - gid); - return 0; -} - -int32_t -trace_fchmod (call_frame_t *frame, - xlator_t *this, - fd_t *fd, - mode_t mode) -{ - ERR_EINVAL_NORETURN (!this || !fd); - - if (trace_fop_names[GF_FOP_FCHMOD].enabled) { - gf_log (this->name, GF_LOG_NORMAL, - "%"PRId64": (mode=%o, *fd=%p)", - frame->root->unique, mode, fd); - } - - STACK_WIND (frame, - trace_fchmod_cbk, - FIRST_CHILD(this), - FIRST_CHILD(this)->fops->fchmod, - fd, - mode); - return 0; -} - -int32_t trace_fstat (call_frame_t *frame, xlator_t *this, fd_t *fd) @@ -2275,10 +2201,7 @@ struct xlator_fops fops = { .symlink = trace_symlink, .rename = trace_rename, .link = trace_link, - .chmod = trace_chmod, - .chown = trace_chown, .truncate = trace_truncate, - .utimens = trace_utimens, .open = trace_open, .readv = trace_readv, .writev = trace_writev, @@ -2295,8 +2218,6 @@ struct xlator_fops fops = { .ftruncate = trace_ftruncate, .fstat = trace_fstat, .create = trace_create, - .fchown = trace_fchown, - .fchmod = trace_fchmod, .lk = trace_lk, .inodelk = trace_inodelk, .finodelk = trace_finodelk, @@ -2307,6 +2228,8 @@ struct xlator_fops fops = { .checksum = trace_checksum, .xattrop = trace_xattrop, .fxattrop = trace_fxattrop, + .setattr = trace_setattr, + .fsetattr = trace_fsetattr, }; struct xlator_mops mops = { diff --git a/xlators/features/filter/src/filter.c b/xlators/features/filter/src/filter.c index c9cd8dbfa..673956557 100644 --- a/xlators/features/filter/src/filter.c +++ b/xlators/features/filter/src/filter.c @@ -262,25 +262,28 @@ filter_stat (call_frame_t *frame, } static int32_t -filter_chmod_cbk (call_frame_t *frame, - void *cookie, - xlator_t *this, - int32_t op_ret, - int32_t op_errno, - struct stat *buf) +filter_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) { if (op_ret >= 0) { - update_stat (buf, this->private); + update_stat (preop, this->private); + update_stat (postop, this->private); } - STACK_UNWIND (frame, op_ret, op_errno, buf); + STACK_UNWIND (frame, op_ret, op_errno, preop, postop); return 0; } int32_t -filter_chmod (call_frame_t *frame, - xlator_t *this, - loc_t *loc, - mode_t mode) +filter_setattr (call_frame_t *frame, + xlator_t *this, + loc_t *loc, + struct stat *stbuf, + int32_t valid) { int32_t ret = 0; ret = update_frame (frame, loc->inode, this->private); @@ -291,147 +294,65 @@ filter_chmod (call_frame_t *frame, case GF_FILTER_MAP_BOTH: if (loc->inode->st_mode & S_IWOTH) break; - gf_log (this->name, GF_LOG_DEBUG, "%s: returning permission denied", loc->path); - STACK_UNWIND (frame, -1, EPERM, NULL); + gf_log (this->name, GF_LOG_DEBUG, + "%s: returning permission denied", loc->path); + STACK_UNWIND (frame, -1, EPERM, NULL, NULL, NULL); return 0; - + case GF_FILTER_FILTER_UID: case GF_FILTER_FILTER_GID: case GF_FILTER_RO_FS: - STACK_UNWIND (frame, -1, EROFS, NULL); + STACK_UNWIND (frame, -1, EROFS, NULL, NULL); return 0; default: break; } STACK_WIND (frame, - filter_chmod_cbk, + filter_setattr_cbk, FIRST_CHILD(this), - FIRST_CHILD(this)->fops->chmod, + FIRST_CHILD(this)->fops->setattr, loc, - mode); + stbuf, valid); return 0; } - static int32_t -filter_fchmod_cbk (call_frame_t *frame, - void *cookie, - xlator_t *this, - int32_t op_ret, - int32_t op_errno, - struct stat *buf) +filter_fsetattr_cbk (call_frame_t *frame, + void *cookie, + xlator_t *this, + int32_t op_ret, + int32_t op_errno, + struct stat *preop, + struct stat *postop) { if (op_ret >= 0) { - update_stat (buf, this->private); + update_stat (preop, this->private); + update_stat (postop, this->private); } STACK_UNWIND (frame, op_ret, op_errno, - buf); + preop, postop); return 0; } -int32_t -filter_fchmod (call_frame_t *frame, - xlator_t *this, - fd_t *fd, - mode_t mode) +int32_t +filter_fsetattr (call_frame_t *frame, + xlator_t *this, + fd_t *fd, + struct stat *stbuf, + int32_t valid) { STACK_WIND (frame, - filter_fchmod_cbk, + filter_fsetattr_cbk, FIRST_CHILD(this), - FIRST_CHILD(this)->fops->fchmod, + FIRST_CHILD(this)->fops->fsetattr, fd, - mode); - return 0; -} - -static int32_t -filter_chown_cbk (call_frame_t *frame, - void *cookie, - xlator_t *this, - int32_t op_ret, - int32_t op_errno, - struct stat *buf) -{ - if (op_ret >= 0) { - update_stat (buf, this->private); - } - STACK_UNWIND (frame, op_ret, op_errno, buf); - return 0; -} - -int32_t -filter_chown (call_frame_t *frame, - xlator_t *this, - loc_t *loc, - uid_t uid, - gid_t gid) -{ - int32_t ret = 0; - ret = update_frame (frame, loc->inode, this->private); - switch (ret) { - case GF_FILTER_MAP_UID: - if (loc->inode->st_mode & S_IWGRP) - break; - case GF_FILTER_MAP_BOTH: - if (loc->inode->st_mode & S_IWOTH) - break; - gf_log (this->name, GF_LOG_DEBUG, "%s: returning permission denied", loc->path); - STACK_UNWIND (frame, -1, EPERM, NULL); - return 0; - - case GF_FILTER_FILTER_UID: - case GF_FILTER_FILTER_GID: - case GF_FILTER_RO_FS: - STACK_UNWIND (frame, -1, EROFS, NULL); - return 0; - default: - break; - } - - STACK_WIND (frame, - filter_chown_cbk, - FIRST_CHILD(this), - FIRST_CHILD(this)->fops->chown, - loc, - uid, - gid); + stbuf, valid); return 0; } -static int32_t -filter_fchown_cbk (call_frame_t *frame, - void *cookie, - xlator_t *this, - int32_t op_ret, - int32_t op_errno, - struct stat *buf) -{ - if (op_ret >= 0) { - update_stat (buf, this->private); - } - STACK_UNWIND (frame, op_ret, op_errno, buf); - return 0; -} - -int32_t -filter_fchown (call_frame_t *frame, - xlator_t *this, - fd_t *fd, - uid_t uid, - gid_t gid) -{ - STACK_WIND (frame, - filter_fchown_cbk, - FIRST_CHILD(this), - FIRST_CHILD(this)->fops->fchown, - fd, - uid, - gid); - return 0; -} static int32_t filter_truncate_cbk (call_frame_t *frame, @@ -513,56 +434,6 @@ filter_ftruncate (call_frame_t *frame, return 0; } -int32_t -filter_utimens_cbk (call_frame_t *frame, - void *cookie, - xlator_t *this, - int32_t op_ret, - int32_t op_errno, - struct stat *buf) -{ - if (op_ret >= 0) { - update_stat (buf, this->private); - } - STACK_UNWIND (frame, op_ret, op_errno, buf); - return 0; -} - - -int32_t -filter_utimens (call_frame_t *frame, - xlator_t *this, - loc_t *loc, - struct timespec tv[2]) -{ - int32_t ret = 0; - ret = update_frame (frame, loc->inode, this->private); - switch (ret) { - case GF_FILTER_MAP_UID: - if (loc->inode->st_mode & S_IWGRP) - break; - case GF_FILTER_MAP_BOTH: - if (loc->inode->st_mode & S_IWOTH) - break; - gf_log (this->name, GF_LOG_DEBUG, "%s: returning permission denied", loc->path); - STACK_UNWIND (frame, -1, EPERM, NULL); - return 0; - - case GF_FILTER_FILTER_UID: - case GF_FILTER_FILTER_GID: - case GF_FILTER_RO_FS: - STACK_UNWIND (frame, -1, EROFS, NULL); - return 0; - } - - STACK_WIND (frame, - filter_utimens_cbk, - FIRST_CHILD(this), - FIRST_CHILD(this)->fops->utimens, - loc, - tv); - return 0; -} static int32_t filter_readlink_cbk (call_frame_t *frame, @@ -1715,8 +1586,6 @@ struct xlator_fops fops = { .lookup = filter_lookup, .stat = filter_stat, .fstat = filter_fstat, - .chmod = filter_chmod, - .fchmod = filter_fchmod, .readlink = filter_readlink, .mknod = filter_mknod, .mkdir = filter_mkdir, @@ -1725,8 +1594,6 @@ struct xlator_fops fops = { .symlink = filter_symlink, .rename = filter_rename, .link = filter_link, - .chown = filter_chown, - .fchown = filter_fchown, .truncate = filter_truncate, .ftruncate = filter_ftruncate, .create = filter_create, @@ -1737,7 +1604,8 @@ struct xlator_fops fops = { .getxattr = filter_getxattr, .removexattr = filter_removexattr, .opendir = filter_opendir, - .utimens = filter_utimens, + .setattr = filter_setattr, + .fsetattr = filter_fsetattr, }; struct xlator_mops mops = { diff --git a/xlators/features/path-convertor/src/path.c b/xlators/features/path-convertor/src/path.c index 8badef38c..b53286104 100644 --- a/xlators/features/path-convertor/src/path.c +++ b/xlators/features/path-convertor/src/path.c @@ -618,65 +618,49 @@ path_link (call_frame_t *frame, } int32_t -path_chmod (call_frame_t *frame, - xlator_t *this, - loc_t *loc, - mode_t mode) +path_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) { - char *loc_path = (char *)loc->path; - char *tmp_path = NULL; - - if (!(tmp_path = path_this_to_that (this, loc->path))) { - STACK_UNWIND (frame, -1, ENOENT, NULL, NULL); - return 0; - } - loc->path = tmp_path; - - STACK_WIND (frame, - path_common_buf_cbk, - FIRST_CHILD(this), - FIRST_CHILD(this)->fops->chmod, - loc, - mode); - - loc->path = loc_path; - if (tmp_path != loc_path) - FREE (tmp_path); - + STACK_UNWIND (frame, op_ret, op_errno, preop, postop); return 0; } -int32_t -path_chown (call_frame_t *frame, - xlator_t *this, - loc_t *loc, - uid_t uid, - gid_t gid) +int32_t +path_setattr (call_frame_t *frame, + xlator_t *this, + loc_t *loc, + struct stat *stbuf, + int32_t valid) { char *loc_path = (char *)loc->path; char *tmp_path = NULL; - + if (!(tmp_path = path_this_to_that (this, loc->path))) { STACK_UNWIND (frame, -1, ENOENT, NULL, NULL); return 0; } loc->path = tmp_path; - STACK_WIND (frame, - path_common_buf_cbk, - FIRST_CHILD(this), - FIRST_CHILD(this)->fops->chown, - loc, - uid, - gid); + STACK_WIND (frame, + path_setattr_cbk, + FIRST_CHILD(this), + FIRST_CHILD(this)->fops->setattr, + loc, + stbuf, valid); - loc->path = loc_path; + loc->path = loc_path; if (tmp_path != loc_path) FREE (tmp_path); return 0; } + int32_t path_truncate (call_frame_t *frame, xlator_t *this, @@ -706,34 +690,6 @@ path_truncate (call_frame_t *frame, return 0; } -int32_t -path_utimens (call_frame_t *frame, - xlator_t *this, - loc_t *loc, - struct timespec tv[2]) -{ - char *loc_path = (char *)loc->path; - char *tmp_path = NULL; - - if (!(tmp_path = path_this_to_that (this, loc->path))) { - STACK_UNWIND (frame, -1, ENOENT, NULL, NULL); - return 0; - } - loc->path = tmp_path; - - STACK_WIND (frame, - path_common_buf_cbk, - FIRST_CHILD(this), - FIRST_CHILD(this)->fops->utimens, - loc, - tv); - - loc->path = loc_path; - if (tmp_path != loc_path) - FREE (tmp_path); - - return 0; -} int32_t path_open (call_frame_t *frame, @@ -1173,10 +1129,7 @@ struct xlator_fops fops = { .symlink = path_symlink, .rename = path_rename, .link = path_link, - .chmod = path_chmod, - .chown = path_chown, .truncate = path_truncate, - .utimens = path_utimens, .open = path_open, .setxattr = path_setxattr, .getxattr = path_getxattr, @@ -1189,6 +1142,7 @@ struct xlator_fops fops = { .xattrop = path_xattrop, .entrylk = path_entrylk, .inodelk = path_inodelk, + .setattr = path_setattr, }; diff --git a/xlators/mount/fuse/src/fuse-bridge.c b/xlators/mount/fuse/src/fuse-bridge.c index 107982947..b002d264c 100644 --- a/xlators/mount/fuse/src/fuse-bridge.c +++ b/xlators/mount/fuse/src/fuse-bridge.c @@ -159,6 +159,8 @@ typedef struct { dict_t *dict; char *name; char is_revalidate; + int32_t callcount; + gf_lock_t lock; } fuse_state_t; @@ -193,6 +195,67 @@ free_state (fuse_state_t *state) } +static int +__can_fuse_return (fuse_state_t *state, + char success) +{ + int ret = 0; + + if (success) { + if ((state->callcount == 0) + || (state->callcount == 1)) + ret = 1; + else + ret = 0; + } else { + if (state->callcount != -1) + ret = 1; + else + ret = 0; + } + + return ret; +} + + +static void +__fuse_mark_return (fuse_state_t *state, + char success) +{ + if (success) { + if (state->callcount == 2) + state->callcount--; + else + state->callcount = 0; + } else { + if (state->callcount == 2) + state->callcount = -1; + else + state->callcount = 0; + } + + return; +} + + +static int +can_fuse_return (fuse_state_t *state, + char success) +{ + int ret = 0; + + LOCK(&state->lock); + { + ret = __can_fuse_return (state, success); + + __fuse_mark_return (state, success); + } + UNLOCK(&state->lock); + + return ret; +} + + fuse_state_t * get_state (xlator_t *this, fuse_in_header_t *finh) { @@ -206,6 +269,8 @@ get_state (xlator_t *this, fuse_in_header_t *finh) state->finh = finh; state->this = this; + LOCK_INIT (&state->lock); + return state; } @@ -659,11 +724,15 @@ fuse_attr_cbk (call_frame_t *frame, void *cookie, xlator_t *this, state->loc.path ? state->loc.path : "ERR", strerror (op_errno)); - send_fuse_err (this, finh, op_errno); + if (can_fuse_return (state, 0)) + send_fuse_err (this, finh, op_errno); + } + + if (state->callcount == 0) { + free_state (state); + STACK_DESTROY (frame->root); } - free_state (state); - STACK_DESTROY (frame->root); return 0; } @@ -795,196 +864,170 @@ out: } -static void -do_chmod (xlator_t *this, fuse_in_header_t *finh, struct fuse_setattr_in *fsi) +static int +fuse_setattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, + struct stat *statpre, struct stat *statpost) { - fuse_state_t *state = NULL; - fd_t *fd = NULL; - int32_t ret = -1; + fuse_state_t *state; + fuse_in_header_t *finh; + fuse_private_t *priv = NULL; + struct fuse_attr_out fao; - GET_STATE (this, finh, state); - if (fsi->valid & FATTR_FH) { - fd = FH_TO_FD (fsi->fh); - state->fd = fd; - } + priv = this->private; + state = frame->root->state; + finh = state->finh; - if (fd) { + if (op_ret == 0) { gf_log ("glusterfs-fuse", GF_LOG_TRACE, - "%"PRIu64": FCHMOD %p", finh->unique, fd); + "%"PRIu64": %s() %s => %"PRId64, frame->root->unique, + gf_fop_list[frame->root->op], + state->loc.path ? state->loc.path : "ERR", + statpost->st_ino); - FUSE_FOP (state, fuse_attr_cbk, GF_FOP_FCHMOD, - fchmod, fd, fsi->mode); - } else { - ret = fuse_loc_fill (&state->loc, state, finh->nodeid, 0, NULL); + /* TODO: make these timeouts configurable via meta */ + /* TODO: what if the inode number has changed by now */ - if ((state->loc.inode == NULL) || - (ret < 0)) { - gf_log ("glusterfs-fuse", GF_LOG_WARNING, - "%"PRIu64": CHMOD %"PRIu64" (%s) (fuse_loc_fill() failed)", - finh->unique, finh->nodeid, - state->loc.path); - send_fuse_err (this, finh, ENOENT); - free_state (state); - return; - } + statpost->st_blksize = this->ctx->page_size; + stat2attr (statpost, &fao.attr); - gf_log ("glusterfs-fuse", GF_LOG_TRACE, - "%"PRIu64": CHMOD %s", finh->unique, - state->loc.path); + fao.attr_valid = calc_timeout_sec (priv->attribute_timeout); + fao.attr_valid_nsec = + calc_timeout_nsec (priv->attribute_timeout); + + if (can_fuse_return (state, 1)) { + priv->proto_minor >= 9 ? + send_fuse_obj (this, finh, &fao) : + send_fuse_data (this, finh, &fao, + FUSE_COMPAT_ATTR_OUT_SIZE); + } + } else { + gf_log ("glusterfs-fuse", GF_LOG_WARNING, + "%"PRIu64": %s() %s => -1 (%s)", frame->root->unique, + gf_fop_list[frame->root->op], + state->loc.path ? state->loc.path : "ERR", + strerror (op_errno)); - FUSE_FOP (state, fuse_attr_cbk, GF_FOP_CHMOD, - chmod, &state->loc, fsi->mode); + if (can_fuse_return (state, 0)) + send_fuse_err (this, finh, op_errno); + } + + if (state->callcount == 0) { + free_state (state); + STACK_DESTROY (frame->root); } + + return 0; } static void -do_chown (xlator_t *this, fuse_in_header_t *finh, struct fuse_setattr_in *fsi) +fuse_do_truncate (fuse_state_t *state, struct fuse_setattr_in *fsi) { - fuse_state_t *state = NULL; - fd_t *fd = NULL; - int32_t ret = -1; - uid_t uid = 0; - gid_t gid = 0; - - uid = (fsi->valid & FATTR_UID) ? fsi->uid : (uid_t) -1; - gid = (fsi->valid & FATTR_GID) ? fsi->gid : (gid_t) -1; - GET_STATE (this, finh, state); - - if (fsi->valid & FATTR_FH) { - fd = FH_TO_FD (fsi->fh); - state->fd = fd; - } - - if (fd) { - gf_log ("glusterfs-fuse", GF_LOG_TRACE, - "%"PRIu64": FCHOWN %p", finh->unique, fd); - - FUSE_FOP (state, fuse_attr_cbk, GF_FOP_FCHOWN, - fchown, fd, uid, gid); + if (state->fd) { + FUSE_FOP (state, fuse_attr_cbk, GF_FOP_FTRUNCATE, + ftruncate, state->fd, fsi->size); } else { - ret = fuse_loc_fill (&state->loc, state, finh->nodeid, 0, NULL); - if ((state->loc.inode == NULL) || - (ret < 0)) { - gf_log ("glusterfs-fuse", GF_LOG_WARNING, - "%"PRIu64": CHOWN %"PRIu64" (%s) (fuse_loc_fill() failed)", - finh->unique, finh->nodeid, - state->loc.path); - send_fuse_err (this, finh, ENOENT); - free_state (state); - return; - } - - gf_log ("glusterfs-fuse", GF_LOG_TRACE, - "%"PRIu64": CHOWN %s", finh->unique, - state->loc.path); - - FUSE_FOP (state, fuse_attr_cbk, GF_FOP_CHOWN, - chown, &state->loc, uid, gid); + FUSE_FOP (state, fuse_attr_cbk, GF_FOP_TRUNCATE, + truncate, &state->loc, fsi->size); } + + return; } -static void -do_truncate (xlator_t *this, fuse_in_header_t *finh, struct fuse_setattr_in *fsi) +static int32_t +fattr_to_gf_set_attr (int32_t valid) { - fuse_state_t *state = NULL; - fd_t *fd = NULL; - int32_t ret = -1; + int32_t gf_valid = 0; - GET_STATE (this, finh, state); - - if (fsi->valid & FATTR_FH) { - fd = FH_TO_FD (fsi->fh); - state->fd = fd; - } + if (valid & FATTR_UID) + gf_valid |= GF_SET_ATTR_UID; - if (fd) { - gf_log ("glusterfs-fuse", GF_LOG_TRACE, - "%"PRIu64": FTRUNCATE %p/%"PRId64, finh->unique, - fd, fsi->size); + if (valid & FATTR_GID) + gf_valid |= GF_SET_ATTR_GID; - FUSE_FOP (state, fuse_attr_cbk, GF_FOP_FTRUNCATE, - ftruncate, fd, fsi->size); - } else { - ret = fuse_loc_fill (&state->loc, state, finh->nodeid, 0, NULL); - if ((state->loc.inode == NULL) || - (ret < 0)) { - gf_log ("glusterfs-fuse", GF_LOG_WARNING, - "%"PRIu64": TRUNCATE %s/%"PRId64" (fuse_loc_fill() failed)", - finh->unique, state->loc.path, - fsi->size); - send_fuse_err (this, finh, ENOENT); - free_state (state); - return; - } + if (valid & FATTR_ATIME) + gf_valid |= GF_SET_ATTR_ATIME; - gf_log ("glusterfs-fuse", GF_LOG_TRACE, - "%"PRIu64": TRUNCATE %s/%"PRId64"(%"PRIu64")", - finh->unique, - state->loc.path, fsi->size, finh->nodeid); + if (valid & FATTR_MTIME) + gf_valid |= GF_SET_ATTR_MTIME; - FUSE_FOP (state, fuse_attr_cbk, GF_FOP_TRUNCATE, - truncate, &state->loc, fsi->size); - } + if (valid & FATTR_SIZE) + gf_valid |= GF_SET_ATTR_SIZE; - return; + return gf_valid; } +#define FATTR_MASK (FATTR_SIZE \ + | FATTR_UID | FATTR_GID \ + | FATTR_ATIME | FATTR_MTIME \ + | FATTR_MODE) + + static void -do_utimes (xlator_t *this, fuse_in_header_t *finh, struct fuse_setattr_in *fsi) +fuse_setattr (xlator_t *this, fuse_in_header_t *finh, void *msg) { - fuse_state_t *state = NULL; - struct timespec tv[2]; - int32_t ret = -1; + struct fuse_setattr_in *fsi = msg; - tv[0].tv_sec = fsi->atime; - tv[0].tv_nsec = fsi->atimensec; - tv[1].tv_sec = fsi->mtime; - tv[1].tv_nsec = fsi->mtimensec; + struct stat attr; + + fuse_state_t *state = NULL; + int32_t ret = -1; GET_STATE (this, finh, state); + ret = fuse_loc_fill (&state->loc, state, finh->nodeid, 0, NULL); + if ((state->loc.inode == NULL) || (ret < 0)) { + gf_log ("glusterfs-fuse", GF_LOG_WARNING, - "%"PRIu64": UTIMENS %s (fuse_loc_fill() failed)", + "%"PRIu64": SETATTR %s (fuse_loc_fill() failed)", finh->unique, state->loc.path); + send_fuse_err (this, finh, ENOENT); free_state (state); + return; } gf_log ("glusterfs-fuse", GF_LOG_TRACE, - "%"PRIu64": UTIMENS (%"PRIu64")%s", finh->unique, + "%"PRIu64": SETATTR (%"PRIu64")%s", finh->unique, finh->nodeid, state->loc.path); - FUSE_FOP (state, fuse_attr_cbk, GF_FOP_UTIMENS, - utimens, &state->loc, tv); -} + if ((fsi->valid & FATTR_SIZE) + && ((fsi->valid & (FATTR_MASK)) != FATTR_SIZE)) { + state->callcount = 2; + } + state->fd = fd_lookup (state->loc.inode, finh->pid); -static void -fuse_setattr (xlator_t *this, fuse_in_header_t *finh, void *msg) -{ - struct fuse_setattr_in *fsi = msg; + if (fsi->valid & FATTR_SIZE) { + fuse_do_truncate (state, fsi); + } - if (fsi->valid & FATTR_MODE) - do_chmod (this, finh, fsi); - else if (fsi->valid & (FATTR_UID | FATTR_GID)) - do_chown (this, finh, fsi); - else if (fsi->valid & FATTR_SIZE) - do_truncate (this, finh, fsi); - else if (fsi->valid & (FATTR_ATIME | FATTR_MTIME)) - do_utimes (this, finh, fsi); - else - /* As of now, getattr uses only the header. - * If it happens to change, we'll have to - * do some refactoring... - */ - fuse_getattr (this, finh, NULL); + if ((fsi->valid & (FATTR_MASK)) != FATTR_SIZE) { + attr.st_size = fsi->size; + attr.st_atime = fsi->atime; + attr.st_mtime = fsi->mtime; + + attr.st_mode = fsi->mode; + attr.st_uid = fsi->uid; + attr.st_gid = fsi->gid; + + if (state->fd) { + FUSE_FOP (state, fuse_setattr_cbk, GF_FOP_FSETATTR, + fsetattr, state->fd, &attr, + fattr_to_gf_set_attr (fsi->valid)); + } else { + FUSE_FOP (state, fuse_setattr_cbk, GF_FOP_SETATTR, + setattr, &state->loc, &attr, + fattr_to_gf_set_attr (fsi->valid)); + } + } } diff --git a/xlators/performance/io-cache/src/io-cache.c b/xlators/performance/io-cache/src/io-cache.c index 49a1ce823..db1e204fd 100644 --- a/xlators/performance/io-cache/src/io-cache.c +++ b/xlators/performance/io-cache/src/io-cache.c @@ -132,48 +132,32 @@ ioc_inode_flush (ioc_inode_t *ioc_inode) return; } -/* - * ioc_utimens_cbk - - * - * @frame: - * @cookie: - * @this: - * @op_ret: - * @op_errno: - * @stbuf: - * - */ int32_t -ioc_utimens_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, struct stat *stbuf) +ioc_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) { - STACK_UNWIND (frame, op_ret, op_errno, stbuf); - return 0; + STACK_UNWIND (frame, op_ret, op_errno, preop, postop); + return 0; } -/* - * ioc_utimens - - * - * @frame: - * @this: - * @loc: - * @tv: - * - */ int32_t -ioc_utimens (call_frame_t *frame, xlator_t *this, loc_t *loc, - struct timespec *tv) +ioc_setattr (call_frame_t *frame, xlator_t *this, loc_t *loc, + struct stat *stbuf, int32_t valid) { - uint64_t ioc_inode = 0; - inode_ctx_get (loc->inode, this, &ioc_inode); + uint64_t ioc_inode = 0; - if (ioc_inode) - ioc_inode_flush ((ioc_inode_t *)(long)ioc_inode); + inode_ctx_get (loc->inode, this, &ioc_inode); - STACK_WIND (frame, ioc_utimens_cbk, FIRST_CHILD (this), - FIRST_CHILD (this)->fops->utimens, loc, tv); + if (ioc_inode + && ((valid & GF_SET_ATTR_ATIME) + || (valid & GF_SET_ATTR_MTIME))) + ioc_inode_flush ((ioc_inode_t *)(long)ioc_inode); - return 0; + STACK_WIND (frame, ioc_setattr_cbk, FIRST_CHILD (this), + FIRST_CHILD (this)->fops->setattr, loc, stbuf, valid); + + return 0; } int32_t @@ -1563,9 +1547,9 @@ struct xlator_fops fops = { .writev = ioc_writev, .truncate = ioc_truncate, .ftruncate = ioc_ftruncate, - .utimens = ioc_utimens, .lookup = ioc_lookup, - .lk = ioc_lk + .lk = ioc_lk, + .setattr = ioc_setattr }; struct xlator_mops mops = { diff --git a/xlators/performance/io-threads/src/io-threads.c b/xlators/performance/io-threads/src/io-threads.c index 118ae4242..dc4b55616 100644 --- a/xlators/performance/io-threads/src/io-threads.c +++ b/xlators/performance/io-threads/src/io-threads.c @@ -365,199 +365,89 @@ out: int -iot_chmod_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, struct stat *buf) +iot_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) { - STACK_UNWIND (frame, op_ret, op_errno, buf); + STACK_UNWIND (frame, op_ret, op_errno, preop, postop); return 0; } int -iot_chmod_wrapper (call_frame_t *frame, xlator_t *this, loc_t *loc, - mode_t mode) +iot_setattr_wrapper (call_frame_t *frame, xlator_t *this, loc_t *loc, + struct stat *stbuf, int32_t valid) { - STACK_WIND (frame, iot_chmod_cbk, + STACK_WIND (frame, iot_setattr_cbk, FIRST_CHILD (this), - FIRST_CHILD (this)->fops->chmod, - loc, mode); + FIRST_CHILD (this)->fops->setattr, + loc, stbuf, valid); return 0; } int -iot_chmod (call_frame_t *frame, xlator_t *this, loc_t *loc, mode_t mode) +iot_setattr (call_frame_t *frame, xlator_t *this, loc_t *loc, + struct stat *stbuf, int32_t valid) { call_stub_t *stub = NULL; - fd_t *fd = NULL; int ret = -1; - stub = fop_chmod_stub (frame, iot_chmod_wrapper, loc, mode); + stub = fop_setattr_stub (frame, iot_setattr_wrapper, loc, stbuf, valid); if (!stub) { - gf_log (this->name, GF_LOG_ERROR, "cannot create chmod stub" - "(out of memory)"); + gf_log (this->name, GF_LOG_ERROR, "Cannot create setattr stub" + "(Out of memory)"); ret = -ENOMEM; goto out; } - fd = fd_lookup (loc->inode, frame->root->pid); - if (fd == NULL) - ret = iot_schedule_unordered ((iot_conf_t *)this->private, - loc->inode, stub); - else { - ret = iot_schedule_ordered ((iot_conf_t *)this->private, - loc->inode, stub); - fd_unref (fd); - } - -out: - if (ret < 0) { - if (stub != NULL) { - call_stub_destroy (stub); - } - - STACK_UNWIND (frame, -1, -ret, NULL); - } - - return 0; -} - - -int -iot_fchmod_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, struct stat *buf) -{ - STACK_UNWIND (frame, op_ret, op_errno, buf); - return 0; -} - - -int -iot_fchmod_wrapper (call_frame_t *frame, xlator_t *this, - fd_t *fd, mode_t mode) -{ - STACK_WIND (frame, iot_fchmod_cbk, FIRST_CHILD (this), - FIRST_CHILD (this)->fops->fchmod, fd, mode); - return 0; -} - - -int -iot_fchmod (call_frame_t *frame, xlator_t *this, fd_t *fd, mode_t mode) -{ - call_stub_t *stub = NULL; - int ret = -1; - - stub = fop_fchmod_stub (frame, iot_fchmod_wrapper, fd, mode); - if (!stub) { - gf_log (this->name, GF_LOG_ERROR, "cannot create fchmod stub" - "(out of memory)"); - ret = -ENOMEM; - goto out; - } - - ret = iot_schedule_ordered ((iot_conf_t *)this->private, fd->inode, - stub); + ret = iot_schedule_unordered ((iot_conf_t *)this->private, + loc->inode, stub); out: if (ret < 0) { - STACK_UNWIND (frame, -1, -ret, NULL); - if (stub != NULL) { call_stub_destroy (stub); } - } - return 0; -} - - -int -iot_chown_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, struct stat *buf) -{ - STACK_UNWIND (frame, op_ret, op_errno, buf); - return 0; -} - - -int -iot_chown_wrapper (call_frame_t *frame, xlator_t *this, loc_t *loc, uid_t uid, - gid_t gid) -{ - STACK_WIND (frame, iot_chown_cbk, - FIRST_CHILD (this), - FIRST_CHILD (this)->fops->chown, - loc, uid, gid); - return 0; -} - - -int -iot_chown (call_frame_t *frame, xlator_t *this, loc_t *loc, uid_t uid, - gid_t gid) -{ - call_stub_t *stub = NULL; - fd_t *fd = NULL; - int ret = -1; - - stub = fop_chown_stub (frame, iot_chown_wrapper, loc, uid, gid); - if (!stub) { - gf_log (this->name, GF_LOG_ERROR, "cannot create chown stub" - "(out of memory)"); - ret = -ENOMEM; - goto out; - } - fd = fd_lookup (loc->inode, frame->root->pid); - if (fd == NULL) - ret = iot_schedule_unordered ((iot_conf_t *)this->private, - loc->inode, stub); - else { - ret = iot_schedule_ordered ((iot_conf_t *)this->private, - loc->inode, stub); - fd_unref (fd); + STACK_UNWIND (frame, -1, -ret, NULL, NULL); } -out: - if (ret < 0) { - STACK_UNWIND (frame, -1, -ret, NULL); - - if (stub != NULL) { - call_stub_destroy (stub); - } - } return 0; } int -iot_fchown_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, struct stat *buf) +iot_fsetattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, + struct stat *preop, struct stat *postop) { - STACK_UNWIND (frame, op_ret, op_errno, buf); + STACK_UNWIND (frame, op_ret, op_errno, preop, postop); return 0; } int -iot_fchown_wrapper (call_frame_t *frame, xlator_t *this, - fd_t *fd, uid_t uid, gid_t gid) +iot_fsetattr_wrapper (call_frame_t *frame, xlator_t *this, + fd_t *fd, struct stat *stbuf, int32_t valid) { - STACK_WIND (frame, iot_fchown_cbk, FIRST_CHILD (this), - FIRST_CHILD (this)->fops->fchown, fd, uid, gid); + STACK_WIND (frame, iot_fsetattr_cbk, FIRST_CHILD (this), + FIRST_CHILD (this)->fops->fsetattr, fd, stbuf, valid); return 0; } int -iot_fchown (call_frame_t *frame, xlator_t *this, fd_t *fd, uid_t uid, gid_t gid) +iot_fsetattr (call_frame_t *frame, xlator_t *this, fd_t *fd, + struct stat *stbuf, int32_t valid) { call_stub_t *stub = NULL; int ret = -1; - stub = fop_fchown_stub (frame, iot_fchown_wrapper, fd, uid, gid); + stub = fop_fsetattr_stub (frame, iot_fsetattr_wrapper, fd, stbuf, + valid); if (!stub) { - gf_log (this->name, GF_LOG_ERROR, "cannot create fchown stub" + gf_log (this->name, GF_LOG_ERROR, "cannot create fsetattr stub" "(out of memory)"); ret = -ENOMEM; goto out; @@ -568,7 +458,7 @@ iot_fchown (call_frame_t *frame, xlator_t *this, fd_t *fd, uid_t uid, gid_t gid) out: if (ret < 0) { - STACK_UNWIND (frame, -1, -ret, NULL); + STACK_UNWIND (frame, -1, -ret, NULL, NULL); if (stub != NULL) { call_stub_destroy (stub); } @@ -1507,67 +1397,6 @@ out: int -iot_utimens_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, - struct stat *buf) -{ - STACK_UNWIND (frame, op_ret, op_errno, buf); - return 0; -} - - -int -iot_utimens_wrapper (call_frame_t *frame, xlator_t *this, - loc_t *loc, struct timespec tv[2]) -{ - STACK_WIND (frame, iot_utimens_cbk, - FIRST_CHILD(this), - FIRST_CHILD(this)->fops->utimens, - loc, tv); - return 0; -} - - -int -iot_utimens (call_frame_t *frame, xlator_t *this, loc_t *loc, - struct timespec tv[2]) -{ - call_stub_t *stub; - fd_t *fd = NULL; - int ret = -1; - - stub = fop_utimens_stub (frame, iot_utimens_wrapper, loc, tv); - if (!stub) { - gf_log (this->name, GF_LOG_ERROR, - "cannot create fop_utimens call stub" - "(out of memory)"); - ret = -ENOMEM; - goto out; - } - - fd = fd_lookup (loc->inode, frame->root->pid); - if (fd == NULL) - ret = iot_schedule_unordered ((iot_conf_t *)this->private, - loc->inode, stub); - else { - ret = iot_schedule_ordered ((iot_conf_t *)this->private, - loc->inode, stub); - fd_unref (fd); - } - -out: - if (ret < 0) { - STACK_UNWIND (frame, -1, -ret, NULL); - - if (stub != NULL) { - call_stub_destroy (stub); - } - } - return 0; -} - - -int iot_checksum_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno, uint8_t *file_checksum, uint8_t *dir_checksum) @@ -2975,14 +2804,11 @@ struct xlator_fops fops = { .fstat = iot_fstat, /* O */ .truncate = iot_truncate, /* V */ .ftruncate = iot_ftruncate, /* O */ - .utimens = iot_utimens, /* V */ .checksum = iot_checksum, /* U */ .unlink = iot_unlink, /* U */ .lookup = iot_lookup, /* U */ - .chmod = iot_chmod, /* V */ - .fchmod = iot_fchmod, /* O */ - .chown = iot_chown, /* V */ - .fchown = iot_fchown, /* O */ + .setattr = iot_setattr, /* U */ + .fsetattr = iot_fsetattr, /* O */ .access = iot_access, /* U */ .readlink = iot_readlink, /* U */ .mknod = iot_mknod, /* U */ diff --git a/xlators/performance/quick-read/src/quick-read.c b/xlators/performance/quick-read/src/quick-read.c index c7d282aff..1249da87b 100644 --- a/xlators/performance/quick-read/src/quick-read.c +++ b/xlators/performance/quick-read/src/quick-read.c @@ -1183,124 +1183,36 @@ out: } -static int32_t -qr_fchown_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, struct stat *buf) -{ - STACK_UNWIND (frame, op_ret, op_errno, buf); - return 0; -} - - -int32_t -qr_fchown_helper (call_frame_t *frame, xlator_t *this, fd_t *fd, uid_t uid, - gid_t gid) -{ - STACK_WIND (frame, qr_fchown_cbk, FIRST_CHILD (this), - FIRST_CHILD (this)->fops->fchown, fd, uid, gid); - return 0; -} - - -int32_t -qr_fchown (call_frame_t *frame, xlator_t *this, fd_t *fd, uid_t uid, gid_t gid) -{ - uint64_t value = 0; - int flags = 0; - call_stub_t *stub = NULL; - char *path = NULL; - loc_t loc = {0, }; - qr_fd_ctx_t *qr_fd_ctx = NULL; - int32_t ret = -1, op_ret = -1, op_errno = -1; - char need_open = 0, can_wind = 0, need_unwind = 0; - - ret = fd_ctx_get (fd, this, &value); - if (ret == 0) { - qr_fd_ctx = (qr_fd_ctx_t *)(long) value; - } - - if (qr_fd_ctx) { - LOCK (&qr_fd_ctx->lock); - { - path = qr_fd_ctx->path; - flags = qr_fd_ctx->flags; - - if (!(qr_fd_ctx->opened - || qr_fd_ctx->open_in_transit)) { - need_open = 1; - qr_fd_ctx->open_in_transit = 1; - } - - if (qr_fd_ctx->opened) { - can_wind = 1; - } else { - stub = fop_fchown_stub (frame, qr_fchown_helper, - fd, uid, gid); - if (stub == NULL) { - op_ret = -1; - op_errno = ENOMEM; - need_unwind = 1; - qr_fd_ctx->open_in_transit = 0; - goto unlock; - } - - list_add_tail (&stub->list, - &qr_fd_ctx->waiting_ops); - } - } - unlock: - UNLOCK (&qr_fd_ctx->lock); - } else { - can_wind = 1; - } - -out: - if (need_unwind) { - STACK_UNWIND (frame, op_ret, op_errno, NULL); - } else if (can_wind) { - STACK_WIND (frame, qr_fchown_cbk, FIRST_CHILD (this), - FIRST_CHILD (this)->fops->fchown, fd, uid, gid); - } else if (need_open) { - op_ret = qr_loc_fill (&loc, fd->inode, path); - if (op_ret == -1) { - qr_resume_pending_ops (qr_fd_ctx); - goto out; - } - - STACK_WIND (frame, qr_open_cbk, FIRST_CHILD(this), - FIRST_CHILD(this)->fops->open, &loc, flags, fd); - - qr_loc_wipe (&loc); - } - - return 0; -} int32_t -qr_fchmod_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, struct stat *buf) +qr_fsetattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, + struct stat *preop, struct stat *postop) { - STACK_UNWIND (frame, op_ret, op_errno, buf); + STACK_UNWIND (frame, op_ret, op_errno, preop, postop); return 0; } int32_t -qr_fchmod_helper (call_frame_t *frame, xlator_t *this, fd_t *fd, mode_t mode) +qr_fsetattr_helper (call_frame_t *frame, xlator_t *this, fd_t *fd, + struct stat *stbuf, int32_t valid) { - STACK_WIND(frame, qr_fchmod_cbk, FIRST_CHILD(this), - FIRST_CHILD(this)->fops->fchmod, fd, mode); + STACK_WIND(frame, qr_fsetattr_cbk, FIRST_CHILD(this), + FIRST_CHILD(this)->fops->fsetattr, fd, stbuf, + valid); return 0; } int32_t -qr_fchmod (call_frame_t *frame, xlator_t *this, fd_t *fd, mode_t mode) +qr_fsetattr (call_frame_t *frame, xlator_t *this, fd_t *fd, + struct stat *stbuf, int32_t valid) { uint64_t value = 0; int flags = 0; - call_stub_t *stub = NULL; + call_stub_t *stub = NULL; char *path = NULL; loc_t loc = {0, }; qr_fd_ctx_t *qr_fd_ctx = NULL; @@ -1326,8 +1238,9 @@ qr_fchmod (call_frame_t *frame, xlator_t *this, fd_t *fd, mode_t mode) if (qr_fd_ctx->opened) { can_wind = 1; } else { - stub = fop_fchmod_stub (frame, qr_fchmod_helper, - fd, mode); + stub = fop_fsetattr_stub (frame, + qr_fsetattr_helper, + fd, stbuf, valid); if (stub == NULL) { op_ret = -1; op_errno = ENOMEM; @@ -1348,10 +1261,11 @@ qr_fchmod (call_frame_t *frame, xlator_t *this, fd_t *fd, mode_t mode) out: if (need_unwind) { - STACK_UNWIND (frame, op_ret, op_errno, NULL); + STACK_UNWIND (frame, op_ret, op_errno, NULL, NULL); } else if (can_wind) { - STACK_WIND (frame, qr_fchmod_cbk, FIRST_CHILD (this), - FIRST_CHILD (this)->fops->fchmod, fd, mode); + STACK_WIND (frame, qr_fsetattr_cbk, FIRST_CHILD (this), + FIRST_CHILD (this)->fops->fsetattr, fd, stbuf, + valid); } else if (need_open) { op_ret = qr_loc_fill (&loc, fd->inode, path); if (op_ret == -1) { @@ -2292,8 +2206,6 @@ struct xlator_fops fops = { .readv = qr_readv, .writev = qr_writev, .fstat = qr_fstat, - .fchown = qr_fchown, - .fchmod = qr_fchmod, .fsetxattr = qr_fsetxattr, .fgetxattr = qr_fgetxattr, .flush = qr_flush, @@ -2302,6 +2214,7 @@ struct xlator_fops fops = { .fsync = qr_fsync, .ftruncate = qr_ftruncate, .lk = qr_lk, + .fsetattr = qr_fsetattr, }; diff --git a/xlators/performance/read-ahead/src/read-ahead.c b/xlators/performance/read-ahead/src/read-ahead.c index 49cf0b9bf..6d1c5a2bc 100644 --- a/xlators/performance/read-ahead/src/read-ahead.c +++ b/xlators/performance/read-ahead/src/read-ahead.c @@ -725,39 +725,6 @@ ra_fstat (call_frame_t *frame, xlator_t *this, fd_t *fd) int -ra_fchown (call_frame_t *frame, xlator_t *this, fd_t *fd, uid_t uid, gid_t gid) -{ - ra_file_t *file = NULL; - fd_t *iter_fd = NULL; - inode_t *inode = NULL; - int ret = 0; - uint64_t tmp_file = 0; - - inode = fd->inode; - - LOCK (&inode->lock); - { - list_for_each_entry (iter_fd, &inode->fd_list, inode_list) { - ret = fd_ctx_get (iter_fd, this, &tmp_file); - file = (ra_file_t *)(long)tmp_file; - - if (!file) - continue; - flush_region (frame, file, 0, - file->pages.prev->offset + 1); - } - } - UNLOCK (&inode->lock); - - STACK_WIND (frame, ra_attr_cbk, - FIRST_CHILD (this), - FIRST_CHILD (this)->fops->fchown, - fd, uid, gid); - return 0; -} - - -int ra_ftruncate (call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset) { ra_file_t *file = NULL; @@ -892,7 +859,6 @@ struct xlator_fops fops = { .truncate = ra_truncate, .ftruncate = ra_ftruncate, .fstat = ra_fstat, - .fchown = ra_fchown, }; struct xlator_mops mops = { diff --git a/xlators/performance/stat-prefetch/src/stat-prefetch.c b/xlators/performance/stat-prefetch/src/stat-prefetch.c index 57bed9a52..67a61fc47 100644 --- a/xlators/performance/stat-prefetch/src/stat-prefetch.c +++ b/xlators/performance/stat-prefetch/src/stat-prefetch.c @@ -681,30 +681,6 @@ sp_stbuf_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t -sp_chmod (call_frame_t *frame, xlator_t *this, loc_t *loc, mode_t mode) -{ - sp_cache_t *cache = NULL; - - GF_VALIDATE_OR_GOTO (this->name, loc, unwind); - GF_VALIDATE_OR_GOTO (this->name, loc->parent, unwind); - GF_VALIDATE_OR_GOTO (this->name, loc->name, unwind); - - cache = sp_get_cache_inode (this, loc->parent, frame->root->pid); - if (cache) { - sp_cache_remove_entry (cache, (char *)loc->name, 0); - } - - STACK_WIND (frame, sp_stbuf_cbk, FIRST_CHILD(this), - FIRST_CHILD(this)->fops->chmod, loc, mode); - return 0; - -unwind: - SP_STACK_UNWIND (frame, -1, errno, NULL); - return 0; -} - - -int32_t sp_fd_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno, fd_t *fd) { @@ -983,100 +959,6 @@ unwind: int32_t -sp_fchmod (call_frame_t *frame, xlator_t *this, fd_t *fd, mode_t mode) -{ - sp_fd_ctx_t *fd_ctx = NULL; - sp_cache_t *cache = NULL; - uint64_t value = 0; - int32_t ret = 0; - inode_t *parent = NULL; - char *name = NULL; - - ret = fd_ctx_get (fd, this, &value); - if (ret == -1) { - errno = EINVAL; - goto unwind; - } - - fd_ctx = (void *)(long)value; - name = fd_ctx->name; - parent = fd_ctx->parent_inode; - - cache = sp_get_cache_inode (this, parent, frame->root->pid); - if (cache) { - sp_cache_remove_entry (cache, name, 0); - } - - STACK_WIND (frame, sp_stbuf_cbk, FIRST_CHILD(this), - FIRST_CHILD(this)->fops->fchmod, fd, mode); - return 0; - -unwind: - SP_STACK_UNWIND (frame, -1, errno, NULL); - return 0; -} - - -int32_t -sp_chown (call_frame_t *frame, xlator_t *this, loc_t *loc, uid_t uid, gid_t gid) -{ - sp_cache_t *cache = NULL; - - GF_VALIDATE_OR_GOTO (this->name, loc, unwind); - GF_VALIDATE_OR_GOTO (this->name, loc->parent, unwind); - GF_VALIDATE_OR_GOTO (this->name, loc->name, unwind); - - cache = sp_get_cache_inode (this, loc->parent, frame->root->pid); - if (cache) { - sp_cache_remove_entry (cache, (char *)loc->name, 0); - } - - STACK_WIND (frame, sp_stbuf_cbk, FIRST_CHILD(this), - FIRST_CHILD(this)->fops->chown, loc, uid, gid); - return 0; - -unwind: - SP_STACK_UNWIND (frame, -1, errno, NULL); - return 0; -} - - -int32_t -sp_fchown (call_frame_t *frame, xlator_t *this, fd_t *fd, uid_t uid, gid_t gid) -{ - sp_fd_ctx_t *fd_ctx = NULL; - sp_cache_t *cache = NULL; - uint64_t value = 0; - int32_t ret = 0; - inode_t *parent = NULL; - char *name = NULL; - - ret = fd_ctx_get (fd, this, &value); - if (ret == -1) { - errno = EINVAL; - goto unwind; - } - - fd_ctx = (void *)(long)value; - name = fd_ctx->name; - parent = fd_ctx->parent_inode; - - cache = sp_get_cache_inode (this, parent, frame->root->pid); - if (cache) { - sp_cache_remove_entry (cache, name, 0); - } - - STACK_WIND (frame, sp_stbuf_cbk, FIRST_CHILD(this), - FIRST_CHILD(this)->fops->fchown, fd, uid, gid); - return 0; - -unwind: - SP_STACK_UNWIND (frame, -1, errno, NULL); - return 0; -} - - -int32_t sp_truncate (call_frame_t *frame, xlator_t *this, loc_t *loc, off_t offset) { sp_cache_t *cache = NULL; @@ -1136,8 +1018,18 @@ unwind: int32_t -sp_utimens (call_frame_t *frame, xlator_t *this, loc_t *loc, - struct timespec tv[2]) +sp_setattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, + struct stat *prestat, struct stat *poststat) +{ + SP_STACK_UNWIND (frame, op_ret, op_errno, poststat); + return 0; +} + + +int +sp_setattr (call_frame_t *frame, xlator_t *this, + loc_t *loc, struct stat *buf, int32_t valid) { sp_cache_t *cache = NULL; @@ -1150,8 +1042,8 @@ sp_utimens (call_frame_t *frame, xlator_t *this, loc_t *loc, sp_cache_remove_entry (cache, (char *)loc->name, 0); } - STACK_WIND (frame, sp_stbuf_cbk, FIRST_CHILD(this), - FIRST_CHILD(this)->fops->utimens, loc, tv); + STACK_WIND (frame, sp_setattr_cbk, FIRST_CHILD(this), + FIRST_CHILD(this)->fops->setattr, loc, buf, valid); return 0; unwind: @@ -1798,7 +1690,6 @@ fini (xlator_t *this) struct xlator_fops fops = { .lookup = sp_lookup, .readdir = sp_readdir, - .chmod = sp_chmod, .open = sp_open, .create = sp_create, .opendir = sp_opendir, @@ -1806,12 +1697,8 @@ struct xlator_fops fops = { .mknod = sp_mknod, .symlink = sp_symlink, .link = sp_link, - .fchmod = sp_fchmod, - .chown = sp_chown, - .fchown = sp_fchown, .truncate = sp_truncate, .ftruncate = sp_ftruncate, - .utimens = sp_utimens, .readlink = sp_readlink, .unlink = sp_unlink, .rmdir = sp_rmdir, @@ -1826,6 +1713,7 @@ struct xlator_fops fops = { .checksum = sp_checksum, .xattrop = sp_xattrop, .fxattrop = sp_fxattrop, + .setattr = sp_setattr, }; struct xlator_mops mops = { diff --git a/xlators/protocol/client/src/client-protocol.c b/xlators/protocol/client/src/client-protocol.c index a09e1ad34..43f997706 100644 --- a/xlators/protocol/client/src/client-protocol.c +++ b/xlators/protocol/client/src/client-protocol.c @@ -1327,116 +1327,6 @@ unwind: return 0; } -/** - * client_chmod - chmod function for client protocol - * @frame: call frame - * @this: this translator structure - * @loc: location - * @mode: - * - * external reference through client_protocol_xlator->fops->chmod - */ - -int -client_chmod (call_frame_t *frame, xlator_t *this, loc_t *loc, mode_t mode) -{ - gf_hdr_common_t *hdr = NULL; - gf_fop_chmod_req_t *req = NULL; - size_t hdrlen = -1; - int ret = -1; - size_t pathlen = 0; - ino_t ino = 0; - - pathlen = STRLEN_0(loc->path); - - ret = inode_ctx_get (loc->inode, this, &ino); - if (loc->inode->ino && ret < 0) { - gf_log (this->name, GF_LOG_DEBUG, - "CHMOD %"PRId64" (%s): " - "failed to get remote inode number", - loc->inode->ino, loc->path); - } - - hdrlen = gf_hdr_len (req, pathlen); - hdr = gf_hdr_new (req, pathlen); - GF_VALIDATE_OR_GOTO(this->name, hdr, unwind); - - req = gf_param (hdr); - - req->ino = hton64 (ino); - req->mode = hton32 (mode); - strcpy (req->path, loc->path); - - ret = protocol_client_xfer (frame, this, - CLIENT_CHANNEL (this, CHANNEL_LOWLAT), - GF_OP_TYPE_FOP_REQUEST, GF_FOP_CHMOD, - hdr, hdrlen, NULL, 0, NULL); - - return ret; -unwind: - if (hdr) - free (hdr); - STACK_UNWIND(frame, -1, EINVAL, NULL); - return 0; - -} - -/** - * client_chown - chown function for client protocol - * @frame: call frame - * @this: this translator structure - * @loc: location - * @uid: uid of new owner - * @gid: gid of new owner group - * - * external reference through client_protocol_xlator->fops->chown - */ - -int -client_chown (call_frame_t *frame, xlator_t *this, loc_t *loc, uid_t uid, - gid_t gid) -{ - gf_hdr_common_t *hdr = NULL; - gf_fop_chown_req_t *req = NULL; - size_t hdrlen = -1; - int ret = -1; - size_t pathlen = 0; - ino_t ino = 0; - - pathlen = STRLEN_0(loc->path); - - ret = inode_ctx_get (loc->inode, this, &ino); - if (loc->inode->ino && ret < 0) { - gf_log (this->name, GF_LOG_DEBUG, - "CHOWN %"PRId64" (%s): " - "failed to get remote inode number", - loc->inode->ino, loc->path); - } - - hdrlen = gf_hdr_len (req, pathlen); - hdr = gf_hdr_new (req, pathlen); - GF_VALIDATE_OR_GOTO(this->name, hdr, unwind); - - req = gf_param (hdr); - - req->ino = hton64 (ino); - req->uid = hton32 (uid); - req->gid = hton32 (gid); - strcpy (req->path, loc->path); - - ret = protocol_client_xfer (frame, this, - CLIENT_CHANNEL (this, CHANNEL_LOWLAT), - GF_OP_TYPE_FOP_REQUEST, GF_FOP_CHOWN, - hdr, hdrlen, NULL, 0, NULL); - - return ret; -unwind: - if (hdr) - free (hdr); - STACK_UNWIND(frame, -1, EINVAL, NULL); - return 0; - -} /** * client_truncate - truncate function for client protocol @@ -1491,59 +1381,6 @@ unwind: } -/** - * client_utimes - utimes function for client protocol - * @frame: call frame - * @this: this translator structure - * @loc: location - * @tvp: - * - * external reference through client_protocol_xlator->fops->utimes - */ - -int -client_utimens (call_frame_t *frame, xlator_t *this, loc_t *loc, - struct timespec *tvp) -{ - gf_hdr_common_t *hdr = NULL; - gf_fop_utimens_req_t *req = NULL; - size_t hdrlen = -1; - int ret = -1; - size_t pathlen = 0; - ino_t ino = 0; - - pathlen = STRLEN_0(loc->path); - ret = inode_ctx_get (loc->inode, this, &ino); - if (loc->inode->ino && ret < 0) { - gf_log (this->name, GF_LOG_DEBUG, - "UTIMENS %"PRId64" (%s): " - "failed to get remote inode number", - loc->inode->ino, loc->path); - } - - hdrlen = gf_hdr_len (req, pathlen); - hdr = gf_hdr_new (req, pathlen); - GF_VALIDATE_OR_GOTO(this->name, hdr, unwind); - - req = gf_param (hdr); - - req->ino = hton64 (ino); - gf_timespec_from_timespec (req->tv, tvp); - strcpy (req->path, loc->path); - - ret = protocol_client_xfer (frame, this, - CLIENT_CHANNEL (this, CHANNEL_LOWLAT), - GF_OP_TYPE_FOP_REQUEST, GF_FOP_UTIMENS, - hdr, hdrlen, NULL, 0, NULL); - - return ret; -unwind: - if (hdr) - free (hdr); - STACK_UNWIND(frame, -1, EINVAL, NULL); - return 0; - -} /** * client_readv - readv function for client protocol @@ -3248,115 +3085,6 @@ unwind: int -client_fchmod (call_frame_t *frame, xlator_t *this, fd_t *fd, mode_t mode) -{ - gf_hdr_common_t *hdr = NULL; - gf_fop_fchmod_req_t *req = NULL; - int64_t remote_fd = -1; - size_t hdrlen = -1; - int ret = -1; - int32_t op_errno = EINVAL; - int32_t op_ret = -1; - client_fd_ctx_t *fdctx = NULL; - client_conf_t *conf = NULL; - - GF_VALIDATE_OR_GOTO (this->name, fd, unwind); - - conf = this->private; - - pthread_mutex_lock (&conf->mutex); - { - fdctx = this_fd_get_ctx (fd, this); - } - pthread_mutex_unlock (&conf->mutex); - - if (fdctx == NULL) { - op_errno = EBADFD; - gf_log (this->name, GF_LOG_DEBUG, - "(%"PRId64"): failed to get fd ctx. EBADFD", - fd->inode->ino); - goto unwind; - } - remote_fd = fdctx->remote_fd; - hdrlen = gf_hdr_len (req, 0); - hdr = gf_hdr_new (req, 0); - GF_VALIDATE_OR_GOTO (this->name, hdr, unwind); - - req = gf_param (hdr); - - req->fd = hton64 (remote_fd); - req->mode = hton32 (mode); - - ret = protocol_client_xfer (frame, this, - CLIENT_CHANNEL (this, CHANNEL_LOWLAT), - GF_OP_TYPE_FOP_REQUEST, GF_FOP_FCHMOD, - hdr, hdrlen, NULL, 0, NULL); - - return 0; - -unwind: - STACK_UNWIND (frame, op_ret, op_errno, NULL); - return 0; -} - - -int -client_fchown (call_frame_t *frame, xlator_t *this, fd_t *fd, uid_t uid, - gid_t gid) -{ - gf_hdr_common_t *hdr = NULL; - gf_fop_fchown_req_t *req = NULL; - int64_t remote_fd = 0; - size_t hdrlen = -1; - int32_t op_ret = -1; - int32_t op_errno = EINVAL; - int32_t ret = -1; - client_fd_ctx_t *fdctx = NULL; - client_conf_t *conf = NULL; - - GF_VALIDATE_OR_GOTO (this->name, fd, unwind); - - conf = this->private; - - pthread_mutex_lock (&conf->mutex); - { - fdctx = this_fd_get_ctx (fd, this); - } - pthread_mutex_unlock (&conf->mutex); - - if (fdctx == NULL) { - op_errno = EBADFD; - gf_log (this->name, GF_LOG_DEBUG, - "(%"PRId64"): failed to get fd ctx. EBADFD", - fd->inode->ino); - goto unwind; - } - remote_fd = fdctx->remote_fd; - hdrlen = gf_hdr_len (req, 0); - hdr = gf_hdr_new (req, 0); - GF_VALIDATE_OR_GOTO (this->name, hdr, unwind); - - req = gf_param (hdr); - - req->fd = hton64 (remote_fd); - req->uid = hton32 (uid); - req->gid = hton32 (gid); - - ret = protocol_client_xfer (frame, this, - CLIENT_CHANNEL (this, CHANNEL_LOWLAT), - GF_OP_TYPE_FOP_REQUEST, GF_FOP_FCHOWN, - hdr, hdrlen, NULL, 0, NULL); - - return 0; - -unwind: - STACK_UNWIND (frame, op_ret, op_errno, NULL); - return 0; - -} - - -int client_setdents (call_frame_t *frame, xlator_t *this, fd_t *fd, int32_t flags, dir_entry_t *entries, int32_t count) { @@ -3498,6 +3226,102 @@ unwind: return 0; } +int32_t client_setattr (call_frame_t *frame, + xlator_t *this, + loc_t *loc, + struct stat *stbuf, + int32_t valid) +{ + gf_hdr_common_t *hdr = NULL; + gf_fop_setattr_req_t *req = NULL; + size_t hdrlen = 0; + size_t pathlen = 0; + ino_t ino = 0; + int ret = -1; + + GF_VALIDATE_OR_GOTO ("client", this, unwind); + GF_VALIDATE_OR_GOTO (this->name, frame, unwind); + + pathlen = STRLEN_0(loc->path); + + ret = inode_ctx_get (loc->inode, this, &ino); + if (loc->inode->ino && ret < 0) { + gf_log (this->name, GF_LOG_TRACE, + "SETATTR %"PRId64" (%s): " + "failed to get remote inode number", + loc->inode->ino, loc->path); + } + + hdrlen = gf_hdr_len (req, pathlen); + hdr = gf_hdr_new (req, pathlen); + GF_VALIDATE_OR_GOTO (this->name, hdr, unwind); + + req = gf_param (hdr); + + req->ino = hton64 (ino); + strcpy (req->path, loc->path); + + gf_stat_from_stat (&req->stbuf, stbuf); + req->valid = hton32 (valid); + + ret = protocol_client_xfer (frame, this, + CLIENT_CHANNEL (this, CHANNEL_BULK), + GF_OP_TYPE_FOP_REQUEST, GF_FOP_SETATTR, + hdr, hdrlen, NULL, 0, NULL); + + return ret; +unwind: + STACK_UNWIND (frame, -1, EINVAL, NULL); + return 0; +} + +int32_t client_fsetattr (call_frame_t *frame, + xlator_t *this, + fd_t *fd, + struct stat *stbuf, + int32_t valid) +{ + gf_hdr_common_t *hdr = NULL; + gf_fop_fsetattr_req_t *req = NULL; + size_t hdrlen = 0; + int ret = -1; + client_fd_ctx_t *fdctx = NULL; + int64_t remote_fd = -1; + + GF_VALIDATE_OR_GOTO ("client", this, unwind); + GF_VALIDATE_OR_GOTO (this->name, frame, unwind); + + fdctx = this_fd_get_ctx (fd, this); + if (fdctx == NULL) { + gf_log (this->name, GF_LOG_TRACE, + "(%"PRId64"): failed to get fd ctx. EBADFD", + fd->inode->ino); + STACK_UNWIND (frame, -1, EBADFD, NULL, NULL); + return 0; + } + + remote_fd = fdctx->remote_fd; + hdrlen = gf_hdr_len (req, 0); + hdr = gf_hdr_new (req, 0); + GF_VALIDATE_OR_GOTO(this->name, hdr, unwind); + + req = gf_param (hdr); + + req->fd = hton64 (remote_fd); + + gf_stat_from_stat (&req->stbuf, stbuf); + req->valid = hton32 (valid); + + ret = protocol_client_xfer (frame, this, + CLIENT_CHANNEL (this, CHANNEL_BULK), + GF_OP_TYPE_FOP_REQUEST, GF_FOP_FSETATTR, + hdr, hdrlen, NULL, 0, NULL); + + return ret; +unwind: + STACK_UNWIND (frame, -1, EINVAL, NULL, NULL); + return 0; +} /** * client_releasedir - releasedir function for client protocol @@ -3787,63 +3611,6 @@ fail: } /* - * client_chown_cbk - - * - * @frame: - * @args: - * - * not for external reference - */ - -int -client_fchown_cbk (call_frame_t *frame, gf_hdr_common_t *hdr, size_t hdrlen, - struct iobuf *iobuf) -{ - struct stat stbuf = {0, }; - gf_fop_fchown_rsp_t *rsp = NULL; - int32_t op_ret = 0; - int32_t op_errno = 0; - - rsp = gf_param (hdr); - - op_ret = ntoh32 (hdr->rsp.op_ret); - op_errno = gf_error_to_errno (ntoh32 (hdr->rsp.op_errno)); - - if (op_ret == 0) { - gf_stat_to_stat (&rsp->stat, &stbuf); - } - - STACK_UNWIND (frame, op_ret, op_errno, &stbuf); - - return 0; -} - - -int -client_fchmod_cbk (call_frame_t *frame, gf_hdr_common_t *hdr, size_t hdrlen, - struct iobuf *iobuf) -{ - struct stat stbuf = {0, }; - gf_fop_fchmod_rsp_t *rsp = NULL; - int32_t op_ret = 0; - int32_t op_errno = 0; - - rsp = gf_param (hdr); - - op_ret = ntoh32 (hdr->rsp.op_ret); - op_errno = gf_error_to_errno (ntoh32 (hdr->rsp.op_errno)); - - if (op_ret == 0) { - gf_stat_to_stat (&rsp->stat, &stbuf); - } - - STACK_UNWIND (frame, op_ret, op_errno, &stbuf); - - return 0; -} - - -/* * client_create_cbk - create callback function for client protocol * @frame: call frame * @args: arguments in dictionary @@ -4011,98 +3778,6 @@ client_stat_cbk (call_frame_t *frame, gf_hdr_common_t *hdr, size_t hdrlen, return 0; } -/* - * client_utimens_cbk - utimens callback for client protocol - * @frame: call frame - * @args: argument dictionary - * - * not for external reference - */ - -int -client_utimens_cbk (call_frame_t *frame, gf_hdr_common_t *hdr, size_t hdrlen, - struct iobuf *iobuf) -{ - struct stat stbuf = {0, }; - gf_fop_utimens_rsp_t *rsp = NULL; - int32_t op_ret = 0; - int32_t op_errno = 0; - - rsp = gf_param (hdr); - - op_ret = ntoh32 (hdr->rsp.op_ret); - op_errno = gf_error_to_errno (ntoh32 (hdr->rsp.op_errno)); - - if (op_ret == 0) { - gf_stat_to_stat (&rsp->stat, &stbuf); - } - - STACK_UNWIND (frame, op_ret, op_errno, &stbuf); - - return 0; -} - -/* - * client_chmod_cbk - chmod for client protocol - * @frame: call frame - * @args: argument dictionary - * - * not for external reference - */ - -int -client_chmod_cbk (call_frame_t *frame, gf_hdr_common_t *hdr, size_t hdrlen, - struct iobuf *iobuf) -{ - struct stat stbuf = {0, }; - gf_fop_chmod_rsp_t *rsp = NULL; - int32_t op_ret = 0; - int32_t op_errno = 0; - - rsp = gf_param (hdr); - - op_ret = ntoh32 (hdr->rsp.op_ret); - op_errno = gf_error_to_errno (ntoh32 (hdr->rsp.op_errno)); - - if (op_ret == 0) { - gf_stat_to_stat (&rsp->stat, &stbuf); - } - - STACK_UNWIND (frame, op_ret, op_errno, &stbuf); - - return 0; -} - -/* - * client_chown_cbk - chown for client protocol - * @frame: call frame - * @args: argument dictionary - * - * not for external reference - */ - -int -client_chown_cbk (call_frame_t *frame, gf_hdr_common_t *hdr, size_t hdrlen, - struct iobuf *iobuf) -{ - struct stat stbuf = {0, }; - gf_fop_chown_rsp_t *rsp = NULL; - int32_t op_ret = 0; - int32_t op_errno = 0; - - rsp = gf_param (hdr); - - op_ret = ntoh32 (hdr->rsp.op_ret); - op_errno = gf_error_to_errno (ntoh32 (hdr->rsp.op_errno)); - - if (op_ret == 0) { - gf_stat_to_stat (&rsp->stat, &stbuf); - } - - STACK_UNWIND (frame, op_ret, op_errno, &stbuf); - - return 0; -} /* * client_mknod_cbk - mknod callback for client protocol @@ -4843,6 +4518,56 @@ fail: return 0; } +static int32_t +client_setattr_cbk (call_frame_t *frame,gf_hdr_common_t *hdr, size_t hdrlen, + struct iobuf *iobuf) +{ + struct stat statpre = {0, }; + struct stat statpost = {0, }; + gf_fop_setattr_rsp_t *rsp = NULL; + int32_t op_ret = 0; + int32_t op_errno = 0; + + rsp = gf_param (hdr); + + op_ret = ntoh32 (hdr->rsp.op_ret); + op_errno = gf_error_to_errno (ntoh32 (hdr->rsp.op_errno)); + + if (op_ret == 0) { + gf_stat_to_stat (&rsp->statpre, &statpre); + gf_stat_to_stat (&rsp->statpost, &statpost); + } + + STACK_UNWIND (frame, op_ret, op_errno, &statpre, &statpost); + + return 0; +} + +static int32_t +client_fsetattr_cbk (call_frame_t *frame,gf_hdr_common_t *hdr, size_t hdrlen, + struct iobuf *iobuf) +{ + struct stat statpre = {0, }; + struct stat statpost = {0, }; + gf_fop_setattr_rsp_t *rsp = NULL; + int32_t op_ret = 0; + int32_t op_errno = 0; + + rsp = gf_param (hdr); + + op_ret = ntoh32 (hdr->rsp.op_ret); + op_errno = gf_error_to_errno (ntoh32 (hdr->rsp.op_errno)); + + if (op_ret == 0) { + gf_stat_to_stat (&rsp->statpre, &statpre); + gf_stat_to_stat (&rsp->statpost, &statpost); + } + + STACK_UNWIND (frame, op_ret, op_errno, &statpre, &statpost); + + return 0; +} + static dir_entry_t * gf_bin_to_direntry (char *buf, size_t count) { @@ -5935,8 +5660,6 @@ static gf_op_t gf_fops[] = { [GF_FOP_SYMLINK] = client_symlink_cbk, [GF_FOP_RENAME] = client_rename_cbk, [GF_FOP_LINK] = client_link_cbk, - [GF_FOP_CHMOD] = client_chmod_cbk, - [GF_FOP_CHOWN] = client_chown_cbk, [GF_FOP_TRUNCATE] = client_truncate_cbk, [GF_FOP_OPEN] = client_open_cbk, [GF_FOP_READ] = client_readv_cbk, @@ -5955,9 +5678,6 @@ static gf_op_t gf_fops[] = { [GF_FOP_FTRUNCATE] = client_ftruncate_cbk, [GF_FOP_FSTAT] = client_fstat_cbk, [GF_FOP_LK] = client_lk_common_cbk, - [GF_FOP_UTIMENS] = client_utimens_cbk, - [GF_FOP_FCHMOD] = client_fchmod_cbk, - [GF_FOP_FCHOWN] = client_fchown_cbk, [GF_FOP_LOOKUP] = client_lookup_cbk, [GF_FOP_SETDENTS] = client_setdents_cbk, [GF_FOP_READDIR] = client_readdir_cbk, @@ -5969,6 +5689,8 @@ static gf_op_t gf_fops[] = { [GF_FOP_RCHECKSUM] = client_rchecksum_cbk, [GF_FOP_XATTROP] = client_xattrop_cbk, [GF_FOP_FXATTROP] = client_fxattrop_cbk, + [GF_FOP_SETATTR] = client_setattr_cbk, + [GF_FOP_FSETATTR] = client_fsetattr_cbk, }; static gf_op_t gf_mops[] = { @@ -6573,10 +6295,7 @@ struct xlator_fops fops = { .symlink = client_symlink, .rename = client_rename, .link = client_link, - .chmod = client_chmod, - .chown = client_chown, .truncate = client_truncate, - .utimens = client_utimens, .open = client_open, .readv = client_readv, .writev = client_writev, @@ -6601,14 +6320,14 @@ struct xlator_fops fops = { .entrylk = client_entrylk, .fentrylk = client_fentrylk, .lookup = client_lookup, - .fchmod = client_fchmod, - .fchown = client_fchown, .setdents = client_setdents, .getdents = client_getdents, .checksum = client_checksum, .rchecksum = client_rchecksum, .xattrop = client_xattrop, .fxattrop = client_fxattrop, + .setattr = client_setattr, + .fsetattr = client_fsetattr, }; struct xlator_mops mops = { diff --git a/xlators/protocol/server/src/server-protocol.c b/xlators/protocol/server/src/server-protocol.c index fe8e83522..8e4e9e725 100644 --- a/xlators/protocol/server/src/server-protocol.c +++ b/xlators/protocol/server/src/server-protocol.c @@ -79,165 +79,6 @@ protocol_server_reply (call_frame_t *frame, int type, int op, /* - * server_fchmod_cbk - */ -int -server_fchmod_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, struct stat *stbuf) -{ - gf_hdr_common_t *hdr = NULL; - gf_fop_fchmod_rsp_t *rsp = NULL; - size_t hdrlen = 0; - int32_t gf_errno = 0; - server_state_t *state = NULL; - - - hdrlen = gf_hdr_len (rsp, 0); - hdr = gf_hdr_new (rsp, 0); - rsp = gf_param (hdr); - - hdr->rsp.op_ret = hton32 (op_ret); - gf_errno = gf_errno_to_error (op_errno); - hdr->rsp.op_errno = hton32 (gf_errno); - - if (op_ret == 0) { - gf_stat_from_stat (&rsp->stat, stbuf); - } else { - state = CALL_STATE (frame); - - gf_log (this->name, GF_LOG_TRACE, - "%"PRId64": FCHMOD %"PRId64" (%"PRId64") ==> %"PRId32" (%s)", - frame->root->unique, state->fd_no, - state->fd ? state->fd->inode->ino : 0, op_ret, - strerror (op_errno)); - } - - protocol_server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_FOP_FCHMOD, - hdr, hdrlen, NULL, 0, NULL); - - return 0; -} - -/* - * server_fchmod - * - */ -int -server_fchmod (call_frame_t *frame, xlator_t *bound_xl, - gf_hdr_common_t *hdr, size_t hdrlen, - struct iobuf *iobuf) -{ - server_connection_t *conn = NULL; - gf_fop_fchmod_req_t *req = NULL; - server_state_t *state = NULL; - - conn = SERVER_CONNECTION(frame); - - req = gf_param (hdr); - state = CALL_STATE (frame); - { - state->fd_no = ntoh64 (req->fd); - if (state->fd_no >= 0) - state->fd = gf_fd_fdptr_get (conn->fdtable, - state->fd_no); - - state->mode = ntoh32 (req->mode); - } - - GF_VALIDATE_OR_GOTO(bound_xl->name, state->fd, fail); - - STACK_WIND (frame, server_fchmod_cbk, - BOUND_XL(frame), - BOUND_XL(frame)->fops->fchmod, - state->fd, state->mode); - - return 0; -fail: - server_fchmod_cbk (frame, NULL, frame->this, -1, EINVAL, NULL); - return 0; -} - - -/* - * server_fchown_cbk - */ -int -server_fchown_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, struct stat *stbuf) -{ - gf_hdr_common_t *hdr = NULL; - gf_fop_fchown_rsp_t *rsp = NULL; - size_t hdrlen = 0; - int32_t gf_errno = 0; - server_state_t *state = NULL; - - hdrlen = gf_hdr_len (rsp, 0); - hdr = gf_hdr_new (rsp, 0); - rsp = gf_param (hdr); - - hdr->rsp.op_ret = hton32 (op_ret); - gf_errno = gf_errno_to_error (op_errno); - hdr->rsp.op_errno = hton32 (gf_errno); - - if (op_ret == 0) { - gf_stat_from_stat (&rsp->stat, stbuf); - } else { - state = CALL_STATE(frame); - - gf_log (this->name, GF_LOG_TRACE, - "%"PRId64": FCHOWN %"PRId64" (%"PRId64") ==> %"PRId32" (%s)", - frame->root->unique, state->fd_no, - state->fd ? state->fd->inode->ino : 0, op_ret, - strerror (op_errno)); - } - - protocol_server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_FOP_FCHOWN, - hdr, hdrlen, NULL, 0, NULL); - - return 0; -} - -/* - * server_fchown - * - */ -int -server_fchown (call_frame_t *frame, xlator_t *bound_xl, - gf_hdr_common_t *hdr, size_t hdrlen, - struct iobuf *iobuf) -{ - server_connection_t *conn = NULL; - gf_fop_fchown_req_t *req = NULL; - server_state_t *state = NULL; - - conn = SERVER_CONNECTION(frame); - - req = gf_param (hdr); - state = CALL_STATE(frame); - { - state->fd_no = ntoh64 (req->fd); - if (state->fd_no >= 0) - state->fd = gf_fd_fdptr_get (conn->fdtable, - state->fd_no); - - state->uid = ntoh32 (req->uid); - state->gid = ntoh32 (req->gid); - } - - GF_VALIDATE_OR_GOTO(bound_xl->name, state->fd, fail); - - STACK_WIND (frame, server_fchown_cbk, - BOUND_XL(frame), - BOUND_XL(frame)->fops->fchown, - state->fd, state->uid, state->gid); - - return 0; -fail: - server_fchown_cbk (frame, NULL, frame->this, -1, EINVAL, NULL); - return 0; -} - -/* * server_setdents_cbk - writedir callback for server protocol * @frame: call frame * @cookie: @@ -553,133 +394,6 @@ server_access_cbk (call_frame_t *frame, void *cookie, xlator_t *this, } /* - * server_utimens_cbk - utimens callback for server protocol - * @frame: call frame - * @cookie: - * @this: - * @op_ret: - * @op_errno: - * @stbuf: - * - * not for external reference - */ -int -server_utimens_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, struct stat *stbuf) -{ - gf_hdr_common_t *hdr = NULL; - gf_fop_utimens_rsp_t *rsp = NULL; - server_state_t *state = NULL; - size_t hdrlen = 0; - int32_t gf_errno = 0; - - - state = CALL_STATE(frame); - - hdrlen = gf_hdr_len (rsp, 0); - hdr = gf_hdr_new (rsp, 0); - rsp = gf_param (hdr); - - hdr->rsp.op_ret = hton32 (op_ret); - gf_errno = gf_errno_to_error (op_errno); - hdr->rsp.op_errno = hton32 (gf_errno); - - if (op_ret == 0) - gf_stat_from_stat (&rsp->stat, stbuf); - - server_loc_wipe (&(state->loc)); - - protocol_server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_FOP_UTIMENS, - hdr, hdrlen, NULL, 0, NULL); - - return 0; -} - -/* - * server_chmod_cbk - chmod callback for server protocol - * @frame: call frame - * @cookie: - * @this: - * @op_ret: - * @op_errno: - * @stbuf: - * - * not for external reference - */ -int -server_chmod_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, struct stat *stbuf) -{ - gf_hdr_common_t *hdr = NULL; - gf_fop_chmod_rsp_t *rsp = NULL; - server_state_t *state = NULL; - size_t hdrlen = 0; - int32_t gf_errno = 0; - - state = CALL_STATE(frame); - - hdrlen = gf_hdr_len (rsp, 0); - hdr = gf_hdr_new (rsp, 0); - rsp = gf_param (hdr); - - hdr->rsp.op_ret = hton32 (op_ret); - gf_errno = gf_errno_to_error (op_errno); - hdr->rsp.op_errno = hton32 (gf_errno); - - if (op_ret == 0) - gf_stat_from_stat (&rsp->stat, stbuf); - - server_loc_wipe (&(state->loc)); - - protocol_server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_FOP_CHMOD, - hdr, hdrlen, NULL, 0, NULL); - - return 0; -} - -/* - * server_chown_cbk - chown callback for server protocol - * @frame: call frame - * @cookie: - * @this: - * @op_ret: - * @op_errno: - * @stbuf: - * - * not for external reference - */ -int -server_chown_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, struct stat *stbuf) -{ - gf_hdr_common_t *hdr = NULL; - gf_fop_chown_rsp_t *rsp = NULL; - server_state_t *state = NULL; - int32_t gf_errno = 0; - size_t hdrlen = 0; - - state = CALL_STATE(frame); - - hdrlen = gf_hdr_len (rsp, 0); - hdr = gf_hdr_new (rsp, 0); - rsp = gf_param (hdr); - - hdr->rsp.op_ret = hton32 (op_ret); - gf_errno = gf_errno_to_error (op_errno); - hdr->rsp.op_errno = hton32 (gf_errno); - - if (op_ret == 0) - gf_stat_from_stat (&rsp->stat, stbuf); - - server_loc_wipe (&(state->loc)); - - protocol_server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_FOP_CHOWN, - hdr, hdrlen, NULL, 0, NULL); - - return 0; -} - -/* * server_rmdir_cbk - rmdir callback for server protocol * @frame: call frame * @cookie: @@ -2223,6 +1937,117 @@ server_stat_cbk (call_frame_t *frame, void *cookie, xlator_t *this, return 0; } +/* + * server_setattr_cbk - setattr callback for server protocol + * @frame: call frame + * @cookie: + * @this: + * @op_ret: + * @op_errno: + * @stbuf: + * + * not for external reference + */ +int +server_setattr_cbk (call_frame_t *frame, + void *cookie, + xlator_t *this, + int32_t op_ret, + int32_t op_errno, + struct stat *statpre, + struct stat *statpost) +{ + gf_hdr_common_t *hdr = NULL; + gf_fop_setattr_rsp_t *rsp = NULL; + server_state_t *state = NULL; + size_t hdrlen = 0; + int32_t gf_errno = 0; + + state = CALL_STATE (frame); + + hdrlen = gf_hdr_len (rsp, 0); + hdr = gf_hdr_new (rsp, 0); + rsp = gf_param (hdr); + + hdr->rsp.op_ret = hton32 (op_ret); + gf_errno = gf_errno_to_error (op_errno); + hdr->rsp.op_errno = hton32 (gf_errno_to_error (op_errno)); + + if (op_ret == 0) { + gf_stat_from_stat (&rsp->statpre, statpre); + gf_stat_from_stat (&rsp->statpost, statpost); + } else { + gf_log (this->name, GF_LOG_DEBUG, + "%"PRId64": SETATTR %s (%"PRId64") ==> %"PRId32" (%s)", + frame->root->unique, state->loc.path, + state->loc.inode ? state->loc.inode->ino : 0, + op_ret, strerror (op_errno)); + } + + server_loc_wipe (&(state->loc)); + + protocol_server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_FOP_SETATTR, + hdr, hdrlen, NULL, 0, NULL); + + return 0; +} + +/* + * server_setattr_cbk - setattr callback for server protocol + * @frame: call frame + * @cookie: + * @this: + * @op_ret: + * @op_errno: + * @stbuf: + * + * not for external reference + */ +int +server_fsetattr_cbk (call_frame_t *frame, + void *cookie, + xlator_t *this, + int32_t op_ret, + int32_t op_errno, + struct stat *statpre, + struct stat *statpost) +{ + gf_hdr_common_t *hdr = NULL; + gf_fop_fsetattr_rsp_t *rsp = NULL; + server_state_t *state = NULL; + size_t hdrlen = 0; + int32_t gf_errno = 0; + + state = CALL_STATE (frame); + + hdrlen = gf_hdr_len (rsp, 0); + hdr = gf_hdr_new (rsp, 0); + rsp = gf_param (hdr); + + hdr->rsp.op_ret = hton32 (op_ret); + gf_errno = gf_errno_to_error (op_errno); + hdr->rsp.op_errno = hton32 (gf_errno_to_error (op_errno)); + + if (op_ret == 0) { + gf_stat_from_stat (&rsp->statpre, statpre); + gf_stat_from_stat (&rsp->statpost, statpost); + } else { + gf_log (this->name, GF_LOG_DEBUG, + "%"PRId64": FSETATTR %"PRId64" (%"PRId64") ==> " + "%"PRId32" (%s)", + frame->root->unique, state->fd_no, + state->fd ? state->fd->inode->ino : 0, + op_ret, strerror (op_errno)); + } + + server_loc_wipe (&(state->loc)); + + protocol_server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_FOP_FSETATTR, + hdr, hdrlen, NULL, 0, NULL); + + return 0; +} + /* * server_lookup_cbk - lookup callback for server protocol @@ -2779,62 +2604,6 @@ server_stub_resume (call_stub_t *stub, int32_t op_ret, int32_t op_errno, break; } - case GF_FOP_CHMOD: - { - if (op_ret < 0) { - gf_log (stub->frame->this->name, GF_LOG_DEBUG, - "%"PRId64": CHMOD (%s) on %s returning error: " - "%"PRId32" (%"PRId32")", - stub->frame->root->unique, - stub->args.chmod.loc.path, - BOUND_XL(stub->frame)->name, - op_ret, op_errno); - server_chmod_cbk (stub->frame, NULL, stub->frame->this, - -1, ENOENT, NULL); - server_loc_wipe (&stub->args.chmod.loc); - FREE (stub); - return 0; - } - - if (stub->args.chmod.loc.parent == NULL) - stub->args.chmod.loc.parent = inode_ref (parent); - - if (server_inode && (stub->args.chmod.loc.inode == NULL)) { - stub->args.chmod.loc.inode = inode_ref (server_inode); - stub->args.chmod.loc.ino = server_inode->ino; - } - call_resume (stub); - break; - } - - case GF_FOP_CHOWN: - { - if (op_ret < 0) { - gf_log (stub->frame->this->name, GF_LOG_DEBUG, - "%"PRId64": CHOWN (%s) on %s returning ENOENT: " - "%"PRId32" (%"PRId32")", - stub->frame->root->unique, - stub->args.chown.loc.path, - BOUND_XL(stub->frame)->name, - op_ret, op_errno); - server_chown_cbk (stub->frame, NULL, stub->frame->this, - -1, ENOENT, NULL); - server_loc_wipe (&stub->args.chown.loc); - FREE (stub); - return 0; - } - - if (stub->args.chown.loc.parent == NULL) - stub->args.chown.loc.parent = inode_ref (parent); - - if (server_inode && (stub->args.chown.loc.inode == NULL)) { - stub->args.chown.loc.inode = inode_ref (server_inode); - stub->args.chown.loc.ino = server_inode->ino; - } - call_resume (stub); - break; - } - case GF_FOP_LINK: { if ((stub->args.link.oldloc.inode == NULL) @@ -3136,38 +2905,6 @@ server_stub_resume (call_stub_t *stub, int32_t op_ret, int32_t op_errno, break; } - - case GF_FOP_UTIMENS: - { - if (op_ret < 0) { - gf_log (stub->frame->this->name, GF_LOG_DEBUG, - "%"PRId64": UTIMENS (%s) on %s returning error: " - "%"PRId32" (%"PRId32")", - stub->frame->root->unique, - stub->args.utimens.loc.path, - BOUND_XL(stub->frame)->name, - op_ret, op_errno); - - server_utimens_cbk (stub->frame, NULL, - stub->frame->this, -1, ENOENT, - NULL); - server_loc_wipe (&stub->args.utimens.loc); - FREE (stub); - return 0; - } - - if (stub->args.utimens.loc.parent == NULL) - stub->args.utimens.loc.parent = inode_ref (parent); - - if (server_inode && (stub->args.utimens.loc.inode == NULL)) { - stub->args.utimens.loc.inode = - inode_ref (server_inode); - stub->args.utimens.loc.ino = server_inode->ino; - } - call_resume (stub); - break; - } - case GF_FOP_READLINK: { if (op_ret < 0) { @@ -3350,6 +3087,34 @@ server_stub_resume (call_stub_t *stub, int32_t op_ret, int32_t op_errno, call_resume (stub); break; } + case GF_FOP_SETATTR: + { + if (op_ret < 0) { + gf_log (stub->frame->this->name, GF_LOG_DEBUG, + "%"PRId64": SETATTR (%s) on %s returning error:" + " %"PRId32" (%"PRId32")", + stub->frame->root->unique, + stub->args.setattr.loc.path, + BOUND_XL(stub->frame)->name, + op_ret, op_errno); + server_setattr_cbk (stub->frame, NULL, + stub->frame->this, + -1, ENOENT, NULL, NULL); + server_loc_wipe (&stub->args.setattr.loc); + FREE (stub); + return 0; + } + + if (stub->args.setattr.loc.parent == NULL) + stub->args.setattr.loc.parent = inode_ref (parent); + + if (server_inode && (stub->args.setattr.loc.inode == NULL)) { + stub->args.setattr.loc.inode = inode_ref (server_inode); + stub->args.setattr.loc.ino = server_inode->ino; + } + call_resume (stub); + break; + } default: call_resume (stub); } @@ -3576,6 +3341,119 @@ fail: return 0; } +int +server_setattr_resume (call_frame_t *frame, + xlator_t *this, + loc_t *loc, + struct stat *stbuf, + int32_t valid) +{ + server_state_t *state = NULL; + + state = CALL_STATE(frame); + + gf_log (BOUND_XL(frame)->name, GF_LOG_TRACE, + "%"PRId64": SETATTR \'%s (%"PRId64")\'", + frame->root->unique, state->loc.path, state->loc.ino); + + STACK_WIND (frame, server_setattr_cbk, + BOUND_XL(frame), + BOUND_XL(frame)->fops->setattr, + loc, + stbuf, valid); + return 0; +} + +/* + * server_setattr - setattr function for server + * @frame: call frame + * @bound_xl: translator this server is bound to + * @params: parameters dictionary + * + * not for external reference + */ +int +server_setattr (call_frame_t *frame, xlator_t *bound_xl, + gf_hdr_common_t *hdr, size_t hdrlen, + struct iobuf *iobuf) +{ + call_stub_t *setattr_stub = NULL; + gf_fop_setattr_req_t *req = NULL; + server_state_t *state = NULL; + int32_t ret = -1; + size_t pathlen = 0; + struct stat stbuf = {0,}; + int32_t valid = 0; + + req = gf_param (hdr); + + state = CALL_STATE(frame); + + state->ino = ntoh64 (req->ino); + state->path = req->path; + pathlen = STRLEN_0(state->path); + + gf_stat_to_stat (&req->stbuf, &stbuf); + + valid = ntoh32 (req->valid); + + ret = server_loc_fill (&(state->loc), state, state->ino, state->par, + state->bname, state->path); + + setattr_stub = fop_setattr_stub (frame, server_setattr_resume, + &(state->loc), &stbuf, valid); + GF_VALIDATE_OR_GOTO(bound_xl->name, setattr_stub, fail); + + if (((state->loc.parent == NULL) && IS_NOT_ROOT(pathlen)) || + (state->loc.inode == NULL)) { + do_path_lookup (setattr_stub, &(state->loc)); + } else { + call_resume (setattr_stub); + } + return 0; +fail: + server_setattr_cbk (frame, NULL, frame->this, -1, EINVAL, NULL, NULL); + return 0; +} + +int +server_fsetattr (call_frame_t *frame, xlator_t *bound_xl, + gf_hdr_common_t *hdr, size_t hdrlen, + struct iobuf *iobuf) +{ + server_connection_t *conn = NULL; + gf_fop_fsetattr_req_t *req = NULL; + server_state_t *state = NULL; + struct stat stbuf = {0,}; + int32_t valid = 0; + + conn = SERVER_CONNECTION(frame); + + req = gf_param (hdr); + state = CALL_STATE (frame); + { + state->fd_no = ntoh64 (req->fd); + if (state->fd_no >= 0) + state->fd = gf_fd_fdptr_get (conn->fdtable, + state->fd_no); + + gf_stat_to_stat (&req->stbuf, &stbuf); + + valid = ntoh32 (req->valid); + } + + GF_VALIDATE_OR_GOTO(bound_xl->name, state->fd, fail); + + STACK_WIND (frame, server_fsetattr_cbk, + BOUND_XL(frame), + BOUND_XL(frame)->fops->fsetattr, + state->fd, &stbuf, valid); + + return 0; +fail: + server_fsetattr_cbk (frame, NULL, frame->this, -1, EINVAL, NULL, NULL); + return 0; +} int server_readlink_resume (call_frame_t *frame, xlator_t *this, loc_t *loc, @@ -5351,205 +5229,6 @@ server_rmdir (call_frame_t *frame, xlator_t *bound_xl, int -server_chown_resume (call_frame_t *frame, xlator_t *this, loc_t *loc, - uid_t uid, gid_t gid) -{ - server_state_t *state = NULL; - - state = CALL_STATE (frame); - - gf_log (BOUND_XL(frame)->name, GF_LOG_TRACE, - "%"PRId64": CHOWN \'%s (%"PRId64")\'", - frame->root->unique, state->path, state->ino); - - STACK_WIND (frame, server_chown_cbk, - BOUND_XL(frame), - BOUND_XL(frame)->fops->chown, - loc, uid, gid); - return 0; -} - - -/* - * server_chown - chown function for server protocol - * @frame: call frame - * @bound_xl: - * @params: parameter dictionary - * - * not for external reference - */ -int -server_chown (call_frame_t *frame, xlator_t *bound_xl, - gf_hdr_common_t *hdr, size_t hdrlen, - struct iobuf *iobuf) -{ - call_stub_t *chown_stub = NULL; - gf_fop_chown_req_t *req = NULL; - server_state_t *state = NULL; - int32_t ret = -1; - size_t pathlen = 0; - - req = gf_param (hdr); - state = CALL_STATE(frame); - { - state->ino = ntoh64 (req->ino); - state->path = req->path; - pathlen = STRLEN_0(state->path); - state->uid = ntoh32 (req->uid); - state->gid = ntoh32 (req->gid); - } - - ret = server_loc_fill (&(state->loc), state, state->ino, 0, NULL, - state->path); - - chown_stub = fop_chown_stub (frame, server_chown_resume, - &(state->loc), state->uid, state->gid); - - if (((state->loc.parent == NULL) && IS_NOT_ROOT(pathlen)) || - (state->loc.inode == NULL)) { - do_path_lookup (chown_stub, &(state->loc)); - } else { - call_resume (chown_stub); - } - - return 0; -} - - -int -server_chmod_resume (call_frame_t *frame, xlator_t *this, loc_t *loc, - mode_t mode) -{ - server_state_t *state = NULL; - - state = CALL_STATE(frame); - - gf_log (BOUND_XL(frame)->name, GF_LOG_TRACE, - "%"PRId64": CHMOD \'%s (%"PRId64")\'", - frame->root->unique, state->path, state->ino); - - STACK_WIND (frame, server_chmod_cbk, - BOUND_XL(frame), - BOUND_XL(frame)->fops->chmod, - loc, mode); - return 0; - -} - -/* - * server_chmod - chmod function for server protocol - * @frame: call frame - * @bound_xl: - * @params: parameter dictionary - * - * not for external reference - */ -int -server_chmod (call_frame_t *frame, xlator_t *bound_xl, - gf_hdr_common_t *hdr, size_t hdrlen, - struct iobuf *iobuf) -{ - call_stub_t *chmod_stub = NULL; - gf_fop_chmod_req_t *req = NULL; - server_state_t *state = NULL; - int32_t ret = -1; - size_t pathlen = 0; - - req = gf_param (hdr); - - state = CALL_STATE(frame); - { - state->ino = ntoh64 (req->ino); - state->path = req->path; - pathlen = STRLEN_0(state->path); - - state->mode = ntoh32 (req->mode); - } - - ret = server_loc_fill (&(state->loc), state, state->ino, 0, NULL, - state->path); - - chmod_stub = fop_chmod_stub (frame, server_chmod_resume, - &(state->loc), state->mode); - - if (((state->loc.parent == NULL) && IS_NOT_ROOT(pathlen)) || - (state->loc.inode == NULL)) { - do_path_lookup (chmod_stub, &(state->loc)); - } else { - call_resume (chmod_stub); - } - - return 0; -} - - -int -server_utimens_resume (call_frame_t *frame, xlator_t *this, loc_t *loc, - struct timespec *tv) -{ - server_state_t *state = NULL; - - state = CALL_STATE(frame); - - gf_log (BOUND_XL(frame)->name, GF_LOG_TRACE, - "%"PRId64": UTIMENS \'%s (%"PRId64")\'", - frame->root->unique, state->path, state->ino); - - STACK_WIND (frame, server_utimens_cbk, - BOUND_XL(frame), - BOUND_XL(frame)->fops->utimens, - loc, tv); - return 0; -} - -/* - * server_utimens - utimens function for server protocol - * @frame: call frame - * @bound_xl: - * @params: parameter dictionary - * - * not for external reference - */ -int -server_utimens (call_frame_t *frame, xlator_t *bound_xl, - gf_hdr_common_t *hdr, size_t hdrlen, - struct iobuf *iobuf) -{ - call_stub_t *utimens_stub = NULL; - gf_fop_utimens_req_t *req = NULL; - server_state_t *state = NULL; - int32_t ret = -1; - size_t pathlen = 0; - - req = gf_param (hdr); - state = CALL_STATE(frame); - { - state->ino = ntoh64 (req->ino); - state->path = req->path; - pathlen = STRLEN_0(state->path); - - gf_timespec_to_timespec (req->tv, state->tv); - } - - - ret = server_loc_fill (&(state->loc), state, state->ino, 0, NULL, - state->path); - - utimens_stub = fop_utimens_stub (frame, server_utimens_resume, - &(state->loc), state->tv); - - if (((state->loc.parent == NULL) && IS_NOT_ROOT(pathlen)) || - (state->loc.inode == NULL)) { - do_path_lookup (utimens_stub, &(state->loc)); - } else { - call_resume (utimens_stub); - } - - return 0; -} - - -int server_inodelk_resume (call_frame_t *frame, xlator_t *this, const char *volume, loc_t *loc, int32_t cmd, struct flock *flock) @@ -7442,8 +7121,6 @@ static gf_op_t gf_fops[] = { [GF_FOP_SYMLINK] = server_symlink, [GF_FOP_RENAME] = server_rename, [GF_FOP_LINK] = server_link, - [GF_FOP_CHMOD] = server_chmod, - [GF_FOP_CHOWN] = server_chown, [GF_FOP_TRUNCATE] = server_truncate, [GF_FOP_OPEN] = server_open, [GF_FOP_READ] = server_readv, @@ -7464,9 +7141,6 @@ static gf_op_t gf_fops[] = { [GF_FOP_FTRUNCATE] = server_ftruncate, [GF_FOP_FSTAT] = server_fstat, [GF_FOP_LK] = server_lk, - [GF_FOP_UTIMENS] = server_utimens, - [GF_FOP_FCHMOD] = server_fchmod, - [GF_FOP_FCHOWN] = server_fchown, [GF_FOP_LOOKUP] = server_lookup, [GF_FOP_SETDENTS] = server_setdents, [GF_FOP_READDIR] = server_readdir, @@ -7478,6 +7152,8 @@ static gf_op_t gf_fops[] = { [GF_FOP_RCHECKSUM] = server_rchecksum, [GF_FOP_XATTROP] = server_xattrop, [GF_FOP_FXATTROP] = server_fxattrop, + [GF_FOP_SETATTR] = server_setattr, + [GF_FOP_FSETATTR] = server_fsetattr, }; diff --git a/xlators/protocol/server/src/server-protocol.h b/xlators/protocol/server/src/server-protocol.h index dabe6927b..2f88b6346 100644 --- a/xlators/protocol/server/src/server-protocol.h +++ b/xlators/protocol/server/src/server-protocol.h @@ -121,8 +121,6 @@ struct _server_state { off_t offset; mode_t mode; dev_t dev; - uid_t uid; - gid_t gid; size_t nr_count; int cmd; int type; @@ -142,7 +140,6 @@ struct _server_state { char is_revalidate; dict_t *xattr_req; struct flock flock; - struct timespec tv[2]; char *resolved; const char *volume; }; diff --git a/xlators/storage/bdb/src/bdb.c b/xlators/storage/bdb/src/bdb.c index 2b1208b97..bb6d3a434 100644 --- a/xlators/storage/bdb/src/bdb.c +++ b/xlators/storage/bdb/src/bdb.c @@ -1867,23 +1867,79 @@ out: return 0; } /* bdb_symlink */ +static int +bdb_do_chmod (xlator_t *this, + const char *path, + struct stat *stbuf) +{ + int32_t ret = -1; + + ret = lchmod (path, stbuf->st_mode); + if ((ret == -1) && (errno == ENOSYS)) { + ret = chmod (path, stbuf->st_mode); + } + + return ret; +} + +static int +bdb_do_chown (xlator_t *this, + const char *path, + struct stat *stbuf, + int32_t valid) +{ + int32_t ret = -1; + uid_t uid = -1; + gid_t gid = -1; + + if (valid & GF_SET_ATTR_UID) + uid = stbuf->st_uid; + + if (valid & GF_SET_ATTR_GID) + gid = stbuf->st_gid; + + ret = lchown (path, uid, gid); + + return ret; +} + +static int +bdb_do_utimes (xlator_t *this, + const char *path, + struct stat *stbuf) +{ + int32_t ret = -1; + struct timeval tv[2] = {{0,},{0,}}; + + tv[0].tv_sec = stbuf->st_atime; + tv[0].tv_usec = ST_ATIM_NSEC (stbuf) / 1000; + tv[1].tv_sec = stbuf->st_mtime; + tv[1].tv_usec = ST_ATIM_NSEC (stbuf) / 1000; + + ret = lutimes (path, tv); + + return ret; +} + int32_t -bdb_chmod (call_frame_t *frame, - xlator_t *this, - loc_t *loc, - mode_t mode) +bdb_setattr (call_frame_t *frame, + xlator_t *this, + loc_t *loc, + struct stat *stbuf, + int32_t valid) { int32_t op_ret = -1; int32_t op_errno = EINVAL; char *real_path = NULL; - struct stat stbuf = {0,}; + struct stat preop = {0,}; + struct stat postop = {0,}; GF_VALIDATE_OR_GOTO ("bdb", frame, out); GF_VALIDATE_OR_GOTO ("bdb", this, out); GF_VALIDATE_OR_GOTO (this->name, loc, out); MAKE_REAL_PATH (real_path, this, loc->path); - op_ret = lstat (real_path, &stbuf); + op_ret = lstat (real_path, &preop); op_errno = errno; if (op_ret != 0) { if (op_errno == ENOENT) { @@ -1891,62 +1947,77 @@ bdb_chmod (call_frame_t *frame, } else { gf_log (this->name, GF_LOG_DEBUG, "CHMOD %"PRId64" (%s): %s" - "(lstat failed)", + "(pre-op lstat failed)", loc->ino, loc->path, strerror (op_errno)); } goto out; } /* directory or symlink */ - op_ret = chmod (real_path, mode); + if (valid & GF_SET_ATTR_MODE) { + op_ret = bdb_do_chmod (this, real_path, stbuf); + if (op_ret == -1) { + op_errno = errno; + gf_log (this->name, GF_LOG_ERROR, + "setattr (chmod) on %s failed: %s", loc->path, + strerror (op_errno)); + goto out; + } + } + + if (valid & (GF_SET_ATTR_UID | GF_SET_ATTR_GID)){ + op_ret = bdb_do_chown (this, real_path, stbuf, valid); + if (op_ret == -1) { + op_errno = errno; + gf_log (this->name, GF_LOG_ERROR, + "setattr (chown) on %s failed: %s", loc->path, + strerror (op_errno)); + goto out; + } + } + + if (valid & (GF_SET_ATTR_ATIME | GF_SET_ATTR_MTIME)) { + op_ret = bdb_do_utimes (this, real_path, stbuf); + if (op_ret == -1) { + op_errno = errno; + gf_log (this->name, GF_LOG_ERROR, + "setattr (utimes) on %s failed: %s", loc->path, + strerror (op_errno)); + goto out; + } + } + + op_ret = lstat (real_path, &postop); op_errno = errno; + if (op_ret != 0) { + gf_log (this->name, GF_LOG_DEBUG, + "CHMOD %"PRId64" (%s): %s" + "(post-op lstat failed)", + loc->ino, loc->path, strerror (op_errno)); + } out: - STACK_UNWIND (frame, op_ret, op_errno, &stbuf); + STACK_UNWIND (frame, op_ret, op_errno, &preop, &postop); return 0; -}/* bdb_chmod */ - +}/* bdb_setattr */ int32_t -bdb_chown (call_frame_t *frame, - xlator_t *this, - loc_t *loc, - uid_t uid, - gid_t gid) +bdb_fsetattr (call_frame_t *frame, + xlator_t *this, + fd_t *fd, + struct stat *stbuf, + int32_t valid) { int32_t op_ret = -1; - int32_t op_errno = EINVAL; - char *real_path = NULL; - struct stat stbuf = {0,}; - - GF_VALIDATE_OR_GOTO ("bdb", frame, out); - GF_VALIDATE_OR_GOTO ("bdb", this, out); - GF_VALIDATE_OR_GOTO (this->name, loc, out); - - MAKE_REAL_PATH (real_path, this, loc->path); - op_ret = lstat (real_path, &stbuf); - if (op_ret != 0) { - op_errno = errno; - if (op_errno == ENOENT) { - op_errno = EPERM; - } else { - gf_log (this->name, GF_LOG_DEBUG, - "CHOWN %"PRId64" (%s): %s" - "(lstat failed)", - loc->ino, loc->path, strerror (op_errno)); - } - goto out; - } + int32_t op_errno = EPERM; + struct stat preop = {0,}; + struct stat postop = {0,}; - /* directory or symlink */ - op_ret = lchown (real_path, uid, gid); - op_errno = errno; -out: - STACK_UNWIND (frame, op_ret, op_errno, &stbuf); + STACK_UNWIND (frame, op_ret, op_errno, &preop, &postop); return 0; -}/* bdb_chown */ +}/* bdb_fsetattr */ int32_t @@ -2024,72 +2095,6 @@ out: int32_t -bdb_utimens (call_frame_t *frame, - xlator_t *this, - loc_t *loc, - struct timespec ts[2]) -{ - int32_t op_ret = -1; - int32_t op_errno = EPERM; - char *real_path = NULL; - struct stat stbuf = {0,}; - struct timeval tv[2] = {{0,},}; - - GF_VALIDATE_OR_GOTO ("bdb", frame, out); - GF_VALIDATE_OR_GOTO ("bdb", this, out); - GF_VALIDATE_OR_GOTO (this->name, loc, out); - - MAKE_REAL_PATH (real_path, this, loc->path); - op_ret = sys_lstat (real_path, &stbuf); - if (op_ret != 0) { - op_errno = errno; - if (op_errno == ENOENT) { - op_errno = EPERM; - } else { - gf_log (this->name, GF_LOG_DEBUG, - "UTIMENS %"PRId64" (%s): %s", - loc->ino, loc->path, strerror (op_errno)); - } - goto out; - } - - /* directory or symlink */ - tv[0].tv_sec = ts[0].tv_sec; - tv[0].tv_usec = ts[0].tv_nsec / 1000; - tv[1].tv_sec = ts[1].tv_sec; - tv[1].tv_usec = ts[1].tv_nsec / 1000; - - op_ret = lutimes (real_path, tv); - if ((op_ret == -1) && (errno == ENOSYS)) { - op_ret = sys_utimes (real_path, tv); - } - - if (op_ret == -1) { - op_errno = errno; - gf_log (this->name, GF_LOG_DEBUG, - "UTIMENS %"PRId64" (%s): %s", - loc->ino, loc->path, strerror (op_errno)); - goto out; - } - - op_ret = sys_lstat (real_path, &stbuf); - if (op_ret != 0) { - op_errno = errno; - gf_log (this->name, GF_LOG_DEBUG, - "UTIMENS %"PRId64" (%s): %s", - loc->ino, loc->path, strerror (op_errno)); - goto out; - } - - stbuf.st_ino = loc->inode->ino; - -out: - STACK_UNWIND (frame, op_ret, op_errno, &stbuf); - - return 0; -}/* bdb_utimens */ - -int32_t bdb_statfs (call_frame_t *frame, xlator_t *this, loc_t *loc) @@ -2578,49 +2583,7 @@ out: return 0; } -int32_t -bdb_fchown (call_frame_t *frame, - xlator_t *this, - fd_t *fd, - uid_t uid, - gid_t gid) -{ - int32_t op_ret = -1; - int32_t op_errno = EPERM; - struct stat buf = {0,}; - - GF_VALIDATE_OR_GOTO ("bdb", frame, out); - GF_VALIDATE_OR_GOTO ("bdb", this, out); - GF_VALIDATE_OR_GOTO (this->name, fd, out); - /* TODO: implement */ -out: - STACK_UNWIND (frame, op_ret, op_errno, &buf); - - return 0; -} - - -int32_t -bdb_fchmod (call_frame_t *frame, - xlator_t *this, - fd_t *fd, - mode_t mode) -{ - int32_t op_ret = -1; - int32_t op_errno = EPERM; - struct stat buf = {0,}; - - GF_VALIDATE_OR_GOTO ("bdb", frame, out); - GF_VALIDATE_OR_GOTO ("bdb", this, out); - GF_VALIDATE_OR_GOTO (this->name, fd, out); - - /* TODO: impelement */ -out: - STACK_UNWIND (frame, op_ret, op_errno, &buf); - - return 0; -} int32_t bdb_setdents (call_frame_t *frame, @@ -3503,10 +3466,7 @@ struct xlator_fops fops = { .symlink = bdb_symlink, .rename = bdb_rename, .link = bdb_link, - .chmod = bdb_chmod, - .chown = bdb_chown, .truncate = bdb_truncate, - .utimens = bdb_utimens, .create = bdb_create, .open = bdb_open, .readv = bdb_readv, @@ -3526,11 +3486,11 @@ struct xlator_fops fops = { .finodelk = bdb_finodelk, .entrylk = bdb_entrylk, .fentrylk = bdb_fentrylk, - .fchown = bdb_fchown, - .fchmod = bdb_fchmod, .setdents = bdb_setdents, .getdents = bdb_getdents, .checksum = bdb_checksum, + .setattr = bdb_setattr, + .fsetattr = bdb_fsetattr, }; struct xlator_cbks cbks = { diff --git a/xlators/storage/posix/src/posix.c b/xlators/storage/posix/src/posix.c index d022e4c28..c4f47049c 100644 --- a/xlators/storage/posix/src/posix.c +++ b/xlators/storage/posix/src/posix.c @@ -416,6 +416,269 @@ posix_stat (call_frame_t *frame, return 0; } +static int +posix_do_chmod (xlator_t *this, + const char *path, + struct stat *stbuf) +{ + int32_t ret = -1; + + ret = chmod (path, stbuf->st_mode); + if ((ret == -1) && (errno == ENOSYS)) { + ret = chmod (path, stbuf->st_mode); + } + + return ret; +} + +static int +posix_do_chown (xlator_t *this, + const char *path, + struct stat *stbuf, + int32_t valid) +{ + int32_t ret = -1; + uid_t uid = -1; + gid_t gid = -1; + + if (valid & GF_SET_ATTR_UID) + uid = stbuf->st_uid; + + if (valid & GF_SET_ATTR_GID) + gid = stbuf->st_gid; + + ret = chown (path, uid, gid); + + return ret; +} + +static int +posix_do_utimes (xlator_t *this, + const char *path, + struct stat *stbuf) +{ + int32_t ret = -1; + struct timeval tv[2] = {{0,},{0,}}; + + tv[0].tv_sec = stbuf->st_atime; + tv[0].tv_usec = ST_ATIM_NSEC (stbuf) / 1000; + tv[1].tv_sec = stbuf->st_mtime; + tv[1].tv_usec = ST_ATIM_NSEC (stbuf) / 1000; + + ret = utimes (path, tv); + + return ret; +} + +int +posix_setattr (call_frame_t *frame, xlator_t *this, + loc_t *loc, struct stat *stbuf, int32_t valid) +{ + int32_t op_ret = -1; + int32_t op_errno = 0; + char * real_path = 0; + struct stat statpre = {0,}; + struct stat statpost = {0,}; + + DECLARE_OLD_FS_ID_VAR; + + VALIDATE_OR_GOTO (frame, out); + VALIDATE_OR_GOTO (this, out); + VALIDATE_OR_GOTO (loc, out); + + SET_FS_ID (frame->root->uid, frame->root->gid); + MAKE_REAL_PATH (real_path, this, loc->path); + + op_ret = lstat (real_path, &statpre); + if (op_ret == -1) { + op_errno = errno; + gf_log (this->name, GF_LOG_ERROR, + "setattr (lstat) on %s failed: %s", real_path, + strerror (op_errno)); + goto out; + } + + if (valid & GF_SET_ATTR_MODE) { + op_ret = posix_do_chmod (this, real_path, stbuf); + if (op_ret == -1) { + op_errno = errno; + gf_log (this->name, GF_LOG_ERROR, + "setattr (chmod) on %s failed: %s", real_path, + strerror (op_errno)); + goto out; + } + } + + if (valid & (GF_SET_ATTR_UID | GF_SET_ATTR_GID)){ + op_ret = posix_do_chown (this, real_path, stbuf, valid); + if (op_ret == -1) { + op_errno = errno; + gf_log (this->name, GF_LOG_ERROR, + "setattr (chown) on %s failed: %s", real_path, + strerror (op_errno)); + goto out; + } + } + + if (valid & (GF_SET_ATTR_ATIME | GF_SET_ATTR_MTIME)) { + op_ret = posix_do_utimes (this, real_path, stbuf); + if (op_ret == -1) { + op_errno = errno; + gf_log (this->name, GF_LOG_ERROR, + "setattr (utimes) on %s failed: %s", real_path, + strerror (op_errno)); + goto out; + } + } + + op_ret = lstat (real_path, &statpost); + if (op_ret == -1) { + op_errno = errno; + gf_log (this->name, GF_LOG_ERROR, + "setattr (lstat) on %s failed: %s", real_path, + strerror (op_errno)); + goto out; + } + + op_ret = 0; + +out: + SET_TO_OLD_FS_ID (); + + STACK_UNWIND (frame, op_ret, op_errno, &statpre, &statpost); + + return 0; +} + +int32_t +posix_do_fchown (xlator_t *this, + int fd, + struct stat *stbuf, + int32_t valid) +{ + int ret = -1; + uid_t uid = -1; + gid_t gid = -1; + + if (valid & GF_SET_ATTR_UID) + uid = stbuf->st_uid; + + if (valid & GF_SET_ATTR_GID) + gid = stbuf->st_gid; + + ret = fchown (fd, uid, gid); + + return ret; +} + + +int32_t +posix_do_fchmod (xlator_t *this, + int fd, struct stat *stbuf) +{ + return fchmod (fd, stbuf->st_mode); +} + +static int +posix_do_futimes (xlator_t *this, + int fd, + struct stat *stbuf) +{ + errno = ENOSYS; + return -1; +} + +int +posix_fsetattr (call_frame_t *frame, xlator_t *this, + fd_t *fd, struct stat *stbuf, int32_t valid) +{ + int32_t op_ret = -1; + int32_t op_errno = 0; + struct stat statpre = {0,}; + struct stat statpost = {0,}; + struct posix_fd *pfd = NULL; + uint64_t tmp_pfd = 0; + int32_t ret = -1; + + DECLARE_OLD_FS_ID_VAR; + + SET_FS_ID (frame->root->uid, frame->root->gid); + + VALIDATE_OR_GOTO (frame, out); + VALIDATE_OR_GOTO (this, out); + VALIDATE_OR_GOTO (fd, out); + + ret = fd_ctx_get (fd, this, &tmp_pfd); + if (ret < 0) { + op_errno = -ret; + gf_log (this->name, GF_LOG_DEBUG, + "pfd is NULL from fd=%p", fd); + goto out; + } + pfd = (struct posix_fd *)(long)tmp_pfd; + + op_ret = fstat (pfd->fd, &statpre); + if (op_ret == -1) { + op_errno = errno; + gf_log (this->name, GF_LOG_ERROR, + "fsetattr (fstat) failed on fd=%p: %s", fd, + strerror (op_errno)); + goto out; + } + + if (valid & GF_SET_ATTR_MODE) { + op_ret = posix_do_fchmod (this, pfd->fd, stbuf); + if (op_ret == -1) { + op_errno = errno; + gf_log (this->name, GF_LOG_ERROR, + "fsetattr (fchmod) failed on fd=%p: %s", + fd, strerror (op_errno)); + goto out; + } + } + + if (valid & (GF_SET_ATTR_UID | GF_SET_ATTR_GID)) { + op_ret = posix_do_fchown (this, pfd->fd, stbuf, valid); + if (op_ret == -1) { + op_errno = errno; + gf_log (this->name, GF_LOG_ERROR, + "fsetattr (fchown) failed on fd=%p: %s", + fd, strerror (op_errno)); + goto out; + } + + } + + if (valid & (GF_SET_ATTR_ATIME | GF_SET_ATTR_MTIME)) { + op_ret = posix_do_futimes (this, pfd->fd, stbuf); + if (op_ret == -1) { + op_errno = errno; + gf_log (this->name, GF_LOG_ERROR, + "fsetattr (futimes) on failed fd=%p: %s", fd, + strerror (op_errno)); + goto out; + } + } + + op_ret = fstat (pfd->fd, &statpost); + if (op_ret == -1) { + op_errno = errno; + gf_log (this->name, GF_LOG_ERROR, + "fsetattr (fstat) failed on fd=%p: %s", fd, + strerror (op_errno)); + goto out; + } + + op_ret = 0; + +out: + SET_TO_OLD_FS_ID (); + + STACK_UNWIND (frame, op_ret, op_errno, &statpre, &statpost); + + return 0; +} + int32_t posix_opendir (call_frame_t *frame, xlator_t *this, loc_t *loc, fd_t *fd) @@ -1360,139 +1623,6 @@ posix_link (call_frame_t *frame, xlator_t *this, } -int -posix_chmod (call_frame_t *frame, xlator_t *this, - loc_t *loc, mode_t mode) -{ - int32_t op_ret = -1; - int32_t op_errno = 0; - char *real_path = 0; - struct stat stbuf = {0,}; - struct posix_private *priv = NULL; - - DECLARE_OLD_FS_ID_VAR; - - VALIDATE_OR_GOTO (frame, out); - VALIDATE_OR_GOTO (this, out); - VALIDATE_OR_GOTO (loc, out); - - priv = this->private; - VALIDATE_OR_GOTO (priv, out); - - SET_FS_ID (frame->root->uid, frame->root->gid); - MAKE_REAL_PATH (real_path, this, loc->path); - - if (S_ISLNK (loc->inode->st_mode)) { - /* chmod on a link should always succeed */ - op_ret = lstat (real_path, &stbuf); - if (op_ret == -1) { - op_errno = errno; - gf_log (this->name, GF_LOG_ERROR, - "lstat on %s failed: %s", - real_path, strerror (op_errno)); - goto out; - } - - if (priv->span_devices) { - posix_scale_st_ino (priv, &stbuf); - } - - op_ret = 0; - goto out; - } - - op_ret = lchmod (real_path, mode); - if ((op_ret == -1) && (errno == ENOSYS)) { - gf_log (this->name, GF_LOG_TRACE, - "lchmod not implemented, falling back to chmod"); - op_ret = chmod (real_path, mode); - } - - if (op_ret == -1) { - op_errno = errno; - gf_log (this->name, GF_LOG_ERROR, "chmod on %s failed: %s", - loc->path, strerror (op_errno)); - goto out; - } - - op_ret = lstat (real_path, &stbuf); - if (op_ret == -1) { - op_errno = errno; - gf_log (this->name, GF_LOG_ERROR, "lstat on %s failed: %s", - real_path, strerror (op_errno)); - goto out; - } - - if (priv->span_devices) { - posix_scale_st_ino (priv, &stbuf); - } - - op_ret = 0; - - out: - SET_TO_OLD_FS_ID (); - - STACK_UNWIND (frame, op_ret, op_errno, &stbuf); - - return 0; -} - - -int -posix_chown (call_frame_t *frame, xlator_t *this, - loc_t *loc, uid_t uid, gid_t gid) -{ - int32_t op_ret = -1; - int32_t op_errno = 0; - char *real_path = 0; - struct stat stbuf = {0,}; - struct posix_private *priv = NULL; - - DECLARE_OLD_FS_ID_VAR; - - VALIDATE_OR_GOTO (frame, out); - VALIDATE_OR_GOTO (this, out); - VALIDATE_OR_GOTO (loc, out); - - priv = this->private; - VALIDATE_OR_GOTO (priv, out); - - SET_FS_ID (frame->root->uid, frame->root->gid); - MAKE_REAL_PATH (real_path, this, loc->path); - - op_ret = lchown (real_path, uid, gid); - if (op_ret == -1) { - op_errno = errno; - gf_log (this->name, GF_LOG_ERROR, - "lchown on %s failed: %s", - loc->path, strerror (op_errno)); - goto out; - } - - op_ret = lstat (real_path, &stbuf); - if (op_ret == -1) { - op_errno = errno; - gf_log (this->name, GF_LOG_ERROR, - "lstat on %s failed: %s", - real_path, strerror (op_errno)); - goto out; - } - - if (priv->span_devices) { - posix_scale_st_ino (priv, &stbuf); - } - - op_ret = 0; - - out: - SET_TO_OLD_FS_ID (); - - STACK_UNWIND (frame, op_ret, op_errno, &stbuf); - - return 0; -} - - int32_t posix_truncate (call_frame_t *frame, xlator_t *this, @@ -1549,70 +1679,6 @@ posix_truncate (call_frame_t *frame, } -int -posix_utimens (call_frame_t *frame, xlator_t *this, - loc_t *loc, struct timespec ts[2]) -{ - int32_t op_ret = -1; - int32_t op_errno = 0; - char *real_path = 0; - struct stat stbuf = {0,}; - struct timeval tv[2] = {{0,},{0,}}; - struct posix_private *priv = NULL; - - DECLARE_OLD_FS_ID_VAR; - - VALIDATE_OR_GOTO (frame, out); - VALIDATE_OR_GOTO (this, out); - VALIDATE_OR_GOTO (loc, out); - - priv = this->private; - VALIDATE_OR_GOTO (priv, out); - - SET_FS_ID (frame->root->uid, frame->root->gid); - MAKE_REAL_PATH (real_path, this, loc->path); - - tv[0].tv_sec = ts[0].tv_sec; - tv[0].tv_usec = ts[0].tv_nsec / 1000; - tv[1].tv_sec = ts[1].tv_sec; - tv[1].tv_usec = ts[1].tv_nsec / 1000; - - op_ret = lutimes (real_path, tv); - if ((op_ret == -1) && (errno == ENOSYS)) { - op_ret = utimes (real_path, tv); - } - - if (op_ret == -1) { - op_errno = errno; - gf_log (this->name, GF_LOG_ERROR, - "utimes on %s failed: %s", real_path, - strerror (op_errno)); - goto out; - } - - op_ret = lstat (real_path, &stbuf); - if (op_ret == -1) { - op_errno = errno; - gf_log (this->name, GF_LOG_ERROR, - "lstat on %s failed: %s", real_path, - strerror (op_errno)); - goto out; - } - - if (priv->span_devices) { - posix_scale_st_ino (priv, &stbuf); - } - - op_ret = 0; - - out: - SET_TO_OLD_FS_ID (); - - STACK_UNWIND (frame, op_ret, op_errno, &stbuf); - - return 0; -} - int32_t posix_create (call_frame_t *frame, xlator_t *this, loc_t *loc, int32_t flags, mode_t mode, @@ -3382,135 +3448,6 @@ posix_ftruncate (call_frame_t *frame, xlator_t *this, return 0; } -int32_t -posix_fchown (call_frame_t *frame, xlator_t *this, - fd_t *fd, uid_t uid, gid_t gid) -{ - int32_t op_ret = -1; - int32_t op_errno = 0; - int _fd = -1; - struct stat buf = {0,}; - struct posix_fd *pfd = NULL; - int ret = -1; - uint64_t tmp_pfd = 0; - struct posix_private *priv = NULL; - - DECLARE_OLD_FS_ID_VAR; - - SET_FS_ID (frame->root->uid, frame->root->gid); - - VALIDATE_OR_GOTO (frame, out); - VALIDATE_OR_GOTO (this, out); - VALIDATE_OR_GOTO (fd, out); - - priv = this->private; - VALIDATE_OR_GOTO (priv, out); - - ret = fd_ctx_get (fd, this, &tmp_pfd); - if (ret < 0) { - gf_log (this->name, GF_LOG_DEBUG, - "pfd is NULL, fd=%p", fd); - op_errno = -ret; - goto out; - } - pfd = (struct posix_fd *)(long)tmp_pfd; - - _fd = pfd->fd; - - op_ret = fchown (_fd, uid, gid); - if (op_ret == -1) { - op_errno = errno; - gf_log (this->name, GF_LOG_ERROR, "fchown failed on fd=%p: %s", - fd, strerror (op_errno)); - goto out; - } - - op_ret = fstat (_fd, &buf); - if (op_ret == -1) { - op_errno = errno; - gf_log (this->name, GF_LOG_ERROR, "fstat failed on fd=%p: %s", - fd, strerror (op_errno)); - goto out; - } - - if (priv->span_devices) { - posix_scale_st_ino (priv, &buf); - } - - op_ret = 0; - - out: - SET_TO_OLD_FS_ID (); - - STACK_UNWIND (frame, op_ret, op_errno, &buf); - - return 0; -} - - -int32_t -posix_fchmod (call_frame_t *frame, xlator_t *this, - fd_t *fd, mode_t mode) -{ - int32_t op_ret = -1; - int32_t op_errno = 0; - int _fd = -1; - struct stat buf = {0,}; - struct posix_fd *pfd = NULL; - int ret = -1; - uint64_t tmp_pfd = 0; - struct posix_private *priv = NULL; - - DECLARE_OLD_FS_ID_VAR; - - SET_FS_ID (frame->root->uid, frame->root->gid); - - VALIDATE_OR_GOTO (frame, out); - VALIDATE_OR_GOTO (this, out); - VALIDATE_OR_GOTO (fd, out); - - priv = this->private; - VALIDATE_OR_GOTO (priv, out); - - ret = fd_ctx_get (fd, this, &tmp_pfd); - if (ret < 0) { - gf_log (this->name, GF_LOG_DEBUG, - "pfd is NULL fd=%p", fd); - op_errno = -ret; - goto out; - } - pfd = (struct posix_fd *)(long)tmp_pfd; - - _fd = pfd->fd; - - op_ret = fchmod (_fd, mode); - - if (op_ret == -1) { - op_errno = errno; - gf_log (this->name, GF_LOG_ERROR, - "fchmod failed on fd=%p: %s", fd, strerror (errno)); - goto out; - } - - op_ret = fstat (_fd, &buf); - if (op_ret == -1) { - op_errno = errno; - gf_log (this->name, GF_LOG_ERROR, - "fstat failed on fd=%p: %s", - fd, strerror (errno)); - goto out; - } - - op_ret = 0; - - out: - SET_TO_OLD_FS_ID (); - - STACK_UNWIND (frame, op_ret, op_errno, &buf); - - return 0; -} - static int same_file_type (mode_t m1, mode_t m2) @@ -4638,10 +4575,7 @@ struct xlator_fops fops = { .symlink = posix_symlink, .rename = posix_rename, .link = posix_link, - .chmod = posix_chmod, - .chown = posix_chown, .truncate = posix_truncate, - .utimens = posix_utimens, .create = posix_create, .open = posix_open, .readv = posix_readv, @@ -4663,14 +4597,14 @@ struct xlator_fops fops = { .finodelk = posix_finodelk, .entrylk = posix_entrylk, .fentrylk = posix_fentrylk, - .fchown = posix_fchown, - .fchmod = posix_fchmod, .setdents = posix_setdents, .getdents = posix_getdents, .checksum = posix_checksum, .rchecksum = posix_rchecksum, .xattrop = posix_xattrop, .fxattrop = posix_fxattrop, + .setattr = posix_setattr, + .fsetattr = posix_fsetattr, }; struct xlator_cbks cbks = { |