Compare commits

...

40 Commits

Author SHA1 Message Date
5dec46c82e Release 3.0.16
New store:

- Finally fix the source of 'double-claim' errors worked around in 3.0.12 - delete
  entry removal on restart possibly happening before the removal of the masked big_write
- Fix padded checksum (csum_block_size > 4k) verification during some partial reads
- Fix truncated unstable object list responses in limited listing requests (sent by scrub)
- OSD should now stop with an error on data fsync error during batched big_writes, like
  on other disk errors
- Add missing disable_meta_fsync check for enabling immediate_commit

Client:

- Fix CAS writes skipping their built-in fsync (for pools without immediate_commit)
- Validate show_config, sec_list and sec_read_bmp reply sizes
- Fix show_config reply parsed as a null terminated string without taking length into account

Old store:

- Skip too small (corrupted) journal entries

OSD:

- Forbid pools with block_size*pg_size larger than UINT32_MAX
- Do not forcibly report OSD statistics after reporting PG states (should reduce etcd load)
- Prevent repeated reporting of PG epoch bump on multiple writes possibly leading
  to spurious PG state reporting errors, extra PG repeers and increased etcd load
- Fix handling of PGs with pg_size between 32 and 64 (more than 64 is forbidden)
- Add safety checks for ENOENT (missing objects) during read/write operations
- Abort primary writes with a retriable error code when the PG becomes inactive during write
  instead of trying to finish it cleanly
- Fix sync operation correctness and add tests to verify it:
  - Drop dirty PG connections when repeering PG before waiting for actual peering, like in stop
  - Complete sync with an error if PGs dirtied by the client become inactive
  - Skip inactive PGs during sync (double-check). Without this fix and write error handling
    changes inflight operation counter could be incremented on offline PGs and lead to use-after-free
  - Drop client's connection instead of returning SYNC error
- Several scrub fixes:
  - Check bitmaps when grouping identical EC chunks in scrub
  - Fix scrub possibly trying too many combinations in EC pools with large k+n
  - Fix reads from degraded objects marked as inconsistent after scrub not taking
    actual object state into account and possibly returning zeros
  - Fix incorrect array indexing in scrub (possibly affecting scrub results)
2026-07-19 11:09:25 +03:00
14aa842201 Fix short memmove unstable_count in the new store 2026-07-18 19:33:33 +03:00
4974c213fe Add missing abort on data fsync error 2026-07-18 15:10:20 +03:00
dff723b2a2 Check bitmaps when grouping identical EC chunks in scrub 2026-07-18 15:06:46 +03:00
931f753c85 Skip too small (corrupted) journal v1 entries 2026-07-18 15:04:28 +03:00
d978df1274 Reset "isset" on each checksum block
Doesn't really affect anything, "isset" could be removed at all, the only case
it may affect is when something updates the checksum for a hole inside bitmap
and sets it to a value different from 0. Which doesn't happen in practice...
2026-07-18 14:59:12 +03:00
97abf2e53b Validate block_size*pg_size against UINT32_MAX 2026-07-18 14:12:06 +03:00
539826067e Fix possible overflow in C_n_k O_o :) 2026-07-18 14:12:06 +03:00
c7f2247b97 Fix (allowed for now) inconsistent object reads 2026-07-18 01:34:50 +03:00
12c7810a4a Add a test for scrub marking degraded object inconsistent but not degraded 2026-07-18 01:34:50 +03:00
3c9877003f Test PG epoch reporting 2026-07-18 00:09:51 +03:00
4ff2034423 Do not forcibly update statistics after reporting PG states 2026-07-17 21:33:07 +03:00
79b0ec5d79 Prevent double-reporting of PG epoch bump 2026-07-17 21:33:07 +03:00
13a4f156e2 Remove assert(&ref pg) 2026-07-17 21:33:03 +03:00
9c80737bc6 Do not ignore ENOENT in most situations 2026-07-17 20:42:44 +03:00
622e073ab9 Validate show_config, sec_list and sec_read_bmp reply sizes 2026-07-16 00:42:04 +03:00
5e41c65214 Fix possible early DELETE entry removal on restart 2026-07-15 21:02:11 +03:00
2f46447800 Fix execute_cas skipping fsync 2026-07-15 21:01:48 +03:00
5a856336a8 Fix sync logic + add some sync tests
- Drop dirty PG connections when repeering PG before waiting for actual peering, like in stop
- Complete sync with an error if PGs dirtied by the client become inactive
- Skip inactive PGs during sync (double-check) - could lead to inflight++ on OFFLINE PGs
  before write error handling was changed
- Drop client's connection instead of returning SYNC error
2026-07-12 19:56:46 +03:00
e0ced36aa4 Fix error handling in osd_primary_write, abort writing when PG becomes inactive 2026-07-12 19:56:46 +03:00
781ee54af6 Add handle_abort=1 to ASAN 2026-07-12 19:56:46 +03:00
bb7c11a768 Fix continue next writes messing deletes and writes
Funny that it didn't result in actual bugs because the first step of write
and delete happens to be the same... The bug could be reproduced only in a
complex scenario:
1. delete of the same object enqueued right after write
2. initial read during write failed with EDOM, object marked incomplete
3. then the OSD would refuse to delete the object because continue_primary_write
   rejects partial writes to incomplete objects
2026-07-12 19:56:46 +03:00
8bc6aa8ef3 Remove cancel_primary_write() 2026-07-12 19:56:46 +03:00
b3fecc8bf2 Fix erase from peer_states during iteration 2026-07-12 18:52:24 +03:00
88ff27be60 Fix SHOW_CONFIG reply parsed as a null terminated string without length 2026-07-12 18:52:24 +03:00
4bb0c46380 Add (uint64_t)1 << cast 2026-07-09 01:15:40 +03:00
efe33acf1a Add disable_meta_fsync check to the new store 2026-07-09 01:14:02 +03:00
c77f01984c Fix incorrect indexing in osd_scrub 2026-07-09 01:12:48 +03:00
5dbc679e16 Fix padded block checksums - v2 2026-07-05 14:09:57 +03:00
d48864a6be Fix unaligned pointer warnings 2026-07-04 21:40:29 +03:00
462482d319 Fix zero-padded big_write checksum verification in the new store 2026-07-04 21:37:22 +03:00
5ef9d78461 Release 3.0.15
- QEMU virtual disk migration with enabled iothread is finally fixed correctly.
- Fixed operation of Proxmox VMs with swTPM without enabling NBD for all disks.
- Debian packages are now again built with stable Antietcd released instead of
  the unstable master branch.
- Antietcd cluster mode previously broken in that master branch is fixed. The
  symptom was Antietcd being unable to elect the leader in a cluster.
- Fixed monitor startup with embedded Antietcd when using IPv6.
- Fixed space statistics calculation for FS and S3 pools in the new storage ([PR #127](https://github.com/vitalif/vitastor/pull/127)).
2026-06-28 11:29:38 +03:00
1b20010a69 Install npm packages in debian/rules 2026-06-28 11:29:27 +03:00
d750d00c6f Fix SWTPM in Proxmox 2026-06-27 16:04:51 +03:00
66cb564e2c Fix background jobs in etcd_fail test 2026-06-27 15:42:53 +03:00
f782decbd6 Update antietcd to 1.3.1 2026-06-27 15:42:42 +03:00
717582c4ba Use release builds of antietcd&tinyraft in debian packages (not master branch) 2026-06-27 10:27:15 +03:00
cd62c0755f Fix IPv6 antietcd configuration 2026-06-27 00:16:03 +03:00
zhuchengzhen001-crypto
c6f5ab7d79 fix pool stats with no_inode_stats (#127)
Co-authored-by: zhu.chengzhen <zhu.chengzhen@jingjiamicro.com>
2026-06-24 12:41:56 +03:00
09607ddcbe Actual fix for live migration with iothread 2026-06-23 00:07:34 +03:00
58 changed files with 1831 additions and 370 deletions

View File

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

View File

@@ -1,4 +1,4 @@
VITASTOR_VERSION ?= v3.0.14
VITASTOR_VERSION ?= v3.0.16
all: build push

View File

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

View File

@@ -121,7 +121,7 @@ spec:
privileged: true
capabilities:
add: ["SYS_ADMIN"]
image: vitalif/vitastor-csi:v3.0.14
image: vitalif/vitastor-csi:v3.0.16
args:
- "--node=$(NODE_ID)"
- "--endpoint=$(CSI_ENDPOINT)"

View File

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

2
debian/changelog vendored
View File

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

1
debian/rules vendored
View File

@@ -11,6 +11,7 @@ override_dh_install:
cp -v node-binding/package.json node-binding/index.js node-binding/addon.cc node-binding/addon.h node-binding/client.cc node-binding/client.h debian/tmp/usr/lib/x86_64-linux-gnu/nodejs/vitastor
cp -v node-binding/build/Release/addon.node debian/tmp/usr/lib/x86_64-linux-gnu/nodejs/vitastor/build/Release
dh_install
cd debian/vitastor-mon/usr/lib/vitastor/mon && npm install --production
override_dh_installdeb:
cat debian/fio_version >> debian/vitastor-fio.substvars

View File

@@ -37,12 +37,6 @@ rm -rf a b
echo "dep:fio=$FIO" > debian/fio_version
cd /root/vitastor/packages/vitastor-$REL/vitastor-$VER
mkdir mon/node_modules
cd mon/node_modules
curl -s https://git.yourcmc.ru/vitalif/antietcd/archive/master.tar.gz | tar -zx
curl -s https://git.yourcmc.ru/vitalif/tinyraft/archive/master.tar.gz | tar -zx
cd /root/vitastor/packages/vitastor-$REL
if [[ ( "$REL" = "trixie" || "$REL" = "resolute" ) && -e ../vitastor-bookworm/vitastor_$VER.orig.tar.xz ]]; then
# Fucking shit, archives differ between bookworm (xz 5.4.1) and trixie (xz 5.8.1)

View File

@@ -1,4 +1,4 @@
VITASTOR_VERSION ?= v3.0.14
VITASTOR_VERSION ?= v3.0.16
all: build push

View File

@@ -4,7 +4,7 @@
#
# Desired Vitastor version
VITASTOR_VERSION=v3.0.14
VITASTOR_VERSION=v3.0.16
# 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.0.14`
`docker pull vitalif/vitastor:v3.0.16`
2. Install scripts to the host system: \
`docker run --rm -it -v /etc:/host-etc -v /usr/bin:/host-bin vitalif/vitastor:v3.0.14 install.sh`
`docker run --rm -it -v /etc:/host-etc -v /usr/bin:/host-bin vitalif/vitastor:v3.0.16 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.0.14`
`docker pull vitalif/vitastor:v3.0.16`
2. Установите скрипты в хост-систему командой: \
`docker run --rm -it -v /etc:/host-etc -v /usr/bin:/host-bin vitalif/vitastor:v3.0.14 install.sh`
`docker run --rm -it -v /etc:/host-etc -v /usr/bin:/host-bin vitalif/vitastor:v3.0.16 install.sh`
3. Перезагрузите правила udev: \
`udevadm control --reload-rules`
4. Включите сервис vitastor-host: \

View File

@@ -18,7 +18,7 @@ class AntiEtcdAdapter
cluster = cluster ? (''+(cluster||'')).split(/,+/) : [];
cluster = Object.keys(cluster.reduce((a, url) =>
{
a[url.toLowerCase().replace(/^(https?:\/\/)/, '').replace(/\/.*$/, '')] = true;
a[url.toLowerCase().replace(/^(https?:\/\/)?(.*?)(\/.*)?$/, (m, m1, m2) => (m1||'http://')+m2)] = true;
return a;
}, {}));
const cfg_port = config.antietcd_port;
@@ -26,7 +26,18 @@ class AntiEtcdAdapter
is_local['0.0.0.0'] = true;
is_local['::'] = true;
is_local[''] = true;
const selected = cluster.map(s => s.split(':', 2)).filter(ip => is_local[ip[0]] && (!cfg_port || ip[1] == cfg_port));
// split :, 3 -> <schema>:<//ip>:<port>
const selected = [];
for (let i = 0; i < cluster.length; i++)
{
const m = /^(https?:\/\/)?(?:\[(.*)\]|([^\[\:]+))(?::(\d+))?$/.exec(cluster[i]);
if (!m)
continue;
const ip = m[3] || m[2];
const port = m[4] || 2379;
if (is_local[ip] && (!cfg_port || port == cfg_port))
selected.push({ idx: i, ip, port });
}
if (selected.length > 1)
{
console.error('More than 1 etcd_address matches local IPs, please specify port');
@@ -35,15 +46,16 @@ class AntiEtcdAdapter
else if (selected.length == 1)
{
const antietcd_config = {
ip: selected[0][0],
port: selected[0][1],
data: config.antietcd_data_file || ((config.antietcd_data_dir || '/var/lib/vitastor') + '/mon_'+selected[0][1]+'.json.gz'),
ip: selected[0].ip,
port: selected[0].port,
data: config.antietcd_data_file || ((config.antietcd_data_dir || '/var/lib/vitastor') + '/mon_'+selected[0].port+'.json.gz'),
persist_filter: vitastor_persist_filter({ vitastor_prefix: config.etcd_prefix || '/vitastor' }),
node_id: selected[0][0]+':'+selected[0][1], // node_id = ip:port
cluster: (cluster.length == 1 ? null : cluster.reduce((a, c) => { a[c] = "http://"+c; return a; }, {})),
node_id: cluster[selected[0].idx].replace(/^(https?:\/\/)/, ''), // same as in <cluster> below
cluster: (cluster.length == 1 ? null : cluster.reduce((a, c) => { a[c.replace(/^(https?:\/\/)/, '')] = c; return a; }, {})),
cluster_key: (config.etcd_prefix || '/vitastor'),
stale_read: 1,
log_level: 1,
logs: { cluster: true },
};
for (const key in config)
{

View File

@@ -1,6 +1,6 @@
{
"name": "vitastor-mon",
"version": "3.0.14",
"version": "3.0.16",
"description": "Vitastor SDS monitor service",
"main": "mon-main.js",
"scripts": {
@@ -9,7 +9,7 @@
"author": "Vitaliy Filippov",
"license": "UNLICENSED",
"dependencies": {
"antietcd": "^1.2.4",
"antietcd": "^1.3.1",
"sprintf-js": "^1.1.2",
"ws": "^7.2.5"
},

View File

@@ -3,6 +3,9 @@
const { parse_level_indexes, parse_pg_dsl } = require('./lp_optimizer/dsl_pgs.js');
const MIN_DATA_BLOCK_SIZE = 4096;
const MAX_DATA_BLOCK_SIZE = 128*1024*1024;
function validate_pool_cfg(pool_id, pool_cfg, placement_levels, warn)
{
pool_cfg.pg_size = Math.floor(pool_cfg.pg_size);
@@ -23,7 +26,8 @@ function validate_pool_cfg(pool_id, pool_cfg, placement_levels, warn)
console.log('Pool '+pool_id+' has invalid coding scheme (one of "xor", "replicated", "ec" and "jerasure" required)');
return false;
}
if (!pool_cfg.pg_size || pool_cfg.pg_size < 1 || pool_cfg.pg_size > 256 ||
// OSDs don't support pg_size > 64 for now
if (!pool_cfg.pg_size || pool_cfg.pg_size < 1 || pool_cfg.pg_size > 64 ||
pool_cfg.scheme !== 'replicated' && pool_cfg.pg_size < 3)
{
if (warn)
@@ -50,6 +54,18 @@ function validate_pool_cfg(pool_id, pool_cfg, placement_levels, warn)
console.log('Pool '+pool_id+' has invalid parity_chunks (must be between 1 and pg_size-2)');
return false;
}
if (pool_cfg.block_size &&
(!Number(pool_cfg.block_size) || (pool_cfg.block_size & (pool_cfg.block_size-1)) ||
pool_cfg.block_size < MIN_DATA_BLOCK_SIZE || pool_cfg.block_size > MAX_DATA_BLOCK_SIZE ||
pool_cfg.scheme !== 'replicated' && pool_cfg.block_size*pool_cfg.pg_size > 0xFFFFFFFF))
{
if (warn)
{
console.log('Pool '+pool_id+' has invalid block_size (must be a power of two between '+
MIN_DATA_BLOCK_SIZE+' and '+MAX_DATA_BLOCK_SIZE+'; must not exceed 2^32-1 when multiplied by pg_size)');
}
return false;
}
if (!pool_cfg.pg_count || pool_cfg.pg_count < 1)
{
if (warn)

View File

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

View File

@@ -366,15 +366,38 @@ sub map_volume
my $prefix = defined $scfg->{vitastor_prefix} ? $scfg->{vitastor_prefix} : 'pve/';
my ($vtype, $img_name, $vmid) = $class->parse_volname($volname);
my $name = $img_name;
my $name = $prefix.$img_name;
$name .= '@'.$snapname if $snapname;
my $mapped = run_cli($scfg, [ 'ls' ], binary => '/usr/bin/vitastor-nbd');
my ($kerneldev) = grep { $mapped->{$_}->{image} eq $prefix.$name } keys %$mapped;
return $kerneldev if $kerneldev && -b $kerneldev; # already mapped
my ($kerneldev) = grep {
$mapped->{$_} && $mapped->{$_}->{image} && $mapped->{$_}->{image} eq $name
} keys %$mapped;
$kerneldev = run_cli($scfg, [ 'map', '--image', $prefix.$name ], binary => '/usr/bin/vitastor-nbd', json => 0);
return $kerneldev;
if ($kerneldev && -b $kerneldev)
{
my $size = `/usr/sbin/blockdev --getsize64 $kerneldev`;
return $kerneldev if $size && $size > 0;
}
my $map_out = run_cli($scfg, [ 'map', '--image', $name ], binary => '/usr/bin/vitastor-nbd', json => 0);
$map_out =~ s/^\s+|\s+$//gso;
# Wait until the device is started
for (my $i = 0; $i < 100; $i++)
{
$mapped = run_cli($scfg, [ 'ls' ], binary => '/usr/bin/vitastor-nbd');
($kerneldev) = grep { $mapped->{$_} && $mapped->{$_}->{image} && $mapped->{$_}->{image} eq $name } keys %$mapped;
if ($kerneldev && -b $kerneldev)
{
my $size = `/usr/sbin/blockdev --getsize64 $kerneldev`;
return $kerneldev if $size && $size > 0;
}
select(undef, undef, undef, 0.1);
}
die "Failed to map Vitastor image $name via NBD".
($map_out ? ", vitastor-nbd map returned '$map_out'" : "")."\n";
}
sub unmap_volume
@@ -383,13 +406,19 @@ sub unmap_volume
my $prefix = defined $scfg->{vitastor_prefix} ? $scfg->{vitastor_prefix} : 'pve/';
my ($vtype, $name, $vmid) = $class->parse_volname($volname);
$name = $prefix.$name;
$name .= '@'.$snapname if $snapname;
my $mapped = run_cli($scfg, [ 'ls' ], binary => '/usr/bin/vitastor-nbd');
my ($kerneldev) = grep { $mapped->{$_}->{image} eq $prefix.$name } keys %$mapped;
if ($kerneldev && -b $kerneldev)
my @kerneldevs = grep {
$mapped->{$_} && $mapped->{$_}->{image} && $mapped->{$_}->{image} eq $name
} keys %$mapped;
for my $kerneldev (@kerneldevs)
{
run_cli($scfg, [ 'unmap', $kerneldev ], binary => '/usr/bin/vitastor-nbd', json => 0);
next if !$kerneldev || !-b $kerneldev;
eval { run_cli($scfg, [ 'unmap', $kerneldev ], binary => '/usr/bin/vitastor-nbd', json => 0); };
warn "Failed to unmap Vitastor image $name from $kerneldev: $@" if $@;
}
return 1;
@@ -405,7 +434,13 @@ sub activate_volume
sub deactivate_volume
{
my ($class, $storeid, $scfg, $volname, $snapname, $cache) = @_;
$class->unmap_volume($storeid, $scfg, $volname, $snapname) if $scfg->{vitastor_nbd};
# Even with vitastor_nbd=0, Proxmox may call map_volume() for special
# volumes like tpmstate0 because swtpm needs a local file/block path.
# Therefore, always try to unmap an existing NBD mapping here.
# unmap_volume() is a no-op if the volume is not currently mapped.
$class->unmap_volume($storeid, $scfg, $volname, $snapname);
return 1;
}

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.0.14'
VITASTOR_VERSION = '3.0.16'
LOG = logging.getLogger(__name__)

View File

@@ -1,11 +1,11 @@
Name: vitastor
Version: 3.0.14
Version: 3.0.16
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.0.14.el10.tar.gz
Source0: vitastor-3.0.16.el10.tar.gz
BuildRequires: gperftools-devel
BuildRequires: gcc-c++

View File

@@ -1,11 +1,11 @@
Name: vitastor
Version: 3.0.14
Version: 3.0.16
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.0.14.el7.tar.gz
Source0: vitastor-3.0.16.el7.tar.gz
BuildRequires: gperftools-devel
BuildRequires: devtoolset-9-gcc-c++

View File

@@ -1,11 +1,11 @@
Name: vitastor
Version: 3.0.14
Version: 3.0.16
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.0.14.el8.tar.gz
Source0: vitastor-3.0.16.el8.tar.gz
BuildRequires: gperftools-devel
BuildRequires: gcc-toolset-9-gcc-c++

View File

@@ -1,11 +1,11 @@
Name: vitastor
Version: 3.0.14
Version: 3.0.16
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.0.14.el9.tar.gz
Source0: vitastor-3.0.16.el9.tar.gz
BuildRequires: gperftools-devel
BuildRequires: gcc-c++

View File

@@ -20,7 +20,7 @@ if("${CMAKE_INSTALL_PREFIX}" MATCHES "^/usr/local/?$")
endif()
set(ENABLE_COVERAGE false CACHE BOOL "Enable code coverage")
add_definitions(-DVITASTOR_VERSION="3.0.14")
add_definitions(-DVITASTOR_VERSION="3.0.16")
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})

View File

@@ -845,7 +845,7 @@ void blockstore_heap_t::recheck_full_gc()
if (inf.entries[i]->entry.is_garbage())
{
collected_garbage += inf.entries[i]->entry.size;
remove_list_item(inf.entries[i]);
unlink_list_item(inf.entries[i]);
}
else
{
@@ -1141,9 +1141,9 @@ bool blockstore_heap_t::calc_block_checksums(uint32_t *block_csums, uint8_t *bit
uint32_t pos = start;
uint32_t block_end = (start/dsk->csum_block_size + 1)*dsk->csum_block_size;
uint32_t block_crc = 0;
bool isset = false;
while (pos < end)
{
bool isset = false;
uint32_t blk_start = pos;
if (bitmap)
{
@@ -1153,7 +1153,7 @@ bool blockstore_heap_t::calc_block_checksums(uint32_t *block_csums, uint8_t *bit
while (pos < end && pos < block_end && !(bitmap[pos/dsk->bitmap_granularity/8] & (1 << ((pos/dsk->bitmap_granularity) % 8))))
pos += dsk->bitmap_granularity;
// zero padding at the beginning or at the end of the block is not counted
if (pos > prev && prev > 0 && pos < block_end)
if (pos > prev && prev > blk_start && pos < block_end)
block_crc = crc32c_pad(block_crc, NULL, 0, pos-prev, 0);
prev = pos;
while (pos < end && pos < block_end && (bitmap[pos/dsk->bitmap_granularity/8] & (1 << ((pos/dsk->bitmap_granularity) % 8))))
@@ -2300,7 +2300,7 @@ void blockstore_heap_t::use_data(inode_t inode, uint64_t location)
{
auto sh_it = pool_shard_settings.find(INODE_POOL(inode));
if (sh_it != pool_shard_settings.end() && sh_it->second.no_inode_stats)
inode = (INODE_POOL(inode) << POOL_ID_BITS);
inode = INODE_WITH_POOL(INODE_POOL(inode), 0);
assert(!data_alloc->get(location / dsk->data_block_size));
data_alloc->set(location / dsk->data_block_size, true);
inode_space_stats[inode] += dsk->data_block_size;
@@ -2311,7 +2311,7 @@ void blockstore_heap_t::free_data(inode_t inode, uint64_t location)
{
auto sh_it = pool_shard_settings.find(INODE_POOL(inode));
if (sh_it != pool_shard_settings.end() && sh_it->second.no_inode_stats)
inode = (INODE_POOL(inode) << POOL_ID_BITS);
inode = INODE_WITH_POOL(INODE_POOL(inode), 0);
assert(data_alloc->get(location / dsk->data_block_size));
data_alloc->set(location / dsk->data_block_size, false);
auto sp_it = inode_space_stats.find(inode);
@@ -2562,26 +2562,21 @@ void blockstore_heap_t::apply_inflight(heap_inflight_lsn_t & inflight)
{
// Remove entry
auto li = list_item(wr);
remove_list_item(li);
if (!li->next)
{
// The last freed entry must be a deletion
assert(!li->prev);
assert((li->entry.entry_type & ~BS_HEAP_GARBAGE) == (BS_HEAP_DELETE|BS_HEAP_STABLE));
}
else if (!li->prev && li->next->entry.entry_type == (BS_HEAP_DELETE|BS_HEAP_STABLE))
{
// free BS_HEAP_DELETEs when all previous entries are also freed
mark_garbage(li->next->block_num, &li->next->entry, UINT32_MAX);
}
unlink_list_item(li);
}
}
void blockstore_heap_t::remove_list_item(heap_list_item_t *li)
{
if (!li->next)
{
// The last freed entry must be a deletion
assert(!li->prev);
assert((li->entry.entry_type & ~BS_HEAP_GARBAGE) == (BS_HEAP_DELETE|BS_HEAP_STABLE));
}
else if (!li->prev && li->next->entry.entry_type == (BS_HEAP_DELETE|BS_HEAP_STABLE))
{
// free BS_HEAP_DELETEs when all previous entries are also freed
mark_garbage(li->next->block_num, &li->next->entry, UINT32_MAX);
}
unlink_list_item(li);
}
void blockstore_heap_t::unlink_list_item(heap_list_item_t *li)
{
auto prev = li->prev;

View File

@@ -246,7 +246,6 @@ class blockstore_heap_t
void gc_block(heap_block_info_t & inf);
int allocate_entry(uint32_t entry_size, uint32_t *block_num, bool allow_last_free);
void insert_list_items(heap_list_item_t** v, size_t count, bool postpone);
void remove_list_item(heap_list_item_t *li);
void unlink_list_item(heap_list_item_t *li);
int add_entry(uint32_t wr_size, uint32_t *modified_block, bool allow_last_free,
bool explicit_complete, std::function<void(heap_entry_t *wr)> fill_entry);

View File

@@ -345,7 +345,7 @@ void blockstore_impl_t::process_list(blockstore_op_t *op)
std::sort(result, result + stable_count);
if (stable_count > op->list_stable_limit)
{
memmove(result + op->list_stable_limit, result + stable_count, unstable_count);
memmove(result + op->list_stable_limit, result + stable_count, unstable_count*sizeof(obj_ver_id));
stable_count = op->list_stable_limit;
}
}

View File

@@ -105,12 +105,12 @@ void blockstore_impl_t::parse_config(blockstore_config_t & config, bool init)
{
meta_write_recheck_parallelism = 16;
}
if (immediate_commit != IMMEDIATE_NONE && !dsk.disable_journal_fsync)
if (immediate_commit != IMMEDIATE_NONE && (!dsk.disable_journal_fsync || !dsk.disable_meta_fsync))
{
throw std::runtime_error("immediate_commit requires disable_journal_fsync");
throw std::runtime_error("immediate_commit requires disable_journal_fsync and disable_meta_fsync");
}
if (immediate_commit == IMMEDIATE_ALL && !dsk.disable_data_fsync)
{
throw std::runtime_error("immediate_commit=all requires disable_journal_fsync and disable_data_fsync");
throw std::runtime_error("immediate_commit=all requires disable_data_fsync");
}
}

View File

@@ -343,6 +343,9 @@ resume_11:
data->iov = { 0 };
data->callback = [this, op, fs = data_fsync_cur](ring_data_t *data)
{
live = true;
if (data->res != 0)
disk_error_abort("sync data", data->res, 0);
if (fs > data_fsync_done)
{
data_fsync_done = fs;

View File

@@ -789,7 +789,8 @@ int blockstore_init_journal::handle_journal_part(void *buf, uint64_t done_pos, u
{
auto buf_pos = proc_pos - done_pos + pos;
journal_entry *je = (journal_entry*)((uint8_t*)buf + buf_pos);
if (je->magic != JOURNAL_MAGIC || buf_pos+je->size > len || je_crc32(je) != je->crc32 ||
if ((bs->journal.block_size-pos) < 12 || je->size < 12 /*crc,magic,type,size*/ ||
je->magic != JOURNAL_MAGIC || buf_pos+je->size > len || je_crc32(je) != je->crc32 ||
je->type < JE_MIN || je->type > JE_MAX || started && je->crc32_prev != crc32_last)
{
if (pos == 0)

View File

@@ -872,7 +872,7 @@ void cluster_client_t::execute_cas(cluster_op_t *op)
op->retval = -EIO;
op->retval = op->retval == -EPIPE ? -EINTR : op->retval;
auto peer_it = msgr.osd_peers.find(op->parts[0].osd_num);
if (op->retval != 0 || (op->flags & OP_IMMEDIATE_COMMIT))
if (op->retval != expected || (op->flags & OP_IMMEDIATE_COMMIT))
{
auto cb = std::move(op->callback);
cb(op);

View File

@@ -359,15 +359,18 @@ void etcd_state_client_t::clean_nonexistent_pgs()
}
}
}
std::vector<osd_num_t> stale_peers;
for (auto & peer_item: peer_states)
{
if (seen_peers.find(peer_item.first) == seen_peers.end())
{
fprintf(stderr, "OSD %ju state disappeared after reload, forgetting it\n", peer_item.first);
parse_state((etcd_kv_t){
.key = etcd_prefix+"/osd/state/"+std::to_string(peer_item.first),
});
}
stale_peers.push_back(peer_item.first);
}
for (auto & stale_peer: stale_peers)
{
fprintf(stderr, "OSD %ju state disappeared after reload, forgetting it\n", stale_peer);
parse_state((etcd_kv_t){
.key = etcd_prefix+"/osd/state/"+std::to_string(stale_peer),
});
}
seen_peers.clear();
}
@@ -414,10 +417,9 @@ void etcd_state_client_t::parse_state(const etcd_kv_t & kv)
// PG Size
pc.pg_size = pool_item.second["pg_size"].uint64_value();
if (pc.pg_size < 1 ||
pool_item.second["pg_size"].uint64_value() < 3 &&
(pc.scheme == POOL_SCHEME_XOR || pc.scheme == POOL_SCHEME_EC) ||
pc.pg_size < 3 && (pc.scheme == POOL_SCHEME_XOR || pc.scheme == POOL_SCHEME_EC) ||
// limit is 64 because osd_peering_pg.cpp uses a 64-bit mask for has_roles
pool_item.second["pg_size"].uint64_value() > 64)
pc.pg_size > 64)
{
fprintf(stderr, "Pool %u has invalid pg_size, skipping pool\n", pool_id);
continue;
@@ -465,16 +467,18 @@ void etcd_state_client_t::parse_state(const etcd_kv_t & kv)
continue;
}
// Data Block Size
pc.data_block_size = pool_item.second["block_size"].uint64_value();
if (!pc.data_block_size)
pc.data_block_size = global_block_size;
if ((pc.data_block_size & (pc.data_block_size-1)) ||
pc.data_block_size < MIN_DATA_BLOCK_SIZE || pc.data_block_size > MAX_DATA_BLOCK_SIZE)
uint64_t data_block_size = pool_item.second["block_size"].uint64_value();
if (!data_block_size)
data_block_size = global_block_size;
if ((data_block_size & (data_block_size-1)) ||
data_block_size < MIN_DATA_BLOCK_SIZE || data_block_size > MAX_DATA_BLOCK_SIZE ||
pc.scheme != POOL_SCHEME_REPLICATED && data_block_size*pc.pg_size > UINT32_MAX)
{
fprintf(stderr, "Pool %u has invalid block_size (must be a power of two between %u and %u), skipping pool\n",
fprintf(stderr, "Pool %u has invalid block_size (must be a power of two between %u and %u; must not exceed 2^32-1 when multiplied by pg_size), skipping pool\n",
pool_id, MIN_DATA_BLOCK_SIZE, MAX_DATA_BLOCK_SIZE);
continue;
}
pc.data_block_size = data_block_size;
// Bitmap Granularity
pc.bitmap_granularity = pool_item.second["bitmap_granularity"].uint64_value();
if (!pc.bitmap_granularity)

View File

@@ -26,13 +26,25 @@ void etcd_state_client_mock_t::pause()
paused = true;
}
void etcd_state_client_mock_t::resume()
void etcd_state_client_mock_t::resume(size_t n)
{
paused = false;
auto queue = std::move(this->queue);
for (auto& req: queue)
std::vector<etcd_mock_request_t> ran;
if (!n)
{
etcd_call(req.api, req.payload, req.timeout, req.retries, req.interval, req.callback);
paused = false;
ran = std::move(queue);
}
else if (n >= queue.size())
ran = std::move(queue);
else
{
for (size_t i = 0; i < n; i++)
queue.push_back(std::move(queue[i]));
queue.erase(queue.begin(), queue.begin() + n);
}
for (auto& req: ran)
{
etcd_call_nopause(req.api, req.payload, req.timeout, req.retries, req.interval, req.callback);
}
}
@@ -41,6 +53,14 @@ void etcd_state_client_mock_t::set(const std::string& key, json11::Json data, ui
if (!mod_revision)
mod_revision = ++this->mod_revision;
this->data[key] = (etcd_mock_key_data_t){ .value = data.dump(), .mod_revision = mod_revision, .lease_id = lease_id };
etcd_kv_t kv = (etcd_kv_t){ .key = key, .value = data, .mod_revision = mod_revision };
parse_state(kv);
if (on_change_hook != NULL)
{
std::map<std::string, etcd_kv_t> changes;
changes[key] = std::move(kv);
on_change_hook(changes);
}
}
void etcd_state_client_mock_t::etcd_call(std::string api, json11::Json payload, int timeout,
@@ -51,6 +71,12 @@ void etcd_state_client_mock_t::etcd_call(std::string api, json11::Json payload,
queue.push_back({ api, payload, timeout, retries, interval, callback });
return;
}
etcd_call_nopause(api, payload, timeout, retries, interval, callback);
}
void etcd_state_client_mock_t::etcd_call_nopause(std::string api, json11::Json payload, int timeout,
int retries, int interval, std::function<void(std::string, json11::Json)> callback)
{
printf("+ etcd: %s\n", api.c_str());
if (api == "/kv/txn")
{

View File

@@ -33,9 +33,10 @@ public:
etcd_state_client_mock_t();
void set(const std::string& key, json11::Json data, uint64_t mod_revision = 0, uint64_t lease_id = 0);
void pause();
void resume();
void resume(size_t n = 0);
void etcd_call_oneshot(std::string etcd_address, std::string api, json11::Json payload, int timeout, std::function<void(std::string, json11::Json)> callback) override;
void etcd_call(std::string api, json11::Json payload, int timeout, int retries, int interval, std::function<void(std::string, json11::Json)> callback) override;
void etcd_call_nopause(std::string api, json11::Json payload, int timeout, int retries, int interval, std::function<void(std::string, json11::Json)> callback);
void etcd_add_watch(json11::Json watch) override;
void load_global_config() override;
void load_pgs() override;

View File

@@ -572,14 +572,14 @@ void osd_messenger_t::check_peer_config(osd_client_t *cl)
std::string json_err;
json11::Json config;
bool err = false;
if (op->reply.hdr.retval < 0)
if (op->reply.hdr.retval <= 0)
{
err = true;
fprintf(stderr, "Failed to get config from OSD %ju (retval=%jd), disconnecting peer\n", cl->osd_num, op->reply.hdr.retval);
}
else
{
config = json11::Json::parse(std::string((char*)op->buf), json_err);
config = json11::Json::parse(std::string((char*)op->buf, op->reply.hdr.retval-1), json_err);
if (json_err != "")
{
err = true;

View File

@@ -78,7 +78,7 @@ struct osd_client_t
osd_op_t *read_op = NULL;
iovec read_iov = { 0 };
msghdr read_msg = { 0 };
int read_remaining = 0;
uint64_t read_remaining = 0;
int read_state = 0;
osd_op_buf_list_t recv_list;
uint64_t read_op_id = 1;

View File

@@ -421,12 +421,12 @@ bool osd_messenger_t::handle_reply_hdr(osd_client_t *cl)
if (op->reply.hdr.opcode == OSD_OP_SEC_READ || op->reply.hdr.opcode == OSD_OP_READ)
{
// Read data. In this case we assume that the buffer is preallocated by the caller (!)
unsigned bmp_len = (op->reply.hdr.opcode == OSD_OP_SEC_READ ? op->reply.sec_rw.attr_len : op->reply.rw.bitmap_len);
unsigned expected_size = (op->reply.hdr.opcode == OSD_OP_SEC_READ ? op->req.sec_rw.len : op->req.rw.len);
uint32_t bmp_len = (op->reply.hdr.opcode == OSD_OP_SEC_READ ? op->reply.sec_rw.attr_len : op->reply.rw.bitmap_len);
uint32_t expected_size = (op->reply.hdr.opcode == OSD_OP_SEC_READ ? op->req.sec_rw.len : op->req.rw.len);
if (op->reply.hdr.retval >= 0 && (op->reply.hdr.retval != expected_size || bmp_len > op->bitmap_len))
{
// Check reply length to not overflow the buffer
fprintf(stderr, "Client %ju read reply of different length: expected %u+%u, got %jd+%u\n",
fprintf(stderr, "Error: peer %ju read reply has incorrect length: expected %u+%u, got %jd+%u, stopping\n",
cl->client_id, expected_size, op->bitmap_len, op->reply.hdr.retval, bmp_len);
cl->sent_ops[op->req.hdr.id] = op;
stop_client(cl->client_id);
@@ -459,6 +459,14 @@ bool osd_messenger_t::handle_reply_hdr(osd_client_t *cl)
cl->read_op = op;
cl->read_state = CL_READ_REPLY_DATA;
cl->read_remaining = sizeof(obj_ver_id) * op->reply.hdr.retval;
if (cl->read_remaining < op->reply.hdr.retval) // check for overflow
{
fprintf(stderr, "Error: peer %ju object list length is too large: %jx objects, stopping\n",
cl->client_id, op->reply.hdr.retval);
stop_client(cl->client_id);
return false;
}
assert(!op->buf);
op->buf = memalign_or_die(MEM_ALIGNMENT, cl->read_remaining);
cl->recv_list.push_back(op->buf, cl->read_remaining);
}
@@ -469,6 +477,14 @@ bool osd_messenger_t::handle_reply_hdr(osd_client_t *cl)
cl->read_op = op;
cl->read_state = CL_READ_REPLY_DATA;
cl->read_remaining = op->reply.hdr.retval;
uint64_t expected_retval = (op->req.sec_read_bmp.len / sizeof(obj_ver_id) * (8 + clean_entry_bitmap_size));
if (op->reply.hdr.retval != expected_retval)
{
fprintf(stderr, "Error: peer %ju bitmap read reply has incorrect length: expected %jx, got %jx, stopping\n",
cl->client_id, expected_retval, op->reply.hdr.retval);
stop_client(cl->client_id);
return false;
}
free(op->buf);
op->buf = memalign_or_die(MEM_ALIGNMENT, cl->read_remaining);
cl->recv_list.push_back(op->buf, cl->read_remaining);
@@ -479,6 +495,13 @@ bool osd_messenger_t::handle_reply_hdr(osd_client_t *cl)
cl->read_op = op;
cl->read_state = CL_READ_REPLY_DATA;
cl->read_remaining = op->reply.hdr.retval;
if (op->reply.hdr.retval > MAX_SIMPLE_PAYLOAD_SIZE)
{
fprintf(stderr, "Error: peer %ju show_config response length too large (%ju > %u bytes), stopping\n",
cl->client_id, op->reply.hdr.retval, MAX_SIMPLE_PAYLOAD_SIZE);
stop_client(cl->client_id);
return false;
}
free(op->buf);
op->buf = malloc_or_die(op->reply.hdr.retval);
cl->recv_list.push_back(op->buf, op->reply.hdr.retval);

View File

@@ -880,6 +880,25 @@ static int vitastor_refresh_limits(BlockDriverState *bs)
// return 0;
//}
// Move the running coroutine to the BlockDriverState's home AioContext.
//
// The block-coroutine-wrapper generator sets poll_state.ctx to
// qemu_get_current_aio_context() in the sync wrappers (bdrv_flush(),
// bdrv_pread() etc.). When bdrv_flush_all() runs under BQL from outside the
// bs's iothread (e.g. on the migration thread inside do_vm_stop()), that is
// the main AioContext, not the iothread that actually owns the bs. The
// coroutine then runs on the wrong context while completions are delivered on
// the iothread, and racing aio_co_schedule() vs. qemu_aio_coroutine_enter()
// on the same coroutine triggers "Co-routine was already scheduled in
// aio_co_schedule" and aborts the process (observed during live migration).
//
// aio_co_reschedule_self() is a no-op when we are already on the target ctx.
#if QEMU_VERSION_MAJOR > 5 || QEMU_VERSION_MAJOR == 5 && QEMU_VERSION_MINOR >= 2
#define vitastor_co_pin_to_bs_ctx(bs) aio_co_reschedule_self(bdrv_get_aio_context(bs))
#else
#define vitastor_co_pin_to_bs_ctx(bs) ((void)0)
#endif
static void vitastor_co_init_task(BlockDriverState *bs, VitastorRPC *task)
{
*task = (VitastorRPC) {
@@ -938,6 +957,7 @@ static int coroutine_fn vitastor_co_preadv(BlockDriverState *bs,
{
VitastorClient *client = bs->opaque;
VitastorRPC task;
vitastor_co_pin_to_bs_ctx(bs);
vitastor_co_init_task(bs, &task);
task.iov = iov;
@@ -966,6 +986,7 @@ static int coroutine_fn vitastor_co_pwritev(BlockDriverState *bs,
{
VitastorClient *client = bs->opaque;
VitastorRPC task;
vitastor_co_pin_to_bs_ctx(bs);
vitastor_co_init_task(bs, &task);
task.iov = iov;
@@ -1039,6 +1060,7 @@ static int coroutine_fn vitastor_co_block_status(BlockDriverState *bs,
#endif
VitastorRPC task;
VitastorClient *client = bs->opaque;
vitastor_co_pin_to_bs_ctx(bs);
uint64_t inode = client->watch ? vitastor_c_inode_get_num(client->watch) : client->inode;
uint8_t bit = 0;
if (client->last_bitmap && client->last_bitmap_inode == inode &&
@@ -1151,6 +1173,7 @@ static int coroutine_fn vitastor_co_flush(BlockDriverState *bs)
{
VitastorClient *client = bs->opaque;
VitastorRPC task;
vitastor_co_pin_to_bs_ctx(bs);
vitastor_co_init_task(bs, &task);
qemu_mutex_lock(&client->mutex);
@@ -1236,6 +1259,8 @@ static BlockDriver bdrv_vitastor = {
#endif
.bdrv_close = vitastor_close,
// Re-register fd handlers when the bs is moved to a different AioContext
// (live migration, drain, iothread reassignment).
.bdrv_detach_aio_context = vitastor_detach_aio_context,
.bdrv_attach_aio_context = vitastor_attach_aio_context,

View File

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

View File

@@ -344,7 +344,6 @@ class osd_t
void continue_primary_describe(osd_op_t *cur_op);
void continue_primary_list(osd_op_t *cur_op);
void continue_primary_write(osd_op_t *cur_op);
void cancel_primary_write(osd_op_t *cur_op);
void continue_primary_sync(osd_op_t *cur_op);
void continue_primary_del(osd_op_t *cur_op);
bool check_write_queue(osd_op_t *cur_op, pg_t & pg);
@@ -379,11 +378,11 @@ class osd_t
void continue_chained_read(osd_op_t *cur_op);
int submit_chained_read_requests(pg_t *pg, osd_op_t *cur_op);
void check_corrupted_chained(pg_t & pg, osd_op_t *cur_op);
void check_corrupted_chained(pg_t *pg, osd_op_t *cur_op);
void send_chained_read_results(pg_t *pg, osd_op_t *cur_op);
std::vector<osd_chain_read_t> collect_chained_read_requests(osd_op_t *cur_op);
int collect_bitmap_requests(osd_op_t *cur_op, pg_t & pg, std::vector<bitmap_request_t> & bitmap_requests);
int submit_bitmap_subops(osd_op_t *cur_op, pg_t & pg);
int collect_bitmap_requests(osd_op_t *cur_op, pg_t *pg, std::vector<bitmap_request_t> & bitmap_requests);
int submit_bitmap_subops(osd_op_t *cur_op, pg_t *pg);
int read_bitmaps(osd_op_t *cur_op, pg_t *pg, int base_state);
inline pg_num_t map_to_pg(object_id oid)

View File

@@ -989,6 +989,7 @@ void osd_t::apply_pg_config()
pg.pool_id = pool_id;
pg.pg_num = pg_num;
pg.reported_epoch = pg_cfg.epoch;
pg.reporting_epoch = pg_cfg.epoch;
pg.target_history = pg_cfg.target_history;
pg.all_peers = vec_all_peers;
pg.next_scrub = pg_cfg.next_scrub;
@@ -1127,6 +1128,7 @@ void osd_t::report_pg_states()
{
// Prevent race conditions (for the case when the monitor is updating this key at the same time)
pg.history_changed = false;
pg.reporting_epoch = pg.epoch;
std::string history_key = base64_encode(st_cli->etcd_prefix+"/pg/history/"+std::to_string(pg.pool_id)+"/"+std::to_string(pg.pg_num));
json11::Json::object history_value = {
{ "epoch", pg.epoch },
@@ -1231,17 +1233,13 @@ void osd_t::report_pg_states()
{
use_ec(pg_it->second.pg_size, pg_it->second.pg_data_size, false);
}
assert(!pg_it->second.inflight);
this->pgs.erase(pg_it);
}
}
}
// Push other PG state updates, if any
report_pg_states();
if (!this->pg_state_dirty.size())
{
// Update statistics
report_statistics();
}
}
});
}

View File

@@ -119,6 +119,7 @@ void osd_t::repeer_pgs(osd_num_t peer_osd)
void osd_t::repeer_pg(pg_t & pg)
{
drop_dirty_pg_connections({ .pool_id = pg.pool_id, .pg_num = pg.pg_num });
if (!(pg.state & (PG_ACTIVE | PG_REPEERING)) || pg.can_repeer())
{
start_pg_peering(pg);
@@ -156,11 +157,8 @@ void osd_t::reset_pg(pg_t & pg)
delete pg.flush_batch;
}
pg.flush_batch = NULL;
for (auto p: pg.write_queue)
{
cancel_primary_write(p.second);
}
pg.write_queue.clear();
// Protected by inflight - reset_pg is impossible with active inflight operations
assert(!pg.write_queue.size());
for (auto it = unstable_writes.begin(); it != unstable_writes.end(); )
{
// Forget this PG's unstable writes
@@ -169,7 +167,6 @@ void osd_t::reset_pg(pg_t & pg)
else
it++;
}
dirty_pgs.erase({ .pool_id = pg.pool_id, .pg_num = pg.pg_num });
}
// Drop connections of clients who have this PG in dirty_pgs
@@ -189,6 +186,7 @@ void osd_t::drop_dirty_pg_connections(pool_pg_num_t pg)
{
msgr.stop_client(client_id);
}
dirty_pgs.erase({ .pool_id = pg.pool_id, .pg_num = pg.pg_num });
}
}
@@ -198,7 +196,6 @@ void osd_t::start_pg_peering(pg_t & pg)
pg.state = PG_PEERING;
this->peering_state |= OSD_PEERING_PGS;
reset_pg(pg);
drop_dirty_pg_connections({ .pool_id = pg.pool_id, .pg_num = pg.pg_num });
// Try to connect with current peers if they're up, but we don't have connections to them
// Otherwise we may erroneously decide that the pg is incomplete :-)
bool all_connected = true;
@@ -648,6 +645,7 @@ void osd_t::discard_list_subop(osd_op_t *list_op)
bool osd_t::stop_pg(pg_t & pg)
{
drop_dirty_pg_connections({ .pool_id = pg.pool_id, .pg_num = pg.pg_num });
if (pg.peering_state)
{
// Stop peering
@@ -669,7 +667,6 @@ bool osd_t::stop_pg(pg_t & pg)
{
return false;
}
drop_dirty_pg_connections({ .pool_id = pg.pool_id, .pg_num = pg.pg_num });
pg.state = pg.state & ~PG_STARTING & ~PG_PEERING & ~PG_INCOMPLETE & ~PG_ACTIVE & ~PG_REPEERING & ~PG_OFFLINE | PG_STOPPING;
if (pg.can_stop())
{

View File

@@ -92,7 +92,7 @@ struct pg_t
uint64_t clean_count = 0, total_count = 0;
bool disable_pg_locks = false;
// epoch number - should increase with each non-clean activation of the PG
uint64_t epoch = 0, reported_epoch = 0;
uint64_t epoch = 0, reported_epoch = 0, reporting_epoch = 0;
// target history and all potential peers
std::vector<std::vector<osd_num_t>> target_history;
std::vector<osd_num_t> all_peers;

View File

@@ -183,12 +183,18 @@ bool osd_t::prepare_primary_rw(osd_op_t *cur_op)
uint64_t* osd_t::get_object_osd_set(pg_t &pg, object_id &oid, pg_osd_set_state_t **object_state)
{
if (!(pg.state & (PG_HAS_INCOMPLETE | PG_HAS_DEGRADED | PG_HAS_MISPLACED)))
if (!(pg.state & (PG_HAS_INCOMPLETE | PG_HAS_DEGRADED | PG_HAS_MISPLACED | PG_HAS_INCONSISTENT)))
{
*object_state = NULL;
return pg.cur_set.data();
}
auto st_it = pg.incomplete_objects.find(oid);
auto st_it = pg.inconsistent_objects.find(oid);
if (st_it != pg.inconsistent_objects.end())
{
*object_state = st_it->second;
return st_it->second->read_target.data();
}
st_it = pg.incomplete_objects.find(oid);
if (st_it != pg.incomplete_objects.end())
{
*object_state = st_it->second;
@@ -260,6 +266,10 @@ resume_0:
op_data->target_ver = UINT64_MAX;
op_data->prev_set = &this->osd_num;
}
if (!op_data->object_state)
{
op_data->flags |= OP_DATA_ENOENT_OK;
}
if (!pg || pg->state == PG_ACTIVE || pg->scheme == POOL_SCHEME_REPLICATED)
{
// Fast happy-path
@@ -281,7 +291,7 @@ resume_0:
return;
}
// Submit reads
op_data->degraded = 1;
op_data->flags |= OP_DATA_DEGRADED;
assert(!cur_op->buf);
cur_op->buf = alloc_read_buffer(op_data->stripes, pg->pg_size, 0);
submit_primary_subops(SUBMIT_RMW_READ, op_data->target_ver, op_data->prev_set, cur_op);
@@ -313,7 +323,7 @@ resume_2:
}
cur_op->reply.rw.version = op_data->fact_ver;
cur_op->reply.rw.bitmap_len = (pg ? pg->pg_data_size : 1) * clean_entry_bitmap_size;
if (op_data->degraded)
if (op_data->flags & OP_DATA_DEGRADED)
{
// Reconstruct missing stripes
osd_rmw_stripe_t *stripes = op_data->stripes;
@@ -505,10 +515,10 @@ pg_osd_set_state_t* osd_t::add_object_to_set(pg_t & pg, const object_id oid, con
}
else
{
if (!(has_roles & (1 << chunk.role)))
if (!(has_roles & ((uint64_t)1 << chunk.role)))
{
n_roles++;
has_roles |= (1 << chunk.role);
has_roles |= ((uint64_t)1 << chunk.role);
}
if (pg.cur_set[chunk.role] != chunk.osd_num)
{
@@ -765,7 +775,14 @@ resume_3:
if (op_data->errors > 0)
{
deref_object_state(pg, &op_data->object_state, true);
pg_cancel_write_queue(pg, cur_op, op_data->oid, op_data->errcode);
cur_op->reply.hdr.retval = op_data->errcode;
goto continue_others;
}
if (!(pg.state & PG_ACTIVE))
{
// FIXME: Move cleanup to op_data destructor
deref_object_state(pg, &op_data->object_state, true);
pg_cancel_write_queue(pg, cur_op, op_data->oid, -EPIPE);
return;
}
// Check CAS version
@@ -793,8 +810,16 @@ resume_4:
resume_5:
if (op_data->errors > 0)
{
pg.ver_override.erase(op_data->oid);
deref_object_state(pg, &op_data->object_state, true);
pg_cancel_write_queue(pg, cur_op, op_data->oid, op_data->errcode);
cur_op->reply.hdr.retval = op_data->errcode;
goto continue_others;
}
if (!(pg.state & PG_ACTIVE))
{
pg.ver_override.erase(op_data->oid);
deref_object_state(pg, &op_data->object_state, true);
pg_cancel_write_queue(pg, cur_op, op_data->oid, -EPIPE);
return;
}
// Remove version override
@@ -859,6 +884,12 @@ continue_others:
if (next_op)
{
// Continue next write to the same object
continue_primary_write(next_op);
if (next_op->req.hdr.opcode == OSD_OP_WRITE)
continue_primary_write(next_op);
else
{
assert(next_op->req.hdr.opcode == OSD_OP_DELETE);
continue_primary_del(next_op);
}
}
}

View File

@@ -10,6 +10,10 @@
#define SUBMIT_RMW_READ 1
#define SUBMIT_WRITE 2
#define OP_DATA_DEGRADED 1
#define OP_DATA_ENOENT_OK 2
#define OP_DATA_SKIP_VER_CHECK 4
struct unstable_osd_num_t
{
osd_num_t osd_num;
@@ -24,7 +28,7 @@ struct osd_primary_op_data_t
uint64_t target_ver = 0;
uint64_t orig_ver = 0, fact_ver = 0;
int n_subops = 0, done = 0, errors = 0, drops = 0, errcode = 0;
int degraded = 0;
uint64_t flags = 0;
int stripe_count = 0;
osd_rmw_stripe_t *stripes = NULL;
pg_t *pg = NULL;

View File

@@ -50,12 +50,13 @@ resume_3:
return;
}
resume_4:
// FIXME: Check fact_ver mismatch here too
if (op_data->errors > 0)
{
if (pg && (op_data->errcode == -EIO || op_data->errcode == -EDOM))
{
// Handle corrupted reads and retry...
check_corrupted_chained(*pg, cur_op);
check_corrupted_chained(pg, cur_op);
free(cur_op->buf);
cur_op->buf = NULL;
free(op_data->chain_reads);
@@ -88,19 +89,21 @@ int osd_t::read_bitmaps(osd_op_t *cur_op, pg_t *pg, int base_state)
{
// Happy path for clean replicated PGs (all bitmaps are available locally)
osd_primary_op_data_t *op_data = cur_op->op_data;
uint64_t version = 0;
for (int chain_num = 0; chain_num < op_data->chain_size; chain_num++)
{
object_id cur_oid = { .inode = op_data->read_chain[chain_num], .stripe = op_data->oid.stripe };
// Read bitmap synchronously from the local database
bs->read_bitmap(
cur_oid, UINT64_MAX, (uint8_t*)op_data->snapshot_bitmaps + chain_num*clean_entry_bitmap_size,
!chain_num ? &cur_op->reply.rw.version : NULL
!chain_num ? &version : NULL
);
}
cur_op->reply.rw.version = version;
}
else
{
if (submit_bitmap_subops(cur_op, *pg) < 0)
if (submit_bitmap_subops(cur_op, pg) < 0)
{
// Failure
finish_op(cur_op, -EIO);
@@ -156,20 +159,20 @@ resume_1:
return 0;
}
int osd_t::collect_bitmap_requests(osd_op_t *cur_op, pg_t & pg, std::vector<bitmap_request_t> & bitmap_requests)
int osd_t::collect_bitmap_requests(osd_op_t *cur_op, pg_t *pg, std::vector<bitmap_request_t> & bitmap_requests)
{
assert(&pg);
assert(pg);
osd_primary_op_data_t *op_data = cur_op->op_data;
for (int chain_num = 0; chain_num < op_data->chain_size; chain_num++)
{
object_id cur_oid = { .inode = op_data->read_chain[chain_num], .stripe = op_data->oid.stripe };
auto vo_it = pg.ver_override.find(cur_oid);
uint64_t target_version = vo_it != pg.ver_override.end() ? vo_it->second : UINT64_MAX;
uint64_t* cur_set = get_object_osd_set(pg, cur_oid, &op_data->chain_states[chain_num]);
if (pg.scheme == POOL_SCHEME_REPLICATED)
auto vo_it = pg->ver_override.find(cur_oid);
uint64_t target_version = vo_it != pg->ver_override.end() ? vo_it->second : UINT64_MAX;
uint64_t* cur_set = get_object_osd_set(*pg, cur_oid, &op_data->chain_states[chain_num]);
if (pg->scheme == POOL_SCHEME_REPLICATED)
{
osd_num_t read_target = 0;
for (int i = 0; i < pg.pg_size; i++)
for (int i = 0; i < pg->pg_size; i++)
{
if (cur_set[i] == this->osd_num || cur_set[i] != 0 && read_target == 0)
{
@@ -187,31 +190,31 @@ int osd_t::collect_bitmap_requests(osd_op_t *cur_op, pg_t & pg, std::vector<bitm
}
else
{
osd_rmw_stripe_t local_stripes[pg.pg_size];
memcpy(local_stripes, op_data->stripes, sizeof(osd_rmw_stripe_t) * pg.pg_size);
if (extend_missing_stripes(local_stripes, cur_set, pg.pg_data_size, pg.pg_size) < 0)
osd_rmw_stripe_t local_stripes[pg->pg_size];
memcpy(local_stripes, op_data->stripes, sizeof(osd_rmw_stripe_t) * pg->pg_size);
if (extend_missing_stripes(local_stripes, cur_set, pg->pg_data_size, pg->pg_size) < 0)
{
return -1;
}
int need_at_least = 0;
for (int i = 0; i < pg.pg_size; i++)
for (int i = 0; i < pg->pg_size; i++)
{
if (cur_set[i] == 0)
{
if (local_stripes[i].read_end != 0)
{
// We need this part of the bitmap, but it's unavailable
need_at_least = pg.pg_data_size;
need_at_least = pg->pg_data_size;
}
op_data->missing_flags[chain_num*pg.pg_size + i] = 1;
op_data->missing_flags[chain_num*pg->pg_size + i] = 1;
}
else
{
op_data->missing_flags[chain_num*pg.pg_size + i] = 0;
op_data->missing_flags[chain_num*pg->pg_size + i] = 0;
}
}
int found = 0;
for (int i = 0; i < pg.pg_size; i++)
for (int i = 0; i < pg->pg_size; i++)
{
if (cur_set[i] != 0 && (local_stripes[i].read_end != 0 || found < need_at_least))
{
@@ -223,7 +226,7 @@ int osd_t::collect_bitmap_requests(osd_op_t *cur_op, pg_t & pg, std::vector<bitm
.stripe = cur_oid.stripe | i,
},
.version = target_version,
.bmp_buf = (uint8_t*)op_data->snapshot_bitmaps + (chain_num*pg.pg_size + i)*clean_entry_bitmap_size,
.bmp_buf = (uint8_t*)op_data->snapshot_bitmaps + (chain_num*pg->pg_size + i)*clean_entry_bitmap_size,
});
found++;
}
@@ -236,9 +239,9 @@ int osd_t::collect_bitmap_requests(osd_op_t *cur_op, pg_t & pg, std::vector<bitm
return 0;
}
int osd_t::submit_bitmap_subops(osd_op_t *cur_op, pg_t & pg)
int osd_t::submit_bitmap_subops(osd_op_t *cur_op, pg_t *pg)
{
assert(&pg);
assert(pg);
osd_primary_op_data_t *op_data = cur_op->op_data;
std::vector<bitmap_request_t> *bitmap_requests = new std::vector<bitmap_request_t>();
if (collect_bitmap_requests(cur_op, pg, *bitmap_requests) < 0)
@@ -257,7 +260,6 @@ int osd_t::submit_bitmap_subops(osd_op_t *cur_op, pg_t & pg)
}
if (op_data->n_subops > 0)
{
op_data->fact_ver = 0;
op_data->done = op_data->errors = 0;
op_data->subops = new osd_op_t[op_data->n_subops];
}
@@ -269,13 +271,15 @@ int osd_t::submit_bitmap_subops(osd_op_t *cur_op, pg_t & pg)
if (subop_osd_num == this->osd_num)
{
// Read bitmap synchronously from the local database
uint64_t version = 0;
for (int j = prev; j <= i; j++)
{
bs->read_bitmap(
(*bitmap_requests)[j].oid, (*bitmap_requests)[j].version, (*bitmap_requests)[j].bmp_buf,
(*bitmap_requests)[j].oid.inode == cur_op->req.rw.inode ? &cur_op->reply.rw.version : NULL
(*bitmap_requests)[j].oid.inode == cur_op->req.rw.inode ? &version : NULL
);
}
cur_op->reply.rw.version = version;
}
else
{
@@ -442,7 +446,7 @@ int osd_t::submit_chained_read_requests(pg_t *pg, osd_op_t *cur_op)
finish_op(cur_op, -EIO);
return -1;
}
op_data->degraded = 1;
op_data->flags |= OP_DATA_DEGRADED;
}
else
{
@@ -489,7 +493,7 @@ int osd_t::submit_chained_read_requests(pg_t *pg, osd_op_t *cur_op)
}
}
// Submit all reads
op_data->fact_ver = UINT64_MAX;
op_data->flags |= OP_DATA_SKIP_VER_CHECK;
op_data->done = op_data->errors = 0;
op_data->n_subops = n_subops;
if (!n_subops)
@@ -527,11 +531,11 @@ int osd_t::submit_chained_read_requests(pg_t *pg, osd_op_t *cur_op)
return 0;
}
void osd_t::check_corrupted_chained(pg_t & pg, osd_op_t *cur_op)
void osd_t::check_corrupted_chained(pg_t *pg, osd_op_t *cur_op)
{
assert(&pg);
assert(pg);
osd_primary_op_data_t *op_data = cur_op->op_data;
int stripe_count = (pg.scheme == POOL_SCHEME_REPLICATED ? 1 : pg.pg_size);
int stripe_count = (pg->scheme == POOL_SCHEME_REPLICATED ? 1 : pg->pg_size);
osd_rmw_stripe_t *chain_stripes = (osd_rmw_stripe_t*)(
(uint8_t*)op_data->chain_reads + sizeof(osd_chain_read_t) * op_data->chain_read_count
);
@@ -550,7 +554,7 @@ void osd_t::check_corrupted_chained(pg_t & pg, osd_op_t *cur_op)
}
if (corrupted)
{
mark_object_corrupted(pg, cur_oid, op_data->chain_states[op_data->chain_reads[cri].chain_pos], stripes, false);
mark_object_corrupted(*pg, cur_oid, op_data->chain_states[op_data->chain_reads[cri].chain_pos], stripes, false);
}
}
}
@@ -563,7 +567,7 @@ void osd_t::send_chained_read_results(pg_t *pg, osd_op_t *cur_op)
(uint8_t*)op_data->chain_reads + sizeof(osd_chain_read_t) * op_data->chain_read_count
);
// Reconstruct parts if needed
if (op_data->degraded)
if (op_data->flags & OP_DATA_DEGRADED)
{
for (int cri = 0; cri < op_data->chain_read_count; cri++)
{

View File

@@ -400,9 +400,19 @@ void osd_t::handle_primary_subop(osd_op_t *subop, osd_op_t *cur_op)
osd_primary_op_data_t *op_data = cur_op->op_data;
if (retval == -ENOENT && opcode == OSD_OP_SEC_READ)
{
// ENOENT is not an error for almost all reads, except scrub
retval = expected;
memset(((osd_rmw_stripe_t*)subop->rmw_buf)->read_buf, 0, expected);
// 1) ENOENT is not an error for clean object reads from 1 replica
// 2) ENOENT is not an error for clean EC object reads if all replicas return ENOENT
// (i.e. ENOENT is not an error, but fact_ver mismatch is)
// 3) ENOENT is not an error for scrub reads
// 4) In all other cases ENOENT is an error!
if (op_data->flags & OP_DATA_ENOENT_OK)
{
retval = expected;
memset(((osd_rmw_stripe_t*)subop->rmw_buf)->read_buf, 0, expected);
subop->reply.sec_rw.version = 0;
}
else
retval = -EIO;
((osd_rmw_stripe_t*)subop->rmw_buf)->not_exists = true;
}
if (opcode == OSD_OP_SEC_READ && (retval == -EIO || retval == -EDOM) ||
@@ -426,9 +436,10 @@ void osd_t::handle_primary_subop(osd_op_t *subop, osd_op_t *cur_op)
printf("subop %s %jx:%jx from client %ju: version = %ju\n", osd_op_names[opcode],
subop->req.sec_rw.oid.inode, subop->req.sec_rw.oid.stripe, subop->client_id, version);
#endif
if (version != 0 && op_data->fact_ver != UINT64_MAX)
if (!(op_data->flags & OP_DATA_SKIP_VER_CHECK))
{
if (op_data->fact_ver != 0 && op_data->fact_ver != version)
if (op_data->fact_ver != version && (op_data->errors > 0 || op_data->done > 0) &&
(version != 0 && op_data->fact_ver != 0 || !(op_data->flags & OP_DATA_ENOENT_OK)))
{
fprintf(
stderr, "different fact_versions returned from %s %jx:%jx subops for a %s op: %ju vs %ju\n",
@@ -532,24 +543,6 @@ void osd_t::handle_primary_subop(osd_op_t *subop, osd_op_t *cur_op)
}
}
void osd_t::cancel_primary_write(osd_op_t *cur_op)
{
if (cur_op->op_data && cur_op->op_data->subops)
{
// Primary-write operation is waiting for subops, subops
// are sent to peer OSDs, so we can't just throw them away.
// Mark them with an extra EPIPE.
cur_op->op_data->errors++;
if (cur_op->op_data->errcode == 0)
cur_op->op_data->errcode = -EPIPE;
cur_op->op_data->done--; // Caution: `done` must be signed because may become -1 here
}
else
{
finish_op(cur_op, -EPIPE);
}
}
bool contains_osd(osd_num_t *osd_set, uint64_t size, osd_num_t osd_num)
{
for (uint64_t i = 0; i < size; i++)

View File

@@ -34,14 +34,92 @@ resume_1:
syncs_in_progress.push_back(cur_op);
}
resume_2:
op_data->errcode = 0;
op_data->errors = 0;
if (cur_op->client_id)
{
auto it = msgr.clients.find(cur_op->client_id);
if (it == msgr.clients.end())
{
// Client is already dropped
op_data->errcode = -EPIPE;
goto finish;
}
auto cl = it->second;
for (auto dirty_pg_num: cl->dirty_pgs)
{
auto pg_it = pgs.find(dirty_pg_num);
if (pg_it == pgs.end() || !(pg_it->second.state & PG_ACTIVE))
{
// PG is not in a clean state (repeering or stopped), can't sync it
// It will be removed from dirty_pgs on stop/repeer
op_data->errcode = -EPIPE;
goto finish;
}
}
// We can forget client's dirty PGs and even skip restoring them on error because
// a failed SYNC drops the client's connection - there are no legitimate errors for SYNC
cl->dirty_pgs.clear();
}
if (dirty_osds.size() == 0)
{
// Nothing to sync
goto finish;
}
// Save and clear unstable_writes
// Save and clear unstable_writes and dirty_pgs
// In theory it is possible to do in on a per-client basis, but this seems to be an unnecessary complication
// It would be cool not to copy these here at all, but someone has to deduplicate them by object IDs anyway
{
op_data->dirty_pg_count = dirty_pgs.size();
op_data->dirty_osd_count = dirty_osds.size();
void *dirty_buf = malloc_or_die(
sizeof(pool_pg_num_t)*dirty_pgs.size() +
sizeof(uint64_t)*dirty_pgs.size() +
sizeof(osd_num_t)*dirty_osds.size() +
sizeof(obj_ver_osd_t)*this->copies_to_delete_after_sync_count
);
op_data->dirty_pgs = (pool_pg_num_t*)dirty_buf;
uint64_t *pg_del_counts = (uint64_t*)((uint8_t*)op_data->dirty_pgs + (sizeof(pool_pg_num_t))*op_data->dirty_pg_count);
op_data->dirty_osds = (osd_num_t*)((uint8_t*)pg_del_counts + 8*op_data->dirty_pg_count);
if (this->copies_to_delete_after_sync_count)
{
op_data->copies_to_delete_count = 0;
op_data->copies_to_delete = (obj_ver_osd_t*)(op_data->dirty_osds + op_data->dirty_osd_count);
}
int dpg = 0;
for (auto dirty_pg_num: dirty_pgs)
{
auto pg_it = pgs.find(dirty_pg_num);
if (pg_it == pgs.end() || !(pg_it->second.state & PG_ACTIVE))
continue;
auto & pg = pg_it->second;
pg.inflight++;
op_data->dirty_pgs[dpg] = dirty_pg_num;
pg_del_counts[dpg] = pg.copies_to_delete_after_sync.size();
if (this->copies_to_delete_after_sync_count)
{
assert(pg.copies_to_delete_after_sync.size() <= this->copies_to_delete_after_sync_count - op_data->copies_to_delete_count);
memcpy(
op_data->copies_to_delete + op_data->copies_to_delete_count,
pg.copies_to_delete_after_sync.data(),
sizeof(obj_ver_osd_t)*pg.copies_to_delete_after_sync.size()
);
op_data->copies_to_delete_count += pg.copies_to_delete_after_sync.size();
}
dpg++;
}
while (dpg < op_data->dirty_pg_count)
{
op_data->dirty_pgs[dpg++] = { 0, 0 };
}
dirty_pgs.clear();
dpg = 0;
for (auto osd_num: dirty_osds)
{
op_data->dirty_osds[dpg++] = osd_num;
}
dirty_osds.clear();
}
if (unstable_writes.size() > 0)
{
op_data->unstable_write_osds = new std::vector<unstable_osd_num_t>();
@@ -79,51 +157,6 @@ resume_2:
}
this->unstable_writes.clear();
}
{
op_data->dirty_pg_count = dirty_pgs.size();
op_data->dirty_osd_count = dirty_osds.size();
void *dirty_buf = malloc_or_die(
sizeof(pool_pg_num_t)*dirty_pgs.size() +
sizeof(uint64_t)*dirty_pgs.size() +
sizeof(osd_num_t)*dirty_osds.size() +
sizeof(obj_ver_osd_t)*this->copies_to_delete_after_sync_count
);
op_data->dirty_pgs = (pool_pg_num_t*)dirty_buf;
uint64_t *pg_del_counts = (uint64_t*)((uint8_t*)op_data->dirty_pgs + (sizeof(pool_pg_num_t))*op_data->dirty_pg_count);
op_data->dirty_osds = (osd_num_t*)((uint8_t*)pg_del_counts + 8*op_data->dirty_pg_count);
if (this->copies_to_delete_after_sync_count)
{
op_data->copies_to_delete_count = 0;
op_data->copies_to_delete = (obj_ver_osd_t*)(op_data->dirty_osds + op_data->dirty_osd_count);
for (auto dirty_pg_num: dirty_pgs)
{
auto & pg = pgs.at(dirty_pg_num);
assert(pg.copies_to_delete_after_sync.size() <= this->copies_to_delete_after_sync_count);
memcpy(
op_data->copies_to_delete + op_data->copies_to_delete_count,
pg.copies_to_delete_after_sync.data(),
sizeof(obj_ver_osd_t)*pg.copies_to_delete_after_sync.size()
);
op_data->copies_to_delete_count += pg.copies_to_delete_after_sync.size();
}
}
int dpg = 0;
for (auto dirty_pg_num: dirty_pgs)
{
auto & pg = pgs.at(dirty_pg_num);
pg.inflight++;
op_data->dirty_pgs[dpg] = dirty_pg_num;
pg_del_counts[dpg] = pg.copies_to_delete_after_sync.size();
dpg++;
}
dirty_pgs.clear();
dpg = 0;
for (auto osd_num: dirty_osds)
{
op_data->dirty_osds[dpg++] = osd_num;
}
dirty_osds.clear();
}
if (immediate_commit != IMMEDIATE_ALL)
{
// SYNC
@@ -157,7 +190,14 @@ resume_6:
// Return PGs and OSDs back into their dirty sets
for (int i = 0; i < op_data->dirty_pg_count; i++)
{
dirty_pgs.insert(op_data->dirty_pgs[i]);
if (op_data->dirty_pgs[i].pg_num != 0)
{
auto pg_it = pgs.find(op_data->dirty_pgs[i]);
if (pg_it != pgs.end() && (pg_it->second.state & PG_ACTIVE))
{
dirty_pgs.insert(op_data->dirty_pgs[i]);
}
}
}
for (int i = 0; i < op_data->dirty_osd_count; i++)
{
@@ -176,7 +216,8 @@ resume_6:
.pool_id = INODE_POOL(w.oid.inode),
.pg_num = map_to_pg(w.oid),
};
if (pgs.at(wpg).state & PG_ACTIVE)
auto pg_it = pgs.find(wpg);
if (pg_it != pgs.end() && (pg_it->second.state & PG_ACTIVE))
{
uint64_t & dest = this->unstable_writes[(osd_object_id_t){
.osd_num = unstable_osd.osd_num,
@@ -208,6 +249,9 @@ resume_8:
uint64_t *pg_del_counts = (uint64_t*)((uint8_t*)op_data->dirty_pgs + (sizeof(pool_pg_num_t))*op_data->dirty_pg_count);
for (int i = 0; i < op_data->dirty_pg_count; i++)
{
if (op_data->dirty_pgs[i].pg_num == 0)
continue;
// Protected by inflight++
auto & pg = pgs.at(op_data->dirty_pgs[i]);
auto n = pg_del_counts[i];
assert(copies_to_delete_after_sync_count >= n);
@@ -232,13 +276,21 @@ resume_8:
}
for (int i = 0; i < op_data->dirty_pg_count; i++)
{
auto & pg = pgs.at(op_data->dirty_pgs[i]);
rm_inflight(pg);
if (op_data->dirty_pgs[i].pg_num != 0)
{
auto & pg = pgs.at(op_data->dirty_pgs[i]);
rm_inflight(pg);
}
}
finish:
// FIXME: Free those in the destructor (not here)?
free(op_data->dirty_pgs);
op_data->dirty_pgs = NULL;
op_data->dirty_osds = NULL;
if (op_data->dirty_pgs)
{
free(op_data->dirty_pgs);
op_data->dirty_pgs = NULL;
op_data->dirty_osds = NULL;
op_data->copies_to_delete = NULL;
}
if (op_data->unstable_writes)
{
delete op_data->unstable_write_osds;
@@ -246,21 +298,12 @@ resume_8:
op_data->unstable_writes = NULL;
op_data->unstable_write_osds = NULL;
}
if (op_data->errors > 0)
if (cur_op->client_id && op_data->errcode)
{
finish_op(cur_op, op_data->errcode);
}
else
{
finish:
if (cur_op->client_id)
{
auto it = msgr.clients.find(cur_op->client_id);
if (it != msgr.clients.end())
it->second->dirty_pgs.clear();
}
finish_op(cur_op, 0);
// Forcibly drop client's connection instead of returning the error
msgr.stop_client(cur_op->client_id);
}
finish_op(cur_op, op_data->errcode);
assert(syncs_in_progress.front() == cur_op);
syncs_in_progress.pop_front();
if (syncs_in_progress.size() > 0)

View File

@@ -107,6 +107,10 @@ retry_1:
goto continue_others;
}
}
if (!op_data->object_state)
{
op_data->flags |= OP_DATA_ENOENT_OK;
}
// Read required blocks
submit_primary_subops(SUBMIT_RMW_READ, UINT64_MAX, op_data->prev_set, cur_op);
resume_2:
@@ -135,7 +139,14 @@ resume_3:
}
}
deref_object_state(pg, &op_data->object_state, true);
pg_cancel_write_queue(pg, cur_op, op_data->oid, op_data->errcode);
cur_op->reply.hdr.retval = op_data->errcode;
goto continue_others;
}
if (!(pg.state & PG_ACTIVE))
{
// FIXME: Move cleanup to op_data destructor
deref_object_state(pg, &op_data->object_state, true);
pg_cancel_write_queue(pg, cur_op, op_data->oid, -EPIPE);
return;
}
// Check CAS version
@@ -198,22 +209,25 @@ resume_3:
if (pg.epoch > pg.reported_epoch)
{
// Report newer epoch before writing
// FIXME: We don't have to report all changed PG states here
this->pg_state_dirty.insert({ .pool_id = pg.pool_id, .pg_num = pg.pg_num });
if (pg.state != PG_ACTIVE)
if (pg.epoch > pg.reporting_epoch)
{
// Check that current OSD set is in history and/or add it there
std::vector<osd_num_t> history_set;
for (auto peer_osd: pg.cur_set)
if (peer_osd != 0)
history_set.push_back(peer_osd);
std::sort(history_set.begin(), history_set.end());
auto it = std::lower_bound(pg.target_history.begin(), pg.target_history.end(), history_set);
if (it == pg.target_history.end() || *it != history_set)
pg.target_history.insert(it, history_set);
// FIXME: We don't have to report all changed PG states here
this->pg_state_dirty.insert({ .pool_id = pg.pool_id, .pg_num = pg.pg_num });
if (pg.state != PG_ACTIVE)
{
// Check that current OSD set is in history and/or add it there
std::vector<osd_num_t> history_set;
for (auto peer_osd: pg.cur_set)
if (peer_osd != 0)
history_set.push_back(peer_osd);
std::sort(history_set.begin(), history_set.end());
auto it = std::lower_bound(pg.target_history.begin(), pg.target_history.end(), history_set);
if (it == pg.target_history.end() || *it != history_set)
pg.target_history.insert(it, history_set);
}
pg.history_changed = true;
report_pg_states();
}
pg.history_changed = true;
report_pg_states();
resume_10:
if (pg.epoch > pg.reported_epoch)
{
@@ -222,13 +236,14 @@ resume_10:
return;
}
}
// Recheck PG state after reporting history - maybe it's already stopping/restarting
if (pg.state & (PG_STOPPING|PG_REPEERING))
if (!(pg.state & PG_ACTIVE))
{
pg.ver_override.erase(op_data->oid);
deref_object_state(pg, &op_data->object_state, true);
pg_cancel_write_queue(pg, cur_op, op_data->oid, -EPIPE);
return;
}
op_data->flags &= ~OP_DATA_ENOENT_OK;
submit_primary_subops(SUBMIT_WRITE, op_data->target_ver, pg.cur_set.data(), cur_op);
resume_4:
if (op_data->n_subops > 0)
@@ -280,7 +295,14 @@ resume_12:
}
pg.ver_override.erase(op_data->oid);
deref_object_state(pg, &op_data->object_state, true);
pg_cancel_write_queue(pg, cur_op, op_data->oid, op_data->errcode);
cur_op->reply.hdr.retval = op_data->errcode;
goto continue_others;
}
if (!(pg.state & PG_ACTIVE))
{
pg.ver_override.erase(op_data->oid);
deref_object_state(pg, &op_data->object_state, true);
pg_cancel_write_queue(pg, cur_op, op_data->oid, -EPIPE);
return;
}
if (pg.scheme != POOL_SCHEME_REPLICATED)
@@ -344,6 +366,18 @@ resume_7:
{
return;
}
if (op_data->errors > 0)
{
deref_object_state(pg, &op_data->object_state, true);
cur_op->reply.hdr.retval = op_data->errcode;
goto continue_others;
}
if (!(pg.state & PG_ACTIVE))
{
deref_object_state(pg, &op_data->object_state, true);
pg_cancel_write_queue(pg, cur_op, op_data->oid, -EPIPE);
return;
}
if (op_data->orig_ver == 0)
{
// Object is created
@@ -388,8 +422,8 @@ resume_8:
resume_9:
if (op_data->errors > 0)
{
pg_cancel_write_queue(pg, cur_op, op_data->oid, op_data->errcode);
return;
cur_op->reply.hdr.retval = op_data->errcode;
goto continue_others;
}
}
}
@@ -415,7 +449,13 @@ continue_others:
if (next_op)
{
// Continue next write to the same object
continue_primary_write(next_op);
if (next_op->req.hdr.opcode == OSD_OP_WRITE)
continue_primary_write(next_op);
else
{
assert(next_op->req.hdr.opcode == OSD_OP_DELETE);
continue_primary_del(next_op);
}
}
}
@@ -514,11 +554,6 @@ resume_7:
delete[] op_data->unstable_writes;
op_data->unstable_writes = NULL;
op_data->unstable_write_osds = NULL;
if (op_data->errors > 0)
{
pg_cancel_write_queue(pg, cur_op, op_data->oid, op_data->errcode);
return false;
}
}
}
else if (immediate_commit == IMMEDIATE_SMALL)

View File

@@ -1162,14 +1162,27 @@ static bool next_combination(int *subset, int k, int n)
static uint64_t c_n_k(uint64_t n, uint64_t k)
{
uint64_t c = 1;
for (uint64_t i = n; i > k; i--)
uint64_t mul = n;
uint64_t div = 2;
while (mul > k)
{
if ((c*i) < i)
// do some divisions on overflow
while ((c*mul)/mul != c && div <= (n-k))
{
c /= div;
div++;
}
// divisions didn't help, return the overflown value
if ((c*mul)/mul != c)
return UINT64_MAX;
c *= i;
c *= mul;
mul--;
}
while (div <= (n-k))
{
c /= div;
div++;
}
for (uint64_t i = 2; i <= (n-k); i++)
c /= i;
return c;
}
@@ -1298,7 +1311,8 @@ std::vector<int> ec_find_good(osd_rmw_stripe_t *stripes, int stripe_count, int p
for (int j = 0; j < i; j++)
{
if (stripes[j].role == stripes[i].role &&
memcmp(stripes[i].read_buf, stripes[j].read_buf, chunk_size) == 0)
memcmp(stripes[i].read_buf, stripes[j].read_buf, chunk_size) == 0 &&
(!bitmap_size || memcmp(stripes[i].bmp_buf, stripes[j].bmp_buf, bitmap_size) == 0))
{
eq_to[i] = eq_to[j];
break;

View File

@@ -35,6 +35,7 @@ void test_recover_22();
void test_ec_find_good_multi_chunks();
void test_ec_find_good_42_no_good();
void test_ec_partial_write_no_parity_preserves_bitmap();
void test_c_n_k();
int main(int narg, char *args[])
{
@@ -83,6 +84,8 @@ int main(int narg, char *args[])
test_recover_22();
// Test 21
test_ec_partial_write_no_parity_preserves_bitmap();
// Test 22
test_c_n_k();
// End
printf("all ok\n");
return 0;
@@ -1538,3 +1541,15 @@ void test_ec_partial_write_no_parity_preserves_bitmap()
free(rmw_buf);
free(write_buf);
}
/***
22. C_N_K test O_o
***/
void test_c_n_k()
{
assert(c_n_k(25, 5) == 53130);
assert(c_n_k(100, 20) == UINT64_MAX);
}

View File

@@ -421,6 +421,7 @@ void osd_t::submit_scrub_subops(osd_op_t *cur_op)
op_data->stripes[i].bmp_buf = (uint8_t*)cur_op->bitmap_buf + clean_entry_bitmap_size * i;
}
cur_op->buf = alloc_read_buffer(op_data->stripes, op_data->stripe_count, 0);
op_data->flags |= OP_DATA_ENOENT_OK;
op_data->fact_ver = 0;
op_data->done = op_data->errors = op_data->errcode = 0;
op_data->n_subops = op_data->stripe_count;
@@ -632,7 +633,7 @@ void osd_t::scrub_check_results(osd_op_t *cur_op)
chunk.loc_bad = LOC_CORRUPTED;
}
}
else if (op_data->stripes[i].read_end > 0 && !op_data->stripes[chunk.role].missing &&
else if (op_data->stripes[i].read_end > 0 && !op_data->stripes[i].missing &&
(chunk.loc_bad & LOC_CORRUPTED))
{
changes++;

View File

@@ -22,7 +22,8 @@ osd_messenger_t::~osd_messenger_t()
void osd_messenger_t::outbox_push(osd_op_t *cur_op)
{
auto cl = clients.at(cur_op->client_id);
cur_op->req.hdr.id = ++cl->send_op_id;
if (cur_op->op_type == OSD_OP_OUT)
cur_op->req.hdr.id = ++cl->send_op_id;
cl->sent_ops[cur_op->req.hdr.id] = cur_op;
}

File diff suppressed because it is too large Load Diff

View File

@@ -36,7 +36,7 @@ public:
}
// Pop the first queued op with the given opcode. Aborts if none.
blockstore_op_t *take(int opcode)
blockstore_op_t *take(int opcode, bool expect_exist = true)
{
for (auto it = queued.begin(); it != queued.end(); ++it)
{
@@ -47,8 +47,12 @@ public:
return op;
}
}
fprintf(stderr, "capturing_bs_t::take: no queued op with opcode %d\n", opcode);
abort();
if (expect_exist)
{
fprintf(stderr, "capturing_bs_t::take: no queued op with opcode %d\n", opcode);
abort();
}
return NULL;
}
};
@@ -303,15 +307,21 @@ struct osd_test_fixture_t
{
if (kv.second->req.hdr.opcode == opcode)
{
auto *op = kv.second;
cl->sent_ops.erase(op->req.hdr.id);
return op;
return kv.second;
}
}
fprintf(stderr, "peer_take: OSD %ju has no sent op with opcode %ju\n", osd_num, opcode);
abort();
}
void peer_complete(osd_op_t *op, int64_t retval)
{
auto *cl = osd->msgr.clients.at(op->client_id);
cl->sent_ops.erase(op->req.hdr.id);
op->reply.hdr.retval = retval;
op->callback(op);
}
// Drive ringloop to flush handle_peers and any pending lambdas.
void pump()
{
@@ -331,8 +341,87 @@ struct osd_test_fixture_t
return osd->msgr.osd_peers.at(osd_num);
}
// Create a regular (non-OSD) incoming client with no real socket. Replies
// routed to it by finish_op -> outbox_push land in cl->sent_ops (see the
// mock messenger). Returns the new client_id.
uint64_t connect_client()
{
auto *msgr = &osd->msgr;
auto *cl = new osd_client_t();
cl->client_id = msgr->next_client_id++;
cl->osd_num = 0;
cl->peer_fd = -1;
cl->peer_state = PEER_CONNECTED;
cl->is_incoming = true;
msgr->clients[cl->client_id] = cl;
return cl->client_id;
}
osd_client_t *client(uint64_t client_id)
{
auto it = osd->msgr.clients.find(client_id);
return it == osd->msgr.clients.end() ? nullptr : it->second;
}
bool has_client(uint64_t client_id)
{
return osd->msgr.clients.find(client_id) != osd->msgr.clients.end();
}
pg_t &pg(pool_id_t pool, pg_num_t num)
{
return osd->pgs.at({ .pool_id = pool, .pg_num = num });
}
void bs_zero_read_ok(uint64_t version)
{
auto *zr = bs->take(BS_OP_READ);
assert(zr->len == 0);
zr->version = version;
zr->retval = version ? 0 : -ENOENT;
zr->callback(zr);
}
void bs_write_ok(uint64_t opcode, uint64_t version)
{
auto *wr = bs->take(opcode);
wr->version = version;
wr->retval = wr->len;
wr->callback(wr);
}
void peer_write_ok(osd_num_t peer, uint64_t opcode, uint64_t version)
{
auto *pw = peer_take(peer, opcode);
if (opcode == OSD_OP_SEC_DELETE)
{
pw->reply.sec_del.version = version;
peer_complete(pw, 0);
}
else
{
pw->reply.sec_rw.version = version;
peer_complete(pw, pw->req.sec_rw.len);
}
}
bool has_pg(pool_id_t pool, pg_num_t num)
{
return osd->pgs.count({ .pool_id = pool, .pg_num = num }) > 0;
}
bool has_dirty_pg(pool_id_t pool, pg_num_t num)
{
return osd->dirty_pgs.count({ .pool_id = pool, .pg_num = num }) > 0;
}
bool has_dirty_osd(osd_num_t num)
{
return osd->dirty_osds.count(num) > 0;
}
size_t syncs_in_progress_size()
{
return osd->syncs_in_progress.size();
}
};

View File

@@ -57,6 +57,19 @@ struct bs_test_t
}
}
void force_compaction()
{
bs->flusher->dump_diagnostics();
bs->flusher->request_trim();
while (bs->heap->get_compact_queue_size())
ringloop->loop();
while (bs->flusher->is_active())
ringloop->loop();
bs->flusher->release_trim();
// Check that compaction succeeded
assert(!bs->heap->get_to_compact_count());
}
void default_cfg()
{
config["data_device"] = "./test_data.bin";
@@ -330,15 +343,7 @@ static void test_fsync(bool separate_meta)
assert(is_zero(op2.buf+24*1024, 104*1024));
// Trigger & wait compaction
test.bs->flusher->dump_diagnostics();
test.bs->flusher->request_trim();
while (test.bs->heap->get_compact_queue_size())
test.ringloop->loop();
while (test.bs->flusher->is_active())
test.ringloop->loop();
test.bs->flusher->release_trim();
// Check that compaction succeeded
assert(!test.bs->heap->get_to_compact_count());
test.force_compaction();
// Restart and check data again
test.destroy_bs();
@@ -447,6 +452,7 @@ static void test_padded_csum_intent(bool perfect)
assert(!test.bs->heap->prev(wr));
// Trigger & wait compaction
test.bs->flusher->dump_diagnostics();
test.bs->flusher->request_trim();
while (test.bs->heap->get_compact_queue_size())
test.ringloop->loop();
@@ -666,14 +672,7 @@ static void test_compact_rollback()
assert(op.retval == 0);
// Trigger & wait compaction
test.bs->flusher->request_trim();
while (test.bs->heap->get_compact_queue_size())
test.ringloop->loop();
while (test.bs->flusher->is_active())
test.ringloop->loop();
test.bs->flusher->release_trim();
// Check that compaction succeeded
assert(!test.bs->heap->get_to_compact_count());
test.force_compaction();
// Check that the object does not exist
printf("checking that the object does not exist\n");
@@ -834,6 +833,149 @@ static void test_fsync_batch_big()
free(op2.buf);
}
static void test_padded_csum_sparse_leading_hole()
{
printf("\n-- test_padded_csum_sparse_leading_hole\n");
bs_test_t test;
test.default_cfg();
test.config["csum_block_size"] = "16384";
test.init();
// Initial write at offset=20K, len=4K on a fresh object.
// The csum block is [16K..32K); granule [16K..20K) is a leading hole.
printf("writing 20+4K\n");
blockstore_op_t op;
op.opcode = BS_OP_WRITE_STABLE;
op.oid = { .inode = 1, .stripe = 0 };
op.version = 1;
op.offset = 20*1024;
op.len = 4096;
op.buf = (uint8_t*)memalign_or_die(MEM_ALIGNMENT, 4096);
memset(op.buf, 0xaa, 4096);
test.exec_op(&op);
assert(op.retval == op.len);
// Read it back - without the fix, verify_read_checksums returns -EDOM
// because the recomputed CRC includes zero-padding for [16K..20K) while
// the stored CRC was computed only over [20K..24K).
printf("reading\n");
blockstore_op_t op2;
op2.opcode = BS_OP_READ;
op2.oid = { .inode = 1, .stripe = 0 };
op2.version = UINT64_MAX;
op2.offset = 0;
op2.len = 128*1024;
op2.buf = (uint8_t*)memalign_or_die(MEM_ALIGNMENT, 128*1024);
test.exec_op(&op2);
assert(op2.retval == op2.len);
assert(is_zero(op2.buf, 20*1024));
assert(memcheck(op2.buf+20*1024, 0xaa, 4*1024));
assert(is_zero(op2.buf+24*1024, 104*1024));
// Part 2 - add 2 more small writes
printf("writing 24+4K\n");
op.version = 2;
op.offset = 24*1024;
test.exec_op(&op);
assert(op.retval == op.len);
printf("writing 36+4K\n");
op.version = 3;
op.offset = 36*1024;
test.exec_op(&op);
assert(op.retval == op.len);
printf("reading uncompacted\n");
op2.version = UINT64_MAX;
test.exec_op(&op2);
assert(op2.retval == op2.len);
assert(is_zero(op2.buf, 20*1024));
assert(memcheck(op2.buf+20*1024, 0xaa, 8*1024));
assert(is_zero(op2.buf+28*1024, 8*1024));
assert(memcheck(op2.buf+36*1024, 0xaa, 4*1024));
assert(is_zero(op2.buf+40*1024, 88*1024));
// Trigger & wait compaction
test.force_compaction();
printf("reading compacted\n");
op2.version = UINT64_MAX;
test.exec_op(&op2);
assert(op2.retval == op2.len);
assert(is_zero(op2.buf, 20*1024));
assert(memcheck(op2.buf+20*1024, 0xaa, 8*1024));
assert(is_zero(op2.buf+28*1024, 8*1024));
assert(memcheck(op2.buf+36*1024, 0xaa, 4*1024));
assert(is_zero(op2.buf+40*1024, 88*1024));
free(op.buf);
free(op2.buf);
}
static void test_list_limit()
{
printf("\n-- test_list_limit\n");
bs_test_t test;
test.default_cfg();
test.init();
void *st = test.bs->reshard_start(1, 1, 0x20000, 0);
assert(!st);
printf("writing 1:0 0+4K\n");
blockstore_op_t op;
op.opcode = BS_OP_WRITE_STABLE;
op.oid = { .inode = INODE_WITH_POOL(1, 1), .stripe = 0 };
op.version = 1;
op.offset = 0;
op.len = 4096;
op.buf = (uint8_t*)memalign_or_die(MEM_ALIGNMENT, 4096);
memset(op.buf, 0xaa, 4096);
test.exec_op(&op);
assert(op.retval == op.len);
printf("writing 1:128K 0+4K\n");
op.oid = { .inode = INODE_WITH_POOL(1, 1), .stripe = 128*1024 };
op.version = 1;
test.exec_op(&op);
assert(op.retval == op.len);
printf("writing 1:256K 0+4K\n");
op.oid = { .inode = INODE_WITH_POOL(1, 1), .stripe = 256*1024 };
op.version = 1;
test.exec_op(&op);
assert(op.retval == op.len);
printf("writing 4K+4K unstable\n");
op.oid = { .inode = INODE_WITH_POOL(1, 1), .stripe = 0*1024 };
op.opcode = BS_OP_WRITE;
op.version = 2;
op.offset = 4096;
test.exec_op(&op);
assert(op.retval == op.len);
op.opcode = BS_OP_LIST;
free(op.buf);
op.buf = NULL;
op.min_oid = { .inode = INODE_WITH_POOL(1, 1), .stripe = 0 };
op.max_oid = { .inode = INODE_WITH_POOL(1, 1000), .stripe = 0 };
op.pg_alignment = 128*1024;
op.pg_count = 1;
op.pg_number = 0;
op.list_stable_limit = 1;
test.exec_op(&op);
assert(op.retval == 2);
assert(op.version == 1);
obj_ver_id *lst = (obj_ver_id*)op.buf;
assert((lst[0] == (obj_ver_id){ .oid = { .inode = INODE_WITH_POOL(1, 1), .stripe = 0 }, .version = 1 }));
assert((lst[1] == (obj_ver_id){ .oid = { .inode = INODE_WITH_POOL(1, 1), .stripe = 0 }, .version = 2 }));
free(op.buf);
}
// FIXME Add a simple intent_write / big_intent test
int main(int narg, char *args[])
@@ -844,6 +986,7 @@ int main(int narg, char *args[])
test_intent_over_unstable();
test_padded_csum_intent(false);
test_padded_csum_intent(true);
test_padded_csum_sparse_leading_hole();
test_perfect_csum_interrupted();
test_padded_csum_parallel_read(false, 8192);
test_padded_csum_parallel_read(true, 8192);
@@ -852,5 +995,6 @@ int main(int narg, char *args[])
test_compact_rollback();
test_fsync_almost_batch_big();
test_fsync_batch_big();
test_list_limit();
return 0;
}

View File

@@ -2719,6 +2719,124 @@ void test_postpone_load()
assert(obj);
assert(count_writes(heap, obj) == 11);
}
printf("OK test_postpone_load\n");
}
void test_big_padded_csum()
{
blockstore_disk_t dsk;
_test_init(dsk, true, [](std::map<std::string, std::string> & config)
{
config["csum_block_size"] = "32k";
});
std::vector<uint8_t> buffer_area(dsk.journal_device_size);
blockstore_heap_t heap(&dsk, buffer_area.data());
heap.finish_recheck();
{
memset(buffer_area.data()+4096, 0xab, 4*1024);
_test_big_write(heap, dsk, 1, 0, 1, 0, true, 36*1024, 4*1024, buffer_area.data()+4096);
object_id oid = { .inode = INODE_WITH_POOL(1, 1), .stripe = 0 };
heap_entry_t *obj = heap.lock_and_read_entry(oid);
assert(obj);
// Read the whole checksum block and verify its checksum
bool csum_ok = heap.calc_block_checksums(
(uint32_t*)obj->get_checksums(&heap) + 1, buffer_area.data(), obj->get_int_bitmap(&heap),
32*1024, 32*1024+32*1024, false, [](uint32_t, uint32_t, uint32_t) {}
);
assert(csum_ok);
// Part 2 - check internal padding
memset(buffer_area.data()+12*1024, 0xab, 4*1024);
std::vector<uint8_t> bitmap(dsk.clean_entry_bitmap_size);
bitmap_set(bitmap.data(), 36*1024, 4*1024, 4096);
bitmap_set(bitmap.data(), 44*1024, 4*1024, 4096);
std::vector<uint8_t> new_csums(dsk.data_block_size/32768*4);
memcpy(new_csums.data(), obj->get_checksums(&heap), new_csums.size());
((uint32_t*)new_csums.data())[1] = crc32c(0, buffer_area.data()+4*1024, 12*1024);
csum_ok = heap.calc_block_checksums(
(uint32_t*)new_csums.data() + 1, buffer_area.data(), bitmap.data(),
32*1024, 32*1024+32*1024, false, [](uint32_t, uint32_t, uint32_t) {}
);
assert(csum_ok);
}
printf("OK test_big_padded_csum\n");
}
void test_start_double_claim_reuse()
{
blockstore_disk_t dsk;
_test_init(dsk, true);
std::vector<uint8_t> buffer_area(dsk.journal_device_size);
blockstore_heap_t heap(&dsk, buffer_area.data());
heap.finish_recheck();
const uint32_t big_write_size = heap.get_big_entry_size();
const uint32_t small_write_size = heap.get_small_entry_size(0, 4096);
const uint32_t del_size = heap.get_simple_entry_size();
assert(big_write_size == 180);
assert(small_write_size == 64);
assert(del_size == 40);
const uint32_t epb = dsk.meta_block_size/big_write_size;
for (int i = 0; i < epb; i++)
{
_test_big_write(heap, dsk, 1, i*0x20000, 1, i*0x20000, true, 0, 0, buffer_area.data(), 0);
assert(heap.get_meta_block_used_space(0) == (i+1)*big_write_size);
}
for (int i = 1; heap.get_meta_block_used_space(0) <= dsk.meta_block_size-del_size; i++)
{
_test_small_write(heap, dsk, 1, i*0x20000, 2, 0, 4096, i*4096, true, buffer_area.data(), false, 0);
}
// Then 1 delete and 1 big_write to the second metadata block, reusing data block of the first object
{
uint32_t mblock = 999999;
object_id oid = { .inode = INODE_WITH_POOL(1, 1), .stripe = 0 };
auto obj = heap.read_entry(oid);
assert(obj);
int res = heap.add_delete(obj, &mblock);
assert(mblock == 1);
assert(res == 0);
heap.start_block_write(mblock);
heap.complete_block_write(mblock);
_test_big_write(heap, dsk, 1, 0x20000, 1, 0, true, 0, 0, buffer_area.data(), 1);
}
// Persist
std::vector<uint8_t> tmp;
tmp.resize(2*dsk.meta_block_size);
heap.get_meta_block(0, tmp.data());
heap.get_meta_block(1, tmp.data()+dsk.meta_block_size);
{
// reload heap and check that delete is not discarded
blockstore_heap_t heap(&dsk, buffer_area.data());
uint64_t entries_loaded;
heap.load_blocks(0, 2*dsk.meta_block_size, tmp.data(), false, entries_loaded);
heap.finish_load();
bool done = heap.recheck_small_writes([&](bool, uint64_t, uint64_t, uint8_t*, std::function<void()> cb) {}, 1);
assert(done);
heap.finish_recheck();
auto mod = heap.get_recheck_modified_blocks();
assert(mod.size() == 1);
assert(mod[0] == 0);
object_id oid = { .inode = INODE_WITH_POOL(1, 1), .stripe = 0 };
auto obj = heap.read_entry(oid);
assert(obj);
assert(obj->entry_type == (BS_HEAP_DELETE|BS_HEAP_STABLE));
assert(!heap.prev(obj));
}
printf("OK test_start_double_claim_reuse\n");
}
// FIXME: Add a test for big_intent, incl. explicit_complete with big_intent over big_write over deletion over big_write :)
@@ -2759,5 +2877,7 @@ int main(int narg, char *args[])
test_explicit_complete();
test_skip_double_claim();
test_postpone_load();
test_big_padded_csum();
test_start_double_claim_reuse();
return 0;
}

View File

@@ -132,4 +132,4 @@ echo leak:librbd >> testdata/lsan-suppress.txt
echo leak:_M_mutate >> testdata/lsan-suppress.txt
echo leak:_M_assign >> testdata/lsan-suppress.txt
export LSAN_OPTIONS=report_objects=true:suppressions=`pwd`/testdata/lsan-suppress.txt
export ASAN_OPTIONS=verify_asan_link_order=false:abort_on_error=1
export ASAN_OPTIONS=verify_asan_link_order=false:abort_on_error=1:handle_abort=1

View File

@@ -23,9 +23,13 @@ kill_etcds()
start_etcd 3
}
kill_etcds &
$VITASTOR_FIO -bs=4k -direct=1 -iodepth=1 -fsync=1 -rw=randwrite \
-pool=1 -inode=1 -size=128M -cluster_log_level=10 -runtime=30
-pool=1 -inode=1 -size=128M -cluster_log_level=10 -runtime=30 &
FIO_PID=$!
# Kill in foreground because otherwise antietcds are not killed by jobs -p
kill_etcds
wait $FIO_PID
format_green OK