diff options
author | Kyle Evans <kevans@FreeBSD.org> | 2018-07-25 15:14:35 +0000 |
---|---|---|
committer | Kyle Evans <kevans@FreeBSD.org> | 2018-07-25 15:14:35 +0000 |
commit | b29bf2f84ea838b1b7dad4e80858b637395930ae (patch) | |
tree | 01fa5b44f39edd9fcc0dd4b2693dc26b2cb4e1f7 /lib/libbe | |
parent | ff8676cc4e02c6e138f2f3b68a6903dc418e5cc4 (diff) | |
download | src-b29bf2f84ea838b1b7dad4e80858b637395930ae.tar.gz src-b29bf2f84ea838b1b7dad4e80858b637395930ae.zip |
Notes
Diffstat (limited to 'lib/libbe')
-rw-r--r-- | lib/libbe/be.c | 64 | ||||
-rw-r--r-- | lib/libbe/be.h | 13 | ||||
-rw-r--r-- | lib/libbe/be_access.c | 11 | ||||
-rw-r--r-- | lib/libbe/be_impl.h | 6 | ||||
-rw-r--r-- | lib/libbe/be_info.c | 2 | ||||
-rw-r--r-- | lib/libbe/libbe.3 | 10 |
6 files changed, 52 insertions, 54 deletions
diff --git a/lib/libbe/be.c b/lib/libbe/be.c index 934cdaf21f9f..48bb36c2beea 100644 --- a/lib/libbe/be.c +++ b/lib/libbe/be.c @@ -139,7 +139,7 @@ libbe_init(void) zfs_iter_filesystems(rootds, be_locate_rootfs, lbh); zfs_close(rootds); rootds = NULL; - if (lbh->rootfs == NULL) + if (*lbh->rootfs == '\0') goto err; return (lbh); @@ -212,7 +212,7 @@ be_destroy(libbe_handle_t *lbh, char *name, int options) return (set_error(lbh, BE_ERR_ZFSOPEN)); /* Check if mounted, unmount if force is specified */ - if (mounted = zfs_is_mounted(fs, NULL)) { + if ((mounted = zfs_is_mounted(fs, NULL)) != 0) { if (force) zfs_unmount(fs, NULL, 0); else @@ -230,7 +230,7 @@ be_destroy(libbe_handle_t *lbh, char *name, int options) int -be_snapshot(libbe_handle_t *lbh, char *source, char *snap_name, +be_snapshot(libbe_handle_t *lbh, const char *source, const char *snap_name, bool recursive, char *result) { char buf[BE_MAXPATHLEN]; @@ -257,7 +257,7 @@ be_snapshot(libbe_handle_t *lbh, char *source, char *snap_name, strcpy(result, strrchr(buf, '/') + 1); } - if (err = zfs_snapshot(lbh->lzh, buf, recursive, NULL) != 0) { + if ((err = zfs_snapshot(lbh->lzh, buf, recursive, NULL)) != 0) { switch (err) { case EZFS_INVALIDNAME: return (set_error(lbh, BE_ERR_INVALIDNAME)); @@ -280,7 +280,7 @@ be_create(libbe_handle_t *lbh, char *name) { int err; - err = be_create_from_existing(lbh, name, (char *)be_active_path(lbh)); + err = be_create_from_existing(lbh, name, be_active_path(lbh)); return (set_error(lbh, err)); } @@ -327,7 +327,6 @@ be_deep_clone(zfs_handle_t *ds, void *data) int err; char be_path[BE_MAXPATHLEN]; char snap_path[BE_MAXPATHLEN]; - char mp[BE_MAXPATHLEN]; const char *dspath; char *dsname; zfs_handle_t *snap_hdl; @@ -364,7 +363,7 @@ be_deep_clone(zfs_handle_t *ds, void *data) ZFS_TYPE_FILESYSTEM) == ZPROP_INVAL) return (-1); - if (err = zfs_clone(snap_hdl, be_path, props)) { + if ((err = zfs_clone(snap_hdl, be_path, props)) != 0) { switch (err) { case EZFS_SUCCESS: err = BE_ERR_SUCCESS; @@ -392,23 +391,25 @@ be_deep_clone(zfs_handle_t *ds, void *data) * Create the boot environment from pre-existing snapshot */ int -be_create_from_existing_snap(libbe_handle_t *lbh, char *name, char *snap) +be_create_from_existing_snap(libbe_handle_t *lbh, const char *name, + const char *snap) { int err; char be_path[BE_MAXPATHLEN]; char snap_path[BE_MAXPATHLEN]; - char *parentname, *bename, *snapname; + const char *bename; + char *parentname, *snapname; zfs_handle_t *parent_hdl; struct libbe_deep_clone sdc; - if (err = be_validate_name(lbh, name)) + if ((err = be_validate_name(lbh, name)) != 0) return (set_error(lbh, err)); - if (err = be_root_concat(lbh, snap, snap_path)) + if ((err = be_root_concat(lbh, snap, snap_path)) != 0) return (set_error(lbh, err)); - if (err = be_validate_snap(lbh, snap_path)) + if ((err = be_validate_snap(lbh, snap_path)) != 0) return (set_error(lbh, err)); - if (err = be_root_concat(lbh, name, be_path)) + if ((err = be_root_concat(lbh, name, be_path)) != 0) return (set_error(lbh, err)); if ((bename = strrchr(name, '/')) == NULL) @@ -444,7 +445,7 @@ be_create_from_existing_snap(libbe_handle_t *lbh, char *name, char *snap) * Create a boot environment from an existing boot environment */ int -be_create_from_existing(libbe_handle_t *lbh, char *name, char *old) +be_create_from_existing(libbe_handle_t *lbh, const char *name, const char *old) { int err; char buf[BE_MAXPATHLEN]; @@ -464,12 +465,11 @@ be_create_from_existing(libbe_handle_t *lbh, char *name, char *old) * failure. Does not set the internal library error state. */ int -be_validate_snap(libbe_handle_t *lbh, char *snap_name) +be_validate_snap(libbe_handle_t *lbh, const char *snap_name) { zfs_handle_t *zfs_hdl; char buf[BE_MAXPATHLEN]; char *delim_pos; - char *mountpoint; int err = BE_ERR_SUCCESS; if (strlen(snap_name) >= BE_MAXPATHLEN) @@ -490,8 +490,8 @@ be_validate_snap(libbe_handle_t *lbh, char *snap_name) zfs_open(lbh->lzh, buf, ZFS_TYPE_DATASET)) == NULL) return (BE_ERR_NOORIGIN); - if (err = zfs_prop_get(zfs_hdl, ZFS_PROP_MOUNTPOINT, buf, BE_MAXPATHLEN, - NULL, NULL, 0, 1)) + if ((err = zfs_prop_get(zfs_hdl, ZFS_PROP_MOUNTPOINT, buf, BE_MAXPATHLEN, + NULL, NULL, 0, 1)) != 0) err = BE_ERR_INVORIGIN; if ((err != 0) && (strncmp(buf, "/", BE_MAXPATHLEN) != 0)) @@ -512,7 +512,7 @@ be_validate_snap(libbe_handle_t *lbh, char *snap_name) * zfs_be_root. Does not set internal library error state. */ int -be_root_concat(libbe_handle_t *lbh, char *name, char *result) +be_root_concat(libbe_handle_t *lbh, const char *name, char *result) { size_t name_len, root_len; @@ -545,7 +545,7 @@ be_root_concat(libbe_handle_t *lbh, char *name, char *result) * Does not set internal library error state. */ int -be_validate_name(libbe_handle_t *lbh, char *name) +be_validate_name(libbe_handle_t *lbh __unused, const char *name) { for (int i = 0; *name; i++) { char c = *(name++); @@ -569,12 +569,12 @@ be_rename(libbe_handle_t *lbh, char *old, char *new) zfs_handle_t *zfs_hdl; int err; - if (err = be_root_concat(lbh, old, full_old)) + if ((err = be_root_concat(lbh, old, full_old)) != 0) return (set_error(lbh, err)); - if (err = be_root_concat(lbh, new, full_new)) + if ((err = be_root_concat(lbh, new, full_new)) != 0) return (set_error(lbh, err)); - if (be_validate_name(lbh, new)) + if (be_validate_name(lbh, new) != 0) return (BE_ERR_UNKNOWN); /* XXX TODO set and return correct error */ @@ -621,7 +621,7 @@ be_export(libbe_handle_t *lbh, char *bootenv, int fd) zfs_handle_t *zfs; int err; - if (err = be_snapshot(lbh, bootenv, NULL, true, snap_name)) + if ((err = be_snapshot(lbh, bootenv, NULL, true, snap_name)) != 0) /* XXX TODO error handle */ return (-1); @@ -648,7 +648,7 @@ be_import(libbe_handle_t *lbh, char *bootenv, int fd) * XXX TODO: this is a very likely name for someone to already have * used... we should avoid it. */ - if (err = be_root_concat(lbh, "be_import_temp", buf)) + if ((err = be_root_concat(lbh, "be_import_temp", buf)) != 0) /* XXX TODO error handle */ return (-1); @@ -658,7 +658,7 @@ be_import(libbe_handle_t *lbh, char *bootenv, int fd) "@%F-%T", localtime(&rawtime)); /* lzc_receive(SNAPNAME, PROPS, ORIGIN, FORCE, fd)) { */ - if (err = lzc_receive(buf, NULL, NULL, false, fd)) { + if ((err = lzc_receive(buf, NULL, NULL, false, fd)) != 0) { /* TODO: go through libzfs_core's recv_impl and find returned * errors and set appropriate BE_ERR * edit: errors are not in libzfs_core, my assumption is @@ -737,8 +737,8 @@ be_add_child(libbe_handle_t *lbh, char *child_path, bool cp_if_exists) nvlist_add_string(props, "mountpoint", child_path); /* Create */ - if (err = - zfs_create(lbh->lzh, active, ZFS_TYPE_DATASET, props)) + if ((err = + zfs_create(lbh->lzh, active, ZFS_TYPE_DATASET, props)) != 0) /* XXX TODO handle error */ return (-1); nvlist_free(props); @@ -749,7 +749,7 @@ be_add_child(libbe_handle_t *lbh, char *child_path, bool cp_if_exists) return (-1); /* Set props */ - if (err = zfs_prop_set(zfs, "canmount", "noauto")) + if ((err = zfs_prop_set(zfs, "canmount", "noauto")) != 0) /* TODO handle error */ return (-1); } else if (cp_if_exists) { @@ -767,7 +767,7 @@ be_add_child(libbe_handle_t *lbh, char *child_path, bool cp_if_exists) snprintf(buf, BE_MAXPATHLEN, "%s@%ld", child_path, snap_name); - if (err = zfs_snapshot(lbh->lzh, buf, false, NULL)) + if ((err = zfs_snapshot(lbh->lzh, buf, false, NULL)) != 0) /* XXX TODO correct error */ return (-1); @@ -777,7 +777,7 @@ be_add_child(libbe_handle_t *lbh, char *child_path, bool cp_if_exists) /* XXX TODO correct error */ return (-1); - if (err = zfs_clone(zfs, active, NULL)) + if ((err = zfs_clone(zfs, active, NULL)) != 0) /* XXX TODO correct error */ return (-1); @@ -797,8 +797,6 @@ be_activate(libbe_handle_t *lbh, char *bootenv, bool temporary) char buf[BE_MAXPATHLEN]; uint64_t pool_guid; uint64_t vdev_guid; - int zfs_fd; - int len; int err; be_root_concat(lbh, bootenv, be_path); diff --git a/lib/libbe/be.h b/lib/libbe/be.h index 2727c1cdfeee..1b3218c206a4 100644 --- a/lib/libbe/be.h +++ b/lib/libbe/be.h @@ -67,14 +67,15 @@ const char *be_nextboot_path(libbe_handle_t *); const char *be_root_path(libbe_handle_t *); int be_get_bootenv_props(libbe_handle_t *, nvlist_t *); +void be_prop_list_free(nvlist_t *be_list); int be_activate(libbe_handle_t *, char *, bool); /* Bootenv creation functions */ int be_create(libbe_handle_t *, char *); -int be_create_from_existing(libbe_handle_t *, char *, char *); -int be_create_from_existing_snap(libbe_handle_t *, char *, char *); -int be_snapshot(libbe_handle_t *, char *, char *, bool, char *); +int be_create_from_existing(libbe_handle_t *, const char *, const char *); +int be_create_from_existing_snap(libbe_handle_t *, const char *, const char *); +int be_snapshot(libbe_handle_t *, const char *, const char *, bool, char *); /* Bootenv manipulation functions */ int be_rename(libbe_handle_t *, char *, char *); @@ -103,9 +104,9 @@ const char *libbe_error_description(libbe_handle_t *); void libbe_print_on_error(libbe_handle_t *, bool); /* Utility Functions */ -int be_root_concat(libbe_handle_t *, char *, char *); -int be_validate_name(libbe_handle_t *, char *); -int be_validate_snap(libbe_handle_t *, char *); +int be_root_concat(libbe_handle_t *, const char *, char *); +int be_validate_name(libbe_handle_t * __unused, const char *); +int be_validate_snap(libbe_handle_t *, const char *); bool be_exists(libbe_handle_t *, char *); int be_export(libbe_handle_t *, char *, int fd); diff --git a/lib/libbe/be_access.c b/lib/libbe/be_access.c index ebd196f99dec..58176a948222 100644 --- a/lib/libbe/be_access.c +++ b/lib/libbe/be_access.c @@ -38,12 +38,11 @@ be_mount(libbe_handle_t *lbh, char *bootenv, char *mountpoint, int flags, { char be[BE_MAXPATHLEN]; char mnt_temp[BE_MAXPATHLEN]; - zfs_handle_t *zfs_hdl; char *path; int mntflags; int err; - if (err = be_root_concat(lbh, bootenv, be)) + if ((err = be_root_concat(lbh, bootenv, be)) != 0) return (set_error(lbh, err)); if (!be_exists(lbh, bootenv)) @@ -63,8 +62,8 @@ be_mount(libbe_handle_t *lbh, char *bootenv, char *mountpoint, int flags, } char opt = '\0'; - if (err = zmount(be, (mountpoint == NULL) ? mnt_temp : mountpoint, - mntflags, MNTTYPE_ZFS, NULL, 0, &opt, 1)) + if ((err = zmount(be, (mountpoint == NULL) ? mnt_temp : mountpoint, + mntflags, __DECONST(char *, MNTTYPE_ZFS), NULL, 0, &opt, 1)) != 0) /* * XXX TODO: zmount returns the nmount error, look into what * kind of errors we can report from that @@ -90,7 +89,7 @@ be_unmount(libbe_handle_t *lbh, char *bootenv, int flags) int mntsize; char *mntpath; - if (err = be_root_concat(lbh, bootenv, be)) + if ((err = be_root_concat(lbh, bootenv, be)) != 0) return (set_error(lbh, err)); if ((mntsize = getmntinfo(&mntbuf, MNT_NOWAIT)) == 0) @@ -114,7 +113,7 @@ be_unmount(libbe_handle_t *lbh, char *bootenv, int flags) mntflags = (flags & BE_MNT_FORCE) ? MNT_FORCE : 0; - if (err = unmount(mntpath, mntflags)) + if ((err = unmount(mntpath, mntflags)) != 0) /* XXX TODO correct error */ return (set_error(lbh, BE_ERR_NOMOUNT)); diff --git a/lib/libbe/be_impl.h b/lib/libbe/be_impl.h index 923b34d50a8a..73f5c22e386e 100644 --- a/lib/libbe/be_impl.h +++ b/lib/libbe/be_impl.h @@ -46,9 +46,9 @@ struct libbe_handle { struct libbe_deep_clone { libbe_handle_t *lbh; - char *bename; - char *snapname; - char *be_root; + const char *bename; + const char *snapname; + const char *be_root; }; struct libbe_dccb { diff --git a/lib/libbe/be_info.c b/lib/libbe/be_info.c index 6a7e445a5d56..644a93510cdf 100644 --- a/lib/libbe/be_info.c +++ b/lib/libbe/be_info.c @@ -119,7 +119,7 @@ prop_list_builder_cb(zfs_handle_t *zfs_hdl, void *data_p) libbe_handle_t *lbh; nvlist_t *props; const char *dataset, *name; - boolean_t mounted, active, nextboot; + boolean_t mounted; /* * XXX TODO: diff --git a/lib/libbe/libbe.3 b/lib/libbe/libbe.3 index 191840b60338..2ddb2b0a0c58 100644 --- a/lib/libbe/libbe.3 +++ b/lib/libbe/libbe.3 @@ -30,7 +30,7 @@ .\" .\" $FreeBSD$ .\" -.Dd August 28, 2017 +.Dd July 25, 2018 .Dt LIBBE 3 .Os .Sh NAME @@ -76,7 +76,7 @@ of state to be retained, such as errors from previous operations. .Fn be_create "libbe_handle_t *, char *" ; .Pp .Ft int -.Fn be_create_from_existing "libbe_handle_t *, char *, char *" ; +.Fn be_create_from_existing "libbe_handle_t *, const char *, const char *" ; .Pp .Ft int .Fn be_rename "libbe_handle_t *, char *, char *" ; @@ -109,13 +109,13 @@ of state to be retained, such as errors from previous operations. .Fn libbe_print_on_error "libbe_handle_t *, bool" ; .Pp .Ft int -.Fn be_root_concat "libbe_handle_t *, char *, char *" ; +.Fn be_root_concat "libbe_handle_t *, const char *, char *" ; .Pp .Ft int -.Fn be_validate_name "libbe_handle_t *, char *" ; +.Fn be_validate_name "libbe_handle_t *, const char *" ; .Pp .Ft int -.Fn be_validate_snap "libbe_handle_t *, char *" ; +.Fn be_validate_snap "libbe_handle_t *, const char *" ; .Pp .Ft bool .Fn be_exists "libbe_handle_t *, char *" ; |