Re: [PATCH v2 12/28] debugfs: make expand command support inline data

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Dec 03, 2013 at 01:19:54PM -0800, Darrick J. Wong wrote:
[...]
> > +errcode_t ext2fs_inline_data_expand(ext2_filsys fs, ext2_ino_t ino)
> 
> I couldn't tell from the name that this function only expands inline
> directories.  A name like ext2fs_inline_dir_expand() would make that more
> immediately clear; initially I thought this could be a method that also expands
> files.

Your initially thought is right.  This function will expand a directory
or a file.  In this commit, it just handles directory because it is only
used by ext2fs_expand_dir().  Later commit will let it handle a file.
Sorry, I don't clarify this.

> 
> > +{
> > +	struct ext2_inode inode;
> > +	struct ext2_inline_data data;
> > +	errcode_t retval;
> > +	blk64_t blk;
> > +	char *inline_buf = 0;
> > +	char *blk_buf = 0;
> > +
> > +	EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS);
> > +
> > +	retval = ext2fs_read_inode(fs, ino, &inode);
> > +	if (retval)
> > +		return retval;
> > +
> > +	if (!(inode.i_flags & EXT4_INLINE_DATA_FL))
> > +		return EXT2_ET_NO_INLINE_DATA;
> > +
> > +	/* Get inline data first */
> > +	data.fs = fs;
> > +	data.ino = ino;
> > +	retval = ext2fs_inline_data_ea_get(&data);
> > +	if (retval)
> > +		return retval;
> > +	retval = ext2fs_get_mem(EXT4_MIN_INLINE_DATA_SIZE + data.ea_size,
> > +				&inline_buf);
> > +	if (retval)
> > +		goto errout;
> > +
> > +	memcpy(inline_buf, (void *)inode.i_block, EXT4_MIN_INLINE_DATA_SIZE);
> > +	if (data.ea_size > 0) {
> > +		memcpy(inline_buf + EXT4_MIN_INLINE_DATA_SIZE,
> > +		       data.ea_data, data.ea_size);
> > +	}
> > +
> > +	memset((void *)inode.i_block, 0, EXT4_MIN_INLINE_DATA_SIZE);
> > +	retval = ext2fs_inline_data_ea_remove(fs, ino);
> > +	if (retval)
> > +		goto errout;
> > +
> > +	retval = ext2fs_get_mem(fs->blocksize, &blk_buf);
> > +	if (retval)
> > +		goto errout;
> > +
> > +	/* Adjust the rec_len */
> > +	retval = ext2fs_inline_data_convert_dir(fs, ino, blk_buf, inline_buf,
> > +						EXT4_MIN_INLINE_DATA_SIZE +
> > +							data.ea_size);
> > +	if (retval)
> > +		goto errout;
> > +
> > +	/* Allocate a new block */
> > +	retval = ext2fs_new_block2(fs, 0, 0, &blk);
> > +	if (retval)
> > +		goto errout;
> > +	if (EXT2_HAS_INCOMPAT_FEATURE(fs->super, EXT3_FEATURE_INCOMPAT_EXTENTS))
> > +		inode.i_flags |= EXT4_EXTENTS_FL;
> > +	else
> > +		inode.i_block[0] = blk;
> > +	inode.i_flags &= ~EXT4_INLINE_DATA_FL;
> > +	ext2fs_iblk_set(fs, &inode, 1);
> > +	inode.i_size = fs->blocksize;
> > +	retval = ext2fs_write_inode(fs, ino, &inode);
> > +	if (retval)
> > +		goto errout;
> > +	retval = ext2fs_write_dir_block4(fs, blk, blk_buf, 0, ino);
> > +	if (retval)
> > +		goto errout;
> > +	if (EXT2_HAS_INCOMPAT_FEATURE(fs->super, EXT3_FEATURE_INCOMPAT_EXTENTS)) {
> > +		ext2_extent_handle_t handle;
> > +
> > +		retval = ext2fs_extent_open2(fs, ino, &inode, &handle);
> > +		if (retval)
> > +			goto errout;
> > +		retval = ext2fs_extent_set_bmap(handle, 0, blk, 0);
> > +		ext2fs_extent_free(handle);
> > +	}
> 
> Would it be simpler to call ext2fs_bmap2() with bmap_flags = BMAP_SET here?
> Then you wouldn't need to open code the blockmap and extent setting cases.
> Then all you have to do is:
> 
> if (fs_has_extents)
> 	inode.i_flags |= EXT4_EXTENTS_FL;
> ext2fs_bmap2(fs, ino, &inode, NULL, BMAP_SET, 0, NULL, &blk);
> ext2fs_write_inode(...);

Yes, I remember that you have advised me to use this function in first
version.  I will fix it.

Thanks,
                                                - Zheng
--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Reiser Filesystem Development]     [Ceph FS]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Linux FS]     [Yosemite National Park]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Device Mapper]     [Linux Media]

  Powered by Linux