All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: ocfs2-devel@oss.oracle.com
Subject: [Ocfs2-devel] [PATCH] vfs: Set special lockdep map for dirs only if not set by fs
Date: Tue, 02 Jun 2009 14:53:47 +0200	[thread overview]
Message-ID: <1243947227.23657.5964.camel@twins> (raw)
In-Reply-To: <1243945445-25847-7-git-send-email-jack@suse.cz>

On Tue, 2009-06-02 at 14:24 +0200, Jan Kara wrote:
> Some filesystems need to set lockdep map for i_mutex differently for
> different directories. For example OCFS2 has system directories (for
> orphan inode tracking and for gathering all system files like journal
> or quota files into a single place) which have different locking
> locking rules than standard directories. For a filesystem setting
> lockdep map is naturaly done when the inode is read but we have to
> modify unlock_new_inode() not to overwrite the lockdep map the filesystem
> has set.

Still looks good ;-)

Acked-by: peterz at infradead.org

> CC: mingo at redhat.com
> Signed-off-by: Jan Kara <jack@suse.cz>
> ---
>  fs/inode.c              |   17 +++++++++++------
>  include/linux/lockdep.h |   15 +++++++++++++++
>  2 files changed, 26 insertions(+), 6 deletions(-)
> 
> diff --git a/fs/inode.c b/fs/inode.c
> index 6ad14a1..44e1848 100644
> --- a/fs/inode.c
> +++ b/fs/inode.c
> @@ -654,12 +654,17 @@ void unlock_new_inode(struct inode *inode)
>  	if (inode->i_mode & S_IFDIR) {
>  		struct file_system_type *type = inode->i_sb->s_type;
>  
> -		/*
> -		 * ensure nobody is actually holding i_mutex
> -		 */
> -		mutex_destroy(&inode->i_mutex);
> -		mutex_init(&inode->i_mutex);
> -		lockdep_set_class(&inode->i_mutex, &type->i_mutex_dir_key);
> +		/* Set new key only if filesystem hasn't already changed it */
> +		if (!lockdep_match_class(&inode->i_mutex,
> +		    &type->i_mutex_key)) {
> +			/*
> +			 * ensure nobody is actually holding i_mutex
> +			 */
> +			mutex_destroy(&inode->i_mutex);
> +			mutex_init(&inode->i_mutex);
> +			lockdep_set_class(&inode->i_mutex,
> +					  &type->i_mutex_dir_key);
> +		}
>  	}
>  #endif
>  	/*
> diff --git a/include/linux/lockdep.h b/include/linux/lockdep.h
> index da5a5a1..b25d1b5 100644
> --- a/include/linux/lockdep.h
> +++ b/include/linux/lockdep.h
> @@ -258,6 +258,16 @@ extern void lockdep_init_map(struct lockdep_map *lock, const char *name,
>  #define lockdep_set_subclass(lock, sub)	\
>  		lockdep_init_map(&(lock)->dep_map, #lock, \
>  				 (lock)->dep_map.key, sub)
> +/*
> + * Compare locking classes
> + */
> +#define lockdep_match_class(lock, key) lockdep_match_key(&(lock)->dep_map, key)
> +
> +static inline int lockdep_match_key(struct lockdep_map *lock,
> +				    struct lock_class_key *key)
> +{
> +	return lock->key == key;
> +}
>  
>  /*
>   * Acquire a lock.
> @@ -326,6 +336,11 @@ static inline void lockdep_on(void)
>  #define lockdep_set_class_and_subclass(lock, key, sub) \
>  		do { (void)(key); } while (0)
>  #define lockdep_set_subclass(lock, sub)		do { } while (0)
> +/*
> + * We don't define lockdep_match_class() and lockdep_match_key() for !LOCKDEP
> + * case since the result is not well defined and the caller should rather
> + * #ifdef the call himself.
> + */
>  
>  # define INIT_LOCKDEP
>  # define lockdep_reset()		do { debug_locks = 1; } while (0)

  reply	other threads:[~2009-06-02 12:53 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-06-02 12:23 [Ocfs2-devel] [PATCH 0/7] [RESEND] Fix some deadlocks in quota code and implement lockdep for cluster locks Jan Kara
2009-06-02 12:23 ` [Ocfs2-devel] [PATCH] ocfs2: Fix possible deadlock in ocfs2_global_read_dquot() Jan Kara
2009-06-03  0:15   ` Joel Becker
2009-06-03 13:31     ` Jan Kara
2009-06-02 12:24 ` [Ocfs2-devel] [PATCH] ocfs2: Fix lock inversion in ocfs2_local_read_info() Jan Kara
2009-06-02 12:24 ` [Ocfs2-devel] [PATCH] ocfs2: Fix possible deadlock with quotas in ocfs2_setattr() Jan Kara
2009-06-02 12:24 ` [Ocfs2-devel] [PATCH] ocfs2: Fix possible deadlock in quota recovery Jan Kara
2009-06-02 12:24 ` [Ocfs2-devel] [PATCH] ocfs2: Correct ordering of ip_alloc_sem and localloc locks for directories Jan Kara
2009-06-03 21:05   ` Mark Fasheh
2009-06-02 12:24 ` [Ocfs2-devel] [PATCH] vfs: Set special lockdep map for dirs only if not set by fs Jan Kara
2009-06-02 12:53   ` Peter Zijlstra [this message]
2009-06-02 12:24 ` [Ocfs2-devel] [PATCH] ocfs2: Add lockdep annotations Jan Kara
2009-06-03 16:31   ` Joel Becker
2009-06-03 21:48     ` Jan Kara
2009-06-03 22:42       ` Joel Becker
2009-06-04 10:22         ` Jan Kara
2009-06-02 18:43 ` [Ocfs2-devel] [PATCH 0/7] [RESEND] Fix some deadlocks in quota code and implement lockdep for cluster locks Joel Becker
2009-06-04  2:26 ` Joel Becker
2009-06-04 10:09   ` Jan Kara
2009-06-09 17:05     ` Joel Becker

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=1243947227.23657.5964.camel@twins \
    --to=peterz@infradead.org \
    --cc=ocfs2-devel@oss.oracle.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 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.