Skip to content

Commit 69ee7a4

Browse files
committed
nfs: drop support v0 file handles
Motivation: as the initial nfs file handles didn't include schema version, the FileHandle class was adopted to decode unversioned handles. The workaround was introduced to avoid client reboot on server update. That was in 2012... Modification: Drop support for v0 file handle decoding as it not needed anymore. Result: Less dead code. Acked-by: Karen Hoyos Target: master
1 parent e2c2f03 commit 69ee7a4

File tree

2 files changed

+17
-81
lines changed

2 files changed

+17
-81
lines changed

core/src/main/java/org/dcache/nfs/vfs/FileHandle.java

Lines changed: 17 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
/*
2+
* Copyright (c) 2012 - 2025 Deutsches Elektronen-Synchroton,
3+
* Member of the Helmholtz Association, (DESY), HAMBURG, GERMANY
4+
*
25
* This library is free software; you can redistribute it and/or modify
36
* it under the terms of the GNU Library General Public License as
47
* published by the Free Software Foundation; either version 2 of the
@@ -40,8 +43,6 @@ public class FileHandle {
4043
private final static int VERSION = 1;
4144
private final static int MAGIC = 0xCAFFEE;
4245
private final static byte[] EMPTY_FH = new byte[0];
43-
private final static byte[] FH_V0_REG = new byte[] {0x30, 0x3a};
44-
private final static byte[] FH_V0_PFS = new byte[] {0x32, 0x35, 0x35, 0x3a};
4546

4647
private final int version;
4748
private final int magic;
@@ -69,43 +70,22 @@ public FileHandle(byte[] bytes) {
6970

7071
int magic_version = b.getInt();
7172
int geussVersion = (magic_version & 0xFF000000) >>> 24;
72-
if (geussVersion == VERSION) {
73-
version = geussVersion;
74-
magic = magic_version & 0x00FFFFFF;
75-
if (magic != MAGIC) {
76-
throw new IllegalArgumentException("Bad magic number");
77-
}
78-
79-
generation = b.getInt();
80-
exportIdx = b.getInt();
81-
type = (int) b.get();
82-
int olen = (int) b.get();
83-
fs_opaque = new byte[olen];
84-
b.get(fs_opaque);
85-
86-
} else if (arrayEquals(bytes, FH_V0_REG, FH_V0_REG.length)
87-
|| arrayEquals(bytes, FH_V0_PFS, FH_V0_PFS.length)) {
88-
magic = MAGIC;
89-
generation = 0;
90-
type = bytes[1] == FH_V0_REG[1] ? 0 : 1;
91-
if (type == 1) {
92-
/*
93-
* convert pseudo inode into real one: '255:' => '0:' NOTICE: the converted handle will present himself
94-
* as version 1
95-
*/
96-
version = 1;
97-
exportIdx = 0;
98-
fs_opaque = new byte[bytes.length - 2];
99-
System.arraycopy(bytes, 2, fs_opaque, 0, fs_opaque.length);
100-
fs_opaque[0] = 0x30;
101-
} else {
102-
version = 0;
103-
exportIdx = -1;
104-
fs_opaque = bytes;
105-
}
106-
} else {
73+
if (geussVersion != VERSION) {
10774
throw new IllegalArgumentException("Unsupported version: " + geussVersion);
10875
}
76+
77+
version = geussVersion;
78+
magic = magic_version & 0x00FFFFFF;
79+
if (magic != MAGIC) {
80+
throw new IllegalArgumentException("Bad magic number");
81+
}
82+
83+
generation = b.getInt();
84+
exportIdx = b.getInt();
85+
type = (int) b.get();
86+
int olen = (int) b.get();
87+
fs_opaque = new byte[olen];
88+
b.get(fs_opaque);
10989
}
11090

11191
public int getVersion() {
@@ -152,17 +132,6 @@ public String toString() {
152132
return BaseEncoding.base16().lowerCase().encode(this.bytes());
153133
}
154134

155-
private static boolean arrayEquals(byte[] a1, byte[] a2, int len) {
156-
if (a1.length < len || a2.length < len)
157-
return false;
158-
for (int i = 0; i < len; i++) {
159-
if (a1[i] != a2[i]) {
160-
return false;
161-
}
162-
}
163-
return true;
164-
}
165-
166135
public static class FileHandleBuilder {
167136
private int version = VERSION;
168137
private int magic = MAGIC;

core/src/test/java/org/dcache/nfs/vfs/FileHandleTest.java

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -76,37 +76,4 @@ public void testBuilder() {
7676
"01caffee00000000ea15b996002e303a494e4f44453a3030303043333732333331373433393234353645423833453434383434453844323844363a30"),
7777
fh.bytes());
7878
}
79-
80-
@Test
81-
public void testValidHandleV0Regular() {
82-
String oldId = "0:INODE:0000C37233174392456EB83E44844E8D28D6:0";
83-
84-
byte[] bytes = oldId.getBytes(US_ASCII);
85-
FileHandle fh = new FileHandle(bytes);
86-
87-
assertEquals(0, fh.getVersion());
88-
assertEquals(0xCAFFEE, fh.getMagic());
89-
assertEquals(0, fh.getGeneration());
90-
byte[] opaque = fh.getFsOpaque();
91-
assertEquals(-1, fh.getExportIdx());
92-
assertEquals(0, fh.getType());
93-
assertEquals(oldId, new String(opaque, US_ASCII));
94-
}
95-
96-
@Test
97-
public void testValidHandleV0Pseudo() {
98-
String oldIdPseudo = "255:INODE:0000C37233174392456EB83E44844E8D28D6:0";
99-
String oldIdReg = "0:INODE:0000C37233174392456EB83E44844E8D28D6:0";
100-
101-
byte[] bytes = oldIdPseudo.getBytes(US_ASCII);
102-
FileHandle fh = new FileHandle(bytes);
103-
104-
assertEquals(1, fh.getVersion());
105-
assertEquals(0xCAFFEE, fh.getMagic());
106-
assertEquals(0, fh.getGeneration());
107-
byte[] opaque = fh.getFsOpaque();
108-
assertEquals(0, fh.getExportIdx());
109-
assertEquals(1, fh.getType());
110-
assertEquals(oldIdReg, new String(opaque, US_ASCII));
111-
}
11279
}

0 commit comments

Comments
 (0)