[LTP] [PATCH 2/2] lib/tst_virt: support IBM/Z LPAR and z/VM virtualization environments

Cyril Hrubis chrubis@suse.cz
Mon Nov 9 15:42:49 CET 2020


Hi!
> +static int is_ibmz_lpar(void)
> +{
> +	FILE *cpuinfo;
> +	char line[64];
> +	int found_lpar, found_zvm;
> +
> +	if (access("/proc/sysinfo", F_OK) != 0)
> +		return 0;
> +
> +	cpuinfo = SAFE_FOPEN(NULL, "/proc/sysinfo", "r");
> +	found_lpar = 0;
> +	found_zvm = 0;
> +	while (fgets(line, sizeof(line), cpuinfo) != NULL) {
> +		if (strstr(line, "LPAR"))
> +			found_lpar = 1;
> +		else if (strstr(line, "z/VM"))
> +			found_zvm = 1;
> +	}
> +
> +	SAFE_FCLOSE(NULL, cpuinfo);
> +	return found_lpar && !found_zvm;
> +}
> +
> +static int is_ibmz_zvm(void)
> +{
> +	FILE *cpuinfo;
> +	char line[64];
> +	int found_lpar, found_zvm;
> +
> +	if (access("/proc/sysinfo", F_OK) != 0)
> +		return 0;
> +
> +	cpuinfo = SAFE_FOPEN(NULL, "/proc/sysinfo", "r");
> +	found_lpar = 0;
> +	found_zvm = 0;
> +	while (fgets(line, sizeof(line), cpuinfo) != NULL) {
> +		if (strstr(line, "LPAR"))
> +			found_lpar = 1;
> +		else if (strstr(line, "z/VM"))
> +			found_zvm = 1;
> +	}
> +
> +	SAFE_FCLOSE(NULL, cpuinfo);
> +	return found_lpar && found_zvm;
> +}

These two function are nearly identical apart from the last line, I
guess that it would be cleaner to have one function and pass the
VIRT_IBMZ_LPAR and VIRT_IBMZ_ZVM constants to select which result we
want.

Other than this, the rest looks good.

-- 
Cyril Hrubis
chrubis@suse.cz


More information about the ltp mailing list