Received: by 2002:ac0:a679:0:0:0:0:0 with SMTP id p54csp751714imp; Thu, 21 Feb 2019 10:24:40 -0800 (PST) X-Google-Smtp-Source: AHgI3IZIXTQowJObJhOgSr5jxF1ryBYX7kgNu63lqstm4LBZ2mpsq+/B8gXeQU7niuiG2F3hxS+7 X-Received: by 2002:aa7:92da:: with SMTP id k26mr27059359pfa.216.1550773480055; Thu, 21 Feb 2019 10:24:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550773480; cv=none; d=google.com; s=arc-20160816; b=f3ms7F71Ax8KLF6n4zXY7VcMaPJuWrxaVSr4rdJOv1kgzujELmRURpel0lUpy01vpo PSYQhHYAeEQQ/TYyDRE1AlCOIsPcDQ0BA6XLegjS8z3u7XDNXJqQIEXMyNl3mA2eX2I6 1pDvGrodXg2f3qyHsXo1eu3YXkhX4iVG3Bpjq3OG/Du1fv7xc29GexDb+oYHpCs8xDDa KZ0LqouLtCmuBvHb/kG3rHLOZE4Ia9A66TYCHiel+hnG39eBzzYKYRAo+EE6wgCQzM+1 FQkrv79kkqiylW/opjXvaP0bHPu+r6UtH8hJ2ppIwABHJ5vcIKozYYucYg2Um5tj+/kV Gn9A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=4BPGhMMWIsZtl/ebCv8AuP93HT5e9476fWXeFEv/5kI=; b=qMwMEWxgXe6i+EKedCn4Kh6FUwMv1/CBbCHOLuWBL4ZdqDxQOlQMUXHZ0wvad3Swiz fkumXi6WAW/9q9S/OOc4etVJguxJOL1BJd43nQXiUwx/CackFZs7EDLKGVtullGArqre qJQ1hp19tVYuWqAdaINQMOAurSUx3m4MB7Aethe2rOFGfZH8g+1JJ5/lhnfWwxDVRECK dSK2/Ww07BGCuZ3IjqKHAv0vCTDj6RPZwewkwj67obkplYgD8WW8a3EyImNipfowjUI2 tGaIA8LWWd7rOjOM1OIHQP0TACnmMPbAznYNsqTu6F6NWoKtdg4j1CNW7FHwYOcfViHw FBMA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z185si21201949pgb.222.2019.02.21.10.24.24; Thu, 21 Feb 2019 10:24:40 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728622AbfBUSWo (ORCPT + 99 others); Thu, 21 Feb 2019 13:22:44 -0500 Received: from mx2.suse.de ([195.135.220.15]:59562 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726155AbfBUSWn (ORCPT ); Thu, 21 Feb 2019 13:22:43 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id B3A69AFC0; Thu, 21 Feb 2019 18:22:42 +0000 (UTC) From: Johannes Thumshirn To: Christoph Hellwig Cc: Linux Kernel Mailinglist , Linux NVMe Mailinglist , Johannes Thumshirn Subject: [PATCH] nvmet: disable direct I/O when unavailable Date: Thu, 21 Feb 2019 19:22:34 +0100 Message-Id: <20190221182234.22345-1-jthumshirn@suse.de> X-Mailer: git-send-email 2.16.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Some file-systems, like tmpfs, do not support direct IO, but file-backed namespaces default to using direct IO. If direct IO is unavailable fall back to using buffered IO for the file-backed namespace. This might not ultimately be a solution for production environments but for test environments it sometimes is feasible to use tmpfs. Signed-off-by: Johannes Thumshirn --- drivers/nvme/target/io-cmd-file.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/nvme/target/io-cmd-file.c b/drivers/nvme/target/io-cmd-file.c index 517522305e5c..8a861cc0160e 100644 --- a/drivers/nvme/target/io-cmd-file.c +++ b/drivers/nvme/target/io-cmd-file.c @@ -38,11 +38,21 @@ int nvmet_file_ns_enable(struct nvmet_ns *ns) ns->file = filp_open(ns->device_path, flags, 0); if (IS_ERR(ns->file)) { + if (ns->file == ERR_PTR(-EINVAL) && (flags & O_DIRECT)) { + flags &= ~O_DIRECT; + ns->buffered_io = 0; + ns->file = filp_open(ns->device_path, flags, 0); + if (!IS_ERR(ns->file)) { + pr_info("direct I/O unavailable, falling back to buffered I/O\n"); + goto getattr; + } + } pr_err("failed to open file %s: (%ld)\n", ns->device_path, PTR_ERR(ns->file)); return PTR_ERR(ns->file); } +getattr: ret = vfs_getattr(&ns->file->f_path, &stat, STATX_SIZE, AT_STATX_FORCE_SYNC); if (ret) -- 2.16.4