From patchwork Mon Mar 14 21:11:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xavier Roche X-Patchwork-Id: 12780794 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0B2E9C433EF for ; Mon, 14 Mar 2022 21:11:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 443386B0071; Mon, 14 Mar 2022 17:11:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3F3D28D0002; Mon, 14 Mar 2022 17:11:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 292B88D0001; Mon, 14 Mar 2022 17:11:54 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0028.hostedemail.com [216.40.44.28]) by kanga.kvack.org (Postfix) with ESMTP id 16EF66B0071 for ; Mon, 14 Mar 2022 17:11:54 -0400 (EDT) Received: from smtpin16.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id C29C21821CBFE for ; Mon, 14 Mar 2022 21:11:53 +0000 (UTC) X-FDA: 79244238906.16.B257B09 Received: from mail-wr1-f41.google.com (mail-wr1-f41.google.com [209.85.221.41]) by imf20.hostedemail.com (Postfix) with ESMTP id 420511C0006 for ; Mon, 14 Mar 2022 21:11:53 +0000 (UTC) Received: by mail-wr1-f41.google.com with SMTP id h15so25999349wrc.6 for ; Mon, 14 Mar 2022 14:11:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=algolia.com; s=google; h=date:from:to:cc:subject:message-id:mime-version:content-disposition; bh=w+42UXCNtAJ9TGLf2A5cmkfyu32cpXBmuZcjtlmKWJM=; b=h/numXueNH979gadCe+KzmYSaDCK5rcefpMQgJuahYkpNRnOX09QntgacPyzicZF3E KRl9VkiNCCUeKCtQXSFQhyYJzOhewjj/SEajVtr688ttT0ECTEvjzvJcL3GjekMf3tk9 lAmpPtfNc7SXLLa+njjpI2uT3Ht5AcFIKHrGY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition; bh=w+42UXCNtAJ9TGLf2A5cmkfyu32cpXBmuZcjtlmKWJM=; b=Lsr7f9X0ytuHJnlgL/5niHyfbfK1GDmBFxeQC8NKZgIBT3sK8AijJgLdEgrh1f3f1J jspasZLKsen0KboRLW0FzI8aF38ZOM4CcoJPUP0WDBpZYryqztY5V4o7mPWuUUzfpcv6 PZSlr4Msb2CqIbNtC/o56ck6Jjp7KH+JDz3GW5pTkAYM8IQEsMG70mHXC2FNqXZ732Tv fWkDAOLS3QLRmlqwceAXjO83SN476i9so1HqV6NRIvMKnN/osSwqu6oEHv0SomEqS9Cn 9M7R0PDDiwi3gqbAyCHv/chCofb80LEE5O1GPsqF+hlDBdjXNmDmZkozEyegdR8i1NWx sPVA== X-Gm-Message-State: AOAM532V3kKIIVZuX2otCcaxO35jazYPypangPQCaqDoVAc1rdSx3chj UYKFta2XeuOxvBvv9mqjupWlSg== X-Google-Smtp-Source: ABdhPJzuQfk/7tfTzPzLwD+eWx12+yu5LILm2C/cqXTReUV/J/EMlCxItFP0C0L0S0jL2o4sxbhGBw== X-Received: by 2002:adf:ed0c:0:b0:1f0:63a5:36aa with SMTP id a12-20020adfed0c000000b001f063a536aamr17823912wro.588.1647292311832; Mon, 14 Mar 2022 14:11:51 -0700 (PDT) Received: from xavier-xps ([2a01:e0a:830:d971:cc11:3255:8bf2:4a49]) by smtp.gmail.com with ESMTPSA id e20-20020adfa454000000b001f01a14dce8sm14346782wra.97.2022.03.14.14.11.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Mar 2022 14:11:51 -0700 (PDT) Date: Mon, 14 Mar 2022 22:11:50 +0100 From: Xavier Roche To: linux-kernel@vger.kernel.org Cc: Hugh Dickins , Andrew Morton , Jean Delvare , Xavier Roche , linux-mm@kvack.org Subject: [PATCH v4] tmpfs: support for file creation time Message-ID: <20220314211150.GA123458@xavier-xps> MIME-Version: 1.0 Content-Disposition: inline X-Rspam-User: X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 420511C0006 X-Stat-Signature: o1q9zzsthus4be8y6restdrsw5nc7stj Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=algolia.com header.s=google header.b="h/numXue"; dmarc=pass (policy=reject) header.from=algolia.com; spf=pass (imf20.hostedemail.com: domain of xavier.roche@algolia.com designates 209.85.221.41 as permitted sender) smtp.mailfrom=xavier.roche@algolia.com X-HE-Tag: 1647292313-251365 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Various filesystems (including ext4) now support file creation time. This patch adds such support for tmpfs-based filesystems. Note that using shmem_getattr() on other file types than regular requires that shmem_is_huge() check type, to stop incorrect HPAGE_PMD_SIZE blksize. Signed-off-by: Xavier Roche Signed-off-by: Hugh Dickins Signed-off-by: Andrew Morton Tested-by: Jean Delvare Tested-by: Xavier Roche Tested-by: Sylvain Bellone Reviewed-by: Jean Delvare Reported-by: Xavier Grand Cc: Xavier Roche Cc: Jean Delvare Link: https://lore.kernel.org/lkml/b954973a-b8d1-cab8-63bd-6ea8063de3@google.com/ --- include/linux/shmem_fs.h | 1 + mm/shmem.c | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/include/linux/shmem_fs.h b/include/linux/shmem_fs.h index e65b80ed09e7..ab51d3cd39bd 100644 --- a/include/linux/shmem_fs.h +++ b/include/linux/shmem_fs.h @@ -24,6 +24,7 @@ struct shmem_inode_info { struct shared_policy policy; /* NUMA memory alloc policy */ struct simple_xattrs xattrs; /* list of xattrs */ atomic_t stop_eviction; /* hold when working on inode */ + struct timespec64 i_crtime; /* file creation time */ struct inode vfs_inode; }; diff --git a/mm/shmem.c b/mm/shmem.c index a09b29ec2b45..f8205b2b0322 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -476,6 +476,8 @@ bool shmem_is_huge(struct vm_area_struct *vma, { loff_t i_size; + if (!S_ISREG(inode->i_mode)) + return false; if (shmem_huge == SHMEM_HUGE_DENY) return false; if (vma && ((vma->vm_flags & VM_NOHUGEPAGE) || @@ -1061,6 +1063,12 @@ static int shmem_getattr(struct user_namespace *mnt_userns, if (shmem_is_huge(NULL, inode, 0)) stat->blksize = HPAGE_PMD_SIZE; + if (request_mask & STATX_BTIME) { + stat->result_mask |= STATX_BTIME; + stat->btime.tv_sec = info->i_crtime.tv_sec; + stat->btime.tv_nsec = info->i_crtime.tv_nsec; + } + return 0; } @@ -1854,9 +1862,6 @@ static int shmem_getpage_gfp(struct inode *inode, pgoff_t index, return 0; } - /* Never use a huge page for shmem_symlink() */ - if (S_ISLNK(inode->i_mode)) - goto alloc_nohuge; if (!shmem_is_huge(vma, inode, index)) goto alloc_nohuge; @@ -2265,6 +2270,7 @@ static struct inode *shmem_get_inode(struct super_block *sb, const struct inode atomic_set(&info->stop_eviction, 0); info->seals = F_SEAL_SEAL; info->flags = flags & VM_NORESERVE; + info->i_crtime = inode->i_mtime; INIT_LIST_HEAD(&info->shrinklist); INIT_LIST_HEAD(&info->swaplist); simple_xattrs_init(&info->xattrs); @@ -3196,6 +3202,7 @@ static ssize_t shmem_listxattr(struct dentry *dentry, char *buffer, size_t size) #endif /* CONFIG_TMPFS_XATTR */ static const struct inode_operations shmem_short_symlink_operations = { + .getattr = shmem_getattr, .get_link = simple_get_link, #ifdef CONFIG_TMPFS_XATTR .listxattr = shmem_listxattr, @@ -3203,6 +3210,7 @@ static const struct inode_operations shmem_short_symlink_operations = { }; static const struct inode_operations shmem_symlink_inode_operations = { + .getattr = shmem_getattr, .get_link = shmem_get_link, #ifdef CONFIG_TMPFS_XATTR .listxattr = shmem_listxattr, @@ -3790,6 +3798,7 @@ static const struct inode_operations shmem_inode_operations = { static const struct inode_operations shmem_dir_inode_operations = { #ifdef CONFIG_TMPFS + .getattr = shmem_getattr, .create = shmem_create, .lookup = simple_lookup, .link = shmem_link, @@ -3811,6 +3820,7 @@ static const struct inode_operations shmem_dir_inode_operations = { }; static const struct inode_operations shmem_special_inode_operations = { + .getattr = shmem_getattr, #ifdef CONFIG_TMPFS_XATTR .listxattr = shmem_listxattr, #endif