Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp2860465lqt; Tue, 23 Apr 2024 04:05:04 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWqU7z4EoIDkI6EjAk8M3UfFPP2ExdqapucH2uZp98AzbgL6Cd9evCu+Xq2Lf3Bl3slyn5dhfzuDIEd/RL6Yz57YfSorslN98eVrJABcQ== X-Google-Smtp-Source: AGHT+IGQUa7BL/RmLGw8Qjd1U5rtR006UTVP3KUuQYz0PqKL0nIj36i7Qp67ry1GWxpMxAIkb21j X-Received: by 2002:a05:6a00:1805:b0:6ed:2f0d:8d73 with SMTP id y5-20020a056a00180500b006ed2f0d8d73mr3347470pfa.3.1713870304676; Tue, 23 Apr 2024 04:05:04 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713870304; cv=pass; d=google.com; s=arc-20160816; b=WnJzuKM4pkgP9tkmv+JC8C8SAoZrq2zTf53ztvVRuvZui+S3nyh5/VD/toW1XG4Y+l 992WuYdSiwF9cJ1sOw4EezWqgfDMS4gu0YKVH7SgriF2YU+RnMajabWB8ejE4E52N0st JuFS+3Z33kL/Hz3cW6KYVZt+HDkN/AOG3Ul5DESLz3/OFEwOOoDwpuGX9zK0KZtsBhYQ ZeaxpqN+P7BXIB8X3dErhIx/QVCNQ+GrDSCIzzJG43+0eFUuOhHhZ2XAKjc3rqNc6AMn VCr5jpZik6CvoyG001ax/jqR1ftbSivILTHkrFgIYvnKN1tM7rWhPrPBqb5NnZhnItJ9 mzUA== 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=g5S+5xWGh1LSoCH6S0g+mSoCWam8q4GLMeWghGKi028=; b=y0uaFe8D++xZ9dKIEBofUa0Wz/FcZraJGuWclJQavqRWFIQNzc0cSKmAvZ4ih/Y5VZ I+gJbTw2jSvXBe7l2cjvqx7ME4ipOgNR6xQRKsEKVhiqvAa9qEjaojjso8aXV1V+5tks 4ie7AtCWLvN4aiR1Xx+wVNnbuh1jsf6ToxVE+o8hqGBumtXvJExGcWsuQ2dh4dWoAhYd J8nWWMoBOPpqoq2ao3yflihBmwRhIiLLfoJ9lwef10nvkXicYQ7Dlq8P01yvqnMzI3q5 3hbz+54Lg4VJR8X3n+rDJT7NLUtltUyZuwVePJzr4LA5zDjjHmtUEkLoMH3d1dX19ggx mJNw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@yandex.ru header.s=mail header.b=tcz4wkXJ; 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-154921-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-154921-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id q5-20020a63d605000000b005dc894ea130si9617526pgg.384.2024.04.23.04.05.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Apr 2024 04:05:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-154921-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@yandex.ru header.s=mail header.b=tcz4wkXJ; 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-154921-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-154921-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id A2DA92895EA for ; Tue, 23 Apr 2024 10:54:10 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7F29C84A44; Tue, 23 Apr 2024 10:49:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=yandex.ru header.i=@yandex.ru header.b="tcz4wkXJ" Received: from forward100c.mail.yandex.net (forward100c.mail.yandex.net [178.154.239.211]) (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 5DAA67E118; Tue, 23 Apr 2024 10:49:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=178.154.239.211 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713869377; cv=none; b=Rc+LKWqaZGIgMh5Nj1gx1wWqTbzi0Zf2rau45qV1iPnoE4/Qwfau1ZoSEXZZeC13Xk+bTVOZp8/e865/9TlVYIk3r4cC1qgXbvKu/6QF1i4LRpwZGtWAoVs3zE+/aFr2mPXEbsgox85Rkl9vjh/1KkGPMUFvmh0A3MLmh1/vF7c= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713869377; c=relaxed/simple; bh=t2/9kzu5cn37NlBr754kfbC9x4lMRcCfuiRc7DMS7GA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=C2PNivVQesAFeDlCI44Xkgwbh7HYaDpo+7GWQ4/OvsxskblQ5CbQwCXpUIdOzIxVeLb7a5NQ39BmRN51O1qjOllqFzGGJt16iTt44EXGz5R3o2+THlmZpUBcoT/QhOekHneDpdJwxn9ATGD0uFy+gv9G7YbVZEWmPnfoqiBnWdc= 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=tcz4wkXJ; arc=none smtp.client-ip=178.154.239.211 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-85.iva.yp-c.yandex.net (mail-nwsmtp-smtp-production-main-85.iva.yp-c.yandex.net [IPv6:2a02:6b8:c0c:b1a0:0:640:e983:0]) by forward100c.mail.yandex.net (Yandex) with ESMTPS id 0378B60AA7; Tue, 23 Apr 2024 13:49:33 +0300 (MSK) Received: by mail-nwsmtp-smtp-production-main-85.iva.yp-c.yandex.net (smtp/Yandex) with ESMTPSA id TnHoiCGOm4Y0-nnKlF5bh; Tue, 23 Apr 2024 13:49:31 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1713869371; bh=5kgbLMAE980GVvENsTEIPE4CBNTxsGKzzeodVahHYoU=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=tcz4wkXJYAwcAKMdLdgv9qaHJS9DMXEHOP1CxThaqGHSmYF8l2SE8Td9ROtxpOkXJ 5+esTkOVhuiAbedXYk6nhUzZcbbG3XPuZQ4h07XXKBekLt+uDQHLGjfiz1LJ9L/i7+ 9BFA6dxMvAL3JpGn62OLigdcgdbhfXuPsd5fycNw= Authentication-Results: mail-nwsmtp-smtp-production-main-85.iva.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, Paolo Bonzini , =?UTF-8?q?Christian=20G=C3=B6ttsche?= Subject: [PATCH 1/2] fs: reorganize path_openat() Date: Tue, 23 Apr 2024 13:48:23 +0300 Message-ID: <20240423104824.10464-2-stsp2@yandex.ru> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240423104824.10464-1-stsp2@yandex.ru> References: <20240423104824.10464-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