qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH 13/29] 9pfs: local: remove: don't follow symlink


From: Greg Kurz
Subject: Re: [Qemu-devel] [PATCH 13/29] 9pfs: local: remove: don't follow symlinks
Date: Fri, 24 Feb 2017 01:21:26 +0100

On Thu, 23 Feb 2017 14:23:15 +0000
Stefan Hajnoczi <address@hidden> wrote:

> On Mon, Feb 20, 2017 at 03:41:00PM +0100, Greg Kurz wrote:
> > +    dirfd = local_opendir_nofollow(ctx, dirpath);
> > +    if (dirfd) {
> > +        goto out;
> >      }
> >  
> > -    buffer = rpath(ctx, path);
> > -    err = remove(buffer);
> > -    g_free(buffer);
> > +    if (fstatat(dirfd, path, &stbuf, AT_SYMLINK_NOFOLLOW) < 0) {
> > +        goto err_out;
> > +    }
> > +
> > +    if (S_ISDIR(stbuf.st_mode)) {
> > +        flags |= AT_REMOVEDIR;
> > +    }
> > +
> > +    err = local_unlinkat_common(ctx, dirfd, name, flags);  
> 
> The alternative is optimistically skip fstat but then do:
> 
>   if (err == EISDIR) {

It would be err == -1 && errno == EISDIR actually.

>       err = local_unlinkat_common(ctx, dirfd, name, flags | AT_REMOVEDIR);
>   }
> 
> It might be faster.
> 

This would work for passthrough and mapped modes indeed. For mapped-file
mode, things are more complicated though. If path points to a directory
and we call local_unlinkat_common() without AT_REMOVEDIR, it won't unlink
the metadata directory and unlinkat() will fail with ENOENT because
the directory isn't empty... I'd rather try to optimize in a followup
patch later to avoid the extra complexity.

> Reviewed-by: Stefan Hajnoczi <address@hidden>

Attachment: pgp1LJl2bQ1qW.pgp
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]