Lines Matching defs:hndl
94 static void deleteHandle (DataHandle *hndl);
98 static int allocateChunk (DataHandle *hndl, unsigned ichunk);
99 static uint8_t *getBlock (DataHandle *hndl, unsigned iflow, unsigned ichunk);
100 static int remapBlock (DataHandle *hndl, unsigned iflow, unsigned ichunk);
101 static int newBlock (DataHandle *hndl, unsigned iflow, unsigned ichunk);
102 static void deleteBlock (DataHandle *hndl, unsigned iflow, unsigned ichunk);
107 static int newBuffer (DataHandle *hndl, uint64_t pos);
192 DataHandle *hndl = NULL;
196 hndl = &data_hndls[i];
201 if (hndl == NULL)
208 hndl->kind = kind;
209 hndl->nblk = 0;
210 hndl->exempt = exempt;
211 CALL_UTIL (strlcpy)(hndl->fname, fname, sizeof (hndl->fname));
212 int fd = CALL_UTIL (open)(hndl->fname,
217 TprintfT (0, "createHandle open failed -- hndl->fname = `%s', SP_LOG_FILE = `%s': %s\n",
218 hndl->fname, SP_LOG_FILE, CALL_UTIL (strerror)(errno));
219 if (is_not_the_log_file (hndl->fname) == 0)
224 "create_handle: COL_ERROR_LOG_OPEN %s: %s\n", hndl->fname, CALL_UTIL (strerror)(errno));
230 SP_JCMD_CERROR, COL_ERROR_FILEOPN, errno, hndl->fname);
235 hndl->iotype = iotype;
236 if (hndl->iotype == IO_TXT)
250 TprintfT (0, "create_handle: can't mmap MAP_ANON (for %s): %s\n", hndl->fname, CALL_UTIL (strerror)(errno));
252 if (is_not_the_log_file (hndl->fname) == 0)
257 "create_handle: can't mmap MAP_ANON (for %s): %s\n", hndl->fname, CALL_UTIL (strerror)(errno));
262 SP_JCMD_CERROR, COL_ERROR_FILEMAP, errno, hndl->fname);
266 (long) (NBUFS * blksz), (long) (NBUFS * blksz), hndl->fname,
272 hndl->buffers = (Buffer*) __collector_allocCSize (__collector_heap, NBUFS * sizeof (Buffer), 1);
273 if (hndl->buffers == NULL)
275 TprintfT (0, "create_handle allocCSize for hndl->buffers failed\n");
281 Buffer *buf = &hndl->buffers[i];
286 hndl->curpos = CUR_MAKE (0, 0, 0);
290 if (hndl->iotype == IO_BLK)
295 hndl->nflow = (uint32_t) nflow;
297 else if (hndl->iotype == IO_SEQ)
298 hndl->nflow = 1;
300 fname, hndl->nflow, NCHUNKS,
301 (long) (hndl->nflow * NCHUNKS * sizeof (uint32_t)),
302 (long) (hndl->nflow * NCHUNKS * sizeof (uint32_t)));
303 uint32_t *blkstate = (uint32_t*) __collector_allocCSize (__collector_heap, hndl->nflow * NCHUNKS * sizeof (uint32_t), 1);
306 for (int j = 0; j < hndl->nflow * NCHUNKS; ++j)
308 hndl->blkstate = blkstate;
310 fname, hndl->nflow, NCHUNKS,
311 (long) (hndl->nflow * NCHUNKS * sizeof (uint32_t)),
312 (long) (hndl->nflow * NCHUNKS * sizeof (uint32_t)));
313 hndl->blkoff = (uint32_t*) __collector_allocCSize (__collector_heap, hndl->nflow * NCHUNKS * sizeof (uint32_t), 1);
314 if (hndl->blkoff == NULL)
316 hndl->nchnk = 0;
319 hndl->chunks[j] = NULL;
320 hndl->chblk[j] = 0;
323 hndl->active = 1;
324 return hndl;
328 deleteHandle (DataHandle *hndl)
330 if (hndl->active == 0)
332 hndl->active = 0;
334 if (hndl->iotype == IO_BLK || hndl->iotype == IO_SEQ)
337 /* Since access to hndl->active is not synchronized it's still
340 for (int j = 0; j < hndl->nflow * NCHUNKS; ++j)
342 uint32_t oldstate = hndl->blkstate[j];
346 uint32_t state = __collector_cas_32 (hndl->blkstate + j, oldstate, ST_BUSY);
349 deleteBlock (hndl, j / NCHUNKS, j % NCHUNKS);
352 else if (hndl->iotype == IO_TXT)
371 opos = hndl->curpos;
379 TprintfT (0, "deleteHandle ERROR: timeout cleaning up handle for %s\n", hndl->fname);
390 if (__collector_cas_64p (&hndl->curpos, &opos, &npos) != opos)
400 Buffer *buf = &hndl->buffers[indx];
410 Buffer *buf = &hndl->buffers[i];
415 TprintfT (0, "deleteHandle ERROR: timeout waiting for buffer %d for %s\n", i, hndl->fname);
423 __collector_freeCSize (__collector_heap, hndl->buffers, NBUFS * sizeof (Buffer));
428 __collector_delete_handle (DataHandle *hndl)
430 if (hndl == NULL)
432 deleteHandle (hndl);
493 allocateChunk (DataHandle *hndl, unsigned ichunk)
496 * hndl->chunks[ichunk] is one of:
505 if (hndl->chunks[ichunk] > CHUNK_BUSY)
508 if (__collector_cas_ptr (&hndl->chunks[ichunk], NULL, CHUNK_BUSY) == NULL)
512 (size_t) (blksz * hndl->nflow), PROT_READ | PROT_WRITE,
521 deleteHandle (hndl);
523 0, (long) (blksz * hndl->nflow),
524 (long) (blksz * hndl->nflow), 0, newchunk);
525 TprintfT (0, "allocateChunk: can't mmap MAP_ANON (for %s): %s\n", hndl->fname, CALL_UTIL (strerror) (errno));
527 SP_JCMD_CERROR, COL_ERROR_FILEMAP, errno, hndl->fname);
532 if (__collector_cas_ptr (&hndl->chunks[ichunk], CHUNK_BUSY, newchunk) != CHUNK_BUSY)
534 TprintfT (0, "allocateChunk: can't release chunk CAS lock for %s\n", hndl->fname);
536 SP_JCMD_CERROR, COL_ERROR_GENERAL, hndl->fname);
538 __collector_inc_32 (&hndl->nchnk);
547 TprintfT (0, "allocateChunk: timeout for %s\n", hndl->fname);
549 SP_JCMD_CERROR, COL_ERROR_GENERAL, hndl->fname);
559 getBlock (DataHandle *hndl, unsigned iflow, unsigned ichunk)
561 return hndl->chunks[ichunk] + iflow * blksz;
568 remapBlock (DataHandle *hndl, unsigned iflow, unsigned ichunk)
573 uint32_t oldblk = hndl->nblk;
576 uint32_t newblk = __collector_cas_32 (&hndl->nblk, oldblk, oldblk + 1);
592 fd = CALL_UTIL (open)(hndl->fname, O_RDWR, 0);
607 (unsigned long) __collector_thr_self (), hndl->fname,
617 deleteHandle (hndl);
618 TprintfT (0, "remapBlock: can't open file: %s: %s\n", hndl->fname, STR (CALL_UTIL (strerror)(errno)));
622 hndl->fname);
638 (unsigned long) __collector_thr_self (), hndl->fname,
650 deleteHandle (hndl);
651 TprintfT (0, "remapBlock: can't pwrite file: %s : errno=%d\n", hndl->fname, errno);
653 SP_JCMD_CERROR, COL_ERROR_NOSPACE, errno, hndl->fname);
658 hndl->blkoff[iflow * NCHUNKS + ichunk] = 0;
661 uint8_t *bptr = getBlock (hndl, iflow, ichunk);
668 deleteHandle (hndl);
671 TprintfT (0, "remapBlock: can't mmap file: %s : errno=%d\n", hndl->fname, errno);
673 SP_JCMD_CERROR, COL_ERROR_FILEMAP, errno, hndl->fname);
680 if (hndl->exempt == 0)
681 exp_size_ck (1, hndl->fname);
684 1, hndl->fname);
693 newBlock (DataHandle *hndl, unsigned iflow, unsigned ichunk)
695 if (allocateChunk (hndl, ichunk) != 0)
697 if (remapBlock (hndl, iflow, ichunk) != 0)
701 __collector_inc_32 (hndl->chblk + ichunk);
706 deleteBlock (DataHandle *hndl, unsigned iflow, unsigned ichunk)
708 uint8_t *bptr = getBlock (hndl, iflow, ichunk);
710 hndl->blkstate[iflow * NCHUNKS + ichunk] = ST_INIT;
713 __collector_dec_32 (hndl->chblk + ichunk);
717 __collector_write_record (DataHandle *hndl, Common_packet *pckt)
719 if (hndl == NULL || !hndl->active)
723 pckt->type = hndl->kind;
735 hndl->fname, pckt->type, pckt->tsize);
736 return __collector_write_packet (hndl, (CM_Packet*) pckt);
740 __collector_write_packet (DataHandle *hndl, CM_Packet *pckt)
742 if (hndl == NULL || !hndl->active)
769 hndl->fname, xstate);
781 unsigned iflow = (unsigned) (((unsigned long) tid) % hndl->nflow);
784 uint32_t *sptr = &hndl->blkstate[iflow * NCHUNKS];
811 NCHUNKS, iflow, hndl->fname);
815 if (state == ST_INIT && newBlock (hndl, iflow, ichunk) != 0)
817 uint8_t *bptr = getBlock (hndl, iflow, ichunk);
818 uint32_t blkoff = hndl->blkoff[iflow * NCHUNKS + ichunk];
828 if (remapBlock (hndl, iflow, ichunk) != 0)
830 blkoff = hndl->blkoff[iflow * NCHUNKS + ichunk];
842 if (hndl->active == 0)
844 deleteBlock (hndl, iflow, ichunk);
847 hndl->blkoff[iflow * NCHUNKS + ichunk] += recsz;
862 * The current position of the file is handled via hndl->curpos.
867 * - busy: a bit to lock access to hndl->curpos
876 * - acquire the hndl->curpos "busy" lock
891 * It simply updates hndl->curpos atomically to the new file offset.
961 newBuffer (DataHandle *hndl, uint64_t foff)
966 if (__collector_cas_32 (&hndl->buffers[ibuf].state, ST_FREE, ST_BUSY) == ST_FREE)
970 TprintfT (0, "newBuffer ERROR: all buffers busy for %s\n", hndl->fname);
973 Buffer *nbuf = hndl->buffers + ibuf;
976 if (mapBuffer (hndl->fname, nbuf, foff) != 0)
1001 __collector_write_string (DataHandle *hndl, char *src, int len)
1003 if (hndl == NULL || !hndl->active)
1017 opos = hndl->curpos;
1027 * after we checked hndl->active.
1029 TprintfT (0, "__collector_write_string ERROR: timeout writing length=%d to text file: %s\n", len, hndl->fname);
1046 Tprintf (0, "__collector_write_string ERROR: string of length %d too long to be written to text file: %s\n", len, hndl->fname);
1055 if (__collector_cas_64p (&hndl->curpos, &opos, &npos) != opos)
1060 indx, hndl->buffers[indx].vaddr, len, (long long) foff, src);
1061 writeBuffer (&hndl->buffers[indx], foff & (blksz - 1), src, len);
1078 if (__collector_cas_64p (&hndl->curpos, &opos, &lpos) != opos)
1092 buf_indices[ibuf] = newBuffer (hndl, base);
1101 if (__collector_cas_64p (&hndl->curpos, &lpos, &npos) != lpos)
1103 TprintfT (0, "__collector_write_string ERROR: file handle corrupted: %s\n", hndl->fname);
1120 TprintfT (0, "__collector_write_string ERROR: can't map new buffer: %s\n", hndl->fname);
1129 writeBuffer (&hndl->buffers[indx], blk_off, src, blksz - blk_off);
1142 writeBuffer (&hndl->buffers[buf_indices[ibuf]], 0, src, clen);