Skip to content

Commit 7f19a34

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)
1 parent 6426323 commit 7f19a34

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
@@ -380,8 +380,19 @@ int blockdev_partscan_enabled(int fd) {
380380
* is 1, which can be check with 'ext_range' sysfs attribute. Explicit flag ('GENHD_FL_NO_PART_SCAN')
381381
* can be obtained from 'capability' sysattr.
382382
*
383-
* With https://github.com/torvalds/linux/commit/1ebe2e5f9d68e94c524aba876f27b945669a7879 (v5.17), we
384-
* can check the flag from 'ext_range' sysfs attribute directly.
383+
* With https://github.com/torvalds/linux/commit/46e7eac647b34ed4106a8262f8bedbb90801fadd (v5.17),
384+
* the flag is renamed to GENHD_FL_NO_PART.
385+
*
386+
* With https://github.com/torvalds/linux/commit/1ebe2e5f9d68e94c524aba876f27b945669a7879 (v5.17),
387+
* we can check the flag from 'ext_range' sysfs attribute directly.
388+
*
389+
* With https://github.com/torvalds/linux/commit/430cc5d3ab4d0ba0bd011cfbb0035e46ba92920c (v5.17),
390+
* the value of GENHD_FL_NO_PART is changed from 0x0200 to 0x0004. 💣💣💣
391+
* Note, the new value was used by the GENHD_FL_MEDIA_CHANGE_NOTIFY flag, which was introduced by
392+
* 86ce18d7b7925bfd6b64c061828ca2a857ee83b8 (v2.6.22), and removed by
393+
* 9243c6f3e012a92dd900d97ef45efaf8a8edc448 (v5.7). If we believe the commit message of
394+
* e81cd5a983bb35dabd38ee472cf3fea1c63e0f23, the flag was never used. So, fortunately, we can use
395+
* both the new and old values safely.
385396
*
386397
* With https://github.com/torvalds/linux/commit/e81cd5a983bb35dabd38ee472cf3fea1c63e0f23 (v6.3),
387398
* the 'capability' sysfs attribute is deprecated, hence we cannot check the flag from it.
@@ -423,12 +434,10 @@ int blockdev_partscan_enabled(int fd) {
423434
if (r < 0)
424435
return r;
425436

426-
#ifndef GENHD_FL_NO_PART_SCAN
427-
#define GENHD_FL_NO_PART_SCAN (0x0200)
428-
#endif
429-
430-
/* If 0x200 is set, part scanning is definitely off. */
431-
if (FLAGS_SET(capability, GENHD_FL_NO_PART_SCAN))
437+
#define GENHD_FL_NO_PART_OLD 0x0200
438+
#define GENHD_FL_NO_PART_NEW 0x0004
439+
/* If one of the NO_PART flags is set, part scanning is definitely off. */
440+
if ((capability & (GENHD_FL_NO_PART_OLD | GENHD_FL_NO_PART_NEW)) != 0)
432441
return false;
433442

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

0 commit comments

Comments
 (0)