Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/plugins/loop.c
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,9 @@ gboolean bd_loop_setup_from_fd (gint fd, guint64 offset, guint64 size, gboolean
if (status != 0) {
g_set_error (&l_error, BD_LOOP_ERROR, BD_LOOP_ERROR_FAIL,
"Failed to set status for the %s device: %m", loop_device);
if (ioctl (loop_fd, LOOP_CLR_FD) < 0)
bd_utils_log_format (BD_UTILS_LOG_WARNING,
"Failed to clear the %s device: %m", loop_device);
g_free (loop_device);
close (loop_fd);
bd_utils_report_finished (progress_id, l_error->message);
Expand All @@ -391,6 +394,9 @@ gboolean bd_loop_setup_from_fd (gint fd, guint64 offset, guint64 size, gboolean
if (status != 0) {
g_set_error (&l_error, BD_LOOP_ERROR, BD_LOOP_ERROR_FAIL,
"Failed to set sector size for the %s device: %m", loop_device);
if (ioctl (loop_fd, LOOP_CLR_FD) < 0)
bd_utils_log_format (BD_UTILS_LOG_WARNING,
"Failed to clear the %s device: %m", loop_device);
g_free (loop_device);
close (loop_fd);
bd_utils_report_finished (progress_id, l_error->message);
Expand Down
12 changes: 12 additions & 0 deletions tests/loop_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import time
import unittest
import overrides_hack

Expand Down Expand Up @@ -142,6 +143,17 @@ def test_loop_setup_sector_size(self):
with open("/sys/block/%s/queue/logical_block_size" % self.loop, "r") as f:
self.assertEqual(f.read().strip(), "4096")

succ = BlockDev.loop_teardown(self.loop)
self.assertTrue(succ)

# invalid sector size -- setup should fail, make sure we also removed the loop device after
with self.assertRaisesRegex(GLib.GError, "Failed to set sector size"):
BlockDev.loop_setup(self.dev_file, sector_size=7)

time.sleep(2)
loop_name = BlockDev.loop_get_loop_name(self.dev_file)
self.assertIsNone(loop_name)


class LoopTestSetupPartprobe(LoopTestCase):
def test_loop_setup_partprobe(self):
Expand Down