From owner-cvs-all Sat Jul 8 3:31:35 2000 Delivered-To: cvs-all@freebsd.org Received: from flood.ping.uio.no (flood.ping.uio.no [129.240.78.31]) by hub.freebsd.org (Postfix) with ESMTP id 51D1F37B881; Sat, 8 Jul 2000 03:31:29 -0700 (PDT) (envelope-from des@flood.ping.uio.no) Received: (from des@localhost) by flood.ping.uio.no (8.9.3/8.9.3) id MAA64701; Sat, 8 Jul 2000 12:31:07 +0200 (CEST) (envelope-from des@flood.ping.uio.no) To: Kirk McKusick Cc: cvs-committers@FreeBSD.org, cvs-all@FreeBSD.org, eivind@yes.no, sthaug@nethelp.no Subject: Re: cvs commit: src/sys/dev/ccd ccd.c src/sys/dev/vn vn.c src/sys/kern kern_acct.c kern_ktrace.c kern_linker.c kern_sig.c link_aout.c link_elf.c vfs_syscalls.c vfs_vnops.c src/sys/sys vnode.h src/sys/ufs/ufs ufs_extattr.c ufs_quota.c References: <200007040334.UAA00954@freefall.freebsd.org> From: Dag-Erling Smorgrav Date: 08 Jul 2000 12:31:06 +0200 In-Reply-To: Kirk McKusick's message of "Mon, 3 Jul 2000 20:34:11 -0700 (PDT)" Message-ID: Lines: 31 User-Agent: Gnus/5.0802 (Gnus v5.8.2) Emacs/20.4 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Sender: owner-cvs-all@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG Kirk McKusick writes: > Log: > Move the truncation code out of vn_open and into the open system call > after the acquisition of any advisory locks. This fix corrects a case > in which a process tries to open a file with a non-blocking exclusive > lock. Even if it fails to get the lock it would still truncate the > file even though its open failed. With this change, the truncation > is done only after the lock is successfully acquired. Does this also fix the race condition where two processes doing open(fn, O_RDWR|O_CREAT|O_TRUNC|O_EXLOCK, mode) can end up with one file each instead of one blocking the other? This has caused me some grief in the following scenario: fd = open(tmpfile, O_RDWR|O_CREAT|O_TRUNC|O_EXLOCK, 0600); for (i = 0; i < bignum; ++i) write(fd, stuff[i], strlen(stuff[i])); rename(tmpfile, realfile); close(fd); If two processes are doing this at the same time, the first one's tmpfile is replaced by the second one's tmpfile, so that when the first process finishes writing and renames tmpfile to realfile, the second process' tmpfile goes live before it's done writing. If realfile is e.g. /var/qmail/control/rcpthosts on a mail server with lots of virtual domains, this opens a short window during which qmail will refuse mail for some domains. DES -- Dag-Erling Smorgrav - des@flood.ping.uio.no To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe cvs-all" in the body of the message