Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
331 commits
Select commit Hold shift + click to select a range
8160e4c
hr: RAID 4,5: optimize operations with xorbuf
mcimerman Nov 27, 2024
40bf2c6
hr: allow IO requests to be served during rebuild
mcimerman Nov 27, 2024
65706f1
hr: rename dev_no -> extent_no in hr_volume_t
mcimerman Nov 27, 2024
a0c3080
hr: util: hotspare and volume change state functions
mcimerman Nov 28, 2024
586b39d
hrctl: handle unkown options
mcimerman Nov 28, 2024
d7768d1
hr: add different RAID4,5 layouts
mcimerman Dec 6, 2024
241c3f6
hr: move RAID4 to RAID5
mcimerman Dec 6, 2024
4066371
hr: layout info printing
mcimerman Dec 6, 2024
ea0d494
hr: don't set RLQ when assembling
mcimerman Dec 6, 2024
f312fb9
hr: remove RAID4 functions leftovers
mcimerman Dec 13, 2024
521b387
hr: RAID5: fix degraded write
mcimerman Dec 16, 2024
37ffa4d
hr: modify change state message
mcimerman Dec 16, 2024
2876911
hrctl: usage string modification
mcimerman Dec 16, 2024
f725787
hr: fge: fibril group executor
mcimerman Dec 22, 2024
38e3c0a
hr: range locks
mcimerman Dec 22, 2024
83c8bb2
hr: hr_volume_t: fix number of hotspares
mcimerman Dec 22, 2024
57110ac
hr: initialize range lock list and list lock
mcimerman Dec 22, 2024
95158da
hr: fge: can ask for wus that finished with EOK
mcimerman Dec 22, 2024
f3b74d1
hr: fge: use libc queue <adt/circ_buf.h>
mcimerman Dec 22, 2024
6784abc
hr: hr_sess_init(): don't use IPC_FLAG_BLOCKING
mcimerman Dec 22, 2024
37a9c1e
hr: hr_volume_t: rename RLQ -> layout
mcimerman Dec 23, 2024
8137d36
hr: fge: style
mcimerman Dec 23, 2024
eb31781
hr: raid5.c: cstyle
mcimerman Dec 24, 2024
5a8f69e
hr: fge: cstyle
mcimerman Dec 25, 2024
08c98d4
hr: fge: fix deadlock
mcimerman Dec 25, 2024
083ce33
hr: fge: hr_fpool_create(): assert max_wus > 0
mcimerman Dec 25, 2024
5ee5f67
hr: fge: make finished_{okay,failed} not atomic
mcimerman Dec 28, 2024
723f1d9
hr: fge: fgroup_create(): assert worker count > 0
mcimerman Dec 28, 2024
7a3529a
hr: util.c: bounds check on state updates
mcimerman Dec 28, 2024
685c0ab
hr: superblock.c: style
mcimerman Dec 30, 2024
7d25273
hrctl: initialize hr session struct
mcimerman Dec 30, 2024
40be7eb
lib/device/src/hr.c: session init style
mcimerman Dec 30, 2024
bc3d695
hr: RAID0 parallelization
mcimerman Jan 5, 2025
7bf29e5
Merge 'upstream/master' into helenraid-para
mcimerman Jan 9, 2025
a5c2960
hr: RAID0: pass actual block address to workers
mcimerman Jan 12, 2025
efc6259
hr: fge: aggregate ENOMEM final errno
mcimerman Jan 12, 2025
0d77d30
hr: hr_io_worker(): ENOMEM handling for WRITEs
mcimerman Jan 12, 2025
4660649
hr: RAID0: return ENOMEM on out-of-memory READs
mcimerman Jan 12, 2025
ee47537
hr: RAID0: refactor hr_raid0_update_vol_status()
mcimerman Jan 12, 2025
58d82fa
hr: parallelize RAID1
mcimerman Jan 12, 2025
5ee041e
hr: RAID1: deferred extent invalidation
mcimerman Jan 12, 2025
3a68baa
lib/device/hr: add INVALID state
mcimerman Jan 12, 2025
3666177
hr: util.c: add assertions for locks
mcimerman Jan 12, 2025
edc89bd
hr: util: add hr_update_{ext,hotspare}_svc_id()
mcimerman Jan 12, 2025
e2b417f
hr: RAID1: use update_svc_id() wrappers from util
mcimerman Jan 12, 2025
401b9e4
hr: state_changed and peding_invalidation atomic flags
mcimerman Jan 12, 2025
dec4150
hr: RAID1: fix unsafe access in add_hotspare()
mcimerman Jan 12, 2025
d773bea
hr: RAID1: handle state edge cases in a rebuild
mcimerman Jan 12, 2025
35f2a87
hr: raid1.c: move around static functions
mcimerman Jan 12, 2025
23df41b
hr: move hr_process_deferred_invalidations() to util
mcimerman Jan 13, 2025
a6fb937
hr: RAID0: handle hr_fgroup_create() -> ENOMEM
mcimerman Jan 14, 2025
9f15da1
hr: fge: fix fibril unsafe assert
mcimerman Jan 14, 2025
7debda3
hr: fge: make group->wu_cnt an upper bound
mcimerman Jan 22, 2025
d30e067
Merge 'upstream/master' into helenraid-para
mcimerman Mar 2, 2025
8cdf360
app/hrctl: fix case for 'n'
mcimerman Mar 5, 2025
0fcb011
hr: raid0.c: early break if (left == 0)
mcimerman Mar 5, 2025
b15e534
hr/fge.c: add some comments
mcimerman Mar 6, 2025
4d30c47
hr: raid1.c: fix rebuild
mcimerman Mar 6, 2025
6123753
hr: raid1.c: print rebuild progress every 5%
mcimerman Mar 6, 2025
4d42a1b
hr: remove deferred invalidations
mcimerman Mar 6, 2025
10005fd
hr: remove vol->halt_please bit and vol->halt_lock
mcimerman Mar 6, 2025
d6fe2a1
hr: hr_mark_vol_state_dirty() helper
mcimerman Mar 6, 2025
f1be66b
hr: raid5.c: fast patch to make new asserts pass
mcimerman Mar 6, 2025
d2da1be
hr: rename vol->state_changed -> vol->state_dirty
mcimerman Mar 6, 2025
e24c064
hr: add NONE state (use INVALID for inconsistent)
mcimerman Mar 7, 2025
e494d7b
hr: initialize hotspare states to MISSING
mcimerman Mar 7, 2025
eebecdc
merge upstream/master into helenraid
mcimerman Mar 13, 2025
e3e53cc
hr: var.h: remove struct hr_deferred_invalidation
mcimerman Mar 14, 2025
de81104
hr: style headers
mcimerman Mar 23, 2025
2958e70
hr: var.h: revert hotspare no. back from invalidations
mcimerman Mar 23, 2025
5fe0b9b
hr: var.h: comment cstyle
mcimerman Mar 24, 2025
a57dde4
hr: use __func__ for DEBUG printing fcn names
mcimerman Mar 28, 2025
b04f7af
hr: hr.c: add headers
mcimerman Mar 28, 2025
7bfe468
hr: hr.c: hr_client_conn() return ENOENT
mcimerman Mar 28, 2025
8b51009
hr: auto assembly, refactor
mcimerman Mar 28, 2025
0437dd5
hr: util.c: block_fini() hotspares
mcimerman Mar 28, 2025
7a80c63
hr: raid{0,1,5}.c: increment open() count
mcimerman Mar 28, 2025
8a65373
hr: move registering out of specific RAIDs
mcimerman Mar 29, 2025
5621438
hr: util: hr_util_add_hotspare()
mcimerman Mar 29, 2025
49de61c
hr: util.c: fix hr_register_volume()
mcimerman Mar 29, 2025
d946c27
hr: initialize and populate in memory metadata
mcimerman Mar 29, 2025
2e7df2e
hr: superblock.c: fix UUID memcpy()
mcimerman Mar 29, 2025
7e8c0e7
hr: superblock.c: remove UUID generation for each extent
mcimerman Mar 29, 2025
1a28518
hr: superblock.c: fix bsize decoding
mcimerman Mar 29, 2025
d082801
hr: refactor manual assembly
mcimerman Mar 29, 2025
746e636
hr: add comments to raid init()
mcimerman Mar 30, 2025
6d0fc11
hr: style: align structures, function prototypes
mcimerman Mar 30, 2025
baa4929
hr: extent init refactor, blkno truncation
mcimerman Mar 31, 2025
a5ec426
hr: superblock: move to last block
mcimerman Mar 31, 2025
0277ec2
hr: refactor metadata handling
mcimerman Apr 1, 2025
4200735
hr: fix printing extent states with invalid service id
mcimerman Apr 1, 2025
44da6c8
hr: util.c: initialize empty extents to MISSING
mcimerman Apr 1, 2025
c7e6a3e
hr: align struct hr_extent members
mcimerman Apr 1, 2025
52be5fa
hr: increment metadata counter on volume assembly
mcimerman Apr 1, 2025
bbcd06e
hr: keep counter only in memory saved metadata
mcimerman Apr 1, 2025
ca7fa5b
hr: use <inttypes.h> macro specifiers
mcimerman Apr 2, 2025
800d188
hr: metadata saving on stop
mcimerman Apr 15, 2025
29e7cc7
Merge branch 'upstream/master' into helenraid
mcimerman Apr 18, 2025
e77c3ed
hr: superblock.c,h: const quals for args
mcimerman Apr 18, 2025
6f41c21
Merge branch 'upstream/master' into helenraid-metadata-geom
mcimerman Apr 18, 2025
5060340
hr: metadata format agnostic superblock ops
mcimerman Apr 20, 2025
1439414
hr: util.c: style
mcimerman Apr 20, 2025
58c43d4
hr: util.c: matching type as well
mcimerman Apr 20, 2025
6a854c5
srv/hr/metadata/native.c: no explicit arg casting
mcimerman Apr 20, 2025
372a9fc
srv/hr/util.c: don't dump metadata
mcimerman Apr 20, 2025
d3a23c9
srv/hr/util.c: change log level LVL_WARN to LVL_NOTE
mcimerman Apr 20, 2025
f647b87
srv/bd/hr: remove unused nblocks variable
mcimerman Apr 20, 2025
afec52b
srv/bd/hr/superblock.c: fix memory leak
mcimerman Apr 20, 2025
10291a2
hr: FreeBSD GEOM::MIRROR metadata support
mcimerman Apr 20, 2025
f09b75b
hr: metadata/foreign/geom: add <sys/endian.h>
mcimerman Apr 21, 2025
18c3658
hr: raid{0,1,5}.c: unusable volume creation message
mcimerman Apr 21, 2025
80c760e
hr: remove truncated_blkno calculation from raid*.c
mcimerman Apr 21, 2025
75262d2
hr: util.c: hr_create_vol_struct() style
mcimerman Apr 21, 2025
b883aa8
hr: move metadata_type_t to lib/hr for type printing
mcimerman Apr 21, 2025
5cb1631
hr: FreeBSD GEOM::STRIPE metadata support
mcimerman Apr 21, 2025
fb06476
hr: use enum for RAID layouts
mcimerman Apr 21, 2025
c6d2af8
hr: hr.c: more specific message for unsupported hotspare
mcimerman Apr 21, 2025
a056759
hr: hr.c: style Accepting connections. message
mcimerman Apr 21, 2025
d85ee06
hr: geom g{mirror, stripe}: rename files, remove saving
mcimerman Apr 22, 2025
dd76b46
hr: metadata/native.c: use uint64_t for counter
mcimerman Apr 22, 2025
af1b25d
hr: metadata/geom/g_mirror.h: fix checksums
mcimerman Apr 22, 2025
a261634
hr: OpenBSD softraid metadata support
mcimerman Apr 23, 2025
c9ef864
hr: util.c: hr_create_vol_struct: HR_LVL_4 fallthrough
mcimerman Apr 23, 2025
59ec1c5
hr: util.c: fix possible null deref
mcimerman Apr 23, 2025
9bf95d4
hr: hr_softraid.c: remove dead code
mcimerman Apr 24, 2025
2100a4e
uspace/lib/devices/hr: add OpenBSD softraid md type
mcimerman Apr 25, 2025
40f56a4
hr: metadata/softraid: use inttypes.h specifiers
mcimerman May 2, 2025
d1d355f
hr: refactor hrctl and some hr IPC methods
mcimerman May 6, 2025
c2f0160
hr: util: add more checks for hotspare addition
mcimerman May 6, 2025
217d0fb
hrctl: add notes about failing an extent
mcimerman May 6, 2025
13c2365
hr: metadata/softraid: checksum in original endianness
mcimerman May 6, 2025
31eb568
hr: comment hr.c a bit
mcimerman May 6, 2025
ac4b70b
hr: fail only failable extents
mcimerman May 7, 2025
fc265b4
hr: IPC methods: don't create own hr_t session
mcimerman May 7, 2025
af4ecb7
hr: document lib/device/src/hr.c
mcimerman May 7, 2025
155d34f
hr: rename hr_get_*_status_msg -> hr_get_*_state_str
mcimerman May 7, 2025
56602e0
hr: rename all strings `status' -> `state'
mcimerman May 7, 2025
964e897
hrctl: handle invalid level argument
mcimerman May 7, 2025
fde8032
hrctl: correctly handle manualy specified devices
mcimerman May 7, 2025
ed41962
hr: metadata/native: fix possible deadlock
mcimerman May 7, 2025
e5ea5f8
hrctl: finalize parsing, add new sample sif config
mcimerman May 7, 2025
1cfce3f
hr: raid5.c: set default layout
mcimerman May 8, 2025
aca1777
Merge upstream into helenraid
mcimerman May 8, 2025
2f21cd4
hr: util.c: fix hotspare blkno check
mcimerman May 8, 2025
00d80c6
hr: raid5.c: REBUILD fix
mcimerman May 8, 2025
dbb1e3f
hrctl: tweak configuration files
mcimerman May 8, 2025
af73327
hr: use the term 'volume' instead of 'array'
mcimerman May 8, 2025
52e4051
hrctl: check realloc() return value
mcimerman May 9, 2025
e1ed6ec
hr: auto assembly: detect bogus label type
mcimerman May 9, 2025
7e68d61
hr: metadata/geom/stripe: don't dump in vol init
mcimerman May 9, 2025
bfe4a88
bdwrite: measure and print elapsed time
mcimerman May 10, 2025
287b2ea
hr: don't add "devices/" prefix on vol registration
mcimerman May 15, 2025
9a3eec1
hr: util: hr_get_volume_svcs()
mcimerman May 15, 2025
c9ce6d2
hr: refactor volume removal
mcimerman May 15, 2025
a2281ef
hr: print service id of created volume
mcimerman May 17, 2025
6f13257
hr: cstyle: don't align struct members and fcn decls
mcimerman May 20, 2025
c5b60e2
hr: use PRIun to print service_id_t
mcimerman May 20, 2025
49da044
hr: fge: move types to fge.h
mcimerman May 20, 2025
da80de9
hr: move state callback to hr_ops_t
mcimerman Jun 7, 2025
d482b05
hrctl: add synopsis to usage message
mcimerman Jun 9, 2025
431b513
hrctl: also parse levels as words
mcimerman Jun 9, 2025
e0bbecb
hr: move state printing to hrctl
mcimerman Jun 9, 2025
e2a8fd2
hr: try automatic assembly on server start
mcimerman Jun 9, 2025
f34568c
hr: print % done of REBUILD operation
mcimerman Jun 9, 2025
eabc094
hr: add superblock erasure op
mcimerman Jun 9, 2025
0fce1a6
hr: rename HR_RLQ_* to HR_LAYOUT_*
mcimerman Jun 9, 2025
9ee9c60
hr: raid5.c: use RAID 4 layout with RAID 4 level
mcimerman Jun 9, 2025
b5c95da
hr: raid*_{create,init}(): replace asserts with EINVAL
mcimerman Jun 9, 2025
177f6ff
hr: stop all volumes: ignore != EOK
mcimerman Jun 9, 2025
83ff12f
hr: raid0.c: no need to increment md_counter
mcimerman Jun 9, 2025
7fba146
hr: RAID 1: inc meta counter on first write
mcimerman Jun 9, 2025
6791fbf
hr: foreign metadata: un-silent save()
mcimerman Jun 9, 2025
13ada52
hr: make failing an extent erase the superblock
mcimerman Jun 10, 2025
e0622a6
hr: raid1.c: increment meta counter on first write
mcimerman Jun 10, 2025
a62079d
hr: move struct hr_range_lock to util.h
mcimerman Jun 11, 2025
234212a
hr: rename data_dirty to first_write
mcimerman Jun 17, 2025
f0950d2
hr: add malloc_waitok() and calloc_waitok()
mcimerman Jun 17, 2025
d574c11
hr: fge: use malloc_waitok()
mcimerman Jun 17, 2025
66ef60b
hr: range locks: add noalloc lock acquire
mcimerman Jun 17, 2025
73425d4
hr: rai0.c: use renamed hr_add_data_offset()
mcimerman Jun 17, 2025
b22ea20
hr: rai1.c: make rebuild_blk evaluation more conservative
mcimerman Jun 17, 2025
9d1685b
hr: ENOMEM safe wrappers for block_direct_* ops
mcimerman Jun 17, 2025
a3486f2
hr: parallel RAID 5
mcimerman Jun 17, 2025
137f7cf
hr: add common hr_sync_extents() fcn
mcimerman Jun 17, 2025
3c518fc
hr: remove HR_BD_SYNC
mcimerman Jun 17, 2025
f0360ec
hr: RAID 0, 1: use ENOMEM safe primitives
mcimerman Jun 17, 2025
f0cc1c6
Merge upstream into helenraid
mcimerman Jun 20, 2025
817cb83
hr: update loc_service_register() calls
mcimerman Jun 20, 2025
4c103ee
hr: util.c: remove debug print
mcimerman Jun 20, 2025
cff2342
hr: raid5.c: fix bad extent selection
mcimerman Jun 20, 2025
81b4c79
hr: rename malloc_waitok() to hr_malloc_waitok()
mcimerman Jun 21, 2025
263a238
hr: rename volume state ONLINE to OPTIMAL
mcimerman Jun 22, 2025
c2d737d
hrctl: allow --help even when the server is offline
mcimerman Jun 22, 2025
8b0fbb7
hrctl: update usage message
mcimerman Jun 22, 2025
13f4c85
hr: raid1.c: allow rebuild on INVALID extents
mcimerman Jun 23, 2025
a5a2dcf
hr: util.c: make state changes logs mostly DEBUG level
mcimerman Jun 23, 2025
f6590c4
hr: io.c: fix typo in reconstruct reader
mcimerman Jun 23, 2025
09c195e
hr: move rebuild init to util.c
mcimerman Jun 23, 2025
cdfcaea
hr: RAID 5 rebuild
mcimerman Jun 23, 2025
f18e36e
hr: metadata/native: make save use waitok allocation
mcimerman Jun 23, 2025
e0695ce
hr: save REBUILD position
mcimerman Jun 23, 2025
6a8c156
hr: add option to save metadata on single extent
mcimerman Jun 23, 2025
62a8756
hr: metadata: use ENOMEM safe block I/O wrappers
mcimerman Jun 23, 2025
3702c32
hr: metadata/foreign/softraid: remove old comment
mcimerman Jun 23, 2025
c69cbef
hr: metadata/native: remove data_offset
mcimerman Jun 27, 2025
78433bb
hr: allocate in-memory metadata in format code
mcimerman Jun 27, 2025
aa9bad8
hr: let each format implement own probe
mcimerman Jun 27, 2025
2de7c1f
hr: metadata/foreign: implement erase_block()
mcimerman Jun 27, 2025
f93b886
hrctl: use single quotes for volume name
mcimerman Jun 28, 2025
8ad48d1
hr: metadata/gmirror: use syncid as on-disk counter
mcimerman Jun 28, 2025
aaf741f
hr: metadata/foreign: alloc metadata structs
mcimerman Jun 28, 2025
d220b7d
hr: change HelenRAID native metadata type str
mcimerman Jun 28, 2025
c24f96b
hr: add OpenBSD softraid metadata type str
mcimerman Jun 28, 2025
2192a01
hr: basic Linux Multiple Device RAID format support
mcimerman Jun 28, 2025
0dbd4a9
hr: metadata: validate magic early in decode
mcimerman Jun 28, 2025
9c9955a
hr: metadata/softraid: invalidate rebuild chunk
mcimerman Jun 28, 2025
e5c3580
hr: add HR_METADATA_ALLOW_REBUILD flag
mcimerman Jun 29, 2025
93ea452
hr: util.c: catch meta2vol() error
mcimerman Jun 29, 2025
150adbd
hr: add NOOP metadata type
mcimerman Jun 29, 2025
40ab490
hr: metadata/softraid: do not support dirty flag set
mcimerman Jun 29, 2025
c095ad9
hr: metadata/native: remove old debug print
mcimerman Jun 29, 2025
4a77540
hr: GEOM Mirror metadata saving support
mcimerman Jun 29, 2025
b81ae12
hr: softraid metadata saving support
mcimerman Jun 29, 2025
7ef5ea2
hr: encoding and saving MD metadata support
mcimerman Jun 29, 2025
640250b
hr: metadata/md: cstyle for MD metadata header
mcimerman Jun 29, 2025
95ca19d
hr: add --read-only volume flag
mcimerman Jun 30, 2025
059885c
hr: metadata/softraid: fix and allow rebuild
mcimerman Jun 30, 2025
d04a350
hr: metadata/gmirror: fix setting extent states
mcimerman Jun 30, 2025
dcdb990
hr: metadata/md: have to take rebuild into account
mcimerman Jun 30, 2025
996d31a
hr: retire level specific add_hotspare() hr_ops_t
mcimerman Jul 2, 2025
038a8d0
hr: hr_client_conn(): return when no vol is found
mcimerman Jul 3, 2025
b247c71
hr: rename async handler
mcimerman Jul 3, 2025
6aafb48
hr: rebuild: fix deadlock on extents_lock
mcimerman Jul 4, 2025
974f9ba
hr: different RAID 1 read strategies
mcimerman Jul 4, 2025
c76bf33
hr: raid1.c: update rebuild extent's last seek pos
mcimerman Jul 5, 2025
3b14bda
hr: raid1.c: retry split in case of failure
mcimerman Jul 6, 2025
1162b6c
hr: raid1.c: split read: abort on 0 good extents
mcimerman Jul 7, 2025
15e51b0
hr: check extent number
mcimerman Jul 7, 2025
9323bb8
hr: raid5.c: make the critical section smaller
mcimerman Jul 7, 2025
f7169a6
hr: raid5.c, parity_stripe.c: rename exec fcns
mcimerman Jul 8, 2025
ba65caf
hr: hr.c: potentially answer EBUSY on HR_STOP_ALL
mcimerman Jul 8, 2025
c5c367a
hr: use optimal subtract-write in degraded state
mcimerman Jul 8, 2025
9c3369b
hr: raid5.c: remove unused rebuild bufs
mcimerman Jul 9, 2025
b127da2
hr: careful assembly
mcimerman Jul 11, 2025
ca212a5
hr: RAID 0, 5: init strip size to closest (down) pow of 2
mcimerman Jul 11, 2025
a0abd46
hr: increase upper fibril bound of reconstruct write
mcimerman Jul 13, 2025
09e01d2
hr: type fixes for 32-bit archs
mcimerman Jul 14, 2025
c1c1c41
hr: add author's email address to RAID 5 files
mcimerman Jul 15, 2025
25830c2
hrctl: do not use devices/ prefix in usage
mcimerman Jul 15, 2025
73a2780
hr: remove old comments
mcimerman Jul 16, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion abi/include/abi/ipc/interfaces.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,9 @@ typedef enum {
INTERFACE_SYSTEM =
FOURCC_COMPACT('s', 's', 't', 'm') | IFACE_EXCHANGE_SERIALIZE,
INTERFACE_SYSTEM_CB =
FOURCC_COMPACT('s', 's', 't', 'm') | IFACE_EXCHANGE_SERIALIZE | IFACE_MOD_CALLBACK
FOURCC_COMPACT('s', 's', 't', 'm') | IFACE_EXCHANGE_SERIALIZE | IFACE_MOD_CALLBACK,
INTERFACE_HR =
FOURCC_COMPACT('h', 'r', ' ', ' ') | IFACE_EXCHANGE_SERIALIZE
} iface_t;

#endif
Expand Down
153 changes: 153 additions & 0 deletions uspace/app/bdwrite/bdwrite.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
/*
* Copyright (c) 2025 Miroslav Cimerman
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

/** @addtogroup bdwrite
* @{
*/
/**
* @file
*/

#include <block.h>
#include <errno.h>
#include <getopt.h>
#include <mem.h>
#include <stdlib.h>
#include <stdio.h>
#include <abi/ipc/ipc.h>
#include <perf.h>

static void usage(void);

static const char usage_str[] =
"Usage: bdwrite <dev> -o <offset in blocks> -c <block count>\n"
"\n"
" Write cyclic blocks to block device.\n";

static struct option const long_options[] = {
{ 0, 0, 0, 0 }
};

static void usage(void)
{
printf("%s", usage_str);
}

int main(int argc, char **argv)
{
errno_t rc;
size_t bsize;
int c;
char *name = NULL;
size_t blkcnt = 0, off = 0;
service_id_t dev;

if (argc != 6) {
goto bad;
}

name = argv[1];

c = 0;
optreset = 1;
optind = 0;

while (c != -1) {
c = getopt_long(argc, argv, "o:c:", long_options, NULL);
switch (c) {
case 'o':
off = strtol(optarg, NULL, 10);
break;
case 'c':
blkcnt = strtol(optarg, NULL, 10);
break;
}
}

rc = loc_service_get_id(name, &dev, 0);
if (rc != EOK) {
printf("bdwrite: error resolving device \"%s\"\n", name);
return 1;
}
rc = block_init(dev);
if (rc != EOK) {
printf("bdwrite: error initializing block device \"%s\"\n", name);
return 1;
}

rc = block_get_bsize(dev, &bsize);
if (rc != EOK) {
printf("bdwrite: error getting block size of \"%s\"\n", name);
block_fini(dev);
return 1;
}

uint64_t to_alloc = min(DATA_XFER_LIMIT, bsize * blkcnt);
uint8_t *buf = malloc(to_alloc);
if (buf == NULL) {
rc = ENOMEM;
goto end;
}

stopwatch_t stopwatch;
stopwatch_init(&stopwatch);
stopwatch_start(&stopwatch);

uint64_t left = blkcnt;
while (left != 0) {
uint64_t blks_to_write = min(to_alloc / bsize, left);
uint8_t *ptr = buf;
for (size_t i = 0; i < blks_to_write; i++) {
/* memset(ptr, (i + 1) % 0x100, bsize); */
memset(ptr, 'A' + (i % 26), bsize);
ptr += bsize;
}
rc = block_write_direct(dev, off, blks_to_write, buf);
if (rc != EOK) {
printf("bdwrite: error writing to \"%s\"\n", name);
goto end;
}
left -= blks_to_write;
off += blks_to_write;
}
end:
stopwatch_stop(&stopwatch);
nsec_t t = stopwatch_get_nanos(&stopwatch);
printf("Elapsed time:\n");
printf("\t%llu ms\n", NSEC2MSEC(t));
printf("\t%lf s\n", NSEC2SEC((double)t));
free(buf);
block_fini(dev);
return rc;
bad:
usage();
return 0;
}

/** @}
*/
30 changes: 30 additions & 0 deletions uspace/app/bdwrite/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#
# Copyright (c) 2024 Miroslav Cimerman
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# - Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# - Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# - The name of the author may not be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#

deps = [ 'block' ]
src = files('bdwrite.c')
9 changes: 9 additions & 0 deletions uspace/app/hrctl/create_file_bd_disks.bdsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
mkfile -s 100M /tmp/file1
mkfile -s 100M /tmp/file2
mkfile -s 100M /tmp/file3
mkfile -s 100M /tmp/file4

/srv/bd/file_bd -b 512 /tmp/file1 disk1
/srv/bd/file_bd -b 512 /tmp/file2 disk2
/srv/bd/file_bd -b 512 /tmp/file3 disk3
/srv/bd/file_bd -b 512 /tmp/file4 disk4
Loading