X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/4452a7af2eac33dbad800bcc91f2399d62c18f53..7ee9d059c4eecf68ae4f8b0fb99ae2471eda79af:/bsd/sys/buf_internal.h diff --git a/bsd/sys/buf_internal.h b/bsd/sys/buf_internal.h index 728282146..d80eb21c8 100644 --- a/bsd/sys/buf_internal.h +++ b/bsd/sys/buf_internal.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved. + * Copyright (c) 2000-2008 Apple Inc. All rights reserved. * * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ * @@ -90,47 +90,66 @@ struct buf { LIST_ENTRY(buf) b_vnbufs; /* Buffer's associated vnode. */ TAILQ_ENTRY(buf) b_freelist; /* Free list position if not active. */ int b_timestamp; /* timestamp for queuing operation */ - long b_whichq; /* the free list the buffer belongs to */ - volatile long b_flags; /* B_* flags. */ - volatile long b_lflags; /* BL_BUSY | BL_WANTED flags... protected by buf_mtx */ + int b_whichq; /* the free list the buffer belongs to */ + volatile uint32_t b_flags; /* B_* flags. */ + volatile uint32_t b_lflags; /* BL_BUSY | BL_WANTED flags... protected by buf_mtx */ int b_error; /* errno value. */ - long b_bufsize; /* Allocated buffer size. */ - long b_bcount; /* Valid bytes in buffer. */ - long b_resid; /* Remaining I/O. */ + int b_bufsize; /* Allocated buffer size. */ + int b_bcount; /* Valid bytes in buffer. */ + int b_resid; /* Remaining I/O. */ dev_t b_dev; /* Device associated with buffer. */ - uintptr_t b_datap; /* Memory, superblocks, indirect etc.*/ + uintptr_t b_datap; /* Memory, superblocks, indirect etc.*/ daddr64_t b_lblkno; /* Logical block number. */ daddr64_t b_blkno; /* Underlying physical block number. */ void (*b_iodone)(buf_t, void *); /* Function to call upon completion. */ - vnode_t b_vp; /* Device vnode. */ - struct ucred *b_rcred; /* Read credentials reference. */ - struct ucred *b_wcred; /* Write credentials reference. */ + vnode_t b_vp; /* File vnode for data, device vnode for metadata. */ + kauth_cred_t b_rcred; /* Read credentials reference. */ + kauth_cred_t b_wcred; /* Write credentials reference. */ void * b_upl; /* Pointer to UPL */ buf_t b_real_bp; /* used to track bp generated through cluster_bp */ 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; /* filesystem private use */ void * b_transaction; /* journal private use */ int b_dirtyoff; /* Offset in buffer of dirty region. */ int b_dirtyend; /* Offset of end of dirty region. */ int b_validoff; /* Offset in buffer of valid region. */ int b_validend; /* Offset of end of valid region. */ + + /* store extra information related to redundancy of data, such as + * which redundancy copy to use, etc + */ + uint32_t b_redundancy_flags; + proc_t b_proc; /* Associated proc; NULL if kernel. */ +#ifdef BUF_MAKE_PRIVATE + buf_t b_data_store; +#endif +#if CONFIG_PROTECT + struct cprotect *b_cpentry; /* address of cp_entry, to be passed further down */ +#endif /* CONFIG_PROTECT */ #ifdef JOE_DEBUG void * b_owner; int b_tag; void * b_lastbrelse; - int b_stackbrelse[6]; - int b_stackgetblk[6]; + void * b_stackbrelse[6]; + void * b_stackgetblk[6]; #endif }; /* cluster_io definitions for use with io bufs */ #define b_uploffset b_bufsize +#define b_orig b_freelist.tqe_prev +#define b_shadow b_freelist.tqe_next +#define b_shadow_ref b_validoff +#ifdef BUF_MAKE_PRIVATE +#define b_data_ref b_validend +#endif #define b_trans_head b_freelist.tqe_prev #define b_trans_next b_freelist.tqe_next #define b_iostate b_rcred +#define b_cliodone b_wcred /* * These flags are kept in b_lflags... @@ -139,17 +158,30 @@ struct buf { #define BL_BUSY 0x00000001 /* I/O in progress. */ #define BL_WANTED 0x00000002 /* Process wants this buffer. */ #define BL_IOBUF 0x00000004 /* buffer allocated via 'buf_alloc' */ +#define BL_WANTDEALLOC 0x00000010 /* buffer should be put on empty list when clean */ +#define BL_SHADOW 0x00000020 +#define BL_EXTERNAL 0x00000040 +#define BL_WAITSHADOW 0x00000080 +#define BL_IOBUF_ALLOC 0x00000100 +/* + * Parameters for buffer cache garbage collection + */ +#define BUF_STALE_THRESHHOLD 30 /* Collect if untouched in the last 30 seconds */ +#define BUF_MAX_GC_COUNT 1024 /* Generally 6-8 MB */ +#define BUF_MAX_GC_BATCH_SIZE 128 /* Under a single grab of the lock */ /* * mask used by buf_flags... these are the readable external flags */ -#define BUF_X_RDFLAGS (B_CLUSTER | B_PHYS | B_LOCKED | B_DELWRI | B_ASYNC |\ - B_READ | B_WRITE | B_META | B_PAGEIO) +#define BUF_X_RDFLAGS (B_PHYS | B_RAW | B_LOCKED | B_ASYNC | B_READ | B_WRITE | B_PAGEIO |\ + B_META | B_CLUSTER | B_DELWRI | B_FUA | B_PASSIVE | B_IOSTREAMING | B_THROTTLED_IO |\ + B_ENCRYPTED_IO) /* * mask used by buf_clearflags/buf_setflags... these are the writable external flags */ -#define BUF_X_WRFLAGS (B_LOCKED | B_NOCACHE | B_ASYNC | B_READ | B_WRITE | B_PAGEIO) +#define BUF_X_WRFLAGS (B_PHYS | B_RAW | B_LOCKED | B_ASYNC | B_READ | B_WRITE | B_PAGEIO |\ + B_NOCACHE | B_FUA | B_PASSIVE | B_IOSTREAMING) /* * These flags are kept in b_flags... access is lockless @@ -166,7 +198,7 @@ struct buf { #define B_AGE 0x00200000 /* Move to age queue when I/O done. */ #define B_FILTER 0x00400000 /* call b_iodone from biodone as an in-line filter */ #define B_CALL 0x00800000 /* Call b_iodone from biodone, assumes b_iodone consumes bp */ -#define B_RAW 0x01000000 /* Set by physio for raw transfers. */ +#define B_EOT 0x01000000 /* last buffer in a transaction list created by cluster_io */ #define B_WASDIRTY 0x02000000 /* page was found dirty in the VM cache */ #define B_HDRALLOC 0x04000000 /* zone allocated buffer header */ #define B_ZALLOC 0x08000000 /* b_datap is zalloc()ed */ @@ -177,13 +209,9 @@ struct buf { /* * private flags used by by the cluster layer */ -#define B_NEED_IODONE 0x20000000 /* need biodone on the real_bp associated with a cluster_io */ +#define B_TWANTED 0x20000000 /* but_t that is part of a cluster level transaction is wanted */ #define B_COMMIT_UPL 0x40000000 /* commit/abort the UPL on I/O success/failure */ -/* - * can we deprecate? - */ -#define B_TAPE 0x80000000 /* Magnetic tape I/O. */ - +#define B_TDONE 0x80000000 /* buf_t that is part of a cluster level transaction has completed */ /* Flags to low-level allocation routines. */ #define B_CLRBUF 0x01 /* Request allocated buffer be cleared. */ @@ -191,11 +219,11 @@ struct buf { #define B_NOBUFF 0x04 /* Do not allocate struct buf */ -extern int niobuf; /* The number of IO buffer headers for cluster IO */ -extern int nbuf; /* The number of buffer headers */ -extern struct buf *buf; /* The buffer headers. */ +extern int niobuf_headers; /* The number of IO buffer headers for cluster IO */ +extern int nbuf_headers; /* The number of buffer headers */ extern int max_nbuf_headers; /* The max number of buffer headers */ extern int nbuf_hashelements; /* The number of elements in bufhash */ +extern struct buf *buf_headers; /* The buffer headers. */ /* @@ -213,13 +241,13 @@ extern int nbuf_hashelements; /* The number of elements in bufhash */ __BEGIN_DECLS +buf_t buf_create_shadow_priv(buf_t bp, boolean_t force_copy, uintptr_t external_storage, void (*iodone)(buf_t, void *), void *arg); + buf_t alloc_io_buf(vnode_t, int); void free_io_buf(buf_t); int allocbuf(struct buf *, int); -void bufinit(void); - -void buf_setfilter(buf_t, void (*)(buf_t, void *), void *, void **, void **); +void bufinit(void) __attribute__((section("__TEXT, initcode"))); /* * Flags for buf_acquire @@ -229,13 +257,19 @@ void buf_setfilter(buf_t, void (*)(buf_t, void *), void *, void **, void **); #define BAC_SKIP_NONLOCKED 0x04 /* Don't return LOCKED buffers */ #define BAC_SKIP_LOCKED 0x08 /* Only return LOCKED buffers */ -void cluster_init(void); +void buf_list_lock(void); +void buf_list_unlock(void); + +void cluster_init(void) __attribute__((section("__TEXT, initcode"))); void buf_drop(buf_t); errno_t buf_acquire(buf_t, int, int, int); int count_busy_buffers(void); int count_lock_queue(void); +#ifdef BUF_MAKE_PRIVATE +errno_t buf_make_private(buf_t bp); +#endif __END_DECLS