From patchwork Wed Jun 25 21:36:02 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 4424481 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 0F0579F1D6 for ; Wed, 25 Jun 2014 20:36:24 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3573520176 for ; Wed, 25 Jun 2014 20:36:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5D9DB20155 for ; Wed, 25 Jun 2014 20:36:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754447AbaFYUgS (ORCPT ); Wed, 25 Jun 2014 16:36:18 -0400 Received: from mail-wg0-f47.google.com ([74.125.82.47]:34468 "EHLO mail-wg0-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752899AbaFYUgR (ORCPT ); Wed, 25 Jun 2014 16:36:17 -0400 Received: by mail-wg0-f47.google.com with SMTP id k14so2642695wgh.18 for ; Wed, 25 Jun 2014 13:36:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=4pbwDTX0FGDDg3dpBKsF0ajggdMuSXGXAtZ7tX80qBA=; b=yUv3oKFrgH5gtd5KwfpgNK95/XsPRzI1cqULNFBDflDv2ekzTrMWQOK5gia5imgHG9 Amg1+mI/lWZcv7U/Hr5LuybIDElDpZh99pRbYXS+kW+NabCuWQADxju9w0pTqhhlgkPC Tu+ak/44bhhOThXtkmMeOk3LGT/ZNpeihglfM4G4h7ezzLoHVishVnF4+Z0Jitvu2Qjk GSnVAhVOlYESQjdYAPiH2Tbo8hhtVsCKRPuBMxrsJy6yk/ecd6ar33HGXJ3VKtQpTFmq NZ1rkyvIwe0gwp+87vUnNk+ZnnWs/ELvvZzMYiYbLBhGAObUyObspjXHuaEi1oVYmAsu uN+Q== X-Received: by 10.194.48.8 with SMTP id h8mr12133577wjn.106.1403728575481; Wed, 25 Jun 2014 13:36:15 -0700 (PDT) Received: from debian-vm3.lan (bl10-142-244.dsl.telepac.pt. [85.243.142.244]) by mx.google.com with ESMTPSA id wz3sm9639412wjc.39.2014.06.25.13.36.14 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 25 Jun 2014 13:36:14 -0700 (PDT) From: Filipe David Borba Manana To: linux-btrfs@vger.kernel.org Cc: Filipe David Borba Manana Subject: [PATCH] Btrfs: atomically set inode->i_flags in btrfs_update_iflags Date: Wed, 25 Jun 2014 22:36:02 +0100 Message-Id: <1403732162-22405-1-git-send-email-fdmanana@gmail.com> X-Mailer: git-send-email 1.9.1 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.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham 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 This change is based on the corresponding recent change for ext4: ext4: atomically set inode->i_flags in ext4_set_inode_flags() That has the following commit message that applies to btrfs as well: "Use cmpxchg() to atomically set i_flags instead of clearing out the S_IMMUTABLE, S_APPEND, etc. flags and then setting them from the EXT4_IMMUTABLE_FL, EXT4_APPEND_FL flags, since this opens up a race where an immutable file has the immutable flag cleared for a brief window of time." Replacing EXT4_IMMUTABLE_FL and EXT4_APPEND_FL with BTRFS_INODE_IMMUTABLE and BTRFS_INODE_APPEND, respectively. Signed-off-by: Filipe David Borba Manana Reviewed-by: David Sterba Reviewed-by: Satoru Takeuchi --- fs/btrfs/ioctl.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index 6ea1546..02dc64b 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -136,19 +136,22 @@ static unsigned int btrfs_flags_to_ioctl(unsigned int flags) void btrfs_update_iflags(struct inode *inode) { struct btrfs_inode *ip = BTRFS_I(inode); - - inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC); + unsigned int new_fl = 0; if (ip->flags & BTRFS_INODE_SYNC) - inode->i_flags |= S_SYNC; + new_fl |= S_SYNC; if (ip->flags & BTRFS_INODE_IMMUTABLE) - inode->i_flags |= S_IMMUTABLE; + new_fl |= S_IMMUTABLE; if (ip->flags & BTRFS_INODE_APPEND) - inode->i_flags |= S_APPEND; + new_fl |= S_APPEND; if (ip->flags & BTRFS_INODE_NOATIME) - inode->i_flags |= S_NOATIME; + new_fl |= S_NOATIME; if (ip->flags & BTRFS_INODE_DIRSYNC) - inode->i_flags |= S_DIRSYNC; + new_fl |= S_DIRSYNC; + + set_mask_bits(&inode->i_flags, + S_SYNC | S_APPEND | S_IMMUTABLE | S_NOATIME | S_DIRSYNC, + new_fl); } /*