From nobody Thu Dec 18 14:12:15 2025 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4696E223708 for ; Mon, 2 Jun 2025 15:53:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748879615; cv=none; b=eUeJhI6bHgHzdyLKlxRfuML5H9yyBuvPbohQlkrFxgaP/4VUqU7Ih0W93GlUsdgyzuO5BNuKSpvdaAX+ry5777uJf7NkR4BWQhselmE4rCgNX9LqyNmfovXlUhOY8pzSM4rLLk+qLBaJhPpqT6kygqlMtfHkt8ypmTUqQ91yNVM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748879615; c=relaxed/simple; bh=SZ8DWS3QDMg8FLMxfjBixbAuwkv6b7i5A/YU2QXRU2g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cuY8wsj+kST/yWNzbKHj3Ap/O41xjdZta+HflLCBeNRQAQgMp5gcRJV78gAV3Oxs3+xEEB8BTtMdaqYiTwvmQo8PWoMwuwK8SRZM4/O72RdQ0ZMDPHZbBJKxN76FgHIw6SJgSvByxH0RAJQqTaivWB63f3ZLw/B9AJL9HTTGV7s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b=PrUGxjSS; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b=PrUGxjSS; arc=none smtp.client-ip=195.135.223.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="PrUGxjSS"; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="PrUGxjSS" Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id D46E12120C; Mon, 2 Jun 2025 15:53:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1748879602; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6nyjPt297duvLpbWem1nV6wBQV97SYHuvo6JAt3GfO8=; b=PrUGxjSSfPNWIMRfrNrO3aFJskmZIlLUvT5T3dMz7FRSFfJ87kN8QJ2kPuaCPpv3xI7xVo WnU5Uq3wG+vEd7Yr3HJvlaubbb91qaqaQOj37z1gdM7JiTRpwaRdLAQhu3T5bpH/+bD4iU i2NW1tcAGxqEOA5TqpYfFFVJ9l8S1cM= Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1748879602; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6nyjPt297duvLpbWem1nV6wBQV97SYHuvo6JAt3GfO8=; b=PrUGxjSSfPNWIMRfrNrO3aFJskmZIlLUvT5T3dMz7FRSFfJ87kN8QJ2kPuaCPpv3xI7xVo WnU5Uq3wG+vEd7Yr3HJvlaubbb91qaqaQOj37z1gdM7JiTRpwaRdLAQhu3T5bpH/+bD4iU i2NW1tcAGxqEOA5TqpYfFFVJ9l8S1cM= Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id B9DC113A63; Mon, 2 Jun 2025 15:53:22 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id MAOCLPLIPWhIBQAAD6G6ig (envelope-from ); Mon, 02 Jun 2025 15:53:22 +0000 From: Daniel Vacek To: Chris Mason , Josef Bacik , David Sterba , Nick Terrell Cc: linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, Daniel Vacek Subject: [PATCH v3 1/2] btrfs: factor out compress mount options parsing Date: Mon, 2 Jun 2025 17:53:18 +0200 Message-ID: <20250602155320.1854888-2-neelx@suse.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250602155320.1854888-1-neelx@suse.com> References: <20250602155320.1854888-1-neelx@suse.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Flag: NO X-Spam-Score: -6.80 X-Spamd-Result: default: False [-6.80 / 50.00]; REPLY(-4.00)[]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; RCPT_COUNT_SEVEN(0.00)[7]; RCVD_VIA_SMTP_AUTH(0.00)[]; MIME_TRACE(0.00)[0:+]; ARC_NA(0.00)[]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; RCVD_TLS_ALL(0.00)[] X-Spam-Level: Content-Type: text/plain; charset="utf-8" There are many options making the parsing a bit lenghty. Factor the compress options out into a helper function. The next patch is going to harden this function. Signed-off-by: Daniel Vacek --- v3 changes: Split into two patches to ease backporting, no functional changes. fs/btrfs/super.c | 100 +++++++++++++++++++++++++---------------------- 1 file changed, 54 insertions(+), 46 deletions(-) diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index 40709e2a44fce..6291ab45ab2a5 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -270,6 +270,59 @@ static inline blk_mode_t btrfs_open_mode(struct fs_con= text *fc) return sb_open_mode(fc->sb_flags) & ~BLK_OPEN_RESTRICT_WRITES; } =20 +static int btrfs_parse_compress(struct btrfs_fs_context *ctx, + struct fs_parameter *param, int opt) +{ + /* + * Provide the same semantics as older kernels that don't use fs + * context, specifying the "compress" option clears + * "force-compress" without the need to pass + * "compress-force=3D[no|none]" before specifying "compress". + */ + if (opt !=3D Opt_compress_force && opt !=3D Opt_compress_force_type) + btrfs_clear_opt(ctx->mount_opt, FORCE_COMPRESS); + + if (opt =3D=3D Opt_compress || opt =3D=3D Opt_compress_force) { + ctx->compress_type =3D BTRFS_COMPRESS_ZLIB; + ctx->compress_level =3D BTRFS_ZLIB_DEFAULT_LEVEL; + btrfs_set_opt(ctx->mount_opt, COMPRESS); + btrfs_clear_opt(ctx->mount_opt, NODATACOW); + btrfs_clear_opt(ctx->mount_opt, NODATASUM); + } else if (strncmp(param->string, "zlib", 4) =3D=3D 0) { + ctx->compress_type =3D BTRFS_COMPRESS_ZLIB; + ctx->compress_level =3D + btrfs_compress_str2level(BTRFS_COMPRESS_ZLIB, + param->string + 4); + btrfs_set_opt(ctx->mount_opt, COMPRESS); + btrfs_clear_opt(ctx->mount_opt, NODATACOW); + btrfs_clear_opt(ctx->mount_opt, NODATASUM); + } else if (strncmp(param->string, "lzo", 3) =3D=3D 0) { + ctx->compress_type =3D BTRFS_COMPRESS_LZO; + ctx->compress_level =3D 0; + btrfs_set_opt(ctx->mount_opt, COMPRESS); + btrfs_clear_opt(ctx->mount_opt, NODATACOW); + btrfs_clear_opt(ctx->mount_opt, NODATASUM); + } else if (strncmp(param->string, "zstd", 4) =3D=3D 0) { + ctx->compress_type =3D BTRFS_COMPRESS_ZSTD; + ctx->compress_level =3D + btrfs_compress_str2level(BTRFS_COMPRESS_ZSTD, + param->string + 4); + btrfs_set_opt(ctx->mount_opt, COMPRESS); + btrfs_clear_opt(ctx->mount_opt, NODATACOW); + btrfs_clear_opt(ctx->mount_opt, NODATASUM); + } else if (strncmp(param->string, "no", 2) =3D=3D 0) { + ctx->compress_level =3D 0; + ctx->compress_type =3D 0; + btrfs_clear_opt(ctx->mount_opt, COMPRESS); + btrfs_clear_opt(ctx->mount_opt, FORCE_COMPRESS); + } else { + btrfs_err(NULL, "unrecognized compression value %s", + param->string); + return -EINVAL; + } + return 0; +} + static int btrfs_parse_param(struct fs_context *fc, struct fs_parameter *p= aram) { struct btrfs_fs_context *ctx =3D fc->fs_private; @@ -339,53 +392,8 @@ static int btrfs_parse_param(struct fs_context *fc, st= ruct fs_parameter *param) fallthrough; case Opt_compress: case Opt_compress_type: - /* - * Provide the same semantics as older kernels that don't use fs - * context, specifying the "compress" option clears - * "force-compress" without the need to pass - * "compress-force=3D[no|none]" before specifying "compress". - */ - if (opt !=3D Opt_compress_force && opt !=3D Opt_compress_force_type) - btrfs_clear_opt(ctx->mount_opt, FORCE_COMPRESS); - - if (opt =3D=3D Opt_compress || opt =3D=3D Opt_compress_force) { - ctx->compress_type =3D BTRFS_COMPRESS_ZLIB; - ctx->compress_level =3D BTRFS_ZLIB_DEFAULT_LEVEL; - btrfs_set_opt(ctx->mount_opt, COMPRESS); - btrfs_clear_opt(ctx->mount_opt, NODATACOW); - btrfs_clear_opt(ctx->mount_opt, NODATASUM); - } else if (strncmp(param->string, "zlib", 4) =3D=3D 0) { - ctx->compress_type =3D BTRFS_COMPRESS_ZLIB; - ctx->compress_level =3D - btrfs_compress_str2level(BTRFS_COMPRESS_ZLIB, - param->string + 4); - btrfs_set_opt(ctx->mount_opt, COMPRESS); - btrfs_clear_opt(ctx->mount_opt, NODATACOW); - btrfs_clear_opt(ctx->mount_opt, NODATASUM); - } else if (strncmp(param->string, "lzo", 3) =3D=3D 0) { - ctx->compress_type =3D BTRFS_COMPRESS_LZO; - ctx->compress_level =3D 0; - btrfs_set_opt(ctx->mount_opt, COMPRESS); - btrfs_clear_opt(ctx->mount_opt, NODATACOW); - btrfs_clear_opt(ctx->mount_opt, NODATASUM); - } else if (strncmp(param->string, "zstd", 4) =3D=3D 0) { - ctx->compress_type =3D BTRFS_COMPRESS_ZSTD; - ctx->compress_level =3D - btrfs_compress_str2level(BTRFS_COMPRESS_ZSTD, - param->string + 4); - btrfs_set_opt(ctx->mount_opt, COMPRESS); - btrfs_clear_opt(ctx->mount_opt, NODATACOW); - btrfs_clear_opt(ctx->mount_opt, NODATASUM); - } else if (strncmp(param->string, "no", 2) =3D=3D 0) { - ctx->compress_level =3D 0; - ctx->compress_type =3D 0; - btrfs_clear_opt(ctx->mount_opt, COMPRESS); - btrfs_clear_opt(ctx->mount_opt, FORCE_COMPRESS); - } else { - btrfs_err(NULL, "unrecognized compression value %s", - param->string); + if (btrfs_parse_compress(ctx, param, opt)) return -EINVAL; - } break; case Opt_ssd: if (result.negated) { --=20 2.47.2 From nobody Thu Dec 18 14:12:15 2025 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2AD6722333B for ; Mon, 2 Jun 2025 15:53:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748879621; cv=none; b=g8XL6yYreHxBjlXZ17LGJjpHS4vVKx9NJ9Ujjy4cYhcnQla3+CNp/93zE2GgDyNQp7OKDsrEAPGFm2A4rq6WLAPb3By+ELGQ0e6pH57hdR/ZTBS0rl5Ugec81NsMfES6CDGTO9oe1n9zj3fFD60xeGLoKaaJAWSyRrjIvr4UrAs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748879621; c=relaxed/simple; bh=go1PPFz+AMC/M5zXK7Is9Mi6bbDhxdFN6LXeNEBwDLs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MxNd96joX8I5ZP1OlDtpzkNAzEVg/rPkBpH+zFRRqbWulta/cWkb2c7khDOV8fL6qv+PPJ0lgJdQS7SyCx/P4gH5mwj4s/6w6Xqykkf8oRw4ZW369tMc5tddeH1upwXxvwCbGPviAjG8+FlZZcdoidii72I0JKNyyeqgMwmloW8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b=qfVgSCGj; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b=qfVgSCGj; arc=none smtp.client-ip=195.135.223.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="qfVgSCGj"; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="qfVgSCGj" Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 494D22120E; Mon, 2 Jun 2025 15:53:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1748879603; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QWkGADfqpetKnnKrUkvD8J/JBZ9PJNS7K0KKvu/tSqU=; b=qfVgSCGjjop2VBVuGiaPUPGkJ6lG5Z22jYedW+2/NljDiwUvWWCIk9wvnOGvex5LWmAixP 0Hf34TDX71FO+JxkOxmi+3h0efZwl4DTSUYT9+oXhbbmZjxKCcHqh2Q1KvtpkGUzsm4R7M 9eSx05DvlzSGVdptBRnhQxyF0tM4MOE= Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1748879603; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QWkGADfqpetKnnKrUkvD8J/JBZ9PJNS7K0KKvu/tSqU=; b=qfVgSCGjjop2VBVuGiaPUPGkJ6lG5Z22jYedW+2/NljDiwUvWWCIk9wvnOGvex5LWmAixP 0Hf34TDX71FO+JxkOxmi+3h0efZwl4DTSUYT9+oXhbbmZjxKCcHqh2Q1KvtpkGUzsm4R7M 9eSx05DvlzSGVdptBRnhQxyF0tM4MOE= Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 2E98113A63; Mon, 2 Jun 2025 15:53:23 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id IB7GCvPIPWhIBQAAD6G6ig (envelope-from ); Mon, 02 Jun 2025 15:53:23 +0000 From: Daniel Vacek To: Chris Mason , Josef Bacik , David Sterba , Nick Terrell Cc: linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, Daniel Vacek Subject: [PATCH v3 2/2] btrfs: harden parsing of compress mount options Date: Mon, 2 Jun 2025 17:53:19 +0200 Message-ID: <20250602155320.1854888-3-neelx@suse.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250602155320.1854888-1-neelx@suse.com> References: <20250602155320.1854888-1-neelx@suse.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spamd-Result: default: False [-6.80 / 50.00]; REPLY(-4.00)[]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; RCPT_COUNT_SEVEN(0.00)[7]; RCVD_VIA_SMTP_AUTH(0.00)[]; MIME_TRACE(0.00)[0:+]; ARC_NA(0.00)[]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; RCVD_TLS_ALL(0.00)[] X-Spam-Level: X-Spam-Flag: NO X-Spam-Score: -6.80 Content-Type: text/plain; charset="utf-8" Btrfs happily but incorrectly accepts the `-o compress=3Dzlib+foo` and simi= lar options with any random suffix. Fix that by explicitly checking the end of the strings. Signed-off-by: Daniel Vacek --- v3 changes: Split into two patches to ease backporting, no functional changes. fs/btrfs/super.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index 6291ab45ab2a5..4510c5f7a785e 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -270,9 +270,20 @@ static inline blk_mode_t btrfs_open_mode(struct fs_con= text *fc) return sb_open_mode(fc->sb_flags) & ~BLK_OPEN_RESTRICT_WRITES; } =20 +static bool btrfs_match_compress_type(char *string, char *type, bool may_h= ave_level) +{ + int len =3D strlen(type); + + return strncmp(string, type, len) =3D=3D 0 && + ((may_have_level && string[len] =3D=3D ':') || + string[len] =3D=3D '\0'); +} + static int btrfs_parse_compress(struct btrfs_fs_context *ctx, struct fs_parameter *param, int opt) { + char *string =3D param->string; + /* * Provide the same semantics as older kernels that don't use fs * context, specifying the "compress" option clears @@ -288,36 +299,37 @@ static int btrfs_parse_compress(struct btrfs_fs_conte= xt *ctx, btrfs_set_opt(ctx->mount_opt, COMPRESS); btrfs_clear_opt(ctx->mount_opt, NODATACOW); btrfs_clear_opt(ctx->mount_opt, NODATASUM); - } else if (strncmp(param->string, "zlib", 4) =3D=3D 0) { + } else if (btrfs_match_compress_type(string, "zlib", true)) { ctx->compress_type =3D BTRFS_COMPRESS_ZLIB; ctx->compress_level =3D btrfs_compress_str2level(BTRFS_COMPRESS_ZLIB, - param->string + 4); + string + 4); btrfs_set_opt(ctx->mount_opt, COMPRESS); btrfs_clear_opt(ctx->mount_opt, NODATACOW); btrfs_clear_opt(ctx->mount_opt, NODATASUM); - } else if (strncmp(param->string, "lzo", 3) =3D=3D 0) { + } else if (btrfs_match_compress_type(string, "lzo", false)) { ctx->compress_type =3D BTRFS_COMPRESS_LZO; ctx->compress_level =3D 0; btrfs_set_opt(ctx->mount_opt, COMPRESS); btrfs_clear_opt(ctx->mount_opt, NODATACOW); btrfs_clear_opt(ctx->mount_opt, NODATASUM); - } else if (strncmp(param->string, "zstd", 4) =3D=3D 0) { + } else if (btrfs_match_compress_type(string, "zstd", true)) { ctx->compress_type =3D BTRFS_COMPRESS_ZSTD; ctx->compress_level =3D btrfs_compress_str2level(BTRFS_COMPRESS_ZSTD, - param->string + 4); + string + 4); btrfs_set_opt(ctx->mount_opt, COMPRESS); btrfs_clear_opt(ctx->mount_opt, NODATACOW); btrfs_clear_opt(ctx->mount_opt, NODATASUM); - } else if (strncmp(param->string, "no", 2) =3D=3D 0) { + } else if (btrfs_match_compress_type(string, "no", false) || + btrfs_match_compress_type(string, "none", false)) { ctx->compress_level =3D 0; ctx->compress_type =3D 0; btrfs_clear_opt(ctx->mount_opt, COMPRESS); btrfs_clear_opt(ctx->mount_opt, FORCE_COMPRESS); } else { btrfs_err(NULL, "unrecognized compression value %s", - param->string); + string); return -EINVAL; } return 0; --=20 2.47.2