9p: getattr: use fstat if we have a fd
diff mbox

Message ID 146418539999.31132.7141368831414401393.stgit@bahia.huguette.org
State New
Headers show

Commit Message

Greg Kurz May 25, 2016, 2:18 p.m. UTC
If we have an opened fd, it is better to call fstat() as the underlying
file may have been unlinked and lstat() will fail.

Signed-off-by: Greg Kurz <gkurz@linux.vnet.ibm.com>
---

This QEMU patch goes with the create-unlink-getattr fix at:

http://git.kernel.org/cgit/linux/kernel/git/ericvh/v9fs.git/commit/?id=5eb393c464294b2183d526a25a344d7ae6ba8383

I could verify that a basic program doing open(O_CREAT)+unlink()+fstat() in
the guest works as expected.

Eric (or other v9fs maintainers),

Is there a chance the above kernel patch gets pushed upstream in a near
future ?

Cheers.

--
Greg

 hw/9pfs/9p.c |    6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

Patch
diff mbox

diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c
index 482a35ead51b..572aaf09930b 100644
--- a/hw/9pfs/9p.c
+++ b/hw/9pfs/9p.c
@@ -1103,7 +1103,11 @@  static void v9fs_getattr(void *opaque)
      * Currently we only support BASIC fields in stat, so there is no
      * need to look at request_mask.
      */
-    retval = v9fs_co_lstat(pdu, &fidp->path, &stbuf);
+    if (fidp->fs.fd > 0) {
+        retval = v9fs_co_fstat(pdu, fidp, &stbuf);
+    } else {
+        retval = v9fs_co_lstat(pdu, &fidp->path, &stbuf);
+    }
     if (retval < 0) {
         goto out;
     }