Skip to content

Commit

Permalink
- detect fake partitions on FBA DASDs (bnc#786164)
Browse files Browse the repository at this point in the history
  • Loading branch information
aschnell committed Feb 15, 2013
1 parent 9214b01 commit 420d77e
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 8 deletions.
2 changes: 1 addition & 1 deletion VERSION
@@ -1 +1 @@
2.17.127.3
2.17.127.4
57 changes: 50 additions & 7 deletions libstorage/src/Disk.cc
Expand Up @@ -53,7 +53,7 @@ namespace storage
unsigned long long SizeK, SystemInfo& systeminfo)
: Container(s, name, device, staticType(), systeminfo),
init_disk(false), transport(TUNKNOWN), dmp_slave(false), no_addpart(false),
gpt_enlarge(false), del_ptable(false)
gpt_enlarge(false), del_ptable(false), has_fake_partition(false)
{
logfile_name = boost::replace_all_copy(nm, "/", "_");
getMajorMinor();
Expand All @@ -71,7 +71,7 @@ namespace storage
unsigned long long SizeK, SystemInfo& systeminfo)
: Container(s, name, device, staticType(), systeminfo),
init_disk(false), transport(TUNKNOWN), dmp_slave(false), no_addpart(false),
gpt_enlarge(false), del_ptable(false)
gpt_enlarge(false), del_ptable(false), has_fake_partition(false)
{
y2mil("constructed Disk name:" << name << " nr " << num << " sizeK:" << SizeK);
logfile_name = name + decString(num);
Expand All @@ -85,7 +85,7 @@ namespace storage
: Container(s, staticType(), node), label(), udev_path(),
udev_id(), max_primary(0), ext_possible(false), max_logical(0),
init_disk(false), transport(TUNKNOWN), dmp_slave(false), no_addpart(false),
gpt_enlarge(false), range(4), del_ptable(false)
gpt_enlarge(false), range(4), del_ptable(false), has_fake_partition(false)
{
logfile_name = nm;

Expand Down Expand Up @@ -115,7 +115,7 @@ namespace storage
init_disk(c.init_disk), transport(c.transport),
dmp_slave(c.dmp_slave), no_addpart(c.no_addpart),
gpt_enlarge(c.gpt_enlarge), range(c.range),
del_ptable(c.del_ptable)
del_ptable(c.del_ptable), has_fake_partition(c.has_fake_partition)
{
y2deb("copy-constructed Disk " << dev);

Expand Down Expand Up @@ -182,6 +182,18 @@ Disk::sysfsPath( const string& device )
}


Region
Disk::detectSysfsBlkRegion(bool log_error) const
{
string size_p = sysfsPath() + "/size";

unsigned long long len = 0;
read_sysfs_property(size_p, len, log_error);

return Region(0, len);
}


void
Disk::triggerUdevUpdate() const
{
Expand Down Expand Up @@ -485,6 +497,9 @@ bool
y2mil("nm:" << nm);
if (!dmp_slave && !checkPartedValid(systeminfo, pl, range_exceed))
{
ronly = true;
has_fake_partition = checkFakePartition(systeminfo, pl);

Text txt = sformat(
// popup text %1$s is replaced by disk name e.g. /dev/hda
_("The partitioning on disk %1$s is not readable by\n"
Expand All @@ -496,8 +511,8 @@ _("The partitioning on disk %1$s is not readable by\n"
"cannot add, edit, resize, or remove partitions from that\n"
"disk with this tool."), dev.c_str() );

getStorage()->addInfoPopupText( dev, txt );
ronly = true;
if (!has_fake_partition)
getStorage()->addInfoPopupText( dev, txt );
}
if( range_exceed>0 )
{
Expand Down Expand Up @@ -570,7 +585,7 @@ Disk::checkPartitionsValid(SystemInfo& systeminfo, const list<Partition*>& pl) c
}
}

// But if parted sees no disk the kernel must also see no disks.
// But if parted sees no partitions the kernel must also see no partitions.

if (pl.empty())
{
Expand All @@ -588,6 +603,30 @@ Disk::checkPartitionsValid(SystemInfo& systeminfo, const list<Partition*>& pl) c
}


bool
Disk::checkFakePartition(SystemInfo& systeminfo, const list<Partition*>& pl) const
{
// For FBA DASDs without an partition table the kernel generates a fake
// partition spanning almost the whole disk.

if (isDasd() && detected_label.empty() && pl.size() == 1 && pl.front()->nr() == 1)
{
Region disk_region = detectSysfsBlkRegion();
Region part_region = pl.front()->detectSysfsBlkRegion();

y2mil("disk:" << disk_region << " part:" << part_region);

if (disk_region.end() == part_region.end() && part_region.start() == 2)
{
y2mil("found fake partition on " << device());
return true;
}
}

return false;
}


bool
Disk::checkPartedValid(SystemInfo& systeminfo, list<Partition*>& pl,
unsigned long& range_exceed) const
Expand Down Expand Up @@ -2448,6 +2487,8 @@ std::ostream& operator<< (std::ostream& s, const Disk& d )
s << " GptEnlarge";
if (d.del_ptable)
s << " delPT";
if (d.has_fake_partition)
s << " has_fake_partition";
return( s );
}

Expand All @@ -2471,6 +2512,8 @@ std::ostream& operator<< (std::ostream& s, const Disk& d )
logDiffEnum(log, "transport", transport, rhs.transport);

logDiff(log, "del_ptable", del_ptable, rhs.del_ptable);

logDiff(log, "has_fake_partition", has_fake_partition, rhs.has_fake_partition);
}


Expand Down
5 changes: 5 additions & 0 deletions libstorage/src/Disk.h
Expand Up @@ -93,6 +93,9 @@ class Disk : public Container
virtual string sysfsPath() const;
static string sysfsPath( const string& device );

/* disk region from sysfs in 512 byte blocks */
Region detectSysfsBlkRegion(bool log_error = true) const;

unsigned numPartitions() const;
bool isDasd() const { return( nm.find("dasd")==0 ); }
bool isIScsi() const { return transport == ISCSI; }
Expand Down Expand Up @@ -240,6 +243,7 @@ class Disk : public Container
bool checkPartedValid(SystemInfo& systeminfo, list<Partition*>& pl,
unsigned long& rng) const;
virtual bool checkPartitionsValid(SystemInfo& systeminfo, const list<Partition*>& pl) const;
bool checkFakePartition(SystemInfo& systeminfo, const list<Partition*>& pl) const;

bool callDelpart(unsigned nr) const;
bool callAddpart(unsigned nr, const Region& blkRegion) const;
Expand Down Expand Up @@ -296,6 +300,7 @@ class Disk : public Container
bool gpt_enlarge;
unsigned long range;
bool del_ptable;
bool has_fake_partition;

mutable storage::DiskInfo info; // workaround for broken ycp bindings

Expand Down
6 changes: 6 additions & 0 deletions package/yast2-storage.changes
@@ -1,3 +1,9 @@
-------------------------------------------------------------------
Fri Feb 15 10:00:20 CET 2013 - aschnell@suse.de

- detect fake partitions on FBA DASDs (bnc#786164)
- 2.17.127.4

-------------------------------------------------------------------
Wed Jan 09 14:24:39 CET 2013 - aschnell@suse.de

Expand Down

0 comments on commit 420d77e

Please sign in to comment.