Skip to content

Commit

Permalink
[LibOS] Move chroot specific truncate to generic FS operations
Browse files Browse the repository at this point in the history
`generic_truncate` can be used for other file system types.

Signed-off-by: Li, Xun <xun.li@intel.com>
  • Loading branch information
llly authored and mkow committed Sep 4, 2023
1 parent 39b529f commit bc11ecb
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 17 deletions.
1 change: 1 addition & 0 deletions libos/include/libos_fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -943,6 +943,7 @@ int generic_emulated_mmap(struct libos_handle* hdl, void* addr, size_t size, int
uint64_t offset);
int generic_emulated_msync(struct libos_handle* hdl, void* addr, size_t size, int prot, int flags,
uint64_t offset);
int generic_truncate(struct libos_handle* hdl, file_off_t size);

int synthetic_setup_dentry(struct libos_dentry* dent, mode_t type, mode_t perm);

Expand Down
18 changes: 1 addition & 17 deletions libos/src/fs/chroot/fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -338,22 +338,6 @@ static int chroot_mmap(struct libos_handle* hdl, void* addr, size_t size, int pr
return 0;
}

static int chroot_truncate(struct libos_handle* hdl, file_off_t size) {
assert(hdl->type == TYPE_CHROOT);

int ret;

lock(&hdl->inode->lock);
ret = PalStreamSetLength(hdl->pal_handle, size);
if (ret == 0) {
hdl->inode->size = size;
} else {
ret = pal_to_unix_errno(ret);
}
unlock(&hdl->inode->lock);
return ret;
}

int chroot_readdir(struct libos_dentry* dent, readdir_callback_t callback, void* arg) {
int ret;
PAL_HANDLE palhdl;
Expand Down Expand Up @@ -503,7 +487,7 @@ struct libos_fs_ops chroot_fs_ops = {
* breaks for such device-specific cases */
.seek = &generic_inode_seek,
.hstat = &generic_inode_hstat,
.truncate = &chroot_truncate,
.truncate = &generic_truncate,
.poll = &generic_inode_poll,
};

Expand Down
12 changes: 12 additions & 0 deletions libos/src/fs/libos_fs_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -234,3 +234,15 @@ int generic_emulated_msync(struct libos_handle* hdl, void* addr, size_t size, in
}
return ret;
}

int generic_truncate(struct libos_handle* hdl, file_off_t size) {
lock(&hdl->inode->lock);
int ret = PalStreamSetLength(hdl->pal_handle, size);
if (ret == 0) {
hdl->inode->size = size;
} else {
ret = pal_to_unix_errno(ret);
}
unlock(&hdl->inode->lock);
return ret;
}

0 comments on commit bc11ecb

Please sign in to comment.