resolver.conf bugfix, datasets now should be specified with zpool

This commit is contained in:
yo 2023-06-03 11:18:37 +02:00
parent 7cf4594f34
commit 00fd283987

View File

@ -190,24 +190,26 @@ func prepareJailedZfsDatasets(jail *Jail) error {
} }
for _, d := range strings.Split(jail.Config.Jail_zfs_dataset, " ") { for _, d := range strings.Split(jail.Config.Jail_zfs_dataset, " ") {
// Check if dataset exist, create if necessary // Check if dataset exist, create if necessary
cmd := fmt.Sprintf("zfs get -H creation %s/%s", jail.Zpool, d) // Support jailing datasets on differents pools : dataset should be specified with pool name
cmd := fmt.Sprintf("zfs get -H creation %s", d)
out, err := executeCommand(cmd) out, err := executeCommand(cmd)
if err != nil { if err != nil {
if strings.HasSuffix(out, "dataset does not exist") { if strings.HasSuffix(out, "dataset does not exist") {
cmd = fmt.Sprintf("zfs create -o compression=lz4 -o mountpoint=none %s/%s", jail.Zpool, d) // Support jailing datasets on differents pools : dataset should be specified with pool name
cmd = fmt.Sprintf("zfs create -o compression=lz4 -o mountpoint=none %s", d)
_, err = executeCommand(cmd) _, err = executeCommand(cmd)
if err != nil { if err != nil {
return errors.New(fmt.Sprintf("Error creating dataset %s/%s: %s", jail.Zpool, d, err.Error())) return errors.New(fmt.Sprintf("Error creating dataset %s: %s", d, err.Error()))
} }
} else { } else {
return errors.New(fmt.Sprintf("Error getting zfs dataset %s: %s", d, err.Error())) return errors.New(fmt.Sprintf("Error getting zfs dataset %s: %s", d, err.Error()))
} }
} }
cmd = fmt.Sprintf("zfs set jailed=on %s/%s", jail.Zpool, d) cmd = fmt.Sprintf("zfs set jailed=on %s", d)
out, err = executeCommand(cmd) out, err = executeCommand(cmd)
if err != nil { if err != nil {
return errors.New(fmt.Sprintf("Error executing \"zfs set jailed=on %s/%s\": %s", jail.Zpool, d, err.Error())) return errors.New(fmt.Sprintf("Error executing \"zfs set jailed=on %s\": %s", d, err.Error()))
} }
} }
} }
@ -218,27 +220,27 @@ func jailZfsDatasets(jail *Jail) error {
if jail.Config.Jail_zfs > 0 { if jail.Config.Jail_zfs > 0 {
for _, d := range strings.Split(jail.Config.Jail_zfs_dataset, " ") { for _, d := range strings.Split(jail.Config.Jail_zfs_dataset, " ") {
// Jail dataset // Jail dataset
cmd := fmt.Sprintf("zfs jail %d %s/%s", jail.JID, jail.Zpool, d) // Support jailing datasets on differents pools : dataset should be specified with pool name
cmd := fmt.Sprintf("zfs jail %d %s", jail.JID, d)
out, err := executeCommand(cmd) out, err := executeCommand(cmd)
if err != nil { if err != nil {
return errors.New(fmt.Sprintf("Error jailling zfs dataset %s: %v: out", d, err, out)) return errors.New(fmt.Sprintf("Error jailling zfs dataset %s: %v: out", d, err, out))
} }
// Mount from inside jail if mountpoint is set // Mount from inside jail if mountpoint is set
cmd = fmt.Sprintf("zfs get -H -o value mountpoint %s/%s", jail.Zpool, d) cmd = fmt.Sprintf("zfs get -H -o value mountpoint %s", d)
out, err = executeCommand(cmd) out, err = executeCommand(cmd)
if err != nil { if err != nil {
return errors.New(fmt.Sprintf("Error getting zfs dataset %s/%s mountpoint: %v: %s", jail.Zpool, d, err, out)) return errors.New(fmt.Sprintf("Error getting zfs dataset %s mountpoint: %v: %s", d, err, out))
} }
if len(out) > 0 && out != "-" && (false == strings.EqualFold(out, "none")) { if len(out) > 0 && out != "-" && (false == strings.EqualFold(out, "none")) {
//cmd = fmt.Sprintf("zfs mount %s/%s", jail.Zpool, d) // Should we "mount -a" ? cmd = fmt.Sprintf("zfs mount -a")
cmd = fmt.Sprintf("zfs mount -a") cmd = fmt.Sprintf("zfs mount %s", d)
out, err = executeCommandInJail(jail, cmd) out, err = executeCommandInJail(jail, cmd)
if err != nil { if err != nil {
// If already mounted, continue processing // If already mounted, continue processing
if ! strings.HasSuffix(out, "filesystem already mounted\n") { if ! strings.HasSuffix(out, "filesystem already mounted\n") {
//return errors.New(fmt.Sprintf("Error mounting zfs dataset %s/%s: %v: %s", jail.Zpool, d, err, out)) return errors.New(fmt.Sprintf("Error mounting zfs dataset %s from inside jail: %v: %s", d, err, out))
return errors.New(fmt.Sprintf("Error executing \"zfs mount -a\" from inside jail: %v: %s", err, out))
} }
} }
} }
@ -1011,7 +1013,7 @@ func generateResolvConf(jail *Jail) error {
for _, l := range strings.Split(jail.Config.Resolver, ";") { for _, l := range strings.Split(jail.Config.Resolver, ";") {
f.WriteString(fmt.Sprintf("%s\n", l)) f.WriteString(fmt.Sprintf("%s\n", l))
} }
} else if jail.Config.Resolver == "none" { } else if jail.Config.Resolver == "none" || jail.Config.Resolver == "/etc/resolv.conf" {
read, err := ioutil.ReadFile("/etc/resolv.conf") read, err := ioutil.ReadFile("/etc/resolv.conf")
if err != nil { if err != nil {
return fmt.Errorf("Error opening /etc/resolv.conf: %v", err) return fmt.Errorf("Error opening /etc/resolv.conf: %v", err)