📄 unify.c
字号:
struct stat *buf){ /* call_frame_t *bg_frame = NULL; */ unify_local_t *local = frame->local; unify_private_t *priv = this->private; int16_t *list = local->list; int16_t index = 0; int32_t call_count = 0; if (op_ret == -1) { /* No need to send truncate request to other servers, * as namespace action failed */ gf_log (this->name, GF_LOG_ERROR, "fop failed on namespace (%d)", op_errno); unify_local_wipe (local); STACK_UNWIND (frame, op_ret, op_errno, buf); return 0; } local->op_ret = op_ret; local->op_errno = op_errno; local->st_ino = buf->st_ino; /* Send chmod request to all the nodes now */ local->call_count = 0; for (index = 0; list[index] != -1; index++) { if (NS(this) != priv->xl_array[list[index]]) { local->call_count++; call_count++; } } if (local->call_count) { local->stbuf = *buf; for (index = 0; list[index] != -1; index++) { if (priv->xl_array[list[index]] != NS(this)) { loc_t tmp_loc = { .inode = local->inode, .path = local->path, }; STACK_WIND (frame, unify_buf_cbk, priv->xl_array[list[index]], priv->xl_array[list[index]]->fops->truncate, &tmp_loc, local->offset); if (!--call_count) break; } } return 0; } /* If call_count is 0, do STACK_UNWIND here */ unify_local_wipe (local); /* Sending '0' as its successful on NS node */ STACK_UNWIND (frame, 0, 0, &local->stbuf); return 0;}/** * unify_truncate - */int32_tunify_truncate (call_frame_t *frame, xlator_t *this, loc_t *loc, off_t offset){ unify_local_t *local = NULL; UNIFY_CHECK_INODE_CTX_AND_UNWIND_ON_ERR (loc); /* Initialization */ INIT_LOCAL (frame, local); local->inode = loc->inode; local->offset = offset; local->path = strdup (loc->path); if (!local->path) { gf_log (this->name, GF_LOG_CRITICAL, "Not enough memory :O"); STACK_UNWIND (frame, -1, ENOMEM, NULL); return 0; } local->list = data_to_ptr (dict_get (loc->inode->ctx, this->name)); STACK_WIND (frame, unify_ns_truncate_cbk, NS(this), NS(this)->fops->stat, loc); return 0;}/** * unify_ns_utimens_cbk - */int32_t unify_ns_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 *bg_frame = NULL; */ unify_local_t *local = frame->local; unify_private_t *priv = this->private; int16_t *list = local->list; int16_t index = 0; int32_t call_count = 0; if (op_ret == -1) { /* No need to send chmod request to other servers, * as namespace action failed */ gf_log (this->name, GF_LOG_ERROR, "fop failed on namespace (%d)", op_errno); unify_local_wipe (local); STACK_UNWIND (frame, op_ret, op_errno, buf); return 0; } local->op_ret = 0; local->op_errno = op_errno; local->st_ino = buf->st_ino; /* Send utimes request to all the nodes now */ local->call_count = 0; for (index = 0; local->list[index] != -1; index++) { if (NS(this) != priv->xl_array[local->list[index]]) { local->call_count++; call_count++; } } if (local->call_count) { local->stbuf = *buf; for (index = 0; list[index] != -1; index++) { if (priv->xl_array[list[index]] != NS(this)) { loc_t tmp_loc = { .inode = local->inode, .path = local->path, }; STACK_WIND (frame, unify_buf_cbk, priv->xl_array[list[index]], priv->xl_array[list[index]]->fops->utimens, &tmp_loc, local->tv); if (!--call_count) break; } } return 0; } unify_local_wipe (local); /* Sending '0' as its successful on NS node */ STACK_UNWIND (frame, 0, 0, &local->stbuf); return 0;}/** * 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_CHECK_INODE_CTX_AND_UNWIND_ON_ERR (loc); /* Initialization */ INIT_LOCAL (frame, local); local->inode = loc->inode; memcpy (local->tv, tv, 2 * sizeof (struct timespec)); local->path = strdup (loc->path); if (!local->path) { gf_log (this->name, GF_LOG_CRITICAL, "Not enough memory :O"); STACK_UNWIND (frame, -1, ENOMEM, NULL); return 0; } local->list = data_to_ptr (dict_get (loc->inode->ctx, this->name)); STACK_WIND (frame, unify_ns_utimens_cbk, NS(this), NS(this)->fops->utimens, loc, tv); return 0;}/** * unify_readlink_cbk - */int32_tunify_readlink_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno, const char *path){ STACK_UNWIND (frame, op_ret, op_errno, path); return 0;}/** * unify_readlink - Read the link only from the storage node. */int32_tunify_readlink (call_frame_t *frame, xlator_t *this, loc_t *loc, size_t size){ unify_private_t *priv = this->private; int32_t entry_count = 0; int16_t *list = NULL; int16_t index = 0; UNIFY_CHECK_INODE_CTX_AND_UNWIND_ON_ERR (loc); list = data_to_ptr (dict_get (loc->inode->ctx, this->name)); for (index = 0; list[index] != -1; index++) entry_count++; if (entry_count == 2) { for (index = 0; list[index] != -1; index++) { if (priv->xl_array[list[index]] != NS(this)) { STACK_WIND (frame, unify_readlink_cbk, priv->xl_array[list[index]], priv->xl_array[list[index]]->fops->readlink, loc, size); break; } } } else { gf_log (this->name, GF_LOG_ERROR, "returning ENOENT, no softlink files found on storage node"); STACK_UNWIND (frame, -1, ENOENT, NULL); } return 0;}/** * unify_unlink_cbk - */int32_tunify_unlink_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno){ int32_t callcnt = 0; unify_local_t *local = frame->local; LOCK (&frame->lock); { callcnt = --local->call_count; if (op_ret == 0) local->op_ret = 0; } UNLOCK (&frame->lock); if (!callcnt) { unify_local_wipe (local); STACK_UNWIND (frame, local->op_ret, local->op_errno); } return 0;}/** * unify_unlink - */int32_tunify_unlink (call_frame_t *frame, xlator_t *this, loc_t *loc){ unify_private_t *priv = this->private; unify_local_t *local = NULL; int16_t *list = NULL; int16_t index = 0; UNIFY_CHECK_INODE_CTX_AND_UNWIND_ON_ERR (loc); /* Initialization */ INIT_LOCAL (frame, local); local->inode = loc->inode; list = data_to_ptr (dict_get (loc->inode->ctx, this->name)); for (index = 0; list[index] != -1; index++) local->call_count++; if (local->call_count) { for (index = 0; list[index] != -1; index++) { char need_break = list[index+1] == -1; STACK_WIND (frame, unify_unlink_cbk, priv->xl_array[list[index]], priv->xl_array[list[index]]->fops->unlink, loc); if (need_break) break; } } else { STACK_UNWIND (frame, -1, ENOENT); } return 0;}/** * unify_readv_cbk - */int32_tunify_readv_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno, struct iovec *vector, int32_t count, struct stat *stbuf){ STACK_UNWIND (frame, op_ret, op_errno, vector, count, stbuf); return 0;}/** * unify_readv - */int32_tunify_readv (call_frame_t *frame, xlator_t *this, fd_t *fd, size_t size, off_t offset){ xlator_t *child = NULL; UNIFY_CHECK_FD_CTX_AND_UNWIND_ON_ERR (fd); child = data_to_ptr (dict_get (fd->ctx, this->name)); STACK_WIND (frame, unify_readv_cbk, child, child->fops->readv, fd, size, offset); return 0;}/** * unify_writev_cbk - */int32_tunify_writev_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno, struct stat *stbuf){ STACK_UNWIND (frame, op_ret, op_errno, stbuf); return 0;}/** * unify_writev - */int32_tunify_writev (call_frame_t *frame, xlator_t *this, fd_t *fd, struct iovec *vector, int32_t count, off_t off){ xlator_t *child = NULL; UNIFY_CHECK_FD_CTX_AND_UNWIND_ON_ERR (fd); child = data_to_ptr (dict_get (fd->ctx, this->name)); STACK_WIND (frame, unify_writev_cbk, child, child->fops->writev, fd, vector, count, off); return 0;}/** * unify_ftruncate - */int32_tunify_ftruncate (call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset){ xlator_t *child = NULL; unify_local_t *local = NULL; UNIFY_CHECK_FD_CTX_AND_UNWIND_ON_ERR(fd); /* Initialization */ INIT_LOCAL (frame, local); child = data_to_ptr (dict_get (fd->ctx, this->name)); local->call_count = 2; STACK_WIND (frame, unify_buf_cbk, child, child->fops->ftruncate, fd, offset); STACK_WIND (frame, unify_buf_cbk, NS(this), NS(this)->fops->fstat, fd); return 0;}/** * unify_fchmod - */int32_t unify_fchmod (call_frame_t *frame, xlator_t *this, fd_t *fd, mode_t mode){ unify_local_t *local = NULL; unify_private_t *priv = this->private; UNIFY_CHECK_FD_AND_UNWIND_ON_ERR(fd); /* Initialization */ INIT_LOCAL (frame, local); if (dict_get (fd->ctx, this->name)) { /* If its set, then its file */ xlator_t *child = NULL; child = data_to_ptr (dict_get (fd->ctx, this->name)); 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 */ int16_t *list = NULL; int16_t index = 0; if (dict_get (fd->inode->ctx, this->name)) { list = data_to_ptr (dict_get (fd->inode->ctx, this->name)); } else { gf_log (this->name, GF_LOG_ERROR, "returning EINVAL, no list found in inode ctx"); STACK_UNWIND (frame, -1, EINVAL, NULL); return 0; } for (index = 0; list[index] != -1; index++) local->call_count++; for (index = 0; list[index] != -1; index++) { char need_break = list[index+1] == -1; STACK_WIND (frame, unify_buf_cbk, priv->xl_array[list[index]], priv->xl_array[list[index]]->fops->fchmod, fd, mode); if (need_break) break; } } 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; unify_private_t *priv = this->private; UNIFY_CHECK_FD_AND_UNWIND_ON_ERR(fd); /* Initialization */ INIT_LOCAL (frame, local); if (dict_get (fd->ctx, this->name)) { /* If its set, then its file */ xlator_t *child = NULL; child = data_to_ptr (dict_get (fd->ctx, this->name)); 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 { /* this is an directory */ int16_t *list = NULL; int16_t index = 0; if (dict_get (fd->inode->ctx, this->name)) { list = data_to_ptr (dict_get (fd->inode->ctx, this->name)); } else { gf_log (this->name, GF_LOG_ERROR, "returning EINVAL, no list found in inode ctx"); STACK_UNWIND (frame, -1, EINVAL, NULL); return 0; } for (index = 0; list[index] != -1; index++) local->call_count++; for (index = 0; list[index] != -1; index++) { char need_break = list[index+1] == -1; STACK_WIND (frame, unify_buf_cbk, priv->xl_array[list[index]], priv->xl_array[list[index]]->fops->fchown, fd, uid, gid); if (need_break) break; } } return 0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -