6668666 zpool command should put a bootblock on a disk added as a mirror of a root pool vdev
authorLori Alt <lori.alt@oracle.com>
Mon, 19 Jul 2010 20:27:25 -0600
changeset 12877 08987220809a
parent 12876 78ceb0079fba
child 12878 87e07d18c459
6668666 zpool command should put a bootblock on a disk added as a mirror of a root pool vdev
usr/src/cmd/fs.d/zfs/Makefile
usr/src/cmd/fs.d/zfs/bootinstall/Makefile
usr/src/cmd/fs.d/zfs/bootinstall/bootinstall.sh
usr/src/cmd/fs.d/zfs/bootinstall/etc/Makefile
usr/src/cmd/fs.d/zfs/bootinstall/etc/SUNW,EC_zfs,ESC_ZFS_bootfs_vdev_attach,sysevent.conf
usr/src/lib/libzfs/common/libzfs_pool.c
usr/src/pkg/manifests/system-file-system-zfs.mf
usr/src/uts/common/fs/zfs/spa.c
usr/src/uts/common/sys/sysevent/eventdefs.h
--- a/usr/src/cmd/fs.d/zfs/Makefile	Mon Jul 19 18:52:59 2010 -0700
+++ b/usr/src/cmd/fs.d/zfs/Makefile	Mon Jul 19 20:27:25 2010 -0600
@@ -23,7 +23,7 @@
 # Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
 #
 
-SUBDIRS=	fstyp
+SUBDIRS=	fstyp bootinstall
 
 all:=		TARGET= all
 install:=	TARGET= install
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/cmd/fs.d/zfs/bootinstall/Makefile	Mon Jul 19 20:27:25 2010 -0600
@@ -0,0 +1,50 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+#
+
+FSTYPE=		zfs
+LIBPROG=	bootinstall
+SRCS=		bootinstall.sh
+SUBDIRS=	etc
+
+all :=		TARGET = all
+install :=	TARGET = install
+clean :=	TARGET = clean
+clobber :=	TARGET = clobber
+lint :=		TARGET = lint
+
+.KEEP_STATE:
+
+include		../../Makefile.fstype
+
+all:		$(SUBDIRS) $(LIBPROG)
+
+install:	$(SUBDIRS)
+
+clean:
+	$(RM) $(LIBPROG)
+
+$(SUBDIRS): FRC
+	@cd $@; pwd; $(MAKE) $(TARGET)
+FRC:
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/cmd/fs.d/zfs/bootinstall/bootinstall.sh	Mon Jul 19 20:27:25 2010 -0600
@@ -0,0 +1,71 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+#
+
+PATH="/usr/bin:/usr/sbin:${PATH}"; export PATH
+ARCH=$(uname -p)
+KARCH=$(uname -m)
+
+if [ "$ARCH" != "i386" -a "$ARCH" != "sparc" ] ; then
+	echo "Unknown architecture: $ARCH"
+	exit 1
+fi
+
+POOL="$1"
+DEV=$(echo "$2" | sed -e 's+/dsk/+/rdsk/+')
+
+if [ -z "${POOL}" -o -z "${DEV}" ]; then
+	echo "Invalid usage"
+	exit 1
+fi
+
+CURPOOL=$(df -k / | awk 'NR == 2 {print $1}' | sed 's,/.*,,')
+
+if [ "$CURPOOL" != "$POOL" ] ; then
+	echo "Modified pool must be current root pool"
+	exit 1
+fi
+
+#
+# 
+
+if [ "${ARCH}" = "i386" ]; then
+	STAGE1=/boot/grub/stage1
+	STAGE2=/boot/grub/stage2
+	/sbin/installgrub ${STAGE1} ${STAGE2} ${DEV}
+	if [ $? != 0 ]; then
+		echo "Failure installing GRUB on ${DEV}"
+		exit 1
+	fi
+else
+	BOOTBLK=/usr/platform/${KARCH}/lib/fs/zfs/bootblk
+	/usr/sbin/installboot -F zfs ${BOOTBLK} ${DEV}
+	if [ $? != 0 ]; then
+		echo "Failure installing boot block on ${DEV}"
+		exit 
+	fi
+fi
+
+exit 0
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/cmd/fs.d/zfs/bootinstall/etc/Makefile	Mon Jul 19 20:27:25 2010 -0600
@@ -0,0 +1,44 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+#
+# Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+#
+
+.PARALLEL:
+
+include $(SRC)/cmd/Makefile.cmd
+
+CONF = SUNW,EC_zfs,ESC_ZFS_bootfs_vdev_attach,sysevent.conf
+CONFDIR = $(ROOTETC)/sysevent/config
+
+# utilize the predefined install target patterns in cmd/Makefile.targ by
+# overriding ROOTCMDDIR
+#
+ROOTCMDDIR = $(CONFDIR)
+FILEMODE = 0644
+
+.KEEP_STATE:
+
+all clean clobber lint:
+
+install: $(CONF:%=$(CONFDIR)/%)
+
+include $(SRC)/cmd/Makefile.targ
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/cmd/fs.d/zfs/bootinstall/etc/SUNW,EC_zfs,ESC_ZFS_bootfs_vdev_attach,sysevent.conf	Mon Jul 19 20:27:25 2010 -0600
@@ -0,0 +1,24 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+# Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+#
+
+EC_zfs ESC_ZFS_bootfs_vdev_attach SUNW - - - - /usr/lib/fs/zfs/bootinstall $pool_name $vdev_path
--- a/usr/src/lib/libzfs/common/libzfs_pool.c	Mon Jul 19 18:52:59 2010 -0700
+++ b/usr/src/lib/libzfs/common/libzfs_pool.c	Mon Jul 19 20:27:25 2010 -0600
@@ -44,12 +44,6 @@
 
 static int read_efi_label(nvlist_t *config, diskaddr_t *sb);
 
-#if defined(__i386) || defined(__amd64)
-#define	BOOTCMD	"installgrub(1M)"
-#else
-#define	BOOTCMD	"installboot(1M)"
-#endif
-
 #define	DISK_ROOT	"/dev/dsk"
 #define	RDISK_ROOT	"/dev/rdsk"
 #define	BACKUP_SLICE	"s2"
@@ -2379,15 +2373,6 @@
 	if (ret == 0) {
 		if (rootpool) {
 			/*
-			 * XXX - This should be removed once we can
-			 * automatically install the bootblocks on the
-			 * newly attached disk.
-			 */
-			(void) fprintf(stderr, dgettext(TEXT_DOMAIN, "Please "
-			    "be sure to invoke %s to make '%s' bootable.\n"),
-			    BOOTCMD, new_disk);
-
-			/*
 			 * XXX need a better way to prevent user from
 			 * booting up a half-baked vdev.
 			 */
--- a/usr/src/pkg/manifests/system-file-system-zfs.mf	Mon Jul 19 18:52:59 2010 -0700
+++ b/usr/src/pkg/manifests/system-file-system-zfs.mf	Mon Jul 19 20:27:25 2010 -0600
@@ -74,6 +74,8 @@
 $(i386_ONLY)dir path=usr/sbin/$(ARCH32)
 dir path=usr/sbin/$(ARCH64)
 driver name=zfs perms="* 0600 root sys" perms="zfs 0666 root sys"
+file path=etc/sysevent/config/SUNW,EC_zfs,ESC_ZFS_bootfs_vdev_attach,sysevent.conf \
+    group=sys
 file path=kernel/drv/$(ARCH64)/zfs group=sys
 $(i386_ONLY)file path=kernel/drv/zfs group=sys
 file path=kernel/drv/zfs.conf group=sys
@@ -89,6 +91,7 @@
 file path=usr/lib/$(ARCH64)/libzfs_jni.so.1
 file path=usr/lib/$(ARCH64)/libzpool.so.1
 file path=usr/lib/devfsadm/linkmod/SUNW_zfs_link.so group=sys
+file path=usr/lib/fs/zfs/bootinstall mode=0555
 file path=usr/lib/fs/zfs/fstyp.so.1 mode=0555
 file path=usr/lib/libzfs_jni.so.1
 $(i386_ONLY)file path=usr/lib/libzpool.so.1
--- a/usr/src/uts/common/fs/zfs/spa.c	Mon Jul 19 18:52:59 2010 -0700
+++ b/usr/src/uts/common/fs/zfs/spa.c	Mon Jul 19 20:27:25 2010 -0600
@@ -3837,6 +3837,9 @@
 	spa_strfree(oldvdpath);
 	spa_strfree(newvdpath);
 
+	if (spa->spa_bootfs)
+		spa_event_notify(spa, newvd, ESC_ZFS_BOOTFS_VDEV_ATTACH);
+
 	return (0);
 }
 
--- a/usr/src/uts/common/sys/sysevent/eventdefs.h	Mon Jul 19 18:52:59 2010 -0700
+++ b/usr/src/uts/common/sys/sysevent/eventdefs.h	Mon Jul 19 20:27:25 2010 -0600
@@ -19,8 +19,7 @@
  * CDDL HEADER END
  */
 /*
- * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
- * Use is subject to license terms.
+ * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
  */
 
 #ifndef	_SYS_SYSEVENT_EVENTDEFS_H
@@ -246,16 +245,17 @@
  * ZFS subclass definitions.  supporting attributes (name/value paris) are found
  * in sys/fs/zfs.h
  */
-#define	ESC_ZFS_RESILVER_START	"ESC_ZFS_resilver_start"
-#define	ESC_ZFS_RESILVER_FINISH	"ESC_ZFS_resilver_finish"
-#define	ESC_ZFS_VDEV_REMOVE	"ESC_ZFS_vdev_remove"
-#define	ESC_ZFS_POOL_DESTROY	"ESC_ZFS_pool_destroy"
-#define	ESC_ZFS_VDEV_CLEAR	"ESC_ZFS_vdev_clear"
-#define	ESC_ZFS_VDEV_CHECK	"ESC_ZFS_vdev_check"
-#define	ESC_ZFS_CONFIG_SYNC	"ESC_ZFS_config_sync"
-#define	ESC_ZFS_SCRUB_START	"ESC_ZFS_scrub_start"
-#define	ESC_ZFS_SCRUB_FINISH	"ESC_ZFS_scrub_finish"
-#define	ESC_ZFS_VDEV_SPARE	"ESC_ZFS_vdev_spare"
+#define	ESC_ZFS_RESILVER_START		"ESC_ZFS_resilver_start"
+#define	ESC_ZFS_RESILVER_FINISH		"ESC_ZFS_resilver_finish"
+#define	ESC_ZFS_VDEV_REMOVE		"ESC_ZFS_vdev_remove"
+#define	ESC_ZFS_POOL_DESTROY		"ESC_ZFS_pool_destroy"
+#define	ESC_ZFS_VDEV_CLEAR		"ESC_ZFS_vdev_clear"
+#define	ESC_ZFS_VDEV_CHECK		"ESC_ZFS_vdev_check"
+#define	ESC_ZFS_CONFIG_SYNC		"ESC_ZFS_config_sync"
+#define	ESC_ZFS_SCRUB_START		"ESC_ZFS_scrub_start"
+#define	ESC_ZFS_SCRUB_FINISH		"ESC_ZFS_scrub_finish"
+#define	ESC_ZFS_VDEV_SPARE		"ESC_ZFS_vdev_spare"
+#define	ESC_ZFS_BOOTFS_VDEV_ATTACH	"ESC_ZFS_bootfs_vdev_attach"
 
 /*
  * datalink subclass definitions.