Skip to content

Commit 37cf57c

Browse files
authored
Merge pull request #153 from kohlschuetter/ck/Inode
FileHandle vs Inode (real and pseudo) vs Inode's FileId (byte[]) vs. Stat ino: First round of changes
2 parents 8734b9a + e43ba5c commit 37cf57c

File tree

15 files changed

+407
-314
lines changed

15 files changed

+407
-314
lines changed

basic-server/src/main/java/org/dcache/nfs4j/server/LocalFileSystem.java

Lines changed: 103 additions & 80 deletions
Large diffs are not rendered by default.

core/src/main/java/org/dcache/nfs/v4/OperationGETATTR.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@
6666
import org.dcache.nfs.v4.xdr.fattr4_numlinks;
6767
import org.dcache.nfs.v4.xdr.fattr4_owner;
6868
import org.dcache.nfs.v4.xdr.fattr4_rawdev;
69-
import org.dcache.nfs.v4.xdr.fattr4_rdattr_error;
7069
import org.dcache.nfs.v4.xdr.fattr4_size;
7170
import org.dcache.nfs.v4.xdr.fattr4_space_avail;
7271
import org.dcache.nfs.v4.xdr.fattr4_space_free;
@@ -256,7 +255,11 @@ static Optional<? extends XdrAble> fattr2xdr(int fattr, VirtualFileSystem fs, In
256255
case nfs4_prot.FATTR4_CHOWN_RESTRICTED:
257256
return Optional.empty();
258257
case nfs4_prot.FATTR4_FILEID:
259-
return Optional.of(new fattr4_fileid(stat.getIno()));
258+
if (stat.isDefined(StatAttribute.INO)) {
259+
return Optional.of(new fattr4_fileid(stat.getIno()));
260+
} else {
261+
return Optional.empty();
262+
}
260263
case nfs4_prot.FATTR4_FILES_AVAIL:
261264
fsStat = getFsStat(fsStat, fs);
262265
fattr4_files_avail files_avail = new fattr4_files_avail(fsStat.getTotalFiles() - fsStat.getUsedFiles());
@@ -351,6 +354,9 @@ static Optional<? extends XdrAble> fattr2xdr(int fattr, VirtualFileSystem fs, In
351354
* TODO!!!:
352355
*/
353356

357+
if (!stat.isDefined(StatAttribute.INO)) {
358+
return Optional.empty();
359+
}
354360
long mofi = stat.getIno();
355361

356362
if (mofi == 0x00b0a23a /* it's a root */) {

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

Lines changed: 34 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -19,122 +19,20 @@
1919
*/
2020
package org.dcache.nfs.vfs;
2121

22-
import java.nio.ByteBuffer;
23-
import java.nio.ByteOrder;
24-
25-
import com.google.common.io.BaseEncoding;
26-
27-
/**
28-
* NFS file handle on wire representation format v1.
29-
*
30-
* <pre>
31-
* byte fh_version; // file handle format version number; version 1 description
32-
* byte[3] fh_magic // 0xcaffee
33-
* uint32 fh_generation; // server boot time or 0 for permanent handles
34-
* uint32 export_index; // index into export table
35-
* byte fh_type // 1 if pseudo fs
36-
* byte fh_olen; // length of opaque data
37-
* byte[] fh_opaque; // FS specific opaque data <= 114
38-
* </pre>
39-
*/
40-
public class FileHandle {
41-
42-
private final static int MIN_LEN = 14;
43-
private final static int VERSION = 1;
44-
private final static int MAGIC = 0xCAFFEE;
22+
@Deprecated(forRemoval = true)
23+
public class FileHandle extends Inode {
4524
private final static byte[] EMPTY_FH = new byte[0];
4625

47-
private final int version;
48-
private final int magic;
49-
private final int generation;
50-
private final int exportIdx;
51-
private final int type;
52-
private final byte[] fs_opaque;
53-
54-
public FileHandle(int generation, int exportIdx, int type, byte[] fs_opaque) {
55-
this.version = VERSION;
56-
this.magic = MAGIC;
57-
this.generation = generation;
58-
this.exportIdx = exportIdx;
59-
this.type = type;
60-
this.fs_opaque = fs_opaque;
61-
}
62-
6326
public FileHandle(byte[] bytes) {
64-
if (bytes.length < MIN_LEN) {
65-
throw new IllegalArgumentException("too short");
66-
}
67-
68-
ByteBuffer b = ByteBuffer.wrap(bytes);
69-
b.order(ByteOrder.BIG_ENDIAN);
70-
71-
int magic_version = b.getInt();
72-
int geussVersion = (magic_version & 0xFF000000) >>> 24;
73-
if (geussVersion != VERSION) {
74-
throw new IllegalArgumentException("Unsupported version: " + geussVersion);
75-
}
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);
89-
}
90-
91-
public int getVersion() {
92-
return version;
27+
super(bytes);
9328
}
9429

95-
public int getMagic() {
96-
return magic;
97-
}
98-
99-
public int getGeneration() {
100-
return generation;
101-
}
102-
103-
public int getExportIdx() {
104-
return exportIdx;
105-
}
106-
107-
public int getType() {
108-
return type;
109-
}
110-
111-
public byte[] getFsOpaque() {
112-
return fs_opaque;
113-
}
114-
115-
public byte[] bytes() {
116-
int len = fs_opaque.length + MIN_LEN;
117-
byte[] bytes = new byte[len];
118-
ByteBuffer b = ByteBuffer.wrap(bytes);
119-
b.order(ByteOrder.BIG_ENDIAN);
120-
121-
b.putInt(version << 24 | magic);
122-
b.putInt(generation);
123-
b.putInt(exportIdx);
124-
b.put((byte) type);
125-
b.put((byte) fs_opaque.length);
126-
b.put(fs_opaque);
127-
return bytes;
128-
}
129-
130-
@Override
131-
public String toString() {
132-
return BaseEncoding.base16().lowerCase().encode(this.bytes());
30+
public FileHandle(int generation, int exportIdx, int type, byte[] fs_opaque) {
31+
super(generation, exportIdx, type, fs_opaque);
13332
}
13433

34+
@Deprecated(forRemoval = true)
13535
public static class FileHandleBuilder {
136-
private int version = VERSION;
137-
private int magic = MAGIC;
13836
private int generation = 0;
13937
private int export_idx = 0;
14038
private int type = 0;
@@ -160,12 +58,6 @@ public FileHandleBuilder setFsOpaque(byte[] fs_opaque) {
16058
return this;
16159
}
16260

163-
/**
164-
* A shortcut with defaults
165-
*
166-
* @param opaque
167-
* @return
168-
*/
16961
public FileHandle build(byte[] opaque) {
17062
return new FileHandle(generation, export_idx, type, opaque);
17163
}
@@ -174,4 +66,32 @@ public FileHandle build() {
17466
return build(fs_opaque);
17567
}
17668
}
69+
70+
public int getVersion() {
71+
return handleVersion();
72+
}
73+
74+
public int getMagic() {
75+
return super.getMagic();
76+
}
77+
78+
public int getGeneration() {
79+
return super.getGeneration();
80+
}
81+
82+
public int getExportIdx() {
83+
return exportIndex();
84+
}
85+
86+
public int getType() {
87+
return super.getType();
88+
}
89+
90+
public byte[] getFsOpaque() {
91+
return getFileId();
92+
}
93+
94+
public byte[] bytes() {
95+
return toNfsHandle();
96+
}
17797
}

0 commit comments

Comments
 (0)