Print this page
PSARC 2008/290 lofi mount
6384817 Need persistent lofi based mounts and direct mount(1m) support for lofi

Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/zoneadmd/vplat.c
          +++ new/usr/src/cmd/zoneadmd/vplat.c
↓ open down ↓ 16 lines elided ↑ open up ↑
  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 2008 Sun Microsystems, Inc.  All rights reserved.
  24   24   * Use is subject to license terms.
  25   25   */
  26   26  
  27      -#pragma ident   "@(#)vplat.c    1.60    08/04/08 SMI"
       27 +#pragma ident   "@(#)vplat.c    1.61    08/05/07 SMI"
  28   28  
  29   29  /*
  30   30   * This module contains functions used to bring up and tear down the
  31   31   * Virtual Platform: [un]mounting file-systems, [un]plumbing network
  32   32   * interfaces, [un]configuring devices, establishing resource controls,
  33   33   * and creating/destroying the zone in the kernel.  These actions, on
  34   34   * the way up, ready the zone; on the way down, they halt the zone.
  35   35   * See the much longer block comment at the beginning of zoneadmd.c
  36   36   * for a bigger picture of how the whole program functions.
  37   37   *
↓ open down ↓ 759 lines elided ↑ open up ↑
 797  797          }
 798  798          assert(WIFEXITED(child_status));
 799  799          if (WEXITSTATUS(child_status) == ZEXIT_EXEC) {
 800  800                  zerror(zlogp, B_FALSE, "failed to exec %s", path);
 801  801                  return (-1);
 802  802          }
 803  803          return (WEXITSTATUS(child_status));
 804  804  }
 805  805  
 806  806  static int
      807 +isregfile(const char *path)
      808 +{
      809 +        struct stat64 st;
      810 +
      811 +        if (stat64(path, &st) == -1)
      812 +                return (-1);
      813 +
      814 +        return (S_ISREG(st.st_mode));
      815 +}
      816 +
      817 +static int
 807  818  dofsck(zlog_t *zlogp, const char *fstype, const char *rawdev)
 808  819  {
 809  820          char cmdbuf[MAXPATHLEN];
 810  821          char *argv[4];
 811  822          int status;
 812  823  
 813  824          /*
 814  825           * We could alternatively have called /usr/sbin/fsck -F <fstype>, but
 815  826           * that would cost us an extra fork/exec without buying us anything.
 816  827           */
 817  828          if (snprintf(cmdbuf, sizeof (cmdbuf), "/usr/lib/fs/%s/fsck", fstype)
 818  829              >= sizeof (cmdbuf)) {
 819  830                  zerror(zlogp, B_FALSE, "file-system type %s too long", fstype);
 820  831                  return (-1);
 821  832          }
 822  833  
      834 +        /*
      835 +         * If it doesn't exist, that's OK: we verified this previously.
      836 +         */
      837 +        if (isregfile(cmdbuf) == -1)
      838 +                return (0);
      839 +
 823  840          argv[0] = "fsck";
 824  841          argv[1] = "-m";
 825  842          argv[2] = (char *)rawdev;
 826  843          argv[3] = NULL;
 827  844  
 828  845          status = forkexec(zlogp, cmdbuf, argv);
 829  846          if (status == 0 || status == -1)
 830  847                  return (status);
 831  848          zerror(zlogp, B_FALSE, "fsck of '%s' failed with exit status %d; "
 832  849              "run fsck manually", rawdev, status);
↓ open down ↓ 421 lines elided ↑ open up ↑
1254 1271                           */
1255 1272                          resolve_lofs(zlogp, fsptr->zone_fs_special,
1256 1273                              sizeof (fsptr->zone_fs_special));
1257 1274                  }
1258 1275          }
1259 1276  
1260 1277          /*
1261 1278           * Run 'fsck -m' if there's a device to fsck.
1262 1279           */
1263 1280          if (fsptr->zone_fs_raw[0] != '\0' &&
1264      -            dofsck(zlogp, fsptr->zone_fs_type, fsptr->zone_fs_raw) != 0)
     1281 +            dofsck(zlogp, fsptr->zone_fs_type, fsptr->zone_fs_raw) != 0) {
1265 1282                  return (-1);
     1283 +        } else if (isregfile(fsptr->zone_fs_special) == 1 &&
     1284 +            dofsck(zlogp, fsptr->zone_fs_type, fsptr->zone_fs_special) != 0) {
     1285 +                return (-1);
     1286 +        }
1266 1287  
1267 1288          /*
1268 1289           * Build up mount option string.
1269 1290           */
1270 1291          optstr[0] = '\0';
1271 1292          if (fsptr->zone_fs_options != NULL) {
1272 1293                  (void) strlcpy(optstr, fsptr->zone_fs_options->zone_fsopt_opt,
1273 1294                      sizeof (optstr));
1274 1295                  for (optptr = fsptr->zone_fs_options->zone_fsopt_next;
1275 1296                      optptr != NULL; optptr = optptr->zone_fsopt_next) {