Esempio n. 1
0
void
add_nfsmount(struct mic_info *mic, char *target, char *server, char *mountdir, char *nfs_opt)
{
	char buffer[PATH_MAX];
	char *nfsserver;
	char *nfsdir;
	char *hostdir;

	micctrl_parse_config(&mpssenv, mic, &brlist, &mpssperr, PINFO);

	strncpy(buffer, target, PATH_MAX - 1);
	buffer[PATH_MAX - 1] = '\0';
	if (fill_nfsinfo(mic, 0, buffer, server, &nfsserver, &nfsdir))
		return;

	if (nfs_opt && nfs_opt_check(nfs_opt))
		return;

	fstab_add(mic->name, mic->config.filesrc.mic.dir, nfsdir, mountdir, nfsserver, nfs_opt);
	mpssut_mksubtree(&mpssenv, mic->config.filesrc.mic.dir, mountdir, 0, 0, 0755);

	if ((hostdir = micctrl_check_nfs_rootdev(mic)) != NULL) {
		fstab_add(mic->name, hostdir, nfsdir, mountdir, nfsserver, nfs_opt);
		mpssut_mksubtree(&mpssenv, hostdir, mountdir, 0, 0, 0755);
	}
}
Esempio n. 2
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);
}