This service will be undergoing maintenance at 00:00 UTC, 2016-08-01. It is expected to last about 1 hours
Bug 883689 - RFE: export a Python name-validation function ([vgcreate] New volume group name "ñ" is invalid)
RFE: export a Python name-validation function ([vgcreate] New volume group na...
Status: CLOSED NEXTRELEASE
Product: Fedora
Classification: Fedora
Component: lvm2 (Show other bugs)
18
Unspecified Unspecified
unspecified Severity unspecified
: ---
: ---
Assigned To: LVM and device-mapper development team
Fedora Extras Quality Assurance
:
: 889611 (view as bug list)
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2012-12-05 01:23 EST by Steve Tyler
Modified: 2013-12-16 08:16 EST (History)
18 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2013-12-16 08:16:00 EST
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:


Attachments (Terms of Use)
anaconda-tb-_pjRJa (1.58 MB, text/plain)
2012-12-05 01:23 EST, Steve Tyler
no flags Details
anaconda-tb-CR6I2w corresponding to reproducer (1.20 MB, text/plain)
2012-12-05 14:29 EST, Steve Tyler
no flags Details
anaconda-tb-_bVbgz with DeviceCreateError exception after a long VG name was entered (394.27 KB, text/plain)
2012-12-21 02:15 EST, Steve Tyler
no flags Details

  None (edit)
Description Steve Tyler 2012-12-05 01:23:36 EST
Created attachment 657995 [details]
anaconda-tb-_pjRJa

Description of problem:
vgcreate fails when asked to create a volume group named "ñ".

NB: The traceback in the attached anaconda-tb-_pjRJa was duped to Bug 870586.

Version-Release number of selected component (if applicable):
anaconda 18.35
Fedora-18-Beta-x86_64-Live-Desktop.iso

How reproducible:
First try.

Steps to Reproduce:
1. Create a volume group named "ñ".
2. Begin installation.
  
Actual results:
New volume group name "ñ" is invalid

Expected results:
The volume group name "ñ" is rejected before installation starts.

Additional info:
[snippet from attached anaconda-tb-_pjRJa]
...
22:53:53,035 INFO program: Running... lvm vgcreate -s 4m --config  devices { filter=["r|/loop5$|","r|/loop6$|","r|/loop7$|"] }  ñ /dev/sda2
22:53:53,057 ERR program:   New volume group name "ñ" is invalid
22:53:53,059 ERR program:   Run `vgcreate --help' for more information.
...

Tested with:
$ qemu-kvm -m 2048 -hda f18-test-2.img -cdrom ~/xfr/fedora/F18/F18-Beta/Final/Fedora-18-Beta-x86_64-Live-Desktop.iso -usb -vga qxl -boot menu=on -usbdevice mouse
Comment 1 Steve Tyler 2012-12-05 14:29:14 EST
Created attachment 658347 [details]
anaconda-tb-CR6I2w corresponding to reproducer

Here's a reproducer and the corresponding log file:

Create an empty 12 GB disk image:
$ qemu-img create f18-test-2.img 12G

Start the Live CD and update the installer:
$ qemu-kvm -m 2048 -hda f18-test-2.img -cdrom ~/xfr/fedora/F18/F18-Beta/Final/Fedora-18-Beta-x86_64-Live-Desktop.iso -usb -vga qxl -boot menu=on -usbdevice mouse

Start the installer.
Proceed to Manual Partitioning.
Auto-create storage devices.
Click Root.
Expand Customize...
Click Volume Group: fedora
Click Create a new volume group ...
For Name, enter "ñ".[1]
Click Save.
Click Finish Partitioning.
Click Begin Installation.
Exception occurs at Creating lvmpv on /dev/sda3:
DeviceCreateError: ('vgcreate failed for \xc3\xb1: running lvm vgcreate -s 4m --config  devices { filter=["r|/loop5$|","r|/loop6$|","r|/loop7$|"] }  \xc3\xb1 /dev/sda3 failed', '\xc3\xb1')

[1] "ñ" is copied from here:
>>> import babel
>>> print babel.Locale.parse('es_ES').display_name
español (España)
Comment 2 Steve Tyler 2012-12-06 15:05:44 EST
The lvm man page has a whole section on valid names. My question: Does LVM provide a library function that validates names against these minutia? :-)

VALID NAMES
       The following characters are valid for VG and LV names: a-z A-Z 0-9 + _ . -

       VG and LV names cannot begin with a hyphen.  There are also various reserved names that are used internally by lvm that can not be used as LV or VG names.  A VG cannot be called anything that exists
       in /dev/ at the time of creation, nor can it be called '.' or '..'.  A LV cannot be called '.' '..' 'snapshot' or 'pvmove'. The LV name may also not contain the strings  '_mlog',  '_mimage',  '_rim‐
       age', '_tdata', '_tmeta'.
Comment 3 Chris Lumens 2012-12-17 23:33:05 EST
It certainly would be helpful if there were something we could call so we didn't have to know these rules ourselves.
Comment 4 Alasdair Kergon 2012-12-18 05:33:52 EST
At the moment, vgcreate/lvcreate --test is the only option.  There could be a library call.
Comment 5 Steve Tyler 2012-12-21 02:15:41 EST
Created attachment 667114 [details]
anaconda-tb-_bVbgz with DeviceCreateError exception after a long VG name was entered

The lvm man page doesn't say what the maximum length of a volume group name is.
Comment 6 Steve Tyler 2012-12-21 03:25:48 EST
There is indeed an lvm validate_name() function, but it does not appear to be exported in lvm2-devel:

$ less -N lvm2-2_02_98/lib/misc/lvm-string.h
...
     22 #define NAME_LEN 128
...
     33 int validate_name(const char *n);
...

$ less -N lvm2-2_02_98/lib/misc/lvm-string.c
...
     66 /*
     67  * Device layer names are all of the form <vg>-<lv>-<layer>, any
     68  * other hyphens that appear in these names are quoted with yet
     69  * another hyphen.  The top layer of any device has no layer
     70  * name.  eg, vg0-lvol0.
     71  */
     72 int validate_name(const char *n)
     73 {
     74         register char c;
     75         register int len = 0;
     76 
     77         if (!n || !*n)
     78                 return 0;
     79 
     80         /* Hyphen used as VG-LV separator - ambiguity if LV starts with it */
     81         if (*n == '-')
     82                 return 0;
     83 
     84         if (!strcmp(n, ".") || !strcmp(n, ".."))
     85                 return 0;
     86 
     87         while ((len++, c = *n++))
     88                 if (!isalnum(c) && c != '.' && c != '_' && c != '-' && c != '+')
     89                         return 0;
     90 
     91         if (len > NAME_LEN)
     92                 return 0;
     93 
     94         return 1;
     95 }
...
Comment 7 Steve Tyler 2012-12-21 03:44:09 EST
There appears to be a Python interface to lvm:
http://git.fedorahosted.org/cgit/lvm2.git/tree/python

The example doesn't use any try/except blocks, so it may not be ready for production use ...
Comment 8 Chris Lumens 2013-01-02 11:02:46 EST
*** Bug 889611 has been marked as a duplicate of this bug. ***
Comment 9 Alasdair Kergon 2013-01-02 11:17:30 EST
So what is the focus of this bugzilla?

The volume group name "ñ" will remain invalid.  We aren't going to change that.

Is this a request for python name validation functions?
Comment 10 Steve Tyler 2013-01-03 13:09:30 EST
Per Comment 3, this is a request for a Python name-validation function. Revising bug summary accordingly.

Since this function would be validating names entered by users, it would be helpful if the function could return a Python exception object with an error message identifying the error more specifically, so the user wouldn't have to guess and try again.

1. name longer than N characters
2. character not in [list of valid characters]
3. name already in use
4. ...
Comment 11 Tony Asleson 2013-01-03 15:03:05 EST
(In reply to comment #10)
> Per Comment 3, this is a request for a Python name-validation function.
> Revising bug summary accordingly.
> 
> Since this function would be validating names entered by users, it would be
> helpful if the function could return a Python exception object with an error
> message identifying the error more specifically, so the user wouldn't have
> to guess and try again.
> 
> 1. name longer than N characters
> 2. character not in [list of valid characters]
> 3. name already in use
> 4. ...

This seems reasonable.  However, until anaconda picks up and uses the python bindings for lvm (instead of command line) they should really do some type of validation in anaconda.
Comment 12 Tony Asleson 2013-11-22 12:14:03 EST
Patch committed upstream adds this functionality:

http://www.redhat.com/archives/lvm-devel/2013-November/msg00085.html

Will be included in next release (2.02.105)
Comment 13 Peter Rajnoha 2013-12-16 08:16:00 EST
Currently (Fedora 20), it seems that anaconda removes any unsupported characters from VG/LV names before trying to issue an LVM command. The patch mentioned here will also get into the release within next update, but only for recent Fedoras. Marking as closed/nextrelease.

Note You need to log in before you can comment on or make changes to this bug.