]> git.karo-electronics.de Git - karo-tx-linux.git/blobdiff - fs/nfs/callback_xdr.c
Merge branch 'for_rmk' of git://github.com/at91linux/linux-2.6-at91 into devel-stable
[karo-tx-linux.git] / fs / nfs / callback_xdr.c
index dbd0d649805ce4fe2f6cdc8de9665a945deb3ebe..23112c263f81902cb4e8ba1b09c0a31ce3bf7596 100644 (file)
@@ -24,6 +24,7 @@
 #define CB_OP_RECALL_RES_MAXSZ (CB_OP_HDR_RES_MAXSZ)
 
 #if defined(CONFIG_NFS_V4_1)
+#define CB_OP_LAYOUTRECALL_RES_MAXSZ   (CB_OP_HDR_RES_MAXSZ)
 #define CB_OP_SEQUENCE_RES_MAXSZ       (CB_OP_HDR_RES_MAXSZ + \
                                        4 + 1 + 3)
 #define CB_OP_RECALLANY_RES_MAXSZ      (CB_OP_HDR_RES_MAXSZ)
@@ -223,6 +224,66 @@ out:
 
 #if defined(CONFIG_NFS_V4_1)
 
+static __be32 decode_layoutrecall_args(struct svc_rqst *rqstp,
+                                      struct xdr_stream *xdr,
+                                      struct cb_layoutrecallargs *args)
+{
+       __be32 *p;
+       __be32 status = 0;
+       uint32_t iomode;
+
+       args->cbl_addr = svc_addr(rqstp);
+       p = read_buf(xdr, 4 * sizeof(uint32_t));
+       if (unlikely(p == NULL)) {
+               status = htonl(NFS4ERR_BADXDR);
+               goto out;
+       }
+
+       args->cbl_layout_type = ntohl(*p++);
+       /* Depite the spec's xdr, iomode really belongs in the FILE switch,
+        * as it is unuseable and ignored with the other types.
+        */
+       iomode = ntohl(*p++);
+       args->cbl_layoutchanged = ntohl(*p++);
+       args->cbl_recall_type = ntohl(*p++);
+
+       if (args->cbl_recall_type == RETURN_FILE) {
+               args->cbl_range.iomode = iomode;
+               status = decode_fh(xdr, &args->cbl_fh);
+               if (unlikely(status != 0))
+                       goto out;
+
+               p = read_buf(xdr, 2 * sizeof(uint64_t));
+               if (unlikely(p == NULL)) {
+                       status = htonl(NFS4ERR_BADXDR);
+                       goto out;
+               }
+               p = xdr_decode_hyper(p, &args->cbl_range.offset);
+               p = xdr_decode_hyper(p, &args->cbl_range.length);
+               status = decode_stateid(xdr, &args->cbl_stateid);
+               if (unlikely(status != 0))
+                       goto out;
+       } else if (args->cbl_recall_type == RETURN_FSID) {
+               p = read_buf(xdr, 2 * sizeof(uint64_t));
+               if (unlikely(p == NULL)) {
+                       status = htonl(NFS4ERR_BADXDR);
+                       goto out;
+               }
+               p = xdr_decode_hyper(p, &args->cbl_fsid.major);
+               p = xdr_decode_hyper(p, &args->cbl_fsid.minor);
+       } else if (args->cbl_recall_type != RETURN_ALL) {
+               status = htonl(NFS4ERR_BADXDR);
+               goto out;
+       }
+       dprintk("%s: ltype 0x%x iomode %d changed %d recall_type %d\n",
+               __func__,
+               args->cbl_layout_type, iomode,
+               args->cbl_layoutchanged, args->cbl_recall_type);
+out:
+       dprintk("%s: exit with status = %d\n", __func__, ntohl(status));
+       return status;
+}
+
 static __be32 decode_sessionid(struct xdr_stream *xdr,
                                 struct nfs4_sessionid *sid)
 {
@@ -577,10 +638,10 @@ preprocess_nfs41_op(int nop, unsigned int op_nr, struct callback_op **op)
        case OP_CB_SEQUENCE:
        case OP_CB_RECALL_ANY:
        case OP_CB_RECALL_SLOT:
+       case OP_CB_LAYOUTRECALL:
                *op = &callback_ops[op_nr];
                break;
 
-       case OP_CB_LAYOUTRECALL:
        case OP_CB_NOTIFY_DEVICEID:
        case OP_CB_NOTIFY:
        case OP_CB_PUSH_DELEG:
@@ -596,6 +657,37 @@ preprocess_nfs41_op(int nop, unsigned int op_nr, struct callback_op **op)
        return htonl(NFS_OK);
 }
 
+static void nfs4_callback_free_slot(struct nfs4_session *session)
+{
+       struct nfs4_slot_table *tbl = &session->bc_slot_table;
+
+       spin_lock(&tbl->slot_tbl_lock);
+       /*
+        * Let the state manager know callback processing done.
+        * A single slot, so highest used slotid is either 0 or -1
+        */
+       tbl->highest_used_slotid--;
+       nfs4_check_drain_bc_complete(session);
+       spin_unlock(&tbl->slot_tbl_lock);
+}
+
+static void nfs4_cb_free_slot(struct nfs_client *clp)
+{
+       if (clp && clp->cl_session)
+               nfs4_callback_free_slot(clp->cl_session);
+}
+
+/* A single slot, so highest used slotid is either 0 or -1 */
+void nfs4_cb_take_slot(struct nfs_client *clp)
+{
+       struct nfs4_slot_table *tbl = &clp->cl_session->bc_slot_table;
+
+       spin_lock(&tbl->slot_tbl_lock);
+       tbl->highest_used_slotid++;
+       BUG_ON(tbl->highest_used_slotid != 0);
+       spin_unlock(&tbl->slot_tbl_lock);
+}
+
 #else /* CONFIG_NFS_V4_1 */
 
 static __be32
@@ -604,6 +696,9 @@ preprocess_nfs41_op(int nop, unsigned int op_nr, struct callback_op **op)
        return htonl(NFS4ERR_MINOR_VERS_MISMATCH);
 }
 
+static void nfs4_cb_free_slot(struct nfs_client *clp)
+{
+}
 #endif /* CONFIG_NFS_V4_1 */
 
 static __be32
@@ -724,6 +819,7 @@ static __be32 nfs4_callback_compound(struct svc_rqst *rqstp, void *argp, void *r
 
        *hdr_res.status = status;
        *hdr_res.nops = htonl(nops);
+       nfs4_cb_free_slot(cps.clp);
        nfs_put_client(cps.clp);
        dprintk("%s: done, status = %u\n", __func__, ntohl(status));
        return rpc_success;
@@ -748,6 +844,12 @@ static struct callback_op callback_ops[] = {
                .res_maxsize = CB_OP_RECALL_RES_MAXSZ,
        },
 #if defined(CONFIG_NFS_V4_1)
+       [OP_CB_LAYOUTRECALL] = {
+               .process_op = (callback_process_op_t)nfs4_callback_layoutrecall,
+               .decode_args =
+                       (callback_decode_arg_t)decode_layoutrecall_args,
+               .res_maxsize = CB_OP_LAYOUTRECALL_RES_MAXSZ,
+       },
        [OP_CB_SEQUENCE] = {
                .process_op = (callback_process_op_t)nfs4_callback_sequence,
                .decode_args = (callback_decode_arg_t)decode_cb_sequence_args,