svn commit: r343977 - head/lib/libbe
Kyle Evans
kevans at FreeBSD.org
Sun Feb 10 21:19:10 UTC 2019
Author: kevans
Date: Sun Feb 10 21:19:09 2019
New Revision: 343977
URL: https://svnweb.freebsd.org/changeset/base/343977
Log:
libbe(3): Add a destroy option for removing the origin
Currently origin snapshots are left behind when a BE is destroyed, whether
it was an auto-created snapshot or explicitly specified via, for example,
`bectl create -e be at mysnap ...`.
Removing it automatically could be argued as a POLA violation in some
circumstances, so provide a flag to be_destroy for it. An accompanying
option will be added to bectl(8) to utilize this.
Some minor style/consistency nits in the affected areas also addressed.
Reported by: Shawn Webb
MFC after: 1 week
Modified:
head/lib/libbe/be.c
head/lib/libbe/be.h
Modified: head/lib/libbe/be.c
==============================================================================
--- head/lib/libbe/be.c Sun Feb 10 21:00:02 2019 (r343976)
+++ head/lib/libbe/be.c Sun Feb 10 21:19:09 2019 (r343977)
@@ -203,13 +203,14 @@ be_destroy_cb(zfs_handle_t *zfs_hdl, void *data)
int
be_destroy(libbe_handle_t *lbh, const char *name, int options)
{
+ char origin[BE_MAXPATHLEN], path[BE_MAXPATHLEN];
zfs_handle_t *fs;
- char path[BE_MAXPATHLEN];
char *p;
int err, force, mounted;
p = path;
force = options & BE_DESTROY_FORCE;
+ *origin = '\0';
be_root_concat(lbh, name, path);
@@ -222,17 +223,21 @@ be_destroy(libbe_handle_t *lbh, const char *name, int
return (set_error(lbh, BE_ERR_DESTROYACT));
fs = zfs_open(lbh->lzh, p, ZFS_TYPE_FILESYSTEM);
+ if (fs == NULL)
+ return (set_error(lbh, BE_ERR_ZFSOPEN));
+ if ((options & BE_DESTROY_ORIGIN) != 0 &&
+ zfs_prop_get(fs, ZFS_PROP_ORIGIN, origin, sizeof(origin),
+ NULL, NULL, 0, 1) != 0)
+ return (set_error(lbh, BE_ERR_NOORIGIN));
} else {
-
if (!zfs_dataset_exists(lbh->lzh, path, ZFS_TYPE_SNAPSHOT))
return (set_error(lbh, BE_ERR_NOENT));
fs = zfs_open(lbh->lzh, p, ZFS_TYPE_SNAPSHOT);
+ if (fs == NULL)
+ return (set_error(lbh, BE_ERR_ZFSOPEN));
}
- if (fs == NULL)
- return (set_error(lbh, BE_ERR_ZFSOPEN));
-
/* Check if mounted, unmount if force is specified */
if ((mounted = zfs_is_mounted(fs, NULL)) != 0) {
if (force)
@@ -246,6 +251,17 @@ be_destroy(libbe_handle_t *lbh, const char *name, int
if (err == EBUSY)
return (set_error(lbh, BE_ERR_DESTROYMNT));
return (set_error(lbh, BE_ERR_UNKNOWN));
+ }
+
+ if (*origin != '\0') {
+ fs = zfs_open(lbh->lzh, origin, ZFS_TYPE_SNAPSHOT);
+ if (fs == NULL)
+ return (set_error(lbh, BE_ERR_ZFSOPEN));
+ err = zfs_destroy(fs, false);
+ if (err == EBUSY)
+ return (set_error(lbh, BE_ERR_DESTROYMNT));
+ else if (err != 0)
+ return (set_error(lbh, BE_ERR_UNKNOWN));
}
return (0);
Modified: head/lib/libbe/be.h
==============================================================================
--- head/lib/libbe/be.h Sun Feb 10 21:00:02 2019 (r343976)
+++ head/lib/libbe/be.h Sun Feb 10 21:19:09 2019 (r343977)
@@ -93,7 +93,8 @@ int be_rename(libbe_handle_t *, const char *, const ch
/* Bootenv removal functions */
typedef enum {
- BE_DESTROY_FORCE = 1 << 0,
+ BE_DESTROY_FORCE = 1 << 0,
+ BE_DESTROY_ORIGIN = 1 << 1,
} be_destroy_opt_t;
int be_destroy(libbe_handle_t *, const char *, int);
@@ -102,7 +103,7 @@ int be_destroy(libbe_handle_t *, const char *, int);
typedef enum {
BE_MNT_FORCE = 1 << 0,
- BE_MNT_DEEP = 1 << 1,
+ BE_MNT_DEEP = 1 << 1,
} be_mount_opt_t;
int be_mount(libbe_handle_t *, char *, char *, int, char *);
More information about the svn-src-all
mailing list