Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp2863257lqt; Tue, 23 Apr 2024 04:09:50 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXV90K1cTsM1NGKb6zU3lefYFtptpXVszTiwtjQpUsLOLJAxhy+4V5u/Z8zRLK0zFBoG3CXUC6dIKJaru2KqW5Sje05hKyY7bul0V3dPA== X-Google-Smtp-Source: AGHT+IHSjxmEyMSe+BuB+cRsHKqqrjvvR3eZ3N/zX57j9GeInv9PvHkg2M8oqgJDzyO30339b3GI X-Received: by 2002:a05:6a00:114c:b0:6ea:d7b6:f4b4 with SMTP id b12-20020a056a00114c00b006ead7b6f4b4mr14142812pfm.21.1713870589904; Tue, 23 Apr 2024 04:09:49 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713870589; cv=pass; d=google.com; s=arc-20160816; b=bUtabLY+8UXpj3ZTFSZ7ZzzqBNpbaEW1l6vo6TZJdPW00DLKFbkx+xSmQNuDwMVL55 InPuAGgVUtysP5p6A5JYFv036PUbRxqQVfN0ZbeK5BRPUFgk7xTKgxl6b+iGiQWyZBWn KVjZtGvwnxciHVV4tSAnMhcj8ig1Hg1UJ9td6OmkLPCVTDb3708icQGS61qwblrXT7SF +mW9NLlSYjXH8TyqK7x8Ohx14oxwNz1oG2rXACe9XZ2dr6k8UMZjA5lYgl7cH1PENReL QEAK/87i6+z4+fDViPhx2+V21Cz0/86d2sqiYJ4XA1SuTfQBKid6EhWmsBjOoMXEKJed vR0Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=5kgbLMAE980GVvENsTEIPE4CBNTxsGKzzeodVahHYoU=; fh=YcAwmNz4oxqk24GH0R6vlSSN1FC+nTPZ8QzobDeNzRY=; b=xyjPGIgClrLlrtLqnqtU5VI/MadxQgjDJosuCyGL5N0Ljlb5380aIkhig+3kPzNQD/ CDpdUOTuV3sBYM8o8rAA8sIID/amZxr0bfjktHKZgGc8PM4qAuE58e3r9HqBJYlUIdF5 wQDSm75r9EsRyMRkxoQdeHXAjbx8qb5t6STYdALxUGXfMTR/IWakS38V+RTS5pE7SlVE znM6wdVwkbzPnNF+6xG1VH9t/zAdhjyFJoCfwy/SM/eOFOFzUXrD/tadgPj6nqsDy+O+ 0bkXMM2WUmIfIqy4BWIU1muYE3lCADDHw0DXP2CGATfoR/LL668c8oNOpdV2wyLrnz0S AVrg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@yandex.ru header.s=mail header.b=REDNVa84; arc=pass (i=1 spf=pass spfdomain=yandex.ru dkim=pass dkdomain=yandex.ru dmarc=pass fromdomain=yandex.ru); spf=pass (google.com: domain of linux-kernel+bounces-154936-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-154936-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id e9-20020a636909000000b005e3cdc24c26si9546723pgc.467.2024.04.23.04.09.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Apr 2024 04:09:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-154936-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@yandex.ru header.s=mail header.b=REDNVa84; arc=pass (i=1 spf=pass spfdomain=yandex.ru dkim=pass dkdomain=yandex.ru dmarc=pass fromdomain=yandex.ru); spf=pass (google.com: domain of linux-kernel+bounces-154936-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-154936-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 5775DB2385A for ; Tue, 23 Apr 2024 11:02:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8E2157E56C; Tue, 23 Apr 2024 11:02:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=yandex.ru header.i=@yandex.ru header.b="REDNVa84" Received: from forward103b.mail.yandex.net (forward103b.mail.yandex.net [178.154.239.150]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 79855768F0; Tue, 23 Apr 2024 11:02:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=178.154.239.150 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713870136; cv=none; b=uwXrxTYCPSOxuSx3gvx+Q9Y59FRrBPzLVom/R+0r/aGM6imSplzIH+evXWmE3kPwuApUr8U8LA3vFDKIzYElYPG+j7BKeVCjSmIkg5ngn0wkFIJ42A6tkCyIyQxzZfAPkXCoPGWa575ZVlU0ypnhQZTjEVgZy0tQ54jI6nY+6Xg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713870136; c=relaxed/simple; bh=t2/9kzu5cn37NlBr754kfbC9x4lMRcCfuiRc7DMS7GA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oKIb4sa4AvG0XspedcCSi44vxH5//oLIiujCnqguJlFtADpPPWgCRY7jSU765Up396RhicR+3rn0sGAo+Iq08qeQZ8jREhM8R/RmaCuzeqBlyvTyF0bcWiCxcgEOrxQ0CvYRxon30l+JaW7WncIbnym+BDKVxJpWFsd9eoHX27s= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=yandex.ru; spf=pass smtp.mailfrom=yandex.ru; dkim=pass (1024-bit key) header.d=yandex.ru header.i=@yandex.ru header.b=REDNVa84; arc=none smtp.client-ip=178.154.239.150 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=yandex.ru Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=yandex.ru Received: from mail-nwsmtp-smtp-production-main-42.myt.yp-c.yandex.net (mail-nwsmtp-smtp-production-main-42.myt.yp-c.yandex.net [IPv6:2a02:6b8:c12:141d:0:640:ccff:0]) by forward103b.mail.yandex.net (Yandex) with ESMTPS id 5E52860917; Tue, 23 Apr 2024 14:02:05 +0300 (MSK) Received: by mail-nwsmtp-smtp-production-main-42.myt.yp-c.yandex.net (smtp/Yandex) with ESMTPSA id 22IG0mHOiCg0-QkXjyiHP; Tue, 23 Apr 2024 14:02:04 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1713870124; bh=5kgbLMAE980GVvENsTEIPE4CBNTxsGKzzeodVahHYoU=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=REDNVa84SPivIOs507tMPS93uvn3SR3mVPvKLgWzufmj6aeinJUil5LceO6rinnsh t72TwzFis8gFJjWg6nAx/wu/F4axq44QP+PfiSWIM7vA3+DvvmpRy0QUdDNH2UzO// PwTxQrKO+IhslUWv6Bp9PaFCZlv/h3UPhxZz8NzM= Authentication-Results: mail-nwsmtp-smtp-production-main-42.myt.yp-c.yandex.net; dkim=pass header.i=@yandex.ru From: Stas Sergeev To: linux-kernel@vger.kernel.org Cc: Stas Sergeev , Stefan Metzmacher , Eric Biederman , Alexander Viro , Andy Lutomirski , Christian Brauner , Jan Kara , Jeff Layton , Chuck Lever , Alexander Aring , linux-fsdevel@vger.kernel.org, linux-api@vger.kernel.org, Paolo Bonzini , =?UTF-8?q?Christian=20G=C3=B6ttsche?= Subject: [PATCH 1/2] fs: reorganize path_openat() Date: Tue, 23 Apr 2024 14:01:47 +0300 Message-ID: <20240423110148.13114-2-stsp2@yandex.ru> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240423110148.13114-1-stsp2@yandex.ru> References: <20240423110148.13114-1-stsp2@yandex.ru> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit This patch moves the call to alloc_empty_file() below the call to path_init(). That changes is needed for the next patch, which adds a cred override for alloc_empty_file(). The needed cred info is only available after the call to path_init(). No functional changes are intended by that patch. Signed-off-by: Stas Sergeev CC: Eric Biederman CC: Alexander Viro CC: Christian Brauner CC: Jan Kara CC: Andy Lutomirski CC: linux-fsdevel@vger.kernel.org CC: linux-kernel@vger.kernel.org --- fs/namei.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/fs/namei.c b/fs/namei.c index c5b2a25be7d0..2fde2c320ae9 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -3782,22 +3782,30 @@ static struct file *path_openat(struct nameidata *nd, struct file *file; int error; - file = alloc_empty_file(op->open_flag, current_cred()); - if (IS_ERR(file)) - return file; - - if (unlikely(file->f_flags & __O_TMPFILE)) { + if (unlikely(op->open_flag & __O_TMPFILE)) { + file = alloc_empty_file(op->open_flag, current_cred()); + if (IS_ERR(file)) + return file; error = do_tmpfile(nd, flags, op, file); - } else if (unlikely(file->f_flags & O_PATH)) { + } else if (unlikely(op->open_flag & O_PATH)) { + file = alloc_empty_file(op->open_flag, current_cred()); + if (IS_ERR(file)) + return file; error = do_o_path(nd, flags, file); } else { const char *s = path_init(nd, flags); - while (!(error = link_path_walk(s, nd)) && - (s = open_last_lookups(nd, file, op)) != NULL) - ; + file = alloc_empty_file(op->open_flag, current_cred()); + error = PTR_ERR_OR_ZERO(file); + if (!error) { + while (!(error = link_path_walk(s, nd)) && + (s = open_last_lookups(nd, file, op)) != NULL) + ; + } if (!error) error = do_open(nd, file, op); terminate_walk(nd); + if (IS_ERR(file)) + return file; } if (likely(!error)) { if (likely(file->f_mode & FMODE_OPENED)) -- 2.44.0