From patchwork Tue Dec 19 10:02:46 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Timofey Titovets X-Patchwork-Id: 10122905 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 047DE6019C for ; Tue, 19 Dec 2017 10:03:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E9F1E2905F for ; Tue, 19 Dec 2017 10:03:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DE96929165; Tue, 19 Dec 2017 10:03:08 +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 83A242905F for ; Tue, 19 Dec 2017 10:03:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933169AbdLSKDH (ORCPT ); Tue, 19 Dec 2017 05:03:07 -0500 Received: from mail-wr0-f195.google.com ([209.85.128.195]:36844 "EHLO mail-wr0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1761696AbdLSKDA (ORCPT ); Tue, 19 Dec 2017 05:03:00 -0500 Received: by mail-wr0-f195.google.com with SMTP id u19so12056562wrc.3 for ; Tue, 19 Dec 2017 02:03:00 -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:in-reply-to:references; bh=m9UBnECX6kW1502bUdtnc3kLChn8tPpbo7HZzM48wGM=; b=FojCos0tU02Wj4wph4t/IVwqlJYnbZR0GTS7MezAaFw3+BCFC+r8XMyYebPcAcS+G4 L263Q88cnuTfzkUcTDtXmxr+4LD/U2R3LBoJ5hQdx2Eu6diAGrikQTXXsLJLFRRylfia 5XdvnGRoql0Kk/Pcxzdy3JeLZMOZgiiPTgjjG15O01rVplzxQ/kvYLwi5tOCMIz37B89 TmHU8SnyZFzTMGa3iWSwhTVKZsCz8FpfrvXmrZsPcSMq78Q1BtHR02RqMgK2WA4vLztJ 347t8bO3OnWX5NgNG6uqQAvGoiya4xRLeAYa3K4sXmVkJfR3UdGlwV5TysFiDEeyejAM dvUQ== 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=m9UBnECX6kW1502bUdtnc3kLChn8tPpbo7HZzM48wGM=; b=sd61o/HV9VjpJUnXp7+XKi2d58r2ew1mVGRiP4RqK6VAkvDCsUooYT7Vu6TZh5mn42 k/gkLutx1nUTZJ5+B715ztze5NtZuhdTIb04QWBuKA/g/CQOdGqecmUZtkBk+u2Dg2n5 QaI3MaUWJcx9fOB6xGD5SgcrIEIzRSAHtUHbgSDECvFpJGQaPER74brBqd5cGl3HXxYl HgJvi8UU5oKjoMgfcGdgpon2EVzGUYu35UT5FHGNKGk+f+8QNc2kEPQIE/G387GCtZpi 6gUNs/7qflXb8smO21XzCeBOllkS62XGulGA8i1sG7fvkrh+RHurIcMOgnYenbvS5beG 4vnQ== X-Gm-Message-State: AKGB3mIDXs/FEKdoqAQqwuskbUpSBvTgpPYIKVGw2zmdlf+wMnVMj6UE gGSS1vQ80xU4mLAU1kqcGsdqvg== X-Google-Smtp-Source: ACJfBouj9YB/GOK7jRUQqWWX4BzLhgCqMyZRSHbacaPQr09spPVj2psZSHCvqL6atHansE+kdNLhdg== X-Received: by 10.223.150.20 with SMTP id b20mr4309847wra.5.1513677779188; Tue, 19 Dec 2017 02:02:59 -0800 (PST) Received: from titovetst-beplan.itransition.corp ([93.171.6.182]) by smtp.gmail.com with ESMTPSA id s70sm1404372wma.37.2017.12.19.02.02.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 19 Dec 2017 02:02:58 -0800 (PST) From: Timofey Titovets To: linux-btrfs@vger.kernel.org Cc: Timofey Titovets Subject: [PATCH 3/4] Btrfs: allow btrfs_defrag_file() uncompress files on defragmentation Date: Tue, 19 Dec 2017 13:02:46 +0300 Message-Id: <20171219100247.13880-4-nefelim4ag@gmail.com> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20171219100247.13880-1-nefelim4ag@gmail.com> References: <20171219100247.13880-1-nefelim4ag@gmail.com> 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 recompress files with specified compression type. Allow set compression type to none, while call defrag, and use BTRFS_DEFRAG_RANGE_COMPRESS as flag, that user request change of compression type. 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 b29ea1f0f621..40f5e5678eac 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); }