From patchwork Thu Sep 22 08:44:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miklos Szeredi X-Patchwork-Id: 12984736 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D257EC6FA8B for ; Thu, 22 Sep 2022 08:45:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229995AbiIVIpE (ORCPT ); Thu, 22 Sep 2022 04:45:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44488 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230378AbiIVIo5 (ORCPT ); Thu, 22 Sep 2022 04:44:57 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3E028A0267 for ; Thu, 22 Sep 2022 01:44:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1663836290; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=x8lUJ3SpIV4mlVs/JuPNx0a+WWSeeA9bZCgVmcay4M8=; b=YQv7Jf3x792gVe8FyvXFdh8UkWCQ88XyPiAWNK0Isu9uMDyxpsmfJWTer27g+Z/aA3KpJZ vcTwZK7ivFplZcCWYaEwQuKsZys22PO4C6trGCgE+ddqSj1XtF1qL+wE9d4Hx7kiposupQ Bs1wsqe8Ktskp12idYYRAmqfFbZhGeA= Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-594-m5vb3ALKNPmz1ZVJtRoG0Q-1; Thu, 22 Sep 2022 04:44:48 -0400 X-MC-Unique: m5vb3ALKNPmz1ZVJtRoG0Q-1 Received: by mail-ed1-f70.google.com with SMTP id e15-20020a056402190f00b0044f41e776a0so6166205edz.0 for ; Thu, 22 Sep 2022 01:44:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=x8lUJ3SpIV4mlVs/JuPNx0a+WWSeeA9bZCgVmcay4M8=; b=iniMokm3bvxnnkCsuB3+cXxfOXz/n1ClWFCpG2CohnPTds6No9VMEZXWomog5RD1NC XKzjIr3cb/TqO0zMwLFeG9QqhXrGTUXnFBGq53LT95LHj5REKtOltybvSMfC2O4pARj1 qbiAFiT3/7BzZz9S8nHSJWp9oxBP2fN8flHJfhOnZP5QJG8Ao0m64G/GcAp9jnwIVXUw tEXKpR0Hk0RVx/nmV1TPtt1dk61YwCBrpb/HjWapFJTQCNXoArDQAz4vq2PZNjztKKh/ 8FclWnX1RYAYQV2hib9MtOIeRPbk8hU3fPP/E04lWaMvMeGkvBzUA7F75YB9ezVZM5Bf hiDg== X-Gm-Message-State: ACrzQf2eXEgoUP0w3DuIAw2DqN7vjq+ES22RsLsEZZJ2bpKXZjl8rc18 kWw/pVmqTJ2/5oIHuWXxVk9sl2MJr/MrlCWNG6X4W3oXZwxUn5CoD8DVrtpiXCT2rFs2GQJTXfT A1Hq02nURfaY09Hs3rYufXDj4sqr7m2yYTCWGDUUh1c0/rMUmQWBOtkJjxwJAoqZsPtgacd4GGa RCFA== X-Received: by 2002:aa7:c382:0:b0:454:9591:79fe with SMTP id k2-20020aa7c382000000b00454959179femr2148300edq.253.1663836286904; Thu, 22 Sep 2022 01:44:46 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6eFjvyOJxrjK/S38FYT1FYsFoor5/NPGXCzHHhjnyD6Ze1SbQt0l1+KG0NK5RrnzdaqH43Jw== X-Received: by 2002:aa7:c382:0:b0:454:9591:79fe with SMTP id k2-20020aa7c382000000b00454959179femr2148282edq.253.1663836286703; Thu, 22 Sep 2022 01:44:46 -0700 (PDT) Received: from miu.piliscsaba.redhat.com (193-226-214-223.pool.digikabel.hu. [193.226.214.223]) by smtp.gmail.com with ESMTPSA id h15-20020a170906718f00b00730b3bdd8d7sm2297942ejk.179.2022.09.22.01.44.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Sep 2022 01:44:46 -0700 (PDT) From: Miklos Szeredi To: linux-fsdevel@vger.kernel.org Cc: Al Viro , Al Viro , Christian Brauner , Amir Goldstein , David Howells , Yu-li Lin , Chirantan Ekbote Subject: [PATCH v4 02/10] hugetlbfs: cleanup mknod and tmpfile Date: Thu, 22 Sep 2022 10:44:34 +0200 Message-Id: <20220922084442.2401223-3-mszeredi@redhat.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220922084442.2401223-1-mszeredi@redhat.com> References: <20220922084442.2401223-1-mszeredi@redhat.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org From: Al Viro Duplicate the few lines that are shared between hugetlbfs_mknod() and hugetlbfs_tmpfile(). This is a prerequisite for sanely changing the signature of ->tmpfile(). Signed-off-by: Al Viro Reviewed-by: Christian Brauner (Microsoft) Signed-off-by: Miklos Szeredi --- fs/hugetlbfs/inode.c | 40 ++++++++++++++++------------------------ 1 file changed, 16 insertions(+), 24 deletions(-) diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c index f7a5b5124d8a..0b458beb318c 100644 --- a/fs/hugetlbfs/inode.c +++ b/fs/hugetlbfs/inode.c @@ -885,33 +885,18 @@ static struct inode *hugetlbfs_get_inode(struct super_block *sb, /* * File creation. Allocate an inode, and we're done.. */ -static int do_hugetlbfs_mknod(struct inode *dir, - struct dentry *dentry, - umode_t mode, - dev_t dev, - bool tmpfile) +static int hugetlbfs_mknod(struct user_namespace *mnt_userns, struct inode *dir, + struct dentry *dentry, umode_t mode, dev_t dev) { struct inode *inode; - int error = -ENOSPC; inode = hugetlbfs_get_inode(dir->i_sb, dir, mode, dev); - if (inode) { - dir->i_ctime = dir->i_mtime = current_time(dir); - if (tmpfile) { - d_tmpfile(dentry, inode); - } else { - d_instantiate(dentry, inode); - dget(dentry);/* Extra count - pin the dentry in core */ - } - error = 0; - } - return error; -} - -static int hugetlbfs_mknod(struct user_namespace *mnt_userns, struct inode *dir, - struct dentry *dentry, umode_t mode, dev_t dev) -{ - return do_hugetlbfs_mknod(dir, dentry, mode, dev, false); + if (!inode) + return -ENOSPC; + dir->i_ctime = dir->i_mtime = current_time(dir); + d_instantiate(dentry, inode); + dget(dentry);/* Extra count - pin the dentry in core */ + return 0; } static int hugetlbfs_mkdir(struct user_namespace *mnt_userns, struct inode *dir, @@ -935,7 +920,14 @@ static int hugetlbfs_tmpfile(struct user_namespace *mnt_userns, struct inode *dir, struct dentry *dentry, umode_t mode) { - return do_hugetlbfs_mknod(dir, dentry, mode | S_IFREG, 0, true); + struct inode *inode; + + inode = hugetlbfs_get_inode(dir->i_sb, dir, mode | S_IFREG, 0); + if (!inode) + return -ENOSPC; + dir->i_ctime = dir->i_mtime = current_time(dir); + d_tmpfile(dentry, inode); + return 0; } static int hugetlbfs_symlink(struct user_namespace *mnt_userns,