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

📄 server-protocol.c

📁 分布式文件系统
💻 C
📖 第 1 页 / 共 5 页
字号:
      UNLOCK (&server_inode->lock);    }    inode_unref (server_inode);    fd_no = gf_fd_unused_get (priv->fdtable, fd);    if (fd_no < 0 || fd == 0) {      op_ret = fd_no;      op_errno = errno;    }    dict_set (reply, "FD", data_from_int32 (fd_no));        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_CREATE,		reply, frame->root->rsp_refs);    return 0;}/* * server_readlink_cbk - readlink callback for server protocol * @frame: call frame * @cookie:  * @this: * @op_ret: * @op_errno: * @buf: * * not for external reference */int32_tserver_readlink_cbk (call_frame_t *frame,		     void *cookie,		     xlator_t *this,		     int32_t op_ret,		     int32_t op_errno,		     const char *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));  dict_set (reply, "LINK", data_from_dynstr (buf ? strdup (buf) : strdup ("") ));  server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_FOP_READLINK,		reply, frame->root->rsp_refs);  return 0;}/*  * server_stat_cbk - stat callback for server protocol * @frame: call frame * @cookie: * @this: * @op_ret: * @op_errno: * @stbuf: * * not for external reference */int32_tserver_stat_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_STAT,		reply, frame->root->rsp_refs);  return 0;}/* * server_forget_cbk - forget callback for server protocol * @frame: call frame * @cookie: * @this: * @op_ret: * @op_errno: * * not for external reference */int32_tserver_forget_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_FORGET,		reply, frame->root->rsp_refs);  return 0;}/* * server_lookup_cbk - lookup callback for server protocol * @frame: call frame * @cookie: * @this: * @op_ret: * @op_errno: * @inode: * @stbuf: * * not for external reference */int32_tserver_lookup_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 *dict){  dict_t *reply = get_new_dict ();  char *stat_str = NULL;  inode_t *server_inode = NULL;  inode_t *root_inode = NULL;  dict_set (reply, "RET", data_from_int32 (op_ret));  dict_set (reply, "ERRNO", data_from_int32 (op_errno));  if (op_ret == 0) {    root_inode = BOUND_XL(frame)->itable->root;    if (inode == root_inode) {      /* we just looked up root ("/") */      stbuf->st_ino = 1;    }    if (!inode->ino) {      server_inode = inode_update (BOUND_XL(frame)->itable, NULL, NULL, stbuf);          if (server_inode != inode && (!server_inode->ctx)) {	server_inode->ctx = inode->ctx;	inode->ctx = NULL;	if (op_ret >= 0) {	  server_inode->st_mode = stbuf->st_mode;	  server_inode->generation = inode->generation;	}      }      inode_lookup (server_inode);      inode_unref (server_inode);    }    stat_str = stat_to_str (stbuf);    dict_set (reply, "STAT", data_from_dynstr (stat_str));    if (dict) {      int32_t len;      char *dict_buf = NULL;      dict_set (dict, "__@@protocol_client@@__key", str_to_data ("value"));      len = dict_serialized_length (dict);      dict_buf = calloc (len, 1);      dict_serialize (dict, dict_buf);      dict_set (reply, "DICT", data_from_dynptr (dict_buf, len));    }  }  server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_FOP_LOOKUP,		reply, frame->root->rsp_refs);  return 0;}/* * server_stub_cbk - this is callback function used whenever an fop does *                   STACK_WIND to fops->lookup in order to lookup the inode *                   for a pathname. this case of doing fops->lookup arises *                   when fop searches in inode table for pathname and search *                   fails. * * @frame: call frame * @cookie: * @this: * @op_ret: * @op_errno: * @inode: * @stbuf: * * not for external reference */int32_tserver_stub_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 *dict){  /* TODO: should inode pruning be done here or not??? */  inode_t *server_inode = NULL;  server_inode = inode_update (BOUND_XL(frame)->itable, NULL, NULL, stbuf);    if (server_inode != inode) {    server_inode->ctx = inode->ctx;    inode->ctx = NULL;  }    if (server_inode) {    inode_lookup (server_inode);    inode_unref (server_inode);  }    inode_unref (inode);  if (frame->local) {    /* we have a call stub to wind to */    call_stub_t *stub = (call_stub_t *)frame->local;        if (stub->fop != GF_FOP_RENAME)      /* to make sure that STACK_DESTROY() does not try to freee        * frame->local. frame->local points to call_stub_t, which is       * free()ed in call_resume(). */      frame->local = NULL;#if 0       /* classic bug.. :O, intentionally left for sweet memory.     *                                              --benki     */    if (op_ret < 0) {      if (stub->fop != GF_FOP_RENAME) {	/* STACK_UNWIND helps prevent memory leak. how?? */	gf_log (frame->this->name, GF_LOG_ERROR, 		"returning ENOENT");	STACK_UNWIND (stub->frame, -1, ENOENT, 0, 0);	freee (stub);	return 0;      }    }#endif    switch (stub->fop)      {      case GF_FOP_RENAME:	if (!stub->args.rename.old.inode) {	  loc_t *newloc = NULL;	  /* now we are called by lookup of oldpath. */	  if (op_ret < 0) {	    /* to make sure that STACK_DESTROY() does not try to freee 	     * frame->local. frame->local points to call_stub_t, which is	     * free()ed in call_resume(). */	    frame->local = NULL;	    	    /* lookup of oldpath failed, UNWIND to server_rename_cbk with	     * ret=-1 and errno=ENOENT */	    server_rename_cbk (stub->frame,			       NULL,			       stub->frame->this,			       -1,			       ENOENT,			       NULL);	    	    freee (stub->args.rename.old.path);	    freee (stub->args.rename.new.path);	    freee (stub);	    return 0;	  }	  	  /* store inode information of oldpath in our stub and search for 	   * newpath in inode table. 	   * inode_ref()ed because, we might do a STACK_WIND to fops->lookup()	   * again to lookup for newpath */	  stub->args.rename.old.inode = inode_ref (server_inode);	  stub->args.rename.old.ino = stbuf->st_ino;	  	  /* now lookup for newpath */	  newloc = &stub->args.rename.new;	  newloc->inode = inode_search (BOUND_XL(frame)->itable, 					newloc->ino,					NULL);	  	  if (!newloc->inode) {	    /* lookup for newpath */	    newloc->inode = dummy_inode (BOUND_XL(frame)->itable);	    STACK_WIND (stub->frame,			server_stub_cbk,			BOUND_XL (stub->frame),			BOUND_XL (stub->frame)->fops->lookup,			newloc,			0);	    	    break;	  } else {	    /* found newpath in inode cache */	    	    /* to make sure that STACK_DESTROY() does not try to freee 	     * frame->local. frame->local points to call_stub_t, which is	     * free()ed in call_resume(). */	    frame->local = NULL;	    call_resume (stub);	    break;	  }	} else {	  /* we are called by the lookup of newpath */	  	  /* to make sure that STACK_DESTROY() does not try to freee 	   * frame->local. frame->local points to call_stub_t, which is	   * free()ed in call_resume(). */	  frame->local = NULL;	  	  if (server_inode) {	  	    stub->args.rename.new.inode = inode_ref (server_inode);	    stub->args.rename.new.ino = stbuf->st_ino;	  }	}      		/* after looking up for oldpath as well as newpath, 	 * we are ready to resume */	{	  call_resume (stub);	}	break;      case GF_FOP_OPEN:	{	  if (op_ret < 0) {	    gf_log (frame->this->name, GF_LOG_ERROR, 		    "returning ENOENT: %d (%d)", op_ret, op_errno);	    	    server_open_cbk (stub->frame,			     NULL,			     stub->frame->this,			     -1,			     ENOENT,			     NULL);	    freee (stub->args.open.loc.path);	    freee (stub);	    return 0;	  }    	  stub->args.open.loc.inode = inode_ref (server_inode);	  stub->args.open.loc.ino = stbuf->st_ino;	  call_resume (stub);	  break;	}      case GF_FOP_STAT:	{	  if (op_ret < 0) {	    gf_log (frame->this->name, GF_LOG_ERROR, 		    "returning ENOENT: %d (%d)", op_ret, op_errno);	    server_stat_cbk (stub->frame,			     NULL,			     stub->frame->this,			     -1,			     ENOENT,			     NULL);	    freee (stub->args.stat.loc.path);	    freee (stub);	    return 0;	  }	  /* TODO: reply from here only, we already have stat structure */	  stub->args.stat.loc.inode = inode_ref (server_inode);	  stub->args.stat.loc.ino = stbuf->st_ino;	  call_resume (stub);	  break;	}	      case GF_FOP_UNLINK:	{	  if (op_ret < 0) {	    gf_log (frame->this->name, GF_LOG_ERROR, 		    "returning ENOENT: %d (%d)", op_ret, op_errno);	    server_unlink_cbk (stub->frame,			       NULL,			       stub->frame->this,			       -1,			       ENOENT);	    freee (stub->args.unlink.loc.path);	    freee (stub);	    return 0;	  }	  stub->args.unlink.loc.inode = inode_ref (server_inode);	  stub->args.unlink.loc.ino = stbuf->st_ino;	  call_resume (stub);	  break;	}	      case GF_FOP_RMDIR:	{	  if (op_ret < 0) {	    gf_log (frame->this->name, GF_LOG_ERROR, 		    "returning ENOENT: %d (%d)", op_ret, op_errno);	    server_rmdir_cbk (stub->frame,			       NULL,			       stub->frame->this,			       -1,			       ENOENT);	    freee (stub->args.rmdir.loc.path);	    freee (stub);	    return 0;	  }	  stub->args.rmdir.loc.inode = inode_ref (server_inode);	  stub->args.rmdir.loc.ino = stbuf->st_ino;	  call_resume (stub);	  break;	}	      case GF_FOP_CHMOD:	{	  if (op_ret < 0) {	    gf_log (frame->this->name, GF_LOG_ERROR, 		    "returning ENOENT: %d (%d)", op_ret, op_errno);	    server_chmod_cbk (stub->frame,			      NULL,			      stub->frame->this,			      -1,			      ENOENT,			      NULL);	    freee (stub->args.chmod.loc.path);	    freee (stub);	    return 0;	  }	  stub->args.chmod.loc.inode = inode_ref (server_inode);	  stub->args.chmod.loc.ino = stbuf->st_ino;	  call_resume (stub);	  break;	}      case GF_FOP_CHOWN:	{	  if (op_ret < 0) {	    gf_log (frame->this->name, GF_LOG_ERROR, 		    "returning ENOENT: %d (%d)", op_ret, op_errno);	    server_chown_cbk (stub->frame,			      NULL,			      stub->frame->this,			      -1,			      ENOENT,			      NULL);	    freee (stub->args.chown.loc.path);	    freee (stub);	    return 0;	  }	  stub->args.chown.loc.inode = inode_ref (server_inode);	  stub->args.chown.loc.ino = stbuf->st_ino;	  call_resume (stub);	  break;	}      case GF_FOP_LINK:	{	  if (op_ret < 0) {	    gf_log (frame->this->name, GF_LOG_ERROR, 		    "returning ENOENT: %d (%d)", op_ret, op_errno);	    server_link_cbk (stub->frame,			     NULL,			     stub->frame->this,			     -1,			     ENOENT,			     NULL,			     NULL);	    freee (stub->args.link.oldloc.path);	    freee (stub->args.link.newpath);	    freee (stub);	    return 0;	  }	  stub->args.link.oldloc.inode = inode_ref (server_inode);	  stub->args.link.oldloc.ino = stbuf->st_ino;	  call_resume (stub);	  break;	}      case GF_FOP_TRUNCATE:	{	  if (op_ret < 0) {	    gf_log (frame->this->name, GF_LOG_ERROR, 		    "returning ENOENT: %d (%d)", op_ret, op_errno);	    server_truncate_cbk (stub->frame,				 NULL,				 stub->frame->this,				 -1,				 ENOENT,				 NULL);	    freee (stub->args.truncate.loc.path);	    freee (stub);	    return 0;	  }	  stub->args.truncate.loc.inode = inode_ref (server_inode);	  stub->args.truncate.loc.ino = stbuf->st_ino;	  call_resume (stub);	  break;	}	      case GF_FOP_STATFS:	{	  if (op_ret < 0) {	    gf_log (frame->this->name, GF_LOG_ERROR, 		    "returning ENOENT: %d (%d)", op_ret, op_errno);	    server_statfs_cbk (stub->frame,			       NULL,			       stub->frame->this,			       -1,			       ENOENT,			       NULL);	    freee (stub->args.statfs.loc.path);	    freee (stub);	    return 0;	  }	  stub->args.statfs.loc.inode = inode_ref (server_inode);	  stub->args.statfs.loc.ino = stbuf->st_ino;	  call_resume (stub);	  break;	}	      case GF_FOP_SETXATTR:	{	  dict_t *dict = stub->args.setxattr.dict;	  if (op_ret < 0) {	    gf_log (frame->this->name, GF_LOG_ERROR, 		    "returning ENOENT: %d (%d)", op_ret, op_errno);	    server_setxattr_cbk (stub->frame,				 NULL,				 stub->frame->this,				 -1,				 ENOENT);	    freee (stub->args.setxattr.loc.path);	    dict_destroy (dict);	    freee (stub);	    return 0;	  }	  stub->args.setxattr.loc.inode = inode_ref (server_inode);	  stub->args.setxattr.loc.ino = stbuf->st_ino;	  call_resume (stub);	  //	  dict_destroy (dict);	  break;	}	      case GF_FOP_GETXATTR:	{	  if (op_ret < 0) {	    gf_log (frame->this->name, GF_LOG_ERROR, 		    "returning ENOENT: %d (%d)", op_ret, op_errno);	    server_getxattr_cbk (stub->frame,				 NULL,				 stub->frame->this,				 -1,				 ENOENT,				 NULL);	    freee (stub->args.getxattr.loc.path);	    freee (stub);	    return 0;	  }	  stub->args.getxattr.loc.inode = inode_ref (server_inode);	  stub->args.getxattr.loc.ino = stbuf->st_ino;	  call_resume (stub);	  break;	}	      case GF_FOP_REMOVEXATTR:	{	  if (op_ret < 0) {	    gf_log (frame->this->name, GF_LOG_ERROR, 		    "returning ENOENT: %d (%d)", op_ret, op_errno);

⌨️ 快捷键说明

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