postgres hook 测试成功
This commit is contained in:
@@ -69,21 +69,21 @@ off_t lseek64(int fd, off_t offset, int whence)
|
||||
|
||||
|
||||
/*
|
||||
* zvfs_truncate_by_inode - 对有 handle 的 openfile 做 truncate。
|
||||
* 找到任意一个打开该 inode 的 openfile 取其 handle。
|
||||
* zvfs_truncate_by_inode - 对有 handle_id 的 openfile 做 truncate。
|
||||
* 找到任意一个打开该 inode 的 openfile 取其 handle_id。
|
||||
*/
|
||||
static int
|
||||
zvfs_truncate_inode_with_handle(struct zvfs_inode *inode,
|
||||
int real_fd, uint64_t new_size)
|
||||
{
|
||||
/* 在 fd_table 里找一个指向该 inode 的 openfile 取 handle */
|
||||
struct zvfs_blob_handle *handle = NULL;
|
||||
/* 在 fd_table 里找一个指向该 inode 的 openfile 取 handle_id */
|
||||
uint64_t handle_id = 0;
|
||||
pthread_mutex_lock(&g_fs.fd_mu);
|
||||
struct zvfs_open_file *of, *tmp;
|
||||
HASH_ITER(hh, g_fs.fd_table, of, tmp) {
|
||||
(void)tmp;
|
||||
if (of->inode == inode) {
|
||||
handle = of->handle;
|
||||
handle_id = of->handle_id;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -93,20 +93,23 @@ zvfs_truncate_inode_with_handle(struct zvfs_inode *inode,
|
||||
uint64_t old_size = inode->logical_size;
|
||||
pthread_mutex_unlock(&inode->mu);
|
||||
|
||||
if (new_size != old_size && handle) {
|
||||
if (blob_resize(handle, new_size) < 0) {
|
||||
if (new_size != old_size && handle_id != 0) {
|
||||
if (blob_resize(handle_id, new_size) < 0) {
|
||||
errno = EIO;
|
||||
return -1;
|
||||
}
|
||||
} else if (new_size != old_size && !handle) {
|
||||
} else if (new_size != old_size && handle_id == 0) {
|
||||
/*
|
||||
* 文件未被打开:需要临时 blob_open。
|
||||
* 这种情况下 truncate(path, ...) 被调用但文件没有 fd。
|
||||
*/
|
||||
handle = blob_open(inode->blob_id);
|
||||
if (!handle) { errno = EIO; return -1; }
|
||||
int rc = blob_resize(handle, new_size);
|
||||
blob_close(handle);
|
||||
uint64_t temp_handle_id = 0;
|
||||
if (blob_open(inode->blob_id, &temp_handle_id) < 0) {
|
||||
errno = EIO;
|
||||
return -1;
|
||||
}
|
||||
int rc = blob_resize(temp_handle_id, new_size);
|
||||
blob_close(temp_handle_id);
|
||||
if (rc < 0) { errno = EIO; return -1; }
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user