From patchwork Sun Jul 1 13:48:40 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zheng Liu X-Patchwork-Id: 168413 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 2A0A92C01C0 for ; Sun, 1 Jul 2012 23:41:23 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932431Ab2GANlW (ORCPT ); Sun, 1 Jul 2012 09:41:22 -0400 Received: from mail-pb0-f46.google.com ([209.85.160.46]:49296 "EHLO mail-pb0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932428Ab2GANlV (ORCPT ); Sun, 1 Jul 2012 09:41:21 -0400 Received: by mail-pb0-f46.google.com with SMTP id rp8so6469492pbb.19 for ; Sun, 01 Jul 2012 06:41:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=fLol5Qvj/eZ1IphOHUbynanThWW9jqWxWyuNx4hnUp4=; b=dO+xPgE9GIKjSHAy2JZGOoTLusTYQWDMyevrIBz4CQ16lASYOdA3O+dhIZrS440Evv OGFHsKaQv9enH50feKPR3M43xWpmXIJiSUb2jZPUHln1vq1aVyznk3OgSNCILSkRvBZm dNOp2ihY6uUIkeDsnwd5FbueXk1yn7vHEuDgOjZ4cJjZPbcEdpajTURnzIyGQoxgFmSR lVSLFyaIC9R6FKz8D/2SouQpAn7L943jeYWNmnShrowFjdteGMYK1iYUge30OuAYLwKs NZtVvXJZGo2LkafVu4CfFjtHTbH8KH/6utRL9OYG8NPD9N+nN9GuR72jchvSRw68YLoW csPQ== Received: by 10.66.79.8 with SMTP id f8mr14226429pax.81.1341150080870; Sun, 01 Jul 2012 06:41:20 -0700 (PDT) Received: from localhost.localdomain ([182.92.247.2]) by mx.google.com with ESMTPS id ql3sm10544254pbc.72.2012.07.01.06.41.19 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 01 Jul 2012 06:41:20 -0700 (PDT) From: Zheng Liu To: linux-ext4@vger.kernel.org Cc: Zheng Liu Subject: [PATCH 17/35 v3] debugfs: make mkdir cmd support inline data Date: Sun, 1 Jul 2012 21:48:40 +0800 Message-Id: <1341150538-32047-18-git-send-email-wenqing.lz@taobao.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1341150538-32047-1-git-send-email-wenqing.lz@taobao.com> References: <1341150538-32047-1-git-send-email-wenqing.lz@taobao.com> Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org From: Zheng Liu We need to reload inode in ext2fs_mkdir because inode with inline itself data is modified in ext2fs_link. Now we cannot create an empty dir with inline data because we need to do a lot of works for maniluating xattr, and it brings a huge impacts for e2fsprogs. Signed-off-by: Zheng Liu --- lib/ext2fs/mkdir.c | 33 +++++++++++++++++++++++++++++---- 1 files changed, 29 insertions(+), 4 deletions(-) diff --git a/lib/ext2fs/mkdir.c b/lib/ext2fs/mkdir.c index 4a85439..3c226f3 100644 --- a/lib/ext2fs/mkdir.c +++ b/lib/ext2fs/mkdir.c @@ -41,6 +41,7 @@ errcode_t ext2fs_mkdir(ext2_filsys fs, ext2_ino_t parent, ext2_ino_t inum, ext2_ino_t scratch_ino; blk64_t blk; char *block = 0; + int unmark_blk = 0; EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS); @@ -115,6 +116,14 @@ errcode_t ext2fs_mkdir(ext2_filsys fs, ext2_ino_t parent, ext2_ino_t inum, } /* + * XXX: We need to update accouting before we mkdir successful because + * in ext2fs_link it could allocate a new block when there is no space + * to store a new dir entry in inline data. If ext2fs_link failed, we + * need to unmark this block. + */ + ext2fs_block_alloc_stats2(fs, blk, +1); + + /* * Link the directory into the filesystem hierarchy */ if (name) { @@ -123,32 +132,48 @@ errcode_t ext2fs_mkdir(ext2_filsys fs, ext2_ino_t parent, ext2_ino_t inum, if (!retval) { retval = EXT2_ET_DIR_EXISTS; name = 0; + unmark_blk = 1; goto cleanup; } - if (retval != EXT2_ET_FILE_NOT_FOUND) + if (retval != EXT2_ET_FILE_NOT_FOUND) { + unmark_blk = 1; goto cleanup; + } retval = ext2fs_link(fs, parent, name, ino, EXT2_FT_DIR); - if (retval) + if (retval) { + unmark_blk = 1; goto cleanup; + } } /* * Update parent inode's counts */ if (parent != ino) { + /* Reload parent inode */ + retval = ext2fs_read_inode(fs, parent, &parent_inode); + if (retval) { + unmark_blk = 1; + goto cleanup; + } parent_inode.i_links_count++; retval = ext2fs_write_inode(fs, parent, &parent_inode); - if (retval) + if (retval) { + unmark_blk = 1; goto cleanup; + } } /* * Update accounting.... */ - ext2fs_block_alloc_stats2(fs, blk, +1); ext2fs_inode_alloc_stats2(fs, ino, +1, 1); cleanup: + /* Unmark block because mkdir failed */ + if (unmark_blk) + ext2fs_block_alloc_stats2(fs, blk, -1); + if (block) ext2fs_free_mem(&block); return retval;