54 EPNAME(
"UpdateRangeHoleUntilPage");
57 static const std::vector<uint32_t> crc32Vec(
stsize_, crczero);
59 const off_t trackinglen = sizes.first;
61 if (until <= tracked_page)
return 0;
70 TRACE(Warn,
"Unexpected partially filled last page " <<
fn_);
75 const ssize_t rret =
ts_->ReadTags(&prevtag, tracked_page, 1);
85 const ssize_t wret =
ts_->WriteTags(&
crc32c, tracked_page, 1);
95 const off_t nAllEmpty = (tracked_off>0) ? (until - tracked_page - 1) : (until - tracked_page);
96 const off_t firstEmpty = (tracked_off>0) ? (tracked_page + 1) : tracked_page;
98 off_t towrite = nAllEmpty;
102 const size_t nw = std::min(towrite, (off_t)crc32Vec.size());
103 const ssize_t wret =
ts_->WriteTags(&crc32Vec[0], firstEmpty+nwritten, nw);
132 const off_t offset,
const off_t trackinglen,
133 const uint32_t *
const csvec, uint32_t &prepageval)
135 EPNAME(
"StoreRangeUnaligned_preblock");
142 if (p1 > tracked_page)
159 if (p1 == tracked_page && p1_off >= tracked_off)
167 const ssize_t rret =
ts_->ReadTags(&crc32v, p1, 1);
207 if (
static_cast<size_t>(rlen) == tracked_off)
210 if (tracked_off==0 || crc32x == crc32v)
break;
215 if ((tracked_off>0 || p1_off==0) &&
static_cast<size_t>(rlen) <= p1_off+blen)
218 if (tracked_off != 0)
227 " of file " <<
fn_ <<
" rlen=" << rlen <<
" (append)");
231 if (
static_cast<size_t>(rlen) != tracked_off && rlen>0)
234 if (crc32x == crc32v)
242 memcpy(&b[p1_off], buff, blen);
244 if (crc32x == crc32v)
247 " of file " <<
fn_ <<
" (append)");
261 " of file " <<
fn_ <<
", offset-in-page=" << p1_off <<
" rlen=" << rlen <<
" (append)");
271 const size_t nz = p1_off - tracked_off;
291 assert(p1_off < bavail);
295 assert(p1_off !=0 || blen<bavail);
299 ssize_t rret =
ts_->ReadTags(&crc32v, p1, 1);
327 if (
static_cast<size_t>(rlen) == bavail &&
crc32c == crc32v)
break;
334 const size_t rmin = (p1_off+blen < bavail) ? bavail : 0;
335 if (
static_cast<size_t>(rlen) >= rmin &&
static_cast<size_t>(rlen)<=bavail)
344 if (
static_cast<size_t>(rlen) != bavail && rlen > 0)
355 memcpy(&b[p1_off], buff, blen);
356 const size_t vl = std::max(bavail, p1_off+blen);
360 TRACE(Warn,
"Recovered matching write at offset " << (
XrdSys::PageSize * p1)+p1_off <<
" of file " <<
fn_ <<
" (overwrite)");
398 if (p1_off+blen < bavail)
415 const off_t offset,
const off_t trackinglen,
416 const uint32_t *
const csvec, uint32_t &lastpageval)
418 EPNAME(
"StoreRangeUnaligned_postblock");
420 const uint8_t *
const p = (uint8_t*)buff;
434 const size_t bremain = (p2_off < bavail) ? bavail-p2_off : 0;
443 ssize_t rret =
ts_->ReadTags(&crc32v, p2, 1);
482 if (crc32v != crc32prev)
517 EPNAME(
"StoreRangeUnaligned");
520 const off_t trackinglen = sizes.first;
521 if (offset > trackinglen)
526 TRACE(Warn,
"Error updating tags for holes, error=" << ret);
534 bool hasprepage =
false;
550 const off_t np = hasprepage ? p1+1 : p1;
560 const ssize_t wret =
ts_->WriteTags(&prepageval, p1, 1);
570 const uint8_t *
const p = (uint8_t*)buff;
571 const uint32_t *csp = csvec;
572 if (csp && hasprepage) csp++;
575 if (p2_off == 0 || (offset + blen >=
static_cast<size_t>(trackinglen)))
581 TRACE(Warn,
"Error updating tags, error=" << aret);
589 uint32_t lastpageval;
600 TRACE(Warn,
"Error updating tags, error=" << aret);
623 const off_t trackinglen, uint32_t *
const tbuf, uint32_t *
const csvec,
const uint64_t
opts)
625 EPNAME(
"FetchRangeUnaligned_preblock");
634 const size_t bcommon = std::min(bavail - p1_off, blen);
637 const uint8_t *ub = (uint8_t*)buff;
651 if (memcmp(buff, &b[p1_off], bcommon))
654 for(badoff=0;badoff<bcommon;badoff++) {
if (((uint8_t*)buff)[badoff] != b[p1_off+badoff])
break; }
655 badoff = (badoff < bcommon) ? badoff : 0;
666 if (tbuf[0] != crc32calc)
675 if (bavail>bcommon && csvec)
711 const off_t trackinglen, uint32_t *
const tbuf, uint32_t *
const csvec,
const size_t tidx,
const uint64_t
opts)
713 EPNAME(
"FetchRangeUnaligned_postblock");
722 const size_t bremain = (p2_off < bavail) ? bavail-p2_off : 0;
724 const uint8_t *ub = &((uint8_t*)buff)[blen-p2_off];
736 const uint8_t *
const p = (uint8_t*)buff;
737 if (memcmp(&p[blen-p2_off], b, p2_off))
740 for(badoff=0;badoff<p2_off;badoff++) {
if (p[blen-p2_off+badoff] != b[badoff])
break; }
741 badoff = (badoff < p2_off) ? badoff : 0;
751 if (tbuf[tidx] != crc32calc)
759 if (csvec && bremain>0)
788 EPNAME(
"FetchRangeUnaligned");
795 const off_t trackinglen = sizes.first;
797 size_t ntagstoread = (p2_off>0) ? p2-p1+1 : p2-p1;
798 size_t ntagsbase = p1;
799 uint32_t tbufint[
stsize_], *tbuf=0;
804 tbufsz =
sizeof(tbufint)/
sizeof(uint32_t);
809 tbufsz = ntagstoread;
812 size_t tcnt = std::min(ntagstoread, tbufsz);
813 ssize_t rret =
ts_->ReadTags(tbuf, ntagsbase, tcnt);
832 const off_t fp = (p1_off != 0) ? p1+1 : p1;
838 const uint8_t *
const p = (uint8_t*)buff;
840 const size_t cbufsz =
sizeof(calcbuf)/
sizeof(uint32_t);
841 size_t toread = lp-fp;
845 const size_t ccnt = std::min(toread, cbufsz);
847 size_t tovalid = ccnt;
851 const size_t tidx=fp+nread+nvalid - ntagsbase;
852 const size_t nv = std::min(tovalid, tbufsz-tidx);
855 assert(csvec == NULL);
857 tcnt = std::min(ntagstoread, tbufsz);
858 rret =
ts_->ReadTags(tbuf, ntagsbase, tcnt);
867 if (memcmp(&calcbuf[nvalid], &tbuf[tidx], 4*nv))
870 for(badpg=0;badpg<nv;badpg++) {
if (memcmp(&calcbuf[nvalid+badpg], &tbuf[tidx+badpg],4))
break; }
872 (ntagsbase+tidx+badpg),
873 calcbuf[nvalid+badpg], tbuf[tidx+badpg]));
885 if (p2>p1 && p2_off > 0)
889 size_t tidx = p2 - ntagsbase;
892 assert(csvec == NULL);
895 rret =
ts_->ReadTags(tbuf, ntagsbase, 1);
static XrdOssCsiCrcUtils CrcUtils
uint32_t crc32c(uint32_t crc, void const *buf, size_t len)
static uint32_t crc32c_extendwith_zero(uint32_t crc, size_t len)
static uint32_t crc32c_combine(uint32_t crc1, uint32_t crc2, size_t len2)
static uint32_t crc32c_split1(uint32_t crctot, uint32_t crc2, size_t len2)
static uint32_t crc32c_split2(uint32_t crctot, uint32_t crc1, size_t len2)
int StoreRangeUnaligned(XrdOssDF *, const void *, off_t, size_t, const Sizes_t &, const uint32_t *)
ssize_t apply_sequential_aligned_modify(const void *, off_t, size_t, const uint32_t *, bool, bool, uint32_t, uint32_t)
std::string ByteMismatchError(size_t blen, off_t off, uint8_t user, uint8_t page)
static ssize_t maxread(XrdOssDF *fd, void *buff, const off_t off, const size_t sz, size_t tg=0)
std::string TagsReadError(off_t start, size_t n, int ret)
std::unique_ptr< XrdOssCsiTagstore > ts_
int UpdateRangeUnaligned(XrdOssDF *, const void *, off_t, size_t, const Sizes_t &)
std::string TagsWriteError(off_t start, size_t n, int ret)
int FetchRangeUnaligned_preblock(XrdOssDF *, const void *, off_t, size_t, off_t, uint32_t *, uint32_t *, uint64_t)
int UpdateRangeHoleUntilPage(XrdOssDF *, off_t, const Sizes_t &)
static ssize_t fullread(XrdOssDF *fd, void *buff, const off_t off, const size_t sz)
std::pair< off_t, off_t > Sizes_t
int FetchRangeUnaligned(XrdOssDF *, const void *, off_t, size_t, const Sizes_t &, uint32_t *, uint64_t)
int FetchRangeUnaligned_postblock(XrdOssDF *, const void *, off_t, size_t, off_t, uint32_t *, uint32_t *, size_t, uint64_t)
int VerifyRangeUnaligned(XrdOssDF *, const void *, off_t, size_t, const Sizes_t &)
std::string CRCMismatchError(size_t blen, off_t pgnum, uint32_t got, uint32_t expected)
int StoreRangeUnaligned_preblock(XrdOssDF *, const void *, size_t, off_t, off_t, const uint32_t *, uint32_t &)
std::string PageReadError(size_t blen, off_t pgnum, int ret)
int StoreRangeUnaligned_postblock(XrdOssDF *, const void *, size_t, off_t, off_t, const uint32_t *, uint32_t &)
static const size_t stsize_
static const uint64_t Verify
all: Verify checksums
static uint32_t Calc32C(const void *data, size_t count, uint32_t prevcs=0)
static const int PageSize