Skip to content

Commit dd74e72

Browse files
committed
core: Allow Stat to not contain 64-bit "Ino" inode values
VirtualFileSystems must currently return a 64-bit "Ino" value that is used as the NFS "fileid" (through Stat.setIno, called via getAttr(Inode)). In the NFSv4 spec, that 64-bit "fileid" is a "recommended" (not "required") field. Allow for the absence of this "Ino" value, so file systems that only refer to their entries via NFSv4 file handles don't have invent some non-stable number. Note that this value is indeed required for NFSv3 compatibility, so any file system choosing to not call Stat.setIno will likely fail to run on NFSv3. Related: #149 Signed-off-by: Christian Kohlschütter <[email protected]>
1 parent c87f025 commit dd74e72

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

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.hasIno()) {
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.hasIno()) {
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/Stat.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,15 @@ public void setDev(int dev) {
153153
_dev = dev;
154154
}
155155

156+
/**
157+
* Checks if an inode number has been set (even if 0).
158+
*
159+
* @return {@code true} if set.
160+
*/
161+
public boolean hasIno() {
162+
return isDefined(StatAttribute.INO);
163+
}
164+
156165
/**
157166
* Returns file inode number.
158167
*/

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,9 @@ public void testNotDefinedGetBtime() {
168168
@Test
169169
public void testGetIno() {
170170
Stat stat = new Stat();
171+
assertFalse(stat.hasIno());
171172
stat.setIno(1);
173+
assertTrue(stat.hasIno());
172174
assertEquals(1, stat.getIno());
173175

174176
}

0 commit comments

Comments
 (0)