Lines Matching defs:lbp
93 struct nfslog_buf *lbp = NULL;
100 if ((lbp = malloc(sizeof (struct nfslog_buf))) == NULL) {
104 bzero(lbp, sizeof (struct nfslog_buf));
106 if (nfslog_init_buf(bufpath, lbp, error)) {
107 free(lbp);
110 return (lbp);
117 nfslog_close_buf(struct nfslog_buf *lbp, int close_quick)
119 nfslog_free_buf(lbp, close_quick);
120 free(lbp);
134 nfslog_init_buf(char *bufpath, struct nfslog_buf *lbp, int *error)
139 lbp->next = lbp;
140 lbp->prev = lbp;
144 lbp->mmap_addr = (intptr_t)MAP_FAILED;
145 lbp->last_rec_id = MAXINT - 1;
146 lbp->bh.bh_length = 0;
147 lbp->bh_lrp = NULL;
148 lbp->num_lrps = 0;
149 lbp->lrps = NULL;
150 lbp->last_record_offset = 0;
151 lbp->prp = NULL;
152 lbp->num_pr_queued = 0;
154 lbp->bufpath = strdup(bufpath);
155 if (lbp->bufpath == NULL) {
161 nfslog_free_buf(lbp, FALSE);
165 if ((lbp->fd = open(bufpath, O_RDWR)) < 0) {
171 nfslog_free_buf(lbp, FALSE);
180 lbp->fl.l_type = F_WRLCK;
181 lbp->fl.l_whence = SEEK_SET; /* beginning of file */
182 lbp->fl.l_start = (offset_t)0;
183 lbp->fl.l_len = 0; /* entire file */
184 lbp->fl.l_sysid = 0;
185 lbp->fl.l_pid = 0;
186 if (fcntl(lbp->fd, F_SETLKW, &lbp->fl) == -1) {
192 nfslog_free_buf(lbp, FALSE);
196 if (fstat(lbp->fd, &sb)) {
202 nfslog_free_buf(lbp, FALSE);
205 lbp->filesize = sb.st_size;
207 lbp->mmap_addr = (intptr_t)mmap(0, lbp->filesize, PROT_READ|PROT_WRITE,
208 MAP_SHARED|MAP_NORESERVE, lbp->fd, 0);
211 if (lbp->mmap_addr == (intptr_t)MAP_FAILED) {
212 lbp->next_rec = 0;
214 lbp->next_rec = lbp->mmap_addr;
218 if ((lbp->bh_lrp = nfslog_read_buffer(lbp)) == NULL) {
225 nfslog_free_buf(lbp, FALSE);
229 if (!xdr_nfslog_buffer_header(&lbp->bh_lrp->xdrs, &lbp->bh)) {
236 nfslog_free_buf(lbp, FALSE);
242 * 'lbp->bh.bh_offset' contains the offset of where to begin
245 lbp->next_rec += lbp->bh.bh_offset;
254 if (lbp->mmap_addr == (intptr_t)MAP_FAILED && lbp->next_rec != 0) {
255 (void) lseek(lbp->fd, lbp->next_rec, SEEK_SET);
257 lbp->last_record_offset = lbp->next_rec;
259 lbp->last_record_offset = lbp->next_rec - lbp->mmap_addr;
269 nfslog_free_buf(struct nfslog_buf *lbp, int close_quick)
278 if (lbp->prp) {
279 if (lbp->last_record_offset == lbp->prp->start_offset) {
282 lbp->last_record_offset =
283 lbp->prp->start_offset + lbp->prp->len;
285 nfslog_rewrite_bufheader(lbp);
289 prp = lbp->prp;
294 } while (lbp->prp != prp);
301 if (lbp->lrps != NULL) {
302 lrp = lbp->lrps;
307 } while (lrp != lbp->lrps);
308 lbp->lrps = NULL;
312 if (lbp->bh.bh_length != 0) {
313 buffer = (lbp->bh_lrp->buffer != NULL ?
314 lbp->bh_lrp->buffer : (caddr_t)lbp->mmap_addr);
315 xdrmem_create(&xdrs, buffer, lbp->bh_lrp->recsize, XDR_FREE);
316 (void) xdr_nfslog_buffer_header(&xdrs, &lbp->bh);
317 lbp->bh.bh_length = 0;
321 if (lbp->bh_lrp != NULL) {
322 free_lrp(lbp->bh_lrp);
323 lbp->bh_lrp = NULL;
327 if (lbp->mmap_addr != (intptr_t)MAP_FAILED) {
328 if (munmap((void *)lbp->mmap_addr, lbp->filesize)) {
331 (lbp->bufpath != NULL ? lbp->bufpath : ""),
334 lbp->mmap_addr = (intptr_t)MAP_FAILED;
338 if (lbp->fd >= 0) {
339 lbp->fl.l_type = F_UNLCK;
340 if (fcntl(lbp->fd, F_SETLK, &lbp->fl) == -1) {
344 (lbp->bufpath != NULL ? lbp->bufpath : ""),
347 (void) close(lbp->fd);
348 lbp->fd = -1;
350 if (lbp->bufpath != NULL)
351 free(lbp->bufpath);
363 nfslog_read_buffer(struct nfslog_buf *lbp)
376 if (lbp->mmap_addr == (intptr_t)MAP_FAILED) {
380 if (read(lbp->fd, tbuf, BYTES_PER_XDR_UNIT) <= 0) {
387 if (lbp->filesize <= lbp->next_rec - lbp->mmap_addr) {
391 sizebuf = (char *)(uintptr_t)lbp->next_rec;
403 next_rec = lbp->next_rec + lrp->recsize;
405 if (lbp->mmap_addr == (intptr_t)MAP_FAILED) {
411 if (lbp->filesize < next_rec) {
415 "discarded\n"), lbp->bufpath);
425 if (read(lbp->fd, &lrp->buffer[BYTES_PER_XDR_UNIT],
430 } else if (lbp->filesize < next_rec - lbp->mmap_addr) {
434 "discarded\n"), lbp->bufpath);
443 if (lbp->mmap_addr == (intptr_t)MAP_FAILED)
444 lrp->f_offset = lbp->next_rec;
446 lrp->f_offset = lbp->next_rec - lbp->mmap_addr;
448 lrp->record = lbp->next_rec;
450 lrp->lbp = lbp;
459 lbp->next_rec = next_rec;
469 remove_lrp_from_lb(struct nfslog_buf *lbp, struct nfslog_lr *lrp)
471 if (lbp->lrps == lrp) {
472 if (lbp->lrps == lbp->lrps->next) {
473 lbp->lrps = NULL;
475 lbp->lrps = lrp->next;
481 lbp->num_lrps--;
494 insert_lrp_to_lb(struct nfslog_buf *lbp, struct nfslog_lr *lrp)
499 if (lbp->lrps == NULL) {
501 lbp->lrps = lrp;
509 if (ins_rec_id < lbp->lrps->log_record.re_header.rh_rec_id) {
510 lrp->next = lbp->lrps;
511 lrp->prev = lbp->lrps->prev;
512 lbp->lrps->prev->next = lrp;
513 lbp->lrps->prev = lrp;
514 lbp->lrps = lrp;
521 curlrp = lbp->lrps;
527 } while (curlrp != lbp->lrps);
528 if (curlrp == lbp->lrps)
529 insque(lrp, lbp->lrps->prev);
535 lbp->num_lrps++;
543 * 'lbp->last_record_offset' contains the absolute offset of the end
549 nfslog_rewrite_bufheader(struct nfslog_buf *lbp)
562 if (lbp->bh.bh_flags & NFSLOG_BH_OFFSET_OVERFLOW) {
572 bh = lbp->bh;
580 (lbp->last_record_offset - bh.bh_length < UINT32_MAX)) {
581 bh.bh_offset = lbp->last_record_offset - bh.bh_length;
585 lbp->bh.bh_flags = bh.bh_flags;
588 "in a 32 bit field\n"), lbp->bufpath);
596 lbp->bufpath);
602 if (lbp->mmap_addr == (intptr_t)MAP_FAILED) {
604 (void) lseek(lbp->fd, 0, SEEK_SET);
605 (void) write(lbp->fd, buffer, wsize);
606 (void) lseek(lbp->fd, lbp->next_rec, SEEK_SET);
607 (void) fsync(lbp->fd);
609 bcopy(buffer, (void *)lbp->mmap_addr, wsize);
610 (void) msync((void *)lbp->mmap_addr, wsize, MS_SYNC);
646 lrp->lbp->num_pr_queued++;
649 if (lrp->lbp->prp == NULL) {
650 lrp->lbp->prp = prp;
653 tp = lrp->lbp->prp;
658 } while (tp != lrp->lbp->prp);
665 if (tp == lrp->lbp->prp && prp->start_offset < tp->start_offset)
666 lrp->lbp->prp = prp;
692 if (lrp->lbp->num_pr_queued > MAX_RECS_TO_DELAY) {
693 prp = lrp->lbp->prp;
694 if (lrp->lbp->last_record_offset ==
698 lrp->lbp->last_record_offset =
701 nfslog_rewrite_bufheader(lrp->lbp);
708 lrp->lbp->prp = tp;
709 lrp->lbp->num_pr_queued -= prp->num_recs;
742 nfslog_get_logrecord(struct nfslog_buf *lbp)
745 unsigned int next_rec_id = lbp->last_rec_id + 1;
754 if (lbp->lrps != NULL) {
756 if (lbp->lrps->log_record.re_header.rh_rec_id == next_rec_id) {
757 lrp = remove_lrp_from_lb(lbp, lbp->lrps);
758 lbp->last_rec_id = lrp->log_record.re_header.rh_rec_id;
768 lbp->lrps->log_record.re_header.rh_rec_id &&
769 ((lbp->lrps->log_record.re_header.rh_rec_id -
772 lrp = remove_lrp_from_lb(lbp, lbp->lrps);
773 lbp->last_rec_id =
789 if (lbp->num_lrps >= MAX_LRS_READ_AHEAD) {
790 lrp = remove_lrp_from_lb(lbp, lbp->lrps);
791 lbp->last_rec_id = lrp->log_record.re_header.rh_rec_id;
801 if ((lrp = nfslog_read_buffer(lbp)) == NULL) {
802 if (lbp->lrps != NULL) {
803 lrp = remove_lrp_from_lb(lbp, lbp->lrps);
804 lbp->last_rec_id =
828 lbp->last_rec_id =
836 insert_lrp_to_lb(lbp, lrp);