Skip to content

Commit

Permalink
Allow Sender.ListFilesystems returns real placeholders faster
Browse files Browse the repository at this point in the history
If filter contains one entry with recursive dataset

```yaml
datasets:
  - pattern: "foo/bar"
    recursive: true
```

we can reuse Receiver.ListFilesystems, which uses `zfs get` for getting list of
filsystems + needed properties.

So this commit restores original logic, but faster. See commit 9b91e31 for
reference.
  • Loading branch information
dsh2dsh committed Nov 23, 2024
1 parent 3c32817 commit 184b850
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 5 deletions.
7 changes: 7 additions & 0 deletions internal/daemon/filters/entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,10 @@ func (self *filterItem) CompatCompare(b *filterItem) int {
}
return cmp.Compare(self.path.Length(), b.path.Length())
}

func (self *filterItem) RecursiveDataset() *zfs.DatasetPath {
if !self.recursive || !self.mapping {
return nil
}
return self.path
}
7 changes: 7 additions & 0 deletions internal/daemon/filters/fsmapfilter.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,10 @@ func (self *DatasetFilter) UserSpecifiedDatasets() zfs.UserSpecifiedDatasetsSet
func (self *DatasetFilter) AsFilter() endpoint.FSFilter { return self }

func (self *DatasetFilter) Empty() bool { return len(self.entries) == 0 }

func (self *DatasetFilter) SingleRecursiveDataset() *zfs.DatasetPath {
if len(self.entries) != 1 {
return nil
}
return self.entries[0].RecursiveDataset()
}
20 changes: 16 additions & 4 deletions internal/endpoint/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ func (s *Sender) filterCheckFS(fs string) (*zfs.DatasetPath, error) {
func (s *Sender) ListFilesystems(ctx context.Context) (*pdu.ListFilesystemRes,
error,
) {
if root := s.FSFilter.SingleRecursiveDataset(); root != nil {
return listFilesystemsRecursive(ctx, root, zfs.PlaceholderPropertyName)
}

fss, err := zfs.ZFSListMapping(ctx, s.FSFilter)
if err != nil {
return nil, err
Expand Down Expand Up @@ -710,17 +714,25 @@ func (f subroot) MapToLocal(fs string) (*zfs.DatasetPath, error) {
return c, nil
}

func (f subroot) SingleRecursiveDataset() *zfs.DatasetPath {
return f.localRoot
}

const receiveResumeToken = "receive_resume_token"

func (s *Receiver) ListFilesystems(ctx context.Context) (*pdu.ListFilesystemRes,
error,
) {
root := s.clientRootFromCtx(ctx)
return listFilesystemsRecursive(ctx, s.clientRootFromCtx(ctx),
zfs.PlaceholderPropertyName, receiveResumeToken)
}

func listFilesystemsRecursive(ctx context.Context, root *zfs.DatasetPath,
props ...string,
) (*pdu.ListFilesystemRes, error) {
rootStr := root.ToString()
fsProps, err := zfs.ZFSGetRecursive(ctx, rootStr, -1,
[]string{"filesystem"},
[]string{zfs.PlaceholderPropertyName, receiveResumeToken},
zfs.SourceAny)
[]string{"filesystem"}, props, zfs.SourceAny)
if err != nil {
var errNotExist *zfs.DatasetDoesNotExist
if errors.As(err, &errNotExist) {
Expand Down
5 changes: 4 additions & 1 deletion internal/zfs/mapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ type DatasetFilter interface {
// The caller owns the returned set.
// Implementations should return a copy.
UserSpecifiedDatasets() UserSpecifiedDatasetsSet
SingleRecursiveDataset() *DatasetPath
}

// A set of dataset names that the user specified in the configuration file.
type UserSpecifiedDatasetsSet map[string]bool

// Returns a DatasetFilter that does not filter (passes all paths)
func NoFilter() DatasetFilter {
func NoFilter() noFilter {
return noFilter{}
}

Expand All @@ -36,6 +37,8 @@ func (noFilter) UserSpecifiedDatasets() UserSpecifiedDatasetsSet { return nil }

func (noFilter) Empty() bool { return true }

func (noFilter) SingleRecursiveDataset() *DatasetPath { return nil }

func ZFSListMapping(ctx context.Context, filter DatasetFilter,
) ([]*DatasetPath, error) {
res, err := ZFSListMappingProperties(ctx, filter, nil)
Expand Down

0 comments on commit 184b850

Please sign in to comment.