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

📄 client-protocol.c

📁 分布式文件系统
💻 C
📖 第 1 页 / 共 5 页
字号:
	      mode_t mode,	      dev_t dev){  int32_t ret = -1;  dict_t *request = NULL;  client_local_t *local = NULL;  local = calloc (1, sizeof (client_local_t));  local->inode = loc->inode;  frame->local = local;  request = get_new_dict ();  dict_set (request, "PATH", str_to_data ((char *)loc->path));  dict_set (request, "MODE", data_from_int64 (mode));  dict_set (request, "DEV", data_from_int64 (dev));  dict_set (request, "CALLER_UID", data_from_uint64 (frame->root->uid));  dict_set (request, "CALLER_GID", data_from_uint64 (frame->root->gid));  ret = client_protocol_xfer (frame, this, GF_OP_TYPE_FOP_REQUEST,			      GF_FOP_MKNOD, request);  dict_destroy (request);  return ret;}/** * client_mkdir - mkdir function for client protocol * @frame: call frame * @this: this translator structure * @path: pathname of directory * @mode: * * external reference through client_protocol_xlator->fops->mkdir */int32_t client_mkdir (call_frame_t *frame,	      xlator_t *this,	      loc_t *loc,	      mode_t mode){  int32_t ret = -1;  dict_t *request = NULL;  client_local_t *local = NULL;  local = calloc (1, sizeof (client_local_t));  local->inode = loc->inode;  frame->local = local;  request = get_new_dict ();  dict_set (request, "PATH", str_to_data ((char *)loc->path));  dict_set (request, "MODE", data_from_int64 (mode));  dict_set (request, "CALLER_UID", data_from_uint64 (frame->root->uid));  dict_set (request, "CALLER_GID", data_from_uint64 (frame->root->gid));  ret = client_protocol_xfer (frame, this, GF_OP_TYPE_FOP_REQUEST,			      GF_FOP_MKDIR, request);  dict_destroy (request);  return ret;}/** * client_unlink - unlink function for client protocol * @frame: call frame * @this: this translator structure * @loc: location of file * * external reference through client_protocol_xlator->fops->unlink */int32_t client_unlink (call_frame_t *frame,	       xlator_t *this,	       loc_t *loc){  ino_t ino = 0;  int32_t ret = -1;  dict_t *request = NULL;  data_t *ino_data = NULL;  if (loc && loc->inode && loc->inode->ctx)    ino_data = dict_get (loc->inode->ctx, this->name);    if (ino_data) {    ino = data_to_uint64 (ino_data);  } else {    gf_log (this->name, GF_LOG_ERROR, "%s: returning EINVAL", loc->path);    TRAP_ON (ino_data == NULL);    frame->root->rsp_refs = NULL;    STACK_UNWIND (frame, -1, EINVAL);    return 0;  }  request = get_new_dict ();  dict_set (request, "PATH", str_to_data ((char *)loc->path));  dict_set (request, "INODE", data_from_uint64 (ino));  ret = client_protocol_xfer (frame, this, GF_OP_TYPE_FOP_REQUEST,			      GF_FOP_UNLINK, request);  dict_destroy (request);  return ret;}int32_tclient_rmelem (call_frame_t *frame,	       xlator_t *this,	       const char *path){  int32_t ret = -1;  dict_t *request = NULL;      request = get_new_dict();  dict_set (request, "PATH", str_to_data ((char *)path));  ret = client_protocol_xfer (frame, this, GF_OP_TYPE_FOP_REQUEST,			      GF_FOP_RMELEM, request);  dict_destroy (request);  return ret;}/** * client_rmdir - rmdir function for client protocol * @frame: call frame * @this: this translator structure * @loc: location * * external reference through client_protocol_xlator->fops->rmdir */int32_t client_rmdir (call_frame_t *frame,	      xlator_t *this,	      loc_t *loc){  ino_t ino = 0;  int32_t ret = -1;  dict_t *request = NULL;  data_t *ino_data = NULL;  if (loc && loc->inode && loc->inode->ctx)    ino_data = dict_get (loc->inode->ctx, this->name);  if (ino_data) {    ino = data_to_uint64 (ino_data);  } else {    gf_log (this->name, GF_LOG_ERROR, "%s: returning EINVAL", loc->path);    TRAP_ON (ino_data == NULL);    frame->root->rsp_refs = NULL;    STACK_UNWIND (frame, -1, EINVAL);    return 0;  }  request = get_new_dict ();  dict_set (request, "PATH", str_to_data ((char *)loc->path));  dict_set (request, "INODE", data_from_uint64 (ino));  ret = client_protocol_xfer (frame, this, GF_OP_TYPE_FOP_REQUEST,			      GF_FOP_RMDIR, request);  dict_destroy (request);  return ret;}/** * client_symlink - symlink function for client protocol * @frame: call frame * @this: this translator structure * @oldpath: pathname of target * @newpath: pathname of symlink * * external reference through client_protocol_xlator->fops->symlink */int32_t client_symlink (call_frame_t *frame,		xlator_t *this,		const char *linkname,		loc_t *loc){  int32_t ret = -1;  dict_t *request = NULL;  client_local_t *local = NULL;  local = calloc (1, sizeof (client_local_t));  local->inode = loc->inode;  frame->local = local;  request = get_new_dict ();  dict_set (request, "PATH", str_to_data ((char *)loc->path));  dict_set (request, "SYMLINK", str_to_data ((char *)linkname));  dict_set (request, "CALLER_UID", data_from_uint64 (frame->root->uid));  dict_set (request, "CALLER_GID", data_from_uint64 (frame->root->gid));  ret = client_protocol_xfer (frame, this, GF_OP_TYPE_FOP_REQUEST,			      GF_FOP_SYMLINK, request);  dict_destroy (request);  return ret;}/** * client_rename - rename function for client protocol * @frame: call frame * @this: this translator structure * @oldloc: location of old pathname * @newloc: location of new pathname * * external reference through client_protocol_xlator->fops->rename */int32_t client_rename (call_frame_t *frame,	       xlator_t *this,	       loc_t *oldloc,	       loc_t *newloc){  int32_t ret = -1;  ino_t ino = 0, newino = 0;  dict_t *request = NULL;  data_t *ino_data = NULL;  data_t *newino_data = NULL;    if (oldloc && oldloc->inode && oldloc->inode->ctx)    ino_data = dict_get (oldloc->inode->ctx, this->name);  if (ino_data) {    ino = data_to_uint64 (ino_data);  } else {    gf_log (this->name, GF_LOG_ERROR, "%s -> %s: returning EINVAL", 	    oldloc->path, newloc->path);    TRAP_ON (ino_data == NULL);    frame->root->rsp_refs = NULL;    STACK_UNWIND (frame, -1, EINVAL, NULL);    return 0;  }  if (newloc && newloc->inode && newloc->inode->ctx) {    newino_data = dict_get (newloc->inode->ctx, this->name);    if (newino_data)       newino = data_to_uint64 (newino_data);  }  request = get_new_dict ();  dict_set (request, "PATH", str_to_data ((char *)oldloc->path));  dict_set (request, "INODE", data_from_uint64 (ino));  dict_set (request, "NEWPATH", str_to_data ((char *)newloc->path));  dict_set (request, "NEWINODE", data_from_uint64 (newino));  dict_set (request, "CALLER_UID", data_from_uint64 (frame->root->uid));  dict_set (request, "CALLER_GID", data_from_uint64 (frame->root->gid));  ret = client_protocol_xfer (frame, this, GF_OP_TYPE_FOP_REQUEST,			      GF_FOP_RENAME, request);  dict_destroy (request);  return ret;}/** * client_link - link function for client protocol * @frame: call frame * @this: this translator structure * @oldloc: location of old pathname * @newpath: new pathname * * external reference through client_protocol_xlator->fops->link */int32_t client_link (call_frame_t *frame,	     xlator_t *this,	     loc_t *oldloc,	     const char *newpath){  ino_t oldino = 0;  int32_t ret = -1;  dict_t *request = NULL;  data_t *oldino_data = NULL;  client_local_t *local = NULL;  if (oldloc && oldloc->inode && oldloc->inode->ctx)    oldino_data = dict_get (oldloc->inode->ctx, this->name);  if (oldino_data) {    oldino = data_to_uint64 (oldino_data);  } else {    gf_log (this->name, GF_LOG_ERROR, 	    "%s -> %s: returning EINVAL", oldloc->path, newpath);    TRAP_ON (oldino_data == NULL);    frame->root->rsp_refs = NULL;    STACK_UNWIND (frame, -1, EINVAL, NULL, NULL);    return 0;  }  local = calloc (1, sizeof (client_local_t));  local->inode = oldloc->inode;  frame->local = local;  request = get_new_dict ();  dict_set (request, "PATH", str_to_data ((char *)oldloc->path));  dict_set (request, "INODE", data_from_uint64 (oldino));  dict_set (request, "LINK", str_to_data ((char *)newpath));  dict_set (request, "CALLER_UID", data_from_uint64 (frame->root->uid));  dict_set (request, "CALLER_GID", data_from_uint64 (frame->root->gid));  ret = client_protocol_xfer (frame, this, GF_OP_TYPE_FOP_REQUEST,			      GF_FOP_LINK, request);  dict_destroy (request);  return ret;}/** * client_chmod - chmod function for client protocol * @frame: call frame * @this: this translator structure * @loc: location  * @mode: * * external reference through client_protocol_xlator->fops->chmod */int32_t client_chmod (call_frame_t *frame,	      xlator_t *this,	      loc_t *loc,	      mode_t mode){  ino_t ino = 0;  int32_t ret = -1;  dict_t *request = NULL;  data_t *ino_data = NULL;  if (loc && loc->inode && loc->inode->ctx)    ino_data = dict_get (loc->inode->ctx, this->name);  if (ino_data) {    ino = data_to_uint64 (ino_data);  } else {    gf_log (this->name, GF_LOG_ERROR, "%s: returning EINVAL", loc->path);    TRAP_ON (ino_data == NULL);    frame->root->rsp_refs = NULL;    STACK_UNWIND (frame, -1, EINVAL, NULL);    return 0;  }  request = get_new_dict ();  dict_set (request, "PATH", str_to_data ((char *)loc->path));  dict_set (request, "INODE", data_from_uint64 (ino));  dict_set (request, "MODE", data_from_int64 (mode));  ret = client_protocol_xfer (frame, this, GF_OP_TYPE_FOP_REQUEST,			      GF_FOP_CHMOD, request);  dict_destroy (request);  return ret;}/** * client_chown - chown function for client protocol * @frame: call frame * @this: this translator structure * @loc: location * @uid: uid of new owner * @gid: gid of new owner group * * external reference through client_protocol_xlator->fops->chown */int32_t client_chown (call_frame_t *frame,	      xlator_t *this,	      loc_t *loc,	      uid_t uid,	      gid_t gid){  ino_t ino = 0;  int32_t ret = -1;  dict_t *request = NULL;  data_t *ino_data = NULL;  if (loc && loc->inode && loc->inode->ctx)    ino_data = dict_get (loc->inode->ctx, this->name);  if (ino_data) {    ino = data_to_uint64 (ino_data);  } else {    gf_log (this->name, GF_LOG_ERROR, "%s: returning EINVAL", loc->path);    TRAP_ON (ino_data == NULL);    frame->root->rsp_refs = NULL;    STACK_UNWIND (frame, -1, EINVAL, NULL);    return 0;  }  request = get_new_dict ();  dict_set (request, "PATH", str_to_data ((char *)loc->path));  dict_set (request, "INODE", data_from_uint64 (ino));  dict_set (request, "CALLER_UID", data_from_uint64 (frame->root->uid));  dict_set (request, "CALLER_GID", data_from_uint64 (frame->root->gid));  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_CHOWN, request);  dict_destroy (request);  return ret;}/** * client_truncate - truncate function for client protocol * @frame: call frame * @this: this translator structure * @loc: location * @offset: * * external reference through client_protocol_xlator->fops->truncate */int32_t client_truncate (call_frame_t *frame,		 xlator_t *this,		 loc_t *loc,		 off_t offset){  ino_t ino = 0;  int32_t ret = -1;  dict_t *request = NULL;  data_t *ino_data = NULL;  if (loc && loc->inode && loc->inode->ctx)    ino_data = dict_get (loc->inode->ctx, this->name);  if (ino_data) {    ino = data_to_uint64 (ino_data);  } else {    gf_log (this->name, GF_LOG_ERROR, "%s: returning EINVAL", loc->path);    TRAP_ON (ino_data == NULL);    frame->root->rsp_refs = NULL;    STACK_UNWIND (frame, -1, EINVAL, NULL);    return 0;  }  request = get_new_dict ();  dict_set (request, "PATH", str_to_data ((char *)loc->path));  dict_set (request, "INODE", data_from_uint64 (ino));  dict_set (request, "OFFSET", data_from_int64 (offset));  ret = client_protocol_xfer (frame, this, GF_OP_TYPE_FOP_REQUEST,			      GF_FOP_TRUNCATE, request);  dict_destroy (request);  return ret;}/** * client_utimes - utimes function for client protocol * @frame: call frame * @this: this translator structure * @loc: location * @tvp: * * external reference through client_protocol_xlator->fops->utimes */int32_t client_utimens (call_frame_t *frame,		xlator_t *this,		loc_t *loc,		struct timespec *tvp){  ino_t ino = 0;  int32_t ret = -1;  dict_t *request = NULL;  data_t *ino_data = NULL;  if (loc && loc->inode && loc->inode->ctx)    ino_data = dict_get (loc->inode->ctx, this->name);  if (ino_data) {    ino = data_to_uint64 (ino_data);  } else {    gf_log (this->name, GF_LOG_ERROR, "%s: returning EINVAL", loc->path);    TRAP_ON (ino_data == NULL);    frame->root->rsp_refs = NULL;    STACK_UNWIND (frame, -1, EINVAL, NULL);    return 0;  }  request = get_new_dict ();  dict_set (request, "PATH", str_to_data ((char *)loc->path));  dict_set (request, "INODE", data_from_uint64 (ino));  dict_set (request, "ACTIME_SEC", data_from_int64 (tvp[0].tv_sec));  dict_set (request, "ACTIME_NSEC", data_from_int64 (tvp[0].tv_nsec));  dict_set (request, "MODTIME_SEC", data_from_int64 (tvp[1].tv_sec));  dict_set (request, "MODTIME_NSEC", data_from_int64 (tvp[1].tv_nsec));  ret = client_protocol_xfer (frame, this, GF_OP_TYPE_FOP_REQUEST,			      GF_FOP_UTIMENS, request);  dict_destroy (request);  return ret;}/** * client_readv - readv function for client protocol * @frame: call frame * @this: this translator structure * @fd: file descriptor structure * @size: * @offset: * * external reference through client_protocol_xlator->fops->readv */int32_t client_readv (call_frame_t *frame,	      xlator_t *this,	      fd_t *fd,	      size_t size,	      off_t offset){  int32_t ret = -1;  char *fd_str = NULL;  dict_t *request = NULL;  data_t *ctx_data = NULL;  if (fd && fd->ctx)    ctx_data = dict_get (fd->ctx, this->name);  if (!ctx_data) {    struct iovec vec;    struct stat dummy = {0, };

⌨️ 快捷键说明

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