| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
2 |
| 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 |
#include "config.h" |
| 39 |
#include "tape.h" |
| 40 |
|
| 41 |
#include <errno.h> |
| 42 |
#include <fcntl.h> |
| 43 |
#include <signal.h> |
| 44 |
#include <stdio.h> |
| 45 |
#include "compat/include/compaterr.h" |
| 46 |
#include "compat/include/system.h" |
| 47 |
#include <stdlib.h> |
| 48 |
#include <string.h> |
| 49 |
#include <unistd.h> |
| 50 |
|
| 51 |
#include <sys/types.h> |
| 52 |
#include <sys/ioctl.h> |
| 53 |
#include <sys/mount.h> |
| 54 |
#ifndef BLKFLSBUF |
| 55 |
#define BLKFLSBUF _IO(0x12, 97) |
| 56 |
#endif |
| 57 |
#include <time.h> |
| 58 |
#include <sys/param.h> |
| 59 |
#include <sys/socket.h> |
| 60 |
#include <sys/wait.h> |
| 61 |
#include <sys/mtio.h> |
| 62 |
#include <ext2fs/ext2fs.h> |
| 63 |
#include "compat/include/bsdcompat.h" |
| 64 |
|
| 65 |
#include "compat/include/protocols/dumprestore.h" |
| 66 |
|
| 67 |
#include "optr.h" |
| 68 |
#include "traverse.h" |
| 69 |
#include "indexer.h" |
| 70 |
#include "slave.h" |
| 71 |
|
| 72 |
#include <et/com_err.h> |
| 73 |
#include <ext2fs/ext2_io.h> |
| 74 |
#include <stdint.h> |
| 75 |
#include <sys/syscall.h> |
| 76 |
#include "common/transformation.h" |
| 77 |
#include "common/dumprmt.h" |
| 78 |
#include "dump_globals.h" |
| 79 |
|
| 80 |
static int writesize; |
| 81 |
static long long lastspclrec = -1; |
| 82 |
static int trecno = 0; |
| 83 |
static long blocksperfiles_current; |
| 84 |
static long long blocksthisvol; |
| 85 |
static char *nexttape; |
| 86 |
static long long tapea_bytes = 0; |
| 87 |
|
| 88 |
static ssize_t dump_atomic_read (int, char *, size_t); |
| 89 |
static ssize_t dump_atomic_write (int, const char *, size_t); |
| 90 |
static void doslave (int, int, int); |
| 91 |
static void enslave (void); |
| 92 |
static void flushtape (void); |
| 93 |
static void killall (void); |
| 94 |
static void rollforward (void); |
| 95 |
|
| 96 |
static int reqsiz; |
| 97 |
|
| 98 |
struct slave_results { |
| 99 |
ssize_t unclen; |
| 100 |
ssize_t clen; |
| 101 |
}; |
| 102 |
|
| 103 |
static struct slave slaves[SLAVES+1]; |
| 104 |
|
| 105 |
static char (*nextblock)[TP_BSIZE]; |
| 106 |
|
| 107 |
static time_t tstart_volume; |
| 108 |
static long long tapea_volume; |
| 109 |
|
| 110 |
static int master; |
| 111 |
static int tenths; |
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
#include <syscall.h> |
| 120 |
#include <sched.h> |
| 121 |
#include <unistd.h> |
| 122 |
|
| 123 |
|
| 124 |
#if ! defined(SYS_clone) || ! defined (CLONE_IO) |
| 125 |
#define fork_clone_io fork |
| 126 |
#else |
| 127 |
|
| 128 |
#include <linux/version.h> |
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,49) |
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
#if defined(__s390__) || defined(__s390x__) |
| 141 |
#define CLONE_ARGS 0, SIGCHLD|CLONE_IO, NULL, NULL |
| 142 |
#else |
| 143 |
#define CLONE_ARGS SIGCHLD|CLONE_IO, 0, NULL, NULL |
| 144 |
#endif |
| 145 |
#else |
| 146 |
#define CLONE_ARGS SIGCHLD|CLONE_IO, 0 |
| 147 |
#endif |
| 148 |
pid_t fork_clone_io(void); |
| 149 |
#endif |
| 150 |
|
| 151 |
int |
| 152 |
alloctape(void) |
| 153 |
{ |
| 154 |
int pgoff = getpagesize() - 1; |
| 155 |
int i; |
| 156 |
|
| 157 |
writesize = ntrec * TP_BSIZE; |
| 158 |
reqsiz = (ntrec + 1) * sizeof(struct req); |
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
if (!blocksperfiles && !unlimited) |
| 166 |
tenths = (cartridge ? 16 : density == 625 ? 5 : 8); |
| 167 |
else { |
| 168 |
tenths = 0; |
| 169 |
density = 1; |
| 170 |
} |
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
for (i = 0; i <= SLAVES; i++) { |
| 177 |
slaves[i].rawdata = |
| 178 |
malloc((reqsiz + writesize + pgoff + TP_BSIZE)); |
| 179 |
if (slaves[i].rawdata == NULL) |
| 180 |
return(0); |
| 181 |
memset(slaves[i].rawdata, 0, reqsiz + writesize + pgoff + TP_BSIZE); |
| 182 |
slaves[i].tblock = (char (*)[TP_BSIZE]) |
| 183 |
(((intptr_t)slaves[i].rawdata + reqsiz + pgoff) & ~pgoff); |
| 184 |
slaves[i].req = (struct req *)slaves[i].tblock - ntrec - 1; |
| 185 |
memset(slaves[i].req, 0, sizeof *slaves[i].req); |
| 186 |
} |
| 187 |
slp = &slaves[0]; |
| 188 |
slp->count = 1; |
| 189 |
slp->tapea = 0; |
| 190 |
slp->firstrec = 0; |
| 191 |
nextblock = slp->tblock; |
| 192 |
return(1); |
| 193 |
} |
| 194 |
|
| 195 |
void |
| 196 |
dealloctape(void) |
| 197 |
{ |
| 198 |
int i; |
| 199 |
for (i = 0; i <= SLAVES; i++) { |
| 200 |
free(slaves[i].rawdata); |
| 201 |
} |
| 202 |
} |
| 203 |
|
| 204 |
void |
| 205 |
writerec(const void *dp, int isspcl) |
| 206 |
{ |
| 207 |
slp->req[trecno].dblk = (ext2_loff_t)0; |
| 208 |
slp->req[trecno].count = 1; |
| 209 |
slp->req[trecno].uninit = 0; |
| 210 |
|
| 211 |
*(union u_spcl *)(*(nextblock)) = *(const union u_spcl *)dp; |
| 212 |
|
| 213 |
|
| 214 |
indexer->writerec(dp, isspcl); |
| 215 |
|
| 216 |
nextblock++; |
| 217 |
if (isspcl) |
| 218 |
lastspclrec = u_spcl_c_tapea(); |
| 219 |
trecno++; |
| 220 |
u_spcl_c_tapea_add(1); |
| 221 |
if (trecno >= ntrec) |
| 222 |
flushtape(); |
| 223 |
} |
| 224 |
|
| 225 |
void |
| 226 |
dumpblock(blk64_t blkno, int size, int uninit) |
| 227 |
{ |
| 228 |
int avail, tpblks; |
| 229 |
ext2_loff_t dblkno; |
| 230 |
|
| 231 |
dblkno = fsbtodb(sblock, blkno); |
| 232 |
tpblks = size >> tp_bshift; |
| 233 |
while ((avail = MIN(tpblks, ntrec - trecno)) > 0) { |
| 234 |
slp->req[trecno].dblk = dblkno; |
| 235 |
slp->req[trecno].count = avail; |
| 236 |
slp->req[trecno].uninit = uninit; |
| 237 |
trecno += avail; |
| 238 |
u_spcl_c_tapea_add(avail); |
| 239 |
if (trecno >= ntrec) |
| 240 |
flushtape(); |
| 241 |
dblkno += avail << (tp_bshift - dev_bshift); |
| 242 |
tpblks -= avail; |
| 243 |
} |
| 244 |
} |
| 245 |
|
| 246 |
static int nogripe = 0; |
| 247 |
|
| 248 |
static void |
| 249 |
tperror(int errnum) |
| 250 |
{ |
| 251 |
|
| 252 |
if (pipeout) { |
| 253 |
msg("write error on %s: %s\n", tape, strerror(errnum)); |
| 254 |
quit("Cannot recover\n"); |
| 255 |
|
| 256 |
} |
| 257 |
msg("write error %lld blocks into volume %d: %s\n", |
| 258 |
blocksthisvol, tapeno, strerror(errnum)); |
| 259 |
broadcast("DUMP WRITE ERROR!\n"); |
| 260 |
if (query("Do you want to rewrite this volume?")) { |
| 261 |
msg("Closing this volume. Prepare to restart with new media;\n"); |
| 262 |
msg("this dump volume will be rewritten.\n"); |
| 263 |
killall(); |
| 264 |
nogripe = 1; |
| 265 |
close_rewind(); |
| 266 |
Exit(X_REWRITE); |
| 267 |
} |
| 268 |
if (query("Do you want to start the next tape?")) |
| 269 |
return; |
| 270 |
dumpabort(0); |
| 271 |
} |
| 272 |
|
| 273 |
static void |
| 274 |
sigpipe(UNUSED(int signo)) |
| 275 |
{ |
| 276 |
quit("Broken pipe\n"); |
| 277 |
} |
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
time_t |
| 284 |
do_stats(void) |
| 285 |
{ |
| 286 |
time_t tnow, ttaken; |
| 287 |
long blocks; |
| 288 |
|
| 289 |
tnow = time(NULL); |
| 290 |
ttaken = tnow - tstart_volume; |
| 291 |
blocks = u_spcl_c_tapea() - tapea_volume; |
| 292 |
msg("Volume %d completed at: %s", tapeno, ctime(&tnow)); |
| 293 |
if (! compressed) |
| 294 |
msg("Volume %d %ld blocks (%.2fMB)\n", tapeno, |
| 295 |
blocks, ((double)blocks * TP_BSIZE / 1048576)); |
| 296 |
if (ttaken > 0) { |
| 297 |
long volkb = (bytes_written - tapea_bytes) / 1024; |
| 298 |
long txfrate = volkb / ttaken; |
| 299 |
msg("Volume %d took %jd:%02jd:%02jd\n", tapeno, |
| 300 |
(intmax_t)(ttaken / 3600), (intmax_t)((ttaken % 3600) / 60), (intmax_t)(ttaken % 60)); |
| 301 |
msg("Volume %d transfer rate: %ld kB/s\n", tapeno, |
| 302 |
txfrate); |
| 303 |
xferrate += txfrate; |
| 304 |
if (compressed) { |
| 305 |
double rate = .0005 + (double) blocks / (double) volkb; |
| 306 |
msg("Volume %d %ldkB uncompressed, %ldkB compressed," |
| 307 |
" %1.3f:1\n", |
| 308 |
tapeno, blocks, volkb, rate); |
| 309 |
} |
| 310 |
} |
| 311 |
return(tnow); |
| 312 |
} |
| 313 |
|
| 314 |
char * |
| 315 |
mktimeest(time_t tnow) |
| 316 |
{ |
| 317 |
static char msgbuf[128]; |
| 318 |
time_t deltat; |
| 319 |
|
| 320 |
msgbuf[0] = '\0'; |
| 321 |
|
| 322 |
if (blockswritten < 500) |
| 323 |
return NULL; |
| 324 |
if (blockswritten > tapesize) |
| 325 |
tapesize = blockswritten; |
| 326 |
deltat = tstart_writing - tnow + (1.0 * (tnow - tstart_writing)) |
| 327 |
/ blockswritten * tapesize; |
| 328 |
if (tnow > tstart_volume) |
| 329 |
(void)snprintf(msgbuf, sizeof(msgbuf), |
| 330 |
"%3.2f%% done at %lld kB/s, finished in %d:%02d\n", |
| 331 |
(blockswritten * 100.0) / tapesize, |
| 332 |
(u_spcl_c_tapea() - tapea_volume) / (tnow - tstart_volume), |
| 333 |
(int)(deltat / 3600), (int)((deltat % 3600) / 60)); |
| 334 |
else |
| 335 |
(void)snprintf(msgbuf, sizeof(msgbuf), |
| 336 |
"%3.2f%% done, finished in %d:%02d\n", |
| 337 |
(blockswritten * 100.0) / tapesize, |
| 338 |
(int)(deltat / 3600), (int)((deltat % 3600) / 60)); |
| 339 |
|
| 340 |
return msgbuf; |
| 341 |
} |
| 342 |
|
| 343 |
#if defined(SIGINFO) |
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
void |
| 349 |
statussig(int notused) |
| 350 |
{ |
| 351 |
int save_errno = errno; |
| 352 |
char *buf; |
| 353 |
|
| 354 |
buf = mktimeest(time(NULL)); |
| 355 |
if (buf) |
| 356 |
write(STDERR_FILENO, buf, strlen(buf)); |
| 357 |
errno = save_errno; |
| 358 |
} |
| 359 |
#endif |
| 360 |
|
| 361 |
static void |
| 362 |
flushtape(void) |
| 363 |
{ |
| 364 |
int i, blks, got; |
| 365 |
long lastfirstrec; |
| 366 |
struct slave_results returned; |
| 367 |
|
| 368 |
int siz = (char *)nextblock - (char *)slp->req; |
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
returned.unclen = returned.clen = writesize; |
| 373 |
|
| 374 |
slp->req[trecno].count = 0; |
| 375 |
|
| 376 |
if (dump_atomic_write( slp->fd, (char *)slp->req, siz) != siz) |
| 377 |
quit("error writing command pipe: %s\n", strerror(errno)); |
| 378 |
|
| 379 |
slp->sent = 1; |
| 380 |
|
| 381 |
lastfirstrec = slp->firstrec; |
| 382 |
|
| 383 |
if (++slp >= &slaves[SLAVES]) |
| 384 |
slp = &slaves[0]; |
| 385 |
|
| 386 |
|
| 387 |
if (slp->sent) { |
| 388 |
if (dump_atomic_read( slp->fd, (char *)&returned, sizeof returned) |
| 389 |
!= sizeof returned) { |
| 390 |
perror(" DUMP: error reading command pipe in master"); |
| 391 |
dumpabort(0); |
| 392 |
} |
| 393 |
got = returned.unclen; |
| 394 |
bytes_written += returned.clen; |
| 395 |
if (returned.unclen == returned.clen) |
| 396 |
uncomprblks++; |
| 397 |
slp->sent = 0; |
| 398 |
|
| 399 |
|
| 400 |
if (got <= 0) { |
| 401 |
|
| 402 |
if (got < 0) |
| 403 |
tperror(-got); |
| 404 |
else |
| 405 |
msg("End of tape detected\n"); |
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
for (i = 0; i < SLAVES; i++) { |
| 412 |
if (slaves[i].sent) { |
| 413 |
if (dump_atomic_read( slaves[i].fd, |
| 414 |
(char *)&returned, sizeof returned) |
| 415 |
!= sizeof returned) { |
| 416 |
perror(" DUMP: error reading command pipe in master"); |
| 417 |
dumpabort(0); |
| 418 |
} |
| 419 |
slaves[i].sent = 0; |
| 420 |
} |
| 421 |
} |
| 422 |
|
| 423 |
close_rewind(); |
| 424 |
rollforward(); |
| 425 |
return; |
| 426 |
} |
| 427 |
} |
| 428 |
|
| 429 |
blks = 0; |
| 430 |
if (spcl.c_type == TS_CLRI || spcl.c_type == TS_BITS) |
| 431 |
blks = spcl.c_count; |
| 432 |
else { |
| 433 |
if (spcl.c_type != TS_END) { |
| 434 |
for (i = 0; i < spcl.c_count; i++) |
| 435 |
if (spcl.c_addr[i] != 0) |
| 436 |
blks++; |
| 437 |
} |
| 438 |
} |
| 439 |
slp->count = lastspclrec + blks + 1 - u_spcl_c_tapea(); |
| 440 |
slp->tapea = u_spcl_c_tapea(); |
| 441 |
slp->firstrec = lastfirstrec + ntrec; |
| 442 |
slp->inode = curino; |
| 443 |
nextblock = slp->tblock; |
| 444 |
trecno = 0; |
| 445 |
asize += tenths + returned.clen / density; |
| 446 |
blockswritten += ntrec; |
| 447 |
blocksthisvol += ntrec; |
| 448 |
if (!pipeout && !unlimited) { |
| 449 |
if (blocksperfiles && blocksperfiles[blocksperfiles_current]) { |
| 450 |
if ( compressed ? (bytes_written - tapea_bytes + SLAVES * (writesize + sizeof(struct tapebuf)))*1ULL >= ((blocksperfiles[blocksperfiles_current]) * 1024ULL) |
| 451 |
: blocksthisvol >= blocksperfiles[blocksperfiles_current] ) { |
| 452 |
close_rewind(); |
| 453 |
startnewtape(0); |
| 454 |
} |
| 455 |
} |
| 456 |
else if (asize > tsize) { |
| 457 |
close_rewind(); |
| 458 |
startnewtape(0); |
| 459 |
} |
| 460 |
} |
| 461 |
timeest(); |
| 462 |
} |
| 463 |
|
| 464 |
time_t |
| 465 |
trewind(void) |
| 466 |
{ |
| 467 |
int f; |
| 468 |
int got; |
| 469 |
struct slave_results returned; |
| 470 |
|
| 471 |
for (f = 0; f < SLAVES; f++) { |
| 472 |
|
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
|
| 478 |
|
| 479 |
|
| 480 |
if (slaves[f].sent) { |
| 481 |
if (dump_atomic_read( slaves[f].fd, (char *)&returned, sizeof returned) |
| 482 |
!= sizeof returned) { |
| 483 |
perror(" DUMP: error reading command pipe in master"); |
| 484 |
dumpabort(0); |
| 485 |
} |
| 486 |
got = returned.unclen; |
| 487 |
bytes_written += returned.clen; |
| 488 |
if (returned.unclen == returned.clen) |
| 489 |
uncomprblks++; |
| 490 |
slaves[f].sent = 0; |
| 491 |
|
| 492 |
if (got < 0) |
| 493 |
tperror(-got); |
| 494 |
|
| 495 |
if (got == 0) { |
| 496 |
msg("EOT detected in last 2 tape records!\n"); |
| 497 |
msg("Use a longer tape, decrease the size estimate\n"); |
| 498 |
quit("or use no size estimate at all.\n"); |
| 499 |
} |
| 500 |
} |
| 501 |
(void) close(slaves[f].fd); |
| 502 |
} |
| 503 |
while (wait((int *)NULL) >= 0) |
| 504 |
; |
| 505 |
|
| 506 |
if (!pipeout) { |
| 507 |
|
| 508 |
msg("Closing %s\n", tape); |
| 509 |
|
| 510 |
if (host) { |
| 511 |
rmtclose(); |
| 512 |
while (rmtopen(tape, O_RDONLY) < 0) |
| 513 |
sleep(10); |
| 514 |
rmtclose(); |
| 515 |
} else { |
| 516 |
(void) close(tapefd); |
| 517 |
if (!fifoout) { |
| 518 |
while ((f = open(tape, O_RDONLY)) < 0) |
| 519 |
sleep (10); |
| 520 |
(void) close(f); |
| 521 |
} |
| 522 |
} |
| 523 |
} |
| 524 |
return do_stats(); |
| 525 |
} |
| 526 |
|
| 527 |
|
| 528 |
void |
| 529 |
close_rewind(void) |
| 530 |
{ |
| 531 |
int eot_code = 1; |
| 532 |
(void)trewind(); |
| 533 |
if (eot_script) { |
| 534 |
msg("Launching %s\n", eot_script); |
| 535 |
eot_code = system_command(eot_script, tape, tapeno); |
| 536 |
} |
| 537 |
if (eot_code != 0 && eot_code != 1) { |
| 538 |
msg("Dump aborted by the end of tape script\n"); |
| 539 |
dumpabort(0); |
| 540 |
} |
| 541 |
if (eot_code == 0) |
| 542 |
return; |
| 543 |
if (nexttape || Mflag) |
| 544 |
return; |
| 545 |
if (!nogripe) { |
| 546 |
msg("Change Volumes: Mount volume #%d\n", tapeno+1); |
| 547 |
broadcast("CHANGE DUMP VOLUMES!\7\7\n"); |
| 548 |
} |
| 549 |
while (!query("Is the new volume mounted and ready to go?")) |
| 550 |
if (query("Do you want to abort?")) { |
| 551 |
dumpabort(0); |
| 552 |
|
| 553 |
} |
| 554 |
} |
| 555 |
|
| 556 |
void |
| 557 |
rollforward(void) |
| 558 |
{ |
| 559 |
struct req *p, *q = NULL, *prev; |
| 560 |
struct slave *tslp; |
| 561 |
int i, size, got; |
| 562 |
long savedtapea; |
| 563 |
union u_spcl *ntb, *otb; |
| 564 |
struct slave_results returned; |
| 565 |
long blks; |
| 566 |
long lastfirstrec; |
| 567 |
tslp = &slaves[SLAVES]; |
| 568 |
ntb = (union u_spcl *)tslp->tblock[1]; |
| 569 |
|
| 570 |
|
| 571 |
|
| 572 |
returned.unclen = returned.clen = writesize; |
| 573 |
|
| 574 |
|
| 575 |
|
| 576 |
|
| 577 |
|
| 578 |
|
| 579 |
|
| 580 |
for (i = 0; i < SLAVES; i++) { |
| 581 |
q = &tslp->req[1]; |
| 582 |
otb = (union u_spcl *)slp->tblock; |
| 583 |
|
| 584 |
|
| 585 |
|
| 586 |
|
| 587 |
|
| 588 |
prev = NULL; |
| 589 |
for (p = slp->req; p->count > 0; p += p->count) { |
| 590 |
*q = *p; |
| 591 |
if (p->dblk == 0) |
| 592 |
*ntb++ = *otb++; |
| 593 |
prev = q; |
| 594 |
q += q->count; |
| 595 |
} |
| 596 |
if (prev == NULL) |
| 597 |
quit("rollforward: protocol botch"); |
| 598 |
if (prev->dblk != 0) |
| 599 |
prev->count -= 1; |
| 600 |
else |
| 601 |
ntb--; |
| 602 |
q -= 1; |
| 603 |
q->count = 0; |
| 604 |
q = &tslp->req[0]; |
| 605 |
if (i == 0) { |
| 606 |
q->dblk = 0; |
| 607 |
q->count = 1; |
| 608 |
trecno = 0; |
| 609 |
nextblock = tslp->tblock; |
| 610 |
savedtapea = u_spcl_c_tapea(); |
| 611 |
u_spcl_c_tapea_set(slp->tapea); |
| 612 |
startnewtape(0); |
| 613 |
u_spcl_c_tapea_set(savedtapea); |
| 614 |
lastspclrec = savedtapea - 1; |
| 615 |
} |
| 616 |
size = (char *)ntb - (char *)q; |
| 617 |
if (dump_atomic_write( slp->fd, (char *)q, size) != size) { |
| 618 |
perror(" DUMP: error writing command pipe"); |
| 619 |
dumpabort(0); |
| 620 |
} |
| 621 |
slp->sent = 1; |
| 622 |
lastfirstrec = slp->firstrec; |
| 623 |
if (++slp >= &slaves[SLAVES]) |
| 624 |
slp = &slaves[0]; |
| 625 |
|
| 626 |
q->count = 1; |
| 627 |
|
| 628 |
if (prev->dblk != 0) { |
| 629 |
|
| 630 |
|
| 631 |
|
| 632 |
|
| 633 |
|
| 634 |
q->dblk = prev->dblk + |
| 635 |
prev->count * (TP_BSIZE / DEV_BSIZE); |
| 636 |
ntb = (union u_spcl *)tslp->tblock; |
| 637 |
} else { |
| 638 |
|
| 639 |
|
| 640 |
|
| 641 |
|
| 642 |
q->dblk = 0; |
| 643 |
*((union u_spcl *)tslp->tblock) = *ntb; |
| 644 |
ntb = (union u_spcl *)tslp->tblock[1]; |
| 645 |
} |
| 646 |
} |
| 647 |
slp->req[0] = *q; |
| 648 |
nextblock = slp->tblock; |
| 649 |
if (q->dblk == 0) { |
| 650 |
|
| 651 |
*(union u_spcl *)(*nextblock) = *(union u_spcl *)tslp->tblock; |
| 652 |
nextblock++; |
| 653 |
} |
| 654 |
trecno = 1; |
| 655 |
|
| 656 |
|
| 657 |
|
| 658 |
|
| 659 |
|
| 660 |
if (slp->sent) { |
| 661 |
if (dump_atomic_read( slp->fd, (char *)&returned, sizeof returned) |
| 662 |
!= sizeof returned) { |
| 663 |
perror(" DUMP: error reading command pipe in master"); |
| 664 |
dumpabort(0); |
| 665 |
} |
| 666 |
got = returned.unclen; |
| 667 |
bytes_written += returned.clen; |
| 668 |
if (returned.clen == returned.unclen) |
| 669 |
uncomprblks++; |
| 670 |
slp->sent = 0; |
| 671 |
|
| 672 |
if (got < 0) |
| 673 |
tperror(-got); |
| 674 |
|
| 675 |
if (got == 0) { |
| 676 |
quit("EOT detected at start of the tape!\n"); |
| 677 |
} |
| 678 |
} |
| 679 |
|
| 680 |
blks = 0; |
| 681 |
if (spcl.c_type != TS_END) { |
| 682 |
for (i = 0; i < spcl.c_count; i++) |
| 683 |
if (spcl.c_addr[i] != 0) |
| 684 |
blks++; |
| 685 |
} |
| 686 |
|
| 687 |
slp->firstrec = lastfirstrec + ntrec; |
| 688 |
slp->count = lastspclrec + blks + 1 - u_spcl_c_tapea(); |
| 689 |
slp->inode = curino; |
| 690 |
asize += tenths + returned.clen / density; |
| 691 |
blockswritten += ntrec; |
| 692 |
blocksthisvol += ntrec; |
| 693 |
} |
| 694 |
|
| 695 |
#if defined(SYS_clone) && defined(CLONE_IO) |
| 696 |
pid_t |
| 697 |
fork_clone_io(void) |
| 698 |
{ |
| •699 |
pid_t res,parent; |
| 700 |
parent=getppid(); |
| 701 |
|
| 702 |
res=syscall(SYS_clone, CLONE_ARGS); |
| 703 |
getppid(); |
| 704 |
|
| 705 |
getpid(); |
| 706 |
#ifdef __alpha__ |
| 707 |
syscall(SYS_getxpid); |
| 708 |
#else |
| 709 |
syscall(SYS_getpid); |
| 710 |
#endif |
| 711 |
|
| 712 |
|
| 713 |
|
| 714 |
|
| 715 |
return parent==getppid()?res:0; |
| 716 |
|
| 717 |
} |
| 718 |
#endif |
| 719 |
|
| 720 |
|
| 721 |
|
| 722 |
|
| 723 |
|
| 724 |
|
| 725 |
|
| 726 |
|
| 727 |
|
| 728 |
|
| 729 |
void |
| 730 |
startnewtape(int top) |
| 731 |
{ |
| 732 |
int parentpid; |
| 733 |
int childpid; |
| 734 |
int status; |
| 735 |
int waitpid; |
| 736 |
char *p; |
| 737 |
|
| 738 |
sigset_t sigs; |
| 739 |
sigemptyset(&sigs); |
| 740 |
sigaddset(&sigs, SIGINT); |
| 741 |
sigprocmask(SIG_BLOCK, &sigs, NULL); |
| 742 |
|
| 743 |
parentpid = getpid(); |
| 744 |
tapea_volume = u_spcl_c_tapea(); |
| 745 |
tapea_bytes = bytes_written; |
| 746 |
tstart_volume = time(NULL); |
| 747 |
|
| 748 |
restore_check_point: |
| 749 |
sigprocmask(SIG_UNBLOCK, &sigs, NULL); |
| 750 |
|
| 751 |
|
| 752 |
|
| 753 |
childpid = fork_clone_io(); |
| 754 |
if (childpid < 0) { |
| 755 |
msg("Context save fork fails in parent %d\n", parentpid); |
| 756 |
Exit(X_ABORT); |
| 757 |
} |
| 758 |
if (childpid != 0) { |
| 759 |
|
| 760 |
|
| 761 |
|
| 762 |
|
| 763 |
|
| 764 |
|
| 765 |
sigprocmask(SIG_BLOCK, &sigs, NULL); |
| 766 |
Dmsg(TDEBUG, "Tape: %d; parent process: %d child process %d\n", |
| 767 |
tapeno+1, parentpid, childpid); |
| 768 |
while ((waitpid = wait(&status)) != childpid) |
| 769 |
if (waitpid != rshpid) |
| 770 |
msg("Parent %d waiting for child %d has another child %d return\n", |
| 771 |
parentpid, childpid, waitpid); |
| 772 |
if (status & 0xFF) { |
| 773 |
msg("Child %d returns LOB status %o\n", |
| 774 |
childpid, status&0xFF); |
| 775 |
} |
| 776 |
status = (status >> 8) & 0xFF; |
| 777 |
switch(status) { |
| 778 |
case X_FINOK: |
| 779 |
Dmsg(TDEBUG, "Child %d finishes X_FINOK\n", childpid); |
| 780 |
break; |
| 781 |
case X_ABORT: |
| 782 |
Dmsg(TDEBUG, "Child %d finishes X_ABORT\n", childpid); |
| 783 |
break; |
| 784 |
case X_REWRITE: |
| 785 |
Dmsg(TDEBUG, "Child %d finishes X_REWRITE\n", childpid); |
| 786 |
break; |
| 787 |
default: |
| 788 |
msg("Child %d finishes unknown %d\n", |
| 789 |
childpid, status); |
| 790 |
break; |
| 791 |
} |
| 792 |
switch(status) { |
| 793 |
case X_FINOK: |
| 794 |
Exit(X_FINOK); |
| 795 |
case X_ABORT: |
| 796 |
Exit(X_ABORT); |
| 797 |
case X_REWRITE: |
| 798 |
goto restore_check_point; |
| 799 |
default: |
| 800 |
msg("Bad return code from dump: %d\n", status); |
| 801 |
Exit(X_ABORT); |
| 802 |
} |
| 803 |
|
| 804 |
} else { |
| 805 |
Dmsg(TDEBUG, "Child on Tape %d has parent %d, my pid = %d\n", |
| 806 |
tapeno+1, parentpid, getpid()); |
| 807 |
|
| 808 |
|
| 809 |
|
| 810 |
|
| 811 |
|
| 812 |
tapeno++; |
| 813 |
if (Mflag) { |
| 814 |
snprintf(tape, MAXPATHLEN, "%s%03d", tapeprefix, tapeno); |
| 815 |
tape[MAXPATHLEN - 1] = '\0'; |
| 816 |
msg("Dumping volume %d on %s\n", tapeno, tape); |
| 817 |
} |
| 818 |
else if (nexttape || strchr(tapeprefix, ',')) { |
| 819 |
if (nexttape && *nexttape) |
| 820 |
tapeprefix = nexttape; |
| 821 |
if ((p = strchr(tapeprefix, ',')) != NULL) { |
| 822 |
*p = '\0'; |
| 823 |
nexttape = p + 1; |
| 824 |
} else |
| 825 |
nexttape = NULL; |
| 826 |
strncpy(tape, tapeprefix, MAXPATHLEN); |
| 827 |
tape[MAXPATHLEN - 1] = '\0'; |
| 828 |
msg("Dumping volume %d on %s\n", tapeno, tape); |
| 829 |
} |
| 830 |
if (blocksperfiles && blocksperfiles_current < *blocksperfiles) |
| 831 |
blocksperfiles_current++; |
| 832 |
while ((tapefd = (host ? rmtopen(tape, O_WRONLY|O_CREAT|O_TRUNC) : pipeout ? |
| 833 |
fileno(stdout) : |
| 834 |
open(tape, O_WRONLY|O_CREAT|O_TRUNC, 0666))) < 0) |
| 835 |
{ |
| 836 |
msg("Cannot open output \"%s\": %s\n", tape, |
| 837 |
strerror(errno)); |
| 838 |
if (!query("Do you want to retry the open?")) |
| 839 |
dumpabort(0); |
| 840 |
} |
| 841 |
if (!host) { |
| 842 |
struct mtget mt_stat; |
| 843 |
magtapeout = ioctl(tapefd, MTIOCGET, (char *)&mt_stat) == 0; |
| 844 |
|
| 845 |
|
| 846 |
|
| 847 |
|
| 848 |
} |
| 849 |
|
| 850 |
enslave(); |
| 851 |
|
| 852 |
asize = 0; |
| 853 |
blocksthisvol = 0; |
| 854 |
if (top) |
| 855 |
newtape++; |
| 856 |
spcl.c_count = slp->count; |
| 857 |
|
| 858 |
|
| 859 |
|
| 860 |
|
| 861 |
u_spcl_c_firstrec_set(slp->firstrec); |
| 862 |
spcl.c_volume++; |
| 863 |
spcl.c_type = TS_TAPE; |
| 864 |
spcl.c_flags |= DR_NEWHEADER; |
| 865 |
spcl.c_ntrec = ntrec; |
| 866 |
if (compressed) |
| 867 |
spcl.c_flags |= DR_COMPRESSED; |
| 868 |
writeheader((dump_ino_t)slp->inode); |
| 869 |
spcl.c_flags &=~ DR_NEWHEADER; |
| 870 |
msg("Volume %d started with block %lld at: %s", tapeno, |
| 871 |
u_spcl_c_tapea(), ctime(&tstart_volume)); |
| 872 |
if (tapeno > 1) |
| 873 |
msg("Volume %d begins with blocks from inode %d\n", |
| 874 |
tapeno, slp->inode); |
| 875 |
if (tapeno < (int)TP_NINOS) |
| 876 |
volinfo[tapeno] = slp->inode; |
| 877 |
transformation->startNewTape(transformation, NULL, 0); |
| 878 |
} |
| 879 |
} |
| 880 |
|
| 881 |
void |
| 882 |
dumpabort(UNUSED(int signo)) |
| 883 |
{ |
| 884 |
|
| 885 |
if (master != 0 && master != getpid()) |
| 886 |
|
| 887 |
(void) kill(master, SIGTERM); |
| 888 |
else { |
| 889 |
killall(); |
| 890 |
msg("The ENTIRE dump is aborted.\n"); |
| 891 |
} |
| 892 |
rmtclose(); |
| 893 |
Exit(X_ABORT); |
| 894 |
} |
| 895 |
|
| 896 |
void |
| 897 |
Exit(int status) |
| 898 |
{ |
| 899 |
|
| 900 |
Dmsg(TDEBUG, "pid = %d exits with status %d\n", getpid(), status); |
| 901 |
exit(status); |
| 902 |
} |
| 903 |
|
| 904 |
|
| 905 |
|
| 906 |
|
| 907 |
static void |
| 908 |
proceed(UNUSED(int signo)) |
| 909 |
{ |
| 910 |
} |
| 911 |
|
| 912 |
void |
| 913 |
enslave(void) |
| 914 |
{ |
| 915 |
int cmd[2]; |
| 916 |
int i, j; |
| 917 |
|
| 918 |
master = getpid(); |
| 919 |
|
| 920 |
{ struct sigaction sa; |
| 921 |
memset(&sa, 0, sizeof sa); |
| 922 |
sigemptyset(&sa.sa_mask); |
| 923 |
sa.sa_handler = dumpabort; |
| 924 |
sigaction(SIGTERM, &sa, NULL); |
| 925 |
sa.sa_handler = sigpipe; |
| 926 |
sigaction(SIGPIPE, &sa, NULL); |
| 927 |
sa.sa_handler = proceed; |
| 928 |
sa.sa_flags = SA_RESTART; |
| 929 |
sigaction(SIGUSR1, &sa, NULL); |
| 930 |
sa.sa_handler = proceed; |
| 931 |
sa.sa_flags = SA_RESTART; |
| 932 |
sigaction(SIGUSR2, &sa, NULL); |
| 933 |
} |
| 934 |
|
| 935 |
for (i = 0; i < SLAVES; i++) { |
| 936 |
|
| 937 |
if (socketpair(AF_UNIX, SOCK_STREAM, 0, cmd) < 0 || |
| 938 |
(slaves[i].pid = fork_clone_io()) < 0) |
| 939 |
quit("too many slaves, %d (recompile smaller): %s\n", |
| 940 |
i, strerror(errno)); |
| 941 |
|
| 942 |
slaves[i].fd = cmd[1]; |
| 943 |
slaves[i].sent = 0; |
| 944 |
if (slaves[i].pid == 0) { |
| 945 |
sigset_t sigs; |
| 946 |
for (j = 0; j <= i; j++) |
| 947 |
(void) close(slaves[j].fd); |
| 948 |
sigemptyset(&sigs); |
| 949 |
sigaddset(&sigs, SIGINT); |
| 950 |
sigaddset(&sigs, SIGUSR1); |
| 951 |
sigaddset(&sigs, SIGUSR2); |
| 952 |
#if defined(SIGINFO) |
| 953 |
sigaddset(&sigs, SIGINFO); |
| 954 |
#endif |
| 955 |
sigprocmask(SIG_BLOCK, &sigs, NULL); |
| 956 |
|
| 957 |
|
| 958 |
if (dump_atomic_write( cmd[0], (char *) &i, sizeof i) |
| 959 |
!= sizeof i) |
| 960 |
quit("master/slave protocol botched 3\n"); |
| 961 |
|
| 962 |
doslave(cmd[0], |
| 963 |
i, |
| 964 |
(slaves[i].pid == slp->pid)); |
| 965 |
Exit(X_FINOK); |
| 966 |
} |
| 967 |
else |
| 968 |
close(cmd[0]); |
| 969 |
} |
| 970 |
|
| 971 |
for (j = 0; j < SLAVES; j++) { |
| 972 |
|
| 973 |
if (dump_atomic_read( slaves[j].fd, (char *) &i, sizeof i) != sizeof i) |
| 974 |
quit("master/slave protocol botched 4\n"); |
| 975 |
if (dump_atomic_write( slaves[j].fd, |
| 976 |
(char *) &slaves[(j + 1) % SLAVES].pid, |
| 977 |
sizeof slaves[0].pid) != sizeof slaves[0].pid) |
| 978 |
quit("master/slave protocol botched 5\n"); |
| 979 |
if (j == slp - &slaves[0]) { |
| 980 |
|
| 981 |
(void) kill(slaves[j].pid, SIGUSR1); |
| 982 |
(void) kill(slaves[j].pid, SIGUSR2); |
| 983 |
} |
| 984 |
} |
| 985 |
|
| 986 |
master = 0; |
| 987 |
} |
| 988 |
|
| 989 |
void |
| 990 |
killall(void) |
| 991 |
{ |
| 992 |
int i; |
| 993 |
|
| 994 |
for (i = 0; i < SLAVES; i++) |
| 995 |
if (slaves[i].pid > 0) { |
| 996 |
(void) kill(slaves[i].pid, SIGKILL); |
| 997 |
slaves[i].sent = 0; |
| 998 |
} |
| 999 |
} |
| 1000 |
|
| 1001 |
|
| 1002 |
|
| 1003 |
|
| 1004 |
|
| 1005 |
|
| 1006 |
|
| 1007 |
|
| 1008 |
|
| 1009 |
|
| 1010 |
static void |
| 1011 |
doslave(int cmd, |
| 1012 |
int slave_number, |
| 1013 |
#if defined(HAVE_BLOCK_TRANSFORMATION) |
| 1014 |
int first |
| 1015 |
#else |
| 1016 |
UNUSED(int first) |
| 1017 |
#endif |
| 1018 |
) |
| 1019 |
{ |
| 1020 |
int nread; |
| 1021 |
int nextslave; |
| 1022 |
volatile int wrote = 0, size, eot_count, bufsize; |
| 1023 |
char * volatile buffer; |
| 1024 |
#if defined(HAVE_BLOCK_TRANSFORMATION) |
| 1025 |
struct tapebuf * volatile comp_buf = NULL; |
| 1026 |
int compresult; |
| 1027 |
volatile int do_compress = !first; |
| 1028 |
unsigned long worklen; |
| 1029 |
#endif |
| 1030 |
|
| 1031 |
struct slave_results returns; |
| 1032 |
errcode_t retval; |
| 1033 |
#ifdef USE_QFA |
| 1034 |
QFA_State qfa_state; |
| 1035 |
#endif |
| 1036 |
sigset_t set; |
| 1037 |
|
| 1038 |
#ifdef HAVE_BLOCK_TRANSFORMATION |
| 1039 |
transformation->startDiskIOProcess(transformation); |
| 1040 |
#endif |
| 1041 |
|
| 1042 |
#ifdef USE_QFA |
| 1043 |
indexer->openQfaState(&qfa_state); |
| 1044 |
#endif |
| 1045 |
|
| 1046 |
|
| 1047 |
|
| 1048 |
|
| 1049 |
(void) close(diskfd); |
| 1050 |
if ((diskfd = open(disk, O_RDONLY)) < 0) |
| 1051 |
quit("slave couldn't reopen disk: %s\n", strerror(errno)); |
| 1052 |
#ifdef BLKFLSBUF |
| 1053 |
(void)ioctl(diskfd, BLKFLSBUF, 0); |
| 1054 |
#endif |
| 1055 |
ext2fs_close(fs); |
| 1056 |
retval = dump_fs_open(disk, &fs); |
| 1057 |
if (retval) |
| 1058 |
quit("slave couldn't reopen disk: %s\n", error_message(retval)); |
| 1059 |
|
| 1060 |
|
| 1061 |
|
| 1062 |
|
| 1063 |
if ((nread = dump_atomic_read( cmd, (char *)&nextslave, sizeof nextslave)) |
| 1064 |
!= sizeof nextslave) { |
| 1065 |
quit("master/slave protocol botched - didn't get pid of next slave.\n"); |
| 1066 |
} |
| 1067 |
|
| 1068 |
#if defined(HAVE_BLOCK_TRANSFORMATION) |
| 1069 |
|
| 1070 |
if (compressed) { |
| 1071 |
int bsiz = sizeof(struct tapebuf) + writesize; |
| 1072 |
|
| 1073 |
if (TP_BSIZE > writesize/16 + 200) |
| 1074 |
bsiz += TP_BSIZE; |
| 1075 |
else |
| 1076 |
bsiz += writesize/16 + 200; |
| 1077 |
comp_buf = malloc(bsiz); |
| 1078 |
if (comp_buf == NULL) |
| 1079 |
quit("couldn't allocate a compress buffer.\n"); |
| 1080 |
transformation->initialize(transformation, 1); |
| 1081 |
switch(zipflag) { |
| 1082 |
case COMPRESS_ZLIB: |
| 1083 |
case COMPRESS_BZLIB: |
| 1084 |
case COMPRESS_LZO: |
| 1085 |
tapebuf_setflags(comp_buf, zipflag); |
| 1086 |
break; |
| 1087 |
default: |
| 1088 |
quit("internal error - unknown compression method: %d\n", zipflag); |
| 1089 |
} |
| 1090 |
} |
| 1091 |
#endif |
| 1092 |
|
| 1093 |
|
| 1094 |
|
| 1095 |
|
| 1096 |
while ((nread = dump_atomic_read( cmd, (char *)slp->req, reqsiz)) == reqsiz) { |
| 1097 |
|
| 1098 |
sigfillset(&set); |
| 1099 |
sigdelset(&set, SIGUSR1); |
| 1100 |
sigsuspend(&set); |
| 1101 |
|
| 1102 |
struct req *p = slp->req; |
| 1103 |
|
| 1104 |
for (trecno = 0; trecno < ntrec; |
| 1105 |
trecno += p->count, p += p->count) { |
| 1106 |
|
| 1107 |
if (p->dblk) { |
| 1108 |
if(p->uninit) { |
| 1109 |
memset(slp->tblock[trecno], 0, p->count * TP_BSIZE); |
| 1110 |
} else { |
| 1111 |
bread(p->dblk, slp->tblock[trecno], |
| 1112 |
p->count * TP_BSIZE); |
| 1113 |
} |
| 1114 |
} else { |
| 1115 |
if (p->count != 1 || dump_atomic_read( cmd, |
| 1116 |
(char *)slp->tblock[trecno], |
| 1117 |
TP_BSIZE) != TP_BSIZE) |
| 1118 |
quit("master/slave protocol botched.\n"); |
| 1119 |
} |
| 1120 |
} |
| 1121 |
|
| 1122 |
(void) kill(nextslave, SIGUSR1); |
| 1123 |
|
| 1124 |
|
| 1125 |
wrote = 0; |
| 1126 |
eot_count = 0; |
| 1127 |
size = 0; |
| 1128 |
buffer = (char *) slp->tblock[0]; |
| 1129 |
bufsize = writesize; |
| 1130 |
returns.clen = returns.unclen = bufsize; |
| 1131 |
|
| 1132 |
#if defined(HAVE_BLOCK_TRANSFORMATION) |
| 1133 |
|
| 1134 |
|
| 1135 |
|
| 1136 |
|
| 1137 |
|
| 1138 |
|
| 1139 |
|
| 1140 |
|
| 1141 |
|
| 1142 |
|
| 1143 |
|
| 1144 |
|
| 1145 |
if (compressed && do_compress) { |
| 1146 |
tapebuf_setlength(comp_buf, bufsize); |
| 1147 |
worklen = TP_BSIZE + writesize; |
| 1148 |
compresult = 1; |
| 1149 |
|
| 1150 |
|
| 1151 |
compresult = transformation->compress(transformation, comp_buf, |
| 1152 |
&worklen, slp->tblock[0], writesize); |
| 1153 |
if (compresult && (ssize_t)worklen <= writesize - 16) { |
| 1154 |
|
| 1155 |
tapebuf_setlength(comp_buf, worklen); |
| 1156 |
tapebuf_setcompressed(comp_buf, 1); |
| 1157 |
buffer = (char *) comp_buf; |
| 1158 |
returns.clen = bufsize = worklen + sizeof(struct tapebuf); |
| 1159 |
} |
| 1160 |
else { |
| 1161 |
|
| 1162 |
tapebuf_setlength(comp_buf, writesize); |
| 1163 |
tapebuf_setcompressed(comp_buf, 0); |
| 1164 |
buffer = (char *) comp_buf; |
| 1165 |
returns.clen = bufsize = writesize + sizeof(struct tapebuf); |
| 1166 |
returns.unclen = returns.clen; |
| 1167 |
memcpy(comp_buf->buf, (char *)slp->tblock[0], writesize); |
| 1168 |
} |
| 1169 |
} |
| 1170 |
|
| 1171 |
do_compress = compressed; |
| 1172 |
#endif |
| 1173 |
|
| 1174 |
sigfillset(&set); |
| 1175 |
sigdelset(&set, SIGUSR2); |
| 1176 |
sigsuspend(&set); |
| 1177 |
|
| 1178 |
#ifdef USE_QFA |
| 1179 |
indexer->updateQfa(&qfa_state); |
| 1180 |
#endif |
| 1181 |
|
| 1182 |
int bytes_to_write = bufsize - size; |
| 1183 |
while (eot_count < 10 && size < bufsize) { |
| 1184 |
if (host) |
| 1185 |
wrote = rmtwrite(buffer + size, bytes_to_write); |
| 1186 |
else |
| 1187 |
wrote = write(tapefd, buffer + size, bytes_to_write); |
| 1188 |
Dmsg(WRITEDEBUG, "slave %d wrote %d\n", slave_number, wrote); |
| 1189 |
|
| 1190 |
|
| 1191 |
if (wrote < 0 && size==0 && bytes_to_write > ntrec*TP_BSIZE) { |
| 1192 |
warnx("Incompressible block could not be written to tape. Splitting it"); |
| 1193 |
bytes_to_write = ntrec*TP_BSIZE; |
| 1194 |
} else if (wrote < 0 && errno != ENOSPC) |
| 1195 |
break; |
| 1196 |
if (wrote == 0 || (wrote < 0 && errno == ENOSPC)) { |
| 1197 |
eot_count++; |
| 1198 |
} |
| 1199 |
else if (wrote > 0) { |
| 1200 |
size += wrote; |
| 1201 |
bytes_to_write = bufsize - size; |
| 1202 |
} |
| 1203 |
} |
| 1204 |
|
| 1205 |
if (size != bufsize) |
| 1206 |
Dmsg(WRITEDEBUG, "slave %d only wrote %d out of %d bytes and gave up.\n", |
| 1207 |
slave_number, size, bufsize); |
| 1208 |
|
| 1209 |
|
| 1210 |
|
| 1211 |
|
| 1212 |
if (wrote < 0 && errno == ENOSPC) { |
| 1213 |
wrote = 0; |
| 1214 |
eot_count++; |
| 1215 |
} |
| 1216 |
|
| 1217 |
if (eot_count > 0) |
| 1218 |
returns.clen = returns.unclen = 0; |
| 1219 |
|
| 1220 |
|
| 1221 |
|
| 1222 |
|
| 1223 |
if (wrote < 0) |
| 1224 |
returns.unclen = -errno; |
| 1225 |
|
| 1226 |
|
| 1227 |
|
| 1228 |
|
| 1229 |
|
| 1230 |
(void) dump_atomic_write( cmd, (char *)&returns, sizeof returns); |
| 1231 |
|
| 1232 |
|
| 1233 |
|
| 1234 |
|
| 1235 |
(void) kill(nextslave, SIGUSR2); |
| 1236 |
|
| 1237 |
#ifdef USE_QFA |
| 1238 |
indexer->updateQfaState(&qfa_state); |
| 1239 |
#endif |
| 1240 |
} |
| 1241 |
|
| 1242 |
#ifdef HAVE_BLOCK_TRANSFORMATION |
| 1243 |
transformation->endDiskIOProcess(transformation); |
| 1244 |
#endif |
| 1245 |
|
| 1246 |
if (nread != 0) |
| 1247 |
quit("error reading command pipe: %s\n", strerror(errno)); |
| 1248 |
free(comp_buf); |
| 1249 |
} |
| 1250 |
|
| 1251 |
|
| 1252 |
|
| 1253 |
|
| 1254 |
|
| 1255 |
|
| 1256 |
static ssize_t |
| 1257 |
dump_atomic_read(int fd, char *buf, size_t count) |
| 1258 |
{ |
| 1259 |
int got, need = count; |
| 1260 |
|
| 1261 |
do { |
| 1262 |
while ((got = read(fd, buf, need)) > 0 && (need -= got) > 0) |
| 1263 |
buf += got; |
| 1264 |
} while (got == -1 && errno == EINTR); |
| 1265 |
return (got < 0 ? got : (ssize_t)count - need); |
| 1266 |
} |
| 1267 |
|
| 1268 |
|
| 1269 |
|
| 1270 |
|
| 1271 |
|
| 1272 |
|
| 1273 |
static ssize_t |
| 1274 |
dump_atomic_write(int fd, const char *buf, size_t count) |
| 1275 |
{ |
| 1276 |
int got, need = count; |
| 1277 |
|
| 1278 |
do { |
| 1279 |
while ((got = write(fd, buf, need)) > 0 && (need -= got) > 0) |
| 1280 |
buf += got; |
| 1281 |
} while (got == -1 && errno == EINTR); |
| 1282 |
return (got < 0 ? got : (ssize_t)count - need); |
| 1283 |
} |