Line data Source code
1 : #include "../burp.h"
2 : #include "../alloc.h"
3 : #include "../asfd.h"
4 : #include "../async.h"
5 : #include "../cmd.h"
6 : #include "../cntr.h"
7 : #include "../fsops.h"
8 : #include "../handy.h"
9 : #include "../log.h"
10 : #include "../msg.h"
11 : #include "../sbuf.h"
12 : #include "child.h"
13 : #include "compress.h"
14 : #include "manio.h"
15 : #include "quota.h"
16 : #include "sdirs.h"
17 : #include "backup_phase1.h"
18 :
19 1 : int backup_phase1_server_all(struct async *as,
20 : struct sdirs *sdirs, struct conf **confs)
21 : {
22 1 : int ret=-1;
23 1 : struct sbuf *sb=NULL;
24 1 : char *phase1tmp=NULL;
25 1 : struct asfd *asfd=as->asfd;
26 1 : struct manio *manio=NULL;
27 1 : enum protocol protocol=get_protocol(confs);
28 1 : struct cntr *cntr=get_cntr(confs);
29 :
30 1 : logp("Begin phase1 (file system scan)\n");
31 :
32 1 : if(!(phase1tmp=get_tmp_filename(sdirs->phase1data))
33 1 : || !(manio=manio_open_phase1(phase1tmp,
34 1 : comp_level(get_int(confs[OPT_COMPRESSION])), protocol))
35 1 : || !(sb=sbuf_alloc(protocol)))
36 : goto error;
37 :
38 : while(1)
39 : {
40 1 : sbuf_free_content(sb);
41 1 : switch(sbuf_fill_from_net(sb, asfd, NULL, cntr))
42 : {
43 : case 0: break;
44 : case 1: // Last thing the client sends is
45 : // 'backupphase2', and it wants an 'ok' reply.
46 0 : if(asfd->write_str(asfd, CMD_GEN, "ok")
47 0 : || send_msg_fzp(manio->fzp, CMD_GEN,
48 : "phase1end", strlen("phase1end")))
49 : goto error;
50 : goto end;
51 : case -1:
52 : default: goto error;
53 : }
54 0 : if(write_status(CNTR_STATUS_SCANNING, sb->path.buf, cntr)
55 0 : || manio_write_sbuf(manio, sb))
56 : goto error;
57 0 : cntr_add_phase1(cntr, sb->path.cmd, 0);
58 :
59 0 : if(sbuf_is_estimatable(sb))
60 : {
61 0 : cntr_add_val(cntr, CMD_BYTES_ESTIMATED,
62 0 : (uint64_t)sb->statp.st_size);
63 : }
64 : }
65 :
66 : end:
67 0 : if(manio_close(&manio))
68 : {
69 0 : logp("error closing %s in backup_phase1_server\n", phase1tmp);
70 0 : goto error;
71 : }
72 :
73 0 : if(check_quota(as, cntr,
74 : get_uint64_t(confs[OPT_HARD_QUOTA]),
75 : get_uint64_t(confs[OPT_SOFT_QUOTA])))
76 : goto error;
77 :
78 : // Possible rename race condition is of no consequence here, because
79 : // the working directory will always get deleted if phase1 is not
80 : // complete.
81 0 : if(do_rename(phase1tmp, sdirs->phase1data))
82 : goto error;
83 :
84 : //cntr_print(p1cntr, cntr, ACTION_BACKUP);
85 :
86 0 : logp("End phase1 (file system scan)\n");
87 0 : ret=0;
88 : error:
89 1 : free_w(&phase1tmp);
90 1 : manio_close(&manio);
91 1 : sbuf_free(&sb);
92 1 : return ret;
93 : }
|