Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp2120111lqt; Mon, 22 Apr 2024 01:52:51 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVQaHAyMZopdKWzC9hrK9nqaj7RqWznwCEty/ZIOWtXjkTRw4pO81mqf+TB9KL1NXy6Evpa+Jjs7qwzfhcfOxfWJ4SVbG29bl77ukGuXA== X-Google-Smtp-Source: AGHT+IFHwq/uSp0sdmDkf7QYTAgZWJVEnHkxLmkCOET6YpQN0AV8Y0AF2jlXJh5HzzWpeuZXB5OC X-Received: by 2002:a05:620a:12dc:b0:78d:6dce:acc2 with SMTP id e28-20020a05620a12dc00b0078d6dceacc2mr10955052qkl.26.1713775971106; Mon, 22 Apr 2024 01:52:51 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713775971; cv=pass; d=google.com; s=arc-20160816; b=NNCVa2VG8fEgXoRB8Hf8qbt1+/g0+teiAajUJsFm0AsQtCV9+BHlrp7XSj9aoPtfHV E+TmyAGmOnEZrL4riNol9Jgan/wMYwAZ7Uc2lcr7FYG5t+dS2t+rZiIcS/HJqsifagkI kca3nwRewvRl1F8a3Wg8Y02WlrsA4vnCx2qDfug42iwDshMVZrCEi2dz9qtAXC0C5qSF OLBOJgkRdpGA4qucpOANi6O4U02rbAY+J6bC5wUH6fwubNeyBwkj67GaCe1Nt8oRgRnx /OVr54X50U1lL6pQO9Qb0XY41AlFTZqe/BhmNYecuPOPQc9Xz7/J291Km8PFeBdi2fTq V45g== 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:message-id:date:subject:cc:to :from:dkim-signature; bh=5kgbLMAE980GVvENsTEIPE4CBNTxsGKzzeodVahHYoU=; fh=9AzAXS4w4IsN+VvRGocCrL3OXJQhCk/z3Vdk6r2WJmY=; b=bIagq86Am5k8otHgScp9oN3YqNsyjRT7qBIMyoht0j354XU6Gf8QdGoAyu9jxjw6Zo KpXvBv7X1PyK9cA66uk1jFq+4Rk5obYmae7x3+ppI8/TMoGS166EVClGc1kfF1HrNh69 NdLQHwfq1ZAxOMCW0YPer7cAJvXuLrQ8mxMVrbqu90uxjWLWDHa0caSR2g0DTKqeYDg+ tCAx1Hri6a/Eqe1FWPayBu2dLgvyWEy5sNFaRRZND6GHH/TZPvUwDoPFpqYknICg9fvX gh96dX8bjR21xb2ihQ+t7XEO45C2MGnBSNvYPnxVe8mo1Uf+HWMDQxivvzN1DB5mJ8Ht XYzA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@yandex.ru header.s=mail header.b=ObvEmjJ0; 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-153022-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-153022-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id c1-20020a37e101000000b0078d6ee9092csi9993121qkm.372.2024.04.22.01.52.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Apr 2024 01:52:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-153022-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@yandex.ru header.s=mail header.b=ObvEmjJ0; 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-153022-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-153022-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id D110D1C208DE for ; Mon, 22 Apr 2024 08:52:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DC4115491B; Mon, 22 Apr 2024 08:50:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=yandex.ru header.i=@yandex.ru header.b="ObvEmjJ0" Received: from forward202c.mail.yandex.net (forward202c.mail.yandex.net [178.154.239.219]) (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 9C5AB5337F; Mon, 22 Apr 2024 08:50:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=178.154.239.219 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713775841; cv=none; b=RoK3vgFlhpTniApfRZMnRs2uWFqSsiptk0izcaFikJj9Y7rphNtdOxBKZZWvA4jJTbjdJQYJeTCWuP6hJ4Gvr/U/JsslTwHZfIABVYat+B0I98PyvXYAPfbQkHKulo5tTqabWF6rA/ET08NSS9JooTiHEdHy6MQf2Q9qGSIqSeU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713775841; c=relaxed/simple; bh=t2/9kzu5cn37NlBr754kfbC9x4lMRcCfuiRc7DMS7GA=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=FGNKMg44e7EUA0iUEh1KwbEZhFjbfjp4IJjkqfXWGv1r5C54zPwP2sZvJnYXGwZ4IYvyl7VDMERuTT7EqVhrj7N8DWrvktGKscgnksAFDTKce+E8B1otuxs6t72tGxUrT9gJX9zQpBoY5OX2yPvZHsLuz7i/068OPKt5p01rZJM= 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=ObvEmjJ0; arc=none smtp.client-ip=178.154.239.219 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 forward102b.mail.yandex.net (forward102b.mail.yandex.net [IPv6:2a02:6b8:c02:900:1:45:d181:d102]) by forward202c.mail.yandex.net (Yandex) with ESMTPS id 66E0C64AEE; Mon, 22 Apr 2024 11:45:25 +0300 (MSK) Received: from mail-nwsmtp-smtp-production-main-39.sas.yp-c.yandex.net (mail-nwsmtp-smtp-production-main-39.sas.yp-c.yandex.net [IPv6:2a02:6b8:c08:f220:0:640:b85:0]) by forward102b.mail.yandex.net (Yandex) with ESMTPS id 05F1A609C3; Mon, 22 Apr 2024 11:45:17 +0300 (MSK) Received: by mail-nwsmtp-smtp-production-main-39.sas.yp-c.yandex.net (smtp/Yandex) with ESMTPSA id FjEovW2OjiE0-dGbQCA9m; Mon, 22 Apr 2024 11:45:16 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1713775516; bh=5kgbLMAE980GVvENsTEIPE4CBNTxsGKzzeodVahHYoU=; h=Message-ID:Date:Cc:Subject:To:From; b=ObvEmjJ0lkv8C/q4v7NpJijo21BTW5495IkxfhW9ozV8fJYF6NC418d0HkeuGRse9 SNu2Duz1Hqsf3mB+ULgpt6ikY1kPl5moJ8mmms8eJy1eBTr6ZT4FnN7gmzJwoz0Ecr Di/zpjzACSTXUbU6UJoUbvSatw5coHKwl7QYkQQg= Authentication-Results: mail-nwsmtp-smtp-production-main-39.sas.yp-c.yandex.net; dkim=pass header.i=@yandex.ru From: Stas Sergeev To: linux-kernel@vger.kernel.org Cc: Stas Sergeev , Eric Biederman , Alexander Viro , Christian Brauner , Jan Kara , Andy Lutomirski , linux-fsdevel@vger.kernel.org Subject: [PATCH 1/2] fs: reorganize path_openat() Date: Mon, 22 Apr 2024 11:45:04 +0300 Message-ID: <20240422084505.3465238-1-stsp2@yandex.ru> X-Mailer: git-send-email 2.44.0 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