From: Oleg Drokin <green@namesys.com>
To: akpm@osdl.org
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH] [2.5] reiserfs: fix races between link and unlink on same file
Date: Thu, 31 Jul 2003 18:42:04 +0400 [thread overview]
Message-ID: <20030731144204.GP14081@namesys.com> (raw)
Hello!
This patch (originally by Chris Mason) fixes link/unlink races in reiserfs.
The patch is against 2.6.0-test2, please apply.
===== fs/reiserfs/namei.c 1.47 vs edited =====
--- 1.47/fs/reiserfs/namei.c Mon Jun 30 10:49:04 2003
+++ edited/fs/reiserfs/namei.c Thu Jul 31 18:01:55 2003
@@ -822,6 +822,7 @@
int windex ;
struct reiserfs_transaction_handle th ;
int jbegin_count;
+ unsigned long savelink;
inode = dentry->d_inode;
@@ -858,11 +859,20 @@
inode->i_nlink = 1;
}
+ inode->i_nlink--;
+
+ /*
+ * we schedule before doing the add_save_link call, save the link
+ * count so we don't race
+ */
+ savelink = inode->i_nlink;
+
+
retval = reiserfs_cut_from_item (&th, &path, &(de.de_entry_key), dir, NULL, 0);
- if (retval < 0)
+ if (retval < 0) {
+ inode->i_nlink++;
goto end_unlink;
-
- inode->i_nlink--;
+ }
inode->i_ctime = CURRENT_TIME;
reiserfs_update_sd (&th, inode);
@@ -871,7 +881,7 @@
dir->i_ctime = dir->i_mtime = CURRENT_TIME;
reiserfs_update_sd (&th, dir);
- if (!inode->i_nlink)
+ if (!savelink)
/* prevent file from getting lost */
add_save_link (&th, inode, 0/* not truncate */);
@@ -976,6 +986,12 @@
reiserfs_write_unlock(dir->i_sb);
return -EMLINK;
}
+ if (inode->i_nlink == 0) {
+ return -ENOENT;
+ }
+
+ /* inc before scheduling so reiserfs_unlink knows we are here */
+ inode->i_nlink++;
journal_begin(&th, dir->i_sb, jbegin_count) ;
windex = push_journal_writer("reiserfs_link") ;
@@ -988,13 +1004,13 @@
reiserfs_update_inode_transaction(dir) ;
if (retval) {
+ inode->i_nlink--;
pop_journal_writer(windex) ;
journal_end(&th, dir->i_sb, jbegin_count) ;
reiserfs_write_unlock(dir->i_sb);
return retval;
}
- inode->i_nlink++;
inode->i_ctime = CURRENT_TIME;
reiserfs_update_sd (&th, inode);
@@ -1068,6 +1084,7 @@
struct reiserfs_transaction_handle th ;
int jbegin_count ;
umode_t old_inode_mode;
+ unsigned long savelink = 1;
/* two balancings: old name removal, new name insertion or "save" link,
stat data updates: old directory and new directory and maybe block
@@ -1246,6 +1263,7 @@
new_dentry_inode->i_nlink--;
}
new_dentry_inode->i_ctime = new_dir->i_ctime;
+ savelink = new_dentry_inode->i_nlink;
}
if (S_ISDIR(old_inode_mode)) {
@@ -1279,7 +1297,7 @@
reiserfs_update_sd (&th, new_dir);
if (new_dentry_inode) {
- if (new_dentry_inode->i_nlink == 0)
+ if (savelink == 0)
add_save_link (&th, new_dentry_inode, 0/* not truncate */);
reiserfs_update_sd (&th, new_dentry_inode);
}
next reply other threads:[~2003-07-31 14:42 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-07-31 14:42 Oleg Drokin [this message]
2003-07-31 20:37 ` [PATCH] [2.5] reiserfs: fix races between link and unlink on same file Andrew Morton
2003-08-01 11:10 ` Oleg Drokin
2003-08-01 14:05 ` Chris Mason
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=20030731144204.GP14081@namesys.com \
--to=green@namesys.com \
--cc=akpm@osdl.org \
--cc=linux-kernel@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;
as well as URLs for NNTP newsgroup(s).