+ if (blocks >= 0x1000000000 && is_e2fsprogs_feature_supp("-O meta_bg"))
+ append_unique(anchor, ",", "meta_bg", NULL, maxbuflen);
+
+ if (enable_64bit || strstr(mop->mo_mkfsopts, "meta_bg"))
+ append_unique(anchor, ",", "^resize_inode", NULL, maxbuflen);
+
+ /* Allow xattrs larger than one block, stored in a separate inode */
+ if (IS_MDT(&mop->mo_ldd) && is_e2fsprogs_feature_supp("-O ea_inode"))
+ append_unique(anchor, ",", "ea_inode", NULL, maxbuflen);
+
- if ((mop->mo_ldd.ldd_mount_type == LDD_MT_EXT3) ||
- (mop->mo_ldd.ldd_mount_type == LDD_MT_LDISKFS) ||
- (mop->mo_ldd.ldd_mount_type == LDD_MT_LDISKFS2)) {
- long inode_size = 0;
-
- /* Journal size in MB */
- if (strstr(mop->mo_mkfsopts, "-J") == NULL &&
- mop->mo_device_kb > 1024 * 1024) {
- /* Choose our own default journal size */
- long journal_mb = 0, max_mb;
-
- /* cap journal size at 4GB for MDT,
- * leave it at 400MB for OSTs. */
- if (IS_MDT(&mop->mo_ldd))
- max_mb = 4096;
- else if (IS_OST(&mop->mo_ldd))
- max_mb = 400;
- else /* Use mke2fs default size for MGS */
- max_mb = 0;
-
- /* Use at most 4% of device for journal */
- journal_mb = mop->mo_device_kb * 4 / (1024 * 100);
- if (journal_mb > max_mb)
- journal_mb = max_mb;
-
- if (journal_mb) {
- sprintf(buf, " -J size=%ld", journal_mb);
- strscat(mop->mo_mkfsopts, buf,
- sizeof(mop->mo_mkfsopts));
- }
+ return EINVAL;
+ }
+
+ /* Journal size in MB */
+ if (strstr(mop->mo_mkfsopts, "-J") == NULL &&
+ mop->mo_device_kb > 1024 * 1024) {
+ /* Choose our own default journal size */
+ long journal_mb = 0, max_mb;
+
+ /* cap journal size at 4GB for MDT, leave at 1GB for OSTs */
+ if (IS_MDT(&mop->mo_ldd))
+ max_mb = 4096;
+ else if (IS_OST(&mop->mo_ldd))
+ max_mb = 1024;
+ else /* Use mke2fs default size for MGS */
+ max_mb = 0;
+
+ /* Use at most 4% of device for journal */
+ journal_mb = mop->mo_device_kb * 4 / (1024 * 100);
+ if (journal_mb > max_mb)
+ journal_mb = max_mb;
+
+ if (journal_mb) {
+ snprintf(buf, sizeof(buf), " -J size=%ld", journal_mb);
+ strscat(mop->mo_mkfsopts, buf,
+ sizeof(mop->mo_mkfsopts));
- /*
- * The inode size is constituted by following elements
- * (assuming all files are in composite layout and has
- * 3 components):
- *
- * ldiskfs inode size: 160
- * MDT extended attributes size, including:
- * ext4_xattr_header: 32
- * LOV EA size: 32(lov_comp_md_v1) +
- * 3 * 40(lov_comp_md_entry_v1) +
- * 3 * 32(lov_mds_md) +
- * stripes * 24(lov_ost_data) +
- * 16(xattr_entry) + 4("lov")
- * LMA EA size: 24(lustre_mdt_attrs) +
- * 16(xattr_entry) + 4("lma")
- * SOM EA size: 24(lustre_som_attrs) +
- * 16(xattr_entry) + 4("som")
- * link EA size: 24(link_ea_header) + 18(link_ea_entry) +
- * 16(filename) + 16(xattr_entry) + 4("link")
- * and some margin for 4-byte alignment, ACLs and other EAs.
- *
- * If we say the average filename length is about 32 bytes,
- * the calculation looks like:
- * 160 + 32 + (32+3*(40+32)+24*stripes+20) + (24+20) + (24+20) +
- * (24+20) + (~42+16+20) + other <= 512*2^m, {m=0,1,2,3}
- */
- if (strstr(mop->mo_mkfsopts, "-I") == NULL) {
- if (IS_MDT(&mop->mo_ldd)) {
- if (mop->mo_stripe_count > 59)
- inode_size = 512; /* bz 7241 */
- /* see also "-i" below for EA blocks */
- else if (mop->mo_stripe_count > 16)
- inode_size = 2048;
- else
- inode_size = 1024;
- } else if (IS_OST(&mop->mo_ldd)) {
- /* We store MDS FID and necessary composite
- * layout information in the OST object EA:
- * ldiskfs inode size: 160
- * OST extended attributes size, including:
- * ext4_xattr_header: 32
- * LMA EA size: 24(lustre_mdt_attrs) +
- * 16(xattr_entry) + 4("lma")
- * FID EA size: 52(filter_fid) +
- * 16(xattr_entry) + 4("fid")
- * 160 + 32 + (24+20) + (52+20) = 308
- */
- inode_size = 512;
- }
+ /*
+ * The inode size is constituted by following elements
+ * (assuming all files are in composite layout and has
+ * 3 components):
+ *
+ * ldiskfs inode size: 160
+ * MDT extended attributes size, including:
+ * ext4_xattr_header: 32
+ * LOV EA size: 32(lov_comp_md_v1) +
+ * 3 * 40(lov_comp_md_entry_v1) +
+ * 3 * 32(lov_mds_md) +
+ * stripes * 24(lov_ost_data) +
+ * 16(xattr_entry) + 4("lov")
+ * LMA EA size: 24(lustre_mdt_attrs) +
+ * 16(xattr_entry) + 4("lma")
+ * SOM EA size: 24(lustre_som_attrs) +
+ * 16(xattr_entry) + 4("som")
+ * link EA size: 24(link_ea_header) + 18(link_ea_entry) +
+ * 16(filename) + 16(xattr_entry) + 4("link")
+ * and some margin for 4-byte alignment, ACLs and other EAs.
+ *
+ * If we say the average filename length is about 32 bytes,
+ * the calculation looks like:
+ * 160 + 32 + (32+3*(40+32)+24*stripes+20) + (24+20) + (24+20) +
+ * (24+20) + (~42+16+20) + other <= 512*2^m, {m=0,1,2,3}
+ */
+ if (strstr(mop->mo_mkfsopts, "-I") == NULL) {
+ if (IS_MDT(&mop->mo_ldd)) {
+ if (mop->mo_stripe_count > 59)
+ inode_size = 512; /* bz 7241 */
+ /* see also "-i" below for EA blocks */
+ else if (mop->mo_stripe_count > 16)
+ inode_size = 2048;
+ else
+ inode_size = 1024;
+ } else if (IS_OST(&mop->mo_ldd)) {
+ /* We store MDS FID and necessary composite
+ * layout information in the OST object EA:
+ * ldiskfs inode size: 160
+ * OST extended attributes size, including:
+ * ext4_xattr_header: 32
+ * LMA EA size: 24(lustre_mdt_attrs) +
+ * 16(xattr_entry) + 4("lma")
+ * FID EA size: 52(filter_fid) +
+ * 16(xattr_entry) + 4("fid")
+ * 160 + 32 + (24+20) + (52+20) = 308
+ */
+ inode_size = 512;
+ }
- /* Bytes_per_inode: disk size / num inodes */
- if (strstr(mop->mo_mkfsopts, "-i") == NULL &&
- strstr(mop->mo_mkfsopts, "-N") == NULL) {
- long bytes_per_inode = 0;
-
- /* Allocate more inodes on MDT devices. There is
- * no data stored on the MDT, and very little extra
- * metadata beyond the inode. It could go down as
- * low as 1024 bytes, but this is conservative.
- * Account for external EA blocks for wide striping. */
- if (IS_MDT(&mop->mo_ldd)) {
- bytes_per_inode = inode_size + 1536;
-
- if (mop->mo_stripe_count > 59) {
- int extra = mop->mo_stripe_count * 24;
- extra = ((extra - 1) | 4095) + 1;
- bytes_per_inode += extra;
- }
- }
+ /* Bytes_per_inode: disk size / num inodes */
+ if (strstr(mop->mo_mkfsopts, "-i") == NULL &&
+ strstr(mop->mo_mkfsopts, "-N") == NULL) {
+ long bytes_per_inode = 0;
- /* Allocate fewer inodes on large OST devices. Most
- * filesystems can be much more aggressive than even
- * this, but it is impossible to know in advance. */
- if (IS_OST(&mop->mo_ldd)) {
- /* OST > 16TB assume average file size 1MB */
- if (mop->mo_device_kb > (16ULL << 30))
- bytes_per_inode = 1024 * 1024;
- /* OST > 4TB assume average file size 512kB */
- else if (mop->mo_device_kb > (4ULL << 30))
- bytes_per_inode = 512 * 1024;
- /* OST > 1TB assume average file size 256kB */
- else if (mop->mo_device_kb > (1ULL << 30))
- bytes_per_inode = 256 * 1024;
- /* OST > 10GB assume average file size 64kB,
- * plus a bit so that inodes will fit into a
- * 256x flex_bg without overflowing */
- else if (mop->mo_device_kb > (10ULL << 20))
- bytes_per_inode = 69905;
- }
+ /* Allocate more inodes on MDT devices. There is
+ * no data stored on the MDT, and very little extra
+ * metadata beyond the inode. It could go down as
+ * low as 1024 bytes, but this is conservative.
+ * Account for external EA blocks for wide striping.
+ */
+ if (IS_MDT(&mop->mo_ldd)) {
+ bytes_per_inode = inode_size + 1536;
+
+ if (mop->mo_stripe_count > 59) {
+ int extra = mop->mo_stripe_count * 24;
- if (verbose < 2) {
- strscat(mop->mo_mkfsopts, " -q",
- sizeof(mop->mo_mkfsopts));
+ /* Allocate fewer inodes on large OST devices. Most
+ * filesystems can be much more aggressive than even
+ * this, but it is impossible to know in advance.
+ */
+ if (IS_OST(&mop->mo_ldd)) {
+ /* OST > 16TB assume average file size 1MB */
+ if (mop->mo_device_kb > (16ULL << 30))
+ bytes_per_inode = 1024 * 1024;
+ /* OST > 4TB assume average file size 512kB */
+ else if (mop->mo_device_kb > (4ULL << 30))
+ bytes_per_inode = 512 * 1024;
+ /* OST > 1TB assume average file size 256kB */
+ else if (mop->mo_device_kb > (1ULL << 30))
+ bytes_per_inode = 256 * 1024;
+ /* OST > 10GB assume average file size 64kB,
+ * plus a bit so that inodes will fit into a
+ * 256x flex_bg without overflowing.
+ */
+ else if (mop->mo_device_kb > (10ULL << 20))
+ bytes_per_inode = 69905;
- /* start handle -O mkfs options */
- if ((start = strstr(mop->mo_mkfsopts, "-O")) != NULL) {
- if (strstr(start + 2, "-O") != NULL) {
- fprintf(stderr,
- "%s: don't specify multiple -O options\n",
- progname);
- return EINVAL;
- }
- start = moveopts_to_end(start);
- maxbuflen = sizeof(mop->mo_mkfsopts) -
- (start - mop->mo_mkfsopts) - strlen(start);
- ret = enable_default_ext4_features(mop, start,
- maxbuflen, 1);
- } else {
- start = mop->mo_mkfsopts + strlen(mop->mo_mkfsopts),
- maxbuflen = sizeof(mop->mo_mkfsopts) -
- strlen(mop->mo_mkfsopts);
- ret = enable_default_ext4_features(mop, start,
- maxbuflen, 0);
+ if (bytes_per_inode > 0) {
+ snprintf(buf, sizeof(buf), " -i %ld", bytes_per_inode);
+ strscat(mop->mo_mkfsopts, buf,
+ sizeof(mop->mo_mkfsopts));
+ mop->mo_inode_size = bytes_per_inode;
- /* start handle -E mkfs options */
- if ((start = strstr(mop->mo_mkfsopts, "-E")) != NULL) {
- if (strstr(start + 2, "-E") != NULL) {
- fprintf(stderr,
- "%s: don't specify multiple -E options\n",
- progname);
- return EINVAL;
- }
- start = moveopts_to_end(start);
- maxbuflen = sizeof(mop->mo_mkfsopts) -
- (start - mop->mo_mkfsopts) - strlen(start);
- ext_opts = 1;
- } else {
- start = mop->mo_mkfsopts + strlen(mop->mo_mkfsopts);
- maxbuflen = sizeof(mop->mo_mkfsopts) -
- strlen(mop->mo_mkfsopts);
+ if (verbose < 2)
+ strscat(mop->mo_mkfsopts, " -q", sizeof(mop->mo_mkfsopts));
+
+ /* start handle -O mkfs options */
+ start = strstr(mop->mo_mkfsopts, "-O");
+ if (start) {
+ if (strstr(start + 2, "-O") != NULL) {
+ fprintf(stderr,
+ "%s: don't specify multiple -O options\n",
+ progname);
+ return EINVAL;
- /* In order to align the filesystem metadata on 1MB boundaries,
- * give a resize value that will reserve a power-of-two group
- * descriptor blocks, but leave one block for the superblock.
- * Only useful for filesystems with < 2^32 blocks due to resize
- * limitations. */
- if (strstr(mop->mo_mkfsopts, "meta_bg") == NULL &&
- IS_OST(&mop->mo_ldd) && mop->mo_device_kb > 100 * 1024 &&
- !have_64bit) {
- unsigned int group_blocks = mop->mo_blocksize_kb * 8192;
- unsigned int desc_per_block =
- mop->mo_blocksize_kb * 1024 / 32;
- unsigned int resize_blks;
-
- resize_blks = (1ULL<<32) - desc_per_block*group_blocks;
- snprintf(buf, sizeof(buf), "%u", resize_blks);
- append_unique(start, ext_opts ? "," : " -E ",
- "resize", buf, maxbuflen);
- ext_opts = 1;
+ /* start handle -E mkfs options */
+ start = strstr(mop->mo_mkfsopts, "-E");
+ if (start) {
+ if (strstr(start + 2, "-E") != NULL) {
+ fprintf(stderr,
+ "%s: don't specify multiple -E options\n",
+ progname);
+ return EINVAL;
- /* Avoid zeroing out the full journal - speeds up mkfs */
- if (is_e2fsprogs_feature_supp("-E lazy_journal_init") == 0)
- append_unique(start, ext_opts ? "," : " -E ",
- "lazy_journal_init", NULL, maxbuflen);
- /* end handle -E mkfs options */
+ /* In order to align the filesystem metadata on 1MB boundaries,
+ * give a resize value that will reserve a power-of-two group
+ * descriptor blocks, but leave one block for the superblock.
+ * Only useful for filesystems with < 2^32 blocks due to resize
+ * limitations.
+ */
+ if (!enable_64bit && strstr(mop->mo_mkfsopts, "meta_bg") == NULL &&
+ IS_OST(&mop->mo_ldd) && mop->mo_device_kb > 100 * 1024) {
+ unsigned int group_blocks = mop->mo_blocksize_kb * 8192;
+ unsigned int desc_per_block = mop->mo_blocksize_kb * 1024 / 32;
+ unsigned int resize_blks;
+
+ resize_blks = (1ULL<<32) - desc_per_block*group_blocks;
+ snprintf(buf, sizeof(buf), "%u", resize_blks);
+ append_unique(start, ext_opts ? "," : " -E ",
+ "resize", buf, maxbuflen);
+ ext_opts = 1;
+ }
- snprintf(mkfs_cmd, sizeof(mkfs_cmd),
- "%s -j -b %d -L %s ", MKE2FS,
- mop->mo_blocksize_kb * 1024, mop->mo_ldd.ldd_svname);
- } else {
- fprintf(stderr,"%s: unsupported fs type: %d (%s)\n",
- progname, mop->mo_ldd.ldd_mount_type,
- MT_STR(&mop->mo_ldd));
- return EINVAL;
- }
+ /* Allow reformat of full devices (as opposed to partitions).
+ * We already checked for mounted dev.
+ */
+ strscat(mop->mo_mkfsopts, " -F", sizeof(mop->mo_mkfsopts));
+
+ snprintf(mkfs_cmd, sizeof(mkfs_cmd), "%s -j -b %d -L %s ", MKE2FS,
+ mop->mo_blocksize_kb * 1024, mop->mo_ldd.ldd_svname);