changeset 13388:6c2fc79987ac

923 bootadm tries to rebuild archives which it shouldn't Reviewed by: Garrett D'Amore <garrett@nexenta.com> Reviewed by: Dan McDonald <danmcd@nexenta.com> Approved by: Albert Lee <trisk@nexenta.com>
author Alexander Eremin <a.eremin@nexenta.com>
date Tue, 14 Jun 2011 14:58:56 -0400
parents 7dd5626b8b49
children 5929916bbfff
files usr/src/cmd/boot/bootadm/Makefile usr/src/cmd/boot/bootadm/bootadm.c
diffstat 2 files changed, 64 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/usr/src/cmd/boot/bootadm/Makefile	Mon Jun 13 18:04:20 2011 -0700
+++ b/usr/src/cmd/boot/bootadm/Makefile	Tue Jun 14 14:58:56 2011 -0400
@@ -22,6 +22,8 @@
 # Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
 # Use is subject to license terms.
 # 
+# Copyright 2011 Nexenta Systems, Inc. All rights reserved.
+#
 
 PROG= bootadm
 
@@ -36,7 +38,7 @@
 .KEEP_STATE:
 
 LDLIBS_i386= -lfdisk
-LDLIBS +=	-lnvpair -lgen -ladm -lefi -lscf -lz $(LDLIBS_$(MACH))
+LDLIBS +=	-lnvpair -lgen -ladm -lefi -lscf -lz -lbe -lzfs $(LDLIBS_$(MACH))
 
 # Writing into string literals is incorrect.  We need to match gcc's
 # behavior, which causes us to take SIGSEGV on such a write.
--- a/usr/src/cmd/boot/bootadm/bootadm.c	Mon Jun 13 18:04:20 2011 -0700
+++ b/usr/src/cmd/boot/bootadm/bootadm.c	Tue Jun 14 14:58:56 2011 -0400
@@ -23,6 +23,10 @@
  */
 
 /*
+ * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
+ */
+
+/*
  * bootadm(1M) is a new utility for managing bootability of
  * Solaris *Newboot* environments. It has two primary tasks:
  * 	- Allow end users to manage bootability of Newboot Solaris instances
@@ -62,6 +66,7 @@
 #include <zlib.h>
 #include <sys/lockfs.h>
 #include <sys/filio.h>
+#include <libbe.h>
 #ifdef i386
 #include <libfdisk.h>
 #endif
@@ -2920,6 +2925,57 @@
 	return (BAM_SUCCESS);
 }
 
+static boolean_t
+is_be(char *root)
+{
+	zfs_handle_t	*zhp;
+	libzfs_handle_t	*hdl;
+	be_node_list_t	*be_nodes = NULL;
+	be_node_list_t	*cur_be;
+	boolean_t	be_exist = B_FALSE;
+	char		ds_path[ZFS_MAXNAMELEN];
+
+	if (!is_zfs(root))
+		return (B_FALSE);
+	/*
+	 * Get dataset for mountpoint
+	 */
+	if ((hdl = libzfs_init()) == NULL)
+		return (B_FALSE);
+
+	if ((zhp = zfs_path_to_zhandle(hdl, root,
+	    ZFS_TYPE_FILESYSTEM)) == NULL) {
+		libzfs_fini(hdl);
+		return (B_FALSE);
+	}
+
+	(void) strlcpy(ds_path, zfs_get_name(zhp), sizeof (ds_path));
+
+	/*
+	 * Check if the current dataset is BE
+	 */
+	if (be_list(NULL, &be_nodes) == BE_SUCCESS) {
+		for (cur_be = be_nodes; cur_be != NULL;
+		    cur_be = cur_be->be_next_node) {
+
+			/*
+			 * Because we guarantee that cur_be->be_root_ds
+			 * is null-terminated by internal data structure,
+			 * we can safely use strcmp()
+			 */
+			if (strcmp(ds_path, cur_be->be_root_ds) == 0) {
+				be_exist = B_TRUE;
+				break;
+			}
+		}
+		be_free_list(be_nodes);
+	}
+	zfs_close(zhp);
+	libzfs_fini(hdl);
+
+	return (be_exist);
+}
+
 /*
  * Returns 1 if mkiso is in the expected PATH, 0 otherwise
  */
@@ -3588,6 +3644,11 @@
 	(void) umask(022);
 
 	/*
+	 * Never update non-BE root in update_all
+	 */
+	if (!is_be(root) && bam_update_all)
+		return (BAM_SUCCESS);
+	/*
 	 * root must belong to a boot archive based OS,
 	 */
 	if (!is_boot_archive(root)) {