From: Kuniyuki Iwashima <kuniyu@amazon.com>
To: <whzhao@gmail.com>
Cc: <davem@davemloft.net>, <edumazet@google.com>, <kuba@kernel.org>,
<linux-kernel@vger.kernel.org>, <netdev@vger.kernel.org>,
<pabeni@redhat.com>
Subject: Re: [PATCH] net/socket: set socket inode times to current_time
Date: Thu, 2 Feb 2023 12:42:24 -0800 [thread overview]
Message-ID: <20230202204224.9668-1-kuniyu@amazon.com> (raw)
In-Reply-To: <20230201043019.592994-1-whzhao@gmail.com>
From: Wenhua Zhao <whzhao@gmail.com>
Date: Tue, 31 Jan 2023 20:30:19 -0800
> Socket creation time are sometimes useful but not available becasue the
> socket inode times are not set when initializing the inode. This patch
> sets the socket inode times to current_time().
>
> Before the fix, the socket inode times are at epoch, for example:
>
> $ stat -L /proc/383/fd/3
> File: /proc/383/fd/3
> Size: 0 Blocks: 0 IO Block: 4096 socket
> Device: 0,8 Inode: 15996 Links: 1
> Access: (0777/srwxrwxrwx) Uid: ( 1000/ arch) Gid: ( 1000/ arch)
> Access: 1970-01-01 00:00:00.000000000 +0000
> Modify: 1970-01-01 00:00:00.000000000 +0000
> Change: 1970-01-01 00:00:00.000000000 +0000
>
> After the fix, the inode times are the socket creation time:
>
> $ stat -L /proc/254/fd/3
> File: /proc/254/fd/3
> Size: 0 Blocks: 0 IO Block: 4096 socket
> Device: 0,7 Inode: 13170 Links: 1
> Access: (0777/srwxrwxrwx) Uid: ( 1000/ arch) Gid: ( 1000/ arch)
> Access: 2023-02-01 03:27:50.094731201 +0000
> Modify: 2023-02-01 03:27:50.094731201 +0000
> Change: 2023-02-01 03:27:50.094731201 +0000
>
> Signed-off-by: Wenhua Zhao <whzhao@gmail.com>
Looks good, but we may want to use another example in changelog
because you can get almost the same time without the -L option
and the use case is bit confusing at least for me.
I guess you will use it in your application, not from the outside
world by stat.
$ python3
>>> from socket import socket
>>> from os import fstat
>>>
>>> sk = socket()
>>> fstat(sk.fileno())
os.stat_result(..., st_atime=0, st_mtime=0, st_ctime=0)
> ---
> net/socket.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/net/socket.c b/net/socket.c
> index 888cd618a968..c656c9599a92 100644
> --- a/net/socket.c
> +++ b/net/socket.c
> @@ -635,6 +635,7 @@ struct socket *sock_alloc(void)
> inode->i_uid = current_fsuid();
> inode->i_gid = current_fsgid();
> inode->i_op = &sockfs_inode_ops;
> + inode->i_mtime = inode->i_atime = inode->i_ctime = current_time(inode);
>
> return sock;
> }
> --
> 2.39.1
prev parent reply other threads:[~2023-02-02 20:42 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-01 4:30 Wenhua Zhao
2023-02-02 20:42 ` Kuniyuki Iwashima [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230202204224.9668-1-kuniyu@amazon.com \
--to=kuniyu@amazon.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=whzhao@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®