Received: by 2002:ab2:3c46:0:b0:1f5:f2ab:c469 with SMTP id x6csp276886lqf; Fri, 26 Apr 2024 06:34:26 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVOxOkapeOH/9oceF3fzTNNTgkiiKZ69+TbsQB/NoT7PL62cXrIW+tG4cE/zp2AUB6e3Nr+/w1cBr0JikCOqRhhgR1fdptH/VrFGysXAw== X-Google-Smtp-Source: AGHT+IETwowbrFdm/fPw6BGjBt9SyABgl8Bx0OFetYfAOXLgca9YT1He0BMY3a50fBpr7ULD942Q X-Received: by 2002:a17:906:30d0:b0:a55:adf5:e698 with SMTP id b16-20020a17090630d000b00a55adf5e698mr5682844ejb.28.1714138466497; Fri, 26 Apr 2024 06:34:26 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714138466; cv=pass; d=google.com; s=arc-20160816; b=ojVXZa9+c+tuZZa9pQ6vVE0xTRgSSBpbCt6gzP0OMTRk1qrOEzkno7IgWajSlg+uID ohHPAcqgPhEMHJMINFjsWyiGWubK21RczUhUTP7U1ZcSkoP9V8QrdGRWFxaHrNbhKv5I DO9H7adcstpnb9FRuJZNQzaVV9qPMG4NrN954ONI7Zp6sei6vLYJEj+I//g6Lwkeg4xF qzPmHEs07zSM+tBWLAKzFeDozFCU8FjGYYaIZv36g9NSHRkXxuguriwzY6gNMJo20Tmn 2b/Vwv+EakzucAPrBG2cNpA9mPAa+Dtc/nJ8P8pxrgdmP5CTJ1I070hg0O/JmOOv0zy/ SGSA== 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=N6Wa5ZdYH+jnqmFV3t56OpNcrMxvOQwAgYBdbDZuPl8=; fh=328TqmIIEN4VgTC/+/XdKCFZhWn0fxfd+KKmu/Qf5iY=; b=iBghBJfg6sOW4ylRqoY6FU9QbOeUgr1KNhkYnfGQwSOonWWdGieRQE84DJiWkUS/+r wsPT0Ls2p6k/UGScOdXKuW2hKnyLxIeqW6bl7tXlvsIp8YpPFynFAByQxLxwSVdZaI05 003JZHUc9iy8vArK/5i3AyAVs0duMuBmzHhd9ixtiiTXcBm0F66E8FRquV4cASUtNyZC 4GYmc6RK4tqAVYLE2jYYDKMy09EpOUfYU9n2HHWXyRPoZcmyGX2kXy9kaOHC8CVc+i6v MZsvPjZzqCSZBgYtM+/7Z4cX7afdQ7uMDapLNd5JscJAwB/TR7TFez/D+sgg0ivgncfI cWGA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@yandex.ru header.s=mail header.b=S7rq6OGV; 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-160057-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-160057-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id t16-20020a170906065000b00a51a115b483si11144343ejb.129.2024.04.26.06.34.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Apr 2024 06:34:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-160057-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@yandex.ru header.s=mail header.b=S7rq6OGV; 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-160057-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-160057-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 3CB6A1F236EB for ; Fri, 26 Apr 2024 13:34:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 58F2D147C75; Fri, 26 Apr 2024 13:34:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=yandex.ru header.i=@yandex.ru header.b="S7rq6OGV" Received: from forward102a.mail.yandex.net (forward102a.mail.yandex.net [178.154.239.85]) (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 86FCB1474DF; Fri, 26 Apr 2024 13:34:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=178.154.239.85 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714138453; cv=none; b=YUxuy6O3i22tfH6a1E4KwLkyGsl5cCN7gfyizO9GRe+nyRX6hfuVJ6mggU4rA6CJcdVYPbj57vlxGb6JyuTmNVrem640ZM7UW5Mjjwoc38hmlgQoqSYrmhFMNo57Yq3QSynONPhFwB7UnM5QAW0vhV3T88yuke/YdLLgaHBujxw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714138453; c=relaxed/simple; bh=eW+R7T+4wDE0CCmXnPO5w8nUsJ7ogtYZtHHlx4MY378=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Q/1m4xHkyyuiIRZI4dGpfI0rMSs42Hak/3wB2aXzDVRqDlblndC3xzYCe+50tshJkAxAVhBqzfMHHLKiGShAPHEViN1bCRqR6Gt2x/WCxsRM3eZ/R21Hkc6GKHURzaG6FUKXUdv//CuNq6CwEfODubnseCTOjmZzKGOsmFwcHUk= 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=S7rq6OGV; arc=none smtp.client-ip=178.154.239.85 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-55.vla.yp-c.yandex.net (mail-nwsmtp-smtp-production-main-55.vla.yp-c.yandex.net [IPv6:2a02:6b8:c0d:230c:0:640:f8e:0]) by forward102a.mail.yandex.net (Yandex) with ESMTPS id 37B5760905; Fri, 26 Apr 2024 16:34:05 +0300 (MSK) Received: by mail-nwsmtp-smtp-production-main-55.vla.yp-c.yandex.net (smtp/Yandex) with ESMTPSA id 2YN3P0DXnmI0-Bn2tdwo5; Fri, 26 Apr 2024 16:34:04 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1714138444; bh=N6Wa5ZdYH+jnqmFV3t56OpNcrMxvOQwAgYBdbDZuPl8=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=S7rq6OGVdRG+mfSoFeDmu1F7HVcrELvHlGVgK9rz2d/czf3zQAnRMgwTMkb7e9CPa DyMulwy+fyq0UAcFk54BZj+z45yyKC4hJKPwBaQ3GLEpL/8MX92LGXyZjj66fRsWjE YbAoUmJ3Y8bfj/YOc8V1rnYbmfMzGec64WjlTRlE= Authentication-Results: mail-nwsmtp-smtp-production-main-55.vla.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 , David Laight , linux-fsdevel@vger.kernel.org, linux-api@vger.kernel.org, Paolo Bonzini , =?UTF-8?q?Christian=20G=C3=B6ttsche?= Subject: [PATCH v5 1/3] fs: reorganize path_openat() Date: Fri, 26 Apr 2024 16:33:08 +0300 Message-ID: <20240426133310.1159976-2-stsp2@yandex.ru> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240426133310.1159976-1-stsp2@yandex.ru> References: <20240426133310.1159976-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() down the if branches. That changes is needed for the next patch, which adds a cred override for alloc_empty_file(). The cred override is only needed in one branch, i.e. it is not needed for O_PATH and O_TMPFILE.. 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: David Laight CC: linux-fsdevel@vger.kernel.org CC: linux-kernel@vger.kernel.org --- fs/namei.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/fs/namei.c b/fs/namei.c index c5b2a25be7d0..dd50345f7260 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -3781,17 +3781,24 @@ static struct file *path_openat(struct nameidata *nd, { struct file *file; int error; + int open_flags = op->open_flag; - file = alloc_empty_file(op->open_flag, current_cred()); - if (IS_ERR(file)) - return file; - - if (unlikely(file->f_flags & __O_TMPFILE)) { - error = do_tmpfile(nd, flags, op, file); - } else if (unlikely(file->f_flags & O_PATH)) { - error = do_o_path(nd, flags, file); + if (unlikely(open_flags & (__O_TMPFILE | O_PATH))) { + file = alloc_empty_file(open_flags, current_cred()); + if (IS_ERR(file)) + return file; + if (open_flags & __O_TMPFILE) + error = do_tmpfile(nd, flags, op, file); + else + error = do_o_path(nd, flags, file); } else { - const char *s = path_init(nd, flags); + const char *s; + + file = alloc_empty_file(open_flags, current_cred()); + if (IS_ERR(file)) + return file; + + s = path_init(nd, flags); while (!(error = link_path_walk(s, nd)) && (s = open_last_lookups(nd, file, op)) != NULL) ; -- 2.44.0