Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp1073395imm; Tue, 5 Jun 2018 08:43:02 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJDtm44HeRmLkOvbptERhvg5xokG32iqQfUASa7qo4prqDCNiUUDLfnFtyCB7CP6PnvpVSQ X-Received: by 2002:a17:902:aa95:: with SMTP id d21-v6mr26577008plr.73.1528213382055; Tue, 05 Jun 2018 08:43:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528213382; cv=none; d=google.com; s=arc-20160816; b=tKGQitjCln6dLcXtrD051iLwkkaZNPx9NRyc7hBmuPud82iTWMDauYPERVYcJ3uaJR YWv0VFi20tjdtANaaK2U9pebPO/kVsGax5GeGXdYTGYkMopFN0YESHQWwMZ7H8LP4iyT gyoOElLIRxkkH+EkeuQq+eSwQ8Vsin+SKvdtyyGpIIfnSxNJZE10PLjpTDjTVgcXVqby kDP6MFihzGCiIb9t3pTH4iHS6boKHG0nFJW3/ysCDYcNBPh7BkFYdTiyJtFTkmpCiMHl HGb0AJFm5zdjVBTeiKAwil+MzofkpbGht2NVSKQwoBJJr0yA3QvnE2kI+XDRFTOyBiBA cAAw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=z6kYEfZrDhMHeyaA29ZTMM5KVWCrL2nWdny5t+WJBJQ=; b=ejt0wN46R8IkeoBUROgN8V0zzpToBOW2kPmj1IElDes6GqvqoNgEfgbk/jNr3YzLXP D3hLGF8hjb5yjMEEjmuKy/mAFTkGaEwNvU10h3pxX1tn/dL/HyXuNGiswH7FH26ZIjXP bBAeZLtUI5z6or8ozIkxGMCdpcSKs3fysvj9lyNfKXUM8qIuuLv+R9XgD2qHF6OMjPUm xRwRQKt/MCrWw9/msYml4BLVBGgXUMuKEZCzp6Qh8pw+81yXXGldWn7xO1pcHvM0bvx6 LRUKks3HatyoNNi6xdpD6bFjhmMzlZeMzcPY9tShvQK1ny4d2gwa1NZfZ7UmQQVaRXJ5 xfRQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=bbvbHk3O; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q11-v6si39109589pgc.669.2018.06.05.08.42.47; Tue, 05 Jun 2018 08:43:02 -0700 (PDT) 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; dkim=fail header.i=@gmail.com header.s=20161025 header.b=bbvbHk3O; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752101AbeFEPmP (ORCPT + 99 others); Tue, 5 Jun 2018 11:42:15 -0400 Received: from mail-yb0-f196.google.com ([209.85.213.196]:41870 "EHLO mail-yb0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751599AbeFEPmO (ORCPT ); Tue, 5 Jun 2018 11:42:14 -0400 Received: by mail-yb0-f196.google.com with SMTP id l2-v6so926336ybp.8 for ; Tue, 05 Jun 2018 08:42:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=z6kYEfZrDhMHeyaA29ZTMM5KVWCrL2nWdny5t+WJBJQ=; b=bbvbHk3OKVadIWRtLt2d7TPKUCv1bf6p1e7ozg9vdfC9WG1yqtmCLs/im0PTJyjWrU P1zUSLh+XLcRYL8mGcncfbr3MU919d4fEghLgVbnjTNVn1IRkjAfEg8VLqyZUcz5hBm8 5m4OwlCQ9ZfDFlPj2eOLH16j+wvUILmJ9b++dZEIRCp397kcvAmUsqSr+zgoQr7W0spC zYUMv3vs6H4N/3trPBBjoukUlFLt6sg8U76ZntoK7z3KvUH3IMe5Nwr+RrRAoI+bL8kg +r78jb/T7tEPAlzmh51b1GZ24keECueIcPmUQ7o0rNbx2gSu0cYNfUVdMUi56bukqBYo 4SFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :references:mime-version:content-disposition:in-reply-to:user-agent; bh=z6kYEfZrDhMHeyaA29ZTMM5KVWCrL2nWdny5t+WJBJQ=; b=sdDeE60GwJhhii/zKcuG6En3MURtszvfGIDCg2z+cw4vwGgwOuSsgaNiwYYKxh5DuQ c84O8AerhmeZbaKYXXuxzRD+Phb9lp+DmHp4tNqEIhMYvKM5hOspu97OBOCO4KLhskd+ DxJfu91NeDOtXnAiXZUqqAwqcUiGdHhAOoGvdewf7e4FzUK8MYHQcDvtQlklZjkspwiv +/Q5ObO636y8rqrPHo9ILhMt0JyhkKirQEh57aOBrJ7c23gycnAmlYbw8630dY1KH5uf 3w610lxr3qHNzGZ+VMjBezUQrnf0trrhnU4xx6s0w+v6xp0FZp4UTdVLL+g2K1gTZNwM FydQ== X-Gm-Message-State: ALKqPwcJMLMSr+EbzQk4rBM+4LdHYIJ9zJduLYA7ST6OeIhkgwFeIQek rqI8OQ0VQ3FjuxmGPMFvbPA= X-Received: by 2002:a5b:7c2:: with SMTP id t2-v6mr14027020ybq.83.1528213333604; Tue, 05 Jun 2018 08:42:13 -0700 (PDT) Received: from localhost ([2620:10d:c091:200::1:8d19]) by smtp.gmail.com with ESMTPSA id i5-v6sm9271080ywg.110.2018.06.05.08.42.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 05 Jun 2018 08:42:12 -0700 (PDT) Date: Tue, 5 Jun 2018 08:42:10 -0700 From: "'tj@kernel.org'" To: "Eric W. Biederman" Cc: "Hatayama, Daisuke" , "'gregkh@linuxfoundation.org'" , "Okajima, Toshiyuki" , "linux-kernel@vger.kernel.org" , "'ebiederm@aristanetworks.com'" Subject: Re: [CFT][PATCH] kernfs: Correct kernfs directory seeks. Message-ID: <20180605154210.GD1351649@devbig577.frc2.facebook.com> References: <33710E6CAA200E4583255F4FB666C4E21B63D491@G01JPEXMBYT03> <87wovhqex2.fsf@xmission.com> <87po17r9ek.fsf_-_@xmission.com> <33710E6CAA200E4583255F4FB666C4E21B65E04E@G01JPEXMBYT03> <87sh62k3vk.fsf@xmission.com> <33710E6CAA200E4583255F4FB666C4E21B66BAC8@G01JPEXMBYT03> <87h8mhgsh3.fsf@xmission.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87h8mhgsh3.fsf@xmission.com> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hello, On Tue, Jun 05, 2018 at 10:31:36AM -0500, Eric W. Biederman wrote: > What I have above is not the clearest, and in fact the logic could be > better. > > The fundamental challenge is because hash collisions are possible a file > offset does not hold complete position information in a directory. > > So the kernfs node that is to be read/displayed next is saved in the > struct file. The it is tested if the saved kernfs node is usable > for finding the location in the directory. Several things may have > gone wrong. > > - Someone may have called seekdir. > - The saved kernfs node may have been renamed. > - The saved kernfs node may have been moved to a different directory in > kernfs. > - the saved kernfs node may have been deleted. > > If any of those are true the code needs to do the rbtree lookup. So, given that the whole thing is protected by a mutex which protects modifications, it could be an option to simply keep track of who's iterating what and shift them on removals. IOW, always keep cursor pointing to the next thing to visit and if that gets removed shift the cursor to the next one. Thanks. -- tejun