From patchwork Mon Nov 17 10:36:55 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 5317331 Return-Path: X-Original-To: patchwork-linux-btrfs@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 C53739F1E1 for ; Mon, 17 Nov 2014 10:41:13 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id EDA7020160 for ; Mon, 17 Nov 2014 10:41:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1588720136 for ; Mon, 17 Nov 2014 10:41:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752505AbaKQKlI (ORCPT ); Mon, 17 Nov 2014 05:41:08 -0500 Received: from mail-pa0-f48.google.com ([209.85.220.48]:53302 "EHLO mail-pa0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752501AbaKQKhX (ORCPT ); Mon, 17 Nov 2014 05:37:23 -0500 Received: by mail-pa0-f48.google.com with SMTP id rd3so8396708pab.21 for ; Mon, 17 Nov 2014 02:37:22 -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=8OVN0JcZNBMEKbEPXDUA80ozwWPo/pJf3vBFJKd5JHI=; b=Fn3D7JnFTqdfjs4PmSgH7e/KU9tv5VEavIixvkm/BShs6bLWJZ8Xp7vN1NRvBAQw4O W3DQX+AdMl0KOCk72Xwb0WJCVsvAOZa1sgVXTh1S+1xdoonjBv1zzntRLf6skG2pn9Wa RdUcLdj+75vbkxgUjr2ymfRgAFUyxsZLY+MplFgVvl2MZL6AKGSbF1+P+5hE0YnqQaT4 aPURPqtdEGhL3oQkrpCfYHG+wj7MJgv39Mh5LmYfgJcw8rgVM9XXDEl3Vjjfg+R9va7h tc0CMPnCkPUW8p6afoW+V2pH4/UVIxEqQBVjveGvPnJV4iUk+K86vhe/ivEnJxSSXnv3 ljzg== X-Gm-Message-State: ALoCoQk7RQmWW9vchh0XnPhu+GzGKNgAuG94y144T7v4g9KLIfEkv1+jD+0N44kwwVnrKiCyWYcP X-Received: by 10.68.234.9 with SMTP id ua9mr28325533pbc.2.1416220642405; Mon, 17 Nov 2014 02:37:22 -0800 (PST) Received: from mew.home.network (c-24-19-133-29.hsd1.wa.comcast.net. [24.19.133.29]) by mx.google.com with ESMTPSA id hb6sm34680321pbc.31.2014.11.17.02.37.20 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 17 Nov 2014 02:37:21 -0800 (PST) From: Omar Sandoval To: linux-btrfs@vger.kernel.org Cc: Mel Gorman , linux-kernel@vger.kernel.org, , Omar Sandoval Subject: [RFC PATCH 2/6] btrfs: don't allow -C or +c chattrs on a swap file Date: Mon, 17 Nov 2014 02:36:55 -0800 Message-Id: <2142904afc8c21bd78d0d2e0450224109669a224.1416219974.git.osandov@osandov.com> X-Mailer: git-send-email 2.1.3 In-Reply-To: References: In-Reply-To: References: Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@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 e3b458a..7aee8cf 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)