usr/src/cmd/zoneadmd/vplat.c
author Gary Pennington <gary.pennington@oracle.com>
Wed, 30 Jun 2010 03:42:01 -0700
changeset 12734 76969fc28795
parent 12725 334fd88ae67c
child 12748 40c62600acd3
permissions -rw-r--r--
6939693 zones no longer needs the inherit-pkg-dir property
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
     1
/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
     2
 * CDDL HEADER START
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
     3
 *
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
     4
 * The contents of this file are subject to the terms of the
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
     5
 * Common Development and Distribution License (the "License").
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
     6
 * You may not use this file except in compliance with the License.
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
     7
 *
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
     8
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
     9
 * or http://www.opensolaris.org/os/licensing.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    10
 * See the License for the specific language governing permissions
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    11
 * and limitations under the License.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    12
 *
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    13
 * When distributing Covered Code, include this CDDL HEADER in each
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    14
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    15
 * If applicable, add the following below this CDDL HEADER, with the
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    16
 * fields enclosed by brackets "[]" replaced with your own identifying
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    17
 * information: Portions Copyright [yyyy] [name of copyright owner]
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    18
 *
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    19
 * CDDL HEADER END
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    20
 */
1645
5c204cdba7d2 PSARC 2006/124 Configurable Privileges for Zones
comay
parents: 1544
diff changeset
    21
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    22
/*
12633
9f2cda0ed938 PSARC 2010/144 lofi(7D) in non global zones
John Levon <john.levon@sun.com>
parents: 11878
diff changeset
    23
 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    24
 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    25
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    26
/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    27
 * This module contains functions used to bring up and tear down the
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    28
 * Virtual Platform: [un]mounting file-systems, [un]plumbing network
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    29
 * interfaces, [un]configuring devices, establishing resource controls,
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    30
 * and creating/destroying the zone in the kernel.  These actions, on
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    31
 * the way up, ready the zone; on the way down, they halt the zone.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    32
 * See the much longer block comment at the beginning of zoneadmd.c
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    33
 * for a bigger picture of how the whole program functions.
766
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
    34
 *
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
    35
 * This module also has primary responsibility for the layout of "scratch
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
    36
 * zones."  These are mounted, but inactive, zones that are used during
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
    37
 * operating system upgrade and potentially other administrative action.  The
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
    38
 * scratch zone environment is similar to the miniroot environment.  The zone's
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
    39
 * actual root is mounted read-write on /a, and the standard paths (/usr,
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
    40
 * /sbin, /lib) all lead to read-only copies of the running system's binaries.
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
    41
 * This allows the administrative tools to manipulate the zone using "-R /a"
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
    42
 * without relying on any binaries in the zone itself.
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
    43
 *
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
    44
 * If the scratch zone is on an alternate root (Live Upgrade [LU] boot
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
    45
 * environment), then we must resolve the lofs mounts used there to uncover
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
    46
 * writable (unshared) resources.  Shared resources, though, are always
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
    47
 * read-only.  In addition, if the "same" zone with a different root path is
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
    48
 * currently running, then "/b" inside the zone points to the running zone's
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
    49
 * root.  This allows LU to synchronize configuration files during the upgrade
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
    50
 * process.
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
    51
 *
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
    52
 * To construct this environment, this module creates a tmpfs mount on
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
    53
 * $ZONEPATH/lu.  Inside this scratch area, the miniroot-like environment as
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
    54
 * described above is constructed on the fly.  The zone is then created using
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
    55
 * $ZONEPATH/lu as the root.
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
    56
 *
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
    57
 * Note that scratch zones are inactive.  The zone's bits are not running and
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
    58
 * likely cannot be run correctly until upgrade is done.  Init is not running
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
    59
 * there, nor is SMF.  Because of this, the "mounted" state of a scratch zone
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
    60
 * is not a part of the usual halt/ready/boot state machine.
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    61
 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    62
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    63
#include <sys/param.h>
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    64
#include <sys/mount.h>
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    65
#include <sys/mntent.h>
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    66
#include <sys/socket.h>
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    67
#include <sys/utsname.h>
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    68
#include <sys/types.h>
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    69
#include <sys/stat.h>
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    70
#include <sys/sockio.h>
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    71
#include <sys/stropts.h>
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    72
#include <sys/conf.h>
8662
18153249ee93 PSARC/2008/647 Configurable Hostids for Non-Global Zones
jv227347 <Jordan.Vaughan@Sun.com>
parents: 8485
diff changeset
    73
#include <sys/systeminfo.h>
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    74
3448
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
    75
#include <libdlpi.h>
3871
5a1dfce6c5cc PSARC 2007/140 libdladm restructure
yz147064
parents: 3813
diff changeset
    76
#include <libdllink.h>
5895
f251acdd9bdc PSARC/2006/499 Clearview Nemo unification and vanity naming
yz147064
parents: 5863
diff changeset
    77
#include <libdlvlan.h>
3448
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
    78
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    79
#include <inet/tcp.h>
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    80
#include <arpa/inet.h>
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    81
#include <netinet/in.h>
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    82
#include <net/route.h>
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    83
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    84
#include <stdio.h>
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    85
#include <errno.h>
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    86
#include <fcntl.h>
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    87
#include <unistd.h>
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    88
#include <rctl.h>
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    89
#include <stdlib.h>
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    90
#include <string.h>
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    91
#include <strings.h>
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    92
#include <wait.h>
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    93
#include <limits.h>
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    94
#include <libgen.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
    95
#include <libzfs.h>
2621
4ea88858d952 PSARC/2003/246 Filesystem Driven Device Naming
llai1
parents: 2611
diff changeset
    96
#include <libdevinfo.h>
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    97
#include <zone.h>
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    98
#include <assert.h>
2303
327ca1e2fdf0 PSARC 2006/387 Zones Features For Zulu
carlsonj
parents: 2267
diff changeset
    99
#include <libcontract.h>
327ca1e2fdf0 PSARC 2006/387 Zones Features For Zulu
carlsonj
parents: 2267
diff changeset
   100
#include <libcontract_priv.h>
327ca1e2fdf0 PSARC 2006/387 Zones Features For Zulu
carlsonj
parents: 2267
diff changeset
   101
#include <uuid/uuid.h>
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   102
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   103
#include <sys/mntio.h>
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   104
#include <sys/mnttab.h>
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   105
#include <sys/fs/autofs.h>	/* for _autofssys() */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   106
#include <sys/fs/lofs_info.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
   107
#include <sys/fs/zfs.h>
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   108
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   109
#include <pool.h>
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   110
#include <sys/pool.h>
3247
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
   111
#include <sys/priocntl.h>
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   112
2712
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
   113
#include <libbrand.h>
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
   114
#include <sys/brand.h>
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   115
#include <libzonecfg.h>
2170
eb691d2a219e PSARC 2005/714 Automounter Scalability Enhancements
evanl
parents: 2082
diff changeset
   116
#include <synch.h>
2611
72abb3d7690c 6367840 Zones does not boot if configured for a failed network interface
vp157776
parents: 2592
diff changeset
   117
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   118
#include "zoneadmd.h"
1676
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
   119
#include <tsol/label.h>
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
   120
#include <libtsnet.h>
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
   121
#include <sys/priv.h>
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   122
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   123
#define	V4_ADDR_LEN	32
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   124
#define	V6_ADDR_LEN	128
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   125
12734
76969fc28795 6939693 zones no longer needs the inherit-pkg-dir property
Gary Pennington <gary.pennington@oracle.com>
parents: 12725
diff changeset
   126
#define	RESOURCE_DEFAULT_OPTS \
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   127
	MNTOPT_RO "," MNTOPT_LOFS_NOSUB "," MNTOPT_NODEVICES
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   128
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   129
#define	DFSTYPES	"/etc/dfs/fstypes"
1676
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
   130
#define	MAXTNZLEN	2048
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   131
5829
20241b1ccadc PSARC 2007/621 zone update on attach
gjelinek
parents: 5596
diff changeset
   132
#define	ALT_MOUNT(mount_cmd) 	((mount_cmd) != Z_MNT_BOOT)
20241b1ccadc PSARC 2007/621 zone update on attach
gjelinek
parents: 5596
diff changeset
   133
12725
334fd88ae67c PSARC 2009/042 max-processes rctl
Menno Lageman <Menno.Lageman@Sun.COM>
parents: 12633
diff changeset
   134
/* a reasonable estimate for the number of lwps per process */
334fd88ae67c PSARC 2009/042 max-processes rctl
Menno Lageman <Menno.Lageman@Sun.COM>
parents: 12633
diff changeset
   135
#define	LWPS_PER_PROCESS	10
334fd88ae67c PSARC 2009/042 max-processes rctl
Menno Lageman <Menno.Lageman@Sun.COM>
parents: 12633
diff changeset
   136
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   137
/* for routing socket */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   138
static int rts_seqno = 0;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   139
766
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   140
/* mangled zone name when mounting in an alternate root environment */
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   141
static char kernzone[ZONENAME_MAX];
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   142
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   143
/* array of cached mount entries for resolve_lofs */
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   144
static struct mnttab *resolve_lofs_mnts, *resolve_lofs_mnt_max;
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   145
1676
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
   146
/* for Trusted Extensions */
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
   147
static tsol_zcent_t *get_zone_label(zlog_t *, priv_set_t *);
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
   148
static int tsol_mounts(zlog_t *, char *, char *);
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
   149
static void tsol_unmounts(zlog_t *, char *);
5596
e1223011b5eb 6616075 ce driver needs to work with solaris 10 IP Instances (ON part)
dh155122
parents: 5576
diff changeset
   150
1676
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
   151
static m_label_t *zlabel = NULL;
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
   152
static m_label_t *zid_label = NULL;
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
   153
static priv_set_t *zprivs = NULL;
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
   154
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   155
/* from libsocket, not in any header file */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   156
extern int getnetmaskbyaddr(struct in_addr, struct in_addr *);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   157
7370
e94ec740675f 6733450 RFE: need more flexible hooks for mounting and booting a zone
<Gerald Jelinek>
parents: 7342
diff changeset
   158
/* from zoneadmd */
e94ec740675f 6733450 RFE: need more flexible hooks for mounting and booting a zone
<Gerald Jelinek>
parents: 7342
diff changeset
   159
extern char query_hook[];
e94ec740675f 6733450 RFE: need more flexible hooks for mounting and booting a zone
<Gerald Jelinek>
parents: 7342
diff changeset
   160
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   161
/*
766
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   162
 * An optimization for build_mnttable: reallocate (and potentially copy the
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   163
 * data) only once every N times through the loop.
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   164
 */
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   165
#define	MNTTAB_HUNK	32
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   166
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   167
/*
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   168
 * Private autofs system call
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   169
 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   170
extern int _autofssys(int, void *);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   171
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   172
static int
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   173
autofs_cleanup(zoneid_t zoneid)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   174
{
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   175
	/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   176
	 * Ask autofs to unmount all trigger nodes in the given zone.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   177
	 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   178
	return (_autofssys(AUTOFS_UNMOUNTALL, (void *)zoneid));
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   179
}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   180
766
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   181
static void
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   182
free_mnttable(struct mnttab *mnt_array, uint_t nelem)
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   183
{
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   184
	uint_t i;
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   185
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   186
	if (mnt_array == NULL)
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   187
		return;
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   188
	for (i = 0; i < nelem; i++) {
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   189
		free(mnt_array[i].mnt_mountp);
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   190
		free(mnt_array[i].mnt_fstype);
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   191
		free(mnt_array[i].mnt_special);
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   192
		free(mnt_array[i].mnt_mntopts);
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   193
		assert(mnt_array[i].mnt_time == NULL);
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   194
	}
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   195
	free(mnt_array);
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   196
}
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   197
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   198
/*
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   199
 * Build the mount table for the zone rooted at "zroot", storing the resulting
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   200
 * array of struct mnttabs in "mnt_arrayp" and the number of elements in the
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   201
 * array in "nelemp".
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   202
 */
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   203
static int
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   204
build_mnttable(zlog_t *zlogp, const char *zroot, size_t zrootlen, FILE *mnttab,
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   205
    struct mnttab **mnt_arrayp, uint_t *nelemp)
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   206
{
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   207
	struct mnttab mnt;
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   208
	struct mnttab *mnts;
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   209
	struct mnttab *mnp;
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   210
	uint_t nmnt;
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   211
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   212
	rewind(mnttab);
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   213
	resetmnttab(mnttab);
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   214
	nmnt = 0;
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   215
	mnts = NULL;
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   216
	while (getmntent(mnttab, &mnt) == 0) {
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   217
		struct mnttab *tmp_array;
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   218
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   219
		if (strncmp(mnt.mnt_mountp, zroot, zrootlen) != 0)
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   220
			continue;
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   221
		if (nmnt % MNTTAB_HUNK == 0) {
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   222
			tmp_array = realloc(mnts,
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   223
			    (nmnt + MNTTAB_HUNK) * sizeof (*mnts));
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   224
			if (tmp_array == NULL) {
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   225
				free_mnttable(mnts, nmnt);
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   226
				return (-1);
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   227
			}
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   228
			mnts = tmp_array;
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   229
		}
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   230
		mnp = &mnts[nmnt++];
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   231
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   232
		/*
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   233
		 * Zero out any fields we're not using.
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   234
		 */
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   235
		(void) memset(mnp, 0, sizeof (*mnp));
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   236
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   237
		if (mnt.mnt_special != NULL)
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   238
			mnp->mnt_special = strdup(mnt.mnt_special);
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   239
		if (mnt.mnt_mntopts != NULL)
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   240
			mnp->mnt_mntopts = strdup(mnt.mnt_mntopts);
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   241
		mnp->mnt_mountp = strdup(mnt.mnt_mountp);
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   242
		mnp->mnt_fstype = strdup(mnt.mnt_fstype);
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   243
		if ((mnt.mnt_special != NULL && mnp->mnt_special == NULL) ||
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   244
		    (mnt.mnt_mntopts != NULL && mnp->mnt_mntopts == NULL) ||
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   245
		    mnp->mnt_mountp == NULL || mnp->mnt_fstype == NULL) {
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   246
			zerror(zlogp, B_TRUE, "memory allocation failed");
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   247
			free_mnttable(mnts, nmnt);
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   248
			return (-1);
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   249
		}
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   250
	}
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   251
	*mnt_arrayp = mnts;
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   252
	*nelemp = nmnt;
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   253
	return (0);
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   254
}
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   255
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   256
/*
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   257
 * This is an optimization.  The resolve_lofs function is used quite frequently
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   258
 * to manipulate file paths, and on a machine with a large number of zones,
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   259
 * there will be a huge number of mounted file systems.  Thus, we trigger a
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   260
 * reread of the list of mount points
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   261
 */
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   262
static void
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   263
lofs_discard_mnttab(void)
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   264
{
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   265
	free_mnttable(resolve_lofs_mnts,
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   266
	    resolve_lofs_mnt_max - resolve_lofs_mnts);
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   267
	resolve_lofs_mnts = resolve_lofs_mnt_max = NULL;
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   268
}
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   269
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   270
static int
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   271
lofs_read_mnttab(zlog_t *zlogp)
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   272
{
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   273
	FILE *mnttab;
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   274
	uint_t nmnts;
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   275
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   276
	if ((mnttab = fopen(MNTTAB, "r")) == NULL)
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   277
		return (-1);
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   278
	if (build_mnttable(zlogp, "", 0, mnttab, &resolve_lofs_mnts,
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   279
	    &nmnts) == -1) {
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   280
		(void) fclose(mnttab);
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   281
		return (-1);
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   282
	}
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   283
	(void) fclose(mnttab);
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   284
	resolve_lofs_mnt_max = resolve_lofs_mnts + nmnts;
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   285
	return (0);
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   286
}
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   287
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   288
/*
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   289
 * This function loops over potential loopback mounts and symlinks in a given
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   290
 * path and resolves them all down to an absolute path.
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   291
 */
5576
600b6e9b3a5b 6629088 lucreate fails with zone roots in shared file systems
edp
parents: 5185
diff changeset
   292
void
766
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   293
resolve_lofs(zlog_t *zlogp, char *path, size_t pathlen)
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   294
{
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   295
	int len, arlen;
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   296
	const char *altroot;
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   297
	char tmppath[MAXPATHLEN];
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   298
	boolean_t outside_altroot;
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   299
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   300
	if ((len = resolvepath(path, tmppath, sizeof (tmppath))) == -1)
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   301
		return;
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   302
	tmppath[len] = '\0';
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   303
	(void) strlcpy(path, tmppath, sizeof (tmppath));
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   304
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   305
	/* This happens once per zoneadmd operation. */
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   306
	if (resolve_lofs_mnts == NULL && lofs_read_mnttab(zlogp) == -1)
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   307
		return;
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   308
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   309
	altroot = zonecfg_get_root();
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   310
	arlen = strlen(altroot);
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   311
	outside_altroot = B_FALSE;
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   312
	for (;;) {
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   313
		struct mnttab *mnp;
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   314
3079
e31d53b3c780 6489671 lumount problems after luupgrade
dminer
parents: 3071
diff changeset
   315
		/* Search in reverse order to find longest match */
e31d53b3c780 6489671 lumount problems after luupgrade
dminer
parents: 3071
diff changeset
   316
		for (mnp = resolve_lofs_mnt_max - 1; mnp >= resolve_lofs_mnts;
e31d53b3c780 6489671 lumount problems after luupgrade
dminer
parents: 3071
diff changeset
   317
		    mnp--) {
766
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   318
			if (mnp->mnt_fstype == NULL ||
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   319
			    mnp->mnt_mountp == NULL ||
3079
e31d53b3c780 6489671 lumount problems after luupgrade
dminer
parents: 3071
diff changeset
   320
			    mnp->mnt_special == NULL)
766
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   321
				continue;
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   322
			len = strlen(mnp->mnt_mountp);
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   323
			if (strncmp(mnp->mnt_mountp, path, len) == 0 &&
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   324
			    (path[len] == '/' || path[len] == '\0'))
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   325
				break;
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   326
		}
3079
e31d53b3c780 6489671 lumount problems after luupgrade
dminer
parents: 3071
diff changeset
   327
		if (mnp < resolve_lofs_mnts)
e31d53b3c780 6489671 lumount problems after luupgrade
dminer
parents: 3071
diff changeset
   328
			break;
e31d53b3c780 6489671 lumount problems after luupgrade
dminer
parents: 3071
diff changeset
   329
		/* If it's not a lofs then we're done */
e31d53b3c780 6489671 lumount problems after luupgrade
dminer
parents: 3071
diff changeset
   330
		if (strcmp(mnp->mnt_fstype, MNTTYPE_LOFS) != 0)
766
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   331
			break;
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   332
		if (outside_altroot) {
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   333
			char *cp;
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   334
			int olen = sizeof (MNTOPT_RO) - 1;
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   335
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   336
			/*
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   337
			 * If we run into a read-only mount outside of the
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   338
			 * alternate root environment, then the user doesn't
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   339
			 * want this path to be made read-write.
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   340
			 */
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   341
			if (mnp->mnt_mntopts != NULL &&
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   342
			    (cp = strstr(mnp->mnt_mntopts, MNTOPT_RO)) !=
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   343
			    NULL &&
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   344
			    (cp == mnp->mnt_mntopts || cp[-1] == ',') &&
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   345
			    (cp[olen] == '\0' || cp[olen] == ',')) {
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   346
				break;
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   347
			}
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   348
		} else if (arlen > 0 &&
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   349
		    (strncmp(mnp->mnt_special, altroot, arlen) != 0 ||
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   350
		    (mnp->mnt_special[arlen] != '\0' &&
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   351
		    mnp->mnt_special[arlen] != '/'))) {
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   352
			outside_altroot = B_TRUE;
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   353
		}
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   354
		/* use temporary buffer because new path might be longer */
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   355
		(void) snprintf(tmppath, sizeof (tmppath), "%s%s",
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   356
		    mnp->mnt_special, path + len);
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   357
		if ((len = resolvepath(tmppath, path, pathlen)) == -1)
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   358
			break;
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   359
		path[len] = '\0';
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   360
	}
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   361
}
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   362
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   363
/*
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   364
 * For a regular mount, check if a replacement lofs mount is needed because the
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   365
 * referenced device is already mounted somewhere.
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   366
 */
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   367
static int
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   368
check_lofs_needed(zlog_t *zlogp, struct zone_fstab *fsptr)
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   369
{
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   370
	struct mnttab *mnp;
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   371
	zone_fsopt_t *optptr, *onext;
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   372
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   373
	/* This happens once per zoneadmd operation. */
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   374
	if (resolve_lofs_mnts == NULL && lofs_read_mnttab(zlogp) == -1)
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   375
		return (-1);
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   376
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   377
	/*
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   378
	 * If this special node isn't already in use, then it's ours alone;
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   379
	 * no need to worry about conflicting mounts.
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   380
	 */
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   381
	for (mnp = resolve_lofs_mnts; mnp < resolve_lofs_mnt_max;
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   382
	    mnp++) {
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   383
		if (strcmp(mnp->mnt_special, fsptr->zone_fs_special) == 0)
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   384
			break;
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   385
	}
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   386
	if (mnp >= resolve_lofs_mnt_max)
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   387
		return (0);
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   388
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   389
	/*
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   390
	 * Convert this duplicate mount into a lofs mount.
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   391
	 */
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   392
	(void) strlcpy(fsptr->zone_fs_special, mnp->mnt_mountp,
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   393
	    sizeof (fsptr->zone_fs_special));
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   394
	(void) strlcpy(fsptr->zone_fs_type, MNTTYPE_LOFS,
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   395
	    sizeof (fsptr->zone_fs_type));
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   396
	fsptr->zone_fs_raw[0] = '\0';
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   397
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   398
	/*
12734
76969fc28795 6939693 zones no longer needs the inherit-pkg-dir property
Gary Pennington <gary.pennington@oracle.com>
parents: 12725
diff changeset
   399
	 * Discard all but one of the original options and set that to our
76969fc28795 6939693 zones no longer needs the inherit-pkg-dir property
Gary Pennington <gary.pennington@oracle.com>
parents: 12725
diff changeset
   400
	 * default set of options used for resources.
766
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   401
	 */
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   402
	optptr = fsptr->zone_fs_options;
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   403
	if (optptr == NULL) {
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   404
		optptr = malloc(sizeof (*optptr));
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   405
		if (optptr == NULL) {
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   406
			zerror(zlogp, B_TRUE, "cannot mount %s",
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   407
			    fsptr->zone_fs_dir);
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   408
			return (-1);
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   409
		}
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   410
	} else {
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   411
		while ((onext = optptr->zone_fsopt_next) != NULL) {
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   412
			optptr->zone_fsopt_next = onext->zone_fsopt_next;
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   413
			free(onext);
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   414
		}
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   415
	}
12734
76969fc28795 6939693 zones no longer needs the inherit-pkg-dir property
Gary Pennington <gary.pennington@oracle.com>
parents: 12725
diff changeset
   416
	(void) strcpy(optptr->zone_fsopt_opt, RESOURCE_DEFAULT_OPTS);
766
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   417
	optptr->zone_fsopt_next = NULL;
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   418
	fsptr->zone_fs_options = optptr;
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   419
	return (0);
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   420
}
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   421
5182
1933ef4db196 6572723 zoneadmd should allow lofs mounts on files
edp
parents: 4791
diff changeset
   422
int
3813
c7c433a53b1a 6213465 non-global zone's /dev directory has wrong group owner
dp
parents: 3716
diff changeset
   423
make_one_dir(zlog_t *zlogp, const char *prefix, const char *subdir, mode_t mode,
c7c433a53b1a 6213465 non-global zone's /dev directory has wrong group owner
dp
parents: 3716
diff changeset
   424
    uid_t userid, gid_t groupid)
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   425
{
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   426
	char path[MAXPATHLEN];
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   427
	struct stat st;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   428
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   429
	if (snprintf(path, sizeof (path), "%s%s", prefix, subdir) >
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   430
	    sizeof (path)) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   431
		zerror(zlogp, B_FALSE, "pathname %s%s is too long", prefix,
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   432
		    subdir);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   433
		return (-1);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   434
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   435
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   436
	if (lstat(path, &st) == 0) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   437
		/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   438
		 * We don't check the file mode since presumably the zone
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   439
		 * administrator may have had good reason to change the mode,
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   440
		 * and we don't need to second guess him.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   441
		 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   442
		if (!S_ISDIR(st.st_mode)) {
7714
285beea91405 6746407 [tx] cannot upgrade s10u5_10 -> s10u6_07 TX system with ufs zone if passwd included in zones xmls
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 7655
diff changeset
   443
			if (S_ISREG(st.st_mode)) {
1676
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
   444
				/*
7714
285beea91405 6746407 [tx] cannot upgrade s10u5_10 -> s10u6_07 TX system with ufs zone if passwd included in zones xmls
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 7655
diff changeset
   445
				 * Allow readonly mounts of /etc/ files; this
285beea91405 6746407 [tx] cannot upgrade s10u5_10 -> s10u6_07 TX system with ufs zone if passwd included in zones xmls
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 7655
diff changeset
   446
				 * is needed most by Trusted Extensions.
1676
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
   447
				 */
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
   448
				if (strncmp(subdir, "/etc/",
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
   449
				    strlen("/etc/")) != 0) {
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
   450
					zerror(zlogp, B_FALSE,
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
   451
					    "%s is not in /etc", path);
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
   452
					return (-1);
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
   453
				}
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
   454
			} else {
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
   455
				zerror(zlogp, B_FALSE,
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
   456
				    "%s is not a directory", path);
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
   457
				return (-1);
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
   458
			}
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   459
		}
3813
c7c433a53b1a 6213465 non-global zone's /dev directory has wrong group owner
dp
parents: 3716
diff changeset
   460
		return (0);
c7c433a53b1a 6213465 non-global zone's /dev directory has wrong group owner
dp
parents: 3716
diff changeset
   461
	}
c7c433a53b1a 6213465 non-global zone's /dev directory has wrong group owner
dp
parents: 3716
diff changeset
   462
c7c433a53b1a 6213465 non-global zone's /dev directory has wrong group owner
dp
parents: 3716
diff changeset
   463
	if (mkdirp(path, mode) != 0) {
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   464
		if (errno == EROFS)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   465
			zerror(zlogp, B_FALSE, "Could not mkdir %s.\nIt is on "
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   466
			    "a read-only file system in this local zone.\nMake "
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   467
			    "sure %s exists in the global zone.", path, subdir);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   468
		else
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   469
			zerror(zlogp, B_TRUE, "mkdirp of %s failed", path);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   470
		return (-1);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   471
	}
3813
c7c433a53b1a 6213465 non-global zone's /dev directory has wrong group owner
dp
parents: 3716
diff changeset
   472
c7c433a53b1a 6213465 non-global zone's /dev directory has wrong group owner
dp
parents: 3716
diff changeset
   473
	(void) chown(path, userid, groupid);
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   474
	return (0);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   475
}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   476
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   477
static void
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   478
free_remote_fstypes(char **types)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   479
{
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   480
	uint_t i;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   481
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   482
	if (types == NULL)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   483
		return;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   484
	for (i = 0; types[i] != NULL; i++)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   485
		free(types[i]);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   486
	free(types);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   487
}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   488
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   489
static char **
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   490
get_remote_fstypes(zlog_t *zlogp)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   491
{
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   492
	char **types = NULL;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   493
	FILE *fp;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   494
	char buf[MAXPATHLEN];
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   495
	char fstype[MAXPATHLEN];
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   496
	uint_t lines = 0;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   497
	uint_t i;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   498
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   499
	if ((fp = fopen(DFSTYPES, "r")) == NULL) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   500
		zerror(zlogp, B_TRUE, "failed to open %s", DFSTYPES);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   501
		return (NULL);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   502
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   503
	/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   504
	 * Count the number of lines
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   505
	 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   506
	while (fgets(buf, sizeof (buf), fp) != NULL)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   507
		lines++;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   508
	if (lines == 0)	/* didn't read anything; empty file */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   509
		goto out;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   510
	rewind(fp);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   511
	/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   512
	 * Allocate enough space for a NULL-terminated array.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   513
	 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   514
	types = calloc(lines + 1, sizeof (char *));
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   515
	if (types == NULL) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   516
		zerror(zlogp, B_TRUE, "memory allocation failed");
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   517
		goto out;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   518
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   519
	i = 0;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   520
	while (fgets(buf, sizeof (buf), fp) != NULL) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   521
		/* LINTED - fstype is big enough to hold buf */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   522
		if (sscanf(buf, "%s", fstype) == 0) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   523
			zerror(zlogp, B_FALSE, "unable to parse %s", DFSTYPES);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   524
			free_remote_fstypes(types);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   525
			types = NULL;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   526
			goto out;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   527
		}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   528
		types[i] = strdup(fstype);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   529
		if (types[i] == NULL) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   530
			zerror(zlogp, B_TRUE, "memory allocation failed");
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   531
			free_remote_fstypes(types);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   532
			types = NULL;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   533
			goto out;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   534
		}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   535
		i++;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   536
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   537
out:
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   538
	(void) fclose(fp);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   539
	return (types);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   540
}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   541
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   542
static boolean_t
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   543
is_remote_fstype(const char *fstype, char *const *remote_fstypes)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   544
{
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   545
	uint_t i;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   546
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   547
	if (remote_fstypes == NULL)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   548
		return (B_FALSE);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   549
	for (i = 0; remote_fstypes[i] != NULL; i++) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   550
		if (strcmp(remote_fstypes[i], fstype) == 0)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   551
			return (B_TRUE);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   552
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   553
	return (B_FALSE);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   554
}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   555
766
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   556
/*
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   557
 * This converts a zone root path (normally of the form .../root) to a Live
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   558
 * Upgrade scratch zone root (of the form .../lu).
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   559
 */
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   560
static void
766
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   561
root_to_lu(zlog_t *zlogp, char *zroot, size_t zrootlen, boolean_t isresolved)
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   562
{
766
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   563
	if (!isresolved && zonecfg_in_alt_root())
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   564
		resolve_lofs(zlogp, zroot, zrootlen);
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   565
	(void) strcpy(strrchr(zroot, '/') + 1, "lu");
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   566
}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   567
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   568
/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   569
 * The general strategy for unmounting filesystems is as follows:
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   570
 *
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   571
 * - Remote filesystems may be dead, and attempting to contact them as
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   572
 * part of a regular unmount may hang forever; we want to always try to
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   573
 * forcibly unmount such filesystems and only fall back to regular
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   574
 * unmounts if the filesystem doesn't support forced unmounts.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   575
 *
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   576
 * - We don't want to unnecessarily corrupt metadata on local
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   577
 * filesystems (ie UFS), so we want to start off with graceful unmounts,
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   578
 * and only escalate to doing forced unmounts if we get stuck.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   579
 *
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   580
 * We start off walking backwards through the mount table.  This doesn't
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   581
 * give us strict ordering but ensures that we try to unmount submounts
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   582
 * first.  We thus limit the number of failed umount2(2) calls.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   583
 *
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   584
 * The mechanism for determining if we're stuck is to count the number
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   585
 * of failed unmounts each iteration through the mount table.  This
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   586
 * gives us an upper bound on the number of filesystems which remain
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   587
 * mounted (autofs trigger nodes are dealt with separately).  If at the
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   588
 * end of one unmount+autofs_cleanup cycle we still have the same number
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   589
 * of mounts that we started out with, we're stuck and try a forced
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   590
 * unmount.  If that fails (filesystem doesn't support forced unmounts)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   591
 * then we bail and are unable to teardown the zone.  If it succeeds,
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   592
 * we're no longer stuck so we continue with our policy of trying
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   593
 * graceful mounts first.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   594
 *
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   595
 * Zone must be down (ie, no processes or threads active).
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   596
 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   597
static int
766
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   598
unmount_filesystems(zlog_t *zlogp, zoneid_t zoneid, boolean_t unmount_cmd)
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   599
{
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   600
	int error = 0;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   601
	FILE *mnttab;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   602
	struct mnttab *mnts;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   603
	uint_t nmnt;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   604
	char zroot[MAXPATHLEN + 1];
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   605
	size_t zrootlen;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   606
	uint_t oldcount = UINT_MAX;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   607
	boolean_t stuck = B_FALSE;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   608
	char **remote_fstypes = NULL;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   609
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   610
	if (zone_get_rootpath(zone_name, zroot, sizeof (zroot)) != Z_OK) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   611
		zerror(zlogp, B_FALSE, "unable to determine zone root");
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   612
		return (-1);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   613
	}
766
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   614
	if (unmount_cmd)
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
   615
		root_to_lu(zlogp, zroot, sizeof (zroot), B_FALSE);
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   616
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   617
	(void) strcat(zroot, "/");
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   618
	zrootlen = strlen(zroot);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   619
1676
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
   620
	/*
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
   621
	 * For Trusted Extensions unmount each higher level zone's mount
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
   622
	 * of our zone's /export/home
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
   623
	 */
1769
338500d67d4f 6404654 zoneadm mount command fails on labeled systems
carlsonj
parents: 1676
diff changeset
   624
	if (!unmount_cmd)
338500d67d4f 6404654 zoneadm mount command fails on labeled systems
carlsonj
parents: 1676
diff changeset
   625
		tsol_unmounts(zlogp, zone_name);
1676
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
   626
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   627
	if ((mnttab = fopen(MNTTAB, "r")) == NULL) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   628
		zerror(zlogp, B_TRUE, "failed to open %s", MNTTAB);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   629
		return (-1);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   630
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   631
	/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   632
	 * Use our hacky mntfs ioctl so we see everything, even mounts with
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   633
	 * MS_NOMNTTAB.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   634
	 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   635
	if (ioctl(fileno(mnttab), MNTIOC_SHOWHIDDEN, NULL) < 0) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   636
		zerror(zlogp, B_TRUE, "unable to configure %s", MNTTAB);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   637
		error++;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   638
		goto out;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   639
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   640
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   641
	/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   642
	 * Build the list of remote fstypes so we know which ones we
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   643
	 * should forcibly unmount.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   644
	 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   645
	remote_fstypes = get_remote_fstypes(zlogp);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   646
	for (; /* ever */; ) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   647
		uint_t newcount = 0;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   648
		boolean_t unmounted;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   649
		struct mnttab *mnp;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   650
		char *path;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   651
		uint_t i;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   652
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   653
		mnts = NULL;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   654
		nmnt = 0;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   655
		/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   656
		 * MNTTAB gives us a way to walk through mounted
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   657
		 * filesystems; we need to be able to walk them in
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   658
		 * reverse order, so we build a list of all mounted
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   659
		 * filesystems.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   660
		 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   661
		if (build_mnttable(zlogp, zroot, zrootlen, mnttab, &mnts,
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   662
		    &nmnt) != 0) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   663
			error++;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   664
			goto out;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   665
		}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   666
		for (i = 0; i < nmnt; i++) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   667
			mnp = &mnts[nmnt - i - 1]; /* access in reverse order */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   668
			path = mnp->mnt_mountp;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   669
			unmounted = B_FALSE;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   670
			/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   671
			 * Try forced unmount first for remote filesystems.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   672
			 *
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   673
			 * Not all remote filesystems support forced unmounts,
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   674
			 * so if this fails (ENOTSUP) we'll continue on
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   675
			 * and try a regular unmount.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   676
			 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   677
			if (is_remote_fstype(mnp->mnt_fstype, remote_fstypes)) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   678
				if (umount2(path, MS_FORCE) == 0)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   679
					unmounted = B_TRUE;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   680
			}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   681
			/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   682
			 * Try forced unmount if we're stuck.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   683
			 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   684
			if (stuck) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   685
				if (umount2(path, MS_FORCE) == 0) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   686
					unmounted = B_TRUE;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   687
					stuck = B_FALSE;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   688
				} else {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   689
					/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   690
					 * The first failure indicates a
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   691
					 * mount we won't be able to get
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   692
					 * rid of automatically, so we
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   693
					 * bail.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   694
					 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   695
					error++;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   696
					zerror(zlogp, B_FALSE,
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   697
					    "unable to unmount '%s'", path);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   698
					free_mnttable(mnts, nmnt);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   699
					goto out;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   700
				}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   701
			}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   702
			/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   703
			 * Try regular unmounts for everything else.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   704
			 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   705
			if (!unmounted && umount2(path, 0) != 0)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   706
				newcount++;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   707
		}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   708
		free_mnttable(mnts, nmnt);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   709
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   710
		if (newcount == 0)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   711
			break;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   712
		if (newcount >= oldcount) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   713
			/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   714
			 * Last round didn't unmount anything; we're stuck and
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   715
			 * should start trying forced unmounts.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   716
			 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   717
			stuck = B_TRUE;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   718
		}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   719
		oldcount = newcount;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   720
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   721
		/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   722
		 * Autofs doesn't let you unmount its trigger nodes from
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   723
		 * userland so we have to tell the kernel to cleanup for us.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   724
		 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   725
		if (autofs_cleanup(zoneid) != 0) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   726
			zerror(zlogp, B_TRUE, "unable to remove autofs nodes");
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   727
			error++;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   728
			goto out;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   729
		}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   730
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   731
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   732
out:
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   733
	free_remote_fstypes(remote_fstypes);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   734
	(void) fclose(mnttab);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   735
	return (error ? -1 : 0);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   736
}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   737
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   738
static int
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   739
fs_compare(const void *m1, const void *m2)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   740
{
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   741
	struct zone_fstab *i = (struct zone_fstab *)m1;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   742
	struct zone_fstab *j = (struct zone_fstab *)m2;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   743
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   744
	return (strcmp(i->zone_fs_dir, j->zone_fs_dir));
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   745
}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   746
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   747
/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   748
 * Fork and exec (and wait for) the mentioned binary with the provided
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   749
 * arguments.  Returns (-1) if something went wrong with fork(2) or exec(2),
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   750
 * returns the exit status otherwise.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   751
 *
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   752
 * If we were unable to exec the provided pathname (for whatever
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   753
 * reason), we return the special token ZEXIT_EXEC.  The current value
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   754
 * of ZEXIT_EXEC doesn't conflict with legitimate exit codes of the
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   755
 * consumers of this function; any future consumers must make sure this
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   756
 * remains the case.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   757
 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   758
static int
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   759
forkexec(zlog_t *zlogp, const char *path, char *const argv[])
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   760
{
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   761
	pid_t child_pid;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   762
	int child_status = 0;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   763
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   764
	/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   765
	 * Do not let another thread localize a message while we are forking.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   766
	 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   767
	(void) mutex_lock(&msglock);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   768
	child_pid = fork();
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   769
	(void) mutex_unlock(&msglock);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   770
	if (child_pid == -1) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   771
		zerror(zlogp, B_TRUE, "could not fork for %s", argv[0]);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   772
		return (-1);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   773
	} else if (child_pid == 0) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   774
		closefrom(0);
1915
ab5b727bff8b 5106568 "zoneadm verify" can print unclear message in certain cases with IPv6
gjelinek
parents: 1769
diff changeset
   775
		/* redirect stdin, stdout & stderr to /dev/null */
ab5b727bff8b 5106568 "zoneadm verify" can print unclear message in certain cases with IPv6
gjelinek
parents: 1769
diff changeset
   776
		(void) open("/dev/null", O_RDONLY);	/* stdin */
ab5b727bff8b 5106568 "zoneadm verify" can print unclear message in certain cases with IPv6
gjelinek
parents: 1769
diff changeset
   777
		(void) open("/dev/null", O_WRONLY);	/* stdout */
ab5b727bff8b 5106568 "zoneadm verify" can print unclear message in certain cases with IPv6
gjelinek
parents: 1769
diff changeset
   778
		(void) open("/dev/null", O_WRONLY);	/* stderr */
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   779
		(void) execv(path, argv);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   780
		/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   781
		 * Since we are in the child, there is no point calling zerror()
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   782
		 * since there is nobody waiting to consume it.  So exit with a
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   783
		 * special code that the parent will recognize and call zerror()
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   784
		 * accordingly.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   785
		 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   786
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   787
		_exit(ZEXIT_EXEC);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   788
	} else {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   789
		(void) waitpid(child_pid, &child_status, 0);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   790
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   791
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   792
	if (WIFSIGNALED(child_status)) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   793
		zerror(zlogp, B_FALSE, "%s unexpectedly terminated due to "
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   794
		    "signal %d", path, WTERMSIG(child_status));
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   795
		return (-1);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   796
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   797
	assert(WIFEXITED(child_status));
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   798
	if (WEXITSTATUS(child_status) == ZEXIT_EXEC) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   799
		zerror(zlogp, B_FALSE, "failed to exec %s", path);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   800
		return (-1);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   801
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   802
	return (WEXITSTATUS(child_status));
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   803
}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   804
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   805
static int
6734
d16dda992d39 PSARC/2008/290 lofi mount
johnlev
parents: 6631
diff changeset
   806
isregfile(const char *path)
d16dda992d39 PSARC/2008/290 lofi mount
johnlev
parents: 6631
diff changeset
   807
{
d16dda992d39 PSARC/2008/290 lofi mount
johnlev
parents: 6631
diff changeset
   808
	struct stat64 st;
d16dda992d39 PSARC/2008/290 lofi mount
johnlev
parents: 6631
diff changeset
   809
d16dda992d39 PSARC/2008/290 lofi mount
johnlev
parents: 6631
diff changeset
   810
	if (stat64(path, &st) == -1)
d16dda992d39 PSARC/2008/290 lofi mount
johnlev
parents: 6631
diff changeset
   811
		return (-1);
d16dda992d39 PSARC/2008/290 lofi mount
johnlev
parents: 6631
diff changeset
   812
d16dda992d39 PSARC/2008/290 lofi mount
johnlev
parents: 6631
diff changeset
   813
	return (S_ISREG(st.st_mode));
d16dda992d39 PSARC/2008/290 lofi mount
johnlev
parents: 6631
diff changeset
   814
}
d16dda992d39 PSARC/2008/290 lofi mount
johnlev
parents: 6631
diff changeset
   815
d16dda992d39 PSARC/2008/290 lofi mount
johnlev
parents: 6631
diff changeset
   816
static int
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   817
dofsck(zlog_t *zlogp, const char *fstype, const char *rawdev)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   818
{
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   819
	char cmdbuf[MAXPATHLEN];
11581
fe24b9b26502 6495558 zoneadm -z <zone> boot should not only check but repair filesystems
batschul <Frank.Batschulat@Sun.COM>
parents: 11276
diff changeset
   820
	char *argv[5];
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   821
	int status;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   822
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   823
	/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   824
	 * We could alternatively have called /usr/sbin/fsck -F <fstype>, but
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   825
	 * that would cost us an extra fork/exec without buying us anything.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   826
	 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   827
	if (snprintf(cmdbuf, sizeof (cmdbuf), "/usr/lib/fs/%s/fsck", fstype)
2712
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
   828
	    >= sizeof (cmdbuf)) {
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   829
		zerror(zlogp, B_FALSE, "file-system type %s too long", fstype);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   830
		return (-1);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   831
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   832
6734
d16dda992d39 PSARC/2008/290 lofi mount
johnlev
parents: 6631
diff changeset
   833
	/*
d16dda992d39 PSARC/2008/290 lofi mount
johnlev
parents: 6631
diff changeset
   834
	 * If it doesn't exist, that's OK: we verified this previously
d16dda992d39 PSARC/2008/290 lofi mount
johnlev
parents: 6631
diff changeset
   835
	 * in zoneadm.
d16dda992d39 PSARC/2008/290 lofi mount
johnlev
parents: 6631
diff changeset
   836
	 */
d16dda992d39 PSARC/2008/290 lofi mount
johnlev
parents: 6631
diff changeset
   837
	if (isregfile(cmdbuf) == -1)
d16dda992d39 PSARC/2008/290 lofi mount
johnlev
parents: 6631
diff changeset
   838
		return (0);
d16dda992d39 PSARC/2008/290 lofi mount
johnlev
parents: 6631
diff changeset
   839
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   840
	argv[0] = "fsck";
11581
fe24b9b26502 6495558 zoneadm -z <zone> boot should not only check but repair filesystems
batschul <Frank.Batschulat@Sun.COM>
parents: 11276
diff changeset
   841
	argv[1] = "-o";
fe24b9b26502 6495558 zoneadm -z <zone> boot should not only check but repair filesystems
batschul <Frank.Batschulat@Sun.COM>
parents: 11276
diff changeset
   842
	argv[2] = "p";
fe24b9b26502 6495558 zoneadm -z <zone> boot should not only check but repair filesystems
batschul <Frank.Batschulat@Sun.COM>
parents: 11276
diff changeset
   843
	argv[3] = (char *)rawdev;
fe24b9b26502 6495558 zoneadm -z <zone> boot should not only check but repair filesystems
batschul <Frank.Batschulat@Sun.COM>
parents: 11276
diff changeset
   844
	argv[4] = NULL;
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   845
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   846
	status = forkexec(zlogp, cmdbuf, argv);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   847
	if (status == 0 || status == -1)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   848
		return (status);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   849
	zerror(zlogp, B_FALSE, "fsck of '%s' failed with exit status %d; "
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   850
	    "run fsck manually", rawdev, status);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   851
	return (-1);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   852
}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   853
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   854
static int
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   855
domount(zlog_t *zlogp, const char *fstype, const char *opts,
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   856
    const char *special, const char *directory)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   857
{
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   858
	char cmdbuf[MAXPATHLEN];
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   859
	char *argv[6];
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   860
	int status;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   861
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   862
	/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   863
	 * We could alternatively have called /usr/sbin/mount -F <fstype>, but
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   864
	 * that would cost us an extra fork/exec without buying us anything.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   865
	 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   866
	if (snprintf(cmdbuf, sizeof (cmdbuf), "/usr/lib/fs/%s/mount", fstype)
2712
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
   867
	    >= sizeof (cmdbuf)) {
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   868
		zerror(zlogp, B_FALSE, "file-system type %s too long", fstype);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   869
		return (-1);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   870
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   871
	argv[0] = "mount";
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   872
	if (opts[0] == '\0') {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   873
		argv[1] = (char *)special;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   874
		argv[2] = (char *)directory;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   875
		argv[3] = NULL;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   876
	} else {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   877
		argv[1] = "-o";
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   878
		argv[2] = (char *)opts;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   879
		argv[3] = (char *)special;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   880
		argv[4] = (char *)directory;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   881
		argv[5] = NULL;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   882
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   883
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   884
	status = forkexec(zlogp, cmdbuf, argv);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   885
	if (status == 0 || status == -1)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   886
		return (status);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   887
	if (opts[0] == '\0')
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   888
		zerror(zlogp, B_FALSE, "\"%s %s %s\" "
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   889
		    "failed with exit code %d",
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   890
		    cmdbuf, special, directory, status);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   891
	else
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   892
		zerror(zlogp, B_FALSE, "\"%s -o %s %s %s\" "
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   893
		    "failed with exit code %d",
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   894
		    cmdbuf, opts, special, directory, status);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   895
	return (-1);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   896
}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   897
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   898
/*
5182
1933ef4db196 6572723 zoneadmd should allow lofs mounts on files
edp
parents: 4791
diff changeset
   899
 * Check if a given mount point path exists.
1933ef4db196 6572723 zoneadmd should allow lofs mounts on files
edp
parents: 4791
diff changeset
   900
 * If it does, make sure it doesn't contain any symlinks.
1933ef4db196 6572723 zoneadmd should allow lofs mounts on files
edp
parents: 4791
diff changeset
   901
 * Note that if "leaf" is false we're checking an intermediate
1933ef4db196 6572723 zoneadmd should allow lofs mounts on files
edp
parents: 4791
diff changeset
   902
 * component of the mount point path, so it must be a directory.
1933ef4db196 6572723 zoneadmd should allow lofs mounts on files
edp
parents: 4791
diff changeset
   903
 * If "leaf" is true, then we're checking the entire mount point
1933ef4db196 6572723 zoneadmd should allow lofs mounts on files
edp
parents: 4791
diff changeset
   904
 * path, so the mount point itself can be anything aside from a
1933ef4db196 6572723 zoneadmd should allow lofs mounts on files
edp
parents: 4791
diff changeset
   905
 * symbolic link.
1933ef4db196 6572723 zoneadmd should allow lofs mounts on files
edp
parents: 4791
diff changeset
   906
 *
1933ef4db196 6572723 zoneadmd should allow lofs mounts on files
edp
parents: 4791
diff changeset
   907
 * If the path is invalid then a negative value is returned.  If the
1933ef4db196 6572723 zoneadmd should allow lofs mounts on files
edp
parents: 4791
diff changeset
   908
 * path exists and is a valid mount point path then 0 is returned.
1933ef4db196 6572723 zoneadmd should allow lofs mounts on files
edp
parents: 4791
diff changeset
   909
 * If the path doesn't exist return a positive value.
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   910
 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   911
static int
5182
1933ef4db196 6572723 zoneadmd should allow lofs mounts on files
edp
parents: 4791
diff changeset
   912
valid_mount_point(zlog_t *zlogp, const char *path, const boolean_t leaf)
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   913
{
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   914
	struct stat statbuf;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   915
	char respath[MAXPATHLEN];
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   916
	int res;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   917
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   918
	if (lstat(path, &statbuf) != 0) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   919
		if (errno == ENOENT)
5182
1933ef4db196 6572723 zoneadmd should allow lofs mounts on files
edp
parents: 4791
diff changeset
   920
			return (1);
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   921
		zerror(zlogp, B_TRUE, "can't stat %s", path);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   922
		return (-1);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   923
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   924
	if (S_ISLNK(statbuf.st_mode)) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   925
		zerror(zlogp, B_FALSE, "%s is a symlink", path);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   926
		return (-1);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   927
	}
5182
1933ef4db196 6572723 zoneadmd should allow lofs mounts on files
edp
parents: 4791
diff changeset
   928
	if (!leaf && !S_ISDIR(statbuf.st_mode)) {
1933ef4db196 6572723 zoneadmd should allow lofs mounts on files
edp
parents: 4791
diff changeset
   929
		zerror(zlogp, B_FALSE, "%s is not a directory", path);
1933ef4db196 6572723 zoneadmd should allow lofs mounts on files
edp
parents: 4791
diff changeset
   930
		return (-1);
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   931
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   932
	if ((res = resolvepath(path, respath, sizeof (respath))) == -1) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   933
		zerror(zlogp, B_TRUE, "unable to resolve path %s", path);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   934
		return (-1);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   935
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   936
	respath[res] = '\0';
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   937
	if (strcmp(path, respath) != 0) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   938
		/*
5182
1933ef4db196 6572723 zoneadmd should allow lofs mounts on files
edp
parents: 4791
diff changeset
   939
		 * We don't like ".."s, "."s, or "//"s throwing us off
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   940
		 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   941
		zerror(zlogp, B_FALSE, "%s is not a canonical path", path);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   942
		return (-1);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   943
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   944
	return (0);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   945
}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   946
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   947
/*
5182
1933ef4db196 6572723 zoneadmd should allow lofs mounts on files
edp
parents: 4791
diff changeset
   948
 * Validate a mount point path.  A valid mount point path is an
1933ef4db196 6572723 zoneadmd should allow lofs mounts on files
edp
parents: 4791
diff changeset
   949
 * absolute path that either doesn't exist, or, if it does exists it
1933ef4db196 6572723 zoneadmd should allow lofs mounts on files
edp
parents: 4791
diff changeset
   950
 * must be an absolute canonical path that doesn't have any symbolic
1933ef4db196 6572723 zoneadmd should allow lofs mounts on files
edp
parents: 4791
diff changeset
   951
 * links in it.  The target of a mount point path can be any filesystem
1933ef4db196 6572723 zoneadmd should allow lofs mounts on files
edp
parents: 4791
diff changeset
   952
 * object.  (Different filesystems can support different mount points,
1933ef4db196 6572723 zoneadmd should allow lofs mounts on files
edp
parents: 4791
diff changeset
   953
 * for example "lofs" and "mntfs" both support files and directories
1933ef4db196 6572723 zoneadmd should allow lofs mounts on files
edp
parents: 4791
diff changeset
   954
 * while "ufs" just supports directories.)
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   955
 *
5182
1933ef4db196 6572723 zoneadmd should allow lofs mounts on files
edp
parents: 4791
diff changeset
   956
 * If the path is invalid then a negative value is returned.  If the
1933ef4db196 6572723 zoneadmd should allow lofs mounts on files
edp
parents: 4791
diff changeset
   957
 * path exists and is a valid mount point path then 0 is returned.
1933ef4db196 6572723 zoneadmd should allow lofs mounts on files
edp
parents: 4791
diff changeset
   958
 * If the path doesn't exist return a positive value.
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   959
 */
5182
1933ef4db196 6572723 zoneadmd should allow lofs mounts on files
edp
parents: 4791
diff changeset
   960
int
1933ef4db196 6572723 zoneadmd should allow lofs mounts on files
edp
parents: 4791
diff changeset
   961
valid_mount_path(zlog_t *zlogp, const char *rootpath, const char *spec,
1933ef4db196 6572723 zoneadmd should allow lofs mounts on files
edp
parents: 4791
diff changeset
   962
    const char *dir, const char *fstype)
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   963
{
5182
1933ef4db196 6572723 zoneadmd should allow lofs mounts on files
edp
parents: 4791
diff changeset
   964
	char abspath[MAXPATHLEN], *slashp, *slashp_next;
1933ef4db196 6572723 zoneadmd should allow lofs mounts on files
edp
parents: 4791
diff changeset
   965
	int rv;
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   966
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   967
	/*
5182
1933ef4db196 6572723 zoneadmd should allow lofs mounts on files
edp
parents: 4791
diff changeset
   968
	 * Sanity check the target mount point path.
1933ef4db196 6572723 zoneadmd should allow lofs mounts on files
edp
parents: 4791
diff changeset
   969
	 * It must be a non-null string that starts with a '/'.
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   970
	 */
5182
1933ef4db196 6572723 zoneadmd should allow lofs mounts on files
edp
parents: 4791
diff changeset
   971
	if (dir[0] != '/') {
12734
76969fc28795 6939693 zones no longer needs the inherit-pkg-dir property
Gary Pennington <gary.pennington@oracle.com>
parents: 12725
diff changeset
   972
		/* Something went wrong. */
76969fc28795 6939693 zones no longer needs the inherit-pkg-dir property
Gary Pennington <gary.pennington@oracle.com>
parents: 12725
diff changeset
   973
		zerror(zlogp, B_FALSE, "invalid mount directory, "
76969fc28795 6939693 zones no longer needs the inherit-pkg-dir property
Gary Pennington <gary.pennington@oracle.com>
parents: 12725
diff changeset
   974
		    "type: \"%s\", special: \"%s\", dir: \"%s\"",
76969fc28795 6939693 zones no longer needs the inherit-pkg-dir property
Gary Pennington <gary.pennington@oracle.com>
parents: 12725
diff changeset
   975
		    fstype, spec, dir);
5182
1933ef4db196 6572723 zoneadmd should allow lofs mounts on files
edp
parents: 4791
diff changeset
   976
		return (-1);
1933ef4db196 6572723 zoneadmd should allow lofs mounts on files
edp
parents: 4791
diff changeset
   977
	}
1933ef4db196 6572723 zoneadmd should allow lofs mounts on files
edp
parents: 4791
diff changeset
   978
1933ef4db196 6572723 zoneadmd should allow lofs mounts on files
edp
parents: 4791
diff changeset
   979
	/*
1933ef4db196 6572723 zoneadmd should allow lofs mounts on files
edp
parents: 4791
diff changeset
   980
	 * Join rootpath and dir.  Make sure abspath ends with '/', this
1933ef4db196 6572723 zoneadmd should allow lofs mounts on files
edp
parents: 4791
diff changeset
   981
	 * is added to all paths (even non-directory paths) to allow us
1933ef4db196 6572723 zoneadmd should allow lofs mounts on files
edp
parents: 4791
diff changeset
   982
	 * to detect the end of paths below.  If the path already ends
1933ef4db196 6572723 zoneadmd should allow lofs mounts on files
edp
parents: 4791
diff changeset
   983
	 * in a '/', then that's ok too (although we'll fail the
1933ef4db196 6572723 zoneadmd should allow lofs mounts on files
edp
parents: 4791
diff changeset
   984
	 * cannonical path check in valid_mount_point()).
1933ef4db196 6572723 zoneadmd should allow lofs mounts on files
edp
parents: 4791
diff changeset
   985
	 */
1933ef4db196 6572723 zoneadmd should allow lofs mounts on files
edp
parents: 4791
diff changeset
   986
	if (snprintf(abspath, sizeof (abspath),
1933ef4db196 6572723 zoneadmd should allow lofs mounts on files
edp
parents: 4791
diff changeset
   987
	    "%s%s/", rootpath, dir) >= sizeof (abspath)) {
1933ef4db196 6572723 zoneadmd should allow lofs mounts on files
edp
parents: 4791
diff changeset
   988
		zerror(zlogp, B_FALSE, "pathname %s%s is too long",
1933ef4db196 6572723 zoneadmd should allow lofs mounts on files
edp
parents: 4791
diff changeset
   989
		    rootpath, dir);
1933ef4db196 6572723 zoneadmd should allow lofs mounts on files
edp
parents: 4791
diff changeset
   990
		return (-1);
1933ef4db196 6572723 zoneadmd should allow lofs mounts on files
edp
parents: 4791
diff changeset
   991
	}
1933ef4db196 6572723 zoneadmd should allow lofs mounts on files
edp
parents: 4791
diff changeset
   992
1933ef4db196 6572723 zoneadmd should allow lofs mounts on files
edp
parents: 4791
diff changeset
   993
	/*
1933ef4db196 6572723 zoneadmd should allow lofs mounts on files
edp
parents: 4791
diff changeset
   994
	 * Starting with rootpath, verify the mount path one component
1933ef4db196 6572723 zoneadmd should allow lofs mounts on files
edp
parents: 4791
diff changeset
   995
	 * at a time.  Continue until we've evaluated all of abspath.
1933ef4db196 6572723 zoneadmd should allow lofs mounts on files
edp
parents: 4791
diff changeset
   996
	 */
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   997
	slashp = &abspath[strlen(rootpath)];
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   998
	assert(*slashp == '/');
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   999
	do {
5182
1933ef4db196 6572723 zoneadmd should allow lofs mounts on files
edp
parents: 4791
diff changeset
  1000
		slashp_next = strchr(slashp + 1, '/');
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1001
		*slashp = '\0';
5182
1933ef4db196 6572723 zoneadmd should allow lofs mounts on files
edp
parents: 4791
diff changeset
  1002
		if (slashp_next != NULL) {
1933ef4db196 6572723 zoneadmd should allow lofs mounts on files
edp
parents: 4791
diff changeset
  1003
			/* This is an intermediary mount path component. */
1933ef4db196 6572723 zoneadmd should allow lofs mounts on files
edp
parents: 4791
diff changeset
  1004
			rv = valid_mount_point(zlogp, abspath, B_FALSE);
1933ef4db196 6572723 zoneadmd should allow lofs mounts on files
edp
parents: 4791
diff changeset
  1005
		} else {
1933ef4db196 6572723 zoneadmd should allow lofs mounts on files
edp
parents: 4791
diff changeset
  1006
			/* This is the last component of the mount path. */
1933ef4db196 6572723 zoneadmd should allow lofs mounts on files
edp
parents: 4791
diff changeset
  1007
			rv = valid_mount_point(zlogp, abspath, B_TRUE);
1933ef4db196 6572723 zoneadmd should allow lofs mounts on files
edp
parents: 4791
diff changeset
  1008
		}
1933ef4db196 6572723 zoneadmd should allow lofs mounts on files
edp
parents: 4791
diff changeset
  1009
		if (rv < 0)
1933ef4db196 6572723 zoneadmd should allow lofs mounts on files
edp
parents: 4791
diff changeset
  1010
			return (rv);
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1011
		*slashp = '/';
5182
1933ef4db196 6572723 zoneadmd should allow lofs mounts on files
edp
parents: 4791
diff changeset
  1012
	} while ((slashp = slashp_next) != NULL);
1933ef4db196 6572723 zoneadmd should allow lofs mounts on files
edp
parents: 4791
diff changeset
  1013
	return (rv);
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1014
}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1015
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1016
static int
2712
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1017
mount_one_dev_device_cb(void *arg, const char *match, const char *name)
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1018
{
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1019
	di_prof_t prof = arg;
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1020
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1021
	if (name == NULL)
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1022
		return (di_prof_add_dev(prof, match));
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1023
	return (di_prof_add_map(prof, match, name));
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1024
}
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1025
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1026
static int
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1027
mount_one_dev_symlink_cb(void *arg, const char *source, const char *target)
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1028
{
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1029
	di_prof_t prof = arg;
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1030
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1031
	return (di_prof_add_symlink(prof, source, target));
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1032
}
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1033
10616
3be00c4a6835 PSARC 2009/373 Clearview IP Tunneling
Sebastien Roy <Sebastien.Roy@Sun.COM>
parents: 10067
diff changeset
  1034
int
3be00c4a6835 PSARC 2009/373 Clearview IP Tunneling
Sebastien Roy <Sebastien.Roy@Sun.COM>
parents: 10067
diff changeset
  1035
vplat_get_iptype(zlog_t *zlogp, zone_iptype_t *iptypep)
3448
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  1036
{
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  1037
	zone_dochandle_t handle;
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  1038
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  1039
	if ((handle = zonecfg_init_handle()) == NULL) {
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  1040
		zerror(zlogp, B_TRUE, "getting zone configuration handle");
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  1041
		return (-1);
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  1042
	}
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  1043
	if (zonecfg_get_snapshot_handle(zone_name, handle) != Z_OK) {
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  1044
		zerror(zlogp, B_FALSE, "invalid configuration");
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  1045
		zonecfg_fini_handle(handle);
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  1046
		return (-1);
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  1047
	}
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  1048
	if (zonecfg_get_iptype(handle, iptypep) != Z_OK) {
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  1049
		zerror(zlogp, B_FALSE, "invalid ip-type configuration");
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  1050
		zonecfg_fini_handle(handle);
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  1051
		return (-1);
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  1052
	}
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  1053
	zonecfg_fini_handle(handle);
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  1054
	return (0);
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  1055
}
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  1056
2712
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1057
/*
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1058
 * Apply the standard lists of devices/symlinks/mappings and the user-specified
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1059
 * list of devices (via zonecfg) to the /dev filesystem.  The filesystem will
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1060
 * use these as a profile/filter to determine what exists in /dev.
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1061
 */
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1062
static int
7655
76c161ee52b3 6746514 RFE: need ability to mount non-native branded zones
<gerald.jelinek@sun.com>
parents: 7370
diff changeset
  1063
mount_one_dev(zlog_t *zlogp, char *devpath, zone_mnt_t mount_cmd)
2712
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1064
{
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1065
	char			brand[MAXNAMELEN];
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1066
	zone_dochandle_t	handle = NULL;
2727
fa06bd58f0f9 6469453 invalid assert in ioctl.c:ldlinux_check()
edp
parents: 2712
diff changeset
  1067
	brand_handle_t		bh = NULL;
2712
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1068
	struct zone_devtab	ztab;
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1069
	di_prof_t		prof = NULL;
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1070
	int			err;
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1071
	int			retval = -1;
3448
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  1072
	zone_iptype_t		iptype;
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  1073
	const char 		*curr_iptype;
2712
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1074
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1075
	if (di_prof_init(devpath, &prof)) {
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1076
		zerror(zlogp, B_TRUE, "failed to initialize profile");
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1077
		goto cleanup;
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1078
	}
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1079
7655
76c161ee52b3 6746514 RFE: need ability to mount non-native branded zones
<gerald.jelinek@sun.com>
parents: 7370
diff changeset
  1080
	/*
76c161ee52b3 6746514 RFE: need ability to mount non-native branded zones
<gerald.jelinek@sun.com>
parents: 7370
diff changeset
  1081
	 * Get a handle to the brand info for this zone.
10943
b45d62b629cd 6889379 zoneadm mount fails on opensolaris
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 10796
diff changeset
  1082
	 * If we are mounting the zone, then we must always use the default
7655
76c161ee52b3 6746514 RFE: need ability to mount non-native branded zones
<gerald.jelinek@sun.com>
parents: 7370
diff changeset
  1083
	 * brand device mounts.
76c161ee52b3 6746514 RFE: need ability to mount non-native branded zones
<gerald.jelinek@sun.com>
parents: 7370
diff changeset
  1084
	 */
76c161ee52b3 6746514 RFE: need ability to mount non-native branded zones
<gerald.jelinek@sun.com>
parents: 7370
diff changeset
  1085
	if (ALT_MOUNT(mount_cmd)) {
10943
b45d62b629cd 6889379 zoneadm mount fails on opensolaris
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 10796
diff changeset
  1086
		(void) strlcpy(brand, default_brand, sizeof (brand));
7655
76c161ee52b3 6746514 RFE: need ability to mount non-native branded zones
<gerald.jelinek@sun.com>
parents: 7370
diff changeset
  1087
	} else {
10796
c03a117618e2 6874636 RFE: zoneadmd should mount cluster branded zones as native in alternate roots.
Steve Lawrence <Stephen.Lawrence@Sun.COM>
parents: 10616
diff changeset
  1088
		(void) strlcpy(brand, brand_name, sizeof (brand));
7655
76c161ee52b3 6746514 RFE: need ability to mount non-native branded zones
<gerald.jelinek@sun.com>
parents: 7370
diff changeset
  1089
	}
76c161ee52b3 6746514 RFE: need ability to mount non-native branded zones
<gerald.jelinek@sun.com>
parents: 7370
diff changeset
  1090
76c161ee52b3 6746514 RFE: need ability to mount non-native branded zones
<gerald.jelinek@sun.com>
parents: 7370
diff changeset
  1091
	if ((bh = brand_open(brand)) == NULL) {
2712
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1092
		zerror(zlogp, B_FALSE, "unable to determine zone brand");
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1093
		goto cleanup;
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1094
	}
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1095
10616
3be00c4a6835 PSARC 2009/373 Clearview IP Tunneling
Sebastien Roy <Sebastien.Roy@Sun.COM>
parents: 10067
diff changeset
  1096
	if (vplat_get_iptype(zlogp, &iptype) < 0) {
3448
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  1097
		zerror(zlogp, B_TRUE, "unable to determine ip-type");
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  1098
		goto cleanup;
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  1099
	}
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  1100
	switch (iptype) {
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  1101
	case ZS_SHARED:
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  1102
		curr_iptype = "shared";
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  1103
		break;
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  1104
	case ZS_EXCLUSIVE:
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  1105
		curr_iptype = "exclusive";
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  1106
		break;
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  1107
	}
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  1108
2727
fa06bd58f0f9 6469453 invalid assert in ioctl.c:ldlinux_check()
edp
parents: 2712
diff changeset
  1109
	if (brand_platform_iter_devices(bh, zone_name,
3448
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  1110
	    mount_one_dev_device_cb, prof, curr_iptype) != 0) {
2712
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1111
		zerror(zlogp, B_TRUE, "failed to add standard device");
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1112
		goto cleanup;
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1113
	}
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1114
2727
fa06bd58f0f9 6469453 invalid assert in ioctl.c:ldlinux_check()
edp
parents: 2712
diff changeset
  1115
	if (brand_platform_iter_link(bh,
2712
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1116
	    mount_one_dev_symlink_cb, prof) != 0) {
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1117
		zerror(zlogp, B_TRUE, "failed to add standard symlink");
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1118
		goto cleanup;
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1119
	}
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1120
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1121
	/* Add user-specified devices and directories */
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1122
	if ((handle = zonecfg_init_handle()) == NULL) {
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1123
		zerror(zlogp, B_FALSE, "can't initialize zone handle");
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1124
		goto cleanup;
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1125
	}
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1126
	if (err = zonecfg_get_handle(zone_name, handle)) {
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1127
		zerror(zlogp, B_FALSE, "can't get handle for zone "
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1128
		    "%s: %s", zone_name, zonecfg_strerror(err));
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1129
		goto cleanup;
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1130
	}
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1131
	if (err = zonecfg_setdevent(handle)) {
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1132
		zerror(zlogp, B_FALSE, "%s: %s", zone_name,
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1133
		    zonecfg_strerror(err));
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1134
		goto cleanup;
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1135
	}
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1136
	while (zonecfg_getdevent(handle, &ztab) == Z_OK) {
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1137
		if (di_prof_add_dev(prof, ztab.zone_dev_match)) {
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1138
			zerror(zlogp, B_TRUE, "failed to add "
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1139
			    "user-specified device");
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1140
			goto cleanup;
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1141
		}
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1142
	}
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1143
	(void) zonecfg_enddevent(handle);
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1144
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1145
	/* Send profile to kernel */
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1146
	if (di_prof_commit(prof)) {
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1147
		zerror(zlogp, B_TRUE, "failed to commit profile");
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1148
		goto cleanup;
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1149
	}
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1150
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1151
	retval = 0;
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1152
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1153
cleanup:
2727
fa06bd58f0f9 6469453 invalid assert in ioctl.c:ldlinux_check()
edp
parents: 2712
diff changeset
  1154
	if (bh != NULL)
fa06bd58f0f9 6469453 invalid assert in ioctl.c:ldlinux_check()
edp
parents: 2712
diff changeset
  1155
		brand_close(bh);
3716
1429cb51c952 6527301 zoneadmd has sprung a few leaks
gjelinek
parents: 3688
diff changeset
  1156
	if (handle != NULL)
2712
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1157
		zonecfg_fini_handle(handle);
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1158
	if (prof)
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1159
		di_prof_fini(prof);
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1160
	return (retval);
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1161
}
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1162
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1163
static int
7655
76c161ee52b3 6746514 RFE: need ability to mount non-native branded zones
<gerald.jelinek@sun.com>
parents: 7370
diff changeset
  1164
mount_one(zlog_t *zlogp, struct zone_fstab *fsptr, const char *rootpath,
76c161ee52b3 6746514 RFE: need ability to mount non-native branded zones
<gerald.jelinek@sun.com>
parents: 7370
diff changeset
  1165
    zone_mnt_t mount_cmd)
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1166
{
2712
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1167
	char path[MAXPATHLEN];
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1168
	char optstr[MAX_MNTOPT_STR];
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1169
	zone_fsopt_t *optptr;
2712
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1170
	int rv;
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1171
5182
1933ef4db196 6572723 zoneadmd should allow lofs mounts on files
edp
parents: 4791
diff changeset
  1172
	if ((rv = valid_mount_path(zlogp, rootpath, fsptr->zone_fs_special,
1933ef4db196 6572723 zoneadmd should allow lofs mounts on files
edp
parents: 4791
diff changeset
  1173
	    fsptr->zone_fs_dir, fsptr->zone_fs_type)) < 0) {
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1174
		zerror(zlogp, B_FALSE, "%s%s is not a valid mount point",
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1175
		    rootpath, fsptr->zone_fs_dir);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1176
		return (-1);
5182
1933ef4db196 6572723 zoneadmd should allow lofs mounts on files
edp
parents: 4791
diff changeset
  1177
	} else if (rv > 0) {
1933ef4db196 6572723 zoneadmd should allow lofs mounts on files
edp
parents: 4791
diff changeset
  1178
		/* The mount point path doesn't exist, create it now. */
1933ef4db196 6572723 zoneadmd should allow lofs mounts on files
edp
parents: 4791
diff changeset
  1179
		if (make_one_dir(zlogp, rootpath, fsptr->zone_fs_dir,
1933ef4db196 6572723 zoneadmd should allow lofs mounts on files
edp
parents: 4791
diff changeset
  1180
		    DEFAULT_DIR_MODE, DEFAULT_DIR_USER,
1933ef4db196 6572723 zoneadmd should allow lofs mounts on files
edp
parents: 4791
diff changeset
  1181
		    DEFAULT_DIR_GROUP) != 0) {
1933ef4db196 6572723 zoneadmd should allow lofs mounts on files
edp
parents: 4791
diff changeset
  1182
			zerror(zlogp, B_FALSE, "failed to create mount point");
1933ef4db196 6572723 zoneadmd should allow lofs mounts on files
edp
parents: 4791
diff changeset
  1183
			return (-1);
1933ef4db196 6572723 zoneadmd should allow lofs mounts on files
edp
parents: 4791
diff changeset
  1184
		}
1933ef4db196 6572723 zoneadmd should allow lofs mounts on files
edp
parents: 4791
diff changeset
  1185
1933ef4db196 6572723 zoneadmd should allow lofs mounts on files
edp
parents: 4791
diff changeset
  1186
		/*
1933ef4db196 6572723 zoneadmd should allow lofs mounts on files
edp
parents: 4791
diff changeset
  1187
		 * Now this might seem weird, but we need to invoke
1933ef4db196 6572723 zoneadmd should allow lofs mounts on files
edp
parents: 4791
diff changeset
  1188
		 * valid_mount_path() again.  Why?  Because it checks
1933ef4db196 6572723 zoneadmd should allow lofs mounts on files
edp
parents: 4791
diff changeset
  1189
		 * to make sure that the mount point path is canonical,
1933ef4db196 6572723 zoneadmd should allow lofs mounts on files
edp
parents: 4791
diff changeset
  1190
		 * which it can only do if the path exists, so now that
1933ef4db196 6572723 zoneadmd should allow lofs mounts on files
edp
parents: 4791
diff changeset
  1191
		 * we've created the path we have to verify it again.
1933ef4db196 6572723 zoneadmd should allow lofs mounts on files
edp
parents: 4791
diff changeset
  1192
		 */
1933ef4db196 6572723 zoneadmd should allow lofs mounts on files
edp
parents: 4791
diff changeset
  1193
		if ((rv = valid_mount_path(zlogp, rootpath,
1933ef4db196 6572723 zoneadmd should allow lofs mounts on files
edp
parents: 4791
diff changeset
  1194
		    fsptr->zone_fs_special, fsptr->zone_fs_dir,
1933ef4db196 6572723 zoneadmd should allow lofs mounts on files
edp
parents: 4791
diff changeset
  1195
		    fsptr->zone_fs_type)) < 0) {
1933ef4db196 6572723 zoneadmd should allow lofs mounts on files
edp
parents: 4791
diff changeset
  1196
			zerror(zlogp, B_FALSE,
1933ef4db196 6572723 zoneadmd should allow lofs mounts on files
edp
parents: 4791
diff changeset
  1197
			    "%s%s is not a valid mount point",
1933ef4db196 6572723 zoneadmd should allow lofs mounts on files
edp
parents: 4791
diff changeset
  1198
			    rootpath, fsptr->zone_fs_dir);
1933ef4db196 6572723 zoneadmd should allow lofs mounts on files
edp
parents: 4791
diff changeset
  1199
			return (-1);
1933ef4db196 6572723 zoneadmd should allow lofs mounts on files
edp
parents: 4791
diff changeset
  1200
		}
1933ef4db196 6572723 zoneadmd should allow lofs mounts on files
edp
parents: 4791
diff changeset
  1201
	}
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1202
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1203
	(void) snprintf(path, sizeof (path), "%s%s", rootpath,
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1204
	    fsptr->zone_fs_dir);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1205
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1206
	/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1207
	 * In general the strategy here is to do just as much verification as
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1208
	 * necessary to avoid crashing or otherwise doing something bad; if the
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1209
	 * administrator initiated the operation via zoneadm(1m), he'll get
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1210
	 * auto-verification which will let him know what's wrong.  If he
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1211
	 * modifies the zone configuration of a running zone and doesn't attempt
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1212
	 * to verify that it's OK we won't crash but won't bother trying to be
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1213
	 * too helpful either.  zoneadm verify is only a couple keystrokes away.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1214
	 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1215
	if (!zonecfg_valid_fs_type(fsptr->zone_fs_type)) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1216
		zerror(zlogp, B_FALSE, "cannot mount %s on %s: "
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1217
		    "invalid file-system type %s", fsptr->zone_fs_special,
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1218
		    fsptr->zone_fs_dir, fsptr->zone_fs_type);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1219
		return (-1);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1220
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1221
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1222
	/*
766
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  1223
	 * If we're looking at an alternate root environment, then construct
3688
bd23485682e4 6523454 zoneadm fails to scratchmount a zone in the miniroot
edp
parents: 3673
diff changeset
  1224
	 * read-only loopback mounts as necessary.  Note that any special
bd23485682e4 6523454 zoneadm fails to scratchmount a zone in the miniroot
edp
parents: 3673
diff changeset
  1225
	 * paths for lofs zone mounts in an alternate root must have
bd23485682e4 6523454 zoneadm fails to scratchmount a zone in the miniroot
edp
parents: 3673
diff changeset
  1226
	 * already been pre-pended with any alternate root path by the
bd23485682e4 6523454 zoneadm fails to scratchmount a zone in the miniroot
edp
parents: 3673
diff changeset
  1227
	 * time we get here.
766
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  1228
	 */
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  1229
	if (zonecfg_in_alt_root()) {
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  1230
		struct stat64 st;
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  1231
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  1232
		if (stat64(fsptr->zone_fs_special, &st) != -1 &&
2772
284bda1a2ceb 6471974 zoneadm mount mishandles shared file systems
carlsonj
parents: 2727
diff changeset
  1233
		    S_ISBLK(st.st_mode)) {
3688
bd23485682e4 6523454 zoneadm fails to scratchmount a zone in the miniroot
edp
parents: 3673
diff changeset
  1234
			/*
bd23485682e4 6523454 zoneadm fails to scratchmount a zone in the miniroot
edp
parents: 3673
diff changeset
  1235
			 * If we're going to mount a block device we need
bd23485682e4 6523454 zoneadm fails to scratchmount a zone in the miniroot
edp
parents: 3673
diff changeset
  1236
			 * to check if that device is already mounted
bd23485682e4 6523454 zoneadm fails to scratchmount a zone in the miniroot
edp
parents: 3673
diff changeset
  1237
			 * somewhere else, and if so, do a lofs mount
bd23485682e4 6523454 zoneadm fails to scratchmount a zone in the miniroot
edp
parents: 3673
diff changeset
  1238
			 * of the device instead of a direct mount
bd23485682e4 6523454 zoneadm fails to scratchmount a zone in the miniroot
edp
parents: 3673
diff changeset
  1239
			 */
2772
284bda1a2ceb 6471974 zoneadm mount mishandles shared file systems
carlsonj
parents: 2727
diff changeset
  1240
			if (check_lofs_needed(zlogp, fsptr) == -1)
284bda1a2ceb 6471974 zoneadm mount mishandles shared file systems
carlsonj
parents: 2727
diff changeset
  1241
				return (-1);
284bda1a2ceb 6471974 zoneadm mount mishandles shared file systems
carlsonj
parents: 2727
diff changeset
  1242
		} else if (strcmp(fsptr->zone_fs_type, MNTTYPE_LOFS) == 0) {
3688
bd23485682e4 6523454 zoneadm fails to scratchmount a zone in the miniroot
edp
parents: 3673
diff changeset
  1243
			/*
bd23485682e4 6523454 zoneadm fails to scratchmount a zone in the miniroot
edp
parents: 3673
diff changeset
  1244
			 * For lofs mounts, the special node is inside the
bd23485682e4 6523454 zoneadm fails to scratchmount a zone in the miniroot
edp
parents: 3673
diff changeset
  1245
			 * alternate root.  We need lofs resolution for
bd23485682e4 6523454 zoneadm fails to scratchmount a zone in the miniroot
edp
parents: 3673
diff changeset
  1246
			 * this case in order to get at the underlying
bd23485682e4 6523454 zoneadm fails to scratchmount a zone in the miniroot
edp
parents: 3673
diff changeset
  1247
			 * read-write path.
bd23485682e4 6523454 zoneadm fails to scratchmount a zone in the miniroot
edp
parents: 3673
diff changeset
  1248
			 */
bd23485682e4 6523454 zoneadm fails to scratchmount a zone in the miniroot
edp
parents: 3673
diff changeset
  1249
			resolve_lofs(zlogp, fsptr->zone_fs_special,
766
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  1250
			    sizeof (fsptr->zone_fs_special));
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  1251
		}
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  1252
	}
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  1253
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  1254
	/*
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1255
	 * Run 'fsck -m' if there's a device to fsck.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1256
	 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1257
	if (fsptr->zone_fs_raw[0] != '\0' &&
6734
d16dda992d39 PSARC/2008/290 lofi mount
johnlev
parents: 6631
diff changeset
  1258
	    dofsck(zlogp, fsptr->zone_fs_type, fsptr->zone_fs_raw) != 0) {
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1259
		return (-1);
6734
d16dda992d39 PSARC/2008/290 lofi mount
johnlev
parents: 6631
diff changeset
  1260
	} else if (isregfile(fsptr->zone_fs_special) == 1 &&
d16dda992d39 PSARC/2008/290 lofi mount
johnlev
parents: 6631
diff changeset
  1261
	    dofsck(zlogp, fsptr->zone_fs_type, fsptr->zone_fs_special) != 0) {
d16dda992d39 PSARC/2008/290 lofi mount
johnlev
parents: 6631
diff changeset
  1262
		return (-1);
d16dda992d39 PSARC/2008/290 lofi mount
johnlev
parents: 6631
diff changeset
  1263
	}
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1264
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1265
	/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1266
	 * Build up mount option string.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1267
	 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1268
	optstr[0] = '\0';
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1269
	if (fsptr->zone_fs_options != NULL) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1270
		(void) strlcpy(optstr, fsptr->zone_fs_options->zone_fsopt_opt,
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1271
		    sizeof (optstr));
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1272
		for (optptr = fsptr->zone_fs_options->zone_fsopt_next;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1273
		    optptr != NULL; optptr = optptr->zone_fsopt_next) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1274
			(void) strlcat(optstr, ",", sizeof (optstr));
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1275
			(void) strlcat(optstr, optptr->zone_fsopt_opt,
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1276
			    sizeof (optstr));
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1277
		}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1278
	}
2712
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1279
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1280
	if ((rv = domount(zlogp, fsptr->zone_fs_type, optstr,
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1281
	    fsptr->zone_fs_special, path)) != 0)
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1282
		return (rv);
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1283
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1284
	/*
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1285
	 * The mount succeeded.  If this was not a mount of /dev then
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1286
	 * we're done.
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1287
	 */
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1288
	if (strcmp(fsptr->zone_fs_type, MNTTYPE_DEV) != 0)
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1289
		return (0);
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1290
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1291
	/*
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1292
	 * We just mounted an instance of a /dev filesystem, so now we
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1293
	 * need to configure it.
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1294
	 */
7655
76c161ee52b3 6746514 RFE: need ability to mount non-native branded zones
<gerald.jelinek@sun.com>
parents: 7370
diff changeset
  1295
	return (mount_one_dev(zlogp, path, mount_cmd));
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1296
}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1297
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1298
static void
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1299
free_fs_data(struct zone_fstab *fsarray, uint_t nelem)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1300
{
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1301
	uint_t i;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1302
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1303
	if (fsarray == NULL)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1304
		return;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1305
	for (i = 0; i < nelem; i++)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1306
		zonecfg_free_fs_option_list(fsarray[i].zone_fs_options);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1307
	free(fsarray);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1308
}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1309
766
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  1310
/*
2653
2d7674c15d98 6463524 separate /var filesystem not mounted in scratch zone
vp157776
parents: 2621
diff changeset
  1311
 * This function initiates the creation of a small Solaris Environment for
2d7674c15d98 6463524 separate /var filesystem not mounted in scratch zone
vp157776
parents: 2621
diff changeset
  1312
 * scratch zone. The Environment creation process is split up into two
2d7674c15d98 6463524 separate /var filesystem not mounted in scratch zone
vp157776
parents: 2621
diff changeset
  1313
 * functions(build_mounted_pre_var() and build_mounted_post_var()). It
2d7674c15d98 6463524 separate /var filesystem not mounted in scratch zone
vp157776
parents: 2621
diff changeset
  1314
 * is done this way because:
2d7674c15d98 6463524 separate /var filesystem not mounted in scratch zone
vp157776
parents: 2621
diff changeset
  1315
 * 	We need to have both /etc and /var in the root of the scratchzone.
2d7674c15d98 6463524 separate /var filesystem not mounted in scratch zone
vp157776
parents: 2621
diff changeset
  1316
 * 	We loopback mount zone's own /etc and /var into the root of the
2d7674c15d98 6463524 separate /var filesystem not mounted in scratch zone
vp157776
parents: 2621
diff changeset
  1317
 * 	scratch zone. Unlike /etc, /var can be a seperate filesystem. So we
2d7674c15d98 6463524 separate /var filesystem not mounted in scratch zone
vp157776
parents: 2621
diff changeset
  1318
 * 	need to delay the mount of /var till the zone's root gets populated.
2d7674c15d98 6463524 separate /var filesystem not mounted in scratch zone
vp157776
parents: 2621
diff changeset
  1319
 *	So mounting of localdirs[](/etc and /var) have been moved to the
2d7674c15d98 6463524 separate /var filesystem not mounted in scratch zone
vp157776
parents: 2621
diff changeset
  1320
 * 	build_mounted_post_var() which gets called only after the zone
2d7674c15d98 6463524 separate /var filesystem not mounted in scratch zone
vp157776
parents: 2621
diff changeset
  1321
 * 	specific filesystems are mounted.
5829
20241b1ccadc PSARC 2007/621 zone update on attach
gjelinek
parents: 5596
diff changeset
  1322
 *
20241b1ccadc PSARC 2007/621 zone update on attach
gjelinek
parents: 5596
diff changeset
  1323
 * Note that the scratch zone we set up for updating the zone (Z_MNT_UPDATE)
20241b1ccadc PSARC 2007/621 zone update on attach
gjelinek
parents: 5596
diff changeset
  1324
 * does not loopback mount the zone's own /etc and /var into the root of the
20241b1ccadc PSARC 2007/621 zone update on attach
gjelinek
parents: 5596
diff changeset
  1325
 * scratch zone.
766
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  1326
 */
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  1327
static boolean_t
2653
2d7674c15d98 6463524 separate /var filesystem not mounted in scratch zone
vp157776
parents: 2621
diff changeset
  1328
build_mounted_pre_var(zlog_t *zlogp, char *rootpath,
3071
7fdd962e12e3 6479675 lucreate fails when making new boot environment bootable
vp157776
parents: 2772
diff changeset
  1329
    size_t rootlen, const char *zonepath, char *luroot, size_t lurootlen)
766
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  1330
{
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  1331
	char tmp[MAXPATHLEN], fromdir[MAXPATHLEN];
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  1332
	const char **cpp;
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  1333
	static const char *mkdirs[] = {
2592
008725356a5a 6462530 Fix for 6387493 broke zoneadm clone and mount operations
dp
parents: 2503
diff changeset
  1334
		"/system", "/system/contract", "/system/object", "/proc",
008725356a5a 6462530 Fix for 6387493 broke zoneadm clone and mount operations
dp
parents: 2503
diff changeset
  1335
		"/dev", "/tmp", "/a", NULL
766
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  1336
	};
2653
2d7674c15d98 6463524 separate /var filesystem not mounted in scratch zone
vp157776
parents: 2621
diff changeset
  1337
	char *altstr;
766
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  1338
	FILE *fp;
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  1339
	uuid_t uuid;
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  1340
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  1341
	resolve_lofs(zlogp, rootpath, rootlen);
3071
7fdd962e12e3 6479675 lucreate fails when making new boot environment bootable
vp157776
parents: 2772
diff changeset
  1342
	(void) snprintf(luroot, lurootlen, "%s/lu", zonepath);
7fdd962e12e3 6479675 lucreate fails when making new boot environment bootable
vp157776
parents: 2772
diff changeset
  1343
	resolve_lofs(zlogp, luroot, lurootlen);
766
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  1344
	(void) snprintf(tmp, sizeof (tmp), "%s/bin", luroot);
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  1345
	(void) symlink("./usr/bin", tmp);
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  1346
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  1347
	/*
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  1348
	 * These are mostly special mount points; not handled here.  (See
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  1349
	 * zone_mount_early.)
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  1350
	 */
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  1351
	for (cpp = mkdirs; *cpp != NULL; cpp++) {
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  1352
		(void) snprintf(tmp, sizeof (tmp), "%s%s", luroot, *cpp);
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  1353
		if (mkdir(tmp, 0755) != 0) {
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  1354
			zerror(zlogp, B_TRUE, "cannot create %s", tmp);
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  1355
			return (B_FALSE);
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  1356
		}
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  1357
	}
2653
2d7674c15d98 6463524 separate /var filesystem not mounted in scratch zone
vp157776
parents: 2621
diff changeset
  1358
	/*
2d7674c15d98 6463524 separate /var filesystem not mounted in scratch zone
vp157776
parents: 2621
diff changeset
  1359
	 * This is here to support lucopy.  If there's an instance of this same
2d7674c15d98 6463524 separate /var filesystem not mounted in scratch zone
vp157776
parents: 2621
diff changeset
  1360
	 * zone on the current running system, then we mount its root up as
2d7674c15d98 6463524 separate /var filesystem not mounted in scratch zone
vp157776
parents: 2621
diff changeset
  1361
	 * read-only inside the scratch zone.
2d7674c15d98 6463524 separate /var filesystem not mounted in scratch zone
vp157776
parents: 2621
diff changeset
  1362
	 */
2d7674c15d98 6463524 separate /var filesystem not mounted in scratch zone
vp157776
parents: 2621
diff changeset
  1363
	(void) zonecfg_get_uuid(zone_name, uuid);
2d7674c15d98 6463524 separate /var filesystem not mounted in scratch zone
vp157776
parents: 2621
diff changeset
  1364
	altstr = strdup(zonecfg_get_root());
2d7674c15d98 6463524 separate /var filesystem not mounted in scratch zone
vp157776
parents: 2621
diff changeset
  1365
	if (altstr == NULL) {
2d7674c15d98 6463524 separate /var filesystem not mounted in scratch zone
vp157776
parents: 2621
diff changeset
  1366
		zerror(zlogp, B_TRUE, "memory allocation failed");
2d7674c15d98 6463524 separate /var filesystem not mounted in scratch zone
vp157776
parents: 2621
diff changeset
  1367
		return (B_FALSE);
2d7674c15d98 6463524 separate /var filesystem not mounted in scratch zone
vp157776
parents: 2621
diff changeset
  1368
	}
2d7674c15d98 6463524 separate /var filesystem not mounted in scratch zone
vp157776
parents: 2621
diff changeset
  1369
	zonecfg_set_root("");
2d7674c15d98 6463524 separate /var filesystem not mounted in scratch zone
vp157776
parents: 2621
diff changeset
  1370
	(void) strlcpy(tmp, zone_name, sizeof (tmp));
2d7674c15d98 6463524 separate /var filesystem not mounted in scratch zone
vp157776
parents: 2621
diff changeset
  1371
	(void) zonecfg_get_name_by_uuid(uuid, tmp, sizeof (tmp));
2d7674c15d98 6463524 separate /var filesystem not mounted in scratch zone
vp157776
parents: 2621
diff changeset
  1372
	if (zone_get_rootpath(tmp, fromdir, sizeof (fromdir)) == Z_OK &&
2d7674c15d98 6463524 separate /var filesystem not mounted in scratch zone
vp157776
parents: 2621
diff changeset
  1373
	    strcmp(fromdir, rootpath) != 0) {
2d7674c15d98 6463524 separate /var filesystem not mounted in scratch zone
vp157776
parents: 2621
diff changeset
  1374
		(void) snprintf(tmp, sizeof (tmp), "%s/b", luroot);
2d7674c15d98 6463524 separate /var filesystem not mounted in scratch zone
vp157776
parents: 2621
diff changeset
  1375
		if (mkdir(tmp, 0755) != 0) {
2d7674c15d98 6463524 separate /var filesystem not mounted in scratch zone
vp157776
parents: 2621
diff changeset
  1376
			zerror(zlogp, B_TRUE, "cannot create %s", tmp);
2d7674c15d98 6463524 separate /var filesystem not mounted in scratch zone
vp157776
parents: 2621
diff changeset
  1377
			return (B_FALSE);
2d7674c15d98 6463524 separate /var filesystem not mounted in scratch zone
vp157776
parents: 2621
diff changeset
  1378
		}
12734
76969fc28795 6939693 zones no longer needs the inherit-pkg-dir property
Gary Pennington <gary.pennington@oracle.com>
parents: 12725
diff changeset
  1379
		if (domount(zlogp, MNTTYPE_LOFS, RESOURCE_DEFAULT_OPTS, fromdir,
2653
2d7674c15d98 6463524 separate /var filesystem not mounted in scratch zone
vp157776
parents: 2621
diff changeset
  1380
		    tmp) != 0) {
2d7674c15d98 6463524 separate /var filesystem not mounted in scratch zone
vp157776
parents: 2621
diff changeset
  1381
			zerror(zlogp, B_TRUE, "cannot mount %s on %s", tmp,
2d7674c15d98 6463524 separate /var filesystem not mounted in scratch zone
vp157776
parents: 2621
diff changeset
  1382
			    fromdir);
2d7674c15d98 6463524 separate /var filesystem not mounted in scratch zone
vp157776
parents: 2621
diff changeset
  1383
			return (B_FALSE);
2d7674c15d98 6463524 separate /var filesystem not mounted in scratch zone
vp157776
parents: 2621
diff changeset
  1384
		}
2d7674c15d98 6463524 separate /var filesystem not mounted in scratch zone
vp157776
parents: 2621
diff changeset
  1385
	}
2d7674c15d98 6463524 separate /var filesystem not mounted in scratch zone
vp157776
parents: 2621
diff changeset
  1386
	zonecfg_set_root(altstr);
2d7674c15d98 6463524 separate /var filesystem not mounted in scratch zone
vp157776
parents: 2621
diff changeset
  1387
	free(altstr);
2d7674c15d98 6463524 separate /var filesystem not mounted in scratch zone
vp157776
parents: 2621
diff changeset
  1388
2d7674c15d98 6463524 separate /var filesystem not mounted in scratch zone
vp157776
parents: 2621
diff changeset
  1389
	if ((fp = zonecfg_open_scratch(luroot, B_TRUE)) == NULL) {
2d7674c15d98 6463524 separate /var filesystem not mounted in scratch zone
vp157776
parents: 2621
diff changeset
  1390
		zerror(zlogp, B_TRUE, "cannot open zone mapfile");
2d7674c15d98 6463524 separate /var filesystem not mounted in scratch zone
vp157776
parents: 2621
diff changeset
  1391
		return (B_FALSE);
2d7674c15d98 6463524 separate /var filesystem not mounted in scratch zone
vp157776
parents: 2621
diff changeset
  1392
	}
2d7674c15d98 6463524 separate /var filesystem not mounted in scratch zone
vp157776
parents: 2621
diff changeset
  1393
	(void) ftruncate(fileno(fp), 0);
2d7674c15d98 6463524 separate /var filesystem not mounted in scratch zone
vp157776
parents: 2621
diff changeset
  1394
	if (zonecfg_add_scratch(fp, zone_name, kernzone, "/") == -1) {
2d7674c15d98 6463524 separate /var filesystem not mounted in scratch zone
vp157776
parents: 2621
diff changeset
  1395
		zerror(zlogp, B_TRUE, "cannot add zone mapfile entry");
2d7674c15d98 6463524 separate /var filesystem not mounted in scratch zone
vp157776
parents: 2621
diff changeset
  1396
	}
2d7674c15d98 6463524 separate /var filesystem not mounted in scratch zone
vp157776
parents: 2621
diff changeset
  1397
	zonecfg_close_scratch(fp);
2d7674c15d98 6463524 separate /var filesystem not mounted in scratch zone
vp157776
parents: 2621
diff changeset
  1398
	(void) snprintf(tmp, sizeof (tmp), "%s/a", luroot);
2d7674c15d98 6463524 separate /var filesystem not mounted in scratch zone
vp157776
parents: 2621
diff changeset
  1399
	if (domount(zlogp, MNTTYPE_LOFS, "", rootpath, tmp) != 0)
2d7674c15d98 6463524 separate /var filesystem not mounted in scratch zone
vp157776
parents: 2621
diff changeset
  1400
		return (B_FALSE);
2d7674c15d98 6463524 separate /var filesystem not mounted in scratch zone
vp157776
parents: 2621
diff changeset
  1401
	(void) strlcpy(rootpath, tmp, rootlen);
2d7674c15d98 6463524 separate /var filesystem not mounted in scratch zone
vp157776
parents: 2621
diff changeset
  1402
	return (B_TRUE);
2d7674c15d98 6463524 separate /var filesystem not mounted in scratch zone
vp157776
parents: 2621
diff changeset
  1403
}
2d7674c15d98 6463524 separate /var filesystem not mounted in scratch zone
vp157776
parents: 2621
diff changeset
  1404
2d7674c15d98 6463524 separate /var filesystem not mounted in scratch zone
vp157776
parents: 2621
diff changeset
  1405
2d7674c15d98 6463524 separate /var filesystem not mounted in scratch zone
vp157776
parents: 2621
diff changeset
  1406
static boolean_t
5829
20241b1ccadc PSARC 2007/621 zone update on attach
gjelinek
parents: 5596
diff changeset
  1407
build_mounted_post_var(zlog_t *zlogp, zone_mnt_t mount_cmd, char *rootpath,
20241b1ccadc PSARC 2007/621 zone update on attach
gjelinek
parents: 5596
diff changeset
  1408
    const char *luroot)
2653
2d7674c15d98 6463524 separate /var filesystem not mounted in scratch zone
vp157776
parents: 2621
diff changeset
  1409
{
2d7674c15d98 6463524 separate /var filesystem not mounted in scratch zone
vp157776
parents: 2621
diff changeset
  1410
	char tmp[MAXPATHLEN], fromdir[MAXPATHLEN];
2d7674c15d98 6463524 separate /var filesystem not mounted in scratch zone
vp157776
parents: 2621
diff changeset
  1411
	const char **cpp;
5829
20241b1ccadc PSARC 2007/621 zone update on attach
gjelinek
parents: 5596
diff changeset
  1412
	const char **loopdirs;
20241b1ccadc PSARC 2007/621 zone update on attach
gjelinek
parents: 5596
diff changeset
  1413
	const char **tmpdirs;
2653
2d7674c15d98 6463524 separate /var filesystem not mounted in scratch zone
vp157776
parents: 2621
diff changeset
  1414
	static const char *localdirs[] = {
2d7674c15d98 6463524 separate /var filesystem not mounted in scratch zone
vp157776
parents: 2621
diff changeset
  1415
		"/etc", "/var", NULL
2d7674c15d98 6463524 separate /var filesystem not mounted in scratch zone
vp157776
parents: 2621
diff changeset
  1416
	};
5829
20241b1ccadc PSARC 2007/621 zone update on attach
gjelinek
parents: 5596
diff changeset
  1417
	static const char *scr_loopdirs[] = {
2653
2d7674c15d98 6463524 separate /var filesystem not mounted in scratch zone
vp157776
parents: 2621
diff changeset
  1418
		"/etc/lib", "/etc/fs", "/lib", "/sbin", "/platform",
2d7674c15d98 6463524 separate /var filesystem not mounted in scratch zone
vp157776
parents: 2621
diff changeset
  1419
		"/usr", NULL
2d7674c15d98 6463524 separate /var filesystem not mounted in scratch zone
vp157776
parents: 2621
diff changeset
  1420
	};
5829
20241b1ccadc PSARC 2007/621 zone update on attach
gjelinek
parents: 5596
diff changeset
  1421
	static const char *upd_loopdirs[] = {
20241b1ccadc PSARC 2007/621 zone update on attach
gjelinek
parents: 5596
diff changeset
  1422
		"/etc", "/kernel", "/lib", "/opt", "/platform", "/sbin",
20241b1ccadc PSARC 2007/621 zone update on attach
gjelinek
parents: 5596
diff changeset
  1423
		"/usr", "/var", NULL
20241b1ccadc PSARC 2007/621 zone update on attach
gjelinek
parents: 5596
diff changeset
  1424
	};
20241b1ccadc PSARC 2007/621 zone update on attach
gjelinek
parents: 5596
diff changeset
  1425
	static const char *scr_tmpdirs[] = {
2653
2d7674c15d98 6463524 separate /var filesystem not mounted in scratch zone
vp157776
parents: 2621
diff changeset
  1426
		"/tmp", "/var/run", NULL
2d7674c15d98 6463524 separate /var filesystem not mounted in scratch zone
vp157776
parents: 2621
diff changeset
  1427
	};
5829
20241b1ccadc PSARC 2007/621 zone update on attach
gjelinek
parents: 5596
diff changeset
  1428
	static const char *upd_tmpdirs[] = {
20241b1ccadc PSARC 2007/621 zone update on attach
gjelinek
parents: 5596
diff changeset
  1429
		"/tmp", "/var/run", "/var/tmp", NULL
20241b1ccadc PSARC 2007/621 zone update on attach
gjelinek
parents: 5596
diff changeset
  1430
	};
2653
2d7674c15d98 6463524 separate /var filesystem not mounted in scratch zone
vp157776
parents: 2621
diff changeset
  1431
	struct stat st;
2d7674c15d98 6463524 separate /var filesystem not mounted in scratch zone
vp157776
parents: 2621
diff changeset
  1432
5829
20241b1ccadc PSARC 2007/621 zone update on attach
gjelinek
parents: 5596
diff changeset
  1433
	if (mount_cmd == Z_MNT_SCRATCH) {
20241b1ccadc PSARC 2007/621 zone update on attach
gjelinek
parents: 5596
diff changeset
  1434
		/*
20241b1ccadc PSARC 2007/621 zone update on attach
gjelinek
parents: 5596
diff changeset
  1435
		 * These are mounted read-write from the zone undergoing
20241b1ccadc PSARC 2007/621 zone update on attach
gjelinek
parents: 5596
diff changeset
  1436
		 * upgrade.  We must be careful not to 'leak' things from the
20241b1ccadc PSARC 2007/621 zone update on attach
gjelinek
parents: 5596
diff changeset
  1437
		 * main system into the zone, and this accomplishes that goal.
20241b1ccadc PSARC 2007/621 zone update on attach
gjelinek
parents: 5596
diff changeset
  1438
		 */
20241b1ccadc PSARC 2007/621 zone update on attach
gjelinek
parents: 5596
diff changeset
  1439
		for (cpp = localdirs; *cpp != NULL; cpp++) {
20241b1ccadc PSARC 2007/621 zone update on attach
gjelinek
parents: 5596
diff changeset
  1440
			(void) snprintf(tmp, sizeof (tmp), "%s%s", luroot,
20241b1ccadc PSARC 2007/621 zone update on attach
gjelinek
parents: 5596
diff changeset
  1441
			    *cpp);
20241b1ccadc PSARC 2007/621 zone update on attach
gjelinek
parents: 5596
diff changeset
  1442
			(void) snprintf(fromdir, sizeof (fromdir), "%s%s",
20241b1ccadc PSARC 2007/621 zone update on attach
gjelinek
parents: 5596
diff changeset
  1443
			    rootpath, *cpp);
20241b1ccadc PSARC 2007/621 zone update on attach
gjelinek
parents: 5596
diff changeset
  1444
			if (mkdir(tmp, 0755) != 0) {
20241b1ccadc PSARC 2007/621 zone update on attach
gjelinek
parents: 5596
diff changeset
  1445
				zerror(zlogp, B_TRUE, "cannot create %s", tmp);
20241b1ccadc PSARC 2007/621 zone update on attach
gjelinek
parents: 5596
diff changeset
  1446
				return (B_FALSE);
20241b1ccadc PSARC 2007/621 zone update on attach
gjelinek
parents: 5596
diff changeset
  1447
			}
20241b1ccadc PSARC 2007/621 zone update on attach
gjelinek
parents: 5596
diff changeset
  1448
			if (domount(zlogp, MNTTYPE_LOFS, "", fromdir, tmp)
20241b1ccadc PSARC 2007/621 zone update on attach
gjelinek
parents: 5596
diff changeset
  1449
			    != 0) {
20241b1ccadc PSARC 2007/621 zone update on attach
gjelinek
parents: 5596
diff changeset
  1450
				zerror(zlogp, B_TRUE, "cannot mount %s on %s",
20241b1ccadc PSARC 2007/621 zone update on attach
gjelinek
parents: 5596
diff changeset
  1451
				    tmp, *cpp);
20241b1ccadc PSARC 2007/621 zone update on attach
gjelinek
parents: 5596
diff changeset
  1452
				return (B_FALSE);
20241b1ccadc PSARC 2007/621 zone update on attach
gjelinek
parents: 5596
diff changeset
  1453
			}
766
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  1454
		}
5829
20241b1ccadc PSARC 2007/621 zone update on attach
gjelinek
parents: 5596
diff changeset
  1455
	}
20241b1ccadc PSARC 2007/621 zone update on attach
gjelinek
parents: 5596
diff changeset
  1456
20241b1ccadc PSARC 2007/621 zone update on attach
gjelinek
parents: 5596
diff changeset
  1457
	if (mount_cmd == Z_MNT_UPDATE)
20241b1ccadc PSARC 2007/621 zone update on attach
gjelinek
parents: 5596
diff changeset
  1458
		loopdirs = upd_loopdirs;
20241b1ccadc PSARC 2007/621 zone update on attach
gjelinek
parents: 5596
diff changeset
  1459
	else
20241b1ccadc PSARC 2007/621 zone update on attach
gjelinek
parents: 5596
diff changeset
  1460
		loopdirs = scr_loopdirs;
766
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  1461
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  1462
	/*
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  1463
	 * These are things mounted read-only from the running system because
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  1464
	 * they contain binaries that must match system.
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  1465
	 */
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  1466
	for (cpp = loopdirs; *cpp != NULL; cpp++) {
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  1467
		(void) snprintf(tmp, sizeof (tmp), "%s%s", luroot, *cpp);
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  1468
		if (mkdir(tmp, 0755) != 0) {
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  1469
			if (errno != EEXIST) {
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  1470
				zerror(zlogp, B_TRUE, "cannot create %s", tmp);
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  1471
				return (B_FALSE);
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  1472
			}
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  1473
			if (lstat(tmp, &st) != 0) {
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  1474
				zerror(zlogp, B_TRUE, "cannot stat %s", tmp);
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  1475
				return (B_FALSE);
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  1476
			}
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  1477
			/*
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  1478
			 * Ignore any non-directories encountered.  These are
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  1479
			 * things that have been converted into symlinks
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  1480
			 * (/etc/fs and /etc/lib) and no longer need a lofs
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  1481
			 * fixup.
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  1482
			 */
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  1483
			if (!S_ISDIR(st.st_mode))
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  1484
				continue;
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  1485
		}
12734
76969fc28795 6939693 zones no longer needs the inherit-pkg-dir property
Gary Pennington <gary.pennington@oracle.com>
parents: 12725
diff changeset
  1486
		if (domount(zlogp, MNTTYPE_LOFS, RESOURCE_DEFAULT_OPTS, *cpp,
766
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  1487
		    tmp) != 0) {
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  1488
			zerror(zlogp, B_TRUE, "cannot mount %s on %s", tmp,
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  1489
			    *cpp);
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  1490
			return (B_FALSE);
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  1491
		}
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  1492
	}
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  1493
5829
20241b1ccadc PSARC 2007/621 zone update on attach
gjelinek
parents: 5596
diff changeset
  1494
	if (mount_cmd == Z_MNT_UPDATE)
20241b1ccadc PSARC 2007/621 zone update on attach
gjelinek
parents: 5596
diff changeset
  1495
		tmpdirs = upd_tmpdirs;
20241b1ccadc PSARC 2007/621 zone update on attach
gjelinek
parents: 5596
diff changeset
  1496
	else
20241b1ccadc PSARC 2007/621 zone update on attach
gjelinek
parents: 5596
diff changeset
  1497
		tmpdirs = scr_tmpdirs;
20241b1ccadc PSARC 2007/621 zone update on attach
gjelinek
parents: 5596
diff changeset
  1498
766
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  1499
	/*
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  1500
	 * These are things with tmpfs mounted inside.
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  1501
	 */
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  1502
	for (cpp = tmpdirs; *cpp != NULL; cpp++) {
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  1503
		(void) snprintf(tmp, sizeof (tmp), "%s%s", luroot, *cpp);
5829
20241b1ccadc PSARC 2007/621 zone update on attach
gjelinek
parents: 5596
diff changeset
  1504
		if (mount_cmd == Z_MNT_SCRATCH && mkdir(tmp, 0755) != 0 &&
20241b1ccadc PSARC 2007/621 zone update on attach
gjelinek
parents: 5596
diff changeset
  1505
		    errno != EEXIST) {
766
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  1506
			zerror(zlogp, B_TRUE, "cannot create %s", tmp);
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  1507
			return (B_FALSE);
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  1508
		}
3514
afbbbffc464b 6507630 default scratch zone permissions on /tmp overly restrictive
gjelinek
parents: 3448
diff changeset
  1509
afbbbffc464b 6507630 default scratch zone permissions on /tmp overly restrictive
gjelinek
parents: 3448
diff changeset
  1510
		/*
afbbbffc464b 6507630 default scratch zone permissions on /tmp overly restrictive
gjelinek
parents: 3448
diff changeset
  1511
		 * We could set the mode for /tmp when we do the mkdir but
afbbbffc464b 6507630 default scratch zone permissions on /tmp overly restrictive
gjelinek
parents: 3448
diff changeset
  1512
		 * since that can be modified by the umask we will just set
afbbbffc464b 6507630 default scratch zone permissions on /tmp overly restrictive
gjelinek
parents: 3448
diff changeset
  1513
		 * the correct mode for /tmp now.
afbbbffc464b 6507630 default scratch zone permissions on /tmp overly restrictive
gjelinek
parents: 3448
diff changeset
  1514
		 */
afbbbffc464b 6507630 default scratch zone permissions on /tmp overly restrictive
gjelinek
parents: 3448
diff changeset
  1515
		if (strcmp(*cpp, "/tmp") == 0 && chmod(tmp, 01777) != 0) {
afbbbffc464b 6507630 default scratch zone permissions on /tmp overly restrictive
gjelinek
parents: 3448
diff changeset
  1516
			zerror(zlogp, B_TRUE, "cannot chmod %s", tmp);
afbbbffc464b 6507630 default scratch zone permissions on /tmp overly restrictive
gjelinek
parents: 3448
diff changeset
  1517
			return (B_FALSE);
afbbbffc464b 6507630 default scratch zone permissions on /tmp overly restrictive
gjelinek
parents: 3448
diff changeset
  1518
		}
afbbbffc464b 6507630 default scratch zone permissions on /tmp overly restrictive
gjelinek
parents: 3448
diff changeset
  1519
766
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  1520
		if (domount(zlogp, MNTTYPE_TMPFS, "", "swap", tmp) != 0) {
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  1521
			zerror(zlogp, B_TRUE, "cannot mount swap on %s", *cpp);
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  1522
			return (B_FALSE);
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  1523
		}
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  1524
	}
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  1525
	return (B_TRUE);
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  1526
}
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  1527
2712
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1528
typedef struct plat_gmount_cb_data {
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1529
	zlog_t			*pgcd_zlogp;
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1530
	struct zone_fstab	**pgcd_fs_tab;
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1531
	int			*pgcd_num_fs;
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1532
} plat_gmount_cb_data_t;
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1533
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1534
/*
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1535
 * plat_gmount_cb() is a callback function invoked by libbrand to iterate
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1536
 * through all global brand platform mounts.
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1537
 */
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1538
int
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1539
plat_gmount_cb(void *data, const char *spec, const char *dir,
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1540
    const char *fstype, const char *opt)
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1541
{
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1542
	plat_gmount_cb_data_t	*cp = data;
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1543
	zlog_t			*zlogp = cp->pgcd_zlogp;
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1544
	struct zone_fstab	*fs_ptr = *cp->pgcd_fs_tab;
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1545
	int			num_fs = *cp->pgcd_num_fs;
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1546
	struct zone_fstab	*fsp, *tmp_ptr;
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1547
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1548
	num_fs++;
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1549
	if ((tmp_ptr = realloc(fs_ptr, num_fs * sizeof (*tmp_ptr))) == NULL) {
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1550
		zerror(zlogp, B_TRUE, "memory allocation failed");
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1551
		return (-1);
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1552
	}
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1553
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1554
	fs_ptr = tmp_ptr;
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1555
	fsp = &fs_ptr[num_fs - 1];
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1556
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1557
	/* update the callback struct passed in */
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1558
	*cp->pgcd_fs_tab = fs_ptr;
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1559
	*cp->pgcd_num_fs = num_fs;
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1560
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1561
	fsp->zone_fs_raw[0] = '\0';
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1562
	(void) strlcpy(fsp->zone_fs_special, spec,
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1563
	    sizeof (fsp->zone_fs_special));
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1564
	(void) strlcpy(fsp->zone_fs_dir, dir, sizeof (fsp->zone_fs_dir));
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1565
	(void) strlcpy(fsp->zone_fs_type, fstype, sizeof (fsp->zone_fs_type));
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1566
	fsp->zone_fs_options = NULL;
3688
bd23485682e4 6523454 zoneadm fails to scratchmount a zone in the miniroot
edp
parents: 3673
diff changeset
  1567
	if ((opt != NULL) &&
bd23485682e4 6523454 zoneadm fails to scratchmount a zone in the miniroot
edp
parents: 3673
diff changeset
  1568
	    (zonecfg_add_fs_option(fsp, (char *)opt) != Z_OK)) {
2712
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1569
		zerror(zlogp, B_FALSE, "error adding property");
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1570
		return (-1);
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1571
	}
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1572
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1573
	return (0);
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1574
}
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1575
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1576
static int
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1577
mount_filesystems_fsent(zone_dochandle_t handle, zlog_t *zlogp,
5829
20241b1ccadc PSARC 2007/621 zone update on attach
gjelinek
parents: 5596
diff changeset
  1578
    struct zone_fstab **fs_tabp, int *num_fsp, zone_mnt_t mount_cmd)
2712
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1579
{
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1580
	struct zone_fstab *tmp_ptr, *fs_ptr, *fsp, fstab;
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1581
	int num_fs;
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1582
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1583
	num_fs = *num_fsp;
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1584
	fs_ptr = *fs_tabp;
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1585
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1586
	if (zonecfg_setfsent(handle) != Z_OK) {
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1587
		zerror(zlogp, B_FALSE, "invalid configuration");
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1588
		return (-1);
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1589
	}
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1590
	while (zonecfg_getfsent(handle, &fstab) == Z_OK) {
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1591
		/*
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1592
		 * ZFS filesystems will not be accessible under an alternate
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1593
		 * root, since the pool will not be known.  Ignore them in this
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1594
		 * case.
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1595
		 */
5829
20241b1ccadc PSARC 2007/621 zone update on attach
gjelinek
parents: 5596
diff changeset
  1596
		if (ALT_MOUNT(mount_cmd) &&
20241b1ccadc PSARC 2007/621 zone update on attach
gjelinek
parents: 5596
diff changeset
  1597
		    strcmp(fstab.zone_fs_type, MNTTYPE_ZFS) == 0)
2712
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1598
			continue;
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1599
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1600
		num_fs++;
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1601
		if ((tmp_ptr = realloc(fs_ptr,
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1602
		    num_fs * sizeof (*tmp_ptr))) == NULL) {
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1603
			zerror(zlogp, B_TRUE, "memory allocation failed");
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1604
			(void) zonecfg_endfsent(handle);
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1605
			return (-1);
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1606
		}
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1607
		/* update the pointers passed in */
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1608
		*fs_tabp = tmp_ptr;
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1609
		*num_fsp = num_fs;
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1610
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1611
		fs_ptr = tmp_ptr;
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1612
		fsp = &fs_ptr[num_fs - 1];
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1613
		(void) strlcpy(fsp->zone_fs_dir,
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1614
		    fstab.zone_fs_dir, sizeof (fsp->zone_fs_dir));
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1615
		(void) strlcpy(fsp->zone_fs_raw, fstab.zone_fs_raw,
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1616
		    sizeof (fsp->zone_fs_raw));
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1617
		(void) strlcpy(fsp->zone_fs_type, fstab.zone_fs_type,
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1618
		    sizeof (fsp->zone_fs_type));
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1619
		fsp->zone_fs_options = fstab.zone_fs_options;
3688
bd23485682e4 6523454 zoneadm fails to scratchmount a zone in the miniroot
edp
parents: 3673
diff changeset
  1620
bd23485682e4 6523454 zoneadm fails to scratchmount a zone in the miniroot
edp
parents: 3673
diff changeset
  1621
		/*
bd23485682e4 6523454 zoneadm fails to scratchmount a zone in the miniroot
edp
parents: 3673
diff changeset
  1622
		 * For all lofs mounts, make sure that the 'special'
bd23485682e4 6523454 zoneadm fails to scratchmount a zone in the miniroot
edp
parents: 3673
diff changeset
  1623
		 * entry points inside the alternate root.  The
bd23485682e4 6523454 zoneadm fails to scratchmount a zone in the miniroot
edp
parents: 3673
diff changeset
  1624
		 * source path for a lofs mount in a given zone needs
bd23485682e4 6523454 zoneadm fails to scratchmount a zone in the miniroot
edp
parents: 3673
diff changeset
  1625
		 * to be relative to the root of the boot environment
bd23485682e4 6523454 zoneadm fails to scratchmount a zone in the miniroot
edp
parents: 3673
diff changeset
  1626
		 * that contains the zone.  Note that we don't do this
bd23485682e4 6523454 zoneadm fails to scratchmount a zone in the miniroot
edp
parents: 3673
diff changeset
  1627
		 * for non-lofs mounts since they will have a device
bd23485682e4 6523454 zoneadm fails to scratchmount a zone in the miniroot
edp
parents: 3673
diff changeset
  1628
		 * as a backing store and device paths must always be
bd23485682e4 6523454 zoneadm fails to scratchmount a zone in the miniroot
edp
parents: 3673
diff changeset
  1629
		 * specified relative to the current boot environment.
bd23485682e4 6523454 zoneadm fails to scratchmount a zone in the miniroot
edp
parents: 3673
diff changeset
  1630
		 */
bd23485682e4 6523454 zoneadm fails to scratchmount a zone in the miniroot
edp
parents: 3673
diff changeset
  1631
		fsp->zone_fs_special[0] = '\0';
bd23485682e4 6523454 zoneadm fails to scratchmount a zone in the miniroot
edp
parents: 3673
diff changeset
  1632
		if (strcmp(fsp->zone_fs_type, MNTTYPE_LOFS) == 0) {
bd23485682e4 6523454 zoneadm fails to scratchmount a zone in the miniroot
edp
parents: 3673
diff changeset
  1633
			(void) strlcat(fsp->zone_fs_special, zonecfg_get_root(),
bd23485682e4 6523454 zoneadm fails to scratchmount a zone in the miniroot
edp
parents: 3673
diff changeset
  1634
			    sizeof (fsp->zone_fs_special));
bd23485682e4 6523454 zoneadm fails to scratchmount a zone in the miniroot
edp
parents: 3673
diff changeset
  1635
		}
bd23485682e4 6523454 zoneadm fails to scratchmount a zone in the miniroot
edp
parents: 3673
diff changeset
  1636
		(void) strlcat(fsp->zone_fs_special, fstab.zone_fs_special,
bd23485682e4 6523454 zoneadm fails to scratchmount a zone in the miniroot
edp
parents: 3673
diff changeset
  1637
		    sizeof (fsp->zone_fs_special));
2712
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1638
	}
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1639
	(void) zonecfg_endfsent(handle);
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1640
	return (0);
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1641
}
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1642
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1643
static int
5829
20241b1ccadc PSARC 2007/621 zone update on attach
gjelinek
parents: 5596
diff changeset
  1644
mount_filesystems(zlog_t *zlogp, zone_mnt_t mount_cmd)
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1645
{
2712
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1646
	char rootpath[MAXPATHLEN];
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1647
	char zonepath[MAXPATHLEN];
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1648
	char brand[MAXNAMELEN];
3071
7fdd962e12e3 6479675 lucreate fails when making new boot environment bootable
vp157776
parents: 2772
diff changeset
  1649
	char luroot[MAXPATHLEN];
2712
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1650
	int i, num_fs = 0;
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1651
	struct zone_fstab *fs_ptr = NULL;
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1652
	zone_dochandle_t handle = NULL;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1653
	zone_state_t zstate;
2727
fa06bd58f0f9 6469453 invalid assert in ioctl.c:ldlinux_check()
edp
parents: 2712
diff changeset
  1654
	brand_handle_t bh;
2712
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1655
	plat_gmount_cb_data_t cb;
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1656
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1657
	if (zone_get_state(zone_name, &zstate) != Z_OK ||
766
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  1658
	    (zstate != ZONE_STATE_READY && zstate != ZONE_STATE_MOUNTED)) {
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1659
		zerror(zlogp, B_FALSE,
766
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  1660
		    "zone must be in '%s' or '%s' state to mount file-systems",
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  1661
		    zone_state_str(ZONE_STATE_READY),
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  1662
		    zone_state_str(ZONE_STATE_MOUNTED));
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1663
		goto bad;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1664
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1665
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1666
	if (zone_get_zonepath(zone_name, zonepath, sizeof (zonepath)) != Z_OK) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1667
		zerror(zlogp, B_TRUE, "unable to determine zone path");
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1668
		goto bad;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1669
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1670
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1671
	if (zone_get_rootpath(zone_name, rootpath, sizeof (rootpath)) != Z_OK) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1672
		zerror(zlogp, B_TRUE, "unable to determine zone root");
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1673
		goto bad;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1674
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1675
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1676
	if ((handle = zonecfg_init_handle()) == NULL) {
1645
5c204cdba7d2 PSARC 2006/124 Configurable Privileges for Zones
comay
parents: 1544
diff changeset
  1677
		zerror(zlogp, B_TRUE, "getting zone configuration handle");
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1678
		goto bad;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1679
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1680
	if (zonecfg_get_snapshot_handle(zone_name, handle) != Z_OK ||
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1681
	    zonecfg_setfsent(handle) != Z_OK) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1682
		zerror(zlogp, B_FALSE, "invalid configuration");
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1683
		goto bad;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1684
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1685
7655
76c161ee52b3 6746514 RFE: need ability to mount non-native branded zones
<gerald.jelinek@sun.com>
parents: 7370
diff changeset
  1686
	/*
10943
b45d62b629cd 6889379 zoneadm mount fails on opensolaris
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 10796
diff changeset
  1687
	 * If we are mounting the zone, then we must always use the default
7655
76c161ee52b3 6746514 RFE: need ability to mount non-native branded zones
<gerald.jelinek@sun.com>
parents: 7370
diff changeset
  1688
	 * brand global mounts.
76c161ee52b3 6746514 RFE: need ability to mount non-native branded zones
<gerald.jelinek@sun.com>
parents: 7370
diff changeset
  1689
	 */
76c161ee52b3 6746514 RFE: need ability to mount non-native branded zones
<gerald.jelinek@sun.com>
parents: 7370
diff changeset
  1690
	if (ALT_MOUNT(mount_cmd)) {
10943
b45d62b629cd 6889379 zoneadm mount fails on opensolaris
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 10796
diff changeset
  1691
		(void) strlcpy(brand, default_brand, sizeof (brand));
7655
76c161ee52b3 6746514 RFE: need ability to mount non-native branded zones
<gerald.jelinek@sun.com>
parents: 7370
diff changeset
  1692
	} else {
10796
c03a117618e2 6874636 RFE: zoneadmd should mount cluster branded zones as native in alternate roots.
Steve Lawrence <Stephen.Lawrence@Sun.COM>
parents: 10616
diff changeset
  1693
		(void) strlcpy(brand, brand_name, sizeof (brand));
7655
76c161ee52b3 6746514 RFE: need ability to mount non-native branded zones
<gerald.jelinek@sun.com>
parents: 7370
diff changeset
  1694
	}
76c161ee52b3 6746514 RFE: need ability to mount non-native branded zones
<gerald.jelinek@sun.com>
parents: 7370
diff changeset
  1695
2712
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1696
	/* Get a handle to the brand info for this zone */
7655
76c161ee52b3 6746514 RFE: need ability to mount non-native branded zones
<gerald.jelinek@sun.com>
parents: 7370
diff changeset
  1697
	if ((bh = brand_open(brand)) == NULL) {
2712
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1698
		zerror(zlogp, B_FALSE, "unable to determine zone brand");
3716
1429cb51c952 6527301 zoneadmd has sprung a few leaks
gjelinek
parents: 3688
diff changeset
  1699
		zonecfg_fini_handle(handle);
2712
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1700
		return (-1);
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1701
	}
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1702
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1703
	/*
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1704
	 * Get the list of global filesystems to mount from the brand
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1705
	 * configuration.
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1706
	 */
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1707
	cb.pgcd_zlogp = zlogp;
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1708
	cb.pgcd_fs_tab = &fs_ptr;
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1709
	cb.pgcd_num_fs = &num_fs;
2727
fa06bd58f0f9 6469453 invalid assert in ioctl.c:ldlinux_check()
edp
parents: 2712
diff changeset
  1710
	if (brand_platform_iter_gmounts(bh, zonepath,
2712
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1711
	    plat_gmount_cb, &cb) != 0) {
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1712
		zerror(zlogp, B_FALSE, "unable to mount filesystems");
2727
fa06bd58f0f9 6469453 invalid assert in ioctl.c:ldlinux_check()
edp
parents: 2712
diff changeset
  1713
		brand_close(bh);
3716
1429cb51c952 6527301 zoneadmd has sprung a few leaks
gjelinek
parents: 3688
diff changeset
  1714
		zonecfg_fini_handle(handle);
2712
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1715
		return (-1);
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1716
	}
2727
fa06bd58f0f9 6469453 invalid assert in ioctl.c:ldlinux_check()
edp
parents: 2712
diff changeset
  1717
	brand_close(bh);
2712
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1718
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1719
	/*
12734
76969fc28795 6939693 zones no longer needs the inherit-pkg-dir property
Gary Pennington <gary.pennington@oracle.com>
parents: 12725
diff changeset
  1720
	 * Iterate through the rest of the filesystems. Sort them all,
76969fc28795 6939693 zones no longer needs the inherit-pkg-dir property
Gary Pennington <gary.pennington@oracle.com>
parents: 12725
diff changeset
  1721
	 * then mount them in sorted order. This is to make sure the
76969fc28795 6939693 zones no longer needs the inherit-pkg-dir property
Gary Pennington <gary.pennington@oracle.com>
parents: 12725
diff changeset
  1722
	 * higher level directories (e.g., /usr) get mounted before
76969fc28795 6939693 zones no longer needs the inherit-pkg-dir property
Gary Pennington <gary.pennington@oracle.com>
parents: 12725
diff changeset
  1723
	 * any beneath them (e.g., /usr/local).
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1724
	 */
2712
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1725
	if (mount_filesystems_fsent(handle, zlogp, &fs_ptr, &num_fs,
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1726
	    mount_cmd) != 0)
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1727
		goto bad;
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1728
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1729
	zonecfg_fini_handle(handle);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1730
	handle = NULL;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1731
766
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  1732
	/*
2712
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1733
	 * Normally when we mount a zone all the zone filesystems
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1734
	 * get mounted relative to rootpath, which is usually
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1735
	 * <zonepath>/root.  But when mounting a zone for administration
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1736
	 * purposes via the zone "mount" state, build_mounted_pre_var()
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1737
	 * updates rootpath to be <zonepath>/lu/a so we'll mount all
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1738
	 * the zones filesystems there instead.
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1739
	 *
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1740
	 * build_mounted_pre_var() and build_mounted_post_var() will
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1741
	 * also do some extra work to create directories and lofs mount
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1742
	 * a bunch of global zone file system paths into <zonepath>/lu.
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1743
	 *
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1744
	 * This allows us to be able to enter the zone (now rooted at
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1745
	 * <zonepath>/lu) and run the upgrade/patch tools that are in the
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1746
	 * global zone and have them upgrade the to-be-modified zone's
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1747
	 * files mounted on /a.  (Which mirrors the existing standard
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1748
	 * upgrade environment.)
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1749
	 *
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1750
	 * There is of course one catch.  When doing the upgrade
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1751
	 * we need <zoneroot>/lu/dev to be the /dev filesystem
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1752
	 * for the zone and we don't want to have any /dev filesystem
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1753
	 * mounted at <zoneroot>/lu/a/dev.  Since /dev is specified
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1754
	 * as a normal zone filesystem by default we'll try to mount
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1755
	 * it at <zoneroot>/lu/a/dev, so we have to detect this
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1756
	 * case and instead mount it at <zoneroot>/lu/dev.
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1757
	 *
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1758
	 * All this work is done in three phases:
2653
2d7674c15d98 6463524 separate /var filesystem not mounted in scratch zone
vp157776
parents: 2621
diff changeset
  1759
	 *   1) Create and populate lu directory (build_mounted_pre_var()).
2d7674c15d98 6463524 separate /var filesystem not mounted in scratch zone
vp157776
parents: 2621
diff changeset
  1760
	 *   2) Mount the required filesystems as per the zone configuration.
2d7674c15d98 6463524 separate /var filesystem not mounted in scratch zone
vp157776
parents: 2621
diff changeset
  1761
	 *   3) Set up the rest of the scratch zone environment
2d7674c15d98 6463524 separate /var filesystem not mounted in scratch zone
vp157776
parents: 2621
diff changeset
  1762
	 *	(build_mounted_post_var()).
766
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  1763
	 */
5829
20241b1ccadc PSARC 2007/621 zone update on attach
gjelinek
parents: 5596
diff changeset
  1764
	if (ALT_MOUNT(mount_cmd) && !build_mounted_pre_var(zlogp,
3071
7fdd962e12e3 6479675 lucreate fails when making new boot environment bootable
vp157776
parents: 2772
diff changeset
  1765
	    rootpath, sizeof (rootpath), zonepath, luroot, sizeof (luroot)))
766
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  1766
		goto bad;
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  1767
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1768
	qsort(fs_ptr, num_fs, sizeof (*fs_ptr), fs_compare);
2712
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1769
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1770
	for (i = 0; i < num_fs; i++) {
5829
20241b1ccadc PSARC 2007/621 zone update on attach
gjelinek
parents: 5596
diff changeset
  1771
		if (ALT_MOUNT(mount_cmd) &&
2712
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1772
		    strcmp(fs_ptr[i].zone_fs_dir, "/dev") == 0) {
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1773
			size_t slen = strlen(rootpath) - 2;
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1774
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1775
			/*
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1776
			 * By default we'll try to mount /dev as /a/dev
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1777
			 * but /dev is special and always goes at the top
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1778
			 * so strip the trailing '/a' from the rootpath.
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1779
			 */
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1780
			assert(strcmp(&rootpath[slen], "/a") == 0);
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1781
			rootpath[slen] = '\0';
7655
76c161ee52b3 6746514 RFE: need ability to mount non-native branded zones
<gerald.jelinek@sun.com>
parents: 7370
diff changeset
  1782
			if (mount_one(zlogp, &fs_ptr[i], rootpath, mount_cmd)
76c161ee52b3 6746514 RFE: need ability to mount non-native branded zones
<gerald.jelinek@sun.com>
parents: 7370
diff changeset
  1783
			    != 0)
2712
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1784
				goto bad;
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1785
			rootpath[slen] = '/';
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1786
			continue;
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  1787
		}
7655
76c161ee52b3 6746514 RFE: need ability to mount non-native branded zones
<gerald.jelinek@sun.com>
parents: 7370
diff changeset
  1788
		if (mount_one(zlogp, &fs_ptr[i], rootpath, mount_cmd) != 0)
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1789
			goto bad;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1790
	}
5829
20241b1ccadc PSARC 2007/621 zone update on attach
gjelinek
parents: 5596
diff changeset
  1791
	if (ALT_MOUNT(mount_cmd) &&
20241b1ccadc PSARC 2007/621 zone update on attach
gjelinek
parents: 5596
diff changeset
  1792
	    !build_mounted_post_var(zlogp, mount_cmd, rootpath, luroot))
2653
2d7674c15d98 6463524 separate /var filesystem not mounted in scratch zone
vp157776
parents: 2621
diff changeset
  1793
		goto bad;
1676
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  1794
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  1795
	/*
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  1796
	 * For Trusted Extensions cross-mount each lower level /export/home
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  1797
	 */
5829
20241b1ccadc PSARC 2007/621 zone update on attach
gjelinek
parents: 5596
diff changeset
  1798
	if (mount_cmd == Z_MNT_BOOT &&
20241b1ccadc PSARC 2007/621 zone update on attach
gjelinek
parents: 5596
diff changeset
  1799
	    tsol_mounts(zlogp, zone_name, rootpath) != 0)
1676
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  1800
		goto bad;
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  1801
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1802
	free_fs_data(fs_ptr, num_fs);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1803
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1804
	/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1805
	 * Everything looks fine.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1806
	 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1807
	return (0);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1808
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1809
bad:
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1810
	if (handle != NULL)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1811
		zonecfg_fini_handle(handle);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1812
	free_fs_data(fs_ptr, num_fs);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1813
	return (-1);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1814
}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1815
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1816
/* caller makes sure neither parameter is NULL */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1817
static int
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1818
addr2netmask(char *prefixstr, int maxprefixlen, uchar_t *maskstr)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1819
{
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1820
	int prefixlen;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1821
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1822
	prefixlen = atoi(prefixstr);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1823
	if (prefixlen < 0 || prefixlen > maxprefixlen)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1824
		return (1);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1825
	while (prefixlen > 0) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1826
		if (prefixlen >= 8) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1827
			*maskstr++ = 0xFF;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1828
			prefixlen -= 8;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1829
			continue;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1830
		}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1831
		*maskstr |= 1 << (8 - prefixlen);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1832
		prefixlen--;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1833
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1834
	return (0);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1835
}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1836
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1837
/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1838
 * Tear down all interfaces belonging to the given zone.  This should
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1839
 * be called with the zone in a state other than "running", so that
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1840
 * interfaces can't be assigned to the zone after this returns.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1841
 *
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1842
 * If anything goes wrong, log an error message and return an error.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1843
 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1844
static int
3448
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  1845
unconfigure_shared_network_interfaces(zlog_t *zlogp, zoneid_t zone_id)
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1846
{
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1847
	struct lifnum lifn;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1848
	struct lifconf lifc;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1849
	struct lifreq *lifrp, lifrl;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1850
	int64_t lifc_flags = LIFC_NOXMIT | LIFC_ALLZONES;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1851
	int num_ifs, s, i, ret_code = 0;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1852
	uint_t bufsize;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1853
	char *buf = NULL;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1854
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1855
	if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1856
		zerror(zlogp, B_TRUE, "could not get socket");
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1857
		ret_code = -1;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1858
		goto bad;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1859
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1860
	lifn.lifn_family = AF_UNSPEC;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1861
	lifn.lifn_flags = (int)lifc_flags;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1862
	if (ioctl(s, SIOCGLIFNUM, (char *)&lifn) < 0) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1863
		zerror(zlogp, B_TRUE,
3448
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  1864
		    "could not determine number of network interfaces");
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1865
		ret_code = -1;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1866
		goto bad;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1867
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1868
	num_ifs = lifn.lifn_count;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1869
	bufsize = num_ifs * sizeof (struct lifreq);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1870
	if ((buf = malloc(bufsize)) == NULL) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1871
		zerror(zlogp, B_TRUE, "memory allocation failed");
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1872
		ret_code = -1;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1873
		goto bad;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1874
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1875
	lifc.lifc_family = AF_UNSPEC;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1876
	lifc.lifc_flags = (int)lifc_flags;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1877
	lifc.lifc_len = bufsize;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1878
	lifc.lifc_buf = buf;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1879
	if (ioctl(s, SIOCGLIFCONF, (char *)&lifc) < 0) {
3448
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  1880
		zerror(zlogp, B_TRUE, "could not get configured network "
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  1881
		    "interfaces");
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1882
		ret_code = -1;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1883
		goto bad;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1884
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1885
	lifrp = lifc.lifc_req;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1886
	for (i = lifc.lifc_len / sizeof (struct lifreq); i > 0; i--, lifrp++) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1887
		(void) close(s);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1888
		if ((s = socket(lifrp->lifr_addr.ss_family, SOCK_DGRAM, 0)) <
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1889
		    0) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1890
			zerror(zlogp, B_TRUE, "%s: could not get socket",
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1891
			    lifrl.lifr_name);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1892
			ret_code = -1;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1893
			continue;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1894
		}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1895
		(void) memset(&lifrl, 0, sizeof (lifrl));
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1896
		(void) strncpy(lifrl.lifr_name, lifrp->lifr_name,
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1897
		    sizeof (lifrl.lifr_name));
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1898
		if (ioctl(s, SIOCGLIFZONE, (caddr_t)&lifrl) < 0) {
3251
0fb2f0dcf27b 6354498 rctl_local_replace_cb needs to remove new value when deletion fails
sl108498
parents: 3247
diff changeset
  1899
			if (errno == ENXIO)
0fb2f0dcf27b 6354498 rctl_local_replace_cb needs to remove new value when deletion fails
sl108498
parents: 3247
diff changeset
  1900
				/*
0fb2f0dcf27b 6354498 rctl_local_replace_cb needs to remove new value when deletion fails
sl108498
parents: 3247
diff changeset
  1901
				 * Interface may have been removed by admin or
0fb2f0dcf27b 6354498 rctl_local_replace_cb needs to remove new value when deletion fails
sl108498
parents: 3247
diff changeset
  1902
				 * another zone halting.
0fb2f0dcf27b 6354498 rctl_local_replace_cb needs to remove new value when deletion fails
sl108498
parents: 3247
diff changeset
  1903
				 */
0fb2f0dcf27b 6354498 rctl_local_replace_cb needs to remove new value when deletion fails
sl108498
parents: 3247
diff changeset
  1904
				continue;
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1905
			zerror(zlogp, B_TRUE,
3251
0fb2f0dcf27b 6354498 rctl_local_replace_cb needs to remove new value when deletion fails
sl108498
parents: 3247
diff changeset
  1906
			    "%s: could not determine the zone to which this "
3448
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  1907
			    "network interface is bound", lifrl.lifr_name);
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1908
			ret_code = -1;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1909
			continue;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1910
		}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1911
		if (lifrl.lifr_zoneid == zone_id) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1912
			if (ioctl(s, SIOCLIFREMOVEIF, (caddr_t)&lifrl) < 0) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1913
				zerror(zlogp, B_TRUE,
3448
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  1914
				    "%s: could not remove network interface",
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1915
				    lifrl.lifr_name);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1916
				ret_code = -1;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1917
				continue;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1918
			}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1919
		}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1920
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1921
bad:
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1922
	if (s > 0)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1923
		(void) close(s);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1924
	if (buf)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1925
		free(buf);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1926
	return (ret_code);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1927
}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1928
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1929
static union	sockunion {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1930
	struct	sockaddr sa;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1931
	struct	sockaddr_in sin;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1932
	struct	sockaddr_dl sdl;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1933
	struct	sockaddr_in6 sin6;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1934
} so_dst, so_ifp;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1935
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1936
static struct {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1937
	struct	rt_msghdr hdr;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1938
	char	space[512];
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1939
} rtmsg;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1940
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1941
static int
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1942
salen(struct sockaddr *sa)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1943
{
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1944
	switch (sa->sa_family) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1945
	case AF_INET:
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1946
		return (sizeof (struct sockaddr_in));
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1947
	case AF_LINK:
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1948
		return (sizeof (struct sockaddr_dl));
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1949
	case AF_INET6:
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1950
		return (sizeof (struct sockaddr_in6));
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1951
	default:
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1952
		return (sizeof (struct sockaddr));
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1953
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1954
}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1955
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1956
#define	ROUNDUP_LONG(a) \
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1957
	((a) > 0 ? (1 + (((a) - 1) | (sizeof (long) - 1))) : sizeof (long))
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1958
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1959
/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1960
 * Look up which zone is using a given IP address.  The address in question
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1961
 * is expected to have been stuffed into the structure to which lifr points
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1962
 * via a previous SIOCGLIFADDR ioctl().
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1963
 *
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1964
 * This is done using black router socket magic.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1965
 *
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1966
 * Return the name of the zone on success or NULL on failure.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1967
 *
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1968
 * This is a lot of code for a simple task; a new ioctl request to take care
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1969
 * of this might be a useful RFE.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1970
 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1971
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1972
static char *
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1973
who_is_using(zlog_t *zlogp, struct lifreq *lifr)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1974
{
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1975
	static char answer[ZONENAME_MAX];
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1976
	pid_t pid;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1977
	int s, rlen, l, i;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1978
	char *cp = rtmsg.space;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1979
	struct sockaddr_dl *ifp = NULL;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1980
	struct sockaddr *sa;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1981
	char save_if_name[LIFNAMSIZ];
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1982
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1983
	answer[0] = '\0';
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1984
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1985
	pid = getpid();
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1986
	if ((s = socket(PF_ROUTE, SOCK_RAW, 0)) < 0) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1987
		zerror(zlogp, B_TRUE, "could not get routing socket");
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1988
		return (NULL);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1989
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1990
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1991
	if (lifr->lifr_addr.ss_family == AF_INET) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1992
		struct sockaddr_in *sin4;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1993
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1994
		so_dst.sa.sa_family = AF_INET;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1995
		sin4 = (struct sockaddr_in *)&lifr->lifr_addr;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1996
		so_dst.sin.sin_addr = sin4->sin_addr;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1997
	} else {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1998
		struct sockaddr_in6 *sin6;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1999
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2000
		so_dst.sa.sa_family = AF_INET6;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2001
		sin6 = (struct sockaddr_in6 *)&lifr->lifr_addr;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2002
		so_dst.sin6.sin6_addr = sin6->sin6_addr;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2003
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2004
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2005
	so_ifp.sa.sa_family = AF_LINK;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2006
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2007
	(void) memset(&rtmsg, 0, sizeof (rtmsg));
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2008
	rtmsg.hdr.rtm_type = RTM_GET;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2009
	rtmsg.hdr.rtm_flags = RTF_UP | RTF_HOST;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2010
	rtmsg.hdr.rtm_version = RTM_VERSION;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2011
	rtmsg.hdr.rtm_seq = ++rts_seqno;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2012
	rtmsg.hdr.rtm_addrs = RTA_IFP | RTA_DST;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2013
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2014
	l = ROUNDUP_LONG(salen(&so_dst.sa));
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2015
	(void) memmove(cp, &(so_dst), l);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2016
	cp += l;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2017
	l = ROUNDUP_LONG(salen(&so_ifp.sa));
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2018
	(void) memmove(cp, &(so_ifp), l);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2019
	cp += l;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2020
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2021
	rtmsg.hdr.rtm_msglen = l = cp - (char *)&rtmsg;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2022
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2023
	if ((rlen = write(s, &rtmsg, l)) < 0) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2024
		zerror(zlogp, B_TRUE, "writing to routing socket");
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2025
		return (NULL);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2026
	} else if (rlen < (int)rtmsg.hdr.rtm_msglen) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2027
		zerror(zlogp, B_TRUE,
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2028
		    "write to routing socket got only %d for len\n", rlen);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2029
		return (NULL);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2030
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2031
	do {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2032
		l = read(s, &rtmsg, sizeof (rtmsg));
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2033
	} while (l > 0 && (rtmsg.hdr.rtm_seq != rts_seqno ||
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2034
	    rtmsg.hdr.rtm_pid != pid));
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2035
	if (l < 0) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2036
		zerror(zlogp, B_TRUE, "reading from routing socket");
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2037
		return (NULL);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2038
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2039
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2040
	if (rtmsg.hdr.rtm_version != RTM_VERSION) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2041
		zerror(zlogp, B_FALSE,
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2042
		    "routing message version %d not understood",
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2043
		    rtmsg.hdr.rtm_version);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2044
		return (NULL);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2045
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2046
	if (rtmsg.hdr.rtm_msglen != (ushort_t)l) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2047
		zerror(zlogp, B_FALSE, "message length mismatch, "
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2048
		    "expected %d bytes, returned %d bytes",
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2049
		    rtmsg.hdr.rtm_msglen, l);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2050
		return (NULL);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2051
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2052
	if (rtmsg.hdr.rtm_errno != 0)  {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2053
		errno = rtmsg.hdr.rtm_errno;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2054
		zerror(zlogp, B_TRUE, "RTM_GET routing socket message");
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2055
		return (NULL);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2056
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2057
	if ((rtmsg.hdr.rtm_addrs & RTA_IFP) == 0) {
3448
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2058
		zerror(zlogp, B_FALSE, "network interface not found");
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2059
		return (NULL);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2060
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2061
	cp = ((char *)(&rtmsg.hdr + 1));
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2062
	for (i = 1; i != 0; i <<= 1) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2063
		/* LINTED E_BAD_PTR_CAST_ALIGN */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2064
		sa = (struct sockaddr *)cp;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2065
		if (i != RTA_IFP) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2066
			if ((i & rtmsg.hdr.rtm_addrs) != 0)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2067
				cp += ROUNDUP_LONG(salen(sa));
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2068
			continue;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2069
		}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2070
		if (sa->sa_family == AF_LINK &&
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2071
		    ((struct sockaddr_dl *)sa)->sdl_nlen != 0)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2072
			ifp = (struct sockaddr_dl *)sa;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2073
		break;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2074
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2075
	if (ifp == NULL) {
3448
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2076
		zerror(zlogp, B_FALSE, "network interface could not be "
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2077
		    "determined");
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2078
		return (NULL);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2079
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2080
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2081
	/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2082
	 * We need to set the I/F name to what we got above, then do the
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2083
	 * appropriate ioctl to get its zone name.  But lifr->lifr_name is
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2084
	 * used by the calling function to do a REMOVEIF, so if we leave the
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2085
	 * "good" zone's I/F name in place, *that* I/F will be removed instead
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2086
	 * of the bad one.  So we save the old (bad) I/F name before over-
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2087
	 * writing it and doing the ioctl, then restore it after the ioctl.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2088
	 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2089
	(void) strlcpy(save_if_name, lifr->lifr_name, sizeof (save_if_name));
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2090
	(void) strncpy(lifr->lifr_name, ifp->sdl_data, ifp->sdl_nlen);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2091
	lifr->lifr_name[ifp->sdl_nlen] = '\0';
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2092
	i = ioctl(s, SIOCGLIFZONE, lifr);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2093
	(void) strlcpy(lifr->lifr_name, save_if_name, sizeof (save_if_name));
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2094
	if (i < 0) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2095
		zerror(zlogp, B_TRUE,
3448
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2096
		    "%s: could not determine the zone network interface "
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2097
		    "belongs to", lifr->lifr_name);
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2098
		return (NULL);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2099
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2100
	if (getzonenamebyid(lifr->lifr_zoneid, answer, sizeof (answer)) < 0)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2101
		(void) snprintf(answer, sizeof (answer), "%d",
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2102
		    lifr->lifr_zoneid);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2103
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2104
	if (strlen(answer) > 0)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2105
		return (answer);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2106
	return (NULL);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2107
}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2108
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2109
/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2110
 * Configures a single interface: a new virtual interface is added, based on
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2111
 * the physical interface nwiftabptr->zone_nwif_physical, with the address
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2112
 * specified in nwiftabptr->zone_nwif_address, for zone zone_id.  Note that
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2113
 * the "address" can be an IPv6 address (with a /prefixlength required), an
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2114
 * IPv4 address (with a /prefixlength optional), or a name; for the latter,
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2115
 * an IPv4 name-to-address resolution will be attempted.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2116
 *
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2117
 * If anything goes wrong, we log an detailed error message, attempt to tear
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2118
 * down whatever we set up and return an error.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2119
 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2120
static int
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2121
configure_one_interface(zlog_t *zlogp, zoneid_t zone_id,
8058
ead1ee36a8ed 6722583 zoneadmd's default multicast route logic can go
jv227347 <Jordan.Vaughan@Sun.com>
parents: 7714
diff changeset
  2122
    struct zone_nwiftab *nwiftabptr)
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2123
{
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2124
	struct lifreq lifr;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2125
	struct sockaddr_in netmask4;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2126
	struct sockaddr_in6 netmask6;
10067
42ad9bccb964 6848271 zoneadmd: initial assignment of ip address ending with .0 .255 (cidr) doesn't work
Vamsi Nagineni <Vamsi.Krishna@Sun.COM>
parents: 9720
diff changeset
  2127
	struct sockaddr_storage laddr;
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2128
	struct in_addr in4;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2129
	sa_family_t af;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2130
	char *slashp = strchr(nwiftabptr->zone_nwif_address, '/');
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2131
	int s;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2132
	boolean_t got_netmask = B_FALSE;
9720
9a7c48f95b4d 6751345 zoneadmd doesn't set custom netmask for non-loopback addresses hosted on lo0 in shared-ip zones
saurabh vyas - Sun Microsystems - Bangalore India <Saurabh.Vyas@Sun.COM>
parents: 8905
diff changeset
  2133
	boolean_t is_loopback = B_FALSE;
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2134
	char addrstr4[INET_ADDRSTRLEN];
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2135
	int res;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2136
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2137
	res = zonecfg_valid_net_address(nwiftabptr->zone_nwif_address, &lifr);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2138
	if (res != Z_OK) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2139
		zerror(zlogp, B_FALSE, "%s: %s", zonecfg_strerror(res),
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2140
		    nwiftabptr->zone_nwif_address);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2141
		return (-1);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2142
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2143
	af = lifr.lifr_addr.ss_family;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2144
	if (af == AF_INET)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2145
		in4 = ((struct sockaddr_in *)(&lifr.lifr_addr))->sin_addr;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2146
	if ((s = socket(af, SOCK_DGRAM, 0)) < 0) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2147
		zerror(zlogp, B_TRUE, "could not get socket");
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2148
		return (-1);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2149
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2150
10067
42ad9bccb964 6848271 zoneadmd: initial assignment of ip address ending with .0 .255 (cidr) doesn't work
Vamsi Nagineni <Vamsi.Krishna@Sun.COM>
parents: 9720
diff changeset
  2151
	/*
42ad9bccb964 6848271 zoneadmd: initial assignment of ip address ending with .0 .255 (cidr) doesn't work
Vamsi Nagineni <Vamsi.Krishna@Sun.COM>
parents: 9720
diff changeset
  2152
	 * This is a similar kind of "hack" like in addif() to get around
42ad9bccb964 6848271 zoneadmd: initial assignment of ip address ending with .0 .255 (cidr) doesn't work
Vamsi Nagineni <Vamsi.Krishna@Sun.COM>
parents: 9720
diff changeset
  2153
	 * the problem of SIOCLIFADDIF.  The problem is that this ioctl
42ad9bccb964 6848271 zoneadmd: initial assignment of ip address ending with .0 .255 (cidr) doesn't work
Vamsi Nagineni <Vamsi.Krishna@Sun.COM>
parents: 9720
diff changeset
  2154
	 * does not include the netmask when adding a logical interface.
42ad9bccb964 6848271 zoneadmd: initial assignment of ip address ending with .0 .255 (cidr) doesn't work
Vamsi Nagineni <Vamsi.Krishna@Sun.COM>
parents: 9720
diff changeset
  2155
	 * To get around this problem, we first add the logical interface
42ad9bccb964 6848271 zoneadmd: initial assignment of ip address ending with .0 .255 (cidr) doesn't work
Vamsi Nagineni <Vamsi.Krishna@Sun.COM>
parents: 9720
diff changeset
  2156
	 * with a 0 address.  After that, we set the netmask if provided.
42ad9bccb964 6848271 zoneadmd: initial assignment of ip address ending with .0 .255 (cidr) doesn't work
Vamsi Nagineni <Vamsi.Krishna@Sun.COM>
parents: 9720
diff changeset
  2157
	 * Finally we set the interface address.
42ad9bccb964 6848271 zoneadmd: initial assignment of ip address ending with .0 .255 (cidr) doesn't work
Vamsi Nagineni <Vamsi.Krishna@Sun.COM>
parents: 9720
diff changeset
  2158
	 */
42ad9bccb964 6848271 zoneadmd: initial assignment of ip address ending with .0 .255 (cidr) doesn't work
Vamsi Nagineni <Vamsi.Krishna@Sun.COM>
parents: 9720
diff changeset
  2159
	laddr = lifr.lifr_addr;
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2160
	(void) strlcpy(lifr.lifr_name, nwiftabptr->zone_nwif_physical,
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2161
	    sizeof (lifr.lifr_name));
10067
42ad9bccb964 6848271 zoneadmd: initial assignment of ip address ending with .0 .255 (cidr) doesn't work
Vamsi Nagineni <Vamsi.Krishna@Sun.COM>
parents: 9720
diff changeset
  2162
	(void) memset(&lifr.lifr_addr, 0, sizeof (lifr.lifr_addr));
42ad9bccb964 6848271 zoneadmd: initial assignment of ip address ending with .0 .255 (cidr) doesn't work
Vamsi Nagineni <Vamsi.Krishna@Sun.COM>
parents: 9720
diff changeset
  2163
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2164
	if (ioctl(s, SIOCLIFADDIF, (caddr_t)&lifr) < 0) {
2611
72abb3d7690c 6367840 Zones does not boot if configured for a failed network interface
vp157776
parents: 2592
diff changeset
  2165
		/*
72abb3d7690c 6367840 Zones does not boot if configured for a failed network interface
vp157776
parents: 2592
diff changeset
  2166
		 * Here, we know that the interface can't be brought up.
72abb3d7690c 6367840 Zones does not boot if configured for a failed network interface
vp157776
parents: 2592
diff changeset
  2167
		 * A similar warning message was already printed out to
72abb3d7690c 6367840 Zones does not boot if configured for a failed network interface
vp157776
parents: 2592
diff changeset
  2168
		 * the console by zoneadm(1M) so instead we log the
72abb3d7690c 6367840 Zones does not boot if configured for a failed network interface
vp157776
parents: 2592
diff changeset
  2169
		 * message to syslog and continue.
72abb3d7690c 6367840 Zones does not boot if configured for a failed network interface
vp157776
parents: 2592
diff changeset
  2170
		 */
3448
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2171
		zerror(&logsys, B_TRUE, "WARNING: skipping network interface "
2611
72abb3d7690c 6367840 Zones does not boot if configured for a failed network interface
vp157776
parents: 2592
diff changeset
  2172
		    "'%s' which may not be present/plumbed in the "
72abb3d7690c 6367840 Zones does not boot if configured for a failed network interface
vp157776
parents: 2592
diff changeset
  2173
		    "global zone.", lifr.lifr_name);
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2174
		(void) close(s);
2611
72abb3d7690c 6367840 Zones does not boot if configured for a failed network interface
vp157776
parents: 2592
diff changeset
  2175
		return (Z_OK);
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2176
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2177
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2178
	/* Preserve literal IPv4 address for later potential printing. */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2179
	if (af == AF_INET)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2180
		(void) inet_ntop(AF_INET, &in4, addrstr4, INET_ADDRSTRLEN);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2181
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2182
	lifr.lifr_zoneid = zone_id;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2183
	if (ioctl(s, SIOCSLIFZONE, (caddr_t)&lifr) < 0) {
3448
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2184
		zerror(zlogp, B_TRUE, "%s: could not place network interface "
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2185
		    "into zone", lifr.lifr_name);
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2186
		goto bad;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2187
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2188
9720
9a7c48f95b4d 6751345 zoneadmd doesn't set custom netmask for non-loopback addresses hosted on lo0 in shared-ip zones
saurabh vyas - Sun Microsystems - Bangalore India <Saurabh.Vyas@Sun.COM>
parents: 8905
diff changeset
  2189
	/*
9a7c48f95b4d 6751345 zoneadmd doesn't set custom netmask for non-loopback addresses hosted on lo0 in shared-ip zones
saurabh vyas - Sun Microsystems - Bangalore India <Saurabh.Vyas@Sun.COM>
parents: 8905
diff changeset
  2190
	 * Loopback interface will use the default netmask assigned, if no
9a7c48f95b4d 6751345 zoneadmd doesn't set custom netmask for non-loopback addresses hosted on lo0 in shared-ip zones
saurabh vyas - Sun Microsystems - Bangalore India <Saurabh.Vyas@Sun.COM>
parents: 8905
diff changeset
  2191
	 * netmask is found.
9a7c48f95b4d 6751345 zoneadmd doesn't set custom netmask for non-loopback addresses hosted on lo0 in shared-ip zones
saurabh vyas - Sun Microsystems - Bangalore India <Saurabh.Vyas@Sun.COM>
parents: 8905
diff changeset
  2192
	 */
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2193
	if (strcmp(nwiftabptr->zone_nwif_physical, "lo0") == 0) {
9720
9a7c48f95b4d 6751345 zoneadmd doesn't set custom netmask for non-loopback addresses hosted on lo0 in shared-ip zones
saurabh vyas - Sun Microsystems - Bangalore India <Saurabh.Vyas@Sun.COM>
parents: 8905
diff changeset
  2194
		is_loopback = B_TRUE;
9a7c48f95b4d 6751345 zoneadmd doesn't set custom netmask for non-loopback addresses hosted on lo0 in shared-ip zones
saurabh vyas - Sun Microsystems - Bangalore India <Saurabh.Vyas@Sun.COM>
parents: 8905
diff changeset
  2195
	}
9a7c48f95b4d 6751345 zoneadmd doesn't set custom netmask for non-loopback addresses hosted on lo0 in shared-ip zones
saurabh vyas - Sun Microsystems - Bangalore India <Saurabh.Vyas@Sun.COM>
parents: 8905
diff changeset
  2196
	if (af == AF_INET) {
9a7c48f95b4d 6751345 zoneadmd doesn't set custom netmask for non-loopback addresses hosted on lo0 in shared-ip zones
saurabh vyas - Sun Microsystems - Bangalore India <Saurabh.Vyas@Sun.COM>
parents: 8905
diff changeset
  2197
		/*
9a7c48f95b4d 6751345 zoneadmd doesn't set custom netmask for non-loopback addresses hosted on lo0 in shared-ip zones
saurabh vyas - Sun Microsystems - Bangalore India <Saurabh.Vyas@Sun.COM>
parents: 8905
diff changeset
  2198
		 * The IPv4 netmask can be determined either
9a7c48f95b4d 6751345 zoneadmd doesn't set custom netmask for non-loopback addresses hosted on lo0 in shared-ip zones
saurabh vyas - Sun Microsystems - Bangalore India <Saurabh.Vyas@Sun.COM>
parents: 8905
diff changeset
  2199
		 * directly if a prefix length was supplied with
9a7c48f95b4d 6751345 zoneadmd doesn't set custom netmask for non-loopback addresses hosted on lo0 in shared-ip zones
saurabh vyas - Sun Microsystems - Bangalore India <Saurabh.Vyas@Sun.COM>
parents: 8905
diff changeset
  2200
		 * the address or via the netmasks database.  Not
9a7c48f95b4d 6751345 zoneadmd doesn't set custom netmask for non-loopback addresses hosted on lo0 in shared-ip zones
saurabh vyas - Sun Microsystems - Bangalore India <Saurabh.Vyas@Sun.COM>
parents: 8905
diff changeset
  2201
		 * being able to determine it is a common failure,
9a7c48f95b4d 6751345 zoneadmd doesn't set custom netmask for non-loopback addresses hosted on lo0 in shared-ip zones
saurabh vyas - Sun Microsystems - Bangalore India <Saurabh.Vyas@Sun.COM>
parents: 8905
diff changeset
  2202
		 * but it often is not fatal to operation of the
9a7c48f95b4d 6751345 zoneadmd doesn't set custom netmask for non-loopback addresses hosted on lo0 in shared-ip zones
saurabh vyas - Sun Microsystems - Bangalore India <Saurabh.Vyas@Sun.COM>
parents: 8905
diff changeset
  2203
		 * interface.  In that case, a warning will be
9a7c48f95b4d 6751345 zoneadmd doesn't set custom netmask for non-loopback addresses hosted on lo0 in shared-ip zones
saurabh vyas - Sun Microsystems - Bangalore India <Saurabh.Vyas@Sun.COM>
parents: 8905
diff changeset
  2204
		 * printed after the rest of the interface's
9a7c48f95b4d 6751345 zoneadmd doesn't set custom netmask for non-loopback addresses hosted on lo0 in shared-ip zones
saurabh vyas - Sun Microsystems - Bangalore India <Saurabh.Vyas@Sun.COM>
parents: 8905
diff changeset
  2205
		 * parameters have been configured.
9a7c48f95b4d 6751345 zoneadmd doesn't set custom netmask for non-loopback addresses hosted on lo0 in shared-ip zones
saurabh vyas - Sun Microsystems - Bangalore India <Saurabh.Vyas@Sun.COM>
parents: 8905
diff changeset
  2206
		 */
9a7c48f95b4d 6751345 zoneadmd doesn't set custom netmask for non-loopback addresses hosted on lo0 in shared-ip zones
saurabh vyas - Sun Microsystems - Bangalore India <Saurabh.Vyas@Sun.COM>
parents: 8905
diff changeset
  2207
		(void) memset(&netmask4, 0, sizeof (netmask4));
9a7c48f95b4d 6751345 zoneadmd doesn't set custom netmask for non-loopback addresses hosted on lo0 in shared-ip zones
saurabh vyas - Sun Microsystems - Bangalore India <Saurabh.Vyas@Sun.COM>
parents: 8905
diff changeset
  2208
		if (slashp != NULL) {
9a7c48f95b4d 6751345 zoneadmd doesn't set custom netmask for non-loopback addresses hosted on lo0 in shared-ip zones
saurabh vyas - Sun Microsystems - Bangalore India <Saurabh.Vyas@Sun.COM>
parents: 8905
diff changeset
  2209
			if (addr2netmask(slashp + 1, V4_ADDR_LEN,
9a7c48f95b4d 6751345 zoneadmd doesn't set custom netmask for non-loopback addresses hosted on lo0 in shared-ip zones
saurabh vyas - Sun Microsystems - Bangalore India <Saurabh.Vyas@Sun.COM>
parents: 8905
diff changeset
  2210
			    (uchar_t *)&netmask4.sin_addr) != 0) {
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2211
				*slashp = '/';
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2212
				zerror(zlogp, B_FALSE,
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2213
				    "%s: invalid prefix length in %s",
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2214
				    lifr.lifr_name,
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2215
				    nwiftabptr->zone_nwif_address);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2216
				goto bad;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2217
			}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2218
			got_netmask = B_TRUE;
9720
9a7c48f95b4d 6751345 zoneadmd doesn't set custom netmask for non-loopback addresses hosted on lo0 in shared-ip zones
saurabh vyas - Sun Microsystems - Bangalore India <Saurabh.Vyas@Sun.COM>
parents: 8905
diff changeset
  2219
		} else if (getnetmaskbyaddr(in4,
9a7c48f95b4d 6751345 zoneadmd doesn't set custom netmask for non-loopback addresses hosted on lo0 in shared-ip zones
saurabh vyas - Sun Microsystems - Bangalore India <Saurabh.Vyas@Sun.COM>
parents: 8905
diff changeset
  2220
		    &netmask4.sin_addr) == 0) {
9a7c48f95b4d 6751345 zoneadmd doesn't set custom netmask for non-loopback addresses hosted on lo0 in shared-ip zones
saurabh vyas - Sun Microsystems - Bangalore India <Saurabh.Vyas@Sun.COM>
parents: 8905
diff changeset
  2221
			got_netmask = B_TRUE;
9a7c48f95b4d 6751345 zoneadmd doesn't set custom netmask for non-loopback addresses hosted on lo0 in shared-ip zones
saurabh vyas - Sun Microsystems - Bangalore India <Saurabh.Vyas@Sun.COM>
parents: 8905
diff changeset
  2222
		}
9a7c48f95b4d 6751345 zoneadmd doesn't set custom netmask for non-loopback addresses hosted on lo0 in shared-ip zones
saurabh vyas - Sun Microsystems - Bangalore India <Saurabh.Vyas@Sun.COM>
parents: 8905
diff changeset
  2223
		if (got_netmask) {
9a7c48f95b4d 6751345 zoneadmd doesn't set custom netmask for non-loopback addresses hosted on lo0 in shared-ip zones
saurabh vyas - Sun Microsystems - Bangalore India <Saurabh.Vyas@Sun.COM>
parents: 8905
diff changeset
  2224
			netmask4.sin_family = af;
9a7c48f95b4d 6751345 zoneadmd doesn't set custom netmask for non-loopback addresses hosted on lo0 in shared-ip zones
saurabh vyas - Sun Microsystems - Bangalore India <Saurabh.Vyas@Sun.COM>
parents: 8905
diff changeset
  2225
			(void) memcpy(&lifr.lifr_addr, &netmask4,
9a7c48f95b4d 6751345 zoneadmd doesn't set custom netmask for non-loopback addresses hosted on lo0 in shared-ip zones
saurabh vyas - Sun Microsystems - Bangalore India <Saurabh.Vyas@Sun.COM>
parents: 8905
diff changeset
  2226
			    sizeof (netmask4));
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2227
		}
9720
9a7c48f95b4d 6751345 zoneadmd doesn't set custom netmask for non-loopback addresses hosted on lo0 in shared-ip zones
saurabh vyas - Sun Microsystems - Bangalore India <Saurabh.Vyas@Sun.COM>
parents: 8905
diff changeset
  2228
	} else {
9a7c48f95b4d 6751345 zoneadmd doesn't set custom netmask for non-loopback addresses hosted on lo0 in shared-ip zones
saurabh vyas - Sun Microsystems - Bangalore India <Saurabh.Vyas@Sun.COM>
parents: 8905
diff changeset
  2229
		(void) memset(&netmask6, 0, sizeof (netmask6));
9a7c48f95b4d 6751345 zoneadmd doesn't set custom netmask for non-loopback addresses hosted on lo0 in shared-ip zones
saurabh vyas - Sun Microsystems - Bangalore India <Saurabh.Vyas@Sun.COM>
parents: 8905
diff changeset
  2230
		if (addr2netmask(slashp + 1, V6_ADDR_LEN,
9a7c48f95b4d 6751345 zoneadmd doesn't set custom netmask for non-loopback addresses hosted on lo0 in shared-ip zones
saurabh vyas - Sun Microsystems - Bangalore India <Saurabh.Vyas@Sun.COM>
parents: 8905
diff changeset
  2231
		    (uchar_t *)&netmask6.sin6_addr) != 0) {
9a7c48f95b4d 6751345 zoneadmd doesn't set custom netmask for non-loopback addresses hosted on lo0 in shared-ip zones
saurabh vyas - Sun Microsystems - Bangalore India <Saurabh.Vyas@Sun.COM>
parents: 8905
diff changeset
  2232
			*slashp = '/';
9a7c48f95b4d 6751345 zoneadmd doesn't set custom netmask for non-loopback addresses hosted on lo0 in shared-ip zones
saurabh vyas - Sun Microsystems - Bangalore India <Saurabh.Vyas@Sun.COM>
parents: 8905
diff changeset
  2233
			zerror(zlogp, B_FALSE,
9a7c48f95b4d 6751345 zoneadmd doesn't set custom netmask for non-loopback addresses hosted on lo0 in shared-ip zones
saurabh vyas - Sun Microsystems - Bangalore India <Saurabh.Vyas@Sun.COM>
parents: 8905
diff changeset
  2234
			    "%s: invalid prefix length in %s",
9a7c48f95b4d 6751345 zoneadmd doesn't set custom netmask for non-loopback addresses hosted on lo0 in shared-ip zones
saurabh vyas - Sun Microsystems - Bangalore India <Saurabh.Vyas@Sun.COM>
parents: 8905
diff changeset
  2235
			    lifr.lifr_name,
9a7c48f95b4d 6751345 zoneadmd doesn't set custom netmask for non-loopback addresses hosted on lo0 in shared-ip zones
saurabh vyas - Sun Microsystems - Bangalore India <Saurabh.Vyas@Sun.COM>
parents: 8905
diff changeset
  2236
			    nwiftabptr->zone_nwif_address);
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2237
			goto bad;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2238
		}
9720
9a7c48f95b4d 6751345 zoneadmd doesn't set custom netmask for non-loopback addresses hosted on lo0 in shared-ip zones
saurabh vyas - Sun Microsystems - Bangalore India <Saurabh.Vyas@Sun.COM>
parents: 8905
diff changeset
  2239
		got_netmask = B_TRUE;
9a7c48f95b4d 6751345 zoneadmd doesn't set custom netmask for non-loopback addresses hosted on lo0 in shared-ip zones
saurabh vyas - Sun Microsystems - Bangalore India <Saurabh.Vyas@Sun.COM>
parents: 8905
diff changeset
  2240
		netmask6.sin6_family = af;
9a7c48f95b4d 6751345 zoneadmd doesn't set custom netmask for non-loopback addresses hosted on lo0 in shared-ip zones
saurabh vyas - Sun Microsystems - Bangalore India <Saurabh.Vyas@Sun.COM>
parents: 8905
diff changeset
  2241
		(void) memcpy(&lifr.lifr_addr, &netmask6,
9a7c48f95b4d 6751345 zoneadmd doesn't set custom netmask for non-loopback addresses hosted on lo0 in shared-ip zones
saurabh vyas - Sun Microsystems - Bangalore India <Saurabh.Vyas@Sun.COM>
parents: 8905
diff changeset
  2242
		    sizeof (netmask6));
9a7c48f95b4d 6751345 zoneadmd doesn't set custom netmask for non-loopback addresses hosted on lo0 in shared-ip zones
saurabh vyas - Sun Microsystems - Bangalore India <Saurabh.Vyas@Sun.COM>
parents: 8905
diff changeset
  2243
	}
9a7c48f95b4d 6751345 zoneadmd doesn't set custom netmask for non-loopback addresses hosted on lo0 in shared-ip zones
saurabh vyas - Sun Microsystems - Bangalore India <Saurabh.Vyas@Sun.COM>
parents: 8905
diff changeset
  2244
	if (got_netmask &&
9a7c48f95b4d 6751345 zoneadmd doesn't set custom netmask for non-loopback addresses hosted on lo0 in shared-ip zones
saurabh vyas - Sun Microsystems - Bangalore India <Saurabh.Vyas@Sun.COM>
parents: 8905
diff changeset
  2245
	    ioctl(s, SIOCSLIFNETMASK, (caddr_t)&lifr) < 0) {
9a7c48f95b4d 6751345 zoneadmd doesn't set custom netmask for non-loopback addresses hosted on lo0 in shared-ip zones
saurabh vyas - Sun Microsystems - Bangalore India <Saurabh.Vyas@Sun.COM>
parents: 8905
diff changeset
  2246
		zerror(zlogp, B_TRUE, "%s: could not set netmask",
9a7c48f95b4d 6751345 zoneadmd doesn't set custom netmask for non-loopback addresses hosted on lo0 in shared-ip zones
saurabh vyas - Sun Microsystems - Bangalore India <Saurabh.Vyas@Sun.COM>
parents: 8905
diff changeset
  2247
		    lifr.lifr_name);
9a7c48f95b4d 6751345 zoneadmd doesn't set custom netmask for non-loopback addresses hosted on lo0 in shared-ip zones
saurabh vyas - Sun Microsystems - Bangalore India <Saurabh.Vyas@Sun.COM>
parents: 8905
diff changeset
  2248
		goto bad;
9a7c48f95b4d 6751345 zoneadmd doesn't set custom netmask for non-loopback addresses hosted on lo0 in shared-ip zones
saurabh vyas - Sun Microsystems - Bangalore India <Saurabh.Vyas@Sun.COM>
parents: 8905
diff changeset
  2249
	}
9a7c48f95b4d 6751345 zoneadmd doesn't set custom netmask for non-loopback addresses hosted on lo0 in shared-ip zones
saurabh vyas - Sun Microsystems - Bangalore India <Saurabh.Vyas@Sun.COM>
parents: 8905
diff changeset
  2250
10067
42ad9bccb964 6848271 zoneadmd: initial assignment of ip address ending with .0 .255 (cidr) doesn't work
Vamsi Nagineni <Vamsi.Krishna@Sun.COM>
parents: 9720
diff changeset
  2251
	/* Set the interface address */
42ad9bccb964 6848271 zoneadmd: initial assignment of ip address ending with .0 .255 (cidr) doesn't work
Vamsi Nagineni <Vamsi.Krishna@Sun.COM>
parents: 9720
diff changeset
  2252
	lifr.lifr_addr = laddr;
9720
9a7c48f95b4d 6751345 zoneadmd doesn't set custom netmask for non-loopback addresses hosted on lo0 in shared-ip zones
saurabh vyas - Sun Microsystems - Bangalore India <Saurabh.Vyas@Sun.COM>
parents: 8905
diff changeset
  2253
	if (ioctl(s, SIOCSLIFADDR, (caddr_t)&lifr) < 0) {
9a7c48f95b4d 6751345 zoneadmd doesn't set custom netmask for non-loopback addresses hosted on lo0 in shared-ip zones
saurabh vyas - Sun Microsystems - Bangalore India <Saurabh.Vyas@Sun.COM>
parents: 8905
diff changeset
  2254
		zerror(zlogp, B_TRUE,
10067
42ad9bccb964 6848271 zoneadmd: initial assignment of ip address ending with .0 .255 (cidr) doesn't work
Vamsi Nagineni <Vamsi.Krishna@Sun.COM>
parents: 9720
diff changeset
  2255
		    "%s: could not set IP address to %s",
42ad9bccb964 6848271 zoneadmd: initial assignment of ip address ending with .0 .255 (cidr) doesn't work
Vamsi Nagineni <Vamsi.Krishna@Sun.COM>
parents: 9720
diff changeset
  2256
		    lifr.lifr_name, nwiftabptr->zone_nwif_address);
9720
9a7c48f95b4d 6751345 zoneadmd doesn't set custom netmask for non-loopback addresses hosted on lo0 in shared-ip zones
saurabh vyas - Sun Microsystems - Bangalore India <Saurabh.Vyas@Sun.COM>
parents: 8905
diff changeset
  2257
		goto bad;
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2258
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2259
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2260
	if (ioctl(s, SIOCGLIFFLAGS, (caddr_t)&lifr) < 0) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2261
		zerror(zlogp, B_TRUE, "%s: could not get flags",
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2262
		    lifr.lifr_name);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2263
		goto bad;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2264
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2265
	lifr.lifr_flags |= IFF_UP;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2266
	if (ioctl(s, SIOCSLIFFLAGS, (caddr_t)&lifr) < 0) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2267
		int save_errno = errno;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2268
		char *zone_using;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2269
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2270
		/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2271
		 * If we failed with something other than EADDRNOTAVAIL,
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2272
		 * then skip to the end.  Otherwise, look up our address,
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2273
		 * then call a function to determine which zone is already
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2274
		 * using that address.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2275
		 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2276
		if (errno != EADDRNOTAVAIL) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2277
			zerror(zlogp, B_TRUE,
3448
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2278
			    "%s: could not bring network interface up",
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2279
			    lifr.lifr_name);
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2280
			goto bad;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2281
		}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2282
		if (ioctl(s, SIOCGLIFADDR, (caddr_t)&lifr) < 0) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2283
			zerror(zlogp, B_TRUE, "%s: could not get address",
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2284
			    lifr.lifr_name);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2285
			goto bad;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2286
		}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2287
		zone_using = who_is_using(zlogp, &lifr);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2288
		errno = save_errno;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2289
		if (zone_using == NULL)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2290
			zerror(zlogp, B_TRUE,
3448
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2291
			    "%s: could not bring network interface up",
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2292
			    lifr.lifr_name);
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2293
		else
3448
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2294
			zerror(zlogp, B_TRUE, "%s: could not bring network "
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2295
			    "interface up: address in use by zone '%s'",
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2296
			    lifr.lifr_name, zone_using);
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2297
		goto bad;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2298
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2299
9720
9a7c48f95b4d 6751345 zoneadmd doesn't set custom netmask for non-loopback addresses hosted on lo0 in shared-ip zones
saurabh vyas - Sun Microsystems - Bangalore India <Saurabh.Vyas@Sun.COM>
parents: 8905
diff changeset
  2300
	if (!got_netmask && !is_loopback) {
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2301
		/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2302
		 * A common, but often non-fatal problem, is that the system
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2303
		 * cannot find the netmask for an interface address. This is
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2304
		 * often caused by it being only in /etc/inet/netmasks, but
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2305
		 * /etc/nsswitch.conf says to use NIS or NIS+ and it's not
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2306
		 * in that. This doesn't show up at boot because the netmask
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2307
		 * is obtained from /etc/inet/netmasks when no network
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2308
		 * interfaces are up, but isn't consulted when NIS/NIS+ is
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2309
		 * available. We warn the user here that something like this
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2310
		 * has happened and we're just running with a default and
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2311
		 * possible incorrect netmask.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2312
		 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2313
		char buffer[INET6_ADDRSTRLEN];
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2314
		void  *addr;
8485
633e5b5eb268 PSARC/2007/272 Project Clearview: IPMP Rearchitecture
meem <Peter.Memishian@Sun.COM>
parents: 8453
diff changeset
  2315
		const char *nomatch = "no matching subnet found in netmasks(4)";
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2316
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2317
		if (af == AF_INET)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2318
			addr = &((struct sockaddr_in *)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2319
			    (&lifr.lifr_addr))->sin_addr;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2320
		else
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2321
			addr = &((struct sockaddr_in6 *)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2322
			    (&lifr.lifr_addr))->sin6_addr;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2323
8485
633e5b5eb268 PSARC/2007/272 Project Clearview: IPMP Rearchitecture
meem <Peter.Memishian@Sun.COM>
parents: 8453
diff changeset
  2324
		/*
633e5b5eb268 PSARC/2007/272 Project Clearview: IPMP Rearchitecture
meem <Peter.Memishian@Sun.COM>
parents: 8453
diff changeset
  2325
		 * Find out what netmask the interface is going to be using.
633e5b5eb268 PSARC/2007/272 Project Clearview: IPMP Rearchitecture
meem <Peter.Memishian@Sun.COM>
parents: 8453
diff changeset
  2326
		 * If we just brought up an IPMP data address on an underlying
633e5b5eb268 PSARC/2007/272 Project Clearview: IPMP Rearchitecture
meem <Peter.Memishian@Sun.COM>
parents: 8453
diff changeset
  2327
		 * interface above, the address will have already migrated, so
633e5b5eb268 PSARC/2007/272 Project Clearview: IPMP Rearchitecture
meem <Peter.Memishian@Sun.COM>
parents: 8453
diff changeset
  2328
		 * the SIOCGLIFNETMASK won't be able to find it (but we need
633e5b5eb268 PSARC/2007/272 Project Clearview: IPMP Rearchitecture
meem <Peter.Memishian@Sun.COM>
parents: 8453
diff changeset
  2329
		 * to bring the address up to get the actual netmask).  Just
633e5b5eb268 PSARC/2007/272 Project Clearview: IPMP Rearchitecture
meem <Peter.Memishian@Sun.COM>
parents: 8453
diff changeset
  2330
		 * omit printing the actual netmask in this corner-case.
633e5b5eb268 PSARC/2007/272 Project Clearview: IPMP Rearchitecture
meem <Peter.Memishian@Sun.COM>
parents: 8453
diff changeset
  2331
		 */
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2332
		if (ioctl(s, SIOCGLIFNETMASK, (caddr_t)&lifr) < 0 ||
8485
633e5b5eb268 PSARC/2007/272 Project Clearview: IPMP Rearchitecture
meem <Peter.Memishian@Sun.COM>
parents: 8453
diff changeset
  2333
		    inet_ntop(af, addr, buffer, sizeof (buffer)) == NULL) {
633e5b5eb268 PSARC/2007/272 Project Clearview: IPMP Rearchitecture
meem <Peter.Memishian@Sun.COM>
parents: 8453
diff changeset
  2334
			zerror(zlogp, B_FALSE, "WARNING: %s; using default.",
633e5b5eb268 PSARC/2007/272 Project Clearview: IPMP Rearchitecture
meem <Peter.Memishian@Sun.COM>
parents: 8453
diff changeset
  2335
			    nomatch);
633e5b5eb268 PSARC/2007/272 Project Clearview: IPMP Rearchitecture
meem <Peter.Memishian@Sun.COM>
parents: 8453
diff changeset
  2336
		} else {
633e5b5eb268 PSARC/2007/272 Project Clearview: IPMP Rearchitecture
meem <Peter.Memishian@Sun.COM>
parents: 8453
diff changeset
  2337
			zerror(zlogp, B_FALSE,
633e5b5eb268 PSARC/2007/272 Project Clearview: IPMP Rearchitecture
meem <Peter.Memishian@Sun.COM>
parents: 8453
diff changeset
  2338
			    "WARNING: %s: %s: %s; using default of %s.",
633e5b5eb268 PSARC/2007/272 Project Clearview: IPMP Rearchitecture
meem <Peter.Memishian@Sun.COM>
parents: 8453
diff changeset
  2339
			    lifr.lifr_name, nomatch, addrstr4, buffer);
633e5b5eb268 PSARC/2007/272 Project Clearview: IPMP Rearchitecture
meem <Peter.Memishian@Sun.COM>
parents: 8453
diff changeset
  2340
		}
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2341
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2342
6076
39e1b255225b 6583565 need a mechanism to configure a per zone default route in shared IP stack for TX
gfaden
parents: 5895
diff changeset
  2343
	/*
39e1b255225b 6583565 need a mechanism to configure a per zone default route in shared IP stack for TX
gfaden
parents: 5895
diff changeset
  2344
	 * If a default router was specified for this interface
39e1b255225b 6583565 need a mechanism to configure a per zone default route in shared IP stack for TX
gfaden
parents: 5895
diff changeset
  2345
	 * set the route now. Ignore if already set.
39e1b255225b 6583565 need a mechanism to configure a per zone default route in shared IP stack for TX
gfaden
parents: 5895
diff changeset
  2346
	 */
39e1b255225b 6583565 need a mechanism to configure a per zone default route in shared IP stack for TX
gfaden
parents: 5895
diff changeset
  2347
	if (strlen(nwiftabptr->zone_nwif_defrouter) > 0) {
39e1b255225b 6583565 need a mechanism to configure a per zone default route in shared IP stack for TX
gfaden
parents: 5895
diff changeset
  2348
		int status;
39e1b255225b 6583565 need a mechanism to configure a per zone default route in shared IP stack for TX
gfaden
parents: 5895
diff changeset
  2349
		char *argv[7];
39e1b255225b 6583565 need a mechanism to configure a per zone default route in shared IP stack for TX
gfaden
parents: 5895
diff changeset
  2350
39e1b255225b 6583565 need a mechanism to configure a per zone default route in shared IP stack for TX
gfaden
parents: 5895
diff changeset
  2351
		argv[0] = "route";
39e1b255225b 6583565 need a mechanism to configure a per zone default route in shared IP stack for TX
gfaden
parents: 5895
diff changeset
  2352
		argv[1] = "add";
39e1b255225b 6583565 need a mechanism to configure a per zone default route in shared IP stack for TX
gfaden
parents: 5895
diff changeset
  2353
		argv[2] = "-ifp";
39e1b255225b 6583565 need a mechanism to configure a per zone default route in shared IP stack for TX
gfaden
parents: 5895
diff changeset
  2354
		argv[3] = nwiftabptr->zone_nwif_physical;
39e1b255225b 6583565 need a mechanism to configure a per zone default route in shared IP stack for TX
gfaden
parents: 5895
diff changeset
  2355
		argv[4] = "default";
39e1b255225b 6583565 need a mechanism to configure a per zone default route in shared IP stack for TX
gfaden
parents: 5895
diff changeset
  2356
		argv[5] = nwiftabptr->zone_nwif_defrouter;
39e1b255225b 6583565 need a mechanism to configure a per zone default route in shared IP stack for TX
gfaden
parents: 5895
diff changeset
  2357
		argv[6] = NULL;
39e1b255225b 6583565 need a mechanism to configure a per zone default route in shared IP stack for TX
gfaden
parents: 5895
diff changeset
  2358
39e1b255225b 6583565 need a mechanism to configure a per zone default route in shared IP stack for TX
gfaden
parents: 5895
diff changeset
  2359
		status = forkexec(zlogp, "/usr/sbin/route", argv);
39e1b255225b 6583565 need a mechanism to configure a per zone default route in shared IP stack for TX
gfaden
parents: 5895
diff changeset
  2360
		if (status != 0 && status != EEXIST)
39e1b255225b 6583565 need a mechanism to configure a per zone default route in shared IP stack for TX
gfaden
parents: 5895
diff changeset
  2361
			zerror(zlogp, B_FALSE, "Unable to set route for "
39e1b255225b 6583565 need a mechanism to configure a per zone default route in shared IP stack for TX
gfaden
parents: 5895
diff changeset
  2362
			    "interface %s to %s\n",
39e1b255225b 6583565 need a mechanism to configure a per zone default route in shared IP stack for TX
gfaden
parents: 5895
diff changeset
  2363
			    nwiftabptr->zone_nwif_physical,
39e1b255225b 6583565 need a mechanism to configure a per zone default route in shared IP stack for TX
gfaden
parents: 5895
diff changeset
  2364
			    nwiftabptr->zone_nwif_defrouter);
39e1b255225b 6583565 need a mechanism to configure a per zone default route in shared IP stack for TX
gfaden
parents: 5895
diff changeset
  2365
	}
39e1b255225b 6583565 need a mechanism to configure a per zone default route in shared IP stack for TX
gfaden
parents: 5895
diff changeset
  2366
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2367
	(void) close(s);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2368
	return (Z_OK);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2369
bad:
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2370
	(void) ioctl(s, SIOCLIFREMOVEIF, (caddr_t)&lifr);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2371
	(void) close(s);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2372
	return (-1);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2373
}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2374
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2375
/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2376
 * Sets up network interfaces based on information from the zone configuration.
8058
ead1ee36a8ed 6722583 zoneadmd's default multicast route logic can go
jv227347 <Jordan.Vaughan@Sun.com>
parents: 7714
diff changeset
  2377
 * IPv4 and IPv6 loopback interfaces are set up "for free", modeling the global
ead1ee36a8ed 6722583 zoneadmd's default multicast route logic can go
jv227347 <Jordan.Vaughan@Sun.com>
parents: 7714
diff changeset
  2378
 * system.
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2379
 *
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2380
 * If anything goes wrong, we log a general error message, attempt to tear down
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2381
 * whatever we set up, and return an error.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2382
 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2383
static int
3448
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2384
configure_shared_network_interfaces(zlog_t *zlogp)
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2385
{
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2386
	zone_dochandle_t handle;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2387
	struct zone_nwiftab nwiftab, loopback_iftab;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2388
	zoneid_t zoneid;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2389
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2390
	if ((zoneid = getzoneidbyname(zone_name)) == ZONE_ID_UNDEFINED) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2391
		zerror(zlogp, B_TRUE, "unable to get zoneid");
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2392
		return (-1);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2393
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2394
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2395
	if ((handle = zonecfg_init_handle()) == NULL) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2396
		zerror(zlogp, B_TRUE, "getting zone configuration handle");
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2397
		return (-1);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2398
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2399
	if (zonecfg_get_snapshot_handle(zone_name, handle) != Z_OK) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2400
		zerror(zlogp, B_FALSE, "invalid configuration");
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2401
		zonecfg_fini_handle(handle);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2402
		return (-1);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2403
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2404
	if (zonecfg_setnwifent(handle) == Z_OK) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2405
		for (;;) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2406
			if (zonecfg_getnwifent(handle, &nwiftab) != Z_OK)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2407
				break;
8058
ead1ee36a8ed 6722583 zoneadmd's default multicast route logic can go
jv227347 <Jordan.Vaughan@Sun.com>
parents: 7714
diff changeset
  2408
			if (configure_one_interface(zlogp, zoneid, &nwiftab) !=
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2409
			    Z_OK) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2410
				(void) zonecfg_endnwifent(handle);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2411
				zonecfg_fini_handle(handle);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2412
				return (-1);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2413
			}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2414
		}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2415
		(void) zonecfg_endnwifent(handle);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2416
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2417
	zonecfg_fini_handle(handle);
5863
ae9aa63b706d 6645988 Labeled zones require at least one all-zones interface
gfaden
parents: 5829
diff changeset
  2418
	if (is_system_labeled()) {
ae9aa63b706d 6645988 Labeled zones require at least one all-zones interface
gfaden
parents: 5829
diff changeset
  2419
		/*
ae9aa63b706d 6645988 Labeled zones require at least one all-zones interface
gfaden
parents: 5829
diff changeset
  2420
		 * Labeled zones share the loopback interface
ae9aa63b706d 6645988 Labeled zones require at least one all-zones interface
gfaden
parents: 5829
diff changeset
  2421
		 * so it is not plumbed for shared stack instances.
ae9aa63b706d 6645988 Labeled zones require at least one all-zones interface
gfaden
parents: 5829
diff changeset
  2422
		 */
ae9aa63b706d 6645988 Labeled zones require at least one all-zones interface
gfaden
parents: 5829
diff changeset
  2423
		return (0);
ae9aa63b706d 6645988 Labeled zones require at least one all-zones interface
gfaden
parents: 5829
diff changeset
  2424
	}
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2425
	(void) strlcpy(loopback_iftab.zone_nwif_physical, "lo0",
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2426
	    sizeof (loopback_iftab.zone_nwif_physical));
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2427
	(void) strlcpy(loopback_iftab.zone_nwif_address, "127.0.0.1",
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2428
	    sizeof (loopback_iftab.zone_nwif_address));
6378
1c4e2be0aeb0 6684810 per zone default routes break zones without networking
gfaden
parents: 6076
diff changeset
  2429
	loopback_iftab.zone_nwif_defrouter[0] = '\0';
8058
ead1ee36a8ed 6722583 zoneadmd's default multicast route logic can go
jv227347 <Jordan.Vaughan@Sun.com>
parents: 7714
diff changeset
  2430
	if (configure_one_interface(zlogp, zoneid, &loopback_iftab) != Z_OK)
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2431
		return (-1);
8058
ead1ee36a8ed 6722583 zoneadmd's default multicast route logic can go
jv227347 <Jordan.Vaughan@Sun.com>
parents: 7714
diff changeset
  2432
ead1ee36a8ed 6722583 zoneadmd's default multicast route logic can go
jv227347 <Jordan.Vaughan@Sun.com>
parents: 7714
diff changeset
  2433
	/* Always plumb up the IPv6 loopback interface. */
ead1ee36a8ed 6722583 zoneadmd's default multicast route logic can go
jv227347 <Jordan.Vaughan@Sun.com>
parents: 7714
diff changeset
  2434
	(void) strlcpy(loopback_iftab.zone_nwif_address, "::1/128",
ead1ee36a8ed 6722583 zoneadmd's default multicast route logic can go
jv227347 <Jordan.Vaughan@Sun.com>
parents: 7714
diff changeset
  2435
	    sizeof (loopback_iftab.zone_nwif_address));
ead1ee36a8ed 6722583 zoneadmd's default multicast route logic can go
jv227347 <Jordan.Vaughan@Sun.com>
parents: 7714
diff changeset
  2436
	if (configure_one_interface(zlogp, zoneid, &loopback_iftab) != Z_OK)
ead1ee36a8ed 6722583 zoneadmd's default multicast route logic can go
jv227347 <Jordan.Vaughan@Sun.com>
parents: 7714
diff changeset
  2437
		return (-1);
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2438
	return (0);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2439
}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2440
8878
f2a5f3367187 6667014 zoneadmd calls zerror() with bogus errno values
meem <Peter.Memishian@Sun.COM>
parents: 8770
diff changeset
  2441
static void
f2a5f3367187 6667014 zoneadmd calls zerror() with bogus errno values
meem <Peter.Memishian@Sun.COM>
parents: 8770
diff changeset
  2442
zdlerror(zlog_t *zlogp, dladm_status_t err, const char *dlname, const char *str)
f2a5f3367187 6667014 zoneadmd calls zerror() with bogus errno values
meem <Peter.Memishian@Sun.COM>
parents: 8770
diff changeset
  2443
{
f2a5f3367187 6667014 zoneadmd calls zerror() with bogus errno values
meem <Peter.Memishian@Sun.COM>
parents: 8770
diff changeset
  2444
	char errmsg[DLADM_STRSIZE];
f2a5f3367187 6667014 zoneadmd calls zerror() with bogus errno values
meem <Peter.Memishian@Sun.COM>
parents: 8770
diff changeset
  2445
f2a5f3367187 6667014 zoneadmd calls zerror() with bogus errno values
meem <Peter.Memishian@Sun.COM>
parents: 8770
diff changeset
  2446
	(void) dladm_status2str(err, errmsg);
f2a5f3367187 6667014 zoneadmd calls zerror() with bogus errno values
meem <Peter.Memishian@Sun.COM>
parents: 8770
diff changeset
  2447
	zerror(zlogp, B_FALSE, "%s '%s': %s", str, dlname, errmsg);
f2a5f3367187 6667014 zoneadmd calls zerror() with bogus errno values
meem <Peter.Memishian@Sun.COM>
parents: 8770
diff changeset
  2448
}
f2a5f3367187 6667014 zoneadmd calls zerror() with bogus errno values
meem <Peter.Memishian@Sun.COM>
parents: 8770
diff changeset
  2449
3448
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2450
static int
10616
3be00c4a6835 PSARC 2009/373 Clearview IP Tunneling
Sebastien Roy <Sebastien.Roy@Sun.COM>
parents: 10067
diff changeset
  2451
add_datalink(zlog_t *zlogp, char *zone_name, datalink_id_t linkid, char *dlname)
3448
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2452
{
8878
f2a5f3367187 6667014 zoneadmd calls zerror() with bogus errno values
meem <Peter.Memishian@Sun.COM>
parents: 8770
diff changeset
  2453
	dladm_status_t err;
11878
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  2454
	boolean_t cpuset, poolset;
8878
f2a5f3367187 6667014 zoneadmd calls zerror() with bogus errno values
meem <Peter.Memishian@Sun.COM>
parents: 8770
diff changeset
  2455
3448
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2456
	/* First check if it's in use by global zone. */
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2457
	if (zonecfg_ifname_exists(AF_INET, dlname) ||
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2458
	    zonecfg_ifname_exists(AF_INET6, dlname)) {
8878
f2a5f3367187 6667014 zoneadmd calls zerror() with bogus errno values
meem <Peter.Memishian@Sun.COM>
parents: 8770
diff changeset
  2459
		zerror(zlogp, B_FALSE, "WARNING: skipping network interface "
f2a5f3367187 6667014 zoneadmd calls zerror() with bogus errno values
meem <Peter.Memishian@Sun.COM>
parents: 8770
diff changeset
  2460
		    "'%s' which is used in the global zone", dlname);
3448
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2461
		return (-1);
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2462
	}
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2463
5895
f251acdd9bdc PSARC/2006/499 Clearview Nemo unification and vanity naming
yz147064
parents: 5863
diff changeset
  2464
	/* Set zoneid of this link. */
10616
3be00c4a6835 PSARC 2009/373 Clearview IP Tunneling
Sebastien Roy <Sebastien.Roy@Sun.COM>
parents: 10067
diff changeset
  2465
	err = dladm_set_linkprop(dld_handle, linkid, "zone", &zone_name, 1,
3be00c4a6835 PSARC 2009/373 Clearview IP Tunneling
Sebastien Roy <Sebastien.Roy@Sun.COM>
parents: 10067
diff changeset
  2466
	    DLADM_OPT_ACTIVE);
8878
f2a5f3367187 6667014 zoneadmd calls zerror() with bogus errno values
meem <Peter.Memishian@Sun.COM>
parents: 8770
diff changeset
  2467
	if (err != DLADM_STATUS_OK) {
f2a5f3367187 6667014 zoneadmd calls zerror() with bogus errno values
meem <Peter.Memishian@Sun.COM>
parents: 8770
diff changeset
  2468
		zdlerror(zlogp, err, dlname,
f2a5f3367187 6667014 zoneadmd calls zerror() with bogus errno values
meem <Peter.Memishian@Sun.COM>
parents: 8770
diff changeset
  2469
		    "WARNING: unable to add network interface");
3448
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2470
		return (-1);
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2471
	}
11878
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  2472
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  2473
	/*
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  2474
	 * Set the pool of this link if the zone has a pool and
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  2475
	 * neither the cpus nor the pool datalink property is
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  2476
	 * already set.
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  2477
	 */
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  2478
	err = dladm_linkprop_is_set(dld_handle, linkid, DLADM_PROP_VAL_CURRENT,
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  2479
	    "cpus", &cpuset);
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  2480
	if (err != DLADM_STATUS_OK) {
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  2481
		zdlerror(zlogp, err, dlname,
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  2482
		    "WARNING: unable to check if cpus link property is set");
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  2483
	}
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  2484
	err = dladm_linkprop_is_set(dld_handle, linkid, DLADM_PROP_VAL_CURRENT,
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  2485
	    "pool", &poolset);
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  2486
	if (err != DLADM_STATUS_OK) {
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  2487
		zdlerror(zlogp, err, dlname,
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  2488
		    "WARNING: unable to check if pool link property is set");
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  2489
	}
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  2490
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  2491
	if ((strlen(pool_name) != 0) && !cpuset && !poolset) {
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  2492
		err = dladm_set_linkprop(dld_handle, linkid, "pool",
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  2493
		    &pool_name, 1, DLADM_OPT_ACTIVE);
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  2494
		if (err != DLADM_STATUS_OK) {
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  2495
			zerror(zlogp, B_FALSE, "WARNING: unable to set "
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  2496
			    "pool %s to datalink %s", pool_name, dlname);
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  2497
			bzero(pool_name, MAXPATHLEN);
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  2498
		}
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  2499
	} else {
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  2500
		bzero(pool_name, MAXPATHLEN);
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  2501
	}
3448
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2502
	return (0);
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2503
}
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2504
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2505
/*
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2506
 * Add the kernel access control information for the interface names.
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2507
 * If anything goes wrong, we log a general error message, attempt to tear down
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2508
 * whatever we set up, and return an error.
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2509
 */
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2510
static int
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2511
configure_exclusive_network_interfaces(zlog_t *zlogp)
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2512
{
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2513
	zone_dochandle_t handle;
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2514
	struct zone_nwiftab nwiftab;
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2515
	char rootpath[MAXPATHLEN];
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2516
	char path[MAXPATHLEN];
10616
3be00c4a6835 PSARC 2009/373 Clearview IP Tunneling
Sebastien Roy <Sebastien.Roy@Sun.COM>
parents: 10067
diff changeset
  2517
	datalink_id_t linkid;
3448
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2518
	di_prof_t prof = NULL;
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2519
	boolean_t added = B_FALSE;
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2520
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2521
	if ((handle = zonecfg_init_handle()) == NULL) {
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2522
		zerror(zlogp, B_TRUE, "getting zone configuration handle");
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2523
		return (-1);
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2524
	}
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2525
	if (zonecfg_get_snapshot_handle(zone_name, handle) != Z_OK) {
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2526
		zerror(zlogp, B_FALSE, "invalid configuration");
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2527
		zonecfg_fini_handle(handle);
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2528
		return (-1);
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2529
	}
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2530
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2531
	if (zonecfg_setnwifent(handle) != Z_OK) {
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2532
		zonecfg_fini_handle(handle);
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2533
		return (0);
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2534
	}
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2535
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2536
	for (;;) {
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2537
		if (zonecfg_getnwifent(handle, &nwiftab) != Z_OK)
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2538
			break;
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2539
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2540
		if (prof == NULL) {
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2541
			if (zone_get_devroot(zone_name, rootpath,
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2542
			    sizeof (rootpath)) != Z_OK) {
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2543
				(void) zonecfg_endnwifent(handle);
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2544
				zonecfg_fini_handle(handle);
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2545
				zerror(zlogp, B_TRUE,
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2546
				    "unable to determine dev root");
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2547
				return (-1);
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2548
			}
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2549
			(void) snprintf(path, sizeof (path), "%s%s", rootpath,
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2550
			    "/dev");
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2551
			if (di_prof_init(path, &prof) != 0) {
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2552
				(void) zonecfg_endnwifent(handle);
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2553
				zonecfg_fini_handle(handle);
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2554
				zerror(zlogp, B_TRUE,
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2555
				    "failed to initialize profile");
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2556
				return (-1);
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2557
			}
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2558
		}
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2559
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2560
		/*
5895
f251acdd9bdc PSARC/2006/499 Clearview Nemo unification and vanity naming
yz147064
parents: 5863
diff changeset
  2561
		 * Create the /dev entry for backward compatibility.
3448
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2562
		 * Only create the /dev entry if it's not in use.
5895
f251acdd9bdc PSARC/2006/499 Clearview Nemo unification and vanity naming
yz147064
parents: 5863
diff changeset
  2563
		 * Note that the zone still boots when the assigned
f251acdd9bdc PSARC/2006/499 Clearview Nemo unification and vanity naming
yz147064
parents: 5863
diff changeset
  2564
		 * interface is inaccessible, used by others, etc.
f251acdd9bdc PSARC/2006/499 Clearview Nemo unification and vanity naming
yz147064
parents: 5863
diff changeset
  2565
		 * Also, when vanity naming is used, some interface do
f251acdd9bdc PSARC/2006/499 Clearview Nemo unification and vanity naming
yz147064
parents: 5863
diff changeset
  2566
		 * do not have corresponding /dev node names (for example,
f251acdd9bdc PSARC/2006/499 Clearview Nemo unification and vanity naming
yz147064
parents: 5863
diff changeset
  2567
		 * vanity named aggregations).  The /dev entry is not
f251acdd9bdc PSARC/2006/499 Clearview Nemo unification and vanity naming
yz147064
parents: 5863
diff changeset
  2568
		 * created in that case.  The /dev/net entry is always
f251acdd9bdc PSARC/2006/499 Clearview Nemo unification and vanity naming
yz147064
parents: 5863
diff changeset
  2569
		 * accessible.
3448
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2570
		 */
10616
3be00c4a6835 PSARC 2009/373 Clearview IP Tunneling
Sebastien Roy <Sebastien.Roy@Sun.COM>
parents: 10067
diff changeset
  2571
		if (dladm_name2info(dld_handle, nwiftab.zone_nwif_physical,
3be00c4a6835 PSARC 2009/373 Clearview IP Tunneling
Sebastien Roy <Sebastien.Roy@Sun.COM>
parents: 10067
diff changeset
  2572
		    &linkid, NULL, NULL, NULL) == DLADM_STATUS_OK &&
3be00c4a6835 PSARC 2009/373 Clearview IP Tunneling
Sebastien Roy <Sebastien.Roy@Sun.COM>
parents: 10067
diff changeset
  2573
		    add_datalink(zlogp, zone_name, linkid,
3be00c4a6835 PSARC 2009/373 Clearview IP Tunneling
Sebastien Roy <Sebastien.Roy@Sun.COM>
parents: 10067
diff changeset
  2574
		    nwiftab.zone_nwif_physical) == 0) {
7342
ba01248bb368 6714745 zone/autopush should be implemented using DLDIOC_*MACPROP ioctls.
Aruna Ramakrishna - Sun Microsystems <Aruna.Ramakrishna@Sun.COM>
parents: 7089
diff changeset
  2575
			added = B_TRUE;
ba01248bb368 6714745 zone/autopush should be implemented using DLDIOC_*MACPROP ioctls.
Aruna Ramakrishna - Sun Microsystems <Aruna.Ramakrishna@Sun.COM>
parents: 7089
diff changeset
  2576
		} else {
ba01248bb368 6714745 zone/autopush should be implemented using DLDIOC_*MACPROP ioctls.
Aruna Ramakrishna - Sun Microsystems <Aruna.Ramakrishna@Sun.COM>
parents: 7089
diff changeset
  2577
			(void) zonecfg_endnwifent(handle);
ba01248bb368 6714745 zone/autopush should be implemented using DLDIOC_*MACPROP ioctls.
Aruna Ramakrishna - Sun Microsystems <Aruna.Ramakrishna@Sun.COM>
parents: 7089
diff changeset
  2578
			zonecfg_fini_handle(handle);
ba01248bb368 6714745 zone/autopush should be implemented using DLDIOC_*MACPROP ioctls.
Aruna Ramakrishna - Sun Microsystems <Aruna.Ramakrishna@Sun.COM>
parents: 7089
diff changeset
  2579
			zerror(zlogp, B_TRUE, "failed to add network device");
ba01248bb368 6714745 zone/autopush should be implemented using DLDIOC_*MACPROP ioctls.
Aruna Ramakrishna - Sun Microsystems <Aruna.Ramakrishna@Sun.COM>
parents: 7089
diff changeset
  2580
			return (-1);
3448
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2581
		}
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2582
	}
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2583
	(void) zonecfg_endnwifent(handle);
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2584
	zonecfg_fini_handle(handle);
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2585
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2586
	if (prof != NULL && added) {
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2587
		if (di_prof_commit(prof) != 0) {
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2588
			zerror(zlogp, B_TRUE, "failed to commit profile");
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2589
			return (-1);
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2590
		}
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2591
	}
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2592
	if (prof != NULL)
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2593
		di_prof_fini(prof);
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2594
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2595
	return (0);
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2596
}
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2597
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2598
static int
11878
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  2599
remove_datalink_pool(zlog_t *zlogp, zoneid_t zoneid)
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  2600
{
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  2601
	ushort_t flags;
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  2602
	zone_iptype_t iptype;
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  2603
	int i, dlnum = 0;
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  2604
	datalink_id_t *dllink, *dllinks = NULL;
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  2605
	dladm_status_t err;
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  2606
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  2607
	if (strlen(pool_name) == 0)
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  2608
		return (0);
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  2609
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  2610
	if (zone_getattr(zoneid, ZONE_ATTR_FLAGS, &flags,
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  2611
	    sizeof (flags)) < 0) {
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  2612
		if (vplat_get_iptype(zlogp, &iptype) < 0) {
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  2613
			zerror(zlogp, B_TRUE, "unable to determine "
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  2614
			    "ip-type");
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  2615
			return (-1);
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  2616
		}
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  2617
	} else {
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  2618
		if (flags & ZF_NET_EXCL)
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  2619
			iptype = ZS_EXCLUSIVE;
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  2620
		else
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  2621
			iptype = ZS_SHARED;
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  2622
	}
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  2623
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  2624
	if (iptype == ZS_EXCLUSIVE) {
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  2625
		/*
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  2626
		 * Get the datalink count and for each datalink,
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  2627
		 * attempt to clear the pool property and clear
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  2628
		 * the pool_name.
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  2629
		 */
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  2630
		if (zone_list_datalink(zoneid, &dlnum, NULL) != 0) {
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  2631
			zerror(zlogp, B_TRUE, "unable to count network "
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  2632
			    "interfaces");
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  2633
			return (-1);
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  2634
		}
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  2635
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  2636
		if (dlnum == 0)
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  2637
			return (0);
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  2638
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  2639
		if ((dllinks = malloc(dlnum * sizeof (datalink_id_t)))
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  2640
		    == NULL) {
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  2641
			zerror(zlogp, B_TRUE, "memory allocation failed");
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  2642
			return (-1);
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  2643
		}
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  2644
		if (zone_list_datalink(zoneid, &dlnum, dllinks) != 0) {
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  2645
			zerror(zlogp, B_TRUE, "unable to list network "
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  2646
			    "interfaces");
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  2647
			return (-1);
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  2648
		}
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  2649
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  2650
		bzero(pool_name, MAXPATHLEN);
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  2651
		for (i = 0, dllink = dllinks; i < dlnum; i++, dllink++) {
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  2652
			err = dladm_set_linkprop(dld_handle, *dllink, "pool",
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  2653
			    NULL, 0, DLADM_OPT_ACTIVE);
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  2654
			if (err != DLADM_STATUS_OK) {
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  2655
				zerror(zlogp, B_TRUE,
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  2656
				    "WARNING: unable to clear pool");
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  2657
			}
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  2658
		}
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  2659
		free(dllinks);
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  2660
	}
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  2661
	return (0);
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  2662
}
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  2663
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  2664
static int
10616
3be00c4a6835 PSARC 2009/373 Clearview IP Tunneling
Sebastien Roy <Sebastien.Roy@Sun.COM>
parents: 10067
diff changeset
  2665
unconfigure_exclusive_network_interfaces(zlog_t *zlogp, zoneid_t zoneid)
3448
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2666
{
10616
3be00c4a6835 PSARC 2009/373 Clearview IP Tunneling
Sebastien Roy <Sebastien.Roy@Sun.COM>
parents: 10067
diff changeset
  2667
	int dlnum = 0;
3be00c4a6835 PSARC 2009/373 Clearview IP Tunneling
Sebastien Roy <Sebastien.Roy@Sun.COM>
parents: 10067
diff changeset
  2668
3be00c4a6835 PSARC 2009/373 Clearview IP Tunneling
Sebastien Roy <Sebastien.Roy@Sun.COM>
parents: 10067
diff changeset
  2669
	/*
3be00c4a6835 PSARC 2009/373 Clearview IP Tunneling
Sebastien Roy <Sebastien.Roy@Sun.COM>
parents: 10067
diff changeset
  2670
	 * The kernel shutdown callback for the dls module should have removed
3be00c4a6835 PSARC 2009/373 Clearview IP Tunneling
Sebastien Roy <Sebastien.Roy@Sun.COM>
parents: 10067
diff changeset
  2671
	 * all datalinks from this zone.  If any remain, then there's a
3be00c4a6835 PSARC 2009/373 Clearview IP Tunneling
Sebastien Roy <Sebastien.Roy@Sun.COM>
parents: 10067
diff changeset
  2672
	 * problem.
3be00c4a6835 PSARC 2009/373 Clearview IP Tunneling
Sebastien Roy <Sebastien.Roy@Sun.COM>
parents: 10067
diff changeset
  2673
	 */
3448
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2674
	if (zone_list_datalink(zoneid, &dlnum, NULL) != 0) {
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2675
		zerror(zlogp, B_TRUE, "unable to list network interfaces");
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2676
		return (-1);
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2677
	}
10616
3be00c4a6835 PSARC 2009/373 Clearview IP Tunneling
Sebastien Roy <Sebastien.Roy@Sun.COM>
parents: 10067
diff changeset
  2678
	if (dlnum != 0) {
3be00c4a6835 PSARC 2009/373 Clearview IP Tunneling
Sebastien Roy <Sebastien.Roy@Sun.COM>
parents: 10067
diff changeset
  2679
		zerror(zlogp, B_FALSE,
3be00c4a6835 PSARC 2009/373 Clearview IP Tunneling
Sebastien Roy <Sebastien.Roy@Sun.COM>
parents: 10067
diff changeset
  2680
		    "datalinks remain in zone after shutdown");
3448
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2681
		return (-1);
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2682
	}
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2683
	return (0);
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2684
}
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  2685
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2686
static int
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2687
tcp_abort_conn(zlog_t *zlogp, zoneid_t zoneid,
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2688
    const struct sockaddr_storage *local, const struct sockaddr_storage *remote)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2689
{
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2690
	int fd;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2691
	struct strioctl ioc;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2692
	tcp_ioc_abort_conn_t conn;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2693
	int error;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2694
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2695
	conn.ac_local = *local;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2696
	conn.ac_remote = *remote;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2697
	conn.ac_start = TCPS_SYN_SENT;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2698
	conn.ac_end = TCPS_TIME_WAIT;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2699
	conn.ac_zoneid = zoneid;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2700
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2701
	ioc.ic_cmd = TCP_IOC_ABORT_CONN;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2702
	ioc.ic_timout = -1; /* infinite timeout */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2703
	ioc.ic_len = sizeof (conn);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2704
	ioc.ic_dp = (char *)&conn;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2705
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2706
	if ((fd = open("/dev/tcp", O_RDONLY)) < 0) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2707
		zerror(zlogp, B_TRUE, "unable to open %s", "/dev/tcp");
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2708
		return (-1);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2709
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2710
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2711
	error = ioctl(fd, I_STR, &ioc);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2712
	(void) close(fd);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2713
	if (error == 0 || errno == ENOENT)	/* ENOENT is not an error */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2714
		return (0);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2715
	return (-1);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2716
}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2717
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2718
static int
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2719
tcp_abort_connections(zlog_t *zlogp, zoneid_t zoneid)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2720
{
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2721
	struct sockaddr_storage l, r;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2722
	struct sockaddr_in *local, *remote;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2723
	struct sockaddr_in6 *local6, *remote6;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2724
	int error;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2725
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2726
	/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2727
	 * Abort IPv4 connections.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2728
	 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2729
	bzero(&l, sizeof (*local));
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2730
	local = (struct sockaddr_in *)&l;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2731
	local->sin_family = AF_INET;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2732
	local->sin_addr.s_addr = INADDR_ANY;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2733
	local->sin_port = 0;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2734
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2735
	bzero(&r, sizeof (*remote));
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2736
	remote = (struct sockaddr_in *)&r;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2737
	remote->sin_family = AF_INET;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2738
	remote->sin_addr.s_addr = INADDR_ANY;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2739
	remote->sin_port = 0;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2740
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2741
	if ((error = tcp_abort_conn(zlogp, zoneid, &l, &r)) != 0)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2742
		return (error);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2743
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2744
	/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2745
	 * Abort IPv6 connections.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2746
	 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2747
	bzero(&l, sizeof (*local6));
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2748
	local6 = (struct sockaddr_in6 *)&l;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2749
	local6->sin6_family = AF_INET6;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2750
	local6->sin6_port = 0;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2751
	local6->sin6_addr = in6addr_any;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2752
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2753
	bzero(&r, sizeof (*remote6));
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2754
	remote6 = (struct sockaddr_in6 *)&r;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2755
	remote6->sin6_family = AF_INET6;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2756
	remote6->sin6_port = 0;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2757
	remote6->sin6_addr = in6addr_any;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2758
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2759
	if ((error = tcp_abort_conn(zlogp, zoneid, &l, &r)) != 0)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2760
		return (error);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2761
	return (0);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2762
}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2763
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2764
static int
5829
20241b1ccadc PSARC 2007/621 zone update on attach
gjelinek
parents: 5596
diff changeset
  2765
get_privset(zlog_t *zlogp, priv_set_t *privs, zone_mnt_t mount_cmd)
1645
5c204cdba7d2 PSARC 2006/124 Configurable Privileges for Zones
comay
parents: 1544
diff changeset
  2766
{
5c204cdba7d2 PSARC 2006/124 Configurable Privileges for Zones
comay
parents: 1544
diff changeset
  2767
	int error = -1;
5c204cdba7d2 PSARC 2006/124 Configurable Privileges for Zones
comay
parents: 1544
diff changeset
  2768
	zone_dochandle_t handle;
5c204cdba7d2 PSARC 2006/124 Configurable Privileges for Zones
comay
parents: 1544
diff changeset
  2769
	char *privname = NULL;
5c204cdba7d2 PSARC 2006/124 Configurable Privileges for Zones
comay
parents: 1544
diff changeset
  2770
5c204cdba7d2 PSARC 2006/124 Configurable Privileges for Zones
comay
parents: 1544
diff changeset
  2771
	if ((handle = zonecfg_init_handle()) == NULL) {
5c204cdba7d2 PSARC 2006/124 Configurable Privileges for Zones
comay
parents: 1544
diff changeset
  2772
		zerror(zlogp, B_TRUE, "getting zone configuration handle");
5c204cdba7d2 PSARC 2006/124 Configurable Privileges for Zones
comay
parents: 1544
diff changeset
  2773
		return (-1);
5c204cdba7d2 PSARC 2006/124 Configurable Privileges for Zones
comay
parents: 1544
diff changeset
  2774
	}
5c204cdba7d2 PSARC 2006/124 Configurable Privileges for Zones
comay
parents: 1544
diff changeset
  2775
	if (zonecfg_get_snapshot_handle(zone_name, handle) != Z_OK) {
5c204cdba7d2 PSARC 2006/124 Configurable Privileges for Zones
comay
parents: 1544
diff changeset
  2776
		zerror(zlogp, B_FALSE, "invalid configuration");
5c204cdba7d2 PSARC 2006/124 Configurable Privileges for Zones
comay
parents: 1544
diff changeset
  2777
		zonecfg_fini_handle(handle);
5c204cdba7d2 PSARC 2006/124 Configurable Privileges for Zones
comay
parents: 1544
diff changeset
  2778
		return (-1);
5c204cdba7d2 PSARC 2006/124 Configurable Privileges for Zones
comay
parents: 1544
diff changeset
  2779
	}
5c204cdba7d2 PSARC 2006/124 Configurable Privileges for Zones
comay
parents: 1544
diff changeset
  2780
5829
20241b1ccadc PSARC 2007/621 zone update on attach
gjelinek
parents: 5596
diff changeset
  2781
	if (ALT_MOUNT(mount_cmd)) {
3673
5bba3401c7f4 6516265 an exclusive zone with "limitpriv" other than "default" will panic the machine
dh155122
parents: 3514
diff changeset
  2782
		zone_iptype_t	iptype;
5bba3401c7f4 6516265 an exclusive zone with "limitpriv" other than "default" will panic the machine
dh155122
parents: 3514
diff changeset
  2783
		const char	*curr_iptype;
5bba3401c7f4 6516265 an exclusive zone with "limitpriv" other than "default" will panic the machine
dh155122
parents: 3514
diff changeset
  2784
5bba3401c7f4 6516265 an exclusive zone with "limitpriv" other than "default" will panic the machine
dh155122
parents: 3514
diff changeset
  2785
		if (zonecfg_get_iptype(handle, &iptype) != Z_OK) {
5bba3401c7f4 6516265 an exclusive zone with "limitpriv" other than "default" will panic the machine
dh155122
parents: 3514
diff changeset
  2786
			zerror(zlogp, B_TRUE, "unable to determine ip-type");
5bba3401c7f4 6516265 an exclusive zone with "limitpriv" other than "default" will panic the machine
dh155122
parents: 3514
diff changeset
  2787
			zonecfg_fini_handle(handle);
5bba3401c7f4 6516265 an exclusive zone with "limitpriv" other than "default" will panic the machine
dh155122
parents: 3514
diff changeset
  2788
			return (-1);
5bba3401c7f4 6516265 an exclusive zone with "limitpriv" other than "default" will panic the machine
dh155122
parents: 3514
diff changeset
  2789
		}
5bba3401c7f4 6516265 an exclusive zone with "limitpriv" other than "default" will panic the machine
dh155122
parents: 3514
diff changeset
  2790
5bba3401c7f4 6516265 an exclusive zone with "limitpriv" other than "default" will panic the machine
dh155122
parents: 3514
diff changeset
  2791
		switch (iptype) {
5bba3401c7f4 6516265 an exclusive zone with "limitpriv" other than "default" will panic the machine
dh155122
parents: 3514
diff changeset
  2792
		case ZS_SHARED:
5bba3401c7f4 6516265 an exclusive zone with "limitpriv" other than "default" will panic the machine
dh155122
parents: 3514
diff changeset
  2793
			curr_iptype = "shared";
5bba3401c7f4 6516265 an exclusive zone with "limitpriv" other than "default" will panic the machine
dh155122
parents: 3514
diff changeset
  2794
			break;
5bba3401c7f4 6516265 an exclusive zone with "limitpriv" other than "default" will panic the machine
dh155122
parents: 3514
diff changeset
  2795
		case ZS_EXCLUSIVE:
5bba3401c7f4 6516265 an exclusive zone with "limitpriv" other than "default" will panic the machine
dh155122
parents: 3514
diff changeset
  2796
			curr_iptype = "exclusive";
5bba3401c7f4 6516265 an exclusive zone with "limitpriv" other than "default" will panic the machine
dh155122
parents: 3514
diff changeset
  2797
			break;
5bba3401c7f4 6516265 an exclusive zone with "limitpriv" other than "default" will panic the machine
dh155122
parents: 3514
diff changeset
  2798
		}
5bba3401c7f4 6516265 an exclusive zone with "limitpriv" other than "default" will panic the machine
dh155122
parents: 3514
diff changeset
  2799
3716
1429cb51c952 6527301 zoneadmd has sprung a few leaks
gjelinek
parents: 3688
diff changeset
  2800
		if (zonecfg_default_privset(privs, curr_iptype) == Z_OK) {
1429cb51c952 6527301 zoneadmd has sprung a few leaks
gjelinek
parents: 3688
diff changeset
  2801
			zonecfg_fini_handle(handle);
2712
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  2802
			return (0);
3716
1429cb51c952 6527301 zoneadmd has sprung a few leaks
gjelinek
parents: 3688
diff changeset
  2803
		}
2712
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  2804
		zerror(zlogp, B_FALSE,
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  2805
		    "failed to determine the zone's default privilege set");
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  2806
		zonecfg_fini_handle(handle);
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  2807
		return (-1);
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  2808
	}
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  2809
1645
5c204cdba7d2 PSARC 2006/124 Configurable Privileges for Zones
comay
parents: 1544
diff changeset
  2810
	switch (zonecfg_get_privset(handle, privs, &privname)) {
5c204cdba7d2 PSARC 2006/124 Configurable Privileges for Zones
comay
parents: 1544
diff changeset
  2811
	case Z_OK:
5c204cdba7d2 PSARC 2006/124 Configurable Privileges for Zones
comay
parents: 1544
diff changeset
  2812
		error = 0;
5c204cdba7d2 PSARC 2006/124 Configurable Privileges for Zones
comay
parents: 1544
diff changeset
  2813
		break;
5c204cdba7d2 PSARC 2006/124 Configurable Privileges for Zones
comay
parents: 1544
diff changeset
  2814
	case Z_PRIV_PROHIBITED:
5c204cdba7d2 PSARC 2006/124 Configurable Privileges for Zones
comay
parents: 1544
diff changeset
  2815
		zerror(zlogp, B_FALSE, "privilege \"%s\" is not permitted "
5c204cdba7d2 PSARC 2006/124 Configurable Privileges for Zones
comay
parents: 1544
diff changeset
  2816
		    "within the zone's privilege set", privname);
5c204cdba7d2 PSARC 2006/124 Configurable Privileges for Zones
comay
parents: 1544
diff changeset
  2817
		break;
5c204cdba7d2 PSARC 2006/124 Configurable Privileges for Zones
comay
parents: 1544
diff changeset
  2818
	case Z_PRIV_REQUIRED:
5c204cdba7d2 PSARC 2006/124 Configurable Privileges for Zones
comay
parents: 1544
diff changeset
  2819
		zerror(zlogp, B_FALSE, "required privilege \"%s\" is missing "
5c204cdba7d2 PSARC 2006/124 Configurable Privileges for Zones
comay
parents: 1544
diff changeset
  2820
		    "from the zone's privilege set", privname);
5c204cdba7d2 PSARC 2006/124 Configurable Privileges for Zones
comay
parents: 1544
diff changeset
  2821
		break;
5c204cdba7d2 PSARC 2006/124 Configurable Privileges for Zones
comay
parents: 1544
diff changeset
  2822
	case Z_PRIV_UNKNOWN:
5c204cdba7d2 PSARC 2006/124 Configurable Privileges for Zones
comay
parents: 1544
diff changeset
  2823
		zerror(zlogp, B_FALSE, "unknown privilege \"%s\" specified "
5c204cdba7d2 PSARC 2006/124 Configurable Privileges for Zones
comay
parents: 1544
diff changeset
  2824
		    "in the zone's privilege set", privname);
5c204cdba7d2 PSARC 2006/124 Configurable Privileges for Zones
comay
parents: 1544
diff changeset
  2825
		break;
5c204cdba7d2 PSARC 2006/124 Configurable Privileges for Zones
comay
parents: 1544
diff changeset
  2826
	default:
5c204cdba7d2 PSARC 2006/124 Configurable Privileges for Zones
comay
parents: 1544
diff changeset
  2827
		zerror(zlogp, B_FALSE, "failed to determine the zone's "
5c204cdba7d2 PSARC 2006/124 Configurable Privileges for Zones
comay
parents: 1544
diff changeset
  2828
		    "privilege set");
5c204cdba7d2 PSARC 2006/124 Configurable Privileges for Zones
comay
parents: 1544
diff changeset
  2829
		break;
5c204cdba7d2 PSARC 2006/124 Configurable Privileges for Zones
comay
parents: 1544
diff changeset
  2830
	}
5c204cdba7d2 PSARC 2006/124 Configurable Privileges for Zones
comay
parents: 1544
diff changeset
  2831
5c204cdba7d2 PSARC 2006/124 Configurable Privileges for Zones
comay
parents: 1544
diff changeset
  2832
	free(privname);
5c204cdba7d2 PSARC 2006/124 Configurable Privileges for Zones
comay
parents: 1544
diff changeset
  2833
	zonecfg_fini_handle(handle);
5c204cdba7d2 PSARC 2006/124 Configurable Privileges for Zones
comay
parents: 1544
diff changeset
  2834
	return (error);
5c204cdba7d2 PSARC 2006/124 Configurable Privileges for Zones
comay
parents: 1544
diff changeset
  2835
}
5c204cdba7d2 PSARC 2006/124 Configurable Privileges for Zones
comay
parents: 1544
diff changeset
  2836
5c204cdba7d2 PSARC 2006/124 Configurable Privileges for Zones
comay
parents: 1544
diff changeset
  2837
static int
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2838
get_rctls(zlog_t *zlogp, char **bufp, size_t *bufsizep)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2839
{
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2840
	nvlist_t *nvl = NULL;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2841
	char *nvl_packed = NULL;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2842
	size_t nvl_size = 0;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2843
	nvlist_t **nvlv = NULL;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2844
	int rctlcount = 0;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2845
	int error = -1;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2846
	zone_dochandle_t handle;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2847
	struct zone_rctltab rctltab;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2848
	rctlblk_t *rctlblk = NULL;
12725
334fd88ae67c PSARC 2009/042 max-processes rctl
Menno Lageman <Menno.Lageman@Sun.COM>
parents: 12633
diff changeset
  2849
	uint64_t maxlwps;
334fd88ae67c PSARC 2009/042 max-processes rctl
Menno Lageman <Menno.Lageman@Sun.COM>
parents: 12633
diff changeset
  2850
	uint64_t maxprocs;
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2851
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2852
	*bufp = NULL;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2853
	*bufsizep = 0;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2854
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2855
	if ((handle = zonecfg_init_handle()) == NULL) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2856
		zerror(zlogp, B_TRUE, "getting zone configuration handle");
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2857
		return (-1);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2858
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2859
	if (zonecfg_get_snapshot_handle(zone_name, handle) != Z_OK) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2860
		zerror(zlogp, B_FALSE, "invalid configuration");
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2861
		zonecfg_fini_handle(handle);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2862
		return (-1);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2863
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2864
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2865
	rctltab.zone_rctl_valptr = NULL;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2866
	if (nvlist_alloc(&nvl, NV_UNIQUE_NAME, 0) != 0) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2867
		zerror(zlogp, B_TRUE, "%s failed", "nvlist_alloc");
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2868
		goto out;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2869
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2870
12725
334fd88ae67c PSARC 2009/042 max-processes rctl
Menno Lageman <Menno.Lageman@Sun.COM>
parents: 12633
diff changeset
  2871
	/*
334fd88ae67c PSARC 2009/042 max-processes rctl
Menno Lageman <Menno.Lageman@Sun.COM>
parents: 12633
diff changeset
  2872
	 * Allow the administrator to control both the maximum number of
334fd88ae67c PSARC 2009/042 max-processes rctl
Menno Lageman <Menno.Lageman@Sun.COM>
parents: 12633
diff changeset
  2873
	 * process table slots and the maximum number of lwps with just the
334fd88ae67c PSARC 2009/042 max-processes rctl
Menno Lageman <Menno.Lageman@Sun.COM>
parents: 12633
diff changeset
  2874
	 * max-processes property.  If only the max-processes property is set,
334fd88ae67c PSARC 2009/042 max-processes rctl
Menno Lageman <Menno.Lageman@Sun.COM>
parents: 12633
diff changeset
  2875
	 * we add a max-lwps property with a limit derived from max-processes.
334fd88ae67c PSARC 2009/042 max-processes rctl
Menno Lageman <Menno.Lageman@Sun.COM>
parents: 12633
diff changeset
  2876
	 */
334fd88ae67c PSARC 2009/042 max-processes rctl
Menno Lageman <Menno.Lageman@Sun.COM>
parents: 12633
diff changeset
  2877
	if (zonecfg_get_aliased_rctl(handle, ALIAS_MAXPROCS, &maxprocs)
334fd88ae67c PSARC 2009/042 max-processes rctl
Menno Lageman <Menno.Lageman@Sun.COM>
parents: 12633
diff changeset
  2878
	    == Z_OK &&
334fd88ae67c PSARC 2009/042 max-processes rctl
Menno Lageman <Menno.Lageman@Sun.COM>
parents: 12633
diff changeset
  2879
	    zonecfg_get_aliased_rctl(handle, ALIAS_MAXLWPS, &maxlwps)
334fd88ae67c PSARC 2009/042 max-processes rctl
Menno Lageman <Menno.Lageman@Sun.COM>
parents: 12633
diff changeset
  2880
	    == Z_NO_ENTRY) {
334fd88ae67c PSARC 2009/042 max-processes rctl
Menno Lageman <Menno.Lageman@Sun.COM>
parents: 12633
diff changeset
  2881
		if (zonecfg_set_aliased_rctl(handle, ALIAS_MAXLWPS,
334fd88ae67c PSARC 2009/042 max-processes rctl
Menno Lageman <Menno.Lageman@Sun.COM>
parents: 12633
diff changeset
  2882
		    maxprocs * LWPS_PER_PROCESS) != Z_OK) {
334fd88ae67c PSARC 2009/042 max-processes rctl
Menno Lageman <Menno.Lageman@Sun.COM>
parents: 12633
diff changeset
  2883
			zerror(zlogp, B_FALSE, "unable to set max-lwps alias");
334fd88ae67c PSARC 2009/042 max-processes rctl
Menno Lageman <Menno.Lageman@Sun.COM>
parents: 12633
diff changeset
  2884
			goto out;
334fd88ae67c PSARC 2009/042 max-processes rctl
Menno Lageman <Menno.Lageman@Sun.COM>
parents: 12633
diff changeset
  2885
		}
334fd88ae67c PSARC 2009/042 max-processes rctl
Menno Lageman <Menno.Lageman@Sun.COM>
parents: 12633
diff changeset
  2886
	}
334fd88ae67c PSARC 2009/042 max-processes rctl
Menno Lageman <Menno.Lageman@Sun.COM>
parents: 12633
diff changeset
  2887
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2888
	if (zonecfg_setrctlent(handle) != Z_OK) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2889
		zerror(zlogp, B_FALSE, "%s failed", "zonecfg_setrctlent");
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2890
		goto out;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2891
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2892
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2893
	if ((rctlblk = malloc(rctlblk_size())) == NULL) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2894
		zerror(zlogp, B_TRUE, "memory allocation failed");
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2895
		goto out;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2896
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2897
	while (zonecfg_getrctlent(handle, &rctltab) == Z_OK) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2898
		struct zone_rctlvaltab *rctlval;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2899
		uint_t i, count;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2900
		const char *name = rctltab.zone_rctl_name;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2901
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2902
		/* zoneadm should have already warned about unknown rctls. */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2903
		if (!zonecfg_is_rctl(name)) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2904
			zonecfg_free_rctl_value_list(rctltab.zone_rctl_valptr);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2905
			rctltab.zone_rctl_valptr = NULL;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2906
			continue;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2907
		}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2908
		count = 0;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2909
		for (rctlval = rctltab.zone_rctl_valptr; rctlval != NULL;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2910
		    rctlval = rctlval->zone_rctlval_next) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2911
			count++;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2912
		}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2913
		if (count == 0) {	/* ignore */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2914
			continue;	/* Nothing to free */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2915
		}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2916
		if ((nvlv = malloc(sizeof (*nvlv) * count)) == NULL)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2917
			goto out;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2918
		i = 0;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2919
		for (rctlval = rctltab.zone_rctl_valptr; rctlval != NULL;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2920
		    rctlval = rctlval->zone_rctlval_next, i++) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2921
			if (nvlist_alloc(&nvlv[i], NV_UNIQUE_NAME, 0) != 0) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2922
				zerror(zlogp, B_TRUE, "%s failed",
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2923
				    "nvlist_alloc");
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2924
				goto out;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2925
			}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2926
			if (zonecfg_construct_rctlblk(rctlval, rctlblk)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2927
			    != Z_OK) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2928
				zerror(zlogp, B_FALSE, "invalid rctl value: "
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2929
				    "(priv=%s,limit=%s,action=%s)",
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2930
				    rctlval->zone_rctlval_priv,
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2931
				    rctlval->zone_rctlval_limit,
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2932
				    rctlval->zone_rctlval_action);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2933
				goto out;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2934
			}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2935
			if (!zonecfg_valid_rctl(name, rctlblk)) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2936
				zerror(zlogp, B_FALSE,
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2937
				    "(priv=%s,limit=%s,action=%s) is not a "
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2938
				    "valid value for rctl '%s'",
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2939
				    rctlval->zone_rctlval_priv,
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2940
				    rctlval->zone_rctlval_limit,
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2941
				    rctlval->zone_rctlval_action,
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2942
				    name);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2943
				goto out;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2944
			}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2945
			if (nvlist_add_uint64(nvlv[i], "privilege",
1645
5c204cdba7d2 PSARC 2006/124 Configurable Privileges for Zones
comay
parents: 1544
diff changeset
  2946
			    rctlblk_get_privilege(rctlblk)) != 0) {
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2947
				zerror(zlogp, B_FALSE, "%s failed",
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2948
				    "nvlist_add_uint64");
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2949
				goto out;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2950
			}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2951
			if (nvlist_add_uint64(nvlv[i], "limit",
1645
5c204cdba7d2 PSARC 2006/124 Configurable Privileges for Zones
comay
parents: 1544
diff changeset
  2952
			    rctlblk_get_value(rctlblk)) != 0) {
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2953
				zerror(zlogp, B_FALSE, "%s failed",
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2954
				    "nvlist_add_uint64");
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2955
				goto out;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2956
			}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2957
			if (nvlist_add_uint64(nvlv[i], "action",
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2958
			    (uint_t)rctlblk_get_local_action(rctlblk, NULL))
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2959
			    != 0) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2960
				zerror(zlogp, B_FALSE, "%s failed",
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2961
				    "nvlist_add_uint64");
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2962
				goto out;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2963
			}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2964
		}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2965
		zonecfg_free_rctl_value_list(rctltab.zone_rctl_valptr);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2966
		rctltab.zone_rctl_valptr = NULL;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2967
		if (nvlist_add_nvlist_array(nvl, (char *)name, nvlv, count)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2968
		    != 0) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2969
			zerror(zlogp, B_FALSE, "%s failed",
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2970
			    "nvlist_add_nvlist_array");
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2971
			goto out;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2972
		}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2973
		for (i = 0; i < count; i++)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2974
			nvlist_free(nvlv[i]);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2975
		free(nvlv);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2976
		nvlv = NULL;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2977
		rctlcount++;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2978
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2979
	(void) zonecfg_endrctlent(handle);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2980
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2981
	if (rctlcount == 0) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2982
		error = 0;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2983
		goto out;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2984
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2985
	if (nvlist_pack(nvl, &nvl_packed, &nvl_size, NV_ENCODE_NATIVE, 0)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2986
	    != 0) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2987
		zerror(zlogp, B_FALSE, "%s failed", "nvlist_pack");
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2988
		goto out;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2989
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2990
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2991
	error = 0;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2992
	*bufp = nvl_packed;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2993
	*bufsizep = nvl_size;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2994
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2995
out:
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2996
	free(rctlblk);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2997
	zonecfg_free_rctl_value_list(rctltab.zone_rctl_valptr);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2998
	if (error && nvl_packed != NULL)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  2999
		free(nvl_packed);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  3000
	if (nvl != NULL)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  3001
		nvlist_free(nvl);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  3002
	if (nvlv != NULL)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  3003
		free(nvlv);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  3004
	if (handle != NULL)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  3005
		zonecfg_fini_handle(handle);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  3006
	return (error);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  3007
}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  3008
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  3009
static int
7370
e94ec740675f 6733450 RFE: need more flexible hooks for mounting and booting a zone
<Gerald Jelinek>
parents: 7342
diff changeset
  3010
get_implicit_datasets(zlog_t *zlogp, char **retstr)
e94ec740675f 6733450 RFE: need more flexible hooks for mounting and booting a zone
<Gerald Jelinek>
parents: 7342
diff changeset
  3011
{
e94ec740675f 6733450 RFE: need more flexible hooks for mounting and booting a zone
<Gerald Jelinek>
parents: 7342
diff changeset
  3012
	char cmdbuf[2 * MAXPATHLEN];
e94ec740675f 6733450 RFE: need more flexible hooks for mounting and booting a zone
<Gerald Jelinek>
parents: 7342
diff changeset
  3013
e94ec740675f 6733450 RFE: need more flexible hooks for mounting and booting a zone
<Gerald Jelinek>
parents: 7342
diff changeset
  3014
	if (query_hook[0] == '\0')
e94ec740675f 6733450 RFE: need more flexible hooks for mounting and booting a zone
<Gerald Jelinek>
parents: 7342
diff changeset
  3015
		return (0);
e94ec740675f 6733450 RFE: need more flexible hooks for mounting and booting a zone
<Gerald Jelinek>
parents: 7342
diff changeset
  3016
e94ec740675f 6733450 RFE: need more flexible hooks for mounting and booting a zone
<Gerald Jelinek>
parents: 7342
diff changeset
  3017
	if (snprintf(cmdbuf, sizeof (cmdbuf), "%s datasets", query_hook)
e94ec740675f 6733450 RFE: need more flexible hooks for mounting and booting a zone
<Gerald Jelinek>
parents: 7342
diff changeset
  3018
	    > sizeof (cmdbuf))
e94ec740675f 6733450 RFE: need more flexible hooks for mounting and booting a zone
<Gerald Jelinek>
parents: 7342
diff changeset
  3019
		return (-1);
e94ec740675f 6733450 RFE: need more flexible hooks for mounting and booting a zone
<Gerald Jelinek>
parents: 7342
diff changeset
  3020
e94ec740675f 6733450 RFE: need more flexible hooks for mounting and booting a zone
<Gerald Jelinek>
parents: 7342
diff changeset
  3021
	if (do_subproc(zlogp, cmdbuf, retstr) != 0)
e94ec740675f 6733450 RFE: need more flexible hooks for mounting and booting a zone
<Gerald Jelinek>
parents: 7342
diff changeset
  3022
		return (-1);
e94ec740675f 6733450 RFE: need more flexible hooks for mounting and booting a zone
<Gerald Jelinek>
parents: 7342
diff changeset
  3023
e94ec740675f 6733450 RFE: need more flexible hooks for mounting and booting a zone
<Gerald Jelinek>
parents: 7342
diff changeset
  3024
	return (0);
e94ec740675f 6733450 RFE: need more flexible hooks for mounting and booting a zone
<Gerald Jelinek>
parents: 7342
diff changeset
  3025
}
e94ec740675f 6733450 RFE: need more flexible hooks for mounting and booting a zone
<Gerald Jelinek>
parents: 7342
diff changeset
  3026
e94ec740675f 6733450 RFE: need more flexible hooks for mounting and booting a zone
<Gerald Jelinek>
parents: 7342
diff changeset
  3027
static int
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3028
get_datasets(zlog_t *zlogp, char **bufp, size_t *bufsizep)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3029
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3030
	zone_dochandle_t handle;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3031
	struct zone_dstab dstab;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3032
	size_t total, offset, len;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3033
	int error = -1;
5185
b74e2ef4da00 6609815 zone_create appears to have a hard limit on number of dataset allowed
gjelinek
parents: 5182
diff changeset
  3034
	char *str = NULL;
7370
e94ec740675f 6733450 RFE: need more flexible hooks for mounting and booting a zone
<Gerald Jelinek>
parents: 7342
diff changeset
  3035
	char *implicit_datasets = NULL;
e94ec740675f 6733450 RFE: need more flexible hooks for mounting and booting a zone
<Gerald Jelinek>
parents: 7342
diff changeset
  3036
	int implicit_len = 0;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3037
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3038
	*bufp = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3039
	*bufsizep = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3040
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3041
	if ((handle = zonecfg_init_handle()) == NULL) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3042
		zerror(zlogp, B_TRUE, "getting zone configuration handle");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3043
		return (-1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3044
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3045
	if (zonecfg_get_snapshot_handle(zone_name, handle) != Z_OK) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3046
		zerror(zlogp, B_FALSE, "invalid configuration");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3047
		zonecfg_fini_handle(handle);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3048
		return (-1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3049
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3050
7370
e94ec740675f 6733450 RFE: need more flexible hooks for mounting and booting a zone
<Gerald Jelinek>
parents: 7342
diff changeset
  3051
	if (get_implicit_datasets(zlogp, &implicit_datasets) != 0) {
e94ec740675f 6733450 RFE: need more flexible hooks for mounting and booting a zone
<Gerald Jelinek>
parents: 7342
diff changeset
  3052
		zerror(zlogp, B_FALSE, "getting implicit datasets failed");
e94ec740675f 6733450 RFE: need more flexible hooks for mounting and booting a zone
<Gerald Jelinek>
parents: 7342
diff changeset
  3053
		goto out;
e94ec740675f 6733450 RFE: need more flexible hooks for mounting and booting a zone
<Gerald Jelinek>
parents: 7342
diff changeset
  3054
	}
e94ec740675f 6733450 RFE: need more flexible hooks for mounting and booting a zone
<Gerald Jelinek>
parents: 7342
diff changeset
  3055
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3056
	if (zonecfg_setdsent(handle) != Z_OK) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3057
		zerror(zlogp, B_FALSE, "%s failed", "zonecfg_setdsent");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3058
		goto out;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3059
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3060
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3061
	total = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3062
	while (zonecfg_getdsent(handle, &dstab) == Z_OK)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3063
		total += strlen(dstab.zone_dataset_name) + 1;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3064
	(void) zonecfg_enddsent(handle);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3065
7370
e94ec740675f 6733450 RFE: need more flexible hooks for mounting and booting a zone
<Gerald Jelinek>
parents: 7342
diff changeset
  3066
	if (implicit_datasets != NULL)
e94ec740675f 6733450 RFE: need more flexible hooks for mounting and booting a zone
<Gerald Jelinek>
parents: 7342
diff changeset
  3067
		implicit_len = strlen(implicit_datasets);
e94ec740675f 6733450 RFE: need more flexible hooks for mounting and booting a zone
<Gerald Jelinek>
parents: 7342
diff changeset
  3068
	if (implicit_len > 0)
e94ec740675f 6733450 RFE: need more flexible hooks for mounting and booting a zone
<Gerald Jelinek>
parents: 7342
diff changeset
  3069
		total += implicit_len + 1;
e94ec740675f 6733450 RFE: need more flexible hooks for mounting and booting a zone
<Gerald Jelinek>
parents: 7342
diff changeset
  3070
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3071
	if (total == 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3072
		error = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3073
		goto out;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3074
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3075
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3076
	if ((str = malloc(total)) == NULL) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3077
		zerror(zlogp, B_TRUE, "memory allocation failed");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3078
		goto out;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3079
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3080
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3081
	if (zonecfg_setdsent(handle) != Z_OK) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3082
		zerror(zlogp, B_FALSE, "%s failed", "zonecfg_setdsent");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3083
		goto out;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3084
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3085
	offset = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3086
	while (zonecfg_getdsent(handle, &dstab) == Z_OK) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3087
		len = strlen(dstab.zone_dataset_name);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3088
		(void) strlcpy(str + offset, dstab.zone_dataset_name,
5185
b74e2ef4da00 6609815 zone_create appears to have a hard limit on number of dataset allowed
gjelinek
parents: 5182
diff changeset
  3089
		    total - offset);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3090
		offset += len;
5185
b74e2ef4da00 6609815 zone_create appears to have a hard limit on number of dataset allowed
gjelinek
parents: 5182
diff changeset
  3091
		if (offset < total - 1)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3092
			str[offset++] = ',';
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3093
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3094
	(void) zonecfg_enddsent(handle);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3095
7370
e94ec740675f 6733450 RFE: need more flexible hooks for mounting and booting a zone
<Gerald Jelinek>
parents: 7342
diff changeset
  3096
	if (implicit_len > 0)
e94ec740675f 6733450 RFE: need more flexible hooks for mounting and booting a zone
<Gerald Jelinek>
parents: 7342
diff changeset
  3097
		(void) strlcpy(str + offset, implicit_datasets, total - offset);
e94ec740675f 6733450 RFE: need more flexible hooks for mounting and booting a zone
<Gerald Jelinek>
parents: 7342
diff changeset
  3098
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3099
	error = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3100
	*bufp = str;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3101
	*bufsizep = total;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3102
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3103
out:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3104
	if (error != 0 && str != NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3105
		free(str);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3106
	if (handle != NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3107
		zonecfg_fini_handle(handle);
7370
e94ec740675f 6733450 RFE: need more flexible hooks for mounting and booting a zone
<Gerald Jelinek>
parents: 7342
diff changeset
  3108
	if (implicit_datasets != NULL)
e94ec740675f 6733450 RFE: need more flexible hooks for mounting and booting a zone
<Gerald Jelinek>
parents: 7342
diff changeset
  3109
		free(implicit_datasets);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3110
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3111
	return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3112
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3113
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3114
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3115
validate_datasets(zlog_t *zlogp)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3116
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3117
	zone_dochandle_t handle;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3118
	struct zone_dstab dstab;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3119
	zfs_handle_t *zhp;
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1915
diff changeset
  3120
	libzfs_handle_t *hdl;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3121
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3122
	if ((handle = zonecfg_init_handle()) == NULL) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3123
		zerror(zlogp, B_TRUE, "getting zone configuration handle");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3124
		return (-1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3125
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3126
	if (zonecfg_get_snapshot_handle(zone_name, handle) != Z_OK) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3127
		zerror(zlogp, B_FALSE, "invalid configuration");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3128
		zonecfg_fini_handle(handle);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3129
		return (-1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3130
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3131
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3132
	if (zonecfg_setdsent(handle) != Z_OK) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3133
		zerror(zlogp, B_FALSE, "invalid configuration");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3134
		zonecfg_fini_handle(handle);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3135
		return (-1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3136
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3137
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1915
diff changeset
  3138
	if ((hdl = libzfs_init()) == NULL) {
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1915
diff changeset
  3139
		zerror(zlogp, B_FALSE, "opening ZFS library");
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1915
diff changeset
  3140
		zonecfg_fini_handle(handle);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1915
diff changeset
  3141
		return (-1);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1915
diff changeset
  3142
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3143
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3144
	while (zonecfg_getdsent(handle, &dstab) == Z_OK) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3145
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1915
diff changeset
  3146
		if ((zhp = zfs_open(hdl, dstab.zone_dataset_name,
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3147
		    ZFS_TYPE_FILESYSTEM)) == NULL) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3148
			zerror(zlogp, B_FALSE, "cannot open ZFS dataset '%s'",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3149
			    dstab.zone_dataset_name);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3150
			zonecfg_fini_handle(handle);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1915
diff changeset
  3151
			libzfs_fini(hdl);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3152
			return (-1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3153
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3154
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3155
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3156
		 * Automatically set the 'zoned' property.  We check the value
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3157
		 * first because we'll get EPERM if it is already set.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3158
		 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3159
		if (!zfs_prop_get_int(zhp, ZFS_PROP_ZONED) &&
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2656
diff changeset
  3160
		    zfs_prop_set(zhp, zfs_prop_to_name(ZFS_PROP_ZONED),
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2656
diff changeset
  3161
		    "on") != 0) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3162
			zerror(zlogp, B_FALSE, "cannot set 'zoned' "
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3163
			    "property for ZFS dataset '%s'\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3164
			    dstab.zone_dataset_name);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3165
			zonecfg_fini_handle(handle);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3166
			zfs_close(zhp);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1915
diff changeset
  3167
			libzfs_fini(hdl);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3168
			return (-1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3169
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3170
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3171
		zfs_close(zhp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3172
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3173
	(void) zonecfg_enddsent(handle);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3174
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3175
	zonecfg_fini_handle(handle);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1915
diff changeset
  3176
	libzfs_fini(hdl);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3177
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3178
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3179
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  3180
1676
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3181
/*
10972
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3182
 * Return true if the path is its own zfs file system.  We determine this
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3183
 * by stat-ing the path to see if it is zfs and stat-ing the parent to see
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3184
 * if it is a different fs.
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3185
 */
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3186
boolean_t
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3187
is_zonepath_zfs(char *zonepath)
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3188
{
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3189
	int res;
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3190
	char *path;
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3191
	char *parent;
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3192
	struct statvfs64 buf1, buf2;
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3193
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3194
	if (statvfs64(zonepath, &buf1) != 0)
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3195
		return (B_FALSE);
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3196
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3197
	if (strcmp(buf1.f_basetype, "zfs") != 0)
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3198
		return (B_FALSE);
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3199
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3200
	if ((path = strdup(zonepath)) == NULL)
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3201
		return (B_FALSE);
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3202
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3203
	parent = dirname(path);
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3204
	res = statvfs64(parent, &buf2);
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3205
	free(path);
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3206
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3207
	if (res != 0)
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3208
		return (B_FALSE);
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3209
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3210
	if (buf1.f_fsid == buf2.f_fsid)
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3211
		return (B_FALSE);
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3212
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3213
	return (B_TRUE);
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3214
}
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3215
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3216
/*
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3217
 * Verify the MAC label in the root dataset for the zone.
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3218
 * If the label exists, it must match the label configured for the zone.
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3219
 * Otherwise if there's no label on the dataset, create one here.
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3220
 */
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3221
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3222
static int
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3223
validate_rootds_label(zlog_t *zlogp, char *rootpath, m_label_t *zone_sl)
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3224
{
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3225
	int		error = -1;
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3226
	zfs_handle_t	*zhp;
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3227
	libzfs_handle_t	*hdl;
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3228
	m_label_t	ds_sl;
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3229
	char		zonepath[MAXPATHLEN];
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3230
	char		ds_hexsl[MAXNAMELEN];
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3231
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3232
	if (!is_system_labeled())
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3233
		return (0);
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3234
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3235
	if (zone_get_zonepath(zone_name, zonepath, sizeof (zonepath)) != Z_OK) {
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3236
		zerror(zlogp, B_TRUE, "unable to determine zone path");
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3237
		return (-1);
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3238
	}
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3239
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3240
	if (!is_zonepath_zfs(zonepath))
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3241
		return (0);
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3242
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3243
	if ((hdl = libzfs_init()) == NULL) {
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3244
		zerror(zlogp, B_FALSE, "opening ZFS library");
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3245
		return (-1);
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3246
	}
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3247
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3248
	if ((zhp = zfs_path_to_zhandle(hdl, rootpath,
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3249
	    ZFS_TYPE_FILESYSTEM)) == NULL) {
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3250
		zerror(zlogp, B_FALSE, "cannot open ZFS dataset for path '%s'",
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3251
		    rootpath);
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3252
		libzfs_fini(hdl);
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3253
		return (-1);
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3254
	}
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3255
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3256
	/* Get the mlslabel property if it exists. */
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3257
	if ((zfs_prop_get(zhp, ZFS_PROP_MLSLABEL, ds_hexsl, MAXNAMELEN,
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3258
	    NULL, NULL, 0, B_TRUE) != 0) ||
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3259
	    (strcmp(ds_hexsl, ZFS_MLSLABEL_DEFAULT) == 0)) {
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3260
		char		*str2 = NULL;
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3261
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3262
		/*
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3263
		 * No label on the dataset (or default only); create one.
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3264
		 * (Only do this automatic labeling for the labeled brand.)
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3265
		 */
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3266
		if (strcmp(brand_name, LABELED_BRAND_NAME) != 0) {
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3267
			error = 0;
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3268
			goto out;
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3269
		}
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3270
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3271
		error = l_to_str_internal(zone_sl, &str2);
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3272
		if (error)
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3273
			goto out;
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3274
		if (str2 == NULL) {
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3275
			error = -1;
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3276
			goto out;
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3277
		}
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3278
		if ((error = zfs_prop_set(zhp,
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3279
		    zfs_prop_to_name(ZFS_PROP_MLSLABEL), str2)) != 0) {
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3280
			zerror(zlogp, B_FALSE, "cannot set 'mlslabel' "
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3281
			    "property for root dataset at '%s'\n", rootpath);
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3282
		}
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3283
		free(str2);
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3284
		goto out;
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3285
	}
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3286
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3287
	/* Convert the retrieved dataset label to binary form. */
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3288
	error = hexstr_to_label(ds_hexsl, &ds_sl);
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3289
	if (error) {
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3290
		zerror(zlogp, B_FALSE, "invalid 'mlslabel' "
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3291
		    "property on root dataset at '%s'\n", rootpath);
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3292
		goto out;			/* exit with error */
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3293
	}
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3294
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3295
	/*
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3296
	 * Perform a MAC check by comparing the zone label with the
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3297
	 * dataset label.
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3298
	 */
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3299
	error = (!blequal(zone_sl, &ds_sl));
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3300
	if (error)
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3301
		zerror(zlogp, B_FALSE, "Rootpath dataset has mismatched label");
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3302
out:
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3303
	zfs_close(zhp);
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3304
	libzfs_fini(hdl);
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3305
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3306
	return (error);
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3307
}
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3308
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  3309
/*
1676
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3310
 * Mount lower level home directories into/from current zone
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3311
 * Share exported directories specified in dfstab for zone
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3312
 */
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3313
static int
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3314
tsol_mounts(zlog_t *zlogp, char *zone_name, char *rootpath)
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3315
{
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3316
	zoneid_t *zids = NULL;
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3317
	priv_set_t *zid_privs;
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3318
	const priv_impl_info_t *ip = NULL;
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3319
	uint_t nzents_saved;
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3320
	uint_t nzents;
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3321
	int i;
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3322
	char readonly[] = "ro";
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3323
	struct zone_fstab lower_fstab;
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3324
	char *argv[4];
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3325
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3326
	if (!is_system_labeled())
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3327
		return (0);
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3328
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3329
	if (zid_label == NULL) {
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3330
		zid_label = m_label_alloc(MAC_LABEL);
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3331
		if (zid_label == NULL)
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3332
			return (-1);
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3333
	}
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3334
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3335
	/* Make sure our zone has an /export/home dir */
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3336
	(void) make_one_dir(zlogp, rootpath, "/export/home",
3813
c7c433a53b1a 6213465 non-global zone's /dev directory has wrong group owner
dp
parents: 3716
diff changeset
  3337
	    DEFAULT_DIR_MODE, DEFAULT_DIR_USER, DEFAULT_DIR_GROUP);
1676
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3338
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3339
	lower_fstab.zone_fs_raw[0] = '\0';
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3340
	(void) strlcpy(lower_fstab.zone_fs_type, MNTTYPE_LOFS,
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3341
	    sizeof (lower_fstab.zone_fs_type));
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3342
	lower_fstab.zone_fs_options = NULL;
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3343
	(void) zonecfg_add_fs_option(&lower_fstab, readonly);
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3344
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3345
	/*
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3346
	 * Get the list of zones from the kernel
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3347
	 */
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3348
	if (zone_list(NULL, &nzents) != 0) {
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3349
		zerror(zlogp, B_TRUE, "unable to list zones");
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3350
		zonecfg_free_fs_option_list(lower_fstab.zone_fs_options);
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3351
		return (-1);
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3352
	}
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3353
again:
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3354
	if (nzents == 0) {
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3355
		zonecfg_free_fs_option_list(lower_fstab.zone_fs_options);
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3356
		return (-1);
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3357
	}
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3358
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3359
	zids = malloc(nzents * sizeof (zoneid_t));
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3360
	if (zids == NULL) {
2267
c5d9a656170f PSARC/2006/269 Zone Boot Arguments II
dp
parents: 2170
diff changeset
  3361
		zerror(zlogp, B_TRUE, "memory allocation failed");
1676
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3362
		return (-1);
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3363
	}
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3364
	nzents_saved = nzents;
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3365
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3366
	if (zone_list(zids, &nzents) != 0) {
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3367
		zerror(zlogp, B_TRUE, "unable to list zones");
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3368
		zonecfg_free_fs_option_list(lower_fstab.zone_fs_options);
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3369
		free(zids);
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3370
		return (-1);
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3371
	}
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3372
	if (nzents != nzents_saved) {
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3373
		/* list changed, try again */
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3374
		free(zids);
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3375
		goto again;
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3376
	}
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3377
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3378
	ip = getprivimplinfo();
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3379
	if ((zid_privs = priv_allocset()) == NULL) {
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3380
		zerror(zlogp, B_TRUE, "%s failed", "priv_allocset");
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3381
		zonecfg_free_fs_option_list(
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3382
		    lower_fstab.zone_fs_options);
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3383
		free(zids);
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3384
		return (-1);
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3385
	}
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3386
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3387
	for (i = 0; i < nzents; i++) {
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3388
		char zid_name[ZONENAME_MAX];
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3389
		zone_state_t zid_state;
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3390
		char zid_rpath[MAXPATHLEN];
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3391
		struct stat stat_buf;
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3392
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3393
		if (zids[i] == GLOBAL_ZONEID)
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3394
			continue;
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3395
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3396
		if (getzonenamebyid(zids[i], zid_name, ZONENAME_MAX) == -1)
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3397
			continue;
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3398
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3399
		/*
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3400
		 * Do special setup for the zone we are booting
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3401
		 */
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3402
		if (strcmp(zid_name, zone_name) == 0) {
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3403
			struct zone_fstab autofs_fstab;
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3404
			char map_path[MAXPATHLEN];
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3405
			int fd;
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3406
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3407
			/*
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3408
			 * Create auto_home_<zone> map for this zone
2712
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  3409
			 * in the global zone. The non-global zone entry
1676
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3410
			 * will be created by automount when the zone
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3411
			 * is booted.
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3412
			 */
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3413
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3414
			(void) snprintf(autofs_fstab.zone_fs_special,
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3415
			    MAXPATHLEN, "auto_home_%s", zid_name);
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3416
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3417
			(void) snprintf(autofs_fstab.zone_fs_dir, MAXPATHLEN,
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3418
			    "/zone/%s/home", zid_name);
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3419
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3420
			(void) snprintf(map_path, sizeof (map_path),
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3421
			    "/etc/%s", autofs_fstab.zone_fs_special);
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3422
			/*
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3423
			 * If the map file doesn't exist create a template
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3424
			 */
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3425
			if ((fd = open(map_path, O_RDWR | O_CREAT | O_EXCL,
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3426
			    S_IRUSR | S_IWUSR | S_IRGRP| S_IROTH)) != -1) {
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3427
				int len;
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3428
				char map_rec[MAXPATHLEN];
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3429
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3430
				len = snprintf(map_rec, sizeof (map_rec),
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3431
				    "+%s\n*\t-fstype=lofs\t:%s/export/home/&\n",
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3432
				    autofs_fstab.zone_fs_special, rootpath);
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3433
				(void) write(fd, map_rec, len);
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3434
				(void) close(fd);
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3435
			}
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3436
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3437
			/*
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3438
			 * Mount auto_home_<zone> in the global zone if absent.
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3439
			 * If it's already of type autofs, then
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3440
			 * don't mount it again.
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3441
			 */
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3442
			if ((stat(autofs_fstab.zone_fs_dir, &stat_buf) == -1) ||
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3443
			    strcmp(stat_buf.st_fstype, MNTTYPE_AUTOFS) != 0) {
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3444
				char optstr[] = "indirect,ignore,nobrowse";
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3445
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3446
				(void) make_one_dir(zlogp, "",
3813
c7c433a53b1a 6213465 non-global zone's /dev directory has wrong group owner
dp
parents: 3716
diff changeset
  3447
				    autofs_fstab.zone_fs_dir, DEFAULT_DIR_MODE,
c7c433a53b1a 6213465 non-global zone's /dev directory has wrong group owner
dp
parents: 3716
diff changeset
  3448
				    DEFAULT_DIR_USER, DEFAULT_DIR_GROUP);
1676
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3449
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3450
				/*
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3451
				 * Mount will fail if automounter has already
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3452
				 * processed the auto_home_<zonename> map
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3453
				 */
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3454
				(void) domount(zlogp, MNTTYPE_AUTOFS, optstr,
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3455
				    autofs_fstab.zone_fs_special,
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3456
				    autofs_fstab.zone_fs_dir);
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3457
			}
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3458
			continue;
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3459
		}
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3460
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3461
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3462
		if (zone_get_state(zid_name, &zid_state) != Z_OK ||
1769
338500d67d4f 6404654 zoneadm mount command fails on labeled systems
carlsonj
parents: 1676
diff changeset
  3463
		    (zid_state != ZONE_STATE_READY &&
338500d67d4f 6404654 zoneadm mount command fails on labeled systems
carlsonj
parents: 1676
diff changeset
  3464
		    zid_state != ZONE_STATE_RUNNING))
1676
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3465
			/* Skip over zones without mounted filesystems */
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3466
			continue;
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3467
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3468
		if (zone_getattr(zids[i], ZONE_ATTR_SLBL, zid_label,
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3469
		    sizeof (m_label_t)) < 0)
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3470
			/* Skip over zones with unspecified label */
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3471
			continue;
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3472
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3473
		if (zone_getattr(zids[i], ZONE_ATTR_ROOT, zid_rpath,
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3474
		    sizeof (zid_rpath)) == -1)
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3475
			/* Skip over zones with bad path */
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3476
			continue;
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3477
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3478
		if (zone_getattr(zids[i], ZONE_ATTR_PRIVSET, zid_privs,
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3479
		    sizeof (priv_chunk_t) * ip->priv_setsize) == -1)
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3480
			/* Skip over zones with bad privs */
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3481
			continue;
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3482
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3483
		/*
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3484
		 * Reading down is valid according to our label model
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3485
		 * but some customers want to disable it because it
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3486
		 * allows execute down and other possible attacks.
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3487
		 * Therefore, we restrict this feature to zones that
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3488
		 * have the NET_MAC_AWARE privilege which is required
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3489
		 * for NFS read-down semantics.
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3490
		 */
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3491
		if ((bldominates(zlabel, zid_label)) &&
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3492
		    (priv_ismember(zprivs, PRIV_NET_MAC_AWARE))) {
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3493
			/*
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3494
			 * Our zone dominates this one.
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3495
			 * Create a lofs mount from lower zone's /export/home
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3496
			 */
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3497
			(void) snprintf(lower_fstab.zone_fs_dir, MAXPATHLEN,
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3498
			    "%s/zone/%s/export/home", rootpath, zid_name);
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3499
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3500
			/*
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3501
			 * If the target is already an LOFS mount
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3502
			 * then don't do it again.
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3503
			 */
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3504
			if ((stat(lower_fstab.zone_fs_dir, &stat_buf) == -1) ||
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3505
			    strcmp(stat_buf.st_fstype, MNTTYPE_LOFS) != 0) {
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3506
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3507
				if (snprintf(lower_fstab.zone_fs_special,
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3508
				    MAXPATHLEN, "%s/export",
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3509
				    zid_rpath) > MAXPATHLEN)
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3510
					continue;
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3511
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3512
				/*
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3513
				 * Make sure the lower-level home exists
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3514
				 */
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3515
				if (make_one_dir(zlogp,
3813
c7c433a53b1a 6213465 non-global zone's /dev directory has wrong group owner
dp
parents: 3716
diff changeset
  3516
				    lower_fstab.zone_fs_special, "/home",
c7c433a53b1a 6213465 non-global zone's /dev directory has wrong group owner
dp
parents: 3716
diff changeset
  3517
				    DEFAULT_DIR_MODE, DEFAULT_DIR_USER,
c7c433a53b1a 6213465 non-global zone's /dev directory has wrong group owner
dp
parents: 3716
diff changeset
  3518
				    DEFAULT_DIR_GROUP) != 0)
1676
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3519
					continue;
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3520
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3521
				(void) strlcat(lower_fstab.zone_fs_special,
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3522
				    "/home", MAXPATHLEN);
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3523
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3524
				/*
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3525
				 * Mount can fail because the lower-level
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3526
				 * zone may have already done a mount up.
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3527
				 */
7655
76c161ee52b3 6746514 RFE: need ability to mount non-native branded zones
<gerald.jelinek@sun.com>
parents: 7370
diff changeset
  3528
				(void) mount_one(zlogp, &lower_fstab, "",
76c161ee52b3 6746514 RFE: need ability to mount non-native branded zones
<gerald.jelinek@sun.com>
parents: 7370
diff changeset
  3529
				    Z_MNT_BOOT);
1676
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3530
			}
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3531
		} else if ((bldominates(zid_label, zlabel)) &&
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3532
		    (priv_ismember(zid_privs, PRIV_NET_MAC_AWARE))) {
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3533
			/*
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3534
			 * This zone dominates our zone.
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3535
			 * Create a lofs mount from our zone's /export/home
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3536
			 */
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3537
			if (snprintf(lower_fstab.zone_fs_dir, MAXPATHLEN,
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3538
			    "%s/zone/%s/export/home", zid_rpath,
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3539
			    zone_name) > MAXPATHLEN)
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3540
				continue;
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3541
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3542
			/*
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3543
			 * If the target is already an LOFS mount
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3544
			 * then don't do it again.
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3545
			 */
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3546
			if ((stat(lower_fstab.zone_fs_dir, &stat_buf) == -1) ||
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3547
			    strcmp(stat_buf.st_fstype, MNTTYPE_LOFS) != 0) {
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3548
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3549
				(void) snprintf(lower_fstab.zone_fs_special,
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3550
				    MAXPATHLEN, "%s/export/home", rootpath);
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3551
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3552
				/*
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3553
				 * Mount can fail because the higher-level
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3554
				 * zone may have already done a mount down.
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3555
				 */
7655
76c161ee52b3 6746514 RFE: need ability to mount non-native branded zones
<gerald.jelinek@sun.com>
parents: 7370
diff changeset
  3556
				(void) mount_one(zlogp, &lower_fstab, "",
76c161ee52b3 6746514 RFE: need ability to mount non-native branded zones
<gerald.jelinek@sun.com>
parents: 7370
diff changeset
  3557
				    Z_MNT_BOOT);
1676
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3558
			}
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3559
		}
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3560
	}
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3561
	zonecfg_free_fs_option_list(lower_fstab.zone_fs_options);
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3562
	priv_freeset(zid_privs);
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3563
	free(zids);
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3564
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3565
	/*
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3566
	 * Now share any exported directories from this zone.
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3567
	 * Each zone can have its own dfstab.
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3568
	 */
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3569
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3570
	argv[0] = "zoneshare";
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3571
	argv[1] = "-z";
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3572
	argv[2] = zone_name;
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3573
	argv[3] = NULL;
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3574
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3575
	(void) forkexec(zlogp, "/usr/lib/zones/zoneshare", argv);
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3576
	/* Don't check for errors since they don't affect the zone */
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3577
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3578
	return (0);
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3579
}
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3580
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3581
/*
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3582
 * Unmount lofs mounts from higher level zones
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3583
 * Unshare nfs exported directories
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3584
 */
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3585
static void
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3586
tsol_unmounts(zlog_t *zlogp, char *zone_name)
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3587
{
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3588
	zoneid_t *zids = NULL;
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3589
	uint_t nzents_saved;
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3590
	uint_t nzents;
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3591
	int i;
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3592
	char *argv[4];
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3593
	char path[MAXPATHLEN];
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3594
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3595
	if (!is_system_labeled())
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3596
		return;
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3597
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3598
	/*
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3599
	 * Get the list of zones from the kernel
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3600
	 */
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3601
	if (zone_list(NULL, &nzents) != 0) {
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3602
		return;
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3603
	}
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3604
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3605
	if (zid_label == NULL) {
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3606
		zid_label = m_label_alloc(MAC_LABEL);
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3607
		if (zid_label == NULL)
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3608
			return;
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3609
	}
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3610
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3611
again:
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3612
	if (nzents == 0)
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3613
		return;
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3614
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3615
	zids = malloc(nzents * sizeof (zoneid_t));
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3616
	if (zids == NULL) {
2267
c5d9a656170f PSARC/2006/269 Zone Boot Arguments II
dp
parents: 2170
diff changeset
  3617
		zerror(zlogp, B_TRUE, "memory allocation failed");
1676
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3618
		return;
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3619
	}
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3620
	nzents_saved = nzents;
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3621
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3622
	if (zone_list(zids, &nzents) != 0) {
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3623
		free(zids);
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3624
		return;
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3625
	}
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3626
	if (nzents != nzents_saved) {
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3627
		/* list changed, try again */
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3628
		free(zids);
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3629
		goto again;
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3630
	}
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3631
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3632
	for (i = 0; i < nzents; i++) {
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3633
		char zid_name[ZONENAME_MAX];
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3634
		zone_state_t zid_state;
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3635
		char zid_rpath[MAXPATHLEN];
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3636
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3637
		if (zids[i] == GLOBAL_ZONEID)
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3638
			continue;
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3639
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3640
		if (getzonenamebyid(zids[i], zid_name, ZONENAME_MAX) == -1)
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3641
			continue;
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3642
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3643
		/*
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3644
		 * Skip the zone we are halting
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3645
		 */
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3646
		if (strcmp(zid_name, zone_name) == 0)
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3647
			continue;
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3648
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3649
		if ((zone_getattr(zids[i], ZONE_ATTR_STATUS, &zid_state,
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3650
		    sizeof (zid_state)) < 0) ||
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3651
		    (zid_state < ZONE_IS_READY))
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3652
			/* Skip over zones without mounted filesystems */
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3653
			continue;
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3654
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3655
		if (zone_getattr(zids[i], ZONE_ATTR_SLBL, zid_label,
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3656
		    sizeof (m_label_t)) < 0)
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3657
			/* Skip over zones with unspecified label */
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3658
			continue;
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3659
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3660
		if (zone_getattr(zids[i], ZONE_ATTR_ROOT, zid_rpath,
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3661
		    sizeof (zid_rpath)) == -1)
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3662
			/* Skip over zones with bad path */
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3663
			continue;
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3664
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3665
		if (zlabel != NULL && bldominates(zid_label, zlabel)) {
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3666
			/*
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3667
			 * This zone dominates our zone.
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3668
			 * Unmount the lofs mount of our zone's /export/home
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3669
			 */
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3670
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3671
			if (snprintf(path, MAXPATHLEN,
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3672
			    "%s/zone/%s/export/home", zid_rpath,
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3673
			    zone_name) > MAXPATHLEN)
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3674
				continue;
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3675
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3676
			/* Skip over mount failures */
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3677
			(void) umount(path);
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3678
		}
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3679
	}
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3680
	free(zids);
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3681
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3682
	/*
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3683
	 * Unmount global zone autofs trigger for this zone
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3684
	 */
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3685
	(void) snprintf(path, MAXPATHLEN, "/zone/%s/home", zone_name);
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3686
	/* Skip over mount failures */
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3687
	(void) umount(path);
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3688
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3689
	/*
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3690
	 * Next unshare any exported directories from this zone.
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3691
	 */
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3692
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3693
	argv[0] = "zoneunshare";
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3694
	argv[1] = "-z";
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3695
	argv[2] = zone_name;
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3696
	argv[3] = NULL;
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3697
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3698
	(void) forkexec(zlogp, "/usr/lib/zones/zoneunshare", argv);
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3699
	/* Don't check for errors since they don't affect the zone */
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3700
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3701
	/*
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3702
	 * Finally, deallocate any devices in the zone.
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3703
	 */
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3704
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3705
	argv[0] = "deallocate";
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3706
	argv[1] = "-Isz";
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3707
	argv[2] = zone_name;
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3708
	argv[3] = NULL;
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3709
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3710
	(void) forkexec(zlogp, "/usr/sbin/deallocate", argv);
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3711
	/* Don't check for errors since they don't affect the zone */
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3712
}
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3713
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3714
/*
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3715
 * Fetch the Trusted Extensions label and multi-level ports (MLPs) for
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3716
 * this zone.
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3717
 */
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3718
static tsol_zcent_t *
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3719
get_zone_label(zlog_t *zlogp, priv_set_t *privs)
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3720
{
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3721
	FILE *fp;
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3722
	tsol_zcent_t *zcent = NULL;
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3723
	char line[MAXTNZLEN];
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3724
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3725
	if ((fp = fopen(TNZONECFG_PATH, "r")) == NULL) {
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3726
		zerror(zlogp, B_TRUE, "%s", TNZONECFG_PATH);
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3727
		return (NULL);
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3728
	}
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3729
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3730
	while (fgets(line, sizeof (line), fp) != NULL) {
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3731
		/*
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3732
		 * Check for malformed database
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3733
		 */
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3734
		if (strlen(line) == MAXTNZLEN - 1)
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3735
			break;
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3736
		if ((zcent = tsol_sgetzcent(line, NULL, NULL)) == NULL)
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3737
			continue;
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3738
		if (strcmp(zcent->zc_name, zone_name) == 0)
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3739
			break;
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3740
		tsol_freezcent(zcent);
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3741
		zcent = NULL;
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3742
	}
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3743
	(void) fclose(fp);
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3744
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3745
	if (zcent == NULL) {
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3746
		zerror(zlogp, B_FALSE, "zone requires a label assignment. "
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3747
		    "See tnzonecfg(4)");
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3748
	} else {
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3749
		if (zlabel == NULL)
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3750
			zlabel = m_label_alloc(MAC_LABEL);
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3751
		/*
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3752
		 * Save this zone's privileges for later read-down processing
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3753
		 */
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3754
		if ((zprivs = priv_allocset()) == NULL) {
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3755
			zerror(zlogp, B_TRUE, "%s failed", "priv_allocset");
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3756
			return (NULL);
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3757
		} else {
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3758
			priv_copyset(privs, zprivs);
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3759
		}
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3760
	}
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3761
	return (zcent);
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3762
}
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3763
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3764
/*
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3765
 * Add the Trusted Extensions multi-level ports for this zone.
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3766
 */
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3767
static void
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3768
set_mlps(zlog_t *zlogp, zoneid_t zoneid, tsol_zcent_t *zcent)
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3769
{
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3770
	tsol_mlp_t *mlp;
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3771
	tsol_mlpent_t tsme;
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3772
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3773
	if (!is_system_labeled())
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3774
		return;
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3775
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3776
	tsme.tsme_zoneid = zoneid;
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3777
	tsme.tsme_flags = 0;
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3778
	for (mlp = zcent->zc_private_mlp; !TSOL_MLP_END(mlp); mlp++) {
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3779
		tsme.tsme_mlp = *mlp;
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3780
		if (tnmlp(TNDB_LOAD, &tsme) != 0) {
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3781
			zerror(zlogp, B_TRUE, "cannot set zone-specific MLP "
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3782
			    "on %d-%d/%d", mlp->mlp_port,
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3783
			    mlp->mlp_port_upper, mlp->mlp_ipp);
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3784
		}
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3785
	}
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3786
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3787
	tsme.tsme_flags = TSOL_MEF_SHARED;
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3788
	for (mlp = zcent->zc_shared_mlp; !TSOL_MLP_END(mlp); mlp++) {
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3789
		tsme.tsme_mlp = *mlp;
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3790
		if (tnmlp(TNDB_LOAD, &tsme) != 0) {
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3791
			zerror(zlogp, B_TRUE, "cannot set shared MLP "
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3792
			    "on %d-%d/%d", mlp->mlp_port,
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3793
			    mlp->mlp_port_upper, mlp->mlp_ipp);
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3794
		}
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3795
	}
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3796
}
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3797
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3798
static void
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3799
remove_mlps(zlog_t *zlogp, zoneid_t zoneid)
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3800
{
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3801
	tsol_mlpent_t tsme;
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3802
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3803
	if (!is_system_labeled())
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3804
		return;
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3805
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3806
	(void) memset(&tsme, 0, sizeof (tsme));
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3807
	tsme.tsme_zoneid = zoneid;
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3808
	if (tnmlp(TNDB_FLUSH, &tsme) != 0)
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3809
		zerror(zlogp, B_TRUE, "cannot flush MLPs");
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3810
}
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  3811
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  3812
int
11276
4569547d4c39 6880335 zoneadm move needs brand hook
jv227347 <Jordan.Vaughan@Sun.com>
parents: 10972
diff changeset
  3813
prtmount(const struct mnttab *fs, void *x) {
4569547d4c39 6880335 zoneadm move needs brand hook
jv227347 <Jordan.Vaughan@Sun.com>
parents: 10972
diff changeset
  3814
	zerror((zlog_t *)x, B_FALSE, "  %s", fs->mnt_mountp);
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  3815
	return (0);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  3816
}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  3817
766
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  3818
/*
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  3819
 * Look for zones running on the main system that are using this root (or any
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  3820
 * subdirectory of it).  Return B_TRUE and print an error if a conflicting zone
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  3821
 * is found or if we can't tell.
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  3822
 */
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  3823
static boolean_t
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  3824
duplicate_zone_root(zlog_t *zlogp, const char *rootpath)
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  3825
{
766
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  3826
	zoneid_t *zids = NULL;
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  3827
	uint_t nzids = 0;
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  3828
	boolean_t retv;
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  3829
	int rlen, zlen;
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  3830
	char zroot[MAXPATHLEN];
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  3831
	char zonename[ZONENAME_MAX];
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  3832
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  3833
	for (;;) {
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  3834
		nzids += 10;
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  3835
		zids = malloc(nzids * sizeof (*zids));
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  3836
		if (zids == NULL) {
2267
c5d9a656170f PSARC/2006/269 Zone Boot Arguments II
dp
parents: 2170
diff changeset
  3837
			zerror(zlogp, B_TRUE, "memory allocation failed");
766
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  3838
			return (B_TRUE);
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  3839
		}
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  3840
		if (zone_list(zids, &nzids) == 0)
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  3841
			break;
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  3842
		free(zids);
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  3843
	}
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  3844
	retv = B_FALSE;
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  3845
	rlen = strlen(rootpath);
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  3846
	while (nzids > 0) {
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  3847
		/*
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  3848
		 * Ignore errors; they just mean that the zone has disappeared
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  3849
		 * while we were busy.
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  3850
		 */
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  3851
		if (zone_getattr(zids[--nzids], ZONE_ATTR_ROOT, zroot,
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  3852
		    sizeof (zroot)) == -1)
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  3853
			continue;
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  3854
		zlen = strlen(zroot);
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  3855
		if (zlen > rlen)
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  3856
			zlen = rlen;
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  3857
		if (strncmp(rootpath, zroot, zlen) == 0 &&
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  3858
		    (zroot[zlen] == '\0' || zroot[zlen] == '/') &&
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  3859
		    (rootpath[zlen] == '\0' || rootpath[zlen] == '/')) {
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  3860
			if (getzonenamebyid(zids[nzids], zonename,
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  3861
			    sizeof (zonename)) == -1)
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  3862
				(void) snprintf(zonename, sizeof (zonename),
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  3863
				    "id %d", (int)zids[nzids]);
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  3864
			zerror(zlogp, B_FALSE,
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  3865
			    "zone root %s already in use by zone %s",
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  3866
			    rootpath, zonename);
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  3867
			retv = B_TRUE;
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  3868
			break;
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  3869
		}
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  3870
	}
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  3871
	free(zids);
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  3872
	return (retv);
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  3873
}
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  3874
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  3875
/*
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  3876
 * Search for loopback mounts that use this same source node (same device and
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  3877
 * inode).  Return B_TRUE if there is one or if we can't tell.
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  3878
 */
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  3879
static boolean_t
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  3880
duplicate_reachable_path(zlog_t *zlogp, const char *rootpath)
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  3881
{
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  3882
	struct stat64 rst, zst;
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  3883
	struct mnttab *mnp;
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  3884
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  3885
	if (stat64(rootpath, &rst) == -1) {
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  3886
		zerror(zlogp, B_TRUE, "can't stat %s", rootpath);
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  3887
		return (B_TRUE);
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  3888
	}
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  3889
	if (resolve_lofs_mnts == NULL && lofs_read_mnttab(zlogp) == -1)
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  3890
		return (B_TRUE);
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  3891
	for (mnp = resolve_lofs_mnts; mnp < resolve_lofs_mnt_max; mnp++) {
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  3892
		if (mnp->mnt_fstype == NULL ||
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  3893
		    strcmp(MNTTYPE_LOFS, mnp->mnt_fstype) != 0)
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  3894
			continue;
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  3895
		/* We're looking at a loopback mount.  Stat it. */
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  3896
		if (mnp->mnt_special != NULL &&
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  3897
		    stat64(mnp->mnt_special, &zst) != -1 &&
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  3898
		    rst.st_dev == zst.st_dev && rst.st_ino == zst.st_ino) {
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  3899
			zerror(zlogp, B_FALSE,
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  3900
			    "zone root %s is reachable through %s",
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  3901
			    rootpath, mnp->mnt_mountp);
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  3902
			return (B_TRUE);
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  3903
		}
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  3904
	}
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  3905
	return (B_FALSE);
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  3906
}
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  3907
3247
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  3908
/*
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  3909
 * Set memory cap and pool info for the zone's resource management
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  3910
 * configuration.
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  3911
 */
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  3912
static int
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  3913
setup_zone_rm(zlog_t *zlogp, char *zone_name, zoneid_t zoneid)
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  3914
{
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  3915
	int res;
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  3916
	uint64_t tmp;
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  3917
	struct zone_mcaptab mcap;
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  3918
	char sched[MAXNAMELEN];
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  3919
	zone_dochandle_t handle = NULL;
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  3920
	char pool_err[128];
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  3921
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  3922
	if ((handle = zonecfg_init_handle()) == NULL) {
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  3923
		zerror(zlogp, B_TRUE, "getting zone configuration handle");
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  3924
		return (Z_BAD_HANDLE);
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  3925
	}
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  3926
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  3927
	if ((res = zonecfg_get_snapshot_handle(zone_name, handle)) != Z_OK) {
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  3928
		zerror(zlogp, B_FALSE, "invalid configuration");
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  3929
		zonecfg_fini_handle(handle);
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  3930
		return (res);
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  3931
	}
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  3932
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  3933
	/*
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  3934
	 * If a memory cap is configured, set the cap in the kernel using
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  3935
	 * zone_setattr() and make sure the rcapd SMF service is enabled.
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  3936
	 */
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  3937
	if (zonecfg_getmcapent(handle, &mcap) == Z_OK) {
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  3938
		uint64_t num;
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  3939
		char smf_err[128];
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  3940
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  3941
		num = (uint64_t)strtoull(mcap.zone_physmem_cap, NULL, 10);
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  3942
		if (zone_setattr(zoneid, ZONE_ATTR_PHYS_MCAP, &num, 0) == -1) {
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  3943
			zerror(zlogp, B_TRUE, "could not set zone memory cap");
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  3944
			zonecfg_fini_handle(handle);
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  3945
			return (Z_INVAL);
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  3946
		}
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  3947
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  3948
		if (zonecfg_enable_rcapd(smf_err, sizeof (smf_err)) != Z_OK) {
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  3949
			zerror(zlogp, B_FALSE, "enabling system/rcap service "
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  3950
			    "failed: %s", smf_err);
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  3951
			zonecfg_fini_handle(handle);
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  3952
			return (Z_INVAL);
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  3953
		}
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  3954
	}
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  3955
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  3956
	/* Get the scheduling class set in the zone configuration. */
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  3957
	if (zonecfg_get_sched_class(handle, sched, sizeof (sched)) == Z_OK &&
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  3958
	    strlen(sched) > 0) {
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  3959
		if (zone_setattr(zoneid, ZONE_ATTR_SCHED_CLASS, sched,
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  3960
		    strlen(sched)) == -1)
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  3961
			zerror(zlogp, B_TRUE, "WARNING: unable to set the "
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  3962
			    "default scheduling class");
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  3963
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  3964
	} else if (zonecfg_get_aliased_rctl(handle, ALIAS_SHARES, &tmp)
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  3965
	    == Z_OK) {
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  3966
		/*
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  3967
		 * If the zone has the zone.cpu-shares rctl set then we want to
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  3968
		 * use the Fair Share Scheduler (FSS) for processes in the
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  3969
		 * zone.  Check what scheduling class the zone would be running
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  3970
		 * in by default so we can print a warning and modify the class
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  3971
		 * if we wouldn't be using FSS.
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  3972
		 */
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  3973
		char class_name[PC_CLNMSZ];
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  3974
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  3975
		if (zonecfg_get_dflt_sched_class(handle, class_name,
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  3976
		    sizeof (class_name)) != Z_OK) {
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  3977
			zerror(zlogp, B_FALSE, "WARNING: unable to determine "
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  3978
			    "the zone's scheduling class");
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  3979
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  3980
		} else if (strcmp("FSS", class_name) != 0) {
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  3981
			zerror(zlogp, B_FALSE, "WARNING: The zone.cpu-shares "
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  3982
			    "rctl is set but\nFSS is not the default "
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  3983
			    "scheduling class for\nthis zone.  FSS will be "
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  3984
			    "used for processes\nin the zone but to get the "
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  3985
			    "full benefit of FSS,\nit should be the default "
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  3986
			    "scheduling class.\nSee dispadmin(1M) for more "
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  3987
			    "details.");
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  3988
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  3989
			if (zone_setattr(zoneid, ZONE_ATTR_SCHED_CLASS, "FSS",
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  3990
			    strlen("FSS")) == -1)
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  3991
				zerror(zlogp, B_TRUE, "WARNING: unable to set "
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  3992
				    "zone scheduling class to FSS");
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  3993
		}
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  3994
	}
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  3995
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  3996
	/*
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  3997
	 * The next few blocks of code attempt to set up temporary pools as
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  3998
	 * well as persistent pools.  In all cases we call the functions
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  3999
	 * unconditionally.  Within each funtion the code will check if the
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  4000
	 * zone is actually configured for a temporary pool or persistent pool
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  4001
	 * and just return if there is nothing to do.
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  4002
	 *
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  4003
	 * If we are rebooting we want to attempt to reuse any temporary pool
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  4004
	 * that was previously set up.  zonecfg_bind_tmp_pool() will do the
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  4005
	 * right thing in all cases (reuse or create) based on the current
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  4006
	 * zonecfg.
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  4007
	 */
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  4008
	if ((res = zonecfg_bind_tmp_pool(handle, zoneid, pool_err,
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  4009
	    sizeof (pool_err))) != Z_OK) {
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  4010
		if (res == Z_POOL || res == Z_POOL_CREATE || res == Z_POOL_BIND)
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  4011
			zerror(zlogp, B_FALSE, "%s: %s\ndedicated-cpu setting "
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  4012
			    "cannot be instantiated", zonecfg_strerror(res),
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  4013
			    pool_err);
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  4014
		else
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  4015
			zerror(zlogp, B_FALSE, "could not bind zone to "
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  4016
			    "temporary pool: %s", zonecfg_strerror(res));
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  4017
		zonecfg_fini_handle(handle);
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  4018
		return (Z_POOL_BIND);
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  4019
	}
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  4020
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  4021
	/*
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  4022
	 * Check if we need to warn about poold not being enabled.
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  4023
	 */
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  4024
	if (zonecfg_warn_poold(handle)) {
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  4025
		zerror(zlogp, B_FALSE, "WARNING: A range of dedicated-cpus has "
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  4026
		    "been specified\nbut the dynamic pool service is not "
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  4027
		    "enabled.\nThe system will not dynamically adjust the\n"
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  4028
		    "processor allocation within the specified range\n"
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  4029
		    "until svc:/system/pools/dynamic is enabled.\n"
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  4030
		    "See poold(1M).");
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  4031
	}
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  4032
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  4033
	/* The following is a warning, not an error. */
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  4034
	if ((res = zonecfg_bind_pool(handle, zoneid, pool_err,
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  4035
	    sizeof (pool_err))) != Z_OK) {
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  4036
		if (res == Z_POOL_BIND)
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  4037
			zerror(zlogp, B_FALSE, "WARNING: unable to bind to "
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  4038
			    "pool '%s'; using default pool.", pool_err);
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  4039
		else if (res == Z_POOL)
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  4040
			zerror(zlogp, B_FALSE, "WARNING: %s: %s",
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  4041
			    zonecfg_strerror(res), pool_err);
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  4042
		else
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  4043
			zerror(zlogp, B_FALSE, "WARNING: %s",
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  4044
			    zonecfg_strerror(res));
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  4045
	}
11878
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  4046
	(void) zonecfg_get_poolname(handle, zone_name, pool_name, MAXPATHLEN);
3247
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  4047
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  4048
	zonecfg_fini_handle(handle);
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  4049
	return (Z_OK);
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  4050
}
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  4051
12633
9f2cda0ed938 PSARC 2010/144 lofi(7D) in non global zones
John Levon <john.levon@sun.com>
parents: 11878
diff changeset
  4052
static void
9f2cda0ed938 PSARC 2010/144 lofi(7D) in non global zones
John Levon <john.levon@sun.com>
parents: 11878
diff changeset
  4053
report_prop_err(zlog_t *zlogp, const char *name, const char *value, int res)
9f2cda0ed938 PSARC 2010/144 lofi(7D) in non global zones
John Levon <john.levon@sun.com>
parents: 11878
diff changeset
  4054
{
9f2cda0ed938 PSARC 2010/144 lofi(7D) in non global zones
John Levon <john.levon@sun.com>
parents: 11878
diff changeset
  4055
	switch (res) {
9f2cda0ed938 PSARC 2010/144 lofi(7D) in non global zones
John Levon <john.levon@sun.com>
parents: 11878
diff changeset
  4056
	case Z_TOO_BIG:
9f2cda0ed938 PSARC 2010/144 lofi(7D) in non global zones
John Levon <john.levon@sun.com>
parents: 11878
diff changeset
  4057
		zerror(zlogp, B_FALSE, "%s property value is too large.", name);
9f2cda0ed938 PSARC 2010/144 lofi(7D) in non global zones
John Levon <john.levon@sun.com>
parents: 11878
diff changeset
  4058
		break;
9f2cda0ed938 PSARC 2010/144 lofi(7D) in non global zones
John Levon <john.levon@sun.com>
parents: 11878
diff changeset
  4059
9f2cda0ed938 PSARC 2010/144 lofi(7D) in non global zones
John Levon <john.levon@sun.com>
parents: 11878
diff changeset
  4060
	case Z_INVALID_PROPERTY:
9f2cda0ed938 PSARC 2010/144 lofi(7D) in non global zones
John Levon <john.levon@sun.com>
parents: 11878
diff changeset
  4061
		zerror(zlogp, B_FALSE, "%s property value \"%s\" is not valid",
9f2cda0ed938 PSARC 2010/144 lofi(7D) in non global zones
John Levon <john.levon@sun.com>
parents: 11878
diff changeset
  4062
		    name, value);
9f2cda0ed938 PSARC 2010/144 lofi(7D) in non global zones
John Levon <john.levon@sun.com>
parents: 11878
diff changeset
  4063
		break;
9f2cda0ed938 PSARC 2010/144 lofi(7D) in non global zones
John Levon <john.levon@sun.com>
parents: 11878
diff changeset
  4064
9f2cda0ed938 PSARC 2010/144 lofi(7D) in non global zones
John Levon <john.levon@sun.com>
parents: 11878
diff changeset
  4065
	default:
9f2cda0ed938 PSARC 2010/144 lofi(7D) in non global zones
John Levon <john.levon@sun.com>
parents: 11878
diff changeset
  4066
		zerror(zlogp, B_TRUE, "fetching property %s: %d", name, res);
9f2cda0ed938 PSARC 2010/144 lofi(7D) in non global zones
John Levon <john.levon@sun.com>
parents: 11878
diff changeset
  4067
		break;
9f2cda0ed938 PSARC 2010/144 lofi(7D) in non global zones
John Levon <john.levon@sun.com>
parents: 11878
diff changeset
  4068
	}
9f2cda0ed938 PSARC 2010/144 lofi(7D) in non global zones
John Levon <john.levon@sun.com>
parents: 11878
diff changeset
  4069
}
9f2cda0ed938 PSARC 2010/144 lofi(7D) in non global zones
John Levon <john.levon@sun.com>
parents: 11878
diff changeset
  4070
8662
18153249ee93 PSARC/2008/647 Configurable Hostids for Non-Global Zones
jv227347 <Jordan.Vaughan@Sun.com>
parents: 8485
diff changeset
  4071
/*
18153249ee93 PSARC/2008/647 Configurable Hostids for Non-Global Zones
jv227347 <Jordan.Vaughan@Sun.com>
parents: 8485
diff changeset
  4072
 * Sets the hostid of the new zone based on its configured value.  The zone's
18153249ee93 PSARC/2008/647 Configurable Hostids for Non-Global Zones
jv227347 <Jordan.Vaughan@Sun.com>
parents: 8485
diff changeset
  4073
 * zone_t structure must already exist in kernel memory.  'zlogp' refers to the
18153249ee93 PSARC/2008/647 Configurable Hostids for Non-Global Zones
jv227347 <Jordan.Vaughan@Sun.com>
parents: 8485
diff changeset
  4074
 * log used to report errors and warnings and must be non-NULL.  'zone_namep'
18153249ee93 PSARC/2008/647 Configurable Hostids for Non-Global Zones
jv227347 <Jordan.Vaughan@Sun.com>
parents: 8485
diff changeset
  4075
 * is the name of the new zone and must be non-NULL.  'zoneid' is the numeric
18153249ee93 PSARC/2008/647 Configurable Hostids for Non-Global Zones
jv227347 <Jordan.Vaughan@Sun.com>
parents: 8485
diff changeset
  4076
 * ID of the new zone.
18153249ee93 PSARC/2008/647 Configurable Hostids for Non-Global Zones
jv227347 <Jordan.Vaughan@Sun.com>
parents: 8485
diff changeset
  4077
 *
18153249ee93 PSARC/2008/647 Configurable Hostids for Non-Global Zones
jv227347 <Jordan.Vaughan@Sun.com>
parents: 8485
diff changeset
  4078
 * This function returns zero on success and a nonzero error code on failure.
18153249ee93 PSARC/2008/647 Configurable Hostids for Non-Global Zones
jv227347 <Jordan.Vaughan@Sun.com>
parents: 8485
diff changeset
  4079
 */
18153249ee93 PSARC/2008/647 Configurable Hostids for Non-Global Zones
jv227347 <Jordan.Vaughan@Sun.com>
parents: 8485
diff changeset
  4080
static int
12633
9f2cda0ed938 PSARC 2010/144 lofi(7D) in non global zones
John Levon <john.levon@sun.com>
parents: 11878
diff changeset
  4081
setup_zone_hostid(zone_dochandle_t handle, zlog_t *zlogp, zoneid_t zoneid)
8662
18153249ee93 PSARC/2008/647 Configurable Hostids for Non-Global Zones
jv227347 <Jordan.Vaughan@Sun.com>
parents: 8485
diff changeset
  4082
{
18153249ee93 PSARC/2008/647 Configurable Hostids for Non-Global Zones
jv227347 <Jordan.Vaughan@Sun.com>
parents: 8485
diff changeset
  4083
	int res;
18153249ee93 PSARC/2008/647 Configurable Hostids for Non-Global Zones
jv227347 <Jordan.Vaughan@Sun.com>
parents: 8485
diff changeset
  4084
	char hostidp[HW_HOSTID_LEN];
18153249ee93 PSARC/2008/647 Configurable Hostids for Non-Global Zones
jv227347 <Jordan.Vaughan@Sun.com>
parents: 8485
diff changeset
  4085
	unsigned int hostid;
18153249ee93 PSARC/2008/647 Configurable Hostids for Non-Global Zones
jv227347 <Jordan.Vaughan@Sun.com>
parents: 8485
diff changeset
  4086
12633
9f2cda0ed938 PSARC 2010/144 lofi(7D) in non global zones
John Levon <john.levon@sun.com>
parents: 11878
diff changeset
  4087
	res = zonecfg_get_hostid(handle, hostidp, sizeof (hostidp));
9f2cda0ed938 PSARC 2010/144 lofi(7D) in non global zones
John Levon <john.levon@sun.com>
parents: 11878
diff changeset
  4088
9f2cda0ed938 PSARC 2010/144 lofi(7D) in non global zones
John Levon <john.levon@sun.com>
parents: 11878
diff changeset
  4089
	if (res == Z_BAD_PROPERTY) {
9f2cda0ed938 PSARC 2010/144 lofi(7D) in non global zones
John Levon <john.levon@sun.com>
parents: 11878
diff changeset
  4090
		return (Z_OK);
9f2cda0ed938 PSARC 2010/144 lofi(7D) in non global zones
John Levon <john.levon@sun.com>
parents: 11878
diff changeset
  4091
	} else if (res != Z_OK) {
9f2cda0ed938 PSARC 2010/144 lofi(7D) in non global zones
John Levon <john.levon@sun.com>
parents: 11878
diff changeset
  4092
		report_prop_err(zlogp, "hostid", hostidp, res);
9f2cda0ed938 PSARC 2010/144 lofi(7D) in non global zones
John Levon <john.levon@sun.com>
parents: 11878
diff changeset
  4093
		return (res);
9f2cda0ed938 PSARC 2010/144 lofi(7D) in non global zones
John Levon <john.levon@sun.com>
parents: 11878
diff changeset
  4094
	}
9f2cda0ed938 PSARC 2010/144 lofi(7D) in non global zones
John Levon <john.levon@sun.com>
parents: 11878
diff changeset
  4095
9f2cda0ed938 PSARC 2010/144 lofi(7D) in non global zones
John Levon <john.levon@sun.com>
parents: 11878
diff changeset
  4096
	hostid = (unsigned int)strtoul(hostidp, NULL, 16);
9f2cda0ed938 PSARC 2010/144 lofi(7D) in non global zones
John Levon <john.levon@sun.com>
parents: 11878
diff changeset
  4097
	if ((res = zone_setattr(zoneid, ZONE_ATTR_HOSTID, &hostid,
9f2cda0ed938 PSARC 2010/144 lofi(7D) in non global zones
John Levon <john.levon@sun.com>
parents: 11878
diff changeset
  4098
	    sizeof (hostid))) != 0) {
9f2cda0ed938 PSARC 2010/144 lofi(7D) in non global zones
John Levon <john.levon@sun.com>
parents: 11878
diff changeset
  4099
		zerror(zlogp, B_TRUE,
9f2cda0ed938 PSARC 2010/144 lofi(7D) in non global zones
John Levon <john.levon@sun.com>
parents: 11878
diff changeset
  4100
		    "zone hostid is not valid: %s: %d", hostidp, res);
9f2cda0ed938 PSARC 2010/144 lofi(7D) in non global zones
John Levon <john.levon@sun.com>
parents: 11878
diff changeset
  4101
		return (Z_SYSTEM);
9f2cda0ed938 PSARC 2010/144 lofi(7D) in non global zones
John Levon <john.levon@sun.com>
parents: 11878
diff changeset
  4102
	}
9f2cda0ed938 PSARC 2010/144 lofi(7D) in non global zones
John Levon <john.levon@sun.com>
parents: 11878
diff changeset
  4103
9f2cda0ed938 PSARC 2010/144 lofi(7D) in non global zones
John Levon <john.levon@sun.com>
parents: 11878
diff changeset
  4104
	return (res);
9f2cda0ed938 PSARC 2010/144 lofi(7D) in non global zones
John Levon <john.levon@sun.com>
parents: 11878
diff changeset
  4105
}
9f2cda0ed938 PSARC 2010/144 lofi(7D) in non global zones
John Levon <john.levon@sun.com>
parents: 11878
diff changeset
  4106
9f2cda0ed938 PSARC 2010/144 lofi(7D) in non global zones
John Levon <john.levon@sun.com>
parents: 11878
diff changeset
  4107
static int
9f2cda0ed938 PSARC 2010/144 lofi(7D) in non global zones
John Levon <john.levon@sun.com>
parents: 11878
diff changeset
  4108
setup_zone_fs_allowed(zone_dochandle_t handle, zlog_t *zlogp, zoneid_t zoneid)
9f2cda0ed938 PSARC 2010/144 lofi(7D) in non global zones
John Levon <john.levon@sun.com>
parents: 11878
diff changeset
  4109
{
9f2cda0ed938 PSARC 2010/144 lofi(7D) in non global zones
John Levon <john.levon@sun.com>
parents: 11878
diff changeset
  4110
	char fsallowedp[ZONE_FS_ALLOWED_MAX];
9f2cda0ed938 PSARC 2010/144 lofi(7D) in non global zones
John Levon <john.levon@sun.com>
parents: 11878
diff changeset
  4111
	int res;
9f2cda0ed938 PSARC 2010/144 lofi(7D) in non global zones
John Levon <john.levon@sun.com>
parents: 11878
diff changeset
  4112
9f2cda0ed938 PSARC 2010/144 lofi(7D) in non global zones
John Levon <john.levon@sun.com>
parents: 11878
diff changeset
  4113
	res = zonecfg_get_fs_allowed(handle, fsallowedp, sizeof (fsallowedp));
9f2cda0ed938 PSARC 2010/144 lofi(7D) in non global zones
John Levon <john.levon@sun.com>
parents: 11878
diff changeset
  4114
9f2cda0ed938 PSARC 2010/144 lofi(7D) in non global zones
John Levon <john.levon@sun.com>
parents: 11878
diff changeset
  4115
	if (res == Z_BAD_PROPERTY) {
9f2cda0ed938 PSARC 2010/144 lofi(7D) in non global zones
John Levon <john.levon@sun.com>
parents: 11878
diff changeset
  4116
		return (Z_OK);
9f2cda0ed938 PSARC 2010/144 lofi(7D) in non global zones
John Levon <john.levon@sun.com>
parents: 11878
diff changeset
  4117
	} else if (res != Z_OK) {
9f2cda0ed938 PSARC 2010/144 lofi(7D) in non global zones
John Levon <john.levon@sun.com>
parents: 11878
diff changeset
  4118
		report_prop_err(zlogp, "fs-allowed", fsallowedp, res);
9f2cda0ed938 PSARC 2010/144 lofi(7D) in non global zones
John Levon <john.levon@sun.com>
parents: 11878
diff changeset
  4119
		return (res);
9f2cda0ed938 PSARC 2010/144 lofi(7D) in non global zones
John Levon <john.levon@sun.com>
parents: 11878
diff changeset
  4120
	}
9f2cda0ed938 PSARC 2010/144 lofi(7D) in non global zones
John Levon <john.levon@sun.com>
parents: 11878
diff changeset
  4121
9f2cda0ed938 PSARC 2010/144 lofi(7D) in non global zones
John Levon <john.levon@sun.com>
parents: 11878
diff changeset
  4122
	if (zone_setattr(zoneid, ZONE_ATTR_FS_ALLOWED, &fsallowedp,
9f2cda0ed938 PSARC 2010/144 lofi(7D) in non global zones
John Levon <john.levon@sun.com>
parents: 11878
diff changeset
  4123
	    sizeof (fsallowedp)) != 0) {
9f2cda0ed938 PSARC 2010/144 lofi(7D) in non global zones
John Levon <john.levon@sun.com>
parents: 11878
diff changeset
  4124
		zerror(zlogp, B_TRUE,
9f2cda0ed938 PSARC 2010/144 lofi(7D) in non global zones
John Levon <john.levon@sun.com>
parents: 11878
diff changeset
  4125
		    "fs-allowed couldn't be set: %s: %d", fsallowedp, res);
9f2cda0ed938 PSARC 2010/144 lofi(7D) in non global zones
John Levon <john.levon@sun.com>
parents: 11878
diff changeset
  4126
		return (Z_SYSTEM);
9f2cda0ed938 PSARC 2010/144 lofi(7D) in non global zones
John Levon <john.levon@sun.com>
parents: 11878
diff changeset
  4127
	}
9f2cda0ed938 PSARC 2010/144 lofi(7D) in non global zones
John Levon <john.levon@sun.com>
parents: 11878
diff changeset
  4128
9f2cda0ed938 PSARC 2010/144 lofi(7D) in non global zones
John Levon <john.levon@sun.com>
parents: 11878
diff changeset
  4129
	return (res);
9f2cda0ed938 PSARC 2010/144 lofi(7D) in non global zones
John Levon <john.levon@sun.com>
parents: 11878
diff changeset
  4130
}
9f2cda0ed938 PSARC 2010/144 lofi(7D) in non global zones
John Levon <john.levon@sun.com>
parents: 11878
diff changeset
  4131
9f2cda0ed938 PSARC 2010/144 lofi(7D) in non global zones
John Levon <john.levon@sun.com>
parents: 11878
diff changeset
  4132
static int
9f2cda0ed938 PSARC 2010/144 lofi(7D) in non global zones
John Levon <john.levon@sun.com>
parents: 11878
diff changeset
  4133
setup_zone_attrs(zlog_t *zlogp, char *zone_namep, zoneid_t zoneid)
9f2cda0ed938 PSARC 2010/144 lofi(7D) in non global zones
John Levon <john.levon@sun.com>
parents: 11878
diff changeset
  4134
{
9f2cda0ed938 PSARC 2010/144 lofi(7D) in non global zones
John Levon <john.levon@sun.com>
parents: 11878
diff changeset
  4135
	zone_dochandle_t handle;
9f2cda0ed938 PSARC 2010/144 lofi(7D) in non global zones
John Levon <john.levon@sun.com>
parents: 11878
diff changeset
  4136
	int res = Z_OK;
9f2cda0ed938 PSARC 2010/144 lofi(7D) in non global zones
John Levon <john.levon@sun.com>
parents: 11878
diff changeset
  4137
8662
18153249ee93 PSARC/2008/647 Configurable Hostids for Non-Global Zones
jv227347 <Jordan.Vaughan@Sun.com>
parents: 8485
diff changeset
  4138
	if ((handle = zonecfg_init_handle()) == NULL) {
18153249ee93 PSARC/2008/647 Configurable Hostids for Non-Global Zones
jv227347 <Jordan.Vaughan@Sun.com>
parents: 8485
diff changeset
  4139
		zerror(zlogp, B_TRUE, "getting zone configuration handle");
18153249ee93 PSARC/2008/647 Configurable Hostids for Non-Global Zones
jv227347 <Jordan.Vaughan@Sun.com>
parents: 8485
diff changeset
  4140
		return (Z_BAD_HANDLE);
18153249ee93 PSARC/2008/647 Configurable Hostids for Non-Global Zones
jv227347 <Jordan.Vaughan@Sun.com>
parents: 8485
diff changeset
  4141
	}
18153249ee93 PSARC/2008/647 Configurable Hostids for Non-Global Zones
jv227347 <Jordan.Vaughan@Sun.com>
parents: 8485
diff changeset
  4142
	if ((res = zonecfg_get_snapshot_handle(zone_namep, handle)) != Z_OK) {
18153249ee93 PSARC/2008/647 Configurable Hostids for Non-Global Zones
jv227347 <Jordan.Vaughan@Sun.com>
parents: 8485
diff changeset
  4143
		zerror(zlogp, B_FALSE, "invalid configuration");
12633
9f2cda0ed938 PSARC 2010/144 lofi(7D) in non global zones
John Levon <john.levon@sun.com>
parents: 11878
diff changeset
  4144
		goto out;
9f2cda0ed938 PSARC 2010/144 lofi(7D) in non global zones
John Levon <john.levon@sun.com>
parents: 11878
diff changeset
  4145
	}
9f2cda0ed938 PSARC 2010/144 lofi(7D) in non global zones
John Levon <john.levon@sun.com>
parents: 11878
diff changeset
  4146
9f2cda0ed938 PSARC 2010/144 lofi(7D) in non global zones
John Levon <john.levon@sun.com>
parents: 11878
diff changeset
  4147
	if ((res = setup_zone_hostid(handle, zlogp, zoneid)) != Z_OK)
9f2cda0ed938 PSARC 2010/144 lofi(7D) in non global zones
John Levon <john.levon@sun.com>
parents: 11878
diff changeset
  4148
		goto out;
9f2cda0ed938 PSARC 2010/144 lofi(7D) in non global zones
John Levon <john.levon@sun.com>
parents: 11878
diff changeset
  4149
9f2cda0ed938 PSARC 2010/144 lofi(7D) in non global zones
John Levon <john.levon@sun.com>
parents: 11878
diff changeset
  4150
	if ((res = setup_zone_fs_allowed(handle, zlogp, zoneid)) != Z_OK)
9f2cda0ed938 PSARC 2010/144 lofi(7D) in non global zones
John Levon <john.levon@sun.com>
parents: 11878
diff changeset
  4151
		goto out;
9f2cda0ed938 PSARC 2010/144 lofi(7D) in non global zones
John Levon <john.levon@sun.com>
parents: 11878
diff changeset
  4152
9f2cda0ed938 PSARC 2010/144 lofi(7D) in non global zones
John Levon <john.levon@sun.com>
parents: 11878
diff changeset
  4153
out:
8662
18153249ee93 PSARC/2008/647 Configurable Hostids for Non-Global Zones
jv227347 <Jordan.Vaughan@Sun.com>
parents: 8485
diff changeset
  4154
	zonecfg_fini_handle(handle);
12633
9f2cda0ed938 PSARC 2010/144 lofi(7D) in non global zones
John Levon <john.levon@sun.com>
parents: 11878
diff changeset
  4155
	return (res);
8662
18153249ee93 PSARC/2008/647 Configurable Hostids for Non-Global Zones
jv227347 <Jordan.Vaughan@Sun.com>
parents: 8485
diff changeset
  4156
}
18153249ee93 PSARC/2008/647 Configurable Hostids for Non-Global Zones
jv227347 <Jordan.Vaughan@Sun.com>
parents: 8485
diff changeset
  4157
766
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4158
zoneid_t
5829
20241b1ccadc PSARC 2007/621 zone update on attach
gjelinek
parents: 5596
diff changeset
  4159
vplat_create(zlog_t *zlogp, zone_mnt_t mount_cmd)
766
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4160
{
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4161
	zoneid_t rval = -1;
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  4162
	priv_set_t *privs;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  4163
	char rootpath[MAXPATHLEN];
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  4164
	char *rctlbuf = NULL;
766
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4165
	size_t rctlbufsz = 0;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  4166
	char *zfsbuf = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  4167
	size_t zfsbufsz = 0;
766
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4168
	zoneid_t zoneid = -1;
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  4169
	int xerr;
766
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4170
	char *kzone;
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4171
	FILE *fp = NULL;
1676
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  4172
	tsol_zcent_t *zcent = NULL;
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  4173
	int match = 0;
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  4174
	int doi = 0;
3448
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  4175
	int flags;
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  4176
	zone_iptype_t iptype;
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  4177
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  4178
	if (zone_get_rootpath(zone_name, rootpath, sizeof (rootpath)) != Z_OK) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  4179
		zerror(zlogp, B_TRUE, "unable to determine zone root");
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  4180
		return (-1);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  4181
	}
766
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4182
	if (zonecfg_in_alt_root())
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4183
		resolve_lofs(zlogp, rootpath, sizeof (rootpath));
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  4184
10616
3be00c4a6835 PSARC 2009/373 Clearview IP Tunneling
Sebastien Roy <Sebastien.Roy@Sun.COM>
parents: 10067
diff changeset
  4185
	if (vplat_get_iptype(zlogp, &iptype) < 0) {
3448
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  4186
		zerror(zlogp, B_TRUE, "unable to determine ip-type");
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  4187
		return (-1);
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  4188
	}
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  4189
	switch (iptype) {
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  4190
	case ZS_SHARED:
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  4191
		flags = 0;
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  4192
		break;
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  4193
	case ZS_EXCLUSIVE:
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  4194
		flags = ZCF_NET_EXCL;
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  4195
		break;
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  4196
	}
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  4197
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  4198
	if ((privs = priv_allocset()) == NULL) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  4199
		zerror(zlogp, B_TRUE, "%s failed", "priv_allocset");
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  4200
		return (-1);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  4201
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  4202
	priv_emptyset(privs);
1645
5c204cdba7d2 PSARC 2006/124 Configurable Privileges for Zones
comay
parents: 1544
diff changeset
  4203
	if (get_privset(zlogp, privs, mount_cmd) != 0)
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  4204
		goto error;
1645
5c204cdba7d2 PSARC 2006/124 Configurable Privileges for Zones
comay
parents: 1544
diff changeset
  4205
5829
20241b1ccadc PSARC 2007/621 zone update on attach
gjelinek
parents: 5596
diff changeset
  4206
	if (mount_cmd == Z_MNT_BOOT &&
20241b1ccadc PSARC 2007/621 zone update on attach
gjelinek
parents: 5596
diff changeset
  4207
	    get_rctls(zlogp, &rctlbuf, &rctlbufsz) != 0) {
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  4208
		zerror(zlogp, B_FALSE, "Unable to get list of rctls");
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  4209
		goto error;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  4210
	}
1645
5c204cdba7d2 PSARC 2006/124 Configurable Privileges for Zones
comay
parents: 1544
diff changeset
  4211
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  4212
	if (get_datasets(zlogp, &zfsbuf, &zfsbufsz) != 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  4213
		zerror(zlogp, B_FALSE, "Unable to get list of ZFS datasets");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  4214
		goto error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  4215
	}
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  4216
5829
20241b1ccadc PSARC 2007/621 zone update on attach
gjelinek
parents: 5596
diff changeset
  4217
	if (mount_cmd == Z_MNT_BOOT && is_system_labeled()) {
1676
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  4218
		zcent = get_zone_label(zlogp, privs);
1769
338500d67d4f 6404654 zoneadm mount command fails on labeled systems
carlsonj
parents: 1676
diff changeset
  4219
		if (zcent != NULL) {
1676
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  4220
			match = zcent->zc_match;
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  4221
			doi = zcent->zc_doi;
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  4222
			*zlabel = zcent->zc_label;
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  4223
		} else {
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  4224
			goto error;
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  4225
		}
10972
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  4226
		if (validate_rootds_label(zlogp, rootpath, zlabel) != 0)
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10943
diff changeset
  4227
			goto error;
1676
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  4228
	}
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  4229
766
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4230
	kzone = zone_name;
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4231
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4232
	/*
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4233
	 * We must do this scan twice.  First, we look for zones running on the
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4234
	 * main system that are using this root (or any subdirectory of it).
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4235
	 * Next, we reduce to the shortest path and search for loopback mounts
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4236
	 * that use this same source node (same device and inode).
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4237
	 */
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4238
	if (duplicate_zone_root(zlogp, rootpath))
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4239
		goto error;
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4240
	if (duplicate_reachable_path(zlogp, rootpath))
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4241
		goto error;
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4242
5829
20241b1ccadc PSARC 2007/621 zone update on attach
gjelinek
parents: 5596
diff changeset
  4243
	if (ALT_MOUNT(mount_cmd)) {
766
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4244
		root_to_lu(zlogp, rootpath, sizeof (rootpath), B_TRUE);
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4245
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4246
		/*
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4247
		 * Forge up a special root for this zone.  When a zone is
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4248
		 * mounted, we can't let the zone have its own root because the
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4249
		 * tools that will be used in this "scratch zone" need access
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4250
		 * to both the zone's resources and the running machine's
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4251
		 * executables.
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4252
		 *
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4253
		 * Note that the mkdir here also catches read-only filesystems.
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4254
		 */
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4255
		if (mkdir(rootpath, 0755) != 0 && errno != EEXIST) {
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4256
			zerror(zlogp, B_TRUE, "cannot create %s", rootpath);
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4257
			goto error;
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4258
		}
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4259
		if (domount(zlogp, "tmpfs", "", "swap", rootpath) != 0)
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4260
			goto error;
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4261
	}
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4262
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4263
	if (zonecfg_in_alt_root()) {
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4264
		/*
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4265
		 * If we are mounting up a zone in an alternate root partition,
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4266
		 * then we have some additional work to do before starting the
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4267
		 * zone.  First, resolve the root path down so that we're not
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4268
		 * fooled by duplicates.  Then forge up an internal name for
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4269
		 * the zone.
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4270
		 */
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4271
		if ((fp = zonecfg_open_scratch("", B_TRUE)) == NULL) {
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4272
			zerror(zlogp, B_TRUE, "cannot open mapfile");
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4273
			goto error;
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4274
		}
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4275
		if (zonecfg_lock_scratch(fp) != 0) {
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4276
			zerror(zlogp, B_TRUE, "cannot lock mapfile");
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4277
			goto error;
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4278
		}
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4279
		if (zonecfg_find_scratch(fp, zone_name, zonecfg_get_root(),
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4280
		    NULL, 0) == 0) {
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4281
			zerror(zlogp, B_FALSE, "scratch zone already running");
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4282
			goto error;
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4283
		}
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4284
		/* This is the preferred name */
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4285
		(void) snprintf(kernzone, sizeof (kernzone), "SUNWlu-%s",
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4286
		    zone_name);
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4287
		srandom(getpid());
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4288
		while (zonecfg_reverse_scratch(fp, kernzone, NULL, 0, NULL,
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4289
		    0) == 0) {
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4290
			/* This is just an arbitrary name; note "." usage */
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4291
			(void) snprintf(kernzone, sizeof (kernzone),
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4292
			    "SUNWlu.%08lX%08lX", random(), random());
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4293
		}
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4294
		kzone = kernzone;
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4295
	}
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4296
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  4297
	xerr = 0;
766
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4298
	if ((zoneid = zone_create(kzone, rootpath, privs, rctlbuf,
3448
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  4299
	    rctlbufsz, zfsbuf, zfsbufsz, &xerr, match, doi, zlabel,
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  4300
	    flags)) == -1) {
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  4301
		if (xerr == ZE_AREMOUNTS) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  4302
			if (zonecfg_find_mounts(rootpath, NULL, NULL) < 1) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  4303
				zerror(zlogp, B_FALSE,
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  4304
				    "An unknown file-system is mounted on "
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  4305
				    "a subdirectory of %s", rootpath);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  4306
			} else {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  4307
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  4308
				zerror(zlogp, B_FALSE,
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  4309
				    "These file-systems are mounted on "
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  4310
				    "subdirectories of %s:", rootpath);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  4311
				(void) zonecfg_find_mounts(rootpath,
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  4312
				    prtmount, zlogp);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  4313
			}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  4314
		} else if (xerr == ZE_CHROOTED) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  4315
			zerror(zlogp, B_FALSE, "%s: "
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  4316
			    "cannot create a zone from a chrooted "
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  4317
			    "environment", "zone_create");
4791
4ee10afd3f9c 6504809 Misleading zoneadm message "zone_create failed: File exists"
ton
parents: 4350
diff changeset
  4318
		} else if (xerr == ZE_LABELINUSE) {
4ee10afd3f9c 6504809 Misleading zoneadm message "zone_create failed: File exists"
ton
parents: 4350
diff changeset
  4319
			char zonename[ZONENAME_MAX];
4ee10afd3f9c 6504809 Misleading zoneadm message "zone_create failed: File exists"
ton
parents: 4350
diff changeset
  4320
			(void) getzonenamebyid(getzoneidbylabel(zlabel),
4ee10afd3f9c 6504809 Misleading zoneadm message "zone_create failed: File exists"
ton
parents: 4350
diff changeset
  4321
			    zonename, ZONENAME_MAX);
4ee10afd3f9c 6504809 Misleading zoneadm message "zone_create failed: File exists"
ton
parents: 4350
diff changeset
  4322
			zerror(zlogp, B_FALSE, "The zone label is already "
4ee10afd3f9c 6504809 Misleading zoneadm message "zone_create failed: File exists"
ton
parents: 4350
diff changeset
  4323
			    "used by the zone '%s'.", zonename);
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  4324
		} else {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  4325
			zerror(zlogp, B_TRUE, "%s failed", "zone_create");
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  4326
		}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  4327
		goto error;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  4328
	}
766
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4329
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4330
	if (zonecfg_in_alt_root() &&
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4331
	    zonecfg_add_scratch(fp, zone_name, kernzone,
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4332
	    zonecfg_get_root()) == -1) {
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4333
		zerror(zlogp, B_TRUE, "cannot add mapfile entry");
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4334
		goto error;
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4335
	}
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4336
11878
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  4337
	if ((pool_name = malloc(MAXPATHLEN)) == NULL) {
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  4338
		zerror(zlogp, B_TRUE, "memory allocation failed");
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  4339
		return (Z_NOMEM);
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  4340
	}
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  4341
	bzero(pool_name, MAXPATHLEN);
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  4342
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  4343
	/*
3247
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  4344
	 * The following actions are not performed when merely mounting a zone
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  4345
	 * for administrative use.
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  4346
	 */
5829
20241b1ccadc PSARC 2007/621 zone update on attach
gjelinek
parents: 5596
diff changeset
  4347
	if (mount_cmd == Z_MNT_BOOT) {
7655
76c161ee52b3 6746514 RFE: need ability to mount non-native branded zones
<gerald.jelinek@sun.com>
parents: 7370
diff changeset
  4348
		brand_handle_t bh;
76c161ee52b3 6746514 RFE: need ability to mount non-native branded zones
<gerald.jelinek@sun.com>
parents: 7370
diff changeset
  4349
		struct brand_attr attr;
76c161ee52b3 6746514 RFE: need ability to mount non-native branded zones
<gerald.jelinek@sun.com>
parents: 7370
diff changeset
  4350
		char modname[MAXPATHLEN];
76c161ee52b3 6746514 RFE: need ability to mount non-native branded zones
<gerald.jelinek@sun.com>
parents: 7370
diff changeset
  4351
12633
9f2cda0ed938 PSARC 2010/144 lofi(7D) in non global zones
John Levon <john.levon@sun.com>
parents: 11878
diff changeset
  4352
		if (setup_zone_attrs(zlogp, zone_name, zoneid) != Z_OK)
8662
18153249ee93 PSARC/2008/647 Configurable Hostids for Non-Global Zones
jv227347 <Jordan.Vaughan@Sun.com>
parents: 8485
diff changeset
  4353
			goto error;
18153249ee93 PSARC/2008/647 Configurable Hostids for Non-Global Zones
jv227347 <Jordan.Vaughan@Sun.com>
parents: 8485
diff changeset
  4354
10796
c03a117618e2 6874636 RFE: zoneadmd should mount cluster branded zones as native in alternate roots.
Steve Lawrence <Stephen.Lawrence@Sun.COM>
parents: 10616
diff changeset
  4355
		if ((bh = brand_open(brand_name)) == NULL) {
7655
76c161ee52b3 6746514 RFE: need ability to mount non-native branded zones
<gerald.jelinek@sun.com>
parents: 7370
diff changeset
  4356
			zerror(zlogp, B_FALSE,
76c161ee52b3 6746514 RFE: need ability to mount non-native branded zones
<gerald.jelinek@sun.com>
parents: 7370
diff changeset
  4357
			    "unable to determine brand name");
8662
18153249ee93 PSARC/2008/647 Configurable Hostids for Non-Global Zones
jv227347 <Jordan.Vaughan@Sun.com>
parents: 8485
diff changeset
  4358
			goto error;
7655
76c161ee52b3 6746514 RFE: need ability to mount non-native branded zones
<gerald.jelinek@sun.com>
parents: 7370
diff changeset
  4359
		}
76c161ee52b3 6746514 RFE: need ability to mount non-native branded zones
<gerald.jelinek@sun.com>
parents: 7370
diff changeset
  4360
8905
b9e263e6e4ce PSARC/2009/065 labeled brand zone
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 8878
diff changeset
  4361
		if (!is_system_labeled() &&
10796
c03a117618e2 6874636 RFE: zoneadmd should mount cluster branded zones as native in alternate roots.
Steve Lawrence <Stephen.Lawrence@Sun.COM>
parents: 10616
diff changeset
  4362
		    (strcmp(brand_name, LABELED_BRAND_NAME) == 0)) {
8905
b9e263e6e4ce PSARC/2009/065 labeled brand zone
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 8878
diff changeset
  4363
			brand_close(bh);
b9e263e6e4ce PSARC/2009/065 labeled brand zone
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 8878
diff changeset
  4364
			zerror(zlogp, B_FALSE,
b9e263e6e4ce PSARC/2009/065 labeled brand zone
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 8878
diff changeset
  4365
			    "cannot boot labeled zone on unlabeled system");
b9e263e6e4ce PSARC/2009/065 labeled brand zone
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 8878
diff changeset
  4366
			goto error;
b9e263e6e4ce PSARC/2009/065 labeled brand zone
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 8878
diff changeset
  4367
		}
b9e263e6e4ce PSARC/2009/065 labeled brand zone
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 8878
diff changeset
  4368
7655
76c161ee52b3 6746514 RFE: need ability to mount non-native branded zones
<gerald.jelinek@sun.com>
parents: 7370
diff changeset
  4369
		/*
76c161ee52b3 6746514 RFE: need ability to mount non-native branded zones
<gerald.jelinek@sun.com>
parents: 7370
diff changeset
  4370
		 * If this brand requires any kernel support, now is the time to
76c161ee52b3 6746514 RFE: need ability to mount non-native branded zones
<gerald.jelinek@sun.com>
parents: 7370
diff changeset
  4371
		 * get it loaded and initialized.
76c161ee52b3 6746514 RFE: need ability to mount non-native branded zones
<gerald.jelinek@sun.com>
parents: 7370
diff changeset
  4372
		 */
76c161ee52b3 6746514 RFE: need ability to mount non-native branded zones
<gerald.jelinek@sun.com>
parents: 7370
diff changeset
  4373
		if (brand_get_modname(bh, modname, MAXPATHLEN) < 0) {
76c161ee52b3 6746514 RFE: need ability to mount non-native branded zones
<gerald.jelinek@sun.com>
parents: 7370
diff changeset
  4374
			brand_close(bh);
76c161ee52b3 6746514 RFE: need ability to mount non-native branded zones
<gerald.jelinek@sun.com>
parents: 7370
diff changeset
  4375
			zerror(zlogp, B_FALSE,
76c161ee52b3 6746514 RFE: need ability to mount non-native branded zones
<gerald.jelinek@sun.com>
parents: 7370
diff changeset
  4376
			    "unable to determine brand kernel module");
8662
18153249ee93 PSARC/2008/647 Configurable Hostids for Non-Global Zones
jv227347 <Jordan.Vaughan@Sun.com>
parents: 8485
diff changeset
  4377
			goto error;
7655
76c161ee52b3 6746514 RFE: need ability to mount non-native branded zones
<gerald.jelinek@sun.com>
parents: 7370
diff changeset
  4378
		}
76c161ee52b3 6746514 RFE: need ability to mount non-native branded zones
<gerald.jelinek@sun.com>
parents: 7370
diff changeset
  4379
		brand_close(bh);
76c161ee52b3 6746514 RFE: need ability to mount non-native branded zones
<gerald.jelinek@sun.com>
parents: 7370
diff changeset
  4380
76c161ee52b3 6746514 RFE: need ability to mount non-native branded zones
<gerald.jelinek@sun.com>
parents: 7370
diff changeset
  4381
		if (strlen(modname) > 0) {
10796
c03a117618e2 6874636 RFE: zoneadmd should mount cluster branded zones as native in alternate roots.
Steve Lawrence <Stephen.Lawrence@Sun.COM>
parents: 10616
diff changeset
  4382
			(void) strlcpy(attr.ba_brandname, brand_name,
c03a117618e2 6874636 RFE: zoneadmd should mount cluster branded zones as native in alternate roots.
Steve Lawrence <Stephen.Lawrence@Sun.COM>
parents: 10616
diff changeset
  4383
			    sizeof (attr.ba_brandname));
c03a117618e2 6874636 RFE: zoneadmd should mount cluster branded zones as native in alternate roots.
Steve Lawrence <Stephen.Lawrence@Sun.COM>
parents: 10616
diff changeset
  4384
			(void) strlcpy(attr.ba_modname, modname,
c03a117618e2 6874636 RFE: zoneadmd should mount cluster branded zones as native in alternate roots.
Steve Lawrence <Stephen.Lawrence@Sun.COM>
parents: 10616
diff changeset
  4385
			    sizeof (attr.ba_modname));
7655
76c161ee52b3 6746514 RFE: need ability to mount non-native branded zones
<gerald.jelinek@sun.com>
parents: 7370
diff changeset
  4386
			if (zone_setattr(zoneid, ZONE_ATTR_BRAND, &attr,
76c161ee52b3 6746514 RFE: need ability to mount non-native branded zones
<gerald.jelinek@sun.com>
parents: 7370
diff changeset
  4387
			    sizeof (attr) != 0)) {
76c161ee52b3 6746514 RFE: need ability to mount non-native branded zones
<gerald.jelinek@sun.com>
parents: 7370
diff changeset
  4388
				zerror(zlogp, B_TRUE,
76c161ee52b3 6746514 RFE: need ability to mount non-native branded zones
<gerald.jelinek@sun.com>
parents: 7370
diff changeset
  4389
				    "could not set zone brand attribute.");
76c161ee52b3 6746514 RFE: need ability to mount non-native branded zones
<gerald.jelinek@sun.com>
parents: 7370
diff changeset
  4390
				goto error;
76c161ee52b3 6746514 RFE: need ability to mount non-native branded zones
<gerald.jelinek@sun.com>
parents: 7370
diff changeset
  4391
			}
76c161ee52b3 6746514 RFE: need ability to mount non-native branded zones
<gerald.jelinek@sun.com>
parents: 7370
diff changeset
  4392
		}
76c161ee52b3 6746514 RFE: need ability to mount non-native branded zones
<gerald.jelinek@sun.com>
parents: 7370
diff changeset
  4393
8662
18153249ee93 PSARC/2008/647 Configurable Hostids for Non-Global Zones
jv227347 <Jordan.Vaughan@Sun.com>
parents: 8485
diff changeset
  4394
		if (setup_zone_rm(zlogp, zone_name, zoneid) != Z_OK)
3247
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  4395
			goto error;
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  4396
1769
338500d67d4f 6404654 zoneadm mount command fails on labeled systems
carlsonj
parents: 1676
diff changeset
  4397
		set_mlps(zlogp, zoneid, zcent);
3247
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  4398
	}
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  4399
766
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4400
	rval = zoneid;
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4401
	zoneid = -1;
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4402
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  4403
error:
8662
18153249ee93 PSARC/2008/647 Configurable Hostids for Non-Global Zones
jv227347 <Jordan.Vaughan@Sun.com>
parents: 8485
diff changeset
  4404
	if (zoneid != -1) {
18153249ee93 PSARC/2008/647 Configurable Hostids for Non-Global Zones
jv227347 <Jordan.Vaughan@Sun.com>
parents: 8485
diff changeset
  4405
		(void) zone_shutdown(zoneid);
766
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4406
		(void) zone_destroy(zoneid);
8662
18153249ee93 PSARC/2008/647 Configurable Hostids for Non-Global Zones
jv227347 <Jordan.Vaughan@Sun.com>
parents: 8485
diff changeset
  4407
	}
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  4408
	if (rctlbuf != NULL)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  4409
		free(rctlbuf);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  4410
	priv_freeset(privs);
766
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4411
	if (fp != NULL)
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4412
		zonecfg_close_scratch(fp);
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4413
	lofs_discard_mnttab();
1676
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  4414
	if (zcent != NULL)
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  4415
		tsol_freezcent(zcent);
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  4416
	return (rval);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  4417
}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  4418
2303
327ca1e2fdf0 PSARC 2006/387 Zones Features For Zulu
carlsonj
parents: 2267
diff changeset
  4419
/*
327ca1e2fdf0 PSARC 2006/387 Zones Features For Zulu
carlsonj
parents: 2267
diff changeset
  4420
 * Enter the zone and write a /etc/zones/index file there.  This allows
327ca1e2fdf0 PSARC 2006/387 Zones Features For Zulu
carlsonj
parents: 2267
diff changeset
  4421
 * libzonecfg (and thus zoneadm) to report the UUID and potentially other zone
327ca1e2fdf0 PSARC 2006/387 Zones Features For Zulu
carlsonj
parents: 2267
diff changeset
  4422
 * details from inside the zone.
327ca1e2fdf0 PSARC 2006/387 Zones Features For Zulu
carlsonj
parents: 2267
diff changeset
  4423
 */
327ca1e2fdf0 PSARC 2006/387 Zones Features For Zulu
carlsonj
parents: 2267
diff changeset
  4424
static void
327ca1e2fdf0 PSARC 2006/387 Zones Features For Zulu
carlsonj
parents: 2267
diff changeset
  4425
write_index_file(zoneid_t zoneid)
327ca1e2fdf0 PSARC 2006/387 Zones Features For Zulu
carlsonj
parents: 2267
diff changeset
  4426
{
327ca1e2fdf0 PSARC 2006/387 Zones Features For Zulu
carlsonj
parents: 2267
diff changeset
  4427
	FILE *zef;
327ca1e2fdf0 PSARC 2006/387 Zones Features For Zulu
carlsonj
parents: 2267
diff changeset
  4428
	FILE *zet;
327ca1e2fdf0 PSARC 2006/387 Zones Features For Zulu
carlsonj
parents: 2267
diff changeset
  4429
	struct zoneent *zep;
327ca1e2fdf0 PSARC 2006/387 Zones Features For Zulu
carlsonj
parents: 2267
diff changeset
  4430
	pid_t child;
327ca1e2fdf0 PSARC 2006/387 Zones Features For Zulu
carlsonj
parents: 2267
diff changeset
  4431
	int tmpl_fd;
327ca1e2fdf0 PSARC 2006/387 Zones Features For Zulu
carlsonj
parents: 2267
diff changeset
  4432
	ctid_t ct;
327ca1e2fdf0 PSARC 2006/387 Zones Features For Zulu
carlsonj
parents: 2267
diff changeset
  4433
	int fd;
327ca1e2fdf0 PSARC 2006/387 Zones Features For Zulu
carlsonj
parents: 2267
diff changeset
  4434
	char uuidstr[UUID_PRINTABLE_STRING_LENGTH];
327ca1e2fdf0 PSARC 2006/387 Zones Features For Zulu
carlsonj
parents: 2267
diff changeset
  4435
327ca1e2fdf0 PSARC 2006/387 Zones Features For Zulu
carlsonj
parents: 2267
diff changeset
  4436
	/* Locate the zone entry in the global zone's index file */
327ca1e2fdf0 PSARC 2006/387 Zones Features For Zulu
carlsonj
parents: 2267
diff changeset
  4437
	if ((zef = setzoneent()) == NULL)
327ca1e2fdf0 PSARC 2006/387 Zones Features For Zulu
carlsonj
parents: 2267
diff changeset
  4438
		return;
327ca1e2fdf0 PSARC 2006/387 Zones Features For Zulu
carlsonj
parents: 2267
diff changeset
  4439
	while ((zep = getzoneent_private(zef)) != NULL) {
327ca1e2fdf0 PSARC 2006/387 Zones Features For Zulu
carlsonj
parents: 2267
diff changeset
  4440
		if (strcmp(zep->zone_name, zone_name) == 0)
327ca1e2fdf0 PSARC 2006/387 Zones Features For Zulu
carlsonj
parents: 2267
diff changeset
  4441
			break;
327ca1e2fdf0 PSARC 2006/387 Zones Features For Zulu
carlsonj
parents: 2267
diff changeset
  4442
		free(zep);
327ca1e2fdf0 PSARC 2006/387 Zones Features For Zulu
carlsonj
parents: 2267
diff changeset
  4443
	}
327ca1e2fdf0 PSARC 2006/387 Zones Features For Zulu
carlsonj
parents: 2267
diff changeset
  4444
	endzoneent(zef);
327ca1e2fdf0 PSARC 2006/387 Zones Features For Zulu
carlsonj
parents: 2267
diff changeset
  4445
	if (zep == NULL)
327ca1e2fdf0 PSARC 2006/387 Zones Features For Zulu
carlsonj
parents: 2267
diff changeset
  4446
		return;
327ca1e2fdf0 PSARC 2006/387 Zones Features For Zulu
carlsonj
parents: 2267
diff changeset
  4447
327ca1e2fdf0 PSARC 2006/387 Zones Features For Zulu
carlsonj
parents: 2267
diff changeset
  4448
	if ((tmpl_fd = init_template()) == -1) {
327ca1e2fdf0 PSARC 2006/387 Zones Features For Zulu
carlsonj
parents: 2267
diff changeset
  4449
		free(zep);
327ca1e2fdf0 PSARC 2006/387 Zones Features For Zulu
carlsonj
parents: 2267
diff changeset
  4450
		return;
327ca1e2fdf0 PSARC 2006/387 Zones Features For Zulu
carlsonj
parents: 2267
diff changeset
  4451
	}
327ca1e2fdf0 PSARC 2006/387 Zones Features For Zulu
carlsonj
parents: 2267
diff changeset
  4452
327ca1e2fdf0 PSARC 2006/387 Zones Features For Zulu
carlsonj
parents: 2267
diff changeset
  4453
	if ((child = fork()) == -1) {
327ca1e2fdf0 PSARC 2006/387 Zones Features For Zulu
carlsonj
parents: 2267
diff changeset
  4454
		(void) ct_tmpl_clear(tmpl_fd);
327ca1e2fdf0 PSARC 2006/387 Zones Features For Zulu
carlsonj
parents: 2267
diff changeset
  4455
		(void) close(tmpl_fd);
327ca1e2fdf0 PSARC 2006/387 Zones Features For Zulu
carlsonj
parents: 2267
diff changeset
  4456
		free(zep);
327ca1e2fdf0 PSARC 2006/387 Zones Features For Zulu
carlsonj
parents: 2267
diff changeset
  4457
		return;
327ca1e2fdf0 PSARC 2006/387 Zones Features For Zulu
carlsonj
parents: 2267
diff changeset
  4458
	}
327ca1e2fdf0 PSARC 2006/387 Zones Features For Zulu
carlsonj
parents: 2267
diff changeset
  4459
327ca1e2fdf0 PSARC 2006/387 Zones Features For Zulu
carlsonj
parents: 2267
diff changeset
  4460
	/* parent waits for child to finish */
327ca1e2fdf0 PSARC 2006/387 Zones Features For Zulu
carlsonj
parents: 2267
diff changeset
  4461
	if (child != 0) {
327ca1e2fdf0 PSARC 2006/387 Zones Features For Zulu
carlsonj
parents: 2267
diff changeset
  4462
		free(zep);
327ca1e2fdf0 PSARC 2006/387 Zones Features For Zulu
carlsonj
parents: 2267
diff changeset
  4463
		if (contract_latest(&ct) == -1)
327ca1e2fdf0 PSARC 2006/387 Zones Features For Zulu
carlsonj
parents: 2267
diff changeset
  4464
			ct = -1;
327ca1e2fdf0 PSARC 2006/387 Zones Features For Zulu
carlsonj
parents: 2267
diff changeset
  4465
		(void) ct_tmpl_clear(tmpl_fd);
327ca1e2fdf0 PSARC 2006/387 Zones Features For Zulu
carlsonj
parents: 2267
diff changeset
  4466
		(void) close(tmpl_fd);
327ca1e2fdf0 PSARC 2006/387 Zones Features For Zulu
carlsonj
parents: 2267
diff changeset
  4467
		(void) waitpid(child, NULL, 0);
327ca1e2fdf0 PSARC 2006/387 Zones Features For Zulu
carlsonj
parents: 2267
diff changeset
  4468
		(void) contract_abandon_id(ct);
327ca1e2fdf0 PSARC 2006/387 Zones Features For Zulu
carlsonj
parents: 2267
diff changeset
  4469
		return;
327ca1e2fdf0 PSARC 2006/387 Zones Features For Zulu
carlsonj
parents: 2267
diff changeset
  4470
	}
327ca1e2fdf0 PSARC 2006/387 Zones Features For Zulu
carlsonj
parents: 2267
diff changeset
  4471
327ca1e2fdf0 PSARC 2006/387 Zones Features For Zulu
carlsonj
parents: 2267
diff changeset
  4472
	/* child enters zone and sets up index file */
327ca1e2fdf0 PSARC 2006/387 Zones Features For Zulu
carlsonj
parents: 2267
diff changeset
  4473
	(void) ct_tmpl_clear(tmpl_fd);
327ca1e2fdf0 PSARC 2006/387 Zones Features For Zulu
carlsonj
parents: 2267
diff changeset
  4474
	if (zone_enter(zoneid) != -1) {
327ca1e2fdf0 PSARC 2006/387 Zones Features For Zulu
carlsonj
parents: 2267
diff changeset
  4475
		(void) mkdir(ZONE_CONFIG_ROOT, ZONE_CONFIG_MODE);
327ca1e2fdf0 PSARC 2006/387 Zones Features For Zulu
carlsonj
parents: 2267
diff changeset
  4476
		(void) chown(ZONE_CONFIG_ROOT, ZONE_CONFIG_UID,
327ca1e2fdf0 PSARC 2006/387 Zones Features For Zulu
carlsonj
parents: 2267
diff changeset
  4477
		    ZONE_CONFIG_GID);
327ca1e2fdf0 PSARC 2006/387 Zones Features For Zulu
carlsonj
parents: 2267
diff changeset
  4478
		fd = open(ZONE_INDEX_FILE, O_WRONLY|O_CREAT|O_TRUNC,
327ca1e2fdf0 PSARC 2006/387 Zones Features For Zulu
carlsonj
parents: 2267
diff changeset
  4479
		    ZONE_INDEX_MODE);
327ca1e2fdf0 PSARC 2006/387 Zones Features For Zulu
carlsonj
parents: 2267
diff changeset
  4480
		if (fd != -1 && (zet = fdopen(fd, "w")) != NULL) {
327ca1e2fdf0 PSARC 2006/387 Zones Features For Zulu
carlsonj
parents: 2267
diff changeset
  4481
			(void) fchown(fd, ZONE_INDEX_UID, ZONE_INDEX_GID);
327ca1e2fdf0 PSARC 2006/387 Zones Features For Zulu
carlsonj
parents: 2267
diff changeset
  4482
			if (uuid_is_null(zep->zone_uuid))
327ca1e2fdf0 PSARC 2006/387 Zones Features For Zulu
carlsonj
parents: 2267
diff changeset
  4483
				uuidstr[0] = '\0';
327ca1e2fdf0 PSARC 2006/387 Zones Features For Zulu
carlsonj
parents: 2267
diff changeset
  4484
			else
327ca1e2fdf0 PSARC 2006/387 Zones Features For Zulu
carlsonj
parents: 2267
diff changeset
  4485
				uuid_unparse(zep->zone_uuid, uuidstr);
327ca1e2fdf0 PSARC 2006/387 Zones Features For Zulu
carlsonj
parents: 2267
diff changeset
  4486
			(void) fprintf(zet, "%s:%s:/:%s\n", zep->zone_name,
327ca1e2fdf0 PSARC 2006/387 Zones Features For Zulu
carlsonj
parents: 2267
diff changeset
  4487
			    zone_state_str(zep->zone_state),
327ca1e2fdf0 PSARC 2006/387 Zones Features For Zulu
carlsonj
parents: 2267
diff changeset
  4488
			    uuidstr);
327ca1e2fdf0 PSARC 2006/387 Zones Features For Zulu
carlsonj
parents: 2267
diff changeset
  4489
			(void) fclose(zet);
327ca1e2fdf0 PSARC 2006/387 Zones Features For Zulu
carlsonj
parents: 2267
diff changeset
  4490
		}
327ca1e2fdf0 PSARC 2006/387 Zones Features For Zulu
carlsonj
parents: 2267
diff changeset
  4491
	}
327ca1e2fdf0 PSARC 2006/387 Zones Features For Zulu
carlsonj
parents: 2267
diff changeset
  4492
	_exit(0);
327ca1e2fdf0 PSARC 2006/387 Zones Features For Zulu
carlsonj
parents: 2267
diff changeset
  4493
}
327ca1e2fdf0 PSARC 2006/387 Zones Features For Zulu
carlsonj
parents: 2267
diff changeset
  4494
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  4495
int
5829
20241b1ccadc PSARC 2007/621 zone update on attach
gjelinek
parents: 5596
diff changeset
  4496
vplat_bringup(zlog_t *zlogp, zone_mnt_t mount_cmd, zoneid_t zoneid)
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  4497
{
2712
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  4498
	char zonepath[MAXPATHLEN];
2503
163d5b06a026 4963368 zonecfg remove device plus zone reboot does not remove devices
dp
parents: 2303
diff changeset
  4499
5829
20241b1ccadc PSARC 2007/621 zone update on attach
gjelinek
parents: 5596
diff changeset
  4500
	if (mount_cmd == Z_MNT_BOOT && validate_datasets(zlogp) != 0) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  4501
		lofs_discard_mnttab();
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  4502
		return (-1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  4503
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents: 766
diff changeset
  4504
2712
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  4505
	/*
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  4506
	 * Before we try to mount filesystems we need to create the
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  4507
	 * attribute backing store for /dev
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  4508
	 */
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  4509
	if (zone_get_zonepath(zone_name, zonepath, sizeof (zonepath)) != Z_OK) {
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  4510
		lofs_discard_mnttab();
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  4511
		return (-1);
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  4512
	}
3071
7fdd962e12e3 6479675 lucreate fails when making new boot environment bootable
vp157776
parents: 2772
diff changeset
  4513
	resolve_lofs(zlogp, zonepath, sizeof (zonepath));
3813
c7c433a53b1a 6213465 non-global zone's /dev directory has wrong group owner
dp
parents: 3716
diff changeset
  4514
c7c433a53b1a 6213465 non-global zone's /dev directory has wrong group owner
dp
parents: 3716
diff changeset
  4515
	/* Make /dev directory owned by root, grouped sys */
c7c433a53b1a 6213465 non-global zone's /dev directory has wrong group owner
dp
parents: 3716
diff changeset
  4516
	if (make_one_dir(zlogp, zonepath, "/dev", DEFAULT_DIR_MODE,
c7c433a53b1a 6213465 non-global zone's /dev directory has wrong group owner
dp
parents: 3716
diff changeset
  4517
	    0, 3) != 0) {
2712
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  4518
		lofs_discard_mnttab();
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  4519
		return (-1);
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  4520
	}
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  4521
2621
4ea88858d952 PSARC/2003/246 Filesystem Driven Device Naming
llai1
parents: 2611
diff changeset
  4522
	if (mount_filesystems(zlogp, mount_cmd) != 0) {
766
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4523
		lofs_discard_mnttab();
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  4524
		return (-1);
766
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4525
	}
2621
4ea88858d952 PSARC/2003/246 Filesystem Driven Device Naming
llai1
parents: 2611
diff changeset
  4526
5829
20241b1ccadc PSARC 2007/621 zone update on attach
gjelinek
parents: 5596
diff changeset
  4527
	if (mount_cmd == Z_MNT_BOOT) {
3448
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  4528
		zone_iptype_t iptype;
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  4529
10616
3be00c4a6835 PSARC 2009/373 Clearview IP Tunneling
Sebastien Roy <Sebastien.Roy@Sun.COM>
parents: 10067
diff changeset
  4530
		if (vplat_get_iptype(zlogp, &iptype) < 0) {
3448
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  4531
			zerror(zlogp, B_TRUE, "unable to determine ip-type");
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  4532
			lofs_discard_mnttab();
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  4533
			return (-1);
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  4534
		}
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  4535
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  4536
		switch (iptype) {
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  4537
		case ZS_SHARED:
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  4538
			/* Always do this to make lo0 get configured */
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  4539
			if (configure_shared_network_interfaces(zlogp) != 0) {
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  4540
				lofs_discard_mnttab();
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  4541
				return (-1);
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  4542
			}
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  4543
			break;
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  4544
		case ZS_EXCLUSIVE:
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  4545
			if (configure_exclusive_network_interfaces(zlogp) !=
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  4546
			    0) {
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  4547
				lofs_discard_mnttab();
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  4548
				return (-1);
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  4549
			}
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  4550
			break;
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  4551
		}
766
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4552
	}
2303
327ca1e2fdf0 PSARC 2006/387 Zones Features For Zulu
carlsonj
parents: 2267
diff changeset
  4553
327ca1e2fdf0 PSARC 2006/387 Zones Features For Zulu
carlsonj
parents: 2267
diff changeset
  4554
	write_index_file(zoneid);
327ca1e2fdf0 PSARC 2006/387 Zones Features For Zulu
carlsonj
parents: 2267
diff changeset
  4555
766
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4556
	lofs_discard_mnttab();
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  4557
	return (0);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  4558
}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  4559
766
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4560
static int
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4561
lu_root_teardown(zlog_t *zlogp)
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4562
{
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4563
	char zroot[MAXPATHLEN];
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4564
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4565
	if (zone_get_rootpath(zone_name, zroot, sizeof (zroot)) != Z_OK) {
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4566
		zerror(zlogp, B_FALSE, "unable to determine zone root");
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4567
		return (-1);
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4568
	}
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4569
	root_to_lu(zlogp, zroot, sizeof (zroot), B_FALSE);
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4570
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4571
	/*
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4572
	 * At this point, the processes are gone, the filesystems (save the
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4573
	 * root) are unmounted, and the zone is on death row.  But there may
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4574
	 * still be creds floating about in the system that reference the
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4575
	 * zone_t, and which pin down zone_rootvp causing this call to fail
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4576
	 * with EBUSY.  Thus, we try for a little while before just giving up.
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4577
	 * (How I wish this were not true, and umount2 just did the right
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4578
	 * thing, or tmpfs supported MS_FORCE This is a gross hack.)
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4579
	 */
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4580
	if (umount2(zroot, MS_FORCE) != 0) {
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4581
		if (errno == ENOTSUP && umount2(zroot, 0) == 0)
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4582
			goto unmounted;
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4583
		if (errno == EBUSY) {
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4584
			int tries = 10;
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4585
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4586
			while (--tries >= 0) {
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4587
				(void) sleep(1);
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4588
				if (umount2(zroot, 0) == 0)
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4589
					goto unmounted;
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4590
				if (errno != EBUSY)
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4591
					break;
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4592
			}
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4593
		}
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4594
		zerror(zlogp, B_TRUE, "unable to unmount '%s'", zroot);
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4595
		return (-1);
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4596
	}
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4597
unmounted:
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4598
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4599
	/*
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4600
	 * Only zones in an alternate root environment have scratch zone
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4601
	 * entries.
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4602
	 */
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4603
	if (zonecfg_in_alt_root()) {
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4604
		FILE *fp;
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4605
		int retv;
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4606
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4607
		if ((fp = zonecfg_open_scratch("", B_FALSE)) == NULL) {
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4608
			zerror(zlogp, B_TRUE, "cannot open mapfile");
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4609
			return (-1);
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4610
		}
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4611
		retv = -1;
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4612
		if (zonecfg_lock_scratch(fp) != 0)
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4613
			zerror(zlogp, B_TRUE, "cannot lock mapfile");
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4614
		else if (zonecfg_delete_scratch(fp, kernzone) != 0)
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4615
			zerror(zlogp, B_TRUE, "cannot delete map entry");
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4616
		else
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4617
			retv = 0;
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4618
		zonecfg_close_scratch(fp);
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4619
		return (retv);
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4620
	} else {
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4621
		return (0);
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4622
	}
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4623
}
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4624
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  4625
int
3247
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  4626
vplat_teardown(zlog_t *zlogp, boolean_t unmount_cmd, boolean_t rebooting)
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  4627
{
766
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4628
	char *kzone;
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  4629
	zoneid_t zoneid;
3247
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  4630
	int res;
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  4631
	char pool_err[128];
7089
0461a2d76570 6553514 native zone svr4 pkg code should be moved into zone callbacks
gjelinek
parents: 6734
diff changeset
  4632
	char zpath[MAXPATHLEN];
2712
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  4633
	char cmdbuf[MAXPATHLEN];
2727
fa06bd58f0f9 6469453 invalid assert in ioctl.c:ldlinux_check()
edp
parents: 2712
diff changeset
  4634
	brand_handle_t bh = NULL;
10616
3be00c4a6835 PSARC 2009/373 Clearview IP Tunneling
Sebastien Roy <Sebastien.Roy@Sun.COM>
parents: 10067
diff changeset
  4635
	dladm_status_t status;
3be00c4a6835 PSARC 2009/373 Clearview IP Tunneling
Sebastien Roy <Sebastien.Roy@Sun.COM>
parents: 10067
diff changeset
  4636
	char errmsg[DLADM_STRSIZE];
3448
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  4637
	ushort_t flags;
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  4638
766
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4639
	kzone = zone_name;
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4640
	if (zonecfg_in_alt_root()) {
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4641
		FILE *fp;
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4642
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4643
		if ((fp = zonecfg_open_scratch("", B_FALSE)) == NULL) {
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4644
			zerror(zlogp, B_TRUE, "unable to open map file");
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4645
			goto error;
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4646
		}
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4647
		if (zonecfg_find_scratch(fp, zone_name, zonecfg_get_root(),
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4648
		    kernzone, sizeof (kernzone)) != 0) {
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4649
			zerror(zlogp, B_FALSE, "unable to find scratch zone");
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4650
			zonecfg_close_scratch(fp);
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4651
			goto error;
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4652
		}
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4653
		zonecfg_close_scratch(fp);
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4654
		kzone = kernzone;
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4655
	}
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4656
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4657
	if ((zoneid = getzoneidbyname(kzone)) == ZONE_ID_UNDEFINED) {
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  4658
		if (!bringup_failure_recovery)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  4659
			zerror(zlogp, B_TRUE, "unable to get zoneid");
766
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4660
		if (unmount_cmd)
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4661
			(void) lu_root_teardown(zlogp);
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  4662
		goto error;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  4663
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  4664
11878
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  4665
	if (remove_datalink_pool(zlogp, zoneid) != 0) {
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  4666
		zerror(zlogp, B_FALSE, "unable clear datalink pool property");
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  4667
		goto error;
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  4668
	}
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  4669
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  4670
	if (zone_shutdown(zoneid) != 0) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  4671
		zerror(zlogp, B_TRUE, "unable to shutdown zone");
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  4672
		goto error;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  4673
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  4674
7089
0461a2d76570 6553514 native zone svr4 pkg code should be moved into zone callbacks
gjelinek
parents: 6734
diff changeset
  4675
	/* Get the zonepath of this zone */
0461a2d76570 6553514 native zone svr4 pkg code should be moved into zone callbacks
gjelinek
parents: 6734
diff changeset
  4676
	if (zone_get_zonepath(zone_name, zpath, sizeof (zpath)) != Z_OK) {
0461a2d76570 6553514 native zone svr4 pkg code should be moved into zone callbacks
gjelinek
parents: 6734
diff changeset
  4677
		zerror(zlogp, B_FALSE, "unable to determine zone path");
2712
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  4678
		goto error;
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  4679
	}
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  4680
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  4681
	/* Get a handle to the brand info for this zone */
10796
c03a117618e2 6874636 RFE: zoneadmd should mount cluster branded zones as native in alternate roots.
Steve Lawrence <Stephen.Lawrence@Sun.COM>
parents: 10616
diff changeset
  4682
	if ((bh = brand_open(brand_name)) == NULL) {
2712
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  4683
		zerror(zlogp, B_FALSE, "unable to determine zone brand");
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  4684
		return (-1);
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  4685
	}
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  4686
	/*
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  4687
	 * If there is a brand 'halt' callback, execute it now to give the
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  4688
	 * brand a chance to cleanup any custom configuration.
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  4689
	 */
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  4690
	(void) strcpy(cmdbuf, EXEC_PREFIX);
7089
0461a2d76570 6553514 native zone svr4 pkg code should be moved into zone callbacks
gjelinek
parents: 6734
diff changeset
  4691
	if (brand_get_halt(bh, zone_name, zpath, cmdbuf + EXEC_LEN,
0461a2d76570 6553514 native zone svr4 pkg code should be moved into zone callbacks
gjelinek
parents: 6734
diff changeset
  4692
	    sizeof (cmdbuf) - EXEC_LEN) < 0) {
2727
fa06bd58f0f9 6469453 invalid assert in ioctl.c:ldlinux_check()
edp
parents: 2712
diff changeset
  4693
		brand_close(bh);
2712
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  4694
		zerror(zlogp, B_FALSE, "unable to determine branded zone's "
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  4695
		    "halt callback.");
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  4696
		goto error;
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  4697
	}
2727
fa06bd58f0f9 6469453 invalid assert in ioctl.c:ldlinux_check()
edp
parents: 2712
diff changeset
  4698
	brand_close(bh);
2712
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  4699
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  4700
	if ((strlen(cmdbuf) > EXEC_LEN) &&
7370
e94ec740675f 6733450 RFE: need more flexible hooks for mounting and booting a zone
<Gerald Jelinek>
parents: 7342
diff changeset
  4701
	    (do_subproc(zlogp, cmdbuf, NULL) != Z_OK)) {
2712
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  4702
		zerror(zlogp, B_FALSE, "%s failed", cmdbuf);
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  4703
		goto error;
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  4704
	}
f74a135872bc PSARC/2005/471 BrandZ: Support for non-native zones
nn35248
parents: 2676
diff changeset
  4705
3448
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  4706
	if (!unmount_cmd) {
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  4707
		zone_iptype_t iptype;
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  4708
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  4709
		if (zone_getattr(zoneid, ZONE_ATTR_FLAGS, &flags,
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  4710
		    sizeof (flags)) < 0) {
10616
3be00c4a6835 PSARC 2009/373 Clearview IP Tunneling
Sebastien Roy <Sebastien.Roy@Sun.COM>
parents: 10067
diff changeset
  4711
			if (vplat_get_iptype(zlogp, &iptype) < 0) {
3448
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  4712
				zerror(zlogp, B_TRUE, "unable to determine "
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  4713
				    "ip-type");
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  4714
				goto error;
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  4715
			}
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  4716
		} else {
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  4717
			if (flags & ZF_NET_EXCL)
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  4718
				iptype = ZS_EXCLUSIVE;
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  4719
			else
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  4720
				iptype = ZS_SHARED;
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  4721
		}
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  4722
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  4723
		switch (iptype) {
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  4724
		case ZS_SHARED:
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  4725
			if (unconfigure_shared_network_interfaces(zlogp,
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  4726
			    zoneid) != 0) {
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  4727
				zerror(zlogp, B_FALSE, "unable to unconfigure "
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  4728
				    "network interfaces in zone");
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  4729
				goto error;
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  4730
			}
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  4731
			break;
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  4732
		case ZS_EXCLUSIVE:
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  4733
			if (unconfigure_exclusive_network_interfaces(zlogp,
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  4734
			    zoneid) != 0) {
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  4735
				zerror(zlogp, B_FALSE, "unable to unconfigure "
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  4736
				    "network interfaces in zone");
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  4737
				goto error;
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  4738
			}
10616
3be00c4a6835 PSARC 2009/373 Clearview IP Tunneling
Sebastien Roy <Sebastien.Roy@Sun.COM>
parents: 10067
diff changeset
  4739
			status = dladm_zone_halt(dld_handle, zoneid);
3be00c4a6835 PSARC 2009/373 Clearview IP Tunneling
Sebastien Roy <Sebastien.Roy@Sun.COM>
parents: 10067
diff changeset
  4740
			if (status != DLADM_STATUS_OK) {
3be00c4a6835 PSARC 2009/373 Clearview IP Tunneling
Sebastien Roy <Sebastien.Roy@Sun.COM>
parents: 10067
diff changeset
  4741
				zerror(zlogp, B_FALSE, "unable to notify "
3be00c4a6835 PSARC 2009/373 Clearview IP Tunneling
Sebastien Roy <Sebastien.Roy@Sun.COM>
parents: 10067
diff changeset
  4742
				    "dlmgmtd of zone halt: %s",
3be00c4a6835 PSARC 2009/373 Clearview IP Tunneling
Sebastien Roy <Sebastien.Roy@Sun.COM>
parents: 10067
diff changeset
  4743
				    dladm_status2str(status, errmsg));
3be00c4a6835 PSARC 2009/373 Clearview IP Tunneling
Sebastien Roy <Sebastien.Roy@Sun.COM>
parents: 10067
diff changeset
  4744
			}
3448
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  4745
			break;
aaf16568054b PSARC 2006/366 IP Instances
dh155122
parents: 3356
diff changeset
  4746
		}
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  4747
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  4748
766
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4749
	if (!unmount_cmd && tcp_abort_connections(zlogp, zoneid) != 0) {
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  4750
		zerror(zlogp, B_TRUE, "unable to abort TCP connections");
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  4751
		goto error;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  4752
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  4753
766
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4754
	if (unmount_filesystems(zlogp, zoneid, unmount_cmd) != 0) {
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  4755
		zerror(zlogp, B_FALSE,
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  4756
		    "unable to unmount file systems in zone");
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  4757
		goto error;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  4758
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  4759
3247
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  4760
	/*
3356
f56db5cb3b0e 6508068 tmp pool info should not be saved after a dedicated-cpu configuration removed zone rebooting
gjelinek
parents: 3251
diff changeset
  4761
	 * If we are rebooting then we normally don't want to destroy an
f56db5cb3b0e 6508068 tmp pool info should not be saved after a dedicated-cpu configuration removed zone rebooting
gjelinek
parents: 3251
diff changeset
  4762
	 * existing temporary pool at this point so that we can just reuse it
f56db5cb3b0e 6508068 tmp pool info should not be saved after a dedicated-cpu configuration removed zone rebooting
gjelinek
parents: 3251
diff changeset
  4763
	 * when the zone boots back up.  However, it is also possible we were
f56db5cb3b0e 6508068 tmp pool info should not be saved after a dedicated-cpu configuration removed zone rebooting
gjelinek
parents: 3251
diff changeset
  4764
	 * running with a temporary pool and the zone configuration has been
f56db5cb3b0e 6508068 tmp pool info should not be saved after a dedicated-cpu configuration removed zone rebooting
gjelinek
parents: 3251
diff changeset
  4765
	 * modified to no longer use a temporary pool.  In that case we need
f56db5cb3b0e 6508068 tmp pool info should not be saved after a dedicated-cpu configuration removed zone rebooting
gjelinek
parents: 3251
diff changeset
  4766
	 * to destroy the temporary pool now.  This case looks like the case
f56db5cb3b0e 6508068 tmp pool info should not be saved after a dedicated-cpu configuration removed zone rebooting
gjelinek
parents: 3251
diff changeset
  4767
	 * where we never had a temporary pool configured but
f56db5cb3b0e 6508068 tmp pool info should not be saved after a dedicated-cpu configuration removed zone rebooting
gjelinek
parents: 3251
diff changeset
  4768
	 * zonecfg_destroy_tmp_pool will do the right thing either way.
3247
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  4769
	 */
3356
f56db5cb3b0e 6508068 tmp pool info should not be saved after a dedicated-cpu configuration removed zone rebooting
gjelinek
parents: 3251
diff changeset
  4770
	if (!unmount_cmd) {
f56db5cb3b0e 6508068 tmp pool info should not be saved after a dedicated-cpu configuration removed zone rebooting
gjelinek
parents: 3251
diff changeset
  4771
		boolean_t destroy_tmp_pool = B_TRUE;
f56db5cb3b0e 6508068 tmp pool info should not be saved after a dedicated-cpu configuration removed zone rebooting
gjelinek
parents: 3251
diff changeset
  4772
f56db5cb3b0e 6508068 tmp pool info should not be saved after a dedicated-cpu configuration removed zone rebooting
gjelinek
parents: 3251
diff changeset
  4773
		if (rebooting) {
f56db5cb3b0e 6508068 tmp pool info should not be saved after a dedicated-cpu configuration removed zone rebooting
gjelinek
parents: 3251
diff changeset
  4774
			struct zone_psettab pset_tab;
f56db5cb3b0e 6508068 tmp pool info should not be saved after a dedicated-cpu configuration removed zone rebooting
gjelinek
parents: 3251
diff changeset
  4775
			zone_dochandle_t handle;
f56db5cb3b0e 6508068 tmp pool info should not be saved after a dedicated-cpu configuration removed zone rebooting
gjelinek
parents: 3251
diff changeset
  4776
f56db5cb3b0e 6508068 tmp pool info should not be saved after a dedicated-cpu configuration removed zone rebooting
gjelinek
parents: 3251
diff changeset
  4777
			if ((handle = zonecfg_init_handle()) != NULL &&
f56db5cb3b0e 6508068 tmp pool info should not be saved after a dedicated-cpu configuration removed zone rebooting
gjelinek
parents: 3251
diff changeset
  4778
			    zonecfg_get_handle(zone_name, handle) == Z_OK &&
f56db5cb3b0e 6508068 tmp pool info should not be saved after a dedicated-cpu configuration removed zone rebooting
gjelinek
parents: 3251
diff changeset
  4779
			    zonecfg_lookup_pset(handle, &pset_tab) == Z_OK)
f56db5cb3b0e 6508068 tmp pool info should not be saved after a dedicated-cpu configuration removed zone rebooting
gjelinek
parents: 3251
diff changeset
  4780
				destroy_tmp_pool = B_FALSE;
3716
1429cb51c952 6527301 zoneadmd has sprung a few leaks
gjelinek
parents: 3688
diff changeset
  4781
1429cb51c952 6527301 zoneadmd has sprung a few leaks
gjelinek
parents: 3688
diff changeset
  4782
			zonecfg_fini_handle(handle);
3356
f56db5cb3b0e 6508068 tmp pool info should not be saved after a dedicated-cpu configuration removed zone rebooting
gjelinek
parents: 3251
diff changeset
  4783
		}
f56db5cb3b0e 6508068 tmp pool info should not be saved after a dedicated-cpu configuration removed zone rebooting
gjelinek
parents: 3251
diff changeset
  4784
f56db5cb3b0e 6508068 tmp pool info should not be saved after a dedicated-cpu configuration removed zone rebooting
gjelinek
parents: 3251
diff changeset
  4785
		if (destroy_tmp_pool) {
f56db5cb3b0e 6508068 tmp pool info should not be saved after a dedicated-cpu configuration removed zone rebooting
gjelinek
parents: 3251
diff changeset
  4786
			if ((res = zonecfg_destroy_tmp_pool(zone_name, pool_err,
f56db5cb3b0e 6508068 tmp pool info should not be saved after a dedicated-cpu configuration removed zone rebooting
gjelinek
parents: 3251
diff changeset
  4787
			    sizeof (pool_err))) != Z_OK) {
f56db5cb3b0e 6508068 tmp pool info should not be saved after a dedicated-cpu configuration removed zone rebooting
gjelinek
parents: 3251
diff changeset
  4788
				if (res == Z_POOL)
f56db5cb3b0e 6508068 tmp pool info should not be saved after a dedicated-cpu configuration removed zone rebooting
gjelinek
parents: 3251
diff changeset
  4789
					zerror(zlogp, B_FALSE, pool_err);
f56db5cb3b0e 6508068 tmp pool info should not be saved after a dedicated-cpu configuration removed zone rebooting
gjelinek
parents: 3251
diff changeset
  4790
			}
3247
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  4791
		}
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  4792
	}
e05001c14ea2 PSARC 2006/496 Improved Zones/RM Integration
gjelinek
parents: 3079
diff changeset
  4793
11878
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  4794
	free(pool_name);
ac93462db6d7 PSARC/2009/364 dlstat and flowstat
Venugopal Iyer <Venu.Iyer@Sun.COM>
parents: 11581
diff changeset
  4795
1676
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  4796
	remove_mlps(zlogp, zoneid);
37f4a3e2bd99 PSARC/2002/762 Layered Trusted Solaris
jpk
parents: 1645
diff changeset
  4797
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  4798
	if (zone_destroy(zoneid) != 0) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  4799
		zerror(zlogp, B_TRUE, "unable to destroy zone");
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  4800
		goto error;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  4801
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  4802
766
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4803
	/*
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4804
	 * Special teardown for alternate boot environments: remove the tmpfs
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4805
	 * root for the zone and then remove it from the map file.
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4806
	 */
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4807
	if (unmount_cmd && lu_root_teardown(zlogp) != 0)
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4808
		goto error;
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4809
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4810
	lofs_discard_mnttab();
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  4811
	return (0);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  4812
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  4813
error:
766
c521de78a32f PSARC 2005/474 Zones Upgrade (Ashanti and Zulu)
carlsonj
parents: 0
diff changeset
  4814
	lofs_discard_mnttab();
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  4815
	return (-1);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  4816
}