Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp5386278pxb; Mon, 7 Feb 2022 00:23:17 -0800 (PST) X-Google-Smtp-Source: ABdhPJwtcSAshsg3v5s0joHJUlCRNzlOiYVW7JKdAybxMbfyl0JJqXQAQCDfGc9fDF3iRJ0DU1uv X-Received: by 2002:a50:c8ca:: with SMTP id k10mr12886970edh.99.1644222197005; Mon, 07 Feb 2022 00:23:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644222196; cv=none; d=google.com; s=arc-20160816; b=U3wl9dWY4S1JMnVAKitW2aJ21XmbqFsdENLxxURdkhcWlGTiEmWuUHn8OLD+zPiCyI zB+JWN4cfe/i6xcaz7+8mhZOihI4KP57t+tII9ItlQzMTjPhCaGk4nlhoKhtC5MhAPLF WQVgpbo5g08CXZRvgnBHP+n1hOB6Md0hVsXdc8hT6bzUoCOKCfyqK1bUh1ltnN9L9Ikn goiBmIG+sYTmnLoE9X9QR+rh+q2B8Z1wJbR+0OmUe8w+/3T7Ty3pqztmaZJh2SuUSJ5K LDxggqisil4v/aBXTLm2FdIyExlieqUc96DFRW2avtFGh8j1n6WsCY0G8a6mfTTYNhM8 caLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-disposition:mime-version:message-id :subject:cc:to:from:date:dkim-signature; bh=OOEtnw8xKF5peU7h9AlWIN/mhVNk/Fs8o4NsdA8KyPE=; b=ON77P8MZe2dxG6FCNKUAjYigXNLc9tyu8tZfIzjkhNqbiEn2ZP6o7r3Nx6kq522qtj qt9lxsKXabSQs6bS9gR8Y18CBNllGU0GD+f7H6q/hTNHjlUes6uS4NGXHOER2zNpq7hD lhR9fzWpwzrGe4+dD9knBPM8A05XziERb0+VR1r+XQynXZzxQnCOMGqj08PhaaWGq216 7QFZDiVf6C4yaZWXUUI/QrYfssPskDCS6iuhDejX3x5TRL1xm4YpzqfNvjL8rYbsnp/s NHYXOfmlFn8dbbu3cs6/iXOQpQvA15QY4DbhxzmIDiSFUvxC+wZNFVpV1WlbXLlFTnq7 sMzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@algolia.com header.s=google header.b=pV7Xh5Pn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=algolia.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ji14si7264024ejc.505.2022.02.07.00.22.51; Mon, 07 Feb 2022 00:23:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@algolia.com header.s=google header.b=pV7Xh5Pn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=algolia.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377606AbiBEOMj (ORCPT + 99 others); Sat, 5 Feb 2022 09:12:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36034 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239170AbiBEOMi (ORCPT ); Sat, 5 Feb 2022 09:12:38 -0500 Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6A8A5C061346 for ; Sat, 5 Feb 2022 06:12:37 -0800 (PST) Received: by mail-wr1-x435.google.com with SMTP id e3so2584125wra.0 for ; Sat, 05 Feb 2022 06:12:37 -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=kCZgqa6HRAmvuW51smNm4jV04EJ2YMoG6RhVpu7r5PsxSimmUhNFV+EAXcjCEG69pO G90ZoFYv1esH+2sNcYdwB3DFKJiOJhBsze3m9Rhw7mVKkAnDJn2gwBuKMBzDMAJJDzLh Icr0nzS7W+5IRVsxMhOCedg8ytDhrrknPTL8YPnEHQLJj+PPM90okMPJdGXq5wGmeE0K V9ksbm6q7GEdghmusThCpgrFHljrYZQou8VC0lMpWQwxSH8Cv8CwHnm7QPpQeOuUhlfC YjnEK7qb7zTwbRriW5HwxOLwifN9/wXzeFr9Ol/UeMpKzBwxZPFvP6nWQPD+K5ypEzML 6MJw== X-Gm-Message-State: AOAM533pfoyN8uHP1pnu6v1ZCzddcJ6p5spoJS2pHJSkMpfaoEw16n7I zmjU2Ztj6Vn90FuSFGiPrSiRMBSy0qzwVg== 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-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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 -- 2.25.1