Skip to content

Commit f2ada18

Browse files
yuwatabluca
authored andcommitted
blockdev-util: also check newer value of GENHD_FL_NO_PART flag
With torvalds/linux@430cc5d, the value of GENHD_FL_NO_PART, previously named as GENHD_FL_NO_PART_SCAN, is changed from 0x0200 to 0x0004. So, we need to check both flags. (cherry picked from commit f0c2668) (cherry picked from commit 49b0f0e) (cherry picked from commit 7f19a34) (cherry picked from commit d55fcd8)
1 parent c16acd9 commit f2ada18

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

src/shared/blockdev-util.c

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -410,8 +410,19 @@ int blockdev_partscan_enabled(int fd) {
410410
* is 1, which can be check with 'ext_range' sysfs attribute. Explicit flag ('GENHD_FL_NO_PART_SCAN')
411411
* can be obtained from 'capability' sysattr.
412412
*
413-
* With https://github.com/torvalds/linux/commit/1ebe2e5f9d68e94c524aba876f27b945669a7879 (v5.17), we
414-
* can check the flag from 'ext_range' sysfs attribute directly.
413+
* With https://github.com/torvalds/linux/commit/46e7eac647b34ed4106a8262f8bedbb90801fadd (v5.17),
414+
* the flag is renamed to GENHD_FL_NO_PART.
415+
*
416+
* With https://github.com/torvalds/linux/commit/1ebe2e5f9d68e94c524aba876f27b945669a7879 (v5.17),
417+
* we can check the flag from 'ext_range' sysfs attribute directly.
418+
*
419+
* With https://github.com/torvalds/linux/commit/430cc5d3ab4d0ba0bd011cfbb0035e46ba92920c (v5.17),
420+
* the value of GENHD_FL_NO_PART is changed from 0x0200 to 0x0004. 💣💣💣
421+
* Note, the new value was used by the GENHD_FL_MEDIA_CHANGE_NOTIFY flag, which was introduced by
422+
* 86ce18d7b7925bfd6b64c061828ca2a857ee83b8 (v2.6.22), and removed by
423+
* 9243c6f3e012a92dd900d97ef45efaf8a8edc448 (v5.7). If we believe the commit message of
424+
* e81cd5a983bb35dabd38ee472cf3fea1c63e0f23, the flag was never used. So, fortunately, we can use
425+
* both the new and old values safely.
415426
*
416427
* With https://github.com/torvalds/linux/commit/e81cd5a983bb35dabd38ee472cf3fea1c63e0f23 (v6.3),
417428
* the 'capability' sysfs attribute is deprecated, hence we cannot check the flag from it.
@@ -453,12 +464,10 @@ int blockdev_partscan_enabled(int fd) {
453464
if (r < 0)
454465
return r;
455466

456-
#ifndef GENHD_FL_NO_PART_SCAN
457-
#define GENHD_FL_NO_PART_SCAN (0x0200)
458-
#endif
459-
460-
/* If 0x200 is set, part scanning is definitely off. */
461-
if (FLAGS_SET(capability, GENHD_FL_NO_PART_SCAN))
467+
#define GENHD_FL_NO_PART_OLD 0x0200
468+
#define GENHD_FL_NO_PART_NEW 0x0004
469+
/* If one of the NO_PART flags is set, part scanning is definitely off. */
470+
if ((capability & (GENHD_FL_NO_PART_OLD | GENHD_FL_NO_PART_NEW)) != 0)
462471
return false;
463472

464473
/* Otherwise, assume part scanning is on, we have no further checks available. Assume the best. */

0 commit comments

Comments
 (0)