📄 posix.c
字号:
"O_DIRECT enabled: %s", strerror (op_errno)); } break; } op_ret += retval; } /* Free the allocated aligned buffer */ free (alloc_buf); } else /* if (O_DIRECT) */ { /* This is not O_DIRECT'd fd */ op_ret = writev (_fd, vector, count); op_errno = errno; if (op_ret == -1) { gf_log (this->name, GF_LOG_WARNING, "writev failed: %s", strerror (op_errno)); } } priv->write_value += op_ret; priv->interval_write += op_ret; if (op_ret >= 0) { /* wiretv successful, we also need to get the stat of * the file we wrote to */ fstat (_fd, &stbuf); } frame->root->rsp_refs = NULL; STACK_UNWIND (frame, op_ret, op_errno, &stbuf); return 0;}int32_t posix_statfs (call_frame_t *frame, xlator_t *this, loc_t *loc){ char *real_path; int32_t op_ret = 0; int32_t op_errno = 0; struct statvfs buf = {0, }; struct posix_private *priv = this->private; MAKE_REAL_PATH (real_path, this, loc->path); op_ret = statvfs (real_path, &buf); op_errno = errno; if (op_ret == -1) { gf_log (this->name, GF_LOG_ERROR, "statvfs: %s", strerror (op_errno)); } if (!priv->export_statfs) { buf.f_blocks = 0; buf.f_bfree = 0; buf.f_bavail = 0; buf.f_files = 0; buf.f_ffree = 0; buf.f_favail = 0; } frame->root->rsp_refs = NULL; STACK_UNWIND (frame, op_ret, op_errno, &buf); return 0;}int32_t posix_flush (call_frame_t *frame, xlator_t *this, fd_t *fd){ int32_t op_ret = 0; int32_t op_errno = 0; int32_t _fd; data_t *pfd_data = dict_get (fd->ctx, this->name); struct posix_fd *pfd; if (pfd_data == NULL) { gf_log (this->name, GF_LOG_ERROR, "pfd_data is NULL on fd=%p", fd); frame->root->rsp_refs = NULL; STACK_UNWIND (frame, -1, EBADF); return 0; } pfd = data_to_ptr (pfd_data); if (!pfd) { gf_log (this->name, GF_LOG_ERROR, "pfd is NULL on fd=%p", fd); STACK_UNWIND (frame, -1, EBADF); return 0; } _fd = pfd->fd; /* do nothing */ frame->root->rsp_refs = NULL; STACK_UNWIND (frame, op_ret, op_errno); return 0;}int32_t posix_close (call_frame_t *frame, xlator_t *this, fd_t *fd){ int32_t op_ret; int32_t op_errno; int32_t _fd; struct posix_private *priv = this->private; data_t *pfd_data = dict_get (fd->ctx, this->name); struct posix_fd *pfd; priv->stats.nr_files--; frame->root->rsp_refs = NULL; if (pfd_data == NULL) { gf_log (this->name, GF_LOG_ERROR, "pfd_data is NULL from fd=%p", fd); STACK_UNWIND (frame, -1, EBADF); return 0; } pfd = data_to_ptr (pfd_data); if (!pfd) { gf_log (this->name, GF_LOG_ERROR, "pfd is NULL from fd=%p", fd); STACK_UNWIND (frame, -1, EBADF); return 0; } _fd = pfd->fd; op_ret = close (_fd); op_errno = errno; if (op_ret == -1) { gf_log (this->name, GF_LOG_WARNING, "close(): %s", strerror (op_errno)); } if (pfd->dir) { gf_log (this->name, GF_LOG_ERROR, "pfd->dir is %p (not NULL) for file fd=%p", pfd->dir, fd); free (pfd); STACK_UNWIND (frame, -1, EBADF); return 0; } free (pfd); STACK_UNWIND (frame, op_ret, op_errno); return 0;}int32_t posix_fsync (call_frame_t *frame, xlator_t *this, fd_t *fd, int32_t datasync){ int32_t op_ret = -1; int32_t op_errno = ENOSYS; int32_t _fd; data_t *pfd_data = dict_get (fd->ctx, this->name); struct posix_fd *pfd; DECLARE_OLD_FS_UID_VAR; frame->root->rsp_refs = NULL; if (pfd_data == NULL) { gf_log (this->name, GF_LOG_ERROR, "pfd_data is NULL from fd=%p", fd); STACK_UNWIND (frame, -1, EBADF); return 0; } pfd = data_to_ptr (pfd_data); if (!pfd) { gf_log (this->name, GF_LOG_ERROR, "pfd is NULL for fd=%p", fd); STACK_UNWIND (frame, -1, EBADF); return 0; } _fd = pfd->fd; SET_FS_UID (frame->root->uid, frame->root->gid); if (datasync) { ;#ifdef HAVE_FDATASYNC op_ret = fdatasync (_fd);#endif } else { op_ret = fsync (_fd); op_errno = errno; if (op_ret == -1) { gf_log (this->name, GF_LOG_WARNING, "fsync: %s", strerror (op_errno)); } } SET_TO_OLD_FS_UID ();#ifdef GF_DARWIN_HOST_OS /* Always return success in case of fsync in MAC OS X */ op_ret = 0;#endif STACK_UNWIND (frame, op_ret, op_errno); return 0;}int32_tposix_incver (call_frame_t *frame, xlator_t *this, const char *path){ char *real_path; char version[50]; int32_t size = 0; int32_t ver = 0; MAKE_REAL_PATH (real_path, this, path); size = lgetxattr (real_path, GLUSTERFS_VERSION, version, 50); if ((size == -1) && (errno != ENODATA)) { gf_log (this->name, GF_LOG_WARNING, "lgetxattr: %s", strerror(errno)); STACK_UNWIND (frame, -1, errno); return 0; } else { version[size] = '\0'; ver = strtoll (version, NULL, 10); } ver++; sprintf (version, "%u", ver); lsetxattr (real_path, GLUSTERFS_VERSION, version, strlen (version), 0); STACK_UNWIND (frame, ver, 0); return 0;}int32_t posix_setxattr (call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *dict, int flags){ int32_t op_ret = -1; int32_t op_errno = 0; char *real_path; data_pair_t *trav = dict->members_list; DECLARE_OLD_FS_UID_VAR; MAKE_REAL_PATH (real_path, this, loc->path); SET_FS_UID (frame->root->uid, frame->root->gid); while (trav) { op_ret = lsetxattr (real_path, trav->key, trav->value->data, trav->value->len, flags); op_errno = errno; if ((op_ret == -1) && (op_errno != ENOENT)) { gf_log (this->name, GF_LOG_WARNING, "setxattr on %s with key (%s): %s", loc->path, trav->key, strerror (op_errno)); break; } trav = trav->next; } SET_TO_OLD_FS_UID (); frame->root->rsp_refs = NULL; STACK_UNWIND (frame, op_ret, op_errno); return 0;}/** * posix_getxattr - this function returns a dictionary with all the * key:value pair present as xattr. used for both 'listxattr' and * 'getxattr'. */int32_t posix_getxattr (call_frame_t *frame, xlator_t *this, loc_t *loc){ int32_t op_ret = -1; int32_t op_errno = ENOENT; int32_t list_offset = 0; size_t size = 0; size_t remaining_size = 0; char key[1024] = {0,}; char *value = NULL; char *list = NULL; char *real_path = NULL; dict_t *dict = NULL; DECLARE_OLD_FS_UID_VAR; MAKE_REAL_PATH (real_path, this, loc->path); /* Get the total size */ dict = get_new_dict (); SET_FS_UID (frame->root->uid, frame->root->gid); size = llistxattr (real_path, NULL, 0); op_errno = errno; if (size <= 0) { SET_TO_OLD_FS_UID (); /* There are no extended attributes, send an empty dictionary */ if (dict) { dict_ref (dict); } if (size == -1 && op_errno != ENODATA) { gf_log (this->name, GF_LOG_WARNING, "listxattr on %s: %s", loc->path, strerror (op_errno)); } frame->root->rsp_refs = NULL; STACK_UNWIND (frame, size, op_errno, dict); if (dict) dict_unref (dict); return 0; } list = alloca (size + 1); size = llistxattr (real_path, list, size); remaining_size = size; list_offset = 0; while (remaining_size > 0) { if(*(list+list_offset) == '\0') break; strcpy (key, list + list_offset); op_ret = lgetxattr (real_path, key, NULL, 0); if (op_ret == -1) break; value = calloc (op_ret + 1, sizeof(char)); op_ret = lgetxattr (real_path, key, value, op_ret); if (op_ret == -1) break; value [op_ret] = '\0'; dict_set (dict, key, data_from_dynptr (value, op_ret)); remaining_size -= strlen (key) + 1; list_offset += strlen (key) + 1; } SET_TO_OLD_FS_UID (); if (dict) { dict_ref (dict); } frame->root->rsp_refs = NULL; STACK_UNWIND (frame, size, op_errno, dict); if (dict) dict_unref (dict); return 0;} int32_t posix_removexattr (call_frame_t *frame, xlator_t *this, loc_t *loc, const char *name){ int32_t op_ret; int32_t op_errno; char *real_path; DECLARE_OLD_FS_UID_VAR; MAKE_REAL_PATH (real_path, this, loc->path); SET_FS_UID (frame->root->uid, frame->root->gid); op_ret = lremovexattr (real_path, name); op_errno = errno; if (op_ret == -1) { gf_log (this->name, GF_LOG_WARNING, "removexattr on %s: %s", loc->path, strerror (op_errno)); } SET_TO_OLD_FS_UID (); frame->root->rsp_refs = NULL; STACK_UNWIND (frame, op_ret, op_errno); return 0;}int32_t posix_fsyncdir (call_frame_t *frame, xlator_t *this, fd_t *fd, int datasync){ int32_t op_ret; int32_t op_errno; data_t *pfd_data = dict_get (fd->ctx, this->name); struct posix_fd *pfd; int32_t _fd; frame->root->rsp_refs = NULL; if (pfd_data == NULL) { gf_log (this->name, GF_LOG_ERROR, "pfd_data is NULL fd=%p", fd); STACK_UNWIND (frame, -1, EBADF); return 0; } pfd = data_to_ptr (pfd_data); if (!pfd) { gf_log (this->name, GF_LOG_ERROR, "pfd is NULL fd=%p", fd); STACK_UNWIND (frame, -1, EBADF); return 0; } _fd = pfd->fd; op_ret = 0; op_errno = errno; STACK_UNWIND (frame, op_ret, op_errno); return 0;}int32_t posix_access (call_frame_t *frame, xlator_t *this, loc_t *loc, int32_t mask){ int32_t op_ret; int32_t op_errno; char *real_path; DECLARE_OLD_FS_UID_VAR; MAKE_REAL_PATH (real_path, this, loc->path); SET_FS_UID (frame->root->uid, frame->root->gid); op_ret = access (real_path, mask); op_errno = errno; if (op_ret == -1) { gf_log (this->name, GF_LOG_WARNING, "access on %s: %s", loc->path, strerror (op_errno)); } SET_TO_OLD_FS_UID (); frame->root->rsp_refs = NULL; STACK_UNWIND (frame, op_ret, op_errno); return 0;}int32_t posix_ftruncate (call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset){ int32_t op_ret; int32_t op_errno; int32_t _fd = 0; struct stat buf; data_t *pfd_data = dict_get (fd->ctx, this->name); struct posix_fd *pfd; DECLARE_OLD_FS_UID_VAR; frame->root->rsp_refs = NULL; if (pfd_data == NULL) { gf_log (this->name, GF_LOG_ERROR, "pfd_data is NULL fd=%p", fd); STACK_UNWIND (frame, -1, EBADF); return 0; } pfd = data_to_ptr (pfd_data); if (!pfd) { gf_log (this->name, GF_LOG_ERROR, "pfd is NULL fd=%p", fd); STACK_UNWIND (frame, -1, EBADF); return 0; } _fd = pfd->fd; SET_FS_UID (frame->root->uid, frame->root->gid); op_ret = ftruncate (_fd, offset); op_errno = errno; if (op_ret == -1) { gf_log (this->name, GF_LOG_WARNING, "ftruncate: %s", strerror (op_errno)); } if (op_ret == 0) fstat (_fd, &buf); SET_TO_OLD_FS_UID (); frame->root->rsp_refs = NULL; STACK_UNWIND (frame, op_ret, op_errno, &buf); return 0;}int32_t posix_fchown (call_frame_t *frame, xlator_t *this, fd_t *fd, uid_t uid, gid_t gid){ int32_t op_ret; int32_t op_errno; int32_t _fd; struct stat buf; data_t *pfd_data = dict_get (fd->ctx, this->name); struct posix_fd *pfd; DECLARE_OLD_FS_UID_VAR; frame->root->rsp_refs = NULL; if (pfd_data == NULL) { gf_log (this->name, GF_LOG_ERROR, "pfd_data is NULL fd=%p", fd); STACK_UNWIND (frame, -1, EBADF); return 0; } pfd = data_to_ptr (pfd_data); if (!pfd) { gf_log (this->name, GF_LOG_ERROR, "pfd is NULL fd=%p", fd); STACK_UNWIND (frame, -1, EBADF); return 0; } _fd = pfd->fd; SET_FS_UID (frame->root->uid, frame->root->gid); op_ret = fchown (_fd, uid, gid); op_errno = errno; if (op_ret == -1) { gf_log (this->name, GF_LOG_WARNING, "fchown: %s", strerror (op_errno)); } if (op_ret == 0) fstat (_fd, &buf); SET_TO_OLD_FS_UID (); STACK_UNWIND (frame, op_ret, op_errno, &buf); return 0;}int32_t posix_fchmod (call_frame_t *frame, xlator_t *this, fd_t *fd, mode_t mode){ int32_t op_ret; int32_t op_errno; int32_t _fd; struct stat buf; data_t *pfd_data = dict_get (fd->ctx, this->name); struct posix_fd *pfd; DECLARE_OLD_FS_UID_VAR; if (pfd_data == NULL) { gf_log (this->name, GF_LOG_ERROR, "pfd_data is NULL fd=%p", fd); STACK_UNWIND (frame, -1, EBADF); return 0; } pfd = data_to_ptr (pfd_data); if (!pfd) { gf_log (this->name, GF_LOG_ERROR, "pfd is NULL fd=%p", fd); STACK_UNWIND (frame, -1, EBADF); return 0; } _fd = pfd->fd; SET_FS_UID (frame->root->uid, frame->root->gid); op_ret = fchmod (_fd, mode);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -