From patchwork Tue Apr 24 23:37:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Timofey Titovets X-Patchwork-Id: 10361207 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 9985160209 for ; Tue, 24 Apr 2018 23:41:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8C43C28DCC for ; Tue, 24 Apr 2018 23:41:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 80D8D28E8F; Tue, 24 Apr 2018 23:41: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.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_WEB,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 1B3F728DCC for ; Tue, 24 Apr 2018 23:41:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751184AbeDXXlH (ORCPT ); Tue, 24 Apr 2018 19:41:07 -0400 Received: from mail-lf0-f68.google.com ([209.85.215.68]:37855 "EHLO mail-lf0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750766AbeDXXlA (ORCPT ); Tue, 24 Apr 2018 19:41:00 -0400 Received: by mail-lf0-f68.google.com with SMTP id b23-v6so22835108lfg.4 for ; Tue, 24 Apr 2018 16:40:59 -0700 (PDT) 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=MDL0fdi2YfXwTT2yoSxfEqBzeijgKQ3wA8iVvjR3H50N30I8iPGMRA3wod5/d4Lxh3 +CE/nSD3rwaByBK36rWSNWFfifblZPaJcMmT+hBpCPVsB/qLdNHm3ZkBNjN8N3BG+CLx /HDmuIl4NwMBEgq2OQQvBCxfL2vAYbSWiuazXUFMHMxS2imXp2ZHk7SedYu8dd5oegBi 5kemZRHcSH8uJAVJy8V0Msgo6HaDKaaFx8YyRrRD/BgRsUwEjR7HQiX89SYBHl2/Alyo UeedAsz7+PVPlrIGRpGyUAa6OaZlJU1U49W9w8UOOC+CCfaShAmoEzJLkmMCWbFCFHqF G2tw== 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=sV+rCeQGwgmEjiPJcKrlgObIYgedTMQDXoG8WtMdCj9/dDAPqMxegcuGLWbyr2z6Vj PglD6cQ2DTGvfdQ5B1A/icp9dW4aIEAJ+LxIPDn0rSR9oFQWIpXnIY9mXrfXpbhTI3ev 2mUpzD/Tga/rhrUhEQw4BrYUSGHS1jkGdYViShULQR11nvE+LUXESW+kydG+XnU5OzDf V1wmelQrDvsBnKPLqq1v3sAxvHnxYszLiihq0rjp9WDyyp7Gpzw+XLvHtcuTnhEeIm3k /faPyRFly3skUy0l+CB1RgrkxnhtDbMPfl09FMkPW3r2ef/l51heBPBpIcxBhClYAcfD TsGA== X-Gm-Message-State: ALQs6tC5AW5BbroO9sRH7V/LTa1xKxOjgSD48Lxp7EFgrKK49g4bS5bD +qvu8X/2aYSQrNUCZq0To5+VbA== X-Google-Smtp-Source: AB8JxZoBgvqLI/JLfzn4KXM2yyJ7YO5IMkgPhAKzqqMwrzWWYb2MHTml8aXAtYKYrUscN6HaxNWjWQ== X-Received: by 10.46.16.130 with SMTP id 2mr770755ljq.9.1524613258433; Tue, 24 Apr 2018 16:40:58 -0700 (PDT) Received: from localhost.localdomain ([178.121.235.109]) by smtp.gmail.com with ESMTPSA id 66-v6sm3618547lfr.52.2018.04.24.16.40.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 24 Apr 2018 16:40:57 -0700 (PDT) From: Timofey Titovets To: linux-btrfs@vger.kernel.org Cc: Timofey Titovets Subject: [PATCH 3/4] [RESEND] Btrfs: allow btrfs_defrag_file() uncompress files on defragmentation Date: Wed, 25 Apr 2018 02:37:16 +0300 Message-Id: <20180424233717.31283-4-nefelim4ag@gmail.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180424233717.31283-1-nefelim4ag@gmail.com> References: <20180424233717.31283-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); }