Report busy status of jbds (#89)
Continuing from the state in the previous commit, create an ext4 file system using the previously created external journal and mount it. # mke2fs -t ext4 -J device=/dev/sdb1 -L test-ext4 /dev/sdb2 # mount /dev/sdb2 /mnt/2 Did some experimenting with trying to create a second file system using the same external journal which is already in use. # mke2fs -t ext4 -J device=/dev/sdb1 -L 2nd-test-ext4 /dev/sdb3 ... /dev/sdb1 is apparently in use by the system; will not make a journal here! # exit $? 1 Examined the source code of mke2fs and found that it performs an exclusive read-only open of the named journal block device to check if it is in use by the system or not [1]. Use the same method in GParted. Not used alternative method would be to mark the jbd active when the ext3/4 file system using it is active, but that requires working out the linkage between them. That can be done using either blkid or dumpe2fs output but that involves parsing more fields and caching more data so is much more code than just testing the block device busy status using the same method which mke2fs uses. Matching UUIDs via blkid output. # blkid /dev/sdb1 /dev/sdb2 /dev/sdb1: LABEL="test-jbd" UUID="6e52858e-0479-432f-80a1-de42f9a4093e" TYPE="jbd" /dev/sdb2: LABEL="test-ext4" UUID="cea5c2cd-b21c-4abf-a497-8c073bb12300" EXT_JOURNAL="6e52858e-0479-432f-80a1-de42f9a4093e" TYPE="ext4" Matching UUIDs via dumpe2fs output. # dumpe2fs -h /dev/sdb1 | egrep 'Filesystem UUID|Journal users' dumpe2fs 1.46.3 (27-Jul-2021) Filesystem UUID: 6e52858e-0479-432f-80a1-de42f9a4093e Journal users: cea5c2cd-b21c-4abf-a497-8c073bb12300 # dumpe2fs -h /dev/sdb2 | egrep 'Filesystem UUID|Journal UUID' dumpe2fs 1.46.3 (27-Jul-2021) Filesystem UUID: cea5c2cd-b21c-4abf-a497-8c073bb12300 Journal UUID: 6e52858e-0479-432f-80a1-de42f9a4093e If GParted was going to show the journal to file system linkage in the UI then doing this would be needed. However so far there has only been a single reported case of a GParted user using an external journal, therefore adding the code complexity for this feature is not currently justified. The simple busy detection method used by mke2fs is all that is needed. [1] mke2fs source code https://git.kernel.org/pub/scm/fs/ext2/e2fsprogs.git/ misc/mke2fs.c:main() check_mount(journal_device, force, _("journal")); misc/util.c:check_mount() ext2fs_check_if_mounted(device, &mount_flags); lib/ext2fs/ismounted.c:ext2fs_check_if_mounted() ext2fs_check_mount_point(file, mount_flags, NULL, 0); lib/ext2fs/ismounted.c:ext2fs_check_if_mounted() if (stat(device, &st_buf) == 0 && ext2fsP_is_disk_device(st_buf.st_mode)) { int fd = open(device, O_RDONLY | O_EXCL); if (fd >= 0) { /* * The device is not busy so it's * definitelly not mounted. No need to * to perform any more checks. */ close(fd); *mount_flags = 0; return 0; } else if (errno == EBUSY) { busy = 1; } } Closes #89 - GParted doesn't recognise EXT4 fs journal partition
This commit is contained in:
parent
157d4e7470
commit
1950a7a09d
|
@ -183,6 +183,7 @@ public:
|
|||
static int get_mounted_filesystem_usage( const Glib::ustring & mountpoint,
|
||||
Byte_Value & fs_size, Byte_Value & fs_free,
|
||||
Glib::ustring & error_message ) ;
|
||||
static bool is_dev_busy(const Glib::ustring& path);
|
||||
static Byte_Value floor_size( Byte_Value value, Byte_Value rounding_size ) ;
|
||||
static Byte_Value ceil_size( Byte_Value value, Byte_Value rounding_size ) ;
|
||||
|
||||
|
|
|
@ -341,7 +341,8 @@ void Dialog_Partition_Info::Display_Info()
|
|||
filesystem_ptn.fstype == FS_LINUX_SWRAID ||
|
||||
filesystem_ptn.fstype == FS_ATARAID ||
|
||||
filesystem_ptn.fstype == FS_LVM2_PV ||
|
||||
filesystem_ptn.fstype == FS_BCACHE )
|
||||
filesystem_ptn.fstype == FS_BCACHE ||
|
||||
filesystem_ptn.fstype == FS_JBD )
|
||||
{
|
||||
/* TO TRANSLATORS: Active
|
||||
* means that this linux swap, linux software raid partition, or
|
||||
|
@ -376,7 +377,8 @@ void Dialog_Partition_Info::Display_Info()
|
|||
else if (filesystem_ptn.fstype == FS_LINUX_SWAP ||
|
||||
filesystem_ptn.fstype == FS_LINUX_SWRAID ||
|
||||
filesystem_ptn.fstype == FS_ATARAID ||
|
||||
filesystem_ptn.fstype == FS_BCACHE )
|
||||
filesystem_ptn.fstype == FS_BCACHE ||
|
||||
filesystem_ptn.fstype == FS_JBD )
|
||||
{
|
||||
/* TO TRANSLATORS: Not active
|
||||
* means that this linux swap or linux software raid partition
|
||||
|
|
|
@ -1607,6 +1607,7 @@ bool GParted_Core::is_busy(const Glib::ustring& device_path, FSType fstype, cons
|
|||
busy |= (fstype == FS_ATARAID && (SWRaid_Info::is_member_active(partition_path) ||
|
||||
dmraid.is_member_active(partition_path) ));
|
||||
busy |= (fstype == FS_BCACHE && BCache_Info::is_active(device_path, partition_path));
|
||||
busy |= (fstype == FS_JBD && Utils::is_dev_busy(partition_path));
|
||||
}
|
||||
|
||||
return busy ;
|
||||
|
|
14
src/Utils.cc
14
src/Utils.cc
|
@ -929,6 +929,20 @@ int Utils::get_mounted_filesystem_usage( const Glib::ustring & mountpoint,
|
|||
return ret ;
|
||||
}
|
||||
|
||||
|
||||
// Report whether the kernel considers the device busy or not.
|
||||
bool Utils::is_dev_busy(const Glib::ustring& path)
|
||||
{
|
||||
int fd = open(path.c_str(), O_RDONLY|O_EXCL);
|
||||
if (fd == -1 && errno == EBUSY)
|
||||
return true;
|
||||
else if (fd >= 0)
|
||||
close(fd);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
//Round down to multiple of rounding_size
|
||||
Byte_Value Utils::floor_size( Byte_Value value, Byte_Value rounding_size )
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue