From patchwork Fri Feb 4 17:04:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xavier Roche X-Patchwork-Id: 12735314 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 BD3CFC433EF for ; Fri, 4 Feb 2022 17:04:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238730AbiBDREO (ORCPT ); Fri, 4 Feb 2022 12:04:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54510 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236336AbiBDREO (ORCPT ); Fri, 4 Feb 2022 12:04:14 -0500 Received: from mail-lj1-x22f.google.com (mail-lj1-x22f.google.com [IPv6:2a00:1450:4864:20::22f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 186E6C061714 for ; Fri, 4 Feb 2022 09:04:14 -0800 (PST) Received: by mail-lj1-x22f.google.com with SMTP id j14so9412440lja.3 for ; Fri, 04 Feb 2022 09:04:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=algolia.com; s=google; h=mime-version:from:date:message-id:subject:to; bh=sHNaCUSyi40jeSk5rgZsLUetSbk8OD0s9HLyoh3WK4w=; b=oJYKx0DA3ZTIhgzaDcg3HdM8ROoOxU4w6uPwwEmu95Ml/6Th5nAGRhzjpnAHrKm884 9aKKpS7bb0NHPlfIUN6j8brLaenqTIfTwpeK1+DjZ4LAMOGyN2SExEf+0AF1X8g9rt3H sFI0/2Yb6/AGMgwJHcSNm0cbDKrbDOLz4UIWg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=sHNaCUSyi40jeSk5rgZsLUetSbk8OD0s9HLyoh3WK4w=; b=PArCJbWPaz28nqN4d7fg/Hp0Cig374tsIkpSgWNDfD3bRDKtnK07mM4msOHQJIkuLW mAzkusuCOL/pVXhAPdLQECVnDr6C6T7/NoNVxn4jK3WTlwoJ5/jde6fOISs2p8PaulnB 0iE3/1ZvmoJRRqKtJRsAYnAqYUNIPxlJxoJTu2pMKO8wkn0Ma4vCoSNckP4dfUOnbL3o 3eEK4SpL3wVS/wGhxQ+ukxzarlNn/9uYQoWHEAFswKewpZTn+nsWSZJ7gA2zSvpU7RAv 35mFbFuJHartmfXK3o55wTUdZM7gCEGXFqowFvqpuyLbZcpF+Q7bzDbUOAhn87Wmpq8Y kKfg== X-Gm-Message-State: AOAM530EkmYwCoEREvt08E+sVYl4RQPJJoIMqpp1ShpCkm98kgv8CrJe P2iXWjRBxdemINumtG9Af9caP+jilkOdsj7LPoMsPNCe4+Pnww== X-Google-Smtp-Source: ABdhPJwl4FzxprQpirDXGCRk8rYsALsCrs3A+5QCUbWl9aWTqtjqtRUoIPU4NnJC1n0/HWLexJKN5+6bAiRrRl6OS+8= X-Received: by 2002:a05:651c:2122:: with SMTP id a34mr2322775ljq.50.1643994252032; Fri, 04 Feb 2022 09:04:12 -0800 (PST) MIME-Version: 1.0 From: Xavier Roche Date: Fri, 4 Feb 2022 18:04:01 +0100 Message-ID: Subject: [PATCH RFC] Support for btime (creation time) for tmpfs/shmem ? To: linux-fsdevel Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Hi, I am wondering if including support for creation time for tmpfs would be something sensible ? The attached patch tentatively adds support for a creation time in mm/shmem.c, but the patch is probably incomplete or broken, because while files do appear to behave correctly in tmpfs (birth time is correctly set, and unmodified when the file is touched), directories do not appear to bear any metadata (I am missing an obvious other codepath than shmem_getattr). Any comment (or rebuttal) welcome. Note: the birth time can be checked with the now standard statx call: #include #include #include #include #include #include int main(int argc, char** argv) { if (argc == 1) { fprintf(stderr, "Usage: %s [file...]\n", argv[0]); } int i; for (i = 1; i < argc; i++) { struct statx st; if (statx(AT_FDCWD, argv[i], 0, STATX_ALL, &st) == 0) { fprintf(stderr, "file='%s',\tmtime == %ld,\tbtime == %ld\n", argv[i], (long)st.stx_mtime.tv_sec, (long)st.stx_btime.tv_sec); } else { perror("statx"); } } return EXIT_SUCCESS; } From cbcfc268694eaf8493cb7a43c40cb933b4bf1aa2 Mon Sep 17 00:00:00 2001 From: Xavier Roche Date: Thu, 3 Feb 2022 16:04:02 +0100 Subject: [PATCH] mm: support for file creation time --- include/linux/shmem_fs.h | 1 + mm/shmem.c | 7 +++++++ 2 files changed, 8 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..471e8b6e91f1 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); -- 2.25.1