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:
+10
-12
@@ -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) {
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user