From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:54889) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QFTq3-0002Lx-Aw for qemu-devel@nongnu.org; Thu, 28 Apr 2011 12:13:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QFTq2-0006oy-KX for qemu-devel@nongnu.org; Thu, 28 Apr 2011 12:13:11 -0400 Received: from mail-fx0-f45.google.com ([209.85.161.45]:51929) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QFTq2-0006ot-EL for qemu-devel@nongnu.org; Thu, 28 Apr 2011 12:13:10 -0400 Received: by fxm2 with SMTP id 2so2210149fxm.4 for ; Thu, 28 Apr 2011 09:13:09 -0700 (PDT) MIME-Version: 1.0 Sender: ico2ico2@gmail.com Date: Thu, 28 Apr 2011 17:13:09 +0100 Message-ID: From: Sassan Panahinejad Content-Type: multipart/alternative; boundary=001517475ad253ed8004a1fcd5cb Subject: [Qemu-devel] Bug in virtio-9p when fstatting an fd referring to a file that no longer exists List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org --001517475ad253ed8004a1fcd5cb Content-Type: text/plain; charset=ISO-8859-1 It should be possible for guest applications to fstat a file for which they have a valid file descriptor, even if the file has been removed. Demonstrated by the code sample below (fstat reports no such file or directory). Strangely it seems that reading from a file in this state works fine (and when both are run, the server receives a different fid for each). On any other filesystem, the code runs correctly. On our 9p filesystem it fails. Many applications (including bash) depend on this working correctly. I will continue investigating, but any thoughts anyone has on the subject would be appreciated. Thanks Sassan #include #include #include #include #include int main(void) { int ret; struct stat statbuf; int fd = open("test.txt", O_RDWR | O_CREAT, 0666); if (fd < 0) { printf("open failed: %m\n"); return 1; } ret = write(fd, "test1\n", 6); if (ret < 0) { printf("write1 failed: %m\n"); return 1; } ret = unlink("test.txt"); if (ret < 0) { printf("unlink failed: %m\n"); return 1; } ret = fstat(fd, &statbuf); if (ret < 0) { printf("fstat failed: %m\n"); return 1; } return 0; } --001517475ad253ed8004a1fcd5cb Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable It should be possible for guest applications to fstat a file for which they= have a valid file descriptor, even if the file has been removed.
Demons= trated by the code sample below (fstat reports no such file or directory).<= br> Strangely it seems that reading from a file in this state works fine (and w= hen both are run, the server receives a different fid for each).
On any other filesystem, the code runs correctly. On our 9p filesystem it f= ails.
Many applications (including bash) depend on this working correctl= y.
I will continue investigating, but any thoughts anyone has on the subject w= ould be appreciated.


Thanks
Sassan


#include <stdio.h>
#include <unistd.h>
= #include <fcntl.h>
#include <sys/types.h>
#include <sy= s/stat.h>


int main(void)
{
=A0=A0=A0=A0=A0=A0=A0 int re= t;
=A0=A0=A0=A0=A0=A0=A0 struct stat statbuf;
=A0=A0=A0=A0=A0=A0=A0 int fd =3D open("test.txt", O_RDWR | O_CREA= T, 0666);
=A0=A0=A0=A0=A0=A0=A0 if (fd < 0) {
=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0 printf("open failed: %m\n");
=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 return 1;
=A0=A0=A0=A0=A0=A0= =A0 }
=A0=A0=A0=A0=A0=A0=A0 ret =3D write(fd, "test1\n", 6); =A0=A0=A0=A0=A0=A0=A0 if (ret < 0) {
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0 printf("write1 failed: %m\n");
=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 return 1;
=A0=A0=A0=A0=A0=A0=A0 }
=A0= =A0=A0=A0=A0=A0=A0 ret =3D unlink("test.txt");
=A0=A0=A0=A0=A0= =A0=A0 if (ret < 0) {
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 p= rintf("unlink failed: %m\n");
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 return 1;
=A0=A0=A0=A0=A0= =A0=A0 }
=A0=A0=A0=A0=A0=A0=A0 ret =3D fstat(fd, &statbuf);
=A0= =A0=A0=A0=A0=A0=A0 if (ret < 0) {
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0 printf("fstat failed: %m\n");
=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0 return 1;
=A0=A0=A0=A0=A0=A0=A0 }
=A0=A0= =A0=A0=A0=A0=A0 return 0;
}
--001517475ad253ed8004a1fcd5cb--