Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3925812imu; Mon, 28 Jan 2019 13:28:02 -0800 (PST) X-Google-Smtp-Source: ALg8bN6kQn6gK78NnmBz5amYoXDP97lvTaX32NF3gkd2rXghaO+DGrCnrtVlFPoU2yj4iXwjp3jQ X-Received: by 2002:a65:4784:: with SMTP id e4mr20867549pgs.12.1548710882124; Mon, 28 Jan 2019 13:28:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548710882; cv=none; d=google.com; s=arc-20160816; b=FWNFC1P1nEn3aW4lzrIZ8V8uLHUwTMu3BkX1WjuVaJ2XD8ugx83LT+odgf67A7UBgJ p9LBL3kj6G/kHGlkIbG2MUKKhIJdpB5LqPoFWm5pnJnBNpt4+9DDNxOFT8Lkqph2mfSZ IYvrIL6Fu3X74MXMTmNeg2jpBtiGQFvngs/nJqzYYh11/tBlmH7Mk15Mcd4nF6BKLqZE k+6DzxHwc67qY2yk5O2SgdNIKkWd+8asmz8aFUyxZDz4frxFduiAI52KF9Rc1xCCpAL+ HILNJj+JWjvIZ3eaXngcIwVVlu7Y+c3xKeFwaBreKbsYrK1+KBw7IJzlTnog1yJPIq5c hOgw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=urZHYaHVYTvaWvnMKkIGbrK6fCowBa9M7UNu2RVTVI8=; b=FETZ5U0xc86IM6PX4aWnpw3+z8VBLfBHNkESYjfUje324XOZxUNZQPVgLAlofW0EdX raAQRXy93UgQ/M0wGK1Kn/+BytA2UxdakWuucC29drfSSY/yYQuXgBfj76PprCMGSWWQ 01/J8ikAZwJ0lQN1sCroiK4DY23uPb8QIp7Yib4RywI6/6AEdOz00YZIB83gn6CPrAmA 6GmG2hXe+Mgq9HehXAgakEdwRC3RiUPejDneR6pG9adIYUHfhhBfDJSJoKxEV3/RXT7c MzPx6szBpPciQ7I6MDUWb5SYStA6FWHINgFHhtwJxFa5G/tKrcKN+0EYymwv0D04MJvb EmEQ== 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 j29si33638547pga.550.2019.01.28.13.27.46; Mon, 28 Jan 2019 13:28:02 -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 S1728257AbfA1VYt (ORCPT + 99 others); Mon, 28 Jan 2019 16:24:49 -0500 Received: from mail-yb1-f193.google.com ([209.85.219.193]:41497 "EHLO mail-yb1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728111AbfA1VYr (ORCPT ); Mon, 28 Jan 2019 16:24:47 -0500 Received: by mail-yb1-f193.google.com with SMTP id n6so1916052ybg.8; Mon, 28 Jan 2019 13:24:46 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=urZHYaHVYTvaWvnMKkIGbrK6fCowBa9M7UNu2RVTVI8=; b=p/QRTCCL/QGTnFucc6pVxApqjerSboKfViaOdy5hYjE2pZwK7TGJXThqmkNz8bo3nP RCkc7OeDbNt3M0FClF47Y2m+SpUJSrOi8GQhshPgdtqIqevCZSxKzGtta78dHfxgch6x XNvlpoIiU1w4Xo7FQZ2bszVv0KBCZ39nhtu5OOddJI8wUb/ldMgxq97qDP+hTd1AGrE6 lJE0JczYKQnvh3fTozUNaSrw+qlJbj5U+Q4bUg50Xy67az+RobqaZiTkr7RoHi/P3E5t 2dkr8xCaeGKNOck/V0pugCWX0jg1ZNP1gxyovW9rOIrJX1OXNrRwb6BqS0m3HjO0AyjH qtoA== X-Gm-Message-State: AJcUukdfB2ijFKjBrIwAGf66IKAsyM8xrQenPHa7Tu6PP+ZEcGoDGNBd 4DDVDSTcfjnk3lWQRPs04iQ= X-Received: by 2002:a25:6ec5:: with SMTP id j188mr21995242ybc.129.1548710686109; Mon, 28 Jan 2019 13:24:46 -0800 (PST) Received: from dennisz-mbp.thefacebook.com ([199.201.65.135]) by smtp.gmail.com with ESMTPSA id a7sm24170415ywb.18.2019.01.28.13.24.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 28 Jan 2019 13:24:45 -0800 (PST) From: Dennis Zhou To: David Sterba , Josef Bacik , Chris Mason , Omar Sandoval , Nick Terrell Cc: kernel-team@fb.com, linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, Dennis Zhou Subject: [PATCH 01/11] btrfs: add macros for compression type and level Date: Mon, 28 Jan 2019 16:24:27 -0500 Message-Id: <20190128212437.11597-2-dennis@kernel.org> X-Mailer: git-send-email 2.13.5 In-Reply-To: <20190128212437.11597-1-dennis@kernel.org> References: <20190128212437.11597-1-dennis@kernel.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org It is very easy to miss places that rely on a certain bitshifting for decyphering the type_level overloading. Make macros handle this instead. Signed-off-by: Dennis Zhou --- fs/btrfs/compression.c | 2 +- fs/btrfs/compression.h | 3 +++ fs/btrfs/zlib.c | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c index 548057630b69..586f95ac0aea 100644 --- a/fs/btrfs/compression.c +++ b/fs/btrfs/compression.c @@ -1036,9 +1036,9 @@ int btrfs_compress_pages(unsigned int type_level, struct address_space *mapping, unsigned long *total_in, unsigned long *total_out) { + int type = BTRFS_COMPRESS_TYPE(type_level); struct list_head *workspace; int ret; - int type = type_level & 0xF; workspace = find_workspace(type); diff --git a/fs/btrfs/compression.h b/fs/btrfs/compression.h index ddda9b80bf20..69a9197dadc3 100644 --- a/fs/btrfs/compression.h +++ b/fs/btrfs/compression.h @@ -25,6 +25,9 @@ #define BTRFS_ZLIB_DEFAULT_LEVEL 3 +#define BTRFS_COMPRESS_TYPE(type_level) (type_level & 0xF) +#define BTRFS_COMPRESS_LEVEL(type_level) ((type_level & 0xF0) >> 4) + struct compressed_bio { /* number of bios pending for this compressed extent */ refcount_t pending_bios; diff --git a/fs/btrfs/zlib.c b/fs/btrfs/zlib.c index 970ff3e35bb3..1480b3eee306 100644 --- a/fs/btrfs/zlib.c +++ b/fs/btrfs/zlib.c @@ -393,7 +393,7 @@ static int zlib_decompress(struct list_head *ws, unsigned char *data_in, static void zlib_set_level(struct list_head *ws, unsigned int type) { struct workspace *workspace = list_entry(ws, struct workspace, list); - unsigned level = (type & 0xF0) >> 4; + unsigned int level = BTRFS_COMPRESS_LEVEL(type); if (level > 9) level = 9; -- 2.17.1