Skip to contentSkip to conversation

question about a possible deadlock

DISCUSSION Andrey Savochkin 3 participants 5 messages Apr 26, 2002

lore
Share & tools
lore
#0 lore raw

Hi,

I've found a call sequence leading to what looks like a deadlock:
open
reiserfs_create
journal_begin
reiserfs_new_inode
failure by one of multiple reasons
iput [note that inode->i_nlink == 0]
reiserfs_delete_inode
journal_begin
deadlock, waiting for previous journal_begin to end
The code was checked by the mainstream 2.4.18 kernel. Any reasons why this deadlock can't happen?

My reading is that the deadlock should happen under the condition expressed in the code as
if ( (!join && SB_JOURNAL(p_s_sb)->j_must_wait > 0) ||

     ( !join && (SB_JOURNAL(p_s_sb)->j_len_alloc + nblocks + 2) >= JOURNAL_MAX_BATCH) ||
     (!join && atomic_read(&(SB_JOURNAL(p_s_sb)->j_wcount)) > 0 && SB_JOURNAL(p_s_sb)->j_trans_start_time > 0 &&
      (now - SB_JOURNAL(p_s_sb)->j_trans_start_time) > JOURNAL_MAX_TRANS_AGE) ||     (!join && atomic_read(&(SB_JOURNAL(p_s_sb)->j_jlock)) ) ||
     (!join && SB_JOURNAL(p_s_sb)->j_cnode_free < (JOURNAL_TRANS_MAX * 3)))

I'm not a specialist in this code, but it should be possible to trigger this condition, shouldn't it?

Or is it yet another already fixed issue?

Best regards
Andrey

#1 lore raw
Quoted 14 lines · Andrey Savochkin

Hi,

I've found a call sequence leading to what looks like a deadlock:
open
reiserfs_create
journal_begin
reiserfs_new_inode
failure by one of multiple reasons
iput [note that inode->i_nlink == 0]
reiserfs_delete_inode
journal_begin
deadlock, waiting for previous journal_begin to end
The code was checked by the mainstream 2.4.18 kernel. Any reasons why this deadlock can't happen?

Nope, you are exactly right. We've got a patch in testing that should fix this, let me know if you are interested in trying it out.

-chris

#2 lore raw
Quoted 16 lines · Chris Mason
Quoted 14 lines · Andrey Savochkin

Hi,

I've found a call sequence leading to what looks like a deadlock:
open
reiserfs_create
journal_begin
reiserfs_new_inode
failure by one of multiple reasons
iput [note that inode->i_nlink == 0]
reiserfs_delete_inode
journal_begin
deadlock, waiting for previous journal_begin to end
The code was checked by the mainstream 2.4.18 kernel. Any reasons why this deadlock can't happen?

Quoted 2 lines

Nope, you are exactly right. We've got a patch in testing that should fix this, let me know if you are interested in trying it out.

Yes, I'm interested :-)

Andrey

#3 lore raw
Quoted 5 lines · Andrey Savochkin
Quoted 2 lines

Nope, you are exactly right. We've got a patch in testing that should fix this, let me know if you are interested in trying it out.

Yes, I'm interested :-)

This was against 2.4.19-pre6, but should work against pre7 as well. It is a little larger than it needs to be because it incorporates some of the stuff from the quota code (where it was fixed first).

bk receivable at the end of the message.

-chris

[email protected], 2002-04-15 20:49:03-04:00, [email protected]
make sure iput is called outside the transaction by changing around reiserfs_new_inode.

fs/reiserfs/inode.c +63 -54
diff -Nru a/fs/reiserfs/inode.c b/fs/reiserfs/inode.c
@@ -1502,13 +1502,22 @@
 /* inserts the stat data into the tree, and then calls
    reiserfs_new_directory (to insert ".", ".." item if new object is
    directory) or reiserfs_new_symlink (to insert symlink body if new
-   object is symlink) or nothing (if new object is regular file) */
-struct inode * reiserfs_new_inode (struct reiserfs_transaction_handle *th,
+   object is symlink) or nothing (if new object is regular file) 
+
+   NOTE! uid and gid must already be set in the inode.  If we return
+   non-zero due to an error, we have to drop the quota previously allocated
+   for the fresh inode.  This can only be done outside a transaction, so
+   if we return non-zero, we also end the transaction.
+   
+   */
+int reiserfs_new_inode (struct reiserfs_transaction_handle *th,
 				   const struct inode * dir, int mode, 
 				   const char * symname, 
-				   int i_size, /* 0 for regular, EMTRY_DIR_SIZE for dirs,
-						  strlen (symname) for symlinks)*/
-				   struct dentry *dentry, struct inode *inode, int * err)
+				   /* 0 for regular, EMTRY_DIR_SIZE for dirs,
+				      strlen (symname) for symlinks) */
+				   loff_t i_size, 
+				   struct dentry *dentry, 
+				   struct inode *inode) 
 {
     struct super_block * sb;
     INITIALIZE_PATH (path_to_key);
@@ -1516,11 +1525,11 @@
     struct item_head ih;
     struct stat_data sd;
     int retval;
+    int err ;
   
     if (!dir || !dir->i_nlink) {
-	*err = -EPERM;
-	iput(inode) ;
-	return NULL;
+	err = -EPERM ;
+	goto out_bad_inode ;
     }
 
     sb = dir->i_sb;
@@ -1528,13 +1537,16 @@
 	    dir -> u.reiserfs_i.i_attrs & REISERFS_INHERIT_MASK;
     sd_attrs_to_i_attrs( inode -> u.reiserfs_i.i_attrs, inode );
 
+    /* symlink cannot be immutable or append only, right? */
+    if( S_ISLNK( inode -> i_mode ) )
+	    inode -> i_flags &= ~ ( S_IMMUTABLE | S_APPEND );
+
     /* item head of new item */
     ih.ih_key.k_dir_id = INODE_PKEY (dir)->k_objectid;
     ih.ih_key.k_objectid = cpu_to_le32 (reiserfs_get_unused_objectid (th));
     if (!ih.ih_key.k_objectid) {
-	iput(inode) ;
-	*err = -ENOMEM;
-	return NULL;
+	err = -ENOMEM ;
+	goto out_bad_inode ;
     }
     if (old_format_only (sb))
       /* not a perfect generation count, as object ids can be reused, but this
@@ -1550,12 +1562,24 @@
 #else
       inode->i_generation = ++event;
 #endif
+    /* fill stat data */
+    inode->i_nlink = (S_ISDIR (mode) ? 2 : 1);
+
+    /* uid and gid must already be set by the caller for quota init */
+
+    inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
+    inode->i_size = i_size;
+    inode->i_blocks = (i_size + 511) >> 9;
+    inode->u.reiserfs_i.i_first_direct_byte = S_ISLNK(mode) ? 1 : 
+      U32_MAX/*NO_BYTES_IN_DIRECT_ITEM*/;
+
+    INIT_LIST_HEAD(&inode->u.reiserfs_i.i_prealloc_list) ;
+
     if (old_format_only (sb))
 	make_le_item_head (&ih, 0, KEY_FORMAT_3_5, SD_OFFSET, TYPE_STAT_DATA, SD_V1_SIZE, MAX_US_INT);
     else
 	make_le_item_head (&ih, 0, KEY_FORMAT_3_6, SD_OFFSET, TYPE_STAT_DATA, SD_SIZE, MAX_US_INT);
 
-
     /* key to search for correct place for new stat data */
     _make_cpu_key (&key, KEY_FORMAT_3_6, le32_to_cpu (ih.ih_key.k_dir_id),
 		   le32_to_cpu (ih.ih_key.k_objectid), SD_OFFSET, TYPE_STAT_DATA, 3/*key length*/);
@@ -1563,47 +1587,21 @@
     /* find proper place for inserting of stat data */
     retval = search_item (sb, &key, &path_to_key);
     if (retval == IO_ERROR) {
-	iput (inode);
-	*err = -EIO;
-	return NULL;
+	err = -EIO;
+	goto out_bad_inode;
     }
     if (retval == ITEM_FOUND) {
 	pathrelse (&path_to_key);
-	iput (inode);
-	*err = -EEXIST;
-	return NULL;
+	err = -EEXIST;
+	goto out_bad_inode;
     }
 
-    /* fill stat data */
-    inode->i_mode = mode;
-    inode->i_nlink = (S_ISDIR (mode) ? 2 : 1);
-    inode->i_uid = current->fsuid;
-    if (dir->i_mode & S_ISGID) {
-	inode->i_gid = dir->i_gid;
-	if (S_ISDIR(mode))
-	    inode->i_mode |= S_ISGID;
-    } else
-	inode->i_gid = current->fsgid;
-
-    /* symlink cannot be immutable or append only, right? */
-    if( S_ISLNK( inode -> i_mode ) )
-	    inode -> i_flags &= ~ ( S_IMMUTABLE | S_APPEND );
-
-    inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
-    inode->i_size = i_size;
-    inode->i_blocks = (inode->i_size + 511) >> 9;
-    inode->u.reiserfs_i.i_first_direct_byte = S_ISLNK(mode) ? 1 : 
-      U32_MAX/*NO_BYTES_IN_DIRECT_ITEM*/;
-
-    INIT_LIST_HEAD(&inode->u.reiserfs_i.i_prealloc_list) ;
-
     if (old_format_only (sb)) {
 	if (inode->i_uid & ~0xffff || inode->i_gid & ~0xffff) {
 	    pathrelse (&path_to_key);
 	    /* i_uid or i_gid is too big to be stored in stat data v3.5 */
-	    iput (inode);
-	    *err = -EINVAL;
-	    return NULL;
+	    err = -EINVAL;
+	    goto out_bad_inode;
 	}
 	inode2sd_v1 (&sd, inode);
     } else
@@ -1630,10 +1628,9 @@
     /* insert the stat data into the tree */
     retval = reiserfs_insert_item (th, &path_to_key, &key, &ih, (char *)(&sd));
     if (retval) {
-	iput (inode);
-	*err = retval;
 	reiserfs_check_path(&path_to_key) ;
-	return NULL;
+	err = retval;
+	goto out_bad_inode;
     }
 
     if (S_ISDIR(mode)) {
@@ -1648,19 +1645,31 @@
 	retval = reiserfs_new_symlink (th, &ih, &path_to_key, symname, i_size);
     }
     if (retval) {
-      inode->i_nlink = 0;
-	iput (inode);
-	*err = retval;
+	err = retval; 
 	reiserfs_check_path(&path_to_key) ;
-	return NULL;
+	journal_end(th, th->t_super, th->t_blocks_allocated) ;
+	goto out_inserted_sd; 
     }
 
     insert_inode_hash (inode);
-    // we do not mark inode dirty: on disk content matches to the
-    // in-core one
+    reiserfs_update_sd(th, inode) ;
     reiserfs_check_path(&path_to_key) ;
 
-    return inode;
+    return 0 ;
+
+out_bad_inode:
+    /* Invalidate the object, nothing was inserted yet */
+    INODE_PKEY(inode)->k_objectid = 0;	
+
+    /* dquot_drop must be done outside a transaction */
+    journal_end(th, th->t_super, th->t_blocks_allocated) ;
+    make_bad_inode(inode);	
+
+out_inserted_sd:
+    inode->i_nlink = 0;
+    th->t_trans_id = 0 ; /* so the caller can't use this handle later */
+    iput(inode) ;
+    return err;
 }
 
 /*
fs/reiserfs/namei.c +94 -56

286 lines not on this page · raw message

include/linux/reiserfs_fs.h +3 -3
diff -Nru a/include/linux/reiserfs_fs.h b/include/linux/reiserfs_fs.h
@@ -1725,10 +1725,10 @@
 			      const struct cpu_key * key);
 
 
-struct inode * reiserfs_new_inode (struct reiserfs_transaction_handle *th, 
+int reiserfs_new_inode (struct reiserfs_transaction_handle *th, 
 				   const struct inode * dir, int mode, 
-				   const char * symname, int item_len,
-				   struct dentry *dentry, struct inode *inode, int * err);
+				   const char * symname, loff_t i_size,
+				   struct dentry *dentry, struct inode *inode);
 int reiserfs_sync_inode (struct reiserfs_transaction_handle *th, struct inode * inode);
 void reiserfs_update_sd (struct reiserfs_transaction_handle *th, struct inode * inode);
 

================================================================

This BitKeeper patch contains the following changesets:
1.389
## Wrapped with gzip_uu ##

begin 664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RSUH6]ZP81&U+M[V+'2V_=AA>_?/3]?NQV,)[-:LC?[NKMXK'(6=C MX;0ZI#ERHXN.2LFJ,1B=7@PFX_'Y>/0>3;&'5IZT44?F2=.1E7V2=&WR:F)4 M>G#@S6"'Y^-KHY'P:1UVSJ,#'W&C5EZH[5<.+HRBHD]0"B.78L?4<%@!3>,* M:#[email protected](!?S[0.CHOT1W]926:&J@G7AL\TTA]\QN,9QJJ9^D7C96U-@RK+5[= M8?%\:6.E04/[[MHJ\>IFKZUZPE)?]7Z@K5K\0D2,WWB!3;<R:#)^*]/6^)$H M;HO1TTG*,2WPFUR1<+LWS\]</!_J?XXW[Y[=.7-ODVS1<PW#5:?,D_X'1L(\
%0,T>````
`
end

#4 lore raw
In reply to Chris Mason
Quoted 20 lines · Chris Mason
Quoted 16 lines · Andrey Savochkin

Hi,

I've found a call sequence leading to what looks like a deadlock:
open
reiserfs_create
journal_begin
reiserfs_new_inode
failure by one of multiple reasons
iput [note that inode->i_nlink == 0]
reiserfs_delete_inode
journal_begin
deadlock, waiting for previous journal_begin to end
The code was checked by the mainstream 2.4.18 kernel. Any reasons why this deadlock can't happen?

Quoted 10 lines

Nope, you are exactly right. We've got a patch in testing that should fix this, let me know if you are interested in trying it out.

-chris

Thanks a lot Andrey.

Hans