⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 server-protocol.c

📁 分布式文件系统
💻 C
📖 第 1 页 / 共 5 页
字号:
	    server_removexattr_cbk (stub->frame,				    NULL,				    stub->frame->this,				    -1,				    ENOENT);	    freee (stub->args.removexattr.loc.path);	    freee (stub);	    return 0;	  }	  stub->args.removexattr.loc.inode = inode_ref (server_inode);	  stub->args.removexattr.loc.ino = stbuf->st_ino;	  call_resume (stub);	  break;	}	      case GF_FOP_OPENDIR:	{	  if (op_ret < 0) {	    gf_log (frame->this->name, GF_LOG_ERROR, 		    "returning ENOENT: %d (%d)", op_ret, op_errno);	    server_opendir_cbk (stub->frame,				NULL,				stub->frame->this,				-1,				ENOENT,				NULL);	    freee (stub->args.opendir.loc.path);	    freee (stub);	    return 0;	  }	  stub->args.opendir.loc.inode = inode_ref (server_inode);	  stub->args.opendir.loc.ino = stbuf->st_ino;	  call_resume (stub);	  break;	}	      case GF_FOP_ACCESS:	{	  if (op_ret < 0) {	    gf_log (frame->this->name, GF_LOG_ERROR, 		    "returning ENOENT: %d (%d)", op_ret, op_errno);	    server_access_cbk (stub->frame,			       NULL,			       stub->frame->this,			       -1,			       ENOENT);	    freee (stub->args.access.loc.path);	    freee (stub);	    return 0;	  }	  stub->args.access.loc.inode = inode_ref (server_inode);	  stub->args.access.loc.ino = stbuf->st_ino;	  call_resume (stub);	  break;	}		      case GF_FOP_UTIMENS:	{	  	  if (op_ret < 0) {	    gf_log (frame->this->name, GF_LOG_ERROR, 		    "returning ENOENT: %d (%d)", op_ret, op_errno);	    server_utimens_cbk (stub->frame,				NULL,				stub->frame->this,				-1,				ENOENT,				NULL);	    freee (stub->args.utimens.loc.path);	    freee (stub);	    return 0;	  }	  stub->args.utimens.loc.inode = inode_ref (server_inode);	  stub->args.utimens.loc.ino = stbuf->st_ino;	  call_resume (stub);	  break;	}      case GF_FOP_READLINK:	{	  	  if (op_ret < 0) {	    gf_log (frame->this->name, GF_LOG_ERROR, 		    "returning ENOENT: %d (%d)", op_ret, op_errno);	    server_readlink_cbk (stub->frame,				 NULL,				 stub->frame->this,				 -1,				 ENOENT,				 NULL);	    freee (stub->args.readlink.loc.path);	    freee (stub);	    return 0;	  }	  stub->args.utimens.loc.inode = inode_ref (server_inode);	  stub->args.utimens.loc.ino = stbuf->st_ino;	  call_resume (stub);	  break;	}	      default:	call_resume (stub);      }  }   return 0;}/* * server_lookup - lookup function for server protocol * @frame: call frame * @bound_xl: * @params: parameter dictionary * * not for external reference */int32_tserver_lookup (call_frame_t *frame,	       xlator_t *bound_xl,	       dict_t *params){  data_t *path_data = dict_get (params, "PATH");  data_t *inode_data = dict_get (params, "INODE");  data_t *need_xattr_data = dict_get (params, "NEED_XATTR");  loc_t loc = {0,};  server_state_t *state = STATE (frame);  int32_t need_xattr = 0;  if (!path_data || !inode_data) {    gf_log (frame->this->name, GF_LOG_ERROR, 	    "not getting enough data, returning EINVAL");    server_lookup_cbk (frame,		       NULL,		       frame->this,		       -1,		       EINVAL,		       NULL,		       NULL,		       NULL);    return 0;  }  loc.ino  = data_to_uint64 (inode_data);  loc.path = data_to_str (path_data);  loc.inode = inode_search (bound_xl->itable, loc.ino, NULL);  if (need_xattr_data)    need_xattr = data_to_int32 (need_xattr_data);  if (loc.inode) {    /* revalidate */    state->inode = loc.inode;  } else {    /* fresh lookup or inode was previously pruned out */    state->inode = dummy_inode (bound_xl->itable);    loc.inode = state->inode;      }  STACK_WIND (frame,	      server_lookup_cbk,	      bound_xl,	      bound_xl->fops->lookup,	      &loc,	      need_xattr);  return 0;}/* * server_forget - forget function for server protocol * @frame: call frame * @bound_xl: * @params: parameter dictionary * * not for external reference */int32_tserver_forget (call_frame_t *frame,	       xlator_t *bound_xl,	       dict_t *params){  data_t *inode_data = dict_get (params, "INODE");  inode_t *inode = NULL;  if (!inode_data) {    gf_log (frame->this->name, GF_LOG_ERROR, 	    "not getting enough data, returning EINVAL");    server_forget_cbk (frame,		       NULL,		       bound_xl,		       -1,		       EINVAL);    return 0;  }  inode = inode_search (bound_xl->itable, 			data_to_uint64 (inode_data),			NULL);  if (inode) {    inode_forget (inode, 0);    inode_unref (inode);  }  server_forget_cbk (frame, NULL, bound_xl, 0, 0);    return 0;}int32_tserver_stat_resume (call_frame_t *frame,		    xlator_t *this,		    loc_t *loc){  server_state_t *state = STATE (frame);  state->inode = inode_ref (loc->inode);  STACK_WIND (frame,	      server_stat_cbk,	      BOUND_XL (frame),	      BOUND_XL (frame)->fops->stat,	      loc);  return 0;}/* * server_stat - stat function for server * @frame: call frame * @bound_xl: translator this server is bound to * @params: parameters dictionary * * not for external reference */int32_tserver_stat (call_frame_t *frame,	     xlator_t *bound_xl,	     dict_t *params){  data_t *path_data = dict_get (params, "PATH");  data_t *inode_data = dict_get (params, "INODE");  struct stat buf = {0, };  loc_t loc = {0,};  call_stub_t *stat_stub = NULL;  if (!path_data || !inode_data) {    gf_log (frame->this->name, GF_LOG_ERROR, 	    "not getting enough data, returning EINVAL");    server_stat_cbk (frame,		     NULL,		     frame->this,		     -1,		     EINVAL,		     &buf);    return 0;  }  loc.path = data_to_str (path_data);  loc.ino = data_to_uint64 (inode_data);  loc.inode = inode_search (bound_xl->itable, loc.ino, NULL);  stat_stub = fop_stat_stub (frame, 			     server_stat_resume,			     &loc);  if (loc.inode) {    /* unref()ing ref() from inode_search(), since fop_open_stub has kept     * a reference for inode */    inode_unref (loc.inode);  }  if (!loc.inode) {    /* call lookup to get the inode structure.     * resume call after lookup is successful */    frame->local = stat_stub;    loc.inode = dummy_inode (BOUND_XL(frame)->itable);    STACK_WIND (frame,		server_stub_cbk,		bound_xl,		bound_xl->fops->lookup,		&loc,		0);  } else {    call_resume (stat_stub);  }  return 0;}int32_tserver_readlink_resume (call_frame_t *frame,			xlator_t *this,			loc_t *loc,			size_t size){  server_state_t *state = STATE (frame);  state->inode = inode_ref (loc->inode);  STACK_WIND (frame,	      server_readlink_cbk,	      BOUND_XL (frame),	      BOUND_XL (frame)->fops->readlink,	      loc,	      size);  return 0;}/* * server_readlink - readlink function for server * @frame: call frame * @bound_xl: translator this server is bound to * @params: parameters dictionary * * not for external reference */int32_tserver_readlink (call_frame_t *frame,		 xlator_t *bound_xl,		 dict_t *params){  data_t *path_data = dict_get (params, "PATH");  data_t *inode_data = dict_get (params, "INODE");  data_t *len_data = dict_get (params, "LEN");  int32_t len = data_to_int32 (len_data);  loc_t loc = {0,};  if (!path_data || !len_data) {    gf_log (frame->this->name, GF_LOG_ERROR, 	    "not getting enough data, returning EINVAL");    server_readlink_cbk (frame,			 NULL,			 frame->this,			 -1,			 EINVAL,			 "");    return 0;  }  loc.path = data_to_str (path_data);  loc.ino = data_to_uint64 (inode_data);  loc.inode = inode_search (bound_xl->itable, loc.ino, NULL);  call_stub_t *readlink_stub = fop_readlink_stub (frame, 						  server_readlink_resume,						  &loc,						  len);  if (loc.inode) {    /* unref()ing ref() from inode_search(), since fop_open_stub has kept     * a reference for inode */    inode_unref (loc.inode);  }  if (!loc.inode) {    /* make a call stub and call lookup to get the inode structure.     * resume call after lookup is successful */    frame->local = readlink_stub;    loc.inode = dummy_inode (BOUND_XL(frame)->itable);    STACK_WIND (frame,		server_stub_cbk,		bound_xl,		bound_xl->fops->lookup,		&loc,		0);  } else {    call_resume (readlink_stub);  }  return 0;}/* * server_create - create function for server * @frame: call frame * @bound_xl: translator this server is bound to * @params: parameters dictionary * * not for external reference */int32_tserver_create (call_frame_t *frame,	       xlator_t *bound_xl,	       dict_t *params){  int32_t flags = 0;  data_t *path_data = dict_get (params, "PATH");  data_t *mode_data = dict_get (params, "MODE");  data_t *flag_data = dict_get (params, "FLAGS");  fd_t *fd = NULL;  mode_t mode = 0;  loc_t loc = {0,};  if (!path_data || !mode_data) {    struct stat buf = {0, };    gf_log (frame->this->name, GF_LOG_ERROR, 	    "not getting enough data, returning EINVAL");    server_create_cbk (frame,		       NULL,		       frame->this,		       -1,		       EINVAL,		       NULL,		       NULL,		       &buf);    return 0;  }  if (flag_data) {    flags = data_to_int32 (flag_data);  }  mode = data_to_int64 (mode_data);  loc.path = data_to_str (path_data);  loc.inode = dummy_inode (bound_xl->itable);  fd = fd_create (loc.inode);  LOCK (&fd->inode->lock);  {    list_del_init (&fd->inode_list);  }  UNLOCK (&fd->inode->lock);  STACK_WIND (frame, 	      server_create_cbk, 	      bound_xl,	      bound_xl->fops->create,	      &loc,	      flags,	      mode,	      fd);    return 0;}int32_tserver_open_resume (call_frame_t *frame,		    xlator_t *this,		    loc_t *loc,		    int32_t flags,		    fd_t *fd){  server_state_t *state = STATE (frame);  fd_t *new_fd = NULL;  state->inode = inode_ref (loc->inode);    new_fd = fd_create (loc->inode);  STACK_WIND (frame,	      server_open_cbk,	      BOUND_XL (frame),	      BOUND_XL (frame)->fops->open,	      loc,	      flags,	      new_fd);  return 0;	      }/* * server_open - open function for server protocol * @frame: call frame * @bound_xl: translator this server protocol is bound to * @params: parameters dictionary * * not for external reference */int32_tserver_open (call_frame_t *frame,	     xlator_t *bound_xl,	     dict_t *params){  data_t *path_data = dict_get (params, "PATH");  data_t *inode_data = dict_get (params, "INODE");  data_t *flag_data = dict_get (params, "FLAGS");  int32_t flags = data_to_int32 (flag_data);  loc_t loc = {0,};  call_stub_t *open_stub = NULL;  if (!path_data || !inode_data || !flag_data) {    gf_log (frame->this->name, GF_LOG_ERROR, 	    "not getting enough data, returning EINVAL");    server_open_cbk (frame,		     NULL,		     frame->this,		     -1,		     EINVAL,		     NULL);    return 0;  }  loc.path = data_to_str (path_data);  loc.ino = data_to_uint64 (inode_data);  loc.inode = inode_search (bound_xl->itable, loc.ino, NULL);  open_stub = fop_open_stub (frame, 			     server_open_resume,			     &loc,			     flags,			     NULL);  if (loc.inode) {    /* unref()ing ref() from inode_search(), since fop_open_stub has kept     * a reference for inode */    inode_unref (loc.inode);  }  if (!loc.inode) {    /* make a call stub and call lookup to get the inode structure.     * resume call after lookup is successful */    frame->local = open_stub;    loc.inode = dummy_inode (BOUND_XL(frame)->itable);    STACK_WIND (frame,		server_stub_cbk,		bound_xl,		bound_xl->fops->lookup,		&loc,		0);      } else {    /* we are fine with everything, go ahead with open of our child */    call_resume (open_stub);  }  return 0;}/* * server_readv - readv function for server protocol * @frame: call frame * @bound_xl: * @params: parameter dictionary * * not for external reference */int32_tserver_readv (call_frame_t *frame,	      xlator_t *bound_xl,	      dict_t *params){  data_t *fd_data = dict_get (params, "FD");  data_t *len_data = dict_get (params, "LEN");  data_t *off_data = dict_get (params, "OFFSET");  int32_t fd_no = -1;  server_proto_priv_t *priv = SERVER_PRIV (frame);  fd_t *fd = NULL;  if (fd_data) {    fd_no = data_to_int32 (fd_data);    fd = gf_fd_fdptr_get (priv->fdtable, fd_no);    if (!fd)      gf_log (frame->this->name, GF_LOG_ERROR,	      "unresolved fd %d", fd_no);  }  if (!fd || !len_data || !off_data) {    struct iovec vec;    struct stat stbuf = {0,};    vec.iov_base = "";    vec.iov_len = 0;    gf_log (frame->this->name, GF_LOG_ERROR, 	    "not getting enough data, returning EINVAL");    server_readv_cbk (frame,		      NULL,		      frame->this,		      -1,		      EINVAL,		      &vec,		      0,		      &stbuf);    return 0; 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -