Changeset View
Changeset View
Standalone View
Standalone View
lib/libbe/be.c
| Show First 20 Lines • Show All 169 Lines • ▼ Show 20 Lines | if (zpool_get_prop(lbh->active_phandle, ZPOOL_PROP_BOOTFS, lbh->bootfs, | ||||
| sizeof(lbh->bootfs), NULL, true) != 0) | sizeof(lbh->bootfs), NULL, true) != 0) | ||||
| goto err; | goto err; | ||||
| if (zpool_get_prop(lbh->active_phandle, ZPOOL_PROP_ALTROOT, | if (zpool_get_prop(lbh->active_phandle, ZPOOL_PROP_ALTROOT, | ||||
| altroot, sizeof(altroot), NULL, true) == 0 && | altroot, sizeof(altroot), NULL, true) == 0 && | ||||
| strcmp(altroot, "-") != 0) | strcmp(altroot, "-") != 0) | ||||
| lbh->altroot_len = strlen(altroot); | lbh->altroot_len = strlen(altroot); | ||||
| (void) lzbe_get_boot_device(zpool_get_name(lbh->active_phandle), | |||||
| &lbh->bootonce); | |||||
| return (lbh); | return (lbh); | ||||
| err: | err: | ||||
| if (lbh != NULL) { | if (lbh != NULL) { | ||||
| if (lbh->active_phandle != NULL) | if (lbh->active_phandle != NULL) | ||||
| zpool_close(lbh->active_phandle); | zpool_close(lbh->active_phandle); | ||||
| if (lbh->lzh != NULL) | if (lbh->lzh != NULL) | ||||
| libzfs_fini(lbh->lzh); | libzfs_fini(lbh->lzh); | ||||
| free(lbh); | free(lbh); | ||||
| } | } | ||||
| free(poolname); | free(poolname); | ||||
| return (NULL); | return (NULL); | ||||
| } | } | ||||
| /* | /* | ||||
| * Free memory allocated by libbe_init() | * Free memory allocated by libbe_init() | ||||
| */ | */ | ||||
| void | void | ||||
| libbe_close(libbe_handle_t *lbh) | libbe_close(libbe_handle_t *lbh) | ||||
| { | { | ||||
| if (lbh->active_phandle != NULL) | if (lbh->active_phandle != NULL) | ||||
| zpool_close(lbh->active_phandle); | zpool_close(lbh->active_phandle); | ||||
| libzfs_fini(lbh->lzh); | libzfs_fini(lbh->lzh); | ||||
kevans: Need to `free(lbh->bootonce)`here; turns out we were leaking it before... whoops. | |||||
Done Inline Actionsgood catch, i'll include that rcm: good catch, i'll include that | |||||
| free(lbh->bootonce); | |||||
| free(lbh); | free(lbh); | ||||
| } | } | ||||
| /* | /* | ||||
| * Proxy through to libzfs for the moment. | * Proxy through to libzfs for the moment. | ||||
| */ | */ | ||||
| void | void | ||||
| be_nicenum(uint64_t num, char *buf, size_t buflen) | be_nicenum(uint64_t num, char *buf, size_t buflen) | ||||
| ▲ Show 20 Lines • Show All 228 Lines • ▼ Show 20 Lines | if ((snapdelim = strchr(path, '@')) == NULL) { | ||||
| if ((mounted = zfs_is_mounted(fs, NULL)) != 0) { | if ((mounted = zfs_is_mounted(fs, NULL)) != 0) { | ||||
| if (force) { | if (force) { | ||||
| zfs_unmount(fs, NULL, 0); | zfs_unmount(fs, NULL, 0); | ||||
| } else { | } else { | ||||
| free(bdd.snapname); | free(bdd.snapname); | ||||
| return (set_error(lbh, BE_ERR_DESTROYMNT)); | return (set_error(lbh, BE_ERR_DESTROYMNT)); | ||||
| } | } | ||||
| } | } | ||||
| /* Handle destroying bootonce */ | |||||
| if (lbh->bootonce != NULL && | |||||
| strcmp(path, lbh->bootonce) == 0) | |||||
| (void) lzbe_set_boot_device( | |||||
| zpool_get_name(lbh->active_phandle), lzbe_add, NULL); | |||||
| } else { | } else { | ||||
| /* | /* | ||||
| * If we're initially destroying a snapshot, origin options do | * If we're initially destroying a snapshot, origin options do | ||||
| * not make sense. If we're destroying the origin snapshot of | * not make sense. If we're destroying the origin snapshot of | ||||
| * a BE, we want to maintain the options in case we need to | * a BE, we want to maintain the options in case we need to | ||||
| * fake success after failing to promote. | * fake success after failing to promote. | ||||
| */ | */ | ||||
| if (!odestroyer) | if (!odestroyer) | ||||
| ▲ Show 20 Lines • Show All 562 Lines • ▼ Show 20 Lines | if ((zfs_hdl = zfs_open(lbh->lzh, full_old, | ||||
| ZFS_TYPE_FILESYSTEM)) == NULL) | ZFS_TYPE_FILESYSTEM)) == NULL) | ||||
| return (set_error(lbh, BE_ERR_ZFSOPEN)); | return (set_error(lbh, BE_ERR_ZFSOPEN)); | ||||
| /* recurse, nounmount, forceunmount */ | /* recurse, nounmount, forceunmount */ | ||||
| struct renameflags flags = { | struct renameflags flags = { | ||||
| .nounmount = 1, | .nounmount = 1, | ||||
| }; | }; | ||||
| err = zfs_rename(zfs_hdl, full_new, flags); | err = zfs_rename(zfs_hdl, full_new, flags); | ||||
| if (err != 0) | |||||
| goto error; | |||||
| /* handle renaming bootonce */ | |||||
| if (lbh->bootonce != NULL && | |||||
| strcmp(full_old, lbh->bootonce) == 0) | |||||
| err = be_activate(lbh, new, true); | |||||
| error: | |||||
| zfs_close(zfs_hdl); | zfs_close(zfs_hdl); | ||||
| if (err != 0) | return (set_error(lbh, err)); | ||||
| return (set_error(lbh, BE_ERR_UNKNOWN)); | |||||
| return (0); | |||||
| } | } | ||||
| int | int | ||||
| be_export(libbe_handle_t *lbh, const char *bootenv, int fd) | be_export(libbe_handle_t *lbh, const char *bootenv, int fd) | ||||
| { | { | ||||
| char snap_name[BE_MAXPATHLEN]; | char snap_name[BE_MAXPATHLEN]; | ||||
| char buf[BE_MAXPATHLEN]; | char buf[BE_MAXPATHLEN]; | ||||
| ▲ Show 20 Lines • Show All 301 Lines • Show Last 20 Lines | |||||
Need to free(lbh->bootonce)here; turns out we were leaking it before... whoops.