Skip to contentSkip to conversation

cifs: make posix codepaths handle hardlinks appropriately (RFC)

PATCH In review Jeff Layton 2 participants 8 messages Apr 5, 2009 – Apr 10, 2009 VFS

lore
Share & tools
lore
#0 lore raw

cover cifs: make posix codepaths handle hardlinks appropriately (RFC)

This patchset represents a first draft at making cifs detect hardlinks at inode creation time.

Currently, cifs has a pretty broken mechanism where all dentries get a new inode and hardlinks aren't handled at the VFS layer. Presumably this is because getting inode numbers from windows servers has a performance cost (separate call to the server).

The problem is that hardlinks aren't detected by the VFS so we have to try to detect them when we think it will matter. It also means that there isn't cache consistency between hardlinked inodes.

This patch is intended as a first stab at changing this for inodes on posix mounts. With posix extensions we generally get a "uniqueid" value for free from the server when we get inode attributes.

The SNIA docs state that the UniqueId is unique in the scope of the share, and the MS docs seem to hint that it's per-machine unique value. Either way, I think it's safe enough not to worry about collisions. With this change, we'll probably want to make "serverino" the default (and maybe make it hardcoded on) when posix extensions are enabled.

This set just focuses on the posix extension codepaths. Once I get this settled, I'll take a crack at fixing up the non-posix codepaths similarly (they'll be a bit more work -- more functions will need to be broken up, etc).

The set here seems to work, but there's still more to be done:

1) how to handle an unexpected inode number change (consider a rename or a delete and recreate event that happens from another client or server). Right now, I'm not detecting this, but I think we probably need to consider what to do for it.

2) how to deal with non-posix extensions? When serverino is disabled, I think we'll want to use iunique() to generate new inode numbers. We could also consider making that the default as well.

Anyway...the set isn't quite complete, but I'd like to post this to gather comments and suggestions and as a checkpoint to make sure I'm doing this reasonably correctly.

Jeff Layton (3):
cifs: rename cifs_iget to cifs_root_iget
cifs: add new cifs_iget_unix_basic function
cifs: add cifs_iget_unix and have readdir codepath use it

 fs/cifs/cifsfs.c    |    2 +-
 fs/cifs/cifsfs.h    |   15 +++++-
 fs/cifs/cifsglob.h  |    1 +
 fs/cifs/cifsproto.h |    8 ++-
 fs/cifs/dir.c       |   12 ++--
 fs/cifs/inode.c     |  158 ++++++++++++++++++++++++++++++++++++--------------
 fs/cifs/readdir.c   |  147 +++++++++++++++++++++++++++++++++++------------
 7 files changed, 251 insertions(+), 92 deletions(-)
#1 lore raw

PATCH 1/3 cifs: rename cifs_iget to cifs_root_iget

The current cifs_iget isn't suitable for anything but the root inode. Rename it with a more appropriate name.

---
 fs/cifs/cifsfs.c |    2 +-
 fs/cifs/cifsfs.h |    2 +-
 fs/cifs/inode.c  |    2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)
fs/cifs/cifsfs.c +1 -1
index 34f5701..f0fb524 100644
@@ -148,7 +148,7 @@ cifs_read_super(struct super_block *sb, void *data,
 #endif
 	sb->s_blocksize = CIFS_MAX_MSGSIZE;
 	sb->s_blocksize_bits = 14;	/* default 2**14 = CIFS_MAX_MSGSIZE */
-	inode = cifs_iget(sb, ROOT_I);
+	inode = cifs_root_iget(sb, ROOT_I);
 
 	if (IS_ERR(inode)) {
 		rc = PTR_ERR(inode);
fs/cifs/cifsfs.h +1 -1
index 77e190d..fa3694e 100644
@@ -36,7 +36,7 @@ extern void cifs_read_inode(struct inode *);
 
 /* Functions related to inodes */
 extern const struct inode_operations cifs_dir_inode_ops;
-extern struct inode *cifs_iget(struct super_block *, unsigned long);
+extern struct inode *cifs_root_iget(struct super_block *, unsigned long);
 extern int cifs_create(struct inode *, struct dentry *, int,
 		       struct nameidata *);
 extern struct dentry *cifs_lookup(struct inode *, struct dentry *,
fs/cifs/inode.c +1 -1
index 8faf275..b67c527 100644
@@ -699,7 +699,7 @@ char *cifs_build_path_to_root(struct cifs_sb_info *cifs_sb)
 }
 
 /* gets root inode */
-struct inode *cifs_iget(struct super_block *sb, unsigned long ino)
+struct inode *cifs_root_iget(struct super_block *sb, unsigned long ino)
 {
 	int xid;
 	struct cifs_sb_info *cifs_sb;
Signature · 1 line
1.6.0.6
#2 lore raw

Re: [linux-cifs-client] [PATCH 1/3] cifs: rename cifs_iget to cifs_root_iget

Quoted 2 lines · Jeff Layton

The current cifs_iget isn't suitable for anything but the root inode. Rename it with a more appropriate name.

And using it for the root inode is stupid, too as it can't be in cache.

The root inode is the case where you can easily use new_inode.

#3 lore raw

Re: [linux-cifs-client] [PATCH 1/3] cifs: rename cifs_iget to cifs_root_iget

Quoted 8 lines · On Sun, 5 Apr 2009 09:42:14 -0400 Christoph Hellwig <[email protected]> wrote:
Quoted 2 lines · Jeff Layton

The current cifs_iget isn't suitable for anything but the root inode. Rename it with a more appropriate name.

And using it for the root inode is stupid, too as it can't be in cache.

The root inode is the case where you can easily use new_inode.

Yep. We might want to just get rid of that eventually and move the IPC stuff elsewhere. With the follow-on patches here, I think using iget makes the code a little simpler so I'll leave this in place for now.

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

PATCH 2/3 cifs: add new cifs_iget_unix_basic function

In reply to Jeff Layton

Add a new cifs_iget_unix function that uses iget5_locked to identify inodes. This will compare inodes based on the UniqueId value that the server provides when unix extensions are enabled. We also have mounts with unix extensions use that value in the i_ino field (after hashing it down to 32-bits on a 32-bit arches).

With this, we should then have proper hardlink detection and can eventually get rid of some nasty CIFS-specific hacks for handing them.

Fixing the readdir codepath will be done in a later patch.

---
 fs/cifs/cifsfs.h    |   13 +++++
 fs/cifs/cifsglob.h  |    1 +
 fs/cifs/cifsproto.h |    4 +-
 fs/cifs/dir.c       |   12 ++---
 fs/cifs/inode.c     |  138 +++++++++++++++++++++++++++++++++++----------------
 5 files changed, 117 insertions(+), 51 deletions(-)
fs/cifs/cifsfs.h +13 -0
index fa3694e..aa4ffc0 100644
@@ -24,6 +24,19 @@
 
 #define ROOT_I 2
 
+/*
+ * ino_t is 32-bits on 32-bit arch. We have to squash the 64-bit value down
+ * so that it will fit.
+ */
+static inline ino_t
+cifs_uniqueid_to_ino_t(u64 fileid)
+{
+	ino_t ino = (ino_t) fileid;
+	if (sizeof(ino_t) < sizeof(u64))
+		ino ^= fileid >> (sizeof(u64)-sizeof(ino_t)) * 8;
+	return ino;
+}
+
 extern struct file_system_type cifs_fs_type;
 extern const struct address_space_operations cifs_addr_ops;
 extern const struct address_space_operations cifs_addr_ops_smallbuf;
fs/cifs/cifsglob.h +1 -0
index 7ae1986..1bada66 100644
@@ -371,6 +371,7 @@ struct cifsInodeInfo {
 	bool oplockPending:1;
 	bool delete_pending:1;		/* DELETE_ON_CLOSE is set */
 	u64  server_eof;		/* current file size on server */
+	u64  uniqueid;			/* server inode number */
 	struct inode vfs_inode;
 };
 
fs/cifs/cifsproto.h +3 -1
index 4167716..51dfd51 100644
@@ -99,8 +99,10 @@ extern int cifs_posix_open(char *full_path, struct inode **pinode,
 			   struct super_block *sb, int mode, int oflags,
 			   int *poplock, __u16 *pnetfid, int xid);
 extern void posix_fill_in_inode(struct inode *tmp_inode,
-				FILE_UNIX_BASIC_INFO *pData, int isNewInode);
+				FILE_UNIX_BASIC_INFO *pData);
 extern struct inode *cifs_new_inode(struct super_block *sb, __u64 *inum);
+extern struct inode *cifs_iget_unix_basic(struct super_block *sb,
+				FILE_UNIX_BASIC_INFO *info);
 extern int cifs_get_inode_info(struct inode **pinode,
 			const unsigned char *search_path,
 			FILE_ALL_INFO *pfile_info,
fs/cifs/dir.c +5 -7
index d958044..be639ee 100644
@@ -187,18 +187,16 @@ int cifs_posix_open(char *full_path, struct inode **pinode,
 	if (!pinode)
 		goto posix_open_ret; /* caller does not need info */
 
-	if (*pinode == NULL) {
-		__u64 unique_id = le64_to_cpu(presp_data->UniqueId);
-		*pinode = cifs_new_inode(sb, &unique_id);
-	}
+	if (*pinode == NULL)
+		*pinode = cifs_iget_unix_basic(sb, presp_data);
 	/* else an inode was passed in. Update its info, don't create one */
 
 	/* We do not need to close the file if new_inode fails since
 	   the caller will retry qpathinfo as long as inode is null */
-	if (*pinode == NULL)
+	if (IS_ERR(*pinode)) {
+		rc = PTR_ERR(*pinode);
 		goto posix_open_ret;
-
-	posix_fill_in_inode(*pinode, presp_data, 1);
+	}
 
 posix_open_ret:
 	kfree(presp_data);
fs/cifs/inode.c +95 -43

225 lines not on this page · raw message

Signature · 1 line
1.6.0.6
#5 lore raw

Re: [linux-cifs-client] [PATCH 2/3] cifs: add new cifs_iget_unix_basic function

Quoted 5 lines · Jeff Layton

Add a new cifs_iget_unix function that uses iget5_locked to identify inodes. This will compare inodes based on the UniqueId value that the server provides when unix extensions are enabled. We also have mounts with unix extensions use that value in the i_ino field (after hashing it down to 32-bits on a 32-bit arches).

Note that i_ino and ino_t aren't actually all that important. You already do the iget comparisms based on the internal uniqueid, so the only thing i_ino is used for is filling out the inode value in generic_fattr. I would suggest to fill it out explicitly in cifs_getattr so that you can actually return a 64bit ino there which is supported by stat64, possibly under and inode64 mount option.

Quoted 5 lines
fs/cifs/dir.c +0 -0
index d958044..be639ee 100644

fs/cifs/dir.c int cifs_posix_open(char *full_path, struct inode **pinode, · line 192

Quoted 10 lines
fs/cifs/dir.c +2 -4
@@ -187,18 +187,16 @@ int cifs_posix_open(char *full_path, struct inode **pinode,
 	if (!pinode)
 		goto posix_open_ret; /* caller does not need info */
 
-	if (*pinode == NULL) {
-		__u64 unique_id = le64_to_cpu(presp_data->UniqueId);
-		*pinode = cifs_new_inode(sb, &unique_id);
-	}
+	if (*pinode == NULL)
+		*pinode = cifs_iget_unix_basic(sb, presp_data);
 	/* else an inode was passed in. Update its info, don't create one */

Not directly related to this patch, but cifs_posix_open really needs some restructuring. The code up to the !pinode check should be the basic underlying helper, and the call to cifs_iget_unix_basic and posix_fill_in_inode should be moved to those callers that acutally need it.

#6 lore raw

Re: [linux-cifs-client] [PATCH 2/3] cifs: add new cifs_iget_unix_basic function

Quoted 7 lines · On Wed, 8 Apr 2009 13:05:31 -0400 Christoph Hellwig <[email protected]> wrote:
Quoted 5 lines · Jeff Layton

Add a new cifs_iget_unix function that uses iget5_locked to identify inodes. This will compare inodes based on the UniqueId value that the server provides when unix extensions are enabled. We also have mounts with unix extensions use that value in the i_ino field (after hashing it down to 32-bits on a 32-bit arches).

Quoted 7 lines

Note that i_ino and ino_t aren't actually all that important. You already do the iget comparisms based on the internal uniqueid, so the only thing i_ino is used for is filling out the inode value in generic_fattr. I would suggest to fill it out explicitly in cifs_getattr so that you can actually return a 64bit ino there which is supported by stat64, possibly under and inode64 mount option.

Thanks, Christoph. That sounds reasonable. I'll do that with the next iteration.

Quoted 8 lines
Quoted 8 lines
fs/cifs/dir.c +0 -0
index d958044..be639ee 100644
@@ -187,18 +187,16 @@ int cifs_posix_open(char *full_path, struct inode **pinode,
 	if (!pinode)
 		goto posix_open_ret; /* caller does not need info */
 
Quoted 14 lines

fs/cifs/dir.c int cifs_posix_open(char *full_path, struct inode **pinode, · line 192

Quoted 7 lines
fs/cifs/dir.c +2 -4
-	if (*pinode == NULL) {
-		__u64 unique_id = le64_to_cpu(presp_data->UniqueId);
-		*pinode = cifs_new_inode(sb, &unique_id);
-	}
+	if (*pinode == NULL)
+		*pinode = cifs_iget_unix_basic(sb, presp_data);
 	/* else an inode was passed in. Update its info, don't create one */

Not directly related to this patch, but cifs_posix_open really needs some restructuring. The code up to the !pinode check should be the basic underlying helper, and the call to cifs_iget_unix_basic and posix_fill_in_inode should be moved to those callers that acutally need it.

Agreed, and that's not the only place. The current interfaces for this stuff seem very ad-hoc. A primary goal that have with this patchset is to not break anything and to keep the changes to a minimum, but I'd like to see these cleaned up too.

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

PATCH 3/3 cifs: add cifs_iget_unix and have readdir codepath use it

In reply to Jeff Layton

Add a cifs_iget_unix function similar to cifs_iget_unix_basic. This will ID inodes based on the UniqueId value in a FILE_INFO_UNIX struct.

---
 fs/cifs/cifsproto.h |    4 ++
 fs/cifs/inode.c     |   18 ++++++
 fs/cifs/readdir.c   |  147 +++++++++++++++++++++++++++++++++++++-------------
 3 files changed, 131 insertions(+), 38 deletions(-)
fs/cifs/cifsproto.h +4 -0
index 51dfd51..53b79ad 100644
@@ -100,9 +100,13 @@ extern int cifs_posix_open(char *full_path, struct inode **pinode,
 			   int *poplock, __u16 *pnetfid, int xid);
 extern void posix_fill_in_inode(struct inode *tmp_inode,
 				FILE_UNIX_BASIC_INFO *pData);
+extern void unix_fill_in_inode(struct inode *tmp_inode,
+				FILE_UNIX_INFO *pData);
 extern struct inode *cifs_new_inode(struct super_block *sb, __u64 *inum);
 extern struct inode *cifs_iget_unix_basic(struct super_block *sb,
 				FILE_UNIX_BASIC_INFO *info);
+extern struct inode *cifs_iget_unix(struct super_block *sb,
+				FILE_UNIX_INFO *info);
 extern int cifs_get_inode_info(struct inode **pinode,
 			const unsigned char *search_path,
 			FILE_ALL_INFO *pfile_info,
fs/cifs/inode.c +18 -0
index c30c318..ac7336a 100644
@@ -759,6 +759,24 @@ cifs_iget_unix_basic(struct super_block *sb, FILE_UNIX_BASIC_INFO *info)
 	return inode;
 }
 
+struct inode *
+cifs_iget_unix(struct super_block *sb, FILE_UNIX_INFO *info)
+{
+	struct inode *inode;
+
+	inode = cifs_iget_locked(sb, le64_to_cpu(info->UniqueId));
+	if (!inode)
+		return ERR_PTR(-ENOMEM);
+
+	/* update inode since we have info in hand */
+	unix_fill_in_inode(inode, info);
+
+	if (inode->i_state & I_NEW)
+		unlock_new_inode(inode);
+
+	return inode;
+}
+
 /* gets root inode */
 struct inode *cifs_root_iget(struct super_block *sb, unsigned long ino)
 {
fs/cifs/readdir.c +109 -38

206 lines not on this page · raw message

Signature · 1 line
1.6.0.6