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