Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp7303786imu; Thu, 31 Jan 2019 08:11:28 -0800 (PST) X-Google-Smtp-Source: ALg8bN7gPh4knIahRiNoRSMmpQJfkG3Yvuk9AuDQQPgLXNtUmv8Bly+FaAWiW94n3UwJo3X+ot0j X-Received: by 2002:a65:5bc4:: with SMTP id o4mr32385672pgr.426.1548951088388; Thu, 31 Jan 2019 08:11:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548951088; cv=none; d=google.com; s=arc-20160816; b=taOKeQ740qi3bHV4opAyv3OtHvRkrrHgmfEcfKw/GI0/F2PrE05aHubxIp/hSrJedm CKcleqPNl8THI/fWfyrZ9sAfkbMZaRp4p00TBbfL2o1ebi4FXmKa3aHVLfI+0jAeQNzZ LBPd82PAtUl0SvRUS5+8qIzU/NyjVN+CYBm9pz/9vZYuzGIeeTf/7N9Mo+I80I2N2XsA 9E2Yt697Fz09zIwmKEU84DU+9nkrO06ZfzTlbhyPvMFZvxAPI4/I2kK7paMvuQI+Vedr mCRAvX1h5L73xhAxhYY7gaWWe9GzYhXy955gX3YeeITM+tGYIJ5wz0fettjOvGdOFAem 12fA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:mail-followup-to :reply-to:message-id:subject:cc:to:from:date; bh=EEUJxAVCG8IAtXwwz8RjWL6JCMXMkiVLVWIaWw4kP54=; b=Bigwjc80LXOQ2PzxHdfly0RhTqqu5qQNbeXB61Z0oT2B/X6i5/LOf9flCq7mkGNaOM SY0rYNKr/OG2A3TmW5WSujv8hwBCHixLcgbQO39dQg6psrHIfe8DF/DSaWgVtZ3wouvg prtktXZ2lYeDDd+wminAFU9UDHMNGlptU7UzJSzinzM9GfGVNbjBrdZNbrZ9Shl0OVPr tlHwnVFF8QTmHFE8iXZEvHawTIEhEpkbedLFjW0i2FfzJUHJaBgj9uoBIc0WHHSnI9n7 Z+M6JWFu1vlAHitu8AptDKwe5XnwWLkC36lf7ApiG2gP3tQzRWLPP6J82mGpKaTFbuDf TOmQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h16si4390267pgh.283.2019.01.31.08.11.11; Thu, 31 Jan 2019 08:11:28 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388131AbfAaQK5 (ORCPT + 99 others); Thu, 31 Jan 2019 11:10:57 -0500 Received: from mx2.suse.de ([195.135.220.15]:55648 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726355AbfAaQK5 (ORCPT ); Thu, 31 Jan 2019 11:10:57 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 73637B04E; Thu, 31 Jan 2019 16:10:54 +0000 (UTC) Received: by ds.suse.cz (Postfix, from userid 10065) id 0B9EADA7D6; Thu, 31 Jan 2019 17:10:19 +0100 (CET) Date: Thu, 31 Jan 2019 17:10:19 +0100 From: David Sterba To: Dennis Zhou Cc: David Sterba , Josef Bacik , Chris Mason , Omar Sandoval , Nick Terrell , kernel-team@fb.com, linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 03/11] btrfs: manage heuristic workspace as index 0 Message-ID: <20190131161019.GL2900@twin.jikos.cz> Reply-To: dsterba@suse.cz Mail-Followup-To: dsterba@suse.cz, Dennis Zhou , David Sterba , Josef Bacik , Chris Mason , Omar Sandoval , Nick Terrell , kernel-team@fb.com, linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org References: <20190128212437.11597-1-dennis@kernel.org> <20190128212437.11597-4-dennis@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190128212437.11597-4-dennis@kernel.org> User-Agent: Mutt/1.5.23.1 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jan 28, 2019 at 04:24:29PM -0500, Dennis Zhou wrote: > While the heuristic workspaces aren't really compression workspaces, > they use the same interface for managing them. So rather than branching, > let's just handle them once again as the index 0 compression type. > > Signed-off-by: Dennis Zhou > +const struct btrfs_compress_op btrfs_heuristic_compress = { > + .alloc_workspace = alloc_heuristic_ws, > + .free_workspace = free_heuristic_ws, > +}; > struct workspace_manager { > struct list_head idle_ws; > spinlock_t ws_lock; > @@ -782,9 +789,8 @@ struct workspace_manager { > > static struct workspace_manager wsm[BTRFS_COMPRESS_TYPES]; This deserves a comment that the 0th workspace is for the heuristics. > --- a/fs/btrfs/compression.h > +++ b/fs/btrfs/compression.h > @@ -97,7 +97,7 @@ enum btrfs_compression_type { > BTRFS_COMPRESS_ZLIB = 1, > BTRFS_COMPRESS_LZO = 2, > BTRFS_COMPRESS_ZSTD = 3, > - BTRFS_COMPRESS_TYPES = 3, > + BTRFS_COMPRESS_TYPES = 4, And here too, as there are only 3 compressors but 4 types as value of the enum. Or rename BTRFS_COMPRESS_TYPES if you find a better name. > }; > > struct btrfs_compress_op { > @@ -125,6 +125,7 @@ struct btrfs_compress_op { > void (*set_level)(struct list_head *ws, unsigned int type); > }; > > +extern const struct btrfs_compress_op btrfs_heuristic_compress; > extern const struct btrfs_compress_op btrfs_zlib_compress; > extern const struct btrfs_compress_op btrfs_lzo_compress; > extern const struct btrfs_compress_op btrfs_zstd_compress; > diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c > index 9c8e1734429c..20081465a451 100644 > --- a/fs/btrfs/ioctl.c > +++ b/fs/btrfs/ioctl.c > @@ -1410,7 +1410,7 @@ int btrfs_defrag_file(struct inode *inode, struct file *file, > return -EINVAL; > > if (do_compress) { > - if (range->compress_type > BTRFS_COMPRESS_TYPES) > + if (range->compress_type >= BTRFS_COMPRESS_TYPES) > return -EINVAL; > if (range->compress_type) > compress_type = range->compress_type; > diff --git a/fs/btrfs/tree-checker.c b/fs/btrfs/tree-checker.c > index a62e1e837a89..c88e146d8e99 100644 > --- a/fs/btrfs/tree-checker.c > +++ b/fs/btrfs/tree-checker.c > @@ -133,9 +133,9 @@ static int check_extent_data_item(struct btrfs_fs_info *fs_info, > * Support for new compression/encryption must introduce incompat flag, > * and must be caught in open_ctree(). > */ > - if (btrfs_file_extent_compression(leaf, fi) > BTRFS_COMPRESS_TYPES) { > + if (btrfs_file_extent_compression(leaf, fi) >= BTRFS_COMPRESS_TYPES) { > file_extent_err(fs_info, leaf, slot, > - "invalid compression for file extent, have %u expect range [0, %u]", > + "invalid compression for file extent, have %u expect range [0, %u)", > btrfs_file_extent_compression(leaf, fi), > BTRFS_COMPRESS_TYPES); This might become a bit confusing, the message is updated to say [0, 4) but I'm not sure this is commonly understood that 4 does not belong there. Either do -1 or define a new enum that contains the maximum number so BTRFS_COMPRESS_TYPES is not overloaded.