From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:36009) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Szsf0-0001pn-Le for qemu-devel@nongnu.org; Fri, 10 Aug 2012 13:06:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Szsex-0004gQ-94 for qemu-devel@nongnu.org; Fri, 10 Aug 2012 13:06:06 -0400 Received: from e35.co.us.ibm.com ([32.97.110.153]:34266) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Szsex-0004gF-1z for qemu-devel@nongnu.org; Fri, 10 Aug 2012 13:06:03 -0400 Received: from /spool/local by e35.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 10 Aug 2012 11:06:01 -0600 Received: from d03relay05.boulder.ibm.com (d03relay05.boulder.ibm.com [9.17.195.107]) by d03dlp01.boulder.ibm.com (Postfix) with ESMTP id ABA611FF0022 for ; Fri, 10 Aug 2012 17:04:19 +0000 (WET) Received: from d03av04.boulder.ibm.com (d03av04.boulder.ibm.com [9.17.195.170]) by d03relay05.boulder.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id q7AH3m8w119366 for ; Fri, 10 Aug 2012 11:04:04 -0600 Received: from d03av04.boulder.ibm.com (loopback [127.0.0.1]) by d03av04.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id q7AH3VPR004332 for ; Fri, 10 Aug 2012 11:03:31 -0600 Message-ID: <50253EE0.1020901@linux.vnet.ibm.com> Date: Fri, 10 Aug 2012 13:03:28 -0400 From: Corey Bryant MIME-Version: 1.0 References: <1344564649-6272-1-git-send-email-coreyb@linux.vnet.ibm.com> <1344564649-6272-8-git-send-email-coreyb@linux.vnet.ibm.com> <502537FF.8020701@redhat.com> <50253D23.1090409@linux.vnet.ibm.com> In-Reply-To: <50253D23.1090409@linux.vnet.ibm.com> Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v8 7/7] block: Enable qemu_open/close to work with fd sets List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Kevin Wolf Cc: aliguori@us.ibm.com, stefanha@linux.vnet.ibm.com, libvir-list@redhat.com, qemu-devel@nongnu.org, lcapitulino@redhat.com, pbonzini@redhat.com, eblake@redhat.com On 08/10/2012 12:56 PM, Corey Bryant wrote: > > > On 08/10/2012 12:34 PM, Kevin Wolf wrote: >> Am 10.08.2012 04:10, schrieb Corey Bryant: >>> When qemu_open is passed a filename of the "/dev/fdset/nnn" >>> format (where nnn is the fdset ID), an fd with matching access >>> mode flags will be searched for within the specified monitor >>> fd set. If the fd is found, a dup of the fd will be returned >>> from qemu_open. >>> >>> Each fd set has a reference count. The purpose of the reference >>> count is to determine if an fd set contains file descriptors that >>> have open dup() references that have not yet been closed. It is >>> incremented on qemu_open and decremented on qemu_close. It is >>> not until the refcount is zero that file desriptors in an fd set >>> can be closed. If an fd set has dup() references open, then we >>> must keep the other fds in the fd set open in case a reopen >>> of the file occurs that requires an fd with a different access >>> mode. >>> >>> Signed-off-by: Corey Bryant >> >>> @@ -78,6 +79,69 @@ int qemu_madvise(void *addr, size_t len, int advice) >>> #endif >>> } >>> >>> +/* >>> + * Dups an fd and sets the flags >>> + */ >>> +static int qemu_dup(int fd, int flags) >> >> qemu_dup() is probably not a good name. We'll want to use it when we >> need to get a wrapper around dup(). And I suspect that we will need it >> for making bdrv_reopen() compatible with fdset refcounting. >> > > Do you you have a suggestion for a name? > >>> +{ >>> + int ret; >>> + int serrno; >>> + int dup_flags; >>> + int setfl_flags; >>> + >>> + if (flags & O_CLOEXEC) { >>> +#ifdef F_DUPFD_CLOEXEC >>> + ret = fcntl(fd, F_DUPFD_CLOEXEC, 0); >>> +#else >>> + ret = dup(fd); >>> + if (ret != -1) { >>> + qemu_set_cloexec(ret); >>> + } >>> +#endif >>> + } else { >>> + ret = dup(fd); >>> + } >> >> qemu_open() is supposed to add O_CLOEXEC by itself, so I think we should >> execute the then branch unconditionally (or we would have to change the >> qemu_dup() call below to add it - but the fact that O_CLOEXEC isn't even >> necessarily defined doesn't help with that). > > Sure I can modify this to always add O_CLOEXEC. (I know you mentioned > this before but I think I interpreted the comment as a question to others.) > > Do you also want me to modify qemu_open to always add O_CLOEXEC? > My mistake.. it's always set in qemu_open already. -- Regards, Corey