All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kevin Wolf <kwolf@redhat.com>
To: Corey Bryant <coreyb@linux.vnet.ibm.com>
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
Subject: Re: [Qemu-devel] [PATCH v8 7/7] block: Enable qemu_open/close to work with fd sets
Date: Fri, 10 Aug 2012 18:34:07 +0200	[thread overview]
Message-ID: <502537FF.8020701@redhat.com> (raw)
In-Reply-To: <1344564649-6272-8-git-send-email-coreyb@linux.vnet.ibm.com>

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 <coreyb@linux.vnet.ibm.com>

> @@ -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.

> +{
> +    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).

Kevin

  parent reply	other threads:[~2012-08-10 16:34 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-10  2:10 [Qemu-devel] [PATCH v8 0/7] file descriptor passing using fd sets Corey Bryant
2012-08-10  2:10 ` [Qemu-devel] [PATCH v8 1/7] qemu-char: Add MSG_CMSG_CLOEXEC flag to recvmsg Corey Bryant
2012-08-10  2:10 ` [Qemu-devel] [PATCH v8 2/7] qapi: Introduce add-fd, remove-fd, query-fdsets Corey Bryant
2012-08-10  5:57   ` Eric Blake
2012-08-10 13:01     ` Corey Bryant
2012-08-10  7:20   ` Stefan Hajnoczi
2012-08-10 14:21     ` Corey Bryant
2012-08-10 16:08   ` Kevin Wolf
2012-08-10 16:41     ` Corey Bryant
2012-08-10  2:10 ` [Qemu-devel] [PATCH v8 3/7] monitor: Clean up fd sets on monitor disconnect Corey Bryant
2012-08-10  2:10 ` [Qemu-devel] [PATCH v8 4/7] block: Prevent detection of /dev/fdset/ as floppy Corey Bryant
2012-08-10  2:10 ` [Qemu-devel] [PATCH v8 5/7] block: Convert open calls to qemu_open Corey Bryant
2012-08-10  2:10 ` [Qemu-devel] [PATCH v8 6/7] block: Convert close calls to qemu_close Corey Bryant
2012-08-10  2:10 ` [Qemu-devel] [PATCH v8 7/7] block: Enable qemu_open/close to work with fd sets Corey Bryant
2012-08-10  6:16   ` Eric Blake
2012-08-10 14:17     ` Corey Bryant
2012-08-10 15:25       ` Eric Blake
2012-08-10 15:44         ` Corey Bryant
2012-08-10 16:34   ` Kevin Wolf [this message]
2012-08-10 16:56     ` Corey Bryant
2012-08-10 17:03       ` Corey Bryant
2012-08-10 16:36 ` [Qemu-devel] [PATCH v8 0/7] file descriptor passing using " Kevin Wolf
2012-08-10 16:57   ` Corey Bryant

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=502537FF.8020701@redhat.com \
    --to=kwolf@redhat.com \
    --cc=aliguori@us.ibm.com \
    --cc=coreyb@linux.vnet.ibm.com \
    --cc=eblake@redhat.com \
    --cc=lcapitulino@redhat.com \
    --cc=libvir-list@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@linux.vnet.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.