* getblkx: * * Get a block given a specified block and offset into a file/device. * The buffers B_DONE bit will be cleared on return, making it almost * ready for an I/O initiation. B_INVAL may or may not be set on * return. The caller should clear B_INVAL prior to initiating a * READ. * * For a non-VMIO buffer, B_CACHE is set to the opposite of B_INVAL for * an existing buffer. * *
| 3878 | * for blkno and dblkno. |
| 3879 | */ |
| 3880 | int |
| 3881 | getblkx(struct vnode *vp, daddr_t blkno, daddr_t dblkno, int size, int slpflag, |
| 3882 | int slptimeo, int flags, struct buf **bpp) |
| 3883 | { |
| 3884 | struct buf *bp; |
| 3885 | struct bufobj *bo; |
| 3886 | daddr_t d_blkno; |
| 3887 | int bsize, error, maxsize, vmio; |
| 3888 | off_t offset; |
| 3889 | |
| 3890 | CTR3(KTR_BUF, "getblk(%p, %ld, %d)", vp, (long)blkno, size); |
| 3891 | KASSERT((flags & (GB_UNMAPPED | GB_KVAALLOC)) != GB_KVAALLOC, |
| 3892 | ("GB_KVAALLOC only makes sense with GB_UNMAPPED")); |
| 3893 | ASSERT_VOP_LOCKED(vp, "getblk"); |
| 3894 | if (size > maxbcachebuf) |
| 3895 | panic("getblk: size(%d) > maxbcachebuf(%d)\n", size, |
| 3896 | maxbcachebuf); |
| 3897 | if (!unmapped_buf_allowed) |
| 3898 | flags &= ~(GB_UNMAPPED | GB_KVAALLOC); |
| 3899 | |
| 3900 | bo = &vp->v_bufobj; |
| 3901 | d_blkno = dblkno; |
| 3902 | |
| 3903 | /* Attempt lockless lookup first. */ |
| 3904 | bp = gbincore_unlocked(bo, blkno); |
| 3905 | if (bp == NULL) |
| 3906 | goto newbuf_unlocked; |
| 3907 | |
| 3908 | error = BUF_TIMELOCK(bp, LK_EXCLUSIVE | LK_NOWAIT, NULL, "getblku", 0, |
| 3909 | 0); |
| 3910 | if (error != 0) |
| 3911 | goto loop; |
| 3912 | |
| 3913 | /* Verify buf identify has not changed since lookup. */ |
| 3914 | if (bp->b_bufobj == bo && bp->b_lblkno == blkno) |
| 3915 | goto foundbuf_fastpath; |
| 3916 | |
| 3917 | /* It changed, fallback to locked lookup. */ |
| 3918 | BUF_UNLOCK_RAW(bp); |
| 3919 | |
| 3920 | loop: |
| 3921 | BO_RLOCK(bo); |
| 3922 | bp = gbincore(bo, blkno); |
| 3923 | if (bp != NULL) { |
| 3924 | int lockflags; |
| 3925 | |
| 3926 | /* |
| 3927 | * Buffer is in-core. If the buffer is not busy nor managed, |
| 3928 | * it must be on a queue. |
| 3929 | */ |
| 3930 | lockflags = LK_EXCLUSIVE | LK_INTERLOCK | |
| 3931 | ((flags & GB_LOCK_NOWAIT) ? LK_NOWAIT : LK_SLEEPFAIL); |
| 3932 | |
| 3933 | error = BUF_TIMELOCK(bp, lockflags, |
| 3934 | BO_LOCKPTR(bo), "getblk", slpflag, slptimeo); |
| 3935 | |
| 3936 | /* |
| 3937 | * If we slept and got the lock we have to restart in case |
no test coverage detected