quota: provide function to grab quota structure reference
authorJan Kara <jack@suse.cz>
Thu, 3 Apr 2014 21:46:55 +0000 (14:46 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Thu, 3 Apr 2014 23:20:54 +0000 (16:20 -0700)
Provide dqgrab() function to get quota structure reference when we are
sure it already has at least one active reference.  Make use of this
function inside quota code.

Signed-off-by: Jan Kara <jack@suse.cz>
Reviewed-by: Mark Fasheh <mfasheh@suse.de>
Reviewed-by: Srinivas Eeda <srinivas.eeda@oracle.com>
Cc: Joel Becker <jlbec@evilplan.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
fs/quota/dquot.c
include/linux/quotaops.h

index cfc8dcc160437c0daacd234f43d29faeb9b2fd33..9cd5f63715c0ece96c9e92191696997685a2a654 100644 (file)
@@ -528,7 +528,7 @@ restart:
                if (atomic_read(&dquot->dq_count)) {
                        DEFINE_WAIT(wait);
 
-                       atomic_inc(&dquot->dq_count);
+                       dqgrab(dquot);
                        prepare_to_wait(&dquot->dq_wait_unused, &wait,
                                        TASK_UNINTERRUPTIBLE);
                        spin_unlock(&dq_list_lock);
@@ -632,7 +632,7 @@ int dquot_writeback_dquots(struct super_block *sb, int type)
                        /* Now we have active dquot from which someone is
                         * holding reference so we can safely just increase
                         * use count */
-                       atomic_inc(&dquot->dq_count);
+                       dqgrab(dquot);
                        spin_unlock(&dq_list_lock);
                        dqstats_inc(DQST_LOOKUPS);
                        err = sb->dq_op->write_dquot(dquot);
index 6965fe394c3bb9d3b66681a8bfd1b9f84a970def..1d3eee594cd6773ef2fd6f34fd8546c36d2a3221 100644 (file)
@@ -46,6 +46,14 @@ void inode_reclaim_rsv_space(struct inode *inode, qsize_t number);
 void dquot_initialize(struct inode *inode);
 void dquot_drop(struct inode *inode);
 struct dquot *dqget(struct super_block *sb, struct kqid qid);
+static inline struct dquot *dqgrab(struct dquot *dquot)
+{
+       /* Make sure someone else has active reference to dquot */
+       WARN_ON_ONCE(!atomic_read(&dquot->dq_count));
+       WARN_ON_ONCE(!test_bit(DQ_ACTIVE_B, &dquot->dq_flags));
+       atomic_inc(&dquot->dq_count);
+       return dquot;
+}
 void dqput(struct dquot *dquot);
 int dquot_scan_active(struct super_block *sb,
                      int (*fn)(struct dquot *dquot, unsigned long priv),