Skip to content

Commit 815409d

Browse files
Trond MyklebustTrond Myklebust
authored andcommitted
NFSv4: Eliminate nfs4_path_walk()
All we really want is the ability to retrieve the root file handle. We no longer need the ability to walk down the path, since that is now done in nfs_follow_remote_path(). Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
1 parent 2d36bfd commit 815409d

3 files changed

Lines changed: 25 additions & 98 deletions

File tree

‎fs/nfs/client.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1364,7 +1364,7 @@ struct nfs_server *nfs4_create_server(const struct nfs_parsed_mount_data *data,
13641364
goto error;
13651365

13661366
/* Probe the root fh to retrieve its FSID */
1367-
error = nfs4_path_walk(server, mntfh, data->nfs_server.export_path);
1367+
error = nfs4_get_rootfh(server, mntfh);
13681368
if (error < 0)
13691369
goto error;
13701370

@@ -1443,7 +1443,7 @@ struct nfs_server *nfs4_create_referral_server(struct nfs_clone_mount *data,
14431443
BUG_ON(!server->nfs_client->rpc_ops->file_inode_ops);
14441444

14451445
/* Probe the root fh to retrieve its FSID and filehandle */
1446-
error = nfs4_path_walk(server, mntfh, data->mnt_path);
1446+
error = nfs4_get_rootfh(server, mntfh);
14471447
if (error < 0)
14481448
goto error;
14491449

‎fs/nfs/getroot.c‎

Lines changed: 22 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -122,115 +122,44 @@ struct dentry *nfs_get_root(struct super_block *sb, struct nfs_fh *mntfh)
122122

123123
#ifdef CONFIG_NFS_V4
124124

125-
/*
126-
* Do a simple pathwalk from the root FH of the server to the nominated target
127-
* of the mountpoint
128-
* - give error on symlinks
129-
* - give error on ".." occurring in the path
130-
* - follow traversals
131-
*/
132-
int nfs4_path_walk(struct nfs_server *server,
133-
struct nfs_fh *mntfh,
134-
const char *path)
125+
int nfs4_get_rootfh(struct nfs_server *server, struct nfs_fh *mntfh)
135126
{
136127
struct nfs_fsinfo fsinfo;
137-
struct nfs_fattr fattr;
138-
struct nfs_fh lastfh;
139-
struct qstr name;
140-
int ret;
128+
int ret = -ENOMEM;
141129

142-
dprintk("--> nfs4_path_walk(,,%s)\n", path);
130+
dprintk("--> nfs4_get_rootfh()\n");
143131

144-
fsinfo.fattr = &fattr;
145-
nfs_fattr_init(&fattr);
146-
147-
/* Eat leading slashes */
148-
while (*path == '/')
149-
path++;
132+
fsinfo.fattr = nfs_alloc_fattr();
133+
if (fsinfo.fattr == NULL)
134+
goto out;
150135

151136
/* Start by getting the root filehandle from the server */
152137
ret = server->nfs_client->rpc_ops->getroot(server, mntfh, &fsinfo);
153138
if (ret < 0) {
154-
dprintk("nfs4_get_root: getroot error = %d\n", -ret);
155-
return ret;
139+
dprintk("nfs4_get_rootfh: getroot error = %d\n", -ret);
140+
goto out;
156141
}
157142

158-
if (!S_ISDIR(fattr.mode)) {
159-
printk(KERN_ERR "nfs4_get_root:"
143+
if (!(fsinfo.fattr->valid & NFS_ATTR_FATTR_MODE)
144+
|| !S_ISDIR(fsinfo.fattr->mode)) {
145+
printk(KERN_ERR "nfs4_get_rootfh:"
160146
" getroot encountered non-directory\n");
161-
return -ENOTDIR;
147+
ret = -ENOTDIR;
148+
goto out;
162149
}
163150

164-
/* FIXME: It is quite valid for the server to return a referral here */
165-
if (fattr.valid & NFS_ATTR_FATTR_V4_REFERRAL) {
166-
printk(KERN_ERR "nfs4_get_root:"
151+
if (fsinfo.fattr->valid & NFS_ATTR_FATTR_V4_REFERRAL) {
152+
printk(KERN_ERR "nfs4_get_rootfh:"
167153
" getroot obtained referral\n");
168-
return -EREMOTE;
154+
ret = -EREMOTE;
155+
goto out;
169156
}
170157

171-
next_component:
172-
dprintk("Next: %s\n", path);
173-
174-
/* extract the next bit of the path */
175-
if (!*path)
176-
goto path_walk_complete;
177-
178-
name.name = path;
179-
while (*path && *path != '/')
180-
path++;
181-
name.len = path - (const char *) name.name;
182-
183-
if (name.len > NFS4_MAXNAMLEN)
184-
return -ENAMETOOLONG;
185-
186-
eat_dot_dir:
187-
while (*path == '/')
188-
path++;
189-
190-
if (path[0] == '.' && (path[1] == '/' || !path[1])) {
191-
path += 2;
192-
goto eat_dot_dir;
193-
}
194-
195-
/* FIXME: Why shouldn't the user be able to use ".." in the path? */
196-
if (path[0] == '.' && path[1] == '.' && (path[2] == '/' || !path[2])
197-
) {
198-
printk(KERN_ERR "nfs4_get_root:"
199-
" Mount path contains reference to \"..\"\n");
200-
return -EINVAL;
201-
}
202-
203-
/* lookup the next FH in the sequence */
204-
memcpy(&lastfh, mntfh, sizeof(lastfh));
205-
206-
dprintk("LookupFH: %*.*s [%s]\n", name.len, name.len, name.name, path);
207-
208-
ret = server->nfs_client->rpc_ops->lookupfh(server, &lastfh, &name,
209-
mntfh, &fattr);
210-
if (ret < 0) {
211-
dprintk("nfs4_get_root: getroot error = %d\n", -ret);
212-
return ret;
213-
}
214-
215-
if (!S_ISDIR(fattr.mode)) {
216-
printk(KERN_ERR "nfs4_get_root:"
217-
" lookupfh encountered non-directory\n");
218-
return -ENOTDIR;
219-
}
220-
221-
/* FIXME: Referrals are quite valid here too */
222-
if (fattr.valid & NFS_ATTR_FATTR_V4_REFERRAL) {
223-
printk(KERN_ERR "nfs4_get_root:"
224-
" lookupfh obtained referral\n");
225-
return -EREMOTE;
226-
}
227-
228-
goto next_component;
229-
230-
path_walk_complete:
231-
memcpy(&server->fsid, &fattr.fsid, sizeof(server->fsid));
232-
dprintk("<-- nfs4_path_walk() = 0\n");
233-
return 0;
158+
memcpy(&server->fsid, &fsinfo.fattr->fsid, sizeof(server->fsid));
159+
out:
160+
nfs_free_fattr(fsinfo.fattr);
161+
dprintk("<-- nfs4_get_rootfh() = %d\n", ret);
162+
return ret;
234163
}
235164

236165
/*

‎fs/nfs/internal.h‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,9 +244,7 @@ extern struct dentry *nfs_get_root(struct super_block *, struct nfs_fh *);
244244
#ifdef CONFIG_NFS_V4
245245
extern struct dentry *nfs4_get_root(struct super_block *, struct nfs_fh *);
246246

247-
extern int nfs4_path_walk(struct nfs_server *server,
248-
struct nfs_fh *mntfh,
249-
const char *path);
247+
extern int nfs4_get_rootfh(struct nfs_server *server, struct nfs_fh *mntfh);
250248
#endif
251249

252250
/* read.c */

0 commit comments

Comments
 (0)