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