Received: by 2002:a19:771d:0:0:0:0:0 with SMTP id s29csp1239738lfc; Wed, 1 Jun 2022 12:45:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxCV34ctq13QC4Nwzov4Zjc8iNGSBl7j1flLuEGIyVyMD4uwXW5U1GMY/z9F8MvJ2YIlc5n X-Received: by 2002:a17:902:da91:b0:163:cf58:f459 with SMTP id j17-20020a170902da9100b00163cf58f459mr993937plx.71.1654112738774; Wed, 01 Jun 2022 12:45:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654112738; cv=none; d=google.com; s=arc-20160816; b=cHSCO2H/zNT6V3K5rydsFSiQJ9tPDBtWIJyePLmsdIACaAG11X58cCKRei9HGiF0GF 52XRDQLKGNifHbbfLshXeJGRkd0J72naO172AAWIP7xTh2qfeeWfCgZWanRnToesmqP2 Sq5kfTke1hlm9NFPfR+NXqmXToeT+/4eoE2rkTEYWANfvJX1myC63POqil1xhtWQ7bJH ogU2R9HLcdyw/ZtMME5Uu2V0WWvOee2PQWB+jsol99p7felGyZZST6ht+zGzUWRMoP3S Z40N/nH5L2erQYrj14GpbAxKk1657Ocy3+zJhP/AVsdDDq4sfpFIgW3eCdeEKA1FgLna m94g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=jrVbGdfcjLY3mxRjbqeWGmJJMVLxqZJaLyqpgAFIX+U=; b=xxA48+yNqdU+EvYXUCik+3xef6csKlxalMAynvFxG+dkDEycwPfFxNpPN/R9FZkdok MUNCFyIlHhLE4sa3w3n6EMzZyAcFhQv9wuqS6ctrsJj4SjHLD0ceXh7XIl5te+RYzb0b cMskuBlNUOD/KpNGJmc9ou7ezEtIyyvhI3YpbFsL8rE/B/kOY74cTw/dwhSxoM3giyRb eE8vHxYb1KCWUCTYLzDaDTZmBCNxMIfiPKVhA+rLzTyD/QmUR45UMHWodIW8ZEne4mK7 YuK2rHmCryytRHOpoYmrP6rRoPO89nYw63WLNg16B5qHAYaV6vx4EsaO/8y51OQa3jJ7 oEDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=cN9xMcSw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id x142-20020a633194000000b003fa387b9ac8si3251633pgx.513.2022.06.01.12.45.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Jun 2022 12:45:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=cN9xMcSw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 678531DE8C2; Wed, 1 Jun 2022 12:10:33 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1356351AbiFARc2 (ORCPT + 99 others); Wed, 1 Jun 2022 13:32:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57260 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356338AbiFARcW (ORCPT ); Wed, 1 Jun 2022 13:32:22 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 3B5F3488AB for ; Wed, 1 Jun 2022 10:32:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1654104740; 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=jrVbGdfcjLY3mxRjbqeWGmJJMVLxqZJaLyqpgAFIX+U=; b=cN9xMcSwY9vtorrs3dnTT/9lcgVscCAhDjorHGXJdxts2RDSHlXMSnWrIQdrlY12UF+Yuz RfZ8EYl7H7yU0qnTiHsynzlIn/7ZNdNh3nIHThWRjhx/PNW4w5AsBpSNJLflGtQVeUiRhA usmFvf6H52P5ybFi5rhS5rB3etM1CMI= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-605-_QZ0llhvMLOiz78yZtWgFw-1; Wed, 01 Jun 2022 13:32:19 -0400 X-MC-Unique: _QZ0llhvMLOiz78yZtWgFw-1 Received: by mail-wm1-f69.google.com with SMTP id l31-20020a05600c1d1f00b003974df9b91cso3699465wms.8 for ; Wed, 01 Jun 2022 10:32:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=jrVbGdfcjLY3mxRjbqeWGmJJMVLxqZJaLyqpgAFIX+U=; b=ySssnbZ8oVHQUluMkEVMImUQz/upwKj1JLz3McUjnRWLn73BqIhDGdIZssit9Otm4D Ko7ywMCzwutj/d6amM1LLycbuipHn6avikVgqFsWqpMvjNiI6kjg0GUDukMhXzApvl7Y fjOA4OpeNqDw/Vzian7MSVnLIkhSFtGihmY+CZJ4s9C0j0gw/hFGUXVV0Bk9XQLNhWBA 2H42Ms+pSLsaYxIY+IsBEiHAooP11ev3QnQG3Cg6ghBVlII2e5CQI8wx2gI2NrFc7/Jp RJvhrB0d8mtHAFKRqTtgf9aaGeMUs2HfaSnBi/e8o8LP6w0YWnrEI2XuC+qph8qEx6OX jsnw== X-Gm-Message-State: AOAM530vf1hnUI4lYhUHZ1U4bA+QpYFRWOGZGqkGx5FuLaY193kpHIIn BmaWWCoNVCvyyfN9pJZGKtIZHrvxIAv0KOy7g1rLpVi0Cjiv3fZj8rfQWnvM0Irutm7W9Vad4Nb HjgF4CPlB4UWFVAqBxCA70zUeRHkaYxXAqngjo8XdwibYgo9C3sba36QgPZaZCrA1xeaKysWvwX c= X-Received: by 2002:a05:600c:20d:b0:397:3971:909e with SMTP id 13-20020a05600c020d00b003973971909emr401804wmi.203.1654104738035; Wed, 01 Jun 2022 10:32:18 -0700 (PDT) X-Received: by 2002:a05:600c:20d:b0:397:3971:909e with SMTP id 13-20020a05600c020d00b003973971909emr401760wmi.203.1654104737583; Wed, 01 Jun 2022 10:32:17 -0700 (PDT) Received: from minerva.home (205.pool92-176-231.dynamic.orange.es. [92.176.231.205]) by smtp.gmail.com with ESMTPSA id l14-20020a05600c2cce00b0039751bb8c62sm6525625wmc.24.2022.06.01.10.32.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Jun 2022 10:32:17 -0700 (PDT) From: Javier Martinez Canillas To: linux-kernel@vger.kernel.org Cc: Lennart Poettering , OGAWA Hirofumi , Colin Walters , Peter Jones , Alberto Ruiz , Christian Kellner , Chung-Chiang Cheng , Muhammad Usama Anjum , Alexander Larsson , Javier Martinez Canillas Subject: [PATCH v4 2/4] fat: factor out reusable code in vfat_rename() as helper functions Date: Wed, 1 Jun 2022 19:32:02 +0200 Message-Id: <20220601173204.1372569-3-javierm@redhat.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220601173204.1372569-1-javierm@redhat.com> References: <20220601173204.1372569-1-javierm@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: OGAWA Hirofumi The vfat_rename() function is quite big and there are code blocks that can be moved into helper functions. This not only simplify the implementation of that function but also allows these helpers to be reused. For example, the helpers can be used by the handler of the RENAME_EXCHANGE flag once this is implemented in a subsequent patch. Signed-off-by: OGAWA Hirofumi Signed-off-by: Javier Martinez Canillas --- Changes in v4: - Add new patch from OGAWA Hirofumi to use the helpers in vfat_rename(). fs/fat/namei_vfat.c | 89 +++++++++++++++++++++++++++++---------------- 1 file changed, 57 insertions(+), 32 deletions(-) diff --git a/fs/fat/namei_vfat.c b/fs/fat/namei_vfat.c index 88ccb2ee3537..9c04053a8f1c 100644 --- a/fs/fat/namei_vfat.c +++ b/fs/fat/namei_vfat.c @@ -889,16 +889,55 @@ static int vfat_mkdir(struct user_namespace *mnt_userns, struct inode *dir, return err; } +static int vfat_get_dotdot_de(struct inode *inode, struct buffer_head **bh, + struct msdos_dir_entry **de) +{ + if (S_ISDIR(inode->i_mode)) { + if (fat_get_dotdot_entry(inode, bh, de)) + return -EIO; + } + return 0; +} + +static int vfat_sync_ipos(struct inode *dir, struct inode *inode) +{ + if (IS_DIRSYNC(dir)) + return fat_sync_inode(inode); + mark_inode_dirty(inode); + return 0; +} + +static int vfat_update_dotdot_de(struct inode *dir, struct inode *inode, + struct buffer_head *dotdot_bh, + struct msdos_dir_entry *dotdot_de) +{ + fat_set_start(dotdot_de, MSDOS_I(dir)->i_logstart); + mark_buffer_dirty_inode(dotdot_bh, inode); + if (IS_DIRSYNC(dir)) + return sync_dirty_buffer(dotdot_bh); + return 0; +} + +static void vfat_update_dir_metadata(struct inode *dir, struct timespec64 *ts) +{ + inode_inc_iversion(dir); + fat_truncate_time(dir, ts, S_CTIME | S_MTIME); + if (IS_DIRSYNC(dir)) + (void)fat_sync_inode(dir); + else + mark_inode_dirty(dir); +} + static int vfat_rename(struct inode *old_dir, struct dentry *old_dentry, struct inode *new_dir, struct dentry *new_dentry) { struct buffer_head *dotdot_bh; - struct msdos_dir_entry *dotdot_de; + struct msdos_dir_entry *dotdot_de = NULL; struct inode *old_inode, *new_inode; struct fat_slot_info old_sinfo, sinfo; struct timespec64 ts; loff_t new_i_pos; - int err, is_dir, update_dotdot, corrupt = 0; + int err, is_dir, corrupt = 0; struct super_block *sb = old_dir->i_sb; old_sinfo.bh = sinfo.bh = dotdot_bh = NULL; @@ -909,15 +948,13 @@ static int vfat_rename(struct inode *old_dir, struct dentry *old_dentry, if (err) goto out; - is_dir = S_ISDIR(old_inode->i_mode); - update_dotdot = (is_dir && old_dir != new_dir); - if (update_dotdot) { - if (fat_get_dotdot_entry(old_inode, &dotdot_bh, &dotdot_de)) { - err = -EIO; + if (old_dir != new_dir) { + err = vfat_get_dotdot_de(old_inode, &dotdot_bh, &dotdot_de); + if (err) goto out; - } } + is_dir = S_ISDIR(old_inode->i_mode); ts = current_time(old_dir); if (new_inode) { if (is_dir) { @@ -938,21 +975,15 @@ static int vfat_rename(struct inode *old_dir, struct dentry *old_dentry, fat_detach(old_inode); fat_attach(old_inode, new_i_pos); - if (IS_DIRSYNC(new_dir)) { - err = fat_sync_inode(old_inode); - if (err) - goto error_inode; - } else - mark_inode_dirty(old_inode); + err = vfat_sync_ipos(new_dir, old_inode); + if (err) + goto error_inode; - if (update_dotdot) { - fat_set_start(dotdot_de, MSDOS_I(new_dir)->i_logstart); - mark_buffer_dirty_inode(dotdot_bh, old_inode); - if (IS_DIRSYNC(new_dir)) { - err = sync_dirty_buffer(dotdot_bh); - if (err) - goto error_dotdot; - } + if (dotdot_de) { + err = vfat_update_dotdot_de(new_dir, old_inode, dotdot_bh, + dotdot_de); + if (err) + goto error_dotdot; drop_nlink(old_dir); if (!new_inode) inc_nlink(new_dir); @@ -962,12 +993,7 @@ static int vfat_rename(struct inode *old_dir, struct dentry *old_dentry, old_sinfo.bh = NULL; if (err) goto error_dotdot; - inode_inc_iversion(old_dir); - fat_truncate_time(old_dir, &ts, S_CTIME|S_MTIME); - if (IS_DIRSYNC(old_dir)) - (void)fat_sync_inode(old_dir); - else - mark_inode_dirty(old_dir); + vfat_update_dir_metadata(old_dir, &ts); if (new_inode) { drop_nlink(new_inode); @@ -987,10 +1013,9 @@ static int vfat_rename(struct inode *old_dir, struct dentry *old_dentry, /* data cluster is shared, serious corruption */ corrupt = 1; - if (update_dotdot) { - fat_set_start(dotdot_de, MSDOS_I(old_dir)->i_logstart); - mark_buffer_dirty_inode(dotdot_bh, old_inode); - corrupt |= sync_dirty_buffer(dotdot_bh); + if (dotdot_de) { + corrupt |= vfat_update_dotdot_de(old_dir, old_inode, dotdot_bh, + dotdot_de); } error_inode: fat_detach(old_inode); -- 2.36.1