From: "Darrick J. Wong" <darrick.wong@oracle.com>
To: tytso@mit.edu, darrick.wong@oracle.com
Cc: linux-ext4@vger.kernel.org, Pu Hou <houpu.hp@alibaba-inc.com>
Subject: [PATCH 06/27] libext2fs: create inlinedata symlinks
Date: Sat, 16 Aug 2014 16:46:29 -0700 [thread overview]
Message-ID: <20140816234629.11171.85990.stgit@birch.djwong.org> (raw)
In-Reply-To: <20140816234550.11171.61585.stgit@birch.djwong.org>
Add to ext2fs_symlink the ability to create inline data symlinks.
Suggested-by: Pu Hou <houpu.hp@alibaba-inc.com>
Cc: Pu Hou <houpu.hp@alibaba-inc.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
lib/ext2fs/symlink.c | 34 ++++++++++++++++++++---
tests/f_create_symlinks/expect | 36 ++++++++++++++++++++++++
tests/f_create_symlinks/name | 1 +
tests/f_create_symlinks/script | 59 ++++++++++++++++++++++++++++++++++++++++
4 files changed, 125 insertions(+), 5 deletions(-)
create mode 100644 tests/f_create_symlinks/expect
create mode 100644 tests/f_create_symlinks/name
create mode 100644 tests/f_create_symlinks/script
diff --git a/lib/ext2fs/symlink.c b/lib/ext2fs/symlink.c
index ba8ed8e..f6eb6b6 100644
--- a/lib/ext2fs/symlink.c
+++ b/lib/ext2fs/symlink.c
@@ -35,7 +35,7 @@ errcode_t ext2fs_symlink(ext2_filsys fs, ext2_ino_t parent, ext2_ino_t ino,
struct ext2_inode inode;
ext2_ino_t scratch_ino;
blk64_t blk;
- int fastlink;
+ int fastlink, inlinelink;
unsigned int target_len;
char *block_buf = 0;
@@ -77,15 +77,36 @@ errcode_t ext2fs_symlink(ext2_filsys fs, ext2_ino_t parent, ext2_ino_t ino,
memset(&inode, 0, sizeof(struct ext2_inode));
inode.i_mode = LINUX_S_IFLNK | 0777;
inode.i_uid = inode.i_gid = 0;
- ext2fs_iblk_set(fs, &inode, fastlink ? 0 : 1);
inode.i_links_count = 1;
ext2fs_inode_size_set(fs, &inode, target_len);
/* The time fields are set by ext2fs_write_new_inode() */
+ inlinelink = !fastlink &&
+ (fs->super->s_feature_incompat &
+ EXT4_FEATURE_INCOMPAT_INLINE_DATA) &&
+ (target_len < fs->blocksize);
if (fastlink) {
/* Fast symlinks, target stored in inode */
strcpy((char *)&inode.i_block, target);
+ } else if (inlinelink) {
+ /* Try inserting an inline data symlink */
+ inode.i_flags |= EXT4_INLINE_DATA_FL;
+ retval = ext2fs_write_new_inode(fs, ino, &inode);
+ if (retval)
+ goto cleanup;
+ retval = ext2fs_inline_data_set(fs, ino, &inode, target,
+ target_len);
+ if (retval) {
+ inode.i_flags &= ~EXT4_INLINE_DATA_FL;
+ inlinelink = 0;
+ goto need_block;
+ }
+ retval = ext2fs_read_inode(fs, ino, &inode);
+ if (retval)
+ goto cleanup;
} else {
+need_block:
+ ext2fs_iblk_set(fs, &inode, 1);
/* Slow symlinks, target stored in the first block */
memset(block_buf, 0, fs->blocksize);
strcpy(block_buf, target);
@@ -104,11 +125,14 @@ errcode_t ext2fs_symlink(ext2_filsys fs, ext2_ino_t parent, ext2_ino_t ino,
* number is assigned by write_new_inode, which means that the
* operations using ino must come after it.
*/
- retval = ext2fs_write_new_inode(fs, ino, &inode);
+ if (inlinelink)
+ retval = ext2fs_write_inode(fs, ino, &inode);
+ else
+ retval = ext2fs_write_new_inode(fs, ino, &inode);
if (retval)
goto cleanup;
- if (!fastlink) {
+ if (!fastlink && !inlinelink) {
retval = ext2fs_bmap2(fs, ino, &inode, NULL, BMAP_SET, 0, NULL,
&blk);
if (retval)
@@ -139,7 +163,7 @@ errcode_t ext2fs_symlink(ext2_filsys fs, ext2_ino_t parent, ext2_ino_t ino,
/*
* Update accounting....
*/
- if (!fastlink)
+ if (!fastlink && !inlinelink)
ext2fs_block_alloc_stats2(fs, blk, +1);
ext2fs_inode_alloc_stats2(fs, ino, +1, 0);
diff --git a/tests/f_create_symlinks/expect b/tests/f_create_symlinks/expect
new file mode 100644
index 0000000..847e092
--- /dev/null
+++ b/tests/f_create_symlinks/expect
@@ -0,0 +1,36 @@
+mke2fs -q -F -o Linux -b 1024 -g 256 -O inline_data,extents -I 256 test.img 1024
+Pass 1: Checking inodes, blocks, and sizes
+Pass 2: Checking directory structure
+Pass 3: Checking directory connectivity
+Pass 4: Checking reference counts
+Pass 5: Checking group summary information
+test_filesys: 11/128 files (0.0% non-contiguous), 441/1024 blocks
+Exit status is 0
+stat /l_30
+Inode: 12 Type: symlink Mode: 0777 Flags: 0x0
+User: 0 Group: 0 Size: 31
+Links: 1 Blockcount: 0
+Fragment: Address: 0 Number: 0 Size: 0
+Fast link dest: "/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
+stat /l_70
+Inode: 13 Type: symlink Mode: 0777 Flags: 0x10000000
+User: 0 Group: 0 Size: 71
+Links: 1 Blockcount: 0
+Fragment: Address: 0 Number: 0 Size: 0
+Extended attributes:
+ system.data (11)
+Fast link dest: "/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
+stat /l_500
+Inode: 14 Type: symlink Mode: 0777 Flags: 0x80000
+User: 0 Group: 0 Size: 501
+Links: 1 Blockcount: 2
+Fragment: Address: 0 Number: 0 Size: 0
+stat /l_1500
+/l_1500: File not found by ext2_lookup
+Pass 1: Checking inodes, blocks, and sizes
+Pass 2: Checking directory structure
+Pass 3: Checking directory connectivity
+Pass 4: Checking reference counts
+Pass 5: Checking group summary information
+test_filesys: 14/128 files (0.0% non-contiguous), 442/1024 blocks
+Exit status is 0
diff --git a/tests/f_create_symlinks/name b/tests/f_create_symlinks/name
new file mode 100644
index 0000000..0930e79
--- /dev/null
+++ b/tests/f_create_symlinks/name
@@ -0,0 +1 @@
+create fast, inlinedata, and regular symlinks
diff --git a/tests/f_create_symlinks/script b/tests/f_create_symlinks/script
new file mode 100644
index 0000000..c49825a
--- /dev/null
+++ b/tests/f_create_symlinks/script
@@ -0,0 +1,59 @@
+if test -x $DEBUGFS_EXE; then
+
+FSCK_OPT=-yf
+OUT=$test_name.log
+if [ -f $test_dir/expect.gz ]; then
+ EXP=$test_name.tmp
+ gunzip < $test_dir/expect.gz > $EXP1
+else
+ EXP=$test_dir/expect
+fi
+
+cp /dev/null $OUT
+
+dd if=/dev/zero of=$TMPFILE bs=1k count=512 > /dev/null 2>&1
+
+echo mke2fs -q -F -o Linux -b 1024 -g 256 -O inline_data,extents -I 256 test.img 1024 >> $OUT
+$MKE2FS -q -F -o Linux -b 1024 -g 256 -O inline_data,extents -I 256 $TMPFILE 1024 2>&1 |
+ sed -f $cmd_dir/filter.sed -e "s;$TMPFILE;test.img;" >> $OUT
+
+$FSCK $FSCK_OPT -N test_filesys $TMPFILE > $OUT.new 2>&1
+status=$?
+echo Exit status is $status >> $OUT.new
+sed -f $cmd_dir/filter.sed -e "s;$TMPFILE;test.img;" $OUT.new >> $OUT
+rm -f $OUT.new
+
+for i in 30 70 500 1500; do
+ echo "symlink /l_$i /$(perl -e "print 'x' x $i;")"
+done | $DEBUGFS -w $TMPFILE >/dev/null 2>&1
+
+for i in 30 70 500 1500; do
+ echo "stat /l_$i" >> $OUT
+ $DEBUGFS -R "stat /l_$i" $TMPFILE 2>&1 | egrep '(File not found|^Inode|^Fast link dest|Blockcount:|^Extended attributes:|system.data|Size:)' >> $OUT
+done
+
+$FSCK $FSCK_OPT -N test_filesys $TMPFILE > $OUT.new 2>&1
+status=$?
+echo Exit status is $status >> $OUT.new
+sed -f $cmd_dir/filter.sed -e "s;$TMPFILE;test.img;" $OUT.new >> $OUT
+rm -f $OUT.new
+
+rm -f $TMPFILE
+
+cmp -s $OUT $EXP
+status=$?
+
+if [ "$status" = 0 ] ; then
+ echo "$test_name: $test_description: ok"
+ touch $test_name.ok
+else
+ echo "$test_name: $test_description: failed"
+ diff $DIFF_OPTS $EXP $OUT > $test_name.failed
+ rm -f $test_name.tmp
+fi
+
+unset IMAGE FSCK_OPT OUT EXP
+
+else #if test -a -x $DEBUGFS_EXE; then
+ echo "$test_name: $test_description: skipped"
+fi
next prev parent reply other threads:[~2014-08-16 23:46 UTC|newest]
Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-08-16 23:45 [PATCH 00/27] e2fsprogs Summer 2014 patchbomb, part 5.1 Darrick J. Wong
2014-08-16 23:45 ` [PATCH 01/27] e2fuzz: fix pwrite64/pwrite usage Darrick J. Wong
2014-08-24 23:56 ` Theodore Ts'o
2014-08-16 23:46 ` [PATCH 02/27] misc: fix gcc warnings Darrick J. Wong
2014-08-24 23:56 ` Theodore Ts'o
2014-08-16 23:46 ` [PATCH 03/27] libext2fs: byteswap inode when performing the sanity scan Darrick J. Wong
2014-08-25 2:01 ` Theodore Ts'o
2014-08-16 23:46 ` [PATCH 04/27] libext2fs: fix problems with LE<->BE conversions on BE platforms Darrick J. Wong
2014-08-25 2:01 ` Theodore Ts'o
2014-08-16 23:46 ` [PATCH 05/27] e2fsck: on BE, re-swap everything after a damaged dirent so salvage works correctly Darrick J. Wong
2014-08-25 2:03 ` Theodore Ts'o
2014-08-16 23:46 ` Darrick J. Wong [this message]
2014-08-25 2:05 ` [PATCH 06/27] libext2fs: create inlinedata symlinks Theodore Ts'o
2014-08-16 23:46 ` [PATCH 07/27] contrib: add script to help resync journal code with kernel Darrick J. Wong
2014-08-27 3:44 ` Theodore Ts'o
2014-08-16 23:46 ` [PATCH 08/27] e2fsck: resync jbd2 recovery code from Linux 3.16 Darrick J. Wong
2014-08-27 3:44 ` Theodore Ts'o
2014-08-16 23:46 ` [PATCH 09/27] e2fsck: resync jbd2 revoke " Darrick J. Wong
2014-08-27 3:44 ` Theodore Ts'o
2014-08-16 23:46 ` [PATCH 10/27] e2fsck: fix infinite loop when recovering corrupt journal blocks Darrick J. Wong
2014-08-27 3:45 ` Theodore Ts'o
2014-08-16 23:47 ` [PATCH 11/27] e2fsck/debugfs: fix descriptor block size handling errors with journal_csum Darrick J. Wong
2014-08-28 1:15 ` Theodore Ts'o
2014-08-28 1:33 ` Darrick J. Wong
2014-08-16 23:47 ` [PATCH 12/27] debugfs: create journal handling routines Darrick J. Wong
2014-08-16 23:47 ` [PATCH 13/27] e2fsck: set journal superblock s_sequence to tail_sequence Darrick J. Wong
2014-08-16 23:47 ` [PATCH 14/27] debugfs: add the ability to write transactions to the journal Darrick J. Wong
2014-09-06 5:52 ` Darrick J. Wong
2014-08-16 23:47 ` [PATCH 15/27] tests: test writing and recovering checksum-free 32/64bit journals Darrick J. Wong
2014-08-16 23:47 ` [PATCH 16/27] tests: test writing and recovering 64bit csum_v3 journals Darrick J. Wong
2014-08-16 23:47 ` [PATCH 17/27] tests: test writing and recovering 32bit " Darrick J. Wong
2014-08-16 23:47 ` [PATCH 18/27] tests: write and replay blocks with the old journal checksum Darrick J. Wong
2014-08-16 23:47 ` [PATCH 19/27] tests: test recovery of 32 and 64-bit journals with checksum v2 Darrick J. Wong
2014-08-16 23:48 ` [PATCH 20/27] tests: test how e2fsck recovers from corrupt journal superblocks Darrick J. Wong
2014-08-16 23:48 ` [PATCH 21/27] tests: test e2fsck recovery of corrupt revoke blocks Darrick J. Wong
2014-08-16 23:48 ` [PATCH 22/27] tests: test e2fsck recovery with broken commit blocks Darrick J. Wong
2014-08-16 23:48 ` [PATCH 23/27] tests: test e2fsck recovery of corrupt descriptor blocks Darrick J. Wong
2014-08-16 23:48 ` [PATCH 24/27] mke2fs: set block_validity as a default mount option Darrick J. Wong
2014-08-16 23:48 ` [PATCH 25/27] ext2fs: add readahead method to improve scanning Darrick J. Wong
2014-08-16 23:48 ` [PATCH 26/27] libext2fs/e2fsck: provide routines to read-ahead metadata Darrick J. Wong
2014-08-16 23:48 ` [PATCH 27/27] e2fsck: read-ahead metadata during passes 1, 2, and 4 Darrick J. Wong
2014-08-17 17:23 ` [PATCH 28/27] libext2fs: write_journal_inode should check iterate return value Darrick J. Wong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20140816234629.11171.85990.stgit@birch.djwong.org \
--to=darrick.wong@oracle.com \
--cc=houpu.hp@alibaba-inc.com \
--cc=linux-ext4@vger.kernel.org \
--cc=tytso@mit.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).