Whamcloud - gitweb
po: update cs.po (from translationproject.org)
[tools/e2fsprogs.git] / resize / online.c
index f4d24ce..1a77839 100644 (file)
@@ -9,6 +9,7 @@
  * %End-Header%
  */
 
+#include "config.h"
 #include "resize2fs.h"
 #ifdef HAVE_SYS_IOCTL_H
 #include <sys/ioctl.h>
 
 extern char *program_name;
 
+#define MAX_32_NUM ((((unsigned long long) 1) << 32) - 1)
+
 errcode_t online_resize_fs(ext2_filsys fs, const char *mtpt,
-                          blk_t *new_size, int flags EXT2FS_ATTR((unused)))
+                          blk64_t *new_size, int flags EXT2FS_ATTR((unused)))
 {
 #ifdef __linux__
        struct ext2_new_group_input input;
@@ -37,9 +40,8 @@ errcode_t online_resize_fs(ext2_filsys fs, const char *mtpt,
        printf(_("Filesystem at %s is mounted on %s; "
                 "on-line resizing required\n"), fs->device_name, mtpt);
 
-       if (*new_size < sb->s_blocks_count) {
-               printf(_("On-line shrinking from %u to %u not supported.\n"),
-                      sb->s_blocks_count, *new_size);
+       if (*new_size < ext2fs_blocks_count(sb)) {
+               com_err(program_name, 0, _("On-line shrinking not supported"));
                exit(1);
        }
 
@@ -48,11 +50,11 @@ errcode_t online_resize_fs(ext2_filsys fs, const char *mtpt,
         * the on-line resizing inode must be present.
         */
        new_desc_blocks = ext2fs_div_ceil(
-               ext2fs_div_ceil(*new_size -
-                               fs->super->s_first_data_block,
-                               EXT2_BLOCKS_PER_GROUP(fs->super)),
+               ext2fs_div64_ceil(*new_size -
+                                 fs->super->s_first_data_block,
+                                 EXT2_BLOCKS_PER_GROUP(fs->super)),
                EXT2_DESC_PER_BLOCK(fs->super));
-       printf("old desc_blocks = %lu, new_desc_blocks = %lu\n",
+       printf("old_desc_blocks = %lu, new_desc_blocks = %lu\n",
               fs->desc_blocks, new_desc_blocks);
        if (!(fs->super->s_feature_compat &
              EXT2_FEATURE_COMPAT_RESIZE_INODE) &&
@@ -69,7 +71,36 @@ errcode_t online_resize_fs(ext2_filsys fs, const char *mtpt,
                exit(1);
        }
 
-       size=sb->s_blocks_count;
+       if (ioctl(fd, EXT4_IOC_RESIZE_FS, new_size)) {
+               /*
+                * If kernel does not support EXT4_IOC_RESIZE_FS, use the
+                * old online resize. Note that the old approach does not
+                * handle >32 bit file systems
+                */
+               if (errno != ENOTTY) {
+                       if (errno == EPERM)
+                               com_err(program_name, 0,
+                               _("Permission denied to resize filesystem"));
+                       else
+                               com_err(program_name, errno,
+                               _("While checking for on-line resizing "
+                                 "support"));
+                       exit(1);
+               }
+       } else {
+               close(fd);
+               return 0;
+       }
+
+       if ((ext2fs_blocks_count(sb) > MAX_32_NUM) ||
+           (*new_size > MAX_32_NUM)) {
+               com_err(program_name, 0,
+                       _("Kernel does not support resizing a file system "
+                         "this large"));
+               exit(1);
+       }
+       size = ext2fs_blocks_count(sb);
+
        if (ioctl(fd, EXT2_IOC_GROUP_EXTEND, &size)) {
                if (errno == EPERM)
                        com_err(program_name, 0,
@@ -83,7 +114,8 @@ errcode_t online_resize_fs(ext2_filsys fs, const char *mtpt,
                exit(1);
        }
 
-       percent = (sb->s_r_blocks_count * 100.0) / sb->s_blocks_count;
+       percent = (ext2fs_r_blocks_count(sb) * 100.0) /
+               ext2fs_blocks_count(sb);
 
        retval = ext2fs_read_bitmaps(fs);
        if (retval)
@@ -93,11 +125,22 @@ errcode_t online_resize_fs(ext2_filsys fs, const char *mtpt,
        if (retval)
                return retval;
 
-       retval = adjust_fs_info(new_fs, fs, *new_size);
+       /* The current method of adding one block group at a time to a
+        * mounted filesystem means it is impossible to accomodate the
+        * flex_bg allocation method of placing the metadata together
+        * in a single block group.  For now we "fix" this issue by
+        * using the traditional layout for new block groups, where
+        * each block group is self-contained and contains its own
+        * bitmap blocks and inode tables.  This means we don't get
+        * the layout advantages of flex_bg in the new block groups,
+        * but at least it allows on-line resizing to function.
+        */
+       new_fs->super->s_feature_incompat &= ~EXT4_FEATURE_INCOMPAT_FLEX_BG;
+       retval = adjust_fs_info(new_fs, fs, 0, *new_size);
        if (retval)
                return retval;
 
-       printf(_("Performing an on-line resize of %s to %u (%dk) blocks.\n"),
+       printf(_("Performing an on-line resize of %s to %llu (%dk) blocks.\n"),
               fs->device_name, *new_size, fs->blocksize / 1024);
 
        size = fs->group_desc_count * sb->s_blocks_per_group +
@@ -121,15 +164,10 @@ errcode_t online_resize_fs(ext2_filsys fs, const char *mtpt,
                                new_fs->super->s_reserved_gdt_blocks;
 
                input.group = i;
-               input.block_bitmap = new_fs->group_desc[i].bg_block_bitmap;
-               input.inode_bitmap = new_fs->group_desc[i].bg_inode_bitmap;
-               input.inode_table = new_fs->group_desc[i].bg_inode_table;
-               input.blocks_count = sb->s_blocks_per_group;
-               if (i == new_fs->group_desc_count-1) {
-                       input.blocks_count = new_fs->super->s_blocks_count -
-                               sb->s_first_data_block -
-                               (i * sb->s_blocks_per_group);
-               }
+               input.block_bitmap = ext2fs_block_bitmap_loc(new_fs, i);
+               input.inode_bitmap = ext2fs_inode_bitmap_loc(new_fs, i);
+               input.inode_table = ext2fs_inode_table_loc(new_fs, i);
+               input.blocks_count = ext2fs_group_blocks_count(new_fs, i);
                input.reserved_blocks = (blk_t) (percent * input.blocks_count
                                                 / 100.0);
 
@@ -143,9 +181,9 @@ errcode_t online_resize_fs(ext2_filsys fs, const char *mtpt,
                printf("new group will reserve %d blocks\n",
                       input.reserved_blocks);
                printf("new group has %d free blocks\n",
-                      new_fs->group_desc[i].bg_free_blocks_count);
+                      ext2fs_bg_free_blocks_count(new_fs, i),
                printf("new group has %d free inodes (%d blocks)\n",
-                      new_fs->group_desc[i].bg_free_inodes_count,
+                      ext2fs_bg_free_inodes_count(new_fs, i),
                       new_fs->inode_blocks_per_group);
                printf("Adding group #%d\n", input.group);
 #endif
@@ -154,7 +192,7 @@ errcode_t online_resize_fs(ext2_filsys fs, const char *mtpt,
                    ioctl(fd, EXT2_IOC_GROUP_ADD, &input) == 0)
                        continue;
                else
-                       use_old_ioctl = 1;
+                       use_old_ioctl = 0;
 
                input64.group = input.group;
                input64.block_bitmap = input.block_bitmap;