* [PATCH] blockdev: Don't fail on missing start sector
@ 2020-05-31 23:35 Stanislav Brabec
2020-06-01 8:13 ` Karel Zak
2020-06-03 15:16 ` Karel Zak
0 siblings, 2 replies; 6+ messages in thread
From: Stanislav Brabec @ 2020-05-31 23:35 UTC (permalink / raw)
To: util-linux; +Cc: Martin Wilck
Device mapper devices don't provide start sector.
It causes "blockdev --report" error:
blockdev: /dev/dm-9: failed to read partition start from sysfs: No such
file or directory
There is no reliable way to detect a geometry in this case.
Report N/A instead.
Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
Cc: Martin Wilck <martin.wilck@suse.com>
---
disk-utils/blockdev.c | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/disk-utils/blockdev.c b/disk-utils/blockdev.c
index f1067c815..ab18cfa66 100644
--- a/disk-utils/blockdev.c
+++ b/disk-utils/blockdev.c
@@ -455,6 +455,7 @@ static void report_device(char *device, int quiet)
long ra;
unsigned long long bytes;
uint64_t start = 0;
+ char start_str[11] = "";
struct stat st;
fd = open(device, O_RDONLY | O_NONBLOCK);
@@ -476,19 +477,21 @@ static void report_device(char *device, int quiet)
disk != st.st_rdev) {
if (ul_path_read_u64(pc, &start, "start") != 0)
- err(EXIT_FAILURE,
- _("%s: failed to read partition start from sysfs"),
- device);
+ /* TRANSLATORS: Start sector not available. Max. 10
letters. */
+ sprintf(start_str, "%10s", _("N/A"));
}
ul_unref_path(pc);
}
+ if (start_str[0] == 0)
+ sprintf(start_str, "%10ju", start);
+
if (ioctl(fd, BLKROGET, &ro) == 0 &&
ioctl(fd, BLKRAGET, &ra) == 0 &&
ioctl(fd, BLKSSZGET, &ssz) == 0 &&
ioctl(fd, BLKBSZGET, &bsz) == 0 &&
blkdev_get_size(fd, &bytes) == 0) {
- printf("%s %5ld %5d %5d %10ju %15lld %s\n",
- ro ? "ro" : "rw", ra, ssz, bsz, start, bytes, device);
+ printf("%s %5ld %5d %5d %s %15lld %s\n",
+ ro ? "ro" : "rw", ra, ssz, bsz, start_str, bytes, device);
} else {
if (!quiet)
warnx(_("ioctl error on %s"), device);
--
2.25.1
--
Best Regards / S pozdravem,
Stanislav Brabec
software developer
---------------------------------------------------------------------
SUSE LINUX, s. r. o. e-mail: sbrabec@suse.com
Křižíkova 148/34 (Corso IIa) tel: +420 284 084 060
186 00 Praha 8-Karlín fax: +420 284 084 001
Czech Republic http://www.suse.cz/
PGP: 830B 40D5 9E05 35D8 5E27 6FA3 717C 209F A04F CD76
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] blockdev: Don't fail on missing start sector
2020-05-31 23:35 [PATCH] blockdev: Don't fail on missing start sector Stanislav Brabec
@ 2020-06-01 8:13 ` Karel Zak
2020-06-02 1:52 ` Stanislav Brabec
2020-06-03 15:16 ` Karel Zak
1 sibling, 1 reply; 6+ messages in thread
From: Karel Zak @ 2020-06-01 8:13 UTC (permalink / raw)
To: Stanislav Brabec; +Cc: util-linux, Martin Wilck
On Mon, Jun 01, 2020 at 01:35:44AM +0200, Stanislav Brabec wrote:
> Device mapper devices don't provide start sector.
for which type of the device/mapping? I'd like to reproduce this
issue.
> It causes "blockdev --report" error:
> blockdev: /dev/dm-9: failed to read partition start from sysfs: No such
> file or directory
>
> There is no reliable way to detect a geometry in this case.
> Report N/A instead.
I guess the "start" file missing in the sysfs/ in this case, right?
> if (ul_path_read_u64(pc, &start, "start") != 0)
> - err(EXIT_FAILURE,
> - _("%s: failed to read partition start from sysfs"),
> - device);
> + /* TRANSLATORS: Start sector not available. Max. 10
> letters. */
> + sprintf(start_str, "%10s", _("N/A"));
> }
> ul_unref_path(pc);
> }
> + if (start_str[0] == 0)
> + sprintf(start_str, "%10ju", start);
Maybe we ca use ul_path_read_buffer() rather than ul_path_read_u64() to keep
it as string and to avoid sprintf().
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] blockdev: Don't fail on missing start sector
2020-06-01 8:13 ` Karel Zak
@ 2020-06-02 1:52 ` Stanislav Brabec
0 siblings, 0 replies; 6+ messages in thread
From: Stanislav Brabec @ 2020-06-02 1:52 UTC (permalink / raw)
To: Karel Zak; +Cc: util-linux, Martin Wilck
Karel Zak wrote:
> On Mon, Jun 01, 2020 at 01:35:44AM +0200, Stanislav Brabec wrote:
>> Device mapper devices don't provide start sector.
> for which type of the device/mapping? I'd like to reproduce this
> issue.
kpartx-style partition on multipath.
>> It causes "blockdev --report" error:
>> blockdev: /dev/dm-9: failed to read partition start from sysfs: No such
>> file or directory
>>
>> There is no reliable way to detect a geometry in this case.
>> Report N/A instead.
> I guess the "start" file missing in the sysfs/ in this case, right?
Yes.
Actually, debugging shows:
sysfs_blkdev_get_wholedisk(): This function has a special code for
device mapper: If /sys/dev/block/{major}:{minor}/partition does not
exist, check for /sys/dev/block/{major}:{minor}/dm/uuid, parse the
result and attempt to check the structure. (Split by "-", check, whether
string starts by "part".) It starts with "part1" => Device mapper is
detected. => Partition is detected.
The code returns to report_device(), and because partition is detected,
it unconditionally attempts to read "start" file from
"/sys/dev/block/254:9". This fails.
>> if (ul_path_read_u64(pc, &start, "start") != 0)
>> - err(EXIT_FAILURE,
>> - _("%s: failed to read partition start from sysfs"),
>> - device);
>> + /* TRANSLATORS: Start sector not available. Max. 10
>> letters. */
>> + sprintf(start_str, "%10s", _("N/A"));
>> }
>> ul_unref_path(pc);
>> }
>> + if (start_str[0] == 0)
>> + sprintf(start_str, "%10ju", start);
>
> Maybe we ca use ul_path_read_buffer() rather than ul_path_read_u64() to keep
> it as string and to avoid sprintf().
This was in the original code, but your proposal makes a perfect sense.
%10ju is just a space padded original string.
--
Best Regards / S pozdravem,
Stanislav Brabec
software developer
---------------------------------------------------------------------
SUSE LINUX, s. r. o. e-mail: sbrabec@suse.com
Křižíkova 148/34 (Corso IIa) tel: +420 284 084 060
186 00 Praha 8-Karlín fax: +420 284 084 001
Czech Republic http://www.suse.cz/
PGP: 830B 40D5 9E05 35D8 5E27 6FA3 717C 209F A04F CD76
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] blockdev: Don't fail on missing start sector
2020-05-31 23:35 [PATCH] blockdev: Don't fail on missing start sector Stanislav Brabec
2020-06-01 8:13 ` Karel Zak
@ 2020-06-03 15:16 ` Karel Zak
2020-06-05 8:06 ` Karel Zak
1 sibling, 1 reply; 6+ messages in thread
From: Karel Zak @ 2020-06-03 15:16 UTC (permalink / raw)
To: Stanislav Brabec; +Cc: util-linux, Martin Wilck
On Mon, Jun 01, 2020 at 01:35:44AM +0200, Stanislav Brabec wrote:
> It causes "blockdev --report" error:
> blockdev: /dev/dm-9: failed to read partition start from sysfs: No such
> file or directory
Stanislav, can you re-send the patch by git-send-email or create PR on
git-hub? Please. It seems the patch is broken by your/my email client (or
so) :-(
Thanks!
Applying: blockdev: Don't fail on missing start sector
error: corrupt patch at line 10
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] blockdev: Don't fail on missing start sector
2020-06-03 15:16 ` Karel Zak
@ 2020-06-05 8:06 ` Karel Zak
2020-06-13 20:52 ` Stanislav Brabec
0 siblings, 1 reply; 6+ messages in thread
From: Karel Zak @ 2020-06-05 8:06 UTC (permalink / raw)
To: Stanislav Brabec; +Cc: util-linux, Martin Wilck
On Wed, Jun 03, 2020 at 05:16:26PM +0200, Karel Zak wrote:
> Stanislav, can you re-send the patch by git-send-email or create PR on
> git-hub? Please. It seems the patch is broken by your/my email client (or
> so) :-(
OK, applied manually. You don't need to resend it :-)
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] blockdev: Don't fail on missing start sector
2020-06-05 8:06 ` Karel Zak
@ 2020-06-13 20:52 ` Stanislav Brabec
0 siblings, 0 replies; 6+ messages in thread
From: Stanislav Brabec @ 2020-06-13 20:52 UTC (permalink / raw)
To: Karel Zak; +Cc: util-linux, Martin Wilck
Dne 05. 06. 20 v 10:06 Karel Zak napsal(a):
> On Wed, Jun 03, 2020 at 05:16:26PM +0200, Karel Zak wrote:
>> Stanislav, can you re-send the patch by git-send-email or create PR on
>> git-hub? Please. It seems the patch is broken by your/my email client (or
>> so) :-(
> OK, applied manually. You don't need to resend it :-)
>
> Karel
>
Thanks. I used a different instance of Thunderbird, and probably didn't
configure it for a proper patch work.
--
Best Regards / S pozdravem,
Stanislav Brabec
software developer
---------------------------------------------------------------------
SUSE LINUX, s. r. o. e-mail: sbrabec@suse.com
Křižíkova 148/34 (Corso IIa) tel: +420 284 084 060
186 00 Praha 8-Karlín fax: +420 284 084 001
Czech Republic http://www.suse.cz/
PGP: 830B 40D5 9E05 35D8 5E27 6FA3 717C 209F A04F CD76
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2020-06-13 20:52 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-31 23:35 [PATCH] blockdev: Don't fail on missing start sector Stanislav Brabec
2020-06-01 8:13 ` Karel Zak
2020-06-02 1:52 ` Stanislav Brabec
2020-06-03 15:16 ` Karel Zak
2020-06-05 8:06 ` Karel Zak
2020-06-13 20:52 ` Stanislav Brabec
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.