HDFS-6894. Add XDR parser method for each NFS response. Contributed by Brandon Li.

This commit is contained in:
Haohui Mai 2014-10-01 13:18:56 -07:00
parent 1f5b42ac48
commit 875aa797ca
28 changed files with 413 additions and 61 deletions

View File

@ -43,9 +43,21 @@ public ACCESS3Response(int status, Nfs3FileAttributes postOpAttr, int access) {
this.access = access; this.access = access;
} }
public static ACCESS3Response deserialize(XDR xdr) {
int status = xdr.readInt();
Nfs3FileAttributes postOpAttr = null;
int access = 0;
if (status == Nfs3Status.NFS3_OK) {
postOpAttr = Nfs3FileAttributes.deserialize(xdr);
access = xdr.readInt();
}
return new ACCESS3Response(status, postOpAttr, access);
}
@Override @Override
public XDR writeHeaderAndResponse(XDR out, int xid, Verifier verifier) { public XDR serialize(XDR out, int xid, Verifier verifier) {
super.writeHeaderAndResponse(out, xid, verifier); super.serialize(out, xid, verifier);
if (this.getStatus() == Nfs3Status.NFS3_OK) { if (this.getStatus() == Nfs3Status.NFS3_OK) {
out.writeBoolean(true); out.writeBoolean(true);
postOpAttr.serialize(out); postOpAttr.serialize(out);

View File

@ -47,9 +47,19 @@ public long getVerf() {
return verf; return verf;
} }
public static COMMIT3Response deserialize(XDR xdr) {
int status = xdr.readInt();
long verf = 0;
WccData fileWcc = WccData.deserialize(xdr);
if (status == Nfs3Status.NFS3_OK) {
verf = xdr.readHyper();
}
return new COMMIT3Response(status, fileWcc, verf);
}
@Override @Override
public XDR writeHeaderAndResponse(XDR out, int xid, Verifier verifier) { public XDR serialize(XDR out, int xid, Verifier verifier) {
super.writeHeaderAndResponse(out, xid, verifier); super.serialize(out, xid, verifier);
fileWcc.serialize(out); fileWcc.serialize(out);
if (getStatus() == Nfs3Status.NFS3_OK) { if (getStatus() == Nfs3Status.NFS3_OK) {
out.writeLongAsHyper(verf); out.writeLongAsHyper(verf);

View File

@ -55,9 +55,25 @@ public WccData getDirWcc() {
return dirWcc; return dirWcc;
} }
public static CREATE3Response deserialize(XDR xdr) {
int status = xdr.readInt();
FileHandle objHandle = new FileHandle();
Nfs3FileAttributes postOpObjAttr = null;
if (status == Nfs3Status.NFS3_OK) {
xdr.readBoolean();
objHandle.deserialize(xdr);
xdr.readBoolean();
postOpObjAttr = Nfs3FileAttributes.deserialize(xdr);
}
WccData dirWcc = WccData.deserialize(xdr);
return new CREATE3Response(status, objHandle, postOpObjAttr, dirWcc);
}
@Override @Override
public XDR writeHeaderAndResponse(XDR out, int xid, Verifier verifier) { public XDR serialize(XDR out, int xid, Verifier verifier) {
super.writeHeaderAndResponse(out, xid, verifier); super.serialize(out, xid, verifier);
if (getStatus() == Nfs3Status.NFS3_OK) { if (getStatus() == Nfs3Status.NFS3_OK) {
out.writeBoolean(true); // Handle follows out.writeBoolean(true); // Handle follows
objHandle.serialize(out); objHandle.serialize(out);

View File

@ -18,6 +18,7 @@
package org.apache.hadoop.nfs.nfs3.response; package org.apache.hadoop.nfs.nfs3.response;
import org.apache.hadoop.nfs.NfsTime; import org.apache.hadoop.nfs.NfsTime;
import org.apache.hadoop.nfs.nfs3.FileHandle;
import org.apache.hadoop.nfs.nfs3.Nfs3FileAttributes; import org.apache.hadoop.nfs.nfs3.Nfs3FileAttributes;
import org.apache.hadoop.nfs.nfs3.Nfs3Status; import org.apache.hadoop.nfs.nfs3.Nfs3Status;
import org.apache.hadoop.oncrpc.XDR; import org.apache.hadoop.oncrpc.XDR;
@ -109,9 +110,41 @@ public FSINFO3Response(int status, Nfs3FileAttributes postOpAttr, int rtmax,
this.properties = properties; this.properties = properties;
} }
public static FSINFO3Response deserialize(XDR xdr) {
int status = xdr.readInt();
xdr.readBoolean();
Nfs3FileAttributes postOpObjAttr = Nfs3FileAttributes.deserialize(xdr);
int rtmax = 0;
int rtpref = 0;
int rtmult = 0;
int wtmax = 0;
int wtpref = 0;
int wtmult = 0;
int dtpref = 0;
long maxFileSize = 0;
NfsTime timeDelta = null;
int properties = 0;
if (status == Nfs3Status.NFS3_OK) {
rtmax = xdr.readInt();
rtpref = xdr.readInt();
rtmult = xdr.readInt();
wtmax = xdr.readInt();
wtpref = xdr.readInt();
wtmult = xdr.readInt();
dtpref = xdr.readInt();
maxFileSize = xdr.readHyper();
timeDelta = NfsTime.deserialize(xdr);
properties = xdr.readInt();
}
return new FSINFO3Response(status, postOpObjAttr, rtmax, rtpref, rtmult,
wtmax, wtpref, wtmult, dtpref, maxFileSize, timeDelta, properties);
}
@Override @Override
public XDR writeHeaderAndResponse(XDR out, int xid, Verifier verifier) { public XDR serialize(XDR out, int xid, Verifier verifier) {
super.writeHeaderAndResponse(out, xid, verifier); super.serialize(out, xid, verifier);
out.writeBoolean(true); out.writeBoolean(true);
postOpAttr.serialize(out); postOpAttr.serialize(out);

View File

@ -17,6 +17,7 @@
*/ */
package org.apache.hadoop.nfs.nfs3.response; package org.apache.hadoop.nfs.nfs3.response;
import org.apache.hadoop.nfs.nfs3.FileHandle;
import org.apache.hadoop.nfs.nfs3.Nfs3FileAttributes; import org.apache.hadoop.nfs.nfs3.Nfs3FileAttributes;
import org.apache.hadoop.nfs.nfs3.Nfs3Status; import org.apache.hadoop.nfs.nfs3.Nfs3Status;
import org.apache.hadoop.oncrpc.XDR; import org.apache.hadoop.oncrpc.XDR;
@ -90,9 +91,34 @@ public FSSTAT3Response(int status, Nfs3FileAttributes postOpAttr,
this.invarsec = invarsec; this.invarsec = invarsec;
} }
public static FSSTAT3Response deserialize(XDR xdr) {
int status = xdr.readInt();
xdr.readBoolean();
Nfs3FileAttributes postOpAttr = Nfs3FileAttributes.deserialize(xdr);
long tbytes = 0;
long fbytes = 0;
long abytes = 0;
long tfiles = 0;
long ffiles = 0;
long afiles = 0;
int invarsec = 0;
if (status == Nfs3Status.NFS3_OK) {
tbytes = xdr.readHyper();
fbytes = xdr.readHyper();
abytes = xdr.readHyper();
tfiles = xdr.readHyper();
ffiles = xdr.readHyper();
afiles = xdr.readHyper();
invarsec = xdr.readInt();
}
return new FSSTAT3Response(status, postOpAttr, tbytes, fbytes, abytes,
tfiles, ffiles, afiles, invarsec);
}
@Override @Override
public XDR writeHeaderAndResponse(XDR out, int xid, Verifier verifier) { public XDR serialize(XDR out, int xid, Verifier verifier) {
super.writeHeaderAndResponse(out, xid, verifier); super.serialize(out, xid, verifier);
out.writeBoolean(true); out.writeBoolean(true);
if (postOpAttr == null) { if (postOpAttr == null) {
postOpAttr = new Nfs3FileAttributes(); postOpAttr = new Nfs3FileAttributes();

View File

@ -40,9 +40,16 @@ public void setPostOpAttr(Nfs3FileAttributes postOpAttr) {
this.postOpAttr = postOpAttr; this.postOpAttr = postOpAttr;
} }
public static GETATTR3Response deserialize(XDR xdr) {
int status = xdr.readInt();
Nfs3FileAttributes attr = (status == Nfs3Status.NFS3_OK) ? Nfs3FileAttributes
.deserialize(xdr) : new Nfs3FileAttributes();
return new GETATTR3Response(status, attr);
}
@Override @Override
public XDR writeHeaderAndResponse(XDR out, int xid, Verifier verifier) { public XDR serialize(XDR out, int xid, Verifier verifier) {
super.writeHeaderAndResponse(out, xid, verifier); super.serialize(out, xid, verifier);
if (getStatus() == Nfs3Status.NFS3_OK) { if (getStatus() == Nfs3Status.NFS3_OK) {
postOpAttr.serialize(out); postOpAttr.serialize(out);
} }

View File

@ -17,6 +17,8 @@
*/ */
package org.apache.hadoop.nfs.nfs3.response; package org.apache.hadoop.nfs.nfs3.response;
import org.apache.hadoop.nfs.nfs3.Nfs3FileAttributes;
import org.apache.hadoop.nfs.nfs3.Nfs3Status;
import org.apache.hadoop.oncrpc.XDR; import org.apache.hadoop.oncrpc.XDR;
import org.apache.hadoop.oncrpc.security.Verifier; import org.apache.hadoop.oncrpc.security.Verifier;
@ -43,9 +45,17 @@ public WccData getLinkDirWcc() {
return linkDirWcc; return linkDirWcc;
} }
public static LINK3Response deserialize(XDR xdr) {
int status = xdr.readInt();
WccData fromDirWcc = WccData.deserialize(xdr);
WccData linkDirWcc = WccData.deserialize(xdr);
return new LINK3Response(status, fromDirWcc, linkDirWcc);
}
@Override @Override
public XDR writeHeaderAndResponse(XDR out, int xid, Verifier verifier) { public XDR serialize(XDR out, int xid, Verifier verifier) {
super.writeHeaderAndResponse(out, xid, verifier); super.serialize(out, xid, verifier);
fromDirWcc.serialize(out); fromDirWcc.serialize(out);
linkDirWcc.serialize(out); linkDirWcc.serialize(out);

View File

@ -62,8 +62,8 @@ public LOOKUP3Response(XDR xdr) throws IOException {
} }
@Override @Override
public XDR writeHeaderAndResponse(XDR out, int xid, Verifier verifier) { public XDR serialize(XDR out, int xid, Verifier verifier) {
super.writeHeaderAndResponse(out, xid, verifier); super.serialize(out, xid, verifier);
if (this.status == Nfs3Status.NFS3_OK) { if (this.status == Nfs3Status.NFS3_OK) {
fileHandle.serialize(out); fileHandle.serialize(out);
out.writeBoolean(true); // Attribute follows out.writeBoolean(true); // Attribute follows

View File

@ -55,9 +55,25 @@ public WccData getDirWcc() {
return dirWcc; return dirWcc;
} }
public static MKDIR3Response deserialize(XDR xdr) {
int status = xdr.readInt();
FileHandle objFileHandle = new FileHandle();
Nfs3FileAttributes objAttr = null;
WccData dirWcc;
if (status == Nfs3Status.NFS3_OK) {
xdr.readBoolean();
objFileHandle.deserialize(xdr);
xdr.readBoolean();
objAttr = Nfs3FileAttributes.deserialize(xdr);
}
dirWcc = WccData.deserialize(xdr);
return new MKDIR3Response(status, objFileHandle, objAttr, dirWcc);
}
@Override @Override
public XDR writeHeaderAndResponse(XDR out, int xid, Verifier verifier) { public XDR serialize(XDR out, int xid, Verifier verifier) {
super.writeHeaderAndResponse(out, xid, verifier); super.serialize(out, xid, verifier);
if (getStatus() == Nfs3Status.NFS3_OK) { if (getStatus() == Nfs3Status.NFS3_OK) {
out.writeBoolean(true); // Handle follows out.writeBoolean(true); // Handle follows
objFileHandle.serialize(out); objFileHandle.serialize(out);

View File

@ -52,9 +52,25 @@ public WccData getDirWcc() {
return dirWcc; return dirWcc;
} }
public static MKNOD3Response deserialize(XDR xdr) {
int status = xdr.readInt();
FileHandle objFileHandle = new FileHandle();
Nfs3FileAttributes objPostOpAttr = null;
WccData dirWcc;
if (status == Nfs3Status.NFS3_OK) {
xdr.readBoolean();
objFileHandle.deserialize(xdr);
xdr.readBoolean();
objPostOpAttr = Nfs3FileAttributes.deserialize(xdr);
}
dirWcc = WccData.deserialize(xdr);
return new MKNOD3Response(status, objFileHandle, objPostOpAttr, dirWcc);
}
@Override @Override
public XDR writeHeaderAndResponse(XDR out, int xid, Verifier verifier) { public XDR serialize(XDR out, int xid, Verifier verifier) {
super.writeHeaderAndResponse(out, xid, verifier); super.serialize(out, xid, verifier);
if (this.getStatus() == Nfs3Status.NFS3_OK) { if (this.getStatus() == Nfs3Status.NFS3_OK) {
out.writeBoolean(true); out.writeBoolean(true);
objFileHandle.serialize(out); objFileHandle.serialize(out);

View File

@ -44,7 +44,7 @@ public void setStatus(int status) {
* Write the response, along with the rpc header (including verifier), to the * Write the response, along with the rpc header (including verifier), to the
* XDR. * XDR.
*/ */
public XDR writeHeaderAndResponse(XDR out, int xid, Verifier verifier) { public XDR serialize(XDR out, int xid, Verifier verifier) {
RpcAcceptedReply reply = RpcAcceptedReply.getAcceptInstance(xid, verifier); RpcAcceptedReply reply = RpcAcceptedReply.getAcceptInstance(xid, verifier);
reply.write(out); reply.write(out);
out.writeInt(this.getStatus()); out.writeInt(this.getStatus());

View File

@ -77,9 +77,32 @@ public PATHCONF3Response(int status, Nfs3FileAttributes postOpAttr,
this.casePreserving = casePreserving; this.casePreserving = casePreserving;
} }
public static PATHCONF3Response deserialize(XDR xdr) {
int status = xdr.readInt();
xdr.readBoolean();
Nfs3FileAttributes objPostOpAttr = Nfs3FileAttributes.deserialize(xdr);
int linkMax = 0;
int nameMax = 0;
boolean noTrunc = false;
boolean chownRestricted = false;
boolean caseInsensitive = false;
boolean casePreserving = false;
if (status == Nfs3Status.NFS3_OK) {
linkMax = xdr.readInt();
nameMax = xdr.readInt();
noTrunc = xdr.readBoolean();
chownRestricted = xdr.readBoolean();
caseInsensitive = xdr.readBoolean();
casePreserving = xdr.readBoolean();
}
return new PATHCONF3Response(status, objPostOpAttr, linkMax, nameMax,
noTrunc, chownRestricted, caseInsensitive, casePreserving);
}
@Override @Override
public XDR writeHeaderAndResponse(XDR out, int xid, Verifier verifier) { public XDR serialize(XDR out, int xid, Verifier verifier) {
super.writeHeaderAndResponse(out, xid, verifier); super.serialize(out, xid, verifier);
out.writeBoolean(true); out.writeBoolean(true);
postOpAttr.serialize(out); postOpAttr.serialize(out);

View File

@ -62,9 +62,29 @@ public ByteBuffer getData() {
return data; return data;
} }
public static READ3Response deserialize(XDR xdr) {
int status = xdr.readInt();
xdr.readBoolean();
Nfs3FileAttributes postOpAttr = Nfs3FileAttributes.deserialize(xdr);
int count = 0;
boolean eof = false;
byte[] data = new byte[0];
if (status == Nfs3Status.NFS3_OK) {
count = xdr.readInt();
eof = xdr.readBoolean();
int len = xdr.readInt();
assert (len == count);
data = xdr.readFixedOpaque(count);
}
return new READ3Response(status, postOpAttr, count, eof,
ByteBuffer.wrap(data));
}
@Override @Override
public XDR writeHeaderAndResponse(XDR out, int xid, Verifier verifier) { public XDR serialize(XDR out, int xid, Verifier verifier) {
super.writeHeaderAndResponse(out, xid, verifier); super.serialize(out, xid, verifier);
out.writeBoolean(true); // Attribute follows out.writeBoolean(true); // Attribute follows
postOpAttr.serialize(out); postOpAttr.serialize(out);

View File

@ -17,6 +17,8 @@
*/ */
package org.apache.hadoop.nfs.nfs3.response; package org.apache.hadoop.nfs.nfs3.response;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
@ -59,6 +61,19 @@ public String getName() {
long getCookie() { long getCookie() {
return cookie; return cookie;
} }
static Entry3 deserialzie(XDR xdr) {
long fileId = xdr.readHyper();
String name = xdr.readString();
long cookie = xdr.readHyper();
return new Entry3(fileId, name, cookie);
}
void seralize(XDR xdr) {
xdr.writeLongAsHyper(getFileId());
xdr.writeString(getName());
xdr.writeLongAsHyper(getCookie());
}
} }
public static class DirList3 { public static class DirList3 {
@ -104,9 +119,31 @@ public DirList3 getDirList() {
return dirList; return dirList;
} }
public static READDIR3Response deserialize(XDR xdr) {
int status = xdr.readInt();
xdr.readBoolean();
Nfs3FileAttributes postOpDirAttr = Nfs3FileAttributes.deserialize(xdr);
long cookieVerf = 0;
ArrayList<Entry3> entries = new ArrayList<Entry3>();
DirList3 dirList = null;
if (status == Nfs3Status.NFS3_OK) {
cookieVerf = xdr.readHyper();
while (xdr.readBoolean()) {
Entry3 e = Entry3.deserialzie(xdr);
entries.add(e);
}
boolean eof = xdr.readBoolean();
Entry3[] allEntries = new Entry3[entries.size()];
entries.toArray(allEntries);
dirList = new DirList3(allEntries, eof);
}
return new READDIR3Response(status, postOpDirAttr, cookieVerf, dirList);
}
@Override @Override
public XDR writeHeaderAndResponse(XDR xdr, int xid, Verifier verifier) { public XDR serialize(XDR xdr, int xid, Verifier verifier) {
super.writeHeaderAndResponse(xdr, xid, verifier); super.serialize(xdr, xid, verifier);
xdr.writeBoolean(true); // Attributes follow xdr.writeBoolean(true); // Attributes follow
postOpDirAttr.serialize(xdr); postOpDirAttr.serialize(xdr);
@ -114,9 +151,7 @@ public XDR writeHeaderAndResponse(XDR xdr, int xid, Verifier verifier) {
xdr.writeLongAsHyper(cookieVerf); xdr.writeLongAsHyper(cookieVerf);
for (Entry3 e : dirList.entries) { for (Entry3 e : dirList.entries) {
xdr.writeBoolean(true); // Value follows xdr.writeBoolean(true); // Value follows
xdr.writeLongAsHyper(e.getFileId()); e.seralize(xdr);
xdr.writeString(e.getName());
xdr.writeLongAsHyper(e.getCookie());
} }
xdr.writeBoolean(false); xdr.writeBoolean(false);

View File

@ -17,6 +17,7 @@
*/ */
package org.apache.hadoop.nfs.nfs3.response; package org.apache.hadoop.nfs.nfs3.response;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
@ -24,6 +25,8 @@
import org.apache.hadoop.nfs.nfs3.FileHandle; import org.apache.hadoop.nfs.nfs3.FileHandle;
import org.apache.hadoop.nfs.nfs3.Nfs3FileAttributes; import org.apache.hadoop.nfs.nfs3.Nfs3FileAttributes;
import org.apache.hadoop.nfs.nfs3.Nfs3Status; import org.apache.hadoop.nfs.nfs3.Nfs3Status;
import org.apache.hadoop.nfs.nfs3.response.READDIR3Response.DirList3;
import org.apache.hadoop.nfs.nfs3.response.READDIR3Response.Entry3;
import org.apache.hadoop.oncrpc.XDR; import org.apache.hadoop.oncrpc.XDR;
import org.apache.hadoop.oncrpc.security.Verifier; import org.apache.hadoop.oncrpc.security.Verifier;
@ -58,6 +61,17 @@ public String getName() {
return name; return name;
} }
static EntryPlus3 deseralize(XDR xdr) {
long fileId = xdr.readHyper();
String name = xdr.readString();
long cookie = xdr.readHyper();
xdr.readBoolean();
Nfs3FileAttributes nameAttr = Nfs3FileAttributes.deserialize(xdr);
FileHandle objFileHandle = new FileHandle();
objFileHandle.deserialize(xdr);
return new EntryPlus3(fileId, name, cookie, nameAttr, objFileHandle);
}
void seralize(XDR xdr) { void seralize(XDR xdr) {
xdr.writeLongAsHyper(fileId); xdr.writeLongAsHyper(fileId);
xdr.writeString(name); xdr.writeString(name);
@ -105,9 +119,31 @@ public READDIRPLUS3Response(int status, Nfs3FileAttributes postOpDirAttr,
this.dirListPlus = dirListPlus; this.dirListPlus = dirListPlus;
} }
public static READDIRPLUS3Response deserialize(XDR xdr) {
int status = xdr.readInt();
xdr.readBoolean();
Nfs3FileAttributes postOpDirAttr = Nfs3FileAttributes.deserialize(xdr);
long cookieVerf = 0;
ArrayList<EntryPlus3> entries = new ArrayList<EntryPlus3>();
DirListPlus3 dirList = null;
if (status == Nfs3Status.NFS3_OK) {
cookieVerf = xdr.readHyper();
while (xdr.readBoolean()) {
EntryPlus3 e = EntryPlus3.deseralize(xdr);
entries.add(e);
}
boolean eof = xdr.readBoolean();
EntryPlus3[] allEntries = new EntryPlus3[entries.size()];
entries.toArray(allEntries);
dirList = new DirListPlus3(allEntries, eof);
}
return new READDIRPLUS3Response(status, postOpDirAttr, cookieVerf, dirList);
}
@Override @Override
public XDR writeHeaderAndResponse(XDR out, int xid, Verifier verifier) { public XDR serialize(XDR out, int xid, Verifier verifier) {
super.writeHeaderAndResponse(out, xid, verifier); super.serialize(out, xid, verifier);
out.writeBoolean(true); // attributes follow out.writeBoolean(true); // attributes follow
if (postOpDirAttr == null) { if (postOpDirAttr == null) {
postOpDirAttr = new Nfs3FileAttributes(); postOpDirAttr = new Nfs3FileAttributes();

View File

@ -41,9 +41,22 @@ public READLINK3Response(int status, Nfs3FileAttributes postOpAttr,
System.arraycopy(path, 0, this.path, 0, path.length); System.arraycopy(path, 0, this.path, 0, path.length);
} }
public static READLINK3Response deserialize(XDR xdr) {
int status = xdr.readInt();
xdr.readBoolean();
Nfs3FileAttributes postOpSymlinkAttr = Nfs3FileAttributes.deserialize(xdr);
byte path[] = new byte[0];
if (status == Nfs3Status.NFS3_OK) {
path = xdr.readVariableOpaque();
}
return new READLINK3Response(status, postOpSymlinkAttr, path);
}
@Override @Override
public XDR writeHeaderAndResponse(XDR out, int xid, Verifier verifier) { public XDR serialize(XDR out, int xid, Verifier verifier) {
super.writeHeaderAndResponse(out, xid, verifier); super.serialize(out, xid, verifier);
out.writeBoolean(true); // Attribute follows out.writeBoolean(true); // Attribute follows
postOpSymlinkAttr.serialize(out); postOpSymlinkAttr.serialize(out);
if (getStatus() == Nfs3Status.NFS3_OK) { if (getStatus() == Nfs3Status.NFS3_OK) {

View File

@ -17,6 +17,8 @@
*/ */
package org.apache.hadoop.nfs.nfs3.response; package org.apache.hadoop.nfs.nfs3.response;
import org.apache.hadoop.nfs.nfs3.Nfs3FileAttributes;
import org.apache.hadoop.nfs.nfs3.Nfs3Status;
import org.apache.hadoop.oncrpc.XDR; import org.apache.hadoop.oncrpc.XDR;
import org.apache.hadoop.oncrpc.security.Verifier; import org.apache.hadoop.oncrpc.security.Verifier;
@ -35,9 +37,15 @@ public REMOVE3Response(int status, WccData dirWcc) {
this.dirWcc = dirWcc; this.dirWcc = dirWcc;
} }
public static REMOVE3Response deserialize(XDR xdr) {
int status = xdr.readInt();
WccData dirWcc = WccData.deserialize(xdr);
return new REMOVE3Response(status, dirWcc);
}
@Override @Override
public XDR writeHeaderAndResponse(XDR out, int xid, Verifier verifier) { public XDR serialize(XDR out, int xid, Verifier verifier) {
super.writeHeaderAndResponse(out, xid, verifier); super.serialize(out, xid, verifier);
if (dirWcc == null) { if (dirWcc == null) {
dirWcc = new WccData(null, null); dirWcc = new WccData(null, null);
} }

View File

@ -45,9 +45,16 @@ public WccData getToDirWcc() {
return toDirWcc; return toDirWcc;
} }
public static RENAME3Response deserialize(XDR xdr) {
int status = xdr.readInt();
WccData fromDirWcc = WccData.deserialize(xdr);
WccData toDirWcc = WccData.deserialize(xdr);
return new RENAME3Response(status, fromDirWcc, toDirWcc);
}
@Override @Override
public XDR writeHeaderAndResponse(XDR out, int xid, Verifier verifier) { public XDR serialize(XDR out, int xid, Verifier verifier) {
super.writeHeaderAndResponse(out, xid, verifier); super.serialize(out, xid, verifier);
fromDirWcc.serialize(out); fromDirWcc.serialize(out);
toDirWcc.serialize(out); toDirWcc.serialize(out);
return out; return out;

View File

@ -39,9 +39,15 @@ public WccData getDirWcc() {
return dirWcc; return dirWcc;
} }
public static RMDIR3Response deserialize(XDR xdr) {
int status = xdr.readInt();
WccData dirWcc = WccData.deserialize(xdr);
return new RMDIR3Response(status, dirWcc);
}
@Override @Override
public XDR writeHeaderAndResponse(XDR out, int xid, Verifier verifier) { public XDR serialize(XDR out, int xid, Verifier verifier) {
super.writeHeaderAndResponse(out, xid, verifier); super.serialize(out, xid, verifier);
dirWcc.serialize(out); dirWcc.serialize(out);
return out; return out;
} }

View File

@ -39,9 +39,15 @@ public WccData getWccData() {
return wccData; return wccData;
} }
public static SETATTR3Response deserialize(XDR xdr) {
int status = xdr.readInt();
WccData wccData = WccData.deserialize(xdr);
return new SETATTR3Response(status, wccData);
}
@Override @Override
public XDR writeHeaderAndResponse(XDR out, int xid, Verifier verifier) { public XDR serialize(XDR out, int xid, Verifier verifier) {
super.writeHeaderAndResponse(out, xid, verifier); super.serialize(out, xid, verifier);
wccData.serialize(out); wccData.serialize(out);
return out; return out;
} }

View File

@ -55,9 +55,25 @@ public WccData getDirWcc() {
return dirWcc; return dirWcc;
} }
public static SYMLINK3Response deserialize(XDR xdr) {
int status = xdr.readInt();
FileHandle objFileHandle = new FileHandle();
Nfs3FileAttributes objPostOpAttr = null;
WccData dirWcc;
if (status == Nfs3Status.NFS3_OK) {
xdr.readBoolean();
objFileHandle.deserialize(xdr);
xdr.readBoolean();
objPostOpAttr = Nfs3FileAttributes.deserialize(xdr);
}
dirWcc = WccData.deserialize(xdr);
return new SYMLINK3Response(status, objFileHandle, objPostOpAttr, dirWcc);
}
@Override @Override
public XDR writeHeaderAndResponse(XDR out, int xid, Verifier verifier) { public XDR serialize(XDR out, int xid, Verifier verifier) {
super.writeHeaderAndResponse(out, xid, verifier); super.serialize(out, xid, verifier);
if (this.getStatus() == Nfs3Status.NFS3_OK) { if (this.getStatus() == Nfs3Status.NFS3_OK) {
out.writeBoolean(true); out.writeBoolean(true);
objFileHandle.serialize(out); objFileHandle.serialize(out);

View File

@ -17,7 +17,9 @@
*/ */
package org.apache.hadoop.nfs.nfs3.response; package org.apache.hadoop.nfs.nfs3.response;
import org.apache.hadoop.nfs.nfs3.FileHandle;
import org.apache.hadoop.nfs.nfs3.Nfs3Constant; import org.apache.hadoop.nfs.nfs3.Nfs3Constant;
import org.apache.hadoop.nfs.nfs3.Nfs3FileAttributes;
import org.apache.hadoop.nfs.nfs3.Nfs3Status; import org.apache.hadoop.nfs.nfs3.Nfs3Status;
import org.apache.hadoop.nfs.nfs3.Nfs3Constant.WriteStableHow; import org.apache.hadoop.nfs.nfs3.Nfs3Constant.WriteStableHow;
import org.apache.hadoop.oncrpc.XDR; import org.apache.hadoop.oncrpc.XDR;
@ -58,9 +60,25 @@ public long getVerifer() {
return verifer; return verifer;
} }
public static WRITE3Response deserialize(XDR xdr) {
int status = xdr.readInt();
WccData fileWcc = WccData.deserialize(xdr);
int count = 0;
WriteStableHow stableHow = null;
long verifier = 0;
if (status == Nfs3Status.NFS3_OK) {
count = xdr.readInt();
int how = xdr.readInt();
stableHow = WriteStableHow.values()[how];
verifier = xdr.readHyper();
}
return new WRITE3Response(status, fileWcc, count, stableHow, verifier);
}
@Override @Override
public XDR writeHeaderAndResponse(XDR out, int xid, Verifier verifier) { public XDR serialize(XDR out, int xid, Verifier verifier) {
super.writeHeaderAndResponse(out, xid, verifier); super.serialize(out, xid, verifier);
fileWcc.serialize(out); fileWcc.serialize(out);
if (getStatus() == Nfs3Status.NFS3_OK) { if (getStatus() == Nfs3Status.NFS3_OK) {
out.writeInt(count); out.writeInt(count);

View File

@ -52,6 +52,13 @@ public WccAttr(long size, NfsTime mtime, NfsTime ctime) {
this.ctime = ctime; this.ctime = ctime;
} }
public static WccAttr deserialize(XDR xdr) {
long size = xdr.readHyper();
NfsTime mtime = NfsTime.deserialize(xdr);
NfsTime ctime = NfsTime.deserialize(xdr);
return new WccAttr(size, mtime, ctime);
}
public void serialize(XDR out) { public void serialize(XDR out) {
out.writeLongAsHyper(size); out.writeLongAsHyper(size);
if (mtime == null) { if (mtime == null) {

View File

@ -49,6 +49,14 @@ public WccData(WccAttr preOpAttr, Nfs3FileAttributes postOpAttr) {
: postOpAttr; : postOpAttr;
} }
public static WccData deserialize(XDR xdr) {
xdr.readBoolean();
WccAttr preOpAttr = WccAttr.deserialize(xdr);
xdr.readBoolean();
Nfs3FileAttributes postOpAttr = Nfs3FileAttributes.deserialize(xdr);
return new WccData(preOpAttr, postOpAttr);
}
public void serialize(XDR out) { public void serialize(XDR out) {
out.writeBoolean(true); // attributes follow out.writeBoolean(true); // attributes follow
preOpAttr.serialize(out); preOpAttr.serialize(out);

View File

@ -407,7 +407,7 @@ public void receivedNewWrite(DFSClient dfsClient, WRITE3Request request,
WRITE3Response response = new WRITE3Response(Nfs3Status.NFS3ERR_IO, WRITE3Response response = new WRITE3Response(Nfs3Status.NFS3ERR_IO,
fileWcc, 0, request.getStableHow(), Nfs3Constant.WRITE_COMMIT_VERF); fileWcc, 0, request.getStableHow(), Nfs3Constant.WRITE_COMMIT_VERF);
Nfs3Utils.writeChannel(channel, Nfs3Utils.writeChannel(channel,
response.writeHeaderAndResponse(new XDR(), xid, new VerifierNone()), response.serialize(new XDR(), xid, new VerifierNone()),
xid); xid);
} else { } else {
// Update the write time first // Update the write time first
@ -433,7 +433,7 @@ public void receivedNewWrite(DFSClient dfsClient, WRITE3Request request,
WRITE3Response response = new WRITE3Response(Nfs3Status.NFS3_OK, WRITE3Response response = new WRITE3Response(Nfs3Status.NFS3_OK,
fileWcc, request.getCount(), request.getStableHow(), fileWcc, request.getCount(), request.getStableHow(),
Nfs3Constant.WRITE_COMMIT_VERF); Nfs3Constant.WRITE_COMMIT_VERF);
Nfs3Utils.writeChannel(channel, response.writeHeaderAndResponse( Nfs3Utils.writeChannel(channel, response.serialize(
new XDR(), xid, new VerifierNone()), xid); new XDR(), xid, new VerifierNone()), xid);
} }
} else { } else {
@ -570,7 +570,7 @@ private void processOverWrite(DFSClient dfsClient, WRITE3Request request,
} }
updateLastAccessTime(); updateLastAccessTime();
Nfs3Utils.writeChannel(channel, Nfs3Utils.writeChannel(channel,
response.writeHeaderAndResponse(new XDR(), xid, new VerifierNone()), response.serialize(new XDR(), xid, new VerifierNone()),
xid); xid);
} }
@ -642,7 +642,7 @@ private void receivedNewWriteInternal(DFSClient dfsClient,
WRITE3Response response = new WRITE3Response(Nfs3Status.NFS3_OK, WRITE3Response response = new WRITE3Response(Nfs3Status.NFS3_OK,
fileWcc, count, stableHow, Nfs3Constant.WRITE_COMMIT_VERF); fileWcc, count, stableHow, Nfs3Constant.WRITE_COMMIT_VERF);
Nfs3Utils Nfs3Utils
.writeChannel(channel, response.writeHeaderAndResponse(new XDR(), .writeChannel(channel, response.serialize(new XDR(),
xid, new VerifierNone()), xid); xid, new VerifierNone()), xid);
writeCtx.setReplied(true); writeCtx.setReplied(true);
} }
@ -1016,7 +1016,7 @@ private void processCommits(long offset) {
COMMIT3Response response = new COMMIT3Response(status, wccData, COMMIT3Response response = new COMMIT3Response(status, wccData,
Nfs3Constant.WRITE_COMMIT_VERF); Nfs3Constant.WRITE_COMMIT_VERF);
Nfs3Utils.writeChannelCommit(commit.getChannel(), response Nfs3Utils.writeChannelCommit(commit.getChannel(), response
.writeHeaderAndResponse(new XDR(), commit.getXid(), .serialize(new XDR(), commit.getXid(),
new VerifierNone()), commit.getXid()); new VerifierNone()), commit.getXid());
if (LOG.isDebugEnabled()) { if (LOG.isDebugEnabled()) {
@ -1097,7 +1097,7 @@ private void doSingleWrite(final WriteCtx writeCtx) {
} }
WRITE3Response response = new WRITE3Response(Nfs3Status.NFS3_OK, WRITE3Response response = new WRITE3Response(Nfs3Status.NFS3_OK,
fileWcc, count, stableHow, Nfs3Constant.WRITE_COMMIT_VERF); fileWcc, count, stableHow, Nfs3Constant.WRITE_COMMIT_VERF);
Nfs3Utils.writeChannel(channel, response.writeHeaderAndResponse( Nfs3Utils.writeChannel(channel, response.serialize(
new XDR(), xid, new VerifierNone()), xid); new XDR(), xid, new VerifierNone()), xid);
} }
@ -1109,7 +1109,7 @@ private void doSingleWrite(final WriteCtx writeCtx) {
+ offset + " and length " + count, e); + offset + " and length " + count, e);
if (!writeCtx.getReplied()) { if (!writeCtx.getReplied()) {
WRITE3Response response = new WRITE3Response(Nfs3Status.NFS3ERR_IO); WRITE3Response response = new WRITE3Response(Nfs3Status.NFS3ERR_IO);
Nfs3Utils.writeChannel(channel, response.writeHeaderAndResponse( Nfs3Utils.writeChannel(channel, response.serialize(
new XDR(), xid, new VerifierNone()), xid); new XDR(), xid, new VerifierNone()), xid);
// Keep stream open. Either client retries or SteamMonitor closes it. // Keep stream open. Either client retries or SteamMonitor closes it.
} }
@ -1160,7 +1160,7 @@ synchronized void cleanup() {
WRITE3Response response = new WRITE3Response(Nfs3Status.NFS3ERR_IO, WRITE3Response response = new WRITE3Response(Nfs3Status.NFS3ERR_IO,
fileWcc, 0, writeCtx.getStableHow(), Nfs3Constant.WRITE_COMMIT_VERF); fileWcc, 0, writeCtx.getStableHow(), Nfs3Constant.WRITE_COMMIT_VERF);
Nfs3Utils.writeChannel(writeCtx.getChannel(), response Nfs3Utils.writeChannel(writeCtx.getChannel(), response
.writeHeaderAndResponse(new XDR(), writeCtx.getXid(), .serialize(new XDR(), writeCtx.getXid(),
new VerifierNone()), writeCtx.getXid()); new VerifierNone()), writeCtx.getXid());
} }
} }

View File

@ -2163,7 +2163,7 @@ RpcAcceptedReply.AcceptState.PROC_UNAVAIL, new VerifierNone()).write(
return; return;
} }
// TODO: currently we just return VerifierNone // TODO: currently we just return VerifierNone
out = response.writeHeaderAndResponse(out, xid, new VerifierNone()); out = response.serialize(out, xid, new VerifierNone());
ChannelBuffer buf = ChannelBuffers.wrappedBuffer(out.asReadOnlyWrap() ChannelBuffer buf = ChannelBuffers.wrappedBuffer(out.asReadOnlyWrap()
.buffer()); .buffer());
RpcResponse rsp = new RpcResponse(buf, info.remoteAddress()); RpcResponse rsp = new RpcResponse(buf, info.remoteAddress());

View File

@ -123,7 +123,7 @@ void handleWrite(DFSClient dfsClient, WRITE3Request request, Channel channel,
byte[] data = request.getData().array(); byte[] data = request.getData().array();
if (data.length < count) { if (data.length < count) {
WRITE3Response response = new WRITE3Response(Nfs3Status.NFS3ERR_INVAL); WRITE3Response response = new WRITE3Response(Nfs3Status.NFS3ERR_INVAL);
Nfs3Utils.writeChannel(channel, response.writeHeaderAndResponse( Nfs3Utils.writeChannel(channel, response.serialize(
new XDR(), xid, new VerifierNone()), xid); new XDR(), xid, new VerifierNone()), xid);
return; return;
} }
@ -169,7 +169,7 @@ void handleWrite(DFSClient dfsClient, WRITE3Request request, Channel channel,
WRITE3Response response = new WRITE3Response(Nfs3Status.NFS3ERR_IO, WRITE3Response response = new WRITE3Response(Nfs3Status.NFS3ERR_IO,
fileWcc, count, request.getStableHow(), fileWcc, count, request.getStableHow(),
Nfs3Constant.WRITE_COMMIT_VERF); Nfs3Constant.WRITE_COMMIT_VERF);
Nfs3Utils.writeChannel(channel, response.writeHeaderAndResponse( Nfs3Utils.writeChannel(channel, response.serialize(
new XDR(), xid, new VerifierNone()), xid); new XDR(), xid, new VerifierNone()), xid);
return; return;
} }
@ -192,7 +192,7 @@ void handleWrite(DFSClient dfsClient, WRITE3Request request, Channel channel,
WRITE3Response response = new WRITE3Response(Nfs3Status.NFS3ERR_JUKEBOX, WRITE3Response response = new WRITE3Response(Nfs3Status.NFS3ERR_JUKEBOX,
fileWcc, 0, request.getStableHow(), Nfs3Constant.WRITE_COMMIT_VERF); fileWcc, 0, request.getStableHow(), Nfs3Constant.WRITE_COMMIT_VERF);
Nfs3Utils.writeChannel(channel, Nfs3Utils.writeChannel(channel,
response.writeHeaderAndResponse(new XDR(), xid, new VerifierNone()), response.serialize(new XDR(), xid, new VerifierNone()),
xid); xid);
return; return;
} }
@ -297,7 +297,7 @@ void handleCommit(DFSClient dfsClient, FileHandle fileHandle,
COMMIT3Response response = new COMMIT3Response(status, fileWcc, COMMIT3Response response = new COMMIT3Response(status, fileWcc,
Nfs3Constant.WRITE_COMMIT_VERF); Nfs3Constant.WRITE_COMMIT_VERF);
Nfs3Utils.writeChannelCommit(channel, Nfs3Utils.writeChannelCommit(channel,
response.writeHeaderAndResponse(new XDR(), xid, new VerifierNone()), response.serialize(new XDR(), xid, new VerifierNone()),
xid); xid);
} }

View File

@ -642,6 +642,9 @@ Release 2.6.0 - UNRELEASED
HDFS-7158. Reduce the memory usage of WebImageViewer. (wheat9) HDFS-7158. Reduce the memory usage of WebImageViewer. (wheat9)
HDFS-6894. Add XDR parser method for each NFS response.
(Brandon Li via wheat9)
OPTIMIZATIONS OPTIMIZATIONS
HDFS-6690. Deduplicate xattr names in memory. (wang) HDFS-6690. Deduplicate xattr names in memory. (wang)