From: Christoph Hellwig <[email-masked]>

Move some code duplicated in both callers into vfs_quota_on_mount

Signed-off-by: Christoph Hellwig <[email-masked]>
Cc: Jan Kara <[email-masked]>
Signed-off-by: Andrew Morton <[email-masked]>
---

 fs/dquot.c               |   23 +++++++++++++++++++----
 fs/ext3/super.c          |   18 ++----------------
 fs/reiserfs/super.c      |   21 +++------------------
 include/linux/quotaops.h |    3 ++-
 4 files changed, 26 insertions(+), 39 deletions(-)

diff -puN fs/dquot.c~quota-consolidate-code-surrounding-vfs_quota_on_mount fs/dquot.c
--- 25/fs/dquot.c~quota-consolidate-code-surrounding-vfs_quota_on_mount	2005-05-06 18:11:49.000000000 -0700
+++ 25-akpm/fs/dquot.c	2005-05-06 18:11:49.000000000 -0700
@@ -1519,14 +1519,29 @@ out_path:
  * This function is used when filesystem needs to initialize quotas
  * during mount time.
  */
-int vfs_quota_on_mount(int type, int format_id, struct dentry *dentry)
+int vfs_quota_on_mount(struct super_block *sb, char *qf_name,
+		int format_id, int type)
 {
+	struct qstr name = {.name = qf_name, .len = 0, .len = strlen(qf_name)};
+	struct dentry *dentry;
 	int error;
 
+	dentry = lookup_hash(&name, sb->s_root);
+	if (IS_ERR(dentry))
+		return PTR_ERR(dentry);
+
 	error = security_quota_on(dentry);
-	if (error)
-		return error;
-	return vfs_quota_on_inode(dentry->d_inode, type, format_id);
+	if (!error)
+		error = vfs_quota_on_inode(dentry->d_inode, type, format_id);
+
+	/*
+	 * Now invalidate and put the dentry - quota got its own reference
+	 * to inode and dentry has at least wrong hash so we had better
+	 * throw it away.
+	 */
+	d_invalidate(dentry);
+	dput(dentry);
+	return error;
 }
 
 /* Generic routine for getting common part of quota structure */
diff -puN fs/ext3/super.c~quota-consolidate-code-surrounding-vfs_quota_on_mount fs/ext3/super.c
--- 25/fs/ext3/super.c~quota-consolidate-code-surrounding-vfs_quota_on_mount	2005-05-06 18:11:49.000000000 -0700
+++ 25-akpm/fs/ext3/super.c	2005-05-06 18:11:49.000000000 -0700
@@ -2338,22 +2338,8 @@ static int ext3_write_info(struct super_
  */
 static int ext3_quota_on_mount(struct super_block *sb, int type)
 {
-	int err;
-	struct dentry *dentry;
-	struct qstr name = { .name = EXT3_SB(sb)->s_qf_names[type],
-			     .hash = 0,
-			     .len = strlen(EXT3_SB(sb)->s_qf_names[type])};
-
-	dentry = lookup_hash(&name, sb->s_root);
-	if (IS_ERR(dentry))
-		return PTR_ERR(dentry);
-	err = vfs_quota_on_mount(type, EXT3_SB(sb)->s_jquota_fmt, dentry);
-	/* Now invalidate and put the dentry - quota got its own reference
-	 * to inode and dentry has at least wrong hash so we had better
-	 * throw it away */
-	d_invalidate(dentry);
-	dput(dentry);
-	return err;
+	return vfs_quota_on_mount(sb, EXT3_SB(sb)->s_qf_names[type],
+			EXT3_SB(sb)->s_jquota_fmt, type);
 }
 
 /*
diff -puN fs/reiserfs/super.c~quota-consolidate-code-surrounding-vfs_quota_on_mount fs/reiserfs/super.c
--- 25/fs/reiserfs/super.c~quota-consolidate-code-surrounding-vfs_quota_on_mount	2005-05-06 18:11:49.000000000 -0700
+++ 25-akpm/fs/reiserfs/super.c	2005-05-06 18:11:49.000000000 -0700
@@ -1919,27 +1919,12 @@ static int reiserfs_write_info(struct su
 }
 
 /*
- * Turn on quotas during mount time - we need to find
- * the quota file and such...
+ * Turn on quotas during mount time - we need to find the quota file and such...
  */
 static int reiserfs_quota_on_mount(struct super_block *sb, int type)
 {
-    int err;
-    struct dentry *dentry;
-    struct qstr name = { .name = REISERFS_SB(sb)->s_qf_names[type],
-                         .hash = 0,
-                         .len = strlen(REISERFS_SB(sb)->s_qf_names[type])};
-
-    dentry = lookup_hash(&name, sb->s_root);
-    if (IS_ERR(dentry))
-            return PTR_ERR(dentry);
-    err = vfs_quota_on_mount(type, REISERFS_SB(sb)->s_jquota_fmt, dentry);
-    /* Now invalidate and put the dentry - quota got its own reference
-     * to inode and dentry has at least wrong hash so we had better
-     * throw it away */
-    d_invalidate(dentry);
-    dput(dentry);
-    return err;
+	return vfs_quota_on_mount(sb, REISERFS_SB(sb)->s_qf_names[type],
+			REISERFS_SB(sb)->s_jquota_fmt, type);
 }
 
 /*
diff -puN include/linux/quotaops.h~quota-consolidate-code-surrounding-vfs_quota_on_mount include/linux/quotaops.h
--- 25/include/linux/quotaops.h~quota-consolidate-code-surrounding-vfs_quota_on_mount	2005-05-06 18:11:49.000000000 -0700
+++ 25-akpm/include/linux/quotaops.h	2005-05-06 18:11:49.000000000 -0700
@@ -39,7 +39,8 @@ extern int dquot_commit_info(struct supe
 extern int dquot_mark_dquot_dirty(struct dquot *dquot);
 
 extern int vfs_quota_on(struct super_block *sb, int type, int format_id, char *path);
-extern int vfs_quota_on_mount(int type, int format_id, struct dentry *dentry);
+extern int vfs_quota_on_mount(struct super_block *sb, char *qf_name,
+		int format_id, int type);
 extern int vfs_quota_off(struct super_block *sb, int type);
 #define vfs_quota_off_mount(sb, type) vfs_quota_off(sb, type)
 extern int vfs_quota_sync(struct super_block *sb, int type);
_