patch-2.3.1 linux/fs/sysv/namei.c

Next file: linux/fs/ufs/inode.c
Previous file: linux/fs/sysv/inode.c
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.3.0/linux/fs/sysv/namei.c linux/fs/sysv/namei.c
@@ -144,8 +144,6 @@
 
 	*res_buf = NULL;
 	*res_dir = NULL;
-	if (!dir)
-		return -ENOENT;
 	sb = dir->i_sb;
 	if (namelen > SYSV_NAMELEN) {
 		if (sb->sv_truncate)
@@ -240,18 +238,7 @@
 	if (!inode)
 		return -ENOSPC;
 	inode->i_uid = current->fsuid;
-	inode->i_mode = mode;
-	inode->i_op = NULL;
-	if (S_ISREG(inode->i_mode))
-		inode->i_op = &sysv_file_inode_operations;
-	else if (S_ISCHR(inode->i_mode))
-		inode->i_op = &chrdev_inode_operations;
-	else if (S_ISBLK(inode->i_mode))
-		inode->i_op = &blkdev_inode_operations;
-	else if (S_ISFIFO(inode->i_mode))
-		init_fifo(inode);
-	if (S_ISBLK(mode) || S_ISCHR(mode))
-		inode->i_rdev = to_kdev_t(rdev);
+	init_special_inode(inode, mode, rdev);
 	mark_inode_dirty(inode);
 	error = sysv_add_entry(dir, dentry->d_name.name, 
 			       dentry->d_name.len, &bh, &de);
@@ -334,8 +321,6 @@
 	struct buffer_head * bh;
 	struct sysv_dir_entry * de;
 
-	if (!inode)
-		return 1;
 	block = 0;
 	bh = NULL;
 	pos = offset = 2*SYSV_DIRSIZE;
@@ -391,22 +376,16 @@
 	struct buffer_head * bh;
 	struct sysv_dir_entry * de;
 
-	inode = NULL;
-	bh = sysv_find_entry(dir, dentry->d_name.name,
-                             dentry->d_name.len, &de);
+	inode = dentry->d_inode;
+	bh = sysv_find_entry(dir, dentry->d_name.name, dentry->d_name.len, &de);
 	retval = -ENOENT;
-	if (!bh)
+	if (!bh || de->inode != inode->i_ino)
 		goto end_rmdir;
-	inode = dentry->d_inode;
 
 	if (!empty_dir(inode)) {
 		retval = -ENOTEMPTY;
 		goto end_rmdir;
 	}
-	if (de->inode != inode->i_ino) {
-		retval = -ENOENT;
-		goto end_rmdir;
-	}
 	if (!list_empty(&dentry->d_hash)) {
 		retval = -EBUSY;
 		goto end_rmdir;
@@ -416,9 +395,9 @@
 	de->inode = 0;
 	mark_buffer_dirty(bh, 1);
 	inode->i_nlink=0;
-	mark_inode_dirty(inode);
 	dir->i_nlink--;
 	inode->i_ctime = dir->i_ctime = dir->i_mtime = CURRENT_TIME;
+	mark_inode_dirty(inode);
 	mark_inode_dirty(dir);
 	d_delete(dentry);
 	retval = 0;
@@ -434,26 +413,11 @@
 	struct buffer_head * bh;
 	struct sysv_dir_entry * de;
 
-repeat:
 	retval = -ENOENT;
-	inode = NULL;
-	bh = sysv_find_entry(dir, dentry->d_name.name,
-                             dentry->d_name.len, &de);
-	if (!bh)
-		goto end_unlink;
 	inode = dentry->d_inode;
-
-	retval = -EPERM;
-	if (de->inode != inode->i_ino) {
-		brelse(bh);
-		current->counter = 0;
-		schedule();
-		goto repeat;
-	}
-	if (de->inode != inode->i_ino) {
-		retval = -ENOENT;
+	bh = sysv_find_entry(dir, dentry->d_name.name, dentry->d_name.len, &de);
+	if (!bh || de->inode != inode->i_ino)
 		goto end_unlink;
-	}
 	if (!inode->i_nlink) {
 		printk("Deleting nonexistent file (%s:%lu), %d\n",
 		        kdevname(inode->i_dev), inode->i_ino, inode->i_nlink);
@@ -572,12 +536,6 @@
 (((struct sysv_dir_entry *) ((buffer) + 1*SYSV_DIRSIZE))->inode)
 
 /*
- * rename uses retrying to avoid race-conditions: at least they should be minimal.
- * it tries to allocate all the blocks, then sanity-checks, and if the sanity-
- * checks fail, it tries to restart itself again. Very practical - no changes
- * are done until we know everything works ok.. and then all the changes can be
- * done in one fell swoop when we have claimed all the buffers needed.
- *
  * Anybody can rename anything with this: the permission checks are left to the
  * higher-level routines.
  */
@@ -589,24 +547,15 @@
 	struct sysv_dir_entry * old_de, * new_de;
 	int retval;
 
-	goto start_up;
-try_again:
-	brelse(old_bh);
-	brelse(new_bh);
-	brelse(dir_bh);
-	current->counter = 0;
-	schedule();
-start_up:
-	old_inode = new_inode = NULL;
-	old_bh = new_bh = dir_bh = NULL;
+	old_inode = old_dentry->d_inode;
+	new_inode = new_dentry->d_inode;
+	new_bh = dir_bh = NULL;
 	old_bh = sysv_find_entry(old_dir, old_dentry->d_name.name,
 				old_dentry->d_name.len, &old_de);
 	retval = -ENOENT;
-	if (!old_bh)
+	if (!old_bh || old_de->inode != old_inode->i_ino)
 		goto end_rename;
-	old_inode = old_dentry->d_inode;	/* don't cross mnt-points */
 	retval = -EPERM;
-	new_inode = new_dentry->d_inode;
 	new_bh = sysv_find_entry(new_dir, new_dentry->d_name.name,
 				new_dentry->d_name.len, &new_de);
 	if (new_bh) {
@@ -628,7 +577,8 @@
 		if (PARENT_INO(dir_bh->b_data) != old_dir->i_ino)
 			goto end_rename;
 		retval = -EMLINK;
-		if (!new_inode && new_dir->i_nlink >= new_dir->i_sb->sv_link_max)
+		if (!new_inode && new_dir != old_dir &&
+				new_dir->i_nlink >= new_dir->i_sb->sv_link_max)
 			goto end_rename;
 	}
 	if (!new_bh) {
@@ -637,16 +587,8 @@
 		if (retval)
 			goto end_rename;
 	}
-/* sanity checking before doing the rename - avoid races */
-	if (new_inode && (new_de->inode != new_inode->i_ino))
-		goto try_again;
-	if (new_de->inode && !new_inode)
-		goto try_again;
-	if (old_de->inode != old_inode->i_ino)
-		goto try_again;
-/* ok, that's it */
-	old_de->inode = 0;
 	new_de->inode = old_inode->i_ino;
+	old_de->inode = 0;
 	old_dir->i_ctime = old_dir->i_mtime = CURRENT_TIME;
 	mark_inode_dirty(old_dir);
 	new_dir->i_ctime = new_dir->i_mtime = CURRENT_TIME;

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)