Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 8 Aug 2018 03:25:10 +0000 (UTC)
From:      Kyle Evans <kevans@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-projects@freebsd.org
Subject:   svn commit: r337445 - projects/bectl/lib/libbe
Message-ID:  <201808080325.w783PAfg060419@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: kevans
Date: Wed Aug  8 03:25:10 2018
New Revision: 337445
URL: https://svnweb.freebsd.org/changeset/base/337445

Log:
  libbe(3): Clarify some errors
  
  While here, fix a bug with 'rename' that checked the wrong name for being
  the active BE.

Modified:
  projects/bectl/lib/libbe/be.c
  projects/bectl/lib/libbe/be.h
  projects/bectl/lib/libbe/be_error.c

Modified: projects/bectl/lib/libbe/be.c
==============================================================================
--- projects/bectl/lib/libbe/be.c	Wed Aug  8 03:11:13 2018	(r337444)
+++ projects/bectl/lib/libbe/be.c	Wed Aug  8 03:25:10 2018	(r337445)
@@ -287,7 +287,14 @@ be_snapshot(libbe_handle_t *lbh, const char *source, c
 			return (set_error(lbh, BE_ERR_INVALIDNAME));
 
 		default:
-			/* XXX TODO: elaborate return codes */
+			/*
+			 * The other errors that zfs_ioc_snapshot might return
+			 * shouldn't happen if we've set things up properly, so
+			 * we'll gloss over them and call it UNKNOWN as it will
+			 * require further triage.
+			 */
+			if (errno == ENOTSUP)
+				return (set_error(lbh, BE_ERR_NOPOOL));
 			return (set_error(lbh, BE_ERR_UNKNOWN));
 		}
 	}
@@ -598,22 +605,18 @@ be_rename(libbe_handle_t *lbh, char *old, char *new)
 	if ((err = be_root_concat(lbh, new, full_new)) != 0)
 		return (set_error(lbh, err));
 
-	if (be_validate_name(lbh, new) != 0)
-		return (BE_ERR_UNKNOWN);
-		/* XXX TODO set and return correct error */
+	if ((err = be_validate_name(lbh, new)) != 0)
+		return (err);
 
 	/* Check if old is active BE */
-	if (strcmp(full_new, be_active_path(lbh)) == 0)
-		return (BE_ERR_UNKNOWN);
-		/* XXX TODO set and return correct error */
+	if (strcmp(full_old, be_active_path(lbh)) == 0)
+		return (set_error(lbh, BE_ERR_MOUNTED));
 
 	if (!zfs_dataset_exists(lbh->lzh, full_old, ZFS_TYPE_DATASET))
-		return (BE_ERR_UNKNOWN);
-		/* XXX TODO set and return correct error */
+		return (set_error(lbh, BE_ERR_NOENT));
 
 	if (zfs_dataset_exists(lbh->lzh, full_new, ZFS_TYPE_DATASET))
-		return (BE_ERR_UNKNOWN);
-		/* XXX TODO set and return correct error */
+		return (set_error(lbh, BE_ERR_EXISTS));
 
 	/* XXX TODO
 	 * - What about mounted BEs?
@@ -621,14 +624,11 @@ be_rename(libbe_handle_t *lbh, char *old, char *new)
 	 */
 	if ((zfs_hdl = zfs_open(lbh->lzh, full_old,
 	    ZFS_TYPE_FILESYSTEM)) == NULL)
-		return (BE_ERR_UNKNOWN);
-		/* XXX TODO set and return correct error */
+		return (set_error(lbh, BE_ERR_ZFSOPEN));
 
-
 	/* recurse, nounmount, forceunmount */
 	struct renameflags flags = { 0, 0, 0 };
 
-	/* XXX TODO: error log on this call */
 	err = zfs_rename(zfs_hdl, NULL, full_new, flags);
 
 	zfs_close(zfs_hdl);

Modified: projects/bectl/lib/libbe/be.h
==============================================================================
--- projects/bectl/lib/libbe/be.h	Wed Aug  8 03:11:13 2018	(r337444)
+++ projects/bectl/lib/libbe/be.h	Wed Aug  8 03:25:10 2018	(r337445)
@@ -56,6 +56,7 @@ typedef enum be_error {
 	BE_ERR_ZFSOPEN,         /* calling zfs_open() failed */
 	BE_ERR_ZFSCLONE,        /* error when calling zfs_clone to create be */
 	BE_ERR_IO,		/* error when doing some I/O operation */
+	BE_ERR_NOPOOL,		/* operation not supported on this pool */
 	BE_ERR_UNKNOWN,         /* unknown error */
 } be_error_t;
 

Modified: projects/bectl/lib/libbe/be_error.c
==============================================================================
--- projects/bectl/lib/libbe/be_error.c	Wed Aug  8 03:11:13 2018	(r337444)
+++ projects/bectl/lib/libbe/be_error.c	Wed Aug  8 03:25:10 2018	(r337445)
@@ -96,6 +96,9 @@ libbe_error_description(libbe_handle_t *lbh)
 	case BE_ERR_IO:
 		return ("input/output error");
 
+	case BE_ERR_NOPOOL:
+		return ("operation not supported on this pool");
+
 	case BE_ERR_UNKNOWN:
 		return ("unknown error");
 



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