Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp2321828pxb; Sun, 17 Apr 2022 18:41:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx7Pd/Wf/HwpnrPXtohuT0g7oGH4NaY+6VIbtx5G/4gzZcUJHv7uAAzSO/u3FZikdR/7BbO X-Received: by 2002:a17:902:ec8e:b0:158:fd5f:2b2a with SMTP id x14-20020a170902ec8e00b00158fd5f2b2amr2666314plg.72.1650246066401; Sun, 17 Apr 2022 18:41:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650246066; cv=none; d=google.com; s=arc-20160816; b=bHnFyGcNge2lnCVc48vV/YGu/4r3FJ6ofXrDNV986YTElSgZSyBkpKhwkiAolqqtbn EvTSvKDQ6gY3QqCCNLQvdGOvJ0z3WaO1dVBfPsDOG0llYo9kml14a0uRqoaolkrBiLVn jw0n78x/Tozovn6T/3WBGB3da/k0SAnHMNqKs9LZv4lSzgn22HRYw6LzUeyLEEaypWeW ZDH1pXoM1AnAPGWDenAG2Gmd0s0L0OpY8vBe8LbdIpLnlm6nWe5Icwkj3bpCg8MMLeds 0EPsQlRF+zouOkLO6+Bd+hifCiE/04ewsyy/V6DWmpfNRrfWHK0CVtiQX6RjQlnAzOUT rPuw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature :dkim-signature; bh=R+9s+6F3BACaHFBXL1V1byfLZUQtl2m1S2ZeFTjeprQ=; b=dSWcNxcs4tAaNYhThv3GD0bMRA8BpROwLrpH5dfpggu4YeqKKeK/potzvG7Lr5WUFy blv99EKfV+mjCfQufFT21leiGoPq9KIe3jM0JFVg2kxwB5G2VRq4IYlf0+GndXbdoDXm 0y6zI53R8NhpZcSM5QpdCFWr2/9y3CuI+mOx5Ft2RauNfL4kloGwVI9MpslbLIIiN70T oI5HxhEVqT+wjFx2UwjXNbNQ0/8NbsJQvkkfz0C4k5nAGDSkeYzIsms92e4BJrKhGZk7 8n2jTCNzGAvmnjpDeMxoNudza/cdfluu+ZeKxxL+min3B9jxEJyVcUZLQ/T2mGhAcIBj dwDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codewreck.org header.s=2 header.b=zdX+mQu1; dkim=pass header.i=@codewreck.org header.s=2 header.b=AERIv7yv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=codewreck.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k1-20020a17090aaa0100b001c6f01bd910si9717968pjq.153.2022.04.17.18.40.51; Sun, 17 Apr 2022 18:41:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@codewreck.org header.s=2 header.b=zdX+mQu1; dkim=pass header.i=@codewreck.org header.s=2 header.b=AERIv7yv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=codewreck.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235130AbiDQWU5 (ORCPT + 99 others); Sun, 17 Apr 2022 18:20:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46052 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232635AbiDQWUy (ORCPT ); Sun, 17 Apr 2022 18:20:54 -0400 Received: from nautica.notk.org (nautica.notk.org [91.121.71.147]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B333311168; Sun, 17 Apr 2022 15:18:17 -0700 (PDT) Received: by nautica.notk.org (Postfix, from userid 108) id 7D099C021; Mon, 18 Apr 2022 00:18:16 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=codewreck.org; s=2; t=1650233896; bh=R+9s+6F3BACaHFBXL1V1byfLZUQtl2m1S2ZeFTjeprQ=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=zdX+mQu14BWShbXH58oAjlf+I1q8cUZjDhWlxP3rgLOa6kb3fMdIuYpEgxZYXa1lj JneQ7jgjQRN1jrRG4CQbzPR3VnZXPt4Fm2kWd1Hyo/u25lDlGfYvW6NPHRcwKK7PZj eg/Qd744cXD1VWmwtxJiRNCNmNbkoPFi9fb8SandcdUXrhXmX+UXgqW0wLKCD/uZ+6 cM2vu3EHeI0OfJu31pbKx7/WtSJJItUGC9nyur0UnV2tVsFE6QeXB31k20otH3PyLi E46cx6pZ7XWGT6cA0YTzYSs6a3wS/jp+rG08UMB8kj2N/GamAVfQcT/bPBtCAjATsO kRpfbSx3zhVJg== X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 Received: from odin.codewreck.org (localhost [127.0.0.1]) by nautica.notk.org (Postfix) with ESMTPS id 61C07C009; Mon, 18 Apr 2022 00:18:11 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=codewreck.org; s=2; t=1650233894; bh=R+9s+6F3BACaHFBXL1V1byfLZUQtl2m1S2ZeFTjeprQ=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=AERIv7yvLj5DI+RoWTt4FSHIcMJVL5DgKPQQEcZmURu3tnQlBRvhJajTmVSUCjmqu krM9SVxJQ492j+CKF4vntq4VGFwehFtm/wTn+TBWJ18X6B8iv3Mykd9qi/JlSd17wh CldTzCQvcXBhp6dELMu5lxT5+Ycb44Q6fCnHplYqfmJGel7YtFhmxytUeYTjugE4Ku Cr/qrbg5CktegK54JLe04WLxn6PeCa2N/Uv1tA4Je0XeVqIEcZRHPaS1rTEDtnejrs 4XI6V90ajgLapiqns6Cx2A15W6VGReDMmlM1Ijtl/TmgOfq9c+iu+z47hPOgp+q17s 3lOic+jlEMvJw== Received: from localhost (odin.codewreck.org [local]) by odin.codewreck.org (OpenSMTPD) with ESMTPA id 32b99519; Sun, 17 Apr 2022 22:18:08 +0000 (UTC) Date: Mon, 18 Apr 2022 07:17:53 +0900 From: asmadeus@codewreck.org To: David Howells , Christian Schoenebeck Cc: David Kahurani , davem@davemloft.net, ericvh@gmail.com, kuba@kernel.org, linux-kernel@vger.kernel.org, lucho@ionkov.net, netdev@vger.kernel.org, v9fs-developer@lists.sourceforge.net, Greg Kurz Subject: 9p EBADF with cache enabled (Was: 9p fs-cache tests/benchmark (was: 9p fscache Duplicate cookie detected)) Message-ID: References: <2551609.RCmPuZc3Qn@silver> <8420857.9FB56xACZ5@silver> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org (fixed the subject again and promoted David Howells to To, please read the previous couple of mails when you have time) asmadeus@codewreck.org wrote on Mon, Apr 18, 2022 at 06:22:26AM +0900: > Christian Schoenebeck wrote on Sun, Apr 17, 2022 at 03:52:43PM +0200: > > > From the looks of it, write fails in v9fs_write_begin, which itself > > > fails because it tries to read first on a file that was open with > > > O_WRONLY|O_CREAT|O_APPEND. > > > Since this is an append the read is necessary to populate the local page > > > cache when writing, and we're careful that the writeback fid is open in > > > write, but not about read... BTW now this is understood here's a much simpler reproducer: ---append.c---- #include #include int main(int argc, char *argv[]) { if (argc < 2) return 1; int fd = open(argv[1], O_WRONLY|O_APPEND); if (fd < 0) return 1; if (write(fd, "test\n", 5) < 0) return 1; return 0; } --- --- echo foo > foo echo 3 > /proc/sys/vm/drop_caches strace ./append foo ... openat(AT_FDCWD, "foo", O_WRONLY|O_APPEND) = 3 write(3, "test\n", 5) = -1 EBADF (Bad file descriptor) --- at 9p client level: ---- 9pnet: (00000460) >>> TWALK fids 1,2 nwname 1d wname[0] t 9pnet: (00000460) >>> size=20 type: 110 tag: 0 9pnet: (00000460) <<< size=22 type: 111 tag: 0 9pnet: (00000460) <<< RWALK nwqid 1: 9pnet: (00000460) <<< [0] 0.6e672b.6289a895 9pnet: (00000460) >>> TGETATTR fid 2, request_mask 6143 9pnet: (00000460) >>> size=19 type: 24 tag: 0 9pnet: (00000460) <<< size=160 type: 25 tag: 0 9pnet: (00000460) <<< RGETATTR st_result_mask=6143 <<< qid=0.6e672b.6289a895 <<< st_mode=000081ed st_nlink=1 <<< st_uid=1000 st_gid=100 <<< st_rdev=0 st_size=d538 st_blksize=126976 st_blocks=112 <<< st_atime_sec=1650233493 st_atime_nsec=697920121 <<< st_mtime_sec=1650233493 st_mtime_nsec=19911120 <<< st_ctime_sec=1650233493 st_ctime_nsec=19911120 <<< st_btime_sec=0 st_btime_nsec=0 <<< st_gen=0 st_data_version=0 9pnet: (00000460) >>> TWALK fids 2,3 nwname 0d wname[0] (null) 9pnet: (00000460) >>> size=17 type: 110 tag: 0 9pnet: (00000460) <<< size=9 type: 111 tag: 0 9pnet: (00000460) <<< RWALK nwqid 0: 9pnet: (00000460) >>> TLOPEN fid 3 mode 32768 9pnet: (00000460) >>> size=15 type: 12 tag: 0 9pnet: (00000460) <<< size=24 type: 13 tag: 0 9pnet: (00000460) <<< RLOPEN qid 0.6e672b.6289a895 iounit 1f000 9pnet: (00000460) >>> TREAD fid 3 offset 0 8192 9pnet: (00000460) >>> size=23 type: 116 tag: 0 9pnet: (00000460) <<< size=8203 type: 117 tag: 0 9pnet: (00000460) <<< RREAD count 8192 9pnet: (00000460) >>> TREAD fid 3 offset 8192 16384 9pnet: (00000460) >>> size=23 type: 116 tag: 0 9pnet: (00000460) <<< size=16395 type: 117 tag: 0 9pnet: (00000460) <<< RREAD count 16384 9pnet: (00000460) >>> TXATTRWALK file_fid 2, attr_fid 4 name security.capability 9pnet: (00000460) >>> size=36 type: 30 tag: 0 9pnet: (00000460) <<< size=11 type: 7 tag: 0 9pnet: (00000460) <<< RLERROR (-95) 9pnet: (00000460) >>> TREAD fid 3 offset 24576 30008 9pnet: (00000460) >>> size=23 type: 116 tag: 0 9pnet: (00000460) <<< size=30019 type: 117 tag: 0 9pnet: (00000460) <<< RREAD count 30008 9pnet: (00000460) >>> TWALK fids 1,4 nwname 1d wname[0] foo 9pnet: (00000460) >>> size=22 type: 110 tag: 0 9pnet: (00000460) <<< size=22 type: 111 tag: 0 9pnet: (00000460) <<< RWALK nwqid 1: 9pnet: (00000460) <<< [0] 0.6e66f9.625c86a5 9pnet: (00000460) >>> TGETATTR fid 4, request_mask 6143 9pnet: (00000460) >>> size=19 type: 24 tag: 0 9pnet: (00000460) <<< size=160 type: 25 tag: 0 9pnet: (00000460) <<< RGETATTR st_result_mask=6143 <<< qid=0.6e66f9.625c86a5 <<< st_mode=000081a4 st_nlink=1 <<< st_uid=0 st_gid=0 <<< st_rdev=0 st_size=9 st_blksize=126976 st_blocks=8 <<< st_atime_sec=1650233249 st_atime_nsec=226674419 <<< st_mtime_sec=1650233253 st_mtime_nsec=226727529 <<< st_ctime_sec=1650233253 st_ctime_nsec=226727529 <<< st_btime_sec=0 st_btime_nsec=0 <<< st_gen=0 st_data_version=0 9pnet: (00000460) >>> TWALK fids 4,5 nwname 0d wname[0] (null) 9pnet: (00000460) >>> size=17 type: 110 tag: 0 9pnet: (00000460) <<< size=9 type: 111 tag: 0 9pnet: (00000460) <<< RWALK nwqid 0: 9pnet: (00000460) >>> TLOPEN fid 5 mode 33793 9pnet: (00000460) >>> size=15 type: 12 tag: 0 9pnet: (00000460) <<< size=24 type: 13 tag: 0 9pnet: (00000460) <<< RLOPEN qid 0.6e66f9.625c86a5 iounit 1f000 9pnet: (00000460) >>> TWALK fids 4,6 nwname 0d wname[0] (null) 9pnet: (00000460) >>> size=17 type: 110 tag: 0 9pnet: (00000460) <<< size=9 type: 111 tag: 0 9pnet: (00000460) <<< RWALK nwqid 0: 9pnet: (00000460) >>> TLOPEN fid 6 mode 2 9pnet: (00000460) >>> size=15 type: 12 tag: 0 9pnet: (00000460) <<< size=24 type: 13 tag: 0 9pnet: (00000460) <<< RLOPEN qid 0.6e66f9.625c86a5 iounit 1f000 9pnet: (00000460) >>> TXATTRWALK file_fid 4, attr_fid 7 name security.capability 9pnet: (00000460) >>> size=36 type: 30 tag: 0 9pnet: (00000460) <<< size=11 type: 7 tag: 0 9pnet: (00000460) <<< RLERROR (-95) 9pnet: (00000460) >>> TREAD fid 5 offset 0 9 9pnet: (00000460) >>> size=23 type: 116 tag: 0 9pnet: (00000460) <<< size=11 type: 7 tag: 0 9pnet: (00000460) <<< RLERROR (-9) 9pnet: (00000460) >>> TCLUNK fid 5 (try 0) 9pnet: (00000460) >>> size=11 type: 120 tag: 0 9pnet: (00000460) <<< size=7 type: 121 tag: 0 9pnet: (00000460) <<< RCLUNK fid 5 9pnet: (00000460) >>> TCLUNK fid 3 (try 0) 9pnet: (00000460) >>> size=11 type: 120 tag: 0 9pnet: (00000460) <<< size=7 type: 121 tag: 0 9pnet: (00000460) <<< RCLUNK fid 3 ------- -- Dominique