linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Miklos Szeredi <miklos@szeredi.hu>
To: Jan Kara <jack@suse.cz>
Cc: viro@ZenIV.linux.org.uk, torvalds@linux-foundation.org,
	linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
	hch@infradead.org, akpm@linux-foundation.org,
	dhowells@redhat.com, zab@redhat.com, luto@amacapital.net,
	mszeredi@suse.cz
Subject: Re: [PATCH 11/11] ext4: add cross rename support
Date: Tue, 26 Nov 2013 14:47:16 +0100	[thread overview]
Message-ID: <20131126134659.GA528@tucsk.piliscsaba.szeredi.hu> (raw)
In-Reply-To: <20131126095125.GB1384@quack.suse.cz>

On Tue, Nov 26, 2013 at 10:51:25AM +0100, Jan Kara wrote:
> On Wed 20-11-13 14:01:52, Miklos Szeredi wrote:
> > From: Miklos Szeredi <mszeredi@suse.cz>
> > 
> > Implement RENAME_EXCHANGE flag in renameat2 syscall.
> > 
> > Signed-off-by: Miklos Szeredi <mszeredi@suse.cz>
> > ---
> >  fs/ext4/namei.c | 97 ++++++++++++++++++++++++++++++++++++++++-----------------
> >  1 file changed, 69 insertions(+), 28 deletions(-)
> > 
> > diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c
> > index d258b354b937..5307e482f403 100644
> > --- a/fs/ext4/namei.c
> > +++ b/fs/ext4/namei.c
> ...
> > -	old.dir->i_ctime = old.dir->i_mtime = ext4_current_time(old.dir);
> > -	ext4_update_dx_flag(old.dir);
> > +	/* S_ISDIR(old.inode->i_mode */
> >  	if (old.dir_bh) {
> >  		retval = ext4_rename_dir_finish(handle, &old, new.dir->i_ino);
> >  		if (retval)
> >  			goto end_rename;
> >  
> > -		ext4_dec_count(handle, old.dir);
> > -		if (new.inode) {
> > -			/* checked empty_dir above, can't have another parent,
> > -			 * ext4_dec_count() won't work for many-linked dirs */
> > -			clear_nlink(new.inode);
> > -		} else {
> > +		if (!(flags & RENAME_EXCHANGE) || !S_ISDIR(new.inode->i_mode))
> > +			ext4_dec_count(handle, old.dir);
> > +
> > +		if (!new.inode || !S_ISDIR(new.inode->i_mode)) {
> >  			ext4_inc_count(handle, new.dir);
> >  			ext4_update_dx_flag(new.dir);
> >  			ext4_mark_inode_dirty(handle, new.dir);
> >  		}
> >  	}
> > +	/* (flags & RENAME_EXCHANGE) && S_ISDIR(new.inode->i_mode */
> > +	if (new.dir_bh) {
> > +		retval = ext4_rename_dir_finish(handle, &new, old.dir->i_ino);
> > +		if (retval)
> > +			goto end_rename;
> > +
> > +		if (!S_ISDIR(old.inode->i_mode)) {
> > +			ext4_dec_count(handle, new.dir);
> > +			ext4_inc_count(handle, old.dir);
> > +			ext4_mark_inode_dirty(handle, new.dir);
> > +		}
> > +	}
> >  	ext4_mark_inode_dirty(handle, old.dir);
> > -	if (new.inode) {
> > +	if (!(flags & RENAME_EXCHANGE) && new.inode) {
> > +		ext4_dec_count(handle, new.inode);
> > +		new.inode->i_ctime = ext4_current_time(new.inode);
> > +		if (S_ISDIR(old.inode->i_mode)) {
> > +			/* checked empty_dir above, can't have another parent,
> > +			 * ext4_dec_count() won't work for many-linked dirs */
> > +			clear_nlink(new.inode);
> > +		}
>   This hunk looks strange. Why do you check S_ISDIR(old.inode->i_mode)? I'd
> presume we need to clear nlink if new.inode is a directory...

It's confusing, that's for sure.  I think it's correct, since S_ISDIR(old) is
equivalent to S_ISDIR(new) if not cross-renaming, but that's not a lot of
consolation to someone trying to understand the code.

> 
> >  		ext4_mark_inode_dirty(handle, new.inode);
> >  		if (!new.inode->i_nlink)
> > 			ext4_orphan_add(handle, new.inode);
>   Generally, I'm a bit unhappy about the number of various RENAME_EXCHANGE
> checks and the asymmetry between new & old which now shouldn't needed (that
> much). Especially the link count handling looks more complex than it should
> be.
> 
> I'd hope that it should be possible to "delete new.inode iff
> !RENAME_EXCHANGE" and then the rest shouldn't need to care about
> RENAME_EXCHANGE at all and treat old & new completely symmetrically... Now I
> realize this isn't that easy because we want to do all error checks first
> before doing any changes on disk but still I hope some improvement can be
> made (maybe just zero out new.inode in our 'new' ext4_renament to allow for
> code to be symmetric and delete it on disk only when ext4_rename() is
> finishing).
> 
> If the above won't be workable, we might at least make the link count
> handling more obvious by computing "old_link_cnt_update,
> new_link_cnt_update" - how link counts of parent dirs should be updated
> (-1, 0, +1) and then do the checks and updates based on this in one place.

Okay, will try to clean this up.  I agree that it became a bit too complicated.

Thanks,
Miklos

  reply	other threads:[~2013-11-26 13:47 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-20 13:01 [PATCH 00/11] cross rename v2 Miklos Szeredi
2013-11-20 13:01 ` [PATCH 01/11] vfs: add d_is_dir() Miklos Szeredi
2013-11-20 13:01 ` [PATCH 02/11] vfs: rename: move d_move() up Miklos Szeredi
2013-11-20 13:01 ` [PATCH 03/11] vfs: rename: use common code for dir and non-dir Miklos Szeredi
2013-11-20 13:01 ` [PATCH 04/11] vfs: add renameat2 syscall Miklos Szeredi
2013-11-20 16:34   ` Andy Lutomirski
2013-11-21  4:10   ` Stephen Rothwell
2013-11-21 12:37     ` Miklos Szeredi
2013-11-20 13:01 ` [PATCH 05/11] vfs: add RENAME_NOREPLACE flag Miklos Szeredi
2013-11-20 13:01 ` [PATCH 06/11] security: add flags to rename hooks Miklos Szeredi
2013-11-20 13:01 ` [PATCH 07/11] vfs: add cross-rename Miklos Szeredi
2013-11-20 16:39   ` Andy Lutomirski
2013-11-20 16:44     ` Miklos Szeredi
2013-11-20 16:51       ` Andy Lutomirski
2013-11-20 13:01 ` [PATCH 08/11] ext4: rename: create ext4_renament structure for local vars Miklos Szeredi
2013-11-26  8:04   ` Jan Kara
2013-11-20 13:01 ` [PATCH 09/11] ext4: rename: move EMLINK check up Miklos Szeredi
2013-11-20 13:01 ` [PATCH 10/11] ext4: rename: split out helper functions Miklos Szeredi
2013-11-20 13:01 ` [PATCH 11/11] ext4: add cross rename support Miklos Szeredi
2013-11-26  9:51   ` Jan Kara
2013-11-26 13:47     ` Miklos Szeredi [this message]
2014-01-08 22:10 [PATCH 00/11] cross rename v3 Miklos Szeredi
2014-01-08 22:10 ` [PATCH 11/11] ext4: add cross rename support Miklos Szeredi
2014-01-13 12:25   ` Jan Kara
2014-01-14 10:35     ` Miklos Szeredi
2014-01-15 18:23     ` J. Bruce Fields
2014-01-15 18:31       ` Miklos Szeredi
2014-01-16 10:54         ` Miklos Szeredi
2014-01-16 14:48           ` J. Bruce Fields
2014-01-17 10:53           ` Michael Kerrisk (man-pages)
2014-01-17 14:41             ` Miklos Szeredi
2014-04-19  9:08               ` Michael Kerrisk (man-pages)
2014-04-19 12:08                 ` Tetsuo Handa
2014-04-23 14:24                   ` Miklos Szeredi
2014-04-23 14:21                 ` Miklos Szeredi
2014-04-23 19:01                   ` Michael Kerrisk (man-pages)
2014-01-17 22:08             ` J. Bruce Fields
2014-01-18  6:49               ` Miklos Szeredi
2014-01-18 16:27                 ` J. Bruce Fields
2014-01-20 11:39                   ` Miklos Szeredi
2014-01-20 11:50                     ` Michael Kerrisk (man-pages)

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=20131126134659.GA528@tucsk.piliscsaba.szeredi.hu \
    --to=miklos@szeredi.hu \
    --cc=akpm@linux-foundation.org \
    --cc=dhowells@redhat.com \
    --cc=hch@infradead.org \
    --cc=jack@suse.cz \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@amacapital.net \
    --cc=mszeredi@suse.cz \
    --cc=torvalds@linux-foundation.org \
    --cc=viro@ZenIV.linux.org.uk \
    --cc=zab@redhat.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).