-
Notifications
You must be signed in to change notification settings - Fork 515
Expand file tree
/
Copy pathclient_types.cpp
More file actions
1554 lines (1457 loc) · 45.2 KB
/
Copy pathclient_types.cpp
File metadata and controls
1554 lines (1457 loc) · 45.2 KB
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// This file is part of BOINC.
// http://boinc.berkeley.edu
// Copyright (C) 2026 University of California
//
// BOINC is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License
// as published by the Free Software Foundation,
// either version 3 of the License, or (at your option) any later version.
//
// BOINC is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// See the GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
#include "cpp.h"
#ifdef _WIN32
#include "boinc_win.h"
#include "zlib.h"
#else
#include "config.h"
#include <sys/stat.h>
#include <sys/types.h>
#include <zlib.h>
#include <cstring>
#endif
#include "error_numbers.h"
#include "filesys.h"
#include "log_flags.h"
#include "md5.h"
#include "parse.h"
#include "str_util.h"
#include "str_replace.h"
#include "util.h"
#include "async_file.h"
#include "client_msgs.h"
#include "client_state.h"
#include "file_names.h"
#include "project.h"
#include "pers_file_xfer.h"
#include "project.h"
#include "sandbox.h"
#include "client_types.h"
using std::string;
using std::vector;
bool FILE_XFER_BACKOFF::ok_to_transfer() {
double dt = next_xfer_time - gstate.now;
if (dt > gstate.pers_retry_delay_max) {
// must have changed the system clock
//
dt = 0;
}
return (dt <= 0);
}
// A transfer has failed.
// Back off transfers (project-wide) if needed.
//
void FILE_XFER_BACKOFF::file_xfer_failed(PROJECT* p) {
// If we're already backed off, ignore this failure.
// If we start several transfers at once
// (say, N output files of a job) and they all fail,
// we don't want to back off N times, which could be hours.
//
if (gstate.now < next_xfer_time) {
return;
}
file_xfer_failures++;
if (file_xfer_failures < FILE_XFER_FAILURE_LIMIT) {
next_xfer_time = 0;
return;
}
double backoff = calculate_exponential_backoff(
file_xfer_failures,
gstate.pers_retry_delay_min,
gstate.pers_retry_delay_max
);
if (log_flags.file_xfer_debug) {
msg_printf(p, MSG_INFO,
"[file_xfer] project-wide %s delay for %f sec",
is_upload?"upload":"download",
backoff
);
}
next_xfer_time = gstate.now + backoff;
}
void FILE_XFER_BACKOFF::file_xfer_succeeded() {
file_xfer_failures = 0;
next_xfer_time = 0;
}
int parse_project_files(XML_PARSER& xp, vector<FILE_REF>& project_files) {
int retval;
project_files.clear();
while (!xp.get_tag()) {
if (xp.match_tag("/project_files")) return 0;
if (xp.match_tag("file_ref")) {
FILE_REF file_ref;
retval = file_ref.parse(xp);
if (retval) {
msg_printf(0, MSG_INFO,
"can't parse file_ref in project file: %s",
boincerror(retval)
);
} else {
project_files.push_back(file_ref);
}
} else {
if (log_flags.unparsed_xml) {
msg_printf(0, MSG_INFO,
"[unparsed_xml] parse_project_files(): unrecognized: %s\n",
xp.parsed_tag
);
}
xp.skip_unexpected();
}
}
return ERR_XML_PARSE;
}
int APP::parse(XML_PARSER& xp) {
safe_strcpy(name, "");
safe_strcpy(user_friendly_name, "");
project = NULL;
non_cpu_intensive = false;
sporadic = false;
while (!xp.get_tag()) {
if (xp.match_tag("/app")) {
if (!strlen(user_friendly_name)) {
safe_strcpy(user_friendly_name, name);
}
return 0;
}
if (xp.parse_str("name", name, sizeof(name))) continue;
if (xp.parse_str("user_friendly_name", user_friendly_name, sizeof(user_friendly_name))) continue;
if (xp.parse_bool("non_cpu_intensive", non_cpu_intensive)) continue;
if (xp.parse_bool("sporadic", sporadic)) continue;
if (xp.parse_bool("fraction_done_exact", fraction_done_exact)) continue;
if (xp.parse_bool("sporadic", sporadic)) {
if (sporadic) gstate.have_sporadic_app = true;
continue;
}
#ifdef SIM
if (xp.parse_double("latency_bound", latency_bound)) continue;
if (xp.parse_double("fpops_est", fpops_est)) continue;
if (xp.parse_double("weight", weight)) continue;
if (xp.parse_double("working_set", working_set)) continue;
if (xp.match_tag("fpops")) {
fpops.parse(xp, "/fpops");
continue;
}
if (xp.parse_int("max_concurrent", max_concurrent)) {
if (max_concurrent) have_max_concurrent = true;
continue;
}
if (xp.match_tag("checkpoint_period")) {
checkpoint_period.parse(xp, "/checkpoint_period");
continue;
}
#endif
if (log_flags.unparsed_xml) {
msg_printf(0, MSG_INFO,
"[unparsed_xml] APP::parse(): unrecognized: %s\n",
xp.parsed_tag
);
}
xp.skip_unexpected();
}
return ERR_XML_PARSE;
}
int APP::write(MIOFILE& out) {
out.printf(
"<app>\n"
" <name>%s</name>\n"
" <user_friendly_name>%s</user_friendly_name>\n"
" <non_cpu_intensive>%d</non_cpu_intensive>\n"
"</app>\n",
name, user_friendly_name,
non_cpu_intensive?1:0
);
return 0;
}
FILE_INFO::FILE_INFO() {
safe_strcpy(name, "");
safe_strcpy(md5_cksum, "");
max_nbytes = 0;
nbytes = 0;
gzipped_nbytes = 0;
upload_offset = -1;
status = FILE_NOT_PRESENT;
executable = false;
uploaded = false;
sticky = false;
sticky_lifetime = 0;
sticky_expire_time = 0;
gzip_when_done = false;
ref_cnt = 0;
download_gzipped = false;
signature_required = false;
is_user_file = false;
is_project_file = false;
is_auto_update_file = false;
anonymous_platform_file = false;
pers_file_xfer = NULL;
project = NULL;
download_urls.clear();
upload_urls.clear();
safe_strcpy(xml_signature, "");
safe_strcpy(file_signature, "");
cert_sigs = 0;
async_verify = NULL;
}
FILE_INFO::~FILE_INFO() {
#ifndef SIM
if (async_verify) {
remove_async_verify(async_verify);
}
#endif
}
void FILE_INFO::reset() {
status = FILE_NOT_PRESENT;
delete_file();
error_msg.clear();
}
// Set file ownership if using account-based sandbox;
// set permissions depending on whether it's an executable file.
//
// If "path" is non-null, use it instead of the file's
// path in the project directory
// (this is used for files copied into a slot directory)
//
#ifdef _WIN32
int FILE_INFO::set_permissions(const char*) {
return 0; // Not relevant in Windows.
}
#else
int FILE_INFO::set_permissions(const char* path) {
int retval;
char pathname[1024];
if (path) {
safe_strcpy(pathname, path);
} else {
get_pathname(this, pathname, sizeof(pathname));
}
if (g_use_sandbox) {
// give exec permissions for user, group and others but give
// read permissions only for user and group to protect account keys
retval = set_to_project_group(pathname);
if (retval) return retval;
if (executable) {
retval = chmod(pathname,
S_IRUSR|S_IWUSR|S_IXUSR
|S_IRGRP|S_IWGRP|S_IXGRP
|S_IXOTH
);
} else {
retval = chmod(pathname,
S_IRUSR|S_IWUSR
|S_IRGRP|S_IWGRP
);
}
} else {
// give read/exec permissions for user, group and others
// in case someone runs BOINC from different user
if (executable) {
retval = chmod(pathname,
S_IRUSR|S_IWUSR|S_IXUSR
|S_IRGRP|S_IXGRP
|S_IROTH|S_IXOTH
);
} else {
retval = chmod(pathname,
S_IRUSR|S_IWUSR
|S_IRGRP
|S_IROTH
);
}
}
return retval;
}
#endif
// parse a <file_info>, from state file or scheduler RPC reply
//
int FILE_INFO::parse(XML_PARSER& xp) {
char buf2[1024];
string url;
PERS_FILE_XFER *pfxp;
int retval;
bool btemp;
vector<string>gzipped_urls;
while (!xp.get_tag()) {
if (xp.match_tag("/file_info") || xp.match_tag("/file")) {
if (!strlen(name)) return ERR_BAD_FILENAME;
if (strstr(name, "..")) return ERR_BAD_FILENAME;
if (strchr(name, '%')) return ERR_BAD_FILENAME;
if (gzipped_urls.size() > 0) {
download_urls.clear();
download_urls.urls = gzipped_urls;
download_gzipped = true;
}
return 0;
}
if (xp.match_tag("xml_signature")) {
retval = copy_element_contents(
xp.f->f,
"</xml_signature>",
xml_signature,
sizeof(xml_signature)
);
if (retval) return retval;
strip_whitespace(xml_signature);
continue;
}
if (xp.match_tag("file_signature")) {
retval = copy_element_contents(
xp.f->f,
"</file_signature>",
file_signature,
sizeof(file_signature)
);
if (retval) return retval;
strip_whitespace(file_signature);
continue;
}
if (xp.match_tag("signatures")) {
if (!cert_sigs->parse(xp)) {
msg_printf(0, MSG_INTERNAL_ERROR,
"FILE_INFO::parse(): cannot parse <signatures>\n"
);
return ERR_XML_PARSE;
}
continue;
}
if (xp.parse_str("name", name, sizeof(name))) continue;
if (xp.parse_string("url", url)) {
if (strstr(url.c_str(), "file_upload_handler")) {
upload_urls.urls.push_back(url);
} else {
download_urls.urls.push_back(url);
}
continue;
}
if (xp.parse_string("download_url", url)) {
download_urls.urls.push_back(url);
continue;
}
if (xp.parse_string("upload_url", url)) {
upload_urls.urls.push_back(url);
continue;
}
if (xp.parse_string("gzipped_url", url)) {
gzipped_urls.push_back(url);
continue;
}
if (xp.parse_str("md5_cksum", md5_cksum, sizeof(md5_cksum))) continue;
if (xp.parse_double("nbytes", nbytes)) continue;
if (xp.parse_double("gzipped_nbytes", gzipped_nbytes)) continue;
if (xp.parse_double("max_nbytes", max_nbytes)) continue;
if (xp.parse_int("status", status)) {
// on startup, VERIFY_PENDING is meaningless
if (status == FILE_VERIFY_PENDING) {
status = FILE_NOT_PRESENT;
}
continue;
}
if (xp.parse_bool("executable", executable)) continue;
if (xp.parse_bool("uploaded", uploaded)) continue;
if (xp.parse_bool("sticky", sticky)) continue;
if (xp.parse_double("sticky_expire_time", sticky_expire_time)) continue;
// state file has this
if (xp.parse_double("sticky_lifetime", sticky_lifetime)) continue;
// scheduler RPC reply has this
if (xp.parse_bool("gzip_when_done", gzip_when_done)) continue;
if (xp.parse_bool("download_gzipped", download_gzipped)) continue;
if (xp.parse_bool("signature_required", signature_required)) continue;
if (xp.parse_bool("is_project_file", is_project_file)) continue;
if (xp.parse_bool("no_delete", btemp)) continue;
if (xp.match_tag("persistent_file_xfer")) {
pfxp = new PERS_FILE_XFER;
retval = pfxp->parse(xp);
#ifdef SIM
delete pfxp;
#else
if (!retval) {
pers_file_xfer = pfxp;
} else {
delete pfxp;
}
#endif
continue;
}
if (xp.match_tag("file_xfer")) {
while (!xp.get_tag()) {
if (xp.match_tag("/file_xfer")) break;
}
continue;
}
if (xp.match_tag("error_msg")) {
retval = copy_element_contents(
xp.f->f,
"</error_msg>", buf2, sizeof(buf2)
);
if (retval) return retval;
error_msg = buf2;
continue;
}
// deprecated tags
if (xp.parse_bool("generated_locally", btemp)) continue;
if (xp.parse_bool("upload_when_present", btemp)) continue;
if (log_flags.unparsed_xml) {
msg_printf(0, MSG_INFO,
"[unparsed_xml] FILE_INFO::parse(): unrecognized: %s\n",
xp.parsed_tag
);
}
xp.skip_unexpected();
}
return ERR_XML_PARSE;
}
int FILE_INFO::write(MIOFILE& out, bool to_server) {
int retval;
char buf[1024];
if (to_server) {
out.printf("<file_info>\n");
} else {
out.printf("<file>\n");
}
out.printf(
" <name>%s</name>\n"
" <nbytes>%f</nbytes>\n"
" <max_nbytes>%f</max_nbytes>\n",
name, nbytes, max_nbytes
);
if (strlen(md5_cksum)) {
out.printf(
" <md5_cksum>%s</md5_cksum>\n",
md5_cksum
);
}
if (!to_server) {
out.printf(" <status>%d</status>\n", status);
if (executable) out.printf(" <executable/>\n");
if (uploaded) out.printf(" <uploaded/>\n");
if (sticky) out.printf(" <sticky/>\n");
if (gzip_when_done) out.printf(" <gzip_when_done/>\n");
if (download_gzipped) {
out.printf(" <download_gzipped/>\n");
out.printf(" <gzipped_nbytes>%.0f</gzipped_nbytes>\n", gzipped_nbytes);
}
if (signature_required) out.printf(" <signature_required/>\n");
if (is_user_file) out.printf(" <is_user_file/>\n");
if (strlen(file_signature)) out.printf(" <file_signature>\n%s\n</file_signature>\n", file_signature);
}
if (sticky_expire_time) {
out.printf(" <sticky_expire_time>%f</sticky_expire_time>\n",
sticky_expire_time
);
}
for (const string &s: download_urls.urls) {
xml_escape(s.c_str(), buf, sizeof(buf));
out.printf(" <download_url>%s</download_url>\n", buf);
}
for (const string &s: upload_urls.urls) {
xml_escape(s.c_str(), buf, sizeof(buf));
out.printf(" <upload_url>%s</upload_url>\n", buf);
}
if (!to_server && pers_file_xfer) {
retval = pers_file_xfer->write(out);
if (retval) return retval;
}
if (!to_server) {
if (strlen(xml_signature)) {
out.printf(
" <xml_signature>\n%s </xml_signature>\n",
xml_signature
);
}
}
if (!error_msg.empty()) {
strip_whitespace(error_msg);
out.printf(" <error_msg>\n%s\n</error_msg>\n", error_msg.c_str());
}
if (to_server) {
out.printf("</file_info>\n");
} else {
out.printf("</file>\n");
}
return 0;
}
// called only for files with a PERS_FILE_XFER
//
int FILE_INFO::write_gui(MIOFILE& out) {
out.printf(
"<file_transfer>\n"
" <project_url>%s</project_url>\n"
" <project_name>%s</project_name>\n"
" <name>%s</name>\n"
" <nbytes>%f</nbytes>\n"
" <max_nbytes>%f</max_nbytes>\n"
" <status>%d</status>\n",
project->master_url,
project->project_name,
name,
download_gzipped?gzipped_nbytes:nbytes,
max_nbytes,
status
);
pers_file_xfer->write(out);
FILE_XFER_BACKOFF& fxb = project->file_xfer_backoff(pers_file_xfer->is_upload);
if (fxb.next_xfer_time > gstate.now) {
out.printf(" <project_backoff>%f</project_backoff>\n",
fxb.next_xfer_time - gstate.now
);
}
out.printf("</file_transfer>\n");
return 0;
}
// delete physical underlying file associated with FILE_INFO
//
int FILE_INFO::delete_file() {
char path[MAXPATHLEN];
get_pathname(this, path, sizeof(path));
int retval = delete_project_owned_file(path, true);
// files with download_gzipped set may exist
// in temporary or compressed form
//
safe_strcat(path, ".gz");
delete_project_owned_file(path, true);
safe_strcat(path, "t");
delete_project_owned_file(path, true);
if (retval && status != FILE_NOT_PRESENT) {
msg_printf(project, MSG_INTERNAL_ERROR, "Couldn't delete file %s", path);
}
status = FILE_NOT_PRESENT;
return retval;
}
const char* URL_LIST::get_init_url() {
if (!urls.size()) {
return NULL;
}
// if a project supplies multiple URLs, try them in order
// (e.g. in Einstein@home they're ordered by proximity to client).
//
current_index = 0;
start_index = current_index;
return urls[current_index].c_str();
}
// Call this to get the next URL.
// NULL return means you've tried them all.
//
const char* URL_LIST::get_next_url() {
if (!urls.size()) return NULL;
while(1) {
current_index = (current_index + 1)%((int)urls.size());
if (current_index == start_index) {
return NULL;
}
return urls[current_index].c_str();
}
}
const char* URL_LIST::get_current_url(FILE_INFO& fi) {
if (current_index < 0) {
return get_init_url();
}
if (current_index >= (int)urls.size()) {
msg_printf(fi.project, MSG_INTERNAL_ERROR,
"File %s has no URL", fi.name
);
return NULL;
}
return urls[current_index].c_str();
}
// merges information from a new FILE_INFO that has the same name as one
// that is already present in the client state file.
//
int FILE_INFO::merge_info(FILE_INFO& new_info) {
char buf[256];
if (max_nbytes <= 0 && new_info.max_nbytes) {
max_nbytes = new_info.max_nbytes;
snprintf(buf, sizeof(buf), " <max_nbytes>%.0f</max_nbytes>\n", new_info.max_nbytes);
}
// replace existing URLs with new ones
//
download_urls.replace(new_info.download_urls);
upload_urls.replace(new_info.upload_urls);
download_gzipped = new_info.download_gzipped;
// replace signatures
//
if (strlen(new_info.file_signature)) {
safe_strcpy(file_signature, new_info.file_signature);
}
if (strlen(new_info.xml_signature)) {
safe_strcpy(xml_signature, new_info.xml_signature);
}
// If the file is supposed to be executable and is PRESENT,
// make sure it's actually executable.
// This deals with cases where somehow a file didn't
// get protected right when it was initially downloaded.
//
if (status == FILE_PRESENT && !executable && new_info.executable) {
msg_printf(project, MSG_INTERNAL_ERROR,
"%s has changed to executable", name
);
executable = true;
int retval = set_permissions();
if (retval) {
msg_printf(project, MSG_INTERNAL_ERROR,
"merge_info(): failed to change permissions of %s", name
);
}
return retval;
}
// sticky attributes
//
if (new_info.sticky) {
sticky = true;
if (new_info.sticky_lifetime) {
double x = gstate.now + new_info.sticky_lifetime;
if (x > sticky_expire_time) {
sticky_expire_time = x;
}
} else {
sticky_expire_time = 0;
}
} else {
sticky = false;
sticky_expire_time = 0;
}
return 0;
}
// Returns true if the file had an unrecoverable error
// (couldn't download, RSA/MD5 check failed, etc)
//
bool FILE_INFO::had_failure(int& failnum) {
switch (status) {
case FILE_NOT_PRESENT:
case FILE_PRESENT:
case FILE_VERIFY_PENDING:
return false;
}
failnum = status;
return true;
}
void FILE_INFO::failure_message(string& s) {
char buf[1024];
snprintf(buf, sizeof(buf),
"<file_xfer_error>\n"
" <file_name>%s</file_name>\n"
" <error_code>%d (%s)</error_code>\n",
name,
status, boincerror(status)
);
s = buf;
if (error_msg.size()) {
snprintf(buf, sizeof(buf),
" <error_message>%s</error_message>\n",
error_msg.c_str()
);
s = s + buf;
}
s = s + "</file_xfer_error>\n";
}
#ifndef SIM
#define BUFSIZE 16384
int FILE_INFO::gzip() {
char buf[BUFSIZE];
char inpath[MAXPATHLEN], outpath[MAXPATHLEN];
get_pathname(this, inpath, sizeof(inpath));
safe_strcpy(outpath, inpath);
safe_strcat(outpath, ".gz");
FILE* in = boinc_fopen(inpath, "rb");
if (!in) return ERR_FOPEN;
gzFile out = gzopen(outpath, "wb");
while (1) {
int n = (int)fread(buf, 1, BUFSIZE, in);
if (n <= 0) break;
int m = gzwrite(out, buf, n);
if (m != n) {
fclose(in);
gzclose(out);
return ERR_WRITE;
}
}
fclose(in);
gzclose(out);
delete_project_owned_file(inpath, true);
boinc_rename(outpath, inpath);
return 0;
}
// unzip a file, and compute the uncompressed MD5 at the same time
//
int FILE_INFO::gunzip(char* md5_buf) {
unsigned char buf[BUFSIZE];
char inpath[MAXPATHLEN], outpath[MAXPATHLEN], tmppath[MAXPATHLEN];
md5_state_t md5_state;
md5_init(&md5_state);
get_pathname(this, outpath, sizeof(outpath));
safe_strcpy(inpath, outpath);
safe_strcat(inpath, ".gz");
safe_strcpy(tmppath, outpath);
char* p = strrchr(tmppath, '/');
*(p+1) = 0;
safe_strcat(tmppath, "decompress_temp");
FILE* out = boinc_fopen(tmppath, "wb");
if (!out) return ERR_FOPEN;
gzFile in = gzopen(inpath, "rb");
while (1) {
int n = gzread(in, buf, BUFSIZE);
if (n <= 0) break;
int m = (int)fwrite(buf, 1, n, out);
if (m != n) {
gzclose(in);
fclose(out);
return ERR_WRITE;
}
md5_append(&md5_state, buf, n);
}
unsigned char binout[16];
md5_finish(&md5_state, binout);
for (int i=0; i<16; i++) {
sprintf(md5_buf+2*i, "%02x", binout[i]);
}
md5_buf[32] = 0;
gzclose(in);
fclose(out);
boinc_rename(tmppath, outpath);
delete_project_owned_file(inpath, true);
return 0;
}
#endif // SIM
void RESOURCE_USAGE::clear() {
avg_ncpus = 0;
rsc_type = 0;
coproc_usage = 0;
gpu_ram = 0;
flops = 0;
cmdline[0] = 0;
missing_coproc = false;
missing_coproc_name[0] = 0;
}
// see if we have the GPU libraries (OpenCL/CUDA/CAL)
// required by the plan class.
// If not, set missing_coproc
//
void RESOURCE_USAGE::check_gpu_libs(char* plan_class) {
int rt = rsc_type;
if (!rt) return;
if (strstr(plan_class, "opencl")) {
if (!coprocs.coprocs[rt].have_opencl) {
msg_printf(0, MSG_INFO,
"App version needs OpenCL but GPU doesn't support it"
);
missing_coproc = true;
safe_strcpy(missing_coproc_name, coprocs.coprocs[rt].type);
}
} else if (strstr(plan_class, "cuda")) {
if (!coprocs.coprocs[rt].have_cuda) {
msg_printf(0, MSG_INFO,
"App version needs CUDA but GPU doesn't support it"
);
missing_coproc = true;
safe_strcpy(missing_coproc_name, coprocs.coprocs[rt].type);
}
} else if (strstr(plan_class, "ati")) {
if (!coprocs.coprocs[rt].have_cal) {
msg_printf(0, MSG_INFO,
"App version needs CAL but GPU doesn't support it"
);
missing_coproc = true;
safe_strcpy(missing_coproc_name, coprocs.coprocs[rt].type);
}
}
}
void RESOURCE_USAGE::write(MIOFILE& out) {
out.printf(
" <avg_ncpus>%f</avg_ncpus>\n"
" <flops>%f</flops>\n",
avg_ncpus,
flops
);
if (rsc_type) {
out.printf(
" <coproc>\n"
" <type>%s</type>\n"
" <count>%f</count>\n"
" </coproc>\n",
rsc_name(rsc_type),
coproc_usage
);
}
if (missing_coproc && strlen(missing_coproc_name)) {
out.printf(
" <coproc>\n"
" <type>%s</type>\n"
" <count>%f</count>\n"
" </coproc>\n",
missing_coproc_name,
coproc_usage
);
}
if (gpu_ram) {
out.printf(
" <gpu_ram>%f</gpu_ram>\n",
gpu_ram
);
}
}
void APP_VERSION::init() {
app_name[0] = 0;
version_num = 0;
platform[0] = 0;
plan_class[0] = 0;
api_version[0] = 0;
resource_usage.clear();
file_prefix[0] = 0;
needs_network = false;
dont_throttle = false;
app = NULL;
project = NULL;
ref_cnt = 0;
graphics_exec_fip = NULL;
graphics_exec_path[0] = 0;
graphics_exec_file[0] = 0;
max_rss = 0;
is_vbox_app = false;
is_docker_app = false;
is_wrapper = false;
index = 0;
#ifdef SIM
dont_use = false;
#endif
}
// see if app version is disallowed by config
//
bool APP_VERSION::disallowed_by_config(PROJECT *p) {
if (cc_config.dont_use_vbox && strstr(plan_class, "vbox")) {
msg_printf(p, MSG_INFO,
"Skipping VirtualBox app version: disabled in cc_config.xml"
);
return true;
}
if (cc_config.dont_use_wsl && strstr(plan_class, "wsl")) {
msg_printf(p, MSG_INFO,
"skipping WSL app version: disabled in cc_config.xml"
);
return true;
}
if (cc_config.dont_use_docker && strstr(plan_class, "docker")) {
msg_printf(p, MSG_INFO,
"skipping Podman app: disabled in cc_config.xml"
);
return true;
}
return false;
}
// fill in resource usage if not already present
//
void APP_VERSION::fill_in_resource_usage() {
if (resource_usage.avg_ncpus == 0) {
resource_usage.avg_ncpus = 1;
}
if (resource_usage.flops == 0) {
resource_usage.flops = resource_usage.avg_ncpus * gstate.host_info.p_fpops;
// for GPU apps, use conservative estimate:
// assume GPU runs at 10X peak CPU speed
//
if (resource_usage.rsc_type) {
resource_usage.flops += resource_usage.coproc_usage * 10 * gstate.host_info.p_fpops;
}
}
}
// Parse an <app_version> element; called from
// 1) parse scheduler reply: scheduler_op.cpp
// 2) parse client state file: cs_statefile.cpp
// 3) parse app_info.xml for anonymous platform: cs_statefile.cpp
//
// After this you need to:
// - check if disallowed by config
// do this right away; config.xml has already been parsed
// - fill in resource usage if not specified
// In cases 2 and 3 we don't have CPU FLOPS yet,
// so we have to do this a bit later.
// In case 1 we do it right away.
//
int APP_VERSION::parse(XML_PARSER& xp) {
FILE_REF file_ref;
double dtemp;
init();
while (!xp.get_tag()) {
if (xp.match_tag("/app_version")) {
dont_throttle = false;
resource_usage.check_gpu_libs(plan_class);
if (is_wrapper) {
// fix problem where wrappers were never throttled
// can remove this in 8.5 or later
dont_throttle = false;
}
if (resource_usage.rsc_type) {
// never throttle GPU apps, even if wrapped
dont_throttle = true;
}
if (strstr(plan_class, "vbox")) {
// VBox does its own throttling
is_vbox_app = true;
dont_throttle = true;
}
if (strstr(plan_class, "docker")) {
is_docker_app = true;
}
return 0;
}
if (xp.parse_str("app_name", app_name, sizeof(app_name))) continue;
if (xp.match_tag("file_ref")) {
int retval = file_ref.parse(xp);
if (retval) {
msg_printf(0, MSG_INFO,
"couldn't parse file_ref: %s", boincerror(retval)
);
return retval;
}
app_files.push_back(file_ref);
continue;
}
if (xp.parse_int("version_num", version_num)) continue;
if (xp.parse_str("api_version", api_version, sizeof(api_version))) continue;
if (xp.parse_str("platform", platform, sizeof(platform))) continue;
if (xp.parse_str("plan_class", plan_class, sizeof(plan_class))) continue;
if (xp.parse_double("avg_ncpus", resource_usage.avg_ncpus)) continue;
if (xp.parse_double("max_ncpus", dtemp)) continue;
if (xp.parse_double("flops", dtemp)) {
if (dtemp <= 0) {
msg_printf(0, MSG_INTERNAL_ERROR,
"non-positive FLOPS in app version"
);
} else {
resource_usage.flops = dtemp;
}
continue;
}
if (xp.parse_str("cmdline", resource_usage.cmdline, sizeof(resource_usage.cmdline))) continue;
if (xp.parse_str("file_prefix", file_prefix, sizeof(file_prefix))) continue;
if (xp.parse_double("resource_usage.gpu_ram", resource_usage.gpu_ram)) continue;
if (xp.match_tag("coproc")) {
COPROC_REQ cp;