From patchwork Fri Nov 21 10:08:30 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 5353921 Return-Path: X-Original-To: patchwork-linux-nfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id B48DB9F2F1 for ; Fri, 21 Nov 2014 10:10:26 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 121F9200E6 for ; Fri, 21 Nov 2014 10:10:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 29002200E0 for ; Fri, 21 Nov 2014 10:10:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758281AbaKUKJs (ORCPT ); Fri, 21 Nov 2014 05:09:48 -0500 Received: from mail-pa0-f48.google.com ([209.85.220.48]:50678 "EHLO mail-pa0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757720AbaKUKJL (ORCPT ); Fri, 21 Nov 2014 05:09:11 -0500 Received: by mail-pa0-f48.google.com with SMTP id rd3so4569028pab.21 for ; Fri, 21 Nov 2014 02:09:11 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=517dDiZUtTn2q70Gr7kXilERT4tJNyOn4f5q+SbF/f8=; b=DmBMbdzbq3N4OCZO5OEzcpwQcfjubGS5dQGWOWJiSjknCQI1YwHZIdG03IgSkaoWvN 74mLS0pNSLeXrQZzz20i7u3sz9ZV12hGM0tVANOqZu+Y13rNsm4XQ29esKF1pWBGDrHd xXM+BDo4h+qCcSPHT/GBHsdqAk6l7lHasakT0LzA3PJ/cMvJQzjwVHy00LZdRSZFfM2G tou66h3wYXdqW2rHmbLPM3leI5HGLvkGkzCaVZfz3pbf3BmqhpsC9DJr+n5x3pJ0NMbp hAbN6VjD5fFGofhb4O0YozT9lE/Jme/ILC9/EQcMiE2xnmb4oLLy2Wr0gG2K5WGmSSBP bOrA== X-Gm-Message-State: ALoCoQle+AIY6u13+FE8fWQC4a5sOK5Ppg6cZbmvrKW/x76Smg5QlkULkoa0Z5IumGMj70GhOLnj X-Received: by 10.66.139.106 with SMTP id qx10mr5577722pab.138.1416564551147; Fri, 21 Nov 2014 02:09:11 -0800 (PST) Received: from mew.localdomain ([24.19.133.29]) by mx.google.com with ESMTPSA id g12sm4391480pdj.27.2014.11.21.02.09.09 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 21 Nov 2014 02:09:10 -0800 (PST) From: Omar Sandoval To: Alexander Viro , Andrew Morton , Chris Mason , Josef Bacik , linux-btrfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-nfs@vger.kernel.org, Trond Myklebust , Mel Gorman Cc: Omar Sandoval Subject: [PATCH v2 4/5] btrfs: don't allow -C or +c chattrs on a swap file Date: Fri, 21 Nov 2014 02:08:30 -0800 Message-Id: X-Mailer: git-send-email 2.1.3 In-Reply-To: References: In-Reply-To: References: Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP swap_activate will check for a compressed or copy-on-write file; we shouldn't allow it to become either once it has already been activated. Signed-off-by: Omar Sandoval --- fs/btrfs/ioctl.c | 50 +++++++++++++++++++++++++++++++------------------- 1 file changed, 31 insertions(+), 19 deletions(-) diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index 4399f0c..f022dce 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -293,14 +293,21 @@ static int btrfs_ioctl_setflags(struct file *file, void __user *arg) } } else { /* - * Revert back under same assuptions as above + * swap_activate checks that we don't swapon a copy-on-write + * file, but we must also make sure that it doesn't become + * copy-on-write. */ - if (S_ISREG(mode)) { - if (inode->i_size == 0) - ip->flags &= ~(BTRFS_INODE_NODATACOW - | BTRFS_INODE_NODATASUM); - } else { - ip->flags &= ~BTRFS_INODE_NODATACOW; + if (!IS_SWAPFILE(inode)) { + /* + * Revert back under same assumptions as above + */ + if (S_ISREG(mode)) { + if (inode->i_size == 0) + ip->flags &= ~(BTRFS_INODE_NODATACOW | + BTRFS_INODE_NODATASUM); + } else { + ip->flags &= ~BTRFS_INODE_NODATACOW; + } } } @@ -317,20 +324,25 @@ static int btrfs_ioctl_setflags(struct file *file, void __user *arg) if (ret && ret != -ENODATA) goto out_drop; } else if (flags & FS_COMPR_FL) { - const char *comp; - - ip->flags |= BTRFS_INODE_COMPRESS; - ip->flags &= ~BTRFS_INODE_NOCOMPRESS; + /* + * Like nodatacow, swap_activate checks that we don't swapon a + * compressed file, so we shouldn't let it become compressed. + */ + if (!IS_SWAPFILE(inode)) { + const char *comp; - if (root->fs_info->compress_type == BTRFS_COMPRESS_LZO) - comp = "lzo"; - else - comp = "zlib"; - ret = btrfs_set_prop(inode, "btrfs.compression", - comp, strlen(comp), 0); - if (ret) - goto out_drop; + ip->flags |= BTRFS_INODE_COMPRESS; + ip->flags &= ~BTRFS_INODE_NOCOMPRESS; + if (root->fs_info->compress_type == BTRFS_COMPRESS_LZO) + comp = "lzo"; + else + comp = "zlib"; + ret = btrfs_set_prop(inode, "btrfs.compression", + comp, strlen(comp), 0); + if (ret) + goto out_drop; + } } else { ret = btrfs_set_prop(inode, "btrfs.compression", NULL, 0, 0); if (ret && ret != -ENODATA)