From patchwork Fri May 30 16:56:24 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 4272141 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 D5CFD9F1D6 for ; Fri, 30 May 2014 15:56:42 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1692A201BC for ; Fri, 30 May 2014 15:56:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 34D4820171 for ; Fri, 30 May 2014 15:56:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965199AbaE3P4h (ORCPT ); Fri, 30 May 2014 11:56:37 -0400 Received: from mail-wg0-f44.google.com ([74.125.82.44]:57220 "EHLO mail-wg0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S964845AbaE3P4g (ORCPT ); Fri, 30 May 2014 11:56:36 -0400 Received: by mail-wg0-f44.google.com with SMTP id a1so2169153wgh.15 for ; Fri, 30 May 2014 08:56:35 -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=86eHttcEfEl+dae+bWAApkbz4iLaT8k8VQG41fDiD/4=; b=d8yA9OUBzZq/USDE7w2w91SflCklRGLZe1a1bWkyAQ6RS9lsDOs28URhVwoJUIDajP VaTlCkyhr0fw8zDQN1kVwjnsw8XbV7hZUaqvMMR7Ks3QNpy4AG3R3LASGKntx0HAe9uG bp2rXt0mKgQsQHS92uC9SIXvdt7OlP0aPsvwORHTA5CKlZAKzMx0wnzofVe8LVLcALh6 Mak5kW33ajAf+3z4H7qWaXcTXdB+9jf/nVP+BNaP8ggcR9y/QNNd/wV3iHLUifd3vmC4 rutC8gLwYU6uk9YTwZ6nqVZtIPtnuqtA9EURDVvlk7zR7ImxSOGoef67LuDjD8bF3STT 0qjg== X-Received: by 10.180.75.102 with SMTP id b6mr8092443wiw.26.1401465395090; Fri, 30 May 2014 08:56:35 -0700 (PDT) Received: from debian-vm3.lan (bl13-158-17.dsl.telepac.pt. [85.246.158.17]) by mx.google.com with ESMTPSA id ds6sm11068830wjd.38.2014.05.30.08.56.34 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 30 May 2014 08:56:34 -0700 (PDT) From: Filipe David Borba Manana To: linux-btrfs@vger.kernel.org Cc: Filipe David Borba Manana Subject: [PATCH] Btrfs: ioctl, don't re-lock extent range when not necessary Date: Fri, 30 May 2014 17:56:24 +0100 Message-Id: <1401468984-26821-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=-7.4 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, 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 In ioctl.c:lock_extent_range(), after locking our target range, the ordered extent that btrfs_lookup_first_ordered_extent() returns us may not overlap our target range at all. In this case we would just unlock our target range, wait for any new ordered extents that overlap the range to complete, lock again the range and repeat all these steps until we don't get any ordered extent and the delalloc flag isn't set in the io tree for our target range. Therefore just stop if we get an ordered extent that doesn't overlap our target range and the dealalloc flag isn't set for the range in the inode's io tree. Signed-off-by: Filipe David Borba Manana --- fs/btrfs/ioctl.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index 38f2169..603c036 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -2700,10 +2700,15 @@ static inline void lock_extent_range(struct inode *inode, u64 off, u64 len) lock_extent(&BTRFS_I(inode)->io_tree, off, off + len - 1); ordered = btrfs_lookup_first_ordered_extent(inode, off + len - 1); - if (!ordered && + if ((!ordered || + ordered->file_offset + ordered->len <= off || + ordered->file_offset >= off + len) && !test_range_bit(&BTRFS_I(inode)->io_tree, off, - off + len - 1, EXTENT_DELALLOC, 0, NULL)) + off + len - 1, EXTENT_DELALLOC, 0, NULL)) { + if (ordered) + btrfs_put_ordered_extent(ordered); break; + } unlock_extent(&BTRFS_I(inode)->io_tree, off, off + len - 1); if (ordered) btrfs_put_ordered_extent(ordered);