Skip to content

Commit

Permalink
Get list of suitable datasets faster
Browse files Browse the repository at this point in the history
Use "zfs get -r", instead of "zfs list -r" + "zfs get zrepl:placeholder" for
every dataset from the list. It's faster.
  • Loading branch information
dsh2dsh committed Sep 28, 2024
1 parent 7492df6 commit 59288e4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
24 changes: 14 additions & 10 deletions client/monitor/snapshots.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,22 +155,26 @@ func (self *SnapCheck) datasetsFromRootFs(
return nil, err
}

filtered := []string{}
for item := range zfs.ZFSListIter(ctx, []string{"name"}, nil, "-r", rootFs) {
if item.Err != nil {
return nil, item.Err
}
path, err := zfs.NewDatasetPath(item.Fields[0])
propsByFS, err := zfs.ZFSGetRecursive(ctx,
rootFs, -1, []string{"filesystem"},
[]string{zfs.PlaceholderPropertyName}, zfs.SourceAny)
if err != nil {
return nil, fmt.Errorf("properties of %q: %w", rootFs, err)
}

filtered := make([]string, 0, len(propsByFS))
for fs, props := range propsByFS {
path, err := zfs.NewDatasetPath(fs)
if err != nil {
return nil, err
} else if path.Length() < rootPath.Length()+1+skipN {
continue
}
if ph, err := zfs.ZFSGetFilesystemPlaceholderState(ctx, path); err != nil {
return nil, err
} else if ph.FSExists && !ph.IsPlaceholder {
filtered = append(filtered, item.Fields[0])
p := props.GetDetails(zfs.PlaceholderPropertyName)
if p.Source == zfs.SourceLocal && p.Value == "on" {
continue
}
filtered = append(filtered, fs)
}
return filtered, nil
}
Expand Down
2 changes: 1 addition & 1 deletion zfs/placeholder.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func ZFSListPlaceholderFilesystemsWithAdditionalProps(ctx context.Context, root
props = append(props, additionalProps...)
}

propsByFS, err := zfsGetRecursive(ctx, root, -1, []string{"filesystem", "volume"}, props, SourceAny)
propsByFS, err := ZFSGetRecursive(ctx, root, -1, []string{"filesystem", "volume"}, props, SourceAny)
if err != nil {
return nil, fmt.Errorf("cannot get placeholder filesystems under %q: %w", root, err)
}
Expand Down
4 changes: 2 additions & 2 deletions zfs/zfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1467,7 +1467,7 @@ func (s PropertySource) zfsGetSourceFieldPrefixes() []string {
return prefixes
}

func zfsGetRecursive(ctx context.Context, path string, depth int,
func ZFSGetRecursive(ctx context.Context, path string, depth int,
dstypes []string, props []string, allowedSources PropertySource,
) (map[string]*ZFSProperties, error) {
cmd := zfscmd.CommandContext(ctx, ZfsBin,
Expand Down Expand Up @@ -1564,7 +1564,7 @@ func validatePropsByFs(propsByFS map[string]*ZFSProperties, props []string,
func zfsGet(ctx context.Context, path string, props []string,
allowedSources PropertySource,
) (*ZFSProperties, error) {
propMap, err := zfsGetRecursive(ctx, path, 0, nil, props, allowedSources)
propMap, err := ZFSGetRecursive(ctx, path, 0, nil, props, allowedSources)
switch {
case err != nil:
return nil, err
Expand Down

0 comments on commit 59288e4

Please sign in to comment.