[libvirt] [PATCH v2] Ensure disk names follow the disk name regex

Nitesh Konkar posted 1 patch 4 years, 2 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/1487157298-12618-1-git-send-email-niteshkonkar.libvirt@gmail.com
src/util/virutil.c | 2 +-
tests/utiltest.c   | 3 ++-
2 files changed, 3 insertions(+), 2 deletions(-)

[libvirt] [PATCH v2] Ensure disk names follow the disk name regex

Posted by Nitesh Konkar 4 years, 2 months ago
Currently disk names do not follow the
(regex) /^[fhv]d[a-z]+[0-9]*$/ completely
and hence one can assign disk names like
vd2 etc. This patch ensures that the
disk names follow the regex mentioned.
This patch also adds a testcase.

Signed-off-by: Nitesh Konkar <nitkon12@linux.vnet.ibm.com>
---
 src/util/virutil.c | 2 +-
 tests/utiltest.c   | 3 ++-
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/src/util/virutil.c b/src/util/virutil.c
index 91178d1..2796671 100644
--- a/src/util/virutil.c
+++ b/src/util/virutil.c
@@ -563,7 +563,7 @@ int virDiskNameParse(const char *name, int *disk, int *partition)
         }
     }
 
-    if (!ptr)
+    if (!ptr || !c_islower(*ptr))
         return -1;
 
     for (i = 0; *ptr; i++) {
diff --git a/tests/utiltest.c b/tests/utiltest.c
index 9b7a4a3..bd55d44 100644
--- a/tests/utiltest.c
+++ b/tests/utiltest.c
@@ -37,7 +37,8 @@ static struct testDiskName diskNamesPart[] = {
 };
 
 static const char* diskNamesInvalid[] = {
-    "sda00", "sda01", "sdb-1"
+    "sda00", "sda01", "sdb-1",
+    "vd2"
 };
 
 static int
-- 
1.9.3

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] [PATCH v2] Ensure disk names follow the disk name regex

Posted by Michal Privoznik 4 years, 2 months ago
On 02/15/2017 12:14 PM, Nitesh Konkar wrote:
> Currently disk names do not follow the
> (regex) /^[fhv]d[a-z]+[0-9]*$/ completely
> and hence one can assign disk names like
> vd2 etc. This patch ensures that the
> disk names follow the regex mentioned.
> This patch also adds a testcase.
> 
> Signed-off-by: Nitesh Konkar <nitkon12@linux.vnet.ibm.com>
> ---
>  src/util/virutil.c | 2 +-
>  tests/utiltest.c   | 3 ++-
>  2 files changed, 3 insertions(+), 2 deletions(-)
> 

ACKed and pushed.

Michal

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] [PATCH v2] Ensure disk names follow the disk name regex

Posted by Nitesh Konkar 4 years, 2 months ago
As we know that Libvirt translates a device name of the form (regex)
/^[fhv]d[a-z]+[0-9]*$/ into the corresponding index (e.g. sda => 0, hdz =>
25, vdaa => 26) such that any trailing string of digits is simply ignored.
Thus disk names like vda2 after attaching vda1 will error out like this:

2017-02-16 10:31:05.214+0000: 10668: error : qemuMonitorJSONCheckError:387
: internal error: unable to execute QEMU command 'device_add': Duplicate ID
'virtio-disk7' for device
error: Failed to attach disk
error: internal error: unable to execute QEMU command 'device_add':
Duplicate ID 'virtio-disk7' for device

Thus, should we document this (trailing digits are ignored) in virsh
manpage for attach-disk or is the user  expected to know?
Also shd the error message reported be better in such cases or this one is
fine?

Thanks,
Nitesh.




On Thu, Feb 16, 2017 at 2:30 PM, Michal Privoznik <mprivozn@redhat.com>
wrote:

> On 02/15/2017 12:14 PM, Nitesh Konkar wrote:
> > Currently disk names do not follow the
> > (regex) /^[fhv]d[a-z]+[0-9]*$/ completely
> > and hence one can assign disk names like
> > vd2 etc. This patch ensures that the
> > disk names follow the regex mentioned.
> > This patch also adds a testcase.
> >
> > Signed-off-by: Nitesh Konkar <nitkon12@linux.vnet.ibm.com>
> > ---
> >  src/util/virutil.c | 2 +-
> >  tests/utiltest.c   | 3 ++-
> >  2 files changed, 3 insertions(+), 2 deletions(-)
> >
>
> ACKed and pushed.
>
> Michal
>
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list