Skip to content

Set creation/change time (otime/ctime) for offline-created subvolumes and convertd root subvolume - #1157

Merged
adam900710 merged 2 commits into
kdave:develfrom
koraynilay:convert-creation-time
Aug 30, 2026
Merged

Set creation/change time (otime/ctime) for offline-created subvolumes and convertd root subvolume#1157
adam900710 merged 2 commits into
kdave:develfrom
koraynilay:convert-creation-time

Conversation

@koraynilay

@koraynilay koraynilay commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Fix subvol->otime and subvol->ctime not being set on:

  • the root subvolume of a btrfs-convertd filesystem
  • subvolumes created by mkfs.btrfs using --rootdir and --subvol options
  • (less important) the ext2_saved subvolume of a btrfs-convert'd filesystem

Thanks

…subvol

Before this, btrfs-convert would leave the root subvol of the converted
fs with 0 as both otime and ctime, showing "-" when using
btrfs subvolume show /path.

This patch uses the code from mkfs.btrfs's btrfs_create_tree_root() to
set the otime/ctime to the root subvol and generate its UUID right away
(instead of having to wait for btrfs_rebuild_uuid_tree(), not
necessarily needed but cleaner).

This way the timestamp of the filesystem conversion will be available in
the "Creation time" field of btrfs subvolume show /path output, while
the original ext* "Filesystem created" timestamp is available with stat
as the mountpoint's birth time.

Assisted-by: Claude:opus-4.6 antigravity-cli-1.1.7
Assisted-by: Gemini:3.1-pro antigravity-cli-1.1.7
Signed-off-by: koraynilay <koray.fra@gmail.com>
…d subvolumes

Update common/root-tree-utils.c's btrfs_make_subvolume() to also
generate a UUID and set otime and ctime of subvolumes created offline
(if it's a normal subvolume).

This is essentially the same change as commit 0cdfd08
("btrfs-progs: convert: set creation/change time (otime/ctime) of root
subvol") but that applies to:
* mkfs.btrfs' --rootdir and --subvol options
* btrfs-convert's ext2_saved subvolume

Assisted-by: Gemini:3.1-pro antigravity-cli-1.1.7
Signed-off-by: koraynilay <koray.fra@gmail.com>

@adam900710 adam900710 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only very tiny issues related to headers.

Otherwise looks good to me.

You do not need to refresh the patches, I will change them during merge.

Comment thread convert/common.c
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to include time.h explicitly, it's already included by some other headers.

Comment thread common/root-tree-utils.c
*/

#include "kerncompat.h"
#include <string.h>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to include that header explicitly.

There are already users of memset() in the same file, thus it's already included by some other headers.

@adam900710
adam900710 merged commit d1b25e9 into kdave:devel Aug 30, 2026
1 check passed
@koraynilay

Copy link
Copy Markdown
Contributor Author

Thanks, btw I added the headers because I checked other files and e.g. cmds/subvolume.c has an explicit #include <time.h> that was introduced in commit 40c4ba7 because of IWYU (include what you use) so I thought it would be cleaner.

@adam900710

Copy link
Copy Markdown
Collaborator

Normally I only add headers when the LSP server is showing errors or unable to complete the function.

It's already pretty messy to manage the headers for C, so I tend to not include extra unless it failed to compile.

Overall you don't need to bother as long as the project still compiles.

@kdave kdave added this to the v7.2 milestone Sep 8, 2026
kdave pushed a commit that referenced this pull request Sep 8, 2026
…subvol

Before this, btrfs-convert would leave the root subvol of the converted
fs with 0 as both otime and ctime, showing "-" when using
btrfs subvolume show /path.

This patch uses the code from mkfs.btrfs's btrfs_create_tree_root() to
set the otime/ctime to the root subvol and generate its UUID right away
(instead of having to wait for btrfs_rebuild_uuid_tree(), not
necessarily needed but cleaner).

This way the timestamp of the filesystem conversion will be available in
the "Creation time" field of btrfs subvolume show /path output, while
the original ext* "Filesystem created" timestamp is available with stat
as the mountpoint's birth time.

Pull-request: #1157
Assisted-by: Claude:opus-4.6 antigravity-cli-1.1.7
Assisted-by: Gemini:3.1-pro antigravity-cli-1.1.7
Signed-off-by: koraynilay <koray.fra@gmail.com>
Reviewed-by: Qu Wenruo <wqu@suse.com>
[ Remove the duplicated <time.h> header inclusion ]
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
kdave pushed a commit that referenced this pull request Sep 8, 2026
…d subvolumes

Update common/root-tree-utils.c's btrfs_make_subvolume() to also
generate a UUID and set otime and ctime of subvolumes created offline
(if it's a normal subvolume).

This is essentially the same change as commit ("btrfs-progs: convert:
set creation/change time (otime/ctime) of root subvol") but that applies to:

* mkfs.btrfs' --rootdir and --subvol options
* btrfs-convert's ext2_saved subvolume

Pull-request: #1157
Assisted-by: Gemini:3.1-pro antigravity-cli-1.1.7
Signed-off-by: koraynilay <koray.fra@gmail.com>
Reviewed-by: Qu Wenruo <wqu@suse.com>
[ Remove the duplicated <string.h> header inclusion ]
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants