Whamcloud - gitweb
resize2fs: add debugging code to test the old online resizing interfaces
authorTheodore Ts'o <tytso@mit.edu>
Sat, 12 Jan 2013 22:33:44 +0000 (17:33 -0500)
committerTheodore Ts'o <tytso@mit.edu>
Mon, 14 Jan 2013 21:53:50 +0000 (16:53 -0500)
The old online resize ioctl interfaces are still present in the
kernel, and we want to make it easy to test both the kernel code for
those older interfaces, and resize2fs's use of those interfaces in a
relatively easy manner.

To do this, resize2fs will now check the environment variable
RESIZE2FS_KERNEL_VERSION.  If the version given is less than 3.3, then
do not try using the new resizing ioctl, but instead use the resizing
ioctls that were used before Linux version 3.3.

If the version given is less than 3.7, then emulate sanity checks
which get done to protect against the fact that the new resizing ioctl
prior to 3.7 did not handle meta_bg resizing.  (This was previously
tested via the presence of the RESIZE2FS_NO_META_BG_RESIZE environment
variable.  But the new environment variable, RESIZE2FS_KERNEL_VERISON,
is more general.)

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
Reviewed-by: Carlos Maiolino <cmaiolino@redhat.com>
resize/online.c

index d3d3546..2d34640 100644 (file)
@@ -21,6 +21,33 @@ extern char *program_name;
 
 #define MAX_32_NUM ((((unsigned long long) 1) << 32) - 1)
 
+#ifdef __linux__
+static int parse_version_number(const char *s)
+{
+       int     major, minor, rev;
+       char    *endptr;
+       const char *cp = s;
+
+       if (!s)
+               return 0;
+       major = strtol(cp, &endptr, 10);
+       if (cp == endptr || *endptr != '.')
+               return 0;
+       cp = endptr + 1;
+       minor = strtol(cp, &endptr, 10);
+       if (cp == endptr || *endptr != '.')
+               return 0;
+       cp = endptr + 1;
+       rev = strtol(cp, &endptr, 10);
+       if (cp == endptr)
+               return 0;
+       return ((((major * 256) + minor) * 256) + rev);
+}
+
+#define VERSION_CODE(a,b,c) (((a) << 16) + ((b) << 8) + (c))
+
+#endif
+
 errcode_t online_resize_fs(ext2_filsys fs, const char *mtpt,
                           blk64_t *new_size, int flags EXT2FS_ATTR((unused)))
 {
@@ -36,6 +63,18 @@ errcode_t online_resize_fs(ext2_filsys fs, const char *mtpt,
        blk_t                   size;
        int                     fd, overhead;
        int                     use_old_ioctl = 1;
+       int                     no_meta_bg_resize = 0;
+       int                     no_resize_ioctl = 0;
+
+       if (getenv("RESIZE2FS_KERNEL_VERSION")) {
+               char *version_to_emulate = getenv("RESIZE2FS_KERNEL_VERSION");
+               int kvers = parse_version_number(version_to_emulate);
+
+               if (kvers < VERSION_CODE(3, 7, 0))
+                       no_meta_bg_resize = 1;
+               if (kvers < VERSION_CODE(3, 3, 0))
+                       no_resize_ioctl = 1;
+       }
 
        printf(_("Filesystem at %s is mounted on %s; "
                 "on-line resizing required\n"), fs->device_name, mtpt);
@@ -61,7 +100,7 @@ errcode_t online_resize_fs(ext2_filsys fs, const char *mtpt,
         * Do error checking to make sure the resize will be successful.
         */
        if ((access("/sys/fs/ext4/features/meta_bg_resize", R_OK) != 0) ||
-           getenv("RESIZE2FS_NO_META_BG_RESIZE")) {
+           no_meta_bg_resize) {
                if (!EXT2_HAS_COMPAT_FEATURE(fs->super,
                                        EXT2_FEATURE_COMPAT_RESIZE_INODE) &&
                    (new_desc_blocks != fs->desc_blocks)) {
@@ -94,7 +133,9 @@ errcode_t online_resize_fs(ext2_filsys fs, const char *mtpt,
                exit(1);
        }
 
-       if (ioctl(fd, EXT4_IOC_RESIZE_FS, new_size)) {
+       if (no_resize_ioctl) {
+               printf(_("Old resize interface requested.\n"));
+       } else 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