From owner-svn-src-projects@freebsd.org Fri Aug 10 04:01:42 2018 Return-Path: Delivered-To: svn-src-projects@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 213A210596D4 for ; Fri, 10 Aug 2018 04:01:42 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id C67B876C10; Fri, 10 Aug 2018 04:01:41 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id A73C622FA0; Fri, 10 Aug 2018 04:01:41 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w7A41fjX085949; Fri, 10 Aug 2018 04:01:41 GMT (envelope-from kevans@FreeBSD.org) Received: (from kevans@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w7A41fL6085947; Fri, 10 Aug 2018 04:01:41 GMT (envelope-from kevans@FreeBSD.org) Message-Id: <201808100401.w7A41fL6085947@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kevans set sender to kevans@FreeBSD.org using -f From: Kyle Evans Date: Fri, 10 Aug 2018 04:01:41 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org Subject: svn commit: r337563 - projects/bectl/lib/libbe X-SVN-Group: projects X-SVN-Commit-Author: kevans X-SVN-Commit-Paths: projects/bectl/lib/libbe X-SVN-Commit-Revision: 337563 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 10 Aug 2018 04:01:42 -0000 Author: kevans Date: Fri Aug 10 04:01:40 2018 New Revision: 337563 URL: https://svnweb.freebsd.org/changeset/base/337563 Log: libbe(3): more small cleanup, const'ify and light style(9) Modified: projects/bectl/lib/libbe/be.c projects/bectl/lib/libbe/be.h Modified: projects/bectl/lib/libbe/be.c ============================================================================== --- projects/bectl/lib/libbe/be.c Fri Aug 10 03:28:40 2018 (r337562) +++ projects/bectl/lib/libbe/be.c Fri Aug 10 04:01:40 2018 (r337563) @@ -202,7 +202,7 @@ be_destroy_cb(zfs_handle_t *zfs_hdl, void *data) * BE_DESTROY_FORCE : forces operation on mounted datasets */ int -be_destroy(libbe_handle_t *lbh, char *name, int options) +be_destroy(libbe_handle_t *lbh, const char *name, int options) { zfs_handle_t *fs; char path[BE_MAXPATHLEN]; @@ -307,7 +307,7 @@ be_snapshot(libbe_handle_t *lbh, const char *source, c * Create the boot environment specified by the name parameter */ int -be_create(libbe_handle_t *lbh, char *name) +be_create(libbe_handle_t *lbh, const char *name) { int err; @@ -328,11 +328,8 @@ be_deep_clone_prop(int prop, void *cb) dccb = cb; /* Skip some properties we don't want to touch */ - switch (prop) { - case ZFS_PROP_CANMOUNT: - return (ZPROP_CONT); - break; - } + if (prop == ZFS_PROP_CANMOUNT) + return (ZPROP_CONT); /* Don't copy readonly properties */ if (zfs_prop_readonly(prop)) @@ -593,7 +590,7 @@ be_validate_name(libbe_handle_t *lbh __unused, const c * usage */ int -be_rename(libbe_handle_t *lbh, char *old, char *new) +be_rename(libbe_handle_t *lbh, const char *old, const char *new) { char full_old[BE_MAXPATHLEN]; char full_new[BE_MAXPATHLEN]; @@ -638,7 +635,7 @@ be_rename(libbe_handle_t *lbh, char *old, char *new) int -be_export(libbe_handle_t *lbh, char *bootenv, int fd) +be_export(libbe_handle_t *lbh, const char *bootenv, int fd) { char snap_name[BE_MAXPATHLEN]; char buf[BE_MAXPATHLEN]; @@ -660,7 +657,7 @@ be_export(libbe_handle_t *lbh, char *bootenv, int fd) int -be_import(libbe_handle_t *lbh, char *bootenv, int fd) +be_import(libbe_handle_t *lbh, const char *bootenv, int fd) { char buf[BE_MAXPATHLEN]; time_t rawtime; @@ -723,14 +720,16 @@ be_import(libbe_handle_t *lbh, char *bootenv, int fd) int -be_add_child(libbe_handle_t *lbh, char *child_path, bool cp_if_exists) +be_add_child(libbe_handle_t *lbh, const char *child_path, bool cp_if_exists) { + struct stat sb; char active[BE_MAXPATHLEN]; char buf[BE_MAXPATHLEN]; nvlist_t *props; + const char *s; zfs_handle_t *zfs; - struct stat sb; - int err; + long snap_name; + int err, pos; /* Require absolute paths */ if (*child_path != '/') @@ -741,7 +740,7 @@ be_add_child(libbe_handle_t *lbh, char *child_path, bo strcpy(buf, active); /* Create non-mountable parent dataset(s) */ - char *s = child_path; + s = child_path; for (char *p; (p = strchr(s+1, '/')) != NULL; s = p) { size_t len = p - s; strncat(buf, s, len); @@ -753,9 +752,8 @@ be_add_child(libbe_handle_t *lbh, char *child_path, bo nvlist_free(props); } - /* Path does not exist as a descendent of / yet */ - int pos = strlen(active); + pos = strlen(active); /* XXX TODO: Verify that resulting str is less than BE_MAXPATHLEN */ strncpy(&active[pos], child_path, BE_MAXPATHLEN-pos); @@ -797,7 +795,7 @@ be_add_child(libbe_handle_t *lbh, char *child_path, bo */ /* XXX TODO: use mktemp */ - long int snap_name = random(); + snap_name = random(); snprintf(buf, BE_MAXPATHLEN, "%s@%ld", child_path, snap_name); @@ -854,7 +852,7 @@ be_set_nextboot(libbe_handle_t *lbh, nvlist_t *config, int -be_activate(libbe_handle_t *lbh, char *bootenv, bool temporary) +be_activate(libbe_handle_t *lbh, const char *bootenv, bool temporary) { char be_path[BE_MAXPATHLEN]; char buf[BE_MAXPATHLEN]; Modified: projects/bectl/lib/libbe/be.h ============================================================================== --- projects/bectl/lib/libbe/be.h Fri Aug 10 03:28:40 2018 (r337562) +++ projects/bectl/lib/libbe/be.h Fri Aug 10 04:01:40 2018 (r337563) @@ -78,16 +78,16 @@ int be_get_dataset_snapshots(libbe_handle_t *, const c int be_prop_list_alloc(nvlist_t **be_list); void be_prop_list_free(nvlist_t *be_list); -int be_activate(libbe_handle_t *, char *, bool); +int be_activate(libbe_handle_t *, const char *, bool); /* Bootenv creation functions */ -int be_create(libbe_handle_t *, char *); +int be_create(libbe_handle_t *, const 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 *); +int be_rename(libbe_handle_t *, const char *, const char *); /* Bootenv removal functions */ @@ -95,7 +95,7 @@ typedef enum { BE_DESTROY_FORCE = 1 << 0, } be_destroy_opt_t; -int be_destroy(libbe_handle_t *, char *, int); +int be_destroy(libbe_handle_t *, const char *, int); /* Bootenv mounting functions: be_access.c */ @@ -119,10 +119,10 @@ int be_validate_name(libbe_handle_t * __unused, const 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); -int be_import(libbe_handle_t *, char *, int fd); +int be_export(libbe_handle_t *, const char *, int fd); +int be_import(libbe_handle_t *, const char *, int fd); -int be_add_child(libbe_handle_t *, char *, bool); +int be_add_child(libbe_handle_t *, const char *, bool); void be_nicenum(uint64_t num, char *buf, size_t buflen); #endif /* _LIBBE_H */