Skip to contentSkip to conversation

a patch for ocfs2_link

Ocfs2-devel Tiger Yang 3 participants 4 messages Aug 31, 2006 OCFS2

lore
Share & tools
lore

Tiger Yang

author
#0 lore raw

This patch remove the redundant "i_nlink >= OCFS2_LINK_MAX" check and add an unlinked directory check.

Singed-off-by: mfasheh

fs/ocfs2/namei.c +5 -5
index 0673862..719a8d2 100644
@@ -643,11 +643,6 @@ static int ocfs2_link(struct dentry *old
                goto bail;
        }
 
-       if (inode->i_nlink >= OCFS2_LINK_MAX) {
-               err = -EMLINK;
-               goto bail;
-       }
-
        handle = ocfs2_alloc_handle(osb);
        if (handle == NULL) {
                err = -ENOMEM;
@@ -661,6 +656,11 @@ static int ocfs2_link(struct dentry *old
                goto bail;
        }
 
+       if (!dir->i_nlink) {
+               err = -ENOENT;
+               goto bail;
+       }
+
        err = ocfs2_check_dir_for_entry(dir, dentry->d_name.name,
                                        dentry->d_name.len);
        if (err)

-------------- next part --------------

fs/ocfs2/namei.c +5 -5
index 0673862..719a8d2 100644
@@ -643,11 +643,6 @@ static int ocfs2_link(struct dentry *old
 		goto bail;
 	}
 
-	if (inode->i_nlink >= OCFS2_LINK_MAX) {
-		err = -EMLINK;
-		goto bail;
-	}
-
 	handle = ocfs2_alloc_handle(osb);
 	if (handle == NULL) {
 		err = -ENOMEM;
@@ -661,6 +656,11 @@ static int ocfs2_link(struct dentry *old
 		goto bail;
 	}
 
+	if (!dir->i_nlink) {
+		err = -ENOENT;
+		goto bail;
+	}
+
 	err = ocfs2_check_dir_for_entry(dir, dentry->d_name.name,
 					dentry->d_name.len);
 	if (err)
#1 lore raw

fs/ocfs2/namei.c static int ocfs2_link(struct dentry *old · line 650

Quoted 13 lines · Tiger Yang
fs/ocfs2/namei.c +0 -5
index 0673862..719a8d2 100644
@@ -643,11 +643,6 @@ static int ocfs2_link(struct dentry *old
               goto bail;
       }
 
-       if (inode->i_nlink >= OCFS2_LINK_MAX) {
-               err = -EMLINK;
-               goto bail;
-       }
-

Why is this redundant? Is someone doing it for us? I see we
check the fe->i_links_count below, but that's after the expense of a cluster lock. Don't we save some effort here?

fs/ocfs2/namei.c static int ocfs2_link(struct dentry *old · line 663

Quoted 9 lines
fs/ocfs2/namei.c +5 -0
@@ -661,6 +656,11 @@ static int ocfs2_link(struct dentry *old
               goto bail;
       }
 
+       if (!dir->i_nlink) {
+               err = -ENOENT;
+               goto bail;
+       }
+

And what does this do? If a directory...oh, wait, is this to
check for a directory that's going away? Can this actually happen? I'd think that the VFS would protect it.

Joel

Signature · 8 lines
"Well-timed silence hath more eloquence than speech."  
         - Martin Fraquhar Tupper

Joel Becker
Principal Software Developer
Oracle
E-mail: [email protected]
Phone: (650) 506-8127
#2 lore raw
Quoted 9 lines · Joel Becker

fs/ocfs2/namei.c static int ocfs2_link(struct dentry *old · line 650

Quoted 5 lines
fs/ocfs2/namei.c +0 -5
-       if (inode->i_nlink >= OCFS2_LINK_MAX) {
-               err = -EMLINK;
-               goto bail;
-       }
-

Why is this redundant? Is someone doing it for us? I see we
check the fe->i_links_count below, but that's after the expense of a cluster lock. Don't we save some effort here?

It's wrong because the i_nlink might be stale. We might actually be able to insert, but we don't know until we have the cluster lock.

Quoted 4 lines
Quoted 4 lines
fs/ocfs2/namei.c +0 -0
@@ -661,6 +656,11 @@ static int ocfs2_link(struct dentry *old
               goto bail;
       }
 
Quoted 9 lines

fs/ocfs2/namei.c static int ocfs2_link(struct dentry *old · line 663

Quoted 5 lines
fs/ocfs2/namei.c +5 -0
+       if (!dir->i_nlink) {
+               err = -ENOENT;
+               goto bail;
+       }
+

And what does this do? If a directory...oh, wait, is this to
check for a directory that's going away? Can this actually happen? I'd think that the VFS would protect it.

Again, the link count might be stale, so we have to double check after getting the lock. The way I imagine this could happen is if the dir inode is orphaned and a process attempts to do a create (imagine if it was unlinked while someone still had a shell open there)

There are similar checks in ocfs2_symlink() and ocfs2_mknod() which Tiger is basing that one on.

Granted, neither of these conditions are particularly likely, but we should protect against them nonetheless.

	--Mark

--
Mark Fasheh
Senior Software Developer, Oracle
[email protected]

#3 lore raw
In reply to Tiger Yang

Hi Tiger,

Quoted 2 lines · Tiger Yang

This patch remove the redundant "i_nlink >= OCFS2_LINK_MAX" check and add an unlinked directory check.

Ok, this looks good - thanks.

	--Mark

--
Mark Fasheh
Senior Software Developer, Oracle
[email protected]