summary refs log tree commit diff
path: root/sys_util/src/write_zeroes.rs
Commit message (Collapse)AuthorAge
* sys_util: do not deallocate space in write_zeroesDaniel Verkamp2019-11-27
| | | | | | | | | | | | | | | | | | Replace the implementation of File write_zeroes with one that uses fallocate() with the FALLOC_FL_ZERO_RANGE flag instead of FALLOC_FL_PUNCH_HOLE. This means it will keep space allocated for the zeroed region instead of deallocating it. The PunchHole trait is available for this purpose instead, and the virtio-blk implementation already relies on these two traits for their differing behaviors. BUG=chromium:858815 TEST=cargo test -p sys_util write_zeroes Change-Id: I69ab06037f72dc219e6ea9409654f97eeaba32c3 Signed-off-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1913520 Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Dylan Reid <dgreid@chromium.org>
* sys_util: add WriteZeroesAt traitDaniel Verkamp2019-11-27
| | | | | | | | | | | | | | | | | Add a variant of WriteZeroes that allows the caller to specify the offset explicitly instead of using the file's cursor. This gets rid of one of the last bits of shared state between disk file users, which will help in implementing multi-queue support. Additionally, modify the WriteZeroes trait to use a generic implementation based on WriteZeroesAt + Seek when possible. BUG=chromium:858815 TEST=Boot Termina in crosvm Change-Id: If710159771aeeb55f4f7746dd4354b6c042144e8 Signed-off-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1913519
* sys_util: add write_zeroes_all() functionDaniel Verkamp2019-09-25
| | | | | | | | | | | | | | | | | | In the same spirit as write_all() for the standard io::Write::write() function, add a write_zeroes_all() function with a default implementation that calls write_zeroes() in a loop until the requested length is met. This will allow write_zeroes implementations that don't necessarily fulfill the entire requested length. BUG=None TEST=cargo test -p sys_util write_zeroes Change-Id: I0fc3a4b3fe8904946e253ab8a2687555b12657be Signed-off-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1811466 Reviewed-by: Zach Reizner <zachr@chromium.org> Reviewed-by: Cody Schuffelen <schuffelen@google.com> Tested-by: kokoro <noreply+kokoro@google.com>
* tempfile: Unify the two tempdir implementationsDavid Tolnay2019-07-11
| | | | | | | | | | | | | | | | | | | | | | Looks like we ended up with two totally different tempdir implementations: one from CL:520706 and the other from CL:1409705. This CL consolidates them into one implementation. BUG=chromium:974059 TEST=tempfile: cargo test TEST=crosvm: cargo check --all-features TEST=devices: cargo check --tests TEST=sys_util: cargo check --tests TEST=local kokoro TEST=./build_test Cq-Depend: chromium:1574668 Change-Id: Id70e963c9986ed2fc5f160819c4a7f9f16092b3b Signed-off-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1573227 Tested-by: kokoro <noreply+kokoro@google.com> Legacy-Commit-Queue: Commit Bot <commit-bot@chromium.org>
* clippy: Iterate without calling .iter()David Tolnay2019-04-18
| | | | | | | | | | | | | | | | | | | | | | | | | | | See: https://rust-lang.github.io/rust-clippy/master/index.html#explicit_iter_loop https://rust-lang.github.io/rust-clippy/master/index.html#explicit_into_iter_loop Before: for element in slice.iter() {...} After: for element in slice {...} TEST=grep -r '\.iter() {' TEST=grep -r '\.iter_mut() {' TEST=grep -r '\.into_iter() {' TEST=cargo check --all-features TEST=local kokoro Change-Id: I27f0df7cfa1064b2c8b162cba263513926a433a9 Reviewed-on: https://chromium-review.googlesource.com/1568525 Commit-Ready: David Tolnay <dtolnay@chromium.org> Tested-by: David Tolnay <dtolnay@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
* sys_util: write_zeros: Make clippy cleanDylan Reid2019-03-26
| | | | | | | | | | | favor `if let` over `match` for destructing a single value. Signed-off-by: Dylan Reid <dgreid@chromium.org> Change-Id: I0c09d7ffc380e84d7413d6fed338d65a60563a8f Reviewed-on: https://chromium-review.googlesource.com/1510069 Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Stephen Barber <smbarber@chromium.org> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
* edition: Update absolute paths to 2018 styleDavid Tolnay2019-03-13
| | | | | | | | | | | | | | | | | | | | | | | | | | This is an easy step toward adopting 2018 edition eventually, and will make any future CL that sets `edition = "2018"` this much smaller. The module system changes in Rust 2018 are described here: https://doc.rust-lang.org/edition-guide/rust-2018/module-system/path-clarity.html Generated by running: cargo fix --edition --all in each workspace, followed by bin/fmt. TEST=cargo check TEST=cargo check --all-features TEST=cargo check --target aarch64-unknown-linux-gnu Change-Id: I000ab5e69d69aa222c272fae899464bbaf65f6d8 Reviewed-on: https://chromium-review.googlesource.com/1513054 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Tested-by: David Tolnay <dtolnay@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: David Tolnay <dtolnay@chromium.org>
* devices: virtio: block: ignore Discard failuresDaniel Verkamp2018-10-19
| | | | | | | | | | | | | | | | | | | | | Our branch of the 3.18 kernel has FALLOC_FL_PUNCH_HOLE disabled for the ext4 filesystem, which means that systems running that kernel always take the fallback path of writing buffers full of zeroes. This is not necessary for the Discard command, since it is just a hint and is not required to actually zero the blocks. Split the WriteZeroes trait up into a new PunchHole trait, which corresponds to fallocate() with FALLOC_FL_PUNCH_HOLE, and use the new trait to implement the virtio block Discard command. BUG=chromium:896314 TEST=`mkfs.btrfs /dev/vdb` and verify the desired fallocate() is used and no write() calls are issued when inducing a failure Change-Id: I67fd9a132758d8d766531ccca8358c7fe67b0460 Signed-off-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1286224 Reviewed-by: Dylan Reid <dgreid@chromium.org>
* sys_util: use PUNCH_HOLE to implement write_zeroesDaniel Verkamp2018-10-13
| | | | | | | | | | | | | | | | | Some filesystems do not support FALLOC_FL_ZERO_RANGE; in particular, encrypted files on ext4 fail this request with -EOPNOTSUPP. Use fallocate with FALLOC_FL_PUNCH_HOLE instead, which is more widely supported. BUG=None TEST=strace crosvm using qcow files on encrypted ext4 and verify that fallocate(FALLOC_FL_PUNCH_HOLE) is issued when required. Change-Id: Idffabc75ea0e1153efbb13cec8b4a25570427235 Signed-off-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1250022 Reviewed-by: Stephen Barber <smbarber@chromium.org> Reviewed-by: Dylan Reid <dgreid@chromium.org>
* cargo fmt all source codeZach Reizner2018-10-09
| | | | | | | | | | | | | | Now that cargo fmt has landed, run it over everything at once to bring rust source to the standard formatting. TEST=cargo test BUG=None Change-Id: Ic95a48725e5a40dcbd33ba6d5aef2bd01e91865b Reviewed-on: https://chromium-review.googlesource.com/1259287 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Tested-by: Zach Reizner <zachr@chromium.org> Reviewed-by: Zach Reizner <zachr@chromium.org>
* sys_util: add WriteZeroes trait and impl for FileDaniel Verkamp2018-09-05
BUG=chromium:850998 TEST=cargo test -p sys_util write_zeroes Change-Id: I90f670fffed055f39e141b26819d56948b1bf30d Signed-off-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1187017 Reviewed-by: Stephen Barber <smbarber@chromium.org>