Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 10 Aug 2018 04:01:41 +0000 (UTC)
From:      Kyle Evans <kevans@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-projects@freebsd.org
Subject:   svn commit: r337563 - projects/bectl/lib/libbe
Message-ID:  <201808100401.w7A41fL6085947@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
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 */



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201808100401.w7A41fL6085947>