-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathquery_capacity_int.h
108 lines (94 loc) · 3.59 KB
/
query_capacity_int.h
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
/* Copyright IBM Corp. 2013, 2016 */
#ifndef QUERY_CAPACITY_INT
#define QUERY_CAPACITY_INT
#include <stddef.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <time.h>
#include <iconv.h>
#include <inttypes.h>
#include <linux/types.h>
#include <unistd.h>
#include "query_capacity.h"
/* Miscellaneous structures and constants */
#define STR_BUF_SIZE 257
#define ATTR_SRC_SYSINFO 'S'
#define ATTR_SRC_SYSFS 'F'
#define ATTR_SRC_HYPFS 'H'
#define ATTR_SRC_STHYI 'V'
#define ATTR_SRC_POSTPROC 'P' // Note: Post-processed attributes can have multiple origins - would be
// complicated to figure out accurately. We leave it at 'P' for now
#define ATTR_SRC_UNDEF '_'
#ifndef htobe16 // fallbacks for systems with a glibc < 2.9
#if __BYTE_ORDER == __LITTLE_ENDIAN
#define htobe16(x) bswap_16(x)
#define htobe32(x) bswap_32(x)
#define htobe64(x) bswap_64(x)
#else
#define htobe16(x) x
#define htobe32(x) x
#define htobe64(x) x
#endif // __BYTE_ORDER
#endif // htobe32
struct qc_handle {
void *layer; // holds a copy of the respective *_values struct
// and is filled by looking up the offset via the respective *_attrs table
struct qc_attr *attr_list;
int layer_no;
int *attr_present; // array indicating whether attributes are set
char *src; // array indicating the source of the attribute's value, see ATTR_SRC_*
struct qc_handle *next;
struct qc_handle *root; // points to top handle
};
struct qc_data_src {
int (*open)(struct qc_handle *, char **);
int (*process)(struct qc_handle *, char *);
void (*dump)(struct qc_handle *, char *);
void (*close)(struct qc_handle *, char *);
int (*lgm_check)(struct qc_handle *, const char *);
char *priv;
};
extern struct qc_data_src sysinfo, sysfs, hypfs, sthyi;
/* Utility functions */
int qc_ebcdic_to_ascii(struct qc_handle *hdl, char *inbuf, size_t insz);
int qc_is_nonempty_ebcdic(__u64 *str);
int qc_hdl_new(struct qc_handle *hdl, struct qc_handle **tgthdl, int layer_no, int layer_type);
// Insert new layer 'inserted_hdl' of type 'type' before 'hdl'. Won't support inserting a new root
int qc_hdl_insert(struct qc_handle *hdl, struct qc_handle **inserted_hdl, int type);
// Insert new layer 'appended_hdl' of type 'type' after 'hdl'
int qc_hdl_append(struct qc_handle *hdl, struct qc_handle **appended_hdl, int type);
// Remove the layer pointed to by the handle and all layers on top
void qc_hdl_prune(struct qc_handle *hdl);
struct qc_handle *qc_hdl_get_cec(struct qc_handle *hdl);
struct qc_handle *qc_hdl_get_lpar(struct qc_handle *hdl);
struct qc_handle *qc_hdl_get_root(struct qc_handle *hdl);
struct qc_handle *qc_hdl_get_top(struct qc_handle *hdl);
struct qc_handle *qc_hdl_get_prev(struct qc_handle *hdl);
int qc_hdl_get_layer_no(struct qc_handle *hdl);
/* Debugging-related functions and variables */
extern long qc_dbg_level;
extern FILE *qc_dbg_file;
extern char *qc_dbg_dump_dir;
extern char *qc_dbg_use_dump;
extern int qc_dbg_indent;
extern int qc_dbg_console;
extern int qc_consistency_check_requested;
void qc_debug_indent_inc();
void qc_debug_indent_dec();
void qc_mark_dump_incomplete(struct qc_handle *hdl, char *missing_component);
#define qc_debug(hdl, arg, ...) do { \
if (qc_dbg_level > 0) { \
if (qc_dbg_console) { \
fprintf(stderr, "%*s" arg, qc_dbg_indent, "", ##__VA_ARGS__); \
} else { \
time_t t; \
struct tm *tm; \
time(&t); \
tm = localtime(&t); \
fprintf(qc_dbg_file, "%02d/%02d,%02d:%02d:%02d,%-10p: %*s" arg, \
tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, qc_hdl_get_root(hdl), qc_dbg_indent, "", ##__VA_ARGS__); \
} \
} }while(0);
#endif