Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 26 Aug 1998 08:35:48 -0400 (EDT)
From:      Luoqi Chen <luoqi@watermarkgroup.com>
To:        current@FreeBSD.ORG
Subject:   possible race window for getblk?
Message-ID:  <199808261235.IAA04095@lor.watermarkgroup.com>

next in thread | raw e-mail | index | archive | help

In function getblk(), there is a check after getnewbuf() call to make sure
there is no other buffer created when getnewbuf() is blocked: (vfs_bio.c)

                if ((bp = getnewbuf(vp, blkno,
                        slpflag, slptimeo, size, maxsize)) == 0) {
                        if (slpflag || slptimeo) {
                                splx(s);
                                return NULL;
                        }
                        goto loop;
                }
                 
                /*
                 * This code is used to make sure that a buffer is not
                 * created while the getnewbuf routine is blocked.
                 * Normally the vnode is locked so this isn't a problem.
                 * VBLK type I/O requests, however, don't lock the vnode.
                 */ 
                if (!VOP_ISLOCKED(vp) && gbincore(vp, blkno)) {
                        bp->b_flags |= B_INVAL;
                        brelse(bp);
                        goto loop;
                }

The problem with this check is, reads only hold shared lock on the vnode,
thus the vnode lock won't prevent two reads from successfully creating
two new buffers at the same block offset. This check should be extended
to shared lock:
                if (VOP_ISLOCKED(vp) != LK_EXCLUSIVE && gbincore(vp, blkno)) {
                        bp->b_flags |= B_INVAL;
                        brelse(bp);
                        goto loop;
                }

-lq

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-current" in the body of the message



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199808261235.IAA04095>