linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Anton Altaparmakov <aia21@cam.ac.uk>
To: Christoph Hellwig <hch@lst.de>
Cc: aia21@cantab.net, ntfs-dev <linux-ntfs-dev@lists.sourceforge.net>,
	linux-fsdevel@vger.kernel.org
Subject: Re: fishy ->put_inode usage in ntfs
Date: Thu, 14 Oct 2004 13:39:30 +0100	[thread overview]
Message-ID: <1097757569.21275.40.camel@imp.csi.cam.ac.uk> (raw)
In-Reply-To: <20041014112607.GA24508@lst.de>

Hi Christoph,

On Thu, 2004-10-14 at 12:26, Christoph Hellwig wrote:
> the inode->i_count useage in ntfs_put_inode is possibly ract vecause we
> could get anoher reference while you're looking at it.

Hm.  For the directory inode case I don't think this is a problem
because all places that use NTFS_I(vfs inode)->itype.index.bmp_ino hold
i_sem of the vfs inode which guarantees that at least someone is holding
a reference on the vfs inode which in turn guarantees that the i_count
cannot drop to levels that would affect ntfs_put_inode().

Explanation: The person who holds i_sem also has 1 i_count and if
bmp_ino is set this also has 1 i_count on its parent inode thus we now
have a minimum i_count of 2.  To get into ntfs_put_inode() at this point
in time someone would have to do iput() and they better have 1 i_count
before they do the iput() so we now have a minimum i_count of 3 and no
code in ntfs_put_inode() would trigger.

Only when the last external user of the inode does iput(),
ntfs_put_inode() is called with i_count of 2.  ntfs_put_inode() then
iput()s the bmp_ino attribute inode.

This in turn does iput() on the parent inode which drops i_count once
more and now clear_inode() will be called by the VFS.

We cannot move this code to clear_inode() as it would never get called
since the i_count would never drop to 0 due to the existence of the
bmp_ino attribute inode which in turn will never have its i_count drop
to zero due to it being attached to the parent inode.  Catch 22.

If someone does get a new reference while we are running the above this
is also fine as all users of NTFS_I(vfs inode)->itype.index.bmp_ino
check bmp_ino for being NULL and if it is they do an ntfs_attr_iget()
and attach it on NTFS_I(vfs inode)->itype.index.bmp_ino again.

The reason for doing this is to not to have to ntfs_attr_iget() the
bmp_ino every time we need to use it (e.g. every ->readdir()
invocation).  So it may look odd but it is a speedup worth doing IMO.

Hm, I can now see that there is a small race window here and this is
simply fixed by doing the setting to NULL of bmp_ino before doing the
iput() of bmp_ino.  Thanks for pointing this problem area out to!  (-:

> For the index inode case moving this to clear_inode (which is called
> after we released the last reference) should be fine,

Indeed.  I will move it.  Thanks!  (-:

> but I don't understand the case for directories - why are you checking
> for i_count beeing 2 there and not one?

I hope I have explained this above.  If I failed please do ask again...

Best regards,

	Anton
-- 
Anton Altaparmakov <aia21 at cam.ac.uk> (replace at with @)
Unix Support, Computing Service, University of Cambridge, CB2 3QH, UK
Linux NTFS maintainer / IRC: #ntfs on irc.freenode.net
WWW: http://linux-ntfs.sf.net/, http://www-stu.christs.cam.ac.uk/~aia21/


  reply	other threads:[~2004-10-14 12:39 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-10-14 11:26 fishy ->put_inode usage in ntfs Christoph Hellwig
2004-10-14 12:39 ` Anton Altaparmakov [this message]
2004-10-14 12:44   ` Matthew Wilcox
2004-10-14 13:27     ` Anton Altaparmakov
2004-10-14 14:59     ` Anton Altaparmakov
2004-10-14 12:59   ` Christoph Hellwig
2004-10-14 13:26     ` Anton Altaparmakov
2005-02-10 10:47       ` Christoph Hellwig
2005-02-10 14:40         ` Anton Altaparmakov
2005-02-10 14:42           ` Christoph Hellwig
2005-02-10 14:48             ` Anton Altaparmakov
2005-02-10 14:50               ` Anton Altaparmakov
2005-02-10 14:51                 ` Christoph Hellwig
2005-02-10 14:50               ` Christoph Hellwig
2005-02-10 14:59                 ` Anton Altaparmakov
2005-02-13 16:35                   ` Christoph Hellwig
2005-02-14 20:44                     ` Anton Altaparmakov
2005-03-01 23:17                       ` David Woodhouse
2005-03-02  8:43                         ` Anton Altaparmakov
2005-03-02  8:53                           ` David Woodhouse

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=1097757569.21275.40.camel@imp.csi.cam.ac.uk \
    --to=aia21@cam.ac.uk \
    --cc=aia21@cantab.net \
    --cc=hch@lst.de \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-ntfs-dev@lists.sourceforge.net \
    /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).