nfs: Add DEALLOCATE support
[linux-2.6-block.git] / fs / nfs / nfs42xdr.c
index 4248d034479c992cfa8920dabcf09833dec9d1c1..038a7e1521fa8f0d157aaebdd6d39a78ff9a7eab 100644 (file)
@@ -10,6 +10,9 @@
 #define encode_allocate_maxsz          (op_encode_hdr_maxsz + \
                                         encode_fallocate_maxsz)
 #define decode_allocate_maxsz          (op_decode_hdr_maxsz)
+#define encode_deallocate_maxsz                (op_encode_hdr_maxsz + \
+                                        encode_fallocate_maxsz)
+#define decode_deallocate_maxsz                (op_decode_hdr_maxsz)
 #define encode_seek_maxsz              (op_encode_hdr_maxsz + \
                                         encode_stateid_maxsz + \
                                         2 /* offset */ + \
 #define NFS4_dec_allocate_sz           (compound_decode_hdr_maxsz + \
                                         decode_putfh_maxsz + \
                                         decode_allocate_maxsz)
+#define NFS4_enc_deallocate_sz         (compound_encode_hdr_maxsz + \
+                                        encode_putfh_maxsz + \
+                                        encode_deallocate_maxsz)
+#define NFS4_dec_deallocate_sz         (compound_decode_hdr_maxsz + \
+                                        decode_putfh_maxsz + \
+                                        decode_deallocate_maxsz)
 #define NFS4_enc_seek_sz               (compound_encode_hdr_maxsz + \
                                         encode_putfh_maxsz + \
                                         encode_seek_maxsz)
@@ -50,6 +59,14 @@ static void encode_allocate(struct xdr_stream *xdr,
        encode_fallocate(xdr, args);
 }
 
+static void encode_deallocate(struct xdr_stream *xdr,
+                             struct nfs42_falloc_args *args,
+                             struct compound_hdr *hdr)
+{
+       encode_op_hdr(xdr, OP_DEALLOCATE, decode_deallocate_maxsz, hdr);
+       encode_fallocate(xdr, args);
+}
+
 static void encode_seek(struct xdr_stream *xdr,
                        struct nfs42_seek_args *args,
                        struct compound_hdr *hdr)
@@ -78,6 +95,24 @@ static void nfs4_xdr_enc_allocate(struct rpc_rqst *req,
        encode_nops(&hdr);
 }
 
+/*
+ * Encode DEALLOCATE request
+ */
+static void nfs4_xdr_enc_deallocate(struct rpc_rqst *req,
+                                   struct xdr_stream *xdr,
+                                   struct nfs42_falloc_args *args)
+{
+       struct compound_hdr hdr = {
+               .minorversion = nfs4_xdr_minorversion(&args->seq_args),
+       };
+
+       encode_compound_hdr(xdr, req, &hdr);
+       encode_sequence(xdr, &args->seq_args, &hdr);
+       encode_putfh(xdr, args->falloc_fh, &hdr);
+       encode_deallocate(xdr, args, &hdr);
+       encode_nops(&hdr);
+}
+
 /*
  * Encode SEEK request
  */
@@ -101,6 +136,11 @@ static int decode_allocate(struct xdr_stream *xdr, struct nfs42_falloc_res *res)
        return decode_op_hdr(xdr, OP_ALLOCATE);
 }
 
+static int decode_deallocate(struct xdr_stream *xdr, struct nfs42_falloc_res *res)
+{
+       return decode_op_hdr(xdr, OP_DEALLOCATE);
+}
+
 static int decode_seek(struct xdr_stream *xdr, struct nfs42_seek_res *res)
 {
        int status;
@@ -147,6 +187,30 @@ out:
        return status;
 }
 
+/*
+ * Decode DEALLOCATE request
+ */
+static int nfs4_xdr_dec_deallocate(struct rpc_rqst *rqstp,
+                                  struct xdr_stream *xdr,
+                                  struct nfs42_falloc_res *res)
+{
+       struct compound_hdr hdr;
+       int status;
+
+       status = decode_compound_hdr(xdr, &hdr);
+       if (status)
+               goto out;
+       status = decode_sequence(xdr, &res->seq_res, rqstp);
+       if (status)
+               goto out;
+       status = decode_putfh(xdr);
+       if (status)
+               goto out;
+       status = decode_deallocate(xdr, res);
+out:
+       return status;
+}
+
 /*
  * Decode SEEK request
  */