[Ocfs2-commits] mfasheh commits r2423 - trunk/fs/ocfs2

svn-commits at oss.oracle.com svn-commits at oss.oracle.com
Tue Jun 28 16:07:35 CDT 2005


Author: mfasheh
Signed-off-by: manish
Date: 2005-06-23 20:46:21 -0500 (Thu, 23 Jun 2005)
New Revision: 2423

Modified:
   trunk/fs/ocfs2/inode.c
   trunk/fs/ocfs2/namei.c
Log:
* move new_inode down into mknod_locked, where it actually makes sense
  - this also avoids some problems with uninitialized inodes filtering
  down into delete_inode.

* check for bad inodes in ocfs2_delete_inode.

Signed-off-by: manish



Modified: trunk/fs/ocfs2/inode.c
===================================================================
--- trunk/fs/ocfs2/inode.c	2005-06-24 01:43:58 UTC (rev 2422)
+++ trunk/fs/ocfs2/inode.c	2005-06-24 01:46:21 UTC (rev 2423)
@@ -458,6 +458,9 @@
 
 	mlog_entry("(inode->i_ino = %lu)\n", inode->i_ino);
 
+	if (is_bad_inode(inode))
+		goto bail;
+
 	if (OCFS2_I(inode)->ip_flags & OCFS2_INODE_SYSTEM_FILE) {
 		mlog(0, "Skipping system file delete.\n");
 		goto bail;

Modified: trunk/fs/ocfs2/namei.c
===================================================================
--- trunk/fs/ocfs2/namei.c	2005-06-24 01:43:58 UTC (rev 2422)
+++ trunk/fs/ocfs2/namei.c	2005-06-24 01:46:21 UTC (rev 2423)
@@ -91,7 +91,7 @@
 			      struct buffer_head **new_fe_bh, 
 			      struct buffer_head *parent_fe_bh,
 			      ocfs2_journal_handle *handle,
-			      struct inode *inode,
+			      struct inode **ret_inode,
 			      ocfs2_alloc_context *inode_ac);
 
 static int ocfs2_fill_new_dir(ocfs2_super *osb, 
@@ -338,7 +338,6 @@
 	struct buffer_head *parent_fe_bh = NULL;
 	ocfs2_journal_handle *handle = NULL;
 	ocfs2_super *osb;
-	ocfs2_dinode *fe = NULL;
 	ocfs2_dinode *dirfe;
 	struct buffer_head *new_fe_bh = NULL;
 	struct buffer_head *de_bh = NULL;
@@ -360,13 +359,6 @@
 		goto leave;
 	}
 
-	inode = new_inode(dir->i_sb);
-	if (IS_ERR(inode)) {
-		status = PTR_ERR(inode);
-		mlog(ML_ERROR, "new_inode failed!\n");
-		goto leave;
-	}
-
 	handle = ocfs2_alloc_handle(osb);
 	if (handle == NULL) {
 		status = -ENOMEM;
@@ -431,26 +423,12 @@
 	/* do the real work now. */
 	status = ocfs2_mknod_locked(osb, dir, dentry, mode, dev,
 				    &new_fe_bh, parent_fe_bh, handle, 
-				    inode, inode_ac);
+				    &inode, inode_ac);
 	if (status < 0) {
 		mlog_errno(status);
 		goto leave;
 	}
 
-	fe = (ocfs2_dinode *)new_fe_bh->b_data;
-	if (ocfs2_populate_inode(inode, fe, 1) < 0) {
-		mlog(ML_ERROR, "populate inode failed! bh->b_blocknr=%llu, "
-			       "i_blkno=%"MLFu64", i_ino=%lu\n",
-		     (unsigned long long)new_fe_bh->b_blocknr,
-		     fe->i_blkno, inode->i_ino);
-		BUG();
-	}
-
-	ocfs2_inode_set_new(osb, inode);
-	status = ocfs2_create_new_inode_locks(inode);
-	if (status < 0)
-		mlog_errno(status);
-
 	if (S_ISDIR(mode)) {
 		status = ocfs2_fill_new_dir(osb, handle, dir, inode, 
 					    new_fe_bh, data_ac);
@@ -474,8 +452,9 @@
 		dir->i_nlink++;
 	}
 
-	status = ocfs2_add_entry(handle, dentry, inode, fe->i_blkno,
-				 parent_fe_bh, de_bh);
+	status = ocfs2_add_entry(handle, dentry, inode,
+				 OCFS2_I(inode)->ip_blkno, parent_fe_bh,
+				 de_bh);
 	if (status < 0) {
 		mlog_errno(status);
 		goto leave;
@@ -521,7 +500,7 @@
 			      struct buffer_head **new_fe_bh, 
 			      struct buffer_head *parent_fe_bh,
 			      ocfs2_journal_handle *handle,
-			      struct inode *inode,
+			      struct inode **ret_inode,
 			      ocfs2_alloc_context *inode_ac)
 {
 	int status = 0;
@@ -529,6 +508,7 @@
 	ocfs2_extent_list *fel;
 	u64 fe_blkno = 0;
 	u16 suballoc_bit;
+	struct inode *inode = NULL;
 
 	mlog_entry("(0x%p, 0x%p, %d, %lu, '%.*s')\n", dir, dentry, mode,
 		   (unsigned long)dev, dentry->d_name.len,
@@ -536,6 +516,7 @@
 
 	OCFS2_ASSERT(new_fe_bh);
 	*new_fe_bh = NULL;
+	*ret_inode = NULL;
 
 	status = ocfs2_claim_new_inode(osb, handle, inode_ac, &suballoc_bit,
 				       &fe_blkno);
@@ -544,9 +525,26 @@
 		goto leave;
 	}
 
-	/* Set block number as early as possible - many of the
-	 * functions here want to print it during debugging. */
+	inode = new_inode(dir->i_sb);
+	if (IS_ERR(inode)) {
+		status = PTR_ERR(inode);
+		mlog(ML_ERROR, "new_inode failed!\n");
+		goto leave;
+	}
+
+	/* populate as many fields early on as possible - many of
+	 * these are used by the support functions here and in
+	 * callers. */
+	inode->i_ino = ino_from_blkno(osb->sb, fe_blkno);
 	OCFS2_I(inode)->ip_blkno = fe_blkno;
+	if (S_ISDIR(mode))
+		inode->i_nlink = 2;
+	else
+		inode->i_nlink = 1;
+	inode->i_mode = mode;
+	spin_lock(&osb->s_next_gen_lock);
+	inode->i_generation = osb->s_next_generation++;
+	spin_unlock(&osb->s_next_gen_lock);
 
 	*new_fe_bh = sb_getblk(osb->sb, fe_blkno);
 	if (!*new_fe_bh) {
@@ -568,11 +566,7 @@
 
 	fe = (ocfs2_dinode *) (*new_fe_bh)->b_data;
 	memset(fe, 0, osb->sb->s_blocksize);
-	inode->i_ino = ino_from_blkno(osb->sb, fe_blkno);
 
-	spin_lock(&osb->s_next_gen_lock);
-	inode->i_generation = osb->s_next_generation++;
-	spin_unlock(&osb->s_next_gen_lock);
 	fe->i_generation = cpu_to_le32(inode->i_generation);
 	fe->i_fs_generation = cpu_to_le32(osb->fs_generation);
 	fe->i_blkno = fe_blkno;
@@ -589,10 +583,7 @@
 	if (S_ISCHR(mode) || S_ISBLK(mode))
 		fe->id1.dev1.i_rdev = cpu_to_le64(huge_encode_dev(dev));
 
-	if (S_ISDIR(mode))
-		fe->i_links_count = 2;
-	else
-		fe->i_links_count = 1;
+	fe->i_links_count = inode->i_nlink;
 
 	fe->i_last_eb_blk = 0;
 	strcpy(fe->i_signature, OCFS2_INODE_SIGNATURE);
@@ -607,21 +598,37 @@
 	fel->l_next_free_rec = 0;
 	fel->l_count = ocfs2_extent_recs_per_inode(osb->sb);
 
-	fe = NULL;
-
 	status = ocfs2_journal_dirty(handle, *new_fe_bh);
 	if (status < 0) {
 		mlog_errno(status);
 		goto leave;
 	}
 
-	/* Inode is not yet fully populated, but we need some fields
-	 * for add_entry. */
-	inode->i_mode = mode;
+	if (ocfs2_populate_inode(inode, fe, 1) < 0) {
+		mlog(ML_ERROR, "populate inode failed! bh->b_blocknr=%llu, "
+		     "i_blkno=%"MLFu64", i_ino=%lu\n",
+		     (unsigned long long) (*new_fe_bh)->b_blocknr,
+		     fe->i_blkno, inode->i_ino);
+		BUG();
+	}
+
+	ocfs2_inode_set_new(osb, inode);
+	status = ocfs2_create_new_inode_locks(inode);
+	if (status < 0)
+		mlog_errno(status);
+
+	status = 0; /* error in ocfs2_create_new_inode_locks is not
+		     * critical */
+
+	*ret_inode = inode;
 leave:
-	if (status < 0 && *new_fe_bh) {
-		brelse(*new_fe_bh);
-		*new_fe_bh = NULL;
+	if (status < 0) {
+		if (*new_fe_bh) {
+			brelse(*new_fe_bh);
+			*new_fe_bh = NULL;
+		}
+		if (inode)
+			iput(inode);
 	}
 
 	mlog_exit(status);
@@ -1586,14 +1593,6 @@
 
 	l = strlen(symname) + 1;
 
-	inode = new_inode(sb);
-	if (IS_ERR(inode)) {
-		status = PTR_ERR(inode);
-		inode = NULL;
-		mlog(ML_ERROR, "new_inode failed!\n");
-		goto bail;
-	}
-
 	credits = ocfs2_calc_symlink_credits(sb);
 
 	handle = ocfs2_alloc_handle(osb);
@@ -1658,26 +1657,13 @@
 	status = ocfs2_mknod_locked(osb, dir, dentry, 
 				    S_IFLNK | S_IRWXUGO, 0,
 				    &new_fe_bh, parent_fe_bh, handle,
-				    inode, inode_ac);
+				    &inode, inode_ac);
 	if (status < 0) {
 		mlog_errno(status);
 		goto bail;
 	}
 
 	fe = (ocfs2_dinode *) new_fe_bh->b_data;
-	if (ocfs2_populate_inode(inode, fe, 1) < 0) {
-		mlog(ML_ERROR, "populate inode failed! bh->b_blocknr=%llu, "
-		     "i_blkno=%"MLFu64", i_ino=%lu\n",
-		     (unsigned long long)new_fe_bh->b_blocknr,
-		     fe->i_blkno, inode->i_ino);
-		BUG();
-	}
-
-	ocfs2_inode_set_new(osb, inode);
-	status = ocfs2_create_new_inode_locks(inode);
-	if (status < 0)
-		mlog_errno(status);
-
 	inode->i_rdev = 0;
 	newsize = l - 1;
 	if (l > ocfs2_fast_symlink_chars(sb)) {
@@ -1741,6 +1727,8 @@
 		ocfs2_free_alloc_context(inode_ac);
 	if (data_ac)
 		ocfs2_free_alloc_context(data_ac);
+	if ((status < 0) && inode)
+		iput(inode);
 
 	mlog_exit(status);
 



More information about the Ocfs2-commits mailing list