Ejemplo n.º 1
0
/*
 * If the root file system is StaticRamFs type then this recreate the compressed cpio
 * image file used to download and create the ram file system based on the information
 * found in BaseDir, CommonDir, MicDir and all Overlays.
 */
void
updateramfs(struct mic_info *miclist)
{
	struct mic_info *mic = NULL;

	mic = miclist;
	while (mic != NULL) {
		micctrl_parse_config(&mpssenv, mic, &brlist, &mpssperr, PINFO);

		if ((mic->config.rootdev.type != ROOT_TYPE_RAMFS) &&
		    (mic->config.rootdev.type != ROOT_TYPE_STATICRAMFS)) {
			display(PERROR, "%s: RootDevice must be RamFS or StaticRamFS\n", mic->name);
		} else {
			display(PNORM, "%s: Generating static ram file system image %s\n",
			       mic->name, mic->config.rootdev.target);
			mpssfs_gen_initrd(&mpssenv, mic, &mpssperr);
			display(PFS, "%s: Created %s\n", mic->name, mic->config.rootdev.target);
			mpss_print_elist(&mpssperr, PINFO, display);
			mpss_clear_elist(&mpssperr);
		}

		mic = mic->next;
	}

	exit(0);
}
Ejemplo n.º 2
0
/*
 * If the root file system is a NFS type then this will update the export directory based
 * on the information found in BaseDir, CommonDir, MicDir and all Overlays.
 */
void
updatenfs(struct mic_info *miclist)
{
	struct mic_info *mic;
	char tmpname[PATH_MAX];
	char *rootpath;

	mic = miclist;
	while (mic != NULL) {
		micctrl_parse_config(&mpssenv, mic, &brlist, &mpssperr, PINFO);

		if ((rootpath = micctrl_check_nfs_rootdev(mic)) == NULL) {
			mic = mic->next;
			continue;
		}

		if (!mpssut_filename(&mpssenv, NULL, tmpname, PATH_MAX, "%s", rootpath)) {
			display(PINFO, "%s: New creation.  Do not forget to add '%s'"
			       "to the NFS exports file\n", mic->name, rootpath);
			mpssut_mktree(&mpssenv, rootpath, 0, 0, 0755);
		} else {
			display(PINFO, "Updating NFS root directory %s\n", rootpath);
		}

		mpssfs_gen_nfsdir(&mpssenv, mic, 0, &mpssperr);
		mpss_print_elist(&mpssperr, PINFO, display);
		mpss_clear_elist(&mpssperr);
		display(PFS, "%s: Created NFS dir %s\n", mic->name, rootpath);
		mic = mic->next;
	}

	exit(0);
}
Ejemplo n.º 3
0
/*
 * If the root file system is Split NFS type then this will update the shared /usr directory
 * based on the information found in BaseDir, CommonDir, MicDir and all Overlays.
 */
void
updateusr(struct mic_info *miclist)
{
	struct mic_info *smic;
	struct mic_info *mic = NULL;
	char nfsusr[PATH_MAX];

	smic = miclist;
	while (smic != NULL) {
		micctrl_parse_config(&mpssenv, smic, &brlist, &mpssperr, PINFO);

		if (smic->config.rootdev.type != ROOT_TYPE_SPLITNFS) {
			smic = smic->next;
			continue;
		}

		mic = smic;
		break;
	}

	if (mic == NULL) {
		display(PERROR, "Error: updateusr did not find any MIC cards configured "
				"with SplitNFS\n");
		exit(1);
	}

	display(PNORM, "Updating /usr export based on %s\n", mic->name);

	if (!mpssut_filename(&mpssenv, NULL, nfsusr, PATH_MAX, "%s", strchr(mic->config.rootdev.nfsusr, ':') + 1)) {
		display(PNORM, "%s: Common /usr does not exist - creating %s\n", mic->name, nfsusr);

		mpssut_mktree(&mpssenv, nfsusr, 0, 0, 0755);
		mpssfs_gen_nfsdir(&mpssenv, mic, 1, &mpssperr);
		mpss_print_elist(&mpssperr, PINFO, display);
		mpss_clear_elist(&mpssperr);
		display(PFS, "%s: Created NFS /usr dir %s\n", mic->name, nfsusr);
	}

	exit(0);
}
Ejemplo n.º 4
0
void
set_nfsroot(struct mic_info *mic, int type, char *target, char *usr, char *server, int create)
{
	char tmptarget[PATH_MAX];
	char tmpusr[PATH_MAX];
	char tmpdir[PATH_MAX];
	char *nfsserver;
	char *nfsdir;
	char *usrserver;
	char *usrdir;
	struct stat sbuf;
	char *nfs_opt = NULL;

	if (target == NULL) {
		snprintf(tmptarget, PATH_MAX - 1, "%s/%s.export", mpssenv.vardir, mic->name);
		target = tmptarget;
	}

	if (fill_nfsinfo(mic, type, target, server, &nfsserver, &nfsdir))
		return;

	snprintf(tmpdir, PATH_MAX, "%s:%s", nfsserver, nfsdir);
	mic->config.rootdev.target = mpssut_alloc_fill(tmpdir);
	mic->config.rootdev.nfsusr = NULL;

	if (type == ROOT_TYPE_SPLITNFS) {
		if (usr == NULL) {
			snprintf(tmpusr, PATH_MAX - 1, "%s/usr.export", mpssenv.vardir);
			usr = tmpusr;
		}

		if (fill_nfsinfo(mic, type, usr, server, &usrserver, &usrdir))
			return;

		snprintf(tmpdir, PATH_MAX, "%s:%s", usrserver, usrdir);
		mpssut_realloc_fill(&mic->config.rootdev.nfsusr, tmpdir);
		mpssut_filename(&mpssenv, NULL, tmpdir, PATH_MAX, "%s", mic->config.filesrc.mic.dir);
		fstab_add(mic->name, tmpdir, usrdir, "/usr", nfsserver, nfs_opt);
		display(PFS, "%s: Update RootDevice in %s\n", mic->name, mic->config.name);
		mpss_update_config(&mpssenv, mic->config.name, NULL, descriptor, "%s %s %s %s\n\n",
				   "RootDevice", fstypes[type], mic->config.rootdev.target, mic->config.rootdev.nfsusr);
	} else {
		display(PFS, "%s: Update RootDevice in %s\n", mic->name, mic->config.name);
		mpss_update_config(&mpssenv, mic->config.name, NULL, descriptor, "%s %s %s\n\n",
				   "RootDevice", fstypes[type], mic->config.rootdev.target);
	}

	if (!create)
		return;

	if (mpssut_filename(&mpssenv, NULL, tmpdir, PATH_MAX, "%s", nfsdir))
		display(PINFO, "%s: Updating existing directory %s: %s\n", mic->name, nfsdir, strerror(errno));

	mpssut_mktree(&mpssenv, nfsdir, 0, 0, 0755);
	mpssfs_gen_nfsdir(&mpssenv, mic, FALSE, &mpssperr);
	mpss_print_elist(&mpssperr, PINFO, display);
	mpss_clear_elist(&mpssperr);
	display(PFS, "%s: Created NFS dir %s\n", mic->name, nfsdir);

	if ((type != ROOT_TYPE_SPLITNFS) || (stat(usrdir, &sbuf) == 0))
		return;

	display(PINFO, "%s: Common /usr does not exist - creating %s\n", mic->name, usrdir);

	if (mpssut_filename(&mpssenv, NULL, tmpdir, PATH_MAX, "%s", usrdir))
		display(PWARN, "%s: Updating existing directory %s: %s\n", mic->name, usrdir, strerror(errno));

	mpssut_mktree(&mpssenv, usrdir, 0, 0, 0755);
	mpssfs_gen_nfsdir(&mpssenv, mic, TRUE, &mpssperr);
	mpss_print_elist(&mpssperr, PINFO, display);
	mpss_clear_elist(&mpssperr);
	display(PFS, "%s: Created NFS /usr dir %s\n", mic->name, usrdir);
}
Ejemplo n.º 5
0
void *
boot_mic(void *arg)
{
	struct mic_info *mic = (struct mic_info *)arg;
	struct mpssd_info *mpssdi = (struct mpssd_info *)mic->data;
	struct mpss_elist mpssperr;
	struct stat sbuf;
	char *initrd = NULL;
	char *state;
	char *save;
	char *errmsg;
	char boot_string[PATH_MAX];
	char cmdline[2048];
	int shutdown_wait = 180;// Do not wait for shutdown more than 180 secs.
	int reset_wait = 180;	// Do not wait for reset more than 180 secs.
	int err = 0;
	char *shutdown_str;
	char os_image_path[PATH_MAX];
	char kernel[PATH_MAX];
	char ramdisk[PATH_MAX];
	char efiimage[PATH_MAX];
	char *sysfs_rd;

	if ((err = mpss_parse_config(&mpssenv, mic, &brlist, &mpssperr))) {
		mpsslog(PINFO, "%s: Boot aborted - no configuation file present: %s\n", mic->name, strerror(err));
		goto bootexit;
	}

	mpss_print_elist(&mpssperr, PWARN, mpsslog);
	mpss_clear_elist(&mpssperr);

	switch(mic->config.family) {
		case MIC_FAMILY_KNL_VALUE:
			if (!is_mic_knl(mic))
				mpsslog(PWARN, "%s: Family mismatch. Configuration file parameter is %s but MIC family is different\n"
						"\t Please execute micctrl --cleanconfig and --initdefaults again\n", mic->name, family_to_str(mic->config.family));
			break;
		case MIC_FAMILY_KNC_VALUE:
			if (!is_mic_knc(mic))
				mpsslog(PWARN, "%s: Family mismatch. Configuration file parameter is %s but MIC family is different\n"
						"\t Please execute micctrl --cleanconfig and --initdefaults again\n", mic->name, family_to_str(mic->config.family));
			break;
		case MIC_FAMILY_UNKNOWN_VALUE:
		default:
			mpsslog(PWARN, "%s: Family parameter is %s\n\t Please execute micctrl --cleanconfig and --initdefaults again\n", mic->name, family_to_str(mic->config.family));
	}

	if (check_fs_params(mic))
		goto bootexit;

	if (mic->config.boot.osimage == NULL) {
		mpsslog(PINFO, "%s: Boot aborted - OsImage parameter not set\n", mic->name);
		goto bootexit;
	}

	if (is_mic_knl(mic) && mic->config.boot.efiimage == NULL) {
		mpsslog(PINFO, "%s: Boot aborted - EFI Image parameter not set\n", mic->name);
		goto bootexit;
	}

	if (verify_bzImage(&mpssenv, mic->config.boot.osimage, mic->name)) {
		mpsslog(PINFO, "%s: Boot aborted - %s is not a valid Linux bzImage\n",
				mic->name, mic->config.boot.osimage);
		goto bootexit;
	}

	if ((errmsg = mpss_set_cmdline(mic, brlist, cmdline, NULL)) != NULL) {
		mpsslog(PINFO, "%s: Boot aborted - %s\n", mic->name, errmsg);
		goto bootexit;
	}

	mpsslog(PINFO, "%s: Command line: %s\n", mic->name, cmdline);

	set_log_buf_info(mic);

	pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
	pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);

	if (mic->config.boot.onstart != TRUE) {
		mpsslog(PINFO, "%s: Not set to autoboot\n", mic->name);
		goto bootmic_done;
	}

	switch (mic->config.rootdev.type) {
	case ROOT_TYPE_RAMFS:
		if (stat(mic->config.rootdev.target, &sbuf) == 0)
			unlink(mic->config.rootdev.target);
		mpsslog(PINFO, "%s: Generate %s\n", mic->name, mic->config.rootdev.target);
		mpssfs_gen_initrd(&mpssenv, mic, &mpssperr);
		mpss_print_elist(&mpssperr, PWARN, mpsslog);
		mpss_clear_elist(&mpssperr);
	case ROOT_TYPE_STATICRAMFS:
		initrd = mic->config.rootdev.target;
		break;

	case ROOT_TYPE_NFS:
	case ROOT_TYPE_SPLITNFS:
	case ROOT_TYPE_PFS:
		initrd = mic->config.filesrc.base.image;
		break;
	}

	if (initrd == NULL) {
		mpsslog(PERROR, "%s Boot aborted - initial ramdisk not set", mic->name);
		goto bootmic_done;
	}

	if (is_upstream_driver()) {
		/* request_firmware() API that is used in the upstream stack
		 * expects the firmware images to be somewhere under /lib/firmware.
		 * We create /lib/firmware/mic/micX/ and place links to micX specific
		 * images under them. */
		snprintf(os_image_path, PATH_MAX, "/lib/firmware/mic/%s", mic->name);
		mpssut_deltree(&mpssenv, os_image_path);

		if (mpssut_mksubtree(&mpssenv, "", os_image_path, 0, 0, 0755)) {
			mpsslog(PERROR, "%s Boot aborted - Failed to create boot directory. %s\n",
				mic->name, strerror(errno));
			goto bootmic_done;
		}

		snprintf(kernel, PATH_MAX, "%s/uos.img", os_image_path);
		snprintf(ramdisk, PATH_MAX, "%s/mic.image", os_image_path);
		if(is_mic_knl(mic))
			snprintf(efiimage, PATH_MAX, "%s/efi.image", os_image_path);

		if (symlink(mic->config.boot.osimage, kernel) < 0) {
			mpsslog(PERROR, "%s Boot aborted - Failed to create symlink for kernel image. %s",
				mic->name, strerror(errno));
			goto bootmic_done;
		}

		if (initrd == NULL || symlink(initrd, ramdisk) < 0) {
			mpsslog(PERROR, "%s Boot aborted - Failed to create symlink for filesystem. %s",
				mic->name, strerror(errno));
			goto bootmic_done;
		}

		if (is_mic_knl(mic) && symlink(mic->config.boot.efiimage, efiimage) < 0) {
			mpsslog(PERROR, "%s Boot aborted - Failed to create symlink for EFI image. %s",
				mic->name, strerror(errno));
			goto bootmic_done;
		}

		if (mpss_setsysfs(mic->name, "bootmode", "linux")) {
			sysfs_rd = mpss_readsysfs(mic->name, "bootmode");
			mpsslog(PERROR, "%s failed to boot. Bootmode = %s\n", mic->name, sysfs_rd);
			free(sysfs_rd);
			goto bootmic_done;
		}

		/* request_firmware doesn't like absolute paths. */
		snprintf(kernel, PATH_MAX, "mic/%s/uos.img", mic->name);
		snprintf(ramdisk, PATH_MAX, "mic/%s/mic.image", mic->name);
		if (is_mic_knl(mic))
			snprintf(efiimage, PATH_MAX, "mic/%s/efi.image", mic->name);

		if (mpss_setsysfs(mic->name, "firmware", kernel)) {
			sysfs_rd = mpss_readsysfs(mic->name, "firmware");
			mpsslog(PERROR, "%s failed to boot. Firmware = %s\n", mic->name, sysfs_rd);
			free(sysfs_rd);
			goto bootmic_done;
		}

		if (mpss_setsysfs(mic->name, "ramdisk", ramdisk)) {
			sysfs_rd = mpss_readsysfs(mic->name, "ramdisk");
			mpsslog(PERROR, "%s failed to boot. Ramdisk = %s\n", mic->name, sysfs_rd);
			free(sysfs_rd);
			goto bootmic_done;
		}

		if (is_mic_knl(mic) && mpss_setsysfs(mic->name, "efiimage", efiimage)) {
			sysfs_rd = mpss_readsysfs(mic->name, "efiimage");
			mpsslog(PERROR, "%s failed to boot. EFI image = %s\n", mic->name, sysfs_rd);
			free(sysfs_rd);
			goto bootmic_done;
		}

		snprintf(boot_string, PATH_MAX, "boot");

	} else {
		snprintf(boot_string, PATH_MAX, "boot:linux:%s:%s", mic->config.boot.osimage, initrd);
	}

	if ((state = mpss_readsysfs(mic->name, "state")) == NULL) {
		mpsslog(PERROR, "%s: Cannot access state sysfs entry - skipping\n", mic->name);
		goto bootmic_done;
	}

	if (is_upstream_driver())
		shutdown_str = "shutting_down";
	else
		shutdown_str = "shutdown";

	while (!strcmp(state, shutdown_str)) {
		save = state;

		if ((state = mpss_readsysfs(mic->name, "state")) == NULL) {
			mpsslog(PWARN, "%s: Wait for shutdown failed to read state sysfs - try again\n", mic->name);
			state = save;
		} else {
			free(save);
		}

		if (!shutdown_wait--) {
			mpsslog(PWARN, "%s: Wait for shutdown timed out\n", mic->name);
			goto bootmic_done;
		}
		mpsslog(PINFO, "%s: Waiting for shutdown to complete\n", mic->name);
		sleep(1);
	}

	while (!strcmp(state, "resetting")) {
		save = state;
		if ((state = mpss_readsysfs(mic->name, "state")) == NULL) {
			mpsslog(PWARN, "%s: Wait for reset failed to read state sysfs - try again\n", mic->name);
			state = save;
		} else {
			free(save);
		}

		if (!reset_wait--) {
			mpsslog(PINFO, "%s: Wait for reset timed out\n", mic->name);
			goto bootmic_done;
		}
		mpsslog(PINFO, "%s: Waiting for reset to complete\n", mic->name);
		sleep(1);
	}

	if (strcmp(state, "ready")) {
		mpsslog(PINFO, "%s: Current state \"%s\" cannot boot card\n", mic->name, state);
		free(state);
		goto bootmic_done;
	}

	free(state);

	if ((err = mpss_setsysfs(mic->name, "state", boot_string)) != 0) {
		mpsslog(PINFO, "%s: Booting failed - cannot set state: %s\n", mic->name, strerror(err));
	} else {
		mpsslog(PINFO, "%s: Booting %s initrd %s\n", mic->name, mic->config.boot.osimage, initrd);
	}

bootmic_done:
	while (pthread_mutex_lock(&mpssdi->pth_lock) != 0);
	mpssdi->boot_pth = 0;
	while (pthread_mutex_unlock(&mpssdi->pth_lock) != 0);
bootexit:
	while (pthread_mutex_lock(&start_lock) != 0);
	start_count--;
	while (pthread_mutex_unlock(&start_lock) != 0);
	pthread_exit(NULL);
}