Btrfs: Add code to support file creation time.
PATCH 1/1 Btrfs: Add code to support file creation time.
This patch adds a new member to the 'struct btrfs_inode' structure to hold the file creation time.
--- fs/btrfs/btrfs_inode.h | 3 +++ fs/btrfs/ctree.h | 8 ++++++++ fs/btrfs/delayed-inode.c | 10 +++++++++- fs/btrfs/inode.c | 25 ++++++++++++++++++++++--- 4 files changed, 42 insertions(+), 4 deletions(-)
fs/btrfs/btrfs_inode.h +3 -0
@@ -162,6 +162,9 @@ struct btrfs_inode {struct btrfs_delayed_node *delayed_node; +/* File creation time. */ +struct timespec i_otime; +struct inode vfs_inode; };
fs/btrfs/ctree.h +8 -0
@@ -1816,6 +1816,14 @@ btrfs_inode_ctime(struct btrfs_inode_item *inode_item)return (struct btrfs_timespec *)ptr; } +static inline struct btrfs_timespec * +btrfs_inode_otime (struct btrfs_inode_item *inode_item) +{ +unsigned long ptr = (unsigned long )inode_item; + ptr += offsetof(struct btrfs_inode_item , otime); +return (struct btrfs_timespec *)ptr; +} + BTRFS_SETGET_FUNCS(timespec_sec, struct btrfs_timespec, sec, 64); BTRFS_SETGET_FUNCS(timespec_nsec, struct btrfs_timespec, nsec, 32);
fs/btrfs/delayed-inode.c +9 -1
@@ -1742,6 +1742,11 @@ static void fill_stack_inode_item(struct btrfs_trans_handle *trans, inode->i_ctime.tv_sec);btrfs_set_stack_timespec_nsec (btrfs_inode_ctime (inode_item), inode->i_ctime.tv_nsec); + +btrfs_set_stack_timespec_sec (btrfs_inode_otime (inode_item), +BTRFS_I (inode)->i_otime.tv_sec); +btrfs_set_stack_timespec_nsec (btrfs_inode_otime (inode_item), +BTRFS_I (inode)->i_otime.tv_nsec); }int btrfs_fill_inode (struct inode *inode,u32 *rdev)
@@ -1787,6 +1792,10 @@ int btrfs_fill_inode(struct inode *inode, u32 *rdev) inode->i_ctime.tv_sec =btrfs_stack_timespec_sec (tspec); inode->i_ctime.tv_nsec =btrfs_stack_timespec_nsec (tspec); + tspec =btrfs_inode_otime (inode_item); +BTRFS_I (inode)->i_otime.tv_sec =btrfs_stack_timespec_sec (tspec); +BTRFS_I (inode)->i_otime.tv_nsec =btrfs_stack_timespec_nsec (tspec); + inode->i_generation =BTRFS_I (inode)->generation;BTRFS_I (inode)->index_cnt = (u64)-1 ;
@@ -1912,4 +1921,3 @@ void btrfs_destroy_delayed_inodes(struct btrfs_root *root)btrfs_release_delayed_node (prev_node); } } -
fs/btrfs/inode.c +22 -3
@@ -2581,6 +2581,10 @@ static void btrfs_read_locked_inode(struct inode *inode) inode->i_ctime.tv_sec =btrfs_timespec_sec (leaf, tspec); inode->i_ctime.tv_nsec =btrfs_timespec_nsec (leaf, tspec); + tspec =btrfs_inode_otime (inode_item); +BTRFS_I (inode)->i_otime.tv_sec =btrfs_timespec_sec (leaf, tspec); +BTRFS_I (inode)->i_otime.tv_nsec =btrfs_timespec_nsec (leaf, tspec); +inode_set_bytes (inode,btrfs_inode_nbytes (leaf, inode_item));BTRFS_I (inode)->generation =btrfs_inode_generation (leaf, inode_item); inode->i_version =btrfs_inode_sequence (leaf, inode_item);
@@ -2665,6 +2669,11 @@ static void fill_inode_item(struct btrfs_trans_handle *trans,btrfs_set_timespec_nsec (leaf,btrfs_inode_ctime (item), inode->i_ctime.tv_nsec); +btrfs_set_timespec_sec (leaf,btrfs_inode_otime (item), +BTRFS_I (inode)->i_otime.tv_sec); +btrfs_set_timespec_nsec (leaf,btrfs_inode_otime (item), +BTRFS_I (inode)->i_otime.tv_nsec); +btrfs_set_inode_nbytes (leaf, item,inode_get_bytes (inode));btrfs_set_inode_generation (leaf, item,BTRFS_I (inode)->generation);btrfs_set_inode_sequence (leaf, item, inode->i_version);
@@ -2846,7 +2855,7 @@ int btrfs_unlink_inode(struct btrfs_trans_handle *trans, }return ret; } - +/* helper to check if there is any shared block in the path */ static int check_path_shared(struct btrfs_root *root,
@@ -4151,7 +4160,11 @@ static struct inode *new_simple_dir(struct super_block *s, inode->i_op = &btrfs_dir_ro_inode_operations; inode->i_fop = &simple_dir_operations; inode->i_mode =S_IFDIR |S_IRUGO |S_IWUSR |S_IXUGO ; - inode->i_mtime = inode->i_atime = inode->i_ctime =CURRENT_TIME ; +BTRFS_I (inode)->i_otime + = inode->i_mtime + = inode->i_atime + = inode->i_ctime + =CURRENT_TIME ;return inode; }
@@ -4687,7 +4700,11 @@ static struct inode *btrfs_new_inode(struct btrfs_trans_handle *trans,inode_init_owner (inode, dir, mode);inode_set_bytes (inode,0 ); - inode->i_mtime = inode->i_atime = inode->i_ctime =CURRENT_TIME ; +BTRFS_I (inode)->i_otime + = inode->i_mtime + = inode->i_atime + = inode->i_ctime + =CURRENT_TIME ; inode_item =btrfs_item_ptr (path->nodes[0 ], path->slots[0 ], struct btrfs_inode_item);fill_inode_item (trans, path->nodes[0 ], inode_item, inode);
@@ -6960,6 +6977,8 @@ struct inode *btrfs_alloc_inode(struct super_block *sb) ei->delayed_node =NULL ; + ei->i_otime.tv_sec = ei->i_otime.tv_nsec =0 ; + inode = &ei->vfs_inode;extent_map_tree_init (&ei->extent_tree);extent_io_tree_init (&ei->io_tree, &inode->i_data);
Signature · 1 line
1.7.11
Quoted 3 lines · chandan r
This patch adds a new member to the 'struct
btrfs_inode' structure to hold the file creation time.
Well, how do users use this file creation time? There's no syscall and there's no ioctl that exports this information. That xstat syscall hasn't been accepted, so you can revise and repost the patch when you see it happens.
Quoted 10 lines · Li Zefan
Quoted 3 lines · chandan r
This patch adds a new member to the 'struct
btrfs_inode' structure to hold the file creation time.Well, how do users use this file creation time? There's no syscall and there's no ioctl that exports this information. That xstat syscall hasn't been accepted, so you can revise and repost the patch when you see it happens.
In my opinion we should still include this patch. Currently, otime is never even initialized, having undefined values. If it ever gets possible to access otime, we
would at least have some inodes with valid otime fields.
Quoted 4 lines
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 8 lines · Alexander Block
Quoted 7 lines · Li Zefan
Quoted 3 lines · chandan r
This patch adds a new member to the 'struct
btrfs_inode' structure to hold the file creation time.
Quoted 7 lines
Quoted 3 lines
Well, how do users use this file creation time? There's no syscall and there's no ioctl that exports this information. That xstat syscall hasn't been accepted, so you can revise and repost the patch when you see it happens.
In my opinion we should still include this patch. Currently, otime is never even initialized, having undefined values. If it ever gets possible to access otime, we
would at least have some inodes with valid otime fields.
otime (on disk) is initialized to 0, not some undefined value. But yeah, your point makes some sense, that with this patch we can access valid otime in an old filesystem once we update to a new kernel which has otime support.
Quoted 19 lines · Li Zefan
Quoted 8 lines · Alexander Block
Quoted 7 lines · Li Zefan
Quoted 3 lines · chandan r
This patch adds a new member to the 'struct
btrfs_inode' structure to hold the file creation time.Quoted 7 lines
Quoted 3 lines
Well, how do users use this file creation time? There's no syscall and there's no ioctl that exports this information. That xstat syscall hasn't been accepted, so you can revise and repost the patch when you see it happens.
In my opinion we should still include this patch. Currently, otime is never even initialized, having undefined values. If it ever gets possible to access otime, we
would at least have some inodes with valid otime fields.
Quoted 3 lines
otime (on disk) is initialized to 0, not some undefined value. But yeah, your point makes some sense, that with this patch we can access valid otime in an old filesystem once we update to a new kernel which has otime support.
This is true for the inode items found in the root tree. But the inode items found in the filesystem trees are not initialized at all. I did a fast check by adding printing of the otime field in btrfs-debug-tree...and every inode's otime looks random. btrfs_new_inode uses btrfs_insert_empty_items which does not zero the new item, then fill_inode_item is used to initialize the fields and there otime is missing.
Quoted 23 lines · Alexander Block
Quoted 19 lines · Li Zefan
Quoted 8 lines · Alexander Block
Quoted 7 lines · Li Zefan
Quoted 3 lines · chandan r
This patch adds a new member to the 'struct
btrfs_inode' structure to hold the file creation time.Quoted 7 lines
Quoted 3 lines
Well, how do users use this file creation time? There's no syscall and there's no ioctl that exports this information. That xstat syscall hasn't been accepted, so you can revise and repost the patch when you see it happens.
In my opinion we should still include this patch. Currently, otime is never even initialized, having undefined values. If it ever gets possible to access otime, we
would at least have some inodes with valid otime fields.Quoted 3 lines
otime (on disk) is initialized to 0, not some undefined value. But yeah, your point makes some sense, that with this patch we can access valid otime in an old filesystem once we update to a new kernel which has otime support.
Quoted 8 lines
This is true for the inode items found in the root tree. But the inode items found in the filesystem trees are not initialized at all. I did a fast check by adding printing of the otime field in btrfs-debug-tree...and every inode's otime looks random.
btrfs_new_inodeusesbtrfs_insert_empty_itemswhich does not zero the new item, thenfill_inode_itemis used to initialize the fields and there otime is missing.
That's bad..
Quoted 8 lines · Alexander Block
Quoted 7 lines · Li Zefan
Quoted 3 lines · chandan r
This patch adds a new member to the 'struct
btrfs_inode' structure to hold the file creation time.
Quoted 7 lines
Quoted 3 lines
Well, how do users use this file creation time? There's no syscall and there's no ioctl that exports this information. That xstat syscall hasn't been accepted, so you can revise and repost the patch when you see it happens.
In my opinion we should still include this patch. Currently, otime is never even initialized, having undefined values. If it ever gets possible to access otime, we
would at least have some inodes with valid otime fields.
I'll second that, even if by now the fields get correctly initialized. Why should we zero the fields instead of setting them to the correct values?
-Arne