Skip to content

Commit 16b13ca

Browse files
committed
Merge branch 'apatil-master'
* apatil-master: always allocate largest Mount slice add missing Unmount/Mount docs rename Umount -> Unmount to follow zfs command name Added mount and umount methods Small fix to rename. Added Rename
2 parents 1b4ae6f + f701d80 commit 16b13ca

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

zfs.go

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,46 @@ func (d *Dataset) Clone(dest string, properties map[string]string) (*Dataset, er
180180
return GetDataset(dest)
181181
}
182182

183+
// Unmount unmounts currently mounted ZFS file systems.
184+
func (d *Dataset) Unmount(force bool) (*Dataset, error) {
185+
if d.Type == DatasetSnapshot {
186+
return nil, errors.New("cannot unmount snapshots")
187+
}
188+
args := make([]string, 1, 3)
189+
args[0] = "umount"
190+
if force {
191+
args = append(args, "-f")
192+
}
193+
args = append(args, d.Name)
194+
_, err := zfs(args...)
195+
if err != nil {
196+
return nil, err
197+
}
198+
return GetDataset(d.Name)
199+
}
200+
201+
// Mount mounts ZFS file systems.
202+
func (d *Dataset) Mount(overlay bool, options []string) (*Dataset, error) {
203+
if d.Type == DatasetSnapshot {
204+
return nil, errors.New("cannot mount snapshots")
205+
}
206+
args := make([]string, 1, 5)
207+
args[0] = "mount"
208+
if overlay {
209+
args = append(args, "-O")
210+
}
211+
if options != nil {
212+
args = append(args, "-o")
213+
args = append(args, strings.Join(options, ","))
214+
}
215+
args = append(args, d.Name)
216+
_, err := zfs(args...)
217+
if err != nil {
218+
return nil, err
219+
}
220+
return GetDataset(d.Name)
221+
}
222+
183223
// ReceiveSnapshot receives a ZFS stream from the input io.Reader, creates a
184224
// new snapshot with the specified name, and streams the input data into the
185225
// newly-created snapshot.
@@ -275,6 +315,26 @@ func (d *Dataset) GetProperty(key string) (string, error) {
275315
return out[0][2], nil
276316
}
277317

318+
// Rename renames a dataset.
319+
func (d *Dataset) Rename(name string, createParent bool, recursiveRenameSnapshots bool) (*Dataset, error) {
320+
args := make([]string, 3, 5)
321+
args[0] = "rename"
322+
args[1] = d.Name
323+
args[2] = name
324+
if createParent {
325+
args = append(args, "-p")
326+
}
327+
if recursiveRenameSnapshots {
328+
args = append(args, "-r")
329+
}
330+
_, err := zfs(args...)
331+
if err != nil {
332+
return d, err
333+
}
334+
335+
return GetDataset(name)
336+
}
337+
278338
// Snapshots returns a slice of all ZFS snapshots of a given dataset.
279339
func (d *Dataset) Snapshots() ([]*Dataset, error) {
280340
return Snapshots(d.Name)

0 commit comments

Comments
 (0)