Whamcloud - gitweb
tools/e2fsprogs.git
10 years agoMerge branch 'ry/mke2fs-populate' into next
Theodore Ts'o [Thu, 6 Mar 2014 16:22:42 +0000 (11:22 -0500)]
Merge branch 'ry/mke2fs-populate' into next

Conflicts:
debugfs/debugfs.c

10 years agomke2fs.8.in: update the manual for the -d option
Robert Yang [Thu, 6 Mar 2014 16:00:25 +0000 (11:00 -0500)]
mke2fs.8.in: update the manual for the -d option

Update the manual for the -d option

Signed-off-by: Robert Yang <liezhi.yang@windriver.com>
Reviewed-by: Darren Hart <dvhart@linux.intel.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
10 years agodebugfs: use the functions in misc/create_inode.c
Robert Yang [Thu, 6 Mar 2014 16:00:25 +0000 (11:00 -0500)]
debugfs: use the functions in misc/create_inode.c

* Use the functions in misc/create_inode.c, and remove the duplicated
  code.

* The CREATE_INODE_DEPS in the debugfs/Makefile.in is used for recording
  create_inode.o's depends which is from misc/Makefile.in, we have to
  recompile create_inode.o because we need it to print more messages when
  it is used by debugfs, just like we recompile e2freefrag.o, but it seems
  that the e2freefrag.o's depends in debugfs/Makefile.in is incorrect, it
  would not rebuild when its depends (e.g.: lib/config.h) is changed,
  which would cause unexpected errors. Make duplicated code in
  debugfs/Makefile.in and misc/Makefile.in is not a good idea, maybe we'd
  better define CREATE_INODE_DEPS in the top Makefile, I'd like to send
  another patch and fix the e2freefrag if you are fine with it.

Signed-off-by: Robert Yang <liezhi.yang@windriver.com>
Reviewed-by: Darren Hart <dvhart@linux.intel.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
10 years agomisc/create_inode.c: handle hardlinks
Robert Yang [Thu, 6 Mar 2014 16:00:25 +0000 (11:00 -0500)]
misc/create_inode.c: handle hardlinks

Create the inode and save the native inode number when we meet the hard
link (st_nlink > 1) at the first time, use ext2fs_link() to link the
name to the target inode number when we meet the same native inode
number again.

This algorithm is referred this from the genext2fs.

Signed-off-by: Robert Yang <liezhi.yang@windriver.com>
Reviewed-by: Darren Hart <dvhart@linux.intel.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
10 years agomke2fs.c: add an option: -d root-directory
Robert Yang [Thu, 6 Mar 2014 16:00:25 +0000 (11:00 -0500)]
mke2fs.c: add an option: -d root-directory

This option is used for adding the files from a given directory (the
root-directory) to the filesystem, it is similiar to genext2fs, but
genext2fs doesn't fully support ext4.

Signed-off-by: Robert Yang <liezhi.yang@windriver.com>
Reviewed-by: Darren Hart <dvhart@linux.intel.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
10 years agomisc/create_inode.c: set owner/mode/time for the inode
Robert Yang [Thu, 6 Mar 2014 16:00:24 +0000 (11:00 -0500)]
misc/create_inode.c: set owner/mode/time for the inode

Set the uid, gid, mode and time for inode.

Signed-off-by: Robert Yang <liezhi.yang@windriver.com>
Reviewed-by: Darren Hart <dvhart@linux.intel.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
10 years agomisc/create_inode.c: create directory
Robert Yang [Thu, 6 Mar 2014 16:00:24 +0000 (11:00 -0500)]
misc/create_inode.c: create directory

The do_mkdir_internal() is used for making dir on the target fs, most of
the code are from debugfs/debugfs.c, the debugfs/debugfs.c will be
modified to use this function.

Signed-off-by: Robert Yang <liezhi.yang@windriver.com>
Reviewed-by: Darren Hart <dvhart@linux.intel.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
10 years agomisc/create_inode.c: copy regular file
Robert Yang [Thu, 6 Mar 2014 16:00:24 +0000 (11:00 -0500)]
misc/create_inode.c: copy regular file

The do_write_internal() is used for copying file from native fs to
target, most of the code are from debugfs/debugfs.c, the
debugfs/debugfs.c will be modified to use this function.

Signed-off-by: Robert Yang <liezhi.yang@windriver.com>
Reviewed-by: Darren Hart <dvhart@linux.intel.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
10 years agomisc/create_inode.c: create symlink
Robert Yang [Thu, 6 Mar 2014 16:00:24 +0000 (11:00 -0500)]
misc/create_inode.c: create symlink

The do_symlink_internal() is used for creating symlinks, most of the
code are from debugfs/debugfs.c, the debugfs/debugfs.c will be modified
to use this function.

Signed-off-by: Robert Yang <liezhi.yang@windriver.com>
Reviewed-by: Darren Hart <dvhart@linux.intel.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
10 years agomisc/create_inode.c: create special file
Robert Yang [Thu, 6 Mar 2014 16:00:24 +0000 (11:00 -0500)]
misc/create_inode.c: create special file

The do_mknod_internal() is used for creating special file which is
block, character and fifo, most of the code are from debugfs/debugfs.c,
the debugfs/debugfs.c will be modified to use this function.

Signed-off-by: Robert Yang <liezhi.yang@windriver.com>
Reviewed-by: Darren Hart <dvhart@linux.intel.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
10 years agomisc/create_inode.c: copy files recursively
Robert Yang [Thu, 6 Mar 2014 16:00:24 +0000 (11:00 -0500)]
misc/create_inode.c: copy files recursively

Use opendir() and readdir() to read the native directory, then use
lstat() to identify the file type and call the corresponding function to
add the file to the filesystem, call the populate_fs() recursively if it
is a directory.

NOTE: the libext2fs can't create the socket file.

Signed-off-by: Robert Yang <liezhi.yang@windriver.com>
Reviewed-by: Darren Hart <dvhart@linux.intel.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
10 years agomke2fs: add the ability to copy files from a given directory
Robert Yang [Thu, 6 Mar 2014 16:00:23 +0000 (11:00 -0500)]
mke2fs: add the ability to copy files from a given directory

We will add a -d option which will be used for adding the files from a
given directory to the filesystem, it is similiar to genext2fs, but
genext2fs doesn't fully support ext4.

* We already have the basic operations in debugfs:
  - Copy regular file
  - Create directory
  - Create symlink
  - Create special file

  We will move these operations into create_inode.h and create_inode.c,
  then let both mke2fs and debugfs use them.

* What we need to do are:
  - Copy the given directory recursively, this will be done by the
    populate_fs()
  - Set the owner, mode and other informations
  - Handle the hard links

TODO:
  - The libext2fs can't create the socket file (S_IFSOCK), do we have a
    plan to support it ?

Signed-off-by: Robert Yang <liezhi.yang@windriver.com>
Reviewed-by: Darren Hart <dvhart@linux.intel.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
10 years agoMerge branch 'maint' into next
Theodore Ts'o [Thu, 6 Mar 2014 15:53:34 +0000 (10:53 -0500)]
Merge branch 'maint' into next

10 years agomke2fs: disable resize_inode feature if 64bit feature is enabled
Eryu Guan [Thu, 4 Jul 2013 09:05:10 +0000 (17:05 +0800)]
mke2fs: disable resize_inode feature if 64bit feature is enabled

Since auto_64-bit_support is on by default, resize_inode feature will
be disabled when creating a >16T ext4 according to mke2fs.conf(5).

This should also be done when making ext4 with "-O 64bit" to enable
64bit feature explicitly. Otherwise online resize to enlarge a
over-16T fs to larger would fail.

[root@localhost resize]# truncate -s 50t fs.img
[root@localhost resize]# losetup /dev/loop0 fs.img
[root@localhost resize]# mkfs -t ext4 -O 64bit /dev/loop0 30t
[root@localhost resize]# mount /dev/loop0 mnt
[root@localhost resize]# resize2fs /dev/loop0
resize2fs 1.42.7 (21-Jan-2013)
Filesystem at /dev/loop0 is mounted on /root/resize/mnt; on-line resizing required
old_desc_blocks = 3840, new_desc_blocks = 6400
resize2fs: Invalid argument While checking for on-line resizing support

And dmesg shows
[688378.442623] EXT4-fs (loop0): resizing filesystem from 6710886400 to 13421772800 blocks
[688378.443216] EXT4-fs warning (device loop0): verify_reserved_gdb:700: reserved GDT 3201 missing grp 177147 (5804756097)
[688378.443222] EXT4-fs (loop0): resized filesystem to 8858370048
[688378.528451] EXT4-fs warning (device loop0): ext4_group_extend:1710: can't shrink FS - resize aborted

With this fix resize2fs could do the online enlarge correctly.

Signed-off-by: Eryu Guan <guaneryu@gmail.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
10 years agoe2fsck: don't use e2fsck_global_ctx in e2fsck_set_bitmap_type()
Theodore Ts'o [Wed, 5 Mar 2014 00:10:26 +0000 (19:10 -0500)]
e2fsck: don't use e2fsck_global_ctx in e2fsck_set_bitmap_type()

There is no reason to use e2fsck_global_ctx in
e2fsck_set_bitmap_type(), since we can get the context structure from
fs->priv_data.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
10 years agoe2fsck: always make sure e2fsck_global_ctx is set
Theodore Ts'o [Wed, 5 Mar 2014 00:05:00 +0000 (19:05 -0500)]
e2fsck: always make sure e2fsck_global_ctx is set

The e2fsck_global_ctx varible was only being set if HAVE_SIGNAL_H is
defined.  There are systems, such as Android, where this is not true.

This was causing e2fsck_set_bitmap_type() to seg fault since
e2fsck_global_ctx was not NULL.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
Reported-by: JP Abgrall <jpa@google.com>
10 years agolibext2fs: add a unit test for inline data
Zheng Liu [Mon, 3 Mar 2014 06:03:52 +0000 (01:03 -0500)]
libext2fs: add a unit test for inline data

In this unit test, we will test the interface of inline data and make
sure it is fine.

Signed-off-by: Zheng Liu <wenqing.lz@taobao.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
10 years agolibext2fs: export inode cache creation function
Zheng Liu [Mon, 3 Mar 2014 06:03:24 +0000 (01:03 -0500)]
libext2fs: export inode cache creation function

Currently we have already exported inode cache flush and free functions
for users.  This commit exports inode cache creation function.  Later
we will use this function to initialize inode cache and do some unit
tests for inline data.

Signed-off-by: Zheng Liu <wenqing.lz@taobao.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
10 years agomke2fs: enable inline_data feature on ext4dev filesystem
Zheng Liu [Mon, 3 Mar 2014 06:03:16 +0000 (01:03 -0500)]
mke2fs: enable inline_data feature on ext4dev filesystem

Signed-off-by: Zheng Liu <wenqing.lz@taobao.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
10 years agotests: change result in f_bad_disconnected_inode
Zheng Liu [Mon, 3 Mar 2014 06:02:59 +0000 (01:02 -0500)]
tests: change result in f_bad_disconnected_inode

In this test, inode flag is some random data, and after we apply inline
data patch set we should need to handle it.

Signed-off-by: Zheng Liu <wenqing.lz@taobao.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
10 years agoe2fsck: check inline_data in pass3
Zheng Liu [Mon, 3 Mar 2014 06:02:52 +0000 (01:02 -0500)]
e2fsck: check inline_data in pass3

In e2fsck_expand_directory() we don't handle a dir with inline data
because when this function is called the directory inode shouldn't
contains inline data.

Signed-off-by: Zheng Liu <wenqing.lz@taobao.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
10 years agoe2fsck: check inline_data in pass2
Zheng Liu [Mon, 3 Mar 2014 06:02:44 +0000 (01:02 -0500)]
e2fsck: check inline_data in pass2

Signed-off-by: Zheng Liu <wenqing.lz@taobao.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
10 years agoe2fsck: check inline_data in pass1
Zheng Liu [Mon, 3 Mar 2014 06:02:36 +0000 (01:02 -0500)]
e2fsck: check inline_data in pass1

Signed-off-by: Zheng Liu <wenqing.lz@taobao.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
10 years agoe2fsck: add problem descriptions and check inline data feature
Zheng Liu [Mon, 3 Mar 2014 06:02:28 +0000 (01:02 -0500)]
e2fsck: add problem descriptions and check inline data feature

Signed-off-by: Zheng Liu <wenqing.lz@taobao.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
10 years agomke2fs: add inline_data support in mke2fs
Zheng Liu [Mon, 3 Mar 2014 06:02:14 +0000 (01:02 -0500)]
mke2fs: add inline_data support in mke2fs

Now inline_data doesn't depend on ext_attr.  Hence we don't need to do
this sanity check.  But if the inode size is too small (128 bytes),
inline_data will be useless because we couldn't save data in ibody
extented attribute.  So we need to report this error.

Signed-off-by: Zheng Liu <wenqing.lz@taobao.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
10 years agolibext2fs: add inline_data feature into EXT2_LIB_FEATURE_INCOMPAT_SUPP
Zheng Liu [Mon, 3 Mar 2014 05:35:51 +0000 (00:35 -0500)]
libext2fs: add inline_data feature into EXT2_LIB_FEATURE_INCOMPAT_SUPP

Let e2fsprogs support inline_data feature.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Signed-off-by: Zheng Liu <wenqing.lz@taobao.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
10 years agolibext2fs: handle inline data in read/write function
Zheng Liu [Mon, 3 Mar 2014 05:35:51 +0000 (00:35 -0500)]
libext2fs: handle inline data in read/write function

Currently ext2fs_file_read/write are used to copy data from/to a file.
But they manipulate data by blocksize.  For supporting inline data, we
handle it in two new fucntions called ext2fs_file_read/write_inline_data.

In read path the implementation is straightforward.  But in write path
things get more complicated because if the size of data is greater than
the maximum size of inline data we will expand this file.  So now we
will check this in ext2fs_inline_data_set.  If this inode doesn't have
enough space, it will return EXT2_ET_INLINE_DATA_NO_SPACE error.  Then
the caller will check this error and tries to expand the file.

The following commands in debugfs can handle inline_data feature after
applying this patch:
- dump
- cat
- rdump
- write

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Signed-off-by: Zheng Liu <wenqing.lz@taobao.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
10 years agodebugfs: handle inline data feature in punch command
Zheng Liu [Mon, 3 Mar 2014 05:34:40 +0000 (00:34 -0500)]
debugfs: handle inline data feature in punch command

Now punch command only can remove all inline data because now
punch command is based on block unit and the size of inline data is
never beyond a block size.

Signed-off-by: Zheng Liu <wenqing.lz@taobao.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
10 years agodebugfs: handle inline_data feature in bmap command
Zheng Liu [Fri, 6 Dec 2013 09:58:04 +0000 (17:58 +0800)]
debugfs: handle inline_data feature in bmap command

No physical block mapping if an inode has inline data.

Signed-off-by: Zheng Liu <wenqing.lz@taobao.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
10 years agodebugfs: make lsdel command support inline data
Zheng Liu [Mon, 3 Mar 2014 05:31:27 +0000 (00:31 -0500)]
debugfs: make lsdel command support inline data

After checking inline data in ext2fs_inode_have_valid_blocks2() we won't
traverse the block in do_lsdel() function.  But if an inode has inline
data we also need to report it.

Signed-off-by: Zheng Liu <wenqing.lz@taobao.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
10 years agodebugfs: make mkdir command support inline data
Zheng Liu [Mon, 3 Mar 2014 05:31:27 +0000 (00:31 -0500)]
debugfs: make mkdir command support inline data

This commit tries to make mkdir command in debugfs support inline data.

Signed-off-by: Zheng Liu <wenqing.lz@taobao.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
10 years agodebugfs: make expand command support inline data
Zheng Liu [Mon, 3 Mar 2014 05:31:27 +0000 (00:31 -0500)]
debugfs: make expand command support inline data

This commit defines a ext2fs_inline_data_expand() to expand an inode with
inline data.  In this commit this function only can expand a directory.
But later it will expand a file.

Signed-off-by: Zheng Liu <wenqing.lz@taobao.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
10 years agodebugfs: make stat command support inline data
Zheng Liu [Mon, 3 Mar 2014 05:31:26 +0000 (00:31 -0500)]
debugfs: make stat command support inline data

If there is an inode with inline data, we just print the size of inline
data in stat command.

Signed-off-by: Zheng Liu <wenqing.lz@taobao.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
10 years agolibext2fs: handle inline_data in block iterator function
Zheng Liu [Mon, 3 Mar 2014 05:27:48 +0000 (00:27 -0500)]
libext2fs: handle inline_data in block iterator function

After applied this commit (a7f4c635), we have banned to traverse blocks
for an inode which has inline data because no block belongs to it.  But
before calling this function, we need to check inline data flag.  This
commit add a sanity check ext2fs_inode_has_valid_blocks2() to fix them
except that ext2fs_expand_dir because it will be fixed by another patch.

Meanwhile in this commit it fixes a bug that when we kill a file we
could leak an inode.

Signed-off-by: Zheng Liu <wenqing.lz@taobao.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
10 years agolibext2fs: handle inline data in dir iterator function
Zheng Liu [Fri, 6 Dec 2013 09:57:58 +0000 (17:57 +0800)]
libext2fs: handle inline data in dir iterator function

Inline_data is handled in dir iterator because a lot of commands use
this function to traverse directory entries in debugfs.  We need to
handle inline_data individually because inline_data is saved in two
places.  One is in i_block, and another is in ibody extended attribute.

After applied this commit, the following commands in debugfs can
support the inline_data feature:
- cd
- chroot
- link*
- ls
- ncheck
- pwd
- unlink

* TODO: Inline_data doesn't expand to ibody extended attribute because
  link command doesn't handle DIR_NO_SPACE error until now.  But if we
  have already expanded inline data to ibody ea area, link command can
  occupy this space.

Signed-off-by: Zheng Liu <wenqing.lz@taobao.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
10 years agolibext2fs: define new dirent_swab interfaces for inline data
Zheng Liu [Mon, 3 Mar 2014 05:24:30 +0000 (00:24 -0500)]
libext2fs: define new dirent_swab interfaces for inline data

Later we will use ext2fs_dirent_swab_in/out to handle big-endian problem
for inline data.  Now interfaces assume that it handles a block, but it
is not true after adding inline data.  So this commit defines a new
interface for inline data.

Signed-off-by: Zheng Liu <wenqing.lz@taobao.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
10 years agodebian: fix udeb package support
Filipe Brandenburger [Tue, 25 Feb 2014 06:33:00 +0000 (01:33 -0500)]
debian: fix udeb package support

Previous commit which introduced SKIP_UDEB variable had typos in the
variable name in the m4 macros of control.in (UDEV vs. UDEB.) Fix those
typos and fix m4 quoting problem in "Don't".

Signed-off-by: Filipe Brandenburger <filbranden@google.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
10 years agodebugfs: dump all extended attributes
Darrick J. Wong [Sun, 23 Feb 2014 01:40:44 +0000 (20:40 -0500)]
debugfs: dump all extended attributes

Use the new extended attribute APIs to display all extended attributes
(current code does not look in the EA block) and display full names
(current code ignores name index too).

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
10 years agolibext2fs: free key/value pairs before reading
Darrick J. Wong [Sun, 23 Feb 2014 01:40:42 +0000 (20:40 -0500)]
libext2fs: free key/value pairs before reading

Before loading extended attributes, free any key/value pairs that
might already be associated with the file.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
10 years agolibext2fs: extend xattr api to query number of attrs
Darrick J. Wong [Sun, 23 Feb 2014 01:40:41 +0000 (20:40 -0500)]
libext2fs: extend xattr api to query number of attrs

Add another API to query the number of extended attributes.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
10 years agolibext2fs: various tweaks to the xattr editor APIs
Darrick J. Wong [Sun, 23 Feb 2014 01:40:40 +0000 (20:40 -0500)]
libext2fs: various tweaks to the xattr editor APIs

A few tweaks to the extended attribute editing APIs:

 * Use size_t, not unsigned int, in the new extended attribute editing
   API.

 * Don't expose the _expand() call since there should be no external
   users.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
10 years agolibext2fs: support modifying arbitrary extended attributes
Darrick J. Wong [Sun, 23 Feb 2014 01:40:38 +0000 (20:40 -0500)]
libext2fs: support modifying arbitrary extended attributes

Add functions to allow clients to get, set, and remove extended
attributes from any file.  It also supports modifying EAs living in
i_file_acl.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
10 years agoMerge branch 'maint' into next
Theodore Ts'o [Mon, 24 Feb 2014 04:07:38 +0000 (23:07 -0500)]
Merge branch 'maint' into next

10 years agoresize2fs: don't free in-use clusters when moving blocks
Darrick J. Wong [Mon, 24 Feb 2014 01:54:54 +0000 (20:54 -0500)]
resize2fs: don't free in-use clusters when moving blocks

When we're moving blocks around the filesystem, ensure that freeing
the old blocks only frees the clusters if they're not in use by other
metadata.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
10 years agoresize2fs: during shrink, don't free in-use bg data clusters
Darrick J. Wong [Mon, 24 Feb 2014 01:33:59 +0000 (20:33 -0500)]
resize2fs: during shrink, don't free in-use bg data clusters

When freeing a block group descriptor block, be careful not to free
metadata clusters belonging to other groups!

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
10 years agoe2fsck: don't add a UUID on a mounted filesystem with csums
Michael Marineau [Sun, 19 Jan 2014 22:09:34 +0000 (14:09 -0800)]
e2fsck: don't add a UUID on a mounted filesystem with csums

This fix is similar to 66457fcb for tune2fs. When booting from a root
filesystem with an empty UUID which fsck fixes the following remount
step reliably fails, leaving the filesystem in an inconsistent state.
Like the tune2fs fix this patch resolves the issue by simply refusing to
update the UUID if the filesystem is mounted.

Signed-off-by: Michael Marineau <michael.marineau@coreos.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
10 years agoAdd coverage testing using gcov
Theodore Ts'o [Sun, 23 Feb 2014 05:17:09 +0000 (00:17 -0500)]
Add coverage testing using gcov

To check the coverage of e2fsprogs's regression test, do the
following:

configure --enable-gcov
make -j8 ; make -j8 check ; make coverage.txt

The coverage information will be the coverage.txt and *.gcov files in
the build directories.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
10 years agoMerge branch 'maint' into next
Theodore Ts'o [Fri, 21 Feb 2014 02:39:29 +0000 (21:39 -0500)]
Merge branch 'maint' into next

10 years agoSet pointer to NULL after ext2fs_free
Lukas Czerner [Fri, 21 Feb 2014 01:54:29 +0000 (20:54 -0500)]
Set pointer to NULL after ext2fs_free

ext2fs_free() does not set the ext2_filsys pointer to null so the
caller is responsible to setting it himself if it is needed.

This patch fixes some places where caller did not set ext2_filsys
pointer to NULL after ext2fs_free() which might result in use after
free.  Fix it.

Signed-off-by: Lukas Czerner <lczerner@redhat.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
10 years agotune2fs: allow removal of dirty journal with two "-f" options
Eric Sandeen [Fri, 21 Feb 2014 01:18:41 +0000 (20:18 -0500)]
tune2fs: allow removal of dirty journal with two "-f" options

Jim pointed out that "tune2fs -f -O ^has_journal" won't remove the
journal if the needs_recovery flag is set; the manpage seems to indicate
that it should.  And if you've lost an external journal and can no longer
replay it, how should one proceed?

Change tune2fs so that two "-f" options will allow removal of a dirty
journal from a filesystem, even if the filesystem needs recovery.

e2fsck can then do its best to pick up the pieces.

Addresses-Debian-Bug: #559301

Reported-by: Jim Faulkner <james.faulkner@yale.edu>
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
10 years agolibext2fs: delete unused "handle" variable
jon ernst [Fri, 21 Feb 2014 00:59:24 +0000 (19:59 -0500)]
libext2fs: delete unused "handle" variable

After commit 62f17f36031102a2a40fac338e063c556f73b94a, variable
"handle" has no use.  So delete it.

Signed-off-by: Jon Enrst <jonernst07@gmail.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
10 years agoe4defrag: remove local sync_file_range and fallocate
Baruch Siach [Wed, 19 Feb 2014 01:02:49 +0000 (20:02 -0500)]
e4defrag: remove local sync_file_range and fallocate

The locally defined versions of both sync_file_range and fallocate are broken
on 32bit systems. On these systems two 32bit registers are needed for each
64bit parameter. Also, sync_file_range on MIPS32 needs a dummy parameters
after the fd parameter. Just leave all these subtleties to the C library.

Signed-off-by: Baruch Siach <baruch@tkos.co.il>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
10 years agoext2fs: declare struct_io_manager at end of file
Andreas Dilger [Tue, 18 Feb 2014 23:31:36 +0000 (18:31 -0500)]
ext2fs: declare struct_io_manager at end of file

Declare struct_io_manager at the end of unix_io.c, undo_io.c, and
test_io.c files so that there isn't a need to forward declare every
member of this structure.  That avoids a lot of redundant code
at the start of every one of these files.

Move the test_flush() function above test_abort() to avoid the need
for a forward declaration.

Fix a few instances of space before tab in these files.

Signed-off-by: Andreas Dilger <adilger@dilger.ca>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
10 years agotests: skip unsupported tests on MacOS systems
Andreas Dilger [Tue, 18 Feb 2014 23:29:55 +0000 (18:29 -0500)]
tests: skip unsupported tests on MacOS systems

The "mkswap" program is not available on MacOS, so just use the
existing swap0.img.bz2 and swap1.img.bz2 files directly.

Because MacOS HFS+ doesn't support sparse files (welcome to the 80's)
the m_bigjournal test takes forever to zero out the whole 42GB test
filesystem.  Skip this test for Darwin kernels for now.

Unfortunately, neither "df -T" nor "stat -f -c %T" is available on
MacOS to directly determine the filesystem type, and I'm too lazy
to parse the output of "mount" and match it to the path of the test
directory in shell, so it just checks the kernel type and assumes
the filesystem type is HFS and skips the test.

Since this test runs on Linux the majority of the time, the loss of
test coverage is minimal.  If MacOS should ever get a real filesystem,
this can be revisited.

Signed-off-by: Andreas Dilger <adilger@dilger.ca>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
10 years agobuild: fix LLVM compiler warnings
Andreas Dilger [Tue, 18 Feb 2014 17:12:32 +0000 (12:12 -0500)]
build: fix LLVM compiler warnings

Fix a number of non-literal string format warnings from LLVM due
to the use of _() that were not fixed in commit 45ff69ffeb.

Fix mismatched int vs. __u64 format warnings in blkmap64_rb.c.
There were also some comparisons of __u64 start or count <= 0.
Change them to be comparisons == 0, or start + count overflow.

Fix operator precedence warning for (value & (value - 1) != 0)
introduced in 11d1116a7c0b.  It seems "&" is lower precedence
than "!=", so the above didn't fail for power-of-two values,
but only odd values.  Fortunately, either s_desc_size nor
s_inode_size is valid if odd.

Signed-off-by: Andreas Dilger <adilger@dilger.ca>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
10 years agochattr: improve the description for 'j' option in manpage
Zheng Liu [Wed, 12 Feb 2014 17:28:29 +0000 (12:28 -0500)]
chattr: improve the description for 'j' option in manpage

Ext4 file system also supports to set/clear 'j' attribute, but it just
say that this option is only useful for ext3 in manpage.  This commit
fixes it.

Signed-off-by: Zheng Liu <wenqing.lz@taobao.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
Reviewed-by: Carlos Maiolino <cmaiolino@redhat.com>
10 years agolibe2p: allow libe2p.h to be used in C++ programs
Theodore Ts'o [Fri, 7 Feb 2014 22:25:28 +0000 (17:25 -0500)]
libe2p: allow libe2p.h to be used in C++ programs

In C++, "private" is a reserved keyword, so don't use it in the header
file as a function parameter name.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
10 years agoMerge branch 'maint' into next
Theodore Ts'o [Thu, 6 Feb 2014 20:39:28 +0000 (15:39 -0500)]
Merge branch 'maint' into next

10 years agolibext2fs: try to roll back when splitting an extent fails
Darrick J. Wong [Thu, 6 Feb 2014 20:34:00 +0000 (15:34 -0500)]
libext2fs: try to roll back when splitting an extent fails

If a client asks us to remap a block in the middle of an extent, we
potentially have to allocate a fair number of blocks to handle extent
tree splits.  A failure in either of the ext2fs_extent_insert calls
leaves us with an extent tree that no longer maps the logical block in
question and everything that came after it!  Therefore, try to roll
back the extent tree changes before returning an error code.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Zheng Liu <wenqing.lz@taobao.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
10 years agolibext2fs: don't hang on to unmapped block if extent tree update fails
Darrick J. Wong [Thu, 6 Feb 2014 20:32:18 +0000 (15:32 -0500)]
libext2fs: don't hang on to unmapped block if extent tree update fails

If we're doing a BMAP_ALLOC allocation and the extent tree update
fails, there's no point in hanging on to the newly allocated block.
So, free it to make fsck happy.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Zheng Liu <wenqing.lz@taobao.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
10 years agolibext2fs: during punch, fix parent extents after modifying extent
Darrick J. Wong [Thu, 6 Feb 2014 20:30:59 +0000 (15:30 -0500)]
libext2fs: during punch, fix parent extents after modifying extent

When modifying/removing an extent during punch, don't forget to update
the extent's parents.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Zheng Liu <wenqing.lz@taobao.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
10 years agolibext2fs: iterate past lower extents during punch
Darrick J. Wong [Thu, 6 Feb 2014 20:29:15 +0000 (15:29 -0500)]
libext2fs: iterate past lower extents during punch

When we're iterating extents during a punch operation, the loop exits
if the punch region is entirely to the right of the extent we're
looking at.  This can happen if the punch region starts in the middle
of a hole and covers mapped extents.  When this happens, we want to
skip to the next extent, because it might be punchable.

Also, if we've totally passed the punch range, stop.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Zheng Liu <wenqing.lz@taobao.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
10 years agomke2fs: clean up kernel version tests
Darrick J. Wong [Thu, 6 Feb 2014 20:24:01 +0000 (15:24 -0500)]
mke2fs: clean up kernel version tests

Refactor the running kernel version checks to hide the details of
version code checking, etc.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Zheng Liu <wenqing.lz@taobao.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
10 years agoe2fsprogs: Disallow tune2fs enabling sparse_super with ext4 meta_bg enabled
Akira Fujita [Thu, 6 Feb 2014 20:11:52 +0000 (15:11 -0500)]
e2fsprogs: Disallow tune2fs enabling sparse_super with ext4 meta_bg enabled

When meta_bg feature is enabled, group descriptor block is allocated
every 128 block group (or every 64 block group if 64bit feature is
enabled).

In such situation, files in block group more than #128 will be removed
if sparse_super feature is enabled with tune2fs and afterwards
necessary e2fsck running.

Because tune2fs does not reallocate group descriptor blocks but just
set sparse_super feature.  If ext4 has sparse_super,
ext2fs_descriptor_block_loc2() called by e2fsck thinks the block group
(e.g. #128) that it has group descriptor block at the head offset. But
that offset is used as backup super block before.  So e2fsck fixes
ext4 based on invalid group descriptor blocks and this cause data
lost.

The patch avoids this problem simply by disallow tune2fs enabling
sparse_super if meta_bg is enabled.

Steps to reproduce:

1. Create ext4 which has meta_bg, ^sparse_super and 129+ block groups.
# mke2fs -t ext4 -O meta_bg,^resize_inode,^sparse_super DEV 17G
# mount DEV /MP

2. Create direcotry and files which use block group #128's metadata.
# echo $((8192*128+1)) > /sys/fs/ext4/DEV/inode_goal
# mkdir /MP/DIR
# for i in $(seq 1 100); do dd if=/dev/urandom of=/MP/DIR/file$i bs=1024 count=10; done

3. Enable sparse_super with tune2fs then execute e2fsck.
   Data in block group #128 will be lost!!
# umount DEV
# tune2fs -O sparse_super DEV
# e2fsck/e2fsck -yf DEV

Signed-off-by: Akira Fujita <a-fujita@rs.jp.ne.cocm>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
10 years agodebian: fix spelling typo in debian/control.in
Theodore Ts'o [Thu, 6 Feb 2014 20:00:44 +0000 (15:00 -0500)]
debian: fix spelling typo in debian/control.in

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
10 years agodebian: add make variable to prevent building udeb packages
Theodore Ts'o [Thu, 6 Feb 2014 19:59:25 +0000 (14:59 -0500)]
debian: add make variable to prevent building udeb packages

Setting SKIP_UDEBS=yes in rules.custom will prevent the debian/rules
makefile from building the udeb files for the debian installer.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
10 years agomke2fs: minor bugfixes for mk_hugefiles
Theodore Ts'o [Thu, 6 Feb 2014 19:34:12 +0000 (14:34 -0500)]
mke2fs: minor bugfixes for mk_hugefiles

Interpret "zero_hugefiles" relation in mke2fs.conf as a boolean value,
as documented in the man page.

If the hugefile is larger than 2GB, set the large_file file system
feature so e2fsck doesn't complain.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
10 years agoconfigure: support biarch builds with --multiarch=lib64
Theodore Ts'o [Wed, 5 Feb 2014 20:45:36 +0000 (15:45 -0500)]
configure: support biarch builds with --multiarch=lib64

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
10 years agoMerge branch 'maint' into next
Theodore Ts'o [Wed, 5 Feb 2014 20:16:11 +0000 (15:16 -0500)]
Merge branch 'maint' into next

Conflicts:
debian/changelog
debian/e2fslibs.symbols
version.h

10 years agodebian: update debian/changelog and e2fslibs.symbols for 1.42.9-3 release
Theodore Ts'o [Wed, 5 Feb 2014 03:59:25 +0000 (22:59 -0500)]
debian: update debian/changelog and e2fslibs.symbols for 1.42.9-3 release

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
10 years agodebian: fix dpkg-buildpackage for Debian Squeeze
Theodore Ts'o [Wed, 5 Feb 2014 02:45:51 +0000 (21:45 -0500)]
debian: fix dpkg-buildpackage for Debian Squeeze

Commit becb01ce84d breaks building e2fsprogs with dpkg 1.15.8 which is
used in Debian 6.0 (Squeeze), since it doesn't support package
specifications qualified with an architecture (i.e., "dpkg-query -W
libblkid1:amd64").

Debian only needs to use its own version of libblkid and libuuid for
versions of Debian 5.0 (Lenny) or before.  So default to using
util-linux-ng, instead of trying to test the version number of
libblkid1.

Lenny was released in February, 2009, and the current stable Debian
release is 7.x, so it is two stable releases back as of February 2014.
In the unlikely case someone needs to build a modern version of
e2fsprogs on a version of Debian which is five years old or older, can
create the file Debian/rules.custom with the line:

UTIL_LINUX_NG = no

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
10 years agomke2fs: add support for hugefiles_align
Theodore Ts'o [Tue, 4 Feb 2014 17:30:00 +0000 (12:30 -0500)]
mke2fs: add support for hugefiles_align

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
10 years agoMerge branch 'maint' into next
Theodore Ts'o [Fri, 31 Jan 2014 00:05:16 +0000 (19:05 -0500)]
Merge branch 'maint' into next

Conflicts:
lib/ext2fs/alloc.c
misc/mke2fs.c

10 years agoFix up the Makefiles dependencies in lib/ext2fs and lib/quota
Theodore Ts'o [Thu, 30 Jan 2014 23:48:23 +0000 (18:48 -0500)]
Fix up the Makefiles dependencies in lib/ext2fs and lib/quota

Also use angle brackets for the #include of dirpaths.h to avoid the
need to manually massage the Makefile.in for the util directory.  This
is needed because we have to create a fake dirpaths.h file in the util
directory.  The fake dirpaths.h file is rquired to break the circular
dependency caused by util/subst creating dirpaths.h, while
util/subst.c is including config.h, which includes dirpaths.h.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
10 years agoblkid: suppress Coverity warning
Theodore Ts'o [Thu, 30 Jan 2014 23:02:37 +0000 (18:02 -0500)]
blkid: suppress Coverity warning

The getopt() function will never let optarg be NULL (at least without
using the GNU double-colon extension, which we don't use because it's
not portable), so don't bother checking for that case.  It's harmless,
but it triggers a Coverity warning elsewhere, since it thinks optarg
could in fact be NULL.

Addresses-Coverity-Id: #1049156

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
10 years agolibss: fix potential buffer overrun in list_rqs
Theodore Ts'o [Thu, 30 Jan 2014 22:45:36 +0000 (17:45 -0500)]
libss: fix potential buffer overrun in list_rqs

Addresses-Coverity-Bug: #709516

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
10 years agoquota: fix uninitiaized memory reference in mke2fs with quota enabled
Theodore Ts'o [Thu, 30 Jan 2014 22:10:46 +0000 (17:10 -0500)]
quota: fix uninitiaized memory reference in mke2fs with quota enabled

Initialize the on-disk structure before we fill it in, to avoid the
following valgrind warning:

   Conditional jump or move depends on uninitialised value(s)
      at 0x4323A8: qtree_entry_unused (quotaio_tree.c:40)
      by 0x431218: v2r1_mem2diskdqblk (quotaio_v2.c:85)
      by 0x432409: qtree_write_dquot (quotaio_tree.c:336)
      by 0x431136: v2_commit_dquot (quotaio_v2.c:264)
      by 0x42FB63: quota_write_inode (mkquota.c:126)
      by 0x408BE6: create_quota_inodes (mke2fs.c:2466)
      by 0x409A2D: main (mke2fs.c:2850)

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
10 years agoblkid: avoid potential integer overflow issues identified by Coverity
Theodore Ts'o [Thu, 30 Jan 2014 21:19:01 +0000 (16:19 -0500)]
blkid: avoid potential integer overflow issues identified by Coverity

Addresses-Coverity-Id: #1049157
Addresses-Coverity-Id: #1049158

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
10 years agomke2fs: add make_hugefile feature
Theodore Ts'o [Tue, 21 Jan 2014 04:06:07 +0000 (23:06 -0500)]
mke2fs: add make_hugefile feature

This feature is enabled via settings in /etc/mke2fs.conf.  For
example:

hugefile = {
features = extent,huge_file,flex_bg,uninit_bg,dir_nlink,extra_isize,^resize_inode,sparse_super2
inode_size = 128
num_backup_sb = 0
packed_meta_blocks = 1
make_hugefiles = 1
inode_ratio = 4194304
hugefiles_dir = /database
hugefiles_uid = 120
hugefiles_gid = 50
hugefiles_name = storage
hugefiles_digits = 4
hugefiles_size = 1G
num_hugefiles = 0
}

Then "mke2fs -T hugefile /dev/sdXX" will create as many 1G files
needed to fill the file system.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
10 years agoe2fsck, mke2fs: enable octal integers in the profile/config file
Theodore Ts'o [Tue, 21 Jan 2014 05:59:03 +0000 (00:59 -0500)]
e2fsck, mke2fs: enable octal integers in the profile/config file

If an integer in the config file starts with a 0, interpret it as an
octal number.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
10 years agomke2fs: allow metadata blocks to be at the beginning of the file system
Theodore Ts'o [Tue, 28 Jan 2014 19:44:23 +0000 (14:44 -0500)]
mke2fs: allow metadata blocks to be at the beginning of the file system

Add the extended options packed_meta_blocks and journal_location_front
which causes mke2fs to place the metadata blocks at the beginning of
the file system.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
10 years agoAdd support for new compat feature "sparse_super2"
Theodore Ts'o [Sun, 12 Jan 2014 03:11:42 +0000 (22:11 -0500)]
Add support for new compat feature "sparse_super2"

In practice, it is **extremely** rare for users to try to use more
than the first backup superblock located at the beginning of block
group #1.  (i.e., at block number 32768 for file systems with a 4k
block size).  This new compat feature restricts the backup superblock
to block group #1 and the last block group in the file system.

Aside from reducing the overhead of the file system by a small number
of blocks, by eliminating the rest of the backup superblocks, it
allows us to have a much more flexible metadata layout.  For example,
we can force all of the allocation bitmaps and inode table blocks to
the beginning of the disk, which allows most of the disk to be
exclusively used for contiguous data blocks.

This simplifies taking advantage of certain HDD specific features,
such as Shingled Magnetic Recording (aka Shingled Drives), and the
TCG's OPAL Storage Specification where having a simple mapping between
LBA block ranges and the data blocks used by the file system can make
life much simpler.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
10 years agotune2fs, mke2fs: add the ability to control the location of the journal
Theodore Ts'o [Tue, 28 Jan 2014 17:58:56 +0000 (12:58 -0500)]
tune2fs, mke2fs: add the ability to control the location of the journal

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
10 years agolibext2fs: add new function ext2fs_add_journal_inode2()
Theodore Ts'o [Tue, 28 Jan 2014 17:16:35 +0000 (12:16 -0500)]
libext2fs: add new function ext2fs_add_journal_inode2()

This new function has an parameter which allows the caller to specify
the location of the journal.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
10 years agolibext2fs: factor out get_midpoint_journal_block() in mkjournal.c
Theodore Ts'o [Tue, 28 Jan 2014 17:12:27 +0000 (12:12 -0500)]
libext2fs: factor out get_midpoint_journal_block() in mkjournal.c

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
10 years agomke2fs: optimize fix_cluster_bg_counts()
Theodore Ts'o [Mon, 20 Jan 2014 00:44:45 +0000 (19:44 -0500)]
mke2fs: optimize fix_cluster_bg_counts()

Instead of iterating over the allocation bitmap using
ext2fs_test_block_bitmap2(), bit by bit, use
ext2fs_find_first_set_block_bitmap2() instead.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
10 years agolibext2fs: optimize ext2fs_new_block2()
Theodore Ts'o [Mon, 20 Jan 2014 00:35:33 +0000 (19:35 -0500)]
libext2fs: optimize ext2fs_new_block2()

If there are hundreds of thousands of blocks which are in use before
the first free block, it is much, MUCH faster to use
ext2fs_find_first_zero_block_bitmap2() instead of searching the
allocation bitmap bit by bit.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
10 years agolibext2fs: optimize ext2fs_allocate_group_table()
Theodore Ts'o [Sun, 19 Jan 2014 21:47:21 +0000 (16:47 -0500)]
libext2fs: optimize ext2fs_allocate_group_table()

By using ext2fs_mark_block_bitmap_range2 and/or
ext2fs_block_alloc_stats_range(), we can significantly speed up the
time needed by mke2fs to allocate the inode table.

For example, the CPU time needed to run the command "mke2fs -t ext4
/tmp/foo.img 32T" (where tmpfs was mounted on /tmp) was decreased from
21.7 CPU seconds down to under 1.7 seconds.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
10 years agolibext2fs: add ext2fs_block_alloc_stats_range()
Theodore Ts'o [Sun, 19 Jan 2014 21:35:50 +0000 (16:35 -0500)]
libext2fs: add ext2fs_block_alloc_stats_range()

This function is more efficient than using ext2fs_block_alloc_stats2()
for each block in a range.  The efficiencies come from being able to
set a block range in the block bitmap at once, and from being update
the block group descriptors once per block group.  Especially now that
we are checksuming the block group descriptors, and we are using red
black trees for the allocation bitmaps, these changes can make a huge
difference in the CPU time used by mke2fs when creating very large
file systems.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
10 years agolibext2fs: further clean up and rename check_block_uninit
Theodore Ts'o [Sun, 19 Jan 2014 06:24:30 +0000 (01:24 -0500)]
libext2fs: further clean up and rename check_block_uninit

Commit 8e44eb64bb (libext2fs: mark group data blocks when loading
block bitmap) simplified check_block_uninit since we are now
initializing the bitmap when it is loaded from disk.  It left some
variables which were being set but never used, however.  In addition,
since we only need check_block_uninit() to clear the block bitmap's
uninit flag, rename it to clear_block_uninit(), and only call it once
we have found a free block in ext2fs_new_blocks2().

This cleans up the code some and optimizes things if we need to search
multiple block groups trying to find a free block.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
Cc: Darrick J. Wong <darrick.wong@oracle.com>
10 years agolibext2fs: optimize find_first_{zero,set}() for red-black tree based bitmaps
Theodore Ts'o [Mon, 13 Jan 2014 02:46:46 +0000 (21:46 -0500)]
libext2fs: optimize find_first_{zero,set}() for red-black tree based bitmaps

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
10 years agolibext2fs: optimize find_first_set() for bitarray-based bitmaps
Theodore Ts'o [Mon, 13 Jan 2014 02:45:04 +0000 (21:45 -0500)]
libext2fs: optimize find_first_set() for bitarray-based bitmaps

Basically just a trivial adaption of the find_first_zero() function
for bitarray-based bitmaps.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
10 years agolibext2fs: build tst_bitmaps with rep invariants checking enabled
Theodore Ts'o [Mon, 13 Jan 2014 01:18:55 +0000 (20:18 -0500)]
libext2fs: build tst_bitmaps with rep invariants checking enabled

When building tst_bitmaps, enable #define DEBUG_RB, so we are
always testing the sanity of the in-memory representation of the
bitmap when using red-black trees as part of a "make check" run.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
10 years agolibext2fs: clean up generic handling of ext2fs_find_first_{set,zero}_*()
Theodore Ts'o [Mon, 13 Jan 2014 00:45:43 +0000 (19:45 -0500)]
libext2fs: clean up generic handling of ext2fs_find_first_{set,zero}_*()

Move the error checking into the the generic bitmap code, and add
support for bitmaps with cluster_bits set.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
10 years agolibext2fs: fix off-by-one bug in ext2fs_extent_insert()
Theodore Ts'o [Thu, 16 Jan 2014 04:29:21 +0000 (23:29 -0500)]
libext2fs: fix off-by-one bug in ext2fs_extent_insert()

When inserting the first extent into an empty inode, the
ext2fs_extent_insert() leaves path->left set to 1 instead of 0.  Since
path->curr is pointing at the last (only) extent in the file,
path->left should be 0.

This is mostly harmless, and gets corrected fairly quickly if the
calling applicaton jumps to a different part of the extent tree ---
for example, by calling ext2fs_extent_goto(), or calling
ext2fs_extent_get with the flags argument set to EXT2_EXTENT_ROOT.
Which is why we hadn't noticed this problem until now.

However, if you insert four extents using ext2fs_extent_insert, the
fourth insert will end up copying too many bytes in the i_block[]
array, since path->left is one larger than it should be.  This results
in the inode fields i_generation, i_file_acl, and i_size_high getting
zeroed out.

This problem can be replicated as follows:

% cp /dev/null /tmp/foo.img
% mke2fs -F -t ext4 /tmp/foo.img 100
% debugfs -w /tmp/foo.img
debugfs: write /dev/null foo
debugfs: set_inode_field foo i_size_hi 1
debugfs: stat foo
 <----- note that the inode's size is 4294967296
debugfs: extent_open foo
debugfs (extent ino 12): insert --after 0 1 100
debugfs (extent ino 12): insert --after 1 1 101
debugfs (extent ino 12): insert --after 2 1 102
debugfs (extent ino 12): insert --after 3 1 103
debugfs (extent ino 12): extent_close
debugfs: stat foo
 <----- note that the inode's size is now 0
debugfs: quit

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
10 years agolibext2fs: add ext2fs_find_first_set_{block,inode}_bitmap2()
Theodore Ts'o [Sun, 12 Jan 2014 20:57:31 +0000 (15:57 -0500)]
libext2fs: add ext2fs_find_first_set_{block,inode}_bitmap2()

Add functions which try to find the first set block or inode in a
bitmap.  This is useful when trying to allocate a range of blocks
efficiently.

Like the find_first_zero family of functions, provide a generic O(N)
search function which will be used if there is no optimized version
provided by the red-black tree or bitarray functions.

Also, expand the test cases for ext2fs_find_first_zero_*() functions.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
10 years agoext4.5: remove duplicate .TP in man page
Theodore Ts'o [Sun, 12 Jan 2014 03:07:24 +0000 (22:07 -0500)]
ext4.5: remove duplicate .TP in man page

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
Reviewed-by: Carlos Maiolino <cmaiolino@redhat.com>
10 years agotests: adjust test output to reflect block_uninit calculated block bitmaps
Darrick J. Wong [Sat, 11 Jan 2014 19:15:52 +0000 (14:15 -0500)]
tests: adjust test output to reflect block_uninit calculated block bitmaps

Now that libext2fs marks group metadata in the fs block bitmap, adjust
the expected test output to reflect expanded use of block_uninit and
the fact debugfs no longer prints block bitmap data that fails to
account for group data blocks.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
10 years agolibext2fs: no need to clear BLOCK_UNINIT during ext2fs_reserve_super_and_bgd
Darrick J. Wong [Sat, 11 Jan 2014 19:15:51 +0000 (14:15 -0500)]
libext2fs: no need to clear BLOCK_UNINIT during ext2fs_reserve_super_and_bgd

Since the beginning of the uninit_bg feature, the kernel[1] and
e2fsck[2] have always been careful to detect the presence of the
BLOCK_UNINIT flag, and compute a block bitmap with any group metadata
blocks marked in that bitmap.  With that in mind, I think it's safe to
say that this is a design feature of uninit_bg.

Now that we've trained libext2fs to have this same behavior whenever
it's loading a block bitmap, we no longer need to unset BLOCK_UNINIT
for a group that contains only its own group metadata -- kernel,
e2fsck, and e2fsprogs will handle this correctly.

[1] kernel git 717d50e4971b81b96c0199c91cdf0039a8cb181a
    "Ext4: Uninitialized Block Groups"
[2] e2fsprogs git f5fa20078bfc05b554294fe9c5505375d7913e8c
    "Add support for EXT2_FEATURE_COMPAT_LAZY_BG"

Reported-by: Akira Fujita <a-fujita@rs.jp.nec.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
10 years agoe2fsck: remove uninit block bitmap calculation
Darrick J. Wong [Sat, 11 Jan 2014 19:05:02 +0000 (14:05 -0500)]
e2fsck: remove uninit block bitmap calculation

Since libext2fs now detects a BLOCK_UNINIT group and calculates the
group's block bitmap, we no longer need to emulate this behavior in
e2fsck.  We can simply compare the found block map against the
filesystem's, and proceed from there.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>