[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>
pgp1LJl2bQ1qW.pgp
Description: OpenPGP digital signature
- [Qemu-devel] [PATCH 09/29] 9pfs: local: llistxattr: don't follow symlinks, (continued)
- [Qemu-devel] [PATCH 09/29] 9pfs: local: llistxattr: don't follow symlinks, Greg Kurz, 2017/02/20
- [Qemu-devel] [PATCH 10/29] 9pfs: local: lsetxattr: don't follow symlinks, Greg Kurz, 2017/02/20
- [Qemu-devel] [PATCH 11/29] 9pfs: local: lremovexattr: don't follow symlinks, Greg Kurz, 2017/02/20
- [Qemu-devel] [PATCH 12/29] 9pfs: local: unlinkat: don't follow symlinks, Greg Kurz, 2017/02/20
- [Qemu-devel] [PATCH 13/29] 9pfs: local: remove: don't follow symlinks, Greg Kurz, 2017/02/20
- [Qemu-devel] [PATCH 14/29] 9pfs: local: utimensat: don't follow symlinks, Greg Kurz, 2017/02/20
- [Qemu-devel] [PATCH 15/29] 9pfs: local: statfs: don't follow symlinks, Greg Kurz, 2017/02/20
- [Qemu-devel] [PATCH 16/29] 9pfs: local: truncate: don't follow symlinks, Greg Kurz, 2017/02/20
- [Qemu-devel] [PATCH 17/29] 9pfs: local: readlink: don't follow symlinks, Greg Kurz, 2017/02/20
- [Qemu-devel] [PATCH 18/29] 9pfs: local: lstat: don't follow symlinks, Greg Kurz, 2017/02/20