7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
24 */
25
26 /*
27 * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
28 */
29
30
31 /*
32 * System includes
33 */
34 #include <assert.h>
35 #include <errno.h>
36 #include <libgen.h>
37 #include <libintl.h>
38 #include <libnvpair.h>
39 #include <libzfs.h>
40 #include <libgen.h>
41 #include <stdio.h>
42 #include <stdlib.h>
43 #include <string.h>
44 #include <sys/stat.h>
45 #include <sys/types.h>
46 #include <sys/vfstab.h>
47 #include <sys/param.h>
48 #include <sys/systeminfo.h>
49 #include <ctype.h>
50 #include <time.h>
51 #include <unistd.h>
52 #include <fcntl.h>
53 #include <deflt.h>
54 #include <wait.h>
55 #include <libdevinfo.h>
56
57 #include <libbe.h>
58 #include <libbe_priv.h>
59
60 /* Private function prototypes */
61 static int update_dataset(char *, int, char *, char *, char *);
62 static int _update_vfstab(char *, char *, char *, char *, be_fs_list_data_t *);
63 static int be_open_menu(char *, char *, FILE **, char *, boolean_t);
64 static int be_create_menu(char *, char *, FILE **, char *);
65 static char *be_get_auto_name(char *, char *, boolean_t);
66
67 /*
68 * Global error printing
69 */
70 boolean_t do_print = B_FALSE;
71
72 /*
73 * Private datatypes
74 */
75 typedef struct zone_be_name_cb_data {
213 /*
214 * Function: be_make_root_ds
215 * Description: Generate string for BE's root dataset given the pool
216 * it lives in and the BE name.
217 * Parameters:
218 * zpool - pointer zpool name.
219 * be_name - pointer to BE name.
220 * be_root_ds - pointer to buffer to return BE root dataset in.
221 * be_root_ds_size - size of be_root_ds
222 * Returns:
223 * None
224 * Scope:
225 * Semi-private (library wide use only)
226 */
227 void
228 be_make_root_ds(const char *zpool, const char *be_name, char *be_root_ds,
229 int be_root_ds_size)
230 {
231 struct be_defaults be_defaults;
232 be_get_defaults(&be_defaults);
233
234 if (be_defaults.be_deflt_rpool_container)
235 (void) snprintf(be_root_ds, be_root_ds_size, "%s/%s", zpool,
236 be_name);
237 else
238 (void) snprintf(be_root_ds, be_root_ds_size, "%s/%s/%s", zpool,
239 BE_CONTAINER_DS_NAME, be_name);
240 }
241
242 /*
243 * Function: be_make_container_ds
244 * Description: Generate string for the BE container dataset given a pool name.
245 * Parameters:
246 * zpool - pointer zpool name.
247 * container_ds - pointer to buffer to return BE container
248 * dataset in.
249 * container_ds_size - size of container_ds
250 * Returns:
251 * None
252 * Scope:
253 * Semi-private (library wide use only)
254 */
255 void
256 be_make_container_ds(const char *zpool, char *container_ds,
257 int container_ds_size)
258 {
259 struct be_defaults be_defaults;
260 be_get_defaults(&be_defaults);
261
262 if (be_defaults.be_deflt_rpool_container)
263 (void) snprintf(container_ds, container_ds_size, "%s", zpool);
264 else
265 (void) snprintf(container_ds, container_ds_size, "%s/%s", zpool,
266 BE_CONTAINER_DS_NAME);
267 }
268
269 /*
270 * Function: be_make_name_from_ds
271 * Description: This function takes a dataset name and strips off the
272 * BE container dataset portion from the beginning. The
273 * returned name is allocated in heap storage, so the caller
274 * is responsible for freeing it.
275 * Parameters:
276 * dataset - dataset to get name from.
277 * rc_loc - dataset underwhich the root container dataset lives.
278 * Returns:
279 * name of dataset relative to BE container dataset.
280 * NULL if dataset is not under a BE root dataset.
281 * Scope:
282 * Semi-primate (library wide use only)
283 */
284 char *
285 be_make_name_from_ds(const char *dataset, char *rc_loc)
286 {
2419 * Parameters:
2420 * zlp - zpool_handle_t pointer to the current pool being
2421 * looked at.
2422 * data - be_transaction_data_t pointer.
2423 * Upon successfully finding the current BE, the
2424 * obe_zpool member of this parameter is set to the
2425 * pool it is found in.
2426 * Return:
2427 * 1 - Found current BE in this pool.
2428 * 0 - Did not find current BE in this pool.
2429 * Scope:
2430 * Semi-private (library wide use only)
2431 */
2432 int
2433 be_zpool_find_current_be_callback(zpool_handle_t *zlp, void *data)
2434 {
2435 be_transaction_data_t *bt = data;
2436 zfs_handle_t *zhp = NULL;
2437 const char *zpool = zpool_get_name(zlp);
2438 char be_container_ds[MAXPATHLEN];
2439
2440 /*
2441 * Generate string for BE container dataset
2442 */
2443 be_make_container_ds(zpool, be_container_ds, sizeof (be_container_ds));
2444
2445 /*
2446 * Check if a BE container dataset exists in this pool.
2447 */
2448 if (!zfs_dataset_exists(g_zfs, be_container_ds, ZFS_TYPE_FILESYSTEM)) {
2449 zpool_close(zlp);
2450 return (0);
2451 }
2452
2453 /*
2454 * Get handle to this zpool's BE container dataset.
2455 */
2456 if ((zhp = zfs_open(g_zfs, be_container_ds, ZFS_TYPE_FILESYSTEM)) ==
2457 NULL) {
2458 be_print_err(gettext("be_zpool_find_current_be_callback: "
2459 "failed to open BE container dataset (%s)\n"),
2460 be_container_ds);
2461 zpool_close(zlp);
2462 return (0);
2463 }
|
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
24 */
25
26 /*
27 * Copyright 2013 Nexenta Systems, Inc. All rights reserved.
28 */
29
30
31 /*
32 * System includes
33 */
34 #include <assert.h>
35 #include <errno.h>
36 #include <libgen.h>
37 #include <libintl.h>
38 #include <libnvpair.h>
39 #include <libzfs.h>
40 #include <libgen.h>
41 #include <stdio.h>
42 #include <stdlib.h>
43 #include <string.h>
44 #include <sys/stat.h>
45 #include <sys/types.h>
46 #include <sys/vfstab.h>
47 #include <sys/param.h>
48 #include <sys/systeminfo.h>
49 #include <ctype.h>
50 #include <time.h>
51 #include <unistd.h>
52 #include <fcntl.h>
53 #include <deflt.h>
54 #include <wait.h>
55 #include <libdevinfo.h>
56 #include <libgen.h>
57
58 #include <libbe.h>
59 #include <libbe_priv.h>
60
61 /* Private function prototypes */
62 static int update_dataset(char *, int, char *, char *, char *);
63 static int _update_vfstab(char *, char *, char *, char *, be_fs_list_data_t *);
64 static int be_open_menu(char *, char *, FILE **, char *, boolean_t);
65 static int be_create_menu(char *, char *, FILE **, char *);
66 static char *be_get_auto_name(char *, char *, boolean_t);
67
68 /*
69 * Global error printing
70 */
71 boolean_t do_print = B_FALSE;
72
73 /*
74 * Private datatypes
75 */
76 typedef struct zone_be_name_cb_data {
214 /*
215 * Function: be_make_root_ds
216 * Description: Generate string for BE's root dataset given the pool
217 * it lives in and the BE name.
218 * Parameters:
219 * zpool - pointer zpool name.
220 * be_name - pointer to BE name.
221 * be_root_ds - pointer to buffer to return BE root dataset in.
222 * be_root_ds_size - size of be_root_ds
223 * Returns:
224 * None
225 * Scope:
226 * Semi-private (library wide use only)
227 */
228 void
229 be_make_root_ds(const char *zpool, const char *be_name, char *be_root_ds,
230 int be_root_ds_size)
231 {
232 struct be_defaults be_defaults;
233 be_get_defaults(&be_defaults);
234 char *root_ds = NULL;
235
236 if (getzoneid() == GLOBAL_ZONEID) {
237 if (be_defaults.be_deflt_rpool_container) {
238 (void) snprintf(be_root_ds, be_root_ds_size,
239 "%s/%s", zpool, be_name);
240 } else {
241 (void) snprintf(be_root_ds, be_root_ds_size,
242 "%s/%s/%s", zpool, BE_CONTAINER_DS_NAME, be_name);
243 }
244 } else {
245 /*
246 * In non-global zone we can use path from mounted root dataset
247 * to generate BE's root dataset string.
248 */
249 if ((root_ds = be_get_ds_from_dir("/")) != NULL) {
250 (void) snprintf(be_root_ds, be_root_ds_size, "%s/%s",
251 dirname(root_ds), be_name);
252 } else {
253 be_print_err(gettext("be_make_root_ds: zone root "
254 "dataset is not mounted\n"));
255 return;
256 }
257 }
258 }
259
260 /*
261 * Function: be_make_container_ds
262 * Description: Generate string for the BE container dataset given a pool name.
263 * Parameters:
264 * zpool - pointer zpool name.
265 * container_ds - pointer to buffer to return BE container
266 * dataset in.
267 * container_ds_size - size of container_ds
268 * Returns:
269 * None
270 * Scope:
271 * Semi-private (library wide use only)
272 */
273 void
274 be_make_container_ds(const char *zpool, char *container_ds,
275 int container_ds_size)
276 {
277 struct be_defaults be_defaults;
278 be_get_defaults(&be_defaults);
279 char *root_ds = NULL;
280
281 if (getzoneid() == GLOBAL_ZONEID) {
282 if (be_defaults.be_deflt_rpool_container) {
283 (void) snprintf(container_ds, container_ds_size,
284 "%s", zpool);
285 } else {
286 (void) snprintf(container_ds, container_ds_size,
287 "%s/%s", zpool, BE_CONTAINER_DS_NAME);
288 }
289 } else {
290 if ((root_ds = be_get_ds_from_dir("/")) != NULL) {
291 (void) strlcpy(container_ds, dirname(root_ds),
292 container_ds_size);
293 } else {
294 be_print_err(gettext("be_make_container_ds: zone root "
295 "dataset is not mounted\n"));
296 return;
297 }
298 }
299 }
300
301 /*
302 * Function: be_make_name_from_ds
303 * Description: This function takes a dataset name and strips off the
304 * BE container dataset portion from the beginning. The
305 * returned name is allocated in heap storage, so the caller
306 * is responsible for freeing it.
307 * Parameters:
308 * dataset - dataset to get name from.
309 * rc_loc - dataset underwhich the root container dataset lives.
310 * Returns:
311 * name of dataset relative to BE container dataset.
312 * NULL if dataset is not under a BE root dataset.
313 * Scope:
314 * Semi-primate (library wide use only)
315 */
316 char *
317 be_make_name_from_ds(const char *dataset, char *rc_loc)
318 {
2451 * Parameters:
2452 * zlp - zpool_handle_t pointer to the current pool being
2453 * looked at.
2454 * data - be_transaction_data_t pointer.
2455 * Upon successfully finding the current BE, the
2456 * obe_zpool member of this parameter is set to the
2457 * pool it is found in.
2458 * Return:
2459 * 1 - Found current BE in this pool.
2460 * 0 - Did not find current BE in this pool.
2461 * Scope:
2462 * Semi-private (library wide use only)
2463 */
2464 int
2465 be_zpool_find_current_be_callback(zpool_handle_t *zlp, void *data)
2466 {
2467 be_transaction_data_t *bt = data;
2468 zfs_handle_t *zhp = NULL;
2469 const char *zpool = zpool_get_name(zlp);
2470 char be_container_ds[MAXPATHLEN];
2471 char *zpath = NULL;
2472
2473 /*
2474 * Generate string for BE container dataset
2475 */
2476 if (getzoneid() != GLOBAL_ZONEID) {
2477 if ((zpath = be_get_ds_from_dir("/")) != NULL) {
2478 (void) strlcpy(be_container_ds, dirname(zpath),
2479 sizeof (be_container_ds));
2480 } else {
2481 be_print_err(gettext(
2482 "be_zpool_find_current_be_callback: "
2483 "zone root dataset is not mounted\n"));
2484 return (0);
2485 }
2486 } else {
2487 be_make_container_ds(zpool, be_container_ds,
2488 sizeof (be_container_ds));
2489 }
2490
2491 /*
2492 * Check if a BE container dataset exists in this pool.
2493 */
2494 if (!zfs_dataset_exists(g_zfs, be_container_ds, ZFS_TYPE_FILESYSTEM)) {
2495 zpool_close(zlp);
2496 return (0);
2497 }
2498
2499 /*
2500 * Get handle to this zpool's BE container dataset.
2501 */
2502 if ((zhp = zfs_open(g_zfs, be_container_ds, ZFS_TYPE_FILESYSTEM)) ==
2503 NULL) {
2504 be_print_err(gettext("be_zpool_find_current_be_callback: "
2505 "failed to open BE container dataset (%s)\n"),
2506 be_container_ds);
2507 zpool_close(zlp);
2508 return (0);
2509 }
|