📄 server-protocol.c
字号:
if (op_ret >= 0) { stat_buf = stat_to_str (stbuf); dict_set (reply, "STAT", data_from_dynstr (stat_buf)); } server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_FOP_UTIMENS, reply, frame->root->rsp_refs); return 0;}/* * server_chmod_cbk - chmod callback for server protocol * @frame: call frame * @cookie: * @this: * @op_ret: * @op_errno: * @stbuf: * * not for external reference */int32_tserver_chmod_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno, struct stat *stbuf){ dict_t *reply = get_new_dict (); char *stat_buf = NULL; dict_set (reply, "RET", data_from_int32 (op_ret)); dict_set (reply, "ERRNO", data_from_int32 (op_errno)); if (op_ret >= 0) { stat_buf = stat_to_str (stbuf); dict_set (reply, "STAT", data_from_dynstr (stat_buf)); } server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_FOP_CHMOD, reply, frame->root->rsp_refs); return 0;}/* * server_chown_cbk - chown callback for server protocol * @frame: call frame * @cookie: * @this: * @op_ret: * @op_errno: * @stbuf: * * not for external reference */int32_tserver_chown_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno, struct stat *stbuf){ dict_t *reply = get_new_dict (); char *stat_buf = NULL; dict_set (reply, "RET", data_from_int32 (op_ret)); dict_set (reply, "ERRNO", data_from_int32 (op_errno)); if (op_ret >= 0) { stat_buf = stat_to_str (stbuf); dict_set (reply, "STAT", data_from_dynstr (stat_buf)); } server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_FOP_CHOWN, reply, frame->root->rsp_refs); return 0;}/* * server_rmdir_cbk - rmdir callback for server protocol * @frame: call frame * @cookie: * @this: * @op_ret: * @op_errno: * * not for external reference */int32_tserver_rmdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno){ dict_t *reply = get_new_dict (); dict_set (reply, "RET", data_from_int32 (op_ret)); dict_set (reply, "ERRNO", data_from_int32 (op_errno)); server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_FOP_RMDIR, reply, frame->root->rsp_refs); return 0;}/* * server_rmelem_cbk - remove a directory entry (file, dir, link, symlink...) */int32_tserver_rmelem_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno){ dict_t *reply = get_new_dict(); dict_set (reply, "RET", data_from_int32 (op_ret)); dict_set (reply, "ERRNO", data_from_int32 (op_errno)); server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_FOP_RMELEM, reply, frame->root->rsp_refs); return 0;}/* * server_incver_cbk - increment version of the directory trusted.afr.version */int32_tserver_incver_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno){ dict_t *reply = get_new_dict(); dict_set (reply, "RET", data_from_int32(op_ret)); dict_set (reply, "ERRNO", data_from_int32(op_errno)); server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_FOP_INCVER, reply, frame->root->rsp_refs); return 0;}/* * server_inode_prune - procedure to prune inode. this procedure is called * from all fop_cbks where we get a valid inode. * @bound_xl: translator this transport is bound to * * not for external reference */int32_tserver_inode_prune (xlator_t *bound_xl){ struct list_head inode_list; inode_t *inode_curr = NULL, *inode_next = NULL; if (!bound_xl || !bound_xl->itable) return 0; INIT_LIST_HEAD (&inode_list); inode_table_prune (bound_xl->itable, &inode_list); if (!list_empty (&inode_list)) { list_for_each_entry_safe (inode_curr, inode_next, &inode_list, list) { /* gf_log (bound_xl->name, GF_LOG_DEBUG, "pruning inode = %p & ino = %d. lru=%d/%d", inode_curr, inode_curr->buf.st_ino, bound_xl->itable->lru_size, bound_xl->itable->lru_limit); */ inode_curr->ref++; /* manual ref++, to avoid moving inode_curr to active list. :( */ list_del_init (&inode_curr->list); inode_forget (inode_curr, 0); inode_unref (inode_curr); } } return 0;}/* * server_mkdir_cbk - mkdir callback for server protocol * @frame: call frame * @cookie: * @this: * @op_ret: * @op_errno: * @stbuf: * * not for external reference */int32_tserver_mkdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno, inode_t *inode, struct stat *stbuf){ dict_t *reply = get_new_dict (); char *statbuf = NULL; inode_t *server_inode = NULL; dict_set (reply, "RET", data_from_int32 (op_ret)); dict_set (reply, "ERRNO", data_from_int32 (op_errno)); if (op_ret >= 0) { { server_inode = inode_update (BOUND_XL(frame)->itable, NULL, NULL, stbuf); inode_lookup (server_inode); server_inode->ctx = inode->ctx; server_inode->generation = inode->generation; server_inode->st_mode = stbuf->st_mode; inode->ctx = NULL; inode_unref (inode); inode_unref (server_inode); } statbuf = stat_to_str (stbuf); dict_set (reply, "STAT", data_from_dynstr (statbuf)); } server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_FOP_MKDIR, reply, frame->root->rsp_refs); return 0;}/* * server_mknod_cbk - mknod callback for server protocol * @frame: call frame * @cookie: * @this: * @op_ret: * @op_errno: * @stbuf: * * not for external reference */int32_tserver_mknod_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno, inode_t *inode, struct stat *stbuf){ dict_t *reply = get_new_dict (); char *stat_buf = NULL; inode_t *server_inode = NULL; dict_set (reply, "RET", data_from_int32 (op_ret)); dict_set (reply, "ERRNO", data_from_int32 (op_errno)); if (op_ret >= 0) { { server_inode = inode_update (BOUND_XL(frame)->itable, NULL, NULL, stbuf); inode_lookup (server_inode); server_inode->ctx = inode->ctx; server_inode->generation = inode->generation; server_inode->st_mode = stbuf->st_mode; inode->ctx = NULL; inode_unref (inode); inode_unref (server_inode); } stat_buf = stat_to_str (stbuf); dict_set (reply, "STAT", data_from_dynstr (stat_buf)); dict_set (reply, "INODE", data_from_uint64 (inode->ino)); } server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_FOP_MKNOD, reply, frame->root->rsp_refs); return 0;}/* * server_fsyncdir_cbk - fsyncdir callback for server protocol * @frame: call frame * @cookie: * @this: * @op_ret: * @op_errno: * * not for external reference */int32_tserver_fsyncdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno){ dict_t *reply = get_new_dict (); dict_set (reply, "RET", data_from_int32 (op_ret)); dict_set (reply, "ERRNO", data_from_int32 (op_errno)); server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_FOP_FSYNCDIR, reply, frame->root->rsp_refs); return 0;}/* * server_readdir_cbk - readdir callback for server protocol * @frame: call frame * @cookie: * @this: * @op_ret: return value * @op_errno: errno * @entries: * @count: * * not for external reference */int32_tserver_getdents_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno, dir_entry_t *entries, int32_t count){ dict_t *reply = get_new_dict (); char *buffer = NULL; dict_set (reply, "RET", data_from_int32 (op_ret)); dict_set (reply, "ERRNO", data_from_int32 (op_errno)); if (op_ret >= 0) { dict_set (reply, "NR_ENTRIES", data_from_int32 (count)); { dir_entry_t *trav = entries->next; uint32_t len = 0; char *tmp_buf = NULL; while (trav) { len += strlen (trav->name); len += 1; len += strlen (trav->link); len += 1; /* for '\n' */ len += 256; // max possible for statbuf; trav = trav->next; } buffer = calloc (1, len); char *ptr = buffer; trav = entries->next; while (trav) { int this_len; tmp_buf = stat_to_str (&trav->buf); /* tmp_buf will have \n before \0 */ this_len = sprintf (ptr, "%s/%s%s\n", trav->name, tmp_buf, trav->link); freee (tmp_buf); trav = trav->next; ptr += this_len; } dict_set (reply, "DENTRIES", data_from_dynstr (buffer)); } } server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_FOP_GETDENTS, reply, frame->root->rsp_refs); return 0;}/* * server_getdents_cbk - getdents callback for server protocol * @frame: call frame * @cookie: * @this: * @op_ret: * @op_errno: * * not for external reference */int32_tserver_readdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno, gf_dirent_t *entries){ dict_t *reply = get_new_dict (); dict_set (reply, "RET", data_from_int32 (op_ret)); dict_set (reply, "ERRNO", data_from_int32 (op_errno)); if (op_ret >= 0) { char *cpy = memdup (entries, op_ret); dict_set (reply, "BUF", data_from_dynptr (cpy, op_ret)); } server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_FOP_READDIR, reply, frame->root->rsp_refs); return 0;}/* * server_closedir_cbk - closedir callback for server protocol * @frame: call frame * @cookie: * @this: * @op_ret: return value * @op_errno: errno * * not for external reference */int32_tserver_closedir_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno){ dict_t *reply = get_new_dict (); fd_t *fd = frame->local; frame->local = NULL; dict_set (reply, "RET", data_from_int32 (op_ret)); dict_set (reply, "ERRNO", data_from_int32 (op_errno)); server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_FOP_CLOSEDIR, reply, frame->root->rsp_refs); if (fd) fd_destroy (fd); return 0;}/* * server_opendir_cbk - opendir callback for server protocol * @frame: call frame * @cookie: * @this: * @op_ret: return value * @op_errno: errno * @fd: file descriptor structure of opened directory * * not for external reference */int32_tserver_opendir_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno, fd_t *fd){ dict_t *reply = get_new_dict (); dict_set (reply, "RET", data_from_int32 (op_ret)); dict_set (reply, "ERRNO", data_from_int32 (op_errno)); if (op_ret >= 0) { server_proto_priv_t *priv = SERVER_PRIV (frame); int32_t fd_no = -1; fd_no = gf_fd_unused_get (priv->fdtable, fd); dict_set (reply, "FD", data_from_int32 (fd_no)); } server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_FOP_OPENDIR, reply, frame->root->rsp_refs); return 0;}/* * server_statfs_cbk - statfs callback for server protocol * @frame: call frame * @cookie: * @this: * @op_ret: return value * @op_errno: errno * @buf: * * not for external reference */int32_tserver_statfs_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno, struct statvfs *buf){ dict_t *reply = get_new_dict (); dict_set (reply, "RET", data_from_int32 (op_ret)); dict_set (reply, "ERRNO", data_from_int32 (op_errno)); if (op_ret == 0) { char buffer[256] = {0,}; uint32_t bsize = buf->f_bsize; uint32_t frsize = buf->f_frsize; uint64_t blocks = buf->f_blocks; uint64_t bfree = buf->f_bfree; uint64_t bavail = buf->f_bavail; uint64_t files = buf->f_files; uint64_t ffree = buf->f_ffree; uint64_t favail = buf->f_favail; uint32_t fsid = buf->f_fsid; uint32_t flag = buf->f_flag; uint32_t namemax = buf->f_namemax; sprintf (buffer, GF_STATFS_PRINT_FMT_STR, bsize, frsize, blocks, bfree, bavail, files, ffree, favail, fsid, flag, namemax); dict_set (reply, "BUF", data_from_dynstr (strdup (buffer))); } server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_FOP_STATFS, reply, frame->root->rsp_refs); return 0;}/* * server_removexattr_cbk - removexattr callback for server protocol * @frame: call frame * @cookie: * @this: * @op_ret: return value * @op_errno: errno * * not for external reference */int32_tserver_removexattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno){ dict_t *reply = get_new_dict (); dict_set (reply, "RET", data_from_int32 (op_ret)); dict_set (reply, "ERRNO", data_from_int32 (op_errno)); server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_FOP_REMOVEXATTR, reply, frame->root->rsp_refs); return 0;}/* * server_getxattr_cbk - getxattr callback for server protocol
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -