Skip to content

Commit

Permalink
Merge remote-tracking branch 'calmh/master' into p1
Browse files Browse the repository at this point in the history
  • Loading branch information
albalogic committed Feb 9, 2016
2 parents 6709706 + fc23d69 commit 178e69d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
9 changes: 7 additions & 2 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,13 @@ func parseInodeChanges(lines [][]string) ([]*InodeChange, error) {
return changes, nil
}

func listByType(t, filter string) ([]*Dataset, error) {
args := []string{"get", "-rHp", "-t", t, "all"}
func listByType(t, filter string, depth int) ([]*Dataset, error) {
var args []string
if depth > 0 {
args = []string{"get", fmt.Sprintf("-d%d", depth), "-rHp", "-t", t, "all"}
} else {
args = []string{"get", "-rHp", "-t", t, "all"}
}
if filter != "" {
args = append(args, filter)
}
Expand Down
18 changes: 9 additions & 9 deletions zfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,29 +117,29 @@ func zfs(arg ...string) ([][]string, error) {
// Datasets returns a slice of ZFS datasets, regardless of type.
// A filter argument may be passed to select a dataset with the matching name,
// or empty string ("") may be used to select all datasets.
func Datasets(filter string) ([]*Dataset, error) {
return listByType("all", filter)
func Datasets(filter string, depth int) ([]*Dataset, error) {
return listByType("all", filter, depth)
}

// Snapshots returns a slice of ZFS snapshots.
// A filter argument may be passed to select a snapshot with the matching name,
// or empty string ("") may be used to select all snapshots.
func Snapshots(filter string) ([]*Dataset, error) {
return listByType(DatasetSnapshot, filter)
func Snapshots(filter string, depth int) ([]*Dataset, error) {
return listByType(DatasetSnapshot, filter, depth)
}

// Filesystems returns a slice of ZFS filesystems.
// A filter argument may be passed to select a filesystem with the matching name,
// or empty string ("") may be used to select all filesystems.
func Filesystems(filter string) ([]*Dataset, error) {
return listByType(DatasetFilesystem, filter)
func Filesystems(filter string, depth int) ([]*Dataset, error) {
return listByType(DatasetFilesystem, filter, depth)
}

// Volumes returns a slice of ZFS volumes.
// A filter argument may be passed to select a volume with the matching name,
// or empty string ("") may be used to select all volumes.
func Volumes(filter string) ([]*Dataset, error) {
return listByType(DatasetVolume, filter)
func Volumes(filter string, depth int) ([]*Dataset, error) {
return listByType(DatasetVolume, filter, depth)
}

// GetDataset retrieves a single ZFS dataset by name. This dataset could be
Expand Down Expand Up @@ -336,7 +336,7 @@ func (d *Dataset) Rename(name string, createParent bool, recursiveRenameSnapshot

// Snapshots returns a slice of all ZFS snapshots of a given dataset.
func (d *Dataset) Snapshots() ([]*Dataset, error) {
return Snapshots(d.Name)
return Snapshots(d.Name, 1)
}

// CreateFilesystem creates a new ZFS filesystem with the specified name and
Expand Down
8 changes: 4 additions & 4 deletions zpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ func GetZpool(name string) (*Zpool, error) {
}

// Datasets returns a slice of all ZFS datasets in a zpool.
func (z *Zpool) Datasets() ([]*Dataset, error) {
return Datasets(z.Name)
func (z *Zpool) Datasets(depth int) ([]*Dataset, error) {
return Datasets(z.Name, depth)
}

// Snapshots returns a slice of all ZFS snapshots in a zpool.
func (z *Zpool) Snapshots() ([]*Dataset, error) {
return Snapshots(z.Name)
func (z *Zpool) Snapshots(depth int) ([]*Dataset, error) {
return Snapshots(z.Name, depth)
}

// CreateZpool creates a new ZFS zpool with the specified name, properties,
Expand Down

0 comments on commit 178e69d

Please sign in to comment.