xfs
[Top] [All Lists]

Re: [PATCH 2/6] libxfs/linux.c: Replace use of ustat by stat

To: Christoph Hellwig <hch@xxxxxxxxxxxxx>
Subject: Re: [PATCH 2/6] libxfs/linux.c: Replace use of ustat by stat
From: Felix Janda <felix.janda@xxxxxxxxx>
Date: Wed, 13 Jan 2016 18:42:41 +0100
Cc: xfs@xxxxxxxxxxx
Delivered-to: xfs@xxxxxxxxxxx
In-reply-to: <20160113075501.GC21939@xxxxxxxxxxxxx>
References: <cover.1452627740.git.felix.janda@xxxxxxxxx> <20160112195945.GC568@nyan> <20160113075501.GC21939@xxxxxxxxxxxxx>
User-agent: Mutt/1.5.23 (2014-03-12)
Christoph Hellwig wrote:
> On Tue, Jan 12, 2016 at 08:59:45PM +0100, Felix Janda wrote:
> > ustat has been used to check whether a device file is mounted.
> > The function is deprecated and not supported by uclibc and musl.
> > Now do the check using the *mntent functions.
> > 
> > Based on patch by Natanael Copa <ncopa@xxxxxxxxxxxxxxx>.
> > 
> > Signed-off-by: Felix Janda <felix.janda@xxxxxxxxx>
> 
> ustat is a lot more efficient in checking for the mountedness
> than this loop, so I'd really prefer not to do this unconditionally.

Is this really performance relevant?

Notice that linux's platform_check_iswritable does something very
similar. I've tried to make it consistent with the version from
freebsd.c.

> As far as Linux is concerned the best thing we could do is to use
> O_EXCL for any open of a device file, as Linux overloadds O_EXCL
> behavior for block devices so that any other O_EXCL open will
> be rejected if one has the file open.
> 
> But that might be a major pain to find into the cross platform
> framework..

Hmm, so we couldn't we use for linux just something like

int
platform_check_ismounted(char *name, char *block, struct stat64 *s, int verbose)
{
        int fd = open(block, O_EXCL);
        int e = errno;
        
        if (fd != -1) close(fd);
        if (e == EBUSY) {
                if (verbose)
                        fprintf(stderr, _("%s: %s contains a mounted 
filesystem\n"), progname, name);
                return 1;
        }

        return 0;
}


Felix

<Prev in Thread] Current Thread [Next in Thread>