All of lore.kernel.org
 help / color / mirror / Atom feed
From: Priya Kamala <priya.kamala@perpetual-data.com>
To: Linux FS Devel <linux-fsdevel@vger.kernel.org>
Subject: Correct way to handle an error condition in inode lookup
Date: Tue, 07 Jan 2014 13:04:44 +0000	[thread overview]
Message-ID: <52CBFB6C.3040103@perpetual-data.com> (raw)

Hi all,

I am working on a linux filesystem filter driver used for archiving. The 
filter is layered on top of xfs. We are currently trying to implement a 
feature to incrementally recover a filesystem, in other words repopulate 
a directory on-the-fly. During initial recovery only the root directory 
is populated. Other directories get populated when they are accessed for 
the first time. To rebuild a directory the filter has to temporarily 
unlock the directory inode's i_mutex. This does mean that other requests 
can come in at the same time resulting in the following condition.

I launch two threads simultaneously. Thread 1 lists and deletes the 
contents of a folder and finally the folder itself, while Thread 2 
renames the first file in the same folder.

Thread 1                                            Thread 2
------------                                            ------------

readdir
release i_mutex to rebuild dir
acquire lock A to rebuild dir
rebuild offline dir starts
                                                             lookup file.0
                                                             release 
i_mutex to rebuild dir
                                                             acquire 
lock A to rebuild dir
rebuild dir completes
acquire i_mutex
mark directory online
release lock A
                                                             no need to 
rebuild as directory has been populated by Thread 1
revalidate file.0
unlink file.0
                                                             acquire i_mutex
                                                             release lock A
                                                             lookup 
returns valid dentry with inode created during Thread 1 rebuild
                                                             rename 
file.0 (Crashes with "Internal error xfs_trans_cancel at line 1925 of 
file fs/xfs/xfs_trans.c")
evict_inode
destroy_inode


Right now I'm using d_unlinked to check if a valid d_entry has been 
unlinked. I've tried using d_delete if the file has been unlinked, but 
this will fail if there is a third thread trying to stat the same file 
and lookup will return a valid d_entry causing rename to crash. What is 
the correct way to detect that a file has been unlinked but the inode 
hasn't been destroyed yet in the lookup function and how should this be 
handled? I am working with kernel version 3.2.52. Let me know if you 
need additional information.

If this is not the correct forum for this question, please point me in 
the right direction.

Thanks,
Priya


             reply	other threads:[~2014-01-07 13:29 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-07 13:04 Priya Kamala [this message]
2014-01-08  6:35 ` Correct way to handle an error condition in inode lookup Rohan Puri

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=52CBFB6C.3040103@perpetual-data.com \
    --to=priya.kamala@perpetual-data.com \
    --cc=linux-fsdevel@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.