Skip to contentSkip to conversation

cifs: tighten up cifs_iget matching criteria

PATCH New Jeff Layton 4 participants 10 messages Jun 28, 2010 – Dec 7, 2010 5 messages not in the archive

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover cifs: tighten up cifs_iget matching criteria

These patches are intended to help reduce the number of false matches that cifs_iget does. They simply try to make the code do some extra checking of the cached inodes against the new file's attributes when a uniqueid matches one that's already in cache.

I've tested these against samba and windows. They seem to work and help reduce the false positives that can cause server inode numbers to be disabled.

This patchset is intended for 2.6.36. The patches are in the cifs-2.6.36 branch of my kernel.org tree:

http://git.kernel.org/?p=linux/kernel/git/jlayton/linux.git;a=shortlog;h=refs/heads/cifs-2.6.36

Jeff Layton (3):
cifs: don't allow cifs_iget to match inodes of the wrong type
cifs: use CreationTime like an i_generation field
cifs: reduce false positives with inode aliasing serverino
autodisable

 fs/cifs/cifsfs.c   |    2 +
 fs/cifs/cifsglob.h |    2 +
 fs/cifs/inode.c    |   54 ++++++++++++++++++++++++++++++++++++++++-----------
 fs/cifs/readdir.c  |    1 +
 4 files changed, 47 insertions(+), 12 deletions(-)
#1 lore raw

PATCH 1/3 cifs: don't allow cifs_iget to match inodes of the wrong type

If the type is different from what we think it should be, then don't match the existing inode.

---
 fs/cifs/inode.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)
fs/cifs/inode.c +5 -0
index 6f0683c..f64b95f 100644
@@ -723,9 +723,14 @@ cifs_find_inode(struct inode *inode, void *opaque)
 {
 	struct cifs_fattr *fattr = (struct cifs_fattr *) opaque;
 
+	/* don't match inode with different uniqueid */
 	if (CIFS_I(inode)->uniqueid != fattr->cf_uniqueid)
 		return 0;
 
+	/* don't match inode of different type */
+	if ((inode->i_mode & S_IFMT) != (fattr->cf_mode & S_IFMT))
+		return 0;
+
 	/*
 	 * uh oh -- it's a directory. We can't use it since hardlinked dirs are
 	 * verboten. Disable serverino and return it as if it were found, the
Signature · 1 line
1.6.6.1

A message that is not in the archive (sent off-list or not yet received): 1277723413-23769-1-git-send-email-jlayton-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org

#3 lore raw

PATCH 2/3 cifs: use CreationTime like an i_generation field

Reduce false inode collisions by using the CreationTime like an i_generation field. This way, even if the server ends up reusing a uniqueid after a delete/create cycle, we can avoid matching the inode incorrectly.

---
 fs/cifs/cifsfs.c   |    2 ++
 fs/cifs/cifsglob.h |    2 ++
 fs/cifs/inode.c    |    6 ++++++
 fs/cifs/readdir.c  |    1 +
 4 files changed, 11 insertions(+), 0 deletions(-)
fs/cifs/cifsfs.c +2 -0
index 484e52b..e409216 100644
@@ -314,6 +314,8 @@ cifs_alloc_inode(struct super_block *sb)
 	cifs_inode->invalid_mapping = false;
 	cifs_inode->vfs_inode.i_blkbits = 14;  /* 2**14 = CIFS_MAX_MSGSIZE */
 	cifs_inode->server_eof = 0;
+	cifs_inode->uniqueid = 0;
+	cifs_inode->createtime = 0;
 
 	/* Can not set i_flags here - they get immediately overwritten
 	   to zero by the VFS */
fs/cifs/cifsglob.h +2 -0
index e15d7a5..a0fd2c2 100644
@@ -382,6 +382,7 @@ struct cifsInodeInfo {
 	bool invalid_mapping:1;		/* pagecache is invalid */
 	u64  server_eof;		/* current file size on server */
 	u64  uniqueid;			/* server inode number */
+	u64  createtime;		/* creation time on server */
 	struct inode vfs_inode;
 };
 
@@ -499,6 +500,7 @@ struct cifs_fattr {
 	u64		cf_uniqueid;
 	u64		cf_eof;
 	u64		cf_bytes;
+	u64		cf_createtime;
 	uid_t		cf_uid;
 	gid_t		cf_gid;
 	umode_t		cf_mode;
fs/cifs/inode.c +6 -0
index f64b95f..35e2466 100644
@@ -487,6 +487,7 @@ cifs_all_info_to_fattr(struct cifs_fattr *fattr, FILE_ALL_INFO *info,
 
 	fattr->cf_eof = le64_to_cpu(info->EndOfFile);
 	fattr->cf_bytes = le64_to_cpu(info->AllocationSize);
+	fattr->cf_createtime = le64_to_cpu(info->CreationTime);
 
 	if (fattr->cf_cifsattrs & ATTR_DIRECTORY) {
 		fattr->cf_mode = S_IFDIR | cifs_sb->mnt_dir_mode;
@@ -727,6 +728,10 @@ cifs_find_inode(struct inode *inode, void *opaque)
 	if (CIFS_I(inode)->uniqueid != fattr->cf_uniqueid)
 		return 0;
 
+	/* use createtime like an i_generation field */
+	if (CIFS_I(inode)->createtime != fattr->cf_createtime)
+		return 0;
+
 	/* don't match inode of different type */
 	if ((inode->i_mode & S_IFMT) != (fattr->cf_mode & S_IFMT))
 		return 0;
@@ -750,6 +755,7 @@ cifs_init_inode(struct inode *inode, void *opaque)
 	struct cifs_fattr *fattr = (struct cifs_fattr *) opaque;
 
 	CIFS_I(inode)->uniqueid = fattr->cf_uniqueid;
+	CIFS_I(inode)->createtime = fattr->cf_createtime;
 	return 0;
 }
 
fs/cifs/readdir.c +1 -0
index daf1753..8bd18be 100644
@@ -160,6 +160,7 @@ cifs_dir_info_to_fattr(struct cifs_fattr *fattr, FILE_DIRECTORY_INFO *info,
 	fattr->cf_cifsattrs = le32_to_cpu(info->ExtFileAttributes);
 	fattr->cf_eof = le64_to_cpu(info->EndOfFile);
 	fattr->cf_bytes = le64_to_cpu(info->AllocationSize);
+	fattr->cf_createtime = le64_to_cpu(info->CreationTime);
 	fattr->cf_atime = cifs_NTtimeToUnix(info->LastAccessTime);
 	fattr->cf_ctime = cifs_NTtimeToUnix(info->ChangeTime);
 	fattr->cf_mtime = cifs_NTtimeToUnix(info->LastWriteTime);
Signature · 1 line
1.6.6.1

A message that is not in the archive (sent off-list or not yet received): 1277723413-23769-3-git-send-email-jlayton-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org

#5 lore raw

Re: [PATCH 2/3] cifs: use CreationTime like an i_generation field

Quoted 82 lines · Jeff Layton

Reduce false inode collisions by using the CreationTime like an i_generation field. This way, even if the server ends up reusing a uniqueid after a delete/create cycle, we can avoid matching the inode incorrectly.

---
 fs/cifs/cifsfs.c   |    2 ++
 fs/cifs/cifsglob.h |    2 ++
 fs/cifs/inode.c    |    6 ++++++
 fs/cifs/readdir.c  |    1 +
 4 files changed, 11 insertions(+), 0 deletions(-)
fs/cifs/cifsfs.c +2 -0
index 484e52b..e409216 100644
@@ -314,6 +314,8 @@ cifs_alloc_inode(struct super_block *sb)
 	cifs_inode->invalid_mapping = false;
 	cifs_inode->vfs_inode.i_blkbits = 14;  /* 2**14 = CIFS_MAX_MSGSIZE */
 	cifs_inode->server_eof = 0;
+	cifs_inode->uniqueid = 0;
+	cifs_inode->createtime = 0;
 
 	/* Can not set i_flags here - they get immediately overwritten
 	   to zero by the VFS */
fs/cifs/cifsglob.h +2 -0
index e15d7a5..a0fd2c2 100644
@@ -382,6 +382,7 @@ struct cifsInodeInfo {
 	bool invalid_mapping:1;		/* pagecache is invalid */
 	u64  server_eof;		/* current file size on server */
 	u64  uniqueid;			/* server inode number */
+	u64  createtime;		/* creation time on server */
 	struct inode vfs_inode;
 };
 
@@ -499,6 +500,7 @@ struct cifs_fattr {
 	u64		cf_uniqueid;
 	u64		cf_eof;
 	u64		cf_bytes;
+	u64		cf_createtime;
 	uid_t		cf_uid;
 	gid_t		cf_gid;
 	umode_t		cf_mode;
fs/cifs/inode.c +6 -0
index f64b95f..35e2466 100644
@@ -487,6 +487,7 @@ cifs_all_info_to_fattr(struct cifs_fattr *fattr, FILE_ALL_INFO *info,
 
 	fattr->cf_eof = le64_to_cpu(info->EndOfFile);
 	fattr->cf_bytes = le64_to_cpu(info->AllocationSize);
+	fattr->cf_createtime = le64_to_cpu(info->CreationTime);
 
 	if (fattr->cf_cifsattrs & ATTR_DIRECTORY) {
 		fattr->cf_mode = S_IFDIR | cifs_sb->mnt_dir_mode;
@@ -727,6 +728,10 @@ cifs_find_inode(struct inode *inode, void *opaque)
 	if (CIFS_I(inode)->uniqueid != fattr->cf_uniqueid)
 		return 0;
 
+	/* use createtime like an i_generation field */
+	if (CIFS_I(inode)->createtime != fattr->cf_createtime)
+		return 0;
+
 	/* don't match inode of different type */
 	if ((inode->i_mode & S_IFMT) != (fattr->cf_mode & S_IFMT))
 		return 0;
@@ -750,6 +755,7 @@ cifs_init_inode(struct inode *inode, void *opaque)
 	struct cifs_fattr *fattr = (struct cifs_fattr *) opaque;
 
 	CIFS_I(inode)->uniqueid = fattr->cf_uniqueid;
+	CIFS_I(inode)->createtime = fattr->cf_createtime;
 	return 0;
 }
 
fs/cifs/readdir.c +0 -0
index daf1753..8bd18be 100644

fs/cifs/readdir.c cifs_dir_info_to_fattr(struct cifs_fattr *fattr, FILE_DIRECTORY_INFO *info, · line 163

Quoted 4 lines
fs/cifs/readdir.c +1 -0
@@ -160,6 +160,7 @@ cifs_dir_info_to_fattr(struct cifs_fattr *fattr, FILE_DIRECTORY_INFO *info,
 	fattr->cf_cifsattrs = le32_to_cpu(info->ExtFileAttributes);
 	fattr->cf_eof = le64_to_cpu(info->EndOfFile);
 	fattr->cf_bytes = le64_to_cpu(info->AllocationSize);
+	fattr->cf_createtime = le64_to_cpu(info->CreationTime);

cifs_std_info_to_fattr() needs this too?

Quoted 3 lines
fs/cifs/readdir.c +0 -0
 	fattr->cf_atime = cifs_NTtimeToUnix(info->LastAccessTime);
 	fattr->cf_ctime = cifs_NTtimeToUnix(info->ChangeTime);
 	fattr->cf_mtime = cifs_NTtimeToUnix(info->LastWriteTime);
Signature · 1 line
Suresh Jayaraman
#6 lore raw

Re: [PATCH 2/3] cifs: use CreationTime like an i_generation field

Quoted 78 lines · On Mon, 28 Jun 2010 18:56:09 +0530 Suresh Jayaraman <[email protected]> wrote:
Quoted 77 lines · Jeff Layton

Reduce false inode collisions by using the CreationTime like an i_generation field. This way, even if the server ends up reusing a uniqueid after a delete/create cycle, we can avoid matching the inode incorrectly.

---
 fs/cifs/cifsfs.c   |    2 ++
 fs/cifs/cifsglob.h |    2 ++
 fs/cifs/inode.c    |    6 ++++++
 fs/cifs/readdir.c  |    1 +
 4 files changed, 11 insertions(+), 0 deletions(-)
fs/cifs/cifsfs.c +2 -0
index 484e52b..e409216 100644
@@ -314,6 +314,8 @@ cifs_alloc_inode(struct super_block *sb)
 	cifs_inode->invalid_mapping = false;
 	cifs_inode->vfs_inode.i_blkbits = 14;  /* 2**14 = CIFS_MAX_MSGSIZE */
 	cifs_inode->server_eof = 0;
+	cifs_inode->uniqueid = 0;
+	cifs_inode->createtime = 0;
 
 	/* Can not set i_flags here - they get immediately overwritten
 	   to zero by the VFS */
fs/cifs/cifsglob.h +2 -0
index e15d7a5..a0fd2c2 100644
@@ -382,6 +382,7 @@ struct cifsInodeInfo {
 	bool invalid_mapping:1;		/* pagecache is invalid */
 	u64  server_eof;		/* current file size on server */
 	u64  uniqueid;			/* server inode number */
+	u64  createtime;		/* creation time on server */
 	struct inode vfs_inode;
 };
 
@@ -499,6 +500,7 @@ struct cifs_fattr {
 	u64		cf_uniqueid;
 	u64		cf_eof;
 	u64		cf_bytes;
+	u64		cf_createtime;
 	uid_t		cf_uid;
 	gid_t		cf_gid;
 	umode_t		cf_mode;
fs/cifs/inode.c +6 -0
index f64b95f..35e2466 100644
@@ -487,6 +487,7 @@ cifs_all_info_to_fattr(struct cifs_fattr *fattr, FILE_ALL_INFO *info,
 
 	fattr->cf_eof = le64_to_cpu(info->EndOfFile);
 	fattr->cf_bytes = le64_to_cpu(info->AllocationSize);
+	fattr->cf_createtime = le64_to_cpu(info->CreationTime);
 
 	if (fattr->cf_cifsattrs & ATTR_DIRECTORY) {
 		fattr->cf_mode = S_IFDIR | cifs_sb->mnt_dir_mode;
@@ -727,6 +728,10 @@ cifs_find_inode(struct inode *inode, void *opaque)
 	if (CIFS_I(inode)->uniqueid != fattr->cf_uniqueid)
 		return 0;
 
+	/* use createtime like an i_generation field */
+	if (CIFS_I(inode)->createtime != fattr->cf_createtime)
+		return 0;
+
 	/* don't match inode of different type */
 	if ((inode->i_mode & S_IFMT) != (fattr->cf_mode & S_IFMT))
 		return 0;
@@ -750,6 +755,7 @@ cifs_init_inode(struct inode *inode, void *opaque)
 	struct cifs_fattr *fattr = (struct cifs_fattr *) opaque;
 
 	CIFS_I(inode)->uniqueid = fattr->cf_uniqueid;
+	CIFS_I(inode)->createtime = fattr->cf_createtime;
 	return 0;
 }
 
Quoted 12 lines

fs/cifs/readdir.c cifs_dir_info_to_fattr(struct cifs_fattr *fattr, FILE_DIRECTORY_INFO *info, · line 163

Quoted 9 lines
fs/cifs/readdir.c +1 -0
index daf1753..8bd18be 100644
@@ -160,6 +160,7 @@ cifs_dir_info_to_fattr(struct cifs_fattr *fattr, FILE_DIRECTORY_INFO *info,
 	fattr->cf_cifsattrs = le32_to_cpu(info->ExtFileAttributes);
 	fattr->cf_eof = le64_to_cpu(info->EndOfFile);
 	fattr->cf_bytes = le64_to_cpu(info->AllocationSize);
+	fattr->cf_createtime = le64_to_cpu(info->CreationTime);

cifs_std_info_to_fattr() needs this too?

I don't think so. If we're using that function then we're probably going to be using the legacy SMBQueryInformation calls too. Those do not return a CreateTime and it ends up being set to 0. This *should* do the right thing I think...

It would be nice to do this in a more definite way somehow though. The legacy QPathInfo codepath is a bit of a mess...

Quoted 5 lines
Quoted 3 lines
fs/cifs/readdir.c +0 -0
 	fattr->cf_atime = cifs_NTtimeToUnix(info->LastAccessTime);
 	fattr->cf_ctime = cifs_NTtimeToUnix(info->ChangeTime);
 	fattr->cf_mtime = cifs_NTtimeToUnix(info->LastWriteTime);
Signature · 1 line
Jeff Layton <[email protected]>
#7 lore raw

Re: [PATCH 2/3] cifs: use CreationTime like an i_generation field

In reply to Jeff Layton
Quoted 82 lines · On Mon, 28 Jun 2010 07:10:12 -0400 Jeff Layton <[email protected]> wrote:

Reduce false inode collisions by using the CreationTime like an i_generation field. This way, even if the server ends up reusing a uniqueid after a delete/create cycle, we can avoid matching the inode incorrectly.

---
 fs/cifs/cifsfs.c   |    2 ++
 fs/cifs/cifsglob.h |    2 ++
 fs/cifs/inode.c    |    6 ++++++
 fs/cifs/readdir.c  |    1 +
 4 files changed, 11 insertions(+), 0 deletions(-)
fs/cifs/cifsfs.c +2 -0
index 484e52b..e409216 100644
@@ -314,6 +314,8 @@ cifs_alloc_inode(struct super_block *sb)
 	cifs_inode->invalid_mapping = false;
 	cifs_inode->vfs_inode.i_blkbits = 14;  /* 2**14 = CIFS_MAX_MSGSIZE */
 	cifs_inode->server_eof = 0;
+	cifs_inode->uniqueid = 0;
+	cifs_inode->createtime = 0;
 
 	/* Can not set i_flags here - they get immediately overwritten
 	   to zero by the VFS */
fs/cifs/cifsglob.h +2 -0
index e15d7a5..a0fd2c2 100644
@@ -382,6 +382,7 @@ struct cifsInodeInfo {
 	bool invalid_mapping:1;		/* pagecache is invalid */
 	u64  server_eof;		/* current file size on server */
 	u64  uniqueid;			/* server inode number */
+	u64  createtime;		/* creation time on server */
 	struct inode vfs_inode;
 };
 
@@ -499,6 +500,7 @@ struct cifs_fattr {
 	u64		cf_uniqueid;
 	u64		cf_eof;
 	u64		cf_bytes;
+	u64		cf_createtime;
 	uid_t		cf_uid;
 	gid_t		cf_gid;
 	umode_t		cf_mode;
fs/cifs/inode.c +6 -0
index f64b95f..35e2466 100644
@@ -487,6 +487,7 @@ cifs_all_info_to_fattr(struct cifs_fattr *fattr, FILE_ALL_INFO *info,
 
 	fattr->cf_eof = le64_to_cpu(info->EndOfFile);
 	fattr->cf_bytes = le64_to_cpu(info->AllocationSize);
+	fattr->cf_createtime = le64_to_cpu(info->CreationTime);
 
 	if (fattr->cf_cifsattrs & ATTR_DIRECTORY) {
 		fattr->cf_mode = S_IFDIR | cifs_sb->mnt_dir_mode;
@@ -727,6 +728,10 @@ cifs_find_inode(struct inode *inode, void *opaque)
 	if (CIFS_I(inode)->uniqueid != fattr->cf_uniqueid)
 		return 0;
 
+	/* use createtime like an i_generation field */
+	if (CIFS_I(inode)->createtime != fattr->cf_createtime)
+		return 0;
+
 	/* don't match inode of different type */
 	if ((inode->i_mode & S_IFMT) != (fattr->cf_mode & S_IFMT))
 		return 0;
@@ -750,6 +755,7 @@ cifs_init_inode(struct inode *inode, void *opaque)
 	struct cifs_fattr *fattr = (struct cifs_fattr *) opaque;
 
 	CIFS_I(inode)->uniqueid = fattr->cf_uniqueid;
+	CIFS_I(inode)->createtime = fattr->cf_createtime;
 	return 0;
 }
 
fs/cifs/readdir.c +0 -0
index daf1753..8bd18be 100644

fs/cifs/readdir.c cifs_dir_info_to_fattr(struct cifs_fattr *fattr, FILE_DIRECTORY_INFO *info, · line 166

Quoted 7 lines
fs/cifs/readdir.c +1 -0
@@ -160,6 +160,7 @@ cifs_dir_info_to_fattr(struct cifs_fattr *fattr, FILE_DIRECTORY_INFO *info,
 	fattr->cf_cifsattrs = le32_to_cpu(info->ExtFileAttributes);
 	fattr->cf_eof = le64_to_cpu(info->EndOfFile);
 	fattr->cf_bytes = le64_to_cpu(info->AllocationSize);
+	fattr->cf_createtime = le64_to_cpu(info->CreationTime);
 	fattr->cf_atime = cifs_NTtimeToUnix(info->LastAccessTime);
 	fattr->cf_ctime = cifs_NTtimeToUnix(info->ChangeTime);
 	fattr->cf_mtime = cifs_NTtimeToUnix(info->LastWriteTime);

Steve, can you clarify where we are with this patch? I originally sent this back in June. You and I discussed this at the CIFS plugfest and I had thought you had decided to merge it. It's still not in your tree however. Can you give a verdict on whether you're going to merge it and let me know when I can expect to see it in your tree if so?

Thanks,

Signature · 1 line
Jeff Layton <[email protected]>

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): AANLkTimtg0vFVQ5HGo+nq7rE=Z4Sob=z7LuVCMFgWdnv-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

#10 lore raw

Re: [PATCH 2/3] cifs: use CreationTime like an i_generation field

Quoted 13 lines · On Mon, 22 Nov 2010 14:22:50 -0600 Steve French…
Quoted 11 lines · Jeff Layton

On Mon, 28 Jun 2010 07:10:12 -0400
Jeff Layton <[email protected]> wrote:

Steve, can you clarify where we are with this patch? I originally sent this back in June. You and I discussed this at the CIFS plugfest and I had thought you had decided to merge it. It's still not in your tree however. Can you give a verdict on whether you're going to merge it and let me know when I can expect to see it in your tree if so?

Quoted 5 lines

Thanks for reminding me. I had forgotten to ask JRA about a question
on legacy Samba behavior. I remembered that older Samba
had problems with creation time - and was trying to remember what the implication of using this patch with older Samba was.

All samba versions have issues with create times (at least on Linux anyway). They fake them, by using the ctime (which seems like an odd choice to me) in most cases.

Either way, let me know when you decide or if you have a question on this.

Thanks,

Signature · 1 line
Jeff Layton <[email protected]>

A message that is not in the archive (sent off-list or not yet received): 20101122153125.68ee4ee6-4QP7MXygkU+dMjc06nkz3ljfA9RmPOcC@public.gmane.org

#12 lore raw

Re: [PATCH 2/3] cifs: use CreationTime like an i_generation field

Quoted 22 lines · Jeff Layton
Quoted 13 lines · On Mon, 22 Nov 2010 14:22:50 -0600 Steve French…
Quoted 11 lines · Jeff Layton

On Mon, 28 Jun 2010 07:10:12 -0400
Jeff Layton <[email protected]> wrote:

Steve, can you clarify where we are with this patch? I originally sent this back in June. You and I discussed this at the CIFS plugfest and I had thought you had decided to merge it. It's still not in your tree however. Can you give a verdict on whether you're going to merge it and let me know when I can expect to see it in your tree if so?

Quoted 5 lines

Thanks for reminding me. I had forgotten to ask JRA about a question
on legacy Samba behavior. I remembered that older Samba
had problems with creation time - and was trying to remember what the implication of using this patch with older Samba was.

Quoted 3 lines

All samba versions have issues with create times (at least on Linux anyway). They fake them, by using the ctime (which seems like an odd choice to me) in most cases.

New Samba's store create time in an xattr, so they can return a reasonably valid create time value.

Jeremy.

#13 lore raw

Re: [PATCH 2/3] cifs: use CreationTime like an i_generation field

Quoted 23 lines · On Mon, 22 Nov 2010 12:59:17 -0800 Jeremy Allison…
Quoted 22 lines · Jeff Layton
Quoted 18 lines · On Mon, 22 Nov 2010 14:22:50 -0600 Steve French…
Quoted 11 lines · Jeff Layton

On Mon, 28 Jun 2010 07:10:12 -0400
Jeff Layton <[email protected]> wrote:

Steve, can you clarify where we are with this patch? I originally sent this back in June. You and I discussed this at the CIFS plugfest and I had thought you had decided to merge it. It's still not in your tree however. Can you give a verdict on whether you're going to merge it and let me know when I can expect to see it in your tree if so?

Thanks for reminding me. I had forgotten to ask JRA about a question
on legacy Samba behavior. I remembered that older Samba
had problems with creation time - and was trying to remember what the implication of using this patch with older Samba was.

Quoted 7 lines
Quoted 3 lines

All samba versions have issues with create times (at least on Linux anyway). They fake them, by using the ctime (which seems like an odd choice to me) in most cases.

New Samba's store create time in an xattr, so they can return a reasonably valid create time value.

Steve, we're approaching the 6 month mark since I originally sent this patch. Could you make a decision on it soon so that I know what should be done with it?

Thanks,

Signature · 1 line
Jeff Layton <[email protected]>
#14 lore raw

PATCH 3/3 cifs: reduce false positives with inode aliasing serverino autodisable

In reply to a message not in the archive

It turns out that not all directory inodes with dentries on the i_dentry list are unusable here. We only consider them unusable if they are still hashed or if they have a root dentry attached.

Full disclosure -- this check is inherently racy. There's nothing that stops someone from slapping a new dentry onto this inode just after this check, or hashing an existing one that's already attached. So, this is really a "best effort" thing to work around misbehaving servers.

---
 fs/cifs/inode.c |   43 +++++++++++++++++++++++++++++++------------
 1 files changed, 31 insertions(+), 12 deletions(-)
fs/cifs/inode.c +31 -12
index 35e2466..1bfb8ec 100644
@@ -736,15 +736,9 @@ cifs_find_inode(struct inode *inode, void *opaque)
 	if ((inode->i_mode & S_IFMT) != (fattr->cf_mode & S_IFMT))
 		return 0;
 
-	/*
-	 * uh oh -- it's a directory. We can't use it since hardlinked dirs are
-	 * verboten. Disable serverino and return it as if it were found, the
-	 * caller can discard it, generate a uniqueid and retry the find
-	 */
-	if (S_ISDIR(inode->i_mode) && !list_empty(&inode->i_dentry)) {
+	/* if it's not a directory or has no dentries, then flag it */
+	if (S_ISDIR(inode->i_mode) && !list_empty(&inode->i_dentry))
 		fattr->cf_flags |= CIFS_FATTR_INO_COLLISION;
-		cifs_autodisable_serverino(CIFS_SB(inode->i_sb));
-	}
 
 	return 1;
 }
@@ -759,6 +753,27 @@ cifs_init_inode(struct inode *inode, void *opaque)
 	return 0;
 }
 
+/*
+ * walk dentry list for an inode and report whether it has aliases that
+ * are hashed. We use this to determine if a directory inode can actually
+ * be used.
+ */
+static bool
+inode_has_hashed_dentries(struct inode *inode)
+{
+	struct dentry *dentry;
+
+	spin_lock(&dcache_lock);
+	list_for_each_entry(dentry, &inode->i_dentry, d_alias) {
+		if (!d_unhashed(dentry) || IS_ROOT(dentry)) {
+			spin_unlock(&dcache_lock);
+			return true;
+		}
+	}
+	spin_unlock(&dcache_lock);
+	return false;
+}
+
 /* Given fattrs, get a corresponding inode */
 struct inode *
 cifs_iget(struct super_block *sb, struct cifs_fattr *fattr)
@@ -774,12 +789,16 @@ retry_iget5_locked:
 
 	inode = iget5_locked(sb, hash, cifs_find_inode, cifs_init_inode, fattr);
 	if (inode) {
-		/* was there a problematic inode number collision? */
+		/* was there a potentially problematic inode collision? */
 		if (fattr->cf_flags & CIFS_FATTR_INO_COLLISION) {
-			iput(inode);
-			fattr->cf_uniqueid = iunique(sb, ROOT_I);
 			fattr->cf_flags &= ~CIFS_FATTR_INO_COLLISION;
-			goto retry_iget5_locked;
+
+			if (inode_has_hashed_dentries(inode)) {
+				cifs_autodisable_serverino(CIFS_SB(sb));
+				iput(inode);
+				fattr->cf_uniqueid = iunique(sb, ROOT_I);
+				goto retry_iget5_locked;
+			}
 		}
 
 		cifs_fattr_to_inode(inode, fattr);
Signature · 1 line
1.6.6.1