linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Btrfs: Add code to support file creation time.
@ 2012-07-04  7:18 chandan r
  2012-07-04  7:56 ` Li Zefan
  0 siblings, 1 reply; 7+ messages in thread
From: chandan r @ 2012-07-04  7:18 UTC (permalink / raw)
  To: linux-btrfs

This patch adds a new member to the 'struct btrfs_inode' structure to hold
the file creation time.

Signed-off-by: chandan <chandanrmail@gmail.com>
---
 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(-)

diff --git a/fs/btrfs/btrfs_inode.h b/fs/btrfs/btrfs_inode.h
index 12394a9..b761456 100644
--- a/fs/btrfs/btrfs_inode.h
+++ b/fs/btrfs/btrfs_inode.h
@@ -162,6 +162,9 @@ struct btrfs_inode {
 
 	struct btrfs_delayed_node *delayed_node;
 
+	/* File creation time. */
+	struct timespec i_otime;
+
 	struct inode vfs_inode;
 };
 
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index fa5c45b..4ce172f 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -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);
 
diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c
index 21d91a8..63726967 100644
--- a/fs/btrfs/delayed-inode.c
+++ b/fs/btrfs/delayed-inode.c
@@ -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);
 	}
 }
-
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 0d507e6..145a2ed 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -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);
-- 
1.7.11


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH] Btrfs: Add code to support file creation time.
  2012-07-04  7:18 [PATCH] Btrfs: Add code to support file creation time chandan r
@ 2012-07-04  7:56 ` Li Zefan
  2012-07-04 11:04   ` Alexander Block
  0 siblings, 1 reply; 7+ messages in thread
From: Li Zefan @ 2012-07-04  7:56 UTC (permalink / raw)
  To: chandan r; +Cc: linux-btrfs

On 2012/7/4 15:18, chandan r wrote:

> 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.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] Btrfs: Add code to support file creation time.
  2012-07-04  7:56 ` Li Zefan
@ 2012-07-04 11:04   ` Alexander Block
  2012-07-05  1:07     ` Li Zefan
  2012-09-30  8:13     ` Arne Jansen
  0 siblings, 2 replies; 7+ messages in thread
From: Alexander Block @ 2012-07-04 11:04 UTC (permalink / raw)
  To: Li Zefan; +Cc: chandan r, linux-btrfs

On Wed, Jul 4, 2012 at 9:56 AM, Li Zefan <lizefan@huawei.com> wrote:
> On 2012/7/4 15:18, chandan r wrote:
>
>> 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.
> --
> To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] Btrfs: Add code to support file creation time.
  2012-07-04 11:04   ` Alexander Block
@ 2012-07-05  1:07     ` Li Zefan
  2012-07-05  1:52       ` Alexander Block
  2012-09-30  8:13     ` Arne Jansen
  1 sibling, 1 reply; 7+ messages in thread
From: Li Zefan @ 2012-07-05  1:07 UTC (permalink / raw)
  To: Alexander Block; +Cc: chandan r, linux-btrfs

On 2012/7/4 19:04, Alexander Block wrote:

> On Wed, Jul 4, 2012 at 9:56 AM, Li Zefan <lizefan@huawei.com> wrote:
>> On 2012/7/4 15:18, chandan r wrote:
>>
>>> 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.


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.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] Btrfs: Add code to support file creation time.
  2012-07-05  1:07     ` Li Zefan
@ 2012-07-05  1:52       ` Alexander Block
  2012-07-10  5:36         ` Li Zefan
  0 siblings, 1 reply; 7+ messages in thread
From: Alexander Block @ 2012-07-05  1:52 UTC (permalink / raw)
  To: Li Zefan; +Cc: chandan r, linux-btrfs

On Thu, Jul 5, 2012 at 3:07 AM, Li Zefan <lizefan@huawei.com> wrote:
> On 2012/7/4 19:04, Alexander Block wrote:
>
>> On Wed, Jul 4, 2012 at 9:56 AM, Li Zefan <lizefan@huawei.com> wrote:
>>> On 2012/7/4 15:18, chandan r wrote:
>>>
>>>> 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.
>
>
> 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.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] Btrfs: Add code to support file creation time.
  2012-07-05  1:52       ` Alexander Block
@ 2012-07-10  5:36         ` Li Zefan
  0 siblings, 0 replies; 7+ messages in thread
From: Li Zefan @ 2012-07-10  5:36 UTC (permalink / raw)
  To: Alexander Block; +Cc: chandan r, linux-btrfs

On 2012/7/5 9:52, Alexander Block wrote:

> On Thu, Jul 5, 2012 at 3:07 AM, Li Zefan <lizefan@huawei.com> wrote:
>> On 2012/7/4 19:04, Alexander Block wrote:
>>
>>> On Wed, Jul 4, 2012 at 9:56 AM, Li Zefan <lizefan@huawei.com> wrote:
>>>> On 2012/7/4 15:18, chandan r wrote:
>>>>
>>>>> 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.
>>
>>
>> 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.
> 


That's bad..

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] Btrfs: Add code to support file creation time.
  2012-07-04 11:04   ` Alexander Block
  2012-07-05  1:07     ` Li Zefan
@ 2012-09-30  8:13     ` Arne Jansen
  1 sibling, 0 replies; 7+ messages in thread
From: Arne Jansen @ 2012-09-30  8:13 UTC (permalink / raw)
  To: Alexander Block; +Cc: Li Zefan, chandan r, linux-btrfs

On 07/04/12 13:04, Alexander Block wrote:
> On Wed, Jul 4, 2012 at 9:56 AM, Li Zefan <lizefan@huawei.com> wrote:
>> On 2012/7/4 15:18, chandan r wrote:
>>
>>> 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.

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


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2012-09-30  8:12 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-07-04  7:18 [PATCH] Btrfs: Add code to support file creation time chandan r
2012-07-04  7:56 ` Li Zefan
2012-07-04 11:04   ` Alexander Block
2012-07-05  1:07     ` Li Zefan
2012-07-05  1:52       ` Alexander Block
2012-07-10  5:36         ` Li Zefan
2012-09-30  8:13     ` Arne Jansen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).