Compare commits

..

1 Commits

Author SHA1 Message Date
df593badb5 Release 3.2.2
- New store (thanks Changwei Ye)
  - Fix rejected compaction when an object is already overwritten again
  - Reduce superblock I/O amplification introduced after previous correctness fixes
- Fix possible `vitastor-cli rm` crash with `assert(rwo->todo == 1)` introduced in 3.2.1
- Fix replicated objects possibly incorrectly transitioning to the INCOMPLETE state
  after multiple failed partial writes
- Fix possible "operation sequencing broken ... expected num 2, got 3, stopping client"
  possible when a cluster is overloaded by peering/OSD flaps
2026-09-27 14:29:43 +03:00
52 changed files with 638 additions and 2327 deletions

View File

@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 2.8...3.30)
project(vitastor)
set(VITASTOR_VERSION "3.2.1")
set(VITASTOR_VERSION "3.2.2")
include(CTest)

View File

@@ -1,4 +1,4 @@
VITASTOR_VERSION ?= v3.2.1
VITASTOR_VERSION ?= v3.2.2
all: build push

View File

@@ -49,7 +49,7 @@ spec:
capabilities:
add: ["SYS_ADMIN"]
allowPrivilegeEscalation: true
image: vitalif/vitastor-csi:v3.2.1
image: vitalif/vitastor-csi:v3.2.2
args:
- "--node=$(NODE_ID)"
- "--endpoint=$(CSI_ENDPOINT)"

View File

@@ -87,7 +87,7 @@ spec:
- name: socket-dir
mountPath: /csi
- name: csi-attacher
image: k8s.gcr.io/sig-storage/csi-attacher:v3.2.1
image: k8s.gcr.io/sig-storage/csi-attacher:v3.2.2
args:
- "--v=5"
- "--csi-address=$(ADDRESS)"
@@ -121,7 +121,7 @@ spec:
privileged: true
capabilities:
add: ["SYS_ADMIN"]
image: vitalif/vitastor-csi:v3.2.1
image: vitalif/vitastor-csi:v3.2.2
args:
- "--node=$(NODE_ID)"
- "--endpoint=$(CSI_ENDPOINT)"

View File

@@ -5,7 +5,7 @@ package vitastor
const (
vitastorCSIDriverName = "csi.vitastor.io"
vitastorCSIDriverVersion = "3.2.1"
vitastorCSIDriverVersion = "3.2.2"
)
// Config struct fills the parameters of request or user input

2
debian/changelog vendored
View File

@@ -1,4 +1,4 @@
vitastor (3.2.1-1) unstable; urgency=medium
vitastor (3.2.2-1) unstable; urgency=medium
* Bugfixes

View File

@@ -1,4 +1,4 @@
VITASTOR_VERSION ?= v3.2.1
VITASTOR_VERSION ?= v3.2.2
all: build push

View File

@@ -4,7 +4,7 @@
#
# Desired Vitastor version
VITASTOR_VERSION=v3.2.1
VITASTOR_VERSION=v3.2.2
# Additional arguments for all containers
# For example, you may want to specify a custom logging driver here

View File

@@ -26,9 +26,9 @@ at Vitastor Kubernetes operator: https://github.com/Antilles7227/vitastor-operat
The instruction is very simple.
1. Download a Docker image of the desired version: \
`docker pull vitalif/vitastor:v3.2.1`
`docker pull vitalif/vitastor:v3.2.2`
2. Install scripts to the host system: \
`docker run --rm -it -v /etc:/host-etc -v /usr/bin:/host-bin vitalif/vitastor:v3.2.1 install.sh`
`docker run --rm -it -v /etc:/host-etc -v /usr/bin:/host-bin vitalif/vitastor:v3.2.2 install.sh`
3. Reload udev rules: \
`udevadm control --reload-rules`
4. Enable the vitastor-host service: \

View File

@@ -25,9 +25,9 @@ Vitastor можно установить в Docker/Podman. При этом etcd,
Инструкция по установке максимально простая.
1. Скачайте Docker-образ желаемой версии: \
`docker pull vitalif/vitastor:v3.2.1`
`docker pull vitalif/vitastor:v3.2.2`
2. Установите скрипты в хост-систему командой: \
`docker run --rm -it -v /etc:/host-etc -v /usr/bin:/host-bin vitalif/vitastor:v3.2.1 install.sh`
`docker run --rm -it -v /etc:/host-etc -v /usr/bin:/host-bin vitalif/vitastor:v3.2.2 install.sh`
3. Перезагрузите правила udev: \
`udevadm control --reload-rules`
4. Включите сервис vitastor-host: \

View File

@@ -1,6 +1,6 @@
{
"name": "vitastor-mon",
"version": "3.2.1",
"version": "3.2.2",
"description": "Vitastor SDS monitor service",
"main": "mon-main.js",
"scripts": {

View File

@@ -1,6 +1,6 @@
{
"name": "vitastor",
"version": "3.2.1",
"version": "3.2.2",
"description": "Low-level native bindings to Vitastor client library",
"main": "index.js",
"keywords": [

View File

@@ -50,7 +50,7 @@ from cinder.volume import configuration
from cinder.volume import driver
from cinder.volume import volume_utils
VITASTOR_VERSION = '3.2.1'
VITASTOR_VERSION = '3.2.2'
LOG = logging.getLogger(__name__)

View File

@@ -1,11 +1,11 @@
Name: vitastor
Version: 3.2.1
Version: 3.2.2
Release: 1%{?dist}
Summary: Vitastor, a fast software-defined clustered block storage
License: Vitastor Network Public License 1.1
URL: https://vitastor.io/
Source0: vitastor-3.2.1.el10.tar.gz
Source0: vitastor-3.2.2.el10.tar.gz
BuildRequires: gperftools-devel
BuildRequires: gcc-c++

View File

@@ -1,11 +1,11 @@
Name: vitastor
Version: 3.2.1
Version: 3.2.2
Release: 1%{?dist}
Summary: Vitastor, a fast software-defined clustered block storage
License: Vitastor Network Public License 1.1
URL: https://vitastor.io/
Source0: vitastor-3.2.1.el7.tar.gz
Source0: vitastor-3.2.2.el7.tar.gz
BuildRequires: gperftools-devel
BuildRequires: devtoolset-9-gcc-c++

View File

@@ -1,11 +1,11 @@
Name: vitastor
Version: 3.2.1
Version: 3.2.2
Release: 1%{?dist}
Summary: Vitastor, a fast software-defined clustered block storage
License: Vitastor Network Public License 1.1
URL: https://vitastor.io/
Source0: vitastor-3.2.1.el8.tar.gz
Source0: vitastor-3.2.2.el8.tar.gz
BuildRequires: gperftools-devel
BuildRequires: gcc-toolset-9-gcc-c++

View File

@@ -1,11 +1,11 @@
Name: vitastor
Version: 3.2.1
Version: 3.2.2
Release: 1%{?dist}
Summary: Vitastor, a fast software-defined clustered block storage
License: Vitastor Network Public License 1.1
URL: https://vitastor.io/
Source0: vitastor-3.2.1.el9.tar.gz
Source0: vitastor-3.2.2.el9.tar.gz
BuildRequires: gperftools-devel
BuildRequires: gcc-c++

View File

@@ -21,7 +21,7 @@ if("${CMAKE_INSTALL_PREFIX}" MATCHES "^/usr/local/?$")
endif()
set(ENABLE_COVERAGE false CACHE BOOL "Enable code coverage")
add_definitions(-DVITASTOR_VERSION="3.2.1")
add_definitions(-DVITASTOR_VERSION="3.2.2")
add_definitions(-D_GNU_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -Wall -Wno-sign-compare -Wno-comment -Wno-parentheses -Wno-pointer-arith -fdiagnostics-color=always -fno-omit-frame-pointer -fvisibility=hidden -I ${CMAKE_SOURCE_DIR}/src)
add_link_options(-fno-omit-frame-pointer)
if (${WITH_ASAN})
@@ -86,11 +86,6 @@ pkg_check_modules(RDMACM librdmacm)
if (RDMACM_LIBRARIES)
add_definitions(-DWITH_RDMACM)
endif (RDMACM_LIBRARIES)
pkg_check_modules(VFN libvfn)
pkg_check_modules(NVME libnvme)
if (VFN_LIBRARIES AND NVME_LIBRARIES)
add_definitions(-DWITH_VFN)
endif (VFN_LIBRARIES AND NVME_LIBRARIES)
find_package(OpenSSL 3.0 REQUIRED)
add_definitions(-DWITH_OPENSSL)

View File

@@ -1,6 +1,10 @@
// Copyright (c) Vitaliy Filippov, 2019+
// License: VNPL-1.1 (see README.md for details)
#include <sys/file.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <stdexcept>
#include "blockstore.h"
@@ -351,22 +355,31 @@ void blockstore_disk_t::check_lengths()
}
}
static int bs_openmode(const std::string & mode)
{
if (mode == "directsync")
return O_DIRECT|O_SYNC;
else if (mode == "cached")
return O_SYNC;
else
return O_DIRECT;
}
void blockstore_disk_t::open_data()
{
if (data_disk)
if (data_fd >= 0)
{
throw std::runtime_error("data device is already opened");
}
data_disk = mock_mode
? disk_i::create_mock(MOCK_DATA_FD, data_device_size, data_device_sect)
: disk_i::create_and_open(data_device, data_io, disable_flock);
if (!data_disk)
data_fd = mock_mode ? MOCK_DATA_FD : open(data_device.c_str(), bs_openmode(data_io) | O_RDWR);
if (data_fd == -1)
{
throw std::runtime_error("Failed to open data device "+data_device);
throw std::runtime_error("Failed to open data device "+data_device+": "+std::string(strerror(errno)));
}
if (!mock_mode)
{
check_size(data_fd, &data_device_size, &data_device_sect, "data device");
}
data_off_ring = data_disk->is_off_ring();
data_device_size = data_disk->get_size();
data_device_sect = data_disk->get_block_size();
if (disk_alignment % data_device_sect)
{
throw std::runtime_error(
@@ -378,33 +391,41 @@ void blockstore_disk_t::open_data()
{
throw std::runtime_error("data_offset exceeds device size = "+std::to_string(data_device_size));
}
if (!mock_mode && !disable_flock && flock(data_fd, LOCK_EX|LOCK_NB) != 0)
{
throw std::runtime_error(std::string("Failed to lock data device: ") + strerror(errno));
}
}
void blockstore_disk_t::open_meta()
{
if (meta_disk)
if (meta_fd >= 0)
{
throw std::runtime_error("metadata device is already opened");
}
if (meta_device != data_device || meta_io != data_io)
{
meta_disk = mock_mode
? disk_i::create_mock(MOCK_META_FD, meta_device_size, meta_device_sect)
: disk_i::create_and_open(meta_device, meta_io, meta_device == data_device || disable_flock);
if (!meta_disk)
meta_fd = mock_mode ? MOCK_META_FD : open(meta_device.c_str(), bs_openmode(meta_io) | O_RDWR);
if (meta_fd == -1)
{
throw std::runtime_error("Failed to open metadata device "+meta_device);
throw std::runtime_error("Failed to open metadata device "+meta_device+": "+std::string(strerror(errno)));
}
if (!mock_mode)
{
check_size(meta_fd, &meta_device_size, &meta_device_sect, "metadata device");
}
meta_device_size = meta_disk->get_size();
meta_device_sect = meta_disk->get_block_size();
if (meta_offset >= meta_device_size)
{
throw std::runtime_error("meta_offset exceeds device size = "+std::to_string(meta_device_size));
}
if (!mock_mode && !disable_flock && meta_device != data_device && flock(meta_fd, LOCK_EX|LOCK_NB) != 0)
{
throw std::runtime_error(std::string("Failed to lock metadata device: ") + strerror(errno));
}
}
else
{
meta_disk = data_disk;
meta_fd = data_fd;
meta_device_sect = data_device_sect;
meta_device_size = 0;
if (meta_offset >= data_device_size)
@@ -412,7 +433,6 @@ void blockstore_disk_t::open_meta()
throw std::runtime_error("meta_offset exceeds device size = "+std::to_string(data_device_size));
}
}
meta_off_ring = meta_disk->is_off_ring();
if (meta_block_size % meta_device_sect)
{
throw std::runtime_error(
@@ -424,29 +444,33 @@ void blockstore_disk_t::open_meta()
void blockstore_disk_t::open_journal()
{
if (journal_disk)
if (journal_fd >= 0)
{
throw std::runtime_error("journal device is already opened");
}
if (journal_device != meta_device || journal_io != meta_io)
{
journal_disk = mock_mode
? disk_i::create_mock(MOCK_JOURNAL_FD, journal_device_size, journal_device_sect)
: disk_i::create_and_open(journal_device, journal_io, journal_device == meta_device || disable_flock);
if (!journal_disk)
journal_fd = mock_mode ? MOCK_JOURNAL_FD : open(journal_device.c_str(), bs_openmode(journal_io) | O_RDWR);
if (journal_fd == -1)
{
throw std::runtime_error("Failed to open journal device "+journal_device);
throw std::runtime_error("Failed to open journal device "+journal_device+": "+std::string(strerror(errno)));
}
if (!mock_mode)
{
check_size(journal_fd, &journal_device_size, &journal_device_sect, "journal device");
}
journal_device_size = journal_disk->get_size();
journal_device_sect = journal_disk->get_block_size();
if (journal_offset >= journal_device_size)
{
throw std::runtime_error("journal_offset exceeds device size = "+std::to_string(journal_device_size));
}
if (!mock_mode && !disable_flock && journal_device != meta_device && flock(journal_fd, LOCK_EX|LOCK_NB) != 0)
{
throw std::runtime_error(std::string("Failed to lock journal device: ") + strerror(errno));
}
}
else
{
journal_disk = meta_disk;
journal_fd = meta_fd;
journal_device_sect = meta_device_sect;
journal_device_size = 0;
if (journal_offset >= (meta_device_size > 0 ? meta_device_size : data_device_size))
@@ -454,7 +478,6 @@ void blockstore_disk_t::open_journal()
throw std::runtime_error("journal_offset exceeds device size");
}
}
journal_off_ring = journal_disk->is_off_ring();
if (journal_block_size % journal_device_sect)
{
throw std::runtime_error(
@@ -466,19 +489,26 @@ void blockstore_disk_t::open_journal()
void blockstore_disk_t::close_all()
{
if (journal_disk && journal_disk != meta_disk && journal_disk != data_disk)
delete journal_disk;
if (meta_disk && meta_disk != data_disk)
delete meta_disk;
if (data_disk)
delete data_disk;
data_disk = meta_disk = journal_disk = NULL;
if (!mock_mode)
{
if (data_fd >= 0)
close(data_fd);
if (meta_fd >= 0 && meta_fd != data_fd)
close(meta_fd);
if (journal_fd >= 0 && journal_fd != meta_fd)
close(journal_fd);
}
data_fd = meta_fd = journal_fd = -1;
}
// Sadly DISCARD only works through ioctl(), but it seems to always block the device queue,
// so it's not a big deal that we can only run it synchronously.
int blockstore_disk_t::trim_data(std::function<bool(uint64_t)> is_used)
{
if (mock_mode)
{
return -EINVAL;
}
int r = 0;
uint64_t j = 0, i = 0;
uint64_t discarded = 0;
@@ -503,12 +533,12 @@ int blockstore_disk_t::trim_data(std::function<bool(uint64_t)> is_used)
}
if (range[1] > 0)
{
r = data_disk->discard_sync(range[0], range[1]);
r = ioctl(data_fd, BLKDISCARD, &range);
if (r != 0)
{
fprintf(stderr, "Failed to discard %ju+%ju bytes on %s: %s (code %d)\n",
fprintf(stderr, "Failed to execute BLKDISCARD %ju+%ju on %s: %s (code %d)\n",
range[0], range[1], data_device.c_str(), strerror(-r), r);
return r;
return -errno;
}
discarded += range[1];
}

View File

@@ -24,8 +24,6 @@
class allocator_t;
class disk_i;
struct blockstore_disk_t
{
std::string data_device, meta_device, journal_device;
@@ -68,8 +66,6 @@ struct blockstore_disk_t
uint64_t discard_granularity = 0;
int meta_fd = -1, data_fd = -1, journal_fd = -1;
disk_i *meta_disk = NULL, *data_disk = NULL, *journal_disk = NULL;
bool meta_off_ring = false, data_off_ring = false, journal_off_ring = false;
uint64_t meta_offset = 0, meta_device_sect = 0, meta_device_size = 0, meta_area_size = 0, min_meta_len = 0;
uint64_t data_offset = 0, data_device_sect = 0, data_device_size = 0, data_len = 0;
uint64_t journal_offset = 0, journal_device_sect = 0, journal_device_size = 0, journal_len = 0;

View File

@@ -37,18 +37,18 @@ journal_flusher_t::journal_flusher_t(blockstore_impl_t *bs)
journal_flusher_co::journal_flusher_co()
{
wait_state = 0;
simple_callback_r = [this](int res)
simple_callback_r = [this](ring_data_t* data)
{
bs->live = true;
if (res < 0)
bs->disk_error_abort("read operation during flush", res);
if (data->res != data->iov.iov_len)
bs->disk_error_abort("read operation during flush", data->res, data->iov.iov_len);
wait_count--;
};
simple_callback_w = [this](int res)
simple_callback_w = [this](ring_data_t* data)
{
bs->live = true;
if (res < 0)
bs->disk_error_abort("write operation during flush", res);
if (data->res != data->iov.iov_len)
bs->disk_error_abort("write operation during flush", data->res, data->iov.iov_len);
wait_count--;
};
}
@@ -161,8 +161,19 @@ void journal_flusher_t::loop()
bs->ringloop->wakeup();
}
#define await_sqe(label) \
resume_##label:\
sqe = bs->get_sqe();\
if (!sqe)\
{\
wait_state = wait_base+label;\
return false;\
}\
data = ((ring_data_t*)sqe->user_data);
bool journal_flusher_co::loop()
{
int wait_base = 0;
// This is much better than implementing the whole function as an FSM
// Maybe I should consider a coroutine library like https://github.com/hnes/libaco ...
// Or just C++ coroutines, but they require some wrappers
@@ -454,22 +465,13 @@ resume_9:
if ((read_vec[i].copy_flags & COPY_BUF_JOURNAL) &&
!(read_vec[i].copy_flags & COPY_BUF_COALESCED))
{
resume_10:
assert(read_vec[i].buf);
assert(clean_loc + read_vec[i].offset + read_vec[i].len <= bs->dsk.block_count*bs->dsk.data_block_size);
res = bs->dsk.data_disk->write_async(
bs->dsk.data_offset + clean_loc + read_vec[i].offset,
(size_t)read_vec[i].len,
read_vec[i].buf + (read_vec[i].copy_flags & COPY_BUF_PADDED
? read_vec[i].offset - read_vec[i].disk_offset : 0),
simple_callback_w
);
if (res == -EAGAIN)
{
wait_state = 10;
return false;
}
assert(res == 0);
await_sqe(10);
data->iov = (struct iovec){ read_vec[i].buf + (read_vec[i].copy_flags & COPY_BUF_PADDED
? read_vec[i].offset - read_vec[i].disk_offset : 0), (size_t)read_vec[i].len };
data->callback = simple_callback_w;
assert(clean_loc + read_vec[i].offset + data->iov.iov_len <= bs->dsk.block_count*bs->dsk.data_block_size);
io_uring_prep_writev(sqe, bs->dsk.data_fd, &data->iov, 1, bs->dsk.data_offset + clean_loc + read_vec[i].offset);
wait_count++;
}
}
@@ -577,7 +579,7 @@ void journal_flusher_co::fill_partial_checksum_blocks()
.disk_loc = clean_loc,
.disk_offset = blk_begin,
.disk_len = blk_end - blk_begin,
.buf = (uint8_t*)bs->dsk.data_disk->alloc_iomem(blk_end - blk_begin),
.buf = (uint8_t*)memalign_or_die(MEM_ALIGNMENT, blk_end - blk_begin),
.wr = compact_info.clean_wr,
});
}
@@ -602,8 +604,7 @@ void journal_flusher_co::free_buffers()
if (it->buf && !(it->copy_flags & COPY_BUF_COALESCED) &&
(!bs->dsk.inmemory_journal || it->buf < bs->buffer_area || it->buf >= (uint8_t*)bs->buffer_area + bs->dsk.journal_len))
{
disk_i *di = ((it->copy_flags & COPY_BUF_JOURNAL) ? bs->dsk.journal_disk : bs->dsk.data_disk);
di->free_iomem(it->buf);
free(it->buf);
}
}
read_vec.clear();
@@ -754,8 +755,6 @@ resume_1:
bool journal_flusher_co::read_buffered(int wait_base)
{
disk_i *di = NULL;
copy_buffer_t *vec = NULL;
if (wait_state == wait_base)
goto resume_0;
else if (wait_state == wait_base+1)
@@ -773,24 +772,19 @@ bool journal_flusher_co::read_buffered(int wait_base)
if (!(read_vec[i].copy_flags & COPY_BUF_COALESCED) &&
((read_vec[i].copy_flags & COPY_BUF_JOURNAL) && !bs->dsk.inmemory_journal || (read_vec[i].copy_flags & COPY_BUF_DATA)))
{
resume_0:
vec = &read_vec[i];
di = ((vec->copy_flags & COPY_BUF_JOURNAL) ? bs->dsk.journal_disk : bs->dsk.data_disk);
if (!vec->buf)
vec->buf = (uint8_t*)di->alloc_iomem(vec->disk_len);
res = di->read_async(
((vec->copy_flags & COPY_BUF_JOURNAL) ? bs->dsk.journal_offset : bs->dsk.data_offset) + vec->disk_loc + vec->disk_offset,
(size_t)vec->disk_len,
vec->buf,
simple_callback_r
);
if (res == -EAGAIN)
{
wait_state = wait_base+0;
return false;
}
assert(!res);
await_sqe(0);
auto & vec = read_vec[i];
if (!vec.buf)
vec.buf = (uint8_t*)memalign_or_die(MEM_ALIGNMENT, vec.disk_len);
data->iov = (struct iovec){ vec.buf, (size_t)vec.disk_len };
wait_count++;
io_uring_prep_readv(
sqe,
(vec.copy_flags & COPY_BUF_JOURNAL) ? bs->dsk.journal_fd : bs->dsk.data_fd,
&data->iov, 1,
((vec.copy_flags & COPY_BUF_JOURNAL) ? bs->dsk.journal_offset : bs->dsk.data_offset) + vec.disk_loc + vec.disk_offset
);
data->callback = simple_callback_r;
}
}
// Wait for reads/writes if the journal is not inmemory
@@ -833,28 +827,17 @@ resume_0:
if (!cur_sync->sent)
{
// Sync batch is ready. Do it.
resume_1:
res = bs->dsk.data_disk->flush_async(simple_callback_w);
if (res == -EAGAIN)
{
wait_state = wait_base+1;
return false;
}
else if (res == -EALREADY)
{
cur_sync->sent = true;
}
else
{
assert(res == 0);
cur_sync->sent = true;
wait_count++;
await_sqe(1);
data->iov = { 0 };
data->callback = simple_callback_w;
io_uring_prep_fsync(sqe, bs->dsk.data_fd, IORING_FSYNC_DATASYNC);
cur_sync->sent = true;
wait_count++;
resume_2:
if (wait_count > 0)
{
wait_state = wait_base+2;
return false;
}
if (wait_count > 0)
{
wait_state = wait_base+2;
return false;
}
cur_sync->done = true;
// Wake up other flushers
@@ -892,26 +875,16 @@ resume_0:
}
flusher->fsyncing_meta = true;
// Sync batch is ready. Do it.
resume_1:
res = bs->dsk.meta_disk->flush_async(simple_callback_w);
if (res == -EAGAIN)
{
wait_state = wait_base+1;
return false;
}
else if (res == -EALREADY)
{
}
else
{
assert(res == 0);
wait_count++;
await_sqe(1);
data->iov = { 0 };
data->callback = simple_callback_w;
io_uring_prep_fsync(sqe, bs->dsk.meta_fd, IORING_FSYNC_DATASYNC);
wait_count++;
resume_2:
if (wait_count > 0)
{
wait_state = wait_base+2;
return false;
}
if (wait_count > 0)
{
wait_state = wait_base+2;
return false;
}
// Sync completed. All previous coroutines waiting for it must be resumed
flusher->fsyncing_meta = false;
@@ -939,7 +912,7 @@ resume_0:
resume_1:
assert(!wait_count);
fsynced_lsn = bs->heap->get_completed_lsn();
if (bs->submit_fsyncs(wait_count) != 0)
if (!bs->submit_fsyncs(wait_count))
{
wait_state = wait_base+1;
return false;
@@ -978,16 +951,12 @@ resume_0:
flusher->active_flushers++;
((blockstore_meta_header_v3_t*)bs->meta_superblock)->completed_lsn = fsynced_lsn;
((blockstore_meta_header_v3_t*)bs->meta_superblock)->set_crc32c();
// Update superblock with FUA (datasync)
resume_1:
res = bs->dsk.meta_disk->write_async(bs->dsk.meta_offset, bs->dsk.meta_block_size,
bs->meta_superblock, simple_callback_w, true);
if (res == -EAGAIN)
{
wait_state = wait_base+1;
return false;
}
assert(res == 0);
await_sqe(1);
data->iov = (struct iovec){ bs->meta_superblock, (size_t)bs->dsk.meta_block_size };
data->callback = simple_callback_w;
io_uring_prep_writev(sqe, bs->dsk.meta_fd, &data->iov, 1, bs->dsk.meta_offset);
// Update superblock with datasync
sqe->rw_flags = RWF_DSYNC;
wait_count++;
resume_2:
if (wait_count > 0)

View File

@@ -43,12 +43,14 @@ class journal_flusher_co
journal_flusher_t *flusher;
int co_id;
int wait_state, wait_count;
struct io_uring_sqe *sqe;
struct ring_data_t *data;
uint8_t *new_csums = NULL;
uint8_t *new_bmp = NULL;
uint8_t *punch_bmp = NULL;
uint8_t *new_ext_bmp = NULL;
std::function<void(int)> simple_callback_r, simple_callback_w;
std::function<void(ring_data_t*)> simple_callback_r, simple_callback_w;
object_id cur_oid;
heap_entry_t *cur_obj;

View File

@@ -30,15 +30,12 @@ blockstore_impl_t::blockstore_impl_t(blockstore_config_t & config, ring_loop_i *
dsk.close_all();
throw;
}
dsk.data_disk->set_ringloop(ringloop);
dsk.meta_disk->set_ringloop(ringloop);
dsk.journal_disk->set_ringloop(ringloop);
meta_superblock = (uint8_t*)dsk.meta_disk->alloc_iomem(dsk.meta_block_size);
meta_superblock = (uint8_t*)memalign_or_die(MEM_ALIGNMENT, dsk.meta_block_size);
memset(meta_superblock, 0, dsk.meta_block_size);
flusher = new journal_flusher_t(this);
if (dsk.inmemory_journal)
{
buffer_area = (uint8_t*)dsk.journal_disk->alloc_iomem(dsk.journal_len);
buffer_area = (uint8_t*)memalign_or_die(MEM_ALIGNMENT, dsk.journal_len);
}
heap = new blockstore_heap_t(&dsk, buffer_area, log_level);
ringloop->wakeup();
@@ -69,9 +66,9 @@ blockstore_impl_t::~blockstore_impl_t()
if (heap)
delete heap;
if (buffer_area)
dsk.journal_disk->free_iomem(buffer_area);
free(buffer_area);
if (meta_superblock)
dsk.meta_disk->free_iomem(meta_superblock);
free(meta_superblock);
ringloop->unregister_consumer(&ring_consumer);
dsk.close_all();
}
@@ -130,9 +127,9 @@ void blockstore_impl_t::loop()
if (PRIV(op)->wait_for)
{
check_wait(op);
if (PRIV(op)->wait_for != WAIT_COMPACTION)
if (PRIV(op)->wait_for == WAIT_SQE)
{
// disk queue(s) are full, stop submission
// ring is full, stop submission
break;
}
else if (PRIV(op)->wait_for)
@@ -143,6 +140,7 @@ void blockstore_impl_t::loop()
continue;
}
}
unsigned prev_sqe_pos = ringloop->save();
// 0 = can't submit
// 1 = in progress
// 2 = can be removed from queue
@@ -191,7 +189,8 @@ void blockstore_impl_t::loop()
if (wr_st == 0)
{
PRIV(op)->pending_ops = 0;
if (PRIV(op)->wait_for != WAIT_COMPACTION)
ringloop->restore(prev_sqe_pos);
if (PRIV(op)->wait_for == WAIT_SQE)
{
// ring is full, stop submission
break;
@@ -262,34 +261,13 @@ bool blockstore_impl_t::is_safe_to_stop()
void blockstore_impl_t::check_wait(blockstore_op_t *op)
{
if (PRIV(op)->wait_for == WAIT_DATA_QUEUE)
if (PRIV(op)->wait_for == WAIT_SQE)
{
if (dsk.data_disk->get_queue_space() < PRIV(op)->wait_detail)
if (ringloop->space_left() < PRIV(op)->wait_detail)
{
// stop submission if there's still no free space
#ifdef BLOCKSTORE_DEBUG
printf("Still waiting for %ju free data disk queue slots\n", PRIV(op)->wait_detail);
#endif
return;
}
PRIV(op)->wait_for = 0;
}
else if (PRIV(op)->wait_for == WAIT_META_QUEUE)
{
if (dsk.meta_disk->get_queue_space() < PRIV(op)->wait_detail)
{
#ifdef BLOCKSTORE_DEBUG
printf("Still waiting for %ju free meta disk queue slots\n", PRIV(op)->wait_detail);
#endif
return;
}
PRIV(op)->wait_for = 0;
}
else if (PRIV(op)->wait_for == WAIT_JOURNAL_QUEUE)
{
if (dsk.journal_disk->get_queue_space() < PRIV(op)->wait_detail)
{
#ifdef BLOCKSTORE_DEBUG
printf("Still waiting for %ju free journal disk queue slots\n", PRIV(op)->wait_detail);
printf("Still waiting for %ju SQE(s)\n", PRIV(op)->wait_detail);
#endif
return;
}
@@ -426,7 +404,7 @@ void blockstore_meta_header_v3_t::set_crc32c()
header_csum = calc;
}
void blockstore_impl_t::disk_error_abort(const char *op, int retval)
void blockstore_impl_t::disk_error_abort(const char *op, int retval, int expected)
{
if (retval == -EAGAIN)
{
@@ -435,7 +413,7 @@ void blockstore_impl_t::disk_error_abort(const char *op, int retval)
" Please upgrade your kernel. Aborting.\n", op);
exit(1);
}
fprintf(stderr, "Disk %s failed: %s (code %d). Can't continue, sorry :-(\n", op, strerror(-retval), retval);
fprintf(stderr, "Disk %s failed: result is %d, expected %d. Can't continue, sorry :-(\n", op, retval, expected);
exit(1);
}

View File

@@ -20,7 +20,6 @@
#include <unordered_map>
#include <unordered_set>
#include "disk_util.h"
#include "malloc_or_die.h"
class blockstore_impl_t;
@@ -133,16 +132,21 @@ public:
bool stop_sync_submitted = false;
inline struct io_uring_sqe* get_sqe()
{
return ringloop->get_sqe();
}
void open_data();
void open_meta();
void open_journal();
void disk_error_abort(const char *op, int retval);
void disk_error_abort(const char *op, int retval, int expected);
// Asynchronous init
int initialized = 0;
uint64_t metadata_buf_size = 0;
blockstore_init_meta* metadata_init_reader = NULL;
int initialized;
int metadata_buf_size;
blockstore_init_meta* metadata_init_reader;
void check_wait(blockstore_op_t *op);
void init_op(blockstore_op_t *op);
@@ -159,7 +163,7 @@ public:
void find_holes(std::vector<copy_buffer_t> & read_vec, uint32_t item_start, uint32_t item_end,
std::function<void(int&, uint32_t, uint32_t)> callback);
void free_read_buffers(std::vector<copy_buffer_t> & rv);
void handle_read_event(int res, blockstore_op_t *op);
void handle_read_event(ring_data_t *data, blockstore_op_t *op);
bool verify_read_checksums(blockstore_op_t *op);
// Write
@@ -169,11 +173,11 @@ public:
bool intent_write_allowed(blockstore_op_t *op, heap_entry_t *obj);
int dequeue_write(blockstore_op_t *op);
int continue_write(blockstore_op_t *op);
void handle_write_event(int res, blockstore_op_t *op);
void handle_write_event(ring_data_t *data, blockstore_op_t *op);
// Sync
int continue_sync(blockstore_op_t *op);
int submit_fsyncs(int & wait_count);
bool submit_fsyncs(int & wait_count);
int do_sync(blockstore_op_t *op, int base_state);
bool has_unsynced();

View File

@@ -11,6 +11,12 @@
#define INIT_META_READING 1
#define INIT_META_READ_DONE 2
#define GET_SQE() \
sqe = bs->get_sqe();\
if (!sqe)\
throw std::runtime_error("io_uring is full during initialization");\
data = ((ring_data_t*)sqe->user_data)
struct blockstore_recheck_io_t
{
bool is_data;
@@ -30,13 +36,14 @@ blockstore_init_meta::blockstore_init_meta(blockstore_impl_t *bs)
this->bs = bs;
}
void blockstore_init_meta::handle_event(int res, int buf_num, const char *op)
void blockstore_init_meta::handle_event(ring_data_t *data, int buf_num, const char *op)
{
if (res < 0)
if (data->res != data->iov.iov_len)
{
throw std::runtime_error(strprintf(
"%s failed at offset %ju: %s (code %d)",
op, (buf_num >= 0 ? bufs[buf_num].offset : last_read_offset), strerror(-res), res
"%s failed at offset %ju: got %s (code %d), but expected %zu",
op, (buf_num >= 0 ? bufs[buf_num].offset : last_read_offset), strerror(-data->res),
data->res, data->iov.iov_len
));
}
if (buf_num >= 0)
@@ -60,16 +67,16 @@ int blockstore_init_meta::loop()
else if (wait_state == 7) goto resume_7;
else if (wait_state == 8) goto resume_8;
else if (wait_state == 9) goto resume_9;
if (bs->metadata_buf_size > bs->dsk.meta_disk->get_max_io_size())
bs->metadata_buf_size = bs->dsk.meta_disk->get_max_io_size();
metadata_buffer = bs->dsk.meta_disk->alloc_iomem(2*bs->metadata_buf_size);
metadata_buffer = memalign(MEM_ALIGNMENT, 2*bs->metadata_buf_size);
if (!metadata_buffer)
throw std::runtime_error("Failed to allocate metadata read buffer");
// Read metadata superblock
GET_SQE();
last_read_offset = 0;
res = bs->dsk.meta_disk->read_async(bs->dsk.meta_offset, bs->dsk.meta_block_size, bs->meta_superblock,
[this](int res) { handle_event(res, -1, "read metadata header"); });
assert(res == 0);
data->iov = { bs->meta_superblock, (size_t)bs->dsk.meta_block_size };
data->callback = [this](ring_data_t *data) { handle_event(data, -1, "read metadata header"); };
io_uring_prep_readv(sqe, bs->dsk.meta_fd, &data->iov, 1, bs->dsk.meta_offset);
bs->ringloop->submit();
submitted++;
resume_1:
if (submitted > 0)
@@ -158,16 +165,16 @@ resume_1:
md_offset = 0;
while (md_offset < bs->dsk.journal_len)
{
submit_len = (bs->dsk.journal_len - md_offset < bs->metadata_buf_size ? bs->dsk.journal_len - md_offset : bs->metadata_buf_size);
last_read_offset = md_offset;
res = bs->dsk.journal_disk->read_async(
bs->dsk.journal_offset + md_offset, (size_t)submit_len,
GET_SQE();
data->iov = (iovec){
bs->buffer_area + md_offset,
[this](int res) { handle_event(res, -1, "read buffer area"); }
);
assert(res == 0);
md_offset += submit_len;
(size_t)(bs->dsk.journal_len - md_offset < bs->metadata_buf_size ? bs->dsk.journal_len - md_offset : bs->metadata_buf_size),
};
data->callback = [this](ring_data_t *data) { handle_event(data, -1, "read buffer area"); };
io_uring_prep_readv(sqe, bs->dsk.journal_fd, &data->iov, 1, bs->dsk.journal_offset + md_offset);
md_offset += data->iov.iov_len;
submitted++;
bs->ringloop->submit();
resume_3:
if (submitted > 0)
{
@@ -194,31 +201,26 @@ resume_4:
bufs[i].size = bs->dsk.meta_area_size-next_offset > bs->metadata_buf_size
? bs->metadata_buf_size : bs->dsk.meta_area_size-next_offset;
bufs[i].state = INIT_META_READING;
submitted++;
next_offset += bufs[i].size;
GET_SQE();
assert(bufs[i].size <= 0x7fffffff);
data->iov = { bufs[i].buf, (size_t)bufs[i].size };
if (!zero_on_init)
{
res = bs->dsk.meta_disk->read_async(
bs->dsk.meta_offset + bufs[i].offset,
(size_t)bufs[i].size, bufs[i].buf,
[this, i](int res) { handle_event(res, i, "read metadata"); }
);
assert(res == 0);
data->callback = [this, i](ring_data_t *data) { handle_event(data, i, "read metadata"); };
io_uring_prep_readv(sqe, bs->dsk.meta_fd, &data->iov, 1, bs->dsk.meta_offset + bufs[i].offset);
}
else
{
// Fill metadata with empty block pattern
data->callback = [this, i](ring_data_t *data) { handle_event(data, i, "clear metadata"); };
memset(bufs[i].buf, 0, bufs[i].size);
for (uint64_t o = 0; o < bufs[i].size; o += bs->dsk.meta_block_size)
bs->heap->fill_block_empty_space(bufs[i].buf + o, 0);
res = bs->dsk.meta_disk->write_async(
bs->dsk.meta_offset + bufs[i].offset,
(size_t)bufs[i].size, bufs[i].buf,
[this, i](int res) { handle_event(res, i, "clear metadata"); }
);
assert(res == 0);
io_uring_prep_writev(sqe, bs->dsk.meta_fd, &data->iov, 1, bs->dsk.meta_offset + bufs[i].offset);
}
submitted++;
next_offset += bufs[i].size;
bs->ringloop->submit();
break;
}
}
@@ -264,27 +266,26 @@ resume_6:
while (recheck_ios.size())
{
blockstore_recheck_io_t* rc = recheck_ios.back();
disk_i *di = (rc->is_data ? bs->dsk.data_disk : bs->dsk.journal_disk);
if (!rc->buf)
rc->buf = (uint8_t*)di->alloc_iomem(rc->len);
int res = di->read_async(
(rc->is_data ? bs->dsk.data_offset : bs->dsk.journal_offset) + rc->offset,
rc->len, rc->buf, [this, rc](int res)
{
if (res < 0)
{
fprintf(stderr, "Buffer area read failed at offset %ju: %d\n", rc->offset, res);
exit(1);
}
rc->cb(rc->buf);
disk_i *di = (rc->is_data ? bs->dsk.data_disk : bs->dsk.journal_disk);
di->free_iomem(rc->buf);
delete rc;
}
);
if (res == -EAGAIN)
sqe = bs->get_sqe();
if (!sqe)
break;
assert(res == 0);
if (!rc->buf)
rc->buf = (uint8_t*)memalign_or_die(MEM_ALIGNMENT, rc->len);
data = ((ring_data_t*)sqe->user_data);
data->iov = (iovec){ rc->buf, rc->len };
data->callback = [this, rc](ring_data_t *data)
{
if (data->res < 0)
{
fprintf(stderr, "Buffer area read failed at offset %ju: %d\n", rc->offset, data->res);
exit(1);
}
rc->cb(rc->buf);
free(rc->buf);
delete rc;
};
io_uring_prep_readv(sqe, (rc->is_data ? bs->dsk.data_fd : bs->dsk.journal_fd), &data->iov, 1,
(rc->is_data ? bs->dsk.data_offset : bs->dsk.journal_offset) + rc->offset);
recheck_ios.pop_back();
}
return 1;
@@ -306,35 +307,30 @@ resume_7:
for (i = 0; i < recheck_mod.size(); i++)
{
resume_8:
if (wait_count >= bs->meta_write_recheck_parallelism)
if (wait_count >= bs->meta_write_recheck_parallelism || !(sqe = bs->get_sqe()))
{
bs->ringloop->submit();
wait_state = 8;
return 1;
}
uint32_t block_num = recheck_mod[i];
uint64_t block_offset = bs->dsk.meta_offset + (uint64_t)(block_num+1) * bs->dsk.meta_block_size;
uint8_t *buf = (uint8_t*)bs->dsk.meta_disk->alloc_iomem(bs->dsk.meta_block_size);
data = ((ring_data_t*)sqe->user_data);
uint8_t *buf = (uint8_t*)memalign_or_die(MEM_ALIGNMENT, bs->dsk.meta_block_size);
bs->heap->get_meta_block(block_num, buf);
res = bs->dsk.meta_disk->write_async(block_offset, bs->dsk.meta_block_size, buf,
[this, buf, block_offset](int res)
{
wait_count--;
bs->dsk.meta_disk->free_iomem(buf);
if (res < 0)
{
throw std::runtime_error(
"write metadata failed at offset " + std::to_string(block_offset) + ": " + strerror(-res)
);
}
}
);
if (res == -EAGAIN)
data->iov = { buf, bs->dsk.meta_block_size };
data->callback = [this, buf, block_offset](ring_data_t *data)
{
bs->dsk.meta_disk->free_iomem(buf);
wait_state = 8;
return 1;
}
assert(!res);
wait_count--;
free(buf);
if (data->res != bs->dsk.meta_block_size)
{
throw std::runtime_error(
"write metadata failed at offset " + std::to_string(block_offset) + ": " + strerror(-data->res)
);
}
};
io_uring_prep_writev(sqe, bs->dsk.meta_fd, &data->iov, 1, block_offset);
wait_count++;
}
resume_9:
@@ -344,18 +340,18 @@ resume_9:
wait_state = 9;
return 1;
}
bs->dsk.meta_disk->free_iomem(metadata_buffer);
free(metadata_buffer);
metadata_buffer = NULL;
do_fsync:
if (!bs->dsk.disable_meta_fsync && !bs->readonly)
{
GET_SQE();
io_uring_prep_fsync(sqe, bs->dsk.meta_fd, IORING_FSYNC_DATASYNC);
last_read_offset = 0;
res = bs->dsk.meta_disk->flush_async([this](int res) { handle_event(res, -1, "fsync metadata"); });
if (res != -EALREADY)
{
assert(res == 0);
submitted++;
}
data->iov = { 0 };
data->callback = [this](ring_data_t *data) { handle_event(data, -1, "fsync metadata"); };
submitted++;
bs->ringloop->submit();
resume_5:
if (submitted > 0)
{
@@ -365,13 +361,13 @@ do_fsync:
}
if (zero_on_init && !header_written && !bs->readonly)
{
last_read_offset = 0;
res = bs->dsk.meta_disk->write_async(
bs->dsk.meta_offset, (size_t)bs->dsk.meta_block_size, bs->meta_superblock,
[this](int res) { handle_event(res, -1, "write metadata header"); }
);
assert(res == 0);
GET_SQE();
header_written = true;
last_read_offset = 0;
data->iov = (struct iovec){ bs->meta_superblock, (size_t)bs->dsk.meta_block_size };
data->callback = [this](ring_data_t *data) { handle_event(data, -1, "write metadata header"); };
io_uring_prep_writev(sqe, bs->dsk.meta_fd, &data->iov, 1, bs->dsk.meta_offset);
bs->ringloop->submit();
submitted++;
resume_2:
if (submitted > 0)

View File

@@ -21,19 +21,19 @@ class blockstore_init_meta
bool zero_on_init = false;
bool header_written = false;
void *metadata_buffer = NULL;
int res = 0;
blockstore_init_meta_buf bufs[2] = {};
int submitted = 0;
struct io_uring_sqe *sqe;
struct ring_data_t *data;
uint64_t md_offset = 0;
uint64_t next_offset = 0;
uint64_t last_read_offset = 0;
uint64_t entries_loaded = 0;
uint64_t submit_len = 0;
std::vector<uint32_t> recheck_mod;
std::vector<blockstore_recheck_io_t*> recheck_ios;
int i = 0, j = 0;
bool handle_meta_block(uint8_t *buf, uint64_t count, uint64_t done_cnt);
void handle_event(int res, int buf_num, const char *op);
void handle_event(ring_data_t *data, int buf_num, const char *op);
public:
blockstore_init_meta(blockstore_impl_t *bs);
int loop();

View File

@@ -3,40 +3,44 @@
#pragma once
#define BS_SUBMIT_CHECK_JOURNAL_QUEUE(n) {\
if (dsk.journal_disk->get_queue_space() < (n))\
#define BS_SUBMIT_CHECK_SQES(n) \
if (ringloop->space_left() < (n))\
{\
/* Pause until there are more requests available */\
PRIV(op)->wait_detail = (n);\
PRIV(op)->wait_for = WAIT_JOURNAL_QUEUE;\
PRIV(op)->wait_for = WAIT_SQE;\
return 0;\
} }
}
#define BS_SUBMIT_CHECK_DATA_QUEUE(n) {\
if (dsk.data_disk->get_queue_space() < (n))\
{\
/* Pause until there are more requests available */\
PRIV(op)->wait_detail = (n);\
PRIV(op)->wait_for = WAIT_DATA_QUEUE;\
return 0;\
} }
#define BS_SUBMIT_GET_SQE(sqe, data) \
BS_SUBMIT_GET_ONLY_SQE(sqe); \
struct ring_data_t *data = ((ring_data_t*)sqe->user_data)
#define BS_SUBMIT_CHECK_META_QUEUE(n) {\
if (dsk.meta_disk->get_queue_space() < (n))\
#define BS_SUBMIT_GET_ONLY_SQE(sqe) \
struct io_uring_sqe *sqe = get_sqe();\
if (!sqe)\
{\
/* Pause until there are more requests available */\
PRIV(op)->wait_detail = (n);\
PRIV(op)->wait_for = WAIT_META_QUEUE;\
PRIV(op)->wait_detail = 1;\
PRIV(op)->wait_for = WAIT_SQE;\
return 0;\
} }
}
#define BS_SUBMIT_GET_SQE_DECL(sqe) \
sqe = get_sqe();\
if (!sqe)\
{\
/* Pause until there are more requests available */\
PRIV(op)->wait_detail = 1;\
PRIV(op)->wait_for = WAIT_SQE;\
return 0;\
}
#define PRIV(op) ((blockstore_op_private_t*)(op)->private_data)
#define FINISH_OP(op) PRIV(op)->~blockstore_op_private_t(); std::function<void (blockstore_op_t*)>(op->callback)(op)
// Suspend operation until there are more free SQEs
#define WAIT_DATA_QUEUE 1
#define WAIT_META_QUEUE 2
#define WAIT_JOURNAL_QUEUE 3
#define WAIT_SQE 1
// Suspend operation until there are <wait_detail> bytes of free space in the journal on disk
#define WAIT_COMPACTION 2
// Suspend operation until LSN <wait_detail> becomes durable
@@ -61,3 +65,11 @@
#define COPY_BUF_COALESCED 0x10
#define COPY_BUF_PADDED 0x20
#define COPY_BUF_SKIP_CSUM 0x40
#ifndef RWF_ATOMIC
#define RWF_ATOMIC 0x40
#endif
#ifndef RWF_DSYNC
#define RWF_DSYNC 0x02
#endif

View File

@@ -88,7 +88,7 @@ int blockstore_impl_t::dequeue_read(blockstore_op_t *op)
if (need_wait)
{
undo_wait:
// Unlock LSN and wait
// Need to wait. undo added requests, unlock lsn
heap->unlock_entry(op->oid);
free_read_buffers(rv);
rv.clear();
@@ -106,13 +106,12 @@ undo_wait:
assert(fulfilled == op->len);
if (!fulfill_read(op))
{
// Not enough SQEs. Unlock lsn and wait
goto undo_wait;
}
op->version = result_version;
if (!PRIV(op)->pending_ops)
{
// Everything is fulfilled from memory
// everything is fulfilled from memory
heap->unlock_entry(op->oid);
op->retval = op->len;
free_read_buffers(rv);
@@ -126,24 +125,6 @@ undo_wait:
int blockstore_impl_t::fulfill_read(blockstore_op_t *op)
{
int ndata = 0, njournal = 0;
uint32_t nodsk = (COPY_BUF_COALESCED|COPY_BUF_CSUM_FILL|COPY_BUF_ZERO) |
(dsk.inmemory_journal ? COPY_BUF_JOURNAL : 0);
for (auto & vec: PRIV(op)->read_vec)
{
if (!(vec.copy_flags & nodsk))
{
auto & n = (vec.copy_flags & COPY_BUF_JOURNAL) ? njournal : ndata;
n++;
}
}
if (!dsk.data_off_ring && !dsk.journal_off_ring || dsk.data_disk == dsk.journal_disk)
{
ndata += njournal;
njournal = 0;
}
BS_SUBMIT_CHECK_DATA_QUEUE(ndata);
BS_SUBMIT_CHECK_JOURNAL_QUEUE(njournal);
for (auto & vec: PRIV(op)->read_vec)
{
if (vec.copy_flags & (COPY_BUF_COALESCED|COPY_BUF_CSUM_FILL))
@@ -161,14 +142,16 @@ int blockstore_impl_t::fulfill_read(blockstore_op_t *op)
}
else
{
disk_i *di = ((vec.copy_flags & COPY_BUF_JOURNAL) ? dsk.journal_disk : dsk.data_disk);
int res = di->read_async(
((vec.copy_flags & COPY_BUF_JOURNAL) ? dsk.journal_offset : dsk.data_offset) + vec.disk_loc + vec.disk_offset,
vec.disk_len, vec.buf ? vec.buf : (op->buf + vec.offset - op->offset),
[this, op](int res) { handle_read_event(res, op); }
);
assert(res == 0);
BS_SUBMIT_GET_SQE(sqe, data);
data->iov = (struct iovec){ vec.buf ? vec.buf : (op->buf + vec.offset - op->offset), (size_t)vec.disk_len };
PRIV(op)->pending_ops++;
io_uring_prep_readv(
sqe,
(vec.copy_flags & COPY_BUF_JOURNAL) ? dsk.journal_fd : dsk.data_fd,
&data->iov, 1,
((vec.copy_flags & COPY_BUF_JOURNAL) ? dsk.journal_offset : dsk.data_offset) + vec.disk_loc + vec.disk_offset
);
data->callback = [this, op](ring_data_t *data) { handle_read_event(data, op); };
}
}
return 1;
@@ -349,7 +332,7 @@ void blockstore_impl_t::prepare_disk_read(std::vector<copy_buffer_t> & read_vec,
}
else
{
vec.buf = (uint8_t*)((vec.copy_flags & COPY_BUF_JOURNAL) ? dsk.journal_disk : dsk.data_disk)->alloc_iomem(vec.disk_len);
vec.buf = (uint8_t*)memalign_or_die(MEM_ALIGNMENT, vec.disk_len);
}
}
read_vec.insert(read_vec.begin() + pos, vec);
@@ -400,22 +383,21 @@ void blockstore_impl_t::free_read_buffers(std::vector<copy_buffer_t> & rv)
if (!(vec.copy_flags & COPY_BUF_COALESCED) && vec.buf &&
(!buffer_area || vec.buf < buffer_area || vec.buf >= (uint8_t*)buffer_area + dsk.journal_len))
{
disk_i *di = (vec.copy_flags & COPY_BUF_JOURNAL) ? dsk.journal_disk : dsk.data_disk;
di->free_iomem(vec.buf);
free(vec.buf);
vec.buf = NULL;
}
}
}
}
void blockstore_impl_t::handle_read_event(int res, blockstore_op_t *op)
void blockstore_impl_t::handle_read_event(ring_data_t *data, blockstore_op_t *op)
{
live = true;
PRIV(op)->pending_ops--;
if (res < 0)
if (data->res != data->iov.iov_len)
{
// read error
op->retval = res;
op->retval = data->res;
}
if (PRIV(op)->pending_ops == 0)
{

View File

@@ -86,7 +86,7 @@ resume_1:
if (priv->modified_block != UINT32_MAX && priv->modified_block2 != priv->modified_block)
{
priv->op_state = 1;
BS_SUBMIT_CHECK_META_QUEUE(1);
BS_SUBMIT_CHECK_SQES(1);
prepare_meta_block_write(priv->modified_block);
resume_2:
if (meta_block_is_pending(priv->modified_block))

View File

@@ -27,72 +27,71 @@ bool blockstore_impl_t::has_unsynced()
return data || buffer || meta;
}
int blockstore_impl_t::submit_fsyncs(int & wait_count)
bool blockstore_impl_t::submit_fsyncs(int & wait_count)
{
int nm = (unsynced_meta_write_count > 0 && !dsk.disable_meta_fsync ? 1 : 0);
int nj = (unsynced_buffer_write_count > 0 && !dsk.disable_journal_fsync &&
(!unsynced_meta_write_count || dsk.journal_disk != dsk.meta_disk) ? 1 : 0);
int nd = (unsynced_data_write_count > 0 && !dsk.disable_data_fsync &&
(!unsynced_meta_write_count || dsk.data_disk != dsk.meta_disk) &&
(!unsynced_buffer_write_count || dsk.data_disk != dsk.journal_disk) ? 1 : 0);
if (!nm && !nj && !nd)
return 0;
int rnm = nm, rnj = nj, rnd = nd;
if (!dsk.meta_off_ring && !dsk.journal_off_ring)
rnm += rnj, rnj = 0;
if (!dsk.meta_off_ring && !dsk.data_off_ring)
rnm += rnd, rnd = 0;
if (!dsk.journal_off_ring && !dsk.data_off_ring)
rnj += rnd, rnd = 0;
if (rnm > 0 && dsk.meta_disk->get_queue_space() < rnm)
return WAIT_META_QUEUE;
if (rnj > 0 && dsk.journal_disk->get_queue_space() < rnj)
return WAIT_JOURNAL_QUEUE;
if (rnd > 0 && dsk.data_disk->get_queue_space() < rnd)
return WAIT_DATA_QUEUE;
auto cb = [this, & wait_count](int res)
int n = (unsynced_meta_write_count > 0 && !dsk.disable_meta_fsync ? 1 : 0) +
(unsynced_buffer_write_count > 0 && !dsk.disable_journal_fsync &&
(!unsynced_meta_write_count || dsk.journal_fd != dsk.meta_fd) ? 1 : 0) +
(unsynced_data_write_count > 0 && !dsk.disable_data_fsync &&
(!unsynced_meta_write_count || dsk.data_fd != dsk.meta_fd) &&
(!unsynced_buffer_write_count || dsk.data_fd != dsk.journal_fd) ? 1 : 0);
if (ringloop->space_left() < n)
{
if (res != 0)
disk_error_abort("sync meta", res);
return false;
}
if (!n)
{
return true;
}
auto cb = [this, & wait_count](ring_data_t *data)
{
if (data->res != 0)
disk_error_abort("sync meta", data->res, 0);
wait_count--;
assert(wait_count >= 0);
if (!wait_count)
ringloop->wakeup();
};
if (nm)
if (unsynced_meta_write_count > 0 && !dsk.disable_meta_fsync)
{
// fsync meta
int res = dsk.meta_disk->flush_async(cb);
if (res != -EALREADY)
{
assert(res == 0);
wait_count++;
}
io_uring_sqe *sqe = get_sqe();
assert(sqe);
ring_data_t *data = ((ring_data_t*)sqe->user_data);
io_uring_prep_fsync(sqe, dsk.meta_fd, IORING_FSYNC_DATASYNC);
data->iov = { 0 };
data->callback = cb;
wait_count++;
}
if (nj)
if (unsynced_buffer_write_count > 0 && !dsk.disable_journal_fsync &&
(!unsynced_meta_write_count || dsk.journal_fd != dsk.meta_fd))
{
// fsync buffer
int res = dsk.journal_disk->flush_async(cb);
if (res != -EALREADY)
{
assert(res == 0);
wait_count++;
}
io_uring_sqe *sqe = get_sqe();
assert(sqe);
ring_data_t *data = ((ring_data_t*)sqe->user_data);
io_uring_prep_fsync(sqe, dsk.journal_fd, IORING_FSYNC_DATASYNC);
data->iov = { 0 };
data->callback = cb;
wait_count++;
}
if (nd)
if (unsynced_data_write_count > 0 && !dsk.disable_data_fsync &&
(!unsynced_meta_write_count || dsk.data_fd != dsk.meta_fd) &&
(!unsynced_buffer_write_count || dsk.data_fd != dsk.journal_fd))
{
// fsync data
int res = dsk.data_disk->flush_async(cb);
if (res != -EALREADY)
{
assert(res == 0);
wait_count++;
}
io_uring_sqe *sqe = get_sqe();
assert(sqe);
ring_data_t *data = ((ring_data_t*)sqe->user_data);
io_uring_prep_fsync(sqe, dsk.data_fd, IORING_FSYNC_DATASYNC);
data->iov = { 0 };
data->callback = cb;
wait_count++;
}
unsynced_data_write_count = 0;
unsynced_buffer_write_count = 0;
unsynced_meta_write_count = 0;
return 0;
return true;
}
int blockstore_impl_t::do_sync(blockstore_op_t *op, int base_state)
@@ -114,10 +113,11 @@ int blockstore_impl_t::do_sync(blockstore_op_t *op, int base_state)
}
assert(!PRIV(op)->lsn);
PRIV(op)->lsn = heap->get_completed_lsn();
PRIV(op)->wait_for = submit_fsyncs(PRIV(op)->pending_ops);
if (PRIV(op)->wait_for)
if (!submit_fsyncs(PRIV(op)->pending_ops))
{
PRIV(op)->lsn = 0;
PRIV(op)->wait_detail = 1;
PRIV(op)->wait_for = WAIT_SQE;
return 0;
}
resume_1:

View File

@@ -16,31 +16,32 @@ bool blockstore_impl_t::enqueue_write(blockstore_op_t *op)
void blockstore_impl_t::prepare_meta_block_write(uint32_t modified_block)
{
if (modified_blocks.find(modified_block) != modified_blocks.end())
{
return;
}
uint8_t *buf = (uint8_t*)dsk.meta_disk->alloc_iomem(dsk.meta_block_size);
assert(((uint64_t)modified_block+2)*dsk.meta_block_size <= dsk.meta_area_size);
int res = dsk.meta_disk->write_async(
dsk.meta_offset + ((uint64_t)modified_block+1)*dsk.meta_block_size, dsk.meta_block_size, buf,
[this, modified_block](int res)
io_uring_sqe *sqe = get_sqe();
assert(sqe != NULL);
ring_data_t *data = ((ring_data_t*)sqe->user_data);
uint8_t *buf = (uint8_t*)memalign_or_die(MEM_ALIGNMENT, dsk.meta_block_size);
data->iov = (struct iovec){ buf, (size_t)dsk.meta_block_size };
data->callback = [this, modified_block](ring_data_t *data)
{
live = true;
if (data->res != data->iov.iov_len)
{
live = true;
if (res < 0)
{
// FIXME: our state becomes corrupted after a write error. maybe do something better than just die
disk_error_abort("data write", res);
}
auto it = modified_blocks.find(modified_block);
assert(it != modified_blocks.end());
dsk.meta_disk->free_iomem(it->second.buf);
modified_blocks.erase(it);
unsynced_meta_write_count++;
heap->complete_block_write(modified_block);
ringloop->wakeup();
// FIXME: our state becomes corrupted after a write error. maybe do something better than just die
disk_error_abort("data write", data->res, data->iov.iov_len);
}
auto it = modified_blocks.find(modified_block);
assert(it != modified_blocks.end());
free(it->second.buf);
modified_blocks.erase(it);
unsynced_meta_write_count++;
heap->complete_block_write(modified_block);
ringloop->wakeup();
};
assert(((uint64_t)modified_block+2)*dsk.meta_block_size <= dsk.meta_area_size);
io_uring_prep_writev(
sqe, dsk.meta_fd, &data->iov, 1, dsk.meta_offset + ((uint64_t)modified_block+1)*dsk.meta_block_size
);
assert(res == 0);
pending_modified_blocks.push_back(modified_block);
modified_blocks[modified_block] = { .sent = false, .buf = buf };
}
@@ -134,7 +135,7 @@ int blockstore_impl_t::dequeue_write(blockstore_op_t *op)
return 2;
}
PRIV(op)->write_type = BS_HEAP_DELETE;
BS_SUBMIT_CHECK_META_QUEUE(1);
BS_SUBMIT_CHECK_SQES(1);
int res = heap->add_delete(obj, &PRIV(op)->modified_block);
assert(res != EAGAIN);
if (res == ENOSPC)
@@ -151,7 +152,7 @@ int blockstore_impl_t::dequeue_write(blockstore_op_t *op)
{
// Big (redirect) write
PRIV(op)->write_type = dsk.disable_data_fsync || op->opcode != BS_OP_WRITE_STABLE ? BS_HEAP_BIG_WRITE : _REDIRECT_INTENT;
BS_SUBMIT_CHECK_DATA_QUEUE(1);
BS_SUBMIT_CHECK_SQES(1);
PRIV(op)->location = heap->find_free_data();
if (PRIV(op)->location == UINT64_MAX)
{
@@ -176,12 +177,12 @@ enospc:
);
#endif
heap->use_data(op->oid.inode, PRIV(op)->location);
io_uring_sqe *sqe = get_sqe();
ring_data_t *data = ((ring_data_t*)sqe->user_data);
data->iov = (struct iovec){ op->buf, op->len };
data->callback = [this, op](ring_data_t *data) { handle_write_event(data, op); };
assert(loc+op->offset+op->len <= dsk.block_count*dsk.data_block_size);
int res = dsk.data_disk->write_async(
dsk.data_offset + loc + op->offset, op->len, op->buf,
[this, op](int res) { handle_write_event(res, op); }
);
assert(res == 0);
io_uring_prep_writev(sqe, dsk.data_fd, &data->iov, 1, dsk.data_offset + loc + op->offset);
if (!dsk.disable_data_fsync)
{
// use PRIV->lsn for fsync_data_id
@@ -198,7 +199,7 @@ enospc:
else if (intent_write_allowed(op, obj))
{
// Direct intent-write
BS_SUBMIT_CHECK_META_QUEUE(1);
BS_SUBMIT_CHECK_SQES(1);
int res = 0;
if (dsk.csum_block_size <= dsk.bitmap_granularity &&
(obj->entry_type == (BS_HEAP_BIG_INTENT|BS_HEAP_STABLE) ||
@@ -259,15 +260,7 @@ enospc:
return 0;
}
// There is sufficient space. Check SQE(s)
if (!op->len || dsk.journal_disk == dsk.meta_disk || !dsk.journal_off_ring && !dsk.meta_off_ring)
{
BS_SUBMIT_CHECK_META_QUEUE(1 + (op->len > 0 ? 1 : 0));
}
else
{
BS_SUBMIT_CHECK_META_QUEUE(1);
BS_SUBMIT_CHECK_JOURNAL_QUEUE(1);
}
BS_SUBMIT_CHECK_SQES(1 + (op->len > 0 ? 1 : 0));
int res = heap->add_small_write(op->oid, &obj, (BS_HEAP_SMALL_WRITE | (op->opcode == BS_OP_WRITE_STABLE ? BS_HEAP_STABLE : 0)),
op->version, op->offset, op->len, loc, op->bitmap, (uint8_t*)op->buf, &PRIV(op)->modified_block);
BS_SUBMIT_CHECK_PLACEMENT(res, obj->lsn);
@@ -285,12 +278,11 @@ enospc:
{
memcpy((uint8_t*)buffer_area + loc, op->buf, op->len);
}
BS_SUBMIT_GET_SQE(sqe2, data2);
data2->iov = (struct iovec){ op->buf, op->len };
data2->callback = [this, op](ring_data_t *data) { handle_write_event(data, op); };
assert(loc+op->len <= dsk.journal_len);
res = dsk.journal_disk->write_async(
dsk.journal_offset + loc, op->len, op->buf,
[this, op](int res) { handle_write_event(res, op); }
);
assert(res == 0);
io_uring_prep_writev(sqe2, dsk.journal_fd, &data2->iov, 1, dsk.journal_offset + loc);
PRIV(op)->pending_ops++;
}
else
@@ -306,7 +298,6 @@ enospc:
int blockstore_impl_t::continue_write(blockstore_op_t *op)
{
int res = 0;
int op_state = PRIV(op)->op_state;
again:
if (op_state == 2)
@@ -359,29 +350,21 @@ resume_11:
}
if (PRIV(op)->lsn > data_fsync_sent)
{
res = dsk.data_disk->flush_async([this, op, fs = data_fsync_cur](int res)
BS_SUBMIT_GET_SQE(sqe, data);
io_uring_prep_fsync(sqe, dsk.data_fd, IORING_FSYNC_DATASYNC);
data->iov = { 0 };
data->callback = [this, op, fs = data_fsync_cur](ring_data_t *data)
{
live = true;
if (res != 0)
disk_error_abort("sync data", res);
if (data->res != 0)
disk_error_abort("sync data", data->res, 0);
if (fs > data_fsync_done)
{
data_fsync_done = fs;
ringloop->wakeup();
}
});
if (res == -EAGAIN)
{
return 1;
}
else
{
data_fsync_sent = data_fsync_cur;
if (res == -EALREADY)
data_fsync_done = data_fsync_cur;
else
assert(res == 0);
}
};
data_fsync_sent = data_fsync_cur;
}
if (PRIV(op)->lsn > data_fsync_done)
{
@@ -391,8 +374,9 @@ resume_11:
}
resume_4:
{
BS_SUBMIT_CHECK_META_QUEUE(1);
BS_SUBMIT_CHECK_SQES(1);
auto obj = heap->read_entry(op->oid);
int res = 0;
if (PRIV(op)->write_type == _REDIRECT_INTENT)
{
res = heap->add_redirect_intent(op->oid, &obj, op->version, op->offset, op->len,
@@ -492,28 +476,25 @@ resume_8:
resume_10:
// Direct intent-write
// LSN is not marked as completed so big_write won't be freed
BS_SUBMIT_CHECK_DATA_QUEUE(1);
BS_SUBMIT_GET_SQE(sqe, data);
data->iov = (struct iovec){ op->buf, op->len };
data->callback = [this, op](ring_data_t *data) { handle_write_event(data, op); };
assert(PRIV(op)->location + op->offset <= dsk.block_count*dsk.data_block_size);
// FIXME: We tried to use RWF_ATOMIC here, but it's useless because Linux
// incorrectly enforces 2^N atomic write alignment which is a blocker for us.
// So now it's removed.
res = dsk.data_disk->write_async(
dsk.data_offset + PRIV(op)->location + op->offset, op->len, op->buf,
[this, op](int res) { handle_write_event(res, op); }
);
assert(res == 0);
io_uring_prep_writev(sqe, dsk.data_fd, &data->iov, 1, dsk.data_offset + PRIV(op)->location + op->offset);
if (dsk.use_atomic_flag)
sqe->rw_flags = RWF_ATOMIC;
PRIV(op)->pending_ops++;
PRIV(op)->op_state = 7;
return 1;
}
void blockstore_impl_t::handle_write_event(int res, blockstore_op_t *op)
void blockstore_impl_t::handle_write_event(ring_data_t *data, blockstore_op_t *op)
{
live = true;
if (res < 0)
if (data->res != data->iov.iov_len)
{
// FIXME: our state becomes corrupted after a write error. maybe do something better than just die
disk_error_abort("data write", res);
disk_error_abort("data write", data->res, data->iov.iov_len);
}
PRIV(op)->pending_ops--;
assert(PRIV(op)->pending_ops >= 0);

View File

@@ -1,7 +1,6 @@
// Copyright (c) Vitaliy Filippov, 2019+
// License: VNPL-1.1 (see README.md for details)
#include "disk_util.h"
#include "impl.h"
#include "internal.h"
@@ -23,9 +22,6 @@ blockstore_impl_t::blockstore_impl_t(blockstore_config_t & config, ring_loop_i *
dsk.open_meta();
dsk.open_journal();
calc_lengths();
dsk.data_fd = dsk.data_disk->get_fd();
dsk.meta_fd = dsk.meta_disk->get_fd();
dsk.journal_fd = dsk.journal_disk->get_fd();
alloc_dyn_data = dsk.clean_dyn_size > sizeof(void*) || dsk.csum_block_size > 0;
zero_object = (uint8_t*)memalign_or_die(MEM_ALIGNMENT, dsk.data_block_size);
memset(zero_object, 0, dsk.data_block_size);

View File

@@ -6,7 +6,7 @@ includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@
Name: Vitastor
Description: Vitastor client library
Version: 3.2.1
Version: 3.2.2
Libs: -L${libdir} -lvitastor_client
Cflags: -I${includedir}

View File

@@ -10,7 +10,6 @@ add_executable(vitastor-disk
disk_tool.h
disk_tool_journal.cpp
disk_tool_meta.cpp
disk_tool_nvme.cpp
disk_tool_prepare.cpp
disk_tool_resize_auto.cpp
disk_tool_resize.cpp

View File

@@ -1,11 +1,16 @@
// Copyright (c) Vitaliy Filippov, 2019+
// License: VNPL-1.1 (see README.md for details)
#include <fcntl.h>
#include <sys/ioctl.h>
#include <ctype.h>
#include <unistd.h>
#include <sys/stat.h>
#include "json11/json11.hpp"
#include "str_util.h"
#include "blockstore.h"
#include "blockstore_disk.h"
#include "disk_util.h"
#include "blockstore_heap.h"
#include "ondisk_formats.h"
@@ -57,23 +62,39 @@ void disk_tool_simple_offsets(json11::Json cfg, bool json_output)
fprintf(stderr, "Device path is missing\n");
exit(1);
}
disk_i *disk = disk_i::create_and_open(device, "cached,ro", true);
if (!disk)
struct stat st;
if (stat(device.c_str(), &st) < 0)
{
fprintf(stderr, "Failed to open %s\n", device.c_str());
fprintf(stderr, "Can't stat %s: %s\n", device.c_str(), strerror(errno));
exit(1);
}
device_size = disk->get_size();
uint64_t blksize = disk->get_block_size();
if (blksize < device_block_size)
if (S_ISBLK(st.st_mode))
{
fprintf(
stderr, "Warning: %s reports %ju byte blocks, but we use %ju."
" Set --device_block_size=%ju if you're sure it works well with %ju byte blocks.\n",
device.c_str(), blksize, device_block_size, blksize, blksize
);
int fd = open(device.c_str(), O_DIRECT|O_RDONLY);
if (fd < 0 || ioctl(fd, BLKGETSIZE64, &device_size) < 0)
{
fprintf(stderr, "Failed to get device size for %s: %s\n", device.c_str(), strerror(errno));
exit(1);
}
close(fd);
if (st.st_blksize < device_block_size)
{
fprintf(
stderr, "Warning: %s reports %ju byte blocks, but we use %ju."
" Set --device_block_size=%ju if you're sure it works well with %ju byte blocks.\n",
device.c_str(), (uint64_t)st.st_blksize, device_block_size, (uint64_t)st.st_blksize, (uint64_t)st.st_blksize
);
}
}
else if (S_ISREG(st.st_mode))
{
device_size = st.st_size;
}
else
{
fprintf(stderr, "%s is neither a block device nor a regular file\n", device.c_str());
exit(1);
}
delete disk;
}
if (!device_size)
{

View File

@@ -207,9 +207,6 @@ static const char *help_text =
" Write metadata from JSON taken from standard input in the same format as produced by `dump-meta`.\n"
" You can specify any OSD device (data, metadata or journal), or the layout manually.\n"
"\n"
"vitastor-disk find-pci <serial> [nsid]\n"
" Find PCI ID and attributes of an NVMe device with a specified serial number.\n"
"\n"
"vitastor-disk simple-offsets <device>\n"
" Calculate offsets for old simple&stupid (no superblock) OSD deployment. Options:\n"
" --object_size 128k Set blockstore block size\n"
@@ -476,16 +473,6 @@ int main(int argc, char *argv[])
{
return self.raw_resize();
}
else if (!strcmp(cmd[0], "find-pci"))
{
if (cmd.size() != 2 && cmd.size() != 3)
{
fprintf(stderr, "S/N and optionally NS number is required\n");
return 1;
}
self.find_pci_id(cmd[1], cmd.size() == 3 ? stoull_full(cmd[2]) : 0);
return 0;
}
else if (!strcmp(cmd[0], "simple-offsets"))
{
// Calculate offsets for simple & stupid OSD deployment without superblock

View File

@@ -17,7 +17,6 @@
#include "blockstore_disk.h"
#include "blockstore.h"
#include "blockstore_heap.h"
#include "disk_util.h"
#include "ondisk_formats.h"
#include "crc32c.h"
#include "allocator.h"
@@ -86,7 +85,7 @@ struct disk_tool_t
uint64_t total_blocks = 0, free_first = 0, free_last = 0;
uint64_t new_clean_entry_bitmap_size = 0, new_data_csum_size = 0, new_clean_entry_size = 0, new_entries_per_block = 0;
uint32_t new_meta_format = 0;
disk_i *new_journal_disk = NULL, *new_meta_disk = NULL;
int new_journal_fd = -1, new_meta_fd = -1;
resizer_data_moving_t *moving_blocks = NULL;
bool atomic_warned = false;
@@ -153,8 +152,6 @@ struct disk_tool_t
int clear_osd_superblock(const std::string & dev);
int trim_data(std::string device);
std::string find_pci_id(const std::string & nvme_serial, uint32_t nvme_nsid);
json11::Json read_osd_superblock(std::string device, bool expect_exist = true, bool ignore_nonref = false);
uint32_t write_osd_superblock(std::string device, json11::Json params);
@@ -180,6 +177,7 @@ uint64_t get_atomic_write_size(const std::string & dev);
uint64_t get_device_size(const std::string & dev, bool should_exist = false);
std::string get_parent_device(std::string dev);
int shell_exec(const std::vector<std::string> & cmd, const std::string & in, std::string *out, std::string *err);
int write_zero(int fd, uint64_t offset, uint64_t size);
json11::Json read_parttable(std::string dev);
uint64_t dev_size_from_parttable(json11::Json pt);
uint64_t free_from_parttable(json11::Json pt);

View File

@@ -22,22 +22,18 @@ int disk_tool_t::dump_journal()
printf("[\n");
if (all)
{
dsk.journal_disk = disk_i::create_and_open(dsk.journal_device, (options["io"] == "cached" ? "cached,ro" : "ro"), true);
if (!dsk.journal_disk)
dsk.journal_fd = open(dsk.journal_device.c_str(), (options["io"] == "cached" ? 0 : O_DIRECT) | O_RDONLY);
if (dsk.journal_fd < 0)
{
fprintf(stderr, "Failed to open journal device %s\n", dsk.journal_device.c_str());
fprintf(stderr, "Failed to open journal device %s: %s\n", dsk.journal_device.c_str(), strerror(errno));
return 1;
}
void *journal_buf = dsk.journal_disk->alloc_iomem(dsk.journal_block_size);
void *journal_buf = memalign_or_die(MEM_ALIGNMENT, dsk.journal_block_size);
journal_pos = 0;
while (journal_pos < dsk.journal_len)
{
int r = dsk.journal_disk->read_sync(dsk.journal_offset+journal_pos, dsk.journal_block_size, journal_buf);
if (r != 0)
{
fprintf(stderr, "Failed to read journal block at %ju: %s (code %u)\n", dsk.journal_offset+journal_pos, strerror(-r), -r);
break;
}
int r = pread(dsk.journal_fd, journal_buf, dsk.journal_block_size, dsk.journal_offset+journal_pos);
assert(r == dsk.journal_block_size);
uint64_t s;
for (s = 0; s < dsk.journal_block_size; s += 8)
{
@@ -94,9 +90,9 @@ int disk_tool_t::dump_journal()
journal_pos += dsk.journal_block_size;
}
}
dsk.journal_disk->free_iomem(journal_buf);
delete dsk.journal_disk;
dsk.journal_disk = NULL;
free(journal_buf);
close(dsk.journal_fd);
dsk.journal_fd = -1;
}
else
{
@@ -131,28 +127,23 @@ int disk_tool_t::process_journal(std::function<int(void*)> block_fn, bool do_ope
{
if (do_open)
{
if (dsk.journal_disk)
if (dsk.journal_fd >= 0)
{
fprintf(stderr, "Bug: journal device is already opened\n");
return 1;
}
dsk.journal_disk = disk_i::create_and_open(dsk.journal_device, (options["io"] == "cached" ? "cached,ro" : "ro"), true);
if (!dsk.journal_disk)
dsk.journal_fd = open(dsk.journal_device.c_str(), (options["io"] == "cached" ? 0 : O_DIRECT) | O_RDONLY);
if (dsk.journal_fd < 0)
{
fprintf(stderr, "Failed to open journal device %s\n", dsk.journal_device.c_str());
fprintf(stderr, "Failed to open journal device %s: %s\n", dsk.journal_device.c_str(), strerror(errno));
return 1;
}
}
void *data = dsk.journal_disk->alloc_iomem(dsk.journal_block_size);
void *data = memalign_or_die(MEM_ALIGNMENT, dsk.journal_block_size);
journal_pos = 0;
journal_entry *je = NULL;
int r = dsk.journal_disk->read_sync(dsk.journal_offset+journal_pos, dsk.journal_block_size, data);
if (r != 0)
{
fprintf(stderr, "Failed to read journal header at %ju: %s (code %u)\n", dsk.journal_offset+journal_pos, strerror(-r), -r);
goto ret;
}
je = (journal_entry*)(data);
int r = pread(dsk.journal_fd, data, dsk.journal_block_size, dsk.journal_offset+journal_pos);
assert(r == dsk.journal_block_size);
journal_entry *je = (journal_entry*)(data);
if (je->magic != JOURNAL_MAGIC || je->type != JE_START || je_crc32(je) != je->crc32)
{
fprintf(stderr, "offset %08jx: journal superblock is invalid\n", journal_pos);
@@ -184,28 +175,19 @@ int disk_tool_t::process_journal(std::function<int(void*)> block_fn, bool do_ope
{
if (journal_pos >= dsk.journal_len)
journal_pos = dsk.journal_block_size;
r = dsk.journal_disk->read_sync(dsk.journal_offset+journal_pos, dsk.journal_block_size, data);
if (r != 0)
{
fprintf(stderr, "Failed to read journal block at %ju: %s (code %u)\n", dsk.journal_offset+journal_pos, strerror(-r), -r);
break;
}
r = pread(dsk.journal_fd, data, dsk.journal_block_size, dsk.journal_offset+journal_pos);
assert(r == dsk.journal_block_size);
r = block_fn(data);
if (r <= 0)
break;
}
}
ret:
if (data)
{
dsk.journal_disk->free_iomem(data);
data = NULL;
}
if (do_open)
{
delete dsk.journal_disk;
dsk.journal_disk = NULL;
close(dsk.journal_fd);
dsk.journal_fd = -1;
}
free(data);
return r;
}
@@ -245,14 +227,8 @@ int disk_tool_t::process_journal_block(void *buf, std::function<void(int, journa
journal_pos = dsk.journal_block_size;
wrapped = true;
}
small_write_data = dsk.journal_disk->alloc_iomem(je->small_write.len);
int r = dsk.journal_disk->read_sync(dsk.journal_offset+je->small_write.data_offset, je->small_write.len, small_write_data);
if (r != 0)
{
fprintf(stderr, "Failed to read %u journal bytes at %ju: %s (code %u)\n", je->small_write.len,
dsk.journal_offset+je->small_write.data_offset, strerror(-r), -r);
break;
}
small_write_data = memalign_or_die(MEM_ALIGNMENT, je->small_write.len);
assert(pread(dsk.journal_fd, small_write_data, je->small_write.len, dsk.journal_offset+je->small_write.data_offset) == je->small_write.len);
data_crc32 = je_start.csum_block_size ? 0 : crc32c(0, small_write_data, je->small_write.len);
data_csum_valid = (data_crc32 == je->small_write.crc32_data);
if (je_start.csum_block_size && je->small_write.len > 0)
@@ -300,7 +276,7 @@ int disk_tool_t::process_journal_block(void *buf, std::function<void(int, journa
iter_fn(entry, je);
if (je->type == JE_SMALL_WRITE || je->type == JE_SMALL_WRITE_INSTANT)
{
dsk.journal_disk->free_iomem(small_write_data);
free(small_write_data);
small_write_data = NULL;
}
pos += je->size;
@@ -462,7 +438,7 @@ void disk_tool_t::dump_journal_entry(int num, journal_entry *je, bool json)
int disk_tool_t::write_json_journal(json11::Json entries)
{
new_journal_buf = (uint8_t*)dsk.journal_disk->alloc_iomem(new_journal_len);
new_journal_buf = (uint8_t*)memalign_or_die(MEM_ALIGNMENT, new_journal_len);
new_journal_ptr = new_journal_buf;
new_journal_data = new_journal_ptr + dsk.journal_block_size;
new_journal_in_pos = 0;
@@ -521,7 +497,7 @@ int disk_tool_t::write_json_journal(json11::Json entries)
if (new_journal_ptr-new_journal_buf >= new_journal_len)
{
fprintf(stderr, "Error: entries don't fit to the new journal\n");
dsk.journal_disk->free_iomem(new_journal_buf);
free(new_journal_buf);
return 1;
}
new_journal_data = new_journal_ptr+dsk.journal_block_size;
@@ -529,7 +505,7 @@ int disk_tool_t::write_json_journal(json11::Json entries)
if (dsk.journal_block_size < entry_size)
{
fprintf(stderr, "Error: journal entry too large (%u bytes)\n", entry_size);
dsk.journal_disk->free_iomem(new_journal_buf);
free(new_journal_buf);
return 1;
}
}
@@ -539,7 +515,7 @@ int disk_tool_t::write_json_journal(json11::Json entries)
if (new_journal_data - new_journal_buf + len > new_journal_len)
{
fprintf(stderr, "Error: entries don't fit to the new journal\n");
dsk.journal_disk->free_iomem(new_journal_buf);
free(new_journal_buf);
return 1;
}
*((journal_entry_small_write*)ne) = (journal_entry_small_write){
@@ -562,7 +538,7 @@ int disk_tool_t::write_json_journal(json11::Json entries)
if (ne->small_write.len > 0 && !rec["data"].is_string())
{
fprintf(stderr, "Error: entry data is missing, please generate the dump with --json --format data\n");
dsk.journal_disk->free_iomem(new_journal_buf);
free(new_journal_buf);
return 1;
}
if (ne->small_write.len > 0)
@@ -623,6 +599,6 @@ int disk_tool_t::write_json_journal(json11::Json entries)
new_journal_in_pos += ne->size;
}
int r = resize_write_new_journal();
dsk.journal_disk->free_iomem(new_journal_buf);
free(new_journal_buf);
return r;
}

View File

@@ -22,36 +22,31 @@ int disk_tool_t::process_meta(std::function<void(blockstore_meta_header_v3_t *)>
if (buf_size % dsk.meta_block_size)
buf_size = 8*dsk.meta_block_size;
uint8_t *data = NULL;
blockstore_meta_header_v3_t *hdr = NULL;
data = (uint8_t*)memalign_or_die(MEM_ALIGNMENT, buf_size);
blockstore_meta_header_v3_t *hdr = (blockstore_meta_header_v3_t *)memalign_or_die(MEM_ALIGNMENT, dsk.meta_block_size);
if (do_open)
{
if (dsk.meta_disk)
if (dsk.meta_fd >= 0)
{
fprintf(stderr, "Bug: Metadata device is already opened\n");
close_error:
r = 1;
goto close_free;
}
dsk.meta_disk = disk_i::create_and_open(dsk.meta_device, (options["io"] == "cached" ? "cached,ro" : "ro"), true);
if (!dsk.meta_disk)
dsk.meta_fd = open(dsk.meta_device.c_str(), (options["io"] == "cached" ? 0 : O_DIRECT) | O_RDONLY);
if (dsk.meta_fd < 0)
{
fprintf(stderr, "Failed to open metadata device %s\n", dsk.meta_device.c_str());
fprintf(stderr, "Failed to open metadata device %s: %s\n", dsk.meta_device.c_str(), strerror(errno));
goto close_error;
}
}
else if (!dsk.meta_disk)
else if (dsk.meta_fd < 0)
{
fprintf(stderr, "Bug: Metadata device is not opened\n");
goto close_error;
}
data = (uint8_t*)dsk.meta_disk->alloc_iomem(buf_size);
hdr = (blockstore_meta_header_v3_t *)dsk.meta_disk->alloc_iomem(dsk.meta_block_size);
// Check superblock
if ((r = dsk.meta_disk->read_sync(dsk.meta_offset, dsk.meta_block_size, hdr)) != 0)
{
fprintf(stderr, "Failed to read metadata header: %s (code %d)\n", strerror(-r), -r);
goto close_error;
}
pread_blocking(dsk.meta_fd, hdr, dsk.meta_block_size, dsk.meta_offset);
if (hdr->zero == 0 && hdr->magic == BLOCKSTORE_META_MAGIC_V1 && hdr->version == BLOCKSTORE_META_FORMAT_HEAP)
{
if (hdr->data_csum_type != 0 &&
@@ -67,40 +62,35 @@ close_error:
// Load buffer_area
if (with_data)
{
buffer_area = (uint8_t*)memalign_or_die(MEM_ALIGNMENT, dsk.journal_len);
if (dsk.journal_device == dsk.meta_device || dsk.journal_device == "")
{
dsk.journal_disk = dsk.meta_disk;
dsk.journal_fd = dsk.meta_fd;
}
else if (do_open)
{
if (dsk.journal_disk)
if (dsk.journal_fd >= 0)
{
fprintf(stderr, "Bug: Metadata device is already opened\n");
goto close_error;
}
dsk.journal_disk = disk_i::create_and_open(dsk.journal_device, (options["io"] == "cached" ? "cached,ro" : "ro"), true);
if (!dsk.journal_disk)
dsk.journal_fd = open(dsk.journal_device.c_str(), (options["io"] == "cached" ? 0 : O_DIRECT) | O_RDONLY);
if (dsk.journal_fd < 0)
{
fprintf(stderr, "Failed to open journal device %s\n", dsk.journal_device.c_str());
fprintf(stderr, "Failed to open journal device %s: %s\n", dsk.journal_device.c_str(), strerror(errno));
goto close_error;
}
}
else if (!dsk.journal_disk)
else if (dsk.journal_fd < 0)
{
fprintf(stderr, "Bug: journal device is not opened\n");
goto close_error;
}
buffer_area = (uint8_t*)dsk.journal_disk->alloc_iomem(dsk.journal_len);
uint64_t journal_pos = 0;
while (journal_pos < dsk.journal_len)
{
uint64_t read_len = buf_size < dsk.journal_len-journal_pos ? buf_size : dsk.journal_len-journal_pos;
if ((r = dsk.journal_disk->read_sync(dsk.journal_offset+journal_pos, read_len, buffer_area+journal_pos)) != 0)
{
fprintf(stderr, "Failed to read %ju bytes at %ju from journal device %s: %s (code %d)\n",
read_len, dsk.journal_offset+journal_pos, dsk.journal_device.c_str(), strerror(-r), -r);
goto close_error;
}
pread_blocking(dsk.journal_fd, buffer_area+journal_pos, read_len, dsk.journal_offset+journal_pos);
journal_pos += read_len;
}
}
@@ -118,12 +108,7 @@ close_error:
while (meta_pos < hdr->meta_area_size)
{
uint64_t read_len = buf_size < hdr->meta_area_size-meta_pos ? buf_size : hdr->meta_area_size-meta_pos;
if ((r = dsk.meta_disk->read_sync(dsk.meta_offset+meta_pos, read_len, data)) != 0)
{
fprintf(stderr, "Failed to read %ju bytes at %ju from metadata device %s: %s (code %d)\n",
read_len, dsk.meta_offset+meta_pos, dsk.meta_device.c_str(), strerror(-r), -r);
goto close_error;
}
pread_blocking(dsk.meta_fd, data, read_len, dsk.meta_offset+meta_pos);
r = heap->load_blocks(meta_pos-dsk.meta_block_size, read_len, data, true, entries_loaded);
meta_pos += read_len;
}
@@ -185,12 +170,7 @@ csum_unknown:
while (meta_pos < dsk.min_meta_len)
{
uint64_t read_len = buf_size < dsk.min_meta_len-meta_pos ? buf_size : dsk.min_meta_len-meta_pos;
if ((r = dsk.meta_disk->read_sync(dsk.meta_offset+meta_pos, read_len, data)) != 0)
{
fprintf(stderr, "Failed to read %ju bytes at %ju from metadata device %s: %s (code %d)\n",
read_len, dsk.meta_offset+meta_pos, dsk.meta_device.c_str(), strerror(-r), -r);
goto close_error;
}
pread_blocking(dsk.meta_fd, data, read_len, dsk.meta_offset+meta_pos);
meta_pos += read_len;
for (uint64_t blk = 0; blk < read_len; blk += dsk.meta_block_size)
{
@@ -225,12 +205,7 @@ csum_unknown:
while (meta_pos < dsk.min_meta_len)
{
uint64_t read_len = buf_size < dsk.min_meta_len-meta_pos ? buf_size : dsk.min_meta_len-meta_pos;
if ((r = dsk.meta_disk->read_sync(dsk.meta_offset+meta_pos, read_len, data)) != 0)
{
fprintf(stderr, "Failed to read %ju bytes at %ju from metadata device %s: %s (code %d)\n",
read_len, dsk.meta_offset+meta_pos, dsk.meta_device.c_str(), strerror(-r), -r);
goto close_error;
}
pread_blocking(dsk.meta_fd, data, read_len, dsk.meta_offset+meta_pos);
meta_pos += read_len;
for (uint64_t blk = 0; blk < read_len; blk += dsk.meta_block_size)
{
@@ -246,29 +221,23 @@ csum_unknown:
}
}
close_free:
if (data)
{
dsk.meta_disk->free_iomem(data);
data = NULL;
}
if (hdr)
{
dsk.meta_disk->free_iomem(hdr);
hdr = NULL;
}
free(data);
free(hdr);
if (buffer_area)
{
dsk.journal_disk->free_iomem(buffer_area);
free(buffer_area);
buffer_area = NULL;
}
if (do_open)
{
if (dsk.journal_disk && dsk.journal_disk != dsk.meta_disk)
delete dsk.journal_disk;
if (dsk.meta_disk)
delete dsk.meta_disk;
dsk.meta_disk = NULL;
dsk.journal_disk = NULL;
close(dsk.meta_fd);
dsk.meta_fd = -1;
if (dsk.journal_fd >= 0)
{
if (dsk.journal_fd != dsk.meta_fd)
close(dsk.journal_fd);
dsk.journal_fd = -1;
}
}
return r;
}
@@ -551,7 +520,7 @@ int disk_tool_t::write_json_meta(json11::Json meta)
{
return write_json_heap(meta, meta["journal"]);
}
new_meta_buf = (uint8_t*)dsk.meta_disk->alloc_iomem(new_meta_len);
new_meta_buf = (uint8_t*)memalign_or_die(MEM_ALIGNMENT, new_meta_len);
memset(new_meta_buf, 0, new_meta_len);
blockstore_meta_header_v2_t *new_hdr = (blockstore_meta_header_v2_t *)new_meta_buf;
new_hdr->zero = 0;
@@ -589,7 +558,7 @@ int disk_tool_t::write_json_meta(json11::Json meta)
uint64_t mb = 1 + data_block/new_entries_per_block;
if (mb >= new_meta_len/new_hdr->meta_block_size)
{
dsk.meta_disk->free_iomem(new_meta_buf);
free(new_meta_buf);
new_meta_buf = NULL;
fprintf(stderr, "Metadata (data block %ju) doesn't fit into the new area\n", data_block);
return 1;
@@ -623,7 +592,7 @@ int disk_tool_t::write_json_meta(json11::Json meta)
int disk_tool_t::write_json_heap(json11::Json meta, json11::Json journal)
{
assert(new_meta_len >= sizeof(blockstore_meta_header_v3_t));
new_meta_buf = (uint8_t*)dsk.meta_disk->alloc_iomem(new_meta_len);
new_meta_buf = (uint8_t*)memalign_or_die(MEM_ALIGNMENT, new_meta_len);
memset(new_meta_buf, 0, new_meta_len);
new_meta_hdr = (blockstore_meta_header_v3_t *)new_meta_buf;
new_meta_hdr->zero = 0;
@@ -658,7 +627,7 @@ int disk_tool_t::write_json_heap(json11::Json meta, json11::Json journal)
new_journal_buf = NULL;
if (new_journal_len)
{
new_journal_buf = (uint8_t*)dsk.journal_disk->alloc_iomem(new_journal_len);
new_journal_buf = (uint8_t*)memalign(MEM_ALIGNMENT, new_journal_len);
memset(new_journal_buf, 0, new_journal_len);
}
uint64_t total_used_space = 0;
@@ -715,7 +684,8 @@ int disk_tool_t::write_json_heap(json11::Json meta, json11::Json journal)
fprintf(stderr, "Write entry %s has invalid type: %s, aborting\n",
write_entry.dump().c_str(), write_entry["type"].dump().c_str());
close_err0:
free_new_meta();
free(new_meta_buf);
new_meta_buf = NULL;
return 1;
}
uint64_t wr_offset = write_entry["offset"].uint64_value();
@@ -802,7 +772,8 @@ close_err0:
{
fprintf(stderr, "Metadata should include journal in you want to convert it to the \"heap\" format\n");
close_err:
free_new_meta();
free(new_meta_buf);
new_meta_buf = NULL;
return 1;
}
std::map<object_id, std::vector<json11::Json::object>> journal_by_object;

View File

@@ -1,158 +0,0 @@
// Copyright (c) Vitaliy Filippov, 2019+
// License: VNPL-1.1 (see README.md for details)
#ifdef WITH_VFN
#include "disk_tool.h"
#include "str_util.h"
#include "json_util.h"
#include "disk_util.h"
#include "malloc_or_die.h"
#define NVME_CLASS 0x010800
#define NVME_CLASS_MASK 0xffff00
const char *oncs_bit_names[] = {
"compare",
"write uncorrectable",
"dsm (deallocate)",
"write zeroes",
"save features",
"reservations",
"timestamp",
"verify",
"copy",
"copies are atomic",
"copies are fast",
"write zeroes with deallocate",
"namespaces zeroes"
};
bool bind_to_vfio(const std::string & dev)
{
int r;
if (access("/sys/bus/pci/drivers/vfio-pci", F_OK) != 0 && errno == ENOENT)
{
r = system("modprobe vfio-pci");
if (r != 0)
{
fprintf(stderr, "Failed to load vfio-pci kernel module: %s (code %u)\n", strerror(errno), errno);
return false;
}
}
r = write_file("/sys/bus/pci/drivers/vfio-pci/bind", dev);
if (r == -ENODEV)
{
auto vid = str_replace(trim(read_file("/sys/bus/pci/devices/"+dev+"/vendor")), "0x", "");
auto pid = str_replace(trim(read_file("/sys/bus/pci/devices/"+dev+"/device")), "0x", "");
r = write_file("/sys/bus/pci/drivers/vfio-pci/new_id", vid+" "+pid);
if (r != 0)
{
fprintf(stderr, "Failed to register VID:PID %s:%s in vfio-pci: %s (code %u)\n",
vid.c_str(), pid.c_str(), strerror(-r), -r);
return false;
}
r = write_file("/sys/bus/pci/drivers/vfio-pci/bind", dev);
}
if (r != 0)
{
fprintf(stderr, "Failed to bind %s to vfio-pci driver: %s (code %u)\n",
dev.c_str(), strerror(-r), -r);
return false;
}
return true;
}
std::string disk_tool_t::find_pci_id(const std::string & nvme_serial, uint32_t nvme_nsid)
{
auto dev = vfn_disk_i::find_pci_id(nvme_serial, nvme_nsid);
if (dev == "")
{
return dev;
}
std::unique_ptr<vfn_disk_i> dsk(vfn_disk_i::create());
if (!dsk->open_dev(dev))
{
continue;
}
const nvme_id_ctrl* id_ctrl = dsk->get_id_ctrl();
std::string serial = trim(std::string(id_ctrl->sn, 20));
fprintf(stderr, "NVMe device %s found - PCI ID %s\n", serial.c_str(), dev.c_str());
// Interesting fields: mdts, tnvmcap, nn, vwc, awupf, sgls, msdbd, cap.cmbs, hmpre, hmmin, oncs
fprintf(stderr, "Maximum transfer size: %ju bytes\n", dsk->get_mdts());
fprintf(stderr, "Total capacity: %ju bytes\n", *(uint64_t*)id_ctrl->tnvmcap);
fprintf(stderr, "Max number of namespaces: %u\n", id_ctrl->nn);
fprintf(stderr, "Volatile cache: %s\n", (id_ctrl->vwc & NVME_CTRL_VWC_PRESENT) ? "yes" : "no");
fprintf(stderr, "Atomic write unit power fail: %u blocks (probably 4k)\n", id_ctrl->awupf+1);
fprintf(stderr, "SGL support: %s",
(id_ctrl->sgls & NVME_CTRL_SGLS_SUPPORTED) == 1 ? "unaligned" :
((id_ctrl->sgls & NVME_CTRL_SGLS_SUPPORTED) == 2 ? "8 byte aligned" : "no support"));
if (id_ctrl->sgls & NVME_CTRL_SGLS_KEYED)
fprintf(stderr, ", keyed (RDMA)");
if (id_ctrl->sgls & NVME_CTRL_SGLS_BIT_BUCKET)
fprintf(stderr, ", bit bucket");
if (id_ctrl->sgls & NVME_CTRL_SGLS_MPTR_BYTE_ALIGNED)
fprintf(stderr, ", byte-aligned mptr");
if (id_ctrl->sgls & NVME_CTRL_SGLS_OVERSIZE)
fprintf(stderr, ", oversized");
if (id_ctrl->sgls & NVME_CTRL_SGLS_MPTR_SGL)
fprintf(stderr, ", SGL mptr");
if (id_ctrl->sgls & NVME_CTRL_SGLS_OFFSET)
fprintf(stderr, ", offset");
if (id_ctrl->sgls & NVME_CTRL_SGLS_TPORT)
fprintf(stderr, ", transport data block");
fprintf(stderr, "\nMax SGL data block descriptors: %u\n", id_ctrl->msdbd);
fprintf(stderr, "Optional command support:");
int oncs_n = 0;
for (int i = 0; i < sizeof(oncs_bit_names)/sizeof(oncs_bit_names[0]); i++)
{
if ((id_ctrl->oncs >> i) & 1)
fprintf(stderr, "%s%s", oncs_n++ > 0 ? ", " : " ", oncs_bit_names[i]);
}
fprintf(stderr, "%s\n", oncs_n > 0 ? "" : "none");
fprintf(stderr, "CMB: %s\n", NVME_CAP_CMBS(dsk->get_cap()) ? "supported" : "not supported");
fprintf(stderr, "HMB: min %u bytes, preferred %u bytes\n", id_ctrl->hmmin*4096, id_ctrl->hmpre*4096);
if (nvme_nsid > 0)
{
if (!dsk->open_ns(nvme_nsid))
{
return "";
}
// Interesting fields: nsze, nsfeat (bit 3 - nguid, bit 1 - nawupf), nlbaf,
// flbas, mc (bit 1 - OK, bit 0 - not OK), nawupf, nabspf, nabo, nguid, lbaf0-lbaf15
const nvme_id_ns *id_ns = dsk->get_id_ns();
uint8_t fmt = NVME_FLBAS_LOWER(id_ns->flbas);
uint64_t blksize = 1 << id_ns->lbaf[fmt].ds;
uint64_t ms = id_ns->lbaf[fmt].ms;
fprintf(stderr, "Namespace size: %ju bytes\n", (uint64_t)id_ns->nsze * blksize);
fprintf(stderr, "Format %u/%u: %ju byte sectors + %ju byte metadata\n", id_ns->flbas, id_ns->nlbaf+1, blksize, ms);
if (id_ns->nsfeat & NVME_NS_FEAT_ID_REUSE)
{
fprintf(stderr, "Namespace GUID: ");
for (int i = 0; i < sizeof(id_ns->nguid); i++)
fprintf(stderr, "%02x", id_ns->nguid[i]);
fprintf(stderr, "\n");
}
if (id_ns->nsfeat & NVME_NS_FEAT_NATOMIC)
{
fprintf(stderr, "Namespace atomic write unit power fail: %u blocks\n", id_ns->nawupf+1);
fprintf(stderr, "Namespace atomic boundary power fail: %u blocks\n", id_ns->nabspf);
fprintf(stderr, "Namespace atomic boundary offset: %u blocks\n", id_ns->nabo);
}
}
return dev;
}
#else
#include "disk_tool.h"
#include <string>
std::string disk_tool_t::find_pci_id(const std::string & nvme_serial, uint32_t nvme_nsid)
{
fprintf(stderr, "Vitastor is built without userspace NVMe (libvfn) support\n");
exit(1);
return "";
}
#endif

View File

@@ -4,7 +4,6 @@
#include "disk_tool.h"
#include "str_util.h"
#include "json_util.h"
#include "malloc_or_die.h"
void disk_tool_t::parse_meta_reserve()
{
@@ -273,24 +272,10 @@ int disk_tool_t::prepare_one(std::map<std::string, std::string> options, int is_
}
}
// Zero out the first block of metadata and journal - OSD will zero the rest on the first run
int rz = 0;
if (dsk.meta_disk)
if (write_zero(dsk.meta_fd, sb["meta_offset"].uint64_value(), 4096) != 0 ||
write_zero(dsk.journal_fd, sb["journal_offset"].uint64_value(), 4096) != 0)
{
void *zero_buf = dsk.meta_disk->alloc_iomem(4096);
memset(zero_buf, 0, 4096);
rz = dsk.meta_disk->write_sync(sb["meta_offset"].uint64_value(), 4096, zero_buf);
dsk.meta_disk->free_iomem(zero_buf);
}
if (!rz && dsk.journal_disk)
{
void *zero_buf = dsk.journal_disk->alloc_iomem(4096);
memset(zero_buf, 0, 4096);
rz = dsk.journal_disk->write_sync(sb["journal_offset"].uint64_value(), 4096, zero_buf);
dsk.journal_disk->free_iomem(zero_buf);
}
if (rz != 0)
{
fprintf(stderr, "Failed to zero out metadata or journal header: %s (code %d)\n", strerror(-rz), -rz);
fprintf(stderr, "Failed to zero out metadata or journal: %s\n", strerror(errno));
dsk.close_all();
return 1;
}

View File

@@ -303,17 +303,16 @@ int disk_tool_t::resize_copy_data()
iodepth = 32;
}
ringloop = new ring_loop_t(iodepth < RINGLOOP_DEFAULT_SIZE ? RINGLOOP_DEFAULT_SIZE : iodepth);
dsk.data_disk = disk_i::create_and_open(dsk.data_device, (options["io"] == "cached" ? "cached" : ""), true);
if (!dsk.data_disk)
dsk.data_fd = open(dsk.data_device.c_str(), (options["io"] == "cached" ? 0 : O_DIRECT) | O_RDWR);
if (dsk.data_fd < 0)
{
fprintf(stderr, "Failed to open data device %s\n", dsk.data_device.c_str());
fprintf(stderr, "Failed to open data device %s: %s\n", dsk.data_device.c_str(), strerror(errno));
delete ringloop;
ringloop = NULL;
return 1;
}
dsk.data_disk->set_ringloop(ringloop);
moving_blocks = new resizer_data_moving_t[iodepth];
moving_blocks[0].buf = dsk.data_disk->alloc_iomem(iodepth*dsk.data_block_size);
moving_blocks[0].buf = memalign_or_die(MEM_ALIGNMENT, iodepth*dsk.data_block_size);
for (int i = 1; i < iodepth; i++)
{
moving_blocks[i].buf = (uint8_t*)moving_blocks[0].buf + i*dsk.data_block_size;
@@ -335,76 +334,52 @@ int disk_tool_t::resize_copy_data()
}
if (moving_blocks[i].state == DM_ST_TO_READ)
{
int res = dsk.data_disk->read_async(
dsk.data_offset + moving_blocks[i].old_loc*dsk.data_block_size,
dsk.data_block_size, moving_blocks[i].buf, [this, i](int res)
struct io_uring_sqe *sqe = ringloop->get_sqe();
if (sqe)
{
moving_blocks[i].state = DM_ST_READING;
struct ring_data_t *data = ((ring_data_t*)sqe->user_data);
data->iov = (struct iovec){ moving_blocks[i].buf, dsk.data_block_size };
io_uring_prep_readv(sqe, dsk.data_fd, &data->iov, 1, dsk.data_offset + moving_blocks[i].old_loc*dsk.data_block_size);
data->callback = [this, i](ring_data_t *data)
{
if (res != 0)
if (data->res != dsk.data_block_size)
{
fprintf(
stderr, "Failed to read %ju bytes at %ju from %s: %s\n", dsk.data_block_size,
dsk.data_offset + moving_blocks[i].old_loc*dsk.data_block_size, dsk.data_device.c_str(),
strerror(-res)
data->res < 0 ? strerror(-data->res) : "short read"
);
exit(1);
}
moving_blocks[i].state = DM_ST_TO_WRITE;
ringloop->wakeup();
}
);
if (res == 0)
{
moving_blocks[i].state = DM_ST_READING;
}
else if (res == -EAGAIN)
{
break;
}
else
{
fprintf(
stderr, "Failed to submit read of %ju bytes at %ju from %s: %s\n", dsk.data_block_size,
dsk.data_offset + moving_blocks[i].old_loc*dsk.data_block_size, dsk.data_device.c_str(),
strerror(-res)
);
exit(1);
}
};
}
}
if (moving_blocks[i].state == DM_ST_TO_WRITE)
{
int res = dsk.data_disk->write_async(
dsk.data_offset + moving_blocks[i].new_loc*dsk.data_block_size,
dsk.data_block_size, moving_blocks[i].buf, [this, i](int res)
struct io_uring_sqe *sqe = ringloop->get_sqe();
if (sqe)
{
moving_blocks[i].state = DM_ST_WRITING;
struct ring_data_t *data = ((ring_data_t*)sqe->user_data);
data->iov = (struct iovec){ moving_blocks[i].buf, dsk.data_block_size };
io_uring_prep_writev(sqe, dsk.data_fd, &data->iov, 1, dsk.data_offset + moving_blocks[i].new_loc*dsk.data_block_size);
data->callback = [this, i](ring_data_t *data)
{
if (res != 0)
if (data->res != dsk.data_block_size)
{
fprintf(
stderr, "Failed to write %ju bytes at %ju to %s: %s\n", dsk.data_block_size,
dsk.data_offset + moving_blocks[i].new_loc*dsk.data_block_size, dsk.data_device.c_str(),
strerror(-res)
data->res < 0 ? strerror(-data->res) : "short write"
);
exit(1);
}
moving_blocks[i].state = DM_ST_EMPTY;
ringloop->wakeup();
}
);
if (res == 0)
{
moving_blocks[i].state = DM_ST_WRITING;
}
else if (res == -EAGAIN)
{
break;
}
else
{
fprintf(
stderr, "Failed to submit write of %ju bytes at %ju to %s: %s\n", dsk.data_block_size,
dsk.data_offset + moving_blocks[i].new_loc*dsk.data_block_size, dsk.data_device.c_str(),
strerror(-res)
);
exit(1);
};
}
}
remap_active += moving_blocks[i].state != DM_ST_EMPTY ? 1 : 0;
@@ -420,11 +395,11 @@ int disk_tool_t::resize_copy_data()
ringloop->wait();
}
ringloop->unregister_consumer(&ring_consumer);
dsk.data_disk->free_iomem(moving_blocks[0].buf);
free(moving_blocks[0].buf);
delete[] moving_blocks;
moving_blocks = NULL;
delete dsk.data_disk;
dsk.data_disk = NULL;
close(dsk.data_fd);
dsk.data_fd = -1;
delete ringloop;
ringloop = NULL;
return 0;
@@ -432,7 +407,7 @@ int disk_tool_t::resize_copy_data()
void disk_tool_t::resize_alloc_journal()
{
new_journal_buf = (uint8_t*)dsk.journal_disk->alloc_iomem(new_journal_len);
new_journal_buf = (uint8_t*)memalign_or_die(MEM_ALIGNMENT, new_journal_len);
memset(new_journal_buf, 0, new_journal_len);
new_journal_ptr = new_journal_buf;
new_journal_data = new_journal_ptr + dsk.journal_block_size;
@@ -537,24 +512,17 @@ int disk_tool_t::resize_rebuild_journal()
int disk_tool_t::resize_write_new_journal()
{
new_journal_disk = disk_i::create_and_open(new_journal_device, (options["io"] == "cached" ? "cached" : ""), true);
if (!new_journal_disk)
new_journal_fd = open(new_journal_device.c_str(), (options["io"] == "cached" ? 0 : O_DIRECT) | O_RDWR);
if (new_journal_fd < 0)
{
fprintf(stderr, "Failed to open new journal device %s\n", new_journal_device.c_str());
fprintf(stderr, "Failed to open new journal device %s: %s\n", new_journal_device.c_str(), strerror(errno));
return 1;
}
int r = new_journal_disk->write_sync(new_journal_offset, new_journal_len, new_journal_buf);
if (r == 0)
{
r = new_journal_disk->flush_sync();
}
if (r != 0)
{
fprintf(stderr, "Failed to write new journal to %s: %s (code %d)\n", new_journal_device.c_str(), strerror(-r), -r);
}
delete new_journal_disk;
new_journal_disk = NULL;
return r;
pwrite_blocking(new_journal_fd, new_journal_buf, new_journal_len, new_journal_offset);
fsync(new_journal_fd);
close(new_journal_fd);
new_journal_fd = -1;
return 0;
}
void disk_tool_t::remap_big_write(blockstore_heap_t *heap, heap_entry_t *wr)
@@ -591,7 +559,7 @@ void disk_tool_t::remap_small_write(blockstore_heap_t *heap, heap_entry_t *wr)
int disk_tool_t::resize_rebuild_meta()
{
new_meta_buf = (uint8_t*)dsk.meta_disk->alloc_iomem(new_meta_len);
new_meta_buf = (uint8_t*)memalign_or_die(MEM_ALIGNMENT, new_meta_len);
memset(new_meta_buf, 0, new_meta_len);
new_meta_hdr = (blockstore_meta_header_v3_t *)new_meta_buf;
uint64_t new_meta_pos = dsk.meta_block_size;
@@ -723,41 +691,34 @@ int disk_tool_t::resize_rebuild_meta()
int disk_tool_t::resize_write_new_meta()
{
new_meta_disk = disk_i::create_and_open(new_meta_device, (options["io"] == "cached" ? "cached" : ""), true);
if (!new_meta_disk)
new_meta_fd = open(new_meta_device.c_str(), (options["io"] == "cached" ? 0 : O_DIRECT) | O_RDWR);
if (new_meta_fd < 0)
{
fprintf(stderr, "Failed to open new metadata device %s\n", new_meta_device.c_str());
fprintf(stderr, "Failed to open new metadata device %s: %s\n", new_meta_device.c_str(), strerror(errno));
return 1;
}
int r = new_meta_disk->write_sync(new_meta_offset, new_meta_len, new_meta_buf);
if (r == 0)
{
r = new_meta_disk->flush_sync();
}
if (r != 0)
{
fprintf(stderr, "Failed to write new metadata to %s: %s (code %d)\n", new_meta_device.c_str(), strerror(-r), -r);
}
delete new_meta_disk;
new_meta_disk = NULL;
return r;
pwrite_blocking(new_meta_fd, new_meta_buf, new_meta_len, new_meta_offset);
fsync(new_meta_fd);
close(new_meta_fd);
new_meta_fd = -1;
return 0;
}
void disk_tool_t::free_new_meta()
{
if ((uint8_t*)new_meta_hdr != new_meta_buf)
{
dsk.meta_disk->free_iomem(new_meta_hdr);
free(new_meta_hdr);
new_meta_hdr = NULL;
}
if (new_meta_buf)
{
dsk.meta_disk->free_iomem(new_meta_buf);
free(new_meta_buf);
new_meta_buf = NULL;
}
if (new_journal_buf)
{
dsk.journal_disk->free_iomem(new_journal_buf);
free(new_journal_buf);
new_journal_buf = NULL;
}
}

View File

@@ -37,6 +37,8 @@ int disk_tool_t::resize_data(std::string device)
fprintf(stderr, "%s\n", e.what());
return 1;
}
// Save FD numbers because calc_lengths() relies on them
int old_journal_fd = dsk.journal_fd, old_meta_fd = dsk.meta_fd, old_data_fd = dsk.data_fd;
dsk.close_all();
bool dry_run = options.find("dry_run") != options.end();
auto old_journal_device = dsk.journal_device;
@@ -56,7 +58,13 @@ int disk_tool_t::resize_data(std::string device)
? dsk.data_device_size : new_data_dev_size;
dsk.data_device_size = new_data_dev_size;
dsk.cfg_data_size = 0;
dsk.journal_fd = old_journal_fd;
dsk.meta_fd = old_meta_fd;
dsk.data_fd = old_data_fd;
dsk.calc_lengths(true);
dsk.journal_fd = -1;
dsk.meta_fd = -1;
dsk.data_fd = -1;
}
std::map<std::string, std::string> move_options;
if (options.find("move_journal") != options.end())

View File

@@ -155,16 +155,15 @@ json11::Json disk_tool_t::read_osd_superblock(std::string device, bool expect_ex
json11::Json osd_params;
std::string json_err;
std::string real_device, device_type, real_data, real_meta, real_journal;
int r = 0;
auto di = disk_i::create_and_open(device, (options["io"] == "cached" ? "cached,ro" : "ro"), true);
if (!di)
int r, fd = open(device.c_str(), (options["io"] == "cached" ? 0 : O_DIRECT) | O_RDWR);
if (fd < 0)
{
fprintf(stderr, "Failed to open device %s\n", device.c_str());
fprintf(stderr, "Failed to open device %s: %s\n", device.c_str(), strerror(errno));
return osd_params;
}
buf = (uint8_t*)di->alloc_iomem(4096);
r = di->read_sync(0, 4096, buf);
if (r != 0)
buf = (uint8_t*)memalign_or_die(MEM_ALIGNMENT, 4096);
r = pread_blocking(fd, buf, 4096, 0);
if (r != 4096)
{
fprintf(stderr, "Failed to read OSD superblock from %s: %s\n", device.c_str(), strerror(errno));
goto ex;
@@ -187,10 +186,10 @@ json11::Json disk_tool_t::read_osd_superblock(std::string device, bool expect_ex
if (sb->size > 4096)
{
uint64_t sb_size = ((sb->size+4095)/4096)*4096;
di->free_iomem(buf);
buf = (uint8_t*)di->alloc_iomem(sb_size);
r = di->read_sync(0, sb_size, buf);
if (r != 0)
free(buf);
buf = (uint8_t*)memalign_or_die(MEM_ALIGNMENT, sb_size);
r = pread_blocking(fd, buf, sb_size, 0);
if (r != sb_size)
{
fprintf(stderr, "Failed to read OSD superblock from %s: %s\n", device.c_str(), strerror(errno));
goto ex;
@@ -225,12 +224,12 @@ json11::Json disk_tool_t::read_osd_superblock(std::string device, bool expect_ex
osd_params = json11::Json();
goto ex;
}
real_device = disk_i::realpath(device);
real_data = disk_i::realpath(osd_params["data_device"].string_value());
real_device = realpath_str(device);
real_data = realpath_str(osd_params["data_device"].string_value());
real_meta = osd_params["meta_device"].string_value() != "" && osd_params["meta_device"] != osd_params["data_device"]
? disk_i::realpath(osd_params["meta_device"].string_value()) : "";
? realpath_str(osd_params["meta_device"].string_value()) : "";
real_journal = osd_params["journal_device"].string_value() != "" && osd_params["journal_device"] != osd_params["meta_device"]
? disk_i::realpath(osd_params["journal_device"].string_value()) : "";
? realpath_str(osd_params["journal_device"].string_value()) : "";
if (real_journal == real_meta)
{
real_journal = "";
@@ -266,12 +265,8 @@ json11::Json disk_tool_t::read_osd_superblock(std::string device, bool expect_ex
{ "real_journal_device", real_journal },
};
ex:
if (buf)
{
di->free_iomem(buf);
buf = NULL;
}
delete di;
free(buf);
close(fd);
return osd_params;
}

View File

@@ -3,6 +3,7 @@
#include <sys/wait.h>
#include <sys/ioctl.h>
#include <dirent.h>
#include "disk_tool.h"
#include "rw_blocking.h"
@@ -233,6 +234,30 @@ err_pipe1:
return 255;
}
int write_zero(int fd, uint64_t offset, uint64_t size)
{
uint64_t buf_len = 1024*1024;
void *zero_buf = memalign_or_die(MEM_ALIGNMENT, buf_len);
memset(zero_buf, 0, buf_len);
ssize_t r;
while (size > 0)
{
r = pwrite(fd, zero_buf, size > buf_len ? buf_len : size, offset);
if (r > 0)
{
size -= r;
offset += r;
}
else if (errno != EAGAIN && errno != EINTR)
{
free(zero_buf);
return -1;
}
}
free(zero_buf);
return 0;
}
// Returns false in case of an error
// Returns null if there is no partition table
json11::Json read_parttable(std::string dev)

View File

@@ -19,27 +19,20 @@ add_library(util STATIC
../../json11/json11.cpp
xxh_x86dispatch.c
)
if (RDMACM_LIBRARIES OR (VFN_LIBRARIES AND NVME_LIBRARIES))
if (RDMACM_LIBRARIES)
target_sources(util PRIVATE
dma_alloc_impl.cpp
)
endif (RDMACM_LIBRARIES OR (VFN_LIBRARIES AND NVME_LIBRARIES))
endif (RDMACM_LIBRARIES)
if (RDMACM_LIBRARIES)
target_sources(util PRIVATE
rdma_alloc.cpp
)
endif (RDMACM_LIBRARIES)
if (VFN_LIBRARIES AND NVME_LIBRARIES)
target_sources(util PRIVATE
vfn_alloc.cpp
)
endif (VFN_LIBRARIES AND NVME_LIBRARIES)
target_compile_options(util PUBLIC -fPIC)
target_link_libraries(util
${LIBURING_LIBRARIES}
${OPENSSL_LIBRARIES}
${VFN_LIBRARIES}
${NVME_LIBRARIES}
)
# libcrc32c.a to isolate the isa-l dependency

File diff suppressed because it is too large Load Diff

View File

@@ -4,76 +4,6 @@
#pragma once
#include <string>
#include <map>
#include <functional>
#include <stdint.h>
#include <time.h>
#ifdef WITH_VFN
#include <nvme/types.h>
#endif
class ring_loop_i;
class disk_i
{
public:
static disk_i *create_and_open(const std::string & path, const std::string & mode, bool disable_flock = false);
static disk_i *create_mock(int mock_fd, uint64_t mock_size, uint64_t mock_sectsize);
static std::string realpath(const std::string & path);
virtual ~disk_i() = default;
virtual void set_ringloop(ring_loop_i *ringloop) = 0;
virtual bool is_off_ring() const = 0;
virtual int get_fd() const = 0;
virtual void close() = 0;
virtual uint64_t get_size() const = 0;
virtual uint64_t get_block_size() const = 0;
virtual uint64_t get_max_io_size() const = 0;
virtual void *alloc_iomem(size_t size) = 0;
virtual void free_iomem(void *buf) = 0;
virtual uint32_t get_queue_space() const = 0;
// all errors are passed as negative errno's
virtual int rw_sync(bool is_wr, uint64_t offset, size_t len, void *buf) = 0;
virtual int flush_sync() = 0;
virtual int discard_sync(uint64_t offset, uint64_t len) = 0;
virtual int rw_async(bool is_wr, uint64_t offset, size_t len, void *buf, bool fua, std::function<void(int res)> cb) = 0;
virtual int flush_async(std::function<void(int res)> cb) = 0;
virtual int discard_async(uint64_t offset, uint64_t len, std::function<void(int res)> cb) = 0;
inline int read_sync(uint64_t offset, size_t len, void *buf)
{
return rw_sync(false, offset, len, buf);
}
inline int write_sync(uint64_t offset, size_t len, void *buf)
{
return rw_sync(true, offset, len, buf);
}
inline int read_async(uint64_t offset, size_t len, void *buf, std::function<void(int res)> cb)
{
return rw_async(false, offset, len, buf, false, cb);
}
inline int write_async(uint64_t offset, size_t len, void *buf, std::function<void(int res)> cb, bool fua = false)
{
return rw_async(true, offset, len, buf, fua, cb);
}
};
void check_size(int fd, uint64_t *size, uint64_t *sectsize, const std::string & name);
#ifdef WITH_VFN
class vfn_disk_i: public disk_i
{
public:
static vfn_disk_i *create();
virtual ~vfn_disk_i() = default;
virtual bool open_dev(const std::string & pci_id) = 0;
virtual bool open_ns(uint32_t ns_num) = 0;
virtual const nvme_id_ctrl* get_id_ctrl() const = 0;
virtual const nvme_id_ns* get_id_ns() const = 0;
virtual uint64_t get_mdts() const = 0;
virtual uint64_t get_cap() const = 0;
static bool is_vfn_path(const std::string & path);
static bool bind_to_vfio(const std::string & dev);
static std::string find_pci_id(const std::string & nvme_serial, uint32_t nvme_nsid);
};
#endif

View File

@@ -52,8 +52,6 @@ void ring_loop_t::register_consumer(ring_consumer_t *consumer)
{
unregister_consumer(consumer);
consumers.push_back(consumer);
if (consumer->is_idle)
idle_consumers++;
}
void ring_loop_t::wakeup()
@@ -67,8 +65,6 @@ void ring_loop_t::unregister_consumer(ring_consumer_t *consumer)
{
if (consumers[i] == consumer)
{
if (consumer->is_idle)
idle_consumers--;
consumers.erase(consumers.begin()+i, consumers.begin()+i+1);
break;
}
@@ -158,30 +154,10 @@ void ring_loop_t::loop()
}
do
{
do
loop_again = false;
for (int i = 0; i < consumers.size(); i++)
{
loop_again = false;
for (int i = 0; i < consumers.size(); i++)
{
if (!consumers[i]->is_idle)
consumers[i]->loop();
}
if (immediate_queue.size())
{
immediate_queue2.swap(immediate_queue);
for (auto & cb: immediate_queue2)
cb();
immediate_queue2.clear();
}
} while (loop_again);
if (idle_consumers > 0)
{
// idle consumers are those who poll devices when everything is idle
for (int i = 0; i < consumers.size(); i++)
{
if (consumers[i]->is_idle)
consumers[i]->loop();
}
consumers[i]->loop();
if (immediate_queue.size())
{
immediate_queue2.swap(immediate_queue);

View File

@@ -32,7 +32,6 @@ struct ring_data_t
struct ring_consumer_t
{
std::function<void(void)> loop;
bool is_idle = false;
};
class __attribute__((visibility("default"))) ring_loop_i
@@ -61,7 +60,6 @@ class __attribute__((visibility("default"))) ring_loop_t: public ring_loop_i
std::vector<ring_consumer_t*> consumers;
std::vector<ring_data_t> ring_datas;
std::vector<int> free_ring_data;
int idle_consumers = 0;
std::mutex mu;
bool mt;
bool in_loop;

View File

@@ -1,56 +0,0 @@
// Copyright (c) Vitaliy Filippov, 2019+
// License: VNPL-1.1 (see README.md for details)
//
// libvfn (IOMMU) variant of our simple allocator
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <vfn/iommu.h>
#include "dma_alloc_impl.h"
static_assert(sizeof(iova_t) == sizeof(void*));
class vfn_allocator_t: public dma_allocator_t
{
protected:
iommu_ctx *ctx = NULL;
void* reg_mr(void *buf, size_t len) override
{
iova_t iova = 0;
if (iommu_map_vaddr(ctx, buf, len, &iova, 0))
{
fprintf(stderr, "iommu_map_vaddr %zu bytes failed: %s\n", len, strerror(errno));
exit(1);
}
return (void*)iova;
}
void dereg_mr(void *buf, size_t len, void *handle) override
{
if (iommu_unmap_vaddr(ctx, buf, &len))
{
fprintf(stderr, "iommu_unmap_vaddr failed: %s\n", strerror(errno));
exit(1);
}
}
public:
vfn_allocator_t(iommu_ctx *ctx, size_t region_size, size_t max_unused)
: dma_allocator_t(region_size, max_unused, 1), ctx(ctx)
{
alignment = page_size;
}
~vfn_allocator_t()
{
free_unused_buffers(0, true);
}
};
dma_allocator_i *vfn_malloc_create(iommu_ctx *ctx, size_t region_size, size_t max_unused)
{
return new vfn_allocator_t(ctx, region_size, max_unused);
}

View File

@@ -1,11 +0,0 @@
// Copyright (c) Vitaliy Filippov, 2019+
// License: VNPL-1.1 (see README.md for details)
//
// libvfn (IOMMU) variant of our simple allocator
#pragma once
#include "rdma_alloc.h"
struct iommu_ctx;
dma_allocator_i *vfn_malloc_create(iommu_ctx *ctx, size_t rdma_alloc_size, size_t rdma_max_unused);