Print this page
9250 remove xpv related code from bootadm

Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/boot/bootadm/bootadm_loader.c
          +++ new/usr/src/cmd/boot/bootadm/bootadm_loader.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   * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
  23   23   * Copyright 2012 Milan Jurik. All rights reserved.
  24   24   */
  25   25  
  26   26  /*
  27      - * Copyright 2015 Nexenta Systems, Inc. All rights reserved.
       27 + * Copyright 2018 Nexenta Systems, Inc.
  28   28   * Copyright 2016 Toomas Soome <tsoome@me.com>
  29   29   */
  30   30  
  31   31  /*
  32   32   * Loader menu management.
  33   33   */
  34   34  
  35   35  #include <stdio.h>
  36   36  #include <stdlib.h>
  37   37  #include <string.h>
↓ open down ↓ 14 lines elided ↑ open up ↑
  52   52  
  53   53  extern int bam_rootlen;
  54   54  extern int bam_alt_root;
  55   55  extern char *rootbuf;
  56   56  extern char *bam_root;
  57   57  
  58   58  #define BOOT_DIR        "/boot"
  59   59  #define CONF_DIR        BOOT_DIR "/conf.d"
  60   60  #define MENU            BOOT_DIR "/menu.lst"
  61   61  #define TRANSIENT       BOOT_DIR "/transient.conf"
  62      -#define XEN_CONFIG      CONF_DIR "/xen"
  63   62  
  64   63  typedef struct menu_entry {
  65   64          int me_idx;
  66   65          boolean_t me_active;
  67   66          char *me_title;
  68   67          char *me_type;
  69   68          char *me_bootfs;
  70   69          STAILQ_ENTRY(menu_entry) me_next;
  71   70  } menu_entry_t;
  72   71  STAILQ_HEAD(menu_lst, menu_entry);
  73   72  
  74   73  static error_t set_option(struct menu_lst *, char *, char *);
  75   74  static error_t list_entry(struct menu_lst *, char *, char *);
  76   75  static error_t update_entry(struct menu_lst *, char *, char *);
  77   76  static error_t update_temp(struct menu_lst *, char *, char *);
  78   77  static error_t list_setting(struct menu_lst *menu, char *, char *);
  79      -static error_t disable_hyper(struct menu_lst *, char *, char *);
  80      -static error_t enable_hyper(struct menu_lst *, char *, char *);
  81   78  
  82   79  /* Menu related sub commands */
  83   80  static subcmd_defn_t menu_subcmds[] = {
  84   81          "set_option",           OPT_ABSENT,     set_option, 0,  /* PUB */
  85   82          "list_entry",           OPT_OPTIONAL,   list_entry, 1,  /* PUB */
  86   83          "update_entry",         OPT_REQ,        update_entry, 0, /* menu */
  87   84          "update_temp",          OPT_OPTIONAL,   update_temp, 0, /* reboot */
  88   85          "list_setting",         OPT_OPTIONAL,   list_setting, 1, /* menu */
  89      -        "disable_hypervisor",   OPT_ABSENT,     disable_hyper, 0, /* menu */
  90      -        "enable_hypervisor",    OPT_ABSENT,     enable_hyper, 0, /* menu */
  91   86          NULL,                   0,              NULL, 0 /* must be last */
  92   87  };
  93   88  
  94   89  #define NUM_COLS        (5)
  95   90  
  96   91  static boolean_t
  97   92  print_menu_cb(ofmt_arg_t *ofarg, char *buf, uint_t bufsize)
  98   93  {
  99   94          menu_entry_t *entry = ofarg->ofmt_cbarg;
 100   95  
↓ open down ↓ 382 lines elided ↑ open up ↑
 483  478                      menu_path);
 484  479  
 485  480          /*
 486  481           * We already checked the following case in
 487  482           * check_subcmd_and_suboptions() above. Complete the
 488  483           * final step now.
 489  484           */
 490  485          if (strcmp(subcmd, "set_option") == 0) {
 491  486                  assert(largc == 1 && largv[0] && largv[1] == NULL);
 492  487                  opt = largv[0];
 493      -        } else if ((strcmp(subcmd, "enable_hypervisor") != 0) &&
 494      -            (strcmp(subcmd, "list_setting") != 0)) {
      488 +        } else if (strcmp(subcmd, "list_setting") != 0) {
 495  489                  assert(largc == 0 && largv == NULL);
 496  490          }
 497  491  
 498  492          /*
 499  493           * Once the sub-cmd handler has run
 500  494           * only the line field is guaranteed to have valid values
 501  495           */
 502  496          if (strcmp(subcmd, "update_entry") == 0) {
 503  497                  ret = f(&menu, menu_root, osdev);
 504  498          } else if (strcmp(subcmd, "upgrade") == 0) {
 505  499                  ret = f(&menu, bam_root, menu_root);
 506  500          } else if (strcmp(subcmd, "list_entry") == 0) {
 507  501                  ret = f(&menu, menu_path, opt);
 508  502          } else if (strcmp(subcmd, "list_setting") == 0) {
 509  503                  ret = f(&menu, ((largc > 0) ? largv[0] : ""),
 510  504                      ((largc > 1) ? largv[1] : ""));
 511      -        } else if (strcmp(subcmd, "disable_hypervisor") == 0) {
 512      -                if (is_sparc()) {
 513      -                        bam_error(_("%s operation unsupported on SPARC "
 514      -                            "machines\n"), subcmd);
 515      -                        ret = BAM_ERROR;
 516      -                } else {
 517      -                        ret = f(&menu, bam_root, NULL);
 518      -                }
 519      -        } else if (strcmp(subcmd, "enable_hypervisor") == 0) {
 520      -                if (is_sparc()) {
 521      -                        bam_error(_("%s operation unsupported on SPARC "
 522      -                            "machines\n"), subcmd);
 523      -                        ret = BAM_ERROR;
 524      -                } else {
 525      -                        char *extra_args = NULL;
 526      -
 527      -                        /*
 528      -                         * Compress all arguments passed in the largv[] array
 529      -                         * into one string that can then be appended to the
 530      -                         * end of the kernel$ string the routine to enable the
 531      -                         * hypervisor will build.
 532      -                         *
 533      -                         * This allows the caller to supply arbitrary unparsed
 534      -                         * arguments, such as dom0 memory settings or APIC
 535      -                         * options.
 536      -                         *
 537      -                         * This concatenation will be done without ANY syntax
 538      -                         * checking whatsoever, so it's the responsibility of
 539      -                         * the caller to make sure the arguments are valid and
 540      -                         * do not duplicate arguments the conversion routines
 541      -                         * may create.
 542      -                         */
 543      -                        if (largc > 0) {
 544      -                                int extra_len, i;
 545      -
 546      -                                for (extra_len = 0, i = 0; i < largc; i++)
 547      -                                        extra_len += strlen(largv[i]);
 548      -
 549      -                                /*
 550      -                                 * Allocate space for argument strings,
 551      -                                 * intervening spaces and terminating NULL.
 552      -                                 */
 553      -                                extra_args = alloca(extra_len + largc);
 554      -
 555      -                                (void) strcpy(extra_args, largv[0]);
 556      -
 557      -                                for (i = 1; i < largc; i++) {
 558      -                                        (void) strcat(extra_args, " ");
 559      -                                        (void) strcat(extra_args, largv[i]);
 560      -                                }
 561      -                        }
 562      -
 563      -                        ret = f(&menu, bam_root, extra_args);
 564      -                }
 565  505          } else
 566  506                  ret = f(&menu, NULL, opt);
 567  507  
 568  508          if (ret == BAM_WRITE) {
 569  509                  BAM_DPRINTF(("%s: writing menu to clean-menu-root: <%s>\n",
 570  510                      fcn, clean_menu_root));
 571  511                  /* ret = menu_write(clean_menu_root, menu); */
 572  512          }
 573  513  
 574  514          INJECT_ERROR1("POOL_SET", pool = "/pooldata");
↓ open down ↓ 304 lines elided ↑ open up ↑
 879  819                  }
 880  820          }
 881  821  
 882  822          if (*setting == '\0')
 883  823                  (void) printf("Bootfs:      %s\n", entry->me_bootfs);
 884  824          else if (strcasecmp(setting, "bootfs") == 0) {
 885  825                  (void) printf("%s\n", entry->me_bootfs);
 886  826                  goto done;
 887  827          }
 888  828  
 889      -        ptr = getenv("xen_kernel");
      829 +        ptr = getenv("kernelname");
 890  830          if (ptr != NULL) {
 891      -                        if (*setting == '\0') {
 892      -                                (void) printf("Xen kernel:  %s\n", ptr);
 893      -                        } else if (strcasecmp(setting, "xen_kernel") == 0) {
 894      -                                (void) printf("%s\n", ptr);
 895      -                                goto done;
 896      -                        }
 897      -
 898      -                        if (*setting == '\0') {
 899      -                                (void) printf("Xen args:    \"%s\"\n",
 900      -                                    getenv("xen_cmdline"));
 901      -                        } else if (strcasecmp(setting, "xen_cmdline") == 0) {
 902      -                                (void) printf("%s\n", getenv("xen_cmdline"));
 903      -                                goto done;
 904      -                        }
 905      -
 906      -                        if (*setting == '\0') {
 907      -                                (void) printf("Kernel:      %s\n",
 908      -                                    getenv("bootfile"));
 909      -                        } if (strcasecmp(setting, "kernel") == 0) {
 910      -                                (void) printf("%s\n", getenv("bootfile"));
 911      -                                goto done;
 912      -                        }
 913      -        } else {
 914      -                ptr = getenv("kernelname");
 915      -                if (ptr != NULL) {
 916      -                        if (*setting == '\0') {
 917      -                                (void) printf("Kernel:      %s\n", ptr);
 918      -                        } else if (strcasecmp(setting, "kernel") == 0) {
 919      -                                (void) printf("%s\n", ptr);
 920      -                                goto done;
 921      -                        }
      831 +                if (*setting == '\0') {
      832 +                        (void) printf("Kernel:      %s\n", ptr);
      833 +                } else if (strcasecmp(setting, "kernel") == 0) {
      834 +                        (void) printf("%s\n", ptr);
      835 +                        goto done;
 922  836                  }
 923  837          }
 924  838  
 925  839          ptr = getenv("boot-args");
 926  840          if (ptr != NULL) {
 927  841                  if (*setting == '\0') {
 928  842                          (void) printf("Boot-args:   \"%s\"\n", ptr);
 929  843                  } else if (strcasecmp(setting, "boot-args") == 0) {
 930  844                          (void) printf("%s\n", ptr);
 931  845                          goto done;
↓ open down ↓ 122 lines elided ↑ open up ↑
1054  968  /*ARGSUSED*/
1055  969  static error_t
1056  970  update_temp(struct menu_lst *menu, char *dummy, char *opt)
1057  971  {
1058  972          error_t ret = BAM_ERROR;
1059  973          char path[PATH_MAX];
1060  974          char buf[MAX_INPUT];
1061  975          struct mnttab mpref = { 0 };
1062  976          struct mnttab mp = { 0 };
1063  977          ficlVm *vm;
1064      -        char *env, *o;
      978 +        char *o;
1065  979          FILE *fp;
1066  980  
1067  981          (void) snprintf(path, PATH_MAX, "%s" TRANSIENT, bam_root);
1068  982          /*
1069  983           * if opt == NULL, remove transient config
1070  984           */
1071  985          if (opt == NULL) {
1072  986                  (void) unlink(path);
1073  987                  return (BAM_SUCCESS);
1074  988          }
↓ open down ↓ 9 lines elided ↑ open up ↑
1084  998          }
1085  999          (void) fclose(fp);
1086 1000  
1087 1001          vm = bf_init("", ficlTextOutSilent);
1088 1002          if (vm == NULL) {
1089 1003                  bam_error(_("Error setting up forth interpreter\n"));
1090 1004                  return (ret);
1091 1005          }
1092 1006  
1093 1007          /*
1094      -         * need to check current boot config, so fire up the ficl
1095      -         * if its xen setup, we add option to boot-args list, not replacing it.
     1008 +         * Need to check current boot config, so fire up the ficl.
1096 1009           */
1097 1010          (void) snprintf(buf, MAX_INPUT, "set currdev=zfs:%s:", mp.mnt_special);
1098 1011          ret = ficlVmEvaluate(vm, buf);
1099 1012          if (ret != FICL_VM_STATUS_OUT_OF_TEXT) {
1100 1013                  bam_error(_("Error interpreting boot config\n"));
1101 1014                  bf_fini();
1102 1015                  return (BAM_ERROR);
1103 1016          }
1104 1017          (void) snprintf(buf, MAX_INPUT, "include /boot/forth/loader.4th");
1105 1018          ret = ficlVmEvaluate(vm, buf);
↓ open down ↓ 12 lines elided ↑ open up ↑
1118 1031          (void) snprintf(buf, MAX_INPUT, "boot");
1119 1032          ret = ficlVmEvaluate(vm, buf);
1120 1033          if (ret != FICL_VM_STATUS_OUT_OF_TEXT) {
1121 1034                  bam_error(_("Error interpreting boot config\n"));
1122 1035                  bf_fini();
1123 1036                  return (BAM_ERROR);
1124 1037          }
1125 1038          bf_fini();
1126 1039  
1127 1040          if (opt[0] == '-') {
1128      -                env = getenv("xen_kernel");
1129 1041                  fp = fopen(path, "w");
1130 1042                  if (fp == NULL)
1131 1043                          return (BAM_ERROR);
1132      -
1133      -                if (env != NULL) {
1134      -                        env = getenv("boot-args");
1135      -                        (void) fprintf(fp, "boot-args=\"%s %s\"\n", env, opt);
1136      -                } else
1137      -                        (void) fprintf(fp, "boot-args=\"%s\"\n", opt);
     1044 +                (void) fprintf(fp, "boot-args=\"%s\"\n", opt);
1138 1045                  (void) fclose(fp);
1139 1046                  return (BAM_SUCCESS);
1140 1047          }
1141 1048  
1142 1049          /*
1143 1050           * it should be the case with "kernel args"
1144 1051           * so, we split the opt at first space
1145 1052           * and store bootfile= and boot-args=
1146 1053           */
1147      -        env = getenv("xen_kernel");
1148      -
1149 1054          o = strchr(opt, ' ');
1150 1055          if (o == NULL) {
1151 1056                  fp = fopen(path, "w");
1152 1057                  if (fp == NULL)
1153 1058                          return (BAM_ERROR);
1154 1059                  (void) fprintf(fp, "bootfile=\"%s;unix\"\n", opt);
1155 1060                  (void) fclose(fp);
1156 1061                  return (BAM_SUCCESS);
1157 1062          }
1158 1063          *o++ = '\0';
1159 1064          fp = fopen(path, "w");
1160 1065          if (fp == NULL)
1161 1066                  return (BAM_ERROR);
1162 1067          (void) fprintf(fp, "bootfile=\"%s;unix\"\n", opt);
1163      -
1164      -        if (env != NULL) {
1165      -                env = getenv("boot-args");
1166      -                (void) fprintf(fp, "boot-args=\"%s %s\"\n", env, opt);
1167      -        } else
1168      -                (void) fprintf(fp, "boot-args=\"%s\"\n", o);
1169      -
     1068 +        (void) fprintf(fp, "boot-args=\"%s\"\n", o);
1170 1069          (void) fflush(fp);
1171 1070          (void) fclose(fp);
1172 1071          return (ret);
1173 1072  }
1174 1073  
1175 1074  static error_t
1176 1075  list_setting(struct menu_lst *menu, char *which, char *setting)
1177 1076  {
1178 1077          int entry = -1;
1179 1078          menu_entry_t *m;
↓ open down ↓ 52 lines elided ↑ open up ↑
1232 1131                          if (m->me_idx == entry)
1233 1132                                  break;
1234 1133  
1235 1134                  if (m == NULL) {
1236 1135                          bam_error(_("no matching entry found\n"));
1237 1136                          return (BAM_ERROR);
1238 1137                  }
1239 1138          }
1240 1139  
1241 1140          return (list_menu_entry(m, setting));
1242      -}
1243      -
1244      -/*ARGSUSED*/
1245      -static error_t
1246      -disable_hyper(struct menu_lst *menu, char *osroot, char *opt)
1247      -{
1248      -        char path[PATH_MAX];
1249      -
1250      -        (void) snprintf(path, PATH_MAX, "%s" XEN_CONFIG, bam_root);
1251      -        (void) unlink(path);
1252      -        return (BAM_SUCCESS);
1253      -}
1254      -
1255      -/*ARGSUSED*/
1256      -static error_t
1257      -enable_hyper(struct menu_lst *menu, char *osroot, char *opt)
1258      -{
1259      -        ficlVm *vm;
1260      -        char path[PATH_MAX];
1261      -        char buf[MAX_INPUT];
1262      -        char *env;
1263      -        FILE *fp;
1264      -        struct mnttab mpref = { 0 };
1265      -        struct mnttab mp = { 0 };
1266      -        int ret;
1267      -
1268      -        fp = fopen(MNTTAB, "r");
1269      -        if (fp == NULL)
1270      -                return (BAM_ERROR);
1271      -
1272      -        mpref.mnt_mountp = "/";
1273      -        if (getmntany(fp, &mp, &mpref) != 0) {
1274      -                (void) fclose(fp);
1275      -                return (BAM_ERROR);
1276      -        }
1277      -        (void) fclose(fp);
1278      -
1279      -        vm = bf_init("", ficlTextOutSilent);
1280      -        if (vm == NULL) {
1281      -                bam_error(_("Error setting up forth interpreter\n"));
1282      -                return (BAM_ERROR);
1283      -        }
1284      -
1285      -        /*
1286      -         * need to check current boot config, so fire up the ficl
1287      -         * if its xen setup, we add option to boot-args list, not replacing it.
1288      -         */
1289      -        (void) snprintf(buf, MAX_INPUT, "set currdev=zfs:%s:", mp.mnt_special);
1290      -        ret = ficlVmEvaluate(vm, buf);
1291      -        if (ret != FICL_VM_STATUS_OUT_OF_TEXT) {
1292      -                bam_error(_("Error interpreting boot config\n"));
1293      -                bf_fini();
1294      -                return (BAM_ERROR);
1295      -        }
1296      -        (void) snprintf(buf, MAX_INPUT, "include /boot/forth/loader.4th");
1297      -        ret = ficlVmEvaluate(vm, buf);
1298      -        if (ret != FICL_VM_STATUS_OUT_OF_TEXT) {
1299      -                bam_error(_("Error interpreting boot config\n"));
1300      -                bf_fini();
1301      -                return (BAM_ERROR);
1302      -        }
1303      -        (void) snprintf(buf, MAX_INPUT, "start");
1304      -        ret = ficlVmEvaluate(vm, buf);
1305      -        if (ret != FICL_VM_STATUS_OUT_OF_TEXT) {
1306      -                bam_error(_("Error interpreting boot config\n"));
1307      -                bf_fini();
1308      -                return (BAM_ERROR);
1309      -        }
1310      -        (void) snprintf(buf, MAX_INPUT, "boot");
1311      -        ret = ficlVmEvaluate(vm, buf);
1312      -        if (ret != FICL_VM_STATUS_OUT_OF_TEXT) {
1313      -                bam_error(_("Error interpreting boot config\n"));
1314      -                bf_fini();
1315      -                return (BAM_ERROR);
1316      -        }
1317      -        bf_fini();
1318      -
1319      -        (void) mkdir(CONF_DIR, 0755);
1320      -        (void) snprintf(path, PATH_MAX, "%s" XEN_CONFIG, bam_root);
1321      -        fp = fopen(path, "w");
1322      -        if (fp == NULL) {
1323      -                return (BAM_ERROR);     /* error, cant write config */
1324      -        }
1325      -
1326      -        errno = 0;
1327      -        /*
1328      -         * on write error, remove file to ensure we have bootable config.
1329      -         * note we dont mind if config exists, it will get updated
1330      -         */
1331      -        (void) fprintf(fp, "xen_kernel=\"/boot/${ISADIR}/xen\"\n");
1332      -        if (errno != 0)
1333      -                goto error;
1334      -
1335      -        /*
1336      -         * really simple and stupid console conversion.
1337      -         * it really has to be gone, it belongs to milestone/xvm properties.
1338      -         */
1339      -        env = getenv("console");
1340      -        if (env != NULL) {
1341      -                if (strcmp(env, "ttya") == 0)
1342      -                        (void) fprintf(fp, "xen_cmdline=\"console=com1 %s\"\n",
1343      -                            opt);
1344      -                else if (strcmp(env, "ttyb") == 0)
1345      -                        (void) fprintf(fp, "xen_cmdline=\"console=com2 %s\"\n",
1346      -                            opt);
1347      -                else
1348      -                        (void) fprintf(fp, "xen_cmdline=\"console=vga %s\"\n",
1349      -                            opt);
1350      -        } else
1351      -                (void) fprintf(fp, "xen_cmdline=\"%s\"\n", opt);
1352      -        if (errno != 0)
1353      -                goto error;
1354      -
1355      -        (void) fprintf(fp,
1356      -            "bootfile=\"/platform/i86xpv/kernel/${ISADIR}/unix\"\n");
1357      -        if (errno != 0)
1358      -                goto error;
1359      -
1360      -        (void) fprintf(fp,
1361      -            "boot-args=\"/platform/i86xpv/kernel/${ISADIR}/unix\"\n");
1362      -        if (errno != 0)
1363      -                goto error;
1364      -
1365      -        (void) fclose(fp);
1366      -        if (errno != 0) {
1367      -                (void) unlink(path);
1368      -                return (BAM_ERROR);
1369      -        }
1370      -        return (BAM_SUCCESS);
1371      -error:
1372      -        (void) fclose(fp);
1373      -        (void) unlink(path);
1374      -        return (BAM_ERROR);
1375 1141  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX