~ubuntu-branches/ubuntu/precise/slurm-llnl/precise

« back to all changes in this revision

Viewing changes to contribs/perlapi/libslurm/perl/partition.c

  • Committer: Bazaar Package Importer
  • Author(s): Gennaro Oliva
  • Date: 2011-04-08 11:21:17 UTC
  • mfrom: (3.3.16 sid)
  • Revision ID: james.westby@ubuntu.com-20110408112117-nfnyq9dtm55hqoaw
Tags: 2.2.4-1
* New upstream releases 
* Cleaning spare file and directories, not belonging to the sources
  generated by the building process and not removed by distclean.
  Added debian/clean with spare files and rm -rf inside debian/rules
  for directories.
* Added new packages libslurm-perl, libslurmdb-perl, slurm-llnl-torque
  (Closes: #575822) thanks to Julien Blache

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * partition.c - convert data between partition related messages and perl HVs
 
3
 */
 
4
 
 
5
#include <EXTERN.h>
 
6
#include <perl.h>
 
7
#include <XSUB.h>
 
8
#include "ppport.h"
 
9
 
 
10
#include <slurm/slurm.h>
 
11
#include "slurm-perl.h"
 
12
 
 
13
/*
 
14
 * convert partition_info_t to perl HV
 
15
 */
 
16
int
 
17
partition_info_to_hv(partition_info_t *part_info, HV *hv)
 
18
{
 
19
        if (part_info->allow_alloc_nodes)
 
20
                STORE_FIELD(hv, part_info, allow_alloc_nodes, charp);
 
21
        if (part_info->allow_groups)
 
22
                STORE_FIELD(hv, part_info, allow_groups, charp);
 
23
        if (part_info->alternate)
 
24
                STORE_FIELD(hv, part_info, alternate, charp);
 
25
        STORE_FIELD(hv, part_info, default_time, uint32_t);
 
26
        STORE_FIELD(hv, part_info, flags, uint16_t);
 
27
        STORE_FIELD(hv, part_info, max_nodes, uint32_t);
 
28
        STORE_FIELD(hv, part_info, max_share, uint16_t);
 
29
        STORE_FIELD(hv, part_info, max_time, uint32_t);
 
30
        STORE_FIELD(hv, part_info, min_nodes, uint32_t);
 
31
        if (part_info->name)
 
32
                STORE_FIELD(hv, part_info, name, charp);
 
33
        else {
 
34
                Perl_warn(aTHX_ "partition name missing in partition_info_t");
 
35
                return -1;
 
36
        }
 
37
        /* no store for int pointers yet */
 
38
        if (part_info->node_inx) {
 
39
                int j;
 
40
                AV* av = newAV();
 
41
                for(j = 0; ; j += 2) {
 
42
                        if(part_info->node_inx[j] == -1)
 
43
                                break;
 
44
                        av_store(av, j, newSVuv(part_info->node_inx[j]));
 
45
                        av_store(av, j+1, newSVuv(part_info->node_inx[j+1]));
 
46
                }
 
47
                hv_store_sv(hv, "node_inx", newRV_noinc((SV*)av));
 
48
        }
 
49
 
 
50
        if (part_info->nodes)
 
51
                STORE_FIELD(hv, part_info, nodes, charp);
 
52
        STORE_FIELD(hv, part_info, preempt_mode, uint16_t);
 
53
        STORE_FIELD(hv, part_info, priority, uint16_t);
 
54
        STORE_FIELD(hv, part_info, state_up, uint16_t);
 
55
        STORE_FIELD(hv, part_info, total_cpus, uint32_t);
 
56
        STORE_FIELD(hv, part_info, total_nodes, uint32_t);
 
57
 
 
58
        return 0;
 
59
}
 
60
 
 
61
/* 
 
62
 * convert perl HV to partition_info_t
 
63
 */
 
64
int
 
65
hv_to_partition_info(HV *hv, partition_info_t *part_info)
 
66
{
 
67
        SV **svp;
 
68
        AV *av;
 
69
        int i, n;
 
70
 
 
71
        memset(part_info, 0, sizeof(partition_info_t));
 
72
 
 
73
        FETCH_FIELD(hv, part_info, allow_alloc_nodes, charp, FALSE);
 
74
        FETCH_FIELD(hv, part_info, allow_groups, charp, FALSE);
 
75
        FETCH_FIELD(hv, part_info, alternate, charp, FALSE);
 
76
        FETCH_FIELD(hv, part_info, default_time, uint32_t, TRUE);
 
77
        FETCH_FIELD(hv, part_info, flags, uint16_t, TRUE);
 
78
        FETCH_FIELD(hv, part_info, max_nodes, uint32_t, TRUE);
 
79
        FETCH_FIELD(hv, part_info, max_share, uint16_t, TRUE);
 
80
        FETCH_FIELD(hv, part_info, max_time, uint32_t, TRUE);
 
81
        FETCH_FIELD(hv, part_info, min_nodes, uint32_t, TRUE);
 
82
        FETCH_FIELD(hv, part_info, name, charp, TRUE);
 
83
        FETCH_FIELD(hv, part_info, name, charp, TRUE);
 
84
        svp = hv_fetch(hv, "node_inx", 8, FALSE);
 
85
        if (svp && SvROK(*svp) && SvTYPE(SvRV(*svp)) == SVt_PVAV) {
 
86
                av = (AV*)SvRV(*svp);
 
87
                n = av_len(av) + 2; /* for trailing -1 */
 
88
                part_info->node_inx = xmalloc(n * sizeof(int));
 
89
                for (i = 0 ; i < n-1; i += 2) {
 
90
                        part_info->node_inx[i] = (int)SvIV(*(av_fetch(av, i, FALSE)));
 
91
                        part_info->node_inx[i+1] = (int)SvIV(*(av_fetch(av, i+1 ,FALSE)));
 
92
                }
 
93
                part_info->node_inx[n-1] = -1;
 
94
        } else {
 
95
                /* nothing to do */
 
96
        }
 
97
        FETCH_FIELD(hv, part_info, nodes, charp, FALSE);
 
98
        FETCH_FIELD(hv, part_info, preempt_mode, uint16_t, TRUE);
 
99
        FETCH_FIELD(hv, part_info, priority, uint16_t, TRUE);
 
100
        FETCH_FIELD(hv, part_info, state_up, uint16_t, TRUE);
 
101
        FETCH_FIELD(hv, part_info, total_cpus, uint32_t, TRUE);
 
102
        FETCH_FIELD(hv, part_info, total_nodes, uint32_t, TRUE);
 
103
        return 0;
 
104
}
 
105
 
 
106
/*
 
107
 * convert partition_info_msg_t to perl HV
 
108
 */
 
109
int
 
110
partition_info_msg_to_hv(partition_info_msg_t *part_info_msg, HV *hv)
 
111
{
 
112
        int i;
 
113
        HV *hv_info;
 
114
        AV *av;
 
115
 
 
116
        STORE_FIELD(hv, part_info_msg, last_update, time_t);
 
117
        /* record_count implied in partition_array */
 
118
        av = newAV();
 
119
        for(i = 0; i < part_info_msg->record_count; i ++) {
 
120
                hv_info = newHV();
 
121
                if (partition_info_to_hv(part_info_msg->partition_array + i, hv_info)
 
122
                    < 0) {
 
123
                        SvREFCNT_dec(hv_info);
 
124
                        SvREFCNT_dec(av);
 
125
                        return -1;
 
126
                }
 
127
                av_store(av, i, newRV_noinc((SV*)hv_info));
 
128
        }
 
129
        hv_store_sv(hv, "partition_array", newRV_noinc((SV*)av));
 
130
        return 0;
 
131
}
 
132
 
 
133
/* 
 
134
 * convert perl HV to partition_info_msg_t
 
135
 */
 
136
int
 
137
hv_to_partition_info_msg(HV *hv, partition_info_msg_t *part_info_msg)
 
138
{
 
139
        SV **svp;
 
140
        AV *av;
 
141
        int i, n;
 
142
 
 
143
        memset(part_info_msg, 0, sizeof(partition_info_msg_t));
 
144
 
 
145
        FETCH_FIELD(hv, part_info_msg, last_update, time_t, TRUE);
 
146
        svp = hv_fetch(hv, "partition_array", 15, TRUE);
 
147
        if (! (svp && SvROK(*svp) && SvTYPE(SvRV(*svp)) == SVt_PVAV)) {
 
148
                Perl_warn (aTHX_ "partition_array is not an array reference in HV for partition_info_msg_t");
 
149
                return -1;
 
150
        }
 
151
 
 
152
        av = (AV*)SvRV(*svp);
 
153
        n = av_len(av) + 1;
 
154
        part_info_msg->record_count = n;
 
155
 
 
156
        part_info_msg->partition_array = xmalloc(n * sizeof(partition_info_t));
 
157
        for (i = 0; i < n; i ++) {
 
158
                svp = av_fetch(av, i, FALSE);
 
159
                if (! (svp && SvROK(*svp) && SvTYPE(SvRV(*svp)) == SVt_PVHV)) {
 
160
                        Perl_warn (aTHX_ "element %d in partition_array is not valid", i);
 
161
                        return -1;
 
162
                }
 
163
                if (hv_to_partition_info((HV*)SvRV(*svp), &part_info_msg->partition_array[i]) < 0) {
 
164
                        Perl_warn (aTHX_ "failed to convert element %d in partition_array", i);
 
165
                        return -1;
 
166
                }
 
167
        }
 
168
        return 0;
 
169
}
 
170
 
 
171
/*
 
172
 * convert perl HV to update_part_msg_t
 
173
 */
 
174
int
 
175
hv_to_update_part_msg(HV *hv, update_part_msg_t *part_msg)
 
176
{
 
177
        slurm_init_part_desc_msg(part_msg);
 
178
 
 
179
        FETCH_FIELD(hv, part_msg, allow_alloc_nodes, charp, FALSE);
 
180
        FETCH_FIELD(hv, part_msg, allow_groups, charp, FALSE);
 
181
        FETCH_FIELD(hv, part_msg, default_time, uint32_t, FALSE);
 
182
        FETCH_FIELD(hv, part_msg, flags, uint16_t, FALSE);
 
183
        FETCH_FIELD(hv, part_msg, max_nodes, uint32_t, FALSE);
 
184
        FETCH_FIELD(hv, part_msg, max_share, uint16_t, FALSE);
 
185
        FETCH_FIELD(hv, part_msg, max_time, uint32_t, FALSE);
 
186
        FETCH_FIELD(hv, part_msg, min_nodes, uint32_t, FALSE);
 
187
        FETCH_FIELD(hv, part_msg, name, charp, TRUE);
 
188
        /*not used node_inx */
 
189
        FETCH_FIELD(hv, part_msg, nodes, charp, FALSE);
 
190
        FETCH_FIELD(hv, part_msg, priority, uint16_t, FALSE);
 
191
        FETCH_FIELD(hv, part_msg, state_up, uint16_t, FALSE);
 
192
        FETCH_FIELD(hv, part_msg, total_cpus, uint32_t, FALSE);
 
193
        FETCH_FIELD(hv, part_msg, total_nodes, uint32_t, FALSE);
 
194
        return 0;
 
195
}
 
196
 
 
197
/*
 
198
 * convert perl HV to delete_part_msg_t
 
199
 */
 
200
int
 
201
hv_to_delete_part_msg(HV *hv, delete_part_msg_t *delete_msg)
 
202
{
 
203
        FETCH_FIELD(hv, delete_msg, name, charp, TRUE);
 
204
        return 0;
 
205
}