📄 client-protocol.c
字号:
request = get_new_dict (); dict_set (request, "FD", str_to_data (fd_str)); dict_set (request, "MODE", data_from_uint64 (mode)); ret = client_protocol_xfer (frame, this, GF_OP_TYPE_FOP_REQUEST, GF_FOP_FCHMOD, request); freee (fd_str); dict_destroy (request); return 0;}/* * client_fchown - * * @frame: * @this: * @fd: * @uid: * @gid: * */int32_tclient_fchown (call_frame_t *frame, xlator_t *this, fd_t *fd, uid_t uid, gid_t gid){ int32_t ret = -1; char *fd_str = NULL; dict_t *request = NULL; data_t *fd_data = NULL; if (fd && fd->ctx) fd_data = dict_get (fd->ctx, this->name); if (!fd_data) { gf_log (this->name, GF_LOG_ERROR, ": returning EBADFD"); TRAP_ON (fd_data == NULL); frame->root->rsp_refs = NULL; STACK_UNWIND (frame, -1, EBADFD); return 0; } fd_str = strdup (data_to_str (fd_data)); request = get_new_dict (); dict_set (request, "FD", str_to_data (fd_str)); dict_set (request, "UID", data_from_uint64 (uid)); dict_set (request, "GID", data_from_uint64 (gid)); ret = client_protocol_xfer (frame, this, GF_OP_TYPE_FOP_REQUEST, GF_FOP_FCHOWN, request); freee (fd_str); dict_destroy (request); return 0;}/* * MGMT_OPS *//** * client_stats - stats function for client protocol * @frame: call frame * @this: this translator structure * @flags: * * external reference through client_protocol_xlator->mops->stats */int32_t client_stats (call_frame_t *frame, xlator_t *this, int32_t flags){ int32_t ret; dict_t *request = get_new_dict (); /* without this dummy key the server crashes */ dict_set (request, "FLAGS", data_from_int64 (0)); ret = client_protocol_xfer (frame, this, GF_OP_TYPE_MOP_REQUEST, GF_MOP_STATS, request); dict_destroy (request); return ret;}/** * client_fsck - fsck (file system check) function for client protocol * @frame: call frame * @this: this translator structure * @flags: * * external reference through client_protocol_xlator->mops->fsck */int32_t client_fsck (call_frame_t *frame, xlator_t *this, int32_t flags){ gf_log (this->name, GF_LOG_ERROR, "Function not implemented"); STACK_UNWIND (frame, -1, ENOSYS); return 0;}/** * client_lock - lock function for client protocol * @frame: call frame * @this: this translator structure * @name: pathname of file to lock * * external reference through client_protocol_xlator->fops->lock */int32_t client_lock (call_frame_t *frame, xlator_t *this, const char *name){ dict_t *request = get_new_dict (); int32_t ret = -1; dict_set (request, "PATH", str_to_data ((char *)name)); ret = client_protocol_xfer (frame, this, GF_OP_TYPE_MOP_REQUEST, GF_MOP_LOCK, request); dict_destroy (request); return ret;}/** * client_unlock - management function of client protocol to unlock * @frame: call frame * @this: this translator structure * @name: pathname of the file whose lock has to be released * * external reference through client_protocol_xlator->mops->unlock */int32_t client_unlock (call_frame_t *frame, xlator_t *this, const char *name){ dict_t *request = get_new_dict (); int32_t ret = -1; dict_set (request, "PATH", str_to_data ((char *)name)); ret = client_protocol_xfer (frame, this, GF_OP_TYPE_MOP_REQUEST, GF_MOP_UNLOCK, request); dict_destroy (request); return ret;}/** * client_listlocks - management function of client protocol to list locks * @frame: call frame * @this: this translator structure * @pattern: * * external reference through client_protocol_xlator->mops->listlocks */int32_t client_listlocks (call_frame_t *frame, xlator_t *this, const char *pattern){ dict_t *request = get_new_dict (); int32_t ret = -1; dict_set (request, "OP", data_from_uint64 (0xcafebabe)); ret = client_protocol_xfer (frame, this, GF_OP_TYPE_MOP_REQUEST, GF_MOP_LISTLOCKS, request); dict_destroy (request); return ret;}/* Callbacks */#define CLIENT_PRIVATE(frame) (((transport_t *)(frame->this->private))->xl_private)/* * client_chown_cbk - * * @frame: * @args: * * not for external reference */int32_tclient_fchown_cbk (call_frame_t *frame, dict_t *args){ data_t *ret_data = NULL, *errno_data = NULL, *stat_data = NULL; int32_t op_ret = -1; int32_t op_errno = ENOTCONN; char *stat_str = NULL; struct stat *stbuf = NULL; ret_data = dict_get (args, "RET"); errno_data = dict_get (args, "ERRNO"); stat_data = dict_get (args, "STAT"); if (!ret_data || !errno_data) { gf_log (frame->this->name, GF_LOG_ERROR, "no proper reply from server, returning ENOTCONN"); STACK_UNWIND (frame, op_ret, op_errno, stbuf); return -1; } op_ret = data_to_uint64 (ret_data); op_errno = data_to_uint64 (errno_data); if (op_ret >= 0) { if (stat_data) { stat_str = data_to_str (stat_data); stbuf = str_to_stat (stat_str); } else { gf_log (frame->this->name, GF_LOG_ERROR, "no proper reply from server, returning EINVAL"); op_ret = -1; op_errno = EINVAL; } } STACK_UNWIND (frame, op_ret, op_errno, stbuf); if (stbuf) free (stbuf); return 0;}/* * client_fchmod_cbk * * @frame: * @args: * * not for external reference */int32_tclient_fchmod_cbk (call_frame_t *frame, dict_t *args){ int32_t op_ret = -1; int32_t op_errno = ENOTCONN; data_t *ret_data = NULL, *errno_data = NULL, *stat_data = NULL; char *stat_str = NULL; struct stat *stbuf = NULL; ret_data = dict_get (args, "RET"); errno_data = dict_get (args, "ERRNO"); stat_data = dict_get (args, "STAT"); if (!ret_data || !errno_data) { gf_log (frame->this->name, GF_LOG_ERROR, "no proper reply from server, returning ENOTCONN"); STACK_UNWIND (frame, op_ret, op_errno, stbuf); return -1; } op_ret = data_to_uint64 (ret_data); op_errno = data_to_uint64 (errno_data); if (op_ret >= 0) { if (stat_data) { stat_str = data_to_str (stat_data); stbuf = str_to_stat (stat_str); } else { gf_log (frame->this->name, GF_LOG_ERROR, "no proper reply from server, returning EINVAL"); op_ret = -1; op_errno = EINVAL; } } STACK_UNWIND (frame, op_ret, op_errno, stbuf); if (stbuf) free (stbuf); return 0;}/* * client_create_cbk - create callback function for client protocol * @frame: call frame * @args: arguments in dictionary * * not for external reference */int32_t client_create_cbk (call_frame_t *frame, dict_t *args){ int32_t op_ret = 0; int32_t op_errno = ENOTCONN; char *stat_buf = NULL; struct stat *stbuf = NULL; client_proto_priv_t *priv = NULL; inode_t *inode = NULL; fd_t *fd = NULL; data_t *stat_data = dict_get (args, "STAT"); data_t *ret_data = dict_get (args, "RET"); data_t *err_data = dict_get (args, "ERRNO"); data_t *fd_data = dict_get (args, "FD"); client_local_t *local = frame->local; fd = local->fd; inode = local->inode; if (!ret_data || !err_data) { gf_log (frame->this->name, GF_LOG_ERROR, "no proper reply from server, returning ENOTCONN"); STACK_UNWIND (frame, -1, ENOTCONN, fd, inode, NULL); return 0; } op_ret = data_to_int32 (ret_data); op_errno = data_to_int32 (err_data); if (op_ret >= 0) { /* handle fd */ if (fd_data && stat_data) { char *remote_fd = strdup (data_to_str (fd_data)); char *key = NULL; stat_buf = data_to_str (stat_data); stbuf = str_to_stat (stat_buf); /* add newly created file's inode to inode table */ dict_set (inode->ctx, (frame->this)->name, data_from_uint64 (stbuf->st_ino)); dict_set (fd->ctx, (frame->this)->name, data_from_dynstr (remote_fd)); asprintf (&key, "%p", fd); priv = CLIENT_PRIVATE (frame); pthread_mutex_lock (&priv->lock); { dict_set (priv->saved_fds, key, str_to_data ("")); } pthread_mutex_unlock (&priv->lock); free (key); } else { gf_log (frame->this->name, GF_LOG_ERROR, "no proper reply from server, returning EINVAL"); op_ret = -1; op_errno = EINVAL; } } STACK_UNWIND (frame, op_ret, op_errno, fd, inode, stbuf); if (stbuf) free (stbuf); return 0;}/* * client_open_cbk - open callback for client protocol * @frame: call frame * @args: argument dictionary * * not for external reference */int32_t client_open_cbk (call_frame_t *frame, dict_t *args){ data_t *ret_data = dict_get (args, "RET"); data_t *err_data = dict_get (args, "ERRNO"); data_t *fd_data = dict_get (args, "FD"); client_proto_priv_t *priv = NULL; int32_t op_ret = -1; int32_t op_errno = 0; client_local_t *local = frame->local; fd_t *fd = local->fd; if (!ret_data || !err_data) { gf_log (frame->this->name, GF_LOG_ERROR, "no proper reply from server, returning ENOTCONN"); STACK_UNWIND (frame, -1, ENOTCONN, fd); return 0; } op_ret = data_to_int32 (ret_data); op_errno = data_to_int32 (err_data); fd = local->fd; if (op_ret >= 0) { if (fd_data) { /* handle fd */ char *remote_fd = strdup (data_to_str (fd_data)); char *key = NULL; dict_set (fd->ctx, (frame->this)->name, data_from_dynstr (remote_fd)); asprintf (&key, "%p", fd); priv = CLIENT_PRIVATE (frame); pthread_mutex_lock (&priv->lock); { dict_set (priv->saved_fds, key, str_to_data ("")); } pthread_mutex_unlock (&priv->lock); freee (key); } else { gf_log (frame->this->name, GF_LOG_ERROR, "no proper reply from server, returning EINVAL"); op_ret = -1; op_errno = EINVAL; } } STACK_UNWIND (frame, op_ret, op_errno, fd); return 0;}/* * client_stat_cbk - stat callback for client protocol * @frame: call frame * @args: arguments dictionary * * not for external reference */int32_t client_stat_cbk (call_frame_t *frame, dict_t *args){ data_t *buf_data = dict_get (args, "STAT"); data_t *ret_data = dict_get (args, "RET"); data_t *err_data = dict_get (args, "ERRNO"); int32_t op_ret = -1; int32_t op_errno = 0; char *buf = NULL; struct stat *stbuf = NULL; if (!ret_data || !err_data) { gf_log (frame->this->name, GF_LOG_ERROR, "no proper reply from server, returning ENOTCONN"); STACK_UNWIND (frame, -1, ENOTCONN, NULL); return 0; } op_ret = data_to_int32 (ret_data); op_errno = data_to_int32 (err_data); if (op_ret >= 0) { if (buf_data) { buf = data_to_str (buf_data); stbuf = str_to_stat (buf); } else { gf_log (frame->this->name, GF_LOG_ERROR, "no proper reply from server, returning EINVAL"); op_ret = -1; op_errno = EINVAL; } } STACK_UNWIND (frame, op_ret, op_errno, stbuf); if (stbuf) freee (stbuf); return 0;}/* * client_utimens_cbk - utimens callback for client protocol * @frame: call frame * @args: argument dictionary * * not for external reference */ int32_t client_utimens_cbk (call_frame_t *frame, dict_t *args){ data_t *buf_data = dict_get (args, "STAT"); data_t *ret_data = dict_get (args, "RET"); data_t *err_data = dict_get (args, "ERRNO"); int32_t op_ret = -1; int32_t op_errno = 0; char *buf = NULL; struct stat *stbuf = NULL; if (!ret_data || !err_data) { gf_log (frame->this->name, GF_LOG_ERROR, "no proper reply from server, returning ENOTCONN"); STACK_UNWIND (frame, -1, ENOTCONN, NULL); return 0; } op_ret = data_to_int32 (ret_data); op_errno = data_to_int32 (err_data); if (op_ret >= 0) { if (buf_data) { buf = data_to_str (buf_data); stbuf = str_to_stat (buf); } else { gf_log (frame->this->name, GF_LOG_ERROR, "no proper reply from server, returning EINVAL"); op_ret = -1; op_errno = EINVAL; } } STACK_UNWIND (frame, op_re
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -