From patchwork Fri Aug 8 15:00:54 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Weston Andros Adamson X-Patchwork-Id: 4696671 Return-Path: X-Original-To: patchwork-linux-nfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id C937CC033A for ; Fri, 8 Aug 2014 15:01:16 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D25722015E for ; Fri, 8 Aug 2014 15:01:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B7F5D20173 for ; Fri, 8 Aug 2014 15:01:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756008AbaHHPBM (ORCPT ); Fri, 8 Aug 2014 11:01:12 -0400 Received: from mail-ie0-f178.google.com ([209.85.223.178]:35873 "EHLO mail-ie0-f178.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752663AbaHHPBL (ORCPT ); Fri, 8 Aug 2014 11:01:11 -0400 Received: by mail-ie0-f178.google.com with SMTP id rd18so6533789iec.9 for ; Fri, 08 Aug 2014 08:01:10 -0700 (PDT) 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; bh=xTc7jcUeHIgdRoM7zKqE1OvuJg3wOycpa21vqPM6hqI=; b=R+SUJRwi/e8cKYZ/G+PQ6gsejwTKcTVyubQP63eE+pCGovd5eCvq9zv6PGJATWYyeT phnblxEqHp/aV9YUgSDDNiVI4KLpcucTWJk/MFT7urgZUAUfiDLm3HZyOQ52/Xb/W/GN VRfcIU/Cy+JSiyHv2h42O4ck1vAfbjVkCWTNUIR8nmFt9DqsHCS/THpBGlYuttPIWZbC GLeZi0+FCfFJO+ZJ7FwZifna9qSR7JLlW68sZ9o6nDgKoq7FaXtPq7IxdNVCYDP14aZx hzrZomobr79gr4DPxfyos2fhMeM4HRYcOdFNEI5fLYQXGrBQawVB4hqkPOWrzW4fN78X 4Tsg== X-Gm-Message-State: ALoCoQmXkDXV0joHt/PtgI7iJy7it9x1CmnuUDaWjFCnmWAmlhztfvwr83wJDRFbudpee51Rr6IV X-Received: by 10.42.68.15 with SMTP id v15mr12616764ici.79.1407510070639; Fri, 08 Aug 2014 08:01:10 -0700 (PDT) Received: from gavrio-wifi.robotsandstuff.fake (c-98-209-19-144.hsd1.mi.comcast.net. [98.209.19.144]) by mx.google.com with ESMTPSA id ro8sm9930523igb.15.2014.08.08.08.01.09 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 08 Aug 2014 08:01:10 -0700 (PDT) From: Weston Andros Adamson To: trond.myklebust@primarydata.com Cc: linux-nfs@vger.kernel.org, Weston Andros Adamson Subject: [PATCH 2/5] nfs: fix nonblocking calls to nfs_page_group_lock Date: Fri, 8 Aug 2014 11:00:54 -0400 Message-Id: <1407510057-6881-3-git-send-email-dros@primarydata.com> X-Mailer: git-send-email 1.8.5.2 (Apple Git-48) In-Reply-To: <1407510057-6881-1-git-send-email-dros@primarydata.com> References: <1407510057-6881-1-git-send-email-dros@primarydata.com> Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, 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 nfs_page_group_lock was calling wait_on_bit_lock even when told not to block. Fix by first trying test_and_set_bit, followed by wait_on_bit_lock if and only if blocking is allowed. Return -EAGAIN if nonblocking and the test_and_set of the bit was already locked. Signed-off-by: Weston Andros Adamson Reviewed-by: Peng Tao --- fs/nfs/pagelist.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/fs/nfs/pagelist.c b/fs/nfs/pagelist.c index 38eaf83..f393c72 100644 --- a/fs/nfs/pagelist.c +++ b/fs/nfs/pagelist.c @@ -149,24 +149,29 @@ static int nfs_wait_bit_uninterruptible(void *word) * * this lock must be held if modifying the page group list * - * returns result from wait_on_bit_lock: 0 on success, < 0 on error + * return 0 on success, < 0 on error: -EDELAY if nonblocking or the + * result from wait_on_bit_lock + * + * NOTE: calling with nonblock=false should always have set the + * lock bit (see fs/buffer.c and other uses of wait_on_bit_lock + * with TASK_UNINTERRUPTIBLE), so there is no need to check the result. */ int nfs_page_group_lock(struct nfs_page *req, bool nonblock) { struct nfs_page *head = req->wb_head; - int ret; WARN_ON_ONCE(head != head->wb_head); - do { - ret = wait_on_bit_lock(&head->wb_flags, PG_HEADLOCK, - nfs_wait_bit_uninterruptible, - TASK_UNINTERRUPTIBLE); - } while (!nonblock && ret != 0); + if (!test_and_set_bit(PG_HEADLOCK, &head->wb_flags)) + return 0; - WARN_ON_ONCE(ret > 0); - return ret; + if (!nonblock) + return wait_on_bit_lock(&head->wb_flags, PG_HEADLOCK, + nfs_wait_bit_uninterruptible, + TASK_UNINTERRUPTIBLE); + + return -EAGAIN; } /*