Skip to contentSkip to conversation

dfs path construction fix - send dfs paths on all path based operations on share in dfs

PATCH Steve French 2 participants 4 messages May 13, 2008 – May 16, 2008 2 messages not in the archive VFS

lore
Share & tools
lore
#0 lore raw

Samba was not handling paths without the \\server\share prefix (which our current code sends on QueryPathInfo) when "SHARE_IN_DFS" on operations such as rmdir and delete.

This patch fixes that:

Signature · 3 lines
Thanks,

Steve
fs/cifs/dir.c +23 -5
index e4e0078..05afe33 100644
@@ -49,18 +49,25 @@ build_path_from_dentry(struct dentry *direntry)
 	struct dentry *temp;
 	int namelen;
 	int pplen;
+	int dfsplen;
 	char *full_path;
 	char dirsep;
+	struct cifs_sb_info *cifs_sb;
 
 	if (direntry == NULL)
 		return NULL;  /* not much we can do if dentry is freed and
 		we need to reopen the file after it was closed implicitly
 		when the server crashed */
 
-	dirsep = CIFS_DIR_SEP(CIFS_SB(direntry->d_sb));
-	pplen = CIFS_SB(direntry->d_sb)->prepathlen;
+	cifs_sb = CIFS_SB(direntry->d_sb);
+	dirsep = CIFS_DIR_SEP(cifs_sb);
+	pplen = cifs_sb->prepathlen;
+	if (cifs_sb->tcon && (cifs_sb->tcon->Flags & SMB_SHARE_IS_IN_DFS))
+		dfsplen = strnlen(cifs_sb->tcon->treeName, MAX_TREE_SIZE + 1);
+	else
+		dfsplen = 0;
 cifs_bp_rename_retry:
-	namelen = pplen;
+	namelen = pplen + dfsplen;
 	for (temp = direntry; !IS_ROOT(temp);) {
 		namelen += (1 + temp->d_name.len);
 		temp = temp->d_parent;
@@ -91,7 +98,7 @@ cifs_bp_rename_retry:
 			return NULL;
 		}
 	}
-	if (namelen != pplen) {
+	if (namelen != pplen + dfsplen) {
 		cERROR(1,
 		       ("did not end path lookup where expected namelen is %d",
 			namelen));
@@ -107,7 +114,18 @@ cifs_bp_rename_retry:
 	   since the '\' is a valid posix character so we can not switch
 	   those safely to '/' if any are found in the middle of the prepath */
 	/* BB test paths to Windows with '/' in the midst of prepath */
-	strncpy(full_path, CIFS_SB(direntry->d_sb)->prepath, pplen);
+
+	if (dfsplen) {
+		strncpy(full_path, cifs_sb->tcon->treeName, dfsplen);
+		if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_POSIX_PATHS) {
+			int i;
+			for (i = 0; i < dfsplen; i++) {
+				if (full_path[i] == '\\')
+					full_path[i] = '/';
+			}
+		}
+	}
+	strncpy(full_path + dfsplen, CIFS_SB(direntry->d_sb)->prepath, pplen);
 	return full_path;
 }
 
fs/cifs/inode.c +8 -57

150 lines not on this page · raw message

#1 lore raw
Quoted 5 lines · Steve French

Samba was not handling paths without the \\server\share prefix (which our current code sends on QueryPathInfo) when "SHARE_IN_DFS" on operations such as rmdir and delete.

This patch fixes that:

Attempted to test patch and

-
at the first attempt I've got oops caused by a missing CIFSGetDFSRefer patch, after digging it up and applying it, oops is disappeared. But it doesn't help much because your patch broke traversal over a dfs link, at the moment dfs lookup relies on the second lookup attempt with a short path name (without tree name).
BTW, you said that you almost made patch for a fake dfs inode, it could fix things up.

+
mkdir and rmdir on a dfs enabled share work (at least with samba), can't check it on MS however.

PS:
commiting CIFSGetDFSRefer patch will help to avoid oops-es and more people would be able to test the DFS related patches.

Signature · 5 lines
Best regards,

-------------------------
Igor Mammedov,
niallain "at" gmail.com

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): [email protected]

#4 lore raw

just checked in some of the GetDFSRefer cleanup into cifs-2.6. (with minor style changes)

Missing still:
1) faking up inode after initial PATH_NOT_COVERED
2) cleanup of the code which parses the SMB response in GetDFSRefer function in fs/cifs/cifssmb.c

Quoted 68 lines · Steve French

I found the december version - and checked in part. The next two
checkins will be:

1) the part of GetDFSRefer before the smb send which should work as is
2) the post-processing (looking at the SMB response buffer and taking the dfs structs out of it) which Christoph says was too big and needs to be put in a different function - so needs more coding

Quoted 49 lines · Steve French

Do you have a newer version of the GetDFSRefer patch - or point me to which you think is most current?

Quoted 27 lines · Igor Mammedov
Quoted 5 lines · Steve French

Samba was not handling paths without the \\server\share prefix (which our current code sends on QueryPathInfo) when "SHARE_IN_DFS" on operations such as rmdir and delete.

This patch fixes that:

Attempted to test patch and

(quoted diff) +1 -1
-
 at the first attempt I've got oops caused by a missing CIFSGetDFSRefer patch,
 after digging it up and applying it, oops is disappeared. But it doesn't
 help much because your patch broke traversal over a dfs link,  at the moment
 dfs lookup relies on the second lookup attempt with a short path name (without
 tree name).
 BTW, you said that you almost made patch for a fake dfs inode,  it could fix
 things up.
 
+
 mkdir and rmdir on a dfs enabled share work (at least with samba), can't check
 it on MS however.

PS:
commiting CIFSGetDFSRefer patch will help to avoid oops-es and more people would be able to test the DFS related patches.

Quoted 12 lines

--

Best regards,

-------------------------
Igor Mammedov,
niallain "at" gmail.com

--
Thanks,

Quoted 2 lines

Steve

--
Thanks,

Steve

Signature · 3 lines
Thanks,

Steve
#5 lore raw
In reply to Steve French
Quoted 5 lines · Steve French

Samba was not handling paths without the \\server\share prefix (which our current code sends on QueryPathInfo) when "SHARE_IN_DFS" on operations such as rmdir and delete.

This patch fixes that:

A set of patches that fixes path handling (broken by 646dd539878a194) in the DFS related parts of code in accordance with
a new 'build_path_from_dentry' behavior.

Signature · 5 lines
Best regards,

-------------------------
Igor Mammedov,
niallain "at" gmail.com
Quoted 1 line

From b5a37238de56db6a99db746b169fe3deba27b510 Mon Sep 17 00:00:00 2001

From: Igor Mammedov <[email protected]>
Date: Fri, 16 May 2008 13:10:32 +0400
Subject: [PATCH] Fixed DFS code to work with new 'build_path_from_dentry', that returns
full path if share in the dfs, now.

---
 fs/cifs/cifs_dfs_ref.c |   49 +-----------------------------------------------
 1 files changed, 1 insertions(+), 48 deletions(-)
fs/cifs/cifs_dfs_ref.c +1 -48
index f6fdecf..d82374c 100644
@@ -219,53 +219,6 @@ static struct vfsmount *cifs_dfs_do_refmount(const struct vfsmount *mnt_parent,
 
 }
 
-static char *build_full_dfs_path_from_dentry(struct dentry *dentry)
-{
-	char *full_path = NULL;
-	char *search_path;
-	char *tmp_path;
-	size_t l_max_len;
-	struct cifs_sb_info *cifs_sb;
-
-	if (dentry->d_inode == NULL)
-		return NULL;
-
-	cifs_sb = CIFS_SB(dentry->d_inode->i_sb);
-
-	if (cifs_sb->tcon == NULL)
-		return NULL;
-
-	search_path = build_path_from_dentry(dentry);
-	if (search_path == NULL)
-		return NULL;
-
-	if (cifs_sb->tcon->Flags & SMB_SHARE_IS_IN_DFS) {
-		int i;
-		/* we should use full path name for correct working with DFS */
-		l_max_len = strnlen(cifs_sb->tcon->treeName, MAX_TREE_SIZE+1) +
-					strnlen(search_path, MAX_PATHCONF) + 1;
-		tmp_path = kmalloc(l_max_len, GFP_KERNEL);
-		if (tmp_path == NULL) {
-			kfree(search_path);
-			return NULL;
-		}
-		strncpy(tmp_path, cifs_sb->tcon->treeName, l_max_len);
-		tmp_path[l_max_len-1] = 0;
-		if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_POSIX_PATHS)
-			for (i = 0; i < l_max_len; i++) {
-				if (tmp_path[i] == '\\')
-					tmp_path[i] = '/';
-			}
-		strncat(tmp_path, search_path, l_max_len - strlen(tmp_path));
-
-		full_path = tmp_path;
-		kfree(search_path);
-	} else {
-		full_path = search_path;
-	}
-	return full_path;
-}
-
 static int add_mount_helper(struct vfsmount *newmnt, struct nameidata *nd,
 				struct list_head *mntlist)
 {
@@ -333,7 +286,7 @@ cifs_dfs_follow_mountpoint(struct dentry *dentry, struct nameidata *nd)
 		goto out_err;
 	}
 
-	full_path = build_full_dfs_path_from_dentry(dentry);
+	full_path = build_path_from_dentry(dentry);
 	if (full_path == NULL) {
 		rc = -ENOMEM;
 		goto out_err;
Signature · 1 line
1.5.3.7
Quoted 1 line

From fd33ede1ca0b157ecf26711bdf12c2b15336e0cd Mon Sep 17 00:00:00 2001

From: Igor Mammedov <[email protected]>
Date: Fri, 16 May 2008 13:24:59 +0400
Subject: [PATCH] Fixed inode lookup code (DFS related part) to support
new build_path_from_dentry behaviour.

---
 fs/cifs/inode.c |   11 +++++++++++
 1 files changed, 11 insertions(+), 0 deletions(-)
fs/cifs/inode.c +11 -0
index 9d9b56a..c7c5242 100644
@@ -184,6 +184,9 @@ try_again_CIFSSMBUnixQPathInfo:
 	if (rc) {
 		if (rc == -EREMOTE && !is_dfs_referral) {
 			is_dfs_referral = true;
+			full_path = strchr(full_path + 2, '/');
+			full_path++;
+			full_path = strchr(full_path + 2, '/');
 			goto try_again_CIFSSMBUnixQPathInfo;
 		}
 		goto cgiiu_exit;
@@ -230,6 +233,11 @@ try_again_CIFSSMBUnixQPathInfo:
 			(unsigned long) inode->i_size,
 			(unsigned long long)inode->i_blocks));
 
+		if (is_dfs_referral && ((inode->i_mode & S_IFMT) == S_IFLNK)) {
+			inode->i_mode &= ~S_IFLNK;
+			inode->i_mode |= S_IFDIR;
+		}
+
 		cifs_set_ops(inode, is_dfs_referral);
 	}
 cgiiu_exit:
@@ -389,6 +397,9 @@ try_again_CIFSSMBQPathInfo:
 	if (rc) {
 		if (rc == -EREMOTE && !is_dfs_referral) {
 			is_dfs_referral = true;
+			full_path = strchr(full_path + 2, '\\');
+			full_path++;
+			full_path = strchr(full_path + 2, '\\');
 			goto try_again_CIFSSMBQPathInfo;
 		}
 		goto cgii_exit;
Signature · 1 line
1.5.3.7