Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/live-snapshot.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,5 @@ A failed seal needs no rollback: it only appends, leaving an unreachable index a
## Limitations

- Snapshots are not supported with a warpfile upper layer (`upper.target`).
- With a hybrid or sparse upper, writes do not take the snapshot's write lock, so the caller must pause writes while a snapshot runs.
- Write paths and snapshots are mutually exclusive through a read-write lock; writes block until the snapshot finishes, so the caller does not need to pause writes.
- Snapshots on one device are serialized; a running snapshot holds the device's write path.
2 changes: 1 addition & 1 deletion docs/live-snapshot_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,5 @@ seal 失败处理:seal 只追加写,data 尾部仅留下不可达的 index
## 限制

- upper 为 warpfile(`upper.target`)时,不支持快照。
- upper 为 hybrid 或 sparse 时,写路径不持快照使用的写锁,快照期间需调用方暂停写入。
- 写路径和快照通过读写锁互斥,快照期间写请求会阻塞等待快照完成,调用方无需暂停写入。
- 同一设备的快照串行执行;快照期间设备的写路径被占用。
12 changes: 0 additions & 12 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,6 @@ target_link_libraries(overlaybd_image_lib
${AIO_LIBRARIES}
)

# Propagate resize .o files to all consumers of overlaybd_image_lib.
# These provide the resize_fs() symbol needed by photon's resize_extfs().
if (NOT ORIGIN_EXT2FS)
target_link_libraries(overlaybd_image_lib
${E2FS_RESIZE_DIR}/resize2fs.o
${E2FS_RESIZE_DIR}/extent.o
${E2FS_RESIZE_DIR}/resource_track.o
${E2FS_LIBRARIES}
)
add_dependencies(overlaybd_image_lib libext2fs_build)
endif()

add_executable(overlaybd-tcmu
main.cpp
)
Expand Down
64 changes: 1 addition & 63 deletions src/image_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@
#include "overlaybd/gzip/gz.h"
#include "overlaybd/gzindex/gzfile.h"
#include "overlaybd/tar/tar_file.h"
#ifdef PHOTON_ENABLE_RESIZE
#include <photon/fs/extfs/extfs.h>
#endif

#define PARALLEL_LOAD_INDEX 32
using namespace photon::fs;
Expand Down Expand Up @@ -1051,65 +1048,6 @@ int ImageFile::resize(uint64_t target_size, bool resize_fs) {
if (read_only) {
LOG_ERROR_RETURN(EROFS, -1, "cannot resize a read-only image (no upper layer)");
}
// a size that is not a multiple of the device block would leave a
// truncated tail block
uint32_t align = LSMT::ALIGNMENT4K;
if (target_size % align != 0) {
LOG_ERROR_RETURN(EINVAL, -1, "target size must be ` aligned, got `", align, target_size);
}

auto rw = (LSMT::IFileRW *)m_file;
struct stat st;
if (m_file->fstat(&st) != 0) {
LOG_ERRNO_RETURN(0, -1, "fstat failed");
}
uint64_t current = (uint64_t)st.st_size;

if (target_size == current && !resize_fs) {
LOG_INFO("vsize already equals target (` bytes), nothing to do", target_size);
return 0;
}

if (target_size > current) {
// Expand: grow block device first, then filesystem
if (rw->update_vsize(target_size) != 0) {
LOG_ERROR_RETURN(0, -1, "failed to update vsize for expand");
}
}

if (resize_fs) {
#ifdef PHOTON_ENABLE_RESIZE
auto aligned = new_aligned_file_adaptor(m_file, LSMT::ALIGNMENT4K, true, false);
if (aligned == nullptr) {
LOG_ERROR_RETURN(0, -1, "failed to create 4K aligned adaptor for resize");
}
DEFER(delete aligned);
if (photon::fs::resize_extfs(aligned, target_size, 0) != 0) {
if (target_size >= current) {
LOG_ERROR("resize_extfs failed. "
"Re-run to retry or use e2fsck to recover.");
} else {
LOG_ERROR("resize_extfs failed during shrink.");
}
return -1;
}
#else
LOG_ERROR_RETURN(ENOSYS, -1, "resize_fs not supported (built without PHOTON_ENABLE_RESIZE)");
#endif
}

if (target_size < current) {
// Shrink: shrinking without resizing the filesystem is unsafe.
if (!resize_fs) {
LOG_ERROR_RETURN(EINVAL, -1, "cannot shrink without resizing filesystem");
}
// Shrink: update vsize after filesystem is shrunk
if (rw->update_vsize(target_size) != 0) {
LOG_ERROR("filesystem resized but failed to update vsize. Re-run to retry.");
return -1;
}
}

LOG_INFO("resize done: ` -> ` bytes", current, target_size);
return 0;
return rw->resize(target_size, resize_fs);
}
13 changes: 13 additions & 0 deletions src/overlaybd/lsmt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,19 @@ target_include_directories(lsmt_lib PUBLIC
${PHOTON_INCLUDE_DIR}
)

# file.cpp calls photon::fs::resize_extfs(), which needs resize_fs() from the
# e2fsprogs resize objects. Pass them as link items to every lsmt_lib consumer:
# a link item is always included, while a member of this static library would
# only be pulled in when already referenced.
if (NOT ORIGIN_EXT2FS)
target_link_libraries(lsmt_lib INTERFACE
${E2FS_RESIZE_DIR}/resize2fs.o
${E2FS_RESIZE_DIR}/extent.o
${E2FS_RESIZE_DIR}/resource_track.o
${E2FS_LIBRARIES})
add_dependencies(lsmt_lib libext2fs_build)
endif()

if(CMAKE_SYSTEM_PROCESSOR MATCHES "^(aarch64|arm64)$")
option(OVERLAYBD_DISABLE_SVE "Force-disable LSMT SVE acceleration" OFF)
include(CheckCXXSourceCompiles)
Expand Down
Loading
Loading