NFS: Fix following referral mount points with different security
[linux-2.6-block.git] / fs / nfs / nfs4proc.c
index 3d92fe6be780fe945b4a2ab6ca31ee1b94649676..75eb883ed4cec0b52e34788848a037ff39c827c5 100644 (file)
@@ -2377,8 +2377,9 @@ static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *fhandle,
  * Note that we'll actually follow the referral later when
  * we detect fsid mismatch in inode revalidation
  */
-static int nfs4_get_referral(struct inode *dir, const struct qstr *name,
-                            struct nfs_fattr *fattr, struct nfs_fh *fhandle)
+static int nfs4_get_referral(struct rpc_clnt *client, struct inode *dir,
+                            const struct qstr *name, struct nfs_fattr *fattr,
+                            struct nfs_fh *fhandle)
 {
        int status = -ENOMEM;
        struct page *page = NULL;
@@ -2391,7 +2392,7 @@ static int nfs4_get_referral(struct inode *dir, const struct qstr *name,
        if (locations == NULL)
                goto out;
 
-       status = nfs4_proc_fs_locations(dir, name, locations, page);
+       status = nfs4_proc_fs_locations(client, dir, name, locations, page);
        if (status != 0)
                goto out;
        /* Make sure server returned a different fsid for the referral */
@@ -2550,7 +2551,7 @@ static int nfs4_proc_lookup_common(struct rpc_clnt **clnt, struct inode *dir,
                        err = -ENOENT;
                        goto out;
                case -NFS4ERR_MOVED:
-                       err = nfs4_get_referral(dir, name, fattr, fhandle);
+                       err = nfs4_get_referral(client, dir, name, fattr, fhandle);
                        goto out;
                case -NFS4ERR_WRONGSEC:
                        err = -EPERM;
@@ -2591,6 +2592,21 @@ static int nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir, struct qst
        return status;
 }
 
+struct rpc_clnt *
+nfs4_proc_lookup_mountpoint(struct inode *dir, struct qstr *name,
+                           struct nfs_fh *fhandle, struct nfs_fattr *fattr)
+{
+       int status;
+       struct rpc_clnt *client = rpc_clone_client(NFS_CLIENT(dir));
+
+       status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr);
+       if (status < 0) {
+               rpc_shutdown_client(client);
+               return ERR_PTR(status);
+       }
+       return client;
+}
+
 static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry)
 {
        struct nfs_server *server = NFS_SERVER(inode);
@@ -4951,8 +4967,10 @@ static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr)
        fattr->nlink = 2;
 }
 
-static int _nfs4_proc_fs_locations(struct inode *dir, const struct qstr *name,
-               struct nfs4_fs_locations *fs_locations, struct page *page)
+static int _nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir,
+                                  const struct qstr *name,
+                                  struct nfs4_fs_locations *fs_locations,
+                                  struct page *page)
 {
        struct nfs_server *server = NFS_SERVER(dir);
        u32 bitmask[2] = {
@@ -4986,19 +5004,21 @@ static int _nfs4_proc_fs_locations(struct inode *dir, const struct qstr *name,
        nfs_fattr_init(&fs_locations->fattr);
        fs_locations->server = server;
        fs_locations->nlocations = 0;
-       status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0);
+       status = nfs4_call_sync(client, server, &msg, &args.seq_args, &res.seq_res, 0);
        dprintk("%s: returned status = %d\n", __func__, status);
        return status;
 }
 
-int nfs4_proc_fs_locations(struct inode *dir, const struct qstr *name,
-               struct nfs4_fs_locations *fs_locations, struct page *page)
+int nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir,
+                          const struct qstr *name,
+                          struct nfs4_fs_locations *fs_locations,
+                          struct page *page)
 {
        struct nfs4_exception exception = { };
        int err;
        do {
                err = nfs4_handle_exception(NFS_SERVER(dir),
-                               _nfs4_proc_fs_locations(dir, name, fs_locations, page),
+                               _nfs4_proc_fs_locations(client, dir, name, fs_locations, page),
                                &exception);
        } while (exception.retry);
        return err;