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

📄 stripe.c

📁 分布式文件系统
💻 C
📖 第 1 页 / 共 5 页
字号:
  stripe_private_t *priv = this->private;  xlator_list_t *trav = this->children;  LOCK (&frame->lock);  {    callcnt = --local->call_count;        if (op_ret == -1) {      gf_log (this->name, GF_LOG_WARNING, "%s returned errno %d",	      ((call_frame_t *)cookie)->this->name, op_errno);      local->op_ret = -1;      local->op_errno = op_errno;    }  }  UNLOCK (&frame->lock);  if (!callcnt) {    if (local->op_ret == -1) {      local->call_count = priv->child_count;      while (trav) {	loc_t tmp_loc = {	  .inode = local->inode,	  .path = local->path	};	STACK_WIND (frame,		    stripe_mknod_ifreg_fail_unlink_cbk,		    trav->xlator,		    trav->xlator->fops->unlink,		    &tmp_loc);	trav = trav->next;      }      return 0;    }    freee (local->path);    STACK_UNWIND (frame,		  local->op_ret,		  local->op_errno,		  local->inode,		  &local->stbuf);  }  return 0;}/** */int32_tstripe_mknod_ifreg_cbk (call_frame_t *frame,			void *cookie,			xlator_t *this,			int32_t op_ret,			int32_t op_errno,			inode_t *inode,			struct stat *buf){  int32_t callcnt = 0;  stripe_local_t *local = frame->local;  stripe_private_t *priv = this->private;  LOCK (&frame->lock);  {    callcnt = --local->call_count;        if (op_ret == -1) {      gf_log (this->name, GF_LOG_WARNING, "%s returned errno %d",	      ((xlator_t *)cookie)->name, op_errno);      local->failed = 1;      local->op_errno = op_errno;    }        if (op_ret >= 0) {      local->op_ret = op_ret;      /* Get the mapping in inode private */      /* Get the stat buf right */      if (local->stbuf.st_blksize == 0) {	local->stbuf = *buf;      }            if (strcmp (FIRST_CHILD(this)->name, ((xlator_t *)cookie)->name) == 0) {	/* Always, pass the inode number of first child to the above layer */	local->stbuf.st_ino = buf->st_ino;      }            if (local->stbuf.st_size < buf->st_size)	local->stbuf.st_size = buf->st_size;      local->stbuf.st_blocks += buf->st_blocks;      if (local->stbuf.st_blksize != buf->st_blksize) {	/* TODO: add to blocks in terms of original block size */      }    }  }  UNLOCK (&frame->lock);  if (!callcnt) {    if (local->failed) {      local->op_ret = -1;    }    if (local->op_ret >= 0) {      dict_set (local->inode->ctx, 		this->name, 		data_from_int8 (2)); //file is striped    }    if (local->op_ret != -1) {      /* Send a setxattr request to nodes where the files are created */      int32_t index = 0;      char size_key[256] = {0,};      char index_key[256] = {0,};      char count_key[256] = {0,};      xlator_list_t *trav = this->children;      dict_t *dict = get_new_dict ();      sprintf (size_key, "trusted.%s.stripe-size", this->name);      sprintf (count_key, "trusted.%s.stripe-count", this->name);      sprintf (index_key, "trusted.%s.stripe-index", this->name);      dict_set (dict, size_key, data_from_int64 (local->stripe_size));      dict_set (dict, count_key, data_from_int32 (local->call_count));      local->call_count = priv->child_count;	      while (trav) {	loc_t tmp_loc = {	  .inode = local->inode,	  .path = local->path	};	dict_set (dict, index_key, data_from_int32 (index));	STACK_WIND (frame,		    stripe_mknod_ifreg_setxattr_cbk,		    trav->xlator,		    trav->xlator->fops->setxattr,		    &tmp_loc,		    dict,		    0);		index++;	trav = trav->next;      }      dict_destroy (dict);    } else {      /* Create itself has failed.. so return without setxattring */      freee (local->path);            STACK_UNWIND (frame, 		    local->op_ret, 		    local->op_errno, 		    local->inode, 		    &local->stbuf);    }  }    return 0;}/** * stripe_mknod -  */int32_tstripe_mknod (call_frame_t *frame,	      xlator_t *this,	      loc_t *loc,	      mode_t mode,	      dev_t rdev){  stripe_private_t *priv = this->private;    if (priv->first_child_down) {    gf_log (this->name, GF_LOG_WARNING, "First node down, returning EIO");    STACK_UNWIND (frame, -1, EIO, NULL, NULL);    return 0;  }  if (S_ISREG(mode)) {    /* NOTE: on older kernels (older than 2.6.9), creat() fops is sent as        mknod() + open(). Hence handling S_IFREG files is necessary */    off_t stripe_size = 0;        stripe_size = stripe_get_matching_bs (loc->path, priv->pattern);      if (stripe_size) {      stripe_local_t *local = NULL;      xlator_list_t *trav = NULL;      if (priv->nodes_down) {	gf_log (this->name, GF_LOG_WARNING, "Some node down, returning EIO");	STACK_UNWIND (frame, -1, EIO, loc->inode, NULL);	return 0;      }            /* Initialization */      local = calloc (1, sizeof (stripe_local_t));      local->op_ret = -1;      local->op_errno = ENOTCONN;      local->stripe_size = stripe_size;      local->path = strdup (loc->path);      frame->local = local;      local->inode = loc->inode;            /* Everytime in stripe lookup, all child nodes should be looked up */      local->call_count = ((stripe_private_t *)this->private)->child_count;            trav = this->children;      while (trav) {	STACK_WIND_COOKIE (frame,		     stripe_mknod_ifreg_cbk,		     trav->xlator,  /* cookie */		     trav->xlator,		     trav->xlator->fops->mknod,		     loc,		     mode,		     rdev);	trav = trav->next;      }      /* This case is handled, no need to continue further. */      return 0;     }    /* File is not matching the given pattern */  }  STACK_WIND (frame,	      stripe_common_inode_cbk,	      FIRST_CHILD(this),	      FIRST_CHILD(this)->fops->mknod,	      loc,	      mode,	      rdev);  return 0;}/** * stripe_mkdir -  */int32_tstripe_mkdir (call_frame_t *frame,	      xlator_t *this,	      loc_t *loc,	      mode_t mode){  stripe_private_t *priv = this->private;  stripe_local_t *local = NULL;  xlator_list_t *trav = NULL;    if (priv->first_child_down) {    gf_log (this->name, GF_LOG_WARNING, "First node down, returning EIO");    STACK_UNWIND (frame, -1, EIO, NULL, NULL);    return 0;  }  /* Initialization */  local = calloc (1, sizeof (stripe_local_t));  local->op_ret = -1;  local->call_count = priv->child_count;  frame->local = local;  /* Everytime in stripe lookup, all child nodes should be looked up */  trav = this->children;  while (trav) {    STACK_WIND (frame,		stripe_stack_unwind_inode_cbk,		trav->xlator,		trav->xlator->fops->mkdir,		loc,		mode);    trav = trav->next;  }  return 0;}/** * stripe_symlink -  */int32_tstripe_symlink (call_frame_t *frame,		xlator_t *this,		const char *linkpath,		loc_t *loc){  stripe_private_t *priv = this->private;  xlator_list_t *trav = NULL;    if (priv->first_child_down) {    gf_log (this->name, GF_LOG_WARNING, "First node down, returning EIO");    STACK_UNWIND (frame, -1, EIO, NULL, NULL);    return 0;  }  /* send symlink to only first node */  trav = this->children;  STACK_WIND (frame,	      stripe_common_inode_cbk,	      trav->xlator,	      trav->xlator->fops->symlink,	      linkpath,	      loc);  return 0;}/** * stripe_link - */int32_tstripe_link (call_frame_t *frame,	     xlator_t *this,	     loc_t *loc,	     const char *newname){  stripe_private_t *priv = this->private;  stripe_local_t *local = NULL;  xlator_list_t *trav = this->children;  int8_t striped = 0;    STRIPE_CHECK_INODE_CTX_AND_UNWIND_ON_ERR (loc);  if (priv->first_child_down) {    gf_log (this->name, GF_LOG_WARNING, "First node down, returning EIO");    STACK_UNWIND (frame, -1, EIO, NULL, NULL);    return 0;  }  striped = data_to_int8 (dict_get (loc->inode->ctx, this->name));  if (striped == 1) {    STACK_WIND (frame,		stripe_common_inode_cbk,		trav->xlator,		trav->xlator->fops->link,		loc,		newname);  } else {    /* Initialization */    local = calloc (1, sizeof (stripe_local_t));    local->op_ret = -1;    frame->local = local;    local->call_count = priv->child_count;    /* Everytime in stripe lookup, all child nodes should be looked up */    while (trav) {      STACK_WIND (frame,		  stripe_stack_unwind_inode_cbk,		  trav->xlator,		  trav->xlator->fops->link,		  loc,		  newname);      trav = trav->next;    }  }  return 0;}int32_t stripe_create_fail_unlink_cbk (call_frame_t *frame,			       void *cookie,			       xlator_t *this,			       int32_t op_ret,			       int32_t op_errno){  int32_t callcnt = 0;  stripe_local_t *local = frame->local;  LOCK (&frame->lock);  {    callcnt = --local->call_count;  }  UNLOCK (&frame->lock);  if (!callcnt) {    if (local->path)      freee (local->path);    STACK_UNWIND (frame, 		  local->op_ret, 		  local->op_errno, 		  local->fd, 		  local->inode,		  &local->stbuf);  }  return 0;}int32_t stripe_create_fail_cbk (call_frame_t *frame,			void *cookie,			xlator_t *this,			int32_t op_ret,			int32_t op_errno){  int32_t callcnt = 0;  stripe_local_t *local = frame->local;  stripe_private_t *priv = this->private;  xlator_list_t *trav = this->children;  LOCK (&frame->lock);  {    callcnt = --local->call_count;  }  UNLOCK (&frame->lock);  if (!callcnt) {    local->call_count = priv->child_count;    while (trav) {      loc_t tmp_loc = {	.inode = local->inode,	.path = local->path      };      STACK_WIND (frame,		  stripe_create_fail_unlink_cbk,		  trav->xlator,		  trav->xlator->fops->unlink,		  &tmp_loc);      trav = trav->next;    }  }  return 0;}/** * stripe_create_setxattr_cbk -  */int32_tstripe_create_setxattr_cbk (call_frame_t *frame,			    void *cookie,			    xlator_t *this,			    int32_t op_ret,			    int32_t op_errno){  int32_t callcnt = 0;  stripe_local_t *local = frame->local;  stripe_private_t *priv = this->private;  xlator_list_t *trav = this->children;  LOCK (&frame->lock);  {    callcnt = --local->call_count;        if (op_ret == -1) {      gf_log (this->name, GF_LOG_WARNING, "%s returned errno %d",	      ((call_frame_t *)cookie)->this->name, op_errno);      local->op_ret = -1;      local->op_errno = op_errno;    }  }  UNLOCK (&frame->lock);  if (!callcnt) {    if (local->op_ret == -1) {      local->call_count = priv->child_count;      while (trav) {	STACK_WIND (frame,		    stripe_create_fail_cbk,		    trav->xlator,		    trav->xlator->fops->close,		    local->fd);	trav = trav->next;      }      return 0;    }    freee (local->path);    STACK_UNWIND (frame,		  local->op_ret,		  local->op_errno,		  local->fd,		  local->inode,		  &local->stbuf);  }  return 0;}/** * stripe_create_cbk -  */int32_tstripe_create_cbk (call_frame_t *frame,		   void *cookie,		   xlator_t *this,		   int32_t op_ret,		   int32_t op_errno,		   fd_t *fd,		   inode_t *inode,		   struct stat *buf){  int32_t callcnt = 0;  stripe_local_t *local = frame->local;  stripe_private_t *priv = this->private;  LOCK (&frame->lock);  {    callcnt = --local->call_count;        if (op_ret == -1) {      gf_log (this->name, GF_LOG_WARNING, "%s returned errno %d",	      ((xlator_t *)cookie)->name, op_errno);      local->failed = 1;      local->op_errno = op_errno;    }        if (op_ret >= 0) {      local->op_ret = op_ret;      /* Get the mapping in inode private */      /* Get the stat buf right */      if (local->stbuf.st_blksize == 0) {	local->stbuf = *buf;      }            if (FIRST_CHILD(this) == ((xlator_t *)cookie)) {	/* Always, pass the inode number of first child to the above layer */	local->stbuf.st_ino = buf->st_ino;      }            if (local->stbuf.st_size < buf->st_size)	local->stbuf.st_size = buf->st_size;      local->stbuf.st_blocks += buf->st_blocks;      if (local->stbuf.st_blksize != buf->st_blksize) {	/* TODO: add to blocks in terms of original block size */      }    }  }  UNLOCK (&frame->lock);  if (!callcnt) {    if (local->failed) {      local->op_ret = -1;    }    if (local->op_ret >= 0) {      if (local->stripe_size) {	dict_set (local->inode->ctx, 		  this->name, 		  data_from_int8 (2)); //stripped file      } else {	dict_set (local->inode->ctx, 		  this->name, 		  data_from_int8 (1)); //unstripped file      }      dict_set (local->fd->ctx, 		this->name, 		data_from_uint64 (local->stripe_size));    }    if (local->op_ret != -1 && local->stripe_size) {      /* Send a setxattr request to nodes where the files are created */      int32_t index = 0;      char size_key[256] = {0,};      char index_key[256] = {0,};      char count_key[256] = {0,};      xlator_list_t *trav = this->children;      dict_t *dict = get_new_dict ();      sprintf (size_key, "trusted.%s.stripe-size", this->name);      sprintf (count_key, "trusted.%s.stripe-count", this->name);      sprintf (index_key, "trusted.%s.stripe-index", this->name);      dict_set (dict, size_key, data_from_int64 (local->stripe_size));      dict_set (dict, count_key, data_from_int32 (local->call_count));      local->call_count = priv->child_count;	      while (trav) {	loc_t tmp_loc = {	  .inode = local->inode,	  .path = local->path	};	dict_set (dict, index_key, data_from_int32 (index));	STACK_WIND (frame,		    stripe_create_setxattr_cbk,		    trav->xlator,		    trav->xlator->fops->setxattr,		    &tmp_loc,		    dict,		    0);		index++;	trav = trav->next;      }      dict_destroy (dict);    } else {      /* Create itself has failed.. so return without setxattring */      freee (local->path);            STACK_UNWIND (frame, 		    local->op_ret, 		    local->op_errno, 		    local->fd, 		    local->inode, 		    &local->stbuf);    }  }

⌨️ 快捷键说明

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