From patchwork Sat Feb 5 14:12:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xavier Roche X-Patchwork-Id: 12736074 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 9A404C433EF for ; Sat, 5 Feb 2022 14:12:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D2F206B0088; Sat, 5 Feb 2022 09:12:37 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CB7B86B0089; Sat, 5 Feb 2022 09:12:37 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BA62A6B008A; Sat, 5 Feb 2022 09:12:37 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0211.hostedemail.com [216.40.44.211]) by kanga.kvack.org (Postfix) with ESMTP id A69696B0088 for ; Sat, 5 Feb 2022 09:12:37 -0500 (EST) Received: from smtpin07.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 671438249980 for ; Sat, 5 Feb 2022 14:12:37 +0000 (UTC) X-FDA: 79108916754.07.02DA456 Received: from mail-wr1-f48.google.com (mail-wr1-f48.google.com [209.85.221.48]) by imf18.hostedemail.com (Postfix) with ESMTP id 218291C0002 for ; Sat, 5 Feb 2022 14:12:37 +0000 (UTC) Received: by mail-wr1-f48.google.com with SMTP id m27so2647277wrb.2 for ; Sat, 05 Feb 2022 06:12:36 -0800 (PST) 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=OOEtnw8xKF5peU7h9AlWIN/mhVNk/Fs8o4NsdA8KyPE=; b=pV7Xh5PnAO84jxxZcVD7WuvvvlbgYHisTwMUv0V5B/KP970NuI64fOESHlXxNqVcvL +cEFxbGZnxGBRL+2kvt9KpGLcTOh1uQcCx+lyKSlVOmeOw4Pon3Z2MlTrKgwOc3oqQ9E YukEJg7wApWSZr6zOzZMkWkyQ+NZ0CQq1vH0Q= 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=OOEtnw8xKF5peU7h9AlWIN/mhVNk/Fs8o4NsdA8KyPE=; b=WEAgQBL4tBGkD2XmT5ondlgHodUvqRYly278nxjJMCS+E8ykcgD5vTrm/SpM/aTCdt +HVKEMfAIpYGQcC9DMMF3T4grzGH3kPjln+80v/MmapGuKGwI4IXpQLNBi9VzcQUGsvI ObKwxiqDvr1SeqIhQAK7EdLeNY2gICR7AnnPj6fOZZsonuLwc+H6KAoJd8b7UDKVu3eQ SWcd6nUHYTGxUbbEQF/8DEQhoN2BlcbdIK9AEipQhTVeJ9/h85THWiEYY2Dc8PrqeC3t SCvwi0oPeqhsYAYJQI6y5XZfeSiaq2v1LNHi/uvNGPFQZ+GHUjN7PuPaDtEdAHVKCt72 7MHg== X-Gm-Message-State: AOAM532Z+85bpZ+EtATeuysp2aTSWX6zFU3DXM3pMIMFybHodDnTNAbi nG1CKlgJT8YUrv3SKqpWvLBGbA== X-Google-Smtp-Source: ABdhPJwLqN0XhniFdPIk8WXQzvVT7Vuni7tXNmCF6Ihnkq6oGE2q5M7SCowUOUlIzmzpco8yS8r+Tg== X-Received: by 2002:a05:6000:184a:: with SMTP id c10mr3157663wri.212.1644070355724; Sat, 05 Feb 2022 06:12:35 -0800 (PST) Received: from xavier-xps ([2a01:e0a:830:d971:752e:e19b:a691:2171]) by smtp.gmail.com with ESMTPSA id g6sm4559293wrq.97.2022.02.05.06.12.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Feb 2022 06:12:35 -0800 (PST) Date: Sat, 5 Feb 2022 15:12:33 +0100 From: Xavier Roche To: LKML Cc: Xavier Roche , Hugh Dickins , Linux Memory Management List Subject: [PATCH RFC v1] tmpfs: support for file creation time Message-ID: <20220205141233.GA938324@xavier-xps> MIME-Version: 1.0 Content-Disposition: inline X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 218291C0002 X-Stat-Signature: pmc6aprbi37kdkqxfec17fuwpuz75hfd X-Rspam-User: nil Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=algolia.com header.s=google header.b=pV7Xh5Pn; spf=pass (imf18.hostedemail.com: domain of xavier.roche@algolia.com designates 209.85.221.48 as permitted sender) smtp.mailfrom=xavier.roche@algolia.com; dmarc=pass (policy=reject) header.from=algolia.com X-HE-Tag: 1644070357-121790 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000001, 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 tentatively adds such support for tmpfs-based filesystems. The reason is that creation time has been supported on an increasing number of filesystems (this information can be retrieved through the statx() userland function), and its support for tmpfs would add consistency. Example of use includes checking the creation time of an ephemeral status file being updated (such as a "work in progress" placeholder), to get two time points (starting point and last update). Note that I am nothing but a new contributor, and while this patch has been tested (and userland results checked), the logic might be broken. Signed-off-by: Xavier Roche Tested-by: Jean Delvare Reviewed-by: Jean Delvare --- include/linux/shmem_fs.h | 1 + mm/shmem.c | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/include/linux/shmem_fs.h b/include/linux/shmem_fs.h index e65b80ed09e7..29787767c3b9 100644 --- a/include/linux/shmem_fs.h +++ b/include/linux/shmem_fs.h @@ -25,6 +25,7 @@ struct shmem_inode_info { struct simple_xattrs xattrs; /* list of xattrs */ atomic_t stop_eviction; /* hold when working on inode */ struct inode vfs_inode; + struct timespec64 i_crtime; /* file creation time */ }; struct shmem_sb_info { diff --git a/mm/shmem.c b/mm/shmem.c index a09b29ec2b45..5a3907712c4f 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -1061,6 +1061,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; } @@ -2265,6 +2271,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 +3203,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 +3211,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 +3799,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 +3821,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