Richard W.M. Jones
2017-Jan-19 09:46 UTC
[Libguestfs] [PATCH 1/2] canonical_device_name: Don't rewrite /dev/mdX as /dev/sdX (RHBZ#1414682).
The guestfs_canonical_device_name API was rewriting /dev/mdX as /dev/sdX. This is wrong since (eg) /dev/sd0 is not a device name, so if you pass the canonicalized name back to the API it will fail. virt-v2v was one tool doing this. --- src/canonical-name.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/canonical-name.c b/src/canonical-name.c index ae7b468..d72768f 100644 --- a/src/canonical-name.c +++ b/src/canonical-name.c @@ -35,6 +35,7 @@ guestfs_impl_canonical_device_name (guestfs_h *g, const char *device) /* /dev/hd etc. */ if (STRPREFIX (device, "/dev/") && strchr (device+5, '/') == NULL && /* not an LV name */ + device[5] != 'm' && /* not /dev/md - RHBZ#1414682 */ ((len = strcspn (device+5, "d")) > 0 && len <= 2)) { ret = safe_asprintf (g, "/dev/sd%s", &device[5+len+1]); } -- 2.9.3
Richard W.M. Jones
2017-Jan-19 09:46 UTC
[Libguestfs] [PATCH 2/2] tests: Add unit tests for guestfs_canonical_device_name.
--- generator/actions.ml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/generator/actions.ml b/generator/actions.ml index fc3bdea..59afa2e 100644 --- a/generator/actions.ml +++ b/generator/actions.ml @@ -2493,6 +2493,20 @@ information on this topic." }; { defaults with name = "canonical_device_name"; added = (1, 19, 7); style = RString "canonical", [String "device"], []; + tests = [ + InitNone, Always, TestResultString ( + [["canonical_device_name"; "/dev/hda"]], "/dev/sda"), []; + InitNone, Always, TestResultString ( + [["canonical_device_name"; "/dev/vdaaa"]], "/dev/sdaaa"), []; + InitNone, Always, TestResultString ( + [["canonical_device_name"; "/dev/sdb"]], "/dev/sdb"), []; + InitBasicFSonLVM, IfAvailable "lvm2", TestResultString ( + [["canonical_device_name"; "/dev/mapper/VG-LV"]], "/dev/VG/LV"), []; + InitNone, Always, TestResultString ( + [["canonical_device_name"; "/dev/md0"]], "/dev/md0"), []; + InitNone, Always, TestResultString ( + [["canonical_device_name"; "/dev/md127"]], "/dev/md127"), []; + ]; shortdesc = "return canonical device name"; longdesc = "\ This utility function is useful when displaying device names to -- 2.9.3
Pino Toscano
2017-Jan-19 11:31 UTC
Re: [Libguestfs] [PATCH 1/2] canonical_device_name: Don't rewrite /dev/mdX as /dev/sdX (RHBZ#1414682).
On Thursday, 19 January 2017 09:46:36 CET Richard W.M. Jones wrote:> The guestfs_canonical_device_name API was rewriting /dev/mdX as > /dev/sdX. This is wrong since (eg) /dev/sd0 is not a device name, so > if you pass the canonicalized name back to the API it will fail. > virt-v2v was one tool doing this. > ---The series LGTM. Thanks, -- Pino Toscano
Maybe Matching Threads
- [PATCH 0/3] generator: Allow returned strings to be annotated as devices.
- [PATCH 0/6] generator: Split up generator/actions.ml
- [PATCH] tests: disable UUID change on ext journal_dev
- [PATCH] mkfs: add 'label' optional argument
- mdX and mismatch_cnt when building an array