コード例 #1
0
ファイル: masterconn.c プロジェクト: moosefs/moosefs
void masterconn_download_info(masterconn *eptr,const uint8_t *data,uint32_t length) {
    if (length!=1 && length!=8) {
        syslog(LOG_NOTICE,"MATOAN_DOWNLOAD_INFO - wrong size (%"PRIu32"/1|8)",length);
        eptr->mode = KILL;
        return;
    }
    passert(data);
    if (length==1) {
        eptr->downloading = 0;
        syslog(LOG_NOTICE,"download start error");
        return;
    }
    eptr->filesize = get64bit(&data);
    eptr->dloffset = 0;
    eptr->downloadretrycnt = 0;
    eptr->dlstartuts = monotonic_useconds();
    if (eptr->downloading==1) {
        eptr->metafd = open("metadata_ml.tmp",O_WRONLY | O_TRUNC | O_CREAT,0666);
    } else if (eptr->downloading==11 || eptr->downloading==12) {
        eptr->metafd = open("changelog_ml.tmp",O_WRONLY | O_TRUNC | O_CREAT,0666);
    } else {
        syslog(LOG_NOTICE,"unexpected MATOAN_DOWNLOAD_INFO packet");
        eptr->mode = KILL;
        return;
    }
    if (eptr->metafd<0) {
        mfs_errlog_silent(LOG_NOTICE,"error opening metafile");
        masterconn_download_end(eptr);
        return;
    }
    masterconn_download_next(eptr);
}
コード例 #2
0
ファイル: masterconn.c プロジェクト: andyqzb/shadow-mfs
void masterconn_download_start(serventry *eptr,const uint8_t *data,uint32_t length) {
	if (length!=1 && length!=8) {
		MFSLOG(LOG_NOTICE,"MATOSLA_DOWNLOAD_START - wrong size (%"PRIu32"/1|8)",length);
		eptr->mode = KILL;
		return;
	}
	if (length==1) {
		MFSLOG(LOG_NOTICE,"download start error");
		return;
	}
	eptr->filesize = get64bit(&data);
	eptr->dloffset = 0;
	eptr->retrycnt = 0;
	eptr->dlstartuts = main_utime();
	if (eptr->downloading==1) {
		eptr->metafd = open("metadata.tmp",O_WRONLY | O_TRUNC | O_CREAT,0666);
	} else if (eptr->downloading==2) {
		eptr->metafd = open("changelog.0.tmp",O_WRONLY | O_TRUNC | O_CREAT,0666);
	} else {
		MFSLOG(LOG_NOTICE,"unexpected MATOSLA_DOWNLOAD_START packet");
		eptr->mode = KILL;
		return;
	}
	if (eptr->metafd<0) {
		MFSLOG(LOG_NOTICE,"error opening metafile: %m");
		masterconn_download_end(eptr,4);
		return;
	}
	masterconn_download_next(eptr);
}
コード例 #3
0
ファイル: masterconn.c プロジェクト: moosefs/moosefs
void masterconn_download_data(masterconn *eptr,const uint8_t *data,uint32_t length) {
    uint64_t offset;
    uint32_t leng;
    uint32_t crc;
    ssize_t ret;
    if (eptr->metafd<0) {
        syslog(LOG_NOTICE,"MATOAN_DOWNLOAD_DATA - file not opened");
        eptr->mode = KILL;
        return;
    }
    if (length<16) {
        syslog(LOG_NOTICE,"MATOAN_DOWNLOAD_DATA - wrong size (%"PRIu32"/16+data)",length);
        eptr->mode = KILL;
        return;
    }
    passert(data);
    offset = get64bit(&data);
    leng = get32bit(&data);
    crc = get32bit(&data);
    if (leng+16!=length) {
        syslog(LOG_NOTICE,"MATOAN_DOWNLOAD_DATA - wrong size (%"PRIu32"/16+%"PRIu32")",length,leng);
        eptr->mode = KILL;
        return;
    }
    if (offset!=eptr->dloffset) {
        syslog(LOG_NOTICE,"MATOAN_DOWNLOAD_DATA - unexpected file offset (%"PRIu64"/%"PRIu64")",offset,eptr->dloffset);
        eptr->mode = KILL;
        return;
    }
    if (offset+leng>eptr->filesize) {
        syslog(LOG_NOTICE,"MATOAN_DOWNLOAD_DATA - unexpected file size (%"PRIu64"/%"PRIu64")",offset+leng,eptr->filesize);
        eptr->mode = KILL;
        return;
    }
#ifdef HAVE_PWRITE
    ret = pwrite(eptr->metafd,data,leng,offset);
#else /* HAVE_PWRITE */
    lseek(eptr->metafd,offset,SEEK_SET);
    ret = write(eptr->metafd,data,leng);
#endif /* HAVE_PWRITE */
    if (ret!=(ssize_t)leng) {
        mfs_errlog_silent(LOG_NOTICE,"error writing metafile");
        if (eptr->downloadretrycnt>=5) {
            masterconn_download_end(eptr);
        } else {
            eptr->downloadretrycnt++;
            masterconn_download_next(eptr);
        }
        return;
    }
    if (crc!=mycrc32(0,data,leng)) {
        syslog(LOG_NOTICE,"metafile data crc error");
        if (eptr->downloadretrycnt>=5) {
            masterconn_download_end(eptr);
        } else {
            eptr->downloadretrycnt++;
            masterconn_download_next(eptr);
        }
        return;
    }
    if (fsync(eptr->metafd)<0) {
        mfs_errlog_silent(LOG_NOTICE,"error syncing metafile");
        if (eptr->downloadretrycnt>=5) {
            masterconn_download_end(eptr);
        } else {
            eptr->downloadretrycnt++;
            masterconn_download_next(eptr);
        }
        return;
    }
    eptr->dloffset+=leng;
    eptr->downloadretrycnt=0;
    masterconn_download_next(eptr);
}