Commit 982aedfd authored by NeilBrown's avatar NeilBrown Committed by Linus Torvalds

[PATCH] knfsd: tidy up choice of filesystem-identifier when creating a filehandle

If we are using the same version/fsid as a current filehandle, then there is
no need to verify the the numbers are valid for this export, and they must be
(we used them to find this export).

This allows us to simplify the fsid selection code.

Also change "ref_fh_version" and "ref_fh_fsid_type" to "version" and
"fsid_type", as the important thing isn't that they are the version/type of
the reference filehandle, but they are the chosen type for the new filehandle.

And tidy up some indenting.
Signed-off-by: default avatarNeil Brown <neilb@suse.de>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 8971a101
...@@ -317,7 +317,8 @@ static inline void _fh_update_old(struct dentry *dentry, ...@@ -317,7 +317,8 @@ static inline void _fh_update_old(struct dentry *dentry,
} }
__be32 __be32
fh_compose(struct svc_fh *fhp, struct svc_export *exp, struct dentry *dentry, struct svc_fh *ref_fh) fh_compose(struct svc_fh *fhp, struct svc_export *exp, struct dentry *dentry,
struct svc_fh *ref_fh)
{ {
/* ref_fh is a reference file handle. /* ref_fh is a reference file handle.
* if it is non-null and for the same filesystem, then we should compose * if it is non-null and for the same filesystem, then we should compose
...@@ -327,8 +328,8 @@ fh_compose(struct svc_fh *fhp, struct svc_export *exp, struct dentry *dentry, st ...@@ -327,8 +328,8 @@ fh_compose(struct svc_fh *fhp, struct svc_export *exp, struct dentry *dentry, st
* *
*/ */
u8 ref_fh_version = 0; u8 version = 1;
u8 ref_fh_fsid_type = 0; u8 fsid_type = 0;
struct inode * inode = dentry->d_inode; struct inode * inode = dentry->d_inode;
struct dentry *parent = dentry->d_parent; struct dentry *parent = dentry->d_parent;
__u32 *datap; __u32 *datap;
...@@ -340,33 +341,26 @@ fh_compose(struct svc_fh *fhp, struct svc_export *exp, struct dentry *dentry, st ...@@ -340,33 +341,26 @@ fh_compose(struct svc_fh *fhp, struct svc_export *exp, struct dentry *dentry, st
parent->d_name.name, dentry->d_name.name, parent->d_name.name, dentry->d_name.name,
(inode ? inode->i_ino : 0)); (inode ? inode->i_ino : 0));
/* Choose filehandle version and fsid type based on
* the reference filehandle (if it is in the same export)
* or the export options.
*/
if (ref_fh && ref_fh->fh_export == exp) { if (ref_fh && ref_fh->fh_export == exp) {
ref_fh_version = ref_fh->fh_handle.fh_version; version = ref_fh->fh_handle.fh_version;
if (ref_fh_version == 0xca) if (version == 0xca)
ref_fh_fsid_type = 0; fsid_type = 0;
else else
ref_fh_fsid_type = ref_fh->fh_handle.fh_fsid_type; fsid_type = ref_fh->fh_handle.fh_fsid_type;
if (ref_fh_fsid_type > 3) /* We know this version/type works for this export
ref_fh_fsid_type = 0; * so there is no need for further checks.
*/
/* make sure ref_fh type works for given export */
if (ref_fh_fsid_type == 1 &&
!(exp->ex_flags & NFSEXP_FSID)) {
/* if we don't have an fsid, we cannot provide one... */
ref_fh_fsid_type = 0;
}
} else if (exp->ex_flags & NFSEXP_FSID) } else if (exp->ex_flags & NFSEXP_FSID)
ref_fh_fsid_type = 1; fsid_type = 1;
else if (!old_valid_dev(ex_dev))
if (!old_valid_dev(ex_dev) && ref_fh_fsid_type == 0) {
/* for newer device numbers, we must use a newer fsid format */ /* for newer device numbers, we must use a newer fsid format */
ref_fh_version = 1; fsid_type = 3;
ref_fh_fsid_type = 3; else
} fsid_type = 0;
if (old_valid_dev(ex_dev) &&
(ref_fh_fsid_type == 2 || ref_fh_fsid_type == 3))
/* must use type1 for smaller device numbers */
ref_fh_fsid_type = 0;
if (ref_fh == fhp) if (ref_fh == fhp)
fh_put(ref_fh); fh_put(ref_fh);
...@@ -377,20 +371,22 @@ fh_compose(struct svc_fh *fhp, struct svc_export *exp, struct dentry *dentry, st ...@@ -377,20 +371,22 @@ fh_compose(struct svc_fh *fhp, struct svc_export *exp, struct dentry *dentry, st
} }
if (fhp->fh_maxsize < NFS_FHSIZE) if (fhp->fh_maxsize < NFS_FHSIZE)
printk(KERN_ERR "fh_compose: called with maxsize %d! %s/%s\n", printk(KERN_ERR "fh_compose: called with maxsize %d! %s/%s\n",
fhp->fh_maxsize, parent->d_name.name, dentry->d_name.name); fhp->fh_maxsize,
parent->d_name.name, dentry->d_name.name);
fhp->fh_dentry = dget(dentry); /* our internal copy */ fhp->fh_dentry = dget(dentry); /* our internal copy */
fhp->fh_export = exp; fhp->fh_export = exp;
cache_get(&exp->h); cache_get(&exp->h);
if (ref_fh_version == 0xca) { if (version == 0xca) {
/* old style filehandle please */ /* old style filehandle please */
memset(&fhp->fh_handle.fh_base, 0, NFS_FHSIZE); memset(&fhp->fh_handle.fh_base, 0, NFS_FHSIZE);
fhp->fh_handle.fh_size = NFS_FHSIZE; fhp->fh_handle.fh_size = NFS_FHSIZE;
fhp->fh_handle.ofh_dcookie = 0xfeebbaca; fhp->fh_handle.ofh_dcookie = 0xfeebbaca;
fhp->fh_handle.ofh_dev = old_encode_dev(ex_dev); fhp->fh_handle.ofh_dev = old_encode_dev(ex_dev);
fhp->fh_handle.ofh_xdev = fhp->fh_handle.ofh_dev; fhp->fh_handle.ofh_xdev = fhp->fh_handle.ofh_dev;
fhp->fh_handle.ofh_xino = ino_t_to_u32(exp->ex_dentry->d_inode->i_ino); fhp->fh_handle.ofh_xino =
ino_t_to_u32(exp->ex_dentry->d_inode->i_ino);
fhp->fh_handle.ofh_dirino = ino_t_to_u32(parent_ino(dentry)); fhp->fh_handle.ofh_dirino = ino_t_to_u32(parent_ino(dentry));
if (inode) if (inode)
_fh_update_old(dentry, exp, &fhp->fh_handle); _fh_update_old(dentry, exp, &fhp->fh_handle);
...@@ -399,8 +395,8 @@ fh_compose(struct svc_fh *fhp, struct svc_export *exp, struct dentry *dentry, st ...@@ -399,8 +395,8 @@ fh_compose(struct svc_fh *fhp, struct svc_export *exp, struct dentry *dentry, st
fhp->fh_handle.fh_version = 1; fhp->fh_handle.fh_version = 1;
fhp->fh_handle.fh_auth_type = 0; fhp->fh_handle.fh_auth_type = 0;
datap = fhp->fh_handle.fh_auth+0; datap = fhp->fh_handle.fh_auth+0;
fhp->fh_handle.fh_fsid_type = ref_fh_fsid_type; fhp->fh_handle.fh_fsid_type = fsid_type;
switch (ref_fh_fsid_type) { switch (fsid_type) {
case 0: case 0:
/* /*
* fsid_type 0: * fsid_type 0:
...@@ -430,7 +426,7 @@ fh_compose(struct svc_fh *fhp, struct svc_export *exp, struct dentry *dentry, st ...@@ -430,7 +426,7 @@ fh_compose(struct svc_fh *fhp, struct svc_export *exp, struct dentry *dentry, st
exp->ex_dentry->d_inode->i_ino); exp->ex_dentry->d_inode->i_ino);
break; break;
} }
len = key_len(ref_fh_fsid_type); len = key_len(fsid_type);
datap += len/4; datap += len/4;
fhp->fh_handle.fh_size = 4 + len; fhp->fh_handle.fh_size = 4 + len;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment