]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
nfs4.1: Add state protection handler
authorWeston Andros Adamson <dros@netapp.com>
Tue, 13 Aug 2013 20:37:33 +0000 (16:37 -0400)
committerTrond Myklebust <Trond.Myklebust@netapp.com>
Thu, 5 Sep 2013 14:43:33 +0000 (10:43 -0400)
Add nfs4_state_protect - the function responsible for switching to the machine
credential and the correct rpc client when SP4_MACH_CRED is in use.

Signed-off-by: Weston Andros Adamson <dros@netapp.com>
Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
fs/nfs/nfs4_fs.h

index 277407df6d47dd478684964134372aebc5fb8231..3559e899666e6aeb7947cac6ede4641580c4dca4 100644 (file)
@@ -268,6 +268,35 @@ is_ds_client(struct nfs_client *clp)
 {
        return clp->cl_exchange_flags & EXCHGID4_FLAG_USE_PNFS_DS;
 }
+
+/*
+ * Function responsible for determining if an rpc_message should use the
+ * machine cred under SP4_MACH_CRED and if so switching the credential and
+ * authflavor (using the nfs_client's rpc_clnt which will be krb5i/p).
+ * Should be called before rpc_call_sync/rpc_call_async.
+ */
+static inline void
+nfs4_state_protect(struct nfs_client *clp, unsigned long sp4_mode,
+                  struct rpc_clnt **clntp, struct rpc_message *msg)
+{
+       struct rpc_cred *newcred = NULL;
+       rpc_authflavor_t flavor;
+
+       if (test_bit(sp4_mode, &clp->cl_sp4_flags)) {
+               spin_lock(&clp->cl_lock);
+               if (clp->cl_machine_cred != NULL)
+                       newcred = get_rpccred(clp->cl_machine_cred);
+               spin_unlock(&clp->cl_lock);
+               if (msg->rpc_cred)
+                       put_rpccred(msg->rpc_cred);
+               msg->rpc_cred = newcred;
+
+               flavor = clp->cl_rpcclient->cl_auth->au_flavor;
+               WARN_ON(flavor != RPC_AUTH_GSS_KRB5I &&
+                       flavor != RPC_AUTH_GSS_KRB5P);
+               *clntp = clp->cl_rpcclient;
+       }
+}
 #else /* CONFIG_NFS_v4_1 */
 static inline struct nfs4_session *nfs4_get_session(const struct nfs_server *server)
 {
@@ -285,6 +314,12 @@ is_ds_client(struct nfs_client *clp)
 {
        return false;
 }
+
+static inline void
+nfs4_state_protect(struct nfs_client *clp, unsigned long sp4_flags,
+                  struct rpc_clnt **clntp, struct rpc_message *msg)
+{
+}
 #endif /* CONFIG_NFS_V4_1 */
 
 extern const struct nfs4_minor_version_ops *nfs_v4_minor_ops[];