From: Damien Le Moal <dlemoal@kernel.org>
To: Jeff Layton <jlayton@kernel.org>,
jk@ozlabs.org, arnd@arndb.de, mpe@ellerman.id.au,
npiggin@gmail.com, christophe.leroy@csgroup.eu,
hca@linux.ibm.com, gor@linux.ibm.com, agordeev@linux.ibm.com,
borntraeger@linux.ibm.com, svens@linux.ibm.com,
gregkh@linuxfoundation.org, arve@android.com, tkjos@android.com,
maco@android.com, joel@joelfernandes.org, brauner@kernel.org,
cmllamas@google.com, surenb@google.com,
dennis.dalessandro@cornelisnetworks.com, jgg@ziepe.ca,
leon@kernel.org, bwarrum@linux.ibm.com, rituagar@linux.ibm.com,
ericvh@kernel.org, lucho@ionkov.net, asmadeus@codewreck.org,
linux_oss@crudebyte.com, dsterba@suse.com, dhowells@redhat.com,
marc.dionne@auristor.com, viro@zeniv.linux.org.uk,
raven@themaw.net, luisbg@kernel.org, salah.triki@gmail.com,
aivazian.tigran@gmail.com, ebiederm@xmission.com,
keescook@chromium.org, clm@fb.com, josef@toxicpanda.com,
xiubli@redhat.com, idryomov@gmail.com, jaharkes@cs.cmu.edu,
coda@cs.cmu.edu, jlbec@evilplan.org, hch@lst.de,
nico@fluxnic.net, rafael@kernel.org, code@tyhicks.com,
ardb@kernel.org, xiang@kernel.org, chao@kernel.org,
huyue2@coolpad.com, jefflexu@linux.alibaba.com,
linkinjeon@kernel.org, sj1557.seo@samsung.com, jack@suse.com,
tytso@mit.edu, adilger.kernel@dilger.ca, jaegeuk@kernel.org,
hirofumi@mail.parknet.co.jp, miklos@szeredi.hu,
rpeterso@redhat.com, agruenba@redhat.com, richard@nod.at,
anton.ivanov@cambridgegreys.com, johannes@sipsolutions.net,
mikulas@artax.karlin.mff.cuni.cz, mike.kravetz@oracle.com,
muchun.song@linux.dev, dwmw2@infradead.org, shaggy@kernel.org,
tj@kernel.org, trond.myklebust@hammerspace.com, anna@kernel.org,
chuck.lever@oracle.com, neilb@suse.de, kolga@netapp.com,
Dai.Ngo@oracle.com, tom@talpey.com, konishi.ryusuke@gmail.com,
anton@tuxera.com, almaz.alexandrovich@paragon-software.com,
mark@fasheh.com, joseph.qi@linux.alibaba.com, me@bobcopeland.com,
hubcap@omnibond.com, martin@omnibond.com, amir73il@gmail.com,
mcgrof@kernel.org, yzaikin@google.com, tony.luck@intel.com,
gpiccoli@igalia.com, al@alarsen.net, sfrench@samba.org,
pc@manguebit.com, lsahlber@redhat.com, sprasad@microsoft.com,
senozhatsky@chromium.org, phillip@squashfs.org.uk,
rostedt@goodmis.org, mhiramat@kernel.org, dushistov@mail.ru,
hdegoede@redhat.com, djwong@kernel.org, naohiro.aota@wdc.com,
jth@kernel.org, ast@kernel.org, daniel@iogearbox.net,
andrii@kernel.org, martin.lau@linux.dev, song@kernel.org,
yhs@fb.com, john.fastabend@gmail.com, kpsingh@kernel.org,
sdf@google.com, haoluo@google.com, jolsa@kernel.org,
hughd@google.com, akpm@linux-foundation.org, davem@davemloft.net,
edumazet@google.com, kuba@kernel.org, pabeni@redhat.com,
john.johansen@canonical.com, paul@paul-moore.com,
jmorris@namei.org, serge@hallyn.com,
stephen.smalley.work@gmail.com, eparis@parisplace.org,
jgross@suse.com, stern@rowland.harvard.edu, lrh2000@pku.edu.cn,
sebastian.reichel@collabora.com,
wsa+renesas@sang-engineering.com, quic_ugoswami@quicinc.com,
quic_linyyuan@quicinc.com, john@keeping.me.uk, error27@gmail.com,
quic_uaggarwa@quicinc.com, hayama@lineo.co.jp, jomajm@gmail.com,
axboe@kernel.dk, dhavale@google.com, dchinner@redhat.com,
hannes@cmpxchg.org, zhangpeng362@huawei.com, slava@dubeyko.com,
gargaditya08@live.com, penguin-kernel@I-love.SAKURA.ne.jp,
yifeliu@cs.stonybrook.edu, madkar@cs.stonybrook.edu,
ezk@cs.stonybrook.edu, yuzhe@nfschina.com, willy@infradead.org,
okanatov@gmail.com, jeffxu@chromium.org, linux@treblig.org,
mirimmad17@gmail.com, yijiangshan@kylinos.cn,
yang.yang29@zte.com.cn, xu.xin16@zte.com.cn,
chengzhihao1@huawei.com, shr@devkernel.io,
Liam.Howlett@Oracle.com, adobriyan@gmail.com,
chi.minghao@zte.com.cn, roberto.sassu@huawei.com,
linuszeng@tencent.com, bvanassche@acm.org, zohar@linux.ibm.com,
yi.zhang@huawei.com, trix@redhat.com, fmdefrancesco@gmail.com,
ebiggers@google.com, princekumarmaurya06@gmail.com,
chenzhongjin@huawei.com, riel@surriel.com,
shaozhengchao@huawei.com, jingyuwang_vip@163.com,
linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org,
linux-s390@vger.kernel.org, linux-rdma@vger.kernel.org,
linux-usb@vger.kernel.org, v9fs@lists.linux.dev,
linux-fsdevel@vger.kernel.org, linux-afs@lists.infradead.org,
autofs@vger.kernel.org, linux-mm@kvack.org,
linux-btrfs@vger.kernel.org, ceph-devel@vger.kernel.org,
codalist@coda.cs.cmu.edu, ecryptfs@vger.kernel.org,
linux-efi@vger.kernel.org, linux-erofs@lists.ozlabs.org,
linux-ext4@vger.kernel.org,
linux-f2fs-devel@lists.sourceforge.net, cluster-devel@redhat.com,
linux-um@lists.infradead.org, linux-mtd@lists.infradead.org,
jfs-discussion@lists.sourceforge.net, linux-nfs@vger.kernel.org,
linux-nilfs@vger.kernel.org,
linux-ntfs-dev@lists.sourceforge.net, ntfs3@lists.linux.dev,
ocfs2-devel@lists.linux.dev,
linux-karma-devel@lists.sourceforge.net,
devel@lists.orangefs.org, linux-unionfs@vger.kernel.org,
linux-hardening@vger.kernel.org, reiserfs-devel@vger.kernel.org,
linux-cifs@vger.kernel.org, samba-technical@lists.samba.org,
linux-trace-kernel@vger.kernel.org, linux-xfs@vger.kernel.org,
bpf@vger.kernel.org, netdev@vger.kernel.org,
apparmor@lists.ubuntu.com, linux-security-module@vger.kernel.org,
selinux@vger.kernel.org
Subject: Re: [PATCH v2 08/92] fs: new helper: simple_rename_timestamp
Date: Thu, 6 Jul 2023 08:19:00 +0900 [thread overview]
Message-ID: <3b403ef1-22e6-0220-6c9c-435e3444b4d3@kernel.org> (raw)
In-Reply-To: <20230705185812.579118-3-jlayton@kernel.org>
On 7/6/23 03:58, Jeff Layton wrote:
> A rename potentially involves updating 4 different inode timestamps. Add
> a function that handles the details sanely, and convert the libfs.c
> callers to use it.
>
> Signed-off-by: Jeff Layton <jlayton@kernel.org>
> ---
> fs/libfs.c | 36 +++++++++++++++++++++++++++---------
> include/linux/fs.h | 2 ++
> 2 files changed, 29 insertions(+), 9 deletions(-)
>
> diff --git a/fs/libfs.c b/fs/libfs.c
> index a7e56baf8bbd..9ee79668c909 100644
> --- a/fs/libfs.c
> +++ b/fs/libfs.c
> @@ -692,6 +692,31 @@ int simple_rmdir(struct inode *dir, struct dentry *dentry)
> }
> EXPORT_SYMBOL(simple_rmdir);
>
> +/**
> + * simple_rename_timestamp - update the various inode timestamps for rename
> + * @old_dir: old parent directory
> + * @old_dentry: dentry that is being renamed
> + * @new_dir: new parent directory
> + * @new_dentry: target for rename
> + *
> + * POSIX mandates that the old and new parent directories have their ctime and
> + * mtime updated, and that inodes of @old_dentry and @new_dentry (if any), have
> + * their ctime updated.
> + */
> +void simple_rename_timestamp(struct inode *old_dir, struct dentry *old_dentry,
> + struct inode *new_dir, struct dentry *new_dentry)
> +{
> + struct inode *newino = d_inode(new_dentry);
> +
> + old_dir->i_mtime = inode_set_ctime_current(old_dir);
> + if (new_dir != old_dir)
> + new_dir->i_mtime = inode_set_ctime_current(new_dir);
> + inode_set_ctime_current(d_inode(old_dentry));
> + if (newino)
> + inode_set_ctime_current(newino);
> +}
> +EXPORT_SYMBOL_GPL(simple_rename_timestamp);
> +
> int simple_rename_exchange(struct inode *old_dir, struct dentry *old_dentry,
> struct inode *new_dir, struct dentry *new_dentry)
> {
> @@ -707,11 +732,7 @@ int simple_rename_exchange(struct inode *old_dir, struct dentry *old_dentry,
> inc_nlink(old_dir);
> }
> }
> - old_dir->i_ctime = old_dir->i_mtime =
> - new_dir->i_ctime = new_dir->i_mtime =
> - d_inode(old_dentry)->i_ctime =
> - d_inode(new_dentry)->i_ctime = current_time(old_dir);
> -
> + simple_rename_timestamp(old_dir, old_dentry, new_dir, new_dentry);
This is somewhat changing the current behavior: before the patch, the mtime and
ctime of old_dir, new_dir and the inodes associated with the dentries are always
equal. But given that simple_rename_timestamp() calls inode_set_ctime_current()
4 times, the times could potentially be different.
I am not sure if that is an issue, but it seems that calling
inode_set_ctime_current() once, recording the "now" time it sets and using that
value to set all times may be more efficient and preserve the existing behavior.
> return 0;
> }
> EXPORT_SYMBOL_GPL(simple_rename_exchange);
> @@ -720,7 +741,6 @@ int simple_rename(struct mnt_idmap *idmap, struct inode *old_dir,
> struct dentry *old_dentry, struct inode *new_dir,
> struct dentry *new_dentry, unsigned int flags)
> {
> - struct inode *inode = d_inode(old_dentry);
> int they_are_dirs = d_is_dir(old_dentry);
>
> if (flags & ~(RENAME_NOREPLACE | RENAME_EXCHANGE))
> @@ -743,9 +763,7 @@ int simple_rename(struct mnt_idmap *idmap, struct inode *old_dir,
> inc_nlink(new_dir);
> }
>
> - old_dir->i_ctime = old_dir->i_mtime = new_dir->i_ctime =
> - new_dir->i_mtime = inode->i_ctime = current_time(old_dir);
> -
> + simple_rename_timestamp(old_dir, old_dentry, new_dir, new_dentry);
> return 0;
> }
> EXPORT_SYMBOL(simple_rename);
> diff --git a/include/linux/fs.h b/include/linux/fs.h
> index bdfbd11a5811..14e38bd900f1 100644
> --- a/include/linux/fs.h
> +++ b/include/linux/fs.h
> @@ -2979,6 +2979,8 @@ extern int simple_open(struct inode *inode, struct file *file);
> extern int simple_link(struct dentry *, struct inode *, struct dentry *);
> extern int simple_unlink(struct inode *, struct dentry *);
> extern int simple_rmdir(struct inode *, struct dentry *);
> +void simple_rename_timestamp(struct inode *old_dir, struct dentry *old_dentry,
> + struct inode *new_dir, struct dentry *new_dentry);
> extern int simple_rename_exchange(struct inode *old_dir, struct dentry *old_dentry,
> struct inode *new_dir, struct dentry *new_dentry);
> extern int simple_rename(struct mnt_idmap *, struct inode *,
--
Damien Le Moal
Western Digital Research
next prev parent reply other threads:[~2023-07-05 23:19 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-05 18:58 [PATCH v2 00/89] fs: new accessors for inode->i_ctime Jeff Layton
2023-07-05 18:58 ` [PATCH v2 07/92] fs: add ctime accessors infrastructure Jeff Layton
2023-07-05 23:12 ` Damien Le Moal
2023-07-05 18:58 ` [PATCH v2 08/92] fs: new helper: simple_rename_timestamp Jeff Layton
2023-07-05 23:19 ` Damien Le Moal [this message]
2023-07-06 0:04 ` Jeff Layton
2023-07-06 21:02 ` [apparmor] " Seth Arnold
2023-07-07 10:50 ` Jeff Layton
2023-07-06 10:27 ` Jan Kara
2023-08-30 0:19 ` Al Viro
2023-08-30 0:48 ` Jeff Layton
2023-07-05 18:58 ` [PATCH v2 92/92] fs: rename i_ctime field to __i_ctime Jeff Layton
2023-07-05 23:19 ` Damien Le Moal
2023-07-06 14:58 ` Jan Kara
2023-07-05 21:57 ` [PATCH v2 00/89] fs: new accessors for inode->i_ctime Jeff Layton
2023-07-06 15:16 ` Eric W. Biederman
2023-07-06 16:14 ` Jeff Layton
2023-07-07 12:42 ` Jeff Layton
2023-07-10 12:35 ` Christian Brauner
2023-07-10 13:32 ` Jeff Layton
2023-07-10 12:18 ` [PATCH v2 00/92] " Christian Brauner
2023-09-04 18:11 ` [f2fs-dev] [PATCH v2 00/89] " patchwork-bot+f2fs
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=3b403ef1-22e6-0220-6c9c-435e3444b4d3@kernel.org \
--to=dlemoal@kernel.org \
--cc=Dai.Ngo@oracle.com \
--cc=Liam.Howlett@Oracle.com \
--cc=adilger.kernel@dilger.ca \
--cc=adobriyan@gmail.com \
--cc=agordeev@linux.ibm.com \
--cc=agruenba@redhat.com \
--cc=aivazian.tigran@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=al@alarsen.net \
--cc=almaz.alexandrovich@paragon-software.com \
--cc=amir73il@gmail.com \
--cc=andrii@kernel.org \
--cc=anna@kernel.org \
--cc=anton.ivanov@cambridgegreys.com \
--cc=anton@tuxera.com \
--cc=apparmor@lists.ubuntu.com \
--cc=ardb@kernel.org \
--cc=arnd@arndb.de \
--cc=arve@android.com \
--cc=asmadeus@codewreck.org \
--cc=ast@kernel.org \
--cc=autofs@vger.kernel.org \
--cc=axboe@kernel.dk \
--cc=borntraeger@linux.ibm.com \
--cc=bpf@vger.kernel.org \
--cc=brauner@kernel.org \
--cc=bvanassche@acm.org \
--cc=bwarrum@linux.ibm.com \
--cc=ceph-devel@vger.kernel.org \
--cc=chao@kernel.org \
--cc=chengzhihao1@huawei.com \
--cc=chenzhongjin@huawei.com \
--cc=chi.minghao@zte.com.cn \
--cc=christophe.leroy@csgroup.eu \
--cc=chuck.lever@oracle.com \
--cc=clm@fb.com \
--cc=cluster-devel@redhat.com \
--cc=cmllamas@google.com \
--cc=coda@cs.cmu.edu \
--cc=codalist@coda.cs.cmu.edu \
--cc=code@tyhicks.com \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=dchinner@redhat.com \
--cc=dennis.dalessandro@cornelisnetworks.com \
--cc=devel@lists.orangefs.org \
--cc=dhavale@google.com \
--cc=dhowells@redhat.com \
--cc=djwong@kernel.org \
--cc=dsterba@suse.com \
--cc=dushistov@mail.ru \
--cc=dwmw2@infradead.org \
--cc=ebiederm@xmission.com \
--cc=ebiggers@google.com \
--cc=ecryptfs@vger.kernel.org \
--cc=edumazet@google.com \
--cc=eparis@parisplace.org \
--cc=ericvh@kernel.org \
--cc=error27@gmail.com \
--cc=ezk@cs.stonybrook.edu \
--cc=fmdefrancesco@gmail.com \
--cc=gargaditya08@live.com \
--cc=gor@linux.ibm.com \
--cc=gpiccoli@igalia.com \
--cc=gregkh@linuxfoundation.org \
--cc=hannes@cmpxchg.org \
--cc=haoluo@google.com \
--cc=hayama@lineo.co.jp \
--cc=hca@linux.ibm.com \
--cc=hch@lst.de \
--cc=hdegoede@redhat.com \
--cc=hirofumi@mail.parknet.co.jp \
--cc=hubcap@omnibond.com \
--cc=hughd@google.com \
--cc=huyue2@coolpad.com \
--cc=idryomov@gmail.com \
--cc=jack@suse.com \
--cc=jaegeuk@kernel.org \
--cc=jaharkes@cs.cmu.edu \
--cc=jefflexu@linux.alibaba.com \
--cc=jeffxu@chromium.org \
--cc=jfs-discussion@lists.sourceforge.net \
--cc=jgg@ziepe.ca \
--cc=jgross@suse.com \
--cc=jingyuwang_vip@163.com \
--cc=jk@ozlabs.org \
--cc=jlayton@kernel.org \
--cc=jlbec@evilplan.org \
--cc=jmorris@namei.org \
--cc=joel@joelfernandes.org \
--cc=johannes@sipsolutions.net \
--cc=john.fastabend@gmail.com \
--cc=john.johansen@canonical.com \
--cc=john@keeping.me.uk \
--cc=jolsa@kernel.org \
--cc=jomajm@gmail.com \
--cc=josef@toxicpanda.com \
--cc=joseph.qi@linux.alibaba.com \
--cc=jth@kernel.org \
--cc=keescook@chromium.org \
--cc=kolga@netapp.com \
--cc=konishi.ryusuke@gmail.com \
--cc=kpsingh@kernel.org \
--cc=kuba@kernel.org \
--cc=leon@kernel.org \
--cc=linkinjeon@kernel.org \
--cc=linuszeng@tencent.com \
--cc=linux-afs@lists.infradead.org \
--cc=linux-btrfs@vger.kernel.org \
--cc=linux-cifs@vger.kernel.org \
--cc=linux-efi@vger.kernel.org \
--cc=linux-erofs@lists.ozlabs.org \
--cc=linux-ext4@vger.kernel.org \
--cc=linux-f2fs-devel@lists.sourceforge.net \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-karma-devel@lists.sourceforge.net \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-mtd@lists.infradead.org \
--cc=linux-nfs@vger.kernel.org \
--cc=linux-nilfs@vger.kernel.org \
--cc=linux-ntfs-dev@lists.sourceforge.net \
--cc=linux-rdma@vger.kernel.org \
--cc=linux-s390@vger.kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=linux-um@lists.infradead.org \
--cc=linux-unionfs@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=linux-xfs@vger.kernel.org \
--cc=linux@treblig.org \
--cc=linux_oss@crudebyte.com \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=lrh2000@pku.edu.cn \
--cc=lsahlber@redhat.com \
--cc=lucho@ionkov.net \
--cc=luisbg@kernel.org \
--cc=maco@android.com \
--cc=madkar@cs.stonybrook.edu \
--cc=marc.dionne@auristor.com \
--cc=mark@fasheh.com \
--cc=martin.lau@linux.dev \
--cc=martin@omnibond.com \
--cc=mcgrof@kernel.org \
--cc=me@bobcopeland.com \
--cc=mhiramat@kernel.org \
--cc=mike.kravetz@oracle.com \
--cc=miklos@szeredi.hu \
--cc=mikulas@artax.karlin.mff.cuni.cz \
--cc=mirimmad17@gmail.com \
--cc=mpe@ellerman.id.au \
--cc=muchun.song@linux.dev \
--cc=naohiro.aota@wdc.com \
--cc=neilb@suse.de \
--cc=netdev@vger.kernel.org \
--cc=nico@fluxnic.net \
--cc=npiggin@gmail.com \
--cc=ntfs3@lists.linux.dev \
--cc=ocfs2-devel@lists.linux.dev \
--cc=okanatov@gmail.com \
--cc=pabeni@redhat.com \
--cc=paul@paul-moore.com \
--cc=pc@manguebit.com \
--cc=penguin-kernel@I-love.SAKURA.ne.jp \
--cc=phillip@squashfs.org.uk \
--cc=princekumarmaurya06@gmail.com \
--cc=quic_linyyuan@quicinc.com \
--cc=quic_uaggarwa@quicinc.com \
--cc=quic_ugoswami@quicinc.com \
--cc=rafael@kernel.org \
--cc=raven@themaw.net \
--cc=reiserfs-devel@vger.kernel.org \
--cc=richard@nod.at \
--cc=riel@surriel.com \
--cc=rituagar@linux.ibm.com \
--cc=roberto.sassu@huawei.com \
--cc=rostedt@goodmis.org \
--cc=rpeterso@redhat.com \
--cc=salah.triki@gmail.com \
--cc=samba-technical@lists.samba.org \
--cc=sdf@google.com \
--cc=sebastian.reichel@collabora.com \
--cc=selinux@vger.kernel.org \
--cc=senozhatsky@chromium.org \
--cc=serge@hallyn.com \
--cc=sfrench@samba.org \
--cc=shaggy@kernel.org \
--cc=shaozhengchao@huawei.com \
--cc=shr@devkernel.io \
--cc=sj1557.seo@samsung.com \
--cc=slava@dubeyko.com \
--cc=song@kernel.org \
--cc=sprasad@microsoft.com \
--cc=stephen.smalley.work@gmail.com \
--cc=stern@rowland.harvard.edu \
--cc=surenb@google.com \
--cc=svens@linux.ibm.com \
--cc=tj@kernel.org \
--cc=tkjos@android.com \
--cc=tom@talpey.com \
--cc=tony.luck@intel.com \
--cc=trix@redhat.com \
--cc=trond.myklebust@hammerspace.com \
--cc=tytso@mit.edu \
--cc=v9fs@lists.linux.dev \
--cc=viro@zeniv.linux.org.uk \
--cc=willy@infradead.org \
--cc=wsa+renesas@sang-engineering.com \
--cc=xiang@kernel.org \
--cc=xiubli@redhat.com \
--cc=xu.xin16@zte.com.cn \
--cc=yang.yang29@zte.com.cn \
--cc=yhs@fb.com \
--cc=yi.zhang@huawei.com \
--cc=yifeliu@cs.stonybrook.edu \
--cc=yijiangshan@kylinos.cn \
--cc=yuzhe@nfschina.com \
--cc=yzaikin@google.com \
--cc=zhangpeng362@huawei.com \
--cc=zohar@linux.ibm.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;
as well as URLs for NNTP newsgroup(s).