[go: up one dir, main page]

File: dt.c

package info (click to toggle)
s390-tools 2.3.0-2~deb10u1
  • links: PTS
  • area: main
  • in suites: buster
  • size: 6,188 kB
  • sloc: ansic: 87,755; sh: 8,398; cpp: 8,384; perl: 3,783; makefile: 1,476; asm: 654
file content (137 lines) | stat: -rw-r--r-- 2,446 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/*
 * zgetdump - Tool for copying and converting System z dumps
 *
 * Dump tool info generic functions
 *
 * Copyright IBM Corp. 2001, 2017
 *
 * s390-tools is free software; you can redistribute it and/or modify
 * it under the terms of the MIT license. See LICENSE for details.
 */

#include "zgetdump.h"

/*
 * Supported dump tools
 */
static struct dt *dt_vec[] = {
	&dt_s390mv,
	&dt_s390sv,
	&dt_scsi,
	NULL,
};

/*
 * Dumper attribute information
 */
struct attr {
	int	*force;
	u64	*mem_limit;
	char	*dasd_type;
};

/*
 * File local static data
 */
static struct {
	int		version;
	enum dfi_arch	arch;
	struct attr	attr;
	struct dt	*dt;
} l;

/*
 * Init dump tool backends
 */
void dt_init(void)
{
	struct dt *dt;
	int i = 0;

	while ((dt = dt_vec[i])) {
		g.fh = zg_open(g.opts.device, O_RDONLY, ZG_CHECK);
		if (!S_ISBLK(g.fh->sb.st_mode))
			ERR_EXIT("Please specify DASD or SCSI device node"
				 "(e.g. /dev/dasdd or /dev/sda )");
		if (dt->init() == 0) {
			l.dt = dt;
			return;
		}
		zg_close(g.fh);
		i++;
	}
	ERR_EXIT("No dump tool found on \"%s\"", g.opts.device);
}

/*
 * Print info about dump tool
 */
void dt_info_print(void)
{
	STDERR("Dump device info:\n");
	STDERR("  Dump tool.........: %s\n", l.dt->desc);
	STDERR("  Version...........: %d\n", l.version);
	STDERR("  Architecture......: %s\n", dfi_arch_str(l.arch));
	if (l.attr.dasd_type)
		STDERR("  DASD type.........: %s\n", l.attr.dasd_type);

	if (l.attr.mem_limit) {
		if (*l.attr.mem_limit != U64_MAX)
			STDERR("  Dump size limit...: %lld MB\n",
			       TO_MIB(*l.attr.mem_limit));
		else
			STDERR("  Dump size limit...: none\n");
	}
	if (l.attr.force) {
		if (*l.attr.force == 0)
			STDERR("  Force specified...: no\n");
		else
			STDERR("  Force specified...: yes\n");
	}
	if (l.dt->info) {
		STDERR("\n");
		l.dt->info();
	}
}

/*
 * Set DT architecture
 */
void dt_arch_set(enum dfi_arch arch)
{
	l.arch = arch;
}

/*
 * Set DT version
 */
void dt_version_set(int version)
{
	l.version = version;
}

/*
 * Set DT memory limit attribute
 */
void dt_attr_mem_limit_set(u64 mem_limit)
{
	l.attr.mem_limit = zg_alloc(sizeof(*l.attr.mem_limit));
	*l.attr.mem_limit = mem_limit;
}

/*
 * Set DT force attribute
 */
void dt_attr_force_set(int force)
{
	l.attr.force = zg_alloc(sizeof(*l.attr.force));
	*l.attr.force = force;
}

/*
 * Set DT DASD type attribute
 */
void dt_attr_dasd_type_set(const char *dasd_type)
{
	l.attr.dasd_type = zg_strdup(dasd_type);
}