All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] zfs: Support zstd compression
@ 2024-05-16 19:42 Vladimir Serbinenko
  2024-05-16 19:42 ` [PATCH 2/2] Add test for zfs zstd Vladimir Serbinenko
  2024-06-14 17:03 ` [PATCH 1/2] zfs: Support zstd compression Daniel Kiper
  0 siblings, 2 replies; 3+ messages in thread
From: Vladimir Serbinenko @ 2024-05-16 19:42 UTC (permalink / raw)
  To: grub-devel; +Cc: Vladimir Serbinenko

Signed-off-by: Vladimir Serbinenko <phcoder@gmail.com>
---
 grub-core/Makefile.core.def |  1 +
 grub-core/fs/zfs/zfs.c      | 32 ++++++++++++++++++++++++++++++++
 include/grub/zfs/zio.h      |  1 +
 3 files changed, 34 insertions(+)

diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
index 8e1b1d9f3..2ba4962d5 100644
--- a/grub-core/Makefile.core.def
+++ b/grub-core/Makefile.core.def
@@ -1596,6 +1596,7 @@ module = {
   common = fs/zfs/zfs_lz4.c;
   common = fs/zfs/zfs_sha256.c;
   common = fs/zfs/zfs_fletcher.c;
+  cppflags = '-I$(srcdir)/lib/posix_wrap -I$(srcdir)/lib/zstd';
 };
 
 module = {
diff --git a/grub-core/fs/zfs/zfs.c b/grub-core/fs/zfs/zfs.c
index b5453e006..b8441faef 100644
--- a/grub-core/fs/zfs/zfs.c
+++ b/grub-core/fs/zfs/zfs.c
@@ -57,6 +57,8 @@
 #include <grub/i18n.h>
 #include <grub/safemath.h>
 
+#include <zstd.h>
+
 GRUB_MOD_LICENSE ("GPLv3+");
 
 #define	ZPOOL_PROP_BOOTFS		"bootfs"
@@ -291,6 +293,7 @@ static const char *spa_feature_names[] = {
   "com.delphix:embedded_data",
   "com.delphix:extensible_dataset",
   "org.open-zfs:large_blocks",
+  "org.freebsd:zstd_compress",
   NULL
 };
 
@@ -312,6 +315,34 @@ zlib_decompress (void *s, void *d,
   return grub_errno;
 }
 
+static grub_err_t
+zstd_decompress (void *ibuf, void *obuf, grub_size_t isize,
+		 grub_size_t osize)
+{
+  grub_size_t zstd_ret;
+  grub_uint8_t *byte_buf = (grub_uint8_t *) ibuf;
+
+  if (isize < 8)
+      return grub_error (GRUB_ERR_BAD_COMPRESSED_DATA, "zstd data too short");
+
+  grub_uint32_t c_len = grub_be_to_cpu32(grub_get_unaligned32(byte_buf));
+
+  if (c_len > isize - 8)
+      return grub_error (GRUB_ERR_BAD_COMPRESSED_DATA, "zstd data announced size overflow");
+
+  /* Fix magic number.  */
+  byte_buf[4] = 0x28;
+  byte_buf[5] = 0xb5;
+  byte_buf[6] = 0x2f;
+  byte_buf[7] = 0xfd;
+  zstd_ret = ZSTD_decompress (obuf, osize, byte_buf + 4, c_len + 4);
+
+  if (ZSTD_isError (zstd_ret))
+    return grub_error (GRUB_ERR_BAD_COMPRESSED_DATA, "zstd data corrupted (error %d)", (int) zstd_ret);
+
+  return GRUB_ERR_NONE;
+}
+
 static grub_err_t
 zle_decompress (void *s, void *d,
 		grub_size_t slen, grub_size_t dlen)
@@ -362,6 +393,7 @@ static decomp_entry_t decomp_table[ZIO_COMPRESS_FUNCTIONS] = {
   {"gzip-9", zlib_decompress},  /* ZIO_COMPRESS_GZIP9 */
   {"zle", zle_decompress},      /* ZIO_COMPRESS_ZLE   */
   {"lz4", lz4_decompress},      /* ZIO_COMPRESS_LZ4   */
+  {"zstd", zstd_decompress},    /* ZIO_COMPRESS_ZSTD   */
 };
 
 static grub_err_t zio_read_data (blkptr_t * bp, grub_zfs_endian_t endian,
diff --git a/include/grub/zfs/zio.h b/include/grub/zfs/zio.h
index 19ce136bb..997b0c4d4 100644
--- a/include/grub/zfs/zio.h
+++ b/include/grub/zfs/zio.h
@@ -89,6 +89,7 @@ enum zio_compress {
 	ZIO_COMPRESS_GZIP9,
 	ZIO_COMPRESS_ZLE,
 	ZIO_COMPRESS_LZ4,
+	ZIO_COMPRESS_ZSTD,
 	ZIO_COMPRESS_FUNCTIONS
 };
 
-- 
2.39.2


_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 2/2] Add test for zfs zstd
  2024-05-16 19:42 [PATCH 1/2] zfs: Support zstd compression Vladimir Serbinenko
@ 2024-05-16 19:42 ` Vladimir Serbinenko
  2024-06-14 17:03 ` [PATCH 1/2] zfs: Support zstd compression Daniel Kiper
  1 sibling, 0 replies; 3+ messages in thread
From: Vladimir Serbinenko @ 2024-05-16 19:42 UTC (permalink / raw)
  To: grub-devel; +Cc: Vladimir Serbinenko

Signed-off-by: Vladimir Serbinenko <phcoder@gmail.com>
---
 tests/util/grub-fs-tester.in | 2 +-
 tests/zfs_test.in            | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/tests/util/grub-fs-tester.in b/tests/util/grub-fs-tester.in
index ea8b2d1f6..f0451ecd9 100644
--- a/tests/util/grub-fs-tester.in
+++ b/tests/util/grub-fs-tester.in
@@ -775,7 +775,7 @@ for LOGSECSIZE in $(range "$MINLOGSECSIZE" "$MAXLOGSECSIZE" 1); do
 		    sleep 1
 		    "zfs" create -o casesensitivity=insensitive "$FSLABEL"/"grub fs"
 		    sleep 1;;
-		x"zfs_lzjb" | xzfs_gzip | xzfs_zle)
+		x"zfs_lzjb" | xzfs_gzip | xzfs_zle | xzfs_zstd)
 		    "zpool" create -O compression=${fs/zfs_/} -R "$MNTPOINTRW" "$FSLABEL" "${MOUNTDEVICE}"
 		    sleep 1
 		    "zfs" create -o compression=${fs/zfs_/} "$FSLABEL"/"grub fs"
diff --git a/tests/zfs_test.in b/tests/zfs_test.in
index 58cc25b22..0d0a57f7d 100644
--- a/tests/zfs_test.in
+++ b/tests/zfs_test.in
@@ -19,6 +19,7 @@ fi
 "@builddir@/grub-fs-tester" zfs_lzjb
 "@builddir@/grub-fs-tester" zfs_gzip
 "@builddir@/grub-fs-tester" zfs_zle
+"@builddir@/grub-fs-tester" zfs_zstd
 "@builddir@/grub-fs-tester" zfs_raidz3
 "@builddir@/grub-fs-tester" zfs_raidz2
 "@builddir@/grub-fs-tester" zfs_raidz
-- 
2.39.2


_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/2] zfs: Support zstd compression
  2024-05-16 19:42 [PATCH 1/2] zfs: Support zstd compression Vladimir Serbinenko
  2024-05-16 19:42 ` [PATCH 2/2] Add test for zfs zstd Vladimir Serbinenko
@ 2024-06-14 17:03 ` Daniel Kiper
  1 sibling, 0 replies; 3+ messages in thread
From: Daniel Kiper @ 2024-06-14 17:03 UTC (permalink / raw)
  To: Vladimir Serbinenko; +Cc: grub-devel

On Thu, May 16, 2024 at 10:42:25PM +0300, Vladimir Serbinenko wrote:
> Signed-off-by: Vladimir Serbinenko <phcoder@gmail.com>
> ---
>  grub-core/Makefile.core.def |  1 +
>  grub-core/fs/zfs/zfs.c      | 32 ++++++++++++++++++++++++++++++++
>  include/grub/zfs/zio.h      |  1 +
>  3 files changed, 34 insertions(+)
>
> diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
> index 8e1b1d9f3..2ba4962d5 100644
> --- a/grub-core/Makefile.core.def
> +++ b/grub-core/Makefile.core.def
> @@ -1596,6 +1596,7 @@ module = {
>    common = fs/zfs/zfs_lz4.c;
>    common = fs/zfs/zfs_sha256.c;
>    common = fs/zfs/zfs_fletcher.c;
> +  cppflags = '-I$(srcdir)/lib/posix_wrap -I$(srcdir)/lib/zstd';
>  };
>
>  module = {
> diff --git a/grub-core/fs/zfs/zfs.c b/grub-core/fs/zfs/zfs.c
> index b5453e006..b8441faef 100644
> --- a/grub-core/fs/zfs/zfs.c
> +++ b/grub-core/fs/zfs/zfs.c
> @@ -57,6 +57,8 @@
>  #include <grub/i18n.h>
>  #include <grub/safemath.h>
>
> +#include <zstd.h>
> +
>  GRUB_MOD_LICENSE ("GPLv3+");
>
>  #define	ZPOOL_PROP_BOOTFS		"bootfs"
> @@ -291,6 +293,7 @@ static const char *spa_feature_names[] = {
>    "com.delphix:embedded_data",
>    "com.delphix:extensible_dataset",
>    "org.open-zfs:large_blocks",
> +  "org.freebsd:zstd_compress",
>    NULL
>  };
>
> @@ -312,6 +315,34 @@ zlib_decompress (void *s, void *d,
>    return grub_errno;
>  }
>
> +static grub_err_t
> +zstd_decompress (void *ibuf, void *obuf, grub_size_t isize,
> +		 grub_size_t osize)
> +{
> +  grub_size_t zstd_ret;
> +  grub_uint8_t *byte_buf = (grub_uint8_t *) ibuf;
> +
> +  if (isize < 8)
> +      return grub_error (GRUB_ERR_BAD_COMPRESSED_DATA, "zstd data too short");
> +
> +  grub_uint32_t c_len = grub_be_to_cpu32(grub_get_unaligned32(byte_buf));

May I ask you to define c_len at the beginning of the function?
And please fix coding style for function calls.

> +  if (c_len > isize - 8)
> +      return grub_error (GRUB_ERR_BAD_COMPRESSED_DATA, "zstd data announced size overflow");
> +
> +  /* Fix magic number.  */

I think the fix should be explained why it is needed.

> +  byte_buf[4] = 0x28;
> +  byte_buf[5] = 0xb5;
> +  byte_buf[6] = 0x2f;
> +  byte_buf[7] = 0xfd;
> +  zstd_ret = ZSTD_decompress (obuf, osize, byte_buf + 4, c_len + 4);
> +
> +  if (ZSTD_isError (zstd_ret))
> +    return grub_error (GRUB_ERR_BAD_COMPRESSED_DATA, "zstd data corrupted (error %d)", (int) zstd_ret);
> +
> +  return GRUB_ERR_NONE;
> +}

Daniel

_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-06-14 17:04 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-16 19:42 [PATCH 1/2] zfs: Support zstd compression Vladimir Serbinenko
2024-05-16 19:42 ` [PATCH 2/2] Add test for zfs zstd Vladimir Serbinenko
2024-06-14 17:03 ` [PATCH 1/2] zfs: Support zstd compression Daniel Kiper

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.