Skip to content

Commit

Permalink
nfs4-client: show layout types supported by the server
Browse files Browse the repository at this point in the history
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
  • Loading branch information
kofemann committed Feb 22, 2021
1 parent 521abf6 commit 1ec8725
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 3 deletions.
50 changes: 48 additions & 2 deletions basic-client/src/main/java/org/dcache/nfs/v4/client/Main.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* 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
Expand Down Expand Up @@ -44,7 +44,10 @@
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;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -506,6 +517,7 @@ public void mount(String root) throws OncRpcException, IOException {
getRootFh(root);
get_supported_attributes();
if (_isMDS) {
getLayoutTypes();
get_devicelist();
}
reclaimComplete();
Expand Down Expand Up @@ -964,7 +976,7 @@ private StripeMap layoutget(nfs_fh4 fh, stateid4 stateid, int layoutiomode) thro
COMPOUND4args args = new CompoundBuilder()
.withPutfh(fh)
.withLayoutget(false,
layouttype4.LAYOUT4_NFSV4_1_FILES,
clientLayoutType,
layoutiomode, 0, 0xffffffff, 0xff, 4096,
stateid)
.withTag("layoutget")
Expand Down Expand Up @@ -1141,6 +1153,40 @@ private void get_deviceinfo(deviceid4 deviceId) throws OncRpcException,
_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()
Expand Down
6 changes: 5 additions & 1 deletion core/src/main/java/org/dcache/nfs/v4/AttributeMap.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* 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
Expand Down Expand Up @@ -27,6 +27,7 @@
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;
Expand Down Expand Up @@ -158,6 +159,9 @@ private static void xdr2fattr(Map<Integer,XdrAble> attrs, int fattr, XdrDecoding
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));
}
Expand Down

0 comments on commit 1ec8725

Please sign in to comment.