From c9b825c58a9f996379108926754513bca03bb306 Mon Sep 17 00:00:00 2001 From: Jakob Unterwurzacher Date: Fri, 10 Sep 2021 17:17:16 +0200 Subject: inomap: deterministically set root device We used to have "first Translate() wins". This is not deterministic, as the LOOKUP for the root directory does not seem to reach us, so the first user LOOKUP would win, which may be on a mountpoint. --- internal/inomap/inomap.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'internal/inomap/inomap.go') diff --git a/internal/inomap/inomap.go b/internal/inomap/inomap.go index 97f9b61..997ea9b 100644 --- a/internal/inomap/inomap.go +++ b/internal/inomap/inomap.go @@ -49,13 +49,22 @@ type InoMap struct { } // New returns a new InoMap. -func New() *InoMap { - return &InoMap{ +// Inode numbers on device `rootDev` will be passed through as-is. +// If `rootDev` is zero, the first Translate() call decides the effective +// rootDev. +func New(rootDev uint64) *InoMap { + m := &InoMap{ namespaceMap: make(map[namespaceData]uint16), namespaceNext: 0, spillMap: make(map[QIno]uint64), spillNext: 0, } + if rootDev > 0 { + // Reserve namespace 0 for rootDev + m.namespaceMap[namespaceData{rootDev, 0}] = 0 + m.namespaceNext = 1 + } + return m } var spillWarn sync.Once -- cgit v1.2.3