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/cluster | |
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/cluster')
-rw-r--r-- | xlators/cluster/afr/src/afr-inode-write.c | 1079 | ||||
-rw-r--r-- | xlators/cluster/afr/src/afr-inode-write.h | 8 | ||||
-rw-r--r-- | xlators/cluster/afr/src/afr-self-heal-common.c | 61 | ||||
-rw-r--r-- | xlators/cluster/afr/src/afr-self-heal-entry.c | 114 | ||||
-rw-r--r-- | xlators/cluster/afr/src/afr-self-heal-metadata.c | 58 | ||||
-rw-r--r-- | xlators/cluster/afr/src/afr.c | 2 | ||||
-rw-r--r-- | xlators/cluster/afr/src/afr.h | 16 | ||||
-rw-r--r-- | xlators/cluster/dht/src/dht-common.c | 455 | ||||
-rw-r--r-- | xlators/cluster/dht/src/dht-common.h | 2 | ||||
-rw-r--r-- | xlators/cluster/dht/src/dht.c | 7 | ||||
-rw-r--r-- | xlators/cluster/dht/src/nufa.c | 6 | ||||
-rw-r--r-- | xlators/cluster/ha/src/ha.c | 240 | ||||
-rw-r--r-- | xlators/cluster/map/src/map.c | 238 | ||||
-rw-r--r-- | xlators/cluster/stripe/src/stripe.c | 354 | ||||
-rw-r--r-- | xlators/cluster/stripe/src/stripe.h | 2 | ||||
-rw-r--r-- | xlators/cluster/unify/src/unify.c | 325 | ||||
-rw-r--r-- | xlators/cluster/unify/src/unify.h | 2 |
17 files changed, 814 insertions, 2155 deletions
diff --git a/xlators/cluster/afr/src/afr-inode-write.c b/xlators/cluster/afr/src/afr-inode-write.c index 6a2774bee72..591f7cd49aa 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 358d25b5271..b92a66e1f41 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 38fe1e6e7f3..4a260ed903e 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 80608dbd262..b3bb6720917 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 966b754b3d2..686446b5f30 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 5c2320715b6..ef93e5078a2 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 210cd2e2047..37dc139599e 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 62f3822a5e1..d5d6f4c3e2f 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 f5c95b4cb2b..8573b9f5b21 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 46f3b87000c..770629711f6 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 c8ce7fdee14..6be7206bfb5 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 b938071edde..b380cb1e9a7 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 98d6b33b04b..3eb49e2eddc 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 ee230a9c3a2..5a02d17bc2e 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 5ffbc367094..7c72f5c8f8d 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 35c108963e3..b641fb3307e 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 9841e5c7a95..a745a9414fc 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; |