Skip to content

Commit 6bce7ad

Browse files
committed
lower the minimum C++ standard to C++20
1 parent eee7d19 commit 6bce7ad

9 files changed

Lines changed: 95 additions & 79 deletions

File tree

‎CMakeLists.txt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ FetchContent_Declare(
4545

4646
add_library(ublkcpp INTERFACE)
4747
target_include_directories(ublkcpp INTERFACE include)
48-
target_compile_features(ublkcpp INTERFACE cxx_std_23) # TODO: cxx_std_26
48+
target_compile_features(ublkcpp INTERFACE cxx_std_20)
4949
if(UBLKCPP_USE_URING_CMD128)
5050
target_compile_definitions(ublkcpp INTERFACE UBLKCPP_USE_URING_CMD128)
5151
endif()

‎bin/ublkctl.cpp‎

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
#include <cstdlib>
1212
#include <fcntl.h>
1313
#include <filesystem>
14+
#include <format>
1415
#include <iostream>
15-
#include <print>
1616
#include <sched.h>
1717
#include <string>
1818
#include <ublk.hpp>
@@ -127,18 +127,24 @@ std::string flags_str(uint64_t flags) noexcept {
127127

128128
void dump_dev_info(uint32_t dev_id, const ublksrv_ctrl_dev_info &info,
129129
const ublk_params &params) {
130-
std::println("dev id {}: nr_hw_queues {} queue_depth {} block size {} "
131-
"dev_capacity {}",
132-
dev_id, info.nr_hw_queues, info.queue_depth,
133-
1U << params.basic.logical_bs_shift, params.basic.dev_sectors);
134-
std::println("\tmax rq size {} daemon pid {} state {}",
135-
info.max_io_buf_bytes, info.ublksrv_pid,
136-
state_str(info.state));
137-
std::println("\tflags 0x{:x} [{}]", info.flags, flags_str(info.flags));
138-
std::println("\tublkc: {}:{} ublkb: {}:{} owner: {}:{}",
139-
params.devt.char_major, params.devt.char_minor,
140-
params.devt.disk_major, params.devt.disk_minor, info.owner_uid,
141-
info.owner_gid);
130+
std::cout << std::format("dev id {}: nr_hw_queues {} queue_depth {} block "
131+
"size {} dev_capacity {}",
132+
dev_id, info.nr_hw_queues, info.queue_depth,
133+
1U << params.basic.logical_bs_shift,
134+
params.basic.dev_sectors)
135+
<< '\n';
136+
std::cout << std::format("\tmax rq size {} daemon pid {} state {}",
137+
info.max_io_buf_bytes, info.ublksrv_pid,
138+
state_str(info.state))
139+
<< '\n';
140+
std::cout << std::format("\tflags 0x{:x} [{}]", info.flags,
141+
flags_str(info.flags))
142+
<< '\n';
143+
std::cout << std::format("\tublkc: {}:{} ublkb: {}:{} owner: {}:{}",
144+
params.devt.char_major, params.devt.char_minor,
145+
params.devt.disk_major, params.devt.disk_minor,
146+
info.owner_uid, info.owner_gid)
147+
<< '\n';
142148
}
143149

144150
std::string cpu_str(const cpu_set_t &cpuset) noexcept {
@@ -171,7 +177,9 @@ ex::task<void> dump_queue_affinity(int ctrl_fd,
171177
for (uint16_t q_id = 0; q_id < info.nr_hw_queues; q_id++) {
172178
cpu_set_t cpuset;
173179
co_await ublk::get_queue_affinity(ctrl_fd, info.dev_id, q_id, &cpuset);
174-
std::println("\tqueue {}: affinity({})", q_id, cpu_str(cpuset));
180+
std::cout << std::format("\tqueue {}: affinity({})", q_id,
181+
cpu_str(cpuset))
182+
<< '\n';
175183
}
176184
}
177185

@@ -253,10 +261,11 @@ ex::task<void> run_cmd(int ctrl_fd, const FeaturesCmd &) {
253261
uint64_t features = 0;
254262
co_await ublk::get_features(ctrl_fd, &features);
255263

256-
std::println("ublk_drv features: 0x{:x}", features);
264+
std::cout << std::format("ublk_drv features: 0x{:x}", features) << '\n';
257265
for (const auto &e : FLAG_TABLE) {
258266
if (features & e.flag)
259-
std::println("\t{:<20s}: 0x{:x}", e.short_name, e.flag);
267+
std::cout << std::format("\t{:<20s}: 0x{:x}", e.short_name, e.flag)
268+
<< '\n';
260269
}
261270
}
262271

@@ -367,7 +376,7 @@ Cmd parse_args(int argc, char *argv[]) {
367376
} else if (app.got_subcommand("quiesce")) {
368377
return quiesce_opts;
369378
} else {
370-
std::unreachable();
379+
std::abort();
371380
}
372381
}
373382

@@ -391,10 +400,10 @@ int main(int argc, char *argv[]) noexcept(false) {
391400
std::visit([&](const auto &c) { return run_cmd(ctrl_fd, c); },
392401
cmd)));
393402
} catch (const std::system_error &e) {
394-
std::println(std::cerr, "ublkctl: {}", e.what());
403+
std::cerr << std::format("ublkctl: {}", e.what()) << '\n';
395404
return e.code().value();
396405
} catch (const std::exception &e) {
397-
std::println(std::cerr, "ublkctl: {}", e.what());
406+
std::cerr << std::format("ublkctl: {}", e.what()) << '\n';
398407
return 1;
399408
}
400409
return 0;

‎examples/loop.cpp‎

Lines changed: 40 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
#include <cstring>
1414
#include <exception>
1515
#include <fcntl.h>
16+
#include <format>
1617
#include <getopt.h>
1718
#include <iostream>
1819
#include <linux/fs.h>
19-
#include <print>
2020
#include <string>
2121
#include <sys/ioctl.h>
2222
#include <sys/signalfd.h>
@@ -163,35 +163,38 @@ static_assert(ublk::QueueHandler<LoopHandler>);
163163

164164
ex::task<void> wait_signal(int ctrl_fd, int signal_fd, uint32_t dev_id,
165165
ex::inplace_stop_source &source) {
166-
std::println("ublk-loop: ublk device {} is running...", dev_id);
166+
std::cout << std::format("ublk-loop: ublk device {} is running...", dev_id)
167+
<< '\n';
167168
auto parent_token = co_await ex::read_env(ex::get_stop_token);
168-
auto stop_request = [&] noexcept { source.request_stop(); };
169+
auto stop_request = [&]() noexcept { source.request_stop(); };
169170
ex::inplace_stop_callback<decltype(stop_request)> cb{
170171
parent_token, std::move(stop_request)};
171172
signalfd_siginfo si;
172173
co_await (condy::async_read(signal_fd, condy::buffer(&si, sizeof(si)), 0) |
173174
ex::write_env(ex::prop{ex::get_stop_token, source.get_token()}));
174-
std::println("ublk-loop: received signal {}, shutting down...",
175-
si.ssi_signo);
175+
std::cout << std::format("ublk-loop: received signal {}, shutting down...",
176+
si.ssi_signo)
177+
<< '\n';
176178
co_await ublk::stop_dev(ctrl_fd, dev_id);
177179
}
178180

179181
void print_usage(const char *prog) {
180-
std::println("Usage: {} [OPTIONS] -f <backing_file>", prog);
181-
std::println(
182-
"Run a ublk loop device backed by a regular file or block device.");
183-
std::println();
184-
std::println("Options:");
185-
std::println(" -f <file> backing file or block device (required)");
186-
std::println(
187-
" -n <dev_id> ublk device id, -1: auto-allocation (default)");
188-
std::println(" -q <queues> nr_hw_queues (default: 1)");
189-
std::println(
190-
" -d <depth> queue depth, max in-flight io commands (default: 64)");
191-
std::println(" -b <bytes> io buffer size (default: 524288)");
192-
std::println(
193-
" -p enable UBLK_F_UNPRIVILEGED_DEV (unprivileged mode)");
194-
std::println(" -h show this help and exit");
182+
std::cout << std::format("Usage: {} [OPTIONS] -f <backing_file>", prog)
183+
<< '\n';
184+
std::cout << "Run a ublk loop device backed by a regular file or block "
185+
"device.\n";
186+
std::cout << '\n';
187+
std::cout << "Options:\n";
188+
std::cout << " -f <file> backing file or block device (required)\n";
189+
std::cout << " -n <dev_id> ublk device id, -1: auto-allocation "
190+
"(default)\n";
191+
std::cout << " -q <queues> nr_hw_queues (default: 1)\n";
192+
std::cout << " -d <depth> queue depth, max in-flight io commands "
193+
"(default: 64)\n";
194+
std::cout << " -b <bytes> io buffer size (default: 524288)\n";
195+
std::cout << " -p enable UBLK_F_UNPRIVILEGED_DEV "
196+
"(unprivileged mode)\n";
197+
std::cout << " -h show this help and exit\n";
195198
}
196199

197200
} // namespace
@@ -245,24 +248,26 @@ int main(int argc, char *argv[]) noexcept(false) {
245248
"open backing file");
246249
}
247250
auto d_backing =
248-
ublk::detail::defer([&] noexcept { close(backing_fd); });
251+
ublk::detail::defer([&]() noexcept { close(backing_fd); });
249252

250253
int flags = fcntl(backing_fd, F_GETFL);
251254
if (flags >= 0 && fcntl(backing_fd, F_SETFL, flags | O_DIRECT) < 0) {
252-
std::println(
253-
std::cerr,
254-
"ublk-loop: failed to set O_DIRECT on backing file: {}",
255-
std::strerror(errno));
255+
std::cerr << std::format(
256+
"ublk-loop: failed to set O_DIRECT on backing "
257+
"file: {}",
258+
std::strerror(errno))
259+
<< '\n';
256260
}
257261

258262
FileInfo file_info;
259263
lo_file_size(backing_fd, file_info);
260264
uint64_t dev_sectors = file_info.size / SECTOR_SIZE;
261-
std::println("ublk-loop: backing file {} ({} bytes, {} sectors, "
262-
"logical {}B, physical {}B)",
263-
backing_path, file_info.size, dev_sectors,
264-
1u << file_info.logical_bs_shift,
265-
1u << file_info.physical_bs_shift);
265+
std::cout << std::format("ublk-loop: backing file {} ({} bytes, {}"
266+
" sectors, logical {}B, physical {}B)",
267+
backing_path, file_info.size, dev_sectors,
268+
1u << file_info.logical_bs_shift,
269+
1u << file_info.physical_bs_shift)
270+
<< '\n';
266271

267272
sigset_t mask;
268273
sigemptyset(&mask);
@@ -274,20 +279,20 @@ int main(int argc, char *argv[]) noexcept(false) {
274279
if (signal_fd < 0) {
275280
throw std::system_error(errno, std::generic_category(), "signalfd");
276281
}
277-
auto d = ublk::detail::defer([&] noexcept { close(signal_fd); });
282+
auto d = ublk::detail::defer([&]() noexcept { close(signal_fd); });
278283

279284
int ctrl_fd = open("/dev/ublk-control", O_RDWR | O_CLOEXEC);
280285
if (ctrl_fd < 0) {
281286
throw std::system_error(errno, std::generic_category(),
282287
"open /dev/ublk-control");
283288
}
284-
auto d2 = ublk::detail::defer([&] noexcept { close(ctrl_fd); });
289+
auto d2 = ublk::detail::defer([&]() noexcept { close(ctrl_fd); });
285290

286291
condy::RuntimeOptions options;
287292
options.enable_sqe128();
288293
condy::Runtime runtime(options);
289294
std::jthread loop([&]() { runtime.run(); });
290-
auto d3 = ublk::detail::defer([&] noexcept { runtime.allow_exit(); });
295+
auto d3 = ublk::detail::defer([&]() noexcept { runtime.allow_exit(); });
291296
ex::scheduler auto sched = condy::get_scheduler(runtime);
292297

293298
uint64_t features;
@@ -334,10 +339,10 @@ int main(int argc, char *argv[]) noexcept(false) {
334339

335340
ex::sync_wait(ex::starts_on(sched, s));
336341
} catch (const std::system_error &e) {
337-
std::println(std::cerr, "ublk-loop: {}", e.what());
342+
std::cerr << std::format("ublk-loop: {}", e.what()) << '\n';
338343
return e.code().value();
339344
} catch (const std::exception &e) {
340-
std::println(std::cerr, "ublk-loop: {}", e.what());
345+
std::cerr << std::format("ublk-loop: {}", e.what()) << '\n';
341346
return 1;
342347
}
343348

‎examples/nop.cpp‎

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
#include <cstdint>
1212
#include <exception>
1313
#include <fcntl.h>
14+
#include <format>
1415
#include <getopt.h>
1516
#include <iostream>
16-
#include <print>
1717
#include <sys/signalfd.h>
1818
#include <system_error>
1919
#include <thread>
@@ -46,26 +46,28 @@ void prep_params(ublk_params &params,
4646
}
4747

4848
void print_usage(const char *prog) {
49-
std::println("Usage: {} -n <dev_id>", prog);
50-
std::println("Run a no-op ublk block device.");
51-
std::println();
52-
std::println("Options:");
53-
std::println(" -n <dev_id> ublk device id to use");
54-
std::println(" -h show this help and exit");
49+
std::cout << std::format("Usage: {} -n <dev_id>", prog) << '\n';
50+
std::cout << "Run a no-op ublk block device.\n";
51+
std::cout << '\n';
52+
std::cout << "Options:\n";
53+
std::cout << " -n <dev_id> ublk device id to use\n";
54+
std::cout << " -h show this help and exit\n";
5555
}
5656

5757
ex::task<void> wait_signal(int ctrl_fd, int signal_fd, uint32_t dev_id,
5858
ex::inplace_stop_source &source) {
59-
std::println("ublk-nop: ublk device {} is running...", dev_id);
59+
std::cout << std::format("ublk-nop: ublk device {} is running...", dev_id)
60+
<< '\n';
6061
auto parent_token = co_await ex::read_env(ex::get_stop_token);
61-
auto stop_request = [&] noexcept { source.request_stop(); };
62+
auto stop_request = [&]() noexcept { source.request_stop(); };
6263
ex::inplace_stop_callback<decltype(stop_request)> cb{
6364
parent_token, std::move(stop_request)};
6465
signalfd_siginfo si;
6566
co_await (condy::async_read(signal_fd, condy::buffer(&si, sizeof(si)), 0) |
6667
ex::write_env(ex::prop{ex::get_stop_token, source.get_token()}));
67-
std::println("ublk-nop: received signal {}, shutting down...",
68-
si.ssi_signo);
68+
std::cout << std::format("ublk-nop: received signal {}, shutting down...",
69+
si.ssi_signo)
70+
<< '\n';
6971
co_await ublk::stop_dev(ctrl_fd, dev_id);
7072
}
7173

@@ -96,20 +98,20 @@ int main(int argc, char *argv[]) noexcept(false) {
9698
if (signal_fd < 0) {
9799
throw std::system_error(errno, std::generic_category(), "signalfd");
98100
}
99-
auto d = ublk::detail::defer([&] noexcept { close(signal_fd); });
101+
auto d = ublk::detail::defer([&]() noexcept { close(signal_fd); });
100102

101103
int ctrl_fd = open("/dev/ublk-control", O_RDWR | O_CLOEXEC);
102104
if (ctrl_fd < 0) {
103105
throw std::system_error(errno, std::generic_category(),
104106
"open /dev/ublk-control");
105107
}
106-
auto d2 = ublk::detail::defer([&] noexcept { close(ctrl_fd); });
108+
auto d2 = ublk::detail::defer([&]() noexcept { close(ctrl_fd); });
107109

108110
condy::RuntimeOptions options;
109111
options.enable_sqe128();
110112
condy::Runtime runtime(options);
111113
std::jthread loop([&]() { runtime.run(); });
112-
auto d3 = ublk::detail::defer([&] noexcept { runtime.allow_exit(); });
114+
auto d3 = ublk::detail::defer([&]() noexcept { runtime.allow_exit(); });
113115
ex::scheduler auto sched = condy::get_scheduler(runtime);
114116

115117
uint64_t features;
@@ -154,10 +156,10 @@ int main(int argc, char *argv[]) noexcept(false) {
154156

155157
ex::sync_wait(ex::starts_on(sched, s));
156158
} catch (const std::system_error &e) {
157-
std::println(std::cerr, "ublk-nop: {}", e.what());
159+
std::cerr << std::format("ublk-nop: {}", e.what()) << '\n';
158160
return e.code().value();
159161
} catch (const std::exception &e) {
160-
std::println(std::cerr, "ublk-nop: {}", e.what());
162+
std::cerr << std::format("ublk-nop: {}", e.what()) << '\n';
161163
return 1;
162164
}
163165

‎include/ublk/detail/daemon.hpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ struct daemon_run_t {
137137

138138
std::string path = dev_path(dev_id);
139139
int ublkc_fd = co_await condy::async_open(path.c_str(), O_RDWR, 0);
140-
auto d = defer([&] noexcept { close(ublkc_fd); });
140+
auto d = defer([&]() noexcept { close(ublkc_fd); });
141141

142142
ex::simple_counting_scope scope;
143143
AllocVector<std::exception_ptr, decltype(alloc)> errs(info.nr_hw_queues,

‎include/ublk/detail/io.hpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ struct io_run_dev_t {
4242
constexpr int UBLKC_FD = 0;
4343
auto &fd_table = condy::current_runtime().fd_table();
4444
auto r = fd_table.update(UBLKC_FD, &ublkc_fd, 1);
45-
auto d = defer([&] noexcept {
45+
auto d = defer([&]() noexcept {
4646
if (r >= 0) {
4747
int fd = -1;
4848
fd_table.update(UBLKC_FD, &fd, 1); // unregister

‎include/ublk/detail/io_loop.hpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class IoLoop {
3333
"buffer_table init");
3434
}
3535
}
36-
thread_ = std::jthread([this, cpuset] { run_(cpuset); });
36+
thread_ = std::jthread([this, cpuset]() { run_(cpuset); });
3737
}
3838

3939
IoLoop(const IoLoop &) = delete;

‎include/ublk/detail/queue.hpp‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ template <typename Fd, IoHandler Handler, typename Alloc> class IoQueue {
116116
queue_depth_(queue_depth), max_io_buf_bytes_(max_io_buf_bytes),
117117
handler_(handler), alloc_(alloc) {
118118
bool ok = false;
119-
auto d = defer([&] noexcept {
119+
auto d = defer([&]() noexcept {
120120
if (!ok) {
121121
cleanup_();
122122
}
@@ -303,7 +303,7 @@ template <typename Fd, IoHandler Handler, typename Alloc> class BatchIoQueue {
303303
queue_depth_(queue_depth), max_io_buf_bytes_(max_io_buf_bytes),
304304
handler_(handler), alloc_(alloc) {
305305
bool ok = false;
306-
auto d = defer([&] noexcept {
306+
auto d = defer([&]() noexcept {
307307
if (!ok) {
308308
cleanup_();
309309
}
@@ -413,7 +413,7 @@ template <typename Fd, IoHandler Handler, typename Alloc> class BatchIoQueue {
413413
ex::upon_error([&, tag](const std::exception_ptr &ep) noexcept {
414414
worker_errs[tag] = ep;
415415
}) |
416-
ex::then([&] noexcept {
416+
ex::then([&]() noexcept {
417417
if (--running_workers == 0) {
418418
flusher.futex.notify_one();
419419
}

0 commit comments

Comments
 (0)