endpoint: Receiver: only create placeholders below root_fs

fixes #195
This commit is contained in:
Christian Schwarz 2019-09-07 20:01:15 +02:00
parent 921b34235e
commit d81a1818d6
2 changed files with 12 additions and 0 deletions

View File

@ -380,6 +380,15 @@ func (s *Receiver) Receive(ctx context.Context, req *pdu.ReceiveReq, receive zfs
} }
if !ph.FSExists { if !ph.FSExists {
if s.rootWithoutClientComponent.HasPrefix(v.Path) {
if v.Path.Length() == 1 {
visitErr = fmt.Errorf("pool %q not imported", v.Path.ToString())
} else {
visitErr = fmt.Errorf("root_fs %q does not exist", s.rootWithoutClientComponent.ToString())
}
getLogger(ctx).WithError(visitErr).Error("placeholders are only created automatically below root_fs")
return false
}
l := getLogger(ctx).WithField("placeholder_fs", v.Path) l := getLogger(ctx).WithField("placeholder_fs", v.Path)
l.Debug("create placeholder filesystem") l.Debug("create placeholder filesystem")
err := zfs.ZFSCreatePlaceholderFilesystem(v.Path) err := zfs.ZFSCreatePlaceholderFilesystem(v.Path)

View File

@ -78,6 +78,9 @@ func ZFSGetFilesystemPlaceholderState(p *DatasetPath) (state *FilesystemPlacehol
} }
func ZFSCreatePlaceholderFilesystem(p *DatasetPath) (err error) { func ZFSCreatePlaceholderFilesystem(p *DatasetPath) (err error) {
if p.Length() == 1 {
return fmt.Errorf("cannot create %q: pools cannot be created with zfs create", p.ToString())
}
cmd := exec.Command(ZFS_BINARY, "create", cmd := exec.Command(ZFS_BINARY, "create",
"-o", fmt.Sprintf("%s=%s", PlaceholderPropertyName, placeholderPropertyOn), "-o", fmt.Sprintf("%s=%s", PlaceholderPropertyName, placeholderPropertyOn),
"-o", "mountpoint=none", "-o", "mountpoint=none",