From patchwork Fri Mar 6 07:53:31 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Wagner X-Patchwork-Id: 5950401 Return-Path: X-Original-To: patchwork-linux-fsdevel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 6ECA79F373 for ; Fri, 6 Mar 2015 07:54:06 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8B15A201EF for ; Fri, 6 Mar 2015 07:54:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8F7C82043C for ; Fri, 6 Mar 2015 07:54:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932228AbbCFHx4 (ORCPT ); Fri, 6 Mar 2015 02:53:56 -0500 Received: from mail.bmw-carit.de ([62.245.222.98]:53540 "EHLO linuxmail.bmw-carit.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753943AbbCFHxi (ORCPT ); Fri, 6 Mar 2015 02:53:38 -0500 Received: from localhost (handman.bmw-carit.intra [192.168.101.57]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) (Authenticated sender: daniel.wagner) by linuxmail.bmw-carit.de (Postfix) with ESMTPSA id 9029340140; Fri, 6 Mar 2015 06:48:56 +0100 (CET) From: Daniel Wagner To: Jeff Layton Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Daniel Wagner , "J. Bruce Fields" , Alexander Viro Subject: [PATCH v3 1/2] locks: Split insert/delete block functions into flock/posix parts Date: Fri, 6 Mar 2015 08:53:31 +0100 Message-Id: <1425628412-30259-2-git-send-email-daniel.wagner@bmw-carit.de> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1425628412-30259-1-git-send-email-daniel.wagner@bmw-carit.de> References: <1425628412-30259-1-git-send-email-daniel.wagner@bmw-carit.de> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@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 The locks_insert/delete_block() functions are used for flock, posix and leases types. blocked_lock_lock is used to serialize all access to fl_link, fl_block, fl_next and blocked_hash. Here, we prepare the stage for using blocked_lock_lock only to protect blocked_hash. Signed-off-by: Daniel Wagner Cc: Jeff Layton Cc: "J. Bruce Fields" Cc: Alexander Viro --- fs/locks.c | 49 ++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 40 insertions(+), 9 deletions(-) diff --git a/fs/locks.c b/fs/locks.c index d4992a1..0c37d68 100644 --- a/fs/locks.c +++ b/fs/locks.c @@ -611,11 +611,20 @@ static void locks_delete_global_blocked(struct file_lock *waiter) */ static void __locks_delete_block(struct file_lock *waiter) { - locks_delete_global_blocked(waiter); list_del_init(&waiter->fl_block); waiter->fl_next = NULL; } +/* Posix block variant of __locks_delete_block. + * + * Must be called with blocked_lock_lock held. + */ +static void __locks_delete_posix_block(struct file_lock *waiter) +{ + locks_delete_global_blocked(waiter); + __locks_delete_block(waiter); +} + static void locks_delete_block(struct file_lock *waiter) { spin_lock(&blocked_lock_lock); @@ -623,6 +632,13 @@ static void locks_delete_block(struct file_lock *waiter) spin_unlock(&blocked_lock_lock); } +static void locks_delete_posix_block(struct file_lock *waiter) +{ + spin_lock(&blocked_lock_lock); + __locks_delete_posix_block(waiter); + spin_unlock(&blocked_lock_lock); +} + /* Insert waiter into blocker's block list. * We use a circular list so that processes can be easily woken up in * the order they blocked. The documentation doesn't require this but @@ -639,8 +655,17 @@ static void __locks_insert_block(struct file_lock *blocker, BUG_ON(!list_empty(&waiter->fl_block)); waiter->fl_next = blocker; list_add_tail(&waiter->fl_block, &blocker->fl_block); - if (IS_POSIX(blocker) && !IS_OFDLCK(blocker)) - locks_insert_global_blocked(waiter); +} + +/* Posix block variant of __locks_insert_block. + * + * Must be called with flc_lock and blocked_lock_lock held. + */ +static void __locks_insert_posix_block(struct file_lock *blocker, + struct file_lock *waiter) +{ + __locks_insert_block(blocker, waiter); + locks_insert_global_blocked(waiter); } /* Must be called with flc_lock held. */ @@ -675,7 +700,10 @@ static void locks_wake_up_blocks(struct file_lock *blocker) waiter = list_first_entry(&blocker->fl_block, struct file_lock, fl_block); - __locks_delete_block(waiter); + if (IS_POSIX(blocker) && !IS_OFDLCK(blocker)) + __locks_delete_posix_block(waiter); + else + __locks_delete_block(waiter); if (waiter->fl_lmops && waiter->fl_lmops->lm_notify) waiter->fl_lmops->lm_notify(waiter); else @@ -985,7 +1013,7 @@ static int __posix_lock_file(struct inode *inode, struct file_lock *request, str spin_lock(&blocked_lock_lock); if (likely(!posix_locks_deadlock(request, fl))) { error = FILE_LOCK_DEFERRED; - __locks_insert_block(fl, request); + __locks_insert_posix_block(fl, request); } spin_unlock(&blocked_lock_lock); goto out; @@ -1186,7 +1214,7 @@ int posix_lock_file_wait(struct file *filp, struct file_lock *fl) if (!error) continue; - locks_delete_block(fl); + locks_delete_posix_block(fl); break; } return error; @@ -1283,7 +1311,7 @@ int locks_mandatory_area(int read_write, struct inode *inode, continue; } - locks_delete_block(&fl); + locks_delete_posix_block(&fl); break; } @@ -2104,7 +2132,10 @@ static int do_lock_file_wait(struct file *filp, unsigned int cmd, if (!error) continue; - locks_delete_block(fl); + if (IS_POSIX(fl) && !IS_OFDLCK(fl)) + locks_delete_posix_block(fl); + else + locks_delete_block(fl); break; } @@ -2468,7 +2499,7 @@ posix_unblock_lock(struct file_lock *waiter) spin_lock(&blocked_lock_lock); if (waiter->fl_next) - __locks_delete_block(waiter); + __locks_delete_posix_block(waiter); else status = -ENOENT; spin_unlock(&blocked_lock_lock);