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

📄 fuse-bridge.c

📁 分布式文件系统
💻 C
📖 第 1 页 / 共 4 页
字号:
    if (!S_ISDIR (fd->inode->st_mode)) {      if ((fi.flags & 3) && priv->direct_io_mode)	  fi.direct_io = 1;    }    gf_log ("glusterfs-fuse", GF_LOG_DEBUG,	    "%"PRId64": (%d) %s => %p", frame->root->unique, frame->op,	    state->fuse_loc.loc.path, fd);    if (fuse_reply_open (req, &fi) == -ENOENT) {      gf_log ("glusterfs-fuse", GF_LOG_WARNING, "open() got EINTR");      state->req = 0;      if (S_ISDIR (fd->inode->st_mode))	FUSE_FOP_NOREPLY (state, GF_FOP_CLOSEDIR, closedir, fd);      else	FUSE_FOP_NOREPLY (state, GF_FOP_CLOSE, close, fd);    }  } else {    gf_log ("glusterfs-fuse", GF_LOG_ERROR,	    "%"PRId64": (%d) %s => -1 (%d)", frame->root->unique,	    frame->op, state->fuse_loc.loc.path, op_errno);    fuse_reply_err (req, op_errno);    fd_destroy (fd);  }  free_state (state);  STACK_DESTROY (frame->root);  return 0;}static voiddo_chmod (fuse_req_t req,	  fuse_ino_t ino,	  struct stat *attr,	  struct fuse_file_info *fi){  fuse_state_t *state = state_from_req (req);  if (fi) {    gf_log ("glusterfs-fuse", GF_LOG_DEBUG,	    "%"PRId64": FCHMOD %p", req_callid (req), FI_TO_FD (fi));    FUSE_FOP (state,	      fuse_attr_cbk,	      GF_FOP_FCHMOD,	      fchmod,	      FI_TO_FD (fi),	      attr->st_mode);  } else {    fuse_loc_fill (&state->fuse_loc, state, ino, NULL);    if (!state->fuse_loc.loc.inode) {      gf_log ("glusterfs-fuse", GF_LOG_ERROR,	      "%"PRId64": CHMOD %"PRId64" (%s) (fuse_loc_fill() returned NULL inode)", 	      req_callid (req), (int64_t)ino, state->fuse_loc.loc.path);      fuse_reply_err (req, EINVAL);      return;    }    gf_log ("glusterfs-fuse", GF_LOG_DEBUG,	    "%"PRId64": CHMOD %s", req_callid (req),	    state->fuse_loc.loc.path);    FUSE_FOP (state,	      fuse_attr_cbk,	      GF_FOP_CHMOD,	      chmod,	      &state->fuse_loc.loc,	      attr->st_mode);  }}static voiddo_chown (fuse_req_t req,	  fuse_ino_t ino,	  struct stat *attr,	  int valid,	  struct fuse_file_info *fi){  fuse_state_t *state;  uid_t uid = (valid & FUSE_SET_ATTR_UID) ? attr->st_uid : (uid_t) -1;  gid_t gid = (valid & FUSE_SET_ATTR_GID) ? attr->st_gid : (gid_t) -1;  state = state_from_req (req);  if (fi) {    gf_log ("glusterfs-fuse", GF_LOG_DEBUG,	    "%"PRId64": FCHOWN %p", req_callid (req), FI_TO_FD (fi));    FUSE_FOP (state,	      fuse_attr_cbk,	      GF_FOP_FCHOWN,	      fchown,	      FI_TO_FD (fi),	      uid,	      gid);  } else {    fuse_loc_fill (&state->fuse_loc, state, ino, NULL);    if (!state->fuse_loc.loc.inode) {      gf_log ("glusterfs-fuse", GF_LOG_ERROR,	      "%"PRId64": CHOWN %"PRId64" (%s) (fuse_loc_fill() returned NULL inode)", 	      req_callid (req), (int64_t)ino, state->fuse_loc.loc.path);      fuse_reply_err (req, EINVAL);      return;    }    gf_log ("glusterfs-fuse", GF_LOG_DEBUG,	    "%"PRId64": CHOWN %s", req_callid (req),	    state->fuse_loc.loc.path);    FUSE_FOP (state,	      fuse_attr_cbk,	      GF_FOP_CHOWN,	      chown,	      &state->fuse_loc.loc,	      uid,	      gid);  }}static void do_truncate (fuse_req_t req,	     fuse_ino_t ino,	     struct stat *attr,	     struct fuse_file_info *fi){  fuse_state_t *state;  state = state_from_req (req);  if (fi) {    gf_log ("glusterfs-fuse", GF_LOG_DEBUG,	    "%"PRId64": FTRUNCATE %p/%"PRId64, req_callid (req),	    FI_TO_FD (fi), attr->st_size);    FUSE_FOP (state,	      fuse_attr_cbk,	      GF_FOP_FTRUNCATE,	      ftruncate,	      FI_TO_FD (fi),	      attr->st_size);  } else {    fuse_loc_fill (&state->fuse_loc, state, ino, NULL);    if (!state->fuse_loc.loc.inode) {      gf_log ("glusterfs-fuse", GF_LOG_ERROR,	      "%"PRId64": TRUNCATE %s/%"PRId64" (fuse_loc_fill() returned NULL inode)", 	      req_callid (req), state->fuse_loc.loc.path, attr->st_size);      fuse_reply_err (req, EINVAL);      return;    }    gf_log ("glusterfs-fuse", GF_LOG_DEBUG,	    "%"PRId64": TRUNCATE %s/%"PRId64, req_callid (req),	    state->fuse_loc.loc.path, attr->st_size);    FUSE_FOP (state,	      fuse_attr_cbk,	      GF_FOP_TRUNCATE,	      truncate,	      &state->fuse_loc.loc,	      attr->st_size);  }  return;}static void do_utimes (fuse_req_t req,	   fuse_ino_t ino,	   struct stat *attr){  fuse_state_t *state;  struct timespec tv[2];#ifdef FUSE_STAT_HAS_NANOSEC  tv[0] = ST_ATIM(attr);  tv[1] = ST_MTIM(attr);#else  tv[0].tv_sec = attr->st_atime;  tv[0].tv_nsec = 0;  tv[1].tv_sec = attr->st_mtime;  tv[1].tv_nsec = 0;#endif  state = state_from_req (req);  fuse_loc_fill (&state->fuse_loc, state, ino, NULL);  if (!state->fuse_loc.loc.inode) {    gf_log ("glusterfs-fuse", GF_LOG_ERROR,	    "%"PRId64": UTIMENS %s (fuse_loc_fill() returned NULL inode)", 	    req_callid (req), state->fuse_loc.loc.path);    fuse_reply_err (req, EINVAL);    return;  }  gf_log ("glusterfs-fuse", GF_LOG_DEBUG,	  "%"PRId64": UTIMENS %s", req_callid (req),	  state->fuse_loc.loc.path);  FUSE_FOP (state,	    fuse_attr_cbk,	    GF_FOP_UTIMENS,	    utimens,	    &state->fuse_loc.loc,	    tv);}static voidfuse_setattr (fuse_req_t req,	      fuse_ino_t ino,	      struct stat *attr,	      int valid,	      struct fuse_file_info *fi){  if (valid & FUSE_SET_ATTR_MODE)    do_chmod (req, ino, attr, fi);  else if (valid & (FUSE_SET_ATTR_UID | FUSE_SET_ATTR_GID))    do_chown (req, ino, attr, valid, fi);  else if (valid & FUSE_SET_ATTR_SIZE)    do_truncate (req, ino, attr, fi);  else if ((valid & (FUSE_SET_ATTR_ATIME | FUSE_SET_ATTR_MTIME)) == (FUSE_SET_ATTR_ATIME | FUSE_SET_ATTR_MTIME))    do_utimes (req, ino, attr);  if (!valid)    fuse_getattr (req, ino, fi);}static int32_tfuse_err_cbk (call_frame_t *frame,	      void *cookie,	      xlator_t *this,	      int32_t op_ret,	      int32_t op_errno){  fuse_state_t *state = frame->root->state;  fuse_req_t req = state->req;  if (op_ret == 0) {    gf_log ("glusterfs-fuse", GF_LOG_DEBUG,	    "%"PRId64": (%d) %s => 0", frame->root->unique, frame->op, 	    state->fuse_loc.loc.path ? state->fuse_loc.loc.path : "ERR");    fuse_reply_err (req, 0);  } else {    gf_log ("glusterfs-fuse", GF_LOG_ERROR,	    "%"PRId64": (%d) %s => -1 (%d)", frame->root->unique, frame->op,	    state->fuse_loc.loc.path ? state->fuse_loc.loc.path : "ERR",	    op_errno);    fuse_reply_err (req, op_errno);  }  if (state->fd)    fd_destroy (state->fd);  free_state (state);  STACK_DESTROY (frame->root);  return 0;}static int32_tfuse_unlink_cbk (call_frame_t *frame,		 void *cookie,		 xlator_t *this,		 int32_t op_ret,		 int32_t op_errno){  fuse_state_t *state = frame->root->state;  fuse_req_t req = state->req;  if (op_ret == 0)    inode_unlink (state->itable, state->fuse_loc.parent, state->fuse_loc.name);  if (op_ret == 0) {    gf_log ("glusterfs-fuse", GF_LOG_DEBUG,	    "%"PRId64": (%d) %s => 0", frame->root->unique,	    frame->op, state->fuse_loc.loc.path);    fuse_reply_err (req, 0);  } else {    gf_log ("glusterfs-fuse", 	    ((op_errno != ENOTEMPTY) ? GF_LOG_ERROR : GF_LOG_DEBUG),	    "%"PRId64": (%d) %s => -1 (%d)", frame->root->unique,	    frame->op, state->fuse_loc.loc.path, op_errno);    fuse_reply_err (req, op_errno);  }  free_state (state);  STACK_DESTROY (frame->root);  return 0;}static voidfuse_access (fuse_req_t req,	     fuse_ino_t ino,	     int mask){  fuse_state_t *state;  state = state_from_req (req);  fuse_loc_fill (&state->fuse_loc, state, ino, NULL);  if (!state->fuse_loc.loc.inode) {    gf_log ("glusterfs-fuse", GF_LOG_ERROR,	    "%"PRId64": ACCESS %"PRId64" (%s) (fuse_loc_fill() returned NULL inode)", 	    req_callid (req), (int64_t)ino, state->fuse_loc.loc.path);    fuse_reply_err (req, EINVAL);    return;  }  FUSE_FOP (state,	    fuse_err_cbk,	    GF_FOP_ACCESS,	    access,	    &state->fuse_loc.loc,	    mask);  return;}static int32_tfuse_readlink_cbk (call_frame_t *frame,		   void *cookie,		   xlator_t *this,		   int32_t op_ret,		   int32_t op_errno,		   const char *linkname){  fuse_state_t *state = frame->root->state;  fuse_req_t req = state->req;  if (op_ret > 0) {    ((char *)linkname)[op_ret] = '\0';    gf_log ("glusterfs-fuse", GF_LOG_DEBUG,	    "%"PRId64": %s => %s", frame->root->unique,	    state->fuse_loc.loc.path, linkname);      fuse_reply_readlink(req, linkname);  } else {    gf_log ("glusterfs-fuse", GF_LOG_ERROR,	    "%"PRId64": %s => -1 (%d)", frame->root->unique,	    state->fuse_loc.loc.path, op_errno);    fuse_reply_err(req, op_errno);  }  free_state (state);  STACK_DESTROY (frame->root);  return 0;}static voidfuse_readlink (fuse_req_t req,	       fuse_ino_t ino){  fuse_state_t *state;  state = state_from_req (req);  fuse_loc_fill (&state->fuse_loc, state, ino, NULL);  if (!state->fuse_loc.loc.inode) {    gf_log ("glusterfs-fuse", GF_LOG_ERROR,	    "%"PRId64" READLINK %s/%"PRId64" (fuse_loc_fill() returned NULL inode)", 	    req_callid (req), state->fuse_loc.loc.path, state->fuse_loc.loc.inode->ino);    fuse_reply_err (req, EINVAL);    return;  }    gf_log ("glusterfs-fuse", GF_LOG_DEBUG,	  "%"PRId64" READLINK %s/%"PRId64, req_callid (req),	  state->fuse_loc.loc.path, state->fuse_loc.loc.inode->ino);  FUSE_FOP (state,	    fuse_readlink_cbk,	    GF_FOP_READLINK,	    readlink,	    &state->fuse_loc.loc,	    4096);  return;}static voidfuse_mknod (fuse_req_t req,	    fuse_ino_t par,	    const char *name,	    mode_t mode,	    dev_t rdev){  fuse_state_t *state;  state = state_from_req (req);  fuse_loc_fill (&state->fuse_loc, state, par, name);  state->fuse_loc.loc.inode = dummy_inode (state->itable);  gf_log ("glusterfs-fuse", GF_LOG_DEBUG,	  "%"PRId64": MKNOD %s", req_callid (req),	  state->fuse_loc.loc.path);  FUSE_FOP (state,	    fuse_entry_cbk,	    GF_FOP_MKNOD,	    mknod,	    &state->fuse_loc.loc,	    mode,	    rdev);  return;}static void fuse_mkdir (fuse_req_t req,	    fuse_ino_t par,	    const char *name,	    mode_t mode){  fuse_state_t *state;  state = state_from_req (req);  fuse_loc_fill (&state->fuse_loc, state, par, name);  state->fuse_loc.loc.inode = dummy_inode (state->itable);  gf_log ("glusterfs-fuse", GF_LOG_DEBUG,	  "%"PRId64": MKDIR %s", req_callid (req),	  state->fuse_loc.loc.path);  FUSE_FOP (state,	    fuse_entry_cbk,	    GF_FOP_MKDIR,	    mkdir,	    &state->fuse_loc.loc,	    mode);  return;}static void fuse_unlink (fuse_req_t req,	     fuse_ino_t par,	     const char *name){  fuse_state_t *state;  state = state_from_req (req);  gf_log ("glusterfs-fuse", GF_LOG_DEBUG,	  "%"PRId64": UNLINK %s", req_callid (req),	  state->fuse_loc.loc.path);  fuse_loc_fill (&state->fuse_loc, state, par, name);  if (!state->fuse_loc.loc.inode) {    gf_log ("glusterfs-fuse", GF_LOG_ERROR,	    "%"PRId64": UNLINK %s (fuse_loc_fill() returned NULL inode)", req_callid (req),	    state->fuse_loc.loc.path);    fuse_reply_err (req, EINVAL);    return;  }  FUSE_FOP (state,	    fuse_unlink_cbk,	    GF_FOP_UNLINK,	    unlink,	    &state->fuse_loc.loc);  return;}static void fuse_rmdir (fuse_req_t req,	    fuse_ino_t par,	    const char *name){  fuse_state_t *state;  state = state_from_req (req);  fuse_loc_fill (&state->fuse_loc, state, par, name);  if (!state->fuse_loc.loc.inode) {    gf_log ("glusterfs-fuse", GF_LOG_DEBUG,	    "%"PRId64": RMDIR %s (fuse_loc_fill() returned NULL inode)", req_callid (req),	    state->fuse_loc.loc.path);    fuse_reply_err (req, EINVAL);    return;  }  gf_log ("glusterfs-fuse", GF_LOG_DEBUG,	  "%"PRId64": RMDIR %s", req_callid (req),	  state->fuse_loc.loc.path);  FUSE_FOP (state,	    fuse_unlink_cbk,	    GF_FOP_RMDIR,	    rmdir,	    &state->fuse_loc.loc);  return;}static voidfuse_symlink (fuse_req_t req,	      const char *linkname,	      fuse_ino_t par,	      const char *name){  fuse_state_t *state;  state = state_from_req (req);  fuse_loc_fill (&state->fuse_loc, state, par, name);  state->fuse_loc.loc.inode = dummy_inode (state->itable);  gf_log ("glusterfs-fuse", GF_LOG_DEBUG,	  "%"PRId64": SYMLINK %s -> %s", req_callid (req),	  state->fuse_loc.loc.path, linkname);  FUSE_FOP (state,	    fuse_entry_cbk,	    GF_FOP_SYMLINK,	    symlink,	    linkname,	    &state->fuse_loc.loc);  return;}int32_tfuse_rename_cbk (call_frame_t *frame,		 void *cookie,		 xlator_t *this,		 int32_t op_ret,		 int32_t op_errno,		 struct stat *buf){  fuse_state_t *state = frame->root->state;  fuse_req_t req = state->req;  if (op_ret == 0) {    gf_log ("glusterfs-fuse", GF_LOG_DEBUG,	    "%"PRId64": %s -> %s => 0", frame->root->unique,	    state->fuse_loc.loc.path,	    state->fuse_loc2.loc.path);    inode_t *inode;    {      /* ugly ugly - to stay blind to situation where	 rename happens on a new inode      */      buf->st_ino = state->fuse_loc.loc.ino;    }    inode = inode_rename (state->itable,			  state->fuse_loc.parent,			  state->fuse_loc.name,			  state->fuse_loc2.parent,			  state->fuse_loc2.name,			  buf);    inode_unref (inode);    fuse_reply_err (req, 0);  } else {    gf_log ("glusterfs-fuse", GF_LOG_ERROR,	    "%"PRId64": %s -> %s => -1 (%d)", frame->root->unique,	    state->fuse_loc.loc.path,	    state->fuse_loc2.loc.path, op_errno);    fuse_reply_err (req, op_errno);  }  free_state (state);  STACK_DESTROY (frame->root);  return 0;}static voidfuse_rename (fuse_req_t req,	     fuse_ino_t oldpar,	     const char *oldname,	     fuse_ino_t newpar,	     const char *newname){  fuse_state_t *state;  state = state_from_req (req);  fuse_loc_fill (&state->fuse_loc, state, oldpar, oldname);  if (!state->fuse_loc.loc.inode) {    gf_log ("glusterfs-fuse", GF_LOG_ERROR,	    "for %s %"PRId64": RENAME `%s' -> `%s' (fuse_loc_fill() returned NULL inode)",	    state->fuse_loc.loc.path, req_callid (req), state->fuse_loc.loc.path,	    state->fuse_loc2.loc.path);        fuse_reply_err (req, EINVAL);    return;  }  fuse_loc_fill (&state->fuse_loc2, state, newpar, newname);  gf_log ("glusterfs-fuse", GF_LOG_DEBUG,	  "%"PRId64": RENAME `%s' -> `%s'",	  req_callid (req), state->fuse_loc.loc.path,	  state->fuse_loc2.loc.path);  FUSE_FOP (state,	    fuse_rename_cbk,	    GF_FOP_RENAME,	    rename,	    &state->fuse_loc.loc,	    &state->fuse_loc2.loc);  return;}static voidfuse_link (fuse_req_t req,	   fuse_ino_t ino,	   fuse_ino_t par,	   const char *name){  fuse_state_t *state;  state = state_from_req (req);  fuse_loc_fill (&state->fuse_loc, state, par, name);  fuse_loc_fill (&state->fuse_loc2, state, ino, NULL);  if (!state->fuse_loc2.loc.inode) {    gf_log ("glusterfs-fuse", GF_LOG_ERROR,	    "fuse_loc_fill() returned NULL inode for %s %"PRId64": LINK %s %s", 	    state->fuse_loc2.loc.path, req_callid (req), 	    state->fuse_loc2.loc.path, state->fuse_loc.loc.path);    fuse_reply_err (req, EINVAL);    return;  }  state->fuse_loc.loc.inode = inode_ref (state->fuse_loc2.loc.inode);  gf_log ("glusterfs-fuse", GF_LOG_DEBUG,	  "%"PRId64": LINK %s %s", req_callid (req),	  state->fuse_loc2.loc.path, state->fuse_loc.loc.path);  FUSE_FOP (state,	    fuse_entry_cbk,	    GF_FOP_LINK,	    link,	    &state->fuse_loc2.loc,	    state->fuse_loc.loc.path);  return;}static int32_tfuse_create_cbk (call_frame_t *frame,

⌨️ 快捷键说明

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