Commit 9d9a9300 authored by Tigran Mkrtchyan's avatar Tigran Mkrtchyan
Browse files

nfs-client: send layoutcommit if required

Acked-by: Paul Millar
Target: master
parent 1a383866
/*
* Copyright (c) 2009 - 2018 Deutsches Elektronen-Synchroton,
* Copyright (c) 2009 - 2019 Deutsches Elektronen-Synchroton,
* Member of the Helmholtz Association, (DESY), HAMBURG, GERMANY
*
* This library is free software; you can redistribute it and/or modify
......@@ -92,8 +92,13 @@ import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import java.util.OptionalLong;
import org.dcache.nfs.v4.xdr.LAYOUTCOMMIT4args;
import org.dcache.nfs.v4.xdr.LOCKU4args;
import org.dcache.nfs.v4.xdr.RECLAIM_COMPLETE4args;
import org.dcache.nfs.v4.xdr.layoutupdate4;
import org.dcache.nfs.v4.xdr.newoffset4;
import org.dcache.nfs.v4.xdr.newtime4;
import org.dcache.oncrpc4j.util.Bytes;
import org.dcache.oncrpc4j.xdr.Xdr;
......@@ -591,6 +596,33 @@ public class CompoundBuilder {
return this;
}
public CompoundBuilder withLayoutcommit(long offset, long length,
boolean reclaim, stateid4 stateid, OptionalLong lastWriteOffset,
layouttype4 layoutType, byte[] body) {
nfs_argop4 op = new nfs_argop4();
op.argop = nfs_opnum4.OP_LAYOUTCOMMIT;
op.oplayoutcommit = new LAYOUTCOMMIT4args();
op.oplayoutcommit.loca_time_modify = new newtime4();
op.oplayoutcommit.loca_time_modify.nt_timechanged = false;
op.oplayoutcommit.loca_offset = new offset4(offset);
op.oplayoutcommit.loca_length = new length4(length);
op.oplayoutcommit.loca_reclaim = reclaim;
op.oplayoutcommit.loca_stateid = stateid;
op.oplayoutcommit.loca_last_write_offset = new newoffset4();
op.oplayoutcommit.loca_last_write_offset.no_newoffset = lastWriteOffset.isPresent();
if (lastWriteOffset.isPresent()) {
op.oplayoutcommit.loca_last_write_offset.no_offset = new offset4(lastWriteOffset.getAsLong());
}
op.oplayoutcommit.loca_layoutupdate = new layoutupdate4();
op.oplayoutcommit.loca_layoutupdate.lou_type = layoutType.getValue();
op.oplayoutcommit.loca_layoutupdate.lou_body = body;
ops.add(op);
return this;
}
public COMPOUND4args build() {
final COMPOUND4args compound4args = new COMPOUND4args();
compound4args.tag = new utf8str_cs(tag);
......
/*
* Copyright (c) 2009 - 2018 Deutsches Elektronen-Synchroton,
* Copyright (c) 2009 - 2019 Deutsches Elektronen-Synchroton,
* Member of the Helmholtz Association, (DESY), HAMBURG, GERMANY
*
* This library is free software; you can redistribute it and/or modify
......@@ -37,6 +37,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.OptionalLong;
import java.util.UUID;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
......@@ -864,8 +865,15 @@ public class Main {
dsClient.nfsWrite(stripe.getFh(), data, offset, or.stateid());
offset += n;
// offset points to current file size
if (stripe.isCommitThroughMDS()) {
layoutCommit(stripe.getFh(), or.stateid(), 0, offset,
OptionalLong.of(offset - 1), new byte[0]);
}
}
} catch (IOException ie) {
System.out.println("Write failed: " + ie.getMessage());
} finally {
......@@ -1005,6 +1013,19 @@ public class Main {
COMPOUND4res compound4res = sendCompound(args);
}
private void layoutCommit(nfs_fh4 fh, stateid4 stateid, long offset, long len,
OptionalLong newOffset, byte[] body) throws OncRpcException, IOException {
COMPOUND4args args = new CompoundBuilder()
.withSequence(false, _sessionid, _sequenceID.value, _slotId, 0)
.withPutfh(fh)
.withLayoutcommit(offset, len, false, stateid, newOffset, layouttype4.LAYOUT4_NFSV4_1_FILES, body)
.withTag("layoutcommit")
.build();
COMPOUND4res compound4res = sendCompound(args);
}
private COMPOUND4res sendCompound(COMPOUND4args compound4args)
throws OncRpcException, IOException {
......
......@@ -112,6 +112,10 @@ public class Stripe {
return _fh;
}
public boolean isCommitThroughMDS() {
return (_unit & nfs4_prot.NFL4_UFLG_COMMIT_THRU_MDS) != 0;
}
/* (non-Javadoc)
* @see java.lang.Object#hashCode()
*/
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment