1 /** 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 package org.apache.hadoop.nfs.nfs3.response; 19 20 import org.apache.hadoop.nfs.nfs3.FileHandle; 21 import org.apache.hadoop.nfs.nfs3.Nfs3Constant; 22 import org.apache.hadoop.nfs.nfs3.Nfs3FileAttributes; 23 import org.apache.hadoop.nfs.nfs3.Nfs3Status; 24 import org.apache.hadoop.nfs.nfs3.Nfs3Constant.WriteStableHow; 25 import org.apache.hadoop.oncrpc.XDR; 26 import org.apache.hadoop.oncrpc.security.Verifier; 27 28 /** 29 * WRITE3 Response 30 */ 31 public class WRITE3Response extends NFS3Response { 32 private final WccData fileWcc; // return on both success and failure 33 private final int count; 34 private final WriteStableHow stableHow; 35 private final long verifer; 36 WRITE3Response(int status)37 public WRITE3Response(int status) { 38 this(status, new WccData(null, null), 0, WriteStableHow.UNSTABLE, 39 Nfs3Constant.WRITE_COMMIT_VERF); 40 } 41 WRITE3Response(int status, WccData fileWcc, int count, WriteStableHow stableHow, long verifier)42 public WRITE3Response(int status, WccData fileWcc, int count, 43 WriteStableHow stableHow, long verifier) { 44 super(status); 45 this.fileWcc = fileWcc; 46 this.count = count; 47 this.stableHow = stableHow; 48 this.verifer = verifier; 49 } 50 getCount()51 public int getCount() { 52 return count; 53 } 54 getStableHow()55 public WriteStableHow getStableHow() { 56 return stableHow; 57 } 58 getVerifer()59 public long getVerifer() { 60 return verifer; 61 } 62 deserialize(XDR xdr)63 public static WRITE3Response deserialize(XDR xdr) { 64 int status = xdr.readInt(); 65 WccData fileWcc = WccData.deserialize(xdr); 66 int count = 0; 67 WriteStableHow stableHow = null; 68 long verifier = 0; 69 70 if (status == Nfs3Status.NFS3_OK) { 71 count = xdr.readInt(); 72 int how = xdr.readInt(); 73 stableHow = WriteStableHow.values()[how]; 74 verifier = xdr.readHyper(); 75 } 76 return new WRITE3Response(status, fileWcc, count, stableHow, verifier); 77 } 78 79 @Override serialize(XDR out, int xid, Verifier verifier)80 public XDR serialize(XDR out, int xid, Verifier verifier) { 81 super.serialize(out, xid, verifier); 82 fileWcc.serialize(out); 83 if (getStatus() == Nfs3Status.NFS3_OK) { 84 out.writeInt(count); 85 out.writeInt(stableHow.getValue()); 86 out.writeLongAsHyper(verifer); 87 } 88 return out; 89 } 90 } 91