From patchwork Fri Jan 16 11:30:10 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suzuki K Poulose X-Patchwork-Id: 5647511 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 84E099F357 for ; Fri, 16 Jan 2015 11:30:32 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A88BB201C0 for ; Fri, 16 Jan 2015 11:30:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C41962013D for ; Fri, 16 Jan 2015 11:30:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754530AbbAPLa0 (ORCPT ); Fri, 16 Jan 2015 06:30:26 -0500 Received: from service87.mimecast.com ([91.220.42.44]:46027 "EHLO service87.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754496AbbAPLaZ (ORCPT ); Fri, 16 Jan 2015 06:30:25 -0500 Received: from cam-owa2.Emea.Arm.com (fw-tnat.cambridge.arm.com [217.140.96.140]) by service87.mimecast.com; Fri, 16 Jan 2015 11:30:22 +0000 Received: from e106634-lin.cambridge.arm.com ([10.1.255.212]) by cam-owa2.Emea.Arm.com with Microsoft SMTPSVC(6.0.3790.3959); Fri, 16 Jan 2015 11:30:22 +0000 From: "Suzuki K. Poulose" To: penberg@kernel.org Cc: levinsasha928@gmail.com, will.deacon@arm.com, aneesh.kumar@linux.vnet.ibm.com, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, "Suzuki K. Poulose" Subject: [PATCH] kvmtool: virtio-9p: Convert EMFILE error at the server to ENFILE for the guest Date: Fri, 16 Jan 2015 11:30:10 +0000 Message-Id: <1421407810-18302-1-git-send-email-suzuki.poulose@arm.com> X-Mailer: git-send-email 1.7.9.5 X-OriginalArrivalTime: 16 Jan 2015 11:30:22.0266 (UTC) FILETIME=[D083F1A0:01D0317F] X-MC-Unique: 115011611302213301 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: "Suzuki K. Poulose" If an open at the 9p server(host) fails with EMFILE (Too many open files for the process), we should return ENFILE(too many open files in the system) to the guest to indicate the actual status within the guest. This was uncovered during LTP, where getdtablesize01 fails to open the maximum number-open-files. getdtablesize01 0 TINFO : Maximum number of files a process can have opened is 1024 getdtablesize01 0 TINFO : Checking with the value returned by getrlimit...RLIMIT_NOFILE getdtablesize01 1 TPASS : got correct dtablesize, value is 1024 getdtablesize01 0 TINFO : Checking Max num of files that can be opened by a process.Should be: RLIMIT_NOFILE - 1 getdtablesize01 2 TFAIL : getdtablesize01.c:102: 974 != 1023 For a more practial impact: # ./getdtablesize01 & [1] 1834 getdtablesize01 0 TINFO : Maximum number of files a process can have opened is 1024 getdtablesize01 0 TINFO : Checking with the value returned by getrlimit...RLIMIT_NOFILE getdtablesize01 1 TPASS : got correct dtablesize, value is 1024 getdtablesize01 0 TINFO : Checking Max num of files that can be opened by a process.Should be: RLIMIT_NOFILE - 1 getdtablesize01 2 TFAIL : getdtablesize01.c:102: 974 != 1023 [--- Modified to sleep indefinitely, without closing the files --- ] # ls bash: /bin/ls: Too many open files That gives a wrong error message for the bash, when getdtablesize01 has exhausted the system wide limits, giving false indicators. With the fix, we get : # ls bash: /bin/ls: Too many open files in system Signed-off-by: Suzuki K. Poulose --- tools/kvm/virtio/9p.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tools/kvm/virtio/9p.c b/tools/kvm/virtio/9p.c index 9073a1e..b24c0f2 100644 --- a/tools/kvm/virtio/9p.c +++ b/tools/kvm/virtio/9p.c @@ -152,6 +152,10 @@ static void virtio_p9_error_reply(struct p9_dev *p9dev, { u16 tag; + /* EMFILE at server implies ENFILE for the VM */ + if (err == EMFILE) + err = ENFILE; + pdu->write_offset = VIRTIO_9P_HDR_LEN; virtio_p9_pdu_writef(pdu, "d", err); *outlen = pdu->write_offset;