public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@infradead.org>
To: Christoph Hellwig <hch@infradead.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Dave Hansen <haveblue@us.ibm.com>,
	laurent.riffard@free.fr, linux-kernel@vger.kernel.org,
	linux-fsdevel@vger.kernel.org, reiserfs-devel@vger.kernel.org
Subject: [RFC][PATCH] stop abusing filp_open in reiserfs journal code
Date: Fri, 28 Sep 2007 08:29:53 +0100	[thread overview]
Message-ID: <20070928072953.GA29031@infradead.org> (raw)
In-Reply-To: <20070928071635.GA28841@infradead.org>

And here's a patch to stop the filp abuse in the journal code.  An additional
benefit is that the block device is now properly claimed when opened by
device number.


Index: linux-2.6/fs/reiserfs/journal.c
===================================================================
--- linux-2.6.orig/fs/reiserfs/journal.c	2007-09-28 09:18:50.000000000 +0200
+++ linux-2.6/fs/reiserfs/journal.c	2007-09-28 09:28:36.000000000 +0200
@@ -2544,11 +2544,9 @@ static int release_journal_dev(struct su
 
 	result = 0;
 
-	if (journal->j_dev_file != NULL) {
-		result = filp_close(journal->j_dev_file, NULL);
-		journal->j_dev_file = NULL;
-		journal->j_dev_bd = NULL;
-	} else if (journal->j_dev_bd != NULL) {
+	if (journal->j_dev_bd != NULL) {
+		if (journal->j_dev_bd->bd_dev != super->s_dev)
+			bd_release(journal->j_dev_bd);
 		result = blkdev_put(journal->j_dev_bd);
 		journal->j_dev_bd = NULL;
 	}
@@ -2573,7 +2571,6 @@ static int journal_init_dev(struct super
 	result = 0;
 
 	journal->j_dev_bd = NULL;
-	journal->j_dev_file = NULL;
 	jdev = SB_ONDISK_JOURNAL_DEVICE(super) ?
 	    new_decode_dev(SB_ONDISK_JOURNAL_DEVICE(super)) : super->s_dev;
 
@@ -2590,35 +2587,34 @@ static int journal_init_dev(struct super
 					 "cannot init journal device '%s': %i",
 					 __bdevname(jdev, b), result);
 			return result;
-		} else if (jdev != super->s_dev)
+		} else if (jdev != super->s_dev) {
+			result = bd_claim(journal->j_dev_bd, journal);
+			if (result) {
+				blkdev_put(journal->j_dev_bd);
+				return result;
+			}
+
 			set_blocksize(journal->j_dev_bd, super->s_blocksize);
+		}
+
 		return 0;
 	}
 
-	journal->j_dev_file = filp_open(jdev_name, 0, 0);
-	if (!IS_ERR(journal->j_dev_file)) {
-		struct inode *jdev_inode = journal->j_dev_file->f_mapping->host;
-		if (!S_ISBLK(jdev_inode->i_mode)) {
-			reiserfs_warning(super, "journal_init_dev: '%s' is "
-					 "not a block device", jdev_name);
-			result = -ENOTBLK;
-			release_journal_dev(super, journal);
-		} else {
-			/* ok */
-			journal->j_dev_bd = I_BDEV(jdev_inode);
-			set_blocksize(journal->j_dev_bd, super->s_blocksize);
-			reiserfs_info(super,
-				      "journal_init_dev: journal device: %s\n",
-				      bdevname(journal->j_dev_bd, b));
-		}
-	} else {
-		result = PTR_ERR(journal->j_dev_file);
-		journal->j_dev_file = NULL;
+	journal->j_dev_bd = open_bdev_excl(jdev_name, 0, journal);
+	if (IS_ERR(journal->j_dev_bd)) {
+		result = PTR_ERR(journal->j_dev_bd);
+		journal->j_dev_bd = NULL;
 		reiserfs_warning(super,
 				 "journal_init_dev: Cannot open '%s': %i",
 				 jdev_name, result);
+		return result;
 	}
-	return result;
+
+	set_blocksize(journal->j_dev_bd, super->s_blocksize);
+	reiserfs_info(super,
+		      "journal_init_dev: journal device: %s\n",
+		      bdevname(journal->j_dev_bd, b));
+	return 0;
 }
 
 /*
Index: linux-2.6/include/linux/reiserfs_fs_sb.h
===================================================================
--- linux-2.6.orig/include/linux/reiserfs_fs_sb.h	2007-09-28 09:24:27.000000000 +0200
+++ linux-2.6/include/linux/reiserfs_fs_sb.h	2007-09-28 09:24:31.000000000 +0200
@@ -177,7 +177,6 @@ struct reiserfs_journal {
 	struct reiserfs_journal_cnode *j_last;	/* newest journal block */
 	struct reiserfs_journal_cnode *j_first;	/*  oldest journal block.  start here for traverse */
 
-	struct file *j_dev_file;
 	struct block_device *j_dev_bd;
 	int j_1st_reserved_block;	/* first block on s_dev of reserved area journal */
 



  reply	other threads:[~2007-09-28  7:30 UTC|newest]

Thread overview: 57+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-09-27  9:22 2.6.23-rc8-mm2 Andrew Morton
2007-09-27 10:52 ` 2.6.23-rc8-mm2 - drivers/net/ibm_newemac/mal - broken Kamalesh Babulal
2007-09-27 15:19 ` 2.6.23-rc8-mm2: problems on HP nx6325 Rafael J. Wysocki
2007-09-27 15:59   ` Rafael J. Wysocki
2007-09-27 15:49     ` Thomas Gleixner
2007-09-28 21:31       ` Rafael J. Wysocki
2007-09-27 16:53     ` Sam Ravnborg
2007-09-27 17:33       ` Randy Dunlap
2007-09-27 19:19         ` Sam Ravnborg
2007-09-27 19:48           ` Rafael J. Wysocki
2007-09-27 19:37             ` Randy Dunlap
2007-09-27 20:01               ` Rafael J. Wysocki
2007-09-27 19:18 ` 2.6.23-rc8-mm2: BUG near reiserfs_xattr_set Laurent Riffard
2007-09-27 19:48   ` Andrew Morton
2007-09-27 20:05     ` Dave Hansen
2007-09-27 20:26     ` Christoph Hellwig
2007-09-27 20:53       ` [RFC][PATCH] make reiserfs stop using 'struct file' for internal xattr operations Dave Hansen
2007-09-27 21:04         ` Christoph Hellwig
2007-09-27 21:27           ` Dave Hansen
2007-09-27 21:51             ` Andrew Morton
2007-09-27 21:54               ` Andrew Morton
2007-09-27 22:02               ` Peter Zijlstra
2007-09-28  7:16               ` Christoph Hellwig
2007-09-28  7:29                 ` Christoph Hellwig [this message]
     [not found] ` <20070928024054.GA14457@mail.ustc.edu.cn>
2007-09-28  2:40   ` WARNING: at arch/x86_64/kernel/smp.c:397 smp_call_function_mask() Fengguang Wu
2007-09-28  8:52     ` Laurent Vivier
2007-09-28  9:09       ` Andrew Morton
2007-09-28  9:18         ` Laurent Vivier
2007-09-28  9:34           ` Andrew Morton
2007-09-28 12:07             ` Laurent Vivier
     [not found]               ` <20070929065908.GA19615@mail.ustc.edu.cn>
2007-09-29  6:59                 ` Fengguang Wu
     [not found]               ` <20070929081524.GA32760@mail.ustc.edu.cn>
2007-09-29  8:15                 ` Fengguang Wu
     [not found]                 ` <20071002091133.GA31284@mail.ustc.edu.cn>
2007-10-02  9:11                   ` [PATCH][RESEND] call free_init_pages() with irqs enabled in alternative_instructions() Fengguang Wu
2007-09-28 15:42 ` 2.6.23-rc8-mm2 - tcp_fastretrans_alert() WARNING Cedric Le Goater
2007-09-28 19:10   ` Ilpo Järvinen
2007-09-29 12:44     ` Ilpo Järvinen
2007-09-29 14:55       ` Cedric Le Goater
2007-09-29 20:49         ` Ilpo Järvinen
2007-10-01  9:26           ` Cedric Le Goater
2007-10-02 10:26             ` Ilpo Järvinen
2007-10-02 20:06               ` Ilpo Järvinen
2007-10-02 21:48                 ` Ilpo Järvinen
2007-09-28 16:30 ` /proc/net/ bad hard links count [Was: 2.6.23-rc8-mm2] Jiri Slaby
2007-09-28 17:03   ` Eric W. Biederman
2007-09-29  9:37 ` 2.6.23-rc8-mm2 Dave Young
2007-09-29 15:19   ` 2.6.23-rc8-mm2 Greg KH
2007-09-30  1:29     ` 2.6.23-rc8-mm2 Dave Young
2007-09-30  5:18     ` 2.6.23-rc8-mm2 thunder7
2007-10-08  6:43     ` 2.6.23-rc8-mm2 Dave Young
2007-09-30  2:26 ` 2.6.23-rc8-mm2 Valdis.Kletnieks
2007-09-30  8:50   ` 2.6.23-rc8-mm2 Andrew Morton
2007-09-30 20:01     ` 2.6.23-rc8-mm2 Rafael J. Wysocki
2007-10-01 17:12       ` 2.6.23-rc8-mm2 Valdis.Kletnieks
2007-10-01 16:12     ` 2.6.23-rc8-mm2 Valdis.Kletnieks
2007-09-30  4:10 ` 2.6.23-rc8-mm2 - PowerPC link failure at arch/powerpc/kernel/head_64.o Kamalesh Babulal
2007-09-30  9:37   ` Kamalesh Babulal
2007-10-09 17:49 ` 2.6.23-rc8-mm2 Matt Mackall

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=20070928072953.GA29031@infradead.org \
    --to=hch@infradead.org \
    --cc=akpm@linux-foundation.org \
    --cc=haveblue@us.ibm.com \
    --cc=laurent.riffard@free.fr \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=reiserfs-devel@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox