From patchwork Tue Jan 31 12:15:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Mikhalitsyn X-Patchwork-Id: 13122942 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 A09D0C38142 for ; Tue, 31 Jan 2023 12:16:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231519AbjAaMQL (ORCPT ); Tue, 31 Jan 2023 07:16:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37882 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231481AbjAaMQK (ORCPT ); Tue, 31 Jan 2023 07:16:10 -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 ED8BF3FF09 for ; Tue, 31 Jan 2023 04:16:07 -0800 (PST) Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) (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 A6AC7414A7 for ; Tue, 31 Jan 2023 12:16:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1675167365; bh=T9pFM0TaSiU75dNwwObnUqA54OKkqExI+JiVpjCtTNY=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=Mfq5S/9XBDHZwf8X9Z5PyvLshiQ4n9APoR30xl6AZZ31VxeO6z3m2oWjZAZ8qKBPb HkanjfsHaOv5P3Hdmr87dYqD3pGnGBvymJnxfNQHWjpVOQj9HvA24B5J2/abvrUW1Q h3tDj9I+JI5BC5QEUU+wsLN5IUAOfmwqFiQ0vUOqw6hbnk8toOWdx5lBDzat3xu8hK aas8hgS/b/4XLeLP8ldHwQZTwPxvJLDl7QfVFelJB1h2GK/zaUaMzJfYONM9lCr3ej qvYnPFlIvVrm7Nvu38rmE8ZlbvklMCGEL+hhajMMljiIZMTcDn2M5O7rXkfrN0YR1S uVZIjZYHFaUhg== Received: by mail-ed1-f72.google.com with SMTP id m7-20020a056402510700b00488d1fcdaebso10388843edd.9 for ; Tue, 31 Jan 2023 04:16:05 -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:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=T9pFM0TaSiU75dNwwObnUqA54OKkqExI+JiVpjCtTNY=; b=PP84IfmVr7O+tIroZtLMVX8zJBFeGFtl943eVnwTEvNEa9hihOrc1Ngjz87Xcmrviq SULn7Kpl7mUVgA1oaX3YPTPmQgsu7uOvXRnJAVAwkzK+lpg2ryDH+9czyFKZ2PeyxQWF 1AivHhZvU6aU0Fnc1+k5uD8j0Mg04qpf8amMi/XblXHrtkanuClsLku+ayGa7cr6oze3 tedxeAyhNA69Th9mD5a+hiF2iklcWIokMkVMOLeBBzpRMm03Y056G1NWExBP3p4Dg8yS lB1vGckLtLsHuv4YPKCvd9T5dyMdt3MI0+JtUt4970FD93tiqjDJpH/ONhMxF8voUwVH ersA== X-Gm-Message-State: AO0yUKXHKa7eU7x6ik1NncJDjRRpDbeZpo7c3agjvNF8TbIqug8MQGto be55wQBOSJwloxqPOYjqqwck+DPn6i3CDbIorMZsc9OKcm2T0lpaOZO9T/LRg+/gYLJQ+saB+rh fidVGibpA98yg95kiaVVxUQP8t+X5pUCNzgBW3zex2vA= X-Received: by 2002:a50:9e2f:0:b0:4a1:f49e:48bf with SMTP id z44-20020a509e2f000000b004a1f49e48bfmr18447827ede.7.1675167362836; Tue, 31 Jan 2023 04:16:02 -0800 (PST) X-Google-Smtp-Source: AK7set/ypBMfNG1otMzUvh3lwDVgiSjv8iNANEI/lOt7rsQ5LLwFAFauXQGDGD1JtBOLqr1hdn9sVQ== X-Received: by 2002:a50:9e2f:0:b0:4a1:f49e:48bf with SMTP id z44-20020a509e2f000000b004a1f49e48bfmr18447817ede.7.1675167362622; Tue, 31 Jan 2023 04:16:02 -0800 (PST) Received: from amikhalitsyn.. (ip5f5bf399.dynamic.kabel-deutschland.de. [95.91.243.153]) by smtp.gmail.com with ESMTPSA id u20-20020a50a414000000b004a08c52a2f0sm8378432edb.76.2023.01.31.04.16.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Jan 2023 04:16:02 -0800 (PST) From: Alexander Mikhalitsyn To: corbet@lwn.net Cc: Alexander Mikhalitsyn , linux-fsdevel@vger.kernel.org, linux-doc@vger.kernel.org Subject: [PATCH 1/2] docs: filesystems: vfs: actualize struct file_system_type description Date: Tue, 31 Jan 2023 13:15:46 +0100 Message-Id: <20230131121546.176946-1-aleksandr.mikhalitsyn@canonical.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org Cc: linux-doc@vger.kernel.org Signed-off-by: Alexander Mikhalitsyn --- Documentation/filesystems/vfs.rst | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/Documentation/filesystems/vfs.rst b/Documentation/filesystems/vfs.rst index 2c15e7053113..fab3bd702250 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. As of kernel 6.1, 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,8 @@ members are defined: ``next`` for internal VFS use: you should initialize this to NULL - s_lock_key, s_umount_key: lockdep-specific + 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 Jan 31 12:16:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Mikhalitsyn X-Patchwork-Id: 13122943 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 DB03EC636CC for ; Tue, 31 Jan 2023 12:16:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231487AbjAaMQT (ORCPT ); Tue, 31 Jan 2023 07:16:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37918 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231416AbjAaMQS (ORCPT ); Tue, 31 Jan 2023 07:16:18 -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 14DA83FF09 for ; Tue, 31 Jan 2023 04:16:17 -0800 (PST) Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) (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 DFAD73F5DD for ; Tue, 31 Jan 2023 12:16:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1675167372; bh=IPu7fLB6LtSUjT3Xte4CmODWi6kb+UhS9k09P1gjo9M=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=qHEsqu6p2bSCZY6QpS4mcdjRq8C+OFNc0Zo/lHRXfst0JqujKG9AJOa8hn2FC96Kf DzbnrIoqxXbAzxru8ouVHWSI+hg48x2HR/OvDc9a+7jweTeqQjKHtnegJhzdj4kXG0 LEZnmTp6G1JDh1XyACzbG1BmvLbbaAH+XwT3wO3UOrlIgwWe1ZzvYlch1iUBpH2XkZ +63vez6KUlKgCCla9N+ggdPXilT8AXMS7v5mV3RbYdoPEYhYaOjalPh969F2PvA2gH yKCGqI4hm6W4+m3pLHLK2jQXE3zPBpcvqEriw0zV1KqnoZosKqJ24vn3xbJRy/2cCb xeNosUZNoKddA== Received: by mail-ed1-f72.google.com with SMTP id f11-20020a056402354b00b0049e18f0076dso10388311edd.15 for ; Tue, 31 Jan 2023 04:16:12 -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:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=IPu7fLB6LtSUjT3Xte4CmODWi6kb+UhS9k09P1gjo9M=; b=0WfhkvyqtQqx+Fqq/ofo2iBjnGxqRVvLh3UO71DPjRr8CQEQMGYgMFOpNRmduPlZIR E17jliBMImnGXm+HQ5MBb7FuMJwzSGju7eY0VBzskoEEACz8i4E21CJQFB0YMkvHoGn/ Rf6sjrLzSzIFC3PCCCyEdwf6bDQByyocoHlAqpb7o1bHgG3mqKd/fV3sbNo23SiamKc/ CEq6DIRviDOJDmibT0JkVnUKR8Tqw4S++ucJtQddvZeaWSrIWSrQ7KvI62pPWvxGUF+D awzsHNIdnqWLOZMZ9Xs+WM243KsLOA3liUka1oXJmAuyIysMD0zDYsVLoapL+D9YHG9d qdsQ== X-Gm-Message-State: AO0yUKUmnp/9ECvB7MEBkuaQ2MBQ9WbuwS0pkvu1Qqu5UmxJ8NPRXNAs ystBuPtV0bZjlKzs6mbyg/I170fDqh7SSGUrX2p+rEoV/eDf+fEPwW124w8Noz5IVyEGc2yQi1q 0HZEBPkGCfOU2h0AFhZNoN76UVcgTwSqOXSAO5ND96Ck= X-Received: by 2002:a17:907:9703:b0:880:50de:5e86 with SMTP id jg3-20020a170907970300b0088050de5e86mr15641292ejc.3.1675167372412; Tue, 31 Jan 2023 04:16:12 -0800 (PST) X-Google-Smtp-Source: AK7set+czGFbXYX0+SPaylHMGxT+8Ym4RsNb48wOFnL76iqhkYP7Cpjb2HFobHEHxMpYgSDRWiXgCg== X-Received: by 2002:a17:907:9703:b0:880:50de:5e86 with SMTP id jg3-20020a170907970300b0088050de5e86mr15641276ejc.3.1675167372189; Tue, 31 Jan 2023 04:16:12 -0800 (PST) Received: from amikhalitsyn.. (ip5f5bf399.dynamic.kabel-deutschland.de. [95.91.243.153]) by smtp.gmail.com with ESMTPSA id lc7-20020a170906f90700b00887a23bab85sm3641693ejb.220.2023.01.31.04.16.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Jan 2023 04:16:11 -0800 (PST) From: Alexander Mikhalitsyn To: corbet@lwn.net Cc: Alexander Mikhalitsyn , linux-fsdevel@vger.kernel.org, linux-doc@vger.kernel.org Subject: [PATCH 2/2] docs: filesystems: vfs: actualize struct super_operations description Date: Tue, 31 Jan 2023 13:16:08 +0100 Message-Id: <20230131121608.177250-1-aleksandr.mikhalitsyn@canonical.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org 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 fab3bd702250..8671eafa745a 100644 --- a/Documentation/filesystems/vfs.rst +++ b/Documentation/filesystems/vfs.rst @@ -242,33 +242,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. As of kernel 6.1, 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 @@ -289,6 +298,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, @@ -316,8 +330,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 @@ -328,14 +346,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. @@ -344,22 +373,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.