From d81a1818d67860085fc7e73f0a48d9a2c588c7df Mon Sep 17 00:00:00 2001 From: Christian Schwarz Date: Sat, 7 Sep 2019 20:01:15 +0200 Subject: [PATCH] endpoint: Receiver: only create placeholders below root_fs fixes #195 --- endpoint/endpoint.go | 9 +++++++++ zfs/placeholder.go | 3 +++ 2 files changed, 12 insertions(+) diff --git a/endpoint/endpoint.go b/endpoint/endpoint.go index 389527e..9813f8b 100644 --- a/endpoint/endpoint.go +++ b/endpoint/endpoint.go @@ -380,6 +380,15 @@ func (s *Receiver) Receive(ctx context.Context, req *pdu.ReceiveReq, receive zfs } 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.Debug("create placeholder filesystem") err := zfs.ZFSCreatePlaceholderFilesystem(v.Path) diff --git a/zfs/placeholder.go b/zfs/placeholder.go index 10caa17..1fc95f1 100644 --- a/zfs/placeholder.go +++ b/zfs/placeholder.go @@ -78,6 +78,9 @@ func ZFSGetFilesystemPlaceholderState(p *DatasetPath) (state *FilesystemPlacehol } 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", "-o", fmt.Sprintf("%s=%s", PlaceholderPropertyName, placeholderPropertyOn), "-o", "mountpoint=none",