-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathspart_data.h
93 lines (84 loc) · 2.85 KB
/
spart_data.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
/******************************************************************
* spart : a user-oriented partition info command for slurm
* Author : Cem Ahmet Mercan, 2019-02-16
* Licence : GNU General Public License v2.0
* Note : Some part of this code taken from slurm api man pages
*******************************************************************/
#ifndef SPART_SPART_DATA_H_incl
#define SPART_SPART_DATA_H_incl
#include "spart_string.h"
/* Add one gres to partition gres list */
void sp_gres_add(sp_gres_info_t spga[], uint16_t *sp_gres_count,
char *node_gres) {
uint16_t i;
int found = 0;
char *strtmp = NULL;
char *grestok;
for (grestok = strtok_r(node_gres, ",", &strtmp); grestok != NULL;
grestok = strtok_r(NULL, ",", &strtmp)) {
for (i = 0; i < *sp_gres_count; i++) {
if (strncmp(spga[i].gres_name, grestok, SPART_INFO_STRING_SIZE) == 0) {
spga[i].count++;
found = 1;
break;
}
}
if (found == 0) {
sp_strn2cpy(spga[*sp_gres_count].gres_name, SPART_INFO_STRING_SIZE,
grestok, SPART_INFO_STRING_SIZE);
spga[*sp_gres_count].count = 1;
(*sp_gres_count)++;
}
}
}
/* Sets all counts as zero in the partition gres list */
void sp_gres_reset_counts(sp_gres_info_t *spga, uint16_t *sp_gres_count) {
uint16_t i;
for (i = 0; i < *sp_gres_count; i++) {
spga[i].count = 0;
}
(*sp_gres_count) = 0;
}
/* it checks for permision string for user_spec list, return 0 if partition
* should be hide */
int sp_check_permision_set_legend(char *permisions, char **user_spec,
int user_spec_count, char *legendstr,
const char *r_all, const char *r_some,
const char *r_none) {
int found_count;
// char strtmp[SPART_INFO_STRING_SIZE];
char *strtmp;
int nstrtmp;
if (permisions != NULL) {
nstrtmp = strlen(permisions);
if (nstrtmp != 0) {
strtmp = malloc(nstrtmp * sizeof(char));
sp_strn2cpy(strtmp, nstrtmp, permisions, nstrtmp);
found_count = sp_account_check(user_spec, user_spec_count, strtmp);
free(strtmp);
if (found_count) {
/* more than zero in the list */
if (found_count != user_spec_count) {
/* partial match */
sp_strn2cat(legendstr, SPART_MAX_COLUMN_SIZE, r_some, 2);
} else {
/* found_count = ALL */
if (r_all != NULL) {
/* this is an deny list */
sp_strn2cat(legendstr, SPART_MAX_COLUMN_SIZE, r_all, 2);
return 0;
}
}
} else {
/* found_count = 0 */
if (r_none != NULL) {
/* this is an allow list */
sp_strn2cat(legendstr, SPART_MAX_COLUMN_SIZE, r_none, 2);
return 0;
}
}
}
}
return 1;
}
#endif /* SPART_SPART_DATA_H_incl */