From 591ffec1ebb287f3cc5bf154b3c58cc765d78b76 Mon Sep 17 00:00:00 2001 From: Ariel Miculas Date: Sat, 29 Jun 2024 22:40:57 +0300 Subject: [PATCH 1/2] Avoid allocation when decoding hex strings Not particularly useful in user space, but we avoid allocation as much as possible in kernel space and we also want to share the code between the two implementations. Signed-off-by: Ariel Miculas --- puzzlefs-lib/src/format/types.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/puzzlefs-lib/src/format/types.rs b/puzzlefs-lib/src/format/types.rs index c472927..da1d276 100644 --- a/puzzlefs-lib/src/format/types.rs +++ b/puzzlefs-lib/src/format/types.rs @@ -794,10 +794,8 @@ impl Serialize for Digest { impl TryFrom<&str> for Digest { type Error = FromHexError; fn try_from(s: &str) -> std::result::Result { - let digest = hex::decode(s)?; - let digest: [u8; SHA256_BLOCK_SIZE] = digest - .try_into() - .map_err(|_| FromHexError::InvalidStringLength)?; + let mut digest: [u8; SHA256_BLOCK_SIZE] = [0; SHA256_BLOCK_SIZE]; + hex::decode_to_slice(s, &mut digest)?; Ok(Digest(digest)) } } From fe47579ced51258f003e71bfef800bcc5502d3a4 Mon Sep 17 00:00:00 2001 From: Ariel Miculas Date: Sat, 29 Jun 2024 22:44:15 +0300 Subject: [PATCH 2/2] Support classic installation via make The classic `make` and `make install` steps should work for installing puzzlefs, so: 1. change the default make action to do a release build 2. add an install target in the Makefile Signed-off-by: Ariel Miculas --- Makefile | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 7e767da..181fb4b 100644 --- a/Makefile +++ b/Makefile @@ -1,13 +1,16 @@ SRC=$(shell find . -name \*.rs | grep -v "^./target") - -.PHONY: debug -debug: - cargo build +PREFIX?=/usr/local +ROOT_SBINDIR?=$(PREFIX)/sbin +INSTALL=install .PHONY: release release: cargo build --release +.PHONY: debug +debug: + cargo build + .PHONY: check check: RUST_BACKTRACE=1 cargo test -- --nocapture @@ -24,3 +27,6 @@ fmt: .PHONY: clean clean: -cargo clean + +install: + $(INSTALL) -m0755 -D target/release/puzzlefs -t $(ROOT_SBINDIR)