3
votes

As per

struct ext4_inode {
  .....
  __le16  i_extra_isize;
  .....
}

I see that this can be used to store extended attributes, given the fact that I am using the inode size = 256 bytes. Few questions:

  1. How do I know if my FS inode size is 256 or 128 bytes?
  2. How do I set the small extended attributes (<10 bytes) and get it stored in the extra region? (Reason: Performance matters), as I believe there will be not extra IO block read as its contiguous. What's the Fileystem/C lib call for that? Will the typical System call "setattr" do this? I have been setting using command line "setfattr" and not being sure if its goind to extra area allocated after inode 128 bytes.
  3. Whats the in-memory structure for mapping the extra bytes after 128 bytes of inode, the place where I want to store my small extended attributes.
1

1 Answers

2
votes

How do I know if my FS inode size is 256 or 128 bytes ?

$ sudo tune2fs -l /dev/sda2  | egrep -i 'inode size'
Inode size:               256

How do I set the small extended attributes

Ext3/4 supports configurable inode sizes (from the -I option mkfs.ext{3,4} cmd parameter), but the default inode size is 128 bytes. Ext4 will default to 256 bytes. This is needed to accommodate some extra fields (like nanosecond timestamps or inode versioning), and the remaining space of the inode will be used to store extend attributes that are small enough to fit it that space. Also you may want to look into the function implemented fs/ext4/file.c:struct inode_operations{.setattr,.getattr}.

What's the Fileystem/C lib call for that?

Refer API's setxattr(), lsetxattr(), fsetxattr() for setting the extended attributes programmatic. Use commands attr, lsattr, chattr for testing the extended attributes on the set files. Also you may want to look into

Whats the in-memory structure for mapping the extra bytes after 128 bytes of inode, the place where I want to store my small extended attributes.

Refer fs/ext4/xattr.c

"

* Extended attributes are stored directly in inodes (on file systems with
 18  * inodes bigger than 128 bytes) and on additional disk blocks. The i_file_acl
 19  * field contains the block number if an inode uses an additional block. All
 20  * attributes must fit in the inode and one additional block. Blocks that
 21  * contain the identical set of attributes may be shared among several inodes.
 22  * Identical blocks are detected by keeping a cache of blocks that have
 23  * recently been accessed.
 24  *
 25  * The attributes in inodes and on blocks have a different header; the entries
 26  * are stored in the same format:
 27  *
 28  *   +------------------+
 29  *   | header           |
 30  *   | entry 1          | |
 31  *   | entry 2          | | growing downwards
 32  *   | entry 3          | v
 33  *   | four null bytes  |
 34  *   | . . .            |
 35  *   | value 1          | ^
 36  *   | value 3          | | growing upwards
 37  *   | value 2          | |
 38  *   +------------------+
 39  *
 40  * The header is followed by multiple entry descriptors. In disk blocks, the
 41  * entry descriptors are kept sorted. In inodes, they are unsorted. The
 42  * attribute values are aligned to the end of the block in no specific order.

"