19 |
19 |
* CDDL HEADER END
|
20 |
20 |
*/
|
21 |
21 |
/*
|
|
22 |
* Copyright (c) 2013 Andrew Stormont. All rights reserved.
|
22 |
23 |
* Copyright 2010 Sun Microsystems, Inc. All rights reserved.
|
23 |
24 |
* Use is subject to license terms.
|
24 |
25 |
*/
|
... | ... | |
58 |
59 |
#include <assert.h>
|
59 |
60 |
#include <errno.h>
|
60 |
61 |
#include <fcntl.h>
|
|
62 |
#include <libbe.h>
|
61 |
63 |
#include <libgen.h>
|
62 |
64 |
#include <libscf.h>
|
63 |
65 |
#include <libscf_priv.h>
|
... | ... | |
117 |
119 |
#define FMRI_STARTD_CONTRACT \
|
118 |
120 |
"svc:/system/svc/restarter:default/:properties/restarter/contract"
|
119 |
121 |
|
120 |
|
#define BEADM_PROG "/usr/sbin/beadm"
|
121 |
122 |
#define BOOTADM_PROG "/sbin/bootadm"
|
122 |
123 |
#define ZONEADM_PROG "/usr/sbin/zoneadm"
|
123 |
124 |
|
... | ... | |
951 |
952 |
static int
|
952 |
953 |
fastboot_bename(const char *bename, char *mountpoint, size_t mpsz)
|
953 |
954 |
{
|
954 |
|
int rc;
|
|
955 |
int err;
|
|
956 |
nvlist_t *be_attrs;
|
|
957 |
|
|
958 |
/*
|
|
959 |
* Build list containing boot environment details for libbe
|
|
960 |
* Note: BE_ATTR_MOUNTPOINT is only used by be_mount call
|
|
961 |
*/
|
|
962 |
err = nvlist_alloc(&be_attrs, NV_UNIQUE_NAME, 0);
|
|
963 |
if (err != 0) {
|
|
964 |
(void) fprintf(stderr,
|
|
965 |
gettext("%s: Unable to allocate be_attrs\n"),
|
|
966 |
cmdname);
|
|
967 |
return (1);
|
|
968 |
}
|
|
969 |
|
|
970 |
err = nvlist_add_string(be_attrs, BE_ATTR_ORIG_BE_NAME, bename);
|
|
971 |
if (err != 0) {
|
|
972 |
nvlist_free(be_attrs);
|
|
973 |
(void) fprintf(stderr,
|
|
974 |
gettext("%s: Unable to set bename in be_attrs\n"),
|
|
975 |
cmdname);
|
|
976 |
return (1);
|
|
977 |
}
|
|
978 |
|
|
979 |
err = nvlist_add_string(be_attrs, BE_ATTR_MOUNTPOINT,
|
|
980 |
FASTBOOT_MOUNTPOINT);
|
|
981 |
if (err != 0) {
|
|
982 |
nvlist_free(be_attrs);
|
|
983 |
(void) fprintf(stderr,
|
|
984 |
gettext("%s: Unable to set mountpoint in be_attrs\n"),
|
|
985 |
cmdname);
|
|
986 |
return (1);
|
|
987 |
}
|
955 |
988 |
|
956 |
989 |
/*
|
957 |
990 |
* Attempt to unmount the BE first in case it's already mounted
|
958 |
991 |
* elsewhere.
|
959 |
992 |
*/
|
960 |
|
(void) halt_exec(BEADM_PROG, "umount", bename, NULL);
|
|
993 |
err = be_unmount(be_attrs);
|
|
994 |
if (err != BE_SUCCESS && err != BE_ERR_NOTMOUNTED) {
|
|
995 |
nvlist_free(be_attrs);
|
|
996 |
(void) fprintf(stderr,
|
|
997 |
gettext("%s: Unable to unmount BE \"%s\"\n"),
|
|
998 |
cmdname, bename);
|
|
999 |
return (1);
|
|
1000 |
}
|
961 |
1001 |
|
962 |
|
if ((rc = halt_exec(BEADM_PROG, "mount", bename, FASTBOOT_MOUNTPOINT,
|
963 |
|
NULL)) != 0)
|
|
1002 |
/*
|
|
1003 |
* Mount the boot environment for use by fastboot
|
|
1004 |
*/
|
|
1005 |
err = be_mount(be_attrs);
|
|
1006 |
if (err != BE_SUCCESS) {
|
|
1007 |
nvlist_free(be_attrs);
|
964 |
1008 |
(void) fprintf(stderr,
|
965 |
1009 |
gettext("%s: Unable to mount BE \"%s\" at %s\n"),
|
966 |
1010 |
cmdname, bename, FASTBOOT_MOUNTPOINT);
|
967 |
|
else
|
968 |
|
(void) strlcpy(mountpoint, FASTBOOT_MOUNTPOINT, mpsz);
|
|
1011 |
return (1);
|
|
1012 |
}
|
969 |
1013 |
|
970 |
|
return (rc);
|
|
1014 |
(void) strlcpy(mountpoint, FASTBOOT_MOUNTPOINT, mpsz);
|
|
1015 |
nvlist_free(be_attrs);
|
|
1016 |
return (0);
|
971 |
1017 |
}
|
972 |
1018 |
|
973 |
1019 |
/*
|
... | ... | |
1663 |
1709 |
|
1664 |
1710 |
if (fast_reboot == 1) {
|
1665 |
1711 |
if (bename) {
|
1666 |
|
(void) halt_exec(BEADM_PROG, "umount", bename, NULL);
|
|
1712 |
int err;
|
|
1713 |
nvlist_t *be_attrs;
|
1667 |
1714 |
|
|
1715 |
/*
|
|
1716 |
* Build list containing boot environment details
|
|
1717 |
*/
|
|
1718 |
err = nvlist_alloc(&be_attrs, NV_UNIQUE_NAME, 0);
|
|
1719 |
if (err != 0) {
|
|
1720 |
(void) fprintf(stderr,
|
|
1721 |
gettext("%s: Unable to allocate "
|
|
1722 |
"beattrs\n"), cmdname);
|
|
1723 |
return (1);
|
|
1724 |
}
|
|
1725 |
err = nvlist_add_string(be_attrs,
|
|
1726 |
BE_ATTR_ORIG_BE_NAME, bename);
|
|
1727 |
if (err != 0) {
|
|
1728 |
nvlist_free(be_attrs);
|
|
1729 |
(void) fprintf(stderr,
|
|
1730 |
gettext("%s: Unable to set bename in "
|
|
1731 |
"be_attrs\n"), cmdname);
|
|
1732 |
return (1);
|
|
1733 |
}
|
|
1734 |
|
|
1735 |
/*
|
|
1736 |
* Attempt to unmount the BE
|
|
1737 |
*/
|
|
1738 |
err = be_unmount(be_attrs);
|
|
1739 |
if (err != BE_SUCCESS && err != BE_ERR_NOTMOUNTED) {
|
|
1740 |
nvlist_free(be_attrs);
|
|
1741 |
(void) fprintf(stderr,
|
|
1742 |
gettext("%s: Unable to unmount BE "
|
|
1743 |
"\"%s\"\n"), cmdname, bename);
|
|
1744 |
return (1);
|
|
1745 |
}
|
|
1746 |
|
|
1747 |
nvlist_free(be_attrs);
|
|
1748 |
return (1);
|
1668 |
1749 |
} else if (strlen(fastboot_mounted) != 0) {
|
1669 |
1750 |
(void) umount(fastboot_mounted);
|
1670 |
1751 |
#if defined(__i386)
|