From b9678234b9c67affd40051c73df302ea45f74d3c Mon Sep 17 00:00:00 2001 From: "Michael I. Bushnell" Date: Thu, 26 May 1994 19:52:30 +0000 Subject: Formerly node-drop.c.~6~ --- libdiskfs/node-drop.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/libdiskfs/node-drop.c b/libdiskfs/node-drop.c index 8e0fccde..aafbc730 100644 --- a/libdiskfs/node-drop.c +++ b/libdiskfs/node-drop.c @@ -18,7 +18,8 @@ #include "priv.h" /* Node NP now has no more references; clean all state. The - diskfs_node_refcnt_lock must be held. */ + diskfs_node_refcnt_lock must be held, and will be released + upon return. NP must be locked. */ void diskfs_drop_node (struct node *np) { @@ -27,7 +28,24 @@ diskfs_drop_node (struct node *np) if (np->dn_stat.st_nlink == 0) { assert (!diskfs_readonly); - diskfs_truncate (np, 0); + + if (np->allocsize != 0) + { + /* If the node needs to be truncated, then a complication + arises, because truncation might require gaining + new references to the node. So, we give ourselves + a reference back, unlock the refcnt lock. Then + we are in the state of a normal user, and do the truncate + and an nput. The next time through, this routine + will notice that the size is zero, and not have to + do anything. */ + np->references++; + spin_unlock (&diskfs_node_refcnt_lock); + diskfs_truncate (np, 0); + diskfs_nput (np); + return; + } + savemode = np->dn_stat.st_mode; np->dn_stat.st_mode = 0; np->dn_stat.st_rdev = 0; @@ -39,6 +57,7 @@ diskfs_drop_node (struct node *np) diskfs_node_update (np, 0); diskfs_node_norefs (np); + spin_unlock (&diskfs_node_refcnt_lock); } -- cgit v1.2.3