Commit 1ec8725e authored by Tigran Mkrtchyan's avatar Tigran Mkrtchyan
Browse files

nfs4-client: show layout types supported by the server

Motivation:
Current client uses LAYOUT4_NFSV4_1_FILES layout types independent from
what server is offering.

Modification:
Update client to show server side supported layout types and disable pNFS
if client doesn't supports any of them.

Result:
more debug possibilities

Acked-by: Albert Rossi
Acked-by: Paul Millar
Target: master
parent 521abf66
Pipeline #3335 passed with stage
in 1 minute and 19 seconds
/*
* Copyright (c) 2009 - 2020 Deutsches Elektronen-Synchroton,
* Copyright (c) 2009 - 2021 Deutsches Elektronen-Synchroton,
* Member of the Helmholtz Association, (DESY), HAMBURG, GERMANY
*
* This library is free software; you can redistribute it and/or modify
......@@ -44,7 +44,10 @@ import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import org.dcache.nfs.status.BadLayoutException;
import org.dcache.nfs.v4.xdr.fattr4_fs_layout_types;
import org.jline.reader.EndOfFileException;
import org.jline.reader.LineReader;
import org.jline.reader.LineReaderBuilder;
......@@ -108,6 +111,14 @@ public class Main {
private boolean _isMDS = false;
private boolean _isDS = false;
private static final String PROMPT = "NFSv41: ";
/**
* pNFS layout type that client supports.
*
* TODO: add flex_files layout support
*/
private final layouttype4 clientLayoutType = layouttype4.LAYOUT4_NFSV4_1_FILES;
private final ScheduledExecutorService _executorService = Executors.newScheduledThreadPool(1);
public static void main(String[] args) throws IOException, OncRpcException, InterruptedException {
......@@ -506,6 +517,7 @@ public class Main {
getRootFh(root);
get_supported_attributes();
if (_isMDS) {
getLayoutTypes();
get_devicelist();
}
reclaimComplete();
......@@ -964,7 +976,7 @@ public class Main {
COMPOUND4args args = new CompoundBuilder()
.withPutfh(fh)
.withLayoutget(false,
layouttype4.LAYOUT4_NFSV4_1_FILES,
clientLayoutType,
layoutiomode, 0, 0xffffffff, 0xff, 4096,
stateid)
.withTag("layoutget")
......@@ -1141,6 +1153,40 @@ public class Main {
_knowDevices.put(deviceId, new FileIoDevice(addr));
}
private void getLayoutTypes() throws OncRpcException, IOException {
COMPOUND4args args = new CompoundBuilder()
.withPutfh(_rootFh)
.withGetattr(nfs4_prot.FATTR4_FS_LAYOUT_TYPES)
.withTag("get_supported_layout_types")
.build();
COMPOUND4res compound4res = sendCompoundInSession(args);
AttributeMap attrs = new AttributeMap(compound4res.resarray.get(compound4res.resarray.size() - 1).opgetattr.resok4.obj_attributes);
Optional<fattr4_fs_layout_types> layoutTypes = attrs.get(nfs4_prot.FATTR4_FS_LAYOUT_TYPES);
List<layouttype4> serverLayoutTypes = Arrays.stream(layoutTypes.get().value)
.mapToObj(t -> {
try {
return layouttype4.valueOf(t);
} catch (BadLayoutException e) {
throw new IllegalArgumentException(e);
}
})
.collect(Collectors.toList());
System.out.println("Server supported layout types: " + serverLayoutTypes);
serverLayoutTypes.stream()
.filter(clientLayoutType::equals)
.findAny()
.ifPresentOrElse(t -> System.out.println("Using layout type: " + t),
() -> {
System.out.println("Layout type " + clientLayoutType + " not supported. Disabling pNFS");
_isMDS = false;
});
}
private void get_devicelist() throws OncRpcException, IOException {
COMPOUND4args args = new CompoundBuilder()
......
/*
* Copyright (c) 2009 - 2015 Deutsches Elektronen-Synchroton,
* Copyright (c) 2009 - 2021 Deutsches Elektronen-Synchroton,
* Member of the Helmholtz Association, (DESY), HAMBURG, GERMANY
*
* This library is free software; you can redistribute it and/or modify
......@@ -27,6 +27,7 @@ import org.dcache.nfs.status.InvalException;
import org.dcache.nfs.v4.xdr.bitmap4;
import org.dcache.nfs.v4.xdr.fattr4;
import org.dcache.nfs.v4.xdr.fattr4_acl;
import org.dcache.nfs.v4.xdr.fattr4_fs_layout_types;
import org.dcache.nfs.v4.xdr.fattr4_fs_locations;
import org.dcache.nfs.v4.xdr.fattr4_lease_time;
import org.dcache.nfs.v4.xdr.fattr4_size;
......@@ -158,6 +159,9 @@ public class AttributeMap {
case nfs4_prot.FATTR4_FILEHANDLE:
attr = new nfs_fh4();
break;
case nfs4_prot.FATTR4_FS_LAYOUT_TYPES:
attr = new fattr4_fs_layout_types();
break;
default:
throw new InvalException("invalid attribute: " + OperationGETATTR.attrMask2String(fattr));
}
......
Markdown is supported
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