From dc7988b845be51ada1cd62a25137f760d60b0063 Mon Sep 17 00:00:00 2001 From: Denis Pronin Date: Mon, 7 Mar 2022 22:21:19 +0300 Subject: [PATCH] fio is switched to C++ Signed-off-by: Denis Pronin --- CMakeLists.txt | 232 ++++---- Makefile | 156 +++--- backend.c => backend.cpp | 37 +- blktrace.c => blktrace.cpp | 30 +- blktrace.h | 8 + ...o_text_helpers.c => cairo_text_helpers.cpp | 3 +- cairo_text_helpers.h | 9 + cconv.c => cconv.cpp | 49 +- cgroup.c => cgroup.cpp | 16 +- cgroup.h | 9 + client.c => client.cpp | 89 +-- client.h | 7 + configure | 39 +- crc/{crc16.c => crc16.cpp} | 8 +- crc/crc16.h | 16 +- crc/{crc32.c => crc32.cpp} | 6 +- crc/crc32.h | 8 + crc/{crc32c-arm64.c => crc32c-arm64.cpp} | 2 +- crc/{crc32c-intel.c => crc32c-intel.cpp} | 2 +- crc/{crc32c.c => crc32c.cpp} | 6 +- crc/crc32c.h | 8 + crc/{crc64.c => crc64.cpp} | 6 +- crc/crc64.h | 8 + crc/{crc7.c => crc7.cpp} | 0 crc/crc7.h | 8 + crc/{fnv.c => fnv.cpp} | 2 +- crc/fnv.h | 8 + crc/{md5.c => md5.cpp} | 3 +- crc/md5.h | 8 + crc/{murmur3.c => murmur3.cpp} | 0 crc/murmur3.h | 8 + crc/{sha1.c => sha1.cpp} | 8 +- crc/sha1.h | 8 + crc/{sha256.c => sha256.cpp} | 0 crc/sha256.h | 8 + crc/{sha3.c => sha3.cpp} | 2 +- crc/sha3.h | 8 + crc/{sha512.c => sha512.cpp} | 2 +- crc/sha512.h | 8 + crc/{test.c => test.cpp} | 31 +- crc/test.h | 8 + crc/{xxhash.c => xxhash.cpp} | 2 +- debug.c => debug.cpp | 4 +- debug.h | 8 + dedupe.c => dedupe.cpp | 4 +- dedupe.h | 9 + diskutil.c => diskutil.cpp | 24 +- diskutil.h | 8 + eta.c => eta.cpp | 20 +- fdp.c => fdp.cpp | 12 +- fdp.h | 8 + fifo.c => fifo.cpp | 14 +- fifo.h | 8 + file.h | 11 + filehash.c => filehash.cpp | 14 +- filehash.h | 8 + filelock.c => filelock.cpp | 15 +- filelock.h | 8 + filesetup.c => filesetup.cpp | 32 +- fio.c => fio.cpp | 2 +- fio.h | 8 + fio_sem.c => fio_sem.cpp | 11 +- fio_sem.h | 8 + fio_time.h | 8 + flist.h | 13 + flow.c => flow.cpp | 25 +- flow.h | 8 + gclient.c => gclient.cpp | 47 +- gclient.h | 8 + gcompat.c => gcompat.cpp | 2 +- gerror.c => gerror.cpp | 10 +- gerror.h | 8 + gettime-thread.c => gettime-thread.cpp | 13 +- gettime.c => gettime.cpp | 52 +- gettime.h | 8 + gfio.c => gfio.cpp | 46 +- ghelpers.c => ghelpers.cpp | 7 +- goptions.c => goptions.cpp | 107 ++-- goptions.h | 8 + graph.c => graph.cpp | 24 +- hash.h | 2 +- helper_thread.c => helper_thread.cpp | 37 +- helper_thread.h | 8 + helpers.c => helpers.cpp | 2 +- idletime.c => idletime.cpp | 29 +- idletime.h | 8 + init.c => init.cpp | 98 ++-- io_ddir.h | 4 +- io_u.c => io_u.cpp | 30 +- io_u.h | 8 + io_u_queue.c => io_u_queue.cpp | 12 +- io_u_queue.h | 8 + ioengines.c => ioengines.cpp | 15 +- ioengines.h | 10 +- iolog.c => iolog.cpp | 87 +-- iolog.h | 8 + json.c => json.cpp | 40 +- json.h | 11 + lib/{axmap.c => axmap.cpp} | 16 +- lib/axmap.h | 8 + lib/{bloom.c => bloom.cpp} | 8 +- lib/bloom.h | 8 + lib/{flist_sort.c => flist_sort.cpp} | 0 lib/{gauss.c => gauss.cpp} | 0 lib/gauss.h | 8 + lib/{getrusage.c => getrusage.cpp} | 0 lib/getrusage.h | 8 + lib/{hweight.c => hweight.cpp} | 0 lib/hweight.h | 8 + lib/{ieee754.c => ieee754.cpp} | 0 lib/ieee754.h | 8 + lib/{lfsr.c => lfsr.cpp} | 0 lib/lfsr.h | 8 + lib/{memalign.c => memalign.cpp} | 12 +- lib/memalign.h | 8 + lib/{memcpy.c => memcpy.cpp} | 34 +- lib/memcpy.h | 8 + lib/{mountcheck.c => mountcheck.cpp} | 0 lib/mountcheck.h | 8 + lib/{num2str.c => num2str.cpp} | 2 +- lib/num2str.h | 8 + lib/{output_buffer.c => output_buffer.cpp} | 6 +- lib/output_buffer.h | 8 + lib/{pattern.c => pattern.cpp} | 17 +- lib/pattern.h | 8 + lib/{prio_tree.c => prio_tree.cpp} | 2 +- lib/prio_tree.h | 8 + lib/{rand.c => rand.cpp} | 15 +- lib/rand.h | 8 + lib/{rbtree.c => rbtree.cpp} | 10 +- lib/rbtree.h | 8 + lib/{strntol.c => strntol.cpp} | 0 lib/{zipf.c => zipf.cpp} | 4 +- lib/zipf.h | 8 + libfio.c => libfio.cpp | 47 +- log.c => log.cpp | 10 +- log.h | 10 +- memory.c => memory.cpp | 8 +- minmax.h | 20 + optgroup.c => optgroup.cpp | 7 +- optgroup.h | 8 + options.c => options.cpp | 529 +++++++++--------- options.h | 8 + os/os-linux.h | 12 +- os/os.h | 8 + oslib/{asprintf.c => asprintf.cpp} | 5 +- oslib/asprintf.h | 8 + oslib/blkzoned.h | 8 + oslib/{getopt_long.c => getopt_long.cpp} | 5 +- oslib/{inet_aton.c => inet_aton.cpp} | 0 oslib/inet_aton.h | 8 + oslib/{libmtd.c => libmtd.cpp} | 22 +- oslib/{libmtd_legacy.c => libmtd_legacy.cpp} | 8 +- .../{linux-blkzoned.c => linux-blkzoned.cpp} | 18 +- ...inux-dev-lookup.c => linux-dev-lookup.cpp} | 6 +- oslib/linux-dev-lookup.h | 8 + oslib/{statx.c => statx.cpp} | 2 +- oslib/statx.h | 9 + oslib/{strcasestr.c => strcasestr.cpp} | 5 +- oslib/strcasestr.h | 8 + oslib/{strlcat.c => strlcat.cpp} | 4 +- oslib/strlcat.h | 8 + oslib/{strndup.c => strndup.cpp} | 5 +- oslib/strndup.h | 8 + oslib/{strsep.c => strsep.cpp} | 3 +- oslib/strsep.h | 8 + parse.c => parse.cpp | 104 ++-- parse.h | 8 + printing.c => printing.cpp | 3 +- printing.h | 9 + profile.c => profile.cpp | 0 profile.h | 8 + profiles/{act.c => act.cpp} | 24 +- profiles/{tiobench.c => tiobench.cpp} | 10 +- pshared.c => pshared.cpp | 5 +- pshared.h | 8 + rate-submit.c => rate-submit.cpp | 20 +- rate-submit.h | 8 + rwlock.c => rwlock.cpp | 13 +- rwlock.h | 8 + server.c => server.cpp | 119 ++-- server.h | 8 + smalloc.c => smalloc.cpp | 31 +- smalloc.h | 9 + stat.c => stat.cpp | 130 ++--- stat.h | 8 + steadystate.c => steadystate.cpp | 12 +- steadystate.h | 8 + td_error.c => td_error.cpp | 0 td_error.h | 8 + thread_options.h | 8 + tickmarks.c => tickmarks.cpp | 12 +- tickmarks.h | 8 + time.c => time.cpp | 13 +- trim.c => trim.cpp | 4 +- trim.h | 8 + verify-state.h | 8 + verify.c => verify.cpp | 161 +++--- verify.h | 8 + workqueue.c => workqueue.cpp | 4 +- workqueue.h | 9 + zbd.c => zbd.cpp | 70 +-- zbd.h | 8 + zone-dist.c => zone-dist.cpp | 11 +- zone-dist.h | 8 + 205 files changed, 2409 insertions(+), 1500 deletions(-) rename backend.c => backend.cpp (98%) rename blktrace.c => blktrace.cpp (95%) rename cairo_text_helpers.c => cairo_text_helpers.cpp (99%) rename cconv.c => cconv.cpp (94%) rename cgroup.c => cgroup.cpp (93%) rename client.c => client.cpp (95%) rename crc/{crc16.c => crc16.cpp} (94%) rename crc/{crc32.c => crc32.cpp} (97%) rename crc/{crc32c-arm64.c => crc32c-arm64.cpp} (98%) rename crc/{crc32c-intel.c => crc32c-intel.cpp} (98%) rename crc/{crc32c.c => crc32c.cpp} (98%) rename crc/{crc64.c => crc64.cpp} (98%) rename crc/{crc7.c => crc7.cpp} (100%) rename crc/{fnv.c => fnv.cpp} (90%) rename crc/{md5.c => md5.cpp} (99%) rename crc/{murmur3.c => murmur3.cpp} (100%) rename crc/{sha1.c => sha1.cpp} (97%) rename crc/{sha256.c => sha256.cpp} (100%) rename crc/{sha3.c => sha3.cpp} (99%) rename crc/{sha512.c => sha512.cpp} (99%) rename crc/{test.c => test.cpp} (90%) rename crc/{xxhash.c => xxhash.cpp} (99%) rename debug.c => debug.cpp (85%) rename dedupe.c => dedupe.cpp (92%) rename diskutil.c => diskutil.cpp (95%) rename eta.c => eta.cpp (97%) rename fdp.c => fdp.cpp (89%) rename fifo.c => fifo.cpp (86%) rename filehash.c => filehash.cpp (91%) rename filelock.c => filelock.cpp (95%) rename filesetup.c => filesetup.cpp (98%) rename fio.c => fio.cpp (95%) rename fio_sem.c => fio_sem.cpp (95%) rename flow.c => flow.cpp (81%) rename gclient.c => gclient.cpp (95%) rename gcompat.c => gcompat.cpp (96%) rename gerror.c => gerror.cpp (92%) rename gettime-thread.c => gettime-thread.cpp (89%) rename gettime.c => gettime.cpp (93%) rename gfio.c => gfio.cpp (97%) rename ghelpers.c => ghelpers.cpp (97%) rename goptions.c => goptions.cpp (92%) rename graph.c => graph.cpp (97%) rename helper_thread.c => helper_thread.cpp (94%) rename helpers.c => helpers.cpp (96%) rename idletime.c => idletime.cpp (95%) rename init.c => init.cpp (96%) rename io_u.c => io_u.cpp (98%) rename io_u_queue.c => io_u_queue.cpp (72%) rename ioengines.c => ioengines.cpp (98%) rename iolog.c => iolog.cpp (93%) rename json.c => json.cpp (85%) rename lib/{axmap.c => axmap.cpp} (96%) rename lib/{bloom.c => bloom.cpp} (90%) rename lib/{flist_sort.c => flist_sort.cpp} (100%) rename lib/{gauss.c => gauss.cpp} (100%) rename lib/{getrusage.c => getrusage.cpp} (100%) rename lib/{hweight.c => hweight.cpp} (100%) rename lib/{ieee754.c => ieee754.cpp} (100%) rename lib/{lfsr.c => lfsr.cpp} (100%) rename lib/{memalign.c => memalign.cpp} (66%) rename lib/{memcpy.c => memcpy.cpp} (89%) rename lib/{mountcheck.c => mountcheck.cpp} (100%) rename lib/{num2str.c => num2str.cpp} (96%) rename lib/{output_buffer.c => output_buffer.cpp} (86%) rename lib/{pattern.c => pattern.cpp} (98%) rename lib/{prio_tree.c => prio_tree.cpp} (99%) rename lib/{rand.c => rand.cpp} (93%) rename lib/{rbtree.c => rbtree.cpp} (96%) rename lib/{strntol.c => strntol.cpp} (100%) rename lib/{zipf.c => zipf.cpp} (98%) rename libfio.c => libfio.cpp (85%) rename log.c => log.cpp (95%) rename memory.c => memory.cpp (96%) rename optgroup.c => optgroup.cpp (97%) rename options.c => options.cpp (97%) rename oslib/{asprintf.c => asprintf.cpp} (94%) rename oslib/{getopt_long.c => getopt_long.cpp} (99%) rename oslib/{inet_aton.c => inet_aton.cpp} (100%) rename oslib/{libmtd.c => libmtd.cpp} (98%) rename oslib/{libmtd_legacy.c => libmtd_legacy.cpp} (97%) rename oslib/{linux-blkzoned.c => linux-blkzoned.cpp} (96%) rename oslib/{linux-dev-lookup.c => linux-dev-lookup.cpp} (96%) rename oslib/{statx.c => statx.cpp} (95%) rename oslib/{strcasestr.c => strcasestr.cpp} (90%) rename oslib/{strlcat.c => strlcat.cpp} (98%) rename oslib/{strndup.c => strndup.cpp} (83%) rename oslib/{strsep.c => strsep.cpp} (95%) rename parse.c => parse.cpp (92%) rename printing.c => printing.cpp (98%) rename profile.c => profile.cpp (100%) rename profiles/{act.c => act.cpp} (92%) rename profiles/{tiobench.c => tiobench.cpp} (96%) rename pshared.c => pshared.cpp (99%) rename rate-submit.c => rate-submit.cpp (93%) rename rwlock.c => rwlock.cpp (87%) rename server.c => server.cpp (95%) rename smalloc.c => smalloc.cpp (94%) rename stat.c => stat.cpp (96%) rename steadystate.c => steadystate.cpp (97%) rename td_error.c => td_error.cpp (100%) rename tickmarks.c => tickmarks.cpp (94%) rename time.c => time.cpp (95%) rename trim.c => trim.cpp (97%) rename verify.c => verify.cpp (87%) rename workqueue.c => workqueue.cpp (97%) rename zbd.c => zbd.cpp (96%) rename zone-dist.c => zone-dist.cpp (80%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0ab1aca683..e0a84019fa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.25 FATAL_ERROR) project(fio VERSION 3.35.0 HOMEPAGE_URL "https://github.com/axboe/fio" - LANGUAGES C + LANGUAGES C CXX DESCRIPTION "Flexible I/O Tester") option(ENABLE_PDB "Enable Windows PDB symbols generation (needs clang/lld)") @@ -184,30 +184,30 @@ message(STATUS "Static build " ${BUILD_STATIC}) include_directories(${CMAKE_CURRENT_LIST_DIR}) set(FIO_SOURCES - backend.c - blktrace.c - cconv.c - cgroup.c - client.c - crc/crc16.c - crc/crc32.c - crc/crc32c-arm64.c - crc/crc32c-intel.c - crc/crc32c.c - crc/crc64.c - crc/crc7.c - crc/fnv.c - crc/md5.c - crc/murmur3.c - crc/sha1.c - crc/sha256.c - crc/sha3.c - crc/sha512.c - crc/test.c - crc/xxhash.c - debug.c - dedupe.c - diskutil.c + backend.cpp + blktrace.cpp + cconv.cpp + cgroup.cpp + client.cpp + crc/crc16.cpp + crc/crc32.cpp + crc/crc32c-arm64.cpp + crc/crc32c-intel.cpp + crc/crc32c.cpp + crc/crc64.cpp + crc/crc7.cpp + crc/fnv.cpp + crc/md5.cpp + crc/murmur3.cpp + crc/sha1.cpp + crc/sha256.cpp + crc/sha3.cpp + crc/sha512.cpp + crc/test.cpp + crc/xxhash.cpp + debug.cpp + dedupe.cpp + diskutil.cpp engines/cpu.c engines/exec.c engines/fileoperations.c @@ -216,67 +216,67 @@ set(FIO_SOURCES engines/net.c engines/null.c engines/sync.c - eta.c - fdp.c - filehash.c - filelock.c - filesetup.c - fio_sem.c - flow.c - gettime-thread.c - gettime.c - helper_thread.c - helpers.c - idletime.c - init.c - io_u.c - io_u_queue.c - ioengines.c - iolog.c - json.c - lib/axmap.c - lib/bloom.c - lib/flist_sort.c - lib/gauss.c - lib/getrusage.c - lib/hweight.c - lib/ieee754.c - lib/lfsr.c - lib/memalign.c - lib/memcpy.c - lib/mountcheck.c - lib/num2str.c - lib/output_buffer.c - lib/pattern.c - lib/prio_tree.c - lib/rand.c - lib/rbtree.c - lib/strntol.c - lib/zipf.c - libfio.c - log.c - memory.c - optgroup.c - options.c - oslib/linux-dev-lookup.c - parse.c - profile.c - profiles/act.c - profiles/tiobench.c - pshared.c - rate-submit.c - rwlock.c - server.c - smalloc.c - stat.c - steadystate.c - td_error.c - time.c - trim.c - verify.c - workqueue.c - zbd.c - zone-dist.c + eta.cpp + fdp.cpp + filehash.cpp + filelock.cpp + filesetup.cpp + fio_sem.cpp + flow.cpp + gettime-thread.cpp + gettime.cpp + helper_thread.cpp + helpers.cpp + idletime.cpp + init.cpp + io_u.cpp + io_u_queue.cpp + ioengines.cpp + iolog.cpp + json.cpp + lib/axmap.cpp + lib/bloom.cpp + lib/flist_sort.cpp + lib/gauss.cpp + lib/getrusage.cpp + lib/hweight.cpp + lib/ieee754.cpp + lib/lfsr.cpp + lib/memalign.cpp + lib/memcpy.cpp + lib/mountcheck.cpp + lib/num2str.cpp + lib/output_buffer.cpp + lib/pattern.cpp + lib/prio_tree.cpp + lib/rand.cpp + lib/rbtree.cpp + lib/strntol.cpp + lib/zipf.cpp + libfio.cpp + log.cpp + memory.cpp + optgroup.cpp + options.cpp + oslib/linux-dev-lookup.cpp + parse.cpp + profile.cpp + profiles/act.cpp + profiles/tiobench.cpp + pshared.cpp + rate-submit.cpp + rwlock.cpp + server.cpp + smalloc.cpp + stat.cpp + steadystate.cpp + td_error.cpp + time.cpp + trim.cpp + verify.cpp + workqueue.cpp + zbd.cpp + zone-dist.cpp ) set(CMAKE_REQUIRED_INCLUDES_DEFAULT) @@ -2432,34 +2432,34 @@ if (CONFIG_DFS) list(APPEND ENGINES http) endif () -list(APPEND FIO_SOURCES oslib/asprintf.c) +list(APPEND FIO_SOURCES oslib/asprintf.cpp) if (NOT CONFIG_STRSEP) - list(APPEND FIO_SOURCES oslib/strsep.c) + list(APPEND FIO_SOURCES oslib/strsep.cpp) endif () if (NOT CONFIG_STRCASESTR) - list(APPEND FIO_SOURCES oslib/strcasestr.c) + list(APPEND FIO_SOURCES oslib/strcasestr.cpp) endif () if (NOT CONFIG_STRLCAT) - list(APPEND FIO_SOURCES oslib/strlcat.c) + list(APPEND FIO_SOURCES oslib/strlcat.cpp) endif () if (NOT CONFIG_HAVE_STRNDUP) - list(APPEND FIO_SOURCES oslib/strndup.c) + list(APPEND FIO_SOURCES oslib/strndup.cpp) endif () if (NOT CONFIG_GETOPT_LONG_ONLY) - list(APPEND FIO_SOURCES oslib/getopt_long.c) + list(APPEND FIO_SOURCES oslib/getopt_long.cpp) endif () if (NOT CONFIG_INET_ATON) - list(APPEND FIO_SOURCES oslib/inet_aton.c) + list(APPEND FIO_SOURCES oslib/inet_aton.cpp) endif () if (NOT CONFIG_HAVE_STATX) - list(APPEND FIO_SOURCES oslib/statx.c) + list(APPEND FIO_SOURCES oslib/statx.cpp) endif () if (CONFIG_GFAPI) @@ -2473,7 +2473,7 @@ if (CONFIG_GFAPI) endif () if (CONFIG_MTD) - list(APPEND FIO_SOURCES engines/mtd.c oslib/libmtd.c oslib/libmtd_legacy.c) + list(APPEND FIO_SOURCES engines/mtd.c oslib/libmtd.cpp oslib/libmtd_legacy.cpp) endif () if (CONFIG_LINUX_DEVDAX) @@ -2512,19 +2512,19 @@ endif () if (${CONFIG_TARGET_OS} MATCHES "Linux|Android") list(APPEND FIO_SOURCES - diskutil.c - fifo.c - blktrace.c - cgroup.c - trim.c + diskutil.cpp + fifo.cpp + blktrace.cpp + cgroup.cpp + trim.cpp engines/sg.c - oslib/linux-dev-lookup.c + oslib/linux-dev-lookup.cpp engines/io_uring.c engines/nvme.c engines/cmdprio.c) if (CONFIG_HAS_BLKZONED) - list(APPEND FIO_SOURCES oslib/linux-blkzoned.c) + list(APPEND FIO_SOURCES oslib/linux-blkzoned.cpp) endif () list(APPEND FIO_LIBRARIES ${CMAKE_DL_LIBS}) @@ -2536,7 +2536,7 @@ if (${CONFIG_TARGET_OS} STREQUAL "Linux") endif () if (${CONFIG_TARGET_OS} STREQUAL "Android") - list(APPEND FIO_SOURCES profiles/tiobench.c) + list(APPEND FIO_SOURCES profiles/tiobench.cpp) list(APPEND FIO_LIBRARIES log) endif () @@ -2549,7 +2549,7 @@ if (${CONFIG_TARGET_OS} STREQUAL "SunOS") endif () if (${CONFIG_TARGET_OS} STREQUAL "FreeBSD") - list(APPEND FIO_SOURCES trim.c) + list(APPEND FIO_SOURCES trim.cpp) list(APPEND FIO_LIBRARIES Threads::Threads ${CMAKE_DL_LIBS} @@ -2570,7 +2570,7 @@ if (${CONFIG_TARGET_OS} STREQUAL "NetBSD") endif () if (${CONFIG_TARGET_OS} STREQUAL "DragonFly") - list(APPEND FIO_SOURCES trim.c) + list(APPEND FIO_SOURCES trim.cpp) list(APPEND FIO_LIBRARIES Threads::Threads rt) @@ -2649,26 +2649,26 @@ add_link_options( $<$:-fuse-ld=lld> ) -add_executable(fio fio.c ${FIO_SOURCES}) +add_executable(fio fio.cpp ${FIO_SOURCES}) target_link_libraries(fio PRIVATE ${FIO_LIBRARIES}) install(TARGETS fio RUNTIME DESTINATION bin) if (CONFIG_GFIO) set(GFIO_SOURCES - graph.c - tickmarks.c - ghelpers.c - goptions.c - gerror.c - gclient.c - gcompat.c - cairo_text_helpers.c - printing.c + graph.cpp + tickmarks.cpp + ghelpers.cpp + goptions.cpp + gerror.cpp + gclient.cpp + gcompat.cpp + cairo_text_helpers.cpp + printing.cpp ) list(APPEND GFIO_SOURCES ${FIO_SOURCES}) list(APPEND GFIO_LIBRARIES ${FIO_LIBRARIES}) - add_executable(gfio gfio.c ${GFIO_SOURCES}) + add_executable(gfio gfio.cpp ${GFIO_SOURCES}) # target_include_directories(gfio PRIVATE ${GFIO_INCLUDE_DIRS}) target_compile_options(gfio PRIVATE ${GFIO_CFLAGS}) target_link_libraries(gfio PRIVATE ${GFIO_LIBRARIES}) diff --git a/Makefile b/Makefile index cc8164b27d..79d68ae25a 100644 --- a/Makefile +++ b/Makefile @@ -22,7 +22,8 @@ endif DEBUGFLAGS = -DFIO_INC_DEBUG CPPFLAGS+= -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -DFIO_INTERNAL $(DEBUGFLAGS) OPTFLAGS= -g -ffast-math -FIO_CFLAGS= -std=gnu99 -Wwrite-strings -Wall -Wdeclaration-after-statement $(OPTFLAGS) $(EXTFLAGS) $(BUILD_CFLAGS) -I. -I$(SRCDIR) +FIO_C_STANDARD = -std=gnu99 +FIO_CFLAGS= -Wwrite-strings -Wall -Wdeclaration-after-statement $(OPTFLAGS) $(EXTFLAGS) $(BUILD_CFLAGS) -I. -I$(SRCDIR) LIBS += -lm $(EXTLIBS) PROGS = fio SCRIPTS = $(addprefix $(SRCDIR)/,tools/fio_generate_plots tools/plot/fio2gnuplot tools/genfio tools/fiologparser.py tools/hist/fiologparser_hist.py tools/hist/fio-histo-log-pctiles.py tools/fio_jsonplus_clat2csv) @@ -46,23 +47,25 @@ ifeq ($(CC),clang) endif ifdef CONFIG_GFIO - PROGS += gfio -endif - -SOURCE := $(sort $(patsubst $(SRCDIR)/%,%,$(wildcard $(SRCDIR)/crc/*.c)) \ - $(patsubst $(SRCDIR)/%,%,$(wildcard $(SRCDIR)/lib/*.c))) \ - gettime.c ioengines.c init.c stat.c log.c time.c filesetup.c \ - eta.c verify.c memory.c io_u.c parse.c fio_sem.c rwlock.c \ - pshared.c options.c \ - smalloc.c filehash.c profile.c debug.c engines/cpu.c \ + PROGS += gfio +endif + +SOURCE_CXX := $(sort $(patsubst $(SRCDIR)/%,%,$(wildcard $(SRCDIR)/crc/*.cpp)) \ + $(patsubst $(SRCDIR)/%,%,$(wildcard $(SRCDIR)/lib/*.cpp))) \ + gettime.cpp ioengines.cpp init.cpp stat.cpp log.cpp time.cpp filesetup.cpp \ + eta.cpp verify.cpp memory.cpp io_u.cpp parse.cpp fio_sem.cpp rwlock.cpp \ + pshared.cpp options.cpp \ + smalloc.cpp filehash.cpp profile.cpp debug.cpp \ + server.cpp client.cpp iolog.cpp backend.cpp libfio.cpp flow.cpp cconv.cpp \ + gettime-thread.cpp helpers.cpp json.cpp idletime.cpp td_error.cpp \ + profiles/tiobench.cpp profiles/act.cpp io_u_queue.cpp filelock.cpp \ + workqueue.cpp rate-submit.cpp optgroup.cpp helper_thread.cpp \ + steadystate.cpp zone-dist.cpp zbd.cpp dedupe.cpp fdp.cpp \ + +SOURCE := engines/cpu.c \ engines/mmap.c engines/sync.c engines/null.c engines/net.c \ engines/ftruncate.c engines/fileoperations.c \ - engines/exec.c \ - server.c client.c iolog.c backend.c libfio.c flow.c cconv.c \ - gettime-thread.c helpers.c json.c idletime.c td_error.c \ - profiles/tiobench.c profiles/act.c io_u_queue.c filelock.c \ - workqueue.c rate-submit.c optgroup.c helper_thread.c \ - steadystate.c zone-dist.c zbd.c dedupe.c fdp.c + engines/exec.c ifdef CONFIG_LIBHDFS HDFSFLAGS= -I $(JAVA_HOME)/include -I $(JAVA_HOME)/include/linux -I $(FIO_LIBHDFS_INCLUDE) @@ -172,27 +175,27 @@ ifdef CONFIG_DFS dfs_LIBS = -luuid -ldaos -ldfs ENGINES += dfs endif -SOURCE += oslib/asprintf.c +SOURCE_CXX += oslib/asprintf.cpp ifndef CONFIG_STRSEP - SOURCE += oslib/strsep.c + SOURCE_CXX += oslib/strsep.cpp endif ifndef CONFIG_STRCASESTR - SOURCE += oslib/strcasestr.c + SOURCE_CXX += oslib/strcasestr.cpp endif ifndef CONFIG_STRLCAT - SOURCE += oslib/strlcat.c + SOURCE_CXX += oslib/strlcat.cpp endif ifndef CONFIG_HAVE_STRNDUP - SOURCE += oslib/strndup.c + SOURCE_CXX += oslib/strndup.cpp endif ifndef CONFIG_GETOPT_LONG_ONLY - SOURCE += oslib/getopt_long.c + SOURCE_CXX += oslib/getopt_long.cpp endif ifndef CONFIG_INET_ATON - SOURCE += oslib/inet_aton.c + SOURCE_CXX += oslib/inet_aton.cpp endif ifndef CONFIG_HAVE_STATX - SOURCE += oslib/statx.c + SOURCE_CXX += oslib/statx.cpp endif ifdef CONFIG_GFAPI SOURCE += engines/glusterfs.c @@ -205,8 +208,8 @@ ifdef CONFIG_GFAPI endif ifdef CONFIG_MTD SOURCE += engines/mtd.c - SOURCE += oslib/libmtd.c - SOURCE += oslib/libmtd_legacy.c + SOURCE_CXX += oslib/libmtd.cpp + SOURCE_CXX += oslib/libmtd_legacy.cpp endif ifdef CONFIG_LINUX_DEVDAX dev-dax_SRCS = engines/dev-dax.c @@ -239,22 +242,21 @@ ifdef CONFIG_LIBBLKIO ENGINES += libblkio endif ifeq ($(CONFIG_TARGET_OS), Linux) - SOURCE += diskutil.c fifo.c blktrace.c cgroup.c trim.c engines/sg.c \ - oslib/linux-dev-lookup.c engines/io_uring.c engines/nvme.c + SOURCE += engines/sg.c engines/io_uring.c engines/nvme.c + SOURCE_CXX += oslib/linux-dev-lookup.cpp diskutil.cpp fifo.cpp blktrace.cpp cgroup.cpp trim.cpp cmdprio_SRCS = engines/cmdprio.c ifdef CONFIG_HAS_BLKZONED - SOURCE += oslib/linux-blkzoned.c + SOURCE_CXX += oslib/linux-blkzoned.cpp endif LIBS += -lpthread -ldl LDFLAGS += -rdynamic endif ifeq ($(CONFIG_TARGET_OS), Android) - SOURCE += diskutil.c fifo.c blktrace.c cgroup.c trim.c profiles/tiobench.c \ - oslib/linux-dev-lookup.c engines/io_uring.c engines/nvme.c \ - engines/sg.c + SOURCE += engines/io_uring.c engines/nvme.c engines/sg.c + SOURCE_CXX += diskutil.cpp fifo.cpp blktrace.cpp cgroup.cpp trim.cpp profiles/tiobench.cpp oslib/linux-dev-lookup.cpp cmdprio_SRCS = engines/cmdprio.c ifdef CONFIG_HAS_BLKZONED - SOURCE += oslib/linux-blkzoned.c + SOURCE_CXX += oslib/linux-blkzoned.cpp endif LIBS += -ldl -llog LDFLAGS += -rdynamic @@ -264,7 +266,7 @@ ifeq ($(CONFIG_TARGET_OS), SunOS) CPPFLAGS += -D__EXTENSIONS__ endif ifeq ($(CONFIG_TARGET_OS), FreeBSD) - SOURCE += trim.c + SOURCE_CXX += trim.cpp LIBS += -lpthread -lrt LDFLAGS += -rdynamic endif @@ -277,7 +279,7 @@ ifeq ($(CONFIG_TARGET_OS), NetBSD) LDFLAGS += -rdynamic endif ifeq ($(CONFIG_TARGET_OS), DragonFly) - SOURCE += trim.c + SOURCE_CXX += trim.cpp LIBS += -lpthread -lrt LDFLAGS += -rdynamic endif @@ -325,16 +327,22 @@ FIO-VERSION-FILE: FORCE @$(SHELL) $(SRCDIR)/FIO-VERSION-GEN -include FIO-VERSION-FILE -override CFLAGS := -DFIO_VERSION='"$(FIO_VERSION)"' $(FIO_CFLAGS) $(CFLAGS) +FIO_CXX_STANDARD = -std=gnu++20 +FIO_CXXFLAGS = $(filter-out -Wdeclaration-after-statement, $(FIO_CFLAGS)) + +override CFLAGS := -DFIO_VERSION='"$(FIO_VERSION)"' $(FIO_C_STANDARD) $(FIO_CFLAGS) $(CFLAGS) +override CXXFLAGS := -DFIO_VERSION='"$(FIO_VERSION)"' $(FIO_CXX_STANDARD) $(FIO_CXXFLAGS) $(CXXFLAGS) $(foreach eng,$(ENGINES),$(eval $(call engine_template,$(eng)))) OBJS := $(SOURCE:.c=.o) +OBJS_CXX += $(SOURCE_CXX:.cpp=.o) FIO_OBJS = $(OBJS) fio.o +FIO_OBJS_CXX = $(OBJS_CXX) -GFIO_OBJS = $(OBJS) gfio.o graph.o tickmarks.o ghelpers.o goptions.o gerror.o \ - gclient.o gcompat.o cairo_text_helpers.o printing.o +GFIO_OBJS = $(OBJS) $(OBJS_CXX) gfio.o graph.o tickmarks.o ghelpers.o goptions.o gerror.o \ + gclient.o gcompat.o cairo_text_helpers.o printing.o ifdef CONFIG_ARITHMETIC FIO_OBJS += lex.yy.o y.tab.o @@ -342,6 +350,7 @@ GFIO_OBJS += lex.yy.o y.tab.o endif -include $(OBJS:.o=.d) +-include $(OBJS_CXX:.o=.d) T_SMALLOC_OBJS = t/stest.o T_SMALLOC_OBJS += gettime.o fio_sem.o pshared.o smalloc.o t/log.o t/debug.o \ @@ -403,6 +412,7 @@ T_TT_PROGS = t/time-test ifneq (,$(findstring -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION,$(CFLAGS))) T_FUZZ_OBJS = t/fuzz/fuzz_parseini.o T_FUZZ_OBJS += $(OBJS) +T_FUZZ_OBJS_CXX = $(OBJS_CXX) ifdef CONFIG_ARITHMETIC T_FUZZ_OBJS += lex.yy.o y.tab.o endif @@ -437,6 +447,7 @@ T_OBJS += $(T_MEMLOCK_OBJS) T_OBJS += $(T_TT_OBJS) T_OBJS += $(T_IOU_RING_OBJS) T_OBJS += $(T_FUZZ_OBJS) +T_OBJS += $(T_FUZZ_OBJS_CXX) ifneq (,$(findstring CYGWIN,$(CONFIG_TARGET_OS))) T_DEDUPE_OBJS += $(WINDOWS_OBJS) @@ -492,6 +503,7 @@ endif ifneq ($(findstring $(MAKEFLAGS),s),s) ifndef V QUIET_CC = @echo ' ' CC $@; + QUIET_CXX = @echo ' ' CXX $@; QUIET_LINK = @echo ' ' LINK $@; QUIET_DEP = @echo ' ' DEP $@; QUIET_YACC = @echo ' ' YACC $@; @@ -537,6 +549,22 @@ all: $(PROGS) $(T_TEST_PROGS) $(UT_PROGS) $(SCRIPTS) $(ENGS_OBJS) FORCE fi @rm -f $*.d.tmp +%.o : %.cpp + @mkdir -p $(dir $@) + $(QUIET_CXX)$(CXX) -o $@ $(CXXFLAGS) $(CPPFLAGS) -c $< + @$(CXX) -MM $(CXXFLAGS) $(CPPFLAGS) $(SRCDIR)/$*.cpp > $*.d + @mv -f $*.d $*.d.tmp + @sed -e 's|.*:|$*.o:|' < $*.d.tmp > $*.d + @if type -p fmt >/dev/null 2>&1; then \ + sed -e 's/.*://' -e 's/\\$$//' < $*.d.tmp | fmt -w 1 | \ + sed -e 's/^ *//' -e 's/$$/:/' >> $*.d; \ + else \ + sed -e 's/.*://' -e 's/\\$$//' < $*.d.tmp | \ + tr -cs "[:graph:]" "\n" | \ + sed -e 's/^ *//' -e '/^$$/ d' -e 's/$$/:/' >> $*.d; \ + fi + @rm -f $*.d.tmp + ifdef CONFIG_ARITHMETIC lex.yy.c: exp/expression-parser.l ifdef CONFIG_LEX_USE_O @@ -574,34 +602,34 @@ exp/test-expression-parser: exp/test-expression-parser.o parse.o: lex.yy.o y.tab.o endif -init.o: init.c FIO-VERSION-FILE +init.o: init.cpp FIO-VERSION-FILE -gcompat.o: gcompat.c gcompat.h - $(QUIET_CC)$(CC) $(CFLAGS) $(GTK_CFLAGS) $(CPPFLAGS) -c $< +gcompat.o: gcompat.cpp gcompat.h + $(QUIET_CXX)$(CXX) $(CXXFLAGS) $(GTK_CXXFLAGS) $(CPPFLAGS) -c $< -goptions.o: goptions.c goptions.h - $(QUIET_CC)$(CC) $(CFLAGS) $(GTK_CFLAGS) $(CPPFLAGS) -c $< +goptions.o: goptions.cpp goptions.h + $(QUIET_CXX)$(CXX) $(CXXFLAGS) $(GTK_CXXFLAGS) $(CPPFLAGS) -c $< -ghelpers.o: ghelpers.c ghelpers.h - $(QUIET_CC)$(CC) $(CFLAGS) $(GTK_CFLAGS) $(CPPFLAGS) -c $< +ghelpers.o: ghelpers.cpp ghelpers.h + $(QUIET_CXX)$(CXX) $(CXXFLAGS) $(GTK_CXXFLAGS) $(CPPFLAGS) -c $< -gerror.o: gerror.c gerror.h - $(QUIET_CC)$(CC) $(CFLAGS) $(GTK_CFLAGS) $(CPPFLAGS) -c $< +gerror.o: gerror.cpp gerror.h + $(QUIET_CXX)$(CXX) $(CXXFLAGS) $(GTK_CXXFLAGS) $(CPPFLAGS) -c $< -gclient.o: gclient.c gclient.h - $(QUIET_CC)$(CC) $(CFLAGS) $(GTK_CFLAGS) $(CPPFLAGS) -c $< +gclient.o: gclient.cpp gclient.h + $(QUIET_CXX)$(CXX) $(CXXFLAGS) $(GTK_CXXFLAGS) $(CPPFLAGS) -c $< -gfio.o: gfio.c ghelpers.c - $(QUIET_CC)$(CC) $(CFLAGS) $(GTK_CFLAGS) $(CPPFLAGS) -c $< +gfio.o: gfio.cpp ghelpers.cpp + $(QUIET_CXX)$(CXX) $(CXXFLAGS) $(GTK_CXXFLAGS) $(CPPFLAGS) -c $< -graph.o: graph.c graph.h - $(QUIET_CC)$(CC) $(CFLAGS) $(GTK_CFLAGS) $(CPPFLAGS) -c $< +graph.o: graph.cpp graph.h + $(QUIET_CXX)$(CXX) $(CXXFLAGS) $(GTK_CXXFLAGS) $(CPPFLAGS) -c $< -cairo_text_helpers.o: cairo_text_helpers.c cairo_text_helpers.h - $(QUIET_CC)$(CC) $(CFLAGS) $(GTK_CFLAGS) $(CPPFLAGS) -c $< +cairo_text_helpers.o: cairo_text_helpers.cpp cairo_text_helpers.h + $(QUIET_CXX)$(CXX) $(CXXFLAGS) $(GTK_CXXFLAGS) $(CPPFLAGS) -c $< -printing.o: printing.c printing.h - $(QUIET_CC)$(CC) $(CFLAGS) $(GTK_CFLAGS) $(CPPFLAGS) -c $< +printing.o: printing.cpp printing.h + $(QUIET_CXX)$(CXX) $(CXXFLAGS) $(GTK_CXXFLAGS) $(CPPFLAGS) -c $< t/io_uring.o: os/linux/io_uring.h t/io_uring: $(T_IOU_RING_OBJS) @@ -619,18 +647,18 @@ t/stest: $(T_SMALLOC_OBJS) t/ieee754: $(T_IEEE_OBJS) $(QUIET_LINK)$(CC) $(LDFLAGS) -o $@ $(T_IEEE_OBJS) $(LIBS) -fio: $(FIO_OBJS) - $(QUIET_LINK)$(CC) $(LDFLAGS) -o $@ $(FIO_OBJS) $(LIBS) $(HDFSLIB) +fio: $(FIO_OBJS) $(FIO_OBJS_CXX) + $(QUIET_LINK)$(CXX) $(LDFLAGS) -o $@ $(FIO_OBJS) $(FIO_OBJS_CXX) $(LIBS) $(HDFSLIB) -t/fuzz/fuzz_parseini: $(T_FUZZ_OBJS) +t/fuzz/fuzz_parseini: $(T_FUZZ_OBJS) $(T_FUZZ_OBJS_CXX) ifndef LIB_FUZZING_ENGINE - $(QUIET_LINK)$(CC) $(LDFLAGS) -o $@ $(T_FUZZ_OBJS) $(LIBS) $(HDFSLIB) + $(QUIET_LINK)$(CXX) $(LDFLAGS) -o $@ $(T_FUZZ_OBJS) $(T_FUZZ_OBJS_CXX) $(LIBS) $(HDFSLIB) else - $(QUIET_LINK)$(CXX) $(LDFLAGS) -o $@ $(T_FUZZ_OBJS) $(LIB_FUZZING_ENGINE) $(LIBS) $(HDFSLIB) + $(QUIET_LINK)$(CXX) $(LDFLAGS) -o $@ $(T_FUZZ_OBJS) $(T_FUZZ_OBJS_CXX) $(LIB_FUZZING_ENGINE) $(LIBS) $(HDFSLIB) endif gfio: $(GFIO_OBJS) - $(QUIET_LINK)$(CC) $(filter-out -static, $(LDFLAGS)) -o gfio $(GFIO_OBJS) $(LIBS) $(GFIO_LIBS) $(GTK_LDFLAGS) $(HDFSLIB) + $(QUIET_LINK)$(CXX) $(filter-out -static, $(LDFLAGS)) -o gfio $(GFIO_OBJS) $(LIBS) $(GFIO_LIBS) $(GTK_LDFLAGS) $(HDFSLIB) t/fio-genzipf: $(T_ZIPF_OBJS) $(QUIET_LINK)$(CC) $(LDFLAGS) -o $@ $(T_ZIPF_OBJS) $(LIBS) @@ -666,7 +694,7 @@ unittests/unittest: $(UT_OBJS) $(UT_TARGET_OBJS) endif clean: FORCE - @rm -f .depend $(FIO_OBJS) $(GFIO_OBJS) $(OBJS) $(T_OBJS) $(UT_OBJS) $(PROGS) $(T_PROGS) $(T_TEST_PROGS) core.* core gfio unittests/unittest FIO-VERSION-FILE *.[do] lib/*.d oslib/*.[do] crc/*.d engines/*.[do] engines/*.so profiles/*.[do] t/*.[do] t/*/*.[do] unittests/*.[do] unittests/*/*.[do] config-host.mak config-host.h y.tab.[ch] lex.yy.c exp/*.[do] lexer.h + @rm -f .depend $(FIO_OBJS) $(FIO_OBJS_CXX) $(GFIO_OBJS) $(OBJS) $(OBJS_CXX) $(T_OBJS) $(UT_OBJS) $(PROGS) $(T_PROGS) $(T_TEST_PROGS) core.* core gfio unittests/unittest FIO-VERSION-FILE *.[do] lib/*.d oslib/*.[do] crc/*.d engines/*.[do] engines/*.so profiles/*.[do] t/*.[do] t/*/*.[do] unittests/*.[do] unittests/*/*.[do] config-host.mak config-host.h y.tab.[ch] lex.yy.c exp/*.[do] lexer.h @rm -f t/fio-btrace2fio t/io_uring t/read-to-pipe-async @rm -rf doc/output diff --git a/backend.c b/backend.cpp similarity index 98% rename from backend.c rename to backend.cpp index 5f0740395b..d1033215fa 100644 --- a/backend.c +++ b/backend.cpp @@ -21,14 +21,15 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * */ -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include + #include #include -#include +#include #include #include "fio.h" @@ -111,7 +112,7 @@ void sig_show_status(int sig) show_running_run_stats(); } -static void set_sig_handlers(void) +static void set_sig_handlers() { struct sigaction act; @@ -215,7 +216,7 @@ static bool check_min_rate(struct thread_data *td, struct timespec *now) for_each_rw_ddir(ddir) { if (td->bytes_done[ddir]) - ret |= __check_min_rate(td, now, ddir); + ret |= __check_min_rate(td, now, static_cast(ddir)); } return ret; @@ -471,7 +472,7 @@ int io_queue_event(struct thread_data *td, struct io_u *io_u, int *ret, } io_u->xfer_buflen = io_u->resid; - io_u->xfer_buf += bytes; + io_u->xfer_buf = reinterpret_cast(io_u->xfer_buf) + bytes; io_u->offset += bytes; if (ddir_rw(io_u->ddir)) @@ -1226,7 +1227,7 @@ static int init_file_completion_logging(struct thread_data *td, return 0; for_each_file(td, f, i) { - f->last_write_comp = scalloc(depth, sizeof(uint64_t)); + f->last_write_comp = static_castlast_write_comp)>(scalloc(depth, sizeof(uint64_t))); if (!f->last_write_comp) goto cleanup; } @@ -1292,7 +1293,7 @@ static int init_io_u(struct thread_data *td) return 1; } - io_u = ptr; + io_u = static_cast(ptr); memset(io_u, 0, sizeof(*io_u)); INIT_FLIST_HEAD(&io_u->verify_list); dprint(FD_MEM, "io_u alloc %p, index %u\n", io_u, i); @@ -1634,7 +1635,7 @@ struct fork_data { */ static void *thread_main(void *data) { - struct fork_data *fd = data; + struct fork_data *fd = static_cast(data); unsigned long long elapsed_us[DDIR_RWDIR_CNT] = { 0, }; struct thread_data *td = fd->td; struct thread_options *o = &td->o; @@ -2181,7 +2182,7 @@ static void reap_threads(unsigned int *nr_running, uint64_t *t_rate, fio_terminate_threads(TERMINATE_ALL, TERMINATE_ALL); } -static bool __check_trigger_file(void) +static bool __check_trigger_file() { struct stat sb; @@ -2198,7 +2199,7 @@ static bool __check_trigger_file(void) return true; } -static bool trigger_timedout(void) +static bool trigger_timedout() { if (trigger_timeout) if (time_since_genesis() >= trigger_timeout) { @@ -2221,7 +2222,7 @@ void exec_trigger(const char *cmd) log_err("fio: failed executing %s trigger\n", cmd); } -void check_trigger_file(void) +void check_trigger_file() { if (__check_trigger_file() || trigger_timedout()) { if (nr_clients) @@ -2470,7 +2471,7 @@ static void run_threads(struct sk_out *sk_out) map[this_jobs++] = td; nr_started++; - fd = calloc(1, sizeof(*fd)); + fd = static_cast(calloc(1, sizeof(*fd))); fd->td = td; fd->sk_out = sk_out; @@ -2597,7 +2598,7 @@ static void run_threads(struct sk_out *sk_out) update_io_ticks(); } -static void free_disk_util(void) +static void free_disk_util() { disk_util_prune_entries(); helper_thread_destroy(); @@ -2641,7 +2642,7 @@ int fio_backend(struct sk_out *sk_out) if (helper_thread_create(startup_sem, sk_out)) log_err("fio: failed to create helper thread\n"); - cgroup_list = smalloc(sizeof(*cgroup_list)); + cgroup_list = static_cast(smalloc(sizeof(*cgroup_list))); if (cgroup_list) INIT_FLIST_HEAD(cgroup_list); diff --git a/blktrace.c b/blktrace.cpp similarity index 95% rename from blktrace.c rename to blktrace.cpp index ef9ce6bffd..560f990bca 100644 --- a/blktrace.c +++ b/blktrace.cpp @@ -1,10 +1,12 @@ /* * blktrace support code for fio */ -#include -#include +#include +#include +#include + #include -#include + #include #include "flist.h" @@ -85,7 +87,7 @@ static void trace_add_open_close_event(struct thread_data *td, int fileno, enum { struct io_piece *ipo; - ipo = calloc(1, sizeof(*ipo)); + ipo = static_cast(calloc(1, sizeof(*ipo))); init_ipo(ipo); ipo->ddir = DDIR_INVAL; @@ -158,7 +160,7 @@ static void store_ipo(struct thread_data *td, unsigned long long offset, { struct io_piece *ipo; - ipo = calloc(1, sizeof(*ipo)); + ipo = static_cast(calloc(1, sizeof(*ipo))); init_ipo(ipo); ipo->offset = offset * 512; @@ -211,7 +213,7 @@ static bool handle_trace_discard(struct thread_data *td, if (td->o.replay_skip & (1u << DDIR_TRIM)) return false; - ipo = calloc(1, sizeof(*ipo)); + ipo = static_cast(calloc(1, sizeof(*ipo))); init_ipo(ipo); fileno = trace_add_file(td, t->device, cache); @@ -288,7 +290,7 @@ static bool handle_trace_flush(struct thread_data *td, struct blk_io_trace *t, if (td->o.replay_skip & (1u << DDIR_SYNC)) return false; - ipo = calloc(1, sizeof(*ipo)); + ipo = static_cast(calloc(1, sizeof(*ipo))); init_ipo(ipo); fileno = trace_add_file(td, t->device, cache); @@ -577,17 +579,17 @@ bool read_blktrace(struct thread_data* td) return false; } - td->o.td_ddir = 0; + td->o.td_ddir = static_cast(0); if (ios[DDIR_READ]) { - td->o.td_ddir |= TD_DDIR_READ; + td->o.td_ddir = static_cast(static_cast(td->o.td_ddir) | TD_DDIR_READ); td->o.max_bs[DDIR_READ] = rw_bs[DDIR_READ]; } if (ios[DDIR_WRITE]) { - td->o.td_ddir |= TD_DDIR_WRITE; + td->o.td_ddir = static_cast(static_cast(td->o.td_ddir) | TD_DDIR_WRITE); td->o.max_bs[DDIR_WRITE] = rw_bs[DDIR_WRITE]; } if (ios[DDIR_TRIM]) { - td->o.td_ddir |= TD_DDIR_TRIM; + td->o.td_ddir = static_cast(static_cast(td->o.td_ddir) | TD_DDIR_TRIM); td->o.max_bs[DDIR_TRIM] = rw_bs[DDIR_TRIM]; } @@ -706,8 +708,8 @@ static int write_trace(FILE *fp, struct blk_io_trace *t) int merge_blktrace_iologs(struct thread_data *td) { int nr_logs = get_max_str_idx(td->o.read_iolog_file); - struct blktrace_cursor *bcs = malloc(sizeof(struct blktrace_cursor) * - nr_logs); + struct blktrace_cursor *bcs = static_cast(malloc(sizeof(struct blktrace_cursor) * + nr_logs)); struct blktrace_cursor *bc; FILE *merge_fp; char *str, *ptr, *name, *merge_buf; @@ -733,7 +735,7 @@ int merge_blktrace_iologs(struct thread_data *td) /* setup output file */ merge_fp = fopen(td->o.merge_blktrace_file, "w"); - merge_buf = malloc(128 * 1024); + merge_buf = static_cast(malloc(128 * 1024)); if (!merge_buf) goto err_out_file; ret = setvbuf(merge_fp, merge_buf, _IOFBF, 128 * 1024); diff --git a/blktrace.h b/blktrace.h index c53b717ba4..a941a91378 100644 --- a/blktrace.h +++ b/blktrace.h @@ -1,6 +1,9 @@ #ifndef FIO_BLKTRACE_H #define FIO_BLKTRACE_H +#ifdef __cplusplus +extern "C" { +#endif #ifdef FIO_HAVE_BLKTRACE @@ -50,4 +53,9 @@ static inline int merge_blktrace_iologs(struct thread_data *td) } #endif + +#ifdef __cplusplus +} +#endif + #endif diff --git a/cairo_text_helpers.c b/cairo_text_helpers.cpp similarity index 99% rename from cairo_text_helpers.c rename to cairo_text_helpers.cpp index 5bdd60219f..d4d3806c7e 100644 --- a/cairo_text_helpers.c +++ b/cairo_text_helpers.cpp @@ -1,8 +1,9 @@ #include "cairo_text_helpers.h" +#include + #include #include -#include static void draw_aligned_text(cairo_t *cr, const char *font, double x, double y, double fontsize, const char *text, int alignment) diff --git a/cairo_text_helpers.h b/cairo_text_helpers.h index d0f52d51ff..81661c46bb 100644 --- a/cairo_text_helpers.h +++ b/cairo_text_helpers.h @@ -3,6 +3,10 @@ #include +#ifdef __cplusplus +extern "C" { +#endif + void draw_centered_text(cairo_t *cr, const char *font, double x, double y, double fontsize, const char *text); @@ -17,4 +21,9 @@ void draw_left_justified_text(cairo_t *cr, const char *font, void draw_vertical_centered_text(cairo_t *cr, const char *font, double x, double y, double fontsize, const char *text); + +#ifdef __cplusplus +} +#endif + #endif diff --git a/cconv.c b/cconv.cpp similarity index 94% rename from cconv.c rename to cconv.cpp index ce6acbe6ab..45a8cfb3fd 100644 --- a/cconv.c +++ b/cconv.cpp @@ -1,4 +1,5 @@ -#include +#include +#include #include "log.h" #include "thread_options.h" @@ -97,7 +98,7 @@ int convert_thread_options_to_cpu(struct thread_options *o, o->allow_create = le32_to_cpu(top->allow_create); o->allow_mounted_write = le32_to_cpu(top->allow_mounted_write); - o->td_ddir = le32_to_cpu(top->td_ddir); + o->td_ddir = static_cast(le32_to_cpu(top->td_ddir)); o->rw_seq = le32_to_cpu(top->rw_seq); o->kb_base = le32_to_cpu(top->kb_base); o->unit_base = le32_to_cpu(top->unit_base); @@ -129,7 +130,7 @@ int convert_thread_options_to_cpu(struct thread_options *o, o->bssplit_nr[i] = le32_to_cpu(top->bssplit_nr[i]); if (o->bssplit_nr[i]) { - o->bssplit[i] = malloc(o->bssplit_nr[i] * sizeof(struct bssplit)); + o->bssplit[i] = static_cast(malloc(o->bssplit_nr[i] * sizeof(struct bssplit))); for (j = 0; j < o->bssplit_nr[i]; j++) { o->bssplit[i][j].bs = le64_to_cpu(top->bssplit[i][j].bs); o->bssplit[i][j].perc = le32_to_cpu(top->bssplit[i][j].perc); @@ -139,7 +140,7 @@ int convert_thread_options_to_cpu(struct thread_options *o, o->zone_split_nr[i] = le32_to_cpu(top->zone_split_nr[i]); if (o->zone_split_nr[i]) { - o->zone_split[i] = malloc(o->zone_split_nr[i] * sizeof(struct zone_split)); + o->zone_split[i] = static_cast(malloc(o->zone_split_nr[i] * sizeof(struct zone_split))); for (j = 0; j < o->zone_split_nr[i]; j++) { o->zone_split[i][j].access_perc = top->zone_split[i][j].access_perc; o->zone_split[i][j].size_perc = top->zone_split[i][j].size_perc; @@ -162,7 +163,7 @@ int convert_thread_options_to_cpu(struct thread_options *o, o->unique_filename = le32_to_cpu(top->unique_filename); o->nr_files = le32_to_cpu(top->nr_files); o->open_files = le32_to_cpu(top->open_files); - o->file_lock_mode = le32_to_cpu(top->file_lock_mode); + o->file_lock_mode = static_cast(le32_to_cpu(top->file_lock_mode)); o->odirect = le32_to_cpu(top->odirect); o->oatomic = le32_to_cpu(top->oatomic); o->invalidate_cache = le32_to_cpu(top->invalidate_cache); @@ -188,10 +189,10 @@ int convert_thread_options_to_cpu(struct thread_options *o, thread_options_pack_size(o) > top_sz) return -EINVAL; - o->verify_pattern = realloc(o->verify_pattern, - o->verify_pattern_bytes); - o->buffer_pattern = realloc(o->buffer_pattern, - o->buffer_pattern_bytes); + o->verify_pattern = static_cast(realloc(o->verify_pattern, + o->verify_pattern_bytes)); + o->buffer_pattern = static_cast(realloc(o->buffer_pattern, + o->buffer_pattern_bytes)); memcpy(o->verify_pattern, top->patterns, o->verify_pattern_bytes); memcpy(o->buffer_pattern, &top->patterns[o->verify_pattern_bytes], o->buffer_pattern_bytes); @@ -256,7 +257,7 @@ int convert_thread_options_to_cpu(struct thread_options *o, o->zone_size = le64_to_cpu(top->zone_size); o->zone_capacity = le64_to_cpu(top->zone_capacity); o->zone_skip = le64_to_cpu(top->zone_skip); - o->zone_mode = le32_to_cpu(top->zone_mode); + o->zone_mode = static_cast(le32_to_cpu(top->zone_mode)); o->max_open_zones = __le32_to_cpu(top->max_open_zones); o->ignore_zone_limits = le32_to_cpu(top->ignore_zone_limits); o->lockmem = le64_to_cpu(top->lockmem); @@ -268,7 +269,7 @@ int convert_thread_options_to_cpu(struct thread_options *o, o->bw_avg_time = le32_to_cpu(top->bw_avg_time); o->iops_avg_time = le32_to_cpu(top->iops_avg_time); o->loops = le32_to_cpu(top->loops); - o->mem_type = le32_to_cpu(top->mem_type); + o->mem_type = static_cast(le32_to_cpu(top->mem_type)); o->mem_align = le32_to_cpu(top->mem_align); o->exit_what = le32_to_cpu(top->exit_what); o->stonewall = le32_to_cpu(top->stonewall); @@ -286,7 +287,7 @@ int convert_thread_options_to_cpu(struct thread_options *o, o->group_reporting = le32_to_cpu(top->group_reporting); o->stats = le32_to_cpu(top->stats); o->fadvise_hint = le32_to_cpu(top->fadvise_hint); - o->fallocate_mode = le32_to_cpu(top->fallocate_mode); + o->fallocate_mode = static_cast(le32_to_cpu(top->fallocate_mode)); o->zero_buffers = le32_to_cpu(top->zero_buffers); o->refill_buffers = le32_to_cpu(top->refill_buffers); o->scramble_buffers = le32_to_cpu(top->scramble_buffers); @@ -298,7 +299,7 @@ int convert_thread_options_to_cpu(struct thread_options *o, o->unified_rw_rep = le32_to_cpu(top->unified_rw_rep); o->gtod_reduce = le32_to_cpu(top->gtod_reduce); o->gtod_cpu = le32_to_cpu(top->gtod_cpu); - o->clocksource = le32_to_cpu(top->clocksource); + o->clocksource = static_cast(le32_to_cpu(top->clocksource)); o->no_stall = le32_to_cpu(top->no_stall); o->trim_percentage = le32_to_cpu(top->trim_percentage); o->trim_batch = le32_to_cpu(top->trim_batch); @@ -308,7 +309,7 @@ int convert_thread_options_to_cpu(struct thread_options *o, o->slat_percentiles = le32_to_cpu(top->slat_percentiles); o->percentile_precision = le32_to_cpu(top->percentile_precision); o->sig_figs = le32_to_cpu(top->sig_figs); - o->continue_on_error = le32_to_cpu(top->continue_on_error); + o->continue_on_error = static_cast(le32_to_cpu(top->continue_on_error)); o->cgroup_weight = le32_to_cpu(top->cgroup_weight); o->cgroup_nodelete = le32_to_cpu(top->cgroup_nodelete); o->uid = le32_to_cpu(top->uid); @@ -398,7 +399,7 @@ void convert_thread_options_to_net(struct thread_options_pack *top, top->allow_create = cpu_to_le32(o->allow_create); top->allow_mounted_write = cpu_to_le32(o->allow_mounted_write); - top->td_ddir = cpu_to_le32(o->td_ddir); + top->td_ddir = cpu_to_le32(static_cast(o->td_ddir)); top->rw_seq = cpu_to_le32(o->rw_seq); top->kb_base = cpu_to_le32(o->kb_base); top->unit_base = cpu_to_le32(o->unit_base); @@ -418,7 +419,7 @@ void convert_thread_options_to_net(struct thread_options_pack *top, top->nr_files = cpu_to_le32(o->nr_files); top->unique_filename = cpu_to_le32(o->unique_filename); top->open_files = cpu_to_le32(o->open_files); - top->file_lock_mode = cpu_to_le32(o->file_lock_mode); + top->file_lock_mode = cpu_to_le32(static_cast(o->file_lock_mode)); top->odirect = cpu_to_le32(o->odirect); top->oatomic = cpu_to_le32(o->oatomic); top->invalidate_cache = cpu_to_le32(o->invalidate_cache); @@ -484,7 +485,7 @@ void convert_thread_options_to_net(struct thread_options_pack *top, top->bw_avg_time = cpu_to_le32(o->bw_avg_time); top->iops_avg_time = cpu_to_le32(o->iops_avg_time); top->loops = cpu_to_le32(o->loops); - top->mem_type = cpu_to_le32(o->mem_type); + top->mem_type = cpu_to_le32(static_cast(o->mem_type)); top->mem_align = cpu_to_le32(o->mem_align); top->exit_what = cpu_to_le32(o->exit_what); top->stonewall = cpu_to_le32(o->stonewall); @@ -502,7 +503,7 @@ void convert_thread_options_to_net(struct thread_options_pack *top, top->group_reporting = cpu_to_le32(o->group_reporting); top->stats = cpu_to_le32(o->stats); top->fadvise_hint = cpu_to_le32(o->fadvise_hint); - top->fallocate_mode = cpu_to_le32(o->fallocate_mode); + top->fallocate_mode = cpu_to_le32(static_cast(o->fallocate_mode)); top->zero_buffers = cpu_to_le32(o->zero_buffers); top->refill_buffers = cpu_to_le32(o->refill_buffers); top->scramble_buffers = cpu_to_le32(o->scramble_buffers); @@ -515,7 +516,7 @@ void convert_thread_options_to_net(struct thread_options_pack *top, top->unified_rw_rep = cpu_to_le32(o->unified_rw_rep); top->gtod_reduce = cpu_to_le32(o->gtod_reduce); top->gtod_cpu = cpu_to_le32(o->gtod_cpu); - top->clocksource = cpu_to_le32(o->clocksource); + top->clocksource = cpu_to_le32(static_cast(o->clocksource)); top->no_stall = cpu_to_le32(o->no_stall); top->trim_percentage = cpu_to_le32(o->trim_percentage); top->trim_batch = cpu_to_le32(o->trim_batch); @@ -525,7 +526,7 @@ void convert_thread_options_to_net(struct thread_options_pack *top, top->slat_percentiles = cpu_to_le32(o->slat_percentiles); top->percentile_precision = cpu_to_le32(o->percentile_precision); top->sig_figs = cpu_to_le32(o->sig_figs); - top->continue_on_error = cpu_to_le32(o->continue_on_error); + top->continue_on_error = cpu_to_le32(static_cast(o->continue_on_error)); top->cgroup_weight = cpu_to_le32(o->cgroup_weight); top->cgroup_nodelete = cpu_to_le32(o->cgroup_nodelete); top->uid = cpu_to_le32(o->uid); @@ -672,15 +673,15 @@ int fio_test_cconv(struct thread_options *__o) int ret; o1.verify_pattern_bytes = 61; - o1.verify_pattern = malloc(o1.verify_pattern_bytes); + o1.verify_pattern = static_cast(malloc(o1.verify_pattern_bytes)); memset(o1.verify_pattern, 'V', o1.verify_pattern_bytes); o1.buffer_pattern_bytes = 15; - o1.buffer_pattern = malloc(o1.buffer_pattern_bytes); + o1.buffer_pattern = static_cast(malloc(o1.buffer_pattern_bytes)); memset(o1.buffer_pattern, 'B', o1.buffer_pattern_bytes); top_sz = thread_options_pack_size(&o1); - top1 = calloc(1, top_sz); - top2 = calloc(1, top_sz); + top1 = static_cast(calloc(1, top_sz)); + top2 = static_cast(calloc(1, top_sz)); convert_thread_options_to_net(top1, &o1); memset(&o2, 0, sizeof(o2)); diff --git a/cgroup.c b/cgroup.cpp similarity index 93% rename from cgroup.c rename to cgroup.cpp index 77e31a4d0e..b4eec7614e 100644 --- a/cgroup.c +++ b/cgroup.cpp @@ -1,10 +1,12 @@ /* * Code related to setting up a blkio cgroup */ -#include -#include +#include +#include + #include #include + #include "fio.h" #include "flist.h" #include "cgroup.h" @@ -43,7 +45,7 @@ static struct cgroup_mnt *find_cgroup_mnt(struct thread_data *td) } if (mnt) { - cgroup_mnt = smalloc(sizeof(*cgroup_mnt)); + cgroup_mnt = static_cast(smalloc(sizeof(*cgroup_mnt))); if (cgroup_mnt) { cgroup_mnt->path = smalloc_strdup(mnt->mnt_dir); if (!cgroup_mnt->path) { @@ -69,7 +71,7 @@ static void add_cgroup(struct thread_data *td, const char *name, if (!lock) return; - cm = smalloc(sizeof(*cm)); + cm = static_cast(smalloc(sizeof(*cm))); if (!cm) { err: log_err("fio: failed to allocate cgroup member\n"); @@ -113,7 +115,7 @@ void cgroup_kill(struct flist_head *clist) static char *get_cgroup_root(struct thread_data *td, struct cgroup_mnt *mnt) { - char *str = malloc(64); + char *str = static_cast(malloc(64)); if (td->o.cgroup) sprintf(str, "%s/%s", mnt->path, td->o.cgroup); @@ -224,14 +226,14 @@ void cgroup_shutdown(struct thread_data *td, struct cgroup_mnt *mnt) sfree(mnt); } -static void fio_init cgroup_init(void) +static void fio_init cgroup_init() { lock = fio_sem_init(FIO_SEM_UNLOCKED); if (!lock) log_err("fio: failed to allocate cgroup lock\n"); } -static void fio_exit cgroup_exit(void) +static void fio_exit cgroup_exit() { fio_sem_remove(lock); } diff --git a/cgroup.h b/cgroup.h index 10313b7dbc..a39bac808d 100644 --- a/cgroup.h +++ b/cgroup.h @@ -1,6 +1,10 @@ #ifndef FIO_CGROUP_H #define FIO_CGROUP_H +#ifdef __cplusplus +extern "C" { +#endif + #ifdef FIO_HAVE_CGROUPS struct cgroup_mnt { @@ -33,4 +37,9 @@ static inline void cgroup_kill(struct flist_head *list) } #endif + +#ifdef __cplusplus +} +#endif + #endif diff --git a/client.c b/client.cpp similarity index 95% rename from client.c rename to client.cpp index c257036bf5..f49a389bf8 100644 --- a/client.c +++ b/client.cpp @@ -1,17 +1,20 @@ -#include -#include +#include +#include +#include +#include + #include -#include #include #include + #include #include #include #include + #include #include #include -#include #ifdef CONFIG_ZLIB #include #endif @@ -39,10 +42,10 @@ struct client_ops const fio_client_ops = { .disk_util = handle_du, .thread_status = handle_ts, .group_stats = handle_gs, - .stop = handle_stop, - .start = handle_start, .eta = client_display_thread_status, .probe = handle_probe, + .stop = handle_stop, + .start = handle_start, .eta_msec = FIO_CLIENT_DEF_ETA_MSEC, .client_type = FIO_CLIENT_TYPE_CLI, }; @@ -88,7 +91,7 @@ static void fio_client_remove_hash(struct fio_client *client) flist_del_init(&client->hash_list); } -static void fio_init fio_client_hash_init(void) +static void fio_init fio_client_hash_init() { int i; @@ -109,7 +112,7 @@ static int read_data(int fd, void *data, size_t size) } else if (!ret) break; else { - data += ret; + data = static_cast(data) + ret; size -= ret; } } @@ -122,7 +125,7 @@ static int read_data(int fd, void *data, size_t size) static int read_ini_data(int fd, void *data, size_t size) { - char *p = data; + char *p = static_cast(data); int ret = 0; FILE *fp; int dupfd; @@ -172,7 +175,7 @@ static int read_ini_data(int fd, void *data, size_t size) return ret; } -static void fio_client_json_init(void) +static void fio_client_json_init() { char time_buf[32]; time_t time_p; @@ -197,7 +200,7 @@ static void fio_client_json_init(void) json_object_add_value_array(root, "disk_util", du_array); } -static void fio_client_json_fini(void) +static void fio_client_json_fini() { struct buf_output out; @@ -340,14 +343,14 @@ static void __fio_client_add_cmd_option(struct fio_client *client, int index; index = client->argc++; - client->argv = realloc(client->argv, sizeof(char *) * client->argc); + client->argv = static_cast(realloc(client->argv, sizeof(char *) * client->argc)); client->argv[index] = strdup(opt); dprint(FD_NET, "client: add cmd %d: %s\n", index, opt); } void fio_client_add_cmd_option(void *cookie, const char *opt) { - struct fio_client *client = cookie; + struct fio_client *client = static_cast(cookie); struct flist_head *entry; if (!client || !opt) @@ -365,11 +368,11 @@ void fio_client_add_cmd_option(void *cookie, const char *opt) } } -static struct fio_client *get_new_client(void) +static struct fio_client *get_new_client() { struct fio_client *client; - client = calloc(1, sizeof(*client)); + client = static_cast(calloc(1, sizeof(*client))); INIT_FLIST_HEAD(&client->list); INIT_FLIST_HEAD(&client->hash_list); @@ -423,7 +426,7 @@ struct fio_client *fio_client_add_explicit(struct client_ops *ops, int fio_client_add_ini_file(void *cookie, const char *ini_file, bool remote) { - struct fio_client *client = cookie; + struct fio_client *client = static_cast(cookie); struct client_file *cf; size_t new_size; void *new_files; @@ -438,7 +441,7 @@ int fio_client_add_ini_file(void *cookie, const char *ini_file, bool remote) if (!new_files) return 1; - client->files = new_files; + client->files = static_castfiles)>(new_files); cf = &client->files[client->nr_files]; cf->file = strdup(ini_file); cf->remote = remote; @@ -448,7 +451,7 @@ int fio_client_add_ini_file(void *cookie, const char *ini_file, bool remote) int fio_client_add(struct client_ops const *ops, const char *hostname, void **cookie) { - struct fio_client *existing = *cookie; + struct fio_client *existing = static_cast(*cookie); struct fio_client *client; if (existing) { @@ -627,7 +630,7 @@ int fio_client_terminate(struct fio_client *client) return fio_net_send_quit(client->fd); } -static void fio_clients_terminate(void) +static void fio_clients_terminate() { struct flist_head *entry; struct fio_client *client; @@ -646,7 +649,7 @@ static void sig_int(int sig) fio_clients_terminate(); } -static void client_signal_handler(void) +static void client_signal_handler() { struct sigaction act; @@ -686,7 +689,7 @@ static int send_client_cmd_line(struct fio_client *client) dprint(FD_NET, "client: send cmdline %d\n", client->argc); - lens = malloc(client->argc * sizeof(unsigned int)); + lens = static_cast(malloc(client->argc * sizeof(unsigned int))); /* * Find out how much mem we need @@ -702,13 +705,13 @@ static int send_client_cmd_line(struct fio_client *client) mem += sizeof(*clp) + (client->argc * sizeof(*cslp)); pdu = malloc(mem); - clp = pdu; + clp = static_cast(pdu); offset = sizeof(*clp); for (i = 0; i < client->argc; i++) { uint16_t arg_len = lens[i]; - cslp = pdu + offset; + cslp = reinterpret_cast((char*)pdu + offset); strcpy((char *) cslp->text, client->argv[i]); cslp->len = cpu_to_le16(arg_len); offset += sizeof(*cslp) + arg_len; @@ -722,7 +725,7 @@ static int send_client_cmd_line(struct fio_client *client) return ret; } -int fio_clients_connect(void) +int fio_clients_connect() { struct fio_client *client; struct flist_head *entry, *tmp; @@ -759,7 +762,7 @@ int fio_start_client(struct fio_client *client) return fio_net_send_simple_cmd(client->fd, FIO_NET_CMD_RUN, 0, NULL); } -int fio_start_all_clients(void) +int fio_start_all_clients() { struct fio_client *client; struct flist_head *entry, *tmp; @@ -792,7 +795,7 @@ static int __fio_client_send_remote_ini(struct fio_client *client, dprint(FD_NET, "send remote ini %s to %s\n", filename, client->hostname); p_size = sizeof(*pdu) + strlen(filename) + 1; - pdu = calloc(1, p_size); + pdu = static_cast(calloc(1, p_size)); pdu->name_len = strlen(filename); strcpy((char *) pdu->file, filename); pdu->client_type = cpu_to_le16((uint16_t) client->type); @@ -839,11 +842,11 @@ static int __fio_client_send_local_ini(struct fio_client *client, */ sb.st_size += OPT_LEN_MAX; p_size = sb.st_size + sizeof(*pdu); - pdu = malloc(p_size); + pdu = static_cast(malloc(p_size)); buf = pdu->buf; len = sb.st_size; - p = buf; + p = static_cast(buf); if (read_ini_data(fd, p, len)) { log_err("fio: failed reading job file %s\n", filename); close(fd); @@ -925,7 +928,7 @@ int fio_client_update_options(struct fio_client *client, struct cmd_add_job_pdu *pdu; int ret; - pdu = malloc(cmd_sz); + pdu = static_cast(malloc(cmd_sz)); pdu->thread_number = cpu_to_le32(client->thread_number); pdu->groupid = cpu_to_le32(client->groupid); convert_thread_options_to_net(&pdu->top, o); @@ -1170,7 +1173,7 @@ static void handle_job_opt(struct fio_client *client, struct fio_net_cmd *cmd) struct flist_head *opt_list = &client->opt_lists[pdu->groupid]; struct print_option *p; - p = malloc(sizeof(*p)); + p = static_cast(malloc(sizeof(*p))); p->name = strdup((const char *)pdu->name); p->value = pdu->value[0] ? strdup((const char *)pdu->value) : NULL; @@ -1438,8 +1441,8 @@ static int fio_client_handle_iolog(struct fio_client *client, } /* allocate buffer big enough for next sprintf() call */ - log_pathname = malloc(10 + strlen((char *)pdu->name) + - strlen(client->hostname)); + log_pathname = static_cast(malloc(10 + strlen((char *)pdu->name) + + strlen(client->hostname))); if (!log_pathname) { log_err("fio: memory allocation of unique pathname failed\n"); ret = -1; @@ -1545,7 +1548,7 @@ static void handle_start(struct fio_client *client, struct fio_net_cmd *cmd) if (client->opt_lists) free(client->opt_lists); - client->opt_lists = malloc(client->jobs * sizeof(struct flist_head)); + client->opt_lists = static_cast(malloc(client->jobs * sizeof(struct flist_head))); for (i = 0; i < client->jobs; i++) INIT_FLIST_HEAD(&client->opt_lists[i]); } @@ -1605,7 +1608,7 @@ static struct cmd_iolog_pdu *convert_iolog_gz(struct fio_net_cmd *cmd, sizeof(struct io_u_plat_entry)); else total = nr_samples * __log_entry_sz(le32_to_cpu(pdu->log_offset)); - ret = malloc(total + sizeof(*pdu)); + ret = static_cast(malloc(total + sizeof(*pdu))); ret->nr_samples = nr_samples; memcpy(ret, pdu, sizeof(*pdu)); @@ -1613,7 +1616,7 @@ static struct cmd_iolog_pdu *convert_iolog_gz(struct fio_net_cmd *cmd, p = (char *) ret + sizeof(*pdu); stream.avail_in = cmd->pdu_len - sizeof(*pdu); - stream.next_in = (void *)((char *) pdu + sizeof(*pdu)); + stream.next_in = reinterpret_cast((char *) pdu + sizeof(*pdu)); while (stream.avail_in) { unsigned int this_chunk = 65536; unsigned int this_len; @@ -1623,7 +1626,7 @@ static struct cmd_iolog_pdu *convert_iolog_gz(struct fio_net_cmd *cmd, this_chunk = total; stream.avail_out = this_chunk; - stream.next_out = (void *)p; + stream.next_out = reinterpret_cast(p); err = inflate(&stream, Z_NO_FLUSH); /* may be Z_OK, or Z_STREAM_END */ if (err < 0) { @@ -1714,7 +1717,7 @@ static struct cmd_iolog_pdu *convert_iolog(struct fio_net_cmd *cmd, s->priority = le16_to_cpu(s->priority); if (ret->log_offset) { - struct io_sample_offset *so = (void *) s; + struct io_sample_offset *so = reinterpret_cast(s); so->offset = le64_to_cpu(so->offset); } @@ -1745,7 +1748,7 @@ static int fio_send_file(struct fio_client *client, struct cmd_sendfile *pdu, int fd; size = sizeof(*rep); - rep = malloc(size); + rep = static_cast(malloc(size)); if (stat((char *)pdu->path, &sb) < 0) { fail: @@ -1756,7 +1759,7 @@ static int fio_send_file(struct fio_client *client, struct cmd_sendfile *pdu, } size += sb.st_size; - rep = realloc(rep, size); + rep = static_cast(realloc(rep, size)); rep->size = cpu_to_le32((uint32_t) sb.st_size); fd = open((char *)pdu->path, O_RDONLY); @@ -1945,7 +1948,7 @@ int fio_clients_send_trigger(const char *cmd) client = flist_entry(entry, struct fio_client, list); - pdu = malloc(sizeof(*pdu) + slen); + pdu = static_cast(malloc(sizeof(*pdu) + slen)); pdu->len = cpu_to_le16((uint16_t) slen); if (slen) memcpy(pdu->cmd, cmd, slen); @@ -1969,7 +1972,7 @@ static void request_client_etas(struct client_ops const *ops) dprint(FD_NET, "client: request eta (%d)\n", nr_clients); - eta = calloc(1, sizeof(*eta) + __THREAD_RUNSTR_SZ(REAL_MAX_JOBS)); + eta = static_cast(calloc(1, sizeof(*eta) + __THREAD_RUNSTR_SZ(REAL_MAX_JOBS))); eta->pending = nr_clients; flist_for_each(entry, &client_list) { @@ -2055,7 +2058,7 @@ static int client_check_cmd_timeout(struct fio_client *client, return flist_empty(&client->cmd_list) && ret; } -static int fio_check_clients_timed_out(void) +static int fio_check_clients_timed_out() { struct fio_client *client; struct flist_head *entry, *tmp; @@ -2096,7 +2099,7 @@ int fio_handle_clients(struct client_ops const *ops) fio_gettime(&eta_ts, NULL); - pfds = malloc(nr_clients * sizeof(struct pollfd)); + pfds = static_cast(malloc(nr_clients * sizeof(struct pollfd))); init_thread_stat(&client_ts); init_group_run_stat(&client_gs); diff --git a/client.h b/client.h index d77b6076f1..65c75ef2d7 100644 --- a/client.h +++ b/client.h @@ -8,6 +8,10 @@ #include "lib/types.h" #include "stat.h" +#ifdef __cplusplus +extern "C" { +#endif + struct fio_net_cmd; enum { @@ -151,5 +155,8 @@ extern int sum_stat_clients; extern struct thread_stat client_ts; extern struct group_run_stats client_gs; +#ifdef __cplusplus +} #endif +#endif diff --git a/configure b/configure index 6c93825173..28b3dfd588 100755 --- a/configure +++ b/configure @@ -46,6 +46,7 @@ print_config() { # Default CFLAGS CFLAGS="-D_GNU_SOURCE -include config-host.h $CFLAGS" CONFIGURE_CFLAGS="-Werror-implicit-function-declaration" +CONFIGURE_CXXFLAGS=${CONFIGURE_CFLAGS} BUILD_CFLAGS="" # Print a helpful header at the top of config.log @@ -92,6 +93,10 @@ compile_object() { do_cc $CFLAGS $CONFIGURE_CFLAGS -c -o $TMPO $TMPC } +compile_object_cxx() { + do_cxx $CXXFLAGS $CONFIGURE_CXXFLAGS -c -o $TMPO $TMPCXX +} + compile_prog() { local_cflags="$1" local_ldflags="$2 $LIBS" @@ -99,6 +104,13 @@ compile_prog() { do_cc $CFLAGS $CONFIGURE_CFLAGS $local_cflags -o $TMPE $TMPC $LDFLAGS $local_ldflags } +compile_prog_cxx() { + local_cxxflags="$1" + local_ldflags="$2 $LIBS" + echo "Compiling test case $3" >> config.log + do_cxx $CFLAGS $CONFIGURE_CXXFLAGS $local_cxxflags -o $TMPE $TMPCXX $LDFLAGS $local_ldflags +} + feature_not_found() { feature=$1 packages=$2 @@ -196,6 +208,8 @@ for opt do ;; --cc=*) CC="$optarg" ;; + --cxx=*) CXX="$optarg" + ;; --extra-cflags=*) CFLAGS="$CFLAGS $optarg" ;; --build-32bit-win) build_32bit_win="yes" @@ -279,7 +293,8 @@ done if test "$show_help" = "yes" ; then echo "--prefix= Use this directory as installation prefix" echo "--cpu= Specify target CPU if auto-detect fails" - echo "--cc= Specify compiler to use" + echo "--cc= Specify C compiler to use" + echo "--cxx= Specify C++ compiler to use" echo "--extra-cflags= Specify extra CFLAGS to pass to compiler" echo "--build-32bit-win Enable 32-bit build on Windows" echo "--target-win-ver= Minimum version of Windows to target (only accepts 7)" @@ -335,6 +350,16 @@ else cc="${CC-${cross_prefix}gcc}" fi +if test -z "${CXX}${cross_prefix}"; then + if has gcc; then + cxx=g++ + elif has clang; then + cxx=clang++ + fi +else + cxx="${CXX-${cross_prefix}g++}" +fi + if check_define __ANDROID__ ; then targetos="Android" elif check_define __linux__ ; then @@ -402,6 +427,7 @@ int main(void) EOF if compile_prog "" "-Werror=partial-availability" "error on weak symbols"; then CONFIGURE_CFLAGS="$CONFIGURE_CFLAGS -Werror=partial-availability" + CONFIGURE_CXXFLAGS=$(CONFIGURE_CFLAGS) fi ;; SunOS) @@ -417,8 +443,10 @@ CYGWIN*) if test -z "${CC}${cross_prefix}"; then if test ! -z "$build_32bit_win" && test "$build_32bit_win" = "yes"; then cc="i686-w64-mingw32-gcc" + cxx="i686-w64-mingw32-g++" else cc="x86_64-w64-mingw32-gcc" + cxx="x86_64-w64-mingw32-g++" fi fi @@ -456,6 +484,7 @@ if test -z "${CC}${cross_prefix}"; then if test "$targetos" = "FreeBSD" || test "$targetos" = "Darwin"; then if has clang; then cc=clang + cxx=clang++ fi fi fi @@ -595,7 +624,8 @@ print_config "Big endian" "$bigendian" if test ! -z "$target_win_ver"; then print_config "Target Windows version" "$target_win_ver" fi -print_config "Compiler" "$cc" +print_config "C Compiler" "$cc" +print_config "CXX Compiler" "$cxx" print_config "Cross compile" "$cross_compile" echo @@ -1605,6 +1635,7 @@ int main(void) } EOF GTK_CFLAGS=$(${cross_prefix}pkg-config --cflags gtk+-2.0 gthread-2.0) +GTK_CXXFLAGS=${GTK_CFLAGS} ORG_LDFLAGS=$LDFLAGS LDFLAGS=$(echo $LDFLAGS | sed s/"-static"//g) if test "$?" != "0" ; then @@ -1621,6 +1652,7 @@ if check_min_lib_version gtk+-2.0 2.18.0 "gfio"; then if compile_prog "$GTK_CFLAGS" "$GTK_LIBS" "gfio" ; then GFIO_LIBS="$LIBS $GTK_LIBS" CFLAGS="$CFLAGS $GTK_CFLAGS" + CXXFLAGS="$CXXFLAGS $GTK_CXXFLAGS" else echo "Please install gtk and gdk libraries" gfio="no" @@ -3361,8 +3393,11 @@ print_config "seed_buckets" "$seed_buckets" echo "LIBS+=$LIBS" >> $config_host_mak echo "GFIO_LIBS+=$GFIO_LIBS" >> $config_host_mak echo "CFLAGS+=$CFLAGS" >> $config_host_mak +CXXFLAGS+=${CFLAGS} +echo "CXXFLAGS+=$CXXFLAGS" >> $config_host_mak echo "LDFLAGS+=$LDFLAGS" >> $config_host_mak echo "CC=$cc" >> $config_host_mak +echo "CXX=$cxx" >> $config_host_mak echo "BUILD_CFLAGS=$BUILD_CFLAGS $CFLAGS" >> $config_host_mak echo "INSTALL_PREFIX=$prefix" >> $config_host_mak diff --git a/crc/crc16.c b/crc/crc16.cpp similarity index 94% rename from crc/crc16.c rename to crc/crc16.cpp index f593f710df..4746f5e5d7 100644 --- a/crc/crc16.c +++ b/crc/crc16.cpp @@ -7,8 +7,10 @@ #include "crc16.h" +#include + /** CRC table for the CRC-16. The poly is 0x8005 (x^16 + x^15 + x^2 + 1) */ -unsigned short const crc16_table[256] = { +uint16_t const crc16_table[256] = { 0x0000, 0xC0C1, 0xC181, 0x0140, 0xC301, 0x03C0, 0x0280, 0xC241, 0xC601, 0x06C0, 0x0780, 0xC741, 0x0500, 0xC5C1, 0xC481, 0x0440, 0xCC01, 0x0CC0, 0x0D80, 0xCD41, 0x0F00, 0xCFC1, 0xCE81, 0x0E40, @@ -43,10 +45,10 @@ unsigned short const crc16_table[256] = { 0x8201, 0x42C0, 0x4380, 0x8341, 0x4100, 0x81C1, 0x8081, 0x4040 }; -unsigned short fio_crc16(const void *buffer, unsigned int len) +uint16_t fio_crc16(const void *buffer, unsigned int len) { const unsigned char *cp = (const unsigned char *) buffer; - unsigned short crc = 0; + uint16_t crc = 0; while (len--) crc = crc16_byte(crc, *cp++); diff --git a/crc/crc16.h b/crc/crc16.h index 433a7b1442..7d0447bd58 100644 --- a/crc/crc16.h +++ b/crc/crc16.h @@ -15,14 +15,24 @@ #ifndef __CRC16_H #define __CRC16_H -extern unsigned short const crc16_table[256]; +#include -extern unsigned short fio_crc16(const void *buffer, unsigned int len); +#ifdef __cplusplus +extern "C" { +#endif -static inline unsigned short crc16_byte(unsigned short crc, +extern uint16_t const crc16_table[256]; + +extern uint16_t fio_crc16(const void *buffer, unsigned int len); + +static inline uint16_t crc16_byte(uint16_t crc, const unsigned char data) { return (crc >> 8) ^ crc16_table[(crc ^ data) & 0xff]; } +#ifdef __cplusplus +} +#endif + #endif /* __CRC16_H */ diff --git a/crc/crc32.c b/crc/crc32.cpp similarity index 97% rename from crc/crc32.c rename to crc/crc32.cpp index e35f5d9308..bec1290777 100644 --- a/crc/crc32.c +++ b/crc/crc32.cpp @@ -17,7 +17,11 @@ #include "crc32.h" -static const uint32_t crctab[256] = { +#include + +#include + +static constexpr std::array crctab = { 0x0, 0x04C11DB7, 0x09823B6E, 0x0D4326D9, 0x130476DC, 0x17C56B6B, 0x1A864DB2, 0x1E475005, 0x2608EDB8, 0x22C9F00F, 0x2F8AD6D6, diff --git a/crc/crc32.h b/crc/crc32.h index 6378e815b1..4d32e525a3 100644 --- a/crc/crc32.h +++ b/crc/crc32.h @@ -20,6 +20,14 @@ #include +#ifdef __cplusplus +extern "C" { +#endif + extern uint32_t fio_crc32(const void * const, unsigned long); +#ifdef __cplusplus +} +#endif + #endif diff --git a/crc/crc32c-arm64.c b/crc/crc32c-arm64.cpp similarity index 98% rename from crc/crc32c-arm64.c rename to crc/crc32c-arm64.cpp index 11bfe5d5c0..8352c03541 100644 --- a/crc/crc32c-arm64.c +++ b/crc/crc32c-arm64.cpp @@ -96,7 +96,7 @@ uint32_t crc32c_arm64(unsigned char const *data, unsigned long length) return crc; } -void crc32c_arm64_probe(void) +void crc32c_arm64_probe() { if (!crc32c_probed) { crc32c_arm64_available = os_cpu_has(CPU_ARM64_CRC32C); diff --git a/crc/crc32c-intel.c b/crc/crc32c-intel.cpp similarity index 98% rename from crc/crc32c-intel.c rename to crc/crc32c-intel.cpp index 6e810a28f9..e459569ad2 100644 --- a/crc/crc32c-intel.c +++ b/crc/crc32c-intel.cpp @@ -71,7 +71,7 @@ uint32_t crc32c_intel(unsigned char const *data, unsigned long length) return crc; } -void crc32c_intel_probe(void) +void crc32c_intel_probe() { if (!crc32c_probed) { unsigned int eax, ebx, ecx = 0, edx; diff --git a/crc/crc32c.c b/crc/crc32c.cpp similarity index 98% rename from crc/crc32c.c rename to crc/crc32c.cpp index 34944aea92..c09dcba2f3 100644 --- a/crc/crc32c.c +++ b/crc/crc32c.cpp @@ -32,6 +32,10 @@ */ #include "crc32c.h" +#include + +#include + /* * This is the CRC-32C table * Generated with: @@ -41,7 +45,7 @@ * reflect output bytes = true */ -static const uint32_t crc32c_table[256] = { +static constexpr std::array crc32c_table = { 0x00000000L, 0xF26B8303L, 0xE13B70F7L, 0x1350F3F4L, 0xC79A971FL, 0x35F1141CL, 0x26A1E7E8L, 0xD4CA64EBL, 0x8AD958CFL, 0x78B2DBCCL, 0x6BE22838L, 0x9989AB3BL, diff --git a/crc/crc32c.h b/crc/crc32c.h index 18f1161d0a..4ad6be6862 100644 --- a/crc/crc32c.h +++ b/crc/crc32c.h @@ -23,6 +23,10 @@ #include "../arch/arch.h" #include "../lib/types.h" +#ifdef __cplusplus +extern "C" { +#endif + extern uint32_t crc32c_sw(unsigned char const *, unsigned long); extern bool crc32c_arm64_available; extern bool crc32c_intel_available; @@ -58,4 +62,8 @@ static inline uint32_t fio_crc32c(unsigned char const *buf, unsigned long len) return crc32c_sw(buf, len); } +#ifdef __cplusplus +} +#endif + #endif diff --git a/crc/crc64.c b/crc/crc64.cpp similarity index 98% rename from crc/crc64.c rename to crc/crc64.cpp index bf24a97bf2..8d601c1e82 100644 --- a/crc/crc64.c +++ b/crc/crc64.cpp @@ -1,9 +1,13 @@ #include "crc64.h" +#include + +#include + /* * poly 0x95AC9329AC4BC9B5ULL and init 0xFFFFFFFFFFFFFFFFULL */ -static const unsigned long long crctab64[256] = { +static constexpr std::array crctab64 = { 0x0000000000000000ULL, 0x7ad870c830358979ULL, 0xf5b0e190606b12f2ULL, 0x8f689158505e9b8bULL, 0xc038e5739841b68fULL, 0xbae095bba8743ff6ULL, 0x358804e3f82aa47dULL, 0x4f50742bc81f2d04ULL, 0xab28ecb46814fe75ULL, diff --git a/crc/crc64.h b/crc/crc64.h index fe9cad3e26..9f0b24c2dc 100644 --- a/crc/crc64.h +++ b/crc/crc64.h @@ -1,6 +1,14 @@ #ifndef CRC64_H #define CRC64_H +#ifdef __cplusplus +extern "C" { +#endif + unsigned long long fio_crc64(const unsigned char *, unsigned long); +#ifdef __cplusplus +} +#endif + #endif diff --git a/crc/crc7.c b/crc/crc7.cpp similarity index 100% rename from crc/crc7.c rename to crc/crc7.cpp diff --git a/crc/crc7.h b/crc/crc7.h index 5d5d18884c..69498cea46 100644 --- a/crc/crc7.h +++ b/crc/crc7.h @@ -1,6 +1,10 @@ #ifndef CRC7_H #define CRC7_H +#ifdef __cplusplus +extern "C" { +#endif + extern const unsigned char crc7_syndrome_table[256]; static inline unsigned char crc7_byte(unsigned char crc, unsigned char data) @@ -10,4 +14,8 @@ static inline unsigned char crc7_byte(unsigned char crc, unsigned char data) extern unsigned char fio_crc7(const unsigned char *buffer, unsigned int len); +#ifdef __cplusplus +} +#endif + #endif diff --git a/crc/fnv.c b/crc/fnv.cpp similarity index 90% rename from crc/fnv.c rename to crc/fnv.cpp index 4cd06501fd..1ba95f70ee 100644 --- a/crc/fnv.c +++ b/crc/fnv.cpp @@ -8,7 +8,7 @@ */ uint64_t fnv(const void *buf, uint32_t len, uint64_t hval) { - const uint64_t *ptr = buf; + const uint64_t *ptr = static_cast(buf); while (len) { hval *= FNV_PRIME; diff --git a/crc/fnv.h b/crc/fnv.h index ef2b77b47e..c10a318666 100644 --- a/crc/fnv.h +++ b/crc/fnv.h @@ -3,6 +3,14 @@ #include +#ifdef __cplusplus +extern "C" { +#endif + uint64_t fnv(const void *, uint32_t, uint64_t); +#ifdef __cplusplus +} +#endif + #endif diff --git a/crc/md5.c b/crc/md5.cpp similarity index 99% rename from crc/md5.c rename to crc/md5.cpp index ade4f69721..8b3e500b46 100644 --- a/crc/md5.c +++ b/crc/md5.cpp @@ -1,9 +1,10 @@ /* * Shamelessly lifted from the 2.6 kernel (crypto/md5.c) */ -#include #include "md5.h" +#include + static void md5_transform(uint32_t *hash, uint32_t const *in) { uint32_t a, b, c, d; diff --git a/crc/md5.h b/crc/md5.h index 54e350c411..9c2e05df3d 100644 --- a/crc/md5.h +++ b/crc/md5.h @@ -3,6 +3,10 @@ #include +#ifdef __cplusplus +extern "C" { +#endif + #define MD5_DIGEST_SIZE 16 #define MD5_HMAC_BLOCK_SIZE 64 #define MD5_BLOCK_WORDS 16 @@ -26,4 +30,8 @@ extern void fio_md5_update(struct fio_md5_ctx *, const uint8_t *, unsigned int); extern void fio_md5_final(struct fio_md5_ctx *); extern void fio_md5_init(struct fio_md5_ctx *); +#ifdef __cplusplus +} +#endif + #endif diff --git a/crc/murmur3.c b/crc/murmur3.cpp similarity index 100% rename from crc/murmur3.c rename to crc/murmur3.cpp diff --git a/crc/murmur3.h b/crc/murmur3.h index 89f65003ff..a22b2390d6 100644 --- a/crc/murmur3.h +++ b/crc/murmur3.h @@ -3,6 +3,14 @@ #include +#ifdef __cplusplus +extern "C" { +#endif + uint32_t murmurhash3(const void *key, uint32_t len, uint32_t seed); +#ifdef __cplusplus +} +#endif + #endif diff --git a/crc/sha1.c b/crc/sha1.cpp similarity index 97% rename from crc/sha1.c rename to crc/sha1.cpp index 8d64c8ee7b..aa01433008 100644 --- a/crc/sha1.c +++ b/crc/sha1.cpp @@ -4,7 +4,7 @@ * and to avoid unnecessary copies into the context array. */ -#include +#include #include #include "sha1.h" @@ -41,14 +41,14 @@ void fio_sha1_update(struct fio_sha1_ctx *ctx, const void *data, memcpy(lenW + (char *)ctx->W, data, left); lenW = (lenW + left) & 63; len -= left; - data += left; + data = static_cast(data) + left; if (lenW) return; blk_SHA1Block(ctx, ctx->W); } while (len >= 64) { - blk_SHA1Block(ctx, data); - data += 64; + blk_SHA1Block(ctx, static_cast(data)); + data = static_cast(data) + 64; len -= 64; } if (len) diff --git a/crc/sha1.h b/crc/sha1.h index 416199baff..dfb598d2a9 100644 --- a/crc/sha1.h +++ b/crc/sha1.h @@ -3,6 +3,10 @@ #include +#ifdef __cplusplus +extern "C" { +#endif + /* * Based on the Mozilla SHA1 (see mozilla-sha1/sha1.h), * optimized to do word accesses rather than byte accesses, @@ -19,4 +23,8 @@ void fio_sha1_init(struct fio_sha1_ctx *); void fio_sha1_update(struct fio_sha1_ctx *, const void *dataIn, unsigned long len); void fio_sha1_final(struct fio_sha1_ctx *); +#ifdef __cplusplus +} +#endif + #endif diff --git a/crc/sha256.c b/crc/sha256.cpp similarity index 100% rename from crc/sha256.c rename to crc/sha256.cpp diff --git a/crc/sha256.h b/crc/sha256.h index b904c7d1d3..3406b7ab6b 100644 --- a/crc/sha256.h +++ b/crc/sha256.h @@ -3,6 +3,10 @@ #include +#ifdef __cplusplus +extern "C" { +#endif + #define SHA256_DIGEST_SIZE 32 #define SHA256_BLOCK_SIZE 64 @@ -16,4 +20,8 @@ void fio_sha256_init(struct fio_sha256_ctx *); void fio_sha256_update(struct fio_sha256_ctx *, const uint8_t *, unsigned int); void fio_sha256_final(struct fio_sha256_ctx *); +#ifdef __cplusplus +} +#endif + #endif diff --git a/crc/sha3.c b/crc/sha3.cpp similarity index 99% rename from crc/sha3.c rename to crc/sha3.cpp index c136550aae..6b069ea562 100644 --- a/crc/sha3.c +++ b/crc/sha3.cpp @@ -12,7 +12,7 @@ * any later version. * */ -#include +#include #include "../os/os.h" diff --git a/crc/sha3.h b/crc/sha3.h index 9f1970a641..fefa37fca1 100644 --- a/crc/sha3.h +++ b/crc/sha3.h @@ -6,6 +6,10 @@ #include +#ifdef __cplusplus +extern "C" { +#endif + #define SHA3_224_DIGEST_SIZE (224 / 8) #define SHA3_224_BLOCK_SIZE (200 - 2 * SHA3_224_DIGEST_SIZE) @@ -39,4 +43,8 @@ int fio_sha3_update(struct fio_sha3_ctx *sctx, const uint8_t *data, unsigned int len); void fio_sha3_final(struct fio_sha3_ctx *sctx); +#ifdef __cplusplus +} +#endif + #endif diff --git a/crc/sha512.c b/crc/sha512.cpp similarity index 99% rename from crc/sha512.c rename to crc/sha512.cpp index f599cdcc82..1a90995f87 100644 --- a/crc/sha512.c +++ b/crc/sha512.cpp @@ -11,7 +11,7 @@ * */ -#include +#include #include "../lib/bswap.h" #include "sha512.h" diff --git a/crc/sha512.h b/crc/sha512.h index 5adf6271cd..d5dfadd789 100644 --- a/crc/sha512.h +++ b/crc/sha512.h @@ -3,6 +3,10 @@ #include +#ifdef __cplusplus +extern "C" { +#endif + struct fio_sha512_ctx { uint64_t state[8]; uint32_t count[4]; @@ -13,4 +17,8 @@ struct fio_sha512_ctx { void fio_sha512_init(struct fio_sha512_ctx *); void fio_sha512_update(struct fio_sha512_ctx *, const uint8_t *, unsigned int); +#ifdef __cplusplus +} +#endif + #endif diff --git a/crc/test.c b/crc/test.cpp similarity index 90% rename from crc/test.c rename to crc/test.cpp index b57f07a4d7..11daf43285 100644 --- a/crc/test.c +++ b/crc/test.cpp @@ -1,7 +1,8 @@ -#include -#include -#include -#include +#include +#include +#include +#include +#include #include "../gettime.h" #include "../fio_time.h" @@ -64,7 +65,7 @@ static void t_md5(struct test_type *t, void *buf, size_t size) fio_md5_init(&ctx); for (i = 0; i < NR_CHUNKS; i++) { - fio_md5_update(&ctx, buf, size); + fio_md5_update(&ctx, static_cast(buf), size); fio_md5_final(&ctx); } } @@ -74,7 +75,7 @@ static void t_crc64(struct test_type *t, void *buf, size_t size) int i; for (i = 0; i < NR_CHUNKS; i++) - t->output += fio_crc64(buf, size); + t->output += fio_crc64(static_cast(buf), size); } static void t_crc32(struct test_type *t, void *buf, size_t size) @@ -90,7 +91,7 @@ static void t_crc32c(struct test_type *t, void *buf, size_t size) int i; for (i = 0; i < NR_CHUNKS; i++) - t->output += fio_crc32c(buf, size); + t->output += fio_crc32c(static_cast(buf), size); } static void t_crc16(struct test_type *t, void *buf, size_t size) @@ -106,7 +107,7 @@ static void t_crc7(struct test_type *t, void *buf, size_t size) int i; for (i = 0; i < NR_CHUNKS; i++) - t->output += fio_crc7(buf, size); + t->output += fio_crc7(static_cast(buf), size); } static void t_sha1(struct test_type *t, void *buf, size_t size) @@ -132,7 +133,7 @@ static void t_sha256(struct test_type *t, void *buf, size_t size) fio_sha256_init(&ctx); for (i = 0; i < NR_CHUNKS; i++) { - fio_sha256_update(&ctx, buf, size); + fio_sha256_update(&ctx, static_cast(buf), size); fio_sha256_final(&ctx); } } @@ -146,7 +147,7 @@ static void t_sha512(struct test_type *t, void *buf, size_t size) fio_sha512_init(&ctx); for (i = 0; i < NR_CHUNKS; i++) - fio_sha512_update(&ctx, buf, size); + fio_sha512_update(&ctx, static_cast(buf), size); } static void t_sha3_224(struct test_type *t, void *buf, size_t size) @@ -158,7 +159,7 @@ static void t_sha3_224(struct test_type *t, void *buf, size_t size) fio_sha3_224_init(&ctx); for (i = 0; i < NR_CHUNKS; i++) { - fio_sha3_update(&ctx, buf, size); + fio_sha3_update(&ctx, static_cast(buf), size); fio_sha3_final(&ctx); } } @@ -172,7 +173,7 @@ static void t_sha3_256(struct test_type *t, void *buf, size_t size) fio_sha3_256_init(&ctx); for (i = 0; i < NR_CHUNKS; i++) { - fio_sha3_update(&ctx, buf, size); + fio_sha3_update(&ctx, static_cast(buf), size); fio_sha3_final(&ctx); } } @@ -186,7 +187,7 @@ static void t_sha3_384(struct test_type *t, void *buf, size_t size) fio_sha3_384_init(&ctx); for (i = 0; i < NR_CHUNKS; i++) { - fio_sha3_update(&ctx, buf, size); + fio_sha3_update(&ctx, static_cast(buf), size); fio_sha3_final(&ctx); } } @@ -200,7 +201,7 @@ static void t_sha3_512(struct test_type *t, void *buf, size_t size) fio_sha3_512_init(&ctx); for (i = 0; i < NR_CHUNKS; i++) { - fio_sha3_update(&ctx, buf, size); + fio_sha3_update(&ctx, static_cast(buf), size); fio_sha3_final(&ctx); } } @@ -355,7 +356,7 @@ static unsigned int get_test_mask(const char *type) return mask; } -static int list_types(void) +static int list_types() { int i; diff --git a/crc/test.h b/crc/test.h index 2b52d6a921..c10b96a6f1 100644 --- a/crc/test.h +++ b/crc/test.h @@ -1,6 +1,14 @@ #ifndef FIO_CRC_TEST_H #define FIO_CRC_TEST_H +#ifdef __cplusplus +extern "C" { +#endif + int fio_crctest(const char *type); +#ifdef __cplusplus +} +#endif + #endif diff --git a/crc/xxhash.c b/crc/xxhash.cpp similarity index 99% rename from crc/xxhash.c rename to crc/xxhash.cpp index 0119564be3..c6543af125 100644 --- a/crc/xxhash.c +++ b/crc/xxhash.cpp @@ -253,7 +253,7 @@ uint32_t XXH32(const void* input, uint32_t len, uint32_t seed) // Advanced Hash Functions //**************************** -int XXH32_sizeofState(void) +int XXH32_sizeofState() { XXH_STATIC_ASSERT(XXH32_SIZEOFSTATE >= sizeof(struct XXH_state32_t)); // A compilation error here means XXH32_SIZEOFSTATE is not large enough return sizeof(struct XXH_state32_t); diff --git a/debug.c b/debug.cpp similarity index 85% rename from debug.c rename to debug.cpp index d1e2987ba3..68f0867068 100644 --- a/debug.c +++ b/debug.cpp @@ -1,5 +1,5 @@ -#include -#include +#include +#include #include "debug.h" #include "log.h" diff --git a/debug.h b/debug.h index 51b18de235..8ef6774cde 100644 --- a/debug.h +++ b/debug.h @@ -3,6 +3,10 @@ #include "lib/types.h" +#ifdef __cplusplus +extern "C" { +#endif + enum { FD_PROCESS = 0, FD_FILE, @@ -73,4 +77,8 @@ static inline void dprint(int type, const char *str, ...) } #endif +#ifdef __cplusplus +} +#endif + #endif diff --git a/dedupe.c b/dedupe.cpp similarity index 92% rename from dedupe.c rename to dedupe.cpp index 6170568918..75540667cb 100644 --- a/dedupe.c +++ b/dedupe.cpp @@ -5,7 +5,7 @@ * this needs to be called after all jobs' seeds * have been initialized */ -int init_global_dedupe_working_set_seeds(void) +int init_global_dedupe_working_set_seeds() { for_each_td(td) { if (!td->o.dedupe_global) @@ -36,7 +36,7 @@ int init_dedupe_working_set_seeds(struct thread_data *td, bool global_dedup) * Dedupe-ed pages will be generated using those seeds. */ td->num_unique_pages = (td->o.size * (unsigned long long)td->o.dedupe_working_set_percentage / 100) / td->o.min_bs[DDIR_WRITE]; - td->dedupe_working_set_states = malloc(sizeof(struct frand_state) * td->num_unique_pages); + td->dedupe_working_set_states = static_cast(malloc(sizeof(struct frand_state) * td->num_unique_pages)); if (!td->dedupe_working_set_states) { log_err("fio: could not allocate dedupe working set\n"); return 1; diff --git a/dedupe.h b/dedupe.h index bd1f9c0c0b..36ba9d1a9c 100644 --- a/dedupe.h +++ b/dedupe.h @@ -1,7 +1,16 @@ #ifndef DEDUPE_H #define DEDUPE_H +#ifdef __cplusplus +extern "C" { +#endif + +struct thread_data; int init_dedupe_working_set_seeds(struct thread_data *td, bool global_dedupe); int init_global_dedupe_working_set_seeds(void); +#ifdef __cplusplus +} +#endif + #endif diff --git a/diskutil.c b/diskutil.cpp similarity index 95% rename from diskutil.c rename to diskutil.cpp index cf4ede8577..0dc2e600e7 100644 --- a/diskutil.c +++ b/diskutil.cpp @@ -1,9 +1,11 @@ -#include -#include -#include +#include +#include +#include + #include #include #include + #include #include #ifdef CONFIG_VALGRIND_DEV @@ -64,9 +66,9 @@ static int get_io_ticks(struct disk_util *du, struct disk_util_stat *dus) dprint(FD_DISKUTIL, "%s: %s", du->path, p); - ret = sscanf(p, "%"SCNu64" %"SCNu64" %"SCNu64" %"SCNu64" " - "%"SCNu64" %"SCNu64" %"SCNu64" %"SCNu64" " - "%*u %"SCNu64" %"SCNu64"\n", + ret = sscanf(p, "%" SCNu64 " %" SCNu64 " %" SCNu64 " %" SCNu64 " " + "%" SCNu64 " %" SCNu64 " %" SCNu64 " %" SCNu64 " " + "%*u %" SCNu64 " %" SCNu64 "\n", &dus->s.ios[0], &dus->s.merges[0], &dus->s.sectors[0], &dus->s.ticks[0], &dus->s.ios[1], &dus->s.merges[1], &dus->s.sectors[1], @@ -107,7 +109,7 @@ static void update_io_tick_disk(struct disk_util *du) memcpy(&ldus->s, &__dus.s, sizeof(__dus.s)); } -int update_io_ticks(void) +int update_io_ticks() { struct flist_head *entry; struct disk_util *du; @@ -288,7 +290,7 @@ static struct disk_util *disk_util_add(struct thread_data *td, int majdev, dprint(FD_DISKUTIL, "add maj/min %d/%d: %s\n", majdev, mindev, path); - du = smalloc(sizeof(*du)); + du = static_cast(smalloc(sizeof(*du))); if (!du) return NULL; @@ -480,14 +482,14 @@ void init_disk_util(struct thread_data *td) unsigned int i; if (!td->o.do_disk_util || - td_ioengine_flagged(td, FIO_DISKLESSIO | FIO_NODISKUTIL)) + td_ioengine_flagged(td, static_cast(FIO_DISKLESSIO | FIO_NODISKUTIL))) return; for_each_file(td, f, i) f->du = __init_disk_util(td, f); } -void disk_util_prune_entries(void) +void disk_util_prune_entries() { fio_sem_down(disk_util_sem); @@ -504,7 +506,7 @@ void disk_util_prune_entries(void) fio_sem_remove(disk_util_sem); } -void setup_disk_util(void) +void setup_disk_util() { disk_util_sem = fio_sem_init(FIO_SEM_UNLOCKED); } diff --git a/diskutil.h b/diskutil.h index 9b28379983..a5f38fafea 100644 --- a/diskutil.h +++ b/diskutil.h @@ -10,6 +10,10 @@ #include "flist.h" #include "lib/ieee754.h" +#ifdef __cplusplus +extern "C" { +#endif + /** * @ios: Number of I/O operations that have been completed successfully. * @merges: Number of I/O operations that have been merged. @@ -135,4 +139,8 @@ static inline int update_io_ticks(void) } #endif +#ifdef __cplusplus +} +#endif + #endif diff --git a/eta.c b/eta.cpp similarity index 97% rename from eta.c rename to eta.cpp index af4027e0e2..94af2c319c 100644 --- a/eta.c +++ b/eta.cpp @@ -1,15 +1,19 @@ /* * Status and ETA code */ +#include +#include + #include -#include -#include + #ifdef CONFIG_VALGRIND_DEV #include #else #define DRD_IGNORE_VAR(x) do { } while (0) #endif +#include "io_ddir.h" +#include "lib/num2str.h" #include "fio.h" #include "lib/pow2.h" @@ -409,7 +413,7 @@ bool calc_thread_status(struct jobs_eta *je, int force) if (!ddir_rw_sum(disp_io_bytes)) fill_start_time(&disp_prev_time); - eta_secs = calloc(thread_number, sizeof(uint64_t)); + eta_secs = static_cast(calloc(thread_number, sizeof(uint64_t))); je->elapsed_sec = (mtime_since_genesis() + 999) / 1000; @@ -514,7 +518,7 @@ bool calc_thread_status(struct jobs_eta *je, int force) memcpy(&rate_prev_time, &now, sizeof(now)); regrow_agg_logs(); for_each_rw_ddir(ddir) { - add_agg_sample(sample_val(je->rate[ddir]), ddir, 0); + add_agg_sample(sample_val(je->rate[ddir]), static_cast(ddir), 0); } } @@ -645,7 +649,7 @@ void display_thread_status(struct jobs_eta *je) for (ddir = 0; ddir < DDIR_RWDIR_CNT; ddir++) { rate_str[ddir] = num2str(je->rate[ddir], 4, - 1024, je->is_pow2, je->unit_base); + 1024, je->is_pow2, static_cast(je->unit_base)); iops_str[ddir] = num2str(je->iops[ddir], 4, 1, 0, N2S_NONE); } @@ -691,7 +695,7 @@ struct jobs_eta *get_jobs_eta(bool force, size_t *size) return NULL; *size = sizeof(*je) + THREAD_RUNSTR_SZ + 8; - je = calloc(1, *size); + je = static_cast(calloc(1, *size)); if (!je) return NULL; @@ -704,7 +708,7 @@ struct jobs_eta *get_jobs_eta(bool force, size_t *size) return je; } -void print_thread_status(void) +void print_thread_status() { struct jobs_eta *je; size_t size; @@ -720,7 +724,7 @@ void print_status_init(int thr_number) { struct jobs_eta_packed jep; - compiletime_assert(sizeof(struct jobs_eta) == sizeof(jep), "jobs_eta"); + static_assert(sizeof(struct jobs_eta) == sizeof(jep), "jobs_eta"); DRD_IGNORE_VAR(__run_str); __run_str[thr_number] = 'P'; diff --git a/fdp.c b/fdp.cpp similarity index 89% rename from fdp.c rename to fdp.cpp index 49c80d2c61..8f74031706 100644 --- a/fdp.c +++ b/fdp.cpp @@ -5,10 +5,12 @@ * Specify fdp=1 (With char devices /dev/ng0n1) */ -#include -#include -#include +#include +#include +#include + #include + #include "fio.h" #include "file.h" @@ -45,7 +47,7 @@ static int init_ruh_info(struct thread_data *td, struct fio_file *f) struct fio_ruhs_info *ruhs, *tmp; int i, ret; - ruhs = scalloc(1, sizeof(*ruhs) + FDP_MAX_RUHS * sizeof(*ruhs->plis)); + ruhs = static_cast(scalloc(1, sizeof(*ruhs) + FDP_MAX_RUHS * sizeof(*ruhs->plis))); if (!ruhs) return -ENOMEM; @@ -71,7 +73,7 @@ static int init_ruh_info(struct thread_data *td, struct fio_file *f) } } - tmp = scalloc(1, sizeof(*tmp) + ruhs->nr_ruhs * sizeof(*tmp->plis)); + tmp = static_cast(scalloc(1, sizeof(*tmp) + ruhs->nr_ruhs * sizeof(*tmp->plis))); if (!tmp) { ret = -ENOMEM; goto out; diff --git a/fdp.h b/fdp.h index accbac384a..42c9997d39 100644 --- a/fdp.h +++ b/fdp.h @@ -3,6 +3,10 @@ #include "io_u.h" +#ifdef __cplusplus +extern "C" { +#endif + #define FDP_DIR_DTYPE 2 #define FDP_MAX_RUHS 128 @@ -26,4 +30,8 @@ int fdp_init(struct thread_data *td); void fdp_free_ruhs_info(struct fio_file *f); void fdp_fill_dspec_data(struct thread_data *td, struct io_u *io_u); +#ifdef __cplusplus +} +#endif + #endif /* FIO_FDP_H */ diff --git a/fifo.c b/fifo.cpp similarity index 86% rename from fifo.c rename to fifo.cpp index ac0d21576d..a9a262674f 100644 --- a/fifo.c +++ b/fifo.cpp @@ -19,9 +19,9 @@ * */ -#include -#include -#include +#include +#include +#include #include "fifo.h" #include "minmax.h" @@ -30,11 +30,11 @@ struct fifo *fifo_alloc(unsigned int size) { struct fifo *fifo; - fifo = malloc(sizeof(struct fifo)); + fifo = static_cast(malloc(sizeof(struct fifo))); if (!fifo) return NULL; - fifo->buffer = malloc(size); + fifo->buffer = static_castbuffer)>(malloc(size)); fifo->size = size; fifo->in = fifo->out = 0; @@ -58,7 +58,7 @@ unsigned int fifo_put(struct fifo *fifo, void *buffer, unsigned int len) memcpy(fifo->buffer + (fifo->in & (fifo->size - 1)), buffer, l); /* then put the rest (if any) at the beginning of the buffer */ - memcpy(fifo->buffer, buffer + l, len - l); + memcpy(fifo->buffer, static_cast(buffer) + l, len - l); /* * Ensure that we add the bytes to the fifo -before- @@ -86,7 +86,7 @@ unsigned int fifo_get(struct fifo *fifo, void *buf, unsigned int len) /* * then get the rest (if any) from the beginning of the buffer */ - memcpy(buf + l, fifo->buffer, len - l); + memcpy(static_cast(buf) + l, fifo->buffer, len - l); } fifo->out += len; diff --git a/fifo.h b/fifo.h index 61cc5a87bd..8f5cfb003f 100644 --- a/fifo.h +++ b/fifo.h @@ -21,6 +21,10 @@ * */ +#ifdef __cplusplus +extern "C" { +#endif + struct fifo { unsigned char *buffer; /* the buffer holding the data */ unsigned int size; /* the size of the allocated buffer */ @@ -43,4 +47,8 @@ static inline unsigned int fifo_room(struct fifo *fifo) return fifo->size - fifo->in + fifo->out; } +#ifdef __cplusplus +} +#endif + #endif diff --git a/file.h b/file.h index deb36e0291..c305c3b42e 100644 --- a/file.h +++ b/file.h @@ -10,6 +10,13 @@ #include "lib/lfsr.h" #include "lib/gauss.h" +#ifdef __cplusplus +#include +extern "C" { +#else +#include +#endif + /* Forward declarations */ struct zoned_block_device_info; struct fdp_ruh_info; @@ -239,4 +246,8 @@ extern bool exists_and_not_regfile(const char *); extern int fio_set_directio(struct thread_data *, struct fio_file *); extern void fio_file_free(struct fio_file *); +#ifdef __cplusplus +} +#endif + #endif diff --git a/filehash.c b/filehash.cpp similarity index 91% rename from filehash.c rename to filehash.cpp index 71ec7b18c3..0f4aad95ee 100644 --- a/filehash.c +++ b/filehash.cpp @@ -1,5 +1,5 @@ -#include -#include +#include +#include #include "fio.h" #include "flist.h" @@ -24,13 +24,13 @@ static unsigned short hash(const char *name) return jhash(name, strlen(name), 0) & HASH_MASK; } -void fio_file_hash_lock(void) +void fio_file_hash_lock() { if (hash_lock) fio_sem_down(hash_lock); } -void fio_file_hash_unlock(void) +void fio_file_hash_unlock() { if (hash_lock) fio_sem_up(hash_lock); @@ -103,7 +103,7 @@ bool file_bloom_exists(const char *fname, bool set) return bloom_string(file_bloom, fname, strlen(fname), set); } -void file_hash_exit(void) +void file_hash_exit() { unsigned int i, has_entries = 0; @@ -123,11 +123,11 @@ void file_hash_exit(void) file_bloom = NULL; } -void file_hash_init(void) +void file_hash_init() { unsigned int i; - file_hash = smalloc(file_hash_size); + file_hash = static_cast(smalloc(file_hash_size)); for (i = 0; i < HASH_BUCKETS; i++) INIT_FLIST_HEAD(&file_hash[i]); diff --git a/filehash.h b/filehash.h index 5fecc3b100..87fb0dd31d 100644 --- a/filehash.h +++ b/filehash.h @@ -3,6 +3,10 @@ #include "lib/types.h" +#ifdef __cplusplus +extern "C" { +#endif + extern void file_hash_init(void); extern void file_hash_exit(void); extern struct fio_file *lookup_file_hash(const char *); @@ -12,4 +16,8 @@ extern void fio_file_hash_lock(void); extern void fio_file_hash_unlock(void); extern bool file_bloom_exists(const char *, bool); +#ifdef __cplusplus +} +#endif + #endif diff --git a/filelock.c b/filelock.cpp similarity index 95% rename from filelock.c rename to filelock.cpp index fd3a6b29e4..b35b2719bb 100644 --- a/filelock.c +++ b/filelock.cpp @@ -3,10 +3,11 @@ * No hash indexing, just a list, so only works well for < 100 files or * so. But that's more than what fio needs, so should be fine. */ -#include -#include +#include +#include +#include + #include -#include #include "flist.h" #include "filelock.h" @@ -37,7 +38,7 @@ static void put_filelock(struct fio_filelock *ff) flist_add(&ff->list, &fld->free_list); } -static struct fio_filelock *__get_filelock(void) +static struct fio_filelock *__get_filelock() { struct fio_filelock *ff; @@ -67,11 +68,11 @@ static struct fio_filelock *get_filelock(int trylock, int *retry) return ff; } -int fio_filelock_init(void) +int fio_filelock_init() { int i; - fld = smalloc(sizeof(*fld)); + fld = static_cast(smalloc(sizeof(*fld))); if (!fld) return 1; @@ -95,7 +96,7 @@ int fio_filelock_init(void) return 1; } -void fio_filelock_exit(void) +void fio_filelock_exit() { if (!fld) return; diff --git a/filelock.h b/filelock.h index 4551bb0427..f9750773ca 100644 --- a/filelock.h +++ b/filelock.h @@ -3,6 +3,10 @@ #include "lib/types.h" +#ifdef __cplusplus +extern "C" { +#endif + extern void fio_lock_file(const char *); extern bool fio_trylock_file(const char *); extern void fio_unlock_file(const char *); @@ -10,4 +14,8 @@ extern void fio_unlock_file(const char *); extern int fio_filelock_init(void); extern void fio_filelock_exit(void); +#ifdef __cplusplus +} +#endif + #endif diff --git a/filesetup.c b/filesetup.cpp similarity index 98% rename from filesetup.c rename to filesetup.cpp index 816d10816e..267fb23fad 100644 --- a/filesetup.c +++ b/filesetup.cpp @@ -1,9 +1,11 @@ +#include +#include + #include #include -#include -#include #include #include + #include #include "fio.h" @@ -203,7 +205,7 @@ static int extend_file(struct thread_data *td, struct fio_file *f) if (bs > left) bs = left; - b = malloc(bs); + b = static_cast(malloc(bs)); if (!b) { td_verror(td, errno, "malloc"); goto err; @@ -303,7 +305,7 @@ static bool pre_read_file(struct thread_data *td, struct fio_file *f) if (bs > left) bs = left; - b = calloc(1, bs); + b = static_cast(calloc(1, bs)); if (!b) { td_verror(td, errno, "malloc"); ret = false; @@ -387,7 +389,7 @@ int generic_prepopulate_file(struct thread_data *td, struct fio_file *f) if (bs > left) bs = left; - b = malloc(bs); + b = static_cast(malloc(bs)); if (!b) { td_verror(td, errno, "malloc"); goto err; @@ -920,7 +922,7 @@ static unsigned long long get_fs_free_counts(struct thread_data *td) if (fm) continue; - fm = calloc(1, sizeof(*fm)); + fm = static_cast(calloc(1, sizeof(*fm))); snprintf(fm->__base, FIO_ARRAY_SIZE(fm->__base), "%s", buf); fm->base = basename(fm->__base); fm->key = sb.st_dev; @@ -1699,7 +1701,7 @@ static void set_already_allocated(const char *fname) { struct file_name *fn; - fn = malloc(sizeof(struct file_name)); + fn = static_cast(malloc(sizeof(struct file_name))); fn->filename = strdup(fname); fio_file_hash_lock(); @@ -1715,7 +1717,7 @@ static void set_already_allocated(const char *fname) } } -static void free_already_allocated(void) +static void free_already_allocated() { struct flist_head *entry, *tmp; struct file_name *fn; @@ -1739,9 +1741,9 @@ static struct fio_file *alloc_new_file(struct thread_data *td) struct fio_file *f; if (td_ioengine_flagged(td, FIO_NOFILEHASH)) - f = calloc(1, sizeof(*f)); + f = static_cast(calloc(1, sizeof(*f))); else - f = scalloc(1, sizeof(*f)); + f = static_cast(scalloc(1, sizeof(*f))); if (!f) { assert(0); return NULL; @@ -1802,13 +1804,13 @@ int add_file(struct thread_data *td, const char *fname, int numjob, int inc) dprint(FD_FILE, "resize file array to %d files\n", new_size); - td->files = realloc(td->files, new_size * sizeof(f)); + td->files = static_castfiles)>(realloc(td->files, new_size * sizeof(f))); if (td->files == NULL) { log_err("fio: realloc OOM\n"); assert(0); } if (td->o.file_lock_mode != FILE_LOCK_NONE) { - td->file_locks = realloc(td->file_locks, new_size); + td->file_locks = static_castfile_locks)>(realloc(td->file_locks, new_size)); if (!td->file_locks) { log_err("fio: realloc OOM\n"); assert(0); @@ -2028,10 +2030,10 @@ void dup_files(struct thread_data *td, struct thread_data *org) if (!org->files) return; - td->files = calloc(org->files_index, sizeof(f)); + td->files = static_castfiles)>(calloc(org->files_index, sizeof(f))); if (td->o.file_lock_mode != FILE_LOCK_NONE) - td->file_locks = malloc(org->files_index); + td->file_locks = static_castfile_locks)>(malloc(org->files_index)); assert(org->files_index >= org->o.nr_files); for_each_file(org, f, i) { @@ -2115,7 +2117,7 @@ bool fio_files_done(struct thread_data *td) } /* free memory used in initialization phase only */ -void filesetup_mem_free(void) +void filesetup_mem_free() { free_already_allocated(); } diff --git a/fio.c b/fio.cpp similarity index 95% rename from fio.c rename to fio.cpp index f19db1be6f..e909ff235e 100644 --- a/fio.c +++ b/fio.cpp @@ -27,7 +27,7 @@ int main(int argc, char *argv[], char *envp[]) { int ret = 1; - compiletime_assert(TD_NR <= TD_ENG_FLAG_SHIFT, "TD_ENG_FLAG_SHIFT"); + static_assert(TD_NR <= TD_ENG_FLAG_SHIFT, "TD_ENG_FLAG_SHIFT"); if (initialize_fio(envp)) return 1; diff --git a/fio.h b/fio.h index a54f57c93e..08482ab4d0 100644 --- a/fio.h +++ b/fio.h @@ -69,6 +69,10 @@ #include #endif +#ifdef __cplusplus +extern "C" { +#endif + struct fio_sem; /* @@ -926,4 +930,8 @@ static inline void fio_memfree(void *ptr, size_t size, bool shared) return __fio_memfree(ptr, size, shared ? sfree : free); } +#ifdef __cplusplus +} +#endif + #endif diff --git a/fio_sem.c b/fio_sem.cpp similarity index 95% rename from fio_sem.c rename to fio_sem.cpp index c7806acb26..83d0537cd8 100644 --- a/fio_sem.c +++ b/fio_sem.cpp @@ -1,7 +1,8 @@ -#include -#include +#include +#include +#include + #include -#include #ifdef CONFIG_VALGRIND_DEV #include #else @@ -56,9 +57,9 @@ struct fio_sem *fio_sem_init(int value) { struct fio_sem *sem = NULL; - sem = (void *) mmap(NULL, sizeof(struct fio_sem), + sem = static_cast(mmap(NULL, sizeof(struct fio_sem), PROT_READ | PROT_WRITE, - OS_MAP_ANON | MAP_SHARED, -1, 0); + OS_MAP_ANON | MAP_SHARED, -1, 0)); if (sem == MAP_FAILED) { perror("mmap semaphore"); return NULL; diff --git a/fio_sem.h b/fio_sem.h index a796ddd74d..7b5cd38b1f 100644 --- a/fio_sem.h +++ b/fio_sem.h @@ -19,6 +19,10 @@ enum { FIO_SEM_UNLOCKED = 1, }; +#ifdef __cplusplus +extern "C" { +#endif + extern int __fio_sem_init(struct fio_sem *, int); extern struct fio_sem *fio_sem_init(int); extern void __fio_sem_remove(struct fio_sem *); @@ -28,4 +32,8 @@ extern void fio_sem_down(struct fio_sem *); extern bool fio_sem_down_trylock(struct fio_sem *); extern int fio_sem_down_timeout(struct fio_sem *, unsigned int); +#ifdef __cplusplus +} +#endif + #endif diff --git a/fio_time.h b/fio_time.h index 62d92120a5..eb1fb17ca5 100644 --- a/fio_time.h +++ b/fio_time.h @@ -8,6 +8,10 @@ /* IWYU pragma: end_exports */ #include "lib/types.h" +#ifdef __cplusplus +extern "C" { +#endif + struct thread_data; extern uint64_t ntime_since(const struct timespec *, const struct timespec *); extern uint64_t ntime_since_now(const struct timespec *); @@ -32,4 +36,8 @@ extern void fio_time_init(void); extern void timespec_add_msec(struct timespec *, unsigned int); extern void set_epoch_time(struct thread_data *, int, clockid_t); +#ifdef __cplusplus +} +#endif + #endif diff --git a/flist.h b/flist.h index 5437cd80da..6c06f50155 100644 --- a/flist.h +++ b/flist.h @@ -4,9 +4,18 @@ #include #include +#ifdef __cplusplus + +extern "C" { + +#define container_of(ptr, type, member) ({ \ + auto const *__mptr = static_cast<__typeof__( ((type *)0)->member ) const*>(ptr); \ + (type *)( (char *)__mptr - offsetof(type,member) );}) +#else #define container_of(ptr, type, member) ({ \ const __typeof__( ((type *)0)->member ) *__mptr = (ptr); \ (type *)( (char *)__mptr - offsetof(type,member) );}) +#endif /* * Simple doubly linked list implementation. @@ -195,4 +204,8 @@ static inline void flist_splice_init(struct flist_head *list, extern void flist_sort(void *priv, struct flist_head *head, int (*cmp)(void *priv, struct flist_head *a, struct flist_head *b)); +#ifdef __cplusplus +} +#endif + #endif diff --git a/flow.c b/flow.cpp similarity index 81% rename from flow.c rename to flow.cpp index c64bb3b275..d290431173 100644 --- a/flow.c +++ b/flow.cpp @@ -23,9 +23,9 @@ int flow_threshold_exceeded(struct thread_data *td) return 0; flow_counter_ratio = (double)td->flow_counter / - atomic_load_relaxed(&flow->flow_counter); + __atomic_load_n(&flow->flow_counter, __ATOMIC_RELAXED); flow_weight_ratio = (double)td->o.flow / - atomic_load_relaxed(&flow->total_weight); + __atomic_load_n(&flow->total_weight, __ATOMIC_RELAXED); /* * each thread/process executing a fio job will stall based on the @@ -48,7 +48,8 @@ int flow_threshold_exceeded(struct thread_data *td) * increment flow(shared counter, therefore atomically) * and job-specific counter */ - atomic_add(&flow->flow_counter, 1); + + __atomic_fetch_add(&flow->flow_counter, 1, __ATOMIC_RELAXED); ++td->flow_counter; return 0; @@ -60,7 +61,7 @@ static struct fio_flow *flow_get(unsigned int id) struct flist_head *n; if (!flow_lock) - return NULL; + return nullptr; fio_sem_down(flow_lock); @@ -73,10 +74,10 @@ static struct fio_flow *flow_get(unsigned int id) } if (!flow) { - flow = smalloc(sizeof(*flow)); + flow = static_cast(smalloc(sizeof(*flow))); if (!flow) { fio_sem_up(flow_lock); - return NULL; + return nullptr; } flow->refs = 0; INIT_FLIST_HEAD(&flow->list); @@ -100,8 +101,8 @@ static void flow_put(struct fio_flow *flow, unsigned long flow_counter, fio_sem_down(flow_lock); - atomic_sub(&flow->flow_counter, flow_counter); - atomic_sub(&flow->total_weight, weight); + __atomic_fetch_sub(&flow->flow_counter, flow_counter, __ATOMIC_RELAXED); + __atomic_fetch_sub(&flow->total_weight, weight, __ATOMIC_RELAXED); if (!--flow->refs) { assert(flow->flow_counter == 1); @@ -117,7 +118,7 @@ void flow_init_job(struct thread_data *td) if (td->o.flow) { td->flow = flow_get(td->o.flow_id); td->flow_counter = 0; - atomic_add(&td->flow->total_weight, td->o.flow); + __atomic_fetch_add(&td->flow->total_weight, td->o.flow, __ATOMIC_RELAXED); } } @@ -129,9 +130,9 @@ void flow_exit_job(struct thread_data *td) } } -void flow_init(void) +void flow_init() { - flow_list = smalloc(sizeof(*flow_list)); + flow_list = static_cast(smalloc(sizeof(*flow_list))); if (!flow_list) { log_err("fio: smalloc pool exhausted\n"); return; @@ -147,7 +148,7 @@ void flow_init(void) INIT_FLIST_HEAD(flow_list); } -void flow_exit(void) +void flow_exit() { if (flow_lock) fio_sem_remove(flow_lock); diff --git a/flow.h b/flow.h index 95e766defc..147ad9d906 100644 --- a/flow.h +++ b/flow.h @@ -1,6 +1,10 @@ #ifndef FIO_FLOW_H #define FIO_FLOW_H +#ifdef __cplusplus +extern "C" { +#endif + #define FLOW_MAX_WEIGHT 1000 int flow_threshold_exceeded(struct thread_data *td); @@ -10,4 +14,8 @@ void flow_exit_job(struct thread_data *td); void flow_exit(void); void flow_init(void); +#ifdef __cplusplus +} +#endif + #endif diff --git a/gclient.c b/gclient.cpp similarity index 95% rename from gclient.c rename to gclient.cpp index 73f64b3b87..2f268275f8 100644 --- a/gclient.c +++ b/gclient.cpp @@ -1,5 +1,5 @@ -#include -#include +#include +#include #include #include @@ -12,6 +12,7 @@ #include "gerror.h" #include "graph.h" #include "gclient.h" +#include "lib/num2str.h" #include "printing.h" #include "lib/pow2.h" @@ -115,7 +116,7 @@ static GtkWidget *get_results_window(struct gui_entry *ge) static void gfio_text_op(struct fio_client *client, struct fio_net_cmd *cmd) { struct cmd_text_pdu *p = (struct cmd_text_pdu *) cmd->payload; - struct gfio_client *gc = client->client_data; + struct gfio_client *gc = static_cast(client->client_data); struct gui_entry *ge = gc->ge; struct gui *ui = ge->ui; GtkTreeIter iter; @@ -264,11 +265,11 @@ static int gfio_disk_util_show(struct gfio_client *gc) static void gfio_disk_util_op(struct fio_client *client, struct fio_net_cmd *cmd) { struct cmd_du_pdu *p = (struct cmd_du_pdu *) cmd->payload; - struct gfio_client *gc = client->client_data; + struct gfio_client *gc = static_cast(client->client_data); struct gui_entry *ge = gc->ge; unsigned int nr = gc->nr_du; - gc->du = realloc(gc->du, (nr + 1) * sizeof(struct cmd_du_pdu)); + gc->du = static_castdu)>(realloc(gc->du, (nr + 1) * sizeof(struct cmd_du_pdu))); memcpy(&gc->du[nr], p, sizeof(*p)); gc->nr_du++; @@ -341,7 +342,7 @@ static void gfio_update_thread_status_all(struct gui *ui, char *status_message, */ static void gfio_update_client_eta(struct fio_client *client, struct jobs_eta *je) { - struct gfio_client *gc = client->client_data; + struct gfio_client *gc = static_cast(client->client_data); struct gui_entry *ge = gc->ge; static int eta_good; char eta_str[128]; @@ -513,7 +514,7 @@ static void gfio_update_all_eta(struct jobs_eta *je) static void gfio_probe_op(struct fio_client *client, struct fio_net_cmd *cmd) { struct cmd_probe_reply_pdu *probe = (struct cmd_probe_reply_pdu *) cmd->payload; - struct gfio_client *gc = client->client_data; + struct gfio_client *gc = static_cast(client->client_data); struct gui_entry *ge = gc->ge; const char *os, *arch; @@ -545,7 +546,7 @@ static void gfio_probe_op(struct fio_client *client, struct fio_net_cmd *cmd) static void gfio_quit_op(struct fio_client *client, struct fio_net_cmd *cmd) { - struct gfio_client *gc = client->client_data; + struct gfio_client *gc = static_cast(client->client_data); gdk_threads_enter(); gfio_set_state(gc->ge, GE_STATE_NEW); @@ -557,7 +558,7 @@ static struct thread_options *gfio_client_add_job(struct gfio_client *gc, { struct gfio_client_options *gco; - gco = calloc(1, sizeof(*gco)); + gco = static_cast(calloc(1, sizeof(*gco))); if (convert_thread_options_to_cpu(&gco->o, top, top_sz)) { dprint(FD_NET, "client: failed parsing add_job command\n"); return NULL; @@ -571,7 +572,7 @@ static struct thread_options *gfio_client_add_job(struct gfio_client *gc, static void gfio_add_job_op(struct fio_client *client, struct fio_net_cmd *cmd) { struct cmd_add_job_pdu *p = (struct cmd_add_job_pdu *) cmd->payload; - struct gfio_client *gc = client->client_data; + struct gfio_client *gc = static_cast(client->client_data); struct gui_entry *ge = gc->ge; struct thread_options *o; char *c1, *c2, *c3, *c4; @@ -625,7 +626,7 @@ static void gfio_update_job_op(struct fio_client *client, struct fio_net_cmd *cmd) { uint32_t *pdu_error = (uint32_t *) cmd->payload; - struct gfio_client *gc = client->client_data; + struct gfio_client *gc = static_cast(client->client_data); gc->update_job_status = le32_to_cpu(*pdu_error); gc->update_job_done = 1; @@ -633,7 +634,7 @@ static void gfio_update_job_op(struct fio_client *client, static void gfio_client_timed_out(struct fio_client *client) { - struct gfio_client *gc = client->client_data; + struct gfio_client *gc = static_cast(client->client_data); char buf[256]; gdk_threads_enter(); @@ -649,7 +650,7 @@ static void gfio_client_timed_out(struct fio_client *client) static void gfio_client_stop(struct fio_client *client) { - struct gfio_client *gc = client->client_data; + struct gfio_client *gc = static_cast(client->client_data); gdk_threads_enter(); @@ -663,7 +664,7 @@ static void gfio_client_stop(struct fio_client *client) static void gfio_client_start(struct fio_client *client, struct fio_net_cmd *cmd) { - struct gfio_client *gc = client->client_data; + struct gfio_client *gc = static_cast(client->client_data); gdk_threads_enter(); gfio_set_state(gc->ge, GE_STATE_JOB_STARTED); @@ -672,7 +673,7 @@ static void gfio_client_start(struct fio_client *client, struct fio_net_cmd *cmd static void gfio_client_job_start(struct fio_client *client, struct fio_net_cmd *cmd) { - struct gfio_client *gc = client->client_data; + struct gfio_client *gc = static_cast(client->client_data); gdk_threads_enter(); gfio_set_state(gc->ge, GE_STATE_JOB_RUNNING); @@ -714,7 +715,7 @@ static void gfio_add_end_results(struct gfio_client *gc, struct thread_stat *ts, { unsigned int nr = gc->nr_results; - gc->results = realloc(gc->results, (nr + 1) * sizeof(struct end_results)); + gc->results = static_castresults)>(realloc(gc->results, (nr + 1) * sizeof(struct end_results))); memcpy(&gc->results[nr].ts, ts, sizeof(*ts)); memcpy(&gc->results[nr].gs, rs, sizeof(*rs)); gc->nr_results++; @@ -842,7 +843,7 @@ static GtkWidget *gfio_output_lat_buckets(double *lat, const char **labels, GType *types; int i; - types = malloc(num * sizeof(GType)); + types = static_cast(malloc(num * sizeof(GType))); for (i = 0; i < num; i++) types[i] = G_TYPE_STRING; @@ -904,7 +905,7 @@ static struct graph *setup_lat_bucket_graph(const char *title, double *lat, static int on_expose_lat_drawing_area(GtkWidget *w, GdkEvent *event, gpointer p) { - struct graph *g = p; + struct graph *g = static_cast(p); cairo_t *cr; cr = gdk_cairo_create(gtk_widget_get_window(w)); @@ -926,7 +927,7 @@ static gint on_config_lat_drawing_area(GtkWidget *w, GdkEventConfigure *event, { guint width = gtk_widget_get_allocated_width(w); guint height = gtk_widget_get_allocated_height(w); - struct graph *g = data; + struct graph *g = static_cast(data); graph_set_size(g, width, height); graph_set_size(g, width, height); @@ -1207,8 +1208,8 @@ static void gfio_show_ddir_status(struct gfio_client *gc, GtkWidget *mbox, gtk_label_set_text(GTK_LABEL(label), tmp); label = new_info_label_in_frame(box, "Bandwidth"); - bw_p = num2str(bw, ts->sig_figs, 1, i2p, ts->unit_base); - bw_palt = num2str(bw, ts->sig_figs, 1, !i2p, ts->unit_base); + bw_p = num2str(bw, ts->sig_figs, 1, i2p, static_cast(ts->unit_base)); + bw_palt = num2str(bw, ts->sig_figs, 1, !i2p, static_cast(ts->unit_base)); snprintf(tmp, sizeof(tmp), "%s (%s)", bw_p, bw_palt); gtk_label_set_text(GTK_LABEL(label), tmp); @@ -1376,7 +1377,7 @@ void gfio_display_end_results(struct gfio_client *gc) static void gfio_display_ts(struct fio_client *client, struct thread_stat *ts, struct group_run_stats *rs) { - struct gfio_client *gc = client->client_data; + struct gfio_client *gc = static_cast(client->client_data); struct gui_entry *ge = gc->ge; gfio_add_end_results(gc, ts, rs); @@ -1391,7 +1392,7 @@ static void gfio_display_ts(struct fio_client *client, struct thread_stat *ts, static void gfio_client_removed(struct fio_client *client) { - struct gfio_client *gc = client->client_data; + struct gfio_client *gc = static_cast(client->client_data); assert(gc->client == client); fio_put_client(gc->client); diff --git a/gclient.h b/gclient.h index 40383652c4..0f53ca7236 100644 --- a/gclient.h +++ b/gclient.h @@ -3,8 +3,16 @@ extern struct client_ops gfio_client_ops; +#ifdef __cplusplus +extern "C" { +#endif + extern void gfio_display_end_results(struct gfio_client *); +#ifdef __cplusplus +} +#endif + #define GFIO_READ_R 0.13 #define GFIO_READ_G 0.54 #define GFIO_READ_B 0.13 diff --git a/gcompat.c b/gcompat.cpp similarity index 96% rename from gcompat.c rename to gcompat.cpp index 5944df0ddc..b3a79494c3 100644 --- a/gcompat.c +++ b/gcompat.cpp @@ -4,7 +4,7 @@ #if GTK_MAJOR_VERSION <= 2 && GTK_MINOR_VERSION < 24 -GtkWidget *gtk_combo_box_text_new(void) +GtkWidget *gtk_combo_box_text_new() { return gtk_combo_box_new(); } diff --git a/gerror.c b/gerror.cpp similarity index 92% rename from gerror.c rename to gerror.cpp index 1ebcb272fa..b59bdc14f5 100644 --- a/gerror.c +++ b/gerror.cpp @@ -1,7 +1,7 @@ -#include -#include -#include -#include +#include +#include +#include +#include #include @@ -63,7 +63,7 @@ void gfio_report_info(struct gui *ui, const char *title, const char *message) GtkWidget *dialog, *content, *label; dialog = gtk_dialog_new_with_buttons(title, GTK_WINDOW(ui->window), - GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, + static_cast(GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT), GTK_STOCK_OK, GTK_RESPONSE_OK, NULL); content = gtk_dialog_get_content_area(GTK_DIALOG(dialog)); diff --git a/gerror.h b/gerror.h index 3767f92384..8a76be82a9 100644 --- a/gerror.h +++ b/gerror.h @@ -1,7 +1,15 @@ #ifndef GFIO_ERROR_H #define GFIO_ERROR_H +#ifdef __cplusplus +extern "C" { +#endif + extern void gfio_report_error(struct gui_entry *ge, const char *format, ...); extern void gfio_report_info(struct gui *ui, const char *title, const char *message); +#ifdef __cplusplus +} +#endif + #endif diff --git a/gettime-thread.c b/gettime-thread.cpp similarity index 89% rename from gettime-thread.c rename to gettime-thread.cpp index 86c2e2efdc..0fb7cc3156 100644 --- a/gettime-thread.c +++ b/gettime-thread.cpp @@ -1,5 +1,6 @@ +#include + #include -#include #include "fio.h" #include "lib/seqlock.h" @@ -10,15 +11,15 @@ int fio_gtod_offload = 0; static pthread_t gtod_thread; static os_cpu_mask_t fio_gtod_cpumask; -void fio_gtod_init(void) +void fio_gtod_init() { if (fio_ts) return; - fio_ts = smalloc(sizeof(*fio_ts)); + fio_ts = static_cast(smalloc(sizeof(*fio_ts))); } -static void fio_gtod_update(void) +static void fio_gtod_update() { struct timeval __tv; @@ -40,7 +41,7 @@ struct gtod_cpu_data { static void *gtod_thread_main(void *data) { - struct fio_sem *sem = data; + struct fio_sem *sem = static_cast(data); int ret; ret = fio_setaffinity(gettid(), fio_gtod_cpumask); @@ -66,7 +67,7 @@ static void *gtod_thread_main(void *data) return NULL; } -int fio_start_gtod_thread(void) +int fio_start_gtod_thread() { struct fio_sem *sem; pthread_attr_t attr; diff --git a/gettime.c b/gettime.cpp similarity index 93% rename from gettime.c rename to gettime.cpp index bc66a3ac9f..7a7faa01e1 100644 --- a/gettime.c +++ b/gettime.cpp @@ -2,7 +2,7 @@ * Clock functions */ -#include +#include #include "fio.h" #include "os/os.h" @@ -94,7 +94,7 @@ static void gtod_log_caller(void *caller) inc_caller(caller); } -static void fio_exit fio_dump_gtod(void) +static void fio_exit fio_dump_gtod() { unsigned long total_calls = 0; int i; @@ -115,7 +115,7 @@ static void fio_exit fio_dump_gtod(void) printf("Total %lu gettimeofday\n", total_calls); } -static void fio_init gtod_init(void) +static void fio_init gtod_init() { int i; @@ -235,7 +235,7 @@ void fio_gettime(struct timespec *tp, void fio_unused *caller) } #if defined(ARCH_HAVE_CPU_CLOCK) && !defined(ARCH_CPU_CLOCK_CYCLES_PER_USEC) -static unsigned long get_cycles_per_msec(void) +static unsigned long get_cycles_per_msec() { struct timespec s, e; uint64_t c_s, c_e; @@ -258,7 +258,7 @@ static unsigned long get_cycles_per_msec(void) #define NR_TIME_ITERS 50 -static int calibrate_cpu_clock(void) +static int calibrate_cpu_clock() { double delta, mean, S; uint64_t minc, maxc, avg, cycles[NR_TIME_ITERS]; @@ -288,15 +288,15 @@ static int calibrate_cpu_clock(void) minc = -1ULL; maxc = samples = avg = 0; for (i = 0; i < NR_TIME_ITERS; i++) { - double this = cycles[i]; + double __this__ = cycles[i]; minc = min(cycles[i], minc); maxc = max(cycles[i], maxc); - if ((fmax(this, mean) - fmin(this, mean)) > S) + if ((fmax(__this__, mean) - fmin(__this__, mean)) > S) continue; samples++; - avg += this; + avg += __this__; } S /= (double) NR_TIME_ITERS; @@ -369,7 +369,7 @@ static int calibrate_cpu_clock(void) return 0; } #else -static int calibrate_cpu_clock(void) +static int calibrate_cpu_clock() { #ifdef ARCH_CPU_CLOCK_CYCLES_PER_USEC return 0; @@ -380,7 +380,7 @@ static int calibrate_cpu_clock(void) #endif // ARCH_HAVE_CPU_CLOCK #if defined(ARCH_HAVE_CPU_CLOCK) && !defined(CONFIG_TLS_THREAD) -void fio_local_clock_init(void) +void fio_local_clock_init() { struct tv_valid *t; @@ -396,12 +396,12 @@ static void kill_tv_tls_key(void *data) free(data); } #else -void fio_local_clock_init(void) +void fio_local_clock_init() { } #endif -void fio_clock_init(void) +void fio_clock_init() { if (fio_clock_source == fio_clock_source_inited) return; @@ -581,14 +581,14 @@ struct clock_thread { }; static inline uint32_t atomic32_compare_and_swap(uint32_t *ptr, uint32_t old, - uint32_t new) + uint32_t __new__) { - return __sync_val_compare_and_swap(ptr, old, new); + return __sync_val_compare_and_swap(ptr, old, __new__); } static void *clock_thread_fn(void *data) { - struct clock_thread *t = data; + struct clock_thread *t = static_cast(data); struct clock_entry *c; os_cpu_mask_t cpu_mask; unsigned long long first; @@ -659,8 +659,8 @@ static void *clock_thread_fn(void *data) static int clock_cmp(const void *p1, const void *p2) { - const struct clock_entry *c1 = p1; - const struct clock_entry *c2 = p2; + const struct clock_entry *c1 = static_cast(p1); + const struct clock_entry *c2 = static_cast(p2); if (c1->seq == c2->seq) log_err("cs: bug in atomic sequence!\n"); @@ -674,7 +674,7 @@ int fio_monotonic_clocktest(int debug) unsigned int seen_cpus, nr_cpus = cpus_configured(); struct clock_entry *entries; unsigned long nr_entries, tentries, failed = 0; - struct clock_entry *prev, *this; + struct clock_entry *prev, *__this__; uint32_t seq = 0; unsigned int i; os_cpu_mask_t mask; @@ -705,9 +705,9 @@ int fio_monotonic_clocktest(int debug) #endif } - cthreads = malloc(nr_cpus * sizeof(struct clock_thread)); + cthreads = static_cast(malloc(nr_cpus * sizeof(struct clock_thread))); tentries = nr_entries * nr_cpus; - entries = malloc(tentries * sizeof(struct clock_entry)); + entries = static_cast(malloc(tentries * sizeof(struct clock_entry))); if (debug) log_info("cs: Testing %u CPUs\n", nr_cpus); @@ -765,15 +765,15 @@ int fio_monotonic_clocktest(int debug) /* silence silly gcc */ prev = NULL; for (failed = i = 0; i < tentries; i++) { - this = &entries[i]; + __this__ = &entries[i]; if (!i) { - prev = this; + prev = __this__; continue; } - if (prev->tsc > this->tsc) { - uint64_t diff = prev->tsc - this->tsc; + if (prev->tsc > __this__->tsc) { + uint64_t diff = prev->tsc - __this__->tsc; if (!debug) { failed++; @@ -783,11 +783,11 @@ int fio_monotonic_clocktest(int debug) log_info("cs: CPU clock mismatch (diff=%llu):\n", (unsigned long long) diff); log_info("\t CPU%3u: TSC=%llu, SEQ=%u\n", prev->cpu, (unsigned long long) prev->tsc, prev->seq); - log_info("\t CPU%3u: TSC=%llu, SEQ=%u\n", this->cpu, (unsigned long long) this->tsc, this->seq); + log_info("\t CPU%3u: TSC=%llu, SEQ=%u\n", __this__->cpu, (unsigned long long) __this__->tsc, __this__->seq); failed++; } - prev = this; + prev = __this__; } if (debug) { diff --git a/gettime.h b/gettime.h index f1d619ad5b..fa62da480b 100644 --- a/gettime.h +++ b/gettime.h @@ -6,6 +6,10 @@ #include "arch/arch.h" #include "lib/seqlock.h" +#ifdef __cplusplus +extern "C" { +#endif + /* * Clock sources */ @@ -46,4 +50,8 @@ static inline int fio_gettime_offload(struct timespec *ts) extern void fio_gtod_set_cpu(unsigned int cpu); +#ifdef __cplusplus +} +#endif + #endif diff --git a/gfio.c b/gfio.cpp similarity index 97% rename from gfio.c rename to gfio.cpp index 10c9b0947b..7b6dbbfbf5 100644 --- a/gfio.c +++ b/gfio.cpp @@ -21,9 +21,10 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * */ -#include -#include -#include +#include +#include +#include + #include #include @@ -226,6 +227,7 @@ static void update_button_states(struct gui *ui, struct gui_entry *ge) default: gfio_report_error(ge, "Bad client state: %u\n", ge->state); /* fall-through */ + __attribute__((__fallthrough__)); case GE_STATE_NEW: connect_state = 1; edit_state = 1; @@ -325,7 +327,7 @@ static gint on_config_drawing_area(GtkWidget *w, GdkEventConfigure *event, { guint width = gtk_widget_get_allocated_width(w); guint height = gtk_widget_get_allocated_height(w); - struct gfio_graphs *g = data; + struct gfio_graphs *g = static_cast(data); graph_set_size(g->iops_graph, width / 2.0, height); graph_set_position(g->iops_graph, width / 2.0, 0.0); @@ -344,7 +346,7 @@ static gboolean graph_tooltip(GtkWidget *w, gint x, gint y, gboolean keyboard_mode, GtkTooltip *tooltip, gpointer data) { - struct gfio_graphs *g = data; + struct gfio_graphs *g = static_cast(data); const char *text = NULL; if (graph_contains_xy(g->iops_graph, x, y)) @@ -362,7 +364,7 @@ static gboolean graph_tooltip(GtkWidget *w, gint x, gint y, static int on_expose_drawing_area(GtkWidget *w, GdkEvent *event, gpointer p) { - struct gfio_graphs *g = p; + struct gfio_graphs *g = static_cast(p); cairo_t *cr; cr = gdk_cairo_create(gtk_widget_get_window(w)); @@ -427,7 +429,7 @@ static void quit_clicked(__attribute__((unused)) GtkWidget *widget, static void *job_thread(void *arg) { - struct gui *ui = arg; + struct gui *ui = static_cast(arg); ui->handler_running = 1; fio_handle_clients(&gfio_client_ops); @@ -483,7 +485,7 @@ static void gfio_start_server(struct gui *ui) static void start_job_clicked(__attribute__((unused)) GtkWidget *widget, gpointer data) { - struct gui_entry *ge = data; + struct gui_entry *ge = static_cast(data); struct gfio_client *gc = ge->client; if (gc) @@ -501,7 +503,7 @@ struct connection_widgets static void hostname_cb(GtkEntry *entry, gpointer data) { - struct connection_widgets *cw = data; + struct connection_widgets *cw = static_cast(data); int uses_net = 0, is_localhost = 0; const gchar *text; gchar *ctext; @@ -642,7 +644,7 @@ static void gfio_client_added(struct gui_entry *ge, struct fio_client *client) struct gfio_client_options *gco; struct gfio_client *gc; - gc = calloc(1, sizeof(*gc)); + gc = static_cast(calloc(1, sizeof(*gc))); INIT_FLIST_HEAD(&gc->o_list); gc->ge = ge; ge->client = gc; @@ -652,7 +654,7 @@ static void gfio_client_added(struct gui_entry *ge, struct fio_client *client) * Just add a default set of options, need to consider how best * to handle this */ - gco = calloc(1, sizeof(*gco)); + gco = static_cast(calloc(1, sizeof(*gco))); INIT_FLIST_HEAD(&gco->list); options_default_fill(&gco->o); flist_add_tail(&gco->list, &gc->o_list); @@ -667,7 +669,7 @@ static void gfio_clear_graph_data(struct gfio_graphs *g) static void connect_clicked(GtkWidget *widget, gpointer data) { - struct gui_entry *ge = data; + struct gui_entry *ge = static_cast(data); struct gfio_client *gc = ge->client; if (ge->state == GE_STATE_NEW) { @@ -718,7 +720,7 @@ static void connect_clicked(GtkWidget *widget, gpointer data) static void send_clicked(GtkWidget *widget, gpointer data) { - struct gui_entry *ge = data; + struct gui_entry *ge = static_cast(data); if (send_job_file(ge)) gtk_widget_set_sensitive(ge->button[GFIO_BUTTON_START], 1); @@ -730,7 +732,7 @@ static struct gui_entry *alloc_new_gui_entry(struct gui *ui) { struct gui_entry *ge; - ge = calloc(1, sizeof(*ge)); + ge = static_cast(calloc(1, sizeof(*ge))); ge->state = GE_STATE_NEW; ge->ui = ui; return ge; @@ -779,7 +781,7 @@ static struct gui_entry *get_ge_from_page(struct gui *ui, gint cur_page, if (created) *created = 0; - return g_hash_table_lookup(ui->ge_hash, &cur_page); + return static_cast(g_hash_table_lookup(ui->ge_hash, &cur_page)); } static struct gui_entry *get_ge_from_cur_tab(struct gui *ui) @@ -915,7 +917,7 @@ static void recent_open(GtkAction *action, gpointer data) GtkRecentInfo *info; const gchar *uri; - info = g_object_get_data(G_OBJECT(action), "gtk-recent-info"); + info = static_cast(g_object_get_data(G_OBJECT(action), "gtk-recent-info")); uri = gtk_recent_info_get_uri(info); do_file_open_with_tab(ui, uri); @@ -923,7 +925,7 @@ static void recent_open(GtkAction *action, gpointer data) static void file_open(GtkWidget *w, gpointer data) { - struct gui *ui = data; + struct gui *ui = static_cast(data); GtkWidget *dialog; GtkFileFilter *filter; gchar *filename; @@ -959,7 +961,7 @@ static void file_open(GtkWidget *w, gpointer data) static void file_save(GtkWidget *w, gpointer data) { - struct gui *ui = data; + struct gui *ui = static_cast(data); GtkWidget *dialog; dialog = gtk_file_chooser_dialog_new("Save File", @@ -1106,7 +1108,7 @@ static void ge_update_settings_fn(gpointer key, gpointer value, gpointer data) gdk_event_free(ev); } -static void update_graph_limits(void) +static void update_graph_limits() { struct gui *ui = &main_ui; GdkEvent *ev; @@ -1176,7 +1178,7 @@ static void preferences(GtkWidget *w, gpointer data) box = gtk_hbox_new(FALSE, 6); gtk_container_add(GTK_CONTAINER(vbox), box); - buttons = malloc(sizeof(GtkWidget *) * FD_DEBUG_MAX); + buttons = static_cast(malloc(sizeof(GtkWidget *) * FD_DEBUG_MAX)); for (i = 0; i < FD_DEBUG_MAX; i++) { if (i == 7) { @@ -1616,9 +1618,9 @@ static void add_recent_file_items(struct gui *ui) action_name = g_strdup_printf("RecentFile%u", i++); label = gtk_recent_info_get_display_name(info); - action = g_object_new(GTK_TYPE_ACTION, + action = static_cast(g_object_new(GTK_TYPE_ACTION, "name", action_name, - "label", label, NULL); + "label", label, NULL)); g_object_set_data_full(G_OBJECT(action), "gtk-recent-info", gtk_recent_info_ref(info), diff --git a/ghelpers.c b/ghelpers.cpp similarity index 97% rename from ghelpers.c rename to ghelpers.cpp index 7acf588ab3..0fcf3333b5 100644 --- a/ghelpers.c +++ b/ghelpers.cpp @@ -1,5 +1,6 @@ -#include -#include +#include +#include + #include #include "gcompat.h" @@ -143,7 +144,7 @@ GtkTreeViewColumn *tree_view_column(GtkWidget *tree_view, int index, const char void multitext_add_entry(struct multitext_widget *mt, const char *text) { - mt->text = realloc(mt->text, (mt->max_text + 1) * sizeof(char *)); + mt->text = static_cast(realloc(mt->text, (mt->max_text + 1) * sizeof(char *))); mt->text[mt->max_text] = strdup(text); mt->max_text++; } diff --git a/goptions.c b/goptions.cpp similarity index 92% rename from goptions.c rename to goptions.cpp index 0b8c56a261..4e7caf8e0f 100644 --- a/goptions.c +++ b/goptions.cpp @@ -1,6 +1,8 @@ -#include -#include -#include +#include "goptions.h" + +#include +#include +#include #include #include @@ -141,8 +143,8 @@ static void gopt_set_children_visible(struct gopt_job_view *gjv, node = g_node_find(gopt_dep_tree, G_IN_ORDER, G_TRAVERSE_ALL, parent); child = g_node_first_child(node); while (child) { - struct fio_option *o = child->data; - struct gopt *g = o->gui_data; + struct fio_option *o = static_cast(child->data); + struct gopt *g = static_cast(o->gui_data); GtkWidget *widget = g->box; /* @@ -238,7 +240,7 @@ static struct gopt *gopt_new_str_store(struct gopt_job_view *gjv, struct gopt_str *s; GtkWidget *label; - s = calloc(1, sizeof(*s)); + s = static_cast(calloc(1, sizeof(*s))); s->gopt.box = gtk_hbox_new(FALSE, 3); if (!o->lname) @@ -291,7 +293,7 @@ static struct gopt_combo *__gopt_new_combo(struct gopt_job_view *gjv, struct gopt_combo *c; GtkWidget *label; - c = calloc(1, sizeof(*c)); + c = static_cast(calloc(1, sizeof(*c))); c->gopt.box = gtk_hbox_new(FALSE, 3); if (!o->lname) @@ -426,7 +428,7 @@ static struct gopt *gopt_new_str_multi(struct gopt_job_view *gjv, GtkWidget *frame, *hbox; int i; - m = calloc(1, sizeof(*m)); + m = static_cast(calloc(1, sizeof(*m))); m->gopt.box = gtk_hbox_new(FALSE, 3); gopt_mark_index(gjv, &m->gopt, idx, GOPT_STR_MULTI); @@ -470,7 +472,7 @@ static void gopt_int_changed(GtkSpinButton *spin, gpointer data) i->lastval = value; if (o->inv_opt) { - struct gopt *b_inv = o->inv_opt->gui_data; + struct gopt *b_inv = static_cast(o->inv_opt->gui_data); struct gopt_int *i_inv = container_of(b_inv, struct gopt_int, gopt); int cur_val; @@ -507,7 +509,7 @@ static struct gopt_int *__gopt_new_int(struct gopt_job_view *gjv, guint maxval, interval; GtkWidget *label; - i = calloc(1, sizeof(*i)); + i = static_cast(calloc(1, sizeof(*i))); i->gopt.box = gtk_hbox_new(FALSE, 3); if (!o->lname) label = gtk_label_new(o->name); @@ -585,7 +587,7 @@ static void gopt_bool_toggled(GtkToggleButton *button, gpointer data) set = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(b->check)); if (o->inv_opt) { - struct gopt *g_inv = o->inv_opt->gui_data; + struct gopt *g_inv = static_cast(o->inv_opt->gui_data); struct gopt_bool *b_inv = container_of(g_inv, struct gopt_bool, gopt); assert(o->type == o->inv_opt->type); @@ -619,7 +621,7 @@ static struct gopt *gopt_new_bool(struct gopt_job_view *gjv, GtkWidget *label; int defstate = 0; - b = calloc(1, sizeof(*b)); + b = static_cast(calloc(1, sizeof(*b))); b->gopt.box = gtk_hbox_new(FALSE, 3); if (!o->lname) label = gtk_label_new(o->name); @@ -715,7 +717,7 @@ static struct gopt *gopt_new_int_range(struct gopt_job_view *gjv, gint maxval; int i; - r = calloc(1, sizeof(*r)); + r = static_cast(calloc(1, sizeof(*r))); r->gopt.box = gtk_hbox_new(FALSE, 3); gopt_mark_index(gjv, &r->gopt, idx, GOPT_RANGE); if (!o->lname) @@ -830,7 +832,7 @@ static struct gopt *gopt_new_str_val(struct gopt_job_view *gjv, GtkWidget *label; int i; - g = calloc(1, sizeof(*g)); + g = static_cast(calloc(1, sizeof(*g))); g->gopt.box = gtk_hbox_new(FALSE, 3); if (!o->lname) label = gtk_label_new(o->name); @@ -875,7 +877,7 @@ static void gopt_set_option(struct gopt_job_view *gjv, struct fio_option *o, struct gopt_str_val *g; if (o->off1) - ullp = td_var(to, o, o->off1); + ullp = static_cast(td_var(to, o, o->off1)); g = container_of(gopt, struct gopt_str_val, gopt); if (ullp) @@ -887,7 +889,7 @@ static void gopt_set_option(struct gopt_job_view *gjv, struct fio_option *o, struct gopt_int *i; if (o->off1) - ullp = td_var(to, o, o->off1); + ullp = static_cast(td_var(to, o, o->off1)); i = container_of(gopt, struct gopt_int, gopt); if (ullp) @@ -900,7 +902,7 @@ static void gopt_set_option(struct gopt_job_view *gjv, struct fio_option *o, struct gopt_combo *c; if (o->off1) - ip = td_var(to, o, o->off1); + ip = static_cast(td_var(to, o, o->off1)); c = container_of(gopt, struct gopt_combo, gopt); if (ip) @@ -910,7 +912,7 @@ static void gopt_set_option(struct gopt_job_view *gjv, struct fio_option *o, struct gopt_int *i; if (o->off1) - ip = td_var(to, o, o->off1); + ip = static_cast(td_var(to, o, o->off1)); i = container_of(gopt, struct gopt_int, gopt); if (ip) @@ -923,7 +925,7 @@ static void gopt_set_option(struct gopt_job_view *gjv, struct fio_option *o, struct gopt_bool *b; if (o->off1) - ip = td_var(to, o, o->off1); + ip = static_cast(td_var(to, o, o->off1)); b = container_of(gopt, struct gopt_bool, gopt); if (ip) @@ -936,7 +938,7 @@ static void gopt_set_option(struct gopt_job_view *gjv, struct fio_option *o, struct gopt_combo *c; if (o->off1) - ip = td_var(to, o, o->off1); + ip = static_cast(td_var(to, o, o->off1)); c = container_of(gopt, struct gopt_combo, gopt); if (ip) @@ -946,7 +948,7 @@ static void gopt_set_option(struct gopt_job_view *gjv, struct fio_option *o, char *text = NULL; if (o->off1) { - char **p = td_var(to, o, o->off1); + char **p = static_cast(td_var(to, o, o->off1)); text = *p; } @@ -962,7 +964,7 @@ static void gopt_set_option(struct gopt_job_view *gjv, struct fio_option *o, char *text = NULL; if (o->off1) { - char **p = td_var(to, o, o->off1); + char **p = static_cast(td_var(to, o, o->off1)); text = *p; } @@ -984,10 +986,11 @@ static void gopt_set_option(struct gopt_job_view *gjv, struct fio_option *o, break; case FIO_OPT_RANGE: { struct gopt_range *r; - unsigned int *ip[4] = { td_var(to, o, o->off1), - td_var(to, o, o->off2), - td_var(to, o, o->off3), - td_var(to, o, o->off4) }; + unsigned int *ip[4] = { static_cast(td_var(to, o, o->off1)), + static_cast(td_var(to, o, o->off2)), + static_cast(td_var(to, o, o->off3)), + static_cast(td_var(to, o, o->off4)) + }; r = container_of(gopt, struct gopt_range, gopt); gopt_int_range_set_val(r, *ip); @@ -1015,7 +1018,7 @@ static void gopt_add_option(struct gopt_job_view *gjv, GtkWidget *hbox, unsigned long long *ullp = NULL; if (o->off1) - ullp = td_var(to, o, o->off1); + ullp = static_cast(td_var(to, o, o->off1)); go = gopt_new_str_val(gjv, o, ullp, opt_index); break; @@ -1024,7 +1027,7 @@ static void gopt_add_option(struct gopt_job_view *gjv, GtkWidget *hbox, unsigned long long *ullp = NULL; if (o->off1) - ullp = td_var(to, o, o->off1); + ullp = static_cast(td_var(to, o, o->off1)); go = gopt_new_ullong(gjv, o, ullp, opt_index); break; @@ -1034,14 +1037,14 @@ static void gopt_add_option(struct gopt_job_view *gjv, GtkWidget *hbox, unsigned int *ip = NULL; if (o->off1) - ip = td_var(to, o, o->off1); + ip = static_cast(td_var(to, o, o->off1)); go = gopt_new_combo_int(gjv, o, ip, opt_index); } else { unsigned int *ip = NULL; if (o->off1) - ip = td_var(to, o, o->off1); + ip = static_cast(td_var(to, o, o->off1)); go = gopt_new_int(gjv, o, ip, opt_index); } @@ -1051,7 +1054,7 @@ static void gopt_add_option(struct gopt_job_view *gjv, GtkWidget *hbox, unsigned int *ip = NULL; if (o->off1) - ip = td_var(to, o, o->off1); + ip = static_cast(td_var(to, o, o->off1)); go = gopt_new_bool(gjv, o, ip, opt_index); break; @@ -1061,7 +1064,7 @@ static void gopt_add_option(struct gopt_job_view *gjv, GtkWidget *hbox, unsigned int *ip = NULL; if (o->off1) - ip = td_var(to, o, o->off1); + ip = static_cast(td_var(to, o, o->off1)); go = gopt_new_combo_int(gjv, o, ip, opt_index); } else { @@ -1075,7 +1078,7 @@ static void gopt_add_option(struct gopt_job_view *gjv, GtkWidget *hbox, char *text = NULL; if (o->off1) { - char **p = td_var(to, o, o->off1); + char **p = static_cast(td_var(to, o, o->off1)); text = *p; } @@ -1091,10 +1094,11 @@ static void gopt_add_option(struct gopt_job_view *gjv, GtkWidget *hbox, go = gopt_new_str_multi(gjv, o, opt_index); break; case FIO_OPT_RANGE: { - unsigned int *ip[4] = { td_var(to, o, o->off1), - td_var(to, o, o->off2), - td_var(to, o, o->off3), - td_var(to, o, o->off4) }; + unsigned int *ip[4] = { static_cast(td_var(to, o, o->off1)), + static_cast(td_var(to, o, o->off2)), + static_cast(td_var(to, o, o->off3)), + static_cast(td_var(to, o, o->off4)) + }; go = gopt_new_int_range(gjv, o, ip, opt_index); break; @@ -1205,7 +1209,7 @@ static void gopt_handle_str_multi_changed(struct gopt_job_view *gjv, struct gopt_str_multi *m, struct fio_option *o) { - unsigned int *ip = td_var(gjv->o, o, o->off1); + unsigned int *ip = static_cast(td_var(gjv->o, o, o->off1)); struct value_pair *vp; gboolean set; guint val = 0; @@ -1235,10 +1239,11 @@ static void gopt_handle_range_changed(struct gopt_job_view *gjv, struct gopt_range *r, struct fio_option *o) { - unsigned int *ip[4] = { td_var(gjv->o, o, o->off1), - td_var(gjv->o, o, o->off2), - td_var(gjv->o, o, o->off3), - td_var(gjv->o, o, o->off4) }; + unsigned int *ip[4] = { static_cast(td_var(gjv->o, o, o->off1)), + static_cast(td_var(gjv->o, o, o->off2)), + static_cast(td_var(gjv->o, o, o->off3)), + static_cast(td_var(gjv->o, o, o->off4)) + }; gint val; int i; @@ -1252,7 +1257,7 @@ static void gopt_handle_str_val_changed(struct gopt_job_view *gjv, struct gopt_str_val *s, struct fio_option *o) { - unsigned long long *ullp = td_var(gjv->o, o, o->off1); + unsigned long long *ullp = static_cast(td_var(gjv->o, o, o->off1)); GtkAdjustment *adj; gint index; @@ -1276,7 +1281,7 @@ static void gopt_handle_str_val_changed(struct gopt_job_view *gjv, static void gopt_handle_str_changed(struct gopt_job_view *gjv, struct gopt_str *s, struct fio_option *o) { - char **p = td_var(gjv->o, o, o->off1); + char **p = static_cast(td_var(gjv->o, o, o->off1)); if (*p) free(*p); @@ -1287,7 +1292,7 @@ static void gopt_handle_str_changed(struct gopt_job_view *gjv, static void gopt_handle_bool_changed(struct gopt_job_view *gjv, struct gopt_bool *b, struct fio_option *o) { - unsigned int *ip = td_var(gjv->o, o, o->off1); + unsigned int *ip = static_cast(td_var(gjv->o, o, o->off1)); gboolean set; set = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(b->check)); @@ -1297,7 +1302,7 @@ static void gopt_handle_bool_changed(struct gopt_job_view *gjv, static void gopt_handle_int_changed(struct gopt_job_view *gjv, struct gopt_int *i, struct fio_option *o) { - unsigned int *ip = td_var(gjv->o, o, o->off1); + unsigned int *ip = static_cast(td_var(gjv->o, o, o->off1)); GtkAdjustment *adj; guint val; @@ -1310,7 +1315,7 @@ static void gopt_handle_combo_str_changed(struct gopt_job_view *gjv, struct gopt_combo *c, struct fio_option *o) { - char **p = td_var(gjv->o, o, o->off1); + char **p = static_cast(td_var(gjv->o, o, o->off1)); if (*p) free(*p); @@ -1322,7 +1327,7 @@ static void gopt_handle_combo_int_changed(struct gopt_job_view *gjv, struct gopt_combo *c, struct fio_option *o) { - unsigned int *ip = td_var(gjv->o, o, o->off1); + unsigned int *ip = static_cast(td_var(gjv->o, o, o->off1)); gint index; index = gtk_combo_box_get_active(GTK_COMBO_BOX(c->combo)); @@ -1577,7 +1582,7 @@ void gopt_get_options_window(GtkWidget *window, struct gfio_client *gc) gtk_notebook_popup_enable(GTK_NOTEBOOK(notebook)); gtk_box_pack_start(GTK_BOX(vbox), notebook, TRUE, TRUE, 5); - gjv = calloc(1, sizeof(*gjv)); + gjv = static_cast(calloc(1, sizeof(*gjv))); INIT_FLIST_HEAD(&gjv->changed_list); gco = flist_first_entry(&gc->o_list, struct gfio_client_options, list); gjv->o = &gco->o; @@ -1601,7 +1606,7 @@ void gopt_get_options_window(GtkWidget *window, struct gfio_client *gc) /* * Build n-ary option dependency tree */ -void gopt_init(void) +void gopt_init() { int i; @@ -1632,7 +1637,7 @@ void gopt_init(void) } } -void gopt_exit(void) +void gopt_exit() { g_node_destroy(gopt_dep_tree); gopt_dep_tree = NULL; diff --git a/goptions.h b/goptions.h index 0361750946..7bfdf53142 100644 --- a/goptions.h +++ b/goptions.h @@ -3,8 +3,16 @@ #include +#ifdef __cplusplus +extern "C" { +#endif + void gopt_get_options_window(GtkWidget *window, struct gfio_client *gc); void gopt_init(void); void gopt_exit(void); +#ifdef __cplusplus +} +#endif + #endif diff --git a/graph.c b/graph.cpp similarity index 97% rename from graph.c rename to graph.cpp index 3d2b6c96dd..918df64129 100644 --- a/graph.c +++ b/graph.cpp @@ -20,11 +20,11 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * */ -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #include #include @@ -118,7 +118,7 @@ struct graph *graph_new(unsigned int xdim, unsigned int ydim, const char *font) { struct graph *g; - g = calloc(1, sizeof(*g)); + g = static_cast(calloc(1, sizeof(*g))); INIT_FLIST_HEAD(&g->label_list); graph_set_size(g, xdim, ydim); g->per_label_limit = -1; @@ -489,13 +489,13 @@ typedef double (*xy_value_extractor)(struct graph_value *v); static double getx(struct graph_value *v) { - struct xyvalue *xy = v->value; + struct xyvalue *xy = static_cast(v->value); return xy->x; } static double gety(struct graph_value *v) { - struct xyvalue *xy = v->value; + struct xyvalue *xy = static_cast(v->value); return xy->y; } @@ -656,7 +656,7 @@ graph_label_t graph_add_label(struct graph *bg, const char *label) i = graph_find_label(bg, label); if (i) return i; /* already present. */ - i = calloc(1, sizeof(*i)); + i = static_cast(calloc(1, sizeof(*i))); INIT_FLIST_HEAD(&i->value_list); i->parent = bg; setstring(&i->label, label); @@ -713,7 +713,7 @@ static void graph_label_add_value(struct graph_label *i, void *value, struct graph *g = i->parent; struct graph_value *x; - x = calloc(1, sizeof(*x)); + x = static_cast(calloc(1, sizeof(*x))); INIT_FLIST_HEAD(&x->alias); INIT_FLIST_HEAD(&x->list); flist_add_tail(&x->list, &i->value_list); @@ -789,7 +789,7 @@ int graph_add_data(struct graph *bg, graph_label_t label, const double value) struct graph_label *i = label; double *d; - d = malloc(sizeof(*d)); + d = static_cast(malloc(sizeof(*d))); *d = value; graph_label_add_value(i, d, NULL); @@ -822,7 +822,7 @@ int graph_add_xy_data(struct graph *bg, graph_label_t label, else i->hide = 0; - xy = malloc(sizeof(*xy)); + xy = static_cast(malloc(sizeof(*xy))); xy->x = x; xy->y = y; diff --git a/hash.h b/hash.h index 51f0706e2c..4b9b3d17b6 100644 --- a/hash.h +++ b/hash.h @@ -97,7 +97,7 @@ static inline uint32_t rol32(uint32_t word, uint32_t shift) static inline uint32_t jhash(const void *key, uint32_t length, uint32_t initval) { - const uint8_t *k = key; + const uint8_t *k = (const uint8_t*)(key); uint32_t a, b, c; /* Set up the internal state */ diff --git a/helper_thread.c b/helper_thread.cpp similarity index 94% rename from helper_thread.c rename to helper_thread.cpp index 53dea44bab..ef4baf1d95 100644 --- a/helper_thread.c +++ b/helper_thread.cpp @@ -1,7 +1,8 @@ -#include -#include -#include -#include +#include +#include +#include +#include + #include #ifdef CONFIG_HAVE_TIMERFD_CREATE #include @@ -43,10 +44,10 @@ struct interval_timer { const char *name; struct timespec expires; uint32_t interval_ms; - int (*func)(void); + int (*func)(); }; -void helper_thread_destroy(void) +void helper_thread_destroy() { if (!helper_data) return; @@ -57,7 +58,7 @@ void helper_thread_destroy(void) } #ifdef _WIN32 -static void sock_init(void) +static void sock_init() { WSADATA wsaData; int res; @@ -84,7 +85,7 @@ static int read_from_pipe(int fd, void *buf, size_t len) return recv(fd, buf, len, 0); } #else -static void sock_init(void) +static void sock_init() { } @@ -104,7 +105,7 @@ static int read_from_pipe(int fd, void *buf, size_t len) } #endif -static void block_signals(void) +static void block_signals() { #ifdef HAVE_PTHREAD_SIGMASK sigset_t sigmask; @@ -131,7 +132,7 @@ static void submit_action(enum action a) } } -void helper_reset(void) +void helper_reset() { submit_action(A_RESET); } @@ -141,12 +142,12 @@ void helper_reset(void) * that are async-signal-safe. See also * https://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html#tag_15_04_03. */ -void helper_do_stat(void) +void helper_do_stat() { submit_action(A_DO_STAT); } -bool helper_should_exit(void) +bool helper_should_exit() { if (!helper_data) return true; @@ -154,7 +155,7 @@ bool helper_should_exit(void) return helper_data->exit; } -void helper_thread_exit(void) +void helper_thread_exit() { if (!helper_data) return; @@ -272,7 +273,7 @@ static int eval_timer(struct interval_timer *it, const struct timespec *now, static void *helper_thread_main(void *data) { - struct helper_data *hd = data; + struct helper_data *hd = static_cast(data); unsigned int msec_to_next_event, next_log; struct interval_timer timer[] = { { @@ -282,13 +283,13 @@ static void *helper_thread_main(void *data) }, { .name = "status_interval", - .interval_ms = status_interval, + .interval_ms = static_cast(status_interval), .func = __show_running_run_stats, }, { .name = "steadystate", - .interval_ms = steadystate_enabled ? ss_check_interval : - 0, + .interval_ms = static_cast(steadystate_enabled ? ss_check_interval : + 0), .func = steadystate_check, } }; @@ -417,7 +418,7 @@ int helper_thread_create(struct fio_sem *startup_sem, struct sk_out *sk_out) struct helper_data *hd; int ret; - hd = scalloc(1, sizeof(*hd)); + hd = static_cast(scalloc(1, sizeof(*hd))); setup_disk_util(); steadystate_setup(); diff --git a/helper_thread.h b/helper_thread.h index 1c8167e83b..d442e53b24 100644 --- a/helper_thread.h +++ b/helper_thread.h @@ -6,6 +6,10 @@ struct fio_sem; struct sk_out; +#ifdef __cplusplus +extern "C" { +#endif + extern void helper_reset(void); extern void helper_do_stat(void); extern bool helper_should_exit(void); @@ -13,4 +17,8 @@ extern void helper_thread_destroy(void); extern void helper_thread_exit(void); extern int helper_thread_create(struct fio_sem *, struct sk_out *); +#ifdef __cplusplus +} +#endif + #endif diff --git a/helpers.c b/helpers.cpp similarity index 96% rename from helpers.c rename to helpers.cpp index ab9d706da8..f08a3b2ab1 100644 --- a/helpers.c +++ b/helpers.cpp @@ -1,4 +1,4 @@ -#include +#include #include "helpers.h" diff --git a/idletime.c b/idletime.cpp similarity index 95% rename from idletime.c rename to idletime.cpp index 90ed77ea6e..13d8dd5b48 100644 --- a/idletime.c +++ b/idletime.cpp @@ -1,4 +1,5 @@ -#include +#include + #include "fio.h" #include "json.h" #include "idletime.h" @@ -78,7 +79,7 @@ static void *idle_prof_thread_fn(void *data) { int retval; unsigned long j, k; - struct idle_prof_thread *ipt = data; + struct idle_prof_thread *ipt = static_cast(data); /* wait for all threads are spawned */ pthread_mutex_lock(&ipt->init_lock); @@ -86,15 +87,15 @@ static void *idle_prof_thread_fn(void *data) /* exit if any other thread failed to start */ if (ipc.status == IDLE_PROF_STATUS_ABORT) { pthread_mutex_unlock(&ipt->init_lock); - return NULL; + return nullptr; } retval = set_cpu_affinity(ipt); if (retval == -1) { ipt->state = TD_EXITED; pthread_mutex_unlock(&ipt->init_lock); - return NULL; - } + return nullptr; + } ipt->cali_time = calibrate_unit(ipt->data); @@ -156,11 +157,11 @@ static void *idle_prof_thread_fn(void *data) do_exit: free_cpu_affinity(ipt); - return NULL; + return nullptr; } /* calculate mean and standard deviation to complete an unit of work */ -static void calibration_stats(void) +static void calibration_stats() { int i; double sum = 0.0, var = 0.0; @@ -181,7 +182,7 @@ static void calibration_stats(void) ipc.cali_stddev = sqrt(var/(ipc.nr_cpus-1)); } -void fio_idle_prof_init(void) +void fio_idle_prof_init() { int i, ret; struct timespec ts; @@ -211,13 +212,13 @@ void fio_idle_prof_init(void) return; } - ipc.ipts = malloc(ipc.nr_cpus * sizeof(struct idle_prof_thread)); + ipc.ipts = static_cast(malloc(ipc.nr_cpus * sizeof(struct idle_prof_thread))); if (!ipc.ipts) { log_err("fio: malloc failed\n"); return; } - ipc.buf = malloc(ipc.nr_cpus * page_size); + ipc.buf = static_cast(malloc(ipc.nr_cpus * page_size)); if (!ipc.buf) { log_err("fio: malloc failed\n"); free(ipc.ipts); @@ -233,7 +234,7 @@ void fio_idle_prof_init(void) ipt->cpu = i; ipt->state = TD_NOT_CREATED; - ipt->data = (unsigned char *)(ipc.buf + page_size * i); + ipt->data = static_cast(ipc.buf) + page_size * i; if ((ret = pthread_mutex_init(&ipt->init_lock, NULL))) { ipc.status = IDLE_PROF_STATUS_ABORT; @@ -317,7 +318,7 @@ void fio_idle_prof_init(void) ipc.status = IDLE_PROF_STATUS_CALI_STOP; } -void fio_idle_prof_start(void) +void fio_idle_prof_start() { int i; struct idle_prof_thread *ipt; @@ -332,7 +333,7 @@ void fio_idle_prof_start(void) } } -void fio_idle_prof_stop(void) +void fio_idle_prof_stop() { int i; uint64_t runt; @@ -409,7 +410,7 @@ static double fio_idle_prof_cpu_stat(int cpu) return p * 100.0; } -void fio_idle_prof_cleanup(void) +void fio_idle_prof_cleanup() { if (ipc.ipts) { free(ipc.ipts); diff --git a/idletime.h b/idletime.h index 91ca95f5ee..1362a2ece5 100644 --- a/idletime.h +++ b/idletime.h @@ -5,6 +5,10 @@ #include #include "os/os.h" +#ifdef __cplusplus +extern "C" { +#endif + #define CALIBRATE_RUNS 10 #define CALIBRATE_SCALE 1000 #define MAX_CPU_STR_LEN 32 @@ -60,4 +64,8 @@ extern void show_idle_prof_stats(int, struct json_object *, struct buf_output *) extern void fio_idle_prof_cleanup(void); +#ifdef __cplusplus +} +#endif + #endif diff --git a/init.c b/init.cpp similarity index 96% rename from init.c rename to init.cpp index 105339fa28..7d7d3a34c1 100644 --- a/init.c +++ b/init.cpp @@ -1,12 +1,13 @@ /* * This file contains job initialization and setup functions. */ -#include -#include +#include +#include +#include +#include +#include + #include -#include -#include -#include #include #include #include @@ -31,6 +32,7 @@ #include "filelock.h" #include "steadystate.h" #include "blktrace.h" +#include "io_ddir.h" #include "oslib/asprintf.h" #include "oslib/getopt.h" @@ -305,7 +307,7 @@ static struct option l_opts[FIO_NR_OPTIONS] = { }, }; -void free_threads_shm(void) +void free_threads_shm() { int i; @@ -332,7 +334,7 @@ void free_threads_shm(void) cur_segment = 0; } -static void free_shm(void) +static void free_shm() { #ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION if (nr_segments) { @@ -354,7 +356,7 @@ static void free_shm(void) #endif } -static int add_thread_segment(void) +static int add_thread_segment() { struct thread_segment *seg = &segments[nr_segments]; size_t size = JOBS_PER_SEG * sizeof(struct thread_data); @@ -381,7 +383,7 @@ static int add_thread_segment(void) #endif #ifndef CONFIG_NO_SHM - seg->threads = shmat(seg->shm_id, NULL, 0); + seg->threads = static_castthreads)>(shmat(seg->shm_id, NULL, 0)); if (seg->threads == (void *) -1) { perror("shmat"); return 1; @@ -417,7 +419,7 @@ static int add_thread_segment(void) * threads/processes, and is split into chunks of JOBS_PER_SEG. If the current * segment has no more room, add a new chunk. */ -static int expand_thread_area(void) +static int expand_thread_area() { struct thread_segment *seg = &segments[cur_segment]; @@ -466,7 +468,7 @@ static void copy_opt_list(struct thread_data *dst, struct thread_data *src) struct print_option *srcp, *dstp; srcp = flist_entry(entry, struct print_option, list); - dstp = malloc(sizeof(*dstp)); + dstp = static_cast(malloc(sizeof(*dstp))); dstp->name = strdup(srcp->name); if (srcp->value) dstp->value = strdup(srcp->value); @@ -577,7 +579,7 @@ static int setup_rate(struct thread_data *td) for_each_rw_ddir(ddir) { if (td->o.rate[ddir] || td->o.rate_iops[ddir]) { - ret |= __setup_rate(td, ddir); + ret |= __setup_rate(td, static_cast(ddir)); } } return ret; @@ -1242,7 +1244,7 @@ static void init_flags(struct thread_data *td) td->flags &= ~TD_F_SCRAMBLE_BUFFERS; for (i = 0; i < DDIR_RWDIR_CNT; i++) { - if (option_check_rate(td, i)) { + if (option_check_rate(td, static_cast(i))) { td->flags |= TD_F_CHECK_RATE; break; } @@ -1385,7 +1387,7 @@ static char *make_filename(char *buf, size_t buf_size,struct thread_options *o, return buf; } -bool parse_dryrun(void) +bool parse_dryrun() { return dump_cmdline || parse_only; } @@ -1596,12 +1598,12 @@ static int add_job(struct thread_data *td, const char *jobname, int job_add_num, .td = td, .avg_msec = o->log_avg_msec, .hist_msec = o->log_hist_msec, - .hist_coarseness = o->log_hist_coarseness, + .hist_coarseness = static_cast(o->log_hist_coarseness), .log_type = IO_LOG_TYPE_LAT, - .log_offset = o->log_offset, - .log_prio = o->log_prio, - .log_gz = o->log_gz, - .log_gz_store = o->log_gz_store, + .log_offset = static_cast(o->log_offset), + .log_prio = static_cast(o->log_prio), + .log_gz = static_cast(o->log_gz), + .log_gz_store = static_cast(o->log_gz_store), }; const char *pre = make_log_name(o->lat_log_file, o->name); const char *suf; @@ -1636,12 +1638,12 @@ static int add_job(struct thread_data *td, const char *jobname, int job_add_num, .td = td, .avg_msec = o->log_avg_msec, .hist_msec = o->log_hist_msec, - .hist_coarseness = o->log_hist_coarseness, + .hist_coarseness = static_cast(o->log_hist_coarseness), .log_type = IO_LOG_TYPE_HIST, - .log_offset = o->log_offset, - .log_prio = o->log_prio, - .log_gz = o->log_gz, - .log_gz_store = o->log_gz_store, + .log_offset = static_cast(o->log_offset), + .log_prio = static_cast(o->log_prio), + .log_gz = static_cast(o->log_gz), + .log_gz_store = static_cast(o->log_gz_store), }; const char *pre = make_log_name(o->hist_log_file, o->name); const char *suf; @@ -1668,12 +1670,12 @@ static int add_job(struct thread_data *td, const char *jobname, int job_add_num, .td = td, .avg_msec = o->log_avg_msec, .hist_msec = o->log_hist_msec, - .hist_coarseness = o->log_hist_coarseness, + .hist_coarseness = static_cast(o->log_hist_coarseness), .log_type = IO_LOG_TYPE_BW, - .log_offset = o->log_offset, - .log_prio = o->log_prio, - .log_gz = o->log_gz, - .log_gz_store = o->log_gz_store, + .log_offset = static_cast(o->log_offset), + .log_prio = static_cast(o->log_prio), + .log_gz = static_cast(o->log_gz), + .log_gz_store = static_cast(o->log_gz_store), }; const char *pre = make_log_name(o->bw_log_file, o->name); const char *suf; @@ -1700,12 +1702,12 @@ static int add_job(struct thread_data *td, const char *jobname, int job_add_num, .td = td, .avg_msec = o->log_avg_msec, .hist_msec = o->log_hist_msec, - .hist_coarseness = o->log_hist_coarseness, + .hist_coarseness = static_cast(o->log_hist_coarseness), .log_type = IO_LOG_TYPE_IOPS, - .log_offset = o->log_offset, - .log_prio = o->log_prio, - .log_gz = o->log_gz, - .log_gz_store = o->log_gz_store, + .log_offset = static_cast(o->log_offset), + .log_prio = static_cast(o->log_prio), + .log_gz = static_cast(o->log_gz), + .log_gz_store = static_cast(o->log_gz_store), }; const char *pre = make_log_name(o->iops_log_file, o->name); const char *suf; @@ -1945,13 +1947,13 @@ static int __parse_jobs_ini(struct thread_data *td, } } - string = malloc(OPT_LEN_MAX); + string = static_cast(malloc(OPT_LEN_MAX)); /* * it's really 256 + small bit, 280 should suffice */ if (!nested) { - name = calloc(1, 280); + name = static_cast(calloc(1, 280)); } opts = NULL; @@ -1963,7 +1965,7 @@ static int __parse_jobs_ini(struct thread_data *td, if (!opts) { alloc_opts = 8; - opts = malloc(sizeof(char *) * alloc_opts); + opts = static_cast(malloc(sizeof(char *) * alloc_opts)); num_opts = 0; } @@ -2117,8 +2119,8 @@ static int __parse_jobs_ini(struct thread_data *td, if (num_opts == alloc_opts) { alloc_opts <<= 1; - opts = realloc(opts, - alloc_opts * sizeof(char *)); + opts = static_cast(realloc(opts, + alloc_opts * sizeof(char *))); } opts[num_opts] = strdup(p); @@ -2191,7 +2193,7 @@ int parse_jobs_ini(char *file, int is_buf, int stonewall_flag, int type) 0, NULL, NULL, NULL, NULL); } -static int fill_def_thread(void) +static int fill_def_thread() { memset(&def_thread, 0, sizeof(def_thread)); INIT_FLIST_HEAD(&def_thread.opt_list); @@ -2206,7 +2208,7 @@ static int fill_def_thread(void) return 0; } -static void show_debug_categories(void) +static void show_debug_categories() { #ifdef FIO_INC_DEBUG const struct debug_level *dl = &debug_levels[0]; @@ -2445,7 +2447,7 @@ static int set_debug(const char *string) } #endif -static void fio_options_fill_optstring(void) +static void fio_options_fill_optstring() { char *ostr = cmd_optstr; int i, c; @@ -2708,7 +2710,7 @@ int parse_cmd_line(int argc, char *argv[], int client_type) break; } new_size = (nr_job_sections + 1) * sizeof(char *); - job_sections = realloc(job_sections, new_size); + job_sections = static_cast(realloc(job_sections, new_size)); job_sections[nr_job_sections] = strdup(optarg); nr_job_sections++; break; @@ -2726,7 +2728,7 @@ int parse_cmd_line(int argc, char *argv[], int client_type) free(exec_profile); exec_profile = strdup(optarg); break; - case FIO_GETOPT_JOB: { + case static_cast(FIO_GETOPT_JOB): { const char *opt = l_opts[lidx].name; char *val = optarg; @@ -2788,7 +2790,7 @@ int parse_cmd_line(int argc, char *argv[], int client_type) } break; } - case FIO_GETOPT_IOENGINE: { + case static_cast(FIO_GETOPT_IOENGINE): { const char *opt = l_opts[lidx].name; char *val = optarg; @@ -3016,7 +3018,7 @@ int parse_cmd_line(int argc, char *argv[], int client_type) while (!ret && optind < argc) { ini_idx++; - ini_file = realloc(ini_file, ini_idx * sizeof(char *)); + ini_file = static_cast(realloc(ini_file, ini_idx * sizeof(char *))); ini_file[ini_idx - 1] = strdup(argv[optind]); optind++; } @@ -3025,7 +3027,7 @@ int parse_cmd_line(int argc, char *argv[], int client_type) return ini_idx; } -int fio_init_options(void) +int fio_init_options() { f_out = stdout; f_err = stderr; @@ -3106,7 +3108,7 @@ void options_default_fill(struct thread_options *o) memcpy(o, &def_thread.o, sizeof(*o)); } -struct thread_data *get_global_options(void) +struct thread_data *get_global_options() { return &def_thread; } diff --git a/io_ddir.h b/io_ddir.h index 217eb62862..1bfaf78fc2 100644 --- a/io_ddir.h +++ b/io_ddir.h @@ -1,6 +1,8 @@ #ifndef FIO_DDIR_H #define FIO_DDIR_H +#include + enum fio_ddir { DDIR_READ = 0, DDIR_WRITE = 1, @@ -16,7 +18,7 @@ enum fio_ddir { DDIR_RWDIR_SYNC_CNT = 4, }; -#define for_each_rw_ddir(ddir) for (enum fio_ddir ddir = 0; ddir < DDIR_RWDIR_CNT; ddir++) +#define for_each_rw_ddir(ddir) for (int ddir = 0; ddir < DDIR_RWDIR_CNT; ddir++) static inline const char *io_ddir_name(enum fio_ddir ddir) { diff --git a/io_u.c b/io_u.cpp similarity index 98% rename from io_u.c rename to io_u.cpp index 07e5bac5ef..5ceed325f2 100644 --- a/io_u.c +++ b/io_u.cpp @@ -1,6 +1,7 @@ +#include +#include + #include -#include -#include #include "fio.h" #include "verify.h" @@ -546,7 +547,7 @@ static inline bool io_u_fits(struct thread_data *td, struct io_u *io_u, static unsigned long long get_next_buflen(struct thread_data *td, struct io_u *io_u, bool is_random) { - int ddir = io_u->ddir; + auto ddir = io_u->ddir; unsigned long long buflen = 0; unsigned long long minbs, maxbs; uint64_t frand_max, r; @@ -671,7 +672,7 @@ int io_u_quiesce(struct thread_data *td) static enum fio_ddir rate_ddir(struct thread_data *td, enum fio_ddir ddir) { - enum fio_ddir odir = ddir ^ 1; + auto const odir = static_cast(static_cast(ddir) ^ 1); uint64_t usec; uint64_t now; @@ -1279,7 +1280,7 @@ static struct fio_file *get_next_file_rand(struct thread_data *td, int err; if (td->nr_open_files >= td->o.open_files) - return ERR_PTR(-EBUSY); + return static_cast(ERR_PTR(-EBUSY)); err = td_io_open_file(td, f); if (err) @@ -1324,7 +1325,7 @@ static struct fio_file *get_next_file_rr(struct thread_data *td, int goodf, int err; if (td->nr_open_files >= td->o.open_files) - return ERR_PTR(-EBUSY); + return static_cast(ERR_PTR(-EBUSY)); err = td_io_open_file(td, f); if (err) { @@ -1640,7 +1641,7 @@ struct io_u *__get_io_u(struct thread_data *td) IO_U_F_VER_LIST); io_u->error = 0; - io_u->acct_ddir = -1; + io_u->acct_ddir = static_castacct_ddir)>(-1); td->cur_depth++; assert(!(td->flags & TD_F_CHILD)); io_u_set(td, io_u, IO_U_F_IN_CUR_DEPTH); @@ -1731,7 +1732,7 @@ static void small_content_scramble(struct io_u *io_u) if (!nr_blocks) return; - p = io_u->xfer_buf; + p = static_cast(io_u->xfer_buf); boffset = io_u->offset; if (io_u->buf_filled_len) @@ -1750,10 +1751,10 @@ static void small_content_scramble(struct io_u *io_u) * Fill offset into start of cacheline, time into end * of cacheline */ - iptr = (void *) p + (offset << 6); + iptr = reinterpret_cast(p + (offset << 6)); *iptr = boffset; - iptr = (void *) p + 64 - 2 * sizeof(uint64_t); + iptr = reinterpret_cast(p + 64 - 2 * sizeof(uint64_t)); iptr[0] = io_u->start_time.tv_sec; iptr[1] = io_u->start_time.tv_nsec; @@ -1862,7 +1863,7 @@ struct io_u *get_io_u(struct thread_data *td) err_put: dprint(FD_IO, "get_io_u failed\n"); put_io_u(td, io_u); - return ERR_PTR(ret); + return static_cast(ERR_PTR(ret)); } static void __io_u_log_error(struct thread_data *td, struct io_u *io_u) @@ -2024,8 +2025,7 @@ static void io_completed(struct thread_data *td, struct io_u **io_u_ptr, if (io_u->error) unlog_io_piece(td, io_u); else { - atomic_store_release(&io_u->ipo->flags, - io_u->ipo->flags & ~IP_F_IN_FLIGHT); + __atomic_store_n(&io_u->ipo->flags, io_u->ipo->flags & ~IP_F_IN_FLIGHT, __ATOMIC_RELEASE); } } @@ -2055,7 +2055,7 @@ static void io_completed(struct thread_data *td, struct io_u **io_u_ptr, */ if (bytes && io_u->resid) { io_u->xfer_buflen = io_u->resid; - io_u->xfer_buf += bytes; + io_u->xfer_buf = static_cast(io_u->xfer_buf) + bytes; io_u->offset += bytes; td->ts.short_io_u[io_u->ddir]++; if (io_u->offset < io_u->file->real_file_size) { @@ -2316,7 +2316,7 @@ void fill_io_buffer(struct thread_data *td, void *buf, unsigned long long min_wr o->buffer_pattern, o->buffer_pattern_bytes); - buf += this_write; + buf = static_cast(buf) + this_write; left -= this_write; save_buf_state(td, rs); } while (left); diff --git a/io_u.h b/io_u.h index b432a54010..074b933ef3 100644 --- a/io_u.h +++ b/io_u.h @@ -12,6 +12,10 @@ #include #endif +#ifdef __cplusplus +extern "C" { +#endif + enum { IO_U_F_FREE = 1 << 0, IO_U_F_FLIGHT = 1 << 1, @@ -198,4 +202,8 @@ static inline enum fio_ddir acct_ddir(struct io_u *io_u) #define io_u_set(td, io_u, val) \ td_flags_set((td), &(io_u)->flags, (val)) +#ifdef __cplusplus +} +#endif + #endif diff --git a/io_u_queue.c b/io_u_queue.cpp similarity index 72% rename from io_u_queue.c rename to io_u_queue.cpp index 41f98bc4fa..793f2a217a 100644 --- a/io_u_queue.c +++ b/io_u_queue.cpp @@ -1,14 +1,16 @@ -#include -#include #include "io_u_queue.h" + +#include +#include + #include "smalloc.h" bool io_u_qinit(struct io_u_queue *q, unsigned int nr, bool shared) { if (shared) - q->io_us = smalloc(nr * sizeof(struct io_u *)); + q->io_us = static_castio_us)>(smalloc(nr * sizeof(struct io_u *))); else - q->io_us = calloc(nr, sizeof(struct io_u *)); + q->io_us = static_castio_us)>(calloc(nr, sizeof(struct io_u *))); if (!q->io_us) return false; @@ -39,7 +41,7 @@ bool io_u_rinit(struct io_u_ring *ring, unsigned int nr) ring->max++; } - ring->ring = calloc(ring->max, sizeof(struct io_u *)); + ring->ring = static_castring)>(calloc(ring->max, sizeof(struct io_u *))); if (!ring->ring) return false; diff --git a/io_u_queue.h b/io_u_queue.h index 87de894a52..53d324b646 100644 --- a/io_u_queue.h +++ b/io_u_queue.h @@ -6,6 +6,10 @@ #include "lib/types.h" +#ifdef __cplusplus +extern "C" { +#endif + struct io_u; struct io_u_queue { @@ -86,4 +90,8 @@ static inline int io_u_rempty(struct io_u_ring *ring) return ring->head == ring->tail; } +#ifdef __cplusplus +} +#endif + #endif diff --git a/ioengines.c b/ioengines.cpp similarity index 98% rename from ioengines.c rename to ioengines.cpp index 361727250e..369f66149e 100644 --- a/ioengines.c +++ b/ioengines.cpp @@ -9,12 +9,13 @@ * generic io engine that could be used for other projects. * */ -#include +#include +#include +#include + #include -#include #include #include -#include #include #include #include @@ -141,9 +142,9 @@ static struct ioengine_ops *dlopen_ioengine(struct thread_data *td, * Unlike the included modules, external engines should have a * non-static ioengine structure that we can reference. */ - ops = dlsym(dlhandle, engine_lib); + ops = static_cast(dlsym(dlhandle, engine_lib)); if (!ops) - ops = dlsym(dlhandle, "ioengine"); + ops = static_cast(dlsym(dlhandle, "ioengine")); /* * For some external engines (like C++ ones) it is not that trivial @@ -152,7 +153,7 @@ static struct ioengine_ops *dlopen_ioengine(struct thread_data *td, * structure. */ if (!ops) { - get_ioengine_t get_ioengine = dlsym(dlhandle, "get_ioengine"); + auto get_ioengine = reinterpret_cast(dlsym(dlhandle, "get_ioengine")); if (get_ioengine) get_ioengine(&ops); @@ -686,7 +687,7 @@ fio_load_dynamic_engines(struct thread_data *td) #define fio_load_dynamic_engines(td) do { } while (0) #endif -int fio_show_ioengine_help(const char *engine) +int fio_show_ioengine_help(char *engine) { struct flist_head *entry; struct thread_data td; diff --git a/ioengines.h b/ioengines.h index 4391b31e3c..4da5c3dc64 100644 --- a/ioengines.h +++ b/ioengines.h @@ -11,6 +11,10 @@ #define FIO_IOOPS_VERSION 33 +#ifdef __cplusplus +extern "C" { +#endif + #ifndef CONFIG_DYNAMIC_ENGINES #define FIO_STATIC static #else @@ -123,6 +127,10 @@ extern void unregister_ioengine(struct ioengine_ops *); extern void free_ioengine(struct thread_data *); extern void close_ioengine(struct thread_data *); -extern int fio_show_ioengine_help(const char *engine); +extern int fio_show_ioengine_help(char *engine); + +#ifdef __cplusplus +} +#endif #endif diff --git a/iolog.c b/iolog.cpp similarity index 93% rename from iolog.c rename to iolog.cpp index 97ba43967f..a7d56c77ff 100644 --- a/iolog.c +++ b/iolog.cpp @@ -2,9 +2,10 @@ * Code related to writing an iolog of what a thread is doing, and to * later read that back and replay */ -#include -#include -#include +#include +#include +#include + #include #include #include @@ -271,7 +272,7 @@ void log_io_piece(struct thread_data *td, struct io_u *io_u) struct fio_rb_node **p, *parent; struct io_piece *ipo, *__ipo; - ipo = calloc(1, sizeof(struct io_piece)); + ipo = static_cast(calloc(1, sizeof(struct io_piece))); init_ipo(ipo); ipo->file = io_u->file; ipo->offset = io_u->offset; @@ -457,9 +458,9 @@ static bool read_iolog(struct thread_data *td) * Read in the read iolog and store it, reuse the infrastructure * for doing verifications. */ - str = malloc(4096); - rfname = fname = malloc(256+16); - act = malloc(256+16); + str = static_cast(malloc(4096)); + rfname = fname = static_cast(malloc(256 + 16)); + act = static_cast(malloc(256 + 16)); syncs = reads = writes = trims = waits = 0; while ((p = fgets(str, 4096, td->io_log_rfile)) != NULL) { @@ -574,7 +575,7 @@ static bool read_iolog(struct thread_data *td) /* * Make note of file */ - ipo = calloc(1, sizeof(*ipo)); + ipo = static_cast(calloc(1, sizeof(*ipo))); init_ipo(ipo); ipo->ddir = rw; if (td->io_log_version == 3) @@ -644,13 +645,13 @@ static bool read_iolog(struct thread_data *td) if (!reads && !writes && !waits && !trims) return false; - td->o.td_ddir = 0; + td->o.td_ddir = static_cast(0); if (reads) - td->o.td_ddir |= TD_DDIR_READ; + td->o.td_ddir = static_cast(static_cast(td->o.td_ddir) | TD_DDIR_READ); if (writes) - td->o.td_ddir |= TD_DDIR_WRITE; + td->o.td_ddir = static_cast(static_cast(td->o.td_ddir) | TD_DDIR_WRITE); if (trims) - td->o.td_ddir |= TD_DDIR_TRIM; + td->o.td_ddir = static_cast(static_cast(td->o.td_ddir) | TD_DDIR_TRIM); return true; } @@ -764,7 +765,7 @@ static bool init_iolog_write(struct thread_data *td) */ td->iolog_f = f; td->iolog_buf = malloc(8192); - setvbuf(f, td->iolog_buf, _IOFBF, 8192); + setvbuf(f, static_cast(td->iolog_buf), _IOFBF, 8192); fio_gettime(&td->io_log_start_time, NULL); /* @@ -823,7 +824,7 @@ void setup_log(struct io_log **log, struct log_params *p, struct io_u_plat_entry *entry; struct flist_head *list; - l = scalloc(1, sizeof(*l)); + l = static_cast(scalloc(1, sizeof(*l))); INIT_FLIST_HEAD(&l->io_logs); l->log_type = p->log_type; l->log_offset = p->log_offset; @@ -842,7 +843,7 @@ void setup_log(struct io_log **log, struct log_params *p, for (i = 0; i < DDIR_RWDIR_CNT; i++) { list = &l->hist_window[i].list; INIT_FLIST_HEAD(list); - entry = calloc(1, sizeof(struct io_u_plat_entry)); + entry = static_cast(calloc(1, sizeof(struct io_u_plat_entry))); flist_add(&entry->list, list); } @@ -850,7 +851,7 @@ void setup_log(struct io_log **log, struct log_params *p, unsigned int def_samples = DEF_LOG_ENTRIES; struct io_logs *__p; - __p = calloc(1, sizeof(*l->pending)); + __p = static_cast(calloc(1, sizeof(*l->pending))); if (l->td->o.iodepth > DEF_LOG_ENTRIES) def_samples = roundup_pow2(l->td->o.iodepth); __p->max_samples = def_samples; @@ -883,7 +884,7 @@ static void *set_file_buffer(FILE *f) void *buf; buf = malloc(size); - setvbuf(f, buf, _IOFBF, size); + setvbuf(f, static_cast(buf), _IOFBF, size); return buf; } @@ -1029,7 +1030,7 @@ void flush_samples(FILE *f, void *samples, uint64_t sample_size) io_sample_ddir(s), (unsigned long long) s->bs, prio_val); } else { - struct io_sample_offset *so = (void *) s; + struct io_sample_offset *so = (struct io_sample_offset *) s; fprintf(f, fmt, (unsigned long) s->time, @@ -1057,7 +1058,7 @@ static struct iolog_compress *get_new_chunk(unsigned int seq) { struct iolog_compress *c; - c = malloc(sizeof(*c)); + c = static_cast(malloc(sizeof(*c))); INIT_FLIST_HEAD(&c->list); c->buf = malloc(GZ_CHUNK); c->len = 0; @@ -1140,7 +1141,7 @@ static size_t inflate_chunk(struct iolog_compress *ic, int gz_hdr, FILE *f, } stream->avail_in = ic->len; - stream->next_in = ic->buf; + stream->next_in = static_castnext_in)>(ic->buf); if (!iter->buf_size) { iter->buf_size = iter->chunk_sz; @@ -1152,7 +1153,7 @@ static size_t inflate_chunk(struct iolog_compress *ic, int gz_hdr, FILE *f, int err; stream->avail_out = this_out; - stream->next_out = iter->buf + iter->buf_used; + stream->next_out = static_cast(iter->buf) + iter->buf_used; err = inflate(stream, Z_NO_FLUSH); if (err < 0) { @@ -1173,7 +1174,7 @@ static size_t inflate_chunk(struct iolog_compress *ic, int gz_hdr, FILE *f, break; } - ret = (void *) stream->next_in - ic->buf; + ret = stream->next_in - static_castnext_in)>(ic->buf); dprint(FD_COMPRESS, "inflated to size=%lu\n", (unsigned long) iter->buf_size); @@ -1286,7 +1287,7 @@ int iolog_file_inflate(const char *file) ic.seq++; ic.len -= iret; - ic.buf += iret; + ic.buf = static_cast(ic.buf) + iret; } while (1); if (iter.seq) { @@ -1460,7 +1461,7 @@ static int gz_work(struct iolog_flush_data *data) seq = ++data->log->chunk_seq; - stream.next_in = (void *) data->samples; + stream.next_in = static_cast(data->samples); stream.avail_in = data->nr_samples * log_entry_sz(data->log); dprint(FD_COMPRESS, "deflate input size=%lu, seq=%u, log=%s\n", @@ -1472,7 +1473,7 @@ static int gz_work(struct iolog_flush_data *data) (unsigned long) c->len); c = get_new_chunk(seq); stream.avail_out = GZ_CHUNK; - stream.next_out = c->buf; + stream.next_out = static_cast(c->buf); ret = deflate(&stream, Z_NO_FLUSH); if (ret < 0) { log_err("fio: deflate log (%d)\n", ret); @@ -1485,7 +1486,7 @@ static int gz_work(struct iolog_flush_data *data) total += c->len; } while (stream.avail_in); - stream.next_out = c->buf + c->len; + stream.next_out = static_cast(c->buf) + c->len; stream.avail_out = GZ_CHUNK - c->len; ret = deflate(&stream, Z_FINISH); @@ -1512,7 +1513,7 @@ static int gz_work(struct iolog_flush_data *data) do { c = get_new_chunk(seq); stream.avail_out = GZ_CHUNK; - stream.next_out = c->buf; + stream.next_out = static_cast(c->buf); ret = deflate(&stream, Z_FINISH); c->len = GZ_CHUNK - stream.avail_out; total += c->len; @@ -1611,7 +1612,7 @@ static int iolog_flush(struct io_log *log) struct iolog_flush_data *data; workqueue_flush(&log->td->log_compress_wq); - data = malloc(sizeof(*data)); + data = static_cast(malloc(sizeof(*data))); if (!data) return 1; @@ -1640,7 +1641,7 @@ int iolog_cur_flush(struct io_log *log, struct io_logs *cur_log) { struct iolog_flush_data *data; - data = smalloc(sizeof(*data)); + data = static_cast(smalloc(sizeof(*data))); if (!data) return 1; @@ -1705,92 +1706,92 @@ uint64_t iolog_nr_samples(struct io_log *iolog) return ret; } -static int __write_log(struct thread_data *td, struct io_log *log, int try) +static int __write_log(struct thread_data *td, struct io_log *log, int __try__) { if (log) - return finish_log(td, log, try); + return finish_log(td, log, __try__); return 0; } -static int write_iops_log(struct thread_data *td, int try, bool unit_log) +static int write_iops_log(struct thread_data *td, int __try__, bool unit_log) { int ret; if (per_unit_log(td->iops_log) != unit_log) return 0; - ret = __write_log(td, td->iops_log, try); + ret = __write_log(td, td->iops_log, __try__); if (!ret) td->iops_log = NULL; return ret; } -static int write_slat_log(struct thread_data *td, int try, bool unit_log) +static int write_slat_log(struct thread_data *td, int __try__, bool unit_log) { int ret; if (!unit_log) return 0; - ret = __write_log(td, td->slat_log, try); + ret = __write_log(td, td->slat_log, __try__); if (!ret) td->slat_log = NULL; return ret; } -static int write_clat_log(struct thread_data *td, int try, bool unit_log) +static int write_clat_log(struct thread_data *td, int __try__, bool unit_log) { int ret; if (!unit_log) return 0; - ret = __write_log(td, td->clat_log, try); + ret = __write_log(td, td->clat_log, __try__); if (!ret) td->clat_log = NULL; return ret; } -static int write_clat_hist_log(struct thread_data *td, int try, bool unit_log) +static int write_clat_hist_log(struct thread_data *td, int __try__, bool unit_log) { int ret; if (!unit_log) return 0; - ret = __write_log(td, td->clat_hist_log, try); + ret = __write_log(td, td->clat_hist_log, __try__); if (!ret) td->clat_hist_log = NULL; return ret; } -static int write_lat_log(struct thread_data *td, int try, bool unit_log) +static int write_lat_log(struct thread_data *td, int __try__, bool unit_log) { int ret; if (!unit_log) return 0; - ret = __write_log(td, td->lat_log, try); + ret = __write_log(td, td->lat_log, __try__); if (!ret) td->lat_log = NULL; return ret; } -static int write_bandw_log(struct thread_data *td, int try, bool unit_log) +static int write_bandw_log(struct thread_data *td, int __try__, bool unit_log) { int ret; if (per_unit_log(td->bw_log) != unit_log) return 0; - ret = __write_log(td, td->bw_log, try); + ret = __write_log(td, td->bw_log, __try__); if (!ret) td->bw_log = NULL; diff --git a/iolog.h b/iolog.h index 62cbd1b02f..314199a759 100644 --- a/iolog.h +++ b/iolog.h @@ -8,6 +8,10 @@ #include "flist.h" #include "ioengines.h" +#ifdef __cplusplus +extern "C" { +#endif + /* * Use for maintaining statistics */ @@ -323,4 +327,8 @@ struct iolog_compress { unsigned int seq; }; +#ifdef __cplusplus +} +#endif + #endif diff --git a/json.c b/json.cpp similarity index 85% rename from json.c rename to json.cpp index cd3d5d74db..e179ceb352 100644 --- a/json.c +++ b/json.cpp @@ -1,23 +1,25 @@ -#include -#include -#include -#include #include "json.h" + +#include +#include +#include +#include + #include "log.h" -struct json_object *json_create_object(void) +struct json_object *json_create_object() { - return calloc(1, sizeof(struct json_object)); + return static_cast(calloc(1, sizeof(struct json_object))); } -struct json_array *json_create_array(void) +struct json_array *json_create_array() { - return calloc(1, sizeof(struct json_array)); + return static_cast(calloc(1, sizeof(struct json_array))); } static struct json_pair *json_create_pair(const char *name, struct json_value *value) { - struct json_pair *pair = malloc(sizeof(struct json_pair)); + struct json_pair *pair = static_cast(malloc(sizeof(struct json_pair))); if (pair) { pair->name = strdup(name); pair->value = value; @@ -30,7 +32,7 @@ static struct json_pair *json_create_pair(const char *name, struct json_value *v static struct json_value *json_create_value_int(long long number) { - struct json_value *value = malloc(sizeof(struct json_value)); + struct json_value *value = static_cast(malloc(sizeof(struct json_value))); if (value) { value->type = JSON_TYPE_INTEGER; @@ -41,7 +43,7 @@ static struct json_value *json_create_value_int(long long number) static struct json_value *json_create_value_float(double number) { - struct json_value *value = malloc(sizeof(struct json_value)); + struct json_value *value = static_cast(malloc(sizeof(struct json_value))); if (value) { value->type = JSON_TYPE_FLOAT; @@ -65,7 +67,7 @@ static char *strdup_escape(const char *str) input++; } - p = ret = malloc(strlen(str) + escapes + 1); + p = ret = static_cast(malloc(strlen(str) + escapes + 1)); while (*str) { if (*str == '\\' || *str == '\"') *p++ = '\\'; @@ -81,7 +83,7 @@ static char *strdup_escape(const char *str) */ static struct json_value *json_create_value_string(const char *str) { - struct json_value *value = malloc(sizeof(struct json_value)); + struct json_value *value = static_cast(malloc(sizeof(struct json_value))); if (value) { value->type = JSON_TYPE_STRING; @@ -96,7 +98,7 @@ static struct json_value *json_create_value_string(const char *str) static struct json_value *json_create_value_object(struct json_object *obj) { - struct json_value *value = malloc(sizeof(struct json_value)); + struct json_value *value = static_cast(malloc(sizeof(struct json_value))); if (value) { value->type = JSON_TYPE_OBJECT; @@ -108,7 +110,7 @@ static struct json_value *json_create_value_object(struct json_object *obj) static struct json_value *json_create_value_array(struct json_array *array) { - struct json_value *value = malloc(sizeof(struct json_value)); + struct json_value *value = static_cast(malloc(sizeof(struct json_value))); if (value) { value->type = JSON_TYPE_ARRAY; @@ -166,8 +168,8 @@ static void json_free_value(struct json_value *value) static int json_array_add_value(struct json_array *array, struct json_value *value) { - struct json_value **values = realloc(array->values, - sizeof(struct json_value *) * (array->value_cnt + 1)); + struct json_value **values = static_cast(realloc(array->values, + sizeof(struct json_value *) * (array->value_cnt + 1))); if (!values) return ENOMEM; @@ -182,8 +184,8 @@ static int json_array_add_value(struct json_array *array, struct json_value *val static int json_object_add_pair(struct json_object *obj, struct json_pair *pair) { - struct json_pair **pairs = realloc(obj->pairs, - sizeof(struct json_pair *) * (obj->pair_cnt + 1)); + struct json_pair **pairs = static_cast(realloc(obj->pairs, + sizeof(struct json_pair *) * (obj->pair_cnt + 1))); if (!pairs) return ENOMEM; pairs[obj->pair_cnt] = pair; diff --git a/json.h b/json.h index 66bb06b1f1..3d20e2e56c 100644 --- a/json.h +++ b/json.h @@ -1,8 +1,14 @@ #ifndef __JSON__H #define __JSON__H +#include "string.h" + #include "lib/output_buffer.h" +#ifdef __cplusplus +extern "C" { +#endif + #define JSON_TYPE_STRING 0 #define JSON_TYPE_INTEGER 1 #define JSON_TYPE_FLOAT 2 @@ -177,4 +183,9 @@ static inline int json_array_add_value_array(struct json_array *obj, (obj->values[obj->value_cnt - 1]->object) void json_print_object(struct json_object *obj, struct buf_output *out); + +#ifdef __cplusplus +} +#endif + #endif diff --git a/lib/axmap.c b/lib/axmap.cpp similarity index 96% rename from lib/axmap.c rename to lib/axmap.cpp index 27301bd846..8341bd5265 100644 --- a/lib/axmap.c +++ b/lib/axmap.cpp @@ -15,10 +15,10 @@ * is roughly 1.9%, or 1.019 bits per block. The number quickly converges * towards 1.0158, or 1.58% of overhead. */ -#include -#include -#include -#include +#include +#include +#include +#include #include "../arch/arch.h" #include "axmap.h" @@ -115,7 +115,7 @@ struct axmap *axmap_new(uint64_t nr_bits) struct axmap *axmap; unsigned int i, levels; - axmap = malloc(sizeof(*axmap)); + axmap = static_cast(malloc(sizeof(*axmap))); if (!axmap) return NULL; @@ -127,7 +127,7 @@ struct axmap *axmap_new(uint64_t nr_bits) } axmap->nr_levels = levels; - axmap->levels = calloc(axmap->nr_levels, sizeof(struct axmap_level)); + axmap->levels = static_castlevels)>(calloc(axmap->nr_levels, sizeof(struct axmap_level))); if (!axmap->levels) goto free_axmap; axmap->nr_bits = nr_bits; @@ -139,7 +139,7 @@ struct axmap *axmap_new(uint64_t nr_bits) al->level = i; al->map_size = nr_bits; - al->map = malloc(al->map_size * sizeof(unsigned long)); + al->map = static_castmap)>(malloc(al->map_size * sizeof(unsigned long))); if (!al->map) goto free_levels; @@ -223,7 +223,7 @@ struct axmap_set_data { static bool axmap_set_fn(struct axmap_level *al, uint64_t offset, unsigned int bit, void *__data) { - struct axmap_set_data *data = __data; + struct axmap_set_data *data = static_cast(__data); unsigned long mask, overlap; unsigned int nr_bits; diff --git a/lib/axmap.h b/lib/axmap.h index aa5976898c..455732c782 100644 --- a/lib/axmap.h +++ b/lib/axmap.h @@ -4,6 +4,10 @@ #include #include "types.h" +#ifdef __cplusplus +extern "C" { +#endif + struct axmap; struct axmap *axmap_new(uint64_t nr_bits); void axmap_free(struct axmap *bm); @@ -14,4 +18,8 @@ bool axmap_isset(struct axmap *axmap, uint64_t bit_nr); uint64_t axmap_next_free(struct axmap *axmap, uint64_t bit_nr); void axmap_reset(struct axmap *axmap); +#ifdef __cplusplus +} +#endif + #endif diff --git a/lib/bloom.c b/lib/bloom.cpp similarity index 90% rename from lib/bloom.c rename to lib/bloom.cpp index f4f9b6b9ee..685aa48b92 100644 --- a/lib/bloom.c +++ b/lib/bloom.cpp @@ -1,4 +1,4 @@ -#include +#include #include "bloom.h" #include "../hash.h" @@ -23,7 +23,7 @@ struct bloom_hash { static uint32_t bloom_crc32c(const void *buf, uint32_t len, uint32_t seed) { - return fio_crc32c(buf, len); + return fio_crc32c(static_cast(buf), len); } static uint32_t bloom_fnv(const void *buf, uint32_t len, uint32_t seed) @@ -66,10 +66,10 @@ struct bloom *bloom_new(uint64_t entries) crc32c_arm64_probe(); crc32c_intel_probe(); - b = malloc(sizeof(*b)); + b = static_cast(malloc(sizeof(*b))); b->nentries = entries; no_uints = (entries + BITS_PER_INDEX - 1) / BITS_PER_INDEX; - b->map = calloc(no_uints, sizeof(uint32_t)); + b->map = static_castmap)>(calloc(no_uints, sizeof(uint32_t))); if (!b->map) { free(b); return NULL; diff --git a/lib/bloom.h b/lib/bloom.h index 141ead9a68..8715c5479b 100644 --- a/lib/bloom.h +++ b/lib/bloom.h @@ -4,6 +4,10 @@ #include #include "../lib/types.h" +#ifdef __cplusplus +extern "C" { +#endif + struct bloom; struct bloom *bloom_new(uint64_t entries); @@ -11,4 +15,8 @@ void bloom_free(struct bloom *b); bool bloom_set(struct bloom *b, uint32_t *data, unsigned int nwords); bool bloom_string(struct bloom *b, const char *data, unsigned int len, bool); +#ifdef __cplusplus +} +#endif + #endif diff --git a/lib/flist_sort.c b/lib/flist_sort.cpp similarity index 100% rename from lib/flist_sort.c rename to lib/flist_sort.cpp diff --git a/lib/gauss.c b/lib/gauss.cpp similarity index 100% rename from lib/gauss.c rename to lib/gauss.cpp diff --git a/lib/gauss.h b/lib/gauss.h index 19e3a6666b..b5f581361f 100644 --- a/lib/gauss.h +++ b/lib/gauss.h @@ -12,9 +12,17 @@ struct gauss_state { bool disable_hash; }; +#ifdef __cplusplus +extern "C" { +#endif + void gauss_init(struct gauss_state *gs, unsigned long nranges, double dev, double center, unsigned int seed); unsigned long long gauss_next(struct gauss_state *gs); void gauss_disable_hash(struct gauss_state *gs); +#ifdef __cplusplus +} +#endif + #endif diff --git a/lib/getrusage.c b/lib/getrusage.cpp similarity index 100% rename from lib/getrusage.c rename to lib/getrusage.cpp diff --git a/lib/getrusage.h b/lib/getrusage.h index 49e64270ee..3c156ac46d 100644 --- a/lib/getrusage.h +++ b/lib/getrusage.h @@ -4,6 +4,14 @@ #include #include +#ifdef __cplusplus +extern "C" { +#endif + extern int fio_getrusage(struct rusage *ru); +#ifdef __cplusplus +} +#endif + #endif diff --git a/lib/hweight.c b/lib/hweight.cpp similarity index 100% rename from lib/hweight.c rename to lib/hweight.cpp diff --git a/lib/hweight.h b/lib/hweight.h index 68861ddd9d..8b7124d035 100644 --- a/lib/hweight.h +++ b/lib/hweight.h @@ -3,8 +3,16 @@ #include +#ifdef __cplusplus +extern "C" { +#endif + unsigned int hweight8(uint8_t w); unsigned int hweight32(uint32_t w); unsigned int hweight64(uint64_t w); +#ifdef __cplusplus +} +#endif + #endif diff --git a/lib/ieee754.c b/lib/ieee754.cpp similarity index 100% rename from lib/ieee754.c rename to lib/ieee754.cpp diff --git a/lib/ieee754.h b/lib/ieee754.h index 5af9518eee..9596ab8e46 100644 --- a/lib/ieee754.h +++ b/lib/ieee754.h @@ -3,6 +3,10 @@ #include +#ifdef __cplusplus +extern "C" { +#endif + extern uint64_t pack754(long double f, unsigned bits, unsigned expbits); extern long double unpack754(uint64_t i, unsigned bits, unsigned expbits); @@ -17,4 +21,8 @@ typedef struct fio_fp64 { } u; } fio_fp64_t; +#ifdef __cplusplus +} +#endif + #endif diff --git a/lib/lfsr.c b/lib/lfsr.cpp similarity index 100% rename from lib/lfsr.c rename to lib/lfsr.cpp diff --git a/lib/lfsr.h b/lib/lfsr.h index 95bc07fd57..74c38a8c43 100644 --- a/lib/lfsr.h +++ b/lib/lfsr.h @@ -3,6 +3,10 @@ #include +#ifdef __cplusplus +extern "C" { +#endif + #define FIO_MAX_TAPS 6 struct lfsr_taps { @@ -27,4 +31,8 @@ int lfsr_init(struct fio_lfsr *fl, uint64_t size, uint64_t seed, unsigned int spin); int lfsr_reset(struct fio_lfsr *fl, uint64_t seed); +#ifdef __cplusplus +} +#endif + #endif diff --git a/lib/memalign.c b/lib/memalign.cpp similarity index 66% rename from lib/memalign.c rename to lib/memalign.cpp index 214a66faca..fd2dc38920 100644 --- a/lib/memalign.c +++ b/lib/memalign.cpp @@ -1,5 +1,5 @@ -#include -#include +#include +#include #include "memalign.h" #include "smalloc.h" @@ -20,8 +20,8 @@ void *__fio_memalign(size_t alignment, size_t size, malloc_fn fn) ptr = fn(size + alignment + sizeof(*f) - 1); if (ptr) { - ret = PTR_ALIGN(ptr, alignment - 1); - f = ret + size; + ret = PTR_ALIGN((char*)(ptr), alignment - 1); + f = reinterpret_cast((char*)ret + size); f->offset = (uintptr_t) ret - (uintptr_t) ptr; } @@ -30,7 +30,7 @@ void *__fio_memalign(size_t alignment, size_t size, malloc_fn fn) void __fio_memfree(void *ptr, size_t size, free_fn fn) { - struct align_footer *f = ptr + size; + struct align_footer *f = reinterpret_cast((char*)ptr + size); - fn(ptr - f->offset); + fn((char*)ptr - f->offset); } diff --git a/lib/memalign.h b/lib/memalign.h index 815e3aa28f..aeaf5af6e6 100644 --- a/lib/memalign.h +++ b/lib/memalign.h @@ -4,10 +4,18 @@ #include #include +#ifdef __cplusplus +extern "C" { +#endif + typedef void* (*malloc_fn)(size_t); typedef void (*free_fn)(void*); extern void *__fio_memalign(size_t alignment, size_t size, malloc_fn fn); extern void __fio_memfree(void *ptr, size_t size, free_fn fn); +#ifdef __cplusplus +} +#endif + #endif diff --git a/lib/memcpy.c b/lib/memcpy.cpp similarity index 89% rename from lib/memcpy.c rename to lib/memcpy.cpp index a552134357..511778bbf6 100644 --- a/lib/memcpy.c +++ b/lib/memcpy.cpp @@ -1,7 +1,7 @@ -#include -#include -#include -#include +#include +#include +#include +#include #include "memcpy.h" #include "rand.h" @@ -84,7 +84,7 @@ enum { }; #define do_test(test, fn) do { \ - size_t left, this; \ + size_t left, __this__; \ void *src, *dst; \ int i; \ \ @@ -93,13 +93,13 @@ enum { src = test->src; \ dst = test->dst; \ while (left) { \ - this = test->size; \ - if (this > left) \ - this = left; \ - (fn)(dst, src, this); \ - left -= this; \ - src += this; \ - dst += this; \ + __this__ = test->size; \ + if (__this__ > left) \ + __this__ = left; \ + (fn)(dst, src, __this__); \ + left -= __this__; \ + src = (char*)(src) + __this__; \ + dst = (char*)(dst) + __this__; \ } \ } \ } while (0) @@ -116,8 +116,8 @@ static void t_memmove(struct memcpy_test *test) static void simple_memcpy(void *dst, void const *src, size_t len) { - char *d = dst; - const char *s = src; + char *d = static_cast(dst); + const char *s = static_cast(src); while (len--) *d++ = *s++; @@ -184,7 +184,7 @@ static unsigned int get_test_mask(const char *type) return mask; } -static int list_types(void) +static int list_types() { int i; @@ -194,7 +194,7 @@ static int list_types(void) return 1; } -static int setup_tests(void) +static int setup_tests() { struct memcpy_test *test; struct frand_state state; @@ -224,7 +224,7 @@ static int setup_tests(void) return 0; } -static void free_tests(void) +static void free_tests() { free(tests[0].src); free(tests[0].dst); diff --git a/lib/memcpy.h b/lib/memcpy.h index f61a4a099e..6dfdcd1363 100644 --- a/lib/memcpy.h +++ b/lib/memcpy.h @@ -1,6 +1,14 @@ #ifndef FIO_MEMCPY_H #define FIO_MEMCPY_H +#ifdef __cplusplus +extern "C" { +#endif + int fio_memcpy_test(const char *type); +#ifdef __cplusplus +} +#endif + #endif diff --git a/lib/mountcheck.c b/lib/mountcheck.cpp similarity index 100% rename from lib/mountcheck.c rename to lib/mountcheck.cpp diff --git a/lib/mountcheck.h b/lib/mountcheck.h index 14ec45a62d..e317dc2911 100644 --- a/lib/mountcheck.h +++ b/lib/mountcheck.h @@ -1,6 +1,14 @@ #ifndef FIO_MOUNT_CHECK_H #define FIO_MOUNT_CHECK_H +#ifdef __cplusplus +extern "C" { +#endif + extern int device_is_mounted(const char *); +#ifdef __cplusplus +} +#endif + #endif diff --git a/lib/num2str.c b/lib/num2str.cpp similarity index 96% rename from lib/num2str.c rename to lib/num2str.cpp index cd89a0e591..e3afefb7bc 100644 --- a/lib/num2str.c +++ b/lib/num2str.cpp @@ -35,7 +35,7 @@ char *num2str(uint64_t num, int maxlen, int base, int pow2, enum n2s_unit units) char tmp[32]; char *buf; - compiletime_assert(sizeof(sistr) == sizeof(iecstr), "unit prefix arrays must be identical sizes"); + static_assert(sizeof(sistr) == sizeof(iecstr), "unit prefix arrays must be identical sizes"); assert(units < FIO_ARRAY_SIZE(unitstr)); if (pow2) diff --git a/lib/num2str.h b/lib/num2str.h index 797288b5af..0ec5cd924b 100644 --- a/lib/num2str.h +++ b/lib/num2str.h @@ -12,6 +12,14 @@ enum n2s_unit { N2S_BITPERSEC = 5, }; +#ifdef __cplusplus +extern "C" { +#endif + extern char *num2str(uint64_t, int, int, int, enum n2s_unit); +#ifdef __cplusplus +} +#endif + #endif diff --git a/lib/output_buffer.c b/lib/output_buffer.cpp similarity index 86% rename from lib/output_buffer.c rename to lib/output_buffer.cpp index beb8a1426a..941f735209 100644 --- a/lib/output_buffer.c +++ b/lib/output_buffer.cpp @@ -1,5 +1,5 @@ -#include -#include +#include +#include #include "output_buffer.h" #include "../minmax.h" @@ -27,7 +27,7 @@ size_t buf_output_add(struct buf_output *out, const char *buf, size_t len) need = max((size_t) BUF_INC, need); out->max_buflen += need; - out->buf = realloc(out->buf, out->max_buflen); + out->buf = static_castbuf)>(realloc(out->buf, out->max_buflen)); old_max = max(old_max, out->buflen + len); if (old_max + need > out->max_buflen) diff --git a/lib/output_buffer.h b/lib/output_buffer.h index 389ed5b7bc..f7c07ac123 100644 --- a/lib/output_buffer.h +++ b/lib/output_buffer.h @@ -9,8 +9,16 @@ struct buf_output { size_t max_buflen; }; +#ifdef __cplusplus +extern "C" { +#endif + void buf_output_init(struct buf_output *out); void buf_output_free(struct buf_output *out); size_t buf_output_add(struct buf_output *out, const char *buf, size_t len); +#ifdef __cplusplus +} +#endif + #endif diff --git a/lib/pattern.c b/lib/pattern.cpp similarity index 98% rename from lib/pattern.c rename to lib/pattern.cpp index 9fca643e32..380637d49b 100644 --- a/lib/pattern.c +++ b/lib/pattern.cpp @@ -1,9 +1,10 @@ -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include + #include #include @@ -163,7 +164,7 @@ static const char *parse_number(const char *beg, char *out, char *_end; /* Looking ahead */ - _end = strcasestr(beg, "0x"); + _end = const_cast(strcasestr(beg, "0x")); if (_end) num = _end - beg; if (num) @@ -428,7 +429,7 @@ int parse_and_fill_pattern_alloc(const char *in, unsigned int in_len, if (count < 0) return count; - *out = malloc(count); + *out = static_cast(malloc(count)); count = parse_and_fill_pattern(in, in_len, *out, count, fmt_desc, fmt, fmt_sz_out); if (count < 0) { diff --git a/lib/pattern.h b/lib/pattern.h index 7123b42d67..bbefd6126b 100644 --- a/lib/pattern.h +++ b/lib/pattern.h @@ -1,6 +1,10 @@ #ifndef FIO_PARSE_PATTERN_H #define FIO_PARSE_PATTERN_H +#ifdef __cplusplus +extern "C" { +#endif + /* * The pattern is dynamically allocated, but that doesn't mean there * are not limits. The network protocol has a limit of @@ -52,4 +56,8 @@ int cpy_pattern(const char *pattern, unsigned int pattern_len, int cmp_pattern(const char *pattern, unsigned int pattern_size, unsigned int off, const char *buf, unsigned int len); +#ifdef __cplusplus +} +#endif + #endif diff --git a/lib/prio_tree.c b/lib/prio_tree.cpp similarity index 99% rename from lib/prio_tree.c rename to lib/prio_tree.cpp index c4f66a4929..3e1454de33 100644 --- a/lib/prio_tree.c +++ b/lib/prio_tree.cpp @@ -51,7 +51,7 @@ static void get_index(const struct prio_tree_node *node, static unsigned long index_bits_to_maxindex[BITS_PER_LONG]; -static void fio_init prio_tree_init(void) +static void fio_init prio_tree_init() { unsigned int i; diff --git a/lib/prio_tree.h b/lib/prio_tree.h index 9bd458f1b6..9b08d7f2d9 100644 --- a/lib/prio_tree.h +++ b/lib/prio_tree.h @@ -3,6 +3,10 @@ #include +#ifdef __cplusplus +extern "C" { +#endif + struct prio_tree_node { struct prio_tree_node *left; struct prio_tree_node *right; @@ -86,4 +90,8 @@ struct prio_tree_node *prio_tree_insert(struct prio_tree_root *root, void prio_tree_remove(struct prio_tree_root *root, struct prio_tree_node *node); struct prio_tree_node *prio_tree_next(struct prio_tree_iter *iter); +#ifdef __cplusplus +} +#endif + #endif /* _LINUX_PRIO_TREE_H */ diff --git a/lib/rand.c b/lib/rand.cpp similarity index 93% rename from lib/rand.c rename to lib/rand.cpp index 0e787a62ba..6d0fd136d6 100644 --- a/lib/rand.c +++ b/lib/rand.cpp @@ -33,7 +33,8 @@ */ -#include +#include + #include "rand.h" #include "pattern.h" #include "../hash.h" @@ -97,7 +98,7 @@ void init_rand_seed(struct frand_state *state, uint64_t seed, bool use64) void __fill_random_buf_small(void *buf, unsigned int len, uint64_t seed) { - uint64_t *b = buf; + uint64_t *b = static_cast(buf); uint64_t *e = b + len / sizeof(*b); unsigned int rest = len % sizeof(*b); @@ -123,7 +124,7 @@ void __fill_random_buf(void *buf, unsigned int len, uint64_t seed) */ rest = (len / sizeof(*b) / CONFIG_SEED_BUCKETS) * CONFIG_SEED_BUCKETS; - b = buf; + b = static_cast(buf); e = b + rest; rest = len - (rest * sizeof(*b)); @@ -159,7 +160,7 @@ void __fill_random_buf_percentage(uint64_t seed, void *buf, if (percentage == 100) { if (pbytes) - (void)cpy_pattern(pattern, pbytes, buf, len); + (void)cpy_pattern(pattern, pbytes, static_cast(buf), len); else memset(buf, 0, len); return; @@ -181,7 +182,7 @@ void __fill_random_buf_percentage(uint64_t seed, void *buf, len -= this_len; if (!len) break; - buf += this_len; + buf = static_cast(buf) + this_len; this_len = segment - this_len; if (this_len > len) @@ -190,12 +191,12 @@ void __fill_random_buf_percentage(uint64_t seed, void *buf, this_len = len; if (pbytes) - (void)cpy_pattern(pattern, pbytes, buf, this_len); + (void)cpy_pattern(pattern, pbytes, static_cast(buf), this_len); else memset(buf, 0, this_len); len -= this_len; - buf += this_len; + buf = static_cast(buf) + this_len; } } diff --git a/lib/rand.h b/lib/rand.h index 2b4be78893..7ab9002b3c 100644 --- a/lib/rand.h +++ b/lib/rand.h @@ -5,6 +5,10 @@ #include #include "types.h" +#ifdef __cplusplus +extern "C" { +#endif + #define FRAND32_MAX (-1U) #define FRAND32_MAX_PLUS_ONE (1.0 * (1ULL << 32)) #define FRAND64_MAX (-1ULL) @@ -168,4 +172,8 @@ extern uint64_t fill_random_buf(struct frand_state *, void *buf, unsigned int le extern void __fill_random_buf_percentage(uint64_t, void *, unsigned int, unsigned int, unsigned int, char *, unsigned int); extern uint64_t fill_random_buf_percentage(struct frand_state *, void *, unsigned int, unsigned int, unsigned int, char *, unsigned int); +#ifdef __cplusplus +} +#endif + #endif diff --git a/lib/rbtree.c b/lib/rbtree.cpp similarity index 96% rename from lib/rbtree.c rename to lib/rbtree.cpp index 6f0feae3a5..e90916eca6 100644 --- a/lib/rbtree.c +++ b/lib/rbtree.cpp @@ -79,7 +79,7 @@ void rb_insert_color(struct fio_rb_node *node, struct rb_root *root) if (parent == gparent->rb_left) { { - register struct fio_rb_node *uncle = gparent->rb_right; + struct fio_rb_node *uncle = gparent->rb_right; if (uncle && rb_is_red(uncle)) { rb_set_black(uncle); @@ -92,7 +92,7 @@ void rb_insert_color(struct fio_rb_node *node, struct rb_root *root) if (parent->rb_right == node) { - register struct fio_rb_node *tmp; + struct fio_rb_node *tmp; __rb_rotate_left(parent, root); tmp = parent; parent = node; @@ -104,7 +104,7 @@ void rb_insert_color(struct fio_rb_node *node, struct rb_root *root) __rb_rotate_right(gparent, root); } else { { - register struct fio_rb_node *uncle = gparent->rb_left; + struct fio_rb_node *uncle = gparent->rb_left; if (uncle && rb_is_red(uncle)) { rb_set_black(uncle); @@ -117,7 +117,7 @@ void rb_insert_color(struct fio_rb_node *node, struct rb_root *root) if (parent->rb_left == node) { - register struct fio_rb_node *tmp; + struct fio_rb_node *tmp; __rb_rotate_right(parent, root); tmp = parent; parent = node; @@ -199,7 +199,7 @@ static void __rb_erase_color(struct fio_rb_node *node, { if (!other->rb_left || rb_is_black(other->rb_left)) { - register struct fio_rb_node *o_right; + struct fio_rb_node *o_right; if ((o_right = other->rb_right)) rb_set_black(o_right); rb_set_red(other); diff --git a/lib/rbtree.h b/lib/rbtree.h index 82ab97a375..47da43ebfc 100644 --- a/lib/rbtree.h +++ b/lib/rbtree.h @@ -97,6 +97,10 @@ static inline struct page * rb_insert_page_cache(struct inode * inode, #include #include +#ifdef __cplusplus +extern "C" { +#endif + struct fio_rb_node { intptr_t rb_parent_color; @@ -153,4 +157,8 @@ static inline void rb_link_node(struct fio_rb_node * node, *rb_link = node; } +#ifdef __cplusplus +} +#endif + #endif /* _LINUX_RBTREE_H */ diff --git a/lib/strntol.c b/lib/strntol.cpp similarity index 100% rename from lib/strntol.c rename to lib/strntol.cpp diff --git a/lib/zipf.c b/lib/zipf.cpp similarity index 98% rename from lib/zipf.c rename to lib/zipf.cpp index 14d7928f66..4dab07d9e0 100644 --- a/lib/zipf.c +++ b/lib/zipf.cpp @@ -1,5 +1,5 @@ -#include -#include +#include +#include #include "zipf.h" #include "../minmax.h" #include "../hash.h" diff --git a/lib/zipf.h b/lib/zipf.h index 332e3b2f45..a8e9272449 100644 --- a/lib/zipf.h +++ b/lib/zipf.h @@ -16,6 +16,10 @@ struct zipf_state { bool disable_hash; }; +#ifdef __cplusplus +extern "C" { +#endif + void zipf_init(struct zipf_state *zs, uint64_t nranges, double theta, double center, unsigned int seed); uint64_t zipf_next(struct zipf_state *zs); @@ -25,4 +29,8 @@ void pareto_init(struct zipf_state *zs, uint64_t nranges, double h, uint64_t pareto_next(struct zipf_state *zs); void zipf_disable_hash(struct zipf_state *zs); +#ifdef __cplusplus +} +#endif + #endif diff --git a/libfio.c b/libfio.cpp similarity index 85% rename from libfio.c rename to libfio.cpp index 5e3fd30b71..dd8d373260 100644 --- a/libfio.c +++ b/libfio.cpp @@ -22,10 +22,11 @@ * */ -#include -#include -#include -#include +#include +#include +#include +#include + #include #include "fio.h" @@ -161,7 +162,7 @@ void reset_all_stats(struct thread_data *td) helper_reset(); } -void reset_fio_state(void) +void reset_fio_state() { int i; @@ -207,7 +208,7 @@ static const char *td_runstates[] = { const char *runstate_to_name(int runstate) { - compiletime_assert(TD_LAST == 12, "td runstate list"); + static_assert(TD_LAST == 12, "td runstate list"); if (runstate >= 0 && runstate < TD_LAST) return td_runstates[runstate]; @@ -282,7 +283,7 @@ void fio_terminate_threads(unsigned int group_id, unsigned int terminate) } end_for_each(); } -int fio_running_or_pending_io_threads(void) +int fio_running_or_pending_io_threads() { int nr_io_threads = 0; @@ -324,7 +325,7 @@ enum { ENDIAN_BROKEN, }; -static int endian_check(void) +static int endian_check() { union { uint8_t c[8]; @@ -364,20 +365,20 @@ int initialize_fio(char *envp[]) * can run into problems on archs that fault on unaligned fp * access (ARM). */ - compiletime_assert((offsetof(struct thread_data, ts) % sizeof(void *)) == 0, "ts"); - compiletime_assert((offsetof(struct thread_stat, percentile_list) % 8) == 0, "stat percentile_list"); - compiletime_assert((offsetof(struct thread_stat, total_run_time) % 8) == 0, "total_run_time"); - compiletime_assert((offsetof(struct thread_stat, total_err_count) % 8) == 0, "total_err_count"); - compiletime_assert((offsetof(struct thread_stat, latency_percentile) % 8) == 0, "stat latency_percentile"); - compiletime_assert((offsetof(struct thread_data, ts.clat_stat) % 8) == 0, "ts.clat_stat"); - compiletime_assert((offsetof(struct thread_options_pack, zipf_theta) % 8) == 0, "zipf_theta"); - compiletime_assert((offsetof(struct thread_options_pack, pareto_h) % 8) == 0, "pareto_h"); - compiletime_assert((offsetof(struct thread_options_pack, percentile_list) % 8) == 0, "percentile_list"); - compiletime_assert((offsetof(struct thread_options_pack, latency_percentile) % 8) == 0, "latency_percentile"); - compiletime_assert((offsetof(struct jobs_eta, m_rate) % 8) == 0, "m_rate"); - - compiletime_assert(__TD_F_LAST <= TD_ENG_FLAG_SHIFT, "TD_ENG_FLAG_SHIFT"); - compiletime_assert(BSSPLIT_MAX <= ZONESPLIT_MAX, "bsssplit/zone max"); + static_assert((offsetof(struct thread_data, ts) % sizeof(void *)) == 0, "ts"); + static_assert((offsetof(struct thread_stat, percentile_list) % 8) == 0, "stat percentile_list"); + static_assert((offsetof(struct thread_stat, total_run_time) % 8) == 0, "total_run_time"); + static_assert((offsetof(struct thread_stat, total_err_count) % 8) == 0, "total_err_count"); + static_assert((offsetof(struct thread_stat, latency_percentile) % 8) == 0, "stat latency_percentile"); + static_assert((offsetof(struct thread_data, ts.clat_stat) % 8) == 0, "ts.clat_stat"); + static_assert((offsetof(struct thread_options_pack, zipf_theta) % 8) == 0, "zipf_theta"); + static_assert((offsetof(struct thread_options_pack, pareto_h) % 8) == 0, "pareto_h"); + static_assert((offsetof(struct thread_options_pack, percentile_list) % 8) == 0, "percentile_list"); + static_assert((offsetof(struct thread_options_pack, latency_percentile) % 8) == 0, "latency_percentile"); + static_assert((offsetof(struct jobs_eta, m_rate) % 8) == 0, "m_rate"); + + static_assert(__TD_F_LAST <= TD_ENG_FLAG_SHIFT, "TD_ENG_FLAG_SHIFT"); + static_assert(BSSPLIT_MAX <= ZONESPLIT_MAX, "bsssplit/zone max"); err = endian_check(); if (err) { @@ -438,7 +439,7 @@ int initialize_fio(char *envp[]) return 0; } -void deinitialize_fio(void) +void deinitialize_fio() { fio_keywords_exit(); } diff --git a/log.c b/log.cpp similarity index 95% rename from log.c rename to log.cpp index df58ea07a5..9466ab8904 100644 --- a/log.c +++ b/log.cpp @@ -1,9 +1,11 @@ #include "log.h" +#include +#include +#include + #include -#include -#include -#include +#include #include "fio.h" #include "oslib/asprintf.h" @@ -98,7 +100,7 @@ size_t __log_buf(struct buf_output *buf, const char *format, ...) return len; } -int log_info_flush(void) +int log_info_flush() { if (is_backend || log_syslog) return 0; diff --git a/log.h b/log.h index 562f3f4202..5f6feb90ba 100644 --- a/log.h +++ b/log.h @@ -1,8 +1,12 @@ #ifndef FIO_LOG_H #define FIO_LOG_H -#include +#ifdef __cplusplus +extern "C" { +#endif + #include +#include #include #include "lib/output_buffer.h" @@ -37,4 +41,8 @@ enum { extern const char *log_get_level(int level); +#ifdef __cplusplus +} // extern "C" +#endif + #endif diff --git a/memory.c b/memory.cpp similarity index 96% rename from memory.c rename to memory.cpp index 2fdca65768..65c47686cd 100644 --- a/memory.c +++ b/memory.cpp @@ -95,7 +95,7 @@ static int alloc_mem_shm(struct thread_data *td, unsigned int total_mem) return 1; } - td->orig_buffer = shmat(td->shm_id, NULL, 0); + td->orig_buffer = static_castorig_buffer)>(shmat(td->shm_id, NULL, 0)); dprint(FD_MEM, "shmat %d, %p\n", td->shm_id, td->orig_buffer); if (td->orig_buffer == (void *) -1) { td_verror(td, errno, "shmat"); @@ -162,8 +162,8 @@ static int alloc_mem_mmap(struct thread_data *td, size_t total_mem) } else flags |= OS_MAP_ANON | MAP_PRIVATE; - td->orig_buffer = mmap(NULL, total_mem, PROT_READ | PROT_WRITE, flags, - td->mmapfd, 0); + td->orig_buffer = static_castorig_buffer)>(mmap(NULL, total_mem, PROT_READ | PROT_WRITE, flags, + td->mmapfd, 0)); dprint(FD_MEM, "mmap %llu/%d %p\n", (unsigned long long) total_mem, td->mmapfd, td->orig_buffer); if (td->orig_buffer == MAP_FAILED) { @@ -197,7 +197,7 @@ static void free_mem_mmap(struct thread_data *td, size_t total_mem) static int alloc_mem_malloc(struct thread_data *td, size_t total_mem) { - td->orig_buffer = malloc(total_mem); + td->orig_buffer = static_castorig_buffer)>(malloc(total_mem)); dprint(FD_MEM, "malloc %llu %p\n", (unsigned long long) total_mem, td->orig_buffer); diff --git a/minmax.h b/minmax.h index ec0848c0d6..4c96cbaa43 100644 --- a/minmax.h +++ b/minmax.h @@ -1,6 +1,8 @@ #ifndef FIO_MIN_MAX_H #define FIO_MIN_MAX_H +#ifndef __cplusplus + #ifndef min #define min(x,y) ({ \ __typeof__(x) _x = (x); \ @@ -17,6 +19,24 @@ _x > _y ? _x : _y; }) #endif +#else // __cplusplus + +#include + +template +constexpr decltype(auto) min(T const& a, T const& b) +{ + return std::min(a, b); +} + +template +constexpr decltype(auto) max(T const& a, T const& b) +{ + return std::max(a, b); +} + +#endif + #define min_not_zero(x, y) ({ \ __typeof__(x) __x = (x); \ __typeof__(y) __y = (y); \ diff --git a/optgroup.c b/optgroup.cpp similarity index 97% rename from optgroup.c rename to optgroup.cpp index bebb4a5133..448d928244 100644 --- a/optgroup.c +++ b/optgroup.cpp @@ -1,5 +1,6 @@ -#include -#include +#include +#include + #include "optgroup.h" #include "compiler/compiler.h" @@ -222,7 +223,7 @@ const struct opt_group *opt_group_from_mask(uint64_t *mask) const struct opt_group *opt_group_cat_from_mask(uint64_t *mask) { - compiletime_assert(__FIO_OPT_G_NR <= 8 * sizeof(uint64_t), + static_assert(__FIO_OPT_G_NR <= 8 * sizeof(uint64_t), "__FIO_OPT_G_NR"); return group_from_mask(fio_opt_cat_groups, mask, FIO_OPT_G_INVALID); diff --git a/optgroup.h b/optgroup.h index 024b902f63..0178c6451b 100644 --- a/optgroup.h +++ b/optgroup.h @@ -1,6 +1,10 @@ #ifndef FIO_OPT_GROUP_H #define FIO_OPT_GROUP_H +#ifdef __cplusplus +extern "C" { +#endif + struct opt_group { const char *name; uint64_t mask; @@ -127,4 +131,8 @@ enum opt_category_group { extern const struct opt_group *opt_group_from_mask(uint64_t *mask); extern const struct opt_group *opt_group_cat_from_mask(uint64_t *mask); +#ifdef __cplusplus +} +#endif + #endif diff --git a/options.c b/options.cpp similarity index 97% rename from options.c rename to options.cpp index 48aa0d7b1c..fa9a3ea117 100644 --- a/options.c +++ b/options.cpp @@ -1,9 +1,10 @@ -#include -#include +#include +#include +#include +#include +#include + #include -#include -#include -#include #include #include #include @@ -32,7 +33,7 @@ static const struct pattern_fmt_desc fmt_desc[] = { /* * Check if mmap/mmaphuge has a :/foo/bar/file at the end. If so, return that. */ -static char *get_opt_postfix(const char *str) +static char *get_opt_postfix(char *str) { char *p = strstr(str, ":"); @@ -68,8 +69,8 @@ static bool split_parse_distr(const char *str, double *val, double *center) static int bs_cmp(const void *p1, const void *p2) { - const struct bssplit *bsp1 = p1; - const struct bssplit *bsp2 = p2; + auto const *bsp1 = static_cast(p1); + auto const *bsp2 = static_cast(p2); return (int) bsp1->perc - (int) bsp2->perc; } @@ -149,7 +150,7 @@ static int bssplit_ddir(struct thread_options *o, void *eo, max_bs = 0; min_bs = -1; - o->bssplit[ddir] = malloc(split.nr * sizeof(struct bssplit)); + o->bssplit[ddir] = static_cast(malloc(split.nr * sizeof(struct bssplit))); o->bssplit_nr[ddir] = split.nr; for (i = 0; i < split.nr; i++) { if (split.val1[i] > max_bs) @@ -254,8 +255,8 @@ int str_split_parse(struct thread_data *td, char *str, static int fio_fdp_cmp(const void *p1, const void *p2) { - const uint16_t *t1 = p1; - const uint16_t *t2 = p2; + const uint16_t *t1 = static_cast(p1); + const uint16_t *t2 = static_cast(p2); return *t1 - *t2; } @@ -282,7 +283,7 @@ static int str_fdp_pli_cb(void *data, const char *input) static int str_bssplit_cb(void *data, const char *input) { - struct thread_data *td = cb_data_to_td(data); + auto *td = static_cast(cb_data_to_td(data)); char *str, *p; int ret = 0; @@ -313,7 +314,7 @@ static int parse_cmdprio_bssplit_entry(struct thread_options *o, int matches = 0; char *bs_str = NULL; long long bs_val; - unsigned int perc = 0, class, level, hint; + unsigned int perc = 0, class__, level, hint; /* * valid entry formats: @@ -323,7 +324,7 @@ static int parse_cmdprio_bssplit_entry(struct thread_options *o, * bs/perc/class/level/hint - %s/%u/%u/%u/%u */ matches = sscanf(str, "%m[^/]/%u/%u/%u/%u", - &bs_str, &perc, &class, &level, &hint); + &bs_str, &perc, &class__, &level, &hint); if (matches < 1) { log_err("fio: invalid cmdprio_bssplit format\n"); return 1; @@ -345,13 +346,13 @@ static int parse_cmdprio_bssplit_entry(struct thread_options *o, break; case 4: /* bs/perc/class/level case */ case 5: /* bs/perc/class/level/hint case */ - class = min(class, (unsigned int) IOPRIO_MAX_PRIO_CLASS); + class__ = min(class__, (unsigned int) IOPRIO_MAX_PRIO_CLASS); level = min(level, (unsigned int) IOPRIO_MAX_PRIO); if (matches == 5) hint = min(hint, (unsigned int) IOPRIO_MAX_PRIO_HINT); else hint = 0; - entry->prio = ioprio_value(class, level, hint); + entry->prio = ioprio_value(class__, level, hint); break; default: log_err("fio: invalid cmdprio_bssplit format\n"); @@ -368,8 +369,8 @@ static int parse_cmdprio_bssplit_entry(struct thread_options *o, */ static int fio_split_prio_cmp(const void *p1, const void *p2) { - const struct split_prio *tmp1 = p1; - const struct split_prio *tmp2 = p2; + auto const *tmp1 = static_cast(p1); + auto const *tmp2 = static_cast(p2); if (tmp1->bs > tmp2->bs) return 1; @@ -403,7 +404,7 @@ int split_parse_prio_ddir(struct thread_options *o, struct split_prio **entries, return 1; } - tmp_entries = calloc(nr_bssplits, sizeof(*tmp_entries)); + tmp_entries = static_cast(calloc(nr_bssplits, sizeof(*tmp_entries))); if (!tmp_entries) return 1; @@ -469,7 +470,7 @@ static int ignore_error_type(struct thread_data *td, enum error_type_bit etype, } td->o.ignore_error_nr[etype] = 4; - error = calloc(4, sizeof(int)); + error = static_cast(calloc(4, sizeof(int))); i = 0; while ((fname = strsep(&str, ":")) != NULL) { @@ -482,8 +483,8 @@ static int ignore_error_type(struct thread_data *td, enum error_type_bit etype, */ if (i == td->o.ignore_error_nr[etype]) { td->o.ignore_error_nr[etype] <<= 1; - error = realloc(error, td->o.ignore_error_nr[etype] - * sizeof(int)); + error = static_cast(realloc(error, td->o.ignore_error_nr[etype] + * sizeof(int))); } if (fname[0] == 'E') { error[i] = str2error(fname); @@ -502,7 +503,7 @@ static int ignore_error_type(struct thread_data *td, enum error_type_bit etype, i++; } if (i) { - td->o.continue_on_error |= 1 << etype; + td->o.continue_on_error = static_casto.continue_on_error)>(td->o.continue_on_error | 1 << etype); td->o.ignore_error_nr[etype] = i; td->o.ignore_error[etype] = error; } else { @@ -556,7 +557,7 @@ static int str_ignore_error_cb(void *data, const char *input) struct thread_data *td = cb_data_to_td(data); char *str, *p, *n; int ret = 1; - enum error_type_bit type = 0; + auto type = 0; if (parse_dryrun()) return 0; @@ -570,7 +571,7 @@ static int str_ignore_error_cb(void *data, const char *input) n = strchr(p, ','); if (n) *n++ = '\0'; - ret = ignore_error_type(td, type, p); + ret = ignore_error_type(td, static_cast(type), p); if (ret) break; p = n; @@ -580,7 +581,7 @@ static int str_ignore_error_cb(void *data, const char *input) return ret; } -static int str_rw_cb(void *data, const char *str) +static int str_rw_cb(void *data, char *str) { struct thread_data *td = cb_data_to_td(data); struct thread_options *o = &td->o; @@ -614,7 +615,7 @@ static int str_rw_cb(void *data, const char *str) return 0; } -static int str_mem_cb(void *data, const char *mem) +static int str_mem_cb(void *data, char *mem) { struct thread_data *td = cb_data_to_td(data); @@ -653,7 +654,7 @@ static int str_rwmix_write_cb(void *data, unsigned long long *val) return 0; } -static int str_exitall_cb(void) +static int str_exitall_cb() { exitall_on_terminate = true; return 0; @@ -954,7 +955,7 @@ static int str_numa_mpol_cb(void *data, char *input) } #endif -static int str_fst_cb(void *data, const char *str) +static int str_fst_cb(void *data, char *str) { struct thread_data *td = cb_data_to_td(data); double val; @@ -1041,7 +1042,7 @@ static int str_fst_cb(void *data, const char *str) } #ifdef CONFIG_SYNC_FILE_RANGE -static int str_sfr_cb(void *data, const char *str) +static int str_sfr_cb(void *data, char *str) { struct thread_data *td = cb_data_to_td(data); char *nr = get_opt_postfix(str); @@ -1069,7 +1070,7 @@ static int zone_split_ddir(struct thread_options *o, void *eo, if (!split.nr) return 0; - o->zone_split[ddir] = malloc(split.nr * sizeof(struct zone_split)); + o->zone_split[ddir] = static_cast(malloc(split.nr * sizeof(struct zone_split))); o->zone_split_nr[ddir] = split.nr; for (i = 0; i < split.nr; i++) { o->zone_split[ddir][i].access_perc = split.val1[i]; @@ -1204,7 +1205,7 @@ static int parse_zoned_distribution(struct thread_data *td, const char *input, return ret; } -static int str_random_distribution_cb(void *data, const char *str) +static int str_random_distribution_cb(void *data, char *str) { struct thread_data *td = cb_data_to_td(data); double val; @@ -1268,7 +1269,7 @@ static int str_random_distribution_cb(void *data, const char *str) return 0; } -static int str_steadystate_cb(void *data, const char *str) +static int str_steadystate_cb(void *data, char *str) { struct thread_data *td = cb_data_to_td(data); double val; @@ -1855,8 +1856,8 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .type = FIO_OPT_STR_STORE, .off1 = offsetof(struct thread_options, filename), .maxlen = PATH_MAX, - .cb = str_filename_cb, .prio = -1, /* must come after "directory" */ + .cb = reinterpret_cast(str_filename_cb), .help = "File(s) to use for the workload", .category = FIO_OPT_C_FILE, .group = FIO_OPT_G_FILENAME, @@ -1866,7 +1867,7 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .lname = "Directory", .type = FIO_OPT_STR_STORE, .off1 = offsetof(struct thread_options, directory), - .cb = str_directory_cb, + .cb = reinterpret_cast(str_directory_cb), .help = "Directory to store files in", .category = FIO_OPT_C_FILE, .group = FIO_OPT_G_FILENAME, @@ -1897,13 +1898,9 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .lname = "Lockfile", .type = FIO_OPT_STR, .off1 = offsetof(struct thread_options, file_lock_mode), - .help = "Lock file when doing IO to it", .prio = 1, - .parent = "filename", - .hide = 0, + .help = "Lock file when doing IO to it", .def = "none", - .category = FIO_OPT_C_FILE, - .group = FIO_OPT_G_FILENAME, .posval = { { .ival = "none", .oval = FILE_LOCK_NONE, @@ -1919,13 +1916,17 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .help = "Read vs write lock", }, }, + .parent = "filename", + .hide = 0, + .category = FIO_OPT_C_FILE, + .group = FIO_OPT_G_FILENAME, }, { .name = "opendir", .lname = "Open directory", .type = FIO_OPT_STR_STORE, .off1 = offsetof(struct thread_options, opendir), - .cb = str_opendir_cb, + .cb = reinterpret_cast(str_opendir_cb), .help = "Recursively add files from this directory and down", .category = FIO_OPT_C_FILE, .group = FIO_OPT_G_FILENAME, @@ -1935,13 +1936,10 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .lname = "Read/write", .alias = "readwrite", .type = FIO_OPT_STR, - .cb = str_rw_cb, .off1 = offsetof(struct thread_options, td_ddir), + .cb = reinterpret_cast(str_rw_cb), .help = "IO direction", .def = "read", - .verify = rw_verify, - .category = FIO_OPT_C_IO, - .group = FIO_OPT_G_IO_BASIC, .posval = { { .ival = "read", .oval = TD_DDIR_READ, @@ -1988,6 +1986,9 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .help = "Randomly trim and write mix, trims preceding writes" }, }, + .verify = rw_verify, + .category = FIO_OPT_C_IO, + .group = FIO_OPT_G_IO_BASIC, }, { .name = "rw_sequencer", @@ -1996,8 +1997,6 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .off1 = offsetof(struct thread_options, rw_seq), .help = "IO offset generator modifier", .def = "sequential", - .category = FIO_OPT_C_IO, - .group = FIO_OPT_G_IO_BASIC, .posval = { { .ival = "sequential", .oval = RW_SEQ_SEQ, @@ -2008,6 +2007,8 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .help = "Generate identical offsets", }, }, + .category = FIO_OPT_C_IO, + .group = FIO_OPT_G_IO_BASIC, }, { @@ -2017,8 +2018,6 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .off1 = offsetof(struct thread_options, ioengine), .help = "IO engine to use", .def = FIO_PREFERRED_ENGINE, - .category = FIO_OPT_C_IO, - .group = FIO_OPT_G_IO_BASIC, .posval = { { .ival = "sync", .help = "Use read/write", @@ -2154,7 +2153,7 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { }, { .ival = "external", .help = "Load external engine (append name)", - .cb = str_ioengine_external_cb, + .cb = reinterpret_cast(str_ioengine_external_cb), }, #ifdef CONFIG_LIBPMEM { .ival = "libpmem", @@ -2185,15 +2184,17 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { }, #endif }, + .category = FIO_OPT_C_IO, + .group = FIO_OPT_G_IO_BASIC, }, { .name = "iodepth", .lname = "IO Depth", .type = FIO_OPT_INT, .off1 = offsetof(struct thread_options, iodepth), - .help = "Number of IO buffers to keep in flight", .minval = 1, .interval = 1, + .help = "Number of IO buffers to keep in flight", .def = "1", .category = FIO_OPT_C_IO, .group = FIO_OPT_G_IO_BASIC, @@ -2204,11 +2205,11 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .alias = "iodepth_batch_submit", .type = FIO_OPT_INT, .off1 = offsetof(struct thread_options, iodepth_batch), + .interval = 1, .help = "Number of IO buffers to submit in one go", + .def = "1", .parent = "iodepth", .hide = 1, - .interval = 1, - .def = "1", .category = FIO_OPT_C_IO, .group = FIO_OPT_G_IO_BASIC, }, @@ -2218,12 +2219,12 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .alias = "iodepth_batch_complete", .type = FIO_OPT_INT, .off1 = offsetof(struct thread_options, iodepth_batch_complete_min), - .help = "Min number of IO buffers to retrieve in one go", - .parent = "iodepth", - .hide = 1, .minval = 0, .interval = 1, + .help = "Min number of IO buffers to retrieve in one go", .def = "1", + .parent = "iodepth", + .hide = 1, .category = FIO_OPT_C_IO, .group = FIO_OPT_G_IO_BASIC, }, @@ -2232,11 +2233,11 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .lname = "Max IO depth batch complete", .type = FIO_OPT_INT, .off1 = offsetof(struct thread_options, iodepth_batch_complete_max), + .minval = 0, + .interval = 1, .help = "Max number of IO buffers to retrieve in one go", .parent = "iodepth", .hide = 1, - .minval = 0, - .interval = 1, .category = FIO_OPT_C_IO, .group = FIO_OPT_G_IO_BASIC, }, @@ -2245,21 +2246,21 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .lname = "IO Depth batch low", .type = FIO_OPT_INT, .off1 = offsetof(struct thread_options, iodepth_low), + .interval = 1, .help = "Low water mark for queuing depth", .parent = "iodepth", .hide = 1, - .interval = 1, .category = FIO_OPT_C_IO, .group = FIO_OPT_G_IO_BASIC, }, { .name = "serialize_overlap", .lname = "Serialize overlap", - .off1 = offsetof(struct thread_options, serialize_overlap), .type = FIO_OPT_BOOL, + .off1 = offsetof(struct thread_options, serialize_overlap), .help = "Wait for in-flight IOs that collide to complete", - .parent = "iodepth", .def = "0", + .parent = "iodepth", .category = FIO_OPT_C_IO, .group = FIO_OPT_G_IO_BASIC, }, @@ -2270,8 +2271,6 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .off1 = offsetof(struct thread_options, io_submit_mode), .help = "How IO submissions and completions are done", .def = "inline", - .category = FIO_OPT_C_IO, - .group = FIO_OPT_G_IO_BASIC, .posval = { { .ival = "inline", .oval = IO_MODE_INLINE, @@ -2282,24 +2281,26 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .help = "Offload submit and complete to threads", }, }, + .category = FIO_OPT_C_IO, + .group = FIO_OPT_G_IO_BASIC, }, { .name = "size", .lname = "Size", .type = FIO_OPT_STR_VAL_ZONE, - .cb = str_size_cb, .off1 = offsetof(struct thread_options, size), + .cb = reinterpret_cast(str_size_cb), .help = "Total size of device or files", .category = FIO_OPT_C_IO, .group = FIO_OPT_G_INVALID, }, { .name = "io_size", - .alias = "io_limit", .lname = "IO Size", + .alias = "io_limit", .type = FIO_OPT_STR_VAL_ZONE, - .cb = str_io_size_cb, .off1 = offsetof(struct thread_options, io_size), + .cb = reinterpret_cast(str_io_size_cb), .help = "Total size of I/O to be performed", .category = FIO_OPT_C_IO, .group = FIO_OPT_G_INVALID, @@ -2322,8 +2323,8 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .off1 = offsetof(struct thread_options, file_size_low), .off2 = offsetof(struct thread_options, file_size_high), .minval = 1, - .help = "Size of individual files", .interval = 1024 * 1024, + .help = "Size of individual files", .category = FIO_OPT_C_FILE, .group = FIO_OPT_G_INVALID, }, @@ -2342,8 +2343,8 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .lname = "IO offset", .alias = "fileoffset", .type = FIO_OPT_STR_VAL_ZONE, - .cb = str_offset_cb, .off1 = offsetof(struct thread_options, start_offset), + .cb = reinterpret_cast(str_offset_cb), .help = "Start IO from this offset", .def = "0", .category = FIO_OPT_C_IO, @@ -2354,9 +2355,9 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .lname = "IO offset alignment", .type = FIO_OPT_INT, .off1 = offsetof(struct thread_options, start_offset_align), + .interval = 512, .help = "Start IO from this offset alignment", .def = "0", - .interval = 512, .category = FIO_OPT_C_IO, .group = FIO_OPT_G_INVALID, }, @@ -2364,12 +2365,12 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .name = "offset_increment", .lname = "IO offset increment", .type = FIO_OPT_STR_VAL_ZONE, - .cb = str_offset_increment_cb, .off1 = offsetof(struct thread_options, offset_increment), + .cb = reinterpret_cast(str_offset_increment_cb), .help = "What is the increment from one offset to the next", + .def = "0", .parent = "offset", .hide = 1, - .def = "0", .category = FIO_OPT_C_IO, .group = FIO_OPT_G_INVALID, }, @@ -2392,11 +2393,11 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .off2 = offsetof(struct thread_options, bs[DDIR_WRITE]), .off3 = offsetof(struct thread_options, bs[DDIR_TRIM]), .minval = 1, + .interval = 512, .help = "Block size unit", .def = "4096", .parent = "rw", .hide = 1, - .interval = 512, .category = FIO_OPT_C_IO, .group = FIO_OPT_G_INVALID, }, @@ -2409,10 +2410,10 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .off2 = offsetof(struct thread_options, ba[DDIR_WRITE]), .off3 = offsetof(struct thread_options, ba[DDIR_TRIM]), .minval = 1, + .interval = 512, .help = "IO block offset alignment", .parent = "rw", .hide = 1, - .interval = 512, .category = FIO_OPT_C_IO, .group = FIO_OPT_G_INVALID, }, @@ -2428,10 +2429,10 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .off5 = offsetof(struct thread_options, min_bs[DDIR_TRIM]), .off6 = offsetof(struct thread_options, max_bs[DDIR_TRIM]), .minval = 1, + .interval = 4096, .help = "Set block size range (in more detail than bs)", .parent = "rw", .hide = 1, - .interval = 4096, .category = FIO_OPT_C_IO, .group = FIO_OPT_G_INVALID, }, @@ -2439,8 +2440,8 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .name = "bssplit", .lname = "Block size split", .type = FIO_OPT_STR_ULL, - .cb = str_bssplit_cb, .off1 = offsetof(struct thread_options, bssplit), + .cb = reinterpret_cast(str_bssplit_cb), .help = "Set a specific mix of block sizes", .parent = "rw", .hide = 1, @@ -2512,9 +2513,9 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .type = FIO_OPT_BOOL, .off1 = offsetof(struct thread_options, softrandommap), .help = "Set norandommap if randommap allocation fails", + .def = "0", .parent = "norandommap", .hide = 1, - .def = "0", .category = FIO_OPT_C_IO, .group = FIO_OPT_G_RANDOM, }, @@ -2548,7 +2549,7 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .lname = "Random Distribution", .type = FIO_OPT_STR, .off1 = offsetof(struct thread_options, random_distribution), - .cb = str_random_distribution_cb, + .cb = reinterpret_cast(str_random_distribution_cb), .help = "Random offset distribution generator", .def = "random", .posval = { @@ -2588,9 +2589,9 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .off2 = offsetof(struct thread_options, perc_rand[DDIR_WRITE]), .off3 = offsetof(struct thread_options, perc_rand[DDIR_TRIM]), .maxval = 100, + .interval = 5, .help = "Percentage of seq/random mix that should be random", .def = "100,100,100", - .interval = 5, .inverse = "percentage_sequential", .category = FIO_OPT_C_IO, .group = FIO_OPT_G_RANDOM, @@ -2608,9 +2609,9 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .alias = "nr_files", .type = FIO_OPT_INT, .off1 = offsetof(struct thread_options, nr_files), + .interval = 1, .help = "Split job workload between this number of files", .def = "1", - .interval = 1, .category = FIO_OPT_C_FILE, .group = FIO_OPT_G_INVALID, }, @@ -2627,12 +2628,10 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .name = "file_service_type", .lname = "File service type", .type = FIO_OPT_STR, - .cb = str_fst_cb, .off1 = offsetof(struct thread_options, file_service_type), + .cb = reinterpret_cast(str_fst_cb), .help = "How to select which file to service next", .def = "roundrobin", - .category = FIO_OPT_C_FILE, - .group = FIO_OPT_G_INVALID, .posval = { { .ival = "random", .oval = FIO_FSERVICE_RANDOM, @@ -2665,6 +2664,8 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { }, .parent = "nrfiles", .hide = 1, + .category = FIO_OPT_C_FILE, + .group = FIO_OPT_G_INVALID, }, { .name = "fallocate", @@ -2677,8 +2678,6 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { #else .def = "none", #endif - .category = FIO_OPT_C_FILE, - .group = FIO_OPT_G_INVALID, .posval = { { .ival = "none", .oval = FIO_FALLOCATE_NONE, @@ -2716,12 +2715,16 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { }, #endif }, + .category = FIO_OPT_C_FILE, + .group = FIO_OPT_G_INVALID, }, { .name = "fadvise_hint", .lname = "Fadvise hint", .type = FIO_OPT_STR, .off1 = offsetof(struct thread_options, fadvise_hint), + .help = "Use fadvise() to advise the kernel on IO pattern", + .def = "1", .posval = { { .ival = "0", .oval = F_ADV_NONE, @@ -2746,8 +2749,6 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { }, #endif }, - .help = "Use fadvise() to advise the kernel on IO pattern", - .def = "1", .category = FIO_OPT_C_FILE, .group = FIO_OPT_G_INVALID, }, @@ -2756,9 +2757,9 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .lname = "Fsync", .type = FIO_OPT_INT, .off1 = offsetof(struct thread_options, fsync_blocks), + .interval = 1, .help = "Issue fsync for writes every given number of blocks", .def = "0", - .interval = 1, .category = FIO_OPT_C_FILE, .group = FIO_OPT_G_INVALID, }, @@ -2767,9 +2768,9 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .lname = "Fdatasync", .type = FIO_OPT_INT, .off1 = offsetof(struct thread_options, fdatasync_blocks), + .interval = 1, .help = "Issue fdatasync for writes every given number of blocks", .def = "0", - .interval = 1, .category = FIO_OPT_C_FILE, .group = FIO_OPT_G_INVALID, }, @@ -2778,9 +2779,9 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .lname = "Write barrier", .type = FIO_OPT_INT, .off1 = offsetof(struct thread_options, barrier_blocks), + .interval = 1, .help = "Make every Nth write a barrier write", .def = "0", - .interval = 1, .category = FIO_OPT_C_IO, .group = FIO_OPT_G_INVALID, }, @@ -2788,6 +2789,10 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { { .name = "sync_file_range", .lname = "Sync file range", + .type = FIO_OPT_STR_MULTI, + .off1 = offsetof(struct thread_options, sync_file_range), + .cb = reinterpret_cast(str_sfr_cb), + .help = "Use sync_file_range()", .posval = { { .ival = "wait_before", .oval = SYNC_FILE_RANGE_WAIT_BEFORE, @@ -2806,10 +2811,6 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .orval = 1, }, }, - .type = FIO_OPT_STR_MULTI, - .cb = str_sfr_cb, - .off1 = offsetof(struct thread_options, sync_file_range), - .help = "Use sync_file_range()", .category = FIO_OPT_C_FILE, .group = FIO_OPT_G_INVALID, }, @@ -2869,9 +2870,9 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .lname = "Loops", .type = FIO_OPT_INT, .off1 = offsetof(struct thread_options, loops), + .interval = 1, .help = "Number of times to run the job", .def = "1", - .interval = 1, .category = FIO_OPT_C_GENERAL, .group = FIO_OPT_G_RUNTIME, }, @@ -2880,9 +2881,9 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .lname = "Number of jobs", .type = FIO_OPT_INT, .off1 = offsetof(struct thread_options, numjobs), + .interval = 1, .help = "Duplicate this job this many times", .def = "1", - .interval = 1, .category = FIO_OPT_C_GENERAL, .group = FIO_OPT_G_RUNTIME, }, @@ -2894,10 +2895,10 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .off2 = offsetof(struct thread_options, start_delay_high), .help = "Only start job when this period has passed", .def = "0", - .is_seconds = 1, - .is_time = 1, .category = FIO_OPT_C_GENERAL, .group = FIO_OPT_G_RUNTIME, + .is_seconds = 1, + .is_time = 1, }, { .name = "runtime", @@ -2907,10 +2908,10 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .off1 = offsetof(struct thread_options, timeout), .help = "Stop workload when this amount of time has passed", .def = "0", - .is_seconds = 1, - .is_time = 1, .category = FIO_OPT_C_GENERAL, .group = FIO_OPT_G_RUNTIME, + .is_seconds = 1, + .is_time = 1, }, { .name = "time_based", @@ -2936,20 +2937,18 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .type = FIO_OPT_STR_VAL_TIME, .off1 = offsetof(struct thread_options, ramp_time), .help = "Ramp up time before measuring performance", - .is_seconds = 1, - .is_time = 1, .category = FIO_OPT_C_GENERAL, .group = FIO_OPT_G_RUNTIME, + .is_seconds = 1, + .is_time = 1, }, { .name = "clocksource", .lname = "Clock source", .type = FIO_OPT_STR, - .cb = fio_clock_source_cb, .off1 = offsetof(struct thread_options, clocksource), + .cb = reinterpret_cast(fio_clock_source_cb), .help = "What type of timing source to use", - .category = FIO_OPT_C_GENERAL, - .group = FIO_OPT_G_CLOCK, .posval = { #ifdef CONFIG_GETTIMEOFDAY { .ival = "gettimeofday", @@ -2970,18 +2969,18 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { }, #endif }, + .category = FIO_OPT_C_GENERAL, + .group = FIO_OPT_G_CLOCK, }, { .name = "mem", - .alias = "iomem", .lname = "I/O Memory", + .alias = "iomem", .type = FIO_OPT_STR, - .cb = str_mem_cb, .off1 = offsetof(struct thread_options, mem_type), + .cb = reinterpret_cast(str_mem_cb), .help = "Backing type for IO buffers", .def = "malloc", - .category = FIO_OPT_C_IO, - .group = FIO_OPT_G_INVALID, .posval = { { .ival = "malloc", .oval = MEM_MALLOC, @@ -3020,11 +3019,13 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { }, #endif }, + .category = FIO_OPT_C_IO, + .group = FIO_OPT_G_INVALID, }, { .name = "iomem_align", - .alias = "mem_align", .lname = "I/O memory alignment", + .alias = "mem_align", .type = FIO_OPT_INT, .off1 = offsetof(struct thread_options, mem_align), .minval = 0, @@ -3042,8 +3043,6 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .off1 = offsetof(struct thread_options, verify), .help = "Verify data written", .def = "0", - .category = FIO_OPT_C_IO, - .group = FIO_OPT_G_VERIFY, .posval = { { .ival = "0", .oval = VERIFY_NONE, @@ -3127,6 +3126,8 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .help = "Pretend to verify", }, }, + .category = FIO_OPT_C_IO, + .group = FIO_OPT_G_VERIFY, }, { .name = "do_verify", @@ -3160,10 +3161,10 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .type = FIO_OPT_INT, .off1 = offsetof(struct thread_options, verify_interval), .minval = 2 * sizeof(struct verify_header), + .interval = 2 * sizeof(struct verify_header), .help = "Store verify buffer header every N bytes", .parent = "verify", .hide = 1, - .interval = 2 * sizeof(struct verify_header), .category = FIO_OPT_C_IO, .group = FIO_OPT_G_VERIFY, }, @@ -3171,9 +3172,9 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .name = "verify_offset", .lname = "Verify offset", .type = FIO_OPT_INT, - .help = "Offset verify header location by N bytes", .off1 = offsetof(struct thread_options, verify_offset), .minval = sizeof(struct verify_header), + .help = "Offset verify header location by N bytes", .parent = "verify", .hide = 1, .category = FIO_OPT_C_IO, @@ -3183,8 +3184,8 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .name = "verify_pattern", .lname = "Verify pattern", .type = FIO_OPT_STR, - .cb = str_verify_pattern_cb, .off1 = offsetof(struct thread_options, verify_pattern), + .cb = reinterpret_cast(str_verify_pattern_cb), .help = "Fill pattern for IO buffers", .parent = "verify", .hide = 1, @@ -3196,8 +3197,8 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .lname = "Verify fatal", .type = FIO_OPT_BOOL, .off1 = offsetof(struct thread_options, verify_fatal), - .def = "0", .help = "Exit on a single verify failure, don't continue", + .def = "0", .parent = "verify", .hide = 1, .category = FIO_OPT_C_IO, @@ -3208,8 +3209,8 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .lname = "Verify dump", .type = FIO_OPT_BOOL, .off1 = offsetof(struct thread_options, verify_dump), - .def = "0", .help = "Dump contents of good and bad blocks on failure", + .def = "0", .parent = "verify", .hide = 1, .category = FIO_OPT_C_IO, @@ -3220,8 +3221,8 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .lname = "Verify asynchronously", .type = FIO_OPT_INT, .off1 = offsetof(struct thread_options, verify_async), - .def = "0", .help = "Number of async verifier threads to use", + .def = "0", .parent = "verify", .hide = 1, .category = FIO_OPT_C_IO, @@ -3254,8 +3255,8 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .name = "verify_async_cpus", .lname = "Async verify CPUs", .type = FIO_OPT_STR, - .cb = str_verify_cpus_allowed_cb, .off1 = offsetof(struct thread_options, verify_cpumask), + .cb = reinterpret_cast(str_verify_cpus_allowed_cb), .help = "Set CPUs allowed for async verify threads", .parent = "verify_async", .hide = 1, @@ -3273,8 +3274,8 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { { .name = "experimental_verify", .lname = "Experimental Verify", - .off1 = offsetof(struct thread_options, experimental_verify), .type = FIO_OPT_BOOL, + .off1 = offsetof(struct thread_options, experimental_verify), .help = "Enable experimental verification", .parent = "verify", .category = FIO_OPT_C_IO, @@ -3283,8 +3284,8 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { { .name = "verify_state_load", .lname = "Load verify state", - .off1 = offsetof(struct thread_options, verify_state), .type = FIO_OPT_BOOL, + .off1 = offsetof(struct thread_options, verify_state), .help = "Load verify termination state", .parent = "verify", .category = FIO_OPT_C_IO, @@ -3293,10 +3294,10 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { { .name = "verify_state_save", .lname = "Save verify state", - .off1 = offsetof(struct thread_options, verify_state_save), .type = FIO_OPT_BOOL, - .def = "1", + .off1 = offsetof(struct thread_options, verify_state_save), .help = "Save verify state on termination", + .def = "1", .parent = "verify", .category = FIO_OPT_C_IO, .group = FIO_OPT_G_VERIFY, @@ -3307,12 +3308,12 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .lname = "Trim percentage", .type = FIO_OPT_INT, .off1 = offsetof(struct thread_options, trim_percentage), - .minval = 0, .maxval = 100, + .minval = 0, + .interval = 1, .help = "Number of verify blocks to trim (i.e., discard)", - .parent = "verify", .def = "0", - .interval = 1, + .parent = "verify", .hide = 1, .category = FIO_OPT_C_IO, .group = FIO_OPT_G_TRIM, @@ -3321,11 +3322,11 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .name = "trim_verify_zero", .lname = "Verify trim zero", .type = FIO_OPT_BOOL, - .help = "Verify that trimmed (i.e., discarded) blocks are returned as zeroes", .off1 = offsetof(struct thread_options, trim_zero), + .help = "Verify that trimmed (i.e., discarded) blocks are returned as zeroes", + .def = "1", .parent = "trim_percentage", .hide = 1, - .def = "1", .category = FIO_OPT_C_IO, .group = FIO_OPT_G_TRIM, }, @@ -3334,10 +3335,10 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .lname = "Trim backlog", .type = FIO_OPT_STR_VAL, .off1 = offsetof(struct thread_options, trim_backlog), + .interval = 1, .help = "Trim after this number of blocks are written", .parent = "trim_percentage", .hide = 1, - .interval = 1, .category = FIO_OPT_C_IO, .group = FIO_OPT_G_TRIM, }, @@ -3346,10 +3347,10 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .lname = "Trim backlog batch", .type = FIO_OPT_INT, .off1 = offsetof(struct thread_options, trim_batch), + .interval = 1, .help = "Trim this number of IO blocks", .parent = "trim_percentage", .hide = 1, - .interval = 1, .category = FIO_OPT_C_IO, .group = FIO_OPT_G_TRIM, }, @@ -3402,9 +3403,9 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .lname = "Read I/O log in parts", .type = FIO_OPT_BOOL, .off1 = offsetof(struct thread_options, read_iolog_chunked), + .help = "Parse IO pattern in chunks", .def = "0", .parent = "read_iolog", - .help = "Parse IO pattern in chunks", .category = FIO_OPT_C_IO, .group = FIO_OPT_G_IOLOG, }, @@ -3413,10 +3414,10 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .lname = "Don't stall on replay", .type = FIO_OPT_BOOL, .off1 = offsetof(struct thread_options, no_stall), + .help = "Playback IO pattern file as fast as possible without stalls", .def = "0", .parent = "read_iolog", .hide = 1, - .help = "Playback IO pattern file as fast as possible without stalls", .category = FIO_OPT_C_IO, .group = FIO_OPT_G_IOLOG, }, @@ -3425,9 +3426,9 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .lname = "Redirect device for replay", .type = FIO_OPT_STR_STORE, .off1 = offsetof(struct thread_options, replay_redirect), + .help = "Replay all I/O onto this device, regardless of trace device", .parent = "read_iolog", .hide = 1, - .help = "Replay all I/O onto this device, regardless of trace device", .category = FIO_OPT_C_IO, .group = FIO_OPT_G_IOLOG, }, @@ -3436,9 +3437,9 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .lname = "Replace offset scale factor", .type = FIO_OPT_INT, .off1 = offsetof(struct thread_options, replay_scale), - .parent = "read_iolog", - .def = "1", .help = "Align offsets to this blocksize", + .def = "1", + .parent = "read_iolog", .category = FIO_OPT_C_IO, .group = FIO_OPT_G_IOLOG, }, @@ -3447,8 +3448,8 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .lname = "Replace alignment", .type = FIO_OPT_INT, .off1 = offsetof(struct thread_options, replay_align), - .parent = "read_iolog", .help = "Scale offset down by this factor", + .parent = "read_iolog", .category = FIO_OPT_C_IO, .group = FIO_OPT_G_IOLOG, .pow2 = 1, @@ -3458,11 +3459,11 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .lname = "Replay Time Scale", .type = FIO_OPT_INT, .off1 = offsetof(struct thread_options, replay_time_scale), - .def = "100", .minval = 1, + .help = "Scale time for replay events", + .def = "100", .parent = "read_iolog", .hide = 1, - .help = "Scale time for replay events", .category = FIO_OPT_C_IO, .group = FIO_OPT_G_IOLOG, }, @@ -3470,10 +3471,10 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .name = "replay_skip", .lname = "Replay Skip", .type = FIO_OPT_STR, - .cb = str_replay_skip_cb, .off1 = offsetof(struct thread_options, replay_skip), - .parent = "read_iolog", + .cb = reinterpret_cast(str_replay_skip_cb), .help = "Skip certain IO types (read,write,trim,flush)", + .parent = "read_iolog", .category = FIO_OPT_C_IO, .group = FIO_OPT_G_IOLOG, }, @@ -3545,12 +3546,10 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { { .name = "zonemode", .lname = "Zone mode", - .help = "Mode for the zonesize, zonerange and zoneskip parameters", .type = FIO_OPT_STR, .off1 = offsetof(struct thread_options, zone_mode), + .help = "Mode for the zonesize, zonerange and zoneskip parameters", .def = "none", - .category = FIO_OPT_C_IO, - .group = FIO_OPT_G_ZONE, .posval = { { .ival = "none", .oval = ZONE_MODE_NONE, @@ -3565,15 +3564,17 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .help = "zoned block device mode - random I/O selects one of multiple zones randomly", }, }, + .category = FIO_OPT_C_IO, + .group = FIO_OPT_G_ZONE, }, { .name = "zonesize", .lname = "Zone size", .type = FIO_OPT_STR_VAL, .off1 = offsetof(struct thread_options, zone_size), + .interval = 1024 * 1024, .help = "Amount of data to read per zone", .def = "0", - .interval = 1024 * 1024, .category = FIO_OPT_C_IO, .group = FIO_OPT_G_ZONE, }, @@ -3582,9 +3583,9 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .lname = "Zone capacity", .type = FIO_OPT_STR_VAL, .off1 = offsetof(struct thread_options, zone_capacity), + .interval = 1024 * 1024, .help = "Capacity per zone", .def = "0", - .interval = 1024 * 1024, .category = FIO_OPT_C_IO, .group = FIO_OPT_G_ZONE, }, @@ -3593,9 +3594,9 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .lname = "Zone range", .type = FIO_OPT_STR_VAL, .off1 = offsetof(struct thread_options, zone_range), + .interval = 1024 * 1024, .help = "Give size of an IO zone", .def = "0", - .interval = 1024 * 1024, .category = FIO_OPT_C_IO, .group = FIO_OPT_G_ZONE, }, @@ -3603,8 +3604,8 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .name = "zoneskip", .lname = "Zone skip", .type = FIO_OPT_STR_VAL_ZONE, - .cb = str_zoneskip_cb, .off1 = offsetof(struct thread_options, zone_skip), + .cb = reinterpret_cast(str_zoneskip_cb), .help = "Space between IO zones", .def = "0", .category = FIO_OPT_C_IO, @@ -3647,32 +3648,32 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .lname = "Ignore zone resource limits", .type = FIO_OPT_BOOL, .off1 = offsetof(struct thread_options, ignore_zone_limits), - .def = "0", .help = "Ignore the zone resource limits (max open/active zones) reported by the device", + .def = "0", .category = FIO_OPT_C_IO, .group = FIO_OPT_G_INVALID, }, { .name = "zone_reset_threshold", .lname = "Zone reset threshold", - .help = "Zoned block device reset threshold", .type = FIO_OPT_FLOAT_LIST, - .maxlen = 1, .off1 = offsetof(struct thread_options, zrt), - .minfp = 0, .maxfp = 1, + .minfp = 0, + .maxlen = 1, + .help = "Zoned block device reset threshold", .category = FIO_OPT_C_IO, .group = FIO_OPT_G_ZONE, }, { .name = "zone_reset_frequency", .lname = "Zone reset frequency", - .help = "Zoned block device zone reset frequency in HZ", .type = FIO_OPT_FLOAT_LIST, - .maxlen = 1, .off1 = offsetof(struct thread_options, zrf), - .minfp = 0, .maxfp = 1, + .minfp = 0, + .maxlen = 1, + .help = "Zoned block device zone reset frequency in HZ", .category = FIO_OPT_C_IO, .group = FIO_OPT_G_ZONE, }, @@ -3710,8 +3711,8 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .name = "fdp_pli", .lname = "FDP Placement ID indicies", .type = FIO_OPT_STR, - .cb = str_fdp_pli_cb, .off1 = offsetof(struct thread_options, fdp_plis), + .cb = reinterpret_cast(str_fdp_pli_cb), .help = "Sets which placement ids to use (defaults to all)", .hide = 1, .category = FIO_OPT_C_IO, @@ -3722,9 +3723,9 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .lname = "Lock memory", .type = FIO_OPT_STR_VAL, .off1 = offsetof(struct thread_options, lockmem), + .interval = 1024 * 1024, .help = "Lock down this amount of memory (per worker)", .def = "0", - .interval = 1024 * 1024, .category = FIO_OPT_C_GENERAL, .group = FIO_OPT_G_INVALID, }, @@ -3732,12 +3733,12 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .name = "rwmixread", .lname = "Read/write mix read", .type = FIO_OPT_INT, - .cb = str_rwmix_read_cb, .off1 = offsetof(struct thread_options, rwmix[DDIR_READ]), .maxval = 100, + .interval = 5, + .cb = reinterpret_cast(str_rwmix_read_cb), .help = "Percentage of mixed workload that is reads", .def = "50", - .interval = 5, .inverse = "rwmixwrite", .category = FIO_OPT_C_IO, .group = FIO_OPT_G_RWMIX, @@ -3746,12 +3747,12 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .name = "rwmixwrite", .lname = "Read/write mix write", .type = FIO_OPT_INT, - .cb = str_rwmix_write_cb, .off1 = offsetof(struct thread_options, rwmix[DDIR_WRITE]), .maxval = 100, + .interval = 5, + .cb = reinterpret_cast(str_rwmix_write_cb), .help = "Percentage of mixed workload that is writes", .def = "50", - .interval = 5, .inverse = "rwmixread", .category = FIO_OPT_C_IO, .group = FIO_OPT_G_RWMIX, @@ -3768,11 +3769,11 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .lname = "Nice", .type = FIO_OPT_INT, .off1 = offsetof(struct thread_options, nice), - .help = "Set job CPU nice value", - .minval = -20, .maxval = 19, - .def = "0", + .minval = -20, .interval = 1, + .help = "Set job CPU nice value", + .def = "0", .category = FIO_OPT_C_GENERAL, .group = FIO_OPT_G_CRED, }, @@ -3782,10 +3783,10 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .lname = "I/O nice priority", .type = FIO_OPT_INT, .off1 = offsetof(struct thread_options, ioprio), - .help = "Set job IO priority value", - .minval = IOPRIO_MIN_PRIO, .maxval = IOPRIO_MAX_PRIO, + .minval = IOPRIO_MIN_PRIO, .interval = 1, + .help = "Set job IO priority value", .category = FIO_OPT_C_GENERAL, .group = FIO_OPT_G_CRED, }, @@ -3806,10 +3807,10 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .lname = "I/O nice priority class", .type = FIO_OPT_INT, .off1 = offsetof(struct thread_options, ioprio_class), - .help = "Set job IO priority class", - .minval = IOPRIO_MIN_PRIO_CLASS, .maxval = IOPRIO_MAX_PRIO_CLASS, + .minval = IOPRIO_MIN_PRIO_CLASS, .interval = 1, + .help = "Set job IO priority class", .category = FIO_OPT_C_GENERAL, .group = FIO_OPT_G_CRED, }, @@ -3846,9 +3847,9 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .off1 = offsetof(struct thread_options, thinktime), .help = "Idle time between IO buffers (usec)", .def = "0", - .is_time = 1, .category = FIO_OPT_C_IO, .group = FIO_OPT_G_THINKTIME, + .is_time = 1, }, { .name = "thinktime_spin", @@ -3857,11 +3858,11 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .off1 = offsetof(struct thread_options, thinktime_spin), .help = "Start think time by spinning this amount (usec)", .def = "0", - .is_time = 1, .parent = "thinktime", .hide = 1, .category = FIO_OPT_C_IO, .group = FIO_OPT_G_THINKTIME, + .is_time = 1, }, { .name = "thinktime_blocks", @@ -3882,8 +3883,6 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .off1 = offsetof(struct thread_options, thinktime_blocks_type), .help = "How thinktime_blocks takes effect", .def = "complete", - .category = FIO_OPT_C_IO, - .group = FIO_OPT_G_THINKTIME, .posval = { { .ival = "complete", .oval = THINKTIME_BLOCKS_TYPE_COMPLETE, @@ -3896,6 +3895,8 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { }, }, .parent = "thinktime", + .category = FIO_OPT_C_IO, + .group = FIO_OPT_G_THINKTIME, }, { .name = "thinktime_iotime", @@ -3906,10 +3907,10 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .def = "0", .parent = "thinktime", .hide = 1, - .is_seconds = 1, - .is_time = 1, .category = FIO_OPT_C_IO, .group = FIO_OPT_G_THINKTIME, + .is_seconds = 1, + .is_time = 1, }, { .name = "rate", @@ -3924,8 +3925,8 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { }, { .name = "rate_min", - .alias = "ratemin", .lname = "I/O min rate", + .alias = "ratemin", .type = FIO_OPT_ULL, .off1 = offsetof(struct thread_options, ratemin[DDIR_READ]), .off2 = offsetof(struct thread_options, ratemin[DDIR_WRITE]), @@ -3968,8 +3969,6 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .off1 = offsetof(struct thread_options, rate_process), .help = "What process controls how rated IO is managed", .def = "linear", - .category = FIO_OPT_C_IO, - .group = FIO_OPT_G_RATE, .posval = { { .ival = "linear", .oval = RATE_PROCESS_LINEAR, @@ -3982,11 +3981,13 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { }, }, .parent = "rate", + .category = FIO_OPT_C_IO, + .group = FIO_OPT_G_RATE, }, { .name = "rate_cycle", - .alias = "ratecycle", .lname = "I/O rate cycle", + .alias = "ratecycle", .type = FIO_OPT_INT, .off1 = offsetof(struct thread_options, ratecycle), .help = "Window average for rate limits (msec)", @@ -4014,9 +4015,9 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .off2 = offsetof(struct thread_options, max_latency[DDIR_WRITE]), .off3 = offsetof(struct thread_options, max_latency[DDIR_TRIM]), .help = "Maximum tolerated IO latency (usec)", - .is_time = 1, .category = FIO_OPT_C_IO, .group = FIO_OPT_G_LATPROF, + .is_time = 1, }, { .name = "latency_target", @@ -4024,9 +4025,9 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .type = FIO_OPT_STR_VAL_TIME, .off1 = offsetof(struct thread_options, latency_target), .help = "Ramp to max queue depth supporting this latency", - .is_time = 1, .category = FIO_OPT_C_IO, .group = FIO_OPT_G_LATPROF, + .is_time = 1, }, { .name = "latency_window", @@ -4034,20 +4035,20 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .type = FIO_OPT_STR_VAL_TIME, .off1 = offsetof(struct thread_options, latency_window), .help = "Time to sustain latency_target", - .is_time = 1, .category = FIO_OPT_C_IO, .group = FIO_OPT_G_LATPROF, + .is_time = 1, }, { .name = "latency_percentile", .lname = "Latency Percentile", .type = FIO_OPT_FLOAT_LIST, .off1 = offsetof(struct thread_options, latency_percentile), + .maxfp = 100.0, + .minfp = 0.0, + .maxlen = 1, .help = "Percentile of IOs must be below latency_target", .def = "100", - .maxlen = 1, - .minfp = 0.0, - .maxfp = 100.0, .category = FIO_OPT_C_IO, .group = FIO_OPT_G_LATPROF, }, @@ -4078,9 +4079,6 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .off1 = offsetof(struct thread_options, sync_io), .help = "Use synchronous write IO", .def = "none", - .hide = 1, - .category = FIO_OPT_C_IO, - .group = FIO_OPT_G_IO_TYPE, .posval = { { .ival = "none", .oval = 0, @@ -4100,6 +4098,9 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { }, #endif }, + .hide = 1, + .category = FIO_OPT_C_IO, + .group = FIO_OPT_G_IO_TYPE, }, #ifdef FIO_HAVE_WRITE_HINT { @@ -4108,8 +4109,6 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .type = FIO_OPT_STR, .off1 = offsetof(struct thread_options, write_hint), .help = "Set expected write life time", - .category = FIO_OPT_C_ENGINE, - .group = FIO_OPT_G_INVALID, .posval = { { .ival = "none", .oval = RWH_WRITE_LIFE_NONE, @@ -4127,6 +4126,8 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .oval = RWH_WRITE_LIFE_EXTREME, }, }, + .category = FIO_OPT_C_ENGINE, + .group = FIO_OPT_G_INVALID, }, #endif { @@ -4165,8 +4166,8 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .type = FIO_OPT_BOOL, .off1 = offsetof(struct thread_options, create_only), .help = "Only perform file creation phase", - .category = FIO_OPT_C_FILE, .def = "0", + .category = FIO_OPT_C_FILE, }, { .name = "allow_file_create", @@ -4203,8 +4204,8 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .name = "cpumask", .lname = "CPU mask", .type = FIO_OPT_INT, - .cb = str_cpumask_cb, .off1 = offsetof(struct thread_options, cpumask), + .cb = reinterpret_cast(str_cpumask_cb), .help = "CPU affinity mask", .category = FIO_OPT_C_GENERAL, .group = FIO_OPT_G_CRED, @@ -4213,8 +4214,8 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .name = "cpus_allowed", .lname = "CPUs allowed", .type = FIO_OPT_STR, - .cb = str_cpus_allowed_cb, .off1 = offsetof(struct thread_options, cpumask), + .cb = reinterpret_cast(str_cpus_allowed_cb), .help = "Set CPUs allowed", .category = FIO_OPT_C_GENERAL, .group = FIO_OPT_G_CRED, @@ -4224,9 +4225,8 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .lname = "CPUs allowed distribution policy", .type = FIO_OPT_STR, .off1 = offsetof(struct thread_options, cpus_allowed_policy), - .help = "Distribution policy for cpus_allowed", - .parent = "cpus_allowed", .prio = 1, + .help = "Distribution policy for cpus_allowed", .posval = { { .ival = "shared", .oval = FIO_CPUS_SHARED, @@ -4237,6 +4237,7 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .help = "Mask split between threads", }, }, + .parent = "cpus_allowed", .category = FIO_OPT_C_GENERAL, .group = FIO_OPT_G_CRED, }, @@ -4265,8 +4266,8 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .name = "numa_cpu_nodes", .lname = "NUMA CPU Nodes", .type = FIO_OPT_STR, - .cb = str_numa_cpunodes_cb, .off1 = offsetof(struct thread_options, numa_cpunodes), + .cb = reinterpret_cast(str_numa_cpunodes_cb), .help = "NUMA CPU nodes bind", .category = FIO_OPT_C_GENERAL, .group = FIO_OPT_G_INVALID, @@ -4275,8 +4276,8 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .name = "numa_mem_policy", .lname = "NUMA Memory Policy", .type = FIO_OPT_STR, - .cb = str_numa_mpol_cb, .off1 = offsetof(struct thread_options, numa_memnodes), + .cb = reinterpret_cast(str_numa_mpol_cb), .help = "NUMA memory policy setup", .category = FIO_OPT_C_GENERAL, .group = FIO_OPT_G_INVALID, @@ -4351,7 +4352,7 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .name = "exitall", .lname = "Exit-all on terminate", .type = FIO_OPT_STR_SET, - .cb = str_exitall_cb, + .cb = reinterpret_cast(str_exitall_cb), .help = "Terminate all jobs when one exits", .category = FIO_OPT_C_GENERAL, .group = FIO_OPT_G_PROCESS, @@ -4363,8 +4364,6 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .off1 = offsetof(struct thread_options, exit_what), .help = "Fine-grained control for exitall", .def = "group", - .category = FIO_OPT_C_GENERAL, - .group = FIO_OPT_G_PROCESS, .posval = { { .ival = "group", .oval = TERMINATE_GROUP, @@ -4375,10 +4374,12 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .help = "quit all currently running jobs; continue with next stonewall", }, { .ival = "all", - .oval = TERMINATE_ALL, + .oval = static_cast(TERMINATE_ALL), .help = "Quit everything", }, }, + .category = FIO_OPT_C_GENERAL, + .group = FIO_OPT_G_PROCESS, }, { .name = "exitall_on_error", @@ -4436,7 +4437,7 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .lname = "Write bandwidth log", .type = FIO_OPT_STR, .off1 = offsetof(struct thread_options, bw_log_file), - .cb = str_write_bw_log_cb, + .cb = reinterpret_cast(str_write_bw_log_cb), .help = "Write log of bandwidth during run", .category = FIO_OPT_C_LOG, .group = FIO_OPT_G_INVALID, @@ -4446,7 +4447,7 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .lname = "Write latency log", .type = FIO_OPT_STR, .off1 = offsetof(struct thread_options, lat_log_file), - .cb = str_write_lat_log_cb, + .cb = reinterpret_cast(str_write_lat_log_cb), .help = "Write log of latency during run", .category = FIO_OPT_C_LOG, .group = FIO_OPT_G_INVALID, @@ -4456,7 +4457,7 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .lname = "Write IOPS log", .type = FIO_OPT_STR, .off1 = offsetof(struct thread_options, iops_log_file), - .cb = str_write_iops_log_cb, + .cb = reinterpret_cast(str_write_iops_log_cb), .help = "Write log of IOPS during run", .category = FIO_OPT_C_LOG, .group = FIO_OPT_G_INVALID, @@ -4466,10 +4467,10 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .lname = "Log entries", .type = FIO_OPT_INT, .off1 = offsetof(struct thread_options, log_entries), + .maxval = MAX_LOG_ENTRIES, + .minval = DEF_LOG_ENTRIES, .help = "Initial number of entries in a job IO log", .def = __fio_stringify(DEF_LOG_ENTRIES), - .minval = DEF_LOG_ENTRIES, - .maxval = MAX_LOG_ENTRIES, .category = FIO_OPT_C_LOG, .group = FIO_OPT_G_INVALID, }, @@ -4510,7 +4511,7 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .lname = "Write latency histogram logs", .type = FIO_OPT_STR, .off1 = offsetof(struct thread_options, hist_log_file), - .cb = str_write_hist_log_cb, + .cb = reinterpret_cast(str_write_hist_log_cb), .help = "Write log of latency histograms during run", .category = FIO_OPT_C_LOG, .group = FIO_OPT_G_INVALID, @@ -4551,9 +4552,9 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .lname = "Log compression", .type = FIO_OPT_INT, .off1 = offsetof(struct thread_options, log_gz), - .help = "Log in compressed chunks of this size", - .minval = 1024ULL, .maxval = 512 * 1024 * 1024ULL, + .minval = 1024ULL, + .help = "Log in compressed chunks of this size", .category = FIO_OPT_C_LOG, .group = FIO_OPT_G_INVALID, }, @@ -4562,10 +4563,10 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .name = "log_compression_cpus", .lname = "Log Compression CPUs", .type = FIO_OPT_STR, - .cb = str_log_cpus_allowed_cb, .off1 = offsetof(struct thread_options, log_gz_cpumask), - .parent = "log_compression", + .cb = reinterpret_cast(str_log_cpus_allowed_cb), .help = "Limit log compression to these CPUs", + .parent = "log_compression", .category = FIO_OPT_C_LOG, .group = FIO_OPT_G_INVALID, }, @@ -4642,12 +4643,12 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .lname = "Bandwidth average time", .type = FIO_OPT_INT, .off1 = offsetof(struct thread_options, bw_avg_time), + .interval = 100, .help = "Time window over which to calculate bandwidth" " (msec)", .def = "500", .parent = "write_bw_log", .hide = 1, - .interval = 100, .category = FIO_OPT_C_LOG, .group = FIO_OPT_G_INVALID, }, @@ -4656,11 +4657,11 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .lname = "IOPS average time", .type = FIO_OPT_INT, .off1 = offsetof(struct thread_options, iops_avg_time), + .interval = 100, .help = "Time window over which to calculate IOPS (msec)", .def = "500", .parent = "write_iops_log", .hide = 1, - .interval = 100, .category = FIO_OPT_C_LOG, .group = FIO_OPT_G_INVALID, }, @@ -4715,8 +4716,8 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .name = "buffer_pattern", .lname = "Buffer pattern", .type = FIO_OPT_STR, - .cb = str_buffer_pattern_cb, .off1 = offsetof(struct thread_options, buffer_pattern), + .cb = reinterpret_cast(str_buffer_pattern_cb), .help = "Fill pattern for IO buffers", .category = FIO_OPT_C_IO, .group = FIO_OPT_G_IO_BUF, @@ -4725,12 +4726,12 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .name = "buffer_compress_percentage", .lname = "Buffer compression percentage", .type = FIO_OPT_INT, - .cb = str_buffer_compress_cb, .off1 = offsetof(struct thread_options, compress_percentage), .maxval = 100, .minval = 0, - .help = "How compressible the buffer is (approximately)", .interval = 5, + .cb = reinterpret_cast(str_buffer_compress_cb), + .help = "How compressible the buffer is (approximately)", .category = FIO_OPT_C_IO, .group = FIO_OPT_G_IO_BUF, }, @@ -4739,11 +4740,11 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .lname = "Buffer compression chunk size", .type = FIO_OPT_INT, .off1 = offsetof(struct thread_options, compress_chunk), - .parent = "buffer_compress_percentage", - .hide = 1, + .interval = 256, .help = "Size of compressible region in buffer", .def = "512", - .interval = 256, + .parent = "buffer_compress_percentage", + .hide = 1, .category = FIO_OPT_C_IO, .group = FIO_OPT_G_IO_BUF, }, @@ -4751,12 +4752,12 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .name = "dedupe_percentage", .lname = "Dedupe percentage", .type = FIO_OPT_INT, - .cb = str_dedupe_cb, .off1 = offsetof(struct thread_options, dedupe_percentage), .maxval = 100, .minval = 0, - .help = "Percentage of buffers that are dedupable", .interval = 1, + .cb = reinterpret_cast(str_dedupe_cb), + .help = "Percentage of buffers that are dedupable", .category = FIO_OPT_C_IO, .group = FIO_OPT_G_IO_BUF, }, @@ -4773,13 +4774,10 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { { .name = "dedupe_mode", .lname = "Dedupe mode", - .help = "Mode for the deduplication buffer generation", .type = FIO_OPT_STR, .off1 = offsetof(struct thread_options, dedupe_mode), - .parent = "dedupe_percentage", + .help = "Mode for the deduplication buffer generation", .def = "repeat", - .category = FIO_OPT_C_IO, - .group = FIO_OPT_G_IO_BUF, .posval = { { .ival = "repeat", .oval = DEDUPE_MODE_REPEAT, @@ -4790,17 +4788,20 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .help = "choose a page randomly from limited working set defined in dedupe_working_set_percentage", }, }, + .parent = "dedupe_percentage", + .category = FIO_OPT_C_IO, + .group = FIO_OPT_G_IO_BUF, }, { .name = "dedupe_working_set_percentage", .lname = "Dedupe working set percentage", - .help = "Dedupe working set size in percentages from file or device size used to generate dedupe patterns from", .type = FIO_OPT_INT, .off1 = offsetof(struct thread_options, dedupe_working_set_percentage), - .parent = "dedupe_percentage", - .def = "5", .maxval = 100, .minval = 0, + .help = "Dedupe working set size in percentages from file or device size used to generate dedupe patterns from", + .def = "5", + .parent = "dedupe_percentage", .category = FIO_OPT_C_IO, .group = FIO_OPT_G_IO_BUF, }, @@ -4840,12 +4841,12 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .type = FIO_OPT_FLOAT_LIST, .off1 = offsetof(struct thread_options, percentile_list), .off2 = offsetof(struct thread_options, percentile_precision), + .maxfp = 100.0, + .minfp = 0.0, + .maxlen = FIO_IO_U_LIST_MAX_LEN, .help = "Specify a custom list of percentiles to report for " "completion latency and block errors", .def = "1:5:10:20:30:40:50:60:70:80:90:95:99:99.5:99.9:99.95:99.99", - .maxlen = FIO_IO_U_LIST_MAX_LEN, - .minfp = 0.0, - .maxfp = 100.0, .category = FIO_OPT_C_STAT, .group = FIO_OPT_G_INVALID, }, @@ -4856,9 +4857,9 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .off1 = offsetof(struct thread_options, sig_figs), .maxval = 10, .minval = 1, + .interval = 1, .help = "Significant figures for output-format set to normal", .def = "4", - .interval = 1, .category = FIO_OPT_C_STAT, .group = FIO_OPT_G_INVALID, }, @@ -4886,8 +4887,8 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .name = "gtod_reduce", .lname = "Reduce gettimeofday() calls", .type = FIO_OPT_BOOL, + .cb = reinterpret_cast(str_gtod_reduce_cb), .help = "Greatly reduce number of gettimeofday() calls", - .cb = str_gtod_reduce_cb, .def = "0", .hide_on_set = 1, .category = FIO_OPT_C_STAT, @@ -4899,9 +4900,9 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .type = FIO_OPT_BOOL, .off1 = offsetof(struct thread_options, disable_lat), .help = "Disable latency numbers", + .def = "0", .parent = "gtod_reduce", .hide = 1, - .def = "0", .category = FIO_OPT_C_STAT, .group = FIO_OPT_G_INVALID, }, @@ -4911,9 +4912,9 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .type = FIO_OPT_BOOL, .off1 = offsetof(struct thread_options, disable_clat), .help = "Disable completion latency numbers", + .def = "0", .parent = "gtod_reduce", .hide = 1, - .def = "0", .category = FIO_OPT_C_STAT, .group = FIO_OPT_G_INVALID, }, @@ -4923,22 +4924,22 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .type = FIO_OPT_BOOL, .off1 = offsetof(struct thread_options, disable_slat), .help = "Disable submission latency numbers", + .def = "0", .parent = "gtod_reduce", .hide = 1, - .def = "0", .category = FIO_OPT_C_STAT, .group = FIO_OPT_G_INVALID, }, { .name = "disable_bw_measurement", - .alias = "disable_bw", .lname = "Disable bandwidth stats", + .alias = "disable_bw", .type = FIO_OPT_BOOL, .off1 = offsetof(struct thread_options, disable_bw), .help = "Disable bandwidth logging", + .def = "0", .parent = "gtod_reduce", .hide = 1, - .def = "0", .category = FIO_OPT_C_STAT, .group = FIO_OPT_G_INVALID, }, @@ -4959,8 +4960,6 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .off1 = offsetof(struct thread_options, unified_rw_rep), .help = "Unify reporting across data direction", .def = "none", - .category = FIO_OPT_C_GENERAL, - .group = FIO_OPT_G_INVALID, .posval = { { .ival = "none", .oval = UNIFIED_SPLIT, @@ -4988,6 +4987,8 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .help = "Alias for 'both'", }, }, + .category = FIO_OPT_C_GENERAL, + .group = FIO_OPT_G_INVALID, }, { .name = "continue_on_error", @@ -4996,8 +4997,6 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .off1 = offsetof(struct thread_options, continue_on_error), .help = "Continue on non-fatal errors during IO", .def = "none", - .category = FIO_OPT_C_GENERAL, - .group = FIO_OPT_G_ERR, .posval = { { .ival = "none", .oval = ERROR_TYPE_NONE, @@ -5032,13 +5031,15 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .help = "Alias for 'all'", }, }, + .category = FIO_OPT_C_GENERAL, + .group = FIO_OPT_G_ERR, }, { .name = "ignore_error", .lname = "Ignore Error", .type = FIO_OPT_STR, - .cb = str_ignore_error_cb, .off1 = offsetof(struct thread_options, ignore_error_nr), + .cb = reinterpret_cast(str_ignore_error_cb), .help = "Set a specific list of errors to ignore", .parent = "rw", .category = FIO_OPT_C_GENERAL, @@ -5049,8 +5050,8 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .lname = "Error Dump", .type = FIO_OPT_BOOL, .off1 = offsetof(struct thread_options, error_dump), - .def = "0", .help = "Dump info on each error", + .def = "0", .category = FIO_OPT_C_GENERAL, .group = FIO_OPT_G_ERR, }, @@ -5088,9 +5089,9 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .lname = "Cgroup weight", .type = FIO_OPT_INT, .off1 = offsetof(struct thread_options, cgroup_weight), - .help = "Use given weight for cgroup", - .minval = 100, .maxval = 1000, + .minval = 100, + .help = "Use given weight for cgroup", .parent = "cgroup", .category = FIO_OPT_C_GENERAL, .group = FIO_OPT_G_CGROUP, @@ -5119,6 +5120,7 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .type = FIO_OPT_STR, .off1 = offsetof(struct thread_options, kb_base), .prio = 1, + .help = "Unit prefix interpretation for quantities of data (IEC and SI)", .def = "1024", .posval = { { .ival = "1024", @@ -5130,7 +5132,6 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .help = "Inputs use IEC and SI prefixes; outputs prefer SI", }, }, - .help = "Unit prefix interpretation for quantities of data (IEC and SI)", .category = FIO_OPT_C_GENERAL, .group = FIO_OPT_G_INVALID, }, @@ -5140,6 +5141,7 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .type = FIO_OPT_STR, .off1 = offsetof(struct thread_options, unit_base), .prio = 1, + .help = "Bit multiple of result summary data (8 for byte, 1 for bit)", .posval = { { .ival = "0", .oval = N2S_NONE, @@ -5154,7 +5156,6 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .help = "Bit based", }, }, - .help = "Bit multiple of result summary data (8 for byte, 1 for bit)", .category = FIO_OPT_C_GENERAL, .group = FIO_OPT_G_INVALID, }, @@ -5163,9 +5164,9 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .lname = "Hugepage size", .type = FIO_OPT_INT, .off1 = offsetof(struct thread_options, hugepage_size), + .interval = 1024 * 1024, .help = "When using hugepages, specify size of each page", .def = __fio_stringify(FIO_HUGE_PAGE), - .interval = 1024 * 1024, .category = FIO_OPT_C_GENERAL, .group = FIO_OPT_G_INVALID, }, @@ -5184,11 +5185,11 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .lname = "I/O flow weight", .type = FIO_OPT_INT, .off1 = offsetof(struct thread_options, flow), + .maxval = FLOW_MAX_WEIGHT, .help = "Weight for flow control of this job", + .def = "0", .parent = "flow_id", .hide = 1, - .def = "0", - .maxval = FLOW_MAX_WEIGHT, .category = FIO_OPT_C_IO, .group = FIO_OPT_G_IO_FLOW, }, @@ -5206,9 +5207,9 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .off1 = offsetof(struct thread_options, flow_sleep), .help = "How many microseconds to sleep after being held" " back by the flow control mechanism", + .def = "0", .parent = "flow_id", .hide = 1, - .def = "0", .category = FIO_OPT_C_IO, .group = FIO_OPT_G_IO_FLOW, }, @@ -5218,7 +5219,7 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .alias = "ss", .type = FIO_OPT_STR, .off1 = offsetof(struct thread_options, ss_state), - .cb = str_steadystate_cb, + .cb = reinterpret_cast(str_steadystate_cb), .help = "Define the criterion and limit to judge when a job has reached steady state", .def = "iops_slope:0.01%", .posval = { @@ -5247,29 +5248,29 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .name = "steadystate_duration", .lname = "Steady state duration", .alias = "ss_dur", - .parent = "steadystate", .type = FIO_OPT_STR_VAL_TIME, .off1 = offsetof(struct thread_options, ss_dur), .help = "Stop workload upon attaining steady state for specified duration", .def = "0", - .is_seconds = 1, - .is_time = 1, + .parent = "steadystate", .category = FIO_OPT_C_GENERAL, .group = FIO_OPT_G_RUNTIME, + .is_seconds = 1, + .is_time = 1, }, { .name = "steadystate_ramp_time", .lname = "Steady state ramp time", .alias = "ss_ramp", - .parent = "steadystate", .type = FIO_OPT_STR_VAL_TIME, .off1 = offsetof(struct thread_options, ss_ramp_time), .help = "Delay before initiation of data collection for steady state job termination testing", .def = "0", - .is_seconds = 1, - .is_time = 1, + .parent = "steadystate", .category = FIO_OPT_C_GENERAL, .group = FIO_OPT_G_RUNTIME, + .is_seconds = 1, + .is_time = 1, }, { .name = "steadystate_check_interval", @@ -5380,7 +5381,7 @@ static struct fio_keyword fio_keywords[] = { }, }; -void fio_keywords_exit(void) +void fio_keywords_exit() { struct fio_keyword *kw; @@ -5392,7 +5393,7 @@ void fio_keywords_exit(void) } } -void fio_keywords_init(void) +void fio_keywords_init() { unsigned long long mb_memory; char buf[128]; @@ -5530,7 +5531,7 @@ static char *fio_keyword_replace(char *opt) struct fio_keyword *kw = &fio_keywords[i]; while ((s = strstr(opt, kw->word)) != NULL) { - char *new = calloc(strlen(opt) + 1, 1); + char *__new__ = static_cast(calloc(strlen(opt) + 1, 1)); char *o_org = opt; int olen = s - opt; int len; @@ -5539,8 +5540,8 @@ static char *fio_keyword_replace(char *opt) * Copy part of the string before the keyword and * sprintf() the replacement after it. */ - memcpy(new, opt, olen); - len = sprintf(new + olen, "%s", kw->replace); + memcpy(__new__, opt, olen); + len = sprintf(__new__ + olen, "%s", kw->replace); /* * If there's more in the original string, copy that @@ -5549,12 +5550,12 @@ static char *fio_keyword_replace(char *opt) opt += olen + strlen(kw->word); /* keeps final zero thanks to calloc */ if (strlen(opt)) - memcpy(new + olen + len, opt, strlen(opt)); + memcpy(__new__ + olen + len, opt, strlen(opt)); /* * replace opt and free the old opt */ - opt = new; + opt = __new__; free(o_org); docalc = 1; @@ -5573,7 +5574,7 @@ static char *fio_keyword_replace(char *opt) static char **dup_and_sub_options(char **opts, int num_opts) { int i; - char **opts_copy = malloc(num_opts * sizeof(*opts)); + char **opts_copy = static_cast(malloc(num_opts * sizeof(*opts))); for (i = 0; i < num_opts; i++) { opts_copy[i] = fio_option_dup_subs(opts[i]); if (!opts_copy[i]) diff --git a/options.h b/options.h index df80fd9864..dab4c420fa 100644 --- a/options.h +++ b/options.h @@ -8,6 +8,10 @@ #include "parse.h" #include "lib/types.h" +#ifdef __cplusplus +extern "C" { +#endif + int add_option(const struct fio_option *); void invalidate_profile_options(const char *); extern char *exec_profile; @@ -54,4 +58,8 @@ find_option_c(const struct fio_option *, const char *); extern struct fio_option *fio_option_find(const char *); extern unsigned int fio_get_kb_base(void *); +#ifdef __cplusplus +} +#endif + #endif diff --git a/os/os-linux.h b/os/os-linux.h index c5cd651581..7868091978 100644 --- a/os/os-linux.h +++ b/os/os-linux.h @@ -167,12 +167,12 @@ static inline int ioprio_set(int which, int who, int ioprio_class, int ioprio, ioprio_value(ioprio_class, ioprio, ioprio_hint)); } -#ifndef CONFIG_HAVE_GETTID -static inline int gettid(void) -{ - return syscall(__NR_gettid); -} -#endif +// #ifndef CONFIG_HAVE_GETTID +// static inline int gettid(void) +// { +// return syscall(__NR_gettid); +// } +// #endif #define SPLICE_DEF_SIZE (64*1024) diff --git a/os/os.h b/os/os.h index 0f1823240f..841dd96e46 100644 --- a/os/os.h +++ b/os/os.h @@ -88,6 +88,10 @@ typedef struct aiocb os_aiocb_t; #define POSIX_FADV_NORMAL (0) #endif +#ifdef __cplusplus +extern "C" { +#endif + #ifndef FIO_HAVE_CPU_AFFINITY #define fio_cpu_clear(mask, cpu) do { } while (0) typedef unsigned long os_cpu_mask_t; @@ -424,4 +428,8 @@ static inline void os_clk_tck(long *clk_tck) extern void os_clk_tck(long *clk_tck); #endif +#ifdef __cplusplus +} +#endif + #endif /* FIO_OS_H */ diff --git a/oslib/asprintf.c b/oslib/asprintf.cpp similarity index 94% rename from oslib/asprintf.c rename to oslib/asprintf.cpp index 2d9f811c56..54bd6d271d 100644 --- a/oslib/asprintf.c +++ b/oslib/asprintf.cpp @@ -1,5 +1,6 @@ -#include -#include +#include +#include + #include "oslib/asprintf.h" #ifndef CONFIG_HAVE_VASPRINTF diff --git a/oslib/asprintf.h b/oslib/asprintf.h index 43bbb56b07..0ff5cfcc66 100644 --- a/oslib/asprintf.h +++ b/oslib/asprintf.h @@ -3,6 +3,10 @@ #include +#ifdef __cplusplus +extern "C" { +#endif + #ifndef CONFIG_HAVE_VASPRINTF int vasprintf(char **strp, const char *fmt, va_list ap); #endif @@ -10,4 +14,8 @@ int vasprintf(char **strp, const char *fmt, va_list ap); int asprintf(char **strp, const char *fmt, ...); #endif +#ifdef __cplusplus +} +#endif + #endif /* FIO_ASPRINTF_H */ diff --git a/oslib/blkzoned.h b/oslib/blkzoned.h index e598bd4f80..727ad5ce68 100644 --- a/oslib/blkzoned.h +++ b/oslib/blkzoned.h @@ -8,6 +8,10 @@ #include "zbd_types.h" +#ifdef __cplusplus +extern "C" { +#endif + #ifdef CONFIG_HAS_BLKZONED extern int blkzoned_get_zoned_model(struct thread_data *td, struct fio_file *f, enum zbd_zoned_model *model); @@ -70,4 +74,8 @@ static inline int blkzoned_finish_zone(struct thread_data *td, } #endif +#ifdef __cplusplus +} +#endif + #endif /* FIO_BLKZONED_H */ diff --git a/oslib/getopt_long.c b/oslib/getopt_long.cpp similarity index 99% rename from oslib/getopt_long.c rename to oslib/getopt_long.cpp index 463919fb7b..ca22c28017 100644 --- a/oslib/getopt_long.c +++ b/oslib/getopt_long.cpp @@ -10,9 +10,10 @@ * This file was imported from the klibc library from hpa */ -#include +#include +#include + #include -#include #include "getopt.h" diff --git a/oslib/inet_aton.c b/oslib/inet_aton.cpp similarity index 100% rename from oslib/inet_aton.c rename to oslib/inet_aton.cpp diff --git a/oslib/inet_aton.h b/oslib/inet_aton.h index c93c87f86f..a2b3b5c81e 100644 --- a/oslib/inet_aton.h +++ b/oslib/inet_aton.h @@ -3,6 +3,14 @@ #include +#ifdef __cplusplus +extern "C" { +#endif + int inet_aton(const char *cp, struct in_addr *inp); +#ifdef __cplusplus +} +#endif + #endif diff --git a/oslib/libmtd.c b/oslib/libmtd.cpp similarity index 98% rename from oslib/libmtd.c rename to oslib/libmtd.cpp index 5fca3a01b8..ffa8d40664 100644 --- a/oslib/libmtd.c +++ b/oslib/libmtd.cpp @@ -57,7 +57,7 @@ static char *mkpath(const char *path, const char *name) size_t len1 = strlen(path); size_t len2 = strlen(name); - n = xmalloc(len1 + len2 + 6); + n = static_cast(xmalloc(len1 + len2 + 6)); memcpy(n, path, len1); if (n[len1 - 1] != '/') @@ -556,11 +556,11 @@ static int sysfs_is_supported(struct libmtd *lib) return 1; } -libmtd_t libmtd_open(void) +libmtd_t libmtd_open() { struct libmtd *lib; - lib = xzalloc(sizeof(*lib)); + lib = static_cast(xzalloc(sizeof(*lib))); lib->offs64_ioctls = OFFS64_IOCTLS_UNKNOWN; @@ -1071,7 +1071,7 @@ int mtd_read(const struct mtd_dev_info *mtd, int fd, int eb, int offs, /* Seek to the beginning of the eraseblock */ seek = (off_t)eb * mtd->eb_size + offs; if (lseek(fd, seek, SEEK_SET) != seek) - return sys_errmsg("cannot seek mtd%d to offset %"PRIdoff_t, + return sys_errmsg("cannot seek mtd%d to offset %" PRIdoff_t, mtd->mtd_num, seek); while (rd < len) { @@ -1095,7 +1095,7 @@ static int legacy_auto_oob_layout(const struct mtd_dev_info *mtd, int fd, if (ioctl(fd, MEMGETOOBSEL, &old_oobinfo)) return sys_errmsg("MEMGETOOBSEL failed"); - tmp_buf = malloc(ooblen); + tmp_buf = static_cast(malloc(ooblen)); memcpy(tmp_buf, oob, ooblen); /* @@ -1108,14 +1108,14 @@ static int legacy_auto_oob_layout(const struct mtd_dev_info *mtd, int fd, /* Set the reserved bytes to 0xff */ start = old_oobinfo.oobfree[i][0]; len = old_oobinfo.oobfree[i][1]; - memcpy(oob + start, tmp_buf + tags_pos, len); + memcpy(static_cast(oob) + start, tmp_buf + tags_pos, len); tags_pos += len; } } else { /* Set at least the ecc byte positions to 0xff */ start = old_oobinfo.eccbytes; len = mtd->oob_size - start; - memcpy(oob + start, tmp_buf + start, len); + memcpy(static_cast(oob) + start, tmp_buf + start, len); } free(tmp_buf); @@ -1180,7 +1180,7 @@ int mtd_write(libmtd_t desc, const struct mtd_dev_info *mtd, int fd, int eb, if (data) { /* Seek to the beginning of the eraseblock */ if (lseek(fd, seek, SEEK_SET) != seek) - return sys_errmsg("cannot seek mtd%d to offset %"PRIdoff_t, + return sys_errmsg("cannot seek mtd%d to offset %" PRIdoff_t, mtd->mtd_num, seek); ret = write(fd, data, len); if (ret != len) @@ -1260,7 +1260,7 @@ static int do_oob_op(libmtd_t desc, const struct mtd_dev_info *mtd, int fd, oob.start = oob64.start; oob.length = oob64.length; - oob.ptr = data; + oob.ptr = static_cast(data); ret = ioctl(fd, cmd, &oob); if (ret < 0) @@ -1338,12 +1338,12 @@ int mtd_write_img(const struct mtd_dev_info *mtd, int fd, int eb, int offs, /* Seek to the beginning of the eraseblock */ seek = (off_t)eb * mtd->eb_size + offs; if (lseek(fd, seek, SEEK_SET) != seek) { - sys_errmsg("cannot seek mtd%d to offset %"PRIdoff_t, + sys_errmsg("cannot seek mtd%d to offset %" PRIdoff_t, mtd->mtd_num, seek); goto out_close; } - buf = xmalloc(mtd->eb_size); + buf = static_cast(xmalloc(mtd->eb_size)); while (written < len) { int rd = 0; diff --git a/oslib/libmtd_legacy.c b/oslib/libmtd_legacy.cpp similarity index 97% rename from oslib/libmtd_legacy.c rename to oslib/libmtd_legacy.cpp index 137e80a94b..b80074c380 100644 --- a/oslib/libmtd_legacy.c +++ b/oslib/libmtd_legacy.cpp @@ -77,7 +77,7 @@ static int proc_parse_start(struct proc_parse_info *pi) if (fd == -1) return -1; - pi->buf = xmalloc(PROC_MTD_MAX_LEN); + pi->buf = static_cast(xmalloc(PROC_MTD_MAX_LEN)); ret = read(fd, pi->buf, PROC_MTD_MAX_LEN); if (ret == -1) { @@ -119,7 +119,7 @@ static int proc_parse_next(struct proc_parse_info *pi) if (ret != 3) return errmsg("\"%s\" pattern not found", PROC_MTD_PATT); - p = memchr(pi->next, '\"', pi->data_size - pos); + p = static_cast(memchr(pi->next, '\"', pi->data_size - pos)); if (!p) return errmsg("opening \" not found"); p += 1; @@ -127,7 +127,7 @@ static int proc_parse_next(struct proc_parse_info *pi) if (pos >= pi->data_size) return errmsg("opening \" not found"); - p1 = memchr(p, '\"', pi->data_size - pos); + p1 = static_cast(memchr(p, '\"', pi->data_size - pos)); if (!p1) return errmsg("closing \" not found"); pos = p1 - pi->buf; @@ -156,7 +156,7 @@ static int proc_parse_next(struct proc_parse_info *pi) * error code if a real error happened. This is similar to the 'libmtd_open()' * return conventions. */ -int legacy_libmtd_open(void) +int legacy_libmtd_open() { int fd; diff --git a/oslib/linux-blkzoned.c b/oslib/linux-blkzoned.cpp similarity index 96% rename from oslib/linux-blkzoned.c rename to oslib/linux-blkzoned.cpp index 2c3ecf33b4..6a35c7406b 100644 --- a/oslib/linux-blkzoned.c +++ b/oslib/linux-blkzoned.cpp @@ -3,15 +3,20 @@ * * This file is released under the GPL. */ -#include -#include -#include +#include "blkzoned.h" + +#include +#include +#include + #include #include #include #include #include +#include + #include "file.h" #include "fio.h" #include "lib/pow2.h" @@ -21,7 +26,6 @@ #include "verify.h" #include "zbd_types.h" -#include #ifndef BLKFINISHZONE #define BLKFINISHZONE _IOW(0x12, 136, struct blk_zone_range) #endif @@ -231,8 +235,8 @@ int blkzoned_report_zones(struct thread_data *td, struct fio_file *f, if (fd < 0) return -errno; - hdr = calloc(1, sizeof(struct blk_zone_report) + - nr_zones * sizeof(struct blk_zone)); + hdr = static_cast(calloc(1, sizeof(struct blk_zone_report) + + nr_zones * sizeof(struct blk_zone))); if (!hdr) { ret = -ENOMEM; goto out; @@ -247,7 +251,7 @@ int blkzoned_report_zones(struct thread_data *td, struct fio_file *f, } nr_zones = hdr->nr_zones; - blkz = (void *) hdr + sizeof(*hdr); + blkz = reinterpret_cast((char *) hdr + sizeof(*hdr)); z = &zones[0]; for (i = 0; i < nr_zones; i++, z++, blkz++) { z->start = blkz->start << 9; diff --git a/oslib/linux-dev-lookup.c b/oslib/linux-dev-lookup.cpp similarity index 96% rename from oslib/linux-dev-lookup.c rename to oslib/linux-dev-lookup.cpp index 4335faf99b..19e8db8cfe 100644 --- a/oslib/linux-dev-lookup.c +++ b/oslib/linux-dev-lookup.cpp @@ -1,9 +1,11 @@ +#include +#include + #include #include #include + #include -#include -#include #include #include "linux-dev-lookup.h" diff --git a/oslib/linux-dev-lookup.h b/oslib/linux-dev-lookup.h index 144f33ad63..7e8cd10caa 100644 --- a/oslib/linux-dev-lookup.h +++ b/oslib/linux-dev-lookup.h @@ -1,7 +1,15 @@ #ifndef LINUX_DEV_LOOKUP #define LINUX_DEV_LOOKUP +#ifdef __cplusplus +extern "C" { +#endif + int blktrace_lookup_device(const char *redirect, char *path, unsigned int maj, unsigned int min); +#ifdef __cplusplus +} +#endif + #endif diff --git a/oslib/statx.c b/oslib/statx.cpp similarity index 95% rename from oslib/statx.c rename to oslib/statx.cpp index 1ca81ada23..2ce2b8d9fb 100644 --- a/oslib/statx.c +++ b/oslib/statx.cpp @@ -11,7 +11,7 @@ int statx(int dfd, const char *pathname, int flags, unsigned int mask, return syscall(__NR_statx, dfd, pathname, flags, mask, buffer); } #else -#include +#include int statx(int dfd, const char *pathname, int flags, unsigned int mask, struct statx *buffer) diff --git a/oslib/statx.h b/oslib/statx.h index d9758f7337..1e44f299a7 100644 --- a/oslib/statx.h +++ b/oslib/statx.h @@ -9,6 +9,15 @@ struct statx { }; #endif + +#ifdef __cplusplus +extern "C" { +#endif + int statx(int dfd, const char *pathname, int flags, unsigned int mask, struct statx *buffer); +#ifdef __cplusplus +} +#endif + #endif diff --git a/oslib/strcasestr.c b/oslib/strcasestr.cpp similarity index 90% rename from oslib/strcasestr.c rename to oslib/strcasestr.cpp index 5fa05fa140..f92491cb69 100644 --- a/oslib/strcasestr.c +++ b/oslib/strcasestr.cpp @@ -1,7 +1,8 @@ #ifndef CONFIG_STRCASESTR -#include -#include +#include +#include + #include "strcasestr.h" char *strcasestr(const char *s1, const char *s2) diff --git a/oslib/strcasestr.h b/oslib/strcasestr.h index f13e929ddd..0df7b2257a 100644 --- a/oslib/strcasestr.h +++ b/oslib/strcasestr.h @@ -3,8 +3,16 @@ #ifndef FIO_STRCASESTR_H #define FIO_STRCASESTR_H +#ifdef __cplusplus +extern "C" { +#endif + char *strcasestr(const char *haystack, const char *needle); +#ifdef __cplusplus +} +#endif + #endif #endif diff --git a/oslib/strlcat.c b/oslib/strlcat.cpp similarity index 98% rename from oslib/strlcat.c rename to oslib/strlcat.cpp index 3e86eeb979..96e43c8d72 100644 --- a/oslib/strlcat.c +++ b/oslib/strlcat.cpp @@ -15,8 +15,10 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#include + #include -#include + #include "strlcat.h" /* diff --git a/oslib/strlcat.h b/oslib/strlcat.h index 85e4bdab23..6e0105b994 100644 --- a/oslib/strlcat.h +++ b/oslib/strlcat.h @@ -5,8 +5,16 @@ #include +#ifdef __cplusplus +extern "C" { +#endif + size_t strlcat(char *dst, const char *src, size_t dsize); +#ifdef __cplusplus +} +#endif + #endif #endif diff --git a/oslib/strndup.c b/oslib/strndup.cpp similarity index 83% rename from oslib/strndup.c rename to oslib/strndup.cpp index 657904ab64..eca00320ff 100644 --- a/oslib/strndup.c +++ b/oslib/strndup.cpp @@ -1,7 +1,8 @@ #ifndef CONFIG_HAVE_STRNDUP -#include -#include +#include +#include + #include "strndup.h" char *strndup(const char *s, size_t n) diff --git a/oslib/strndup.h b/oslib/strndup.h index 2f41848ec2..cd8ad2a5c9 100644 --- a/oslib/strndup.h +++ b/oslib/strndup.h @@ -5,8 +5,16 @@ #include +#ifdef __cplusplus +extern "C" { +#endif + char *strndup(const char *s, size_t n); +#ifdef __cplusplus +} +#endif + #endif #endif diff --git a/oslib/strsep.c b/oslib/strsep.cpp similarity index 95% rename from oslib/strsep.c rename to oslib/strsep.cpp index 2d42ca0f31..9d8ed1501a 100644 --- a/oslib/strsep.c +++ b/oslib/strsep.cpp @@ -1,6 +1,7 @@ #ifndef CONFIG_STRSEP -#include +#include + #include "strsep.h" char *strsep(char **stringp, const char *delim) diff --git a/oslib/strsep.h b/oslib/strsep.h index 8cd9ada997..c70110c4c8 100644 --- a/oslib/strsep.h +++ b/oslib/strsep.h @@ -3,8 +3,16 @@ #ifndef FIO_STRSEP_LIB_H #define FIO_STRSEP_LIB_H +#ifdef __cplusplus +extern "C" { +#endif + char *strsep(char **, const char *); +#ifdef __cplusplus +} +#endif + #endif #endif diff --git a/parse.c b/parse.cpp similarity index 92% rename from parse.c rename to parse.cpp index 656a50250b..f8b686a1ec 100644 --- a/parse.c +++ b/parse.cpp @@ -1,13 +1,13 @@ /* * This file contains the ini and command liner parser main. */ -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include #include "compiler/compiler.h" #include "parse.h" @@ -47,8 +47,8 @@ static const struct fio_option *__fio_options; static int vp_cmp(const void *p1, const void *p2) { - const struct value_pair *vp1 = p1; - const struct value_pair *vp2 = p2; + const struct value_pair *vp1 = static_cast(p1); + const struct value_pair *vp2 = static_cast(p2); return strlen(vp2->ival) - strlen(vp1->ival); } @@ -121,22 +121,23 @@ static void show_option_values(const struct fio_option *o) static void show_option_help(const struct fio_option *o, int is_err) { const char *typehelp[] = { - [FIO_OPT_INVALID] = "invalid", - [FIO_OPT_STR] = "string (opt=bla)", - [FIO_OPT_STR_ULL] = "string (opt=bla)", - [FIO_OPT_STR_MULTI] = "string with possible k/m/g postfix (opt=4k)", - [FIO_OPT_STR_VAL] = "string (opt=bla)", - [FIO_OPT_STR_VAL_TIME] = "string with time postfix (opt=10s)", - [FIO_OPT_STR_STORE] = "string (opt=bla)", - [FIO_OPT_RANGE] = "one to three ranges (opt=1k-4k[,4k-8k[,1k-8k]])", - [FIO_OPT_INT] = "integer value (opt=100)", - [FIO_OPT_ULL] = "integer value (opt=100)", - [FIO_OPT_BOOL] = "boolean value (opt=1)", - [FIO_OPT_FLOAT_LIST] = "list of floating point values separated by ':' (opt=5.9:7.8)", - [FIO_OPT_STR_SET] = "empty or boolean value ([0|1])", - [FIO_OPT_DEPRECATED] = "deprecated", - [FIO_OPT_SOFT_DEPRECATED] = "deprecated", - [FIO_OPT_UNSUPPORTED] = "unsupported", + "invalid", + "string (opt=bla)", + "string (opt=bla)", + "string with possible k/m/g postfix (opt=4k)", + "string (opt=bla)", + "string with time postfix (opt=10s)", + "string (opt=bla)", + "one to three ranges (opt=1k-4k[,4k-8k[,1k-8k]])", + "integer value (opt=100)", + "integer value (opt=100)", + "boolean value (opt=1)", + "list of floating point values separated by ':' (opt=5.9:7.8)", + "empty or boolean value ([0|1])", + "string (opt=bla)", + "deprecated", + "deprecated", + "unsupported", }; ssize_t (*logger)(const char *format, ...); @@ -317,7 +318,7 @@ static unsigned long long get_mult_bytes(const char *str, int len, void *data, return __get_mult_bytes(p, data, percent); } -extern int evaluate_arithmetic_expression(const char *buffer, long long *ival, +extern "C" int evaluate_arithmetic_expression(const char *buffer, long long *ival, double *dval, double implied_units, int is_time); @@ -478,15 +479,10 @@ static int check_int(const char *p, int *val) static size_t opt_len(const char *str) { char delimiter[] = {',', ':'}; - char *postfix; - unsigned int i; - - for (i = 0; i < FIO_ARRAY_SIZE(delimiter); i++) { - postfix = strchr(str, delimiter[i]); - if (postfix) + for (unsigned int i = 0; i < FIO_ARRAY_SIZE(delimiter); i++) { + if (auto const *postfix = strchr(str, delimiter[i])) return (int)(postfix - str); } - return strlen(str); } @@ -495,10 +491,10 @@ static int str_match_len(const struct value_pair *vp, const char *str) return max(strlen(vp->ival), opt_len(str)); } -#define val_store(ptr, val, off, or, data, o) \ +#define val_store(ptr, val, off, _or, data, o) \ do { \ - ptr = td_var((data), (o), (off)); \ - if ((or)) \ + ptr = static_cast(td_var((data), (o), (off))); \ + if ((_or)) \ *ptr |= (val); \ else \ *ptr = (val); \ @@ -506,7 +502,7 @@ static int str_match_len(const struct value_pair *vp, const char *str) static const char *opt_type_name(const struct fio_option *o) { - compiletime_assert(FIO_ARRAY_SIZE(opt_type_names) - 1 == FIO_OPT_UNSUPPORTED, + static_assert(FIO_ARRAY_SIZE(opt_type_names) - 1 == FIO_OPT_UNSUPPORTED, "opt_type_names[] index"); if (o->type <= FIO_OPT_UNSUPPORTED) @@ -542,7 +538,7 @@ static bool val_too_small(const struct fio_option *o, unsigned long long val, return val < o->minval; } -static int __handle_option(const struct fio_option *o, const char *ptr, +static int __handle_option(const struct fio_option *o, char *ptr, void *data, int first, int more, int curr) { int il=0, *ilp; @@ -569,7 +565,7 @@ static int __handle_option(const struct fio_option *o, const char *ptr, case FIO_OPT_STR: case FIO_OPT_STR_ULL: case FIO_OPT_STR_MULTI: { - fio_opt_str_fn *fn = o->cb; + fio_opt_str_fn *fn = reinterpret_cast(o->cb); posval_sort(o, posval); @@ -607,7 +603,7 @@ static int __handle_option(const struct fio_option *o, const char *ptr, case FIO_OPT_STR_VAL: case FIO_OPT_STR_VAL_ZONE: { - fio_opt_str_val_fn *fn = o->cb; + fio_opt_str_val_fn *fn = reinterpret_cast(o->cb); char tmp[128], *p; size_t len = strlen(ptr); @@ -744,7 +740,7 @@ static int __handle_option(const struct fio_option *o, const char *ptr, break; } case FIO_OPT_FLOAT_LIST: { - char *cp2; + char const *cp2; if (first) { /* @@ -753,11 +749,11 @@ static int __handle_option(const struct fio_option *o, const char *ptr, */ if (o->off2) { ul2 = 0; - ilp = td_var(data, o, o->off2); + ilp = static_cast(td_var(data, o, o->off2)); *ilp = ul2; } - flp = td_var(data, o, o->off1); + flp = static_cast(td_var(data, o, o->off1)); for(i = 0; i < o->maxlen; i++) flp[i].u.f = 0.0; } @@ -783,7 +779,7 @@ static int __handle_option(const struct fio_option *o, const char *ptr, } } - flp = td_var(data, o, o->off1); + flp = static_cast(td_var(data, o, o->off1)); flp[curr].u.f = uf; dprint(FD_PARSE, " out=%f\n", uf); @@ -801,7 +797,7 @@ static int __handle_option(const struct fio_option *o, const char *ptr, len++; if (o->off2) { - ilp = td_var(data, o, o->off2); + ilp = static_cast(td_var(data, o, o->off2)); if (len > *ilp) *ilp = len; } @@ -810,13 +806,13 @@ static int __handle_option(const struct fio_option *o, const char *ptr, break; } case FIO_OPT_STR_STORE: { - fio_opt_str_fn *fn = o->cb; + auto *fn = reinterpret_cast(o->cb); if (!strlen(ptr)) return 1; if (o->off1) { - cp = td_var(data, o, o->off1); + cp = static_cast(td_var(data, o, o->off1)); if (*cp) free(*cp); *cp = strdup(ptr); @@ -843,7 +839,7 @@ static int __handle_option(const struct fio_option *o, const char *ptr, ret = 0; if (vp->cb) - fn = vp->cb; + fn = reinterpret_cast(vp->cb); rest = strstr(*cp ?: ptr, ":"); if (rest) { if (*cp) @@ -938,7 +934,7 @@ static int __handle_option(const struct fio_option *o, const char *ptr, } case FIO_OPT_BOOL: case FIO_OPT_STR_SET: { - fio_opt_int_fn *fn = o->cb; + auto *fn = reinterpret_cast(o->cb); if (ptr) ret = check_int(ptr, &il); @@ -1166,7 +1162,7 @@ static void add_to_dump_list(const struct fio_option *o, if (!dump_list) return; - p = malloc(sizeof(*p)); + p = static_cast(malloc(sizeof(*p))); p->name = strdup(o->name); if (post) p->value = strdup(post); @@ -1240,8 +1236,8 @@ int string_distance(const char *s1, const char *s2) unsigned int *p, *q, *r; unsigned int i, j; - p = malloc(sizeof(unsigned int) * (s2_len + 1)); - q = malloc(sizeof(unsigned int) * (s2_len + 1)); + p = static_cast(malloc(sizeof(unsigned int) * (s2_len + 1))); + q = static_cast(malloc(sizeof(unsigned int) * (s2_len + 1))); p[0] = 0; for (i = 1; i <= s2_len; i++) @@ -1487,7 +1483,7 @@ void options_mem_dupe(const struct fio_option *options, void *data) if (o->type != FIO_OPT_STR_STORE) continue; - ptr = td_var(data, o, o->off1); + ptr = static_cast(td_var(data, o, o->off1)); if (*ptr) *ptr = strdup(*ptr); } @@ -1504,7 +1500,7 @@ void options_free(const struct fio_option *options, void *data) if (o->type != FIO_OPT_STR_STORE || !o->off1 || o->no_free) continue; - ptr = td_var(data, o, o->off1); + ptr = static_cast(td_var(data, o, o->off1)); if (*ptr) { free(*ptr); *ptr = NULL; diff --git a/parse.h b/parse.h index d68484eaf0..432bf52ac7 100644 --- a/parse.h +++ b/parse.h @@ -4,6 +4,10 @@ #include #include "flist.h" +#ifdef __cplusplus +extern "C" { +#endif + /* * Option types */ @@ -151,4 +155,8 @@ struct print_option { char *value; }; +#ifdef __cplusplus +} +#endif + #endif diff --git a/printing.c b/printing.cpp similarity index 98% rename from printing.c rename to printing.cpp index b58996bb6a..2363f73190 100644 --- a/printing.c +++ b/printing.cpp @@ -5,7 +5,6 @@ #include "cairo_text_helpers.h" #include "printing.h" - static struct printing_parameters { gdouble width, height, xdpi, ydpi; GtkPrintSettings *settings; @@ -87,7 +86,7 @@ static void results_print_done(GtkPrintOperation *operation, GtkPrintOperationResult result, gpointer data) { GError *print_error; - struct gui_entry *ge = data; + struct gui_entry *ge = static_cast(data); if (result != GTK_PRINT_OPERATION_RESULT_ERROR) return; diff --git a/printing.h b/printing.h index 00799198f0..0d3c003cde 100644 --- a/printing.h +++ b/printing.h @@ -1,6 +1,15 @@ #ifndef PRINTING_H #define PRINTING_H +#ifdef __cplusplus +extern "C" { +#endif + +struct gui_entry; void gfio_print_results(struct gui_entry *ge); +#ifdef __cplusplus +} +#endif + #endif diff --git a/profile.c b/profile.cpp similarity index 100% rename from profile.c rename to profile.cpp diff --git a/profile.h b/profile.h index 414151e8cb..3777d5a894 100644 --- a/profile.h +++ b/profile.h @@ -3,6 +3,10 @@ #include "flist.h" +#ifdef __cplusplus +extern "C" { +#endif + /* * Functions for overriding internal fio io_u functions */ @@ -47,4 +51,8 @@ void profile_add_hooks(struct thread_data *); int profile_td_init(struct thread_data *); void profile_td_exit(struct thread_data *); +#ifdef __cplusplus +} +#endif + #endif diff --git a/profiles/act.c b/profiles/act.cpp similarity index 92% rename from profiles/act.c rename to profiles/act.cpp index 5d3bd2544e..152e1fd0f6 100644 --- a/profiles/act.c +++ b/profiles/act.cpp @@ -262,7 +262,7 @@ static int act_add_dev(const char *dev) /* * Fill our private options into the command line */ -static int act_prep_cmdline(void) +static int act_prep_cmdline() { if (!act_options.device_names) { log_err("act: you need to set IO target(s) with the " @@ -290,7 +290,7 @@ static int act_prep_cmdline(void) static int act_io_u_lat(struct thread_data *td, uint64_t nsec) { - struct act_prof_data *apd = td->prof_data; + struct act_prof_data *apd = static_cast(td->prof_data); struct act_slice *slice; uint64_t usec = nsec / 1000ULL; int i, ret = 0; @@ -335,7 +335,7 @@ static int act_io_u_lat(struct thread_data *td, uint64_t nsec) return ret; } -static void get_act_ref(void) +static void get_act_ref() { fio_sem_down(act_run_data->sem); act_run_data->pending++; @@ -369,7 +369,7 @@ static int show_slice(struct act_slice *slice, unsigned int slice_num) return failed; } -static void act_show_all_stats(void) +static void act_show_all_stats() { unsigned int i, fails = 0; @@ -393,13 +393,13 @@ static void act_show_all_stats(void) static void put_act_ref(struct thread_data *td) { - struct act_prof_data *apd = td->prof_data; + struct act_prof_data *apd = static_cast(td->prof_data); unsigned int i, slice; fio_sem_down(act_run_data->sem); if (!act_run_data->slices) { - act_run_data->slices = calloc(apd->nr_slices, sizeof(struct act_slice)); + act_run_data->slices = static_castslices)>(calloc(apd->nr_slices, sizeof(struct act_slice))); act_run_data->nr_slices = apd->nr_slices; } @@ -426,9 +426,9 @@ static int act_td_init(struct thread_data *td) get_act_ref(); - apd = calloc(1, sizeof(*apd)); + apd = static_cast(calloc(1, sizeof(*apd))); nr_slices = (act_options.test_duration + SAMPLE_SEC - 1) / SAMPLE_SEC; - apd->slices = calloc(nr_slices, sizeof(struct act_slice)); + apd->slices = static_castslices)>(calloc(nr_slices, sizeof(struct act_slice))); apd->nr_slices = nr_slices; fio_gettime(&apd->sample_tv, NULL); td->prof_data = apd; @@ -437,7 +437,7 @@ static int act_td_init(struct thread_data *td) static void act_td_exit(struct thread_data *td) { - struct act_prof_data *apd = td->prof_data; + struct act_prof_data *apd = static_cast(td->prof_data); put_act_ref(td); free(apd->slices); @@ -461,16 +461,16 @@ static struct profile_ops act_profile = { .io_ops = &act_io_ops, }; -static void fio_init act_register(void) +static void fio_init act_register() { - act_run_data = calloc(1, sizeof(*act_run_data)); + act_run_data = static_cast(calloc(1, sizeof(*act_run_data))); act_run_data->sem = fio_sem_init(FIO_SEM_UNLOCKED); if (register_profile(&act_profile)) log_err("fio: failed to register profile 'act'\n"); } -static void fio_exit act_unregister(void) +static void fio_exit act_unregister() { while (org_idx && org_idx < opt_idx) free((void *) act_opts[++org_idx]); diff --git a/profiles/tiobench.c b/profiles/tiobench.cpp similarity index 96% rename from profiles/tiobench.c rename to profiles/tiobench.cpp index f19a08577b..61c191400c 100644 --- a/profiles/tiobench.c +++ b/profiles/tiobench.cpp @@ -89,7 +89,7 @@ static struct fio_option options[] = { /* * Fill our private options into the command line */ -static int tb_prep_cmdline(void) +static int tb_prep_cmdline() { /* * tiobench uses size as MiB, so multiply up @@ -115,19 +115,19 @@ static int tb_prep_cmdline(void) static struct profile_ops tiobench_profile = { .name = "tiobench", .desc = "tiotest/tiobench benchmark", - .prep_cmd = tb_prep_cmdline, - .cmdline = tb_opts, .options = options, .opt_data = &tiobench_options, + .prep_cmd = tb_prep_cmdline, + .cmdline = tb_opts, }; -static void fio_init tiobench_register(void) +static void fio_init tiobench_register() { if (register_profile(&tiobench_profile)) log_err("fio: failed to register profile 'tiobench'\n"); } -static void fio_exit tiobench_unregister(void) +static void fio_exit tiobench_unregister() { unregister_profile(&tiobench_profile); } diff --git a/pshared.c b/pshared.cpp similarity index 99% rename from pshared.c rename to pshared.cpp index 182a36529d..76333b60cd 100644 --- a/pshared.c +++ b/pshared.cpp @@ -1,7 +1,8 @@ -#include +#include "pshared.h" + +#include #include "log.h" -#include "pshared.h" int cond_init_pshared(pthread_cond_t *cond) { diff --git a/pshared.h b/pshared.h index f33be4627f..8768c7591b 100644 --- a/pshared.h +++ b/pshared.h @@ -3,9 +3,17 @@ #include +#ifdef __cplusplus +extern "C" { +#endif + extern int mutex_init_pshared_with_type(pthread_mutex_t *, int); extern int mutex_init_pshared(pthread_mutex_t *); extern int cond_init_pshared(pthread_cond_t *); extern int mutex_cond_init_pshared(pthread_mutex_t *, pthread_cond_t *); +#ifdef __cplusplus +} +#endif + #endif diff --git a/rate-submit.c b/rate-submit.cpp similarity index 93% rename from rate-submit.c rename to rate-submit.cpp index 6f6d15bd66..2dcb6653bc 100644 --- a/rate-submit.c +++ b/rate-submit.cpp @@ -4,8 +4,9 @@ * Copyright (C) 2015 Jens Axboe * */ -#include -#include +#include +#include + #include #include "fio.h" @@ -65,7 +66,7 @@ static int io_workqueue_fn(struct submit_worker *sw, { struct io_u *io_u = container_of(work, struct io_u, work); const enum fio_ddir ddir = io_u->ddir; - struct thread_data *td = sw->priv; + struct thread_data *td = static_cast(sw->priv); int ret, error; if (td->o.serialize_overlap) @@ -119,7 +120,7 @@ static int io_workqueue_fn(struct submit_worker *sw, static bool io_workqueue_pre_sleep_flush_fn(struct submit_worker *sw) { - struct thread_data *td = sw->priv; + struct thread_data *td = static_cast(sw->priv); if (td->error) return false; @@ -131,7 +132,7 @@ static bool io_workqueue_pre_sleep_flush_fn(struct submit_worker *sw) static void io_workqueue_pre_sleep_fn(struct submit_worker *sw) { - struct thread_data *td = sw->priv; + struct thread_data *td = static_cast(sw->priv); int ret; ret = io_u_quiesce(td); @@ -142,8 +143,7 @@ static void io_workqueue_pre_sleep_fn(struct submit_worker *sw) static int io_workqueue_alloc_fn(struct submit_worker *sw) { struct thread_data *td; - - td = calloc(1, sizeof(*td)); + td = static_cast(calloc(1, sizeof(*td))); sw->priv = td; return 0; } @@ -157,7 +157,7 @@ static void io_workqueue_free_fn(struct submit_worker *sw) static int io_workqueue_init_worker_fn(struct submit_worker *sw) { struct thread_data *parent = sw->wq->td; - struct thread_data *td = sw->priv; + struct thread_data *td = static_cast(sw->priv); memcpy(&td->o, &parent->o, sizeof(td->o)); memcpy(&td->ts, &parent->ts, sizeof(td->ts)); @@ -204,7 +204,7 @@ static int io_workqueue_init_worker_fn(struct submit_worker *sw) static void io_workqueue_exit_worker_fn(struct submit_worker *sw, unsigned int *sum_cnt) { - struct thread_data *td = sw->priv; + struct thread_data *td = static_cast(sw->priv); (*sum_cnt)++; @@ -283,7 +283,7 @@ static void sum_ddir(struct thread_data *dst, struct thread_data *src, static void io_workqueue_update_acct_fn(struct submit_worker *sw) { - struct thread_data *src = sw->priv; + struct thread_data *src = static_cast(sw->priv); struct thread_data *dst = sw->wq->td; if (td_read(src)) diff --git a/rate-submit.h b/rate-submit.h index 19fde3a91c..6b4b2f5eec 100644 --- a/rate-submit.h +++ b/rate-submit.h @@ -1,7 +1,15 @@ #ifndef FIO_RATE_SUBMIT #define FIO_RATE_SUBMIT +#ifdef __cplusplus +extern "C" { +#endif + int rate_submit_init(struct thread_data *, struct sk_out *); void rate_submit_exit(struct thread_data *); +#ifdef __cplusplus +} +#endif + #endif diff --git a/rwlock.c b/rwlock.cpp similarity index 87% rename from rwlock.c rename to rwlock.cpp index 00e3809890..31c938fc26 100644 --- a/rwlock.c +++ b/rwlock.cpp @@ -1,7 +1,8 @@ -#include -#include +#include +#include +#include + #include -#include #include "log.h" #include "rwlock.h" @@ -32,15 +33,15 @@ void fio_rwlock_remove(struct fio_rwlock *lock) munmap((void *) lock, sizeof(*lock)); } -struct fio_rwlock *fio_rwlock_init(void) +struct fio_rwlock *fio_rwlock_init() { struct fio_rwlock *lock; pthread_rwlockattr_t attr; int ret; - lock = (void *) mmap(NULL, sizeof(struct fio_rwlock), + lock = static_cast(mmap(NULL, sizeof(struct fio_rwlock), PROT_READ | PROT_WRITE, - OS_MAP_ANON | MAP_SHARED, -1, 0); + OS_MAP_ANON | MAP_SHARED, -1, 0)); if (lock == MAP_FAILED) { perror("mmap rwlock"); lock = NULL; diff --git a/rwlock.h b/rwlock.h index 2968eed9f7..1236735a2f 100644 --- a/rwlock.h +++ b/rwlock.h @@ -10,10 +10,18 @@ struct fio_rwlock { int magic; }; +#ifdef __cplusplus +extern "C" { +#endif + extern void fio_rwlock_read(struct fio_rwlock *); extern void fio_rwlock_write(struct fio_rwlock *); extern void fio_rwlock_unlock(struct fio_rwlock *); extern struct fio_rwlock *fio_rwlock_init(void); extern void fio_rwlock_remove(struct fio_rwlock *); +#ifdef __cplusplus +} +#endif + #endif diff --git a/server.c b/server.cpp similarity index 95% rename from server.c rename to server.cpp index bb423702a7..872d359029 100644 --- a/server.c +++ b/server.cpp @@ -1,20 +1,24 @@ -#include -#include -#include +#include +#include +#include +#include +#include + #include -#include #include + #include #include #include #include #include #include + #include #include #include #include -#include + #ifdef CONFIG_ZLIB #include #endif @@ -170,11 +174,11 @@ static int __sk_out_drop(struct sk_out *sk_out) return 1; } -void sk_out_drop(void) +void sk_out_drop() { struct sk_out *sk_out; - sk_out = pthread_getspecific(sk_out_key); + sk_out = static_cast(pthread_getspecific(sk_out_key)); __sk_out_drop(sk_out); } @@ -240,7 +244,7 @@ static int fio_sendv_data(int sk, struct iovec *iov, int count) iov++; continue; } - iov->iov_base += ret; + iov->iov_base = static_cast(iov->iov_base) + ret; iov->iov_len -= ret; ret = 0; } @@ -292,7 +296,7 @@ bool fio_server_poll_fd(int fd, short events, int timeout) static int fio_recv_data(int sk, void *buf, unsigned int len, bool wait) { int flags; - char *p = buf; + auto *p = static_cast(buf); if (wait) flags = MSG_WAITALL; @@ -398,7 +402,7 @@ struct fio_net_cmd *fio_net_recv_cmd(int sk, bool wait) break; } - tmp = realloc(cmdret, cmd_size); + tmp = static_cast(realloc(cmdret, cmd_size)); if (!tmp) { log_err("fio: server failed allocating cmd\n"); ret = 1; @@ -479,7 +483,7 @@ static uint64_t alloc_reply(uint64_t tag, uint16_t opcode) { struct fio_net_cmd_reply *reply; - reply = calloc(1, sizeof(*reply)); + reply = static_cast(calloc(1, sizeof(*reply))); INIT_FLIST_HEAD(&reply->list); fio_gettime(&reply->ts, NULL); reply->saved_tag = tag; @@ -535,7 +539,7 @@ int fio_net_send_cmd(int fd, uint16_t opcode, const void *buf, off_t size, free(cmd); cur_len = sizeof(*cmd) + this_len; - cmd = malloc(cur_len); + cmd = static_cast(malloc(cur_len)); } fio_init_net_cmd(cmd, opcode, buf, this_len, tag); @@ -547,7 +551,7 @@ int fio_net_send_cmd(int fd, uint16_t opcode, const void *buf, off_t size, ret = fio_send_data(fd, cmd, sizeof(*cmd) + this_len); size -= this_len; - buf += this_len; + buf = static_cast(buf) + this_len; } while (!ret && size); if (list) { @@ -569,7 +573,7 @@ static struct sk_entry *fio_net_prep_cmd(uint16_t opcode, void *buf, { struct sk_entry *entry; - entry = smalloc(sizeof(*entry)); + entry = static_cast(smalloc(sizeof(*entry))); if (!entry) return NULL; @@ -594,7 +598,7 @@ static int handle_sk_entry(struct sk_out *sk_out, struct sk_entry *entry); static void fio_net_queue_entry(struct sk_entry *entry) { - struct sk_out *sk_out = pthread_getspecific(sk_out_key); + struct sk_out *sk_out = static_cast(pthread_getspecific(sk_out_key)); if (entry->flags & SK_F_INLINE) handle_sk_entry(sk_out, entry); @@ -657,7 +661,7 @@ int fio_net_send_simple_cmd(int sk, uint16_t opcode, uint64_t tag, return 0; } -static int fio_net_queue_quit(void) +static int fio_net_queue_quit() { dprint(FD_NET, "server: sending quit\n"); @@ -751,7 +755,7 @@ static void fio_server_add_fork_item(pid_t pid, struct flist_head *list) { struct fio_fork_item *ffi; - ffi = malloc(sizeof(*ffi)); + ffi = static_cast(malloc(sizeof(*ffi))); ffi->exitval = 0; ffi->signal = 0; ffi->exited = 0; @@ -858,7 +862,7 @@ static int handle_load_file_cmd(struct fio_net_cmd *cmd) pdu->name_len = le16_to_cpu(pdu->name_len); pdu->client_type = le16_to_cpu(pdu->client_type); - if (parse_jobs_ini(file_name, 0, 0, pdu->client_type)) { + if (parse_jobs_ini(static_cast(file_name), 0, 0, pdu->client_type)) { fio_net_queue_quit(); return -1; } @@ -936,7 +940,7 @@ static int handle_job_cmd(struct fio_net_cmd *cmd) pdu->buf_len = le32_to_cpu(pdu->buf_len); pdu->client_type = le32_to_cpu(pdu->client_type); - if (parse_jobs_ini(buf, 1, 0, pdu->client_type)) { + if (parse_jobs_ini(static_cast(buf), 1, 0, pdu->client_type)) { fio_net_queue_quit(); return -1; } @@ -958,16 +962,16 @@ static int handle_jobline_cmd(struct fio_net_cmd *cmd) char **argv; int i; - clp = pdu; + clp = static_cast(pdu); clp->lines = le16_to_cpu(clp->lines); clp->client_type = le16_to_cpu(clp->client_type); - argv = malloc(clp->lines * sizeof(char *)); + argv = static_cast(malloc(clp->lines * sizeof(char *))); offset = sizeof(*clp); dprint(FD_NET, "server: %d command line args\n", clp->lines); for (i = 0; i < clp->lines; i++) { - cslp = pdu + offset; + cslp = reinterpret_cast(static_cast(pdu) + offset); argv[i] = (char *) cslp->text; offset += sizeof(*cslp) + le16_to_cpu(cslp->len); @@ -1041,7 +1045,7 @@ static int handle_send_eta_cmd(struct fio_net_cmd *cmd) je = get_jobs_eta(true, &size); if (!je) { size = sizeof(*je); - je = calloc(1, size); + je = static_cast(calloc(1, size)); } else { je->nr_running = cpu_to_le32(je->nr_running); je->nr_ramp = cpu_to_le32(je->nr_ramp); @@ -1234,7 +1238,7 @@ static int fio_send_cmd_ext_pdu(int sk, uint16_t opcode, const void *buf, ret = fio_sendv_data(sk, iov, 2); size -= this_len; - buf += this_len; + buf = static_cast(buf) + this_len; } while (!ret && size); return ret; @@ -1446,7 +1450,7 @@ static int get_my_addr_str(int sk) } #ifdef WIN32 -static int handle_connection_process(void) +static int handle_connection_process() { WSAPROTOCOL_INFO protocol_info; DWORD bytes_read; @@ -1579,7 +1583,7 @@ static int accept_loop(int listen_sk) dprint(FD_NET, "server: connect from %s\n", from); - sk_out = scalloc(1, sizeof(*sk_out)); + sk_out = static_cast(scalloc(1, sizeof(*sk_out))); if (!sk_out) { close(sk); return -1; @@ -1622,7 +1626,7 @@ static int accept_loop(int listen_sk) int fio_server_text_output(int level, const char *buf, size_t len) { - struct sk_out *sk_out = pthread_getspecific(sk_out_key); + struct sk_out *sk_out = static_cast(pthread_getspecific(sk_out_key)); struct cmd_text_pdu *pdu; unsigned int tlen; struct timeval tv; @@ -1631,7 +1635,7 @@ int fio_server_text_output(int level, const char *buf, size_t len) return -1; tlen = sizeof(*pdu) + len; - pdu = malloc(tlen); + pdu = static_cast(malloc(tlen)); pdu->level = __cpu_to_le32(level); pdu->buf_len = __cpu_to_le32(len); @@ -1849,7 +1853,7 @@ void fio_server_send_ts(struct thread_stat *ts, struct group_run_stats *rs) if (ts->nr_clat_prio[i]) { uint64_t offset = (char *)extended_buf_wp - (char *)extended_buf; - struct cmd_ts_pdu *ptr = extended_buf; + struct cmd_ts_pdu *ptr = static_cast(extended_buf); ptr->ts.clat_prio_offset[i] = cpu_to_le64(offset); ptr->ts.nr_clat_prio[i] = cpu_to_le32(ts->nr_clat_prio[i]); @@ -1862,7 +1866,7 @@ void fio_server_send_ts(struct thread_stat *ts, struct group_run_stats *rs) if (ss_extra_size) { uint64_t *ss_iops, *ss_bw; uint64_t offset; - struct cmd_ts_pdu *ptr = extended_buf; + struct cmd_ts_pdu *ptr = static_cast(extended_buf); dprint(FD_NET, "server sending steadystate ring buffers\n"); @@ -1876,7 +1880,7 @@ void fio_server_send_ts(struct thread_stat *ts, struct group_run_stats *rs) extended_buf_wp = ss_iops + (int) ts->ss_dur; /* ss bw */ - ss_bw = extended_buf_wp; + ss_bw = static_cast(extended_buf_wp); for (i = 0; i < ts->ss_dur; i++) ss_bw[i] = cpu_to_le64(ts->ss_bw_data[i]); @@ -1975,7 +1979,7 @@ static void convert_dus(struct disk_util_stat *dst, struct disk_util_stat *src) dst->s.msec = cpu_to_le64(src->s.msec); } -void fio_server_send_du(void) +void fio_server_send_du() { struct disk_util *du; struct flist_head *entry; @@ -2019,7 +2023,7 @@ static int __deflate_pdu_buffer(void *next_in, unsigned int next_sz, void **out_ { int ret; - stream->next_in = next_in; + stream->next_in = static_cast(next_in); stream->avail_in = next_sz; do { if (!stream->avail_out) { @@ -2030,7 +2034,7 @@ static int __deflate_pdu_buffer(void *next_in, unsigned int next_sz, void **out_ *out_pdu = malloc(FIO_SERVER_MAX_FRAGMENT_PDU); stream->avail_out = FIO_SERVER_MAX_FRAGMENT_PDU; - stream->next_out = *out_pdu; + stream->next_out = static_cast(*out_pdu); } ret = deflate(stream, Z_BLOCK); @@ -2054,7 +2058,7 @@ static int __fio_append_iolog_gz_hist(struct sk_entry *first, struct io_log *log out_pdu = malloc(FIO_SERVER_MAX_FRAGMENT_PDU); stream->avail_out = FIO_SERVER_MAX_FRAGMENT_PDU; - stream->next_out = out_pdu; + stream->next_out = static_cast(out_pdu); for (i = 0; i < cur_log->nr_samples; i++) { struct io_sample *s; @@ -2102,7 +2106,7 @@ static int __fio_append_iolog_gz(struct sk_entry *first, struct io_log *log, if (log->log_type == IO_LOG_TYPE_HIST) return __fio_append_iolog_gz_hist(first, log, cur_log, stream); - stream->next_in = (void *) cur_log->log; + stream->next_in = static_cast(cur_log->log); stream->avail_in = cur_log->nr_samples * log_entry_sz(log); do { @@ -2116,7 +2120,7 @@ static int __fio_append_iolog_gz(struct sk_entry *first, struct io_log *log, out_pdu = malloc(FIO_SERVER_MAX_FRAGMENT_PDU); stream->avail_out = FIO_SERVER_MAX_FRAGMENT_PDU; - stream->next_out = out_pdu; + stream->next_out = static_cast(out_pdu); ret = deflate(stream, Z_BLOCK); /* may be Z_OK, or Z_STREAM_END */ if (ret < 0) { @@ -2170,7 +2174,7 @@ static int fio_append_iolog_gz(struct sk_entry *first, struct io_log *log) out_pdu = malloc(FIO_SERVER_MAX_FRAGMENT_PDU); stream.avail_out = FIO_SERVER_MAX_FRAGMENT_PDU; - stream.next_out = out_pdu; + stream.next_out = static_cast(out_pdu); ret = deflate(&stream, Z_FINISH); /* may be Z_OK, or Z_STREAM_END */ @@ -2293,7 +2297,7 @@ int fio_send_iolog(struct thread_data *td, struct io_log *log, const char *name) s->bs = cpu_to_le64(s->bs); if (log->log_offset) { - struct io_sample_offset *so = (void *) s; + struct io_sample_offset *so = reinterpret_cast(s); so->offset = cpu_to_le64(so->offset); } @@ -2330,7 +2334,7 @@ void fio_server_send_add_job(struct thread_data *td) size_t cmd_sz = offsetof(struct cmd_add_job_pdu, top) + thread_options_pack_size(&td->o); - pdu = malloc(cmd_sz); + pdu = static_cast(malloc(cmd_sz)); pdu->thread_number = cpu_to_le32(td->thread_number); pdu->groupid = cpu_to_le32(td->groupid); @@ -2342,7 +2346,7 @@ void fio_server_send_add_job(struct thread_data *td) void fio_server_send_start(struct thread_data *td) { - struct sk_out *sk_out = pthread_getspecific(sk_out_key); + struct sk_out *sk_out = static_cast(pthread_getspecific(sk_out_key)); if (sk_out->sk == -1) { log_err("pthread getting specific for key failed, sk_out %p, sk %i, err: %i:%s", @@ -2365,7 +2369,7 @@ int fio_server_get_verify_state(const char *name, int threadnumber, dprint(FD_NET, "server: request verify state\n"); - rep = smalloc(sizeof(*rep)); + rep = static_cast(smalloc(sizeof(*rep))); if (!rep) return ENOMEM; @@ -2403,8 +2407,8 @@ int fio_server_get_verify_state(const char *name, int threadnumber, * The format is verify_state_hdr, then thread_io_list. Verify * the header, and the thread_io_list checksum */ - s = rep->data + sizeof(struct verify_state_hdr); - if (verify_state_hdr(rep->data, s)) { + s = reinterpret_cast((char*)rep->data + sizeof(struct verify_state_hdr)); + if (verify_state_hdr(static_cast(rep->data), s)) { ret = EILSEQ; goto fail; } @@ -2424,7 +2428,7 @@ int fio_server_get_verify_state(const char *name, int threadnumber, return ret; } -static int fio_init_server_ip(void) +static int fio_init_server_ip() { struct sockaddr *addr; socklen_t socklen; @@ -2482,7 +2486,7 @@ static int fio_init_server_ip(void) return sk; } -static int fio_init_server_sock(void) +static int fio_init_server_sock() { struct sockaddr_un addr; socklen_t len; @@ -2512,7 +2516,7 @@ static int fio_init_server_sock(void) return sk; } -static int fio_init_server_connection(void) +static int fio_init_server_connection() { char bind_str[128]; int sk; @@ -2658,7 +2662,7 @@ int fio_server_parse_string(const char *str, char **ptr, bool *is_sock, * If no port seen yet, check if there's a last ',' at the end */ if (!lport) { - portp = strchr(host, ','); + portp = strchr(const_cast(host), ','); if (portp) { *portp = '\0'; portp++; @@ -2702,7 +2706,7 @@ int fio_server_parse_string(const char *str, char **ptr, bool *is_sock, * uses IP and binds to 0.0.0.0. * */ -static int fio_handle_server_arg(void) +static int fio_handle_server_arg() { int port = fio_net_port; bool is_sock; @@ -2735,12 +2739,11 @@ static void sig_int(int sig) unlink(bind_sock); } -static void set_sig_handlers(void) +static void set_sig_handlers() { - struct sigaction act = { - .sa_handler = sig_int, - .sa_flags = SA_RESTART, - }; + struct sigaction act{}; + act.sa_flags = SA_RESTART; + act.sa_handler = sig_int; sigaction(SIGINT, &act, NULL); @@ -2750,12 +2753,12 @@ static void set_sig_handlers(void) #endif } -void fio_server_destroy_sk_key(void) +void fio_server_destroy_sk_key() { pthread_key_delete(sk_out_key); } -int fio_server_create_sk_key(void) +int fio_server_create_sk_key() { if (pthread_key_create(&sk_out_key, NULL)) { log_err("fio: can't create sk_out backend key\n"); @@ -2766,7 +2769,7 @@ int fio_server_create_sk_key(void) return 0; } -static int fio_server(void) +static int fio_server() { int sk, ret; @@ -2810,7 +2813,7 @@ static int fio_server(void) void fio_server_got_signal(int signal) { - struct sk_out *sk_out = pthread_getspecific(sk_out_key); + struct sk_out *sk_out = static_cast(pthread_getspecific(sk_out_key)); assert(sk_out); diff --git a/server.h b/server.h index ad7061184b..b51949a73f 100644 --- a/server.h +++ b/server.h @@ -9,6 +9,10 @@ #include "stat.h" #include "diskutil.h" +#ifdef __cplusplus +extern "C" { +#endif + #define FIO_NET_PORT 8765 struct sk_out { @@ -241,4 +245,8 @@ extern void fio_server_destroy_sk_key(void); extern bool exit_backend; extern int fio_net_port; +#ifdef __cplusplus +} // extern "C" +#endif + #endif diff --git a/smalloc.c b/smalloc.cpp similarity index 94% rename from smalloc.c rename to smalloc.cpp index 23243054ec..e87cc17661 100644 --- a/smalloc.c +++ b/smalloc.cpp @@ -2,9 +2,10 @@ * simple memory allocator, backed by mmap() so that it hands out memory * that can be shared across processes and threads */ +#include +#include + #include -#include -#include #include "fio.h" #include "fio_sem.h" @@ -62,7 +63,7 @@ static inline int ptr_valid(struct pool *pool, void *ptr) { unsigned int pool_size = pool->nr_blocks * SMALLOC_BPL; - return (ptr >= pool->map) && (ptr < pool->map + pool_size); + return (ptr >= pool->map) && (ptr < static_cast(pool->map) + pool_size); } static inline size_t size_to_blocks(size_t size) @@ -203,7 +204,7 @@ static bool add_pool(struct pool *pool, unsigned int alloc_size) return false; } -void sinit(void) +void sinit() { bool ret; int i; @@ -247,7 +248,7 @@ static void cleanup_pool(struct pool *pool) fio_sem_remove(pool->lock); } -void scleanup(void) +void scleanup() { unsigned int i; @@ -270,7 +271,7 @@ static void *postred_ptr(struct block_hdr *hdr) static void fill_redzone(struct block_hdr *hdr) { - unsigned int *postred = postred_ptr(hdr); + unsigned int *postred = static_cast(postred_ptr(hdr)); hdr->prered = SMALLOC_PRE_RED; *postred = SMALLOC_POST_RED; @@ -278,7 +279,7 @@ static void fill_redzone(struct block_hdr *hdr) static void sfree_check_redzone(struct block_hdr *hdr) { - unsigned int *postred = postred_ptr(hdr); + unsigned int *postred = static_cast(postred_ptr(hdr)); if (hdr->prered != SMALLOC_PRE_RED) { log_err("smalloc pre redzone destroyed!\n" @@ -312,14 +313,14 @@ static void sfree_pool(struct pool *pool, void *ptr) if (!ptr) return; - ptr -= sizeof(*hdr); - hdr = ptr; + ptr = static_cast(ptr) - sizeof(*hdr); + hdr = static_cast(ptr); assert(ptr_valid(pool, ptr)); sfree_check_redzone(hdr); - offset = ptr - pool->map; + offset = static_cast(ptr) - static_cast(pool->map); i = offset / SMALLOC_BPL; idx = (offset % SMALLOC_BPL) / SMALLOC_BPB; @@ -422,7 +423,7 @@ static void *__smalloc_pool(struct pool *pool, size_t size) if (i < pool->nr_blocks) { pool->free_blocks -= nr_blocks; - ret = pool->map + offset; + ret = static_cast(pool->map) + offset; } fail: fio_sem_up(pool->lock); @@ -452,12 +453,12 @@ static void *smalloc_pool(struct pool *pool, size_t size) ptr = __smalloc_pool(pool, alloc_size); if (ptr) { - struct block_hdr *hdr = ptr; + struct block_hdr *hdr = static_cast(ptr); hdr->size = alloc_size; fill_redzone(hdr); - ptr += sizeof(*hdr); + ptr = static_cast(ptr) + sizeof(*hdr); memset(ptr, 0, size); } @@ -474,7 +475,7 @@ static void smalloc_print_bitmap(struct pool *pool) if (!enable_smalloc_debug) return; - buffer = malloc(SMALLOC_BPI + 1); + buffer = static_cast(malloc(SMALLOC_BPI + 1)); if (!buffer) return; buffer[SMALLOC_BPI] = '\0'; @@ -573,7 +574,7 @@ char *smalloc_strdup(const char *str) { char *ptr = NULL; - ptr = smalloc(strlen(str) + 1); + ptr = static_cast(smalloc(strlen(str) + 1)); if (ptr) strcpy(ptr, str); return ptr; diff --git a/smalloc.h b/smalloc.h index 1f7716f45a..9219428649 100644 --- a/smalloc.h +++ b/smalloc.h @@ -1,7 +1,12 @@ #ifndef FIO_SMALLOC_H #define FIO_SMALLOC_H +#ifdef __cplusplus +#include +extern "C" { +#else #include +#endif extern void *smalloc(size_t); extern void *scalloc(size_t, size_t); @@ -13,4 +18,8 @@ extern void smalloc_debug(size_t); extern unsigned int smalloc_pool_size; +#ifdef __cplusplus +} +#endif + #endif diff --git a/stat.c b/stat.cpp similarity index 96% rename from stat.c rename to stat.cpp index 7b791628f4..7881ba6f27 100644 --- a/stat.c +++ b/stat.cpp @@ -1,20 +1,24 @@ -#include -#include -#include +#include +#include +#include +#include + #include #include -#include #include "fio.h" #include "diskutil.h" +#include "io_ddir.h" #include "lib/ieee754.h" #include "json.h" #include "lib/getrusage.h" #include "idletime.h" +#include "lib/num2str.h" #include "lib/pow2.h" #include "lib/output_buffer.h" #include "helper_thread.h" #include "smalloc.h" +#include "stat.h" #include "zbd.h" #include "oslib/asprintf.h" @@ -166,7 +170,7 @@ unsigned int calc_clat_percentiles(uint64_t *io_u_plat, unsigned long long nr, if (len > 1) qsort(plist, len, sizeof(plist[0]), double_cmp); - ovals = malloc(len * sizeof(*ovals)); + ovals = static_cast(malloc(len * sizeof(*ovals))); if (!ovals) return 0; @@ -319,12 +323,12 @@ void show_mixed_group_stats(struct group_run_stats *rs, struct buf_output *out) } io = num2str(io_mix, rs->sig_figs, 1, i2p, N2S_BYTE); ioalt = num2str(io_mix, rs->sig_figs, 1, !i2p, N2S_BYTE); - agg = num2str(agg_mix, rs->sig_figs, 1, i2p, rs->unit_base); - aggalt = num2str(agg_mix, rs->sig_figs, 1, !i2p, rs->unit_base); - min = num2str(min_mix, rs->sig_figs, 1, i2p, rs->unit_base); - minalt = num2str(min_mix, rs->sig_figs, 1, !i2p, rs->unit_base); - max = num2str(max_mix, rs->sig_figs, 1, i2p, rs->unit_base); - maxalt = num2str(max_mix, rs->sig_figs, 1, !i2p, rs->unit_base); + agg = num2str(agg_mix, rs->sig_figs, 1, i2p, static_cast(rs->unit_base)); + aggalt = num2str(agg_mix, rs->sig_figs, 1, !i2p, static_cast(rs->unit_base)); + min = num2str(min_mix, rs->sig_figs, 1, i2p, static_cast(rs->unit_base)); + minalt = num2str(min_mix, rs->sig_figs, 1, !i2p, static_cast(rs->unit_base)); + max = num2str(max_mix, rs->sig_figs, 1, i2p, static_cast(rs->unit_base)); + maxalt = num2str(max_mix, rs->sig_figs, 1, !i2p, static_cast(rs->unit_base)); log_buf(out, " MIXED: bw=%s (%s), %s-%s (%s-%s), io=%s (%s), run=%llu-%llumsec\n", agg, aggalt, min, max, minalt, maxalt, io, ioalt, (unsigned long long) min_run, @@ -356,12 +360,12 @@ void show_group_stats(struct group_run_stats *rs, struct buf_output *out) io = num2str(rs->iobytes[i], rs->sig_figs, 1, i2p, N2S_BYTE); ioalt = num2str(rs->iobytes[i], rs->sig_figs, 1, !i2p, N2S_BYTE); - agg = num2str(rs->agg[i], rs->sig_figs, 1, i2p, rs->unit_base); - aggalt = num2str(rs->agg[i], rs->sig_figs, 1, !i2p, rs->unit_base); - min = num2str(rs->min_bw[i], rs->sig_figs, 1, i2p, rs->unit_base); - minalt = num2str(rs->min_bw[i], rs->sig_figs, 1, !i2p, rs->unit_base); - max = num2str(rs->max_bw[i], rs->sig_figs, 1, i2p, rs->unit_base); - maxalt = num2str(rs->max_bw[i], rs->sig_figs, 1, !i2p, rs->unit_base); + agg = num2str(rs->agg[i], rs->sig_figs, 1, i2p, static_cast(rs->unit_base)); + aggalt = num2str(rs->agg[i], rs->sig_figs, 1, !i2p, static_cast(rs->unit_base)); + min = num2str(rs->min_bw[i], rs->sig_figs, 1, i2p, static_cast(rs->unit_base)); + minalt = num2str(rs->min_bw[i], rs->sig_figs, 1, !i2p, static_cast(rs->unit_base)); + max = num2str(rs->max_bw[i], rs->sig_figs, 1, i2p, static_cast(rs->unit_base)); + maxalt = num2str(rs->max_bw[i], rs->sig_figs, 1, !i2p, static_cast(rs->unit_base)); log_buf(out, "%s: bw=%s (%s), %s-%s (%s-%s), io=%s (%s), run=%llu-%llumsec\n", (rs->unified_rw_rep == UNIFIED_MIXED) ? " MIXED" : str[i], agg, aggalt, min, max, minalt, maxalt, io, ioalt, @@ -483,10 +487,10 @@ static struct thread_stat *gen_mixed_ddir_stats_from_ts(struct thread_stat *ts) * Handle aggregation of Reads (ddir = 0), Writes (ddir = 1), and * Trims (ddir = 2) */ - ts_lcl = malloc(sizeof(struct thread_stat)); + ts_lcl = static_cast(malloc(sizeof(struct thread_stat))); if (!ts_lcl) { log_err("fio: failed to allocate local thread stat\n"); - return NULL; + return nullptr; } init_thread_stat(ts_lcl); @@ -550,8 +554,8 @@ static void show_ddir_status(struct group_run_stats *rs, struct thread_stat *ts, bw = (1000 * ts->io_bytes[ddir]) / runt; io_p = num2str(ts->io_bytes[ddir], ts->sig_figs, 1, i2p, N2S_BYTE); - bw_p = num2str(bw, ts->sig_figs, 1, i2p, ts->unit_base); - bw_p_alt = num2str(bw, ts->sig_figs, 1, !i2p, ts->unit_base); + bw_p = num2str(bw, ts->sig_figs, 1, i2p, static_cast(ts->unit_base)); + bw_p_alt = num2str(bw, ts->sig_figs, 1, !i2p, static_cast(ts->unit_base)); iops = (1000 * (uint64_t)ts->total_io_u[ddir]) / runt; iops_p = num2str(iops, ts->sig_figs, 1, 0, N2S_NONE); @@ -862,7 +866,7 @@ static int calc_block_percentiles(int nr_block_infos, uint32_t *block_infos, if (nr_uninit == nr_block_infos) return 0; - *percentiles = calloc(len, sizeof(**percentiles)); + *percentiles = static_cast(calloc(len, sizeof(**percentiles))); for (i = 0; i < len; i++) { int idx = (plist[i].u.f * (nr_block_infos - nr_uninit) / 100) @@ -935,8 +939,8 @@ static void show_ss_normal(struct thread_stat *ts, struct buf_output *out) bw_mean = steadystate_bw_mean(ts); iops_mean = steadystate_iops_mean(ts); - p1 = num2str(bw_mean / ts->kb_base, ts->sig_figs, ts->kb_base, i2p, ts->unit_base); - p1alt = num2str(bw_mean / ts->kb_base, ts->sig_figs, ts->kb_base, !i2p, ts->unit_base); + p1 = num2str(bw_mean / ts->kb_base, ts->sig_figs, ts->kb_base, i2p, static_cast(ts->unit_base)); + p1alt = num2str(bw_mean / ts->kb_base, ts->sig_figs, ts->kb_base, !i2p, static_cast(ts->unit_base)); p2 = num2str(iops_mean, ts->sig_figs, 1, 0, N2S_NONE); log_buf(out, " steadystate : attained=%s, bw=%s (%s), iops=%s, %s%s=%.3f%s\n", @@ -1208,7 +1212,7 @@ static void show_thread_status_normal(struct thread_stat *ts, for_each_rw_ddir(ddir) { if (ts->io_bytes[ddir]) - show_ddir_status(rs, ts, ddir, out); + show_ddir_status(rs, ts, static_cast(ddir), out); } if (ts->unified_rw_rep == UNIFIED_BOTH) @@ -2062,12 +2066,10 @@ void sum_group_stats(struct group_run_stats *dst, struct group_run_stats *src) */ void free_clat_prio_stats(struct thread_stat *ts) { - enum fio_ddir ddir; - if (!ts) return; - for (ddir = 0; ddir < DDIR_RWDIR_CNT; ddir++) { + for (int ddir = 0; ddir < DDIR_RWDIR_CNT; ddir++) { sfree(ts->clat_prio[ddir]); ts->clat_prio[ddir] = NULL; ts->nr_clat_prio[ddir] = 0; @@ -2085,7 +2087,7 @@ int alloc_clat_prio_stat_ddir(struct thread_stat *ts, enum fio_ddir ddir, struct clat_prio_stat *clat_prio; int i; - clat_prio = scalloc(nr_prios, sizeof(*ts->clat_prio[ddir])); + clat_prio = static_cast(scalloc(nr_prios, sizeof(*ts->clat_prio[ddir]))); if (!clat_prio) { log_err("fio: failed to allocate ts clat data\n"); return 1; @@ -2115,7 +2117,7 @@ static int grow_clat_prio_stat(struct thread_stat *dst, enum fio_ddir ddir) curr_len * sizeof(*dst->clat_prio[ddir])); sfree(dst->clat_prio[ddir]); - dst->clat_prio[ddir] = new_arr; + dst->clat_prio[ddir] = static_cast(new_arr); dst->clat_prio[ddir][curr_len].clat_stat.min_val = ULONG_MAX; dst->nr_clat_prio[ddir]++; @@ -2161,7 +2163,7 @@ static int clat_prio_stats_copy(struct thread_stat *dst, struct thread_stat *src size_t sz = sizeof(*src->clat_prio[src_ddir]) * src->nr_clat_prio[src_ddir]; - dst->clat_prio[dst_ddir] = smalloc(sz); + dst->clat_prio[dst_ddir] = static_cast(smalloc(sz)); if (!dst->clat_prio[dst_ddir]) { log_err("fio: failed to alloc clat prio array\n"); return 1; @@ -2280,7 +2282,7 @@ void sum_thread_stats(struct thread_stat *dst, struct thread_stat *src) sum_stat(&dst->lat_stat[l], &src->lat_stat[l], false); sum_stat(&dst->bw_stat[l], &src->bw_stat[l], true); sum_stat(&dst->iops_stat[l], &src->iops_stat[l], true); - sum_clat_prio_stats(dst, src, l, l); + sum_clat_prio_stats(dst, src, static_cast(l), static_cast(l)); dst->io_bytes[l] += src->io_bytes[l]; @@ -2292,7 +2294,7 @@ void sum_thread_stats(struct thread_stat *dst, struct thread_stat *src) sum_stat(&dst->lat_stat[0], &src->lat_stat[l], false); sum_stat(&dst->bw_stat[0], &src->bw_stat[l], true); sum_stat(&dst->iops_stat[0], &src->iops_stat[l], true); - sum_clat_prio_stats(dst, src, 0, l); + sum_clat_prio_stats(dst, src, static_cast(0), static_cast(l)); dst->io_bytes[0] += src->io_bytes[l]; @@ -2389,7 +2391,7 @@ static void init_per_prio_stats(struct thread_stat *threadstats, int nr_ts) { struct thread_stat *ts; int i, j, last_ts, idx; - enum fio_ddir ddir; + int ddir; j = 0; last_ts = -1; @@ -2436,7 +2438,7 @@ static void init_per_prio_stats(struct thread_stat *threadstats, int nr_ts) } } -void __show_run_stats(void) +void __show_run_stats() { struct group_run_stats *runstats, *rs; struct thread_stat *threadstats, *ts; @@ -2448,7 +2450,7 @@ void __show_run_stats(void) struct buf_output output[FIO_OUTPUT_NR]; struct flist_head **opt_lists; - runstats = malloc(sizeof(struct group_run_stats) * (groupid + 1)); + runstats = static_cast(malloc(sizeof(struct group_run_stats) * (groupid + 1))); for (i = 0; i < groupid + 1; i++) init_group_run_stat(&runstats[i]); @@ -2473,8 +2475,8 @@ void __show_run_stats(void) nr_ts++; } end_for_each(); - threadstats = malloc(nr_ts * sizeof(struct thread_stat)); - opt_lists = malloc(nr_ts * sizeof(struct flist_head *)); + threadstats = static_cast(malloc(nr_ts * sizeof(struct thread_stat))); + opt_lists = static_cast(malloc(nr_ts * sizeof(struct flist_head *))); for (i = 0; i < nr_ts; i++) { init_thread_stat(&threadstats[i]); @@ -2623,7 +2625,7 @@ void __show_run_stats(void) } for (i = 0; i < groupid + 1; i++) { - enum fio_ddir ddir; + int ddir; rs = &runstats[i]; @@ -2739,14 +2741,14 @@ void __show_run_stats(void) free(opt_lists); } -int __show_running_run_stats(void) +int __show_running_run_stats() { unsigned long long *rt; struct timespec ts; fio_sem_down(stat_sem); - rt = malloc(thread_number * sizeof(unsigned long long)); + rt = static_cast(malloc(thread_number * sizeof(unsigned long long))); fio_gettime(&ts, NULL); for_each_td(td) { @@ -2802,7 +2804,7 @@ static bool status_file_disabled; #define FIO_STATUS_FILE "fio-dump-status" -static int check_status_file(void) +static int check_status_file() { struct stat sb; const char *temp_dir; @@ -2838,7 +2840,7 @@ static int check_status_file(void) return 1; } -void check_for_running_stats(void) +void check_for_running_stats() { if (check_status_file()) { show_running_run_stats(); @@ -2897,7 +2899,7 @@ static struct io_logs *get_new_log(struct io_log *iolog) new_samples = MAX_LOG_ENTRIES; } - cur_log = smalloc(sizeof(*cur_log)); + cur_log = static_cast(smalloc(sizeof(*cur_log))); if (cur_log) { INIT_FLIST_HEAD(&cur_log->list); cur_log->log = calloc(new_samples, log_entry_sz(iolog)); @@ -2911,7 +2913,7 @@ static struct io_logs *get_new_log(struct io_log *iolog) sfree(cur_log); } - return NULL; + return nullptr; } /* @@ -2929,7 +2931,7 @@ static struct io_logs *regrow_log(struct io_log *iolog) if (!cur_log) { cur_log = get_new_log(iolog); if (!cur_log) - return NULL; + return nullptr; } if (cur_log->nr_samples < cur_log->max_samples) @@ -2942,7 +2944,7 @@ static struct io_logs *regrow_log(struct io_log *iolog) if (iolog->log_gz) { if (iolog_cur_flush(iolog, cur_log)) { log_err("fio: failed flushing iolog! Will stop logging.\n"); - return NULL; + return nullptr; } } @@ -2952,7 +2954,7 @@ static struct io_logs *regrow_log(struct io_log *iolog) cur_log = get_new_log(iolog); if (!cur_log) { log_err("fio: failed extending iolog! Will stop logging.\n"); - return NULL; + return nullptr; } if (!iolog->pending || !iolog->pending->nr_samples) @@ -2975,7 +2977,7 @@ static struct io_logs *regrow_log(struct io_log *iolog) disable: if (iolog) iolog->disabled = true; - return NULL; + return nullptr; } void regrow_logs(struct thread_data *td) @@ -2989,9 +2991,9 @@ void regrow_logs(struct thread_data *td) td->flags &= ~TD_F_REGROW_LOGS; } -void regrow_agg_logs(void) +void regrow_agg_logs() { - enum fio_ddir ddir; + int ddir; for (ddir = 0; ddir < DDIR_RWDIR_CNT; ddir++) regrow_log(agg_io_log[ddir]); @@ -3005,7 +3007,7 @@ static struct io_logs *get_cur_log(struct io_log *iolog) if (!cur_log) { cur_log = get_new_log(iolog); if (!cur_log) - return NULL; + return nullptr; } if (cur_log->nr_samples < cur_log->max_samples) @@ -3054,7 +3056,7 @@ static void __add_log_sample(struct io_log *iolog, union io_sample_data data, s->priority = priority; if (iolog->log_offset) { - struct io_sample_offset *so = (void *) s; + struct io_sample_offset *so = reinterpret_cast(s); so->offset = offset; } @@ -3083,7 +3085,7 @@ static inline void reset_io_u_plat(uint64_t *io_u_plat) static inline void reset_clat_prio_stats(struct thread_stat *ts) { - enum fio_ddir ddir; + int ddir; int i; for (ddir = 0; ddir < DDIR_RWDIR_CNT; ddir++) { @@ -3169,10 +3171,8 @@ static void __add_stat_to_log(struct io_log *iolog, enum fio_ddir ddir, static void _add_stat_to_log(struct io_log *iolog, unsigned long elapsed, bool log_max) { - enum fio_ddir ddir; - - for (ddir = 0; ddir < DDIR_RWDIR_CNT; ddir++) - __add_stat_to_log(iolog, ddir, elapsed, log_max); + for (int ddir = 0; ddir < DDIR_RWDIR_CNT; ddir++) + __add_stat_to_log(iolog, static_cast(ddir), elapsed, log_max); } static unsigned long add_log_sample(struct thread_data *td, @@ -3350,7 +3350,7 @@ void add_clat_sample(struct thread_data *td, enum fio_ddir ddir, * log file. */ io_u_plat = (uint64_t *) td->ts.io_u_plat[FIO_CLAT][ddir]; - dst = malloc(sizeof(struct io_u_plat_entry)); + dst = static_cast(malloc(sizeof(struct io_u_plat_entry))); memcpy(&(dst->io_u_plat), io_u_plat, FIO_IO_U_PLAT_NR * sizeof(uint64_t)); flist_add(&dst->list, &hw->list); @@ -3472,7 +3472,7 @@ static int __add_samples(struct thread_data *td, struct timespec *parent_tv, { const bool needs_lock = td_async_processing(td); unsigned long spent, rate; - enum fio_ddir ddir; + int ddir; unsigned long next, next_log; next_log = avg_time; @@ -3510,7 +3510,7 @@ static int __add_samples(struct thread_data *td, struct timespec *parent_tv, if (td->o.min_bs[ddir] == td->o.max_bs[ddir]) bs = td->o.min_bs[ddir]; - next = add_log_sample(td, log, sample_val(rate), ddir, + next = add_log_sample(td, log, sample_val(rate), static_cast(ddir), bs, 0, 0); next_log = min(next_log, next); } @@ -3569,7 +3569,7 @@ static int add_iops_samples(struct thread_data *td, struct timespec *t) /* * Returns msecs to next event */ -int calc_log_samples(void) +int calc_log_samples() { unsigned int next = ~0U, tmp = 0, next_mod = 0, log_avg_msec_min = -1U; struct timespec now; @@ -3621,12 +3621,12 @@ int calc_log_samples(void) return next == ~0U ? 0 : next; } -void stat_init(void) +void stat_init() { stat_sem = fio_sem_init(FIO_SEM_UNLOCKED); } -void stat_exit(void) +void stat_exit() { /* * When we have the mutex, we know out-of-band access to it @@ -3639,7 +3639,7 @@ void stat_exit(void) /* * Called from signal handler. Wake up status thread. */ -void show_running_run_stats(void) +void show_running_run_stats() { helper_do_stat(); } diff --git a/stat.h b/stat.h index 8ceabc48c7..0c596e012f 100644 --- a/stat.h +++ b/stat.h @@ -6,6 +6,10 @@ #include "diskutil.h" #include "json.h" +#ifdef __cplusplus +extern "C" { +#endif + struct group_run_stats { uint64_t max_run[DDIR_RWDIR_CNT], min_run[DDIR_RWDIR_CNT]; uint64_t max_bw[DDIR_RWDIR_CNT], min_bw[DDIR_RWDIR_CNT]; @@ -428,4 +432,8 @@ static inline bool nsec_to_msec(unsigned long long *min, uint32_t *io_u_block_info(struct thread_data *td, struct io_u *io_u); +#ifdef __cplusplus +} +#endif + #endif diff --git a/steadystate.c b/steadystate.cpp similarity index 97% rename from steadystate.c rename to steadystate.cpp index 3e3683f38a..6d766ecba1 100644 --- a/steadystate.c +++ b/steadystate.cpp @@ -1,4 +1,4 @@ -#include +#include #include "fio.h" #include "steadystate.h" @@ -18,13 +18,13 @@ static void steadystate_alloc(struct thread_data *td) { int intervals = td->ss.dur / (ss_check_interval / 1000L); - td->ss.bw_data = calloc(intervals, sizeof(uint64_t)); - td->ss.iops_data = calloc(intervals, sizeof(uint64_t)); + td->ss.bw_data = static_cast(calloc(intervals, sizeof(uint64_t))); + td->ss.iops_data = static_cast(calloc(intervals, sizeof(uint64_t))); td->ss.state |= FIO_SS_DATA; } -void steadystate_setup(void) +void steadystate_setup() { struct thread_data *prev_td; int prev_groupid; @@ -203,7 +203,7 @@ static bool steadystate_deviation(uint64_t iops, uint64_t bw, return false; } -int steadystate_check(void) +int steadystate_check() { int ddir, prev_groupid, group_ramp_time_over = 0; unsigned long rate_time; @@ -358,7 +358,7 @@ uint64_t steadystate_bw_mean(struct thread_stat *ts) int i; uint64_t sum; int intervals = ts->ss_dur / (ss_check_interval / 1000L); - + if (!ts->ss_dur) return 0; diff --git a/steadystate.h b/steadystate.h index f1ef2b20ba..f11b42f4ec 100644 --- a/steadystate.h +++ b/steadystate.h @@ -3,6 +3,10 @@ #include "thread_options.h" +#ifdef __cplusplus +extern "C" { +#endif + extern void steadystate_free(struct thread_data *); extern int steadystate_check(void); extern void steadystate_setup(void); @@ -65,4 +69,8 @@ enum { FIO_SS_BW_SLOPE = FIO_SS_BW | FIO_SS_SLOPE, }; +#ifdef __cplusplus +} +#endif + #endif diff --git a/td_error.c b/td_error.cpp similarity index 100% rename from td_error.c rename to td_error.cpp diff --git a/td_error.h b/td_error.h index 1cc3a75390..7116896baf 100644 --- a/td_error.h +++ b/td_error.h @@ -3,6 +3,10 @@ #include "io_ddir.h" +#ifdef __cplusplus +extern "C" { +#endif + /* * What type of errors to continue on when continue_on_error is used, * and what type of errors to ignore when ignore_error is used. @@ -27,4 +31,8 @@ int td_non_fatal_error(struct thread_data *td, enum error_type_bit etype, int err); void update_error_count(struct thread_data *td, int err); +#ifdef __cplusplus +} +#endif + #endif diff --git a/thread_options.h b/thread_options.h index 38a9993d23..c55566f4b4 100644 --- a/thread_options.h +++ b/thread_options.h @@ -10,6 +10,10 @@ #include "lib/pattern.h" #include "td_error.h" +#ifdef __cplusplus +extern "C" { +#endif + enum fio_zone_mode { ZONE_MODE_NOT_SPECIFIED = 0, ZONE_MODE_NONE = 1, @@ -735,4 +739,8 @@ extern int split_parse_prio_ddir(struct thread_options *o, struct split_prio **entries, int *nr_entries, char *str); +#ifdef __cplusplus +} +#endif + #endif diff --git a/tickmarks.c b/tickmarks.cpp similarity index 94% rename from tickmarks.c rename to tickmarks.cpp index 88bace09dc..5d40b74a37 100644 --- a/tickmarks.c +++ b/tickmarks.cpp @@ -1,7 +1,9 @@ -#include -#include -#include -#include +#include "tickmarks.h" + +#include +#include +#include +#include /* * adapted from Paul Heckbert's algorithm on p 657-659 of @@ -106,7 +108,7 @@ int calc_tickmarks(double min, double max, int nticks, struct tickmark **tm, snprintf(str, sizeof(str)-1, "%%.%df", nfrac); count = ((graphmax + 0.5 * d) - graphmin) / d + 1; - *tm = malloc(sizeof(**tm) * count); + *tm = static_cast(malloc(sizeof(**tm) * count)); i = 0; for (x = graphmin; x < graphmax + 0.5 * d; x += d) { diff --git a/tickmarks.h b/tickmarks.h index 1e310dbb18..d8df2f7d78 100644 --- a/tickmarks.h +++ b/tickmarks.h @@ -6,7 +6,15 @@ struct tickmark { char string[20]; }; +#ifdef __cplusplus +extern "C" { +#endif + int calc_tickmarks(double min, double max, int nticks, struct tickmark **tm, int *power_of_ten, int use_KMG_symbols, int base_off); +#ifdef __cplusplus +} +#endif + #endif diff --git a/time.c b/time.cpp similarity index 95% rename from time.c rename to time.cpp index 5c4d6de039..3ef777ead9 100644 --- a/time.c +++ b/time.cpp @@ -1,4 +1,5 @@ -#include +#include + #include #include "fio.h" @@ -84,17 +85,17 @@ uint64_t usec_sleep(struct thread_data *td, unsigned long usec) return t; } -uint64_t time_since_genesis(void) +uint64_t time_since_genesis() { return time_since_now(&genesis); } -uint64_t mtime_since_genesis(void) +uint64_t mtime_since_genesis() { return mtime_since_now(&genesis); } -uint64_t utime_since_genesis(void) +uint64_t utime_since_genesis() { return utime_since_now(&genesis); } @@ -142,7 +143,7 @@ bool ramp_time_over(struct thread_data *td) return false; } -void fio_time_init(void) +void fio_time_init() { int i; @@ -167,7 +168,7 @@ void fio_time_init(void) } } -void set_genesis_time(void) +void set_genesis_time() { fio_gettime(&genesis, NULL); } diff --git a/trim.c b/trim.cpp similarity index 97% rename from trim.c rename to trim.cpp index bf825db346..cacd36bafe 100644 --- a/trim.c +++ b/trim.cpp @@ -1,8 +1,8 @@ /* * TRIM/DISCARD support */ -#include -#include +#include +#include #include "fio.h" #include "trim.h" diff --git a/trim.h b/trim.h index fe8f9fe990..c978e24a40 100644 --- a/trim.h +++ b/trim.h @@ -1,6 +1,10 @@ #ifndef FIO_TRIM_H #define FIO_TRIM_H +#ifdef __cplusplus +extern "C" { +#endif + #ifdef FIO_HAVE_TRIM #include "flist.h" #include "iolog.h" @@ -37,4 +41,8 @@ static inline void remove_trim_entry(struct thread_data *td, struct io_piece *ip } #endif +#ifdef __cplusplus +} +#endif + #endif diff --git a/verify-state.h b/verify-state.h index 6da1585b24..a34b8703fd 100644 --- a/verify-state.h +++ b/verify-state.h @@ -6,6 +6,10 @@ #include #include "lib/nowarn_snprintf.h" +#ifdef __cplusplus +extern "C" { +#endif + struct thread_rand32_state { uint32_t s[4]; }; @@ -106,4 +110,8 @@ static inline void verify_state_gen_name(char *out, size_t size, out[size - 1] = '\0'; } +#ifdef __cplusplus +} +#endif + #endif diff --git a/verify.c b/verify.cpp similarity index 87% rename from verify.c rename to verify.cpp index 2848b68612..f392bd2569 100644 --- a/verify.c +++ b/verify.cpp @@ -1,10 +1,11 @@ /* * IO verification helpers */ +#include +#include + #include #include -#include -#include #include #include @@ -38,7 +39,7 @@ static void __fill_hdr(struct thread_data *td, struct io_u *io_u, void fill_buffer_pattern(struct thread_data *td, void *p, unsigned int len) { - (void)cpy_pattern(td->o.buffer_pattern, td->o.buffer_pattern_bytes, p, len); + (void)cpy_pattern(td->o.buffer_pattern, td->o.buffer_pattern_bytes, static_cast(p), len); } static void __fill_buffer(struct thread_options *o, uint64_t seed, void *p, @@ -75,7 +76,7 @@ void fill_verify_pattern(struct thread_data *td, void *p, unsigned int len, (void)paste_format(td->o.verify_pattern, td->o.verify_pattern_bytes, td->o.verify_fmt, td->o.verify_fmt_sz, - p, len, io_u); + static_cast(p), len, io_u); io_u->buf_filled_len = len; } @@ -100,14 +101,13 @@ static void fill_pattern_headers(struct thread_data *td, struct io_u *io_u, { unsigned int hdr_inc, header_num; struct verify_header *hdr; - void *p = io_u->buf; - fill_verify_pattern(td, p, io_u->buflen, io_u, seed, use_seed); + fill_verify_pattern(td, io_u->buf, io_u->buflen, io_u, seed, use_seed); hdr_inc = get_hdr_inc(td, io_u); header_num = 0; - for (; p < io_u->buf + io_u->buflen; p += hdr_inc) { - hdr = p; + for (char *p = static_cast(io_u->buf); p < static_cast(io_u->buf) + io_u->buflen; p += hdr_inc) { + hdr = reinterpret_cast(p); populate_hdr(td, io_u, hdr, header_num, hdr_inc); header_num++; } @@ -126,7 +126,7 @@ static void memswp(void *buf1, void *buf2, unsigned int len) static void hexdump(void *buffer, int len) { - unsigned char *p = buffer; + unsigned char *p = static_cast(buffer); int i; for (i = 0; i < len; i++) @@ -212,7 +212,7 @@ static void *hdr_priv(struct verify_header *hdr) { void *priv = hdr; - return priv + sizeof(struct verify_header); + return static_cast(priv) + sizeof(struct verify_header); } /* @@ -302,7 +302,7 @@ static void __dump_verify_buffers(struct verify_header *hdr, struct vcont *vc) */ hdr_offset = vc->hdr_num * hdr->len; - dump_buf(io_u->buf + hdr_offset, hdr->len, io_u->verify_offset + hdr_offset, + dump_buf(static_cast(io_u->buf) + hdr_offset, hdr->len, io_u->verify_offset + hdr_offset, "received", vc->io_u->file); /* @@ -317,7 +317,7 @@ static void __dump_verify_buffers(struct verify_header *hdr, struct vcont *vc) fill_pattern_headers(td, &dummy, hdr->rand_seed, 1); - dump_buf(buf + hdr_offset, hdr->len, io_u->verify_offset + hdr_offset, + dump_buf(static_cast(buf) + hdr_offset, hdr->len, io_u->verify_offset + hdr_offset, "expected", vc->io_u->file); free(buf); } @@ -361,7 +361,7 @@ static void log_verify_failure(struct verify_header *hdr, struct vcont *vc) */ static inline void *io_u_verify_off(struct verify_header *hdr, struct vcont *vc) { - return vc->io_u->buf + vc->hdr_num * hdr->len + hdr_size(vc->td, hdr); + return static_cast(vc->io_u->buf) + vc->hdr_num * hdr->len + hdr_size(vc->td, hdr); } static int verify_io_u_pattern(struct verify_header *hdr, struct vcont *vc) @@ -416,7 +416,7 @@ static int verify_io_u_pattern(struct verify_header *hdr, struct vcont *vc) static int verify_io_u_xxhash(struct verify_header *hdr, struct vcont *vc) { void *p = io_u_verify_off(hdr, vc); - struct vhdr_xxhash *vh = hdr_priv(hdr); + struct vhdr_xxhash *vh = static_cast(hdr_priv(hdr)); uint32_t hash; void *state; @@ -445,7 +445,7 @@ static int verify_io_u_sha3(struct verify_header *hdr, struct vcont *vc, dprint(FD_VERIFY, "%s verify io_u %p, len %u\n", name, vc->io_u, hdr->len); - fio_sha3_update(sha3_ctx, p, hdr->len - hdr_size(vc->td, hdr)); + fio_sha3_update(sha3_ctx, static_cast(p), hdr->len - hdr_size(vc->td, hdr)); fio_sha3_final(sha3_ctx); if (!memcmp(sha, sha3_ctx->sha, sha_size)) @@ -461,7 +461,7 @@ static int verify_io_u_sha3(struct verify_header *hdr, struct vcont *vc, static int verify_io_u_sha3_224(struct verify_header *hdr, struct vcont *vc) { - struct vhdr_sha3_224 *vh = hdr_priv(hdr); + struct vhdr_sha3_224 *vh = static_cast(hdr_priv(hdr)); uint8_t sha[SHA3_224_DIGEST_SIZE]; struct fio_sha3_ctx sha3_ctx = { .sha = sha, @@ -475,7 +475,7 @@ static int verify_io_u_sha3_224(struct verify_header *hdr, struct vcont *vc) static int verify_io_u_sha3_256(struct verify_header *hdr, struct vcont *vc) { - struct vhdr_sha3_256 *vh = hdr_priv(hdr); + struct vhdr_sha3_256 *vh = static_cast(hdr_priv(hdr)); uint8_t sha[SHA3_256_DIGEST_SIZE]; struct fio_sha3_ctx sha3_ctx = { .sha = sha, @@ -489,7 +489,7 @@ static int verify_io_u_sha3_256(struct verify_header *hdr, struct vcont *vc) static int verify_io_u_sha3_384(struct verify_header *hdr, struct vcont *vc) { - struct vhdr_sha3_384 *vh = hdr_priv(hdr); + struct vhdr_sha3_384 *vh = static_cast(hdr_priv(hdr)); uint8_t sha[SHA3_384_DIGEST_SIZE]; struct fio_sha3_ctx sha3_ctx = { .sha = sha, @@ -503,7 +503,7 @@ static int verify_io_u_sha3_384(struct verify_header *hdr, struct vcont *vc) static int verify_io_u_sha3_512(struct verify_header *hdr, struct vcont *vc) { - struct vhdr_sha3_512 *vh = hdr_priv(hdr); + struct vhdr_sha3_512 *vh = static_cast(hdr_priv(hdr)); uint8_t sha[SHA3_512_DIGEST_SIZE]; struct fio_sha3_ctx sha3_ctx = { .sha = sha, @@ -518,7 +518,7 @@ static int verify_io_u_sha3_512(struct verify_header *hdr, struct vcont *vc) static int verify_io_u_sha512(struct verify_header *hdr, struct vcont *vc) { void *p = io_u_verify_off(hdr, vc); - struct vhdr_sha512 *vh = hdr_priv(hdr); + struct vhdr_sha512 *vh = static_cast(hdr_priv(hdr)); uint8_t sha512[128]; struct fio_sha512_ctx sha512_ctx = { .buf = sha512, @@ -527,7 +527,7 @@ static int verify_io_u_sha512(struct verify_header *hdr, struct vcont *vc) dprint(FD_VERIFY, "sha512 verify io_u %p, len %u\n", vc->io_u, hdr->len); fio_sha512_init(&sha512_ctx); - fio_sha512_update(&sha512_ctx, p, hdr->len - hdr_size(vc->td, hdr)); + fio_sha512_update(&sha512_ctx, static_cast(p), hdr->len - hdr_size(vc->td, hdr)); if (!memcmp(vh->sha512, sha512_ctx.buf, sizeof(sha512))) return 0; @@ -543,7 +543,7 @@ static int verify_io_u_sha512(struct verify_header *hdr, struct vcont *vc) static int verify_io_u_sha256(struct verify_header *hdr, struct vcont *vc) { void *p = io_u_verify_off(hdr, vc); - struct vhdr_sha256 *vh = hdr_priv(hdr); + struct vhdr_sha256 *vh = static_cast(hdr_priv(hdr)); uint8_t sha256[64]; struct fio_sha256_ctx sha256_ctx = { .buf = sha256, @@ -552,7 +552,7 @@ static int verify_io_u_sha256(struct verify_header *hdr, struct vcont *vc) dprint(FD_VERIFY, "sha256 verify io_u %p, len %u\n", vc->io_u, hdr->len); fio_sha256_init(&sha256_ctx); - fio_sha256_update(&sha256_ctx, p, hdr->len - hdr_size(vc->td, hdr)); + fio_sha256_update(&sha256_ctx, static_cast(p), hdr->len - hdr_size(vc->td, hdr)); fio_sha256_final(&sha256_ctx); if (!memcmp(vh->sha256, sha256_ctx.buf, sizeof(sha256))) @@ -569,7 +569,7 @@ static int verify_io_u_sha256(struct verify_header *hdr, struct vcont *vc) static int verify_io_u_sha1(struct verify_header *hdr, struct vcont *vc) { void *p = io_u_verify_off(hdr, vc); - struct vhdr_sha1 *vh = hdr_priv(hdr); + struct vhdr_sha1 *vh = static_cast(hdr_priv(hdr)); uint32_t sha1[5]; struct fio_sha1_ctx sha1_ctx = { .H = sha1, @@ -595,12 +595,12 @@ static int verify_io_u_sha1(struct verify_header *hdr, struct vcont *vc) static int verify_io_u_crc7(struct verify_header *hdr, struct vcont *vc) { void *p = io_u_verify_off(hdr, vc); - struct vhdr_crc7 *vh = hdr_priv(hdr); + struct vhdr_crc7 *vh = static_cast(hdr_priv(hdr)); unsigned char c; dprint(FD_VERIFY, "crc7 verify io_u %p, len %u\n", vc->io_u, hdr->len); - c = fio_crc7(p, hdr->len - hdr_size(vc->td, hdr)); + c = fio_crc7(static_cast(p), hdr->len - hdr_size(vc->td, hdr)); if (c == vh->crc7) return 0; @@ -616,7 +616,7 @@ static int verify_io_u_crc7(struct verify_header *hdr, struct vcont *vc) static int verify_io_u_crc16(struct verify_header *hdr, struct vcont *vc) { void *p = io_u_verify_off(hdr, vc); - struct vhdr_crc16 *vh = hdr_priv(hdr); + struct vhdr_crc16 *vh = static_cast(hdr_priv(hdr)); unsigned short c; dprint(FD_VERIFY, "crc16 verify io_u %p, len %u\n", vc->io_u, hdr->len); @@ -637,12 +637,12 @@ static int verify_io_u_crc16(struct verify_header *hdr, struct vcont *vc) static int verify_io_u_crc64(struct verify_header *hdr, struct vcont *vc) { void *p = io_u_verify_off(hdr, vc); - struct vhdr_crc64 *vh = hdr_priv(hdr); + struct vhdr_crc64 *vh = static_cast(hdr_priv(hdr)); unsigned long long c; dprint(FD_VERIFY, "crc64 verify io_u %p, len %u\n", vc->io_u, hdr->len); - c = fio_crc64(p, hdr->len - hdr_size(vc->td, hdr)); + c = fio_crc64(static_cast(p), hdr->len - hdr_size(vc->td, hdr)); if (c == vh->crc64) return 0; @@ -658,7 +658,7 @@ static int verify_io_u_crc64(struct verify_header *hdr, struct vcont *vc) static int verify_io_u_crc32(struct verify_header *hdr, struct vcont *vc) { void *p = io_u_verify_off(hdr, vc); - struct vhdr_crc32 *vh = hdr_priv(hdr); + struct vhdr_crc32 *vh = static_cast(hdr_priv(hdr)); uint32_t c; dprint(FD_VERIFY, "crc32 verify io_u %p, len %u\n", vc->io_u, hdr->len); @@ -679,12 +679,12 @@ static int verify_io_u_crc32(struct verify_header *hdr, struct vcont *vc) static int verify_io_u_crc32c(struct verify_header *hdr, struct vcont *vc) { void *p = io_u_verify_off(hdr, vc); - struct vhdr_crc32 *vh = hdr_priv(hdr); + struct vhdr_crc32 *vh = static_cast(hdr_priv(hdr)); uint32_t c; dprint(FD_VERIFY, "crc32c verify io_u %p, len %u\n", vc->io_u, hdr->len); - c = fio_crc32c(p, hdr->len - hdr_size(vc->td, hdr)); + c = fio_crc32c(static_cast(p), hdr->len - hdr_size(vc->td, hdr)); if (c == vh->crc32) return 0; @@ -700,7 +700,7 @@ static int verify_io_u_crc32c(struct verify_header *hdr, struct vcont *vc) static int verify_io_u_md5(struct verify_header *hdr, struct vcont *vc) { void *p = io_u_verify_off(hdr, vc); - struct vhdr_md5 *vh = hdr_priv(hdr); + struct vhdr_md5 *vh = static_cast(hdr_priv(hdr)); uint32_t hash[MD5_HASH_WORDS]; struct fio_md5_ctx md5_ctx = { .hash = hash, @@ -709,7 +709,7 @@ static int verify_io_u_md5(struct verify_header *hdr, struct vcont *vc) dprint(FD_VERIFY, "md5 verify io_u %p, len %u\n", vc->io_u, hdr->len); fio_md5_init(&md5_ctx); - fio_md5_update(&md5_ctx, p, hdr->len - hdr_size(vc->td, hdr)); + fio_md5_update(&md5_ctx, static_cast(p), hdr->len - hdr_size(vc->td, hdr)); fio_md5_final(&md5_ctx); if (!memcmp(vh->md5_digest, md5_ctx.hash, sizeof(hash))) @@ -754,7 +754,7 @@ int verify_io_u_async(struct thread_data *td, struct io_u **io_u_ptr) */ static int mem_is_zero(const void *data, size_t length) { - const unsigned char *p = data; + const unsigned char *p = static_cast(data); size_t len; /* Check first 16 bytes manually */ @@ -773,7 +773,7 @@ static int mem_is_zero(const void *data, size_t length) static int mem_is_zero_slow(const void *data, size_t length, size_t *offset) { - const unsigned char *p = data; + const unsigned char *p = static_cast(data); *offset = 0; while (length) { @@ -824,13 +824,13 @@ static int verify_header(struct io_u *io_u, struct thread_data *td, goto err; } if (hdr->rand_seed != io_u->rand_seed) { - log_err("verify: bad header rand_seed %"PRIu64 - ", wanted %"PRIu64, + log_err("verify: bad header rand_seed %" PRIu64 + ", wanted %" PRIu64, hdr->rand_seed, io_u->rand_seed); goto err; } if (hdr->offset != io_u->verify_offset + hdr_num * td->o.verify_interval) { - log_err("verify: bad header offset %"PRIu64 + log_err("verify: bad header offset %" PRIu64 ", wanted %llu", hdr->offset, io_u->verify_offset); goto err; @@ -846,13 +846,13 @@ static int verify_header(struct io_u *io_u, struct thread_data *td, !td->o.time_based) if (!td->o.verify_only) if (hdr->numberio != io_u->numberio) { - log_err("verify: bad header numberio %"PRIu16 - ", wanted %"PRIu16, + log_err("verify: bad header numberio %" PRIu16 + ", wanted %" PRIu16, hdr->numberio, io_u->numberio); goto err; } - crc = fio_crc32c(p, offsetof(struct verify_header, crc32)); + crc = fio_crc32c(static_cast(p), offsetof(struct verify_header, crc32)); if (crc != hdr->crc32) { log_err("verify: bad header crc %x, calculated %x", hdr->crc32, crc); @@ -868,7 +868,7 @@ static int verify_header(struct io_u *io_u, struct thread_data *td, io_u->verify_offset, io_u->buflen); if (td->o.verify_dump) - dump_buf(p, hdr_len, io_u->verify_offset + hdr_num * hdr_len, + dump_buf(static_cast(p), hdr_len, io_u->verify_offset + hdr_num * hdr_len, "hdr_fail", io_u->file); return EILSEQ; @@ -879,7 +879,6 @@ int verify_io_u(struct thread_data *td, struct io_u **io_u_ptr) struct verify_header *hdr; struct io_u *io_u = *io_u_ptr; unsigned int header_size, hdr_inc, hdr_num = 0; - void *p; int ret; if (td->o.verify == VERIFY_NULL || io_u->ddir != DDIR_READ) @@ -899,7 +898,7 @@ int verify_io_u(struct thread_data *td, struct io_u **io_u_ptr) hdr_inc = get_hdr_inc(td, io_u); ret = 0; - for (p = io_u->buf; p < io_u->buf + io_u->buflen; + for (auto *p = static_cast(io_u->buf); p < static_cast(io_u->buf) + io_u->buflen; p += hdr_inc, hdr_num++) { struct vcont vc = { .io_u = io_u, @@ -914,7 +913,7 @@ int verify_io_u(struct thread_data *td, struct io_u **io_u_ptr) header_size = __hdr_size(td->o.verify); if (td->o.verify_offset) memswp(p, p + td->o.verify_offset, header_size); - hdr = p; + hdr = reinterpret_cast(p); /* * Make rand_seed check pass when have verify_backlog or @@ -1008,7 +1007,7 @@ int verify_io_u(struct thread_data *td, struct io_u **io_u_ptr) static void fill_xxhash(struct verify_header *hdr, void *p, unsigned int len) { - struct vhdr_xxhash *vh = hdr_priv(hdr); + struct vhdr_xxhash *vh = static_cast(hdr_priv(hdr)); void *state; state = XXH32_init(1); @@ -1018,13 +1017,13 @@ static void fill_xxhash(struct verify_header *hdr, void *p, unsigned int len) static void fill_sha3(struct fio_sha3_ctx *sha3_ctx, void *p, unsigned int len) { - fio_sha3_update(sha3_ctx, p, len); + fio_sha3_update(sha3_ctx, static_cast(p), len); fio_sha3_final(sha3_ctx); } static void fill_sha3_224(struct verify_header *hdr, void *p, unsigned int len) { - struct vhdr_sha3_224 *vh = hdr_priv(hdr); + struct vhdr_sha3_224 *vh = static_cast(hdr_priv(hdr)); struct fio_sha3_ctx sha3_ctx = { .sha = vh->sha, }; @@ -1035,7 +1034,7 @@ static void fill_sha3_224(struct verify_header *hdr, void *p, unsigned int len) static void fill_sha3_256(struct verify_header *hdr, void *p, unsigned int len) { - struct vhdr_sha3_256 *vh = hdr_priv(hdr); + struct vhdr_sha3_256 *vh = static_cast(hdr_priv(hdr)); struct fio_sha3_ctx sha3_ctx = { .sha = vh->sha, }; @@ -1046,7 +1045,7 @@ static void fill_sha3_256(struct verify_header *hdr, void *p, unsigned int len) static void fill_sha3_384(struct verify_header *hdr, void *p, unsigned int len) { - struct vhdr_sha3_384 *vh = hdr_priv(hdr); + struct vhdr_sha3_384 *vh = static_cast(hdr_priv(hdr)); struct fio_sha3_ctx sha3_ctx = { .sha = vh->sha, }; @@ -1057,7 +1056,7 @@ static void fill_sha3_384(struct verify_header *hdr, void *p, unsigned int len) static void fill_sha3_512(struct verify_header *hdr, void *p, unsigned int len) { - struct vhdr_sha3_512 *vh = hdr_priv(hdr); + struct vhdr_sha3_512 *vh = static_cast(hdr_priv(hdr)); struct fio_sha3_ctx sha3_ctx = { .sha = vh->sha, }; @@ -1068,30 +1067,30 @@ static void fill_sha3_512(struct verify_header *hdr, void *p, unsigned int len) static void fill_sha512(struct verify_header *hdr, void *p, unsigned int len) { - struct vhdr_sha512 *vh = hdr_priv(hdr); + struct vhdr_sha512 *vh = static_cast(hdr_priv(hdr)); struct fio_sha512_ctx sha512_ctx = { .buf = vh->sha512, }; fio_sha512_init(&sha512_ctx); - fio_sha512_update(&sha512_ctx, p, len); + fio_sha512_update(&sha512_ctx, static_cast(p), len); } static void fill_sha256(struct verify_header *hdr, void *p, unsigned int len) { - struct vhdr_sha256 *vh = hdr_priv(hdr); + struct vhdr_sha256 *vh = static_cast(hdr_priv(hdr)); struct fio_sha256_ctx sha256_ctx = { .buf = vh->sha256, }; fio_sha256_init(&sha256_ctx); - fio_sha256_update(&sha256_ctx, p, len); + fio_sha256_update(&sha256_ctx, static_cast(p), len); fio_sha256_final(&sha256_ctx); } static void fill_sha1(struct verify_header *hdr, void *p, unsigned int len) { - struct vhdr_sha1 *vh = hdr_priv(hdr); + struct vhdr_sha1 *vh = static_cast(hdr_priv(hdr)); struct fio_sha1_ctx sha1_ctx = { .H = vh->sha1, }; @@ -1103,48 +1102,48 @@ static void fill_sha1(struct verify_header *hdr, void *p, unsigned int len) static void fill_crc7(struct verify_header *hdr, void *p, unsigned int len) { - struct vhdr_crc7 *vh = hdr_priv(hdr); + struct vhdr_crc7 *vh = static_cast(hdr_priv(hdr)); - vh->crc7 = fio_crc7(p, len); + vh->crc7 = fio_crc7(static_cast(p), len); } static void fill_crc16(struct verify_header *hdr, void *p, unsigned int len) { - struct vhdr_crc16 *vh = hdr_priv(hdr); + struct vhdr_crc16 *vh = static_cast(hdr_priv(hdr)); vh->crc16 = fio_crc16(p, len); } static void fill_crc32(struct verify_header *hdr, void *p, unsigned int len) { - struct vhdr_crc32 *vh = hdr_priv(hdr); + struct vhdr_crc32 *vh = static_cast(hdr_priv(hdr)); vh->crc32 = fio_crc32(p, len); } static void fill_crc32c(struct verify_header *hdr, void *p, unsigned int len) { - struct vhdr_crc32 *vh = hdr_priv(hdr); + struct vhdr_crc32 *vh = static_cast(hdr_priv(hdr)); - vh->crc32 = fio_crc32c(p, len); + vh->crc32 = fio_crc32c(static_cast(p), len); } static void fill_crc64(struct verify_header *hdr, void *p, unsigned int len) { - struct vhdr_crc64 *vh = hdr_priv(hdr); + struct vhdr_crc64 *vh = static_cast(hdr_priv(hdr)); - vh->crc64 = fio_crc64(p, len); + vh->crc64 = fio_crc64(static_cast(p), len); } static void fill_md5(struct verify_header *hdr, void *p, unsigned int len) { - struct vhdr_md5 *vh = hdr_priv(hdr); + struct vhdr_md5 *vh = static_cast(hdr_priv(hdr)); struct fio_md5_ctx md5_ctx = { .hash = (uint32_t *) vh->md5_digest, }; fio_md5_init(&md5_ctx); - fio_md5_update(&md5_ctx, p, len); + fio_md5_update(&md5_ctx, static_cast(p), len); fio_md5_final(&md5_ctx); } @@ -1163,7 +1162,7 @@ static void __fill_hdr(struct thread_data *td, struct io_u *io_u, hdr->time_nsec = io_u->start_time.tv_nsec; hdr->thread = td->thread_number; hdr->numberio = io_u->numberio; - hdr->crc32 = fio_crc32c(p, offsetof(struct verify_header, crc32)); + hdr->crc32 = fio_crc32c(static_cast(p), offsetof(struct verify_header, crc32)); } @@ -1310,7 +1309,7 @@ int get_next_verify(struct thread_data *td, struct io_u *io_u) /* * Ensure that the associated IO has completed */ - if (atomic_load_acquire(&ipo->flags) & IP_F_IN_FLIGHT) + if (__atomic_load_n(&ipo->flags, __ATOMIC_ACQUIRE) & IP_F_IN_FLIGHT) goto nothing; rb_erase(n, &td->io_hist_tree); @@ -1322,7 +1321,7 @@ int get_next_verify(struct thread_data *td, struct io_u *io_u) /* * Ensure that the associated IO has completed */ - if (atomic_load_acquire(&ipo->flags) & IP_F_IN_FLIGHT) + if (__atomic_load_n(&ipo->flags, __ATOMIC_ACQUIRE) & IP_F_IN_FLIGHT) goto nothing; flist_del(&ipo->list); @@ -1387,7 +1386,7 @@ void fio_verify_init(struct thread_data *td) static void *verify_async_thread(void *data) { - struct thread_data *td = data; + struct thread_data *td = static_cast(data); struct io_u *io_u; int ret = 0; @@ -1464,7 +1463,7 @@ int verify_async_init(struct thread_data *td) td->verify_thread_exit = 0; - td->verify_threads = malloc(sizeof(pthread_t) * td->o.verify_async); + td->verify_threads = static_castverify_threads)>(malloc(sizeof(pthread_t) * td->o.verify_async)); for (i = 0; i < td->o.verify_async; i++) { ret = pthread_create(&td->verify_threads[i], &attr, verify_async_thread, td); @@ -1514,7 +1513,7 @@ void verify_async_exit(struct thread_data *td) int paste_blockoff(char *buf, unsigned int len, void *priv) { - struct io_u *io = priv; + struct io_u *io = static_cast(priv); unsigned long long off; typecheck(__typeof__(off), io->offset); @@ -1572,7 +1571,7 @@ struct all_io_list *get_all_io_list(int save_mask, size_t *sz) void *next; int nr; - compiletime_assert(sizeof(struct all_io_list) == 8, "all_io_list"); + static_assert(sizeof(struct all_io_list) == 8, "all_io_list"); /* * Calculate reply space needed. We need one 'io_state' per thread, @@ -1595,13 +1594,13 @@ struct all_io_list *get_all_io_list(int save_mask, size_t *sz) *sz = sizeof(*rep); *sz += nr * sizeof(struct thread_io_list); *sz += depth * sizeof(struct file_comp); - rep = calloc(1, *sz); + rep = static_cast(calloc(1, *sz)); rep->threads = cpu_to_le64((uint64_t) nr); next = &rep->state[0]; for_each_td(td) { - struct thread_io_list *s = next; + struct thread_io_list *s = static_cast(next); unsigned int comps, index = 0; if (save_mask != IO_LIST_ALL && (__td_index + 1) != save_mask) @@ -1672,7 +1671,7 @@ static int write_thread_list_state(struct thread_io_list *s, if (fd == -1) return 1; - crc = fio_crc32c((void *)s, thread_io_list_sz(s)); + crc = fio_crc32c(reinterpret_cast(s), thread_io_list_sz(s)); hdr.version = cpu_to_le64((uint64_t) VSTATE_HDR_VERSION); hdr.size = cpu_to_le64((uint64_t) thread_io_list_sz(s)); @@ -1733,7 +1732,7 @@ void verify_free_state(struct thread_data *td) void verify_assign_state(struct thread_data *td, void *p) { - struct thread_io_list *s = p; + struct thread_io_list *s = static_cast(p); int i; s->no_comps = le64_to_cpu(s->no_comps); @@ -1755,7 +1754,7 @@ void verify_assign_state(struct thread_data *td, void *p) s->comps[i].offset = le64_to_cpu(s->comps[i].offset); } - td->vstate = p; + td->vstate = static_castvstate)>(p); } int verify_state_hdr(struct verify_state_hdr *hdr, struct thread_io_list *s) @@ -1769,7 +1768,7 @@ int verify_state_hdr(struct verify_state_hdr *hdr, struct thread_io_list *s) if (hdr->version != VSTATE_HDR_VERSION) return 1; - crc = fio_crc32c((void *)s, hdr->size); + crc = fio_crc32c(reinterpret_cast(s), hdr->size); if (crc != hdr->crc) return 1; @@ -1818,7 +1817,7 @@ int verify_load_state(struct thread_data *td, const char *prefix) goto err; } - crc = fio_crc32c(s, hdr.size); + crc = fio_crc32c(reinterpret_cast(s), hdr.size); if (crc != hdr.crc) { log_err("fio: verify state is corrupt\n"); goto err; diff --git a/verify.h b/verify.h index 539e6f6cf5..27618a45a9 100644 --- a/verify.h +++ b/verify.h @@ -5,6 +5,10 @@ #include "compiler/compiler.h" #include "verify-state.h" +#ifdef __cplusplus +extern "C" { +#endif + #define FIO_HDR_MAGIC 0xacca enum { @@ -112,4 +116,8 @@ extern void verify_async_exit(struct thread_data *); */ extern int paste_blockoff(char *buf, unsigned int len, void *priv); +#ifdef __cplusplus +} +#endif + #endif diff --git a/workqueue.c b/workqueue.cpp similarity index 97% rename from workqueue.c rename to workqueue.cpp index 9e6c41ff2f..a77daa3ca7 100644 --- a/workqueue.c +++ b/workqueue.cpp @@ -128,7 +128,7 @@ static void handle_list(struct submit_worker *sw, struct flist_head *list) static void *worker_thread(void *data) { - struct submit_worker *sw = data; + struct submit_worker *sw = static_cast(data); struct workqueue *wq = sw->wq; unsigned int ret = 0; FLIST_HEAD(local_list); @@ -324,7 +324,7 @@ int workqueue_init(struct thread_data *td, struct workqueue *wq, if (ret) goto err; - wq->workers = smalloc(wq->max_workers * sizeof(struct submit_worker)); + wq->workers = static_castworkers)>(smalloc(wq->max_workers * sizeof(struct submit_worker))); if (!wq->workers) goto err; diff --git a/workqueue.h b/workqueue.h index 0a62b5f7d3..2d8ba58c89 100644 --- a/workqueue.h +++ b/workqueue.h @@ -7,6 +7,10 @@ #include "flist.h" #include "lib/types.h" +#ifdef __cplusplus +extern "C" { +#endif + struct sk_out; struct thread_data; @@ -116,4 +120,9 @@ static inline void workqueue_exit_worker(struct submit_worker *sw, wq->ops.exit_worker_fn(sw, sum_cnt); } + +#ifdef __cplusplus +} +#endif + #endif diff --git a/zbd.c b/zbd.cpp similarity index 96% rename from zbd.c rename to zbd.cpp index caac68bb37..32e4b7ebb8 100644 --- a/zbd.c +++ b/zbd.cpp @@ -4,9 +4,11 @@ * This file is released under the GPL. */ -#include -#include -#include +#include +#include +#include +#include + #include #include #include @@ -211,11 +213,11 @@ static int zbd_report_zones(struct thread_data *td, struct fio_file *f, ret = blkzoned_report_zones(td, f, offset, zones, nr_zones); if (ret < 0) { td_verror(td, errno, "report zones failed"); - log_err("%s: report zones from sector %"PRIu64" failed (nr_zones=%d; errno=%d).\n", + log_err("%s: report zones from sector %" PRIu64 " failed (nr_zones=%d; errno=%d).\n", f->file_name, offset >> 9, nr_zones, errno); } else if (ret == 0) { td_verror(td, errno, "Empty zone report"); - log_err("%s: report zones from sector %"PRIu64" is empty.\n", + log_err("%s: report zones from sector %" PRIu64 " is empty.\n", f->file_name, offset >> 9); ret = -EIO; } @@ -244,7 +246,7 @@ static int zbd_reset_wp(struct thread_data *td, struct fio_file *f, ret = blkzoned_reset_wp(td, f, offset, length); if (ret < 0) { td_verror(td, errno, "resetting wp failed"); - log_err("%s: resetting wp for %"PRIu64" sectors at sector %"PRIu64" failed (%d).\n", + log_err("%s: resetting wp for %" PRIu64 " sectors at sector %" PRIu64 " failed (%d).\n", f->file_name, length >> 9, offset >> 9, errno); } @@ -392,7 +394,7 @@ static int zbd_finish_zone(struct thread_data *td, struct fio_file *f, if (ret < 0) { td_verror(td, errno, "finish zone failed"); - log_err("%s: finish zone at sector %"PRIu64" failed (%d).\n", + log_err("%s: finish zone at sector %" PRIu64 " failed (%d).\n", f->file_name, offset >> 9, errno); } else { z->wp = (z+1)->start; @@ -597,7 +599,7 @@ static bool zbd_write_zone_get(struct thread_data *td, const struct fio_file *f, } /* Verify whether direct I/O is used for all host-managed zoned block drives. */ -static bool zbd_using_direct_io(void) +static bool zbd_using_direct_io() { struct fio_file *f; int j; @@ -661,7 +663,7 @@ static bool zbd_zone_align_file_sizes(struct thread_data *td, return false; } } else if (td->o.zone_size != f->zbd_info->zone_size) { - log_err("%s: zonesize %llu does not match the device zone size %"PRIu64".\n", + log_err("%s: zonesize %llu does not match the device zone size %" PRIu64 ".\n", f->file_name, td->o.zone_size, f->zbd_info->zone_size); return false; @@ -683,7 +685,7 @@ static bool zbd_zone_align_file_sizes(struct thread_data *td, f->file_name); return false; } - log_info("%s: rounded up offset from %"PRIu64" to %"PRIu64"\n", + log_info("%s: rounded up offset from %" PRIu64 " to %" PRIu64 "\n", f->file_name, f->file_offset, new_offset); f->io_size -= (new_offset - f->file_offset); @@ -699,7 +701,7 @@ static bool zbd_zone_align_file_sizes(struct thread_data *td, f->file_name); return false; } - log_info("%s: rounded down io_size from %"PRIu64" to %"PRIu64"\n", + log_info("%s: rounded down io_size from %" PRIu64 " to %" PRIu64 "\n", f->file_name, f->io_size, new_end - f->file_offset); f->io_size = new_end - f->file_offset; @@ -711,7 +713,7 @@ static bool zbd_zone_align_file_sizes(struct thread_data *td, /* * Verify whether offset and size parameters are aligned with zone boundaries. */ -static bool zbd_verify_sizes(void) +static bool zbd_verify_sizes() { struct fio_file *f; int j; @@ -726,7 +728,7 @@ static bool zbd_verify_sizes(void) return true; } -static bool zbd_verify_bs(void) +static bool zbd_verify_bs() { struct fio_file *f; int j; @@ -746,7 +748,7 @@ static bool zbd_verify_bs(void) zone_size = f->zbd_info->zone_size; if (td_trim(td) && td->o.bs[DDIR_TRIM] != zone_size) { - log_info("%s: trim block size %llu is not the zone size %"PRIu64"\n", + log_info("%s: trim block size %llu is not the zone size %" PRIu64 "\n", f->file_name, td->o.bs[DDIR_TRIM], zone_size); return false; @@ -802,14 +804,14 @@ static int init_zone_info(struct thread_data *td, struct fio_file *f) } if (f->real_file_size < zone_size) { - log_err("%s: file/device size %"PRIu64" is smaller than zone size %"PRIu64"\n", + log_err("%s: file/device size %" PRIu64 " is smaller than zone size %" PRIu64 "\n", f->file_name, f->real_file_size, zone_size); return -EINVAL; } nr_zones = (f->real_file_size + zone_size - 1) / zone_size; - zbd_info = scalloc(1, sizeof(*zbd_info) + - (nr_zones + 1) * sizeof(zbd_info->zone_info[0])); + zbd_info = static_cast(scalloc(1, sizeof(*zbd_info) + + (nr_zones + 1) * sizeof(zbd_info->zone_info[0]))); if (!zbd_info) return -ENOMEM; @@ -856,7 +858,7 @@ static int parse_zone_info(struct thread_data *td, struct fio_file *f) struct zoned_block_device_info *zbd_info = NULL; int i, j, ret = -ENOMEM; - zones = calloc(ZBD_REPORT_MAX_ZONES, sizeof(struct zbd_zone)); + zones = static_cast(calloc(ZBD_REPORT_MAX_ZONES, sizeof(struct zbd_zone))); if (!zones) goto out; @@ -875,17 +877,17 @@ static int parse_zone_info(struct thread_data *td, struct fio_file *f) if (td->o.zone_size == 0) { td->o.zone_size = zone_size; } else if (td->o.zone_size != zone_size) { - log_err("fio: %s job parameter zonesize %llu does not match disk zone size %"PRIu64".\n", + log_err("fio: %s job parameter zonesize %llu does not match disk zone size %" PRIu64 ".\n", f->file_name, td->o.zone_size, zone_size); ret = -EINVAL; goto out; } - dprint(FD_ZBD, "Device %s has %d zones of size %"PRIu64" KB\n", + dprint(FD_ZBD, "Device %s has %d zones of size %" PRIu64 " KB\n", f->file_name, nr_zones, zone_size / 1024); - zbd_info = scalloc(1, sizeof(*zbd_info) + - (nr_zones + 1) * sizeof(zbd_info->zone_info[0])); + zbd_info = static_cast(scalloc(1, sizeof(*zbd_info) + + (nr_zones + 1) * sizeof(zbd_info->zone_info[0]))); if (!zbd_info) goto out; mutex_init_pshared(&zbd_info->mutex); @@ -924,7 +926,7 @@ static int parse_zone_info(struct thread_data *td, struct fio_file *f) p->cond = z->cond; if (j > 0 && p->start != p[-1].start + zone_size) { - log_info("%s: invalid zone data [%d:%d]: %"PRIu64" + %"PRIu64" != %"PRIu64"\n", + log_info("%s: invalid zone data [%d:%d]: %" PRIu64 " + %" PRIu64 " != %" PRIu64 "\n", f->file_name, j, i, p[-1].start, zone_size, p->start); ret = -EINVAL; @@ -941,7 +943,7 @@ static int parse_zone_info(struct thread_data *td, struct fio_file *f) ZBD_REPORT_MAX_ZONES)); if (nrz < 0) { ret = nrz; - log_info("fio: report zones (offset %"PRIu64") failed for %s (%d).\n", + log_info("fio: report zones (offset %" PRIu64 ") failed for %s (%d).\n", offset, f->file_name, -ret); goto out; } @@ -958,7 +960,7 @@ static int parse_zone_info(struct thread_data *td, struct fio_file *f) f->zbd_info->max_active_zones = zbd_get_max_active_zones(td, f); if (same_zone_cap) - dprint(FD_ZBD, "Zone capacity = %"PRIu64" KB\n", + dprint(FD_ZBD, "Zone capacity = %" PRIu64" KB\n", capacity / 1024); zbd_info = NULL; @@ -1014,7 +1016,7 @@ static int zbd_set_max_write_zones(struct thread_data *td, struct fio_file *f) return -EINVAL; } - dprint(FD_ZBD, "%s: using max write zones limit: %"PRIu32"\n", + dprint(FD_ZBD, "%s: using max write zones limit: %" PRIu32 "\n", f->file_name, zbd->max_write_zones); return 0; @@ -1370,7 +1372,7 @@ static uint32_t pick_random_zone_idx(const struct fio_file *f, f->zbd_info->num_write_zones / f->io_size; } -static bool any_io_in_flight(void) +static bool any_io_in_flight() { for_each_td(td) { if (td->io_u_in_flight) @@ -1650,7 +1652,7 @@ zbd_find_zone(struct thread_data *td, struct io_u *io_u, uint64_t min_bytes, } dprint(FD_ZBD, - "%s: no zone has %"PRIu64" bytes of readable data\n", + "%s: no zone has %" PRIu64 " bytes of readable data\n", f->file_name, min_bytes); return NULL; @@ -1813,7 +1815,7 @@ void setup_zbd_zone_mode(struct thread_data *td, struct io_u *io_u) f->last_pos[ddir] >= zbd_zone_capacity_end(z)) { dprint(FD_ZBD, "%s: Jump from zone capacity limit to zone end:" - " (%"PRIu64" -> %"PRIu64") for zone %u (%"PRIu64")\n", + " (%" PRIu64 " -> %" PRIu64 ") for zone %u (%" PRIu64 ")\n", f->file_name, f->last_pos[ddir], zbd_zone_end(z), zbd_zone_idx(f, z), z->capacity); td->io_skip_bytes += zbd_zone_end(z) - f->last_pos[ddir]; @@ -1924,7 +1926,7 @@ enum io_u_action zbd_adjust_block(struct thread_data *td, struct io_u *io_u) if (io_u->offset + min_bs > (zb + 1)->start) { dprint(FD_IO, - "%s: off=%llu + min_bs=%"PRIu64" > next zone %"PRIu64"\n", + "%s: off=%llu + min_bs=%" PRIu64 " > next zone %" PRIu64 "\n", f->file_name, io_u->offset, min_bs, (zb + 1)->start); io_u->offset = @@ -2024,7 +2026,7 @@ enum io_u_action zbd_adjust_block(struct thread_data *td, struct io_u *io_u) if (io_u->buflen > zbdi->zone_size) { td_verror(td, EINVAL, "I/O buflen exceeds zone size"); dprint(FD_IO, - "%s: I/O buflen %llu exceeds zone size %"PRIu64"\n", + "%s: I/O buflen %llu exceeds zone size %" PRIu64 "\n", f->file_name, io_u->buflen, zbdi->zone_size); goto eof; } @@ -2107,7 +2109,7 @@ enum io_u_action zbd_adjust_block(struct thread_data *td, struct io_u *io_u) if (zb->capacity < min_bs) { td_verror(td, EINVAL, "ZCAP is less min_bs"); - log_err("zone capacity %"PRIu64" smaller than minimum block size %"PRIu64"\n", + log_err("zone capacity %" PRIu64 " smaller than minimum block size %" PRIu64 "\n", zb->capacity, min_bs); goto eof; } @@ -2141,7 +2143,7 @@ enum io_u_action zbd_adjust_block(struct thread_data *td, struct io_u *io_u) } td_verror(td, EIO, "zone remainder too small"); - log_err("zone remainder %lld smaller than min block size %"PRIu64"\n", + log_err("zone remainder %lld smaller than min block size %" PRIu64 "\n", (zbd_zone_capacity_end(zb) - io_u->offset), min_bs); goto eof; @@ -2206,7 +2208,7 @@ char *zbd_write_status(const struct thread_stat *ts) { char *res; - if (asprintf(&res, "; %"PRIu64" zone resets", ts->nr_zone_resets) < 0) + if (asprintf(&res, "; %" PRIu64 " zone resets", ts->nr_zone_resets) < 0) return NULL; return res; } diff --git a/zbd.h b/zbd.h index 5750a0b808..1e1a5afd36 100644 --- a/zbd.h +++ b/zbd.h @@ -12,6 +12,10 @@ #include "oslib/blkzoned.h" #include "zbd_types.h" +#ifdef __cplusplus +extern "C" { +#endif + struct fio_file; enum io_u_action { @@ -131,4 +135,8 @@ static inline void zbd_put_io_u(struct thread_data *td, struct io_u *io_u) } } +#ifdef __cplusplus +} +#endif + #endif /* FIO_ZBD_H */ diff --git a/zone-dist.c b/zone-dist.cpp similarity index 80% rename from zone-dist.c rename to zone-dist.cpp index 819d531c04..da2f30f704 100644 --- a/zone-dist.c +++ b/zone-dist.cpp @@ -1,4 +1,5 @@ -#include +#include + #include "fio.h" #include "zone-dist.h" @@ -7,7 +8,7 @@ static void __td_zone_gen_index(struct thread_data *td, enum fio_ddir ddir) unsigned int i, j, sprev, aprev; uint64_t sprev_sz; - td->zone_state_index[ddir] = malloc(sizeof(struct zone_split_index) * 100); + td->zone_state_index[ddir] = static_cast(malloc(sizeof(struct zone_split_index) * 100)); sprev_sz = sprev = aprev = 0; for (i = 0; i < td->o.zone_split_nr[ddir]; i++) { @@ -50,11 +51,11 @@ void td_zone_gen_index(struct thread_data *td) if (!has_zones(td)) return; - td->zone_state_index = malloc(DDIR_RWDIR_CNT * - sizeof(struct zone_split_index *)); + td->zone_state_index = static_cast(malloc(DDIR_RWDIR_CNT * + sizeof(struct zone_split_index *))); for (i = 0; i < DDIR_RWDIR_CNT; i++) - __td_zone_gen_index(td, i); + __td_zone_gen_index(td, static_cast(i)); } void td_zone_free_index(struct thread_data *td) diff --git a/zone-dist.h b/zone-dist.h index c0b28844b4..8e5677a7e8 100644 --- a/zone-dist.h +++ b/zone-dist.h @@ -1,7 +1,15 @@ #ifndef FIO_ZONE_DIST_H #define FIO_ZONE_DIST_H +#ifdef __cplusplus +extern "C" { +#endif + void td_zone_gen_index(struct thread_data *td); void td_zone_free_index(struct thread_data *td); +#ifdef __cplusplus +} +#endif + #endif