From patchwork Thu May 24 02:29:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Anderson X-Patchwork-Id: 10422651 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id AD5CE60327 for ; Thu, 24 May 2018 02:29:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8E18B292B1 for ; Thu, 24 May 2018 02:29:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 814C8292F0; Thu, 24 May 2018 02:29:24 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 03F3D292B1 for ; Thu, 24 May 2018 02:29:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935330AbeEXC3W (ORCPT ); Wed, 23 May 2018 22:29:22 -0400 Received: from mail-qk0-f194.google.com ([209.85.220.194]:43068 "EHLO mail-qk0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935126AbeEXC3U (ORCPT ); Wed, 23 May 2018 22:29:20 -0400 Received: by mail-qk0-f194.google.com with SMTP id h19-v6so78545qkj.10; Wed, 23 May 2018 19:29:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=to:cc:from:subject:message-id:date:user-agent:mime-version; bh=9vRR56N8vgfK9QvoXhJfLvDcAEwDZc3t5k+4UCOVeo0=; b=ctFOUG2XddXTOMcu5pDTwpNwHXk5H9uXClVdhTnE+pLHRCrbfxi6uavYaFbzcmlYiv 4nH/PXpvg9jWFYeMCTY72j0f+e8grX00lX4HWm+ZW2wwGnWi4RUi9bh4Xx64VHZQMIxE bz//BhcqVMs5qtG6l8JnDkPUTT1R5beDD0ZQaa8xsDLMV301fokGk8wnAdKaU+O/NOSm ItKvB+9nKzjbJGGWmvvCLtYSnLHWzzr+YIIw42rhkuz/ncQoUJumE5kGxVobbM+7VW6n GFtFLqJVqTq8MYanqmhVMWP7N8mc8NEoDCkmMFZJPWZbarbRvGv5sP6pUhFbVxdQbBJQ rW7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:cc:from:subject:message-id:date:user-agent :mime-version; bh=9vRR56N8vgfK9QvoXhJfLvDcAEwDZc3t5k+4UCOVeo0=; b=nitgngg3SNEWyKuME8YkaW/fvlGs4J4dxK+g9EdK9If4A3MN/yFrfbTYwuBJ0tFF3u rM9GENISAncCVjlTixvt+dFxffezDBCOuW96fDHWpoHpGRT1JvPrycJMS6pJ7bE/334g Cnih8P+njzrH7l349TA/cnGsepeOHmqlB3/J3EJAypG5bpWczXRfO1ajBWL+b3H7f42Q ArTrZQNHIkxq65W7JwIgEK/6TlRdv8EsPSXTLDOfEmjK7uEkP2iyQ8Y4yeLZMvkC2MpI LBTpuzuZZHy5LVZ5BFNUIeHOLAh/AXDuFvbrnscrvEllGc1CaMrMCjC7SukykpjSXHbD Rd7A== X-Gm-Message-State: ALKqPwfS9TxygpqJlKET7mNY0BWc2sSsB1dTeUKv3jRY7bkb70IF4OxL /Q0CVXvjkSqsEdTugKX8oy4= X-Google-Smtp-Source: ADUXVKILqYYrcHdTbXVbXjV2lHQfjwP1vmyy5U8/IJ3qJW2FcX3BOzskyRwThEf0qEOFmMTRdaTIxw== X-Received: by 2002:a37:1aca:: with SMTP id l71-v6mr3453882qkh.355.1527128959916; Wed, 23 May 2018 19:29:19 -0700 (PDT) Received: from [192.168.1.237] (pool-72-66-26-176.washdc.fios.verizon.net. [72.66.26.176]) by smtp.googlemail.com with ESMTPSA id o66-v6sm2188143qki.93.2018.05.23.19.29.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 23 May 2018 19:29:19 -0700 (PDT) To: corbet@lwn.net, linux-doc@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, Al Viro , Matthew Wilcox , Jeff Layton From: Sean Anderson Subject: [PATCH RESEND] Documentation: filesystems: update filesystem locking documentation Message-ID: Date: Wed, 23 May 2018 22:29:10 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Documentation/filesystems/Locking no longer reflects current locking semantics. i_mutex is no longer used for locking, and has been superseded by i_rwsem. Additionally, ->iterate_shared() was not documented. Signed-off-by: Sean Anderson Reviewed-by: Jeff Layton --- Documentation/filesystems/Locking | 43 +++++++++++++++++-------------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/Documentation/filesystems/Locking b/Documentation/filesystems/Locking index 75d2d57e2c44..15853d522941 100644 --- a/Documentation/filesystems/Locking +++ b/Documentation/filesystems/Locking @@ -69,31 +69,31 @@ prototypes: locking rules: all may block - i_mutex(inode) -lookup: yes -create: yes -link: yes (both) -mknod: yes -symlink: yes -mkdir: yes -unlink: yes (both) -rmdir: yes (both) (see below) -rename: yes (all) (see below) + i_rwsem(inode) +lookup: shared +create: exclusive +link: exclusive (both) +mknod: exclusive +symlink: exclusive +mkdir: exclusive +unlink: exclusive (both) +rmdir: exclusive (both)(see below) +rename: exclusive (all) (see below) readlink: no get_link: no -setattr: yes +setattr: exclusive permission: no (may not block if called in rcu-walk mode) get_acl: no getattr: no listxattr: no fiemap: no update_time: no -atomic_open: yes +atomic_open: exclusive tmpfile: no - Additionally, ->rmdir(), ->unlink() and ->rename() have ->i_mutex on -victim. + Additionally, ->rmdir(), ->unlink() and ->rename() have ->i_rwsem + exclusive on victim. cross-directory ->rename() has (per-superblock) ->s_vfs_rename_sem. See Documentation/filesystems/directory-locking for more detailed discussion @@ -111,10 +111,10 @@ prototypes: locking rules: all may block - i_mutex(inode) + i_rwsem(inode) list: no get: no -set: yes +set: exclusive --------------------------- super_operations --------------------------- prototypes: @@ -217,14 +217,14 @@ prototypes: locking rules: All except set_page_dirty and freepage may block - PageLocked(page) i_mutex + PageLocked(page) i_rwsem writepage: yes, unlocks (see below) readpage: yes, unlocks writepages: set_page_dirty no readpages: -write_begin: locks the page yes -write_end: yes, unlocks yes +write_begin: locks the page exclusive +write_end: yes, unlocks exclusive bmap: invalidatepage: yes releasepage: yes @@ -439,6 +439,7 @@ prototypes: ssize_t (*read_iter) (struct kiocb *, struct iov_iter *); ssize_t (*write_iter) (struct kiocb *, struct iov_iter *); int (*iterate) (struct file *, struct dir_context *); + int (*iterate_shared) (struct file *, struct dir_context *); unsigned int (*poll) (struct file *, struct poll_table_struct *); long (*unlocked_ioctl) (struct file *, unsigned int, unsigned long); long (*compat_ioctl) (struct file *, unsigned int, unsigned long); @@ -480,6 +481,10 @@ mutex or just to use i_size_read() instead. Note: this does not protect the file->f_pos against concurrent modifications since this is something the userspace has to take care about. +->iterate() is called with i_rwsem exclusive. + +->iterate_shared() is called with i_rwsem at least shared. + ->fasync() is responsible for maintaining the FASYNC bit in filp->f_flags. Most instances call fasync_helper(), which does that maintenance, so it's not normally something one needs to worry about. Return values > 0 will be