diff --git a/client/migrate.go b/client/migrate.go index c7fbbf9..9d6c358 100644 --- a/client/migrate.go +++ b/client/migrate.go @@ -211,7 +211,7 @@ func doMigrateReplicationCursorFS(ctx context.Context, v1CursorJobs []job.Job, f } fmt.Printf("identified owning job %q\n", owningJob.Name()) - bookmarks, err := zfs.ZFSListFilesystemVersions(fs, zfs.ListFilesystemVersionsOptions{ + bookmarks, err := zfs.ZFSListFilesystemVersions(ctx, fs, zfs.ListFilesystemVersionsOptions{ Types: zfs.Bookmarks, }) if err != nil { diff --git a/daemon/snapper/snapper.go b/daemon/snapper/snapper.go index 44affad..8cc467b 100644 --- a/daemon/snapper/snapper.go +++ b/daemon/snapper/snapper.go @@ -485,7 +485,7 @@ var findSyncPointFSNoFilesystemVersionsErr = fmt.Errorf("no filesystem versions" func findSyncPointFSNextOptimalSnapshotTime(l Logger, now time.Time, interval time.Duration, prefix string, d *zfs.DatasetPath) (time.Time, error) { - fsvs, err := zfs.ZFSListFilesystemVersions(d, zfs.ListFilesystemVersionsOptions{ + fsvs, err := zfs.ZFSListFilesystemVersions(context.TODO(), d, zfs.ListFilesystemVersionsOptions{ Types: zfs.Snapshots, ShortnamePrefix: prefix, }) diff --git a/endpoint/endpoint.go b/endpoint/endpoint.go index 0e4ebe6..69229d0 100644 --- a/endpoint/endpoint.go +++ b/endpoint/endpoint.go @@ -96,7 +96,7 @@ func (s *Sender) ListFilesystemVersions(ctx context.Context, r *pdu.ListFilesyst if err != nil { return nil, err } - fsvs, err := zfs.ZFSListFilesystemVersions(lp, zfs.ListFilesystemVersionsOptions{}) + fsvs, err := zfs.ZFSListFilesystemVersions(ctx, lp, zfs.ListFilesystemVersionsOptions{}) if err != nil { return nil, err } @@ -648,7 +648,7 @@ func (s *Receiver) ListFilesystemVersions(ctx context.Context, req *pdu.ListFile } // TODO share following code with sender - fsvs, err := zfs.ZFSListFilesystemVersions(lp, zfs.ListFilesystemVersionsOptions{}) + fsvs, err := zfs.ZFSListFilesystemVersions(ctx, lp, zfs.ListFilesystemVersionsOptions{}) if err != nil { return nil, err } diff --git a/endpoint/endpoint_zfs_abstraction.go b/endpoint/endpoint_zfs_abstraction.go index 32a521f..6215694 100644 --- a/endpoint/endpoint_zfs_abstraction.go +++ b/endpoint/endpoint_zfs_abstraction.go @@ -573,7 +573,7 @@ func listAbstractionsImplFS(ctx context.Context, fs string, query *ListZFSHoldsA whatTypes[zfs.Snapshot] = true } } - fsvs, err := zfs.ZFSListFilesystemVersions(fsp, zfs.ListFilesystemVersionsOptions{ + fsvs, err := zfs.ZFSListFilesystemVersions(ctx, fsp, zfs.ListFilesystemVersionsOptions{ Types: whatTypes, }) if err != nil { diff --git a/platformtest/tests/listFilesystemVersions.go b/platformtest/tests/listFilesystemVersions.go index 1f499cd..475a0db 100644 --- a/platformtest/tests/listFilesystemVersions.go +++ b/platformtest/tests/listFilesystemVersions.go @@ -43,7 +43,7 @@ func ListFilesystemVersionsTypeFilteringAndPrefix(t *platformtest.Context) { fs := fmt.Sprintf("%s/foo bar", t.RootDataset) // no options := all types - vs, err := zfs.ZFSListFilesystemVersions(mustDatasetPath(fs), zfs.ListFilesystemVersionsOptions{}) + vs, err := zfs.ZFSListFilesystemVersions(t, mustDatasetPath(fs), zfs.ListFilesystemVersionsOptions{}) require.NoError(t, err) require.Equal(t, []string{ "#blup 1", "#bookfoo 1", "#bookfoo 2", "#foo 1", "#foo 2", @@ -51,21 +51,21 @@ func ListFilesystemVersionsTypeFilteringAndPrefix(t *platformtest.Context) { }, versionRelnamesSorted(vs)) // just snapshots - vs, err = zfs.ZFSListFilesystemVersions(mustDatasetPath(fs), zfs.ListFilesystemVersionsOptions{ + vs, err = zfs.ZFSListFilesystemVersions(t, mustDatasetPath(fs), zfs.ListFilesystemVersionsOptions{ Types: zfs.Snapshots, }) require.NoError(t, err) require.Equal(t, []string{"@ foo with leading whitespace", "@blup 1", "@foo 1", "@foo 2"}, versionRelnamesSorted(vs)) // just bookmarks - vs, err = zfs.ZFSListFilesystemVersions(mustDatasetPath(fs), zfs.ListFilesystemVersionsOptions{ + vs, err = zfs.ZFSListFilesystemVersions(t, mustDatasetPath(fs), zfs.ListFilesystemVersionsOptions{ Types: zfs.Bookmarks, }) require.NoError(t, err) require.Equal(t, []string{"#blup 1", "#bookfoo 1", "#bookfoo 2", "#foo 1", "#foo 2"}, versionRelnamesSorted(vs)) // just with prefix foo - vs, err = zfs.ZFSListFilesystemVersions(mustDatasetPath(fs), zfs.ListFilesystemVersionsOptions{ + vs, err = zfs.ZFSListFilesystemVersions(t, mustDatasetPath(fs), zfs.ListFilesystemVersionsOptions{ ShortnamePrefix: "foo", }) require.NoError(t, err) @@ -82,7 +82,7 @@ func ListFilesystemVersionsZeroExistIsNotAnError(t *platformtest.Context) { fs := fmt.Sprintf("%s/foo bar", t.RootDataset) - vs, err := zfs.ZFSListFilesystemVersions(mustDatasetPath(fs), zfs.ListFilesystemVersionsOptions{}) + vs, err := zfs.ZFSListFilesystemVersions(t, mustDatasetPath(fs), zfs.ListFilesystemVersionsOptions{}) require.Empty(t, vs) require.NoError(t, err) dsne, ok := err.(*zfs.DatasetDoesNotExist) @@ -98,7 +98,7 @@ func ListFilesystemVersionsFilesystemNotExist(t *platformtest.Context) { nonexistentFS := fmt.Sprintf("%s/not existent", t.RootDataset) - vs, err := zfs.ZFSListFilesystemVersions(mustDatasetPath(nonexistentFS), zfs.ListFilesystemVersionsOptions{}) + vs, err := zfs.ZFSListFilesystemVersions(t, mustDatasetPath(nonexistentFS), zfs.ListFilesystemVersionsOptions{}) require.Empty(t, vs) require.Error(t, err) t.Logf("err = %T\n%s", err, err) @@ -141,7 +141,7 @@ func ListFilesystemVersionsUserrefs(t *platformtest.Context) { fs := fmt.Sprintf("%s/foo bar", t.RootDataset) - vs, err := zfs.ZFSListFilesystemVersions(mustDatasetPath(fs), zfs.ListFilesystemVersionsOptions{}) + vs, err := zfs.ZFSListFilesystemVersions(t, mustDatasetPath(fs), zfs.ListFilesystemVersionsOptions{}) require.NoError(t, err) type expectation struct { diff --git a/zfs/versions.go b/zfs/versions.go index fed3d60..bcd5cec 100644 --- a/zfs/versions.go +++ b/zfs/versions.go @@ -206,13 +206,13 @@ func (o *ListFilesystemVersionsOptions) matches(v FilesystemVersion) bool { } // returned versions are sorted by createtxg FIXME drop sort by createtxg requirement -func ZFSListFilesystemVersions(fs *DatasetPath, options ListFilesystemVersionsOptions) (res []FilesystemVersion, err error) { +func ZFSListFilesystemVersions(ctx context.Context, fs *DatasetPath, options ListFilesystemVersionsOptions) (res []FilesystemVersion, err error) { listResults := make(chan ZFSListResult) promTimer := prometheus.NewTimer(prom.ZFSListFilesystemVersionDuration.WithLabelValues(fs.ToString())) defer promTimer.ObserveDuration() - ctx, cancel := context.WithCancel(context.Background()) + ctx, cancel := context.WithCancel(ctx) defer cancel() go ZFSListChan(ctx, listResults, []string{"name", "guid", "createtxg", "creation", "userrefs"}, diff --git a/zfs/zfs.go b/zfs/zfs.go index e2eb1f7..2b21ef4 100644 --- a/zfs/zfs.go +++ b/zfs/zfs.go @@ -1084,7 +1084,7 @@ func ZFSRecv(ctx context.Context, fs string, v *ZFSSendArgVersion, streamCopier if opts.RollbackAndForceRecv { // destroy all snapshots before `recv -F` because `recv -F` // does not perform a rollback unless `send -R` was used (which we assume hasn't been the case) - snaps, err := ZFSListFilesystemVersions(fsdp, ListFilesystemVersionsOptions{ + snaps, err := ZFSListFilesystemVersions(ctx, fsdp, ListFilesystemVersionsOptions{ Types: Snapshots, }) if err != nil {