Date: Sun, 5 Nov 2017 02:19:49 GMT From: kneitinger@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r329054 - soc2017/kneitinger/libbe-head/lib/libbe Message-ID: <201711050219.vA52JnZk093925@socsvn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: kneitinger Date: Sun Nov 5 02:19:49 2017 New Revision: 329054 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=329054 Log: Allow libbe:destroy to work on snapshots as well Modified: soc2017/kneitinger/libbe-head/lib/libbe/be.c soc2017/kneitinger/libbe-head/lib/libbe/be_access.c Modified: soc2017/kneitinger/libbe-head/lib/libbe/be.c ============================================================================== --- soc2017/kneitinger/libbe-head/lib/libbe/be.c Sun Nov 5 02:17:42 2017 (r329053) +++ soc2017/kneitinger/libbe-head/lib/libbe/be.c Sun Nov 5 02:19:49 2017 (r329054) @@ -124,9 +124,10 @@ /* - * Destroy the boot environment specified by the name parameter - * Options are or'd together with the possible values: + * Destroy the boot environment or snapshot specified by the name + * parameter. Options are or'd together with the possible values: * BE_DESTROY_FORCE : forces operation on mounted datasets + * TODO: Test destroying a non active but mounted be */ int be_destroy(libbe_handle_t *lbh, char *name, int options) @@ -142,25 +143,42 @@ be_root_concat(lbh, name, path); printf("path: %s\n", path); - if (!zfs_dataset_exists(lbh->lzh, path, ZFS_TYPE_DATASET)) { - return (set_error(lbh, BE_ERR_NOENT)); - } + if (strchr(name, '@') == NULL) { + if (!zfs_dataset_exists(lbh->lzh, path, ZFS_TYPE_DATASET)) { + return (set_error(lbh, BE_ERR_NOENT)); + } + + if (strcmp(path, lbh->active) == 0) { + return (set_error(lbh, BE_ERR_DESTROYACT)); + } + + fs = zfs_open(lbh->lzh, p, ZFS_TYPE_DATASET); + } else { - if (strcmp(path, lbh->active) == 0) { - return (set_error(lbh, BE_ERR_DESTROYACT)); + 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); } - fs = zfs_open(lbh->lzh, p, ZFS_TYPE_DATASET); + if (fs == NULL) + return (set_error(lbh, BE_ERR_ZFSOPEN)); - if ((mounted = zfs_is_mounted(fs, &p)) && !(force)) { - return (set_error(lbh, BE_ERR_DESTROYMNT)); + /* Check if mounted, unmount if force is specified */ + if (mounted = zfs_is_mounted(fs, NULL)) { + if (force) { + zfs_unmount(fs, NULL, 0); + } else { + return (set_error(lbh, BE_ERR_DESTROYMNT)); + } } - // TODO: account for "force" option by unmounting // TODO: convert this to use zfs_iter_children first for deep bes + // XXX note: errno 16 (device busy) occurs when chilren are present if ((err = zfs_destroy(fs, false)) != 0) { - fprintf(stderr, "delete failed\n"); + fprintf(stderr, "delete failed errno: %d\n", errno); } return (err); @@ -707,6 +725,7 @@ // TODO + /* * Establish if the existing path is a zfs dataset or just * the subdirectory of one Modified: soc2017/kneitinger/libbe-head/lib/libbe/be_access.c ============================================================================== --- soc2017/kneitinger/libbe-head/lib/libbe/be_access.c Sun Nov 5 02:17:42 2017 (r329053) +++ soc2017/kneitinger/libbe-head/lib/libbe/be_access.c Sun Nov 5 02:19:49 2017 (r329054) @@ -47,7 +47,6 @@ return (set_error(lbh, err)); } - // TODO: make sure it exists (in a be_exists fn)! if (!be_exists(lbh, bootenv)) { return (set_error(lbh, BE_ERR_NOENT)); } @@ -59,6 +58,7 @@ mntflags = (flags & BE_MNT_FORCE) ? MNT_FORCE : 0; + /* Create mountpoint if it is not specified */ if (mountpoint == NULL) { strcpy(mnt_temp, "/tmp/be_mount.XXXX"); if (mkdtemp(mnt_temp) == NULL) {
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201711050219.vA52JnZk093925>