From patchwork Fri Dec 15 21:27:21 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Timofey Titovets X-Patchwork-Id: 10116043 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 947756019C for ; Fri, 15 Dec 2017 21:28:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 857B62A168 for ; Fri, 15 Dec 2017 21:28:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 77A0B2A172; Fri, 15 Dec 2017 21:28:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 194E72A168 for ; Fri, 15 Dec 2017 21:28:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756633AbdLOV2G (ORCPT ); Fri, 15 Dec 2017 16:28:06 -0500 Received: from mail-wr0-f195.google.com ([209.85.128.195]:42114 "EHLO mail-wr0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756412AbdLOV2F (ORCPT ); Fri, 15 Dec 2017 16:28:05 -0500 Received: by mail-wr0-f195.google.com with SMTP id s66so9150860wrc.9 for ; Fri, 15 Dec 2017 13:28:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=fdRYbvuC6NcjgGKBjnCsnQ3a/SOjxcydvSvI/fCEIbE=; b=aXjRIVGc9QMIfCPBqbb7lQ4Xoom9H/KRFHF3Ulk2cf5ebaZqaU/3K8Y9pxir9sk7ew 6STNIpyXASj88ZVlhZujT6cBHto90Jq1+oBpVVrPJv7X2U/DYUT+RI1dwlXzye9SHn5/ Fmi2zZM8pEVytJbBuZWnb9q465im2vEWSDjWw1Gaqi81TvmfGcsNURkNxcFwqsUtxVPQ 6PoUi91Wj6d6ZmrxodvJAmlWkJ9qKZiolrPK/FcKEkTo8EPs+xPo6MSd+hN8GBrBnW6p 2GWVOQQaxxQVjdt4AM6xft7B7Wo5c+ufG1colQ60d4qB12qPW5WDWpgnRUVx8Zlowk7a 2aYw== 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; bh=fdRYbvuC6NcjgGKBjnCsnQ3a/SOjxcydvSvI/fCEIbE=; b=mkYl8mJNaE1xQrb91XGSTHRcqsg1ydpMsUGhCxOIEh/latioUxMj7X8uxSBpfhMFax 1zw6rmKU9BnNHVb/qRrmqf6FM+apFMUHC8/KqDJyQaQA74pqjQ5EDOkOYU6K5BTs0BSi GaqXbi8jmCKiBkPrYuAAuv8xmx6+eZBO+aMzNv8+mpcNteWJFdeKoFZN+sgyH1WMNhOy JCNFCDRMZG+yyC/NYkPOCIGvF8z34HA8Us0u9BT57N+OID8eBnsIdq1nESt5A7XATOjm 1W0Eit5hd2hzFhBH2445935ZNCUGnu3rKoZZ/6ROLwqxBDwbNRo0r8PNJp1bdKogjUjv CTHA== X-Gm-Message-State: AKGB3mLKun5rweC4fJO9aImBVNvwKzqk+DnmmbkN48zlKP+lC5kHXCGT /CGYlA7WtV17kGwbtEXz25oRsA== X-Google-Smtp-Source: ACJfBotVgF3snLt4znEcYyuWgxA04EkkE9tz+MSNwS+E9P7kHm9oJihGkNoh1UWltfwyjMVOPy55BA== X-Received: by 10.223.196.247 with SMTP id o52mr10423410wrf.119.1513373284408; Fri, 15 Dec 2017 13:28:04 -0800 (PST) Received: from titovetst-beplan.lan (nat6-minsk-pool-46-53-208-190.telecom.by. [46.53.208.190]) by smtp.gmail.com with ESMTPSA id l142sm9448146wmb.43.2017.12.15.13.28.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 15 Dec 2017 13:28:03 -0800 (PST) From: Timofey Titovets To: linux-btrfs@vger.kernel.org Cc: Timofey Titovets Subject: [PATCH] Btrfs: allow btrfs_defrag_file() uncompress files on defragmentation Date: Sat, 16 Dec 2017 00:27:21 +0300 Message-Id: <20171215212721.19866-1-nefelim4ag@gmail.com> X-Mailer: git-send-email 2.15.1 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Currently defrag ioctl only support compress files with specified compression type. Allow set compression type to none, while call defrag. Signed-off-by: Timofey Titovets --- fs/btrfs/btrfs_inode.h | 1 + fs/btrfs/inode.c | 4 ++-- fs/btrfs/ioctl.c | 17 ++++++++++------- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/fs/btrfs/btrfs_inode.h b/fs/btrfs/btrfs_inode.h index 63f0ccc92a71..9eb0c92ee4b4 100644 --- a/fs/btrfs/btrfs_inode.h +++ b/fs/btrfs/btrfs_inode.h @@ -187,6 +187,7 @@ struct btrfs_inode { * different from prop_compress and takes precedence if set */ unsigned defrag_compress; + unsigned change_compress; struct btrfs_delayed_node *delayed_node; diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 46df5e2a64e7..7af8f1784788 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -412,8 +412,8 @@ static inline int inode_need_compress(struct inode *inode, u64 start, u64 end) if (btrfs_test_opt(fs_info, FORCE_COMPRESS)) return 1; /* defrag ioctl */ - if (BTRFS_I(inode)->defrag_compress) - return 1; + if (BTRFS_I(inode)->change_compress) + return BTRFS_I(inode)->defrag_compress; /* bad compression ratios */ if (BTRFS_I(inode)->flags & BTRFS_INODE_NOCOMPRESS) return 0; diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index 12d4fa5d6dec..b777c8f53153 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -1276,7 +1276,7 @@ int btrfs_defrag_file(struct inode *inode, struct file *file, unsigned long cluster = max_cluster; u64 new_align = ~((u64)SZ_128K - 1); struct page **pages = NULL; - bool do_compress = range->flags & BTRFS_DEFRAG_RANGE_COMPRESS; + bool change_compress = range->flags & BTRFS_DEFRAG_RANGE_COMPRESS; if (isize == 0) return 0; @@ -1284,11 +1284,10 @@ int btrfs_defrag_file(struct inode *inode, struct file *file, if (range->start >= isize) return -EINVAL; - if (do_compress) { + if (change_compress) { if (range->compress_type > BTRFS_COMPRESS_TYPES) return -EINVAL; - if (range->compress_type) - compress_type = range->compress_type; + compress_type = range->compress_type; } if (extent_thresh == 0) @@ -1363,7 +1362,7 @@ int btrfs_defrag_file(struct inode *inode, struct file *file, if (!should_defrag_range(inode, (u64)i << PAGE_SHIFT, extent_thresh, &last_len, &skip, - &defrag_end, do_compress, + &defrag_end, change_compress, compress_type)){ unsigned long next; /* @@ -1392,8 +1391,11 @@ int btrfs_defrag_file(struct inode *inode, struct file *file, } inode_lock(inode); - if (do_compress) + if (change_compress) { + BTRFS_I(inode)->change_compress = change_compress; BTRFS_I(inode)->defrag_compress = compress_type; + } + ret = cluster_pages_for_defrag(inode, pages, i, cluster); if (ret < 0) { inode_unlock(inode); @@ -1449,8 +1451,9 @@ int btrfs_defrag_file(struct inode *inode, struct file *file, ret = defrag_count; out_ra: - if (do_compress) { + if (change_compress) { inode_lock(inode); + BTRFS_I(inode)->change_compress = 0; BTRFS_I(inode)->defrag_compress = BTRFS_COMPRESS_NONE; inode_unlock(inode); }