Whamcloud - gitweb
mke2fs: Use unix_discard() for discards
authorLukas Czerner <lczerner@redhat.com>
Thu, 18 Nov 2010 03:38:40 +0000 (03:38 +0000)
committerTheodore Ts'o <tytso@mit.edu>
Tue, 23 Nov 2010 02:14:28 +0000 (21:14 -0500)
There is generic discard function in struct_io_manager, or in
unix_io_manager to be specific. So use this instead of
mke2fs_discard_blocks().

Since mke2fs_discard_blocks() is not used anymore (and should not be)
remove it.

Signed-off-by: Lukas Czerner <lczerner@redhat.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
misc/mke2fs.c

index 0c30339..bc1211d 100644 (file)
@@ -1922,48 +1922,6 @@ static int mke2fs_setup_tdb(const char *name, io_manager *io_ptr)
        return retval;
 }
 
-#ifdef __linux__
-
-#ifndef BLKDISCARD
-#define BLKDISCARD     _IO(0x12,119)
-#endif
-
-/*
- * Return zero if the discard succeeds, and -1 if the discard fails.
- */
-static int mke2fs_discard_blocks(ext2_filsys fs)
-{
-       int fd;
-       int ret;
-       int blocksize;
-       __u64 blocks;
-       __uint64_t range[2];
-
-       blocks = ext2fs_blocks_count(fs->super);
-       blocksize = EXT2_BLOCK_SIZE(fs->super);
-       range[0] = 0;
-       range[1] = blocks * blocksize;
-
-       fd = open64(fs->device_name, O_RDWR);
-
-       if (fd > 0) {
-               ret = ioctl(fd, BLKDISCARD, &range);
-               if (verbose) {
-                       printf(_("Calling BLKDISCARD from %llu to %llu "),
-                              (unsigned long long) range[0],
-                              (unsigned long long) range[1]);
-                       if (ret)
-                               printf(_("failed.\n"));
-                       else
-                               printf(_("succeeded.\n"));
-               }
-               close(fd);
-       }
-       return ret;
-}
-
-#endif
-
 int main (int argc, char *argv[])
 {
        errcode_t       retval = 0;
@@ -2024,7 +1982,18 @@ int main (int argc, char *argv[])
 
        /* Can't undo discard ... */
        if (discard && (io_ptr != undo_io_manager)) {
-               retval = mke2fs_discard_blocks(fs);
+               blk64_t blocks = ext2fs_blocks_count(fs->super);
+               if (verbose)
+                       printf(_("Calling BLKDISCARD from 0 to %llu... "),
+                              (unsigned long long) blocks);
+               retval = io_channel_discard(fs->io, 0, blocks, fs->blocksize);
+               if (verbose) {
+                       if (retval)
+                               printf(_("failed (%s)\n"),
+                                      error_message(retval));
+                       else
+                               printf(_("succeeded\n"));
+               }
 
                if (!retval && io_channel_discard_zeroes_data(fs->io)) {
                        if (verbose)