Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp6443569imu; Wed, 30 Jan 2019 15:02:15 -0800 (PST) X-Google-Smtp-Source: ALg8bN6sQk85SNQ3ewqP/o49KF7ECpURZthD0ertqNvMttKkRkKhpA5Kum71Fh5eEXlI43+0tBzE X-Received: by 2002:a63:b81a:: with SMTP id p26mr29825519pge.433.1548889335090; Wed, 30 Jan 2019 15:02:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548889335; cv=none; d=google.com; s=arc-20160816; b=I0UnSZxQea3WjmYRTAJq2KKVpl9KLTAiISVFBmcgcy4m9PeGC5/iU4qxNUe+oVaIP8 cGHpgeNzWMnUUFC0EFAToqFeNJQfBpB+s5XyADE/W5pb0z4xWR8h3LWVgLZUmiv9vm7a AJPDGxp60G3qQrAgbD3TT8kzdbP0+yeWJe9Hn1ijZyGpXW41Ffw7KPUgNwefykwc/nFE oNAu3FMZNhlNfE/5lavJGNw3vyolA2+u8yaCJPM8ONvqE1saUbAQ4CaIXQw9SoJaDrLz 8IIH8OLVlv/BT1DxkGG3NbBU2oh5HybBlfn9dyVO2LM92WIGNjbXr5W7xSxCdcNOdSDs W3xA== 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-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=+dJ04W65N3iNVrVUolqvLBzs+zc0DbcVcz/eBhNzGVo=; b=bu4L/OEjFw22TnRo97hQL9kP8rH0Q/nyxDSw1kOWoSvzucoaoc453OwxRwwe5XM/HY Tnkj2Jj6wopnUESG+N7QsVGGg1cQiHmTE8dW6MmwnvcfL3KzXn3KXfNgKc4LbkgIKW6s t1/Fi11HYXWoxirz9B4S0ZYHbthzoPLyyoaOpRoD5VoPFVocWI+Z6InKHPp1FCrZCeY7 I+UAklJiitzD11pETrbj8OKnMUqbARyzvyDbkvGNUB8PQ6xNNOxBaDW9eOkFdV5DwIYq ujqD4IG3JJC+2L8OoRInYqPTBqCx6a9WcRh/xAMPg1xNnO1IPNTkXe24bufXWDvFc8zE avFw== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g18si2590988pgg.522.2019.01.30.15.01.58; Wed, 30 Jan 2019 15:02:15 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729486AbfA3W70 (ORCPT + 99 others); Wed, 30 Jan 2019 17:59:26 -0500 Received: from mail-yb1-f193.google.com ([209.85.219.193]:46301 "EHLO mail-yb1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727114AbfA3W7Z (ORCPT ); Wed, 30 Jan 2019 17:59:25 -0500 Received: by mail-yb1-f193.google.com with SMTP id 7so519486ybp.13; Wed, 30 Jan 2019 14:59:24 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to:user-agent; bh=+dJ04W65N3iNVrVUolqvLBzs+zc0DbcVcz/eBhNzGVo=; b=DWrxMlDUI5rRCrheIdE1/2lxJ8rbbRbvkAqivu5gfzKBm3ElvAMU8sRzr4c/1YgTNf U/rUAsiAZZdcvjEkGJ3HZ1p+QXrWv+6OC7qxRdaK724vDGkggPsmSjROmhNbTbltypj7 FXGpU2zfhcdmCm5zaftGxDoeSE4619+bkomLzNRZ3JwFzj+DFy1ZeOI+Q65wUCSTK9wF wve+vgeGDGYC3/rOo2fhCjf4Kb2Ux5b6U2pHTg9pMruS5FynL3Zw4pGe7uEv3iHoX7vH 8zYE2DPIF/g1YVlcLlfin+Dfd7b81ypil76cYcl75UT0hO0nWS8UQUIaCx964ToqQuIA GnZQ== X-Gm-Message-State: AHQUAuaw105l7vYpoPzi5ZrC/nboWO9Q8vL4xsfPdZ0LZOZl99RK6+FH hI4eaVpS0CGo1aAKH3ofZn4= X-Received: by 2002:a25:e09:: with SMTP id 9mr2795858ybo.226.1548886019940; Wed, 30 Jan 2019 14:06:59 -0800 (PST) Received: from dennisz-mbp.dhcp.thefacebook.com ([2620:10d:c091:200::5:f3d1]) by smtp.gmail.com with ESMTPSA id i13sm914751ywe.53.2019.01.30.14.06.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 30 Jan 2019 14:06:58 -0800 (PST) Date: Wed, 30 Jan 2019 17:06:56 -0500 From: Dennis Zhou To: Nikolay Borisov Cc: 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 Subject: Re: [PATCH 09/11] btrfs: change set_level() to bound the level passed in Message-ID: <20190130220656.GA50584@dennisz-mbp.dhcp.thefacebook.com> References: <20190128212437.11597-1-dennis@kernel.org> <20190128212437.11597-10-dennis@kernel.org> <372d47b8-457d-db5d-61f4-de7b901c5e78@suse.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <372d47b8-457d-db5d-61f4-de7b901c5e78@suse.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jan 29, 2019 at 10:14:18AM +0200, Nikolay Borisov wrote: > > > On 28.01.19 г. 23:24 ч., Dennis Zhou wrote: > > Currently, the only user of set_level() is zlib which sets an internal > > workspace parameter. As level is now plumbed into get_workspace(), this > > can be handled there rather than separately. > > > > This repurposes set_level() to bound the level passed in so it can be > > used when setting the mounts compression level and as well as verifying > > the level before getting a workspace. The other benefit is this divides > > the meaning of compress(0) and get_workspace(0). The former means we > > want to use the default compression level of the compression type. The > > latter means we can use any workspace available. > > > > Signed-off-by: Dennis Zhou > > --- > } > > diff --git a/fs/btrfs/compression.h b/fs/btrfs/compression.h > > index e3627139bc5c..d607be40aa0e 100644 > > --- a/fs/btrfs/compression.h > > +++ b/fs/btrfs/compression.h > > @@ -90,7 +90,7 @@ blk_status_t btrfs_submit_compressed_write(struct inode *inode, u64 start, > > blk_status_t btrfs_submit_compressed_read(struct inode *inode, struct bio *bio, > > int mirror_num, unsigned long bio_flags); > > > > -unsigned btrfs_compress_str2level(const char *str); > > +unsigned int btrfs_compress_str2level(unsigned int type, const char *str); > > > > enum btrfs_compression_type { > > BTRFS_COMPRESS_NONE = 0, > > @@ -149,7 +149,7 @@ struct btrfs_compress_op { > > unsigned long start_byte, > > size_t srclen, size_t destlen); > > > > - void (*set_level)(struct list_head *ws, unsigned int type); > > + unsigned int (*set_level)(unsigned int level); > > It might be good to document the return value since this is an > interface. AFAICS implementations are required to return the actual > level set irrespective of what level was passed in, no? > > > }; Yeah that makes sense. I've added a comment about it in btrfs_compress_op. > > > > static void zlib_put_workspace(struct list_head *ws) > > @@ -413,15 +418,14 @@ static int zlib_decompress(struct list_head *ws, unsigned char *data_in, > > return ret; > > } > > > > -static void zlib_set_level(struct list_head *ws, unsigned int type) > > +static unsigned int zlib_set_level(unsigned int level) > > { > > - struct workspace *workspace = list_entry(ws, struct workspace, list); > > - unsigned int level = BTRFS_COMPRESS_LEVEL(type); > > - > > - if (level > 9) > > + if (!level) > > + level = BTRFS_ZLIB_DEFAULT_LEVEL; > > + else if (level > 9) > > level = 9; > > nit: This makes it a bit more obvious (IMO) that you are essentially > doing max: > > if (!level) > level = BTRFS_ZLIB_DEFAULT_LEVEL; > level = max(level, 9); > I agree. I've updated it in both places. It should be min instead of max though. Thanks, Dennis