fix(nfs): move fsid=N inside client parentheses in /etc/exports
exportfs parses 'path host(flags) fsid=N' as a separate fsid= token without host or options, causing 'No options for path fsid=N' errors. The correct format puts fsid=N inside the host parentheses: /path host(flags,fsid=N) Changes: - clientFlags(c, fsid) now appends fsid=N at the end - buildExportFlags(e, fsid) same - buildExportLine removed buildExportSuffix call; fsid is now per-client - Removed now-unused buildExportSuffix function Version: 0.5.3
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
BINARY=nasctl
|
BINARY=nasctl
|
||||||
VERSION?=0.5.2
|
VERSION?=0.5.3
|
||||||
GO?=go
|
GO?=go
|
||||||
LDFLAGS=-s -w -X github.com/darroyo/nasctl/internal/web.Version=$(VERSION) -X github.com/darroyo/nasctl/internal/web.Commit=$(shell git rev-parse --short HEAD 2>/dev/null || echo unknown)
|
LDFLAGS=-s -w -X github.com/darroyo/nasctl/internal/web.Version=$(VERSION) -X github.com/darroyo/nasctl/internal/web.Commit=$(shell git rev-parse --short HEAD 2>/dev/null || echo unknown)
|
||||||
BUILD_FLAGS=CGO_ENABLED=0
|
BUILD_FLAGS=CGO_ENABLED=0
|
||||||
|
|||||||
+10
-12
@@ -82,8 +82,8 @@ func (m *Module) Apply(ctx context.Context, database *db.DB) error {
|
|||||||
return database.ClearDirty(ModuleName)
|
return database.ClearDirty(ModuleName)
|
||||||
}
|
}
|
||||||
|
|
||||||
func buildExportFlags(e db.NFSExport) string {
|
func buildExportFlags(e db.NFSExport, fsid int64) string {
|
||||||
parts := make([]string, 0, 8)
|
parts := make([]string, 0, 9)
|
||||||
if e.ReadOnly {
|
if e.ReadOnly {
|
||||||
parts = append(parts, "ro")
|
parts = append(parts, "ro")
|
||||||
} else {
|
} else {
|
||||||
@@ -132,15 +132,12 @@ func buildExportFlags(e db.NFSExport) string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
parts = append(parts, fmt.Sprintf("fsid=%d", fsid))
|
||||||
return strings.Join(parts, ",")
|
return strings.Join(parts, ",")
|
||||||
}
|
}
|
||||||
|
|
||||||
func buildExportSuffix(e db.NFSExport) string {
|
func clientFlags(c db.NFSClient, fsid int64) string {
|
||||||
return fmt.Sprintf("fsid=%d", e.FSID)
|
parts := make([]string, 0, 9)
|
||||||
}
|
|
||||||
|
|
||||||
func clientFlags(c db.NFSClient) string {
|
|
||||||
parts := make([]string, 0, 8)
|
|
||||||
if c.ReadOnly {
|
if c.ReadOnly {
|
||||||
parts = append(parts, "ro")
|
parts = append(parts, "ro")
|
||||||
} else {
|
} else {
|
||||||
@@ -184,12 +181,13 @@ func clientFlags(c db.NFSClient) string {
|
|||||||
if c.Advanced.Crossmnt {
|
if c.Advanced.Crossmnt {
|
||||||
parts = append(parts, "crossmnt")
|
parts = append(parts, "crossmnt")
|
||||||
}
|
}
|
||||||
|
parts = append(parts, fmt.Sprintf("fsid=%d", fsid))
|
||||||
return strings.Join(parts, ",")
|
return strings.Join(parts, ",")
|
||||||
}
|
}
|
||||||
|
|
||||||
func buildExportLine(e db.NFSExport) string {
|
func buildExportLine(e db.NFSExport) string {
|
||||||
if len(e.Clients) == 0 {
|
if len(e.Clients) == 0 {
|
||||||
return fmt.Sprintf("%s *(%s) %s", e.Path, buildExportFlags(e), buildExportSuffix(e))
|
return fmt.Sprintf("%s *(%s)", e.Path, buildExportFlags(e, e.FSID))
|
||||||
}
|
}
|
||||||
specs := make([]string, 0, len(e.Clients))
|
specs := make([]string, 0, len(e.Clients))
|
||||||
for _, c := range e.Clients {
|
for _, c := range e.Clients {
|
||||||
@@ -197,12 +195,12 @@ func buildExportLine(e db.NFSExport) string {
|
|||||||
if c.Host == "" {
|
if c.Host == "" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
specs = append(specs, fmt.Sprintf("%s(%s)", c.Host, clientFlags(c)))
|
specs = append(specs, fmt.Sprintf("%s(%s)", c.Host, clientFlags(c, e.FSID)))
|
||||||
}
|
}
|
||||||
if len(specs) == 0 {
|
if len(specs) == 0 {
|
||||||
return fmt.Sprintf("%s *(%s) %s", e.Path, buildExportFlags(e), buildExportSuffix(e))
|
return fmt.Sprintf("%s *(%s)", e.Path, buildExportFlags(e, e.FSID))
|
||||||
}
|
}
|
||||||
return fmt.Sprintf("%s %s %s", e.Path, strings.Join(specs, " "), buildExportSuffix(e))
|
return fmt.Sprintf("%s %s", e.Path, strings.Join(specs, " "))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Module) renderConfig(exports []db.NFSExport) ([]byte, error) {
|
func (m *Module) renderConfig(exports []db.NFSExport) ([]byte, error) {
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ func TestBuildExportLine(t *testing.T) {
|
|||||||
FSID: 1,
|
FSID: 1,
|
||||||
Advanced: "{}",
|
Advanced: "{}",
|
||||||
},
|
},
|
||||||
lines: []string{`/srv/nfs/shared 192.168.1.100(rw,sync,root_squash,no_subtree_check,no_all_squash,insecure,no_wdelay,nohide) fsid=1`},
|
lines: []string{`/srv/nfs/shared 192.168.1.100(rw,sync,root_squash,no_subtree_check,no_all_squash,insecure,no_wdelay,nohide,fsid=1)`},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "multiple hosts different options",
|
name: "multiple hosts different options",
|
||||||
@@ -42,7 +42,7 @@ func TestBuildExportLine(t *testing.T) {
|
|||||||
Advanced: "{}",
|
Advanced: "{}",
|
||||||
},
|
},
|
||||||
lines: []string{
|
lines: []string{
|
||||||
`/srv/nfs/shared 192.168.1.0/24(rw,sync,root_squash,no_subtree_check,no_all_squash,insecure,no_wdelay,nohide,crossmnt) 10.0.0.5(ro,async,no_root_squash,no_subtree_check,no_all_squash,insecure,no_wdelay,nohide) fsid=2`,
|
`/srv/nfs/shared 192.168.1.0/24(rw,sync,root_squash,no_subtree_check,no_all_squash,insecure,no_wdelay,nohide,crossmnt,fsid=2) 10.0.0.5(ro,async,no_root_squash,no_subtree_check,no_all_squash,insecure,no_wdelay,nohide,fsid=2)`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -57,7 +57,7 @@ func TestBuildExportLine(t *testing.T) {
|
|||||||
FSID: 3,
|
FSID: 3,
|
||||||
Advanced: "{}",
|
Advanced: "{}",
|
||||||
},
|
},
|
||||||
lines: []string{`/srv/nfs/public *(ro,sync,root_squash,no_subtree_check) fsid=3`},
|
lines: []string{`/srv/nfs/public *(ro,sync,root_squash,no_subtree_check,fsid=3)`},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "advanced options per host",
|
name: "advanced options per host",
|
||||||
@@ -74,7 +74,7 @@ func TestBuildExportLine(t *testing.T) {
|
|||||||
Advanced: "{}",
|
Advanced: "{}",
|
||||||
},
|
},
|
||||||
lines: []string{
|
lines: []string{
|
||||||
`/srv/nfs/secure 192.168.1.0/24(rw,sync,root_squash,no_subtree_check,all_squash,secure,wdelay,hide,crossmnt) fsid=4`,
|
`/srv/nfs/secure 192.168.1.0/24(rw,sync,root_squash,no_subtree_check,all_squash,secure,wdelay,hide,crossmnt,fsid=4)`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -101,8 +101,8 @@ func TestClientFlags(t *testing.T) {
|
|||||||
SubtreeCheck: true,
|
SubtreeCheck: true,
|
||||||
Advanced: db.NFSAdvanced{AllSquash: true, Secure: true},
|
Advanced: db.NFSAdvanced{AllSquash: true, Secure: true},
|
||||||
}
|
}
|
||||||
flags := clientFlags(c)
|
flags := clientFlags(c, 42)
|
||||||
if flags != "ro,async,no_root_squash,subtree_check,all_squash,secure,no_wdelay,nohide" {
|
if flags != "ro,async,no_root_squash,subtree_check,all_squash,secure,no_wdelay,nohide,fsid=42" {
|
||||||
t.Errorf("clientFlags() = %q, unexpected flags", flags)
|
t.Errorf("clientFlags() = %q, unexpected flags", flags)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user