Print this page
patch zone-auto-create-be

Split Close
Expand all
Collapse all
          --- old/usr/src/lib/libinstzones/common/zones.c
          +++ new/usr/src/lib/libinstzones/common/zones.c
↓ open down ↓ 13 lines elided ↑ open up ↑
  14   14   * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15   15   * If applicable, add the following below this CDDL HEADER, with the
  16   16   * fields enclosed by brackets "[]" replaced with your own identifying
  17   17   * information: Portions Copyright [yyyy] [name of copyright owner]
  18   18   *
  19   19   * CDDL HEADER END
  20   20   */
  21   21  
  22   22  /*
  23   23   * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
       24 + * Copyright 2015 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
  24   25   */
  25   26  
  26   27  
  27   28  /*
  28   29   * Module:      zones.c
  29   30   * Group:       libinstzones
  30   31   * Description: Provide "zones" interface for install consolidation code
  31   32   *
  32   33   * Public Methods:
  33   34   *  z_create_zone_admin_file - Given a location to create the file, and
  34   35   *      optionally an existing administration file, generate an
  35   36   *      administration file that can be used to perform "non-interactive"
  36   37   *      operations in a non-global zone.
  37   38   *  z_free_zone_list - free contents of zoneList_t object
  38   39   *  z_get_nonglobal_zone_list - return zoneList_t object describing all
  39   40   *      non-global native zones
       41 + *  z_get_nonglobal_branded_zone_list - return zoneList_t object describing
       42 + *      all branded non-global zones
  40   43   *  z_get_nonglobal_zone_list_by_brand - return zoneList_t object describing
  41   44   *      all non-global zones matching the list of zone brands passed in.
  42   45   *  z_free_brand_list - free contents of a zoneBrandList_t object
  43   46   *  z_make_brand_list - return a zoneBrandList_t object describing the list
  44   47   *      of all zone brands passed in.
  45   48   *  z_get_zonename - return the name of the current zone
  46   49   *  z_global_only - Determine if the global zone is only zone on the spec list
  47   50   *  z_lock_this_zone - lock this zone
  48   51   *  z_lock_zones - lock specified zones
  49   52   *  z_mount_in_lz - Mount global zone directory in specified zone's root file
↓ open down ↓ 373 lines elided ↑ open up ↑
 423  426                          brand = brand->next;
 424  427                          brand->string_ptr = strdup(str);
 425  428                          brand->next = NULL;
 426  429                  }
 427  430          }
 428  431  
 429  432          free(blist);
 430  433          return (head);
 431  434  }
 432  435  
 433      -/*
 434      - * Name:        z_get_nonglobal_zone_list_by_brand
 435      - * Description: return zoneList_t object describing all non-global
 436      - *              zones matching the list of brands passed in.
 437      - * Arguments:   brands - The list of zone brands to look for.
 438      - * Returns:     zoneList_t
 439      - *                      == NULL - error, list could not be generated
 440      - *                      != NULL - success, list returned
 441      - * NOTE:        Any zoneList_t returned is placed in new storage for the
 442      - *              calling function. The caller must use 'z_free_zone_list' to
 443      - *              dispose of the storage once the list is no longer needed.
 444      - */
 445      -zoneList_t
 446      -z_get_nonglobal_zone_list_by_brand(zoneBrandList_t *brands)
      436 +static zoneList_t
      437 +i_get_nonglobal_branded_zone_list(boolean_t (*include)(struct zoneent *,
      438 +    void *), void *arg)
 447  439  {
 448  440          FILE            *zoneIndexFP;
 449  441          int             numzones = 0;
 450  442          struct zoneent  *ze;
 451  443          zoneList_t      zlst = NULL;
 452  444          FILE            *mapFP;
 453  445          char            zonename[ZONENAME_MAX];
 454  446          zone_spec_t     *zent;
 455  447  
 456  448          /* if zones are not implemented, return empty list */
↓ open down ↓ 16 lines elided ↑ open up ↑
 473  465                  zone_state_t    st;
 474  466  
 475  467                  /* skip the global zone */
 476  468  
 477  469                  if (strcmp(ze->zone_name, GLOBAL_ZONENAME) == 0) {
 478  470                          free(ze);
 479  471                          continue;
 480  472                  }
 481  473  
 482  474                  /*
 483      -                 * skip any zones with brands not on the brand list
      475 +                 * skip any zones the filter function doesn't like
 484  476                   */
 485      -                if (!z_is_zone_brand_in_list(ze->zone_name, brands)) {
      477 +                if (include != NULL && !include(ze, arg)) {
 486  478                          free(ze);
 487  479                          continue;
 488  480                  }
 489  481  
 490  482                  /*
 491  483                   * If the user specified an explicit zone list, then ignore any
 492  484                   * zones that aren't on that list.
 493  485                   */
 494  486                  if ((zent = _z_global_data._zone_spec) != NULL) {
 495  487                          while (zent != NULL) {
↓ open down ↓ 63 lines elided ↑ open up ↑
 559  551  
 560  552          if (mapFP != NULL)
 561  553                  zonecfg_close_scratch(mapFP);
 562  554  
 563  555          /* return generated list */
 564  556  
 565  557          return (zlst);
 566  558  }
 567  559  
 568  560  /*
      561 + * Name:        z_get_nonglobal_branded_zone_list
      562 + * Description: return zoneList_t object describing all non-global
      563 + * Returns:     zoneList_t
      564 + *                      == NULL - error, list could not be generated
      565 + *                      != NULL - success, list returned
      566 + * NOTE:        Any zoneList_t returned is placed in new storage for the
      567 + *              calling function. The caller must use 'z_free_zone_list' to
      568 + *              dispose of the storage once the list is no longer needed.
      569 + */
      570 +zoneList_t
      571 +z_get_nonglobal_branded_zone_list(void)
      572 +{
      573 +        return (i_get_nonglobal_branded_zone_list(NULL, NULL));
      574 +}
      575 +
      576 +static boolean_t
      577 +X(struct zoneent *ze, void *arg)
      578 +{
      579 +        zoneBrandList_t *brands = arg;
      580 +
      581 +        return (z_is_zone_brand_in_list(ze->zone_name, brands));
      582 +}
      583 +
      584 +/*
      585 + * Name:        z_get_nonglobal_zone_list_by_brand
      586 + * Description: return zoneList_t object describing all non-global
      587 + *              zones matching the list of brands passed in.
      588 + * Arguments:   brands - The list of zone brands to look for.
      589 + * Returns:     zoneList_t
      590 + *                      == NULL - error, list could not be generated
      591 + *                      != NULL - success, list returned
      592 + * NOTE:        Any zoneList_t returned is placed in new storage for the
      593 + *              calling function. The caller must use 'z_free_zone_list' to
      594 + *              dispose of the storage once the list is no longer needed.
      595 + */
      596 +zoneList_t
      597 +z_get_nonglobal_zone_list_by_brand(zoneBrandList_t *brands)
      598 +{
      599 +        return (i_get_nonglobal_branded_zone_list(X, brands));
      600 +}
      601 +
      602 +/*
 569  603   * Name:        z_get_zonename
 570  604   * Description: return the name of the current zone
 571  605   * Arguments:   void
 572  606   * Returns:     char *
 573  607   *                      - pointer to string representing the name of the current
 574  608   *                      zone
 575  609   * NOTE:        Any string returned is placed in new storage for the
 576  610   *              calling function. The caller must use 'Free' to dispose
 577  611   *              of the storage once the string is no longer needed.
 578  612   */
↓ open down ↓ 1306 lines elided ↑ open up ↑
1885 1919  
1886 1920          /* return error if the specified zone does not exist */
1887 1921  
1888 1922          if (a_zlst[i]._zlName == (char *)NULL) {
1889 1923                  return (NULL);
1890 1924          }
1891 1925  
1892 1926          /* return selected zone's zonepath */
1893 1927  
1894 1928          return (a_zlst[i]._zlPath);
     1929 +}
     1930 +
     1931 +int
     1932 +z_zlist_is_zone_auto_create_be(zoneList_t zlst, int idx, boolean_t *ret)
     1933 +{
     1934 +        char brandname[MAXNAMELEN];
     1935 +        brand_handle_t bh;
     1936 +
     1937 +        if (zone_get_brand(z_zlist_get_zonename(zlst, idx), brandname,
     1938 +            sizeof (brandname)) != Z_OK)
     1939 +                return (-1);
     1940 +
     1941 +        bh = brand_open(brandname);
     1942 +        if (bh == NULL)
     1943 +                return (-1);
     1944 +
     1945 +        *ret = brand_auto_create_be(bh);
     1946 +
     1947 +        brand_close(bh);
     1948 +
     1949 +        return (0);
1895 1950  }
1896 1951  
1897 1952  boolean_t
1898 1953  z_zlist_is_zone_runnable(zoneList_t a_zlst, int a_zoneIndex)
1899 1954  {
1900 1955          int     i;
1901 1956  
1902 1957          /* if zones are not implemented, return error */
1903 1958  
1904 1959          if (z_zones_are_implemented() == B_FALSE) {
↓ open down ↓ 428 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX