diff --git a/Makefile b/Makefile index e986d5f..ef89bb3 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ BINARY=nasctl -VERSION?=0.5.2 +VERSION?=0.5.3 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) BUILD_FLAGS=CGO_ENABLED=0 diff --git a/internal/modules/nfs/nfs.go b/internal/modules/nfs/nfs.go index f725d44..bf1b6e3 100644 --- a/internal/modules/nfs/nfs.go +++ b/internal/modules/nfs/nfs.go @@ -82,8 +82,8 @@ func (m *Module) Apply(ctx context.Context, database *db.DB) error { return database.ClearDirty(ModuleName) } -func buildExportFlags(e db.NFSExport) string { - parts := make([]string, 0, 8) +func buildExportFlags(e db.NFSExport, fsid int64) string { + parts := make([]string, 0, 9) if e.ReadOnly { parts = append(parts, "ro") } else { @@ -132,15 +132,12 @@ func buildExportFlags(e db.NFSExport) string { } } } + parts = append(parts, fmt.Sprintf("fsid=%d", fsid)) return strings.Join(parts, ",") } -func buildExportSuffix(e db.NFSExport) string { - return fmt.Sprintf("fsid=%d", e.FSID) -} - -func clientFlags(c db.NFSClient) string { - parts := make([]string, 0, 8) +func clientFlags(c db.NFSClient, fsid int64) string { + parts := make([]string, 0, 9) if c.ReadOnly { parts = append(parts, "ro") } else { @@ -184,12 +181,13 @@ func clientFlags(c db.NFSClient) string { if c.Advanced.Crossmnt { parts = append(parts, "crossmnt") } + parts = append(parts, fmt.Sprintf("fsid=%d", fsid)) return strings.Join(parts, ",") } func buildExportLine(e db.NFSExport) string { 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)) for _, c := range e.Clients { @@ -197,12 +195,12 @@ func buildExportLine(e db.NFSExport) string { if c.Host == "" { 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 { - 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) { diff --git a/internal/modules/nfs/nfs_test.go b/internal/modules/nfs/nfs_test.go index c64b30f..a3a3649 100644 --- a/internal/modules/nfs/nfs_test.go +++ b/internal/modules/nfs/nfs_test.go @@ -24,7 +24,7 @@ func TestBuildExportLine(t *testing.T) { FSID: 1, 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", @@ -42,7 +42,7 @@ func TestBuildExportLine(t *testing.T) { Advanced: "{}", }, 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, 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", @@ -74,7 +74,7 @@ func TestBuildExportLine(t *testing.T) { Advanced: "{}", }, 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, Advanced: db.NFSAdvanced{AllSquash: true, Secure: true}, } - flags := clientFlags(c) - if flags != "ro,async,no_root_squash,subtree_check,all_squash,secure,no_wdelay,nohide" { + flags := clientFlags(c, 42) + if flags != "ro,async,no_root_squash,subtree_check,all_squash,secure,no_wdelay,nohide,fsid=42" { t.Errorf("clientFlags() = %q, unexpected flags", flags) } }