[linux-cifs-client] Re-exporting cifs mount over NFSv4

Paul "TBBle" Hampson Paul.Hampson at Pobox.com
Fri Mar 7 08:25:08 GMT 2008


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Paul "TBBle" Hampson wrote:
| cifs currently is missing the one mandatory method fh_to_dentry in
| the export_operations structure, so the exportfs code rejects it as
| an exportable filesystem.

| I dunno if anyone's planning to fix this, I think I'll have a go
| just pointing it at generic_fh_to_dentry (as this seems to be the
| intended behaviour under the old API) and see if that works or if
| it sets our machines on fire.

This didn't work immediately, and it's Friday night, so I'm out
until next week.

It exports OK, and I can see stuff in the mounted directory's
listing, with permissions and owners and stuff, but if I try to
access any of the files or directories in that folder, I get
permission denied. After that, an ls -l shows ? for the permissions,
owner, link count etc, and the file names of the files and
directories after the one I tried to access have gained the name of
the local mountpoint in front of them. (for directories it takes a
little while to show up with repeated ls -l of the mountpoint)

ie.
paulh at okami:~$ ls -l mount/
total 23940
drwxrwxr-x 1 paulh domain users        0 2008-02-28 10:30 dir1
drwxrwxr-x 1 paulh domain users        0 2008-02-29 16:49 dir2
drwxrwxr-x 1 paulh domain users        0 2008-01-24 17:29 dir3
drwxrwxr-x 1 paulh domain users        0 2008-01-24 16:13 dir4
drwxrwxr-x 1 paulh domain users        0 2008-01-24 16:12 dir5
- -rwxrwxr-x 1 paulh domain users 24512786 2008-02-28 17:27 file
paulh at okami:~$ ls -l mount/tags # Usually -EPERM, worked this time
- -rwxrwxr-x 1 paulh domain users 24512786 2008-02-28 17:27 mount/tags
paulh at okami:~$ ls -l bigworld/
total 0
drwxrwxr-x 1 paulh domain users 0 2008-02-28 10:30 dir1
?--------- ? ?     ?            ?                ? mount/file
drwxrwxr-x 1 paulh domain users 0 2008-02-29 16:49 dir2
drwxrwxr-x 1 paulh domain users 0 2008-01-24 17:29 dir3
drwxrwxr-x 1 paulh domain users 0 2008-01-24 16:13 dir4
drwxrwxr-x 1 paulh domain users 0 2008-01-24 16:12 dir5

It all appears to be working fine on the cifs client machine, and on
the machines I'm then reexporting to via cifs. (Which I'm hoping to
replace with NFS)

Here's my non-working patch, if anyone can point out what I've done
wrong (I _assume_ my cifs_nfs_get_inode is wrong...) that'd be
great, I'm happy to test it next week when I'm back in the office.

diff -ru linux-source-2.6.24.org/fs/cifs/dir.c
linux-source-2.6.24/fs/cifs/dir.c
- --- linux-source-2.6.24.org/fs/cifs/dir.c	2008-01-25
09:58:37.000000000 +1100
+++ linux-source-2.6.24/fs/cifs/dir.c	2008-03-07 18:42:09.000000000
+1100
@@ -446,6 +446,7 @@
~ 	struct cifs_sb_info *cifs_sb;
~ 	struct cifsTconInfo *pTcon;
~ 	struct inode *newInode = NULL;
+	struct dentry *result = NULL;
~ 	char *full_path = NULL;

~ 	xid = GetXid();
@@ -501,7 +502,7 @@
~ 			direntry->d_op = &cifs_ci_dentry_ops;
~ 		else
~ 			direntry->d_op = &cifs_dentry_ops;
- -		d_add(direntry, newInode);
+		result = d_splice_alias(newInode, direntry);

~ 		/* since paths are not looked up by component - the parent
~ 		   directories are presumed to be good here */
@@ -527,6 +528,9 @@

~ 	kfree(full_path);
~ 	FreeXid(xid);
+	/*	if d_split_alias returned NULL, then rc is also 0 */
+	if (result)
+		return result;
~ 	return ERR_PTR(rc);
~ }

diff -ru linux-source-2.6.24.org/fs/cifs/export.c
linux-source-2.6.24/fs/cifs/export.c
- --- linux-source-2.6.24.org/fs/cifs/export.c	2008-01-25
09:58:37.000000000 +1100
+++ linux-source-2.6.24/fs/cifs/export.c	2008-03-07
18:43:33.000000000 +1100
@@ -46,21 +46,47 @@
~ #include "cifsfs.h"

~ #ifdef CONFIG_CIFS_EXPERIMENTAL
- -static struct dentry *cifs_get_parent(struct dentry *dentry)
+static struct inode *cifs_nfs_get_inode(struct super_block *sb,
+		u64 ino, u32 generation)
~ {
- -	/* BB need to add code here eventually to enable export via NFSD */
- -	cFYI(1, ("get parent for %p", dentry));
- -	return ERR_PTR(-EACCES);
+	/* Borrowed from ext2_nfs_get_inode */
+	struct inode *inode;
+
+	inode = iget(sb, ino);
+	if (inode == NULL)
+		return ERR_PTR(-ENOMEM);
+	if (is_bad_inode(inode) ||
+	    (generation && inode->i_generation != generation)) {
+		/* we didn't find the right inode.. */
+		iput(inode);
+		return ERR_PTR(-ESTALE);
+	}
+	return inode;
+}
+
+static struct dentry *cifs_fh_to_dentry(struct super_block *sb,
struct fid *fid,
+		int fh_len, int fh_type)
+{
+	return generic_fh_to_dentry(sb, fid, fh_len, fh_type,
+				    cifs_nfs_get_inode);
+}
+
+static struct dentry *cifs_fh_to_parent(struct super_block *sb,
struct fid *fid,
+		int fh_len, int fh_type)
+{
+	return generic_fh_to_parent(sb, fid, fh_len, fh_type,
+				    cifs_nfs_get_inode);
~ }

~ const struct export_operations cifs_export_ops = {
- -	.get_parent = cifs_get_parent,
- -/*	Following five export operations are unneeded so far and can
default:
- -	.get_dentry =
- -	.get_name =
- -	.find_exported_dentry =
- -	.decode_fh =
- -	.encode_fs =  */
+	.fh_to_dentry = cifs_fh_to_dentry,
+	.fh_to_parent = cifs_fh_to_parent,
+/*	Fallback to defaults for these, see
+ *	Documentation/filesystems/Exporting for verbosity
+	.encode_fh = encode_inode_and_generation_and_maybe_parent
+	.get_name = scan_directory_using_vfs_readdir_for_name_and_inode
+	.get_parent = return_failure
+*/
~ };

~ #endif /* EXPERIMENTAL */


- --
- -----------------------------------------------------------
Paul "TBBle" Hampson, B.Sc, LPI, MCSE
Very-later-year Asian Studies student, ANU
The Boss, Bubblesworth Pty Ltd (ABN: 51 095 284 361)
Paul.Hampson at Pobox.com

Of course Pacman didn't influence us as kids. If it did,
we'd be running around in darkened rooms, popping pills and
listening to repetitive music.
~ -- Kristian Wilson, Nintendo, Inc, 1989

License: http://creativecommons.org/licenses/by/2.1/au/
- -----------------------------------------------------------
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFH0PvkexDuohKLFuARAnw0AKDHPqWnWIzhwlHoWMhw8JpUnLl0YgCgvyWs
H3ur23A7yks0VOS1H1aSI08=
=sXQb
-----END PGP SIGNATURE-----


More information about the linux-cifs-client mailing list