rebuild: rocksdb dbbench 运行成功
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
#include <unistd.h>
|
||||
#include <limits.h>
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
|
||||
/* ------------------------------------------------------------------ */
|
||||
/* 内部:open 的核心逻辑(路径已解析为绝对路径) */
|
||||
@@ -44,7 +45,15 @@ zvfs_open_impl(int real_fd, const char *abspath, int flags, mode_t mode)
|
||||
|
||||
/* 1. 创建 blob */
|
||||
handle = blob_create(0);
|
||||
if (!handle) { errno = EIO; goto fail; }
|
||||
if (!handle) {
|
||||
int saved = errno;
|
||||
if (saved == 0) saved = EIO;
|
||||
fprintf(stderr,
|
||||
"[zvfs] create blob failed path=%s flags=0x%x errno=%d(%s)\n",
|
||||
abspath, flags, saved, strerror(saved));
|
||||
errno = saved;
|
||||
goto fail;
|
||||
}
|
||||
blob_id = handle->id;
|
||||
|
||||
/* 2. 把 blob_id 写入真实文件的 xattr */
|
||||
@@ -80,7 +89,7 @@ zvfs_open_impl(int real_fd, const char *abspath, int flags, mode_t mode)
|
||||
/* path_cache 命中:直接用缓存的 inode,重新 blob_open */
|
||||
blob_id = inode->blob_id;
|
||||
handle = blob_open(blob_id);
|
||||
if (!handle) { errno = EIO; goto fail; }
|
||||
if (!handle) { if (errno == 0) errno = EIO; goto fail; }
|
||||
/* 共享 inode,增加引用 */
|
||||
atomic_fetch_add(&inode->ref_count, 1);
|
||||
|
||||
@@ -101,7 +110,7 @@ zvfs_open_impl(int real_fd, const char *abspath, int flags, mode_t mode)
|
||||
} else {
|
||||
/* 全新 inode:需从真实文件 stat 获取 mode/size */
|
||||
struct stat st;
|
||||
if (real_fstat(real_fd, &st) < 0) goto fail;
|
||||
if (zvfs_real_fstat(real_fd, &st) < 0) goto fail;
|
||||
|
||||
inode = inode_alloc(blob_id, st.st_mode, ZVFS_ITYPE_FILE);
|
||||
if (!inode) { errno = ENOMEM; goto fail; }
|
||||
@@ -117,7 +126,7 @@ zvfs_open_impl(int real_fd, const char *abspath, int flags, mode_t mode)
|
||||
}
|
||||
|
||||
handle = blob_open(blob_id);
|
||||
if (!handle) { errno = EIO; goto fail; }
|
||||
if (!handle) { if (errno == 0) errno = EIO; goto fail; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -340,11 +349,14 @@ zvfs_close_impl(int fd)
|
||||
return real_close(fd);
|
||||
}
|
||||
|
||||
/* ---- openfile 引用归零:关闭 blob handle --------------------- */
|
||||
/* ---- openfile 引用归零:先刷 metadata,再关闭 blob handle ------ */
|
||||
struct zvfs_inode *inode = of->inode;
|
||||
struct zvfs_blob_handle *handle = of->handle;
|
||||
int sync_failed = 0;
|
||||
openfile_free(of);
|
||||
|
||||
if (blob_sync_md(handle) < 0)
|
||||
sync_failed = 1;
|
||||
blob_close(handle);
|
||||
|
||||
/* ---- inode ref_count-- --------------------------------------- */
|
||||
@@ -391,7 +403,14 @@ zvfs_close_impl(int fd)
|
||||
inode_free(inode);
|
||||
}
|
||||
|
||||
return real_close(fd);
|
||||
int rc = real_close(fd);
|
||||
if (rc < 0)
|
||||
return -1;
|
||||
if (sync_failed) {
|
||||
errno = EIO;
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
|
||||
Reference in New Issue
Block a user