kernel: implement vectored writes for profile index saves

This commit is contained in:
Hector Mödinger S.
2026-10-16 01:27:57 +02:00
committed by nmzik
parent 56d3ce98f0
commit 54abbf48f2
4 changed files with 102 additions and 9 deletions
+23 -9
View File
@@ -21,6 +21,7 @@
#include <cstdio>
#include <cstring>
#include <filesystem>
#include <optional>
#include <random>
#include <system_error>
#include <vector>
@@ -956,12 +957,10 @@ int64_t KYTY_SYSV_ABI KernelPwrite(int d, const void* buf, size_t nbytes, int64_
return bytes_written;
}
int64_t KYTY_SYSV_ABI KernelPwritev(int d, const KernelIovec* iov, int iovcnt, int64_t offset) {
PRINT_NAME();
static int64_t Writev(int d, const KernelIovec* iov, int iovcnt, std::optional<int64_t> offset) {
std::vector<KernelIovec> buffers;
size_t total = 0;
const int error = ValidateIovecs(iov, iovcnt, offset, &buffers, &total);
const int error = ValidateIovecs(iov, iovcnt, offset.value_or(0), &buffers, &total);
if (error != OK) {
return error;
}
@@ -991,11 +990,16 @@ int64_t KYTY_SYSV_ABI KernelPwritev(int d, const KernelIovec* iov, int iovcnt, i
}
const auto position = file->f.Tell();
const auto target = (file->append ? file->f.Size() : static_cast<uint64_t>(offset));
auto target = position;
if (file->append) {
target = file->f.Size();
} else if (offset) {
target = static_cast<uint64_t>(*offset);
}
if (target > static_cast<uint64_t>(INT64_MAX) - total) {
return KERNEL_ERROR_EFBIG;
}
if (!file->f.Seek(target)) {
if ((offset || file->append) && !file->f.Seek(target)) {
return KERNEL_ERROR_EIO;
}
@@ -1012,16 +1016,26 @@ int64_t KYTY_SYSV_ABI KernelPwritev(int d, const KernelIovec* iov, int iovcnt, i
}
}
const bool flushed = !file->sync_writes || file->f.Flush();
const bool restored = file->f.Seek(position);
const bool restored = !offset || file->f.Seek(position);
if (!flushed || !restored) {
return KERNEL_ERROR_EIO;
}
LOGF("\tWritev %" PRId64 " bytes (pos = %" PRId64 ", iovcnt = %d) to: %s\n", bytes_written,
offset, iovcnt, Common::PathToString(file->real_name).c_str());
LOGF("\tWritev %" PRId64 " bytes (pos = %" PRIu64 ", iovcnt = %d) to: %s\n", bytes_written,
target, iovcnt, Common::PathToString(file->real_name).c_str());
return bytes_written;
}
int64_t KYTY_SYSV_ABI KernelWritev(int d, const KernelIovec* iov, int iovcnt) {
PRINT_NAME();
return Writev(d, iov, iovcnt, std::nullopt);
}
int64_t KYTY_SYSV_ABI KernelPwritev(int d, const KernelIovec* iov, int iovcnt, int64_t offset) {
PRINT_NAME();
return Writev(d, iov, iovcnt, offset);
}
int64_t KYTY_SYSV_ABI KernelLseek(int d, int64_t offset, int whence) {
PRINT_NAME();
+1
View File
@@ -64,6 +64,7 @@ int64_t KYTY_SYSV_ABI KernelRead(int d, void* buf, size_t nbytes);
int64_t KYTY_SYSV_ABI KernelPread(int d, void* buf, size_t nbytes, int64_t offset);
int64_t KYTY_SYSV_ABI KernelPreadv(int d, const KernelIovec* iov, int iovcnt, int64_t offset);
int64_t KYTY_SYSV_ABI KernelWrite(int d, const void* buf, size_t nbytes);
int64_t KYTY_SYSV_ABI KernelWritev(int d, const KernelIovec* iov, int iovcnt);
int64_t KYTY_SYSV_ABI KernelPwrite(int d, const void* buf, size_t nbytes, int64_t offset);
int64_t KYTY_SYSV_ABI KernelPwritev(int d, const KernelIovec* iov, int iovcnt, int64_t offset);
int64_t KYTY_SYSV_ABI KernelLseek(int d, int64_t offset, int whence);