Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More flexible b_fsrivate #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bsd/sys/buf_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ struct buf {
TAILQ_ENTRY(buf) b_act; /* Device driver queue when active */
void * b_drvdata; /* Device driver private use */
void * b_fsprivate; /* filesystem private use */
void (*b_fsprivate_done)(void *); /* callback for fs to cleanup its data. */
void * b_transaction; /* journal private use */
int b_dirtyoff; /* Offset in buffer of dirty region. */
int b_dirtyend; /* Offset of end of dirty region. */
Expand Down
11 changes: 10 additions & 1 deletion bsd/vfs/vfs_bio.c
Original file line number Diff line number Diff line change
Expand Up @@ -1113,10 +1113,14 @@ buf_fsprivate(buf_t bp)
return bp->b_fsprivate;
}

// if NULL callback is passed, it's ignored
void
buf_setfsprivate(buf_t bp, void *fsprivate)
buf_setfsprivate(buf_t bp, void *fsprivate, (*release_callback)(void *))
{
bp->b_fsprivate = fsprivate;
if (release_callback != NULL){
bp->b_fsprivate_done = release_callback;
}
}

kauth_cred_t
Expand Down Expand Up @@ -3921,6 +3925,10 @@ bcleanbuf(buf_t bp, boolean_t discard)
bp->b_bufsize = 0;
bp->b_datap = (uintptr_t)NULL;
bp->b_upl = (void *)NULL;
/* call fs callback to release private data */
if (bp->b_fsprivate_done != NULL){
(void)b_fsprivate_done(bp->b_fsprivate);
}
bp->b_fsprivate = (void *)NULL;
/*
* preserve the state of whether this buffer
Expand Down Expand Up @@ -4493,6 +4501,7 @@ alloc_io_buf(vnode_t vp, int priv)
bp->b_bufsize = 0;
bp->b_upl = NULL;
bp->b_fsprivate = (void *)NULL;
bp->b_fsprivate_done = NULL;
bp->b_vp = vp;
bzero(&bp->b_attr, sizeof(struct bufattr));

Expand Down
2 changes: 1 addition & 1 deletion tools/lldbmacros/memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -4151,7 +4151,7 @@ def _GetBufSummary(buf):
buf.b_flags, buf.b_lflags, buf.b_error, buf.b_bufsize, buf.b_bcount, buf.b_resid,
buf.b_dev, buf.b_datap, buf.b_lblkno, buf.b_blkno, buf.b_iodone, buf.b_vp,
buf.b_rcred, buf.b_wcred, buf.b_upl, buf.b_real_bp, buf.b_act, buf.b_drvdata,
buf.b_fsprivate, buf.b_transaction, buf.b_dirtyoff, buf.b_dirtyend, buf.b_validoff,
buf.b_fsprivate, buf.b_fsprivate_done, buf.b_transaction, buf.b_dirtyoff, buf.b_dirtyend, buf.b_validoff,
buf.b_validend, buf.b_redundancy_flags, buf.b_proc, buf.b_attr]

# Join an (already decent) string representation of each field
Expand Down