From patchwork Tue Feb 14 13:02:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aleksandr Mikhalitsyn X-Patchwork-Id: 13140015 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DDE9FC6379F for ; Tue, 14 Feb 2023 13:05:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231761AbjBNNFa (ORCPT ); Tue, 14 Feb 2023 08:05:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47860 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229938AbjBNNF3 (ORCPT ); Tue, 14 Feb 2023 08:05:29 -0500 Received: from smtp-relay-internal-0.canonical.com (smtp-relay-internal-0.canonical.com [185.125.188.122]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 695172386A for ; Tue, 14 Feb 2023 05:05:28 -0800 (PST) Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id 2E7333F5E2 for ; Tue, 14 Feb 2023 13:05:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1676379925; bh=Ku2bmDwU8+fbp3j8ppKDR/hD+8eQUblZOt8X3gSfkfk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=WIVP8Spm0ivq2yDlHOMc4joS5iysngO5dcUV4NqqqjLU7tjE5LTX48dVcP0sfDkUX 00nC8tB58b215utTe1nfYtYH4v5tyMKZl7BFSN8d55KEucd9LVAVJzkHQKoExr0YaH xG2qud27Vnj1nyDIQAFwyD7T2DzEUlhGA/dUD8TaE/VfzxrkxMNwQoZtcCDkHdpB3W 1EDf81Kxre72yrXhOakhuIEEb97Cpy1XWxOZVGQq4GnVcewuZF/AhDcEB8Lf5O3N/m EmAf1txUYNkPUPEty13C1nBSecO6u4i240dMZcshKoPrNuzY2GVYQ0Eoum0KO73rba NAIZljfS64DQw== Received: by mail-ed1-f69.google.com with SMTP id eo7-20020a056402530700b004aab4319cedso9845330edb.2 for ; Tue, 14 Feb 2023 05:05:25 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Ku2bmDwU8+fbp3j8ppKDR/hD+8eQUblZOt8X3gSfkfk=; b=BVuASnD+QAKmp/UYJ4iNiECRrU776zFdXLk6gIYKVpoUgF5g4rN/umdJ2Dd5t5vxGS DeF6fGbWAjho0KH4bK3cO76fGhvYfHJptFXLWp5UyeFJ5ecFlcfvKZ9IyP9pPS2bQb7p hz8B2jdm275ktTY1ztIOvNOuGoelVfMHz06oNg0JYJ/r20mKCmovo2zSEoRIGabmmIVG QilG6ndTbHgN0gCuZTjXcmTI+dRTO5dsJr9/IRa4Jl1sxq9Qp+548Pr2YJy6QZp5YBYO mVmR8o3Pfv2E9IzIcIw2dkPYDT0vleSdOIgnr1GhZ8qo83pyuaU5pStHgWIMeEd72kHx CJqQ== X-Gm-Message-State: AO0yUKWk/3bxGv+TLRbyrYcEj56a8UQ69mkYffsP/ryIEuOKdp+/f0mF 5VsTtkA/2GMS5LS1BXOnD9Gl3eIjP/a6J0C6+f5s2DGBtOlRgDJEovaWP/++JQOZ6YQA9BEvm3y cxw3xuqMySiKxkdiwtlwhlibEPU97PF3BSzNKGVm3lRI= X-Received: by 2002:a17:906:860a:b0:884:c45f:1c04 with SMTP id o10-20020a170906860a00b00884c45f1c04mr2693094ejx.2.1676379924886; Tue, 14 Feb 2023 05:05:24 -0800 (PST) X-Google-Smtp-Source: AK7set9DRrxF6BlN3XBu5l7hJIoAyPZoxdix0NaxVi0SVFEccl7PQoe08ARqXBFKVsYad4uGzPcxdQ== X-Received: by 2002:a17:906:860a:b0:884:c45f:1c04 with SMTP id o10-20020a170906860a00b00884c45f1c04mr2693078ejx.2.1676379924653; Tue, 14 Feb 2023 05:05:24 -0800 (PST) Received: from amikhalitsyn.. ([2a02:8109:bd40:1414:c85e:daf1:c7bb:28dc]) by smtp.gmail.com with ESMTPSA id b9-20020a170906194900b0088478517830sm8209790eje.83.2023.02.14.05.05.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Feb 2023 05:05:24 -0800 (PST) From: Alexander Mikhalitsyn To: corbet@lwn.net Cc: Alexander Mikhalitsyn , Eric Biggers , Miklos Szeredi , Al Viro , linux-fsdevel@vger.kernel.org, linux-doc@vger.kernel.org Subject: [PATCH v3 1/2] docs: filesystems: vfs: actualize struct file_system_type description Date: Tue, 14 Feb 2023 14:02:39 +0100 Message-Id: <20230214130240.166885-2-aleksandr.mikhalitsyn@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230214130240.166885-1-aleksandr.mikhalitsyn@canonical.com> References: <20230214130240.166885-1-aleksandr.mikhalitsyn@canonical.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Added descriptions for: - fscontext API ('init_fs_context' method, 'parameters' field) - 'fs_supers' field Cc: Eric Biggers Cc: Miklos Szeredi Cc: Al Viro Cc: linux-fsdevel@vger.kernel.org Cc: linux-doc@vger.kernel.org Signed-off-by: Alexander Mikhalitsyn --- Documentation/filesystems/vfs.rst | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/Documentation/filesystems/vfs.rst b/Documentation/filesystems/vfs.rst index 2c15e7053113..f8905ff070d0 100644 --- a/Documentation/filesystems/vfs.rst +++ b/Documentation/filesystems/vfs.rst @@ -107,7 +107,7 @@ file /proc/filesystems. struct file_system_type ----------------------- -This describes the filesystem. As of kernel 2.6.39, the following +This describes the filesystem. The following members are defined: .. code-block:: c @@ -115,14 +115,24 @@ members are defined: struct file_system_type { const char *name; int fs_flags; + int (*init_fs_context)(struct fs_context *); + const struct fs_parameter_spec *parameters; struct dentry *(*mount) (struct file_system_type *, int, - const char *, void *); + const char *, void *); void (*kill_sb) (struct super_block *); struct module *owner; struct file_system_type * next; - struct list_head fs_supers; + struct hlist_head fs_supers; + struct lock_class_key s_lock_key; struct lock_class_key s_umount_key; + struct lock_class_key s_vfs_rename_key; + struct lock_class_key s_writers_key[SB_FREEZE_LEVELS]; + + struct lock_class_key i_lock_key; + struct lock_class_key i_mutex_key; + struct lock_class_key invalidate_lock_key; + struct lock_class_key i_mutex_dir_key; }; ``name`` @@ -132,6 +142,15 @@ members are defined: ``fs_flags`` various flags (i.e. FS_REQUIRES_DEV, FS_NO_DCACHE, etc.) +``init_fs_context`` + Initializes 'struct fs_context' ->ops and ->fs_private fields with + filesystem-specific data. + +``parameters`` + Pointer to the array of filesystem parameters descriptors + 'struct fs_parameter_spec'. + More info in Documentation/filesystems/mount_api.rst. + ``mount`` the method to call when a new instance of this filesystem should be mounted @@ -148,7 +167,11 @@ members are defined: ``next`` for internal VFS use: you should initialize this to NULL - s_lock_key, s_umount_key: lockdep-specific +``fs_supers`` + for internal VFS use: hlist of filesystem instances (superblocks) + + s_lock_key, s_umount_key, s_vfs_rename_key, s_writers_key, + i_lock_key, i_mutex_key, invalidate_lock_key, i_mutex_dir_key: lockdep-specific The mount() method has the following arguments: From patchwork Tue Feb 14 13:02:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aleksandr Mikhalitsyn X-Patchwork-Id: 13140016 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 37652C05027 for ; Tue, 14 Feb 2023 13:05:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232281AbjBNNFc (ORCPT ); Tue, 14 Feb 2023 08:05:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47870 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231812AbjBNNFa (ORCPT ); Tue, 14 Feb 2023 08:05:30 -0500 Received: from smtp-relay-internal-0.canonical.com (smtp-relay-internal-0.canonical.com [185.125.188.122]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3630D23860 for ; Tue, 14 Feb 2023 05:05:29 -0800 (PST) Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id C62853F5E7 for ; Tue, 14 Feb 2023 13:05:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1676379926; bh=JxutMUKArkibrm/KgvMOIci9yD/VCE1/gX/WVNDtC4E=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=oqxSYApWR9t+gDrw2NMlmz94oZF4TBZRg9VrsC1qtj5cDn2OymEx6PW4hRuzhYqpS mZbAvS6zreayDt9KJpgQMBy8IkQp3b8kW6Eqs3O33LpDbsN27Nf3UHdgGRaZD607JD flsEZTY3ATWUq3BWjlm57cBV64JlUoXqf9OufxxYHK+r+0x0WnkxwxWf24D0rPY/Ij ByH5xWHp/IulQWeauAetV1QLLCPzUmnOeC8YRu2MDRvLrudfWOnje5GPo5kwdYocgI UtMUfuqJeDbdmmpcve27HpugthP5StQuvSx2Fe7t9znzqNb+kbdl6LZg813KcpSWPt PRCgt9vTDKT0w== Received: by mail-ed1-f69.google.com with SMTP id eo7-20020a056402530700b004aab4319cedso9845390edb.2 for ; Tue, 14 Feb 2023 05:05:26 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JxutMUKArkibrm/KgvMOIci9yD/VCE1/gX/WVNDtC4E=; b=pFlQrGXQaUS41+BNce352GPyhK+wbOw3FHD5cIotBZWEz5kXBJsdtZ0sIvQ1Gx4p/o Ir+NGhytWXqNjxuf6nGXsRRm1UOpGmQIgJbyX/hcVbsBRR7HC3HKdVVClYBpZqgjAsBc QvHWyEfFbBR8nQBRz+jVFjK00v35c1kpwCgWI2UMPT76l/EqpFY4+fFzobK5WNoIkDCd spiFjRn7HFvzM2U6xZjuv0I5hc4TD/gGj/nGDTHhYp5myXszp1I7cLmrOUOpXNTy2LxD kIJpz17/XUgJ0zoqrHS0bf6rHbx98kuso5iIK0PHYeUiSnsa5OXTzHJq2b4cO6BOAkjN hOsg== X-Gm-Message-State: AO0yUKV019pD5RLf6JouExE71fkWdJDU2t874Pz0brcNoBtgsvQY4+91 BJagbT/Ae1j8T/aam16YpFuEmST+cBHDPw2fOcce/rS6MFCn0fhOUg7M3GYfdLAhI7IMk5u/amT MLtfrPDkPTAk7Ne5rtu+deIAe05S+OWK7aSpxF1uNisQ= X-Received: by 2002:a50:c354:0:b0:4a2:588f:b3c5 with SMTP id q20-20020a50c354000000b004a2588fb3c5mr2436213edb.21.1676379926656; Tue, 14 Feb 2023 05:05:26 -0800 (PST) X-Google-Smtp-Source: AK7set/4akfAeWfahZIEKFwLWmMN+68Ei102e772mpSWnR0I/m+0+/uhccRFxNQyXihzinGSHWgb6Q== X-Received: by 2002:a50:c354:0:b0:4a2:588f:b3c5 with SMTP id q20-20020a50c354000000b004a2588fb3c5mr2436198edb.21.1676379926453; Tue, 14 Feb 2023 05:05:26 -0800 (PST) Received: from amikhalitsyn.. ([2a02:8109:bd40:1414:c85e:daf1:c7bb:28dc]) by smtp.gmail.com with ESMTPSA id b9-20020a170906194900b0088478517830sm8209790eje.83.2023.02.14.05.05.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Feb 2023 05:05:25 -0800 (PST) From: Alexander Mikhalitsyn To: corbet@lwn.net Cc: Alexander Mikhalitsyn , Eric Biggers , Miklos Szeredi , Al Viro , linux-fsdevel@vger.kernel.org, linux-doc@vger.kernel.org Subject: [PATCH v3 2/2] docs: filesystems: vfs: actualize struct super_operations description Date: Tue, 14 Feb 2023 14:02:40 +0100 Message-Id: <20230214130240.166885-3-aleksandr.mikhalitsyn@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230214130240.166885-1-aleksandr.mikhalitsyn@canonical.com> References: <20230214130240.166885-1-aleksandr.mikhalitsyn@canonical.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Added/updated descriptions for super_operations: - free_inode method - evict_inode method - freeze_super/thaw_super method - show_{devname,path,stats} procfs-related methods - get_dquots method Cc: Eric Biggers Cc: Miklos Szeredi Cc: Al Viro Cc: linux-fsdevel@vger.kernel.org Cc: linux-doc@vger.kernel.org Signed-off-by: Alexander Mikhalitsyn --- Documentation/filesystems/vfs.rst | 74 ++++++++++++++++++++++++------- 1 file changed, 59 insertions(+), 15 deletions(-) diff --git a/Documentation/filesystems/vfs.rst b/Documentation/filesystems/vfs.rst index f8905ff070d0..682148679b63 100644 --- a/Documentation/filesystems/vfs.rst +++ b/Documentation/filesystems/vfs.rst @@ -245,33 +245,42 @@ struct super_operations ----------------------- This describes how the VFS can manipulate the superblock of your -filesystem. As of kernel 2.6.22, the following members are defined: +filesystem. The following members are defined: .. code-block:: c struct super_operations { struct inode *(*alloc_inode)(struct super_block *sb); void (*destroy_inode)(struct inode *); + void (*free_inode)(struct inode *); void (*dirty_inode) (struct inode *, int flags); - int (*write_inode) (struct inode *, int); - void (*drop_inode) (struct inode *); - void (*delete_inode) (struct inode *); + int (*write_inode) (struct inode *, struct writeback_control *wbc); + int (*drop_inode) (struct inode *); + void (*evict_inode) (struct inode *); void (*put_super) (struct super_block *); int (*sync_fs)(struct super_block *sb, int wait); + int (*freeze_super) (struct super_block *); int (*freeze_fs) (struct super_block *); + int (*thaw_super) (struct super_block *); int (*unfreeze_fs) (struct super_block *); int (*statfs) (struct dentry *, struct kstatfs *); int (*remount_fs) (struct super_block *, int *, char *); - void (*clear_inode) (struct inode *); void (*umount_begin) (struct super_block *); int (*show_options)(struct seq_file *, struct dentry *); + int (*show_devname)(struct seq_file *, struct dentry *); + int (*show_path)(struct seq_file *, struct dentry *); + int (*show_stats)(struct seq_file *, struct dentry *); ssize_t (*quota_read)(struct super_block *, int, char *, size_t, loff_t); ssize_t (*quota_write)(struct super_block *, int, const char *, size_t, loff_t); - int (*nr_cached_objects)(struct super_block *); - void (*free_cached_objects)(struct super_block *, int); + struct dquot **(*get_dquots)(struct inode *); + + long (*nr_cached_objects)(struct super_block *, + struct shrink_control *); + long (*free_cached_objects)(struct super_block *, + struct shrink_control *); }; All methods are called without any locks being held, unless otherwise @@ -292,6 +301,11 @@ or bottom half). ->alloc_inode was defined and simply undoes anything done by ->alloc_inode. +``free_inode`` + this method is called from RCU callback. If you use call_rcu() + in ->destroy_inode to free 'struct inode' memory, then it's + better to release memory in this method. + ``dirty_inode`` this method is called by the VFS when an inode is marked dirty. This is specifically for the inode itself being marked dirty, @@ -319,8 +333,12 @@ or bottom half). practice of using "force_delete" in the put_inode() case, but does not have the races that the "force_delete()" approach had. -``delete_inode`` - called when the VFS wants to delete an inode +``evict_inode`` + called when the VFS wants to evict an inode. Caller does + *not* evict the pagecache or inode-associated metadata buffers; + the method has to use truncate_inode_pages_final() to get rid + of those. Caller makes sure async writeback cannot be running for + the inode while (or after) ->evict_inode() is called. Optional. ``put_super`` called when the VFS wishes to free the superblock @@ -331,14 +349,25 @@ or bottom half). superblock. The second parameter indicates whether the method should wait until the write out has been completed. Optional. +``freeze_super`` + Called instead of ->freeze_fs callback if provided. + Main difference is that ->freeze_super is called without taking + down_write(&sb->s_umount). If filesystem implements it and wants + ->freeze_fs to be called too, then it has to call ->freeze_fs + explicitly from this callback. Optional. + ``freeze_fs`` called when VFS is locking a filesystem and forcing it into a consistent state. This method is currently used by the Logical - Volume Manager (LVM). + Volume Manager (LVM) and ioctl(FIFREEZE). Optional. + +``thaw_super`` + called when VFS is unlocking a filesystem and making it writable + again after ->freeze_super. Optional. ``unfreeze_fs`` called when VFS is unlocking a filesystem and making it writable - again. + again after ->freeze_fs. Optional. ``statfs`` called when the VFS needs to get filesystem statistics. @@ -347,22 +376,37 @@ or bottom half). called when the filesystem is remounted. This is called with the kernel lock held -``clear_inode`` - called then the VFS clears the inode. Optional - ``umount_begin`` called when the VFS is unmounting a filesystem. ``show_options`` - called by the VFS to show mount options for /proc//mounts. + called by the VFS to show mount options for /proc//mounts + and /proc//mountinfo. (see "Mount Options" section) +``show_devname`` + Optional. Called by the VFS to show device name for + /proc//{mounts,mountinfo,mountstats}. If not provided then + '(struct mount).mnt_devname' will be used. + +``show_path`` + Optional. Called by the VFS (for /proc//mountinfo) to show + the mount root dentry path relative to the filesystem root. + +``show_stats`` + Optional. Called by the VFS (for /proc//mountstats) to show + filesystem-specific mount statistics. + ``quota_read`` called by the VFS to read from filesystem quota file. ``quota_write`` called by the VFS to write to filesystem quota file. +``get_dquots`` + called by quota to get 'struct dquot' array for a particular inode. + Optional. + ``nr_cached_objects`` called by the sb cache shrinking function for the filesystem to return the number of freeable cached objects it contains.