From patchwork Sun Oct 23 07:21:27 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yongqiang Yang X-Patchwork-Id: 121222 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 9F9DDB6F80 for ; Sun, 23 Oct 2011 20:11:29 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755235Ab1JWJLJ (ORCPT ); Sun, 23 Oct 2011 05:11:09 -0400 Received: from mail-iy0-f174.google.com ([209.85.210.174]:58496 "EHLO mail-iy0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755230Ab1JWJLI (ORCPT ); Sun, 23 Oct 2011 05:11:08 -0400 Received: by mail-iy0-f174.google.com with SMTP id y12so71200iab.19 for ; Sun, 23 Oct 2011 02:11:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=En/uLe5HPF0Dvxu3DfDihlQUdVJa0Ex5BU9BL4BS2B4=; b=VHEV3aWCam2G+n2AUzW5SdmmhoNPucT5Gb1uiu0sbP30NpXCkGdtWOzEElydVCAs6Z CKwypaCWRUWM0bKHdJlDcL/mFUWrHr6OTatMTrgvdAY8f4+mRFCfM9prapuOoPNqiS4+ FSS2vBwdcq4d476gKv/2dD+5YoyEDh97lU5bM= Received: by 10.231.27.203 with SMTP id j11mr8249842ibc.10.1319361068201; Sun, 23 Oct 2011 02:11:08 -0700 (PDT) Received: from localhost.localdomain ([159.226.43.42]) by mx.google.com with ESMTPS id bu33sm49780971ibb.11.2011.10.23.02.11.05 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 23 Oct 2011 02:11:07 -0700 (PDT) From: Yongqiang Yang To: linux-ext4@vger.kernel.org Cc: amir73il@users.sf.net, Yongqiang Yang Subject: [PATCH 7/8] e2fsprogs: add exclude bitmap support in e2image Date: Sun, 23 Oct 2011 15:21:27 +0800 Message-Id: <1319354488-6050-8-git-send-email-xiaoqiangnk@gmail.com> X-Mailer: git-send-email 1.7.5.1 In-Reply-To: <1319354488-6050-1-git-send-email-xiaoqiangnk@gmail.com> References: <1319354488-6050-1-git-send-email-xiaoqiangnk@gmail.com> Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org Exclude bitmap is a feature needed by ext4 snapshot. This patch Adds exclude bitmap support in e2image. Signed-off-by: Yongqiang Yang --- lib/ext2fs/e2image.h | 1 + lib/ext2fs/ext2fs.h | 1 + lib/ext2fs/imager.c | 22 ++++++++++++++++++++++ lib/ext2fs/rw_bitmaps.c | 16 ++++++++++++++++ misc/e2image.c | 22 ++++++++++++++++++++++ 5 files changed, 62 insertions(+), 0 deletions(-) diff --git a/lib/ext2fs/e2image.h b/lib/ext2fs/e2image.h index c918529..61d7ff9 100644 --- a/lib/ext2fs/e2image.h +++ b/lib/ext2fs/e2image.h @@ -41,6 +41,7 @@ struct ext2_image_hdr { __u32 offset_super; /* Byte offset of the sb and descriptors */ __u32 offset_inode; /* Byte offset of the inode table */ __u32 offset_inodemap; /* Byte offset of the inode bitmaps */ + __u32 offset_excludemap; /* Byte offset of the exclude bitmaps */ __u32 offset_blockmap; /* Byte offset of the inode bitmaps */ __u32 offset_reserved[8]; }; diff --git a/lib/ext2fs/ext2fs.h b/lib/ext2fs/ext2fs.h index d1f0d98..dab5ad7 100644 --- a/lib/ext2fs/ext2fs.h +++ b/lib/ext2fs/ext2fs.h @@ -526,6 +526,7 @@ typedef struct ext2_icount *ext2_icount_t; */ #define IMAGER_FLAG_INODEMAP 1 #define IMAGER_FLAG_SPARSEWRITE 2 +#define IMAGER_FLAG_EXCLUDEMAP 3 /* * For checking structure magic numbers... diff --git a/lib/ext2fs/imager.c b/lib/ext2fs/imager.c index a0fb81e..c6b5af2 100644 --- a/lib/ext2fs/imager.c +++ b/lib/ext2fs/imager.c @@ -296,6 +296,17 @@ errcode_t ext2fs_image_bitmap_write(ext2_filsys fs, int fd, int flags) itr = 1; cnt = EXT2_INODES_PER_GROUP(fs->super) * fs->group_desc_count; size = (EXT2_INODES_PER_GROUP(fs->super) / 8); + } else if (flags & IMAGER_FLAG_EXCLUDEMAP) { + if (!fs->exclude_map) { + retval = ext2fs_read_exclude_bitmap(fs); + if (retval) + return retval; + } + bmap = fs->exclude_map; + err = EXT2_ET_MAGIC_EXCLUDE_BITMAP; + itr = fs->super->s_first_data_block; + cnt = EXT2_BLOCKS_PER_GROUP(fs->super) * fs->group_desc_count; + size = EXT2_BLOCKS_PER_GROUP(fs->super) / 8; } else { if (!fs->block_map) { retval = ext2fs_read_block_bitmap(fs); @@ -373,6 +384,17 @@ errcode_t ext2fs_image_bitmap_read(ext2_filsys fs, int fd, int flags) itr = 1; cnt = EXT2_INODES_PER_GROUP(fs->super) * fs->group_desc_count; size = (EXT2_INODES_PER_GROUP(fs->super) / 8); + } else if (flags & IMAGER_FLAG_EXCLUDEMAP) { + if (!fs->exclude_map) { + retval = ext2fs_read_exclude_bitmap(fs); + if (retval) + return retval; + } + bmap = fs->exclude_map; + err = EXT2_ET_MAGIC_EXCLUDE_BITMAP; + itr = fs->super->s_first_data_block; + cnt = EXT2_BLOCKS_PER_GROUP(fs->super) * fs->group_desc_count; + size = EXT2_BLOCKS_PER_GROUP(fs->super) / 8; } else { if (!fs->block_map) { retval = ext2fs_read_block_bitmap(fs); diff --git a/lib/ext2fs/rw_bitmaps.c b/lib/ext2fs/rw_bitmaps.c index 3126733..6c8179b 100644 --- a/lib/ext2fs/rw_bitmaps.c +++ b/lib/ext2fs/rw_bitmaps.c @@ -274,6 +274,7 @@ static errcode_t read_bitmaps(ext2_filsys fs, int do_inode, int do_block, ext2fs_free_mem(&buf); if (fs->flags & EXT2_FLAG_IMAGE_FILE) { + blk64_t exclude_blk; blk = (fs->image_header->offset_inodemap / fs->blocksize); ino_cnt = fs->super->s_inodes_count; while (inode_nbytes > 0) { @@ -294,10 +295,25 @@ static errcode_t read_bitmaps(ext2_filsys fs, int do_inode, int do_block, } blk = (fs->image_header->offset_blockmap / fs->blocksize); + exclude_blk = (fs->image_header->offset_excludemap / + fs->blocksize); blk_cnt = (blk64_t)EXT2_CLUSTERS_PER_GROUP(fs->super) * fs->group_desc_count; while (block_nbytes > 0) { if (do_exclude) { + retval = io_channel_read_blk64(fs->image_io, + exclude_blk++, 1, exclude_bitmap); + if (retval) + goto cleanup; + cnt = fs->blocksize << 3; + if (cnt > blk_cnt) + cnt = blk_cnt; + retval = ext2fs_set_exclude_bitmap_range2( + fs->exclude_map, + blk_itr, cnt, exclude_bitmap); + if (retval) + goto cleanup; + retval = EXT2_ET_EXCLUDE_BITMAP_READ; goto cleanup; } diff --git a/misc/e2image.c b/misc/e2image.c index 4cd834a..44a602c 100644 --- a/misc/e2image.c +++ b/misc/e2image.c @@ -187,6 +187,18 @@ static void write_image_file(ext2_filsys fs, int fd) exit(1); } + if (EXT2_HAS_COMPAT_FEATURE(fs->super, + EXT2_FEATURE_COMPAT_EXCLUDE_BITMAP)) { + hdr.offset_excludemap = lseek(fd, 0, SEEK_CUR); + retval = ext2fs_image_bitmap_write(fs, fd, + IMAGER_FLAG_EXCLUDEMAP); + if (retval) { + com_err(program_name, retval, _("while writing " + "exclude bitmap")); + exit(1); + } + } + hdr.offset_inodemap = ext2fs_llseek(fd, 0, SEEK_CUR); retval = ext2fs_image_bitmap_write(fs, fd, IMAGER_FLAG_INODEMAP); if (retval) { @@ -359,6 +371,16 @@ static void mark_table_blocks(ext2_filsys fs) } /* + * Mark block used for the exclude bitmap + */ + if (EXT2_HAS_COMPAT_FEATURE(fs->super, + EXT2_FEATURE_COMPAT_EXCLUDE_BITMAP) && + ext2fs_exclude_bitmap_loc(fs, i)) { + ext2fs_mark_block_bitmap2(meta_block_map, + ext2fs_exclude_bitmap_loc(fs, i)); + } + + /* * Mark block used for the inode bitmap */ if (ext2fs_inode_bitmap_loc(fs, i)) {