Report busy status of bcache (#183)
Make (format as) bcache backing device (-B) and cache device (-C) and implicitly attach the backing device to the cache to enable caching, all in one. # bcache make -B /dev/sdb1 -C /dev/sdc1 # bcache show Name Type State Bname AttachToDev /dev/sdb1 1 (data) clean(running) bcache0 /dev/sdc1 /dev/sdc1 3 (cache) active N/A N/A After experimenting with 'bcache unregister', 'bcache register' and stracing 'bcache show' the bcache kernel module creates the sysfs directory /sys/block/DEV[/PTN]/bcache and it's contents only when the bcache device is registered with the kernel (bcache component is active). Use this to identify whether any bcache device (component) should be displayed as active or not in GParted. # ls -ld /sys/block/sd?/sd?1/bcache drwxr-xr-x. 6 root root 0 Jan 7 10:08 /sys/block/sdb/sdb1/bcache drwxr-xr-x. 2 root root 0 Jan 7 10:08 /sys/block/sdc/sdc1/bcache Closes #183 - Basic support for bcache
This commit is contained in:
parent
f1920e306b
commit
5d86c616a8
|
@ -0,0 +1,44 @@
|
||||||
|
/* Copyright (C) 2022 Mike Fleetwood
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/* BCache_Info
|
||||||
|
*
|
||||||
|
* Simple module to query very basic information about bcache devices
|
||||||
|
* (components). No caching is performed by this module.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef GPARTED_BCACHE_INFO_H
|
||||||
|
#define GPARTED_BCACHE_INFO_H
|
||||||
|
|
||||||
|
|
||||||
|
#include <glibmm/ustring.h>
|
||||||
|
|
||||||
|
|
||||||
|
namespace GParted
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
class BCache_Info
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static bool is_active(const Glib::ustring& device_path, const Glib::ustring& partition_path);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
} //GParted
|
||||||
|
|
||||||
|
#endif /* GPARTED_BCACHE_INFO_H */
|
|
@ -1,6 +1,7 @@
|
||||||
gparted_includedir = $(pkgincludedir)
|
gparted_includedir = $(pkgincludedir)
|
||||||
|
|
||||||
EXTRA_DIST = \
|
EXTRA_DIST = \
|
||||||
|
BCache_Info.h \
|
||||||
BlockSpecial.h \
|
BlockSpecial.h \
|
||||||
CopyBlocks.h \
|
CopyBlocks.h \
|
||||||
DMRaid.h \
|
DMRaid.h \
|
||||||
|
|
|
@ -4,6 +4,7 @@ gparted.appdata.xml.in
|
||||||
gparted.desktop.in.in
|
gparted.desktop.in.in
|
||||||
org.gnome.gparted.policy.in.in
|
org.gnome.gparted.policy.in.in
|
||||||
include/Utils.h
|
include/Utils.h
|
||||||
|
src/BCache_Info.cc
|
||||||
src/BlockSpecial.cc
|
src/BlockSpecial.cc
|
||||||
src/CopyBlocks.cc
|
src/CopyBlocks.cc
|
||||||
src/DialogPasswordEntry.cc
|
src/DialogPasswordEntry.cc
|
||||||
|
|
|
@ -0,0 +1,51 @@
|
||||||
|
/* Copyright (C) 2022 Mike Fleetwood
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "BCache_Info.h"
|
||||||
|
|
||||||
|
#include <glibmm/ustring.h>
|
||||||
|
#include <glibmm/fileutils.h>
|
||||||
|
|
||||||
|
|
||||||
|
namespace GParted
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
// Return true if this device or partition contains an active bcache component, false
|
||||||
|
// otherwise. Equivalent to does the directory /sys/block/DEV[/PTN]/bcache exist?
|
||||||
|
bool BCache_Info::is_active(const Glib::ustring& device_path, const Glib::ustring& partition_path)
|
||||||
|
{
|
||||||
|
Glib::ustring bcache_path;
|
||||||
|
Glib::ustring dev_name = device_path.substr(5); // Remove leading "/dev/".
|
||||||
|
|
||||||
|
if (device_path == partition_path)
|
||||||
|
{
|
||||||
|
// Whole drive
|
||||||
|
bcache_path = "/sys/block/" + dev_name + "/bcache";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Partition on drive
|
||||||
|
Glib::ustring ptn_name = partition_path.substr(5); // Remove leading "/dev/".
|
||||||
|
bcache_path = "/sys/block/" + dev_name + "/" + ptn_name + "/bcache";
|
||||||
|
}
|
||||||
|
|
||||||
|
return file_test(bcache_path, Glib::FILE_TEST_IS_DIR);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} //GParted
|
|
@ -340,7 +340,8 @@ void Dialog_Partition_Info::Display_Info()
|
||||||
else if (filesystem_ptn.fstype == FS_LINUX_SWAP ||
|
else if (filesystem_ptn.fstype == FS_LINUX_SWAP ||
|
||||||
filesystem_ptn.fstype == FS_LINUX_SWRAID ||
|
filesystem_ptn.fstype == FS_LINUX_SWRAID ||
|
||||||
filesystem_ptn.fstype == FS_ATARAID ||
|
filesystem_ptn.fstype == FS_ATARAID ||
|
||||||
filesystem_ptn.fstype == FS_LVM2_PV )
|
filesystem_ptn.fstype == FS_LVM2_PV ||
|
||||||
|
filesystem_ptn.fstype == FS_BCACHE )
|
||||||
{
|
{
|
||||||
/* TO TRANSLATORS: Active
|
/* TO TRANSLATORS: Active
|
||||||
* means that this linux swap, linux software raid partition, or
|
* means that this linux swap, linux software raid partition, or
|
||||||
|
@ -374,7 +375,8 @@ void Dialog_Partition_Info::Display_Info()
|
||||||
}
|
}
|
||||||
else if (filesystem_ptn.fstype == FS_LINUX_SWAP ||
|
else if (filesystem_ptn.fstype == FS_LINUX_SWAP ||
|
||||||
filesystem_ptn.fstype == FS_LINUX_SWRAID ||
|
filesystem_ptn.fstype == FS_LINUX_SWRAID ||
|
||||||
filesystem_ptn.fstype == FS_ATARAID )
|
filesystem_ptn.fstype == FS_ATARAID ||
|
||||||
|
filesystem_ptn.fstype == FS_BCACHE )
|
||||||
{
|
{
|
||||||
/* TO TRANSLATORS: Not active
|
/* TO TRANSLATORS: Not active
|
||||||
* means that this linux swap or linux software raid partition
|
* means that this linux swap or linux software raid partition
|
||||||
|
|
|
@ -15,9 +15,11 @@
|
||||||
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "GParted_Core.h"
|
#include "GParted_Core.h"
|
||||||
#include "CopyBlocks.h"
|
#include "BCache_Info.h"
|
||||||
#include "BlockSpecial.h"
|
#include "BlockSpecial.h"
|
||||||
|
#include "CopyBlocks.h"
|
||||||
#include "Device.h"
|
#include "Device.h"
|
||||||
#include "DMRaid.h"
|
#include "DMRaid.h"
|
||||||
#include "FileSystem.h"
|
#include "FileSystem.h"
|
||||||
|
@ -1595,6 +1597,7 @@ bool GParted_Core::is_busy(const Glib::ustring& device_path, FSType fstype, cons
|
||||||
busy |= (fstype == FS_LINUX_SWRAID && SWRaid_Info::is_member_active(partition_path));
|
busy |= (fstype == FS_LINUX_SWRAID && SWRaid_Info::is_member_active(partition_path));
|
||||||
busy |= (fstype == FS_ATARAID && (SWRaid_Info::is_member_active(partition_path) ||
|
busy |= (fstype == FS_ATARAID && (SWRaid_Info::is_member_active(partition_path) ||
|
||||||
dmraid.is_member_active(partition_path) ));
|
dmraid.is_member_active(partition_path) ));
|
||||||
|
busy |= (fstype == FS_BCACHE && BCache_Info::is_active(device_path, partition_path));
|
||||||
}
|
}
|
||||||
|
|
||||||
return busy ;
|
return busy ;
|
||||||
|
|
|
@ -11,6 +11,7 @@ AM_CXXFLAGS = -Wall
|
||||||
libexec_PROGRAMS = gpartedbin
|
libexec_PROGRAMS = gpartedbin
|
||||||
|
|
||||||
gpartedbin_SOURCES = \
|
gpartedbin_SOURCES = \
|
||||||
|
BCache_Info.cc \
|
||||||
BlockSpecial.cc \
|
BlockSpecial.cc \
|
||||||
CopyBlocks.cc \
|
CopyBlocks.cc \
|
||||||
DMRaid.cc \
|
DMRaid.cc \
|
||||||
|
|
|
@ -24,6 +24,7 @@ test_dummy_SOURCES = test_dummy.cc
|
||||||
|
|
||||||
test_SupportedFileSystems_SOURCES = test_SupportedFileSystems.cc
|
test_SupportedFileSystems_SOURCES = test_SupportedFileSystems.cc
|
||||||
test_SupportedFileSystems_LDADD = \
|
test_SupportedFileSystems_LDADD = \
|
||||||
|
$(top_builddir)/src/BCache_Info.$(OBJEXT) \
|
||||||
$(top_builddir)/src/BlockSpecial.$(OBJEXT) \
|
$(top_builddir)/src/BlockSpecial.$(OBJEXT) \
|
||||||
$(top_builddir)/src/CopyBlocks.$(OBJEXT) \
|
$(top_builddir)/src/CopyBlocks.$(OBJEXT) \
|
||||||
$(top_builddir)/src/DMRaid.$(OBJEXT) \
|
$(top_builddir)/src/DMRaid.$(OBJEXT) \
|
||||||
|
|
Loading…
Reference in New Issue