]> www.infradead.org Git - users/sagi/blktests.git/commitdiff
loop: update block size tests for new ioctl
authorOmar Sandoval <osandov@fb.com>
Thu, 7 Sep 2017 17:58:21 +0000 (10:58 -0700)
committerOmar Sandoval <osandov@fb.com>
Thu, 7 Sep 2017 17:58:21 +0000 (10:58 -0700)
Signed-off-by: Omar Sandoval <osandov@fb.com>
common/loop
src/loblksize.c
tests/loop/002
tests/loop/002.out
tests/loop/004

index eb8027c9c83dffd649f47e411196bc0831e90927..16cc3212a028516f6e10b2c00c1abd11b498911a 100644 (file)
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 
-_have_lo_flags_blocksize() {
-       local tmpfile loop_dev
-
-       # XXX: $TMPDIR isn't set up for requires(), should it be?
-       if ! tmpfile="$(mktemp "blktests.${TEST_NAME//\//.}.XXX")" ||
-          ! truncate -s 1M "$tmpfile"; then
-               SKIP_REASON="could not create temporary file"
-               return 1
-       fi
-
-       if ! loop_dev="$(losetup -f --show "$tmpfile" 2>/dev/null)"; then
-               SKIP_REASON="could not get loop device"
-               rm -f "$tmpfile"
+_have_loop_set_block_size() {
+       src/loblksize "$(losetup -f)" 512 &>/dev/null
+       if [[ $? -eq 2 ]]; then
+               SKIP_REASON="kernel does not support LOOP_SET_BLOCK_SIZE"
                return 1
        fi
-
-       if ! src/loblksize "$loop_dev" >/dev/null 2>&1; then
-               SKIP_REASON="kernel does not support LO_FLAGS_BLOCKSIZE"
-               losetup -d "$loop_dev"
-               rm -f "$tmpfile"
-               return 1
-       fi
-
-       losetup -d "$loop_dev"
-       rm -f "$tmpfile"
        return 0
 }
index 45d993942f8bfec4e39684943940c58a62189f6a..7d9ec556e3e113772ba1d6a92563f5933bef0cd1 100644 (file)
@@ -9,65 +9,42 @@
 #include <sys/types.h>
 #include <linux/loop.h>
 
-/* LO_FLAGS_BLOCKSIZE is an enum so we can't ifdef. */
-#define LO_FLAGS_BLOCKSIZE_ 32
-
-#ifndef LO_INFO_BLOCKSIZE
-#define LO_INFO_BLOCKSIZE(l) (l)->lo_init[0]
+#ifndef LOOP_SET_BLOCK_SIZE
+#define LOOP_SET_BLOCK_SIZE 0x4C09
 #endif
 
 int main(int argc, char **argv)
 {
-       struct loop_info64 lo;
        unsigned long long blksize;
        char *end;
        int fd = -1;
-       bool set = argc >= 3;
-       int status = EXIT_FAILURE;
 
-       if (argc != 2 && argc != 3) {
+       if (argc != 3) {
                fprintf(stderr, "usage: %s DEV [BLKSIZE]\n", argv[0]);
-               return EXIT_FAILURE;
+               return 1;
        }
 
-       if (set) {
-               errno = 0;
-               blksize = strtoull(argv[2], &end, 0);
-               if (errno || *end) {
-                       fprintf(stderr, "invalid block size\n");
-                       return EXIT_FAILURE;
-               }
+       errno = 0;
+       blksize = strtoull(argv[2], &end, 0);
+       if (errno || *end) {
+               fprintf(stderr, "invalid block size\n");
+               return 1;
        }
 
-       fd = open(argv[1], O_RDONLY);
+       fd = open(argv[1], O_RDWR);
        if (fd == -1) {
                perror("open");
-               return EXIT_FAILURE;
-       }
-
-       if (ioctl(fd, LOOP_GET_STATUS64, &lo) == -1) {
-               perror("LOOP_GET_STATUS64");
-               goto out;
+               return 1;
        }
 
-       if (!(lo.lo_flags & LO_FLAGS_BLOCKSIZE_)) {
-               fprintf(stderr, "LO_FLAGS_BLOCKSIZE not supported");
-               goto out;
-       }
+       if (ioctl(fd, LOOP_SET_BLOCK_SIZE, blksize) == -1) {
+               int status = errno == EINVAL ? 2 : 1;
 
-       if (set) {
-               lo.lo_flags |= LO_FLAGS_BLOCKSIZE_;
-               LO_INFO_BLOCKSIZE(&lo) = blksize;
-               if (ioctl(fd, LOOP_SET_STATUS64, &lo) == -1) {
-                       perror("LOOP_SET_STATUS64");
-                       goto out;
-               }
-       } else {
-               printf("%llu\n", LO_INFO_BLOCKSIZE(&lo));
+               perror("LOOP_SET_BLOCK_SIZE");
+               close(fd);
+               return status;
        }
 
-       status = EXIT_SUCCESS;
-out:
        close(fd);
-       return status;
+       return 0;
 }
index 8f03070ae5030d55ad0efcea45b5d22e9d371495..2a16dbac8bc7459ea7a07e9f5a939ebde1d15ab6 100755 (executable)
@@ -28,7 +28,7 @@ DESCRIPTION="try various loop device block sizes"
 QUICK=1
 
 requires() {
-       _have_program xfs_io && _have_src_program loblksize && _have_lo_flags_blocksize
+       _have_program xfs_io && _have_src_program loblksize && _have_loop_set_block_size
 }
 
 test() {
@@ -51,13 +51,10 @@ test() {
                                dd if="$loop_dev" bs="$blksize" count=1 iflag=direct status=none | sha256sum
                        fi
                fi
-               local loop_get_status="$(src/loblksize "$loop_dev")"
-               local logical_block_size="$(cat "$sysfs/queue/logical_block_size")"
-               local physical_block_size="$(cat "$sysfs/queue/physical_block_size")"
-               local minimum_io_size="$(cat "$sysfs/queue/minimum_io_size")"
-               echo "LOOP_GET_STATUS=$loop_get_status queue/logical_block_size=$logical_block_size queue/physical_block_size=$physical_block_size queue/minimum_io_size=$minimum_io_size"
+               cat "$sysfs/queue/logical_block_size"
        done
 
+       sync
        losetup -d "$loop_dev"
 
        echo "Test complete"
index 926347eb8895a08fd64e71327a2f68c38062dd9c..4c85620425a7f4c8cd1691b0dddd9fc555acbac0 100644 (file)
@@ -1,19 +1,19 @@
 Running loop/002
 Checking default block size
-LOOP_GET_STATUS=512 queue/logical_block_size=512 queue/physical_block_size=512 queue/minimum_io_size=512
+512
 Setting block size to 4096
 769bd186841c10e5b1106b55986206c0e87fc05a7f565fdee01b5abcaff6ae78  -
-LOOP_GET_STATUS=4096 queue/logical_block_size=4096 queue/physical_block_size=4096 queue/minimum_io_size=4096
+4096
 Setting block size to 2048
 0ca3bfdeda1ef5036bfa5dad078a9f15724e79cf296bd4388cf786bfaf4195d0  -
-LOOP_GET_STATUS=2048 queue/logical_block_size=2048 queue/physical_block_size=2048 queue/minimum_io_size=2048
+2048
 Setting block size to 1234
-LOOP_SET_STATUS64: Invalid argument
-LOOP_GET_STATUS=2048 queue/logical_block_size=2048 queue/physical_block_size=2048 queue/minimum_io_size=2048
+LOOP_SET_BLOCK_SIZE: Invalid argument
+2048
 Setting block size to 1024
 cfa35bcc2f57149955e5e4f666e1bda1318596e8b6306e9055087643beb9f190  -
-LOOP_GET_STATUS=1024 queue/logical_block_size=1024 queue/physical_block_size=1024 queue/minimum_io_size=1024
+1024
 Setting block size to 512
 58b991c23d339f9d25eccb315cf8ba9edb608bb60be3be6c73b03a4481dc7682  -
-LOOP_GET_STATUS=512 queue/logical_block_size=512 queue/physical_block_size=512 queue/minimum_io_size=512
+512
 Test complete
index c5c96e43d890bd3e446339756edb2355b6989bb9..8dcc85165db68fccd75ae860e02bd347b208e2eb 100755 (executable)
@@ -24,7 +24,7 @@ DESCRIPTION="combine loop direct I/O mode and a custom block size"
 QUICK=1
 
 requires() {
-       _have_program xfs_io && _have_scsi_debug && _have_src_program loblksize && _have_lo_flags_blocksize
+       _have_program xfs_io && _have_scsi_debug && _have_src_program loblksize && _have_loop_set_block_size
 }
 
 test() {